diff --git a/modules/lua/sipluafunc.c b/modules/lua/sipluafunc.c index 4a7cbc8086d..d4d6e2b1116 100644 --- a/modules/lua/sipluafunc.c +++ b/modules/lua/sipluafunc.c @@ -110,7 +110,7 @@ int siplua_exec(struct sip_msg* _msg, const str *fnc, const str *mystr) reason.s = "Bad Request-URI"; reason.len = sizeof("Bad Request-URI")-1; - if (slb.reply(_msg, 400, &reason) == -1) { + if (slb.reply(_msg, 400, &reason, NULL) == -1) { LM_ERR("failed to send reply\n"); } return -1; diff --git a/modules/script_helper/script_helper.c b/modules/script_helper/script_helper.c index c75b0a08851..c70d1b8f17f 100644 --- a/modules/script_helper/script_helper.c +++ b/modules/script_helper/script_helper.c @@ -189,7 +189,7 @@ int run_helper_logic(struct sip_msg *msg, void *param) return SCB_RUN_POST_CBS; } - sl_api.reply(msg, 404, &status_404); + sl_api.reply(msg, 404, &status_404, NULL); return SCB_RUN_POST_CBS; } } @@ -223,7 +223,7 @@ int run_helper_logic(struct sip_msg *msg, void *param) } if (tm_api.t_relay(msg, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0) - sl_api.reply(msg, 500, &status_500); + sl_api.reply(msg, 500, &status_500, NULL); return SCB_RUN_POST_CBS; } diff --git a/modules/signaling/signaling.c b/modules/signaling/signaling.c index dfaf1a8bda3..418068f7714 100644 --- a/modules/signaling/signaling.c +++ b/modules/signaling/signaling.c @@ -185,23 +185,54 @@ int sig_send_reply_mod(struct sip_msg* msg, int code, str* reason, str* to_tag) sl_reply: - if(slb.reply(msg, code, reason)< 0) + if(slb.reply(msg, code, reason, to_tag)< 0) { LM_ERR("failed to send reply with sl module\n"); return -1; } - if(to_tag) - { - if(slb.get_totag(msg, to_tag)< 0) - { - LM_ERR("failed to get to_tag from sl\n"); - return -1; + + return 1; +} + + +/* + * sig_gen_totag_mod function - generates the To-tag for the given request, + * according to the underlaying signaling module( tm or sl). + * */ +static int sig_gen_totag_mod(struct sip_msg* msg, str* to_tag) +{ + struct cell * t; + + /* search transaction */ + if (tm_loaded) { + t = tmb.t_gett(); + if (t==NULL || t==T_UNDEFINED) { + if (!sl_loaded) { + LM_ERR("sl module not loaded and no transaction found for the" + " message. Can not generate totag!\n"); + return -1; + } + /* fallback to stateless */ + } else { + /* do it statefull */ + if (tmb.t_gen_totag(msg, to_tag)< 0) { + LM_ERR("failed to generate totag with tm module\n"); + return -1; + } + return 1; } } + /* do it stateless */ + if (slb.gen_totag(msg, to_tag)< 0) { + LM_ERR("failed to generate totag with sl module\n"); + return -1; + } + return 1; } + /* * * fixup_sig_send_reply */ @@ -222,6 +253,7 @@ int load_sig( struct sig_binds *sigb) return -1; sigb->reply = sig_send_reply_mod; + sigb->gen_totag = sig_gen_totag_mod; return 1; } diff --git a/modules/signaling/signaling.h b/modules/signaling/signaling.h index 94fc5935315..e48703da2bd 100644 --- a/modules/signaling/signaling.h +++ b/modules/signaling/signaling.h @@ -32,9 +32,11 @@ typedef int (*sig_send_reply_f)(struct sip_msg *msg, int code, str *reason, str *tag); +typedef int (*sig_gen_totag_f)(struct sip_msg *msg, str *tag); struct sig_binds { sig_send_reply_f reply; + sig_gen_totag_f gen_totag; }; int load_sig( struct sig_binds *sigb); diff --git a/modules/sl/sl.c b/modules/sl/sl.c index 7152654cde7..ca1768528af 100644 --- a/modules/sl/sl.c +++ b/modules/sl/sl.c @@ -187,7 +187,7 @@ static int w_sl_reply_error( struct sip_msg* msg) static int w_sl_send_reply(struct sip_msg* msg, int* code_i, str* code_s) { - return sl_send_reply(msg, *code_i, code_s); + return sl_send_reply(msg, *code_i, code_s, NULL); } @@ -197,7 +197,7 @@ int load_sl( struct sl_binds *slb) return -1; slb->reply = sl_send_reply; - slb->get_totag = sl_get_totag; + slb->gen_totag = sl_gen_totag; return 1; } diff --git a/modules/sl/sl_api.h b/modules/sl/sl_api.h index 9258f01de4f..beaa54c2f3a 100644 --- a/modules/sl/sl_api.h +++ b/modules/sl/sl_api.h @@ -26,15 +26,13 @@ #include "../../dprint.h" #include "../../str.h" -typedef int (*sl_send_reply_f)(struct sip_msg *msg, int code, str *reason); -typedef int (*sl_send_reply_dlg_f)(struct sip_msg *msg, int code, str *reason, +typedef int (*sl_send_reply_f)(struct sip_msg *msg, int code, str *reason, str *tag); -typedef int (*sl_get_totag_f)(struct sip_msg *msg, str *totag); +typedef int (*sl_gen_totag_f)(struct sip_msg *msg, str *totag); struct sl_binds { - sl_send_reply_f reply; - sl_send_reply_dlg_f reply_dlg; - sl_get_totag_f get_totag; + sl_send_reply_f reply; + sl_gen_totag_f gen_totag; }; typedef int(*load_sl_f)(struct sl_binds *slb); diff --git a/modules/sl/sl_funcs.c b/modules/sl/sl_funcs.c index 82bbdb636b4..a9c627f2f26 100644 --- a/modules/sl/sl_funcs.c +++ b/modules/sl/sl_funcs.c @@ -97,10 +97,12 @@ int sl_shutdown(void) } -int sl_get_totag(struct sip_msg *msg, str *totag) +int sl_gen_totag(struct sip_msg *msg, str *totag) { + calc_tag_suffix( msg, tag_suffix ); *totag = sl_tag; - return 0; + + return 1; } @@ -207,9 +209,17 @@ int sl_send_reply_helper(struct sip_msg *msg ,int code, str *text) return -1; } -int sl_send_reply(struct sip_msg *msg ,int code, str *text) +int sl_send_reply(struct sip_msg *msg ,int code, str *text, str *totag) { - return sl_send_reply_helper(msg, code, text); + int ret; + + if ( (ret=sl_send_reply_helper(msg, code, text))<0) + return ret; + + if (totag) + *totag = sl_tag; + + return ret; } diff --git a/modules/sl/sl_funcs.h b/modules/sl/sl_funcs.h index f5d3ca5f016..d848814233a 100644 --- a/modules/sl/sl_funcs.h +++ b/modules/sl/sl_funcs.h @@ -31,10 +31,10 @@ int sl_startup(); int sl_shutdown(); -int sl_send_reply( struct sip_msg *msg, int code, str *reason); -int sl_filter_ACK( struct sip_msg *msg, void *foo ); +int sl_send_reply( struct sip_msg *msg, int code, str *reason, str *totag); +int sl_filter_ACK( struct sip_msg *msg, void *foo); int sl_reply_error( struct sip_msg *msg ); -int sl_get_totag( struct sip_msg *msg, str *totag ); +int sl_gen_totag( struct sip_msg *msg, str *totag); #endif diff --git a/modules/tm/t_reply.c b/modules/tm/t_reply.c index 9aae130c898..aa1b83f7a2a 100644 --- a/modules/tm/t_reply.c +++ b/modules/tm/t_reply.c @@ -1105,14 +1105,13 @@ int t_retransmit_reply( struct cell *t ) } - - int t_reply( struct cell *t, struct sip_msg* p_msg, unsigned int code, str * text ) { return _reply( t, p_msg, code, text, 1 /* lock replies */ ); } + int t_reply_unsafe( struct cell *t, struct sip_msg* p_msg, unsigned int code, str * text ) { @@ -1120,7 +1119,13 @@ int t_reply_unsafe( struct cell *t, struct sip_msg* p_msg, unsigned int code, } +int t_gen_totag(struct sip_msg *msg, str *totag) +{ + calc_tag_suffix( msg, tm_tag_suffix ); + *totag = tm_tag; + return 1; +} void set_final_timer( /* struct s_table *h_table, */ struct cell *t ) diff --git a/modules/tm/t_reply.h b/modules/tm/t_reply.h index 48516588b4a..3223673cc74 100644 --- a/modules/tm/t_reply.h +++ b/modules/tm/t_reply.h @@ -68,6 +68,7 @@ typedef unsigned int branch_bm_t; typedef int (*treply_f)(struct sip_msg * , unsigned int , str * ); typedef int (*treply_wb_f)( struct cell* trans, unsigned int code, str *text, str *body, str *new_header, str *to_tag); +typedef int (*tgen_totag_f)(struct sip_msg * , str * ); #define LOCK_REPLIES(_t) lock(&(_t)->reply_mutex ) #define UNLOCK_REPLIES(_t) unlock(&(_t)->reply_mutex ) @@ -107,6 +108,8 @@ int t_reply( struct cell *t, struct sip_msg * , unsigned int , str * ); int w_t_reply_body(struct sip_msg* msg, unsigned int* code, str *text, str *body); +int t_gen_totag(struct sip_msg *msg, str *totag); + int t_reply_unsafe( struct cell *t, struct sip_msg * , unsigned int , str * ); diff --git a/modules/tm/tm.c b/modules/tm/tm.c index 8e1d0571645..d0ee36d2f0d 100644 --- a/modules/tm/tm.c +++ b/modules/tm/tm.c @@ -639,6 +639,7 @@ int load_tm( struct tm_binds *tmb) /* reply functions */ tmb->t_reply = (treply_f)w_t_reply; tmb->t_reply_with_body = t_reply_with_body; + tmb->t_gen_totag = t_gen_totag; /* transaction location/status functions */ tmb->t_newtran = w_t_newtran; diff --git a/modules/tm/tm_load.h b/modules/tm/tm_load.h index 7486e8cf85a..1ae8cd420f5 100644 --- a/modules/tm/tm_load.h +++ b/modules/tm/tm_load.h @@ -52,6 +52,7 @@ struct tm_binds { tnewtran_f t_newtran; treply_f t_reply; treply_wb_f t_reply_with_body; + tgen_totag_f t_gen_totag; tislocal_f t_is_local; tget_ti_f t_get_trans_ident; tlookup_ident_f t_lookup_ident;