Skip to content

Commit

Permalink
Refactor signaling, sl & tm APIs to add gen_totag()
Browse files Browse the repository at this point in the history
This is a new function to generate the To-tag (which is msg specific and computed in a deterministic way) whitout actually sending a reply.

First stage of a fix for #1722

(cherry picked from commit 666e811)
  • Loading branch information
bogdan-iancu committed Jan 10, 2020
1 parent 8179e1f commit 3e8b549
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 27 deletions.
2 changes: 1 addition & 1 deletion modules/lua/sipluafunc.c
Expand Up @@ -109,7 +109,7 @@ static int siplua_exec(struct sip_msg* _msg, const char *fnc, const char *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;
Expand Down
4 changes: 2 additions & 2 deletions modules/script_helper/script_helper.c
Expand Up @@ -192,7 +192,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;
}
}
Expand Down Expand Up @@ -226,7 +226,7 @@ int run_helper_logic(struct sip_msg *msg, void *param)
}

if (tm_api.t_relay(msg, 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;
}
Expand Down
46 changes: 39 additions & 7 deletions modules/signaling/signaling.c
Expand Up @@ -204,23 +204,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
*/
Expand Down Expand Up @@ -275,6 +306,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;
}
Expand Down
2 changes: 2 additions & 0 deletions modules/signaling/signaling.h
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions modules/sl/sl.c
Expand Up @@ -240,7 +240,7 @@ static int w_sl_send_reply(struct sip_msg* msg, char* str1, char* str2)
code_s = ((pv_elem_p)str2)->text;
}

return sl_send_reply(msg, code_i, &code_s);
return sl_send_reply(msg, code_i, &code_s, NULL);
}


Expand All @@ -250,7 +250,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;
}
10 changes: 4 additions & 6 deletions modules/sl/sl_api.h
Expand Up @@ -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);
Expand Down
18 changes: 14 additions & 4 deletions modules/sl/sl_funcs.c
Expand Up @@ -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;
}


Expand Down Expand Up @@ -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;
}


Expand Down
6 changes: 3 additions & 3 deletions modules/sl/sl_funcs.h
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions modules/tm/t_reply.c
Expand Up @@ -1092,22 +1092,27 @@ 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 )
{
return _reply( t, p_msg, code, text, 0 /* don't lock replies */ );
}


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 )
Expand Down
3 changes: 3 additions & 0 deletions modules/tm/t_reply.h
Expand Up @@ -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 )
Expand Down Expand Up @@ -106,6 +107,8 @@ int t_reply( struct cell *t, struct sip_msg * , unsigned int , str * );

int w_t_reply_body(struct sip_msg* msg,str* 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 * );


Expand Down
1 change: 1 addition & 0 deletions modules/tm/tm.c
Expand Up @@ -707,6 +707,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;
Expand Down
1 change: 1 addition & 0 deletions modules/tm/tm_load.h
Expand Up @@ -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;
Expand Down

0 comments on commit 3e8b549

Please sign in to comment.