12 #include "../../sr_module.h"
13 #include "../../dprint.h"
14 #include "../../error.h"
16 #include "../../script_cb.h"
17 #include "../../fifo_server.h"
33 inline static int w_t_check(struct sip_msg* msg, char* str, char* str2);
34 inline static int w_t_reply(struct sip_msg* msg, char* str, char* str2);
35 inline static int w_t_reply_unsafe(struct sip_msg* msg, char* str, char* str2);
36 inline static int w_t_release(struct sip_msg* msg, char* str, char* str2);
37 inline static int fixup_t_send_reply(void** param, int param_no);
38 inline static int fixup_str2int( void** param, int param_no);
39 inline static int w_t_retransmit_reply(struct sip_msg* p_msg, char* foo, char* bar );
40 inline static int w_t_newtran(struct sip_msg* p_msg, char* foo, char* bar );
41 inline static int w_t_newdlg( struct sip_msg* p_msg, char* foo, char* bar );
42 inline static int w_t_relay( struct sip_msg *p_msg , char *_foo, char *_bar);
43 inline static int w_t_relay_to( struct sip_msg *p_msg , char *proxy, char *);
44 inline static int w_t_replicate( struct sip_msg *p_msg ,
45 char *proxy, /* struct proxy_l *proxy expected */
46 char *_foo /* nothing expected */ );
47 inline static int w_t_forward_nonack(struct sip_msg* msg, char* str, char* );
48 inline static int fixup_hostport2proxy(void** param, int param_no);
49 inline static int w_t_on_negative( struct sip_msg* msg, char *go_to, char *foo );
52 static int mod_init(void);
54 static int child_init(int rank);
58 struct module_exports tm_exports = {
60 struct module_exports exports= {
63 /* -------- exported functions ----------- */
77 /* not applicable from script ... */
97 (cmd_function) register_tmcb,
99 (cmd_function) load_tm,
104 0, /* t_lookup_request */
106 2, /* t_reply_unsafe */
107 0, /* t_retransmit_reply */
112 2, /* t_forward_nonack */
113 1, /* t_on_negative */
114 NO_SCRIPT /* register_tmcb */,
115 NO_SCRIPT /* t_uac */,
116 NO_SCRIPT /* load_tm */,
121 0, /* t_lookup_request */
122 fixup_t_send_reply, /* t_reply */
123 fixup_t_send_reply, /* t_reply_unsafe */
124 0, /* t_retransmit_reply */
126 fixup_hostport2proxy, /* t_relay_to */
127 fixup_hostport2proxy, /* t_replicate */
129 fixup_hostport2proxy, /* t_forward_nonack */
130 fixup_str2int, /* t_on_negative */
131 0, /* register_tmcb */
139 /* ------------ exported variables ---------- */
140 (char *[]) { /* Module parameter names */
152 (modparam_t[]) { /* variable types */
153 INT_PARAM, /* fr_timer */
154 INT_PARAM, /* fr_inv_timer */
155 INT_PARAM, /* wt_timer */
156 INT_PARAM, /* delete_timer */
157 INT_PARAM,/* retr_timer1p1 */
158 INT_PARAM, /* retr_timer1p2 */
159 INT_PARAM, /* retr_timer1p3 */
160 INT_PARAM, /* retr_timer2 */
161 INT_PARAM, /* noisy_ctimer */
162 STR_PARAM, /* uac_from */
164 (void *[]) { /* variable pointers */
165 &(timer_id2timeout[FR_TIMER_LIST]),
166 &(timer_id2timeout[FR_INV_TIMER_LIST]),
167 &(timer_id2timeout[WT_TIMER_LIST]),
168 &(timer_id2timeout[DELETE_LIST]),
169 &(timer_id2timeout[RT_T1_TO_1]),
170 &(timer_id2timeout[RT_T1_TO_2]),
171 &(timer_id2timeout[RT_T1_TO_3]),
172 &(timer_id2timeout[RT_T2]),
176 11, /* Number of module paramers */
178 mod_init, /* module initialization function */
179 (response_function) t_on_reply,
180 (destroy_function) tm_shutdown,
182 child_init /* per-child init function */
185 inline static int fixup_str2int( void** param, int param_no)
191 go_to=str2s(*param, strlen(*param), &err );
194 *param=(void *)go_to;
197 LOG(L_ERR, "ERROR: fixup_str2int: bad number <%s>\n",
205 static int w_t_unref( struct sip_msg *foo, void *bar)
210 static int script_init( struct sip_msg *foo, void *bar)
212 /* we primarily reset all private memory here to make sure
213 private values left over from previous message will
217 /* make sure the new message will not inherit previous
218 message's t_on_negative value
225 static int mod_init(void)
228 DBG( "TM - initializing...\n");
229 /* checking if we have sufficient bitmap capacity for given
230 maximum number of branches */
231 if (1<<(MAX_BRANCHES+1)>UINT_MAX) {
232 LOG(L_CRIT, "Too many max UACs for UAC branch_bm_t bitmap: %d\n",
236 if (register_fifo_cmd(fifo_uac, "t_uac", 0)<0) {
237 LOG(L_CRIT, "cannot register fifo uac\n");
240 if (register_fifo_cmd(fifo_uac_from, "t_uac_from", 0)<0) {
241 LOG(L_CRIT, "cannot register fifo uac\n");
245 if (init_tm_stats()<0) {
246 LOG(L_CRIT, "ERROR: mod_init: failed to init stats\n");
250 /* building the hash table*/
251 if (!init_hash_table()) {
252 LOG(L_ERR, "ERROR: mod_init: initializing hash_table failed\n");
256 if (!tm_init_timers()) {
257 LOG(L_ERR, "ERROR: mod_init: timer init failed\n");
261 /* init static hidden values */
265 register_tmcb( TMCB_ON_NEGATIVE, on_negative_reply, 0 /* empty param */);
266 /* register the timer function */
267 register_timer( timer_routine , 0 /* empty attr */, 1 );
268 /* register post-script clean-up function */
269 register_script_cb( w_t_unref, POST_SCRIPT_CB, 0 /* empty param */ );
270 register_script_cb( script_init, PRE_SCRIPT_CB , 0 /* empty param */ );
275 static int child_init(int rank) {
276 uac_child_init(rank);
281 /* (char *hostname, char *port_nr) ==> (struct proxy_l *, -) */
283 inline static int fixup_hostport2proxy(void** param, int param_no)
288 struct proxy_l *proxy;
290 DBG("TM module: fixup_t_forward(%s, %d)\n", (char*)*param, param_no);
292 DBG("TM module: fixup_t_forward: param 1.. do nothing, wait for #2\n");
294 } else if (param_no==2) {
296 host=(char *) (*(param-1));
297 port=str2s(*param, strlen(*param), &err);
299 LOG(L_ERR, "TM module:fixup_t_forward: bad port number <%s>\n",
303 proxy=mk_proxy(host, port);
305 LOG(L_ERR, "ERROR: fixup_t_forwardv6: bad host name in URI <%s>\n",
307 return E_BAD_ADDRESS;
309 /* success -- fix the first parameter to proxy now ! */
314 LOG(L_ERR, "ERROR: fixup_t_forwardv6 called with parameter #<>{1,2}\n");
320 /* (char *code, char *reason_phrase)==>(int code, r_p as is) */
321 inline static int fixup_t_send_reply(void** param, int param_no)
327 code=str2s(*param, strlen(*param), &err);
333 LOG(L_ERR, "TM module:fixup_t_send_reply: bad number <%s>\n",
338 /* second param => no conversion*/
345 inline static int w_t_check(struct sip_msg* msg, char* str, char* str2)
347 return t_check( msg , 0 ) ? 1 : -1;
352 inline static int w_t_forward_nonack(struct sip_msg* msg, char* proxy, char* _foo)
355 if (t_check( msg , 0 )==-1) return -1;
357 if ( t && t!=T_UNDEFINED ) {
358 if (msg->REQ_METHOD==METHOD_ACK) {
359 LOG(L_WARN,"WARNING: you don't really want to fwd hbh ACK\n");
362 return t_forward_nonack(t, msg, ( struct proxy_l *) proxy );
364 DBG("DEBUG: t_forward_nonack: no transaction found\n");
371 inline static int w_t_reply(struct sip_msg* msg, char* str, char* str2)
375 if (msg->REQ_METHOD==METHOD_ACK) {
376 LOG(L_WARN, "WARNING: t_reply: ACKs are not replied\n");
379 if (t_check( msg , 0 )==-1) return -1;
382 LOG(L_ERR, "ERROR: t_reply: cannot send a t_reply to a message "
383 "for which no T-state has been established\n");
386 return t_reply( t, msg, (unsigned int) str, str2);
390 inline static int w_t_reply_unsafe(struct sip_msg* msg, char* str, char* str2)
394 if (msg->REQ_METHOD==METHOD_ACK) {
395 LOG(L_WARN, "WARNING: t_reply: ACKs are not replied\n");
398 if (t_check( msg , 0 )==-1) return -1;
401 LOG(L_ERR, "ERROR: t_reply: cannot send a t_reply to a message "
402 "for which no T-state has been established\n");
405 return t_reply_unsafe(t, msg, (unsigned int) str, str2);
409 inline static int w_t_release(struct sip_msg* msg, char* str, char* str2)
412 if (t_check( msg , 0 )==-1) return -1;
414 if ( t && t!=T_UNDEFINED )
415 return t_release_transaction( t );
422 inline static int w_t_retransmit_reply( struct sip_msg* p_msg, char* foo, char* bar)
427 if (t_check( p_msg , 0 )==-1)
431 if (p_msg->REQ_METHOD==METHOD_ACK) {
432 LOG(L_WARN, "WARNING: : ACKs ansmit_replies not replied\n");
435 return t_retransmit_reply( t );
445 inline static int w_t_newdlg( struct sip_msg* p_msg, char* foo, char* bar )
447 return t_newdlg( p_msg );
450 inline static int w_t_newtran( struct sip_msg* p_msg, char* foo, char* bar )
452 /* t_newtran returns 0 on error (negative value means
455 return t_newtran( p_msg );
459 inline static int w_t_on_negative( struct sip_msg* msg, char *go_to, char *foo )
461 return t_on_negative( (unsigned int ) go_to );
464 inline static int w_t_relay_to( struct sip_msg *p_msg ,
465 char *proxy, /* struct proxy_l *proxy expected */
466 char *_foo /* nothing expected */ )
468 return t_relay_to( p_msg, ( struct proxy_l *) proxy,
469 0 /* no replication */ );
472 inline static int w_t_replicate( struct sip_msg *p_msg ,
473 char *proxy, /* struct proxy_l *proxy expected */
474 char *_foo /* nothing expected */ )
476 return t_replicate(p_msg, ( struct proxy_l *) proxy );
479 inline static int w_t_relay( struct sip_msg *p_msg ,
480 char *_foo, char *_bar)
482 return t_relay_to( p_msg,
483 (struct proxy_l *) 0 /* no proxy */,
484 0 /* no replication */ );