diff --git a/src/modules/topos/api.h b/src/modules/topos/api.h index ca7c9949704..ec8a1df6904 100644 --- a/src/modules/topos/api.h +++ b/src/modules/topos/api.h @@ -36,16 +36,18 @@ typedef int (*tps_insert_dialog_f)(tps_data_t *td); typedef int (*tps_clean_dialogs_f)(void); typedef int (*tps_insert_branch_f)(tps_data_t *td); typedef int (*tps_clean_branches_f)(void); -typedef int (*tps_load_branch_f)(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, - uint32_t mode); -typedef int (*tps_load_dialog_f)(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd); -typedef int (*tps_update_branch_f)(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, - uint32_t mode); -typedef int (*tps_update_dialog_f)(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, - uint32_t mode); +typedef int (*tps_load_branch_f)( + sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, uint32_t mode); +typedef int (*tps_load_dialog_f)( + sip_msg_t *msg, tps_data_t *md, tps_data_t *sd); +typedef int (*tps_update_branch_f)( + sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, uint32_t mode); +typedef int (*tps_update_dialog_f)( + sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, uint32_t mode); typedef int (*tps_end_dialog_f)(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd); -typedef struct tps_storage_api { +typedef struct tps_storage_api +{ tps_insert_dialog_f insert_dialog; tps_clean_dialogs_f clean_dialogs; tps_insert_branch_f insert_branch; @@ -67,13 +69,14 @@ typedef int (*tps_get_branch_expire_f)(void); /** * @brief TOPOS API structure */ -typedef struct topos_api { +typedef struct topos_api +{ tps_set_storage_api_f set_storage_api; tps_get_dialog_expire_f get_dialog_expire; tps_get_branch_expire_f get_branch_expire; } topos_api_t; -typedef int (*bind_topos_f)(topos_api_t* api); +typedef int (*bind_topos_f)(topos_api_t *api); /** * @brief Load the TOPOS API @@ -87,7 +90,7 @@ static inline int topos_load_api(topos_api_t *api) LM_ERR("cannot find bind_topos\n"); return -1; } - if (bindtopos(api)==-1) { + if(bindtopos(api) == -1) { LM_ERR("cannot bind topos api\n"); return -1; } diff --git a/src/modules/topos/topos_mod.c b/src/modules/topos/topos_mod.c index 78872329588..4540382b725 100644 --- a/src/modules/topos/topos_mod.c +++ b/src/modules/topos/topos_mod.c @@ -73,7 +73,7 @@ MODULE_VERSION /* Database connection handle */ -db1_con_t* _tps_db_handle = NULL; +db1_con_t *_tps_db_handle = NULL; /* DB functions */ db_func_t _tpsdbf; /* sruid to get internal uid */ @@ -99,11 +99,11 @@ static topoh_api_t thb = {0}; int _tps_clean_interval = 60; #define TPS_EVENTRT_OUTGOING 1 -#define TPS_EVENTRT_SENDING 2 -#define TPS_EVENTRT_INCOMING 4 +#define TPS_EVENTRT_SENDING 2 +#define TPS_EVENTRT_INCOMING 4 #define TPS_EVENTRT_RECEIVING 8 static int _tps_eventrt_mode = TPS_EVENTRT_OUTGOING | TPS_EVENTRT_SENDING - | TPS_EVENTRT_INCOMING | TPS_EVENTRT_RECEIVING; + | TPS_EVENTRT_INCOMING | TPS_EVENTRT_RECEIVING; static int _tps_eventrt_outgoing = -1; static str _tps_eventrt_callback = STR_NULL; static str _tps_eventrt_outgoing_name = str_init("topos:msg-outgoing"); @@ -142,60 +142,55 @@ static int child_init(int rank); /* Module destroy function prototype */ static void destroy(void); -static int w_tps_set_context(sip_msg_t* msg, char* pctx, char* p2); +static int w_tps_set_context(sip_msg_t *msg, char *pctx, char *p2); int bind_topos(topos_api_t *api); -static cmd_export_t cmds[]={ - {"tps_set_context", (cmd_function)w_tps_set_context, - 1, fixup_spve_null, fixup_free_spve_null, - ANY_ROUTE}, - - {"bind_topos", (cmd_function)bind_topos, 0, - 0, 0, 0}, - - {0, 0, 0, 0, 0, 0} -}; - -static param_export_t params[]={ - {"storage", PARAM_STR, &_tps_storage}, - {"db_url", PARAM_STR, &_tps_db_url}, - {"mask_callid", PARAM_INT, &_tps_param_mask_callid}, - {"sanity_checks", PARAM_INT, &_tps_sanity_checks}, - {"header_mode", PARAM_INT, &_tps_header_mode}, - {"branch_expire", PARAM_INT, &_tps_branch_expire}, - {"dialog_expire", PARAM_INT, &_tps_dialog_expire}, - {"clean_interval", PARAM_INT, &_tps_clean_interval}, - {"event_callback", PARAM_STR, &_tps_eventrt_callback}, - {"event_mode", PARAM_INT, &_tps_eventrt_mode}, - {"contact_host", PARAM_STR, &_tps_contact_host}, - {"contact_mode", PARAM_INT, &_tps_contact_mode}, - {"cparam_name", PARAM_STR, &_tps_cparam_name}, - {"xavu_cfg", PARAM_STR, &_tps_xavu_cfg}, - {"xavu_field_a_contact", PARAM_STR, &_tps_xavu_field_acontact}, - {"xavu_field_b_contact", PARAM_STR, &_tps_xavu_field_bcontact}, - {"xavu_field_contact_host", PARAM_STR, &_tps_xavu_field_contact_host}, - {"rr_update", PARAM_INT, &_tps_rr_update}, - {"context", PARAM_STR, &_tps_context_param}, - {"methods_nocontact", PARAM_STR, &_tps_methods_nocontact_list}, - {"methods_noinitial", PARAM_STR, &_tps_methods_noinitial_list}, - - {0,0,0} -}; +static cmd_export_t cmds[] = { + {"tps_set_context", (cmd_function)w_tps_set_context, 1, fixup_spve_null, + fixup_free_spve_null, ANY_ROUTE}, + + {"bind_topos", (cmd_function)bind_topos, 0, 0, 0, 0}, + + {0, 0, 0, 0, 0, 0}}; + +static param_export_t params[] = {{"storage", PARAM_STR, &_tps_storage}, + {"db_url", PARAM_STR, &_tps_db_url}, + {"mask_callid", PARAM_INT, &_tps_param_mask_callid}, + {"sanity_checks", PARAM_INT, &_tps_sanity_checks}, + {"header_mode", PARAM_INT, &_tps_header_mode}, + {"branch_expire", PARAM_INT, &_tps_branch_expire}, + {"dialog_expire", PARAM_INT, &_tps_dialog_expire}, + {"clean_interval", PARAM_INT, &_tps_clean_interval}, + {"event_callback", PARAM_STR, &_tps_eventrt_callback}, + {"event_mode", PARAM_INT, &_tps_eventrt_mode}, + {"contact_host", PARAM_STR, &_tps_contact_host}, + {"contact_mode", PARAM_INT, &_tps_contact_mode}, + {"cparam_name", PARAM_STR, &_tps_cparam_name}, + {"xavu_cfg", PARAM_STR, &_tps_xavu_cfg}, + {"xavu_field_a_contact", PARAM_STR, &_tps_xavu_field_acontact}, + {"xavu_field_b_contact", PARAM_STR, &_tps_xavu_field_bcontact}, + {"xavu_field_contact_host", PARAM_STR, &_tps_xavu_field_contact_host}, + {"rr_update", PARAM_INT, &_tps_rr_update}, + {"context", PARAM_STR, &_tps_context_param}, + {"methods_nocontact", PARAM_STR, &_tps_methods_nocontact_list}, + {"methods_noinitial", PARAM_STR, &_tps_methods_noinitial_list}, + + {0, 0, 0}}; /** module exports */ -struct module_exports exports= { - "topos", /* module name */ - DEFAULT_DLFLAGS, /* dlopen flags */ - cmds, /* exported functions */ - params, /* exported parameters */ - 0, /* exported rpc functions */ - 0, /* exported pseudo-variables */ - 0, /* response handling function */ - mod_init, /* module initialization function */ - child_init, /* child initialization function */ - destroy /* destroy function */ +struct module_exports exports = { + "topos", /* module name */ + DEFAULT_DLFLAGS, /* dlopen flags */ + cmds, /* exported functions */ + params, /* exported parameters */ + 0, /* exported rpc functions */ + 0, /* exported pseudo-variables */ + 0, /* response handling function */ + mod_init, /* module initialization function */ + child_init, /* child initialization function */ + destroy /* destroy function */ }; /** @@ -203,85 +198,90 @@ struct module_exports exports= { */ static int mod_init(void) { - _tps_eventrt_outgoing = route_lookup(&event_rt, _tps_eventrt_outgoing_name.s); - if(_tps_eventrt_outgoing<0 - || event_rt.rlist[_tps_eventrt_outgoing]==NULL) { + _tps_eventrt_outgoing = + route_lookup(&event_rt, _tps_eventrt_outgoing_name.s); + if(_tps_eventrt_outgoing < 0 + || event_rt.rlist[_tps_eventrt_outgoing] == NULL) { _tps_eventrt_outgoing = -1; } _tps_eventrt_sending = route_lookup(&event_rt, _tps_eventrt_sending_name.s); - if(_tps_eventrt_sending<0 - || event_rt.rlist[_tps_eventrt_sending]==NULL) { + if(_tps_eventrt_sending < 0 + || event_rt.rlist[_tps_eventrt_sending] == NULL) { _tps_eventrt_sending = -1; } - _tps_eventrt_incoming = route_lookup(&event_rt, _tps_eventrt_incoming_name.s); - if(_tps_eventrt_incoming<0 - || event_rt.rlist[_tps_eventrt_incoming]==NULL) { + _tps_eventrt_incoming = + route_lookup(&event_rt, _tps_eventrt_incoming_name.s); + if(_tps_eventrt_incoming < 0 + || event_rt.rlist[_tps_eventrt_incoming] == NULL) { _tps_eventrt_incoming = -1; } - _tps_eventrt_receiving = route_lookup(&event_rt, _tps_eventrt_receiving_name.s); - if(_tps_eventrt_receiving<0 - || event_rt.rlist[_tps_eventrt_receiving]==NULL) { + _tps_eventrt_receiving = + route_lookup(&event_rt, _tps_eventrt_receiving_name.s); + if(_tps_eventrt_receiving < 0 + || event_rt.rlist[_tps_eventrt_receiving] == NULL) { _tps_eventrt_receiving = -1; } - if(faked_msg_init()<0) { + if(faked_msg_init() < 0) { LM_ERR("failed to init fmsg\n"); return -1; } - if(_tps_methods_nocontact_list.len>0) { - if(parse_methods(&_tps_methods_nocontact_list, &_tps_methods_nocontact)<0) { + if(_tps_methods_nocontact_list.len > 0) { + if(parse_methods(&_tps_methods_nocontact_list, &_tps_methods_nocontact) + < 0) { LM_ERR("failed to parse methods_nocontact parameter\n"); return -1; } } - if(_tps_methods_noinitial_list.len>0) { - if(parse_methods(&_tps_methods_noinitial_list, &_tps_methods_noinitial)<0) { + if(_tps_methods_noinitial_list.len > 0) { + if(parse_methods(&_tps_methods_noinitial_list, &_tps_methods_noinitial) + < 0) { LM_ERR("failed to parse methods_noinitial parameter\n"); return -1; } } - if(_tps_storage.len==2 && strncmp(_tps_storage.s, "db", 2)==0) { + if(_tps_storage.len == 2 && strncmp(_tps_storage.s, "db", 2) == 0) { /* Find a database module */ - if (db_bind_mod(&_tps_db_url, &_tpsdbf)) { + if(db_bind_mod(&_tps_db_url, &_tpsdbf)) { LM_ERR("unable to bind database module\n"); return -1; } - if (!DB_CAPABILITY(_tpsdbf, DB_CAP_ALL)) { + if(!DB_CAPABILITY(_tpsdbf, DB_CAP_ALL)) { LM_CRIT("database modules does not " - "provide all functions needed\n"); + "provide all functions needed\n"); return -1; } } else { - if(_tps_storage.len!=7 && strncmp(_tps_storage.s, "redis", 5)!=0) { - LM_ERR("unknown storage type: %.*s\n", - _tps_storage.len, _tps_storage.s); + if(_tps_storage.len != 7 && strncmp(_tps_storage.s, "redis", 5) != 0) { + LM_ERR("unknown storage type: %.*s\n", _tps_storage.len, + _tps_storage.s); return -1; } } - if(_tps_sanity_checks!=0) { - if(sanity_load_api(&scb)<0) { + if(_tps_sanity_checks != 0) { + if(sanity_load_api(&scb) < 0) { LM_ERR("cannot bind to sanity module\n"); goto error; } } - if(tps_storage_lock_set_init()<0) { + if(tps_storage_lock_set_init() < 0) { LM_ERR("failed to initialize locks set\n"); return -1; } - if(sruid_init(&_tps_sruid, '-', "tpsh", SRUID_INC)<0) + if(sruid_init(&_tps_sruid, '-', "tpsh", SRUID_INC) < 0) return -1; - if (_tps_contact_mode == 2 && (_tps_xavu_cfg.len <= 0 - || _tps_xavu_field_acontact.len <= 0 - || _tps_xavu_field_bcontact.len <= 0)) { + if(_tps_contact_mode == 2 + && (_tps_xavu_cfg.len <= 0 || _tps_xavu_field_acontact.len <= 0 + || _tps_xavu_field_bcontact.len <= 0)) { LM_ERR("contact_mode parameter is 2," - " but a_contact or b_contact xavu fields not defined\n"); + " but a_contact or b_contact xavu fields not defined\n"); return -1; } - + if(_tps_param_mask_callid == 1) { /* bind the topoh API */ if(topoh_load_api(&thb) != 0) { @@ -290,14 +290,14 @@ static int mod_init(void) } } - sr_event_register_cb(SREV_NET_DATA_IN, tps_msg_received); + sr_event_register_cb(SREV_NET_DATA_IN, tps_msg_received); sr_event_register_cb(SREV_NET_DATA_OUT, tps_msg_sent); #ifdef USE_TCP tcp_set_clone_rcvbuf(1); #endif - if(sr_wtimer_add(tps_storage_clean, NULL, _tps_clean_interval)<0) + if(sr_wtimer_add(tps_storage_clean, NULL, _tps_clean_interval) < 0) return -1; return 0; @@ -310,21 +310,20 @@ static int mod_init(void) */ static int child_init(int rank) { - if(sruid_init(&_tps_sruid, '-', "tpsh", SRUID_INC)<0) + if(sruid_init(&_tps_sruid, '-', "tpsh", SRUID_INC) < 0) return -1; - if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN) + if(rank == PROC_INIT || rank == PROC_MAIN || rank == PROC_TCP_MAIN) return 0; /* do nothing for the main process */ - if(_tps_storage.len==2 && strncmp(_tps_storage.s, "db", 2)==0) { + if(_tps_storage.len == 2 && strncmp(_tps_storage.s, "db", 2) == 0) { _tps_db_handle = _tpsdbf.init(&_tps_db_url); - if (!_tps_db_handle) { + if(!_tps_db_handle) { LM_ERR("unable to connect database\n"); return -1; } } return 0; - } /** @@ -332,8 +331,8 @@ static int child_init(int rank) */ static void destroy(void) { - if(_tps_storage.len==2 && strncmp(_tps_storage.s, "db", 2)==0) { - if (_tps_db_handle) { + if(_tps_storage.len == 2 && strncmp(_tps_storage.s, "db", 2) == 0) { + if(_tps_db_handle) { _tpsdbf.close(_tps_db_handle); _tps_db_handle = 0; } @@ -344,9 +343,9 @@ static void destroy(void) /** * */ -static int ki_tps_set_context(sip_msg_t* msg, str* ctx) +static int ki_tps_set_context(sip_msg_t *msg, str *ctx) { - if(ctx==NULL || ctx->len<=0) { + if(ctx == NULL || ctx->len <= 0) { if(_tps_context_value.s) { pkg_free(_tps_context_value.s); } @@ -355,7 +354,7 @@ static int ki_tps_set_context(sip_msg_t* msg, str* ctx) return 1; } - if(_tps_context_value.len>=ctx->len) { + if(_tps_context_value.len >= ctx->len) { memcpy(_tps_context_value.s, ctx->s, ctx->len); _tps_context_value.len = ctx->len; return 1; @@ -366,8 +365,8 @@ static int ki_tps_set_context(sip_msg_t* msg, str* ctx) } _tps_context_value.len = 0; - _tps_context_value.s = (char*)pkg_mallocxz(ctx->len + 1); - if(_tps_context_value.s==NULL) { + _tps_context_value.s = (char *)pkg_mallocxz(ctx->len + 1); + if(_tps_context_value.s == NULL) { PKG_MEM_ERROR; return -1; } @@ -381,11 +380,11 @@ static int ki_tps_set_context(sip_msg_t* msg, str* ctx) /** * */ -static int w_tps_set_context(sip_msg_t* msg, char* pctx, char* p2) +static int w_tps_set_context(sip_msg_t *msg, char *pctx, char *p2) { str sctx = STR_NULL; - if(fixup_get_svalue(msg, (gparam_t*)pctx, &sctx)<0) { + if(fixup_get_svalue(msg, (gparam_t *)pctx, &sctx) < 0) { LM_ERR("failed to get context parameter\n"); return -1; } @@ -398,17 +397,17 @@ static int w_tps_set_context(sip_msg_t* msg, char* pctx, char* p2) */ int tps_prepare_msg(sip_msg_t *msg) { - if (parse_msg(msg->buf, msg->len, msg)!=0) { + if(parse_msg(msg->buf, msg->len, msg) != 0) { LM_DBG("outbuf buffer parsing failed!"); return 1; } - if(msg->first_line.type==SIP_REQUEST) { + if(msg->first_line.type == SIP_REQUEST) { if(!IS_SIP(msg)) { LM_DBG("non sip request message\n"); return 1; } - } else if(msg->first_line.type==SIP_REPLY) { + } else if(msg->first_line.type == SIP_REPLY) { if(!IS_SIP_REPLY(msg)) { LM_DBG("non sip reply message\n"); return 1; @@ -418,39 +417,38 @@ int tps_prepare_msg(sip_msg_t *msg) return 1; } - if(parse_headers(msg, HDR_VIA2_F, 0)<0) { + if(parse_headers(msg, HDR_VIA2_F, 0) < 0) { LM_DBG("no via2 has been parsed\n"); } - if(parse_headers(msg, HDR_CSEQ_F, 0)!=0 || msg->cseq==NULL) { + if(parse_headers(msg, HDR_CSEQ_F, 0) != 0 || msg->cseq == NULL) { LM_ERR("cannot parse cseq header\n"); return -1; } - if (parse_headers(msg, HDR_EOH_F, 0)==-1) { - LM_DBG("parsing headers failed [[%.*s]]\n", - msg->len, msg->buf); + if(parse_headers(msg, HDR_EOH_F, 0) == -1) { + LM_DBG("parsing headers failed [[%.*s]]\n", msg->len, msg->buf); return 2; } - if(parse_from_header(msg)<0) { + if(parse_from_header(msg) < 0) { LM_ERR("cannot parse FROM header\n"); return 3; } - if(parse_to_header(msg)<0 || msg->to==NULL) { + if(parse_to_header(msg) < 0 || msg->to == NULL) { LM_ERR("cannot parse TO header\n"); return 3; } - if(get_to(msg)==NULL) { + if(get_to(msg) == NULL) { LM_ERR("cannot get TO header\n"); return 3; } - if(msg->via1==NULL || msg->callid==NULL) { - LM_ERR("mandatory headers missing - via1: %p callid: %p\n", - msg->via1, msg->callid); + if(msg->via1 == NULL || msg->callid == NULL) { + LM_ERR("mandatory headers missing - via1: %p callid: %p\n", msg->via1, + msg->callid); return 4; } @@ -470,10 +468,11 @@ int tps_msg_received(sr_event_param_t *evp) ki_tps_set_context(NULL, NULL); - obuf = (str*)evp->data; + obuf = (str *)evp->data; if(tps_execute_event_route(NULL, evp, TPS_EVENTRT_INCOMING, - _tps_eventrt_incoming, &_tps_eventrt_incoming_name)==1) { + _tps_eventrt_incoming, &_tps_eventrt_incoming_name) + == 1) { return 0; } @@ -482,7 +481,7 @@ int tps_msg_received(sr_event_param_t *evp) msg.len = obuf->len; ret = 0; - if(tps_prepare_msg(&msg)!=0) { + if(tps_prepare_msg(&msg) != 0) { goto done; } @@ -491,18 +490,19 @@ int tps_msg_received(sr_event_param_t *evp) } if(tps_execute_event_route(&msg, evp, TPS_EVENTRT_RECEIVING, - _tps_eventrt_receiving, &_tps_eventrt_receiving_name)==1) { + _tps_eventrt_receiving, &_tps_eventrt_receiving_name) + == 1) { goto done; } - if(msg.first_line.type==SIP_REQUEST) { - if(_tps_sanity_checks!=0) { - if(scb.check_defaults(&msg)<1) { + if(msg.first_line.type == SIP_REQUEST) { + if(_tps_sanity_checks != 0) { + if(scb.check_defaults(&msg) < 1) { LM_ERR("sanity checks failed\n"); goto done; } } - dialog = (get_to(&msg)->tag_value.len>0)?1:0; + dialog = (get_to(&msg)->tag_value.len > 0) ? 1 : 0; if(dialog) { /* dialog request */ tps_request_received(&msg, dialog); @@ -512,14 +512,14 @@ int tps_msg_received(sr_event_param_t *evp) tps_response_received(&msg); } - nbuf = tps_msg_update(&msg, (unsigned int*)&obuf->len); + nbuf = tps_msg_update(&msg, (unsigned int *)&obuf->len); - if(nbuf==NULL) { + if(nbuf == NULL) { LM_ERR("not enough pkg memory for new message\n"); ret = -1; goto done; } - if(obuf->len>=BUF_SIZE) { + if(obuf->len >= BUF_SIZE) { LM_ERR("new buffer overflow (%d)\n", obuf->len); ret = -1; goto done; @@ -528,7 +528,7 @@ int tps_msg_received(sr_event_param_t *evp) obuf->s[obuf->len] = '\0'; done: - if(nbuf!=NULL) + if(nbuf != NULL) pkg_free(nbuf); free_sip_msg(&msg); return ret; @@ -545,10 +545,11 @@ int tps_msg_sent(sr_event_param_t *evp) int local; str nbuf = STR_NULL; - obuf = (str*)evp->data; + obuf = (str *)evp->data; if(tps_execute_event_route(NULL, evp, TPS_EVENTRT_OUTGOING, - _tps_eventrt_outgoing, &_tps_eventrt_outgoing_name)==1) { + _tps_eventrt_outgoing, &_tps_eventrt_outgoing_name) + == 1) { return 0; } @@ -556,7 +557,7 @@ int tps_msg_sent(sr_event_param_t *evp) msg.buf = obuf->s; msg.len = obuf->len; - if(tps_prepare_msg(&msg)!=0) { + if(tps_prepare_msg(&msg) != 0) { goto done; } @@ -565,23 +566,24 @@ int tps_msg_sent(sr_event_param_t *evp) } if(tps_execute_event_route(&msg, evp, TPS_EVENTRT_SENDING, - _tps_eventrt_sending, &_tps_eventrt_sending_name)==1) { + _tps_eventrt_sending, &_tps_eventrt_sending_name) + == 1) { goto done; } - if(msg.first_line.type==SIP_REQUEST) { + if(msg.first_line.type == SIP_REQUEST) { - dialog = (get_to(&msg)->tag_value.len>0)?1:0; + dialog = (get_to(&msg)->tag_value.len > 0) ? 1 : 0; local = 0; - if(msg.via2==0) { + if(msg.via2 == 0) { local = 1; } - if(local==1 && dialog==0) { + if(local == 1 && dialog == 0) { if((get_cseq(&msg)->method_id) - & (METHOD_OPTIONS|METHOD_NOTIFY|METHOD_KDMQ)) { + & (METHOD_OPTIONS | METHOD_NOTIFY | METHOD_KDMQ)) { /* skip local out-of-dialog requests (e.g., keepalive, dmq) */ goto done; } @@ -590,15 +592,15 @@ int tps_msg_sent(sr_event_param_t *evp) tps_request_sent(&msg, dialog, local); } else { /* reply */ - if(msg.first_line.u.reply.statuscode==100) { + if(msg.first_line.u.reply.statuscode == 100) { /* nothing to do - it should be locally generated */ goto done; } tps_response_sent(&msg); } - nbuf.s = tps_msg_update(&msg, (unsigned int*)&nbuf.len); - if(nbuf.s!=NULL) { + nbuf.s = tps_msg_update(&msg, (unsigned int *)&nbuf.len); + if(nbuf.s != NULL) { LM_DBG("new outbound buffer generated\n"); pkg_free(obuf->s); obuf->s = nbuf.s; @@ -647,10 +649,10 @@ static int tps_execute_event_route(sip_msg_t *msg, sr_event_param_t *evp, p_onsend_bak = p_onsend; - if(evidx<0) { - if(_tps_eventrt_callback.s!=NULL || _tps_eventrt_callback.len>0) { + if(evidx < 0) { + if(_tps_eventrt_callback.s != NULL || _tps_eventrt_callback.len > 0) { keng = sr_kemi_eng_get(); - if(keng==NULL) { + if(keng == NULL) { LM_DBG("event callback (%s) set, but no cfg engine\n", _tps_eventrt_callback.s); goto done; @@ -658,7 +660,7 @@ static int tps_execute_event_route(sip_msg_t *msg, sr_event_param_t *evp, } } - if(evidx<0 && keng==NULL) { + if(evidx < 0 && keng == NULL) { return 0; } @@ -670,7 +672,7 @@ static int tps_execute_event_route(sip_msg_t *msg, sr_event_param_t *evp, onsnd_info.to = &evp->dst->to; onsnd_info.send_sock = evp->dst->send_sock; } - if(msg!=NULL) { + if(msg != NULL) { onsnd_info.buf = msg->buf; onsnd_info.len = msg->len; onsnd_info.msg = msg; @@ -684,27 +686,28 @@ static int tps_execute_event_route(sip_msg_t *msg, sr_event_param_t *evp, rtb = get_route_type(); set_route_type(REQUEST_ROUTE); init_run_actions_ctx(&ctx); - if(evidx>=0) { - run_top_route(event_rt.rlist[evidx], (msg)?msg:fmsg, &ctx); + if(evidx >= 0) { + run_top_route(event_rt.rlist[evidx], (msg) ? msg : fmsg, &ctx); } else { - if(keng!=NULL) { - if(sr_kemi_ctx_route(keng, &ctx, (msg)?msg:fmsg, EVENT_ROUTE, - &_tps_eventrt_callback, evname)<0) { + if(keng != NULL) { + if(sr_kemi_ctx_route(keng, &ctx, (msg) ? msg : fmsg, EVENT_ROUTE, + &_tps_eventrt_callback, evname) + < 0) { LM_ERR("error running event route kemi callback\n"); - p_onsend=p_onsend_bak; + p_onsend = p_onsend_bak; return -1; } } } set_route_type(rtb); - if(ctx.run_flags&DROP_R_F) { + if(ctx.run_flags & DROP_R_F) { LM_DBG("exit due to 'drop' in event route\n"); - p_onsend=p_onsend_bak; + p_onsend = p_onsend_bak; return 1; } done: - p_onsend=p_onsend_bak; + p_onsend = p_onsend_bak; return 0; } @@ -713,7 +716,7 @@ static int tps_execute_event_route(sip_msg_t *msg, sr_event_param_t *evp, */ int bind_topos(topos_api_t *api) { - if (!api) { + if(!api) { ERR("Invalid parameter value\n"); return -1; } @@ -756,20 +759,21 @@ int mod_register(char *path, int *dlflags, void *p1, void *p2) int tps_mask_callid(sip_msg_t *msg) { - struct lump* l; + struct lump *l; str out; str in; - if(_tps_param_mask_callid==0) { + if(_tps_param_mask_callid == 0) { return 0; } - if(msg->callid==NULL) { + if(msg->callid == NULL) { LM_ERR("cannot get Call-Id header\n"); return -1; } - LM_DBG("incoming call-id: [%.*s]\n", msg->callid->body.len, msg->callid->body.s); - in=msg->callid->body; + LM_DBG("incoming call-id: [%.*s]\n", msg->callid->body.len, + msg->callid->body.s); + in = msg->callid->body; if(thb.mask_callid(&in, &out) != 0) { LM_ERR("cannot encode callid\n"); @@ -777,18 +781,18 @@ int tps_mask_callid(sip_msg_t *msg) } LM_DBG("updated (masked) call-id: [%.*s]\n", out.len, out.s); - if(out.s==NULL) { + if(out.s == NULL) { LM_ERR("cannot encode callid\n"); return -1; } - l=del_lump(msg, msg->callid->body.s-msg->buf, msg->callid->body.len, 0); - if (l==0) { + l = del_lump(msg, msg->callid->body.s - msg->buf, msg->callid->body.len, 0); + if(l == 0) { LM_ERR("failed deleting callid\n"); pkg_free(out.s); return -1; } - if (insert_new_lump_after(l, out.s, out.len, 0)==0) { + if(insert_new_lump_after(l, out.s, out.len, 0) == 0) { LM_ERR("could not insert new lump\n"); pkg_free(out.s); return -1; @@ -802,23 +806,24 @@ int tps_mask_callid(sip_msg_t *msg) */ int tps_unmask_callid(sip_msg_t *msg) { - struct lump* l; + struct lump *l; str out; str in; int umask_ret; - if(_tps_param_mask_callid==0) { + if(_tps_param_mask_callid == 0) { return 0; } - if(msg->callid==NULL) { + if(msg->callid == NULL) { LM_ERR("cannot get Call-Id header\n"); return -1; } - LM_DBG("incoming call-id: [%.*s]\n", msg->callid->body.len, msg->callid->body.s); - in=msg->callid->body; - umask_ret=thb.unmask_callid(&in, &out); + LM_DBG("incoming call-id: [%.*s]\n", msg->callid->body.len, + msg->callid->body.s); + in = msg->callid->body; + umask_ret = thb.unmask_callid(&in, &out); if(umask_ret == 1) { LM_DBG("unmask not required\n"); return 0; @@ -827,18 +832,18 @@ int tps_unmask_callid(sip_msg_t *msg) return -1; } LM_DBG("updated (unmasked) call-id: [%.*s]\n", out.len, out.s); - if(out.s==NULL) { + if(out.s == NULL) { LM_ERR("cannot decode callid\n"); return -1; } - l=del_lump(msg, msg->callid->body.s-msg->buf, msg->callid->body.len, 0); - if (l==0) { + l = del_lump(msg, msg->callid->body.s - msg->buf, msg->callid->body.len, 0); + if(l == 0) { LM_ERR("failed deleting callid\n"); pkg_free(out.s); return -1; } - if (insert_new_lump_after(l, out.s, out.len, 0)==0) { + if(insert_new_lump_after(l, out.s, out.len, 0) == 0) { LM_ERR("could not insert new lump\n"); pkg_free(out.s); return -1; diff --git a/src/modules/topos/tps_msg.c b/src/modules/topos/tps_msg.c index 5e6a5288b8f..c2dd3e70b7d 100644 --- a/src/modules/topos/tps_msg.c +++ b/src/modules/topos/tps_msg.c @@ -60,7 +60,7 @@ extern str _tps_context_value; str _sr_hname_xbranch = str_init("P-SR-XBranch"); str _sr_hname_xuuid = str_init("P-SR-XUID"); -unsigned int _tps_methods_nocontact = METHOD_CANCEL|METHOD_BYE|METHOD_PRACK; +unsigned int _tps_methods_nocontact = METHOD_CANCEL | METHOD_BYE | METHOD_PRACK; unsigned int _tps_methods_noinitial = 0; /** @@ -68,12 +68,12 @@ unsigned int _tps_methods_noinitial = 0; */ int tps_skip_rw(char *s, int len) { - while(len>0) - { - if(s[len-1]==' ' || s[len-1]=='\t' || s[len-1]=='\n' || s[len-1]=='\r' - || s[len-1]==',') + while(len > 0) { + if(s[len - 1] == ' ' || s[len - 1] == '\t' || s[len - 1] == '\n' + || s[len - 1] == '\r' || s[len - 1] == ',') len--; - else return len; + else + return len; } return 0; } @@ -84,10 +84,9 @@ int tps_skip_rw(char *s, int len) struct via_param *tps_get_via_param(struct via_body *via, str *name) { struct via_param *p; - for(p=via->param_lst; p; p=p->next) - { - if(p->name.len==name->len - && strncasecmp(p->name.s, name->s, name->len)==0) + for(p = via->param_lst; p; p = p->next) { + if(p->name.len == name->len + && strncasecmp(p->name.s, name->s, name->len) == 0) return p; } return NULL; @@ -98,25 +97,23 @@ struct via_param *tps_get_via_param(struct via_body *via, str *name) */ int tps_get_param_value(str *in, str *name, str *value) { - param_t* params = NULL; - param_t* p = NULL; + param_t *params = NULL; + param_t *p = NULL; param_hooks_t phooks; - if (parse_params(in, CLASS_ANY, &phooks, ¶ms)<0) + if(parse_params(in, CLASS_ANY, &phooks, ¶ms) < 0) return -1; - for (p = params; p; p=p->next) - { - if (p->name.len==name->len - && strncasecmp(p->name.s, name->s, name->len)==0) - { + for(p = params; p; p = p->next) { + if(p->name.len == name->len + && strncasecmp(p->name.s, name->s, name->len) == 0) { *value = p->body; free_params(params); return 0; } } - if(params) free_params(params); + if(params) + free_params(params); return 1; - } /** @@ -125,17 +122,17 @@ int tps_get_param_value(str *in, str *name, str *value) int tps_remove_headers(sip_msg_t *msg, uint32_t hdr) { struct hdr_field *hf; - struct lump* l; + struct lump *l; - if(parse_headers(msg, HDR_EOH_F, 0)<0) { + if(parse_headers(msg, HDR_EOH_F, 0) < 0) { LM_ERR("failed to parse headers\n"); return -1; } - for (hf=msg->headers; hf; hf=hf->next) { - if (hdr!=hf->type) + for(hf = msg->headers; hf; hf = hf->next) { + if(hdr != hf->type) continue; - l=del_lump(msg, hf->name.s-msg->buf, hf->len, 0); - if (l==0) { + l = del_lump(msg, hf->name.s - msg->buf, hf->len, 0); + if(l == 0) { LM_ERR("failed to remove the header\n"); return -1; } @@ -148,13 +145,13 @@ int tps_remove_headers(sip_msg_t *msg, uint32_t hdr) */ int tps_add_headers(sip_msg_t *msg, str *hname, str *hbody, int hpos) { - struct lump* anchor; + struct lump *anchor; str hs; - if(hname==NULL || hname->len<=0 || hbody==NULL || hbody->len<=0) + if(hname == NULL || hname->len <= 0 || hbody == NULL || hbody->len <= 0) return 0; - if(parse_headers(msg, HDR_EOH_F, 0)<0) { + if(parse_headers(msg, HDR_EOH_F, 0) < 0) { LM_ERR("failed to parse headers\n"); return -1; } @@ -173,26 +170,26 @@ int tps_add_headers(sip_msg_t *msg, str *hname, str *hbody, int hpos) } hs.len = hname->len + 2 + hbody->len; - hs.s = (char*)pkg_malloc(hs.len + 3); - if (hs.s==NULL) { + hs.s = (char *)pkg_malloc(hs.len + 3); + if(hs.s == NULL) { PKG_MEM_ERROR_FMT("(%.*s - %d)\n", hname->len, hname->s, hs.len); return -1; } memcpy(hs.s, hname->s, hname->len); hs.s[hname->len] = ':'; - hs.s[hname->len+1] = ' '; + hs.s[hname->len + 1] = ' '; memcpy(hs.s + hname->len + 2, hbody->s, hbody->len); /* add end of header if not present */ - if(hs.s[hname->len + 2 + hbody->len - 1]!='\n') { + if(hs.s[hname->len + 2 + hbody->len - 1] != '\n') { hs.s[hname->len + 2 + hbody->len] = '\r'; - hs.s[hname->len + 2 + hbody->len+1] = '\n'; + hs.s[hname->len + 2 + hbody->len + 1] = '\n'; hs.len += 2; } LM_DBG("adding to headers(%d) - [%.*s]\n", hpos, hs.len, hs.s); - if (insert_new_lump_before(anchor, hs.s, hs.len, 0) == 0) { + if(insert_new_lump_before(anchor, hs.s, hs.len, 0) == 0) { LM_ERR("can't insert lump\n"); pkg_free(hs.s); return -1; @@ -209,7 +206,7 @@ int tps_get_uri_param_value(str *uri, str *name, str *value) struct sip_uri puri; memset(value, 0, sizeof(str)); - if(parse_uri(uri->s, uri->len, &puri)<0) + if(parse_uri(uri->s, uri->len, &puri) < 0) return -1; return tps_get_param_value(&puri.params, name, value); } @@ -225,22 +222,20 @@ int tps_get_uri_type(str *uri, int *mode, str *value) memset(value, 0, sizeof(str)); *mode = 0; - if(parse_uri(uri->s, uri->len, &puri)<0) + if(parse_uri(uri->s, uri->len, &puri) < 0) return -1; LM_DBG("PARAMS [%.*s]\n", puri.params.len, puri.params.s); - if(check_self(&puri.host, puri.port_no, 0)==1) - { + if(check_self(&puri.host, puri.port_no, 0) == 1) { /* myself -- matched on all protos */ ret = tps_get_param_value(&puri.params, &r2, value); - if(ret<0) + if(ret < 0) return -1; - if(ret==1) /* not found */ + if(ret == 1) /* not found */ return 0; /* skip */ - LM_DBG("VALUE [%.*s]\n", - value->len, value->s); - if(value->len==2 && strncasecmp(value->s, "on", 2)==0) + LM_DBG("VALUE [%.*s]\n", value->len, value->s); + if(value->len == 2 && strncasecmp(value->s, "on", 2) == 0) *mode = 1; memset(value, 0, sizeof(str)); return 0; /* skip */ @@ -252,14 +247,14 @@ int tps_get_uri_type(str *uri, int *mode, str *value) /** * */ -char* tps_msg_update(sip_msg_t *msg, unsigned int *olen) +char *tps_msg_update(sip_msg_t *msg, unsigned int *olen) { struct dest_info dst; init_dest_info(&dst); dst.proto = PROTO_UDP; - return build_req_buf_from_sip_req(msg, - olen, &dst, BUILD_NO_LOCAL_VIA|BUILD_NO_VIA1_UPDATE); + return build_req_buf_from_sip_req( + msg, olen, &dst, BUILD_NO_LOCAL_VIA | BUILD_NO_VIA1_UPDATE); } /** @@ -267,16 +262,16 @@ char* tps_msg_update(sip_msg_t *msg, unsigned int *olen) */ int tps_skip_msg(sip_msg_t *msg) { - if (msg->cseq==NULL || get_cseq(msg)==NULL) { + if(msg->cseq == NULL || get_cseq(msg) == NULL) { LM_WARN("Invalid/Unparsed CSeq in message. Skipping."); return 1; } - if((get_cseq(msg)->method_id)&(METHOD_REGISTER|METHOD_PUBLISH)) + if((get_cseq(msg)->method_id) & (METHOD_REGISTER | METHOD_PUBLISH)) return 1; - if(_tps_methods_noinitial!=0 && msg->first_line.type==SIP_REQUEST - && get_to(msg)->tag_value.len<=0) { + if(_tps_methods_noinitial != 0 && msg->first_line.type == SIP_REQUEST + && get_to(msg)->tag_value.len <= 0) { if((get_cseq(msg)->method_id) & _tps_methods_noinitial) { return 1; } @@ -288,21 +283,21 @@ int tps_skip_msg(sip_msg_t *msg) /** * */ -int tps_dlg_detect_direction(sip_msg_t *msg, tps_data_t *ptsd, - uint32_t *direction) +int tps_dlg_detect_direction( + sip_msg_t *msg, tps_data_t *ptsd, uint32_t *direction) { str ftag = {0, 0}; /* detect direction - get from-tag */ - if(parse_from_header(msg)<0 || msg->from==NULL) { + if(parse_from_header(msg) < 0 || msg->from == NULL) { LM_ERR("failed getting 'from' header!\n"); goto error; } ftag = get_from(msg)->tag_value; - if(ptsd->a_tag.len!=ftag.len) { + if(ptsd->a_tag.len != ftag.len) { *direction = TPS_DIR_UPSTREAM; } else { - if(memcmp(ptsd->a_tag.s, ftag.s, ftag.len)==0) { + if(memcmp(ptsd->a_tag.s, ftag.s, ftag.len) == 0) { *direction = TPS_DIR_DOWNSTREAM; } else { *direction = TPS_DIR_UPSTREAM; @@ -324,40 +319,40 @@ int tps_dlg_message_update(sip_msg_t *msg, tps_data_t *ptsd, int ctmode) #define TPS_TUUID_MIN_LEN 10 - if(parse_sip_msg_uri(msg)<0) { + if(parse_sip_msg_uri(msg) < 0) { LM_ERR("failed to parse r-uri\n"); return -1; } - if (ctmode == 1 || ctmode == 2) { - if(msg->parsed_uri.sip_params.lenparsed_uri.sip_params.len < TPS_TUUID_MIN_LEN) { LM_DBG("not an expected param format\n"); return 1; } /* find the r-uri parameter */ - ret = tps_get_param_value(&msg->parsed_uri.params, - &_tps_cparam_name, &tuuid); - if (ret < 0) { + ret = tps_get_param_value( + &msg->parsed_uri.params, &_tps_cparam_name, &tuuid); + if(ret < 0) { LM_ERR("failed to parse param\n"); return -1; } - if (ret == 1) { + if(ret == 1) { LM_DBG("prefix para not found\n"); return 1; } } else { - if(msg->parsed_uri.user.lenparsed_uri.user.len < TPS_TUUID_MIN_LEN) { LM_DBG("not an expected user format\n"); return 1; } tuuid = msg->parsed_uri.user; } - if(memcmp(tuuid.s, "atpsh-", 6)==0) { + if(memcmp(tuuid.s, "atpsh-", 6) == 0) { ptsd->a_uuid = tuuid; return 0; } - if(memcmp(tuuid.s, "btpsh-", 6)==0) { + if(memcmp(tuuid.s, "btpsh-", 6) == 0) { ptsd->a_uuid = tuuid; ptsd->b_uuid = tuuid; return 0; @@ -382,42 +377,44 @@ int tps_pack_message(sip_msg_t *msg, tps_data_t *ptsd) int isreq; int rr_update = _tps_rr_update; - if(ptsd->cp==NULL) { + if(ptsd->cp == NULL) { ptsd->cp = ptsd->cbuf; } if(_tps_rr_update) { - if((msg->first_line.type==SIP_REQUEST) && !(get_to(msg)->tag_value.len>0)) { + if((msg->first_line.type == SIP_REQUEST) + && !(get_to(msg)->tag_value.len > 0)) { rr_update = 0; } } i = 0; - for(hdr=msg->h_via1; hdr; hdr=next_sibling_hdr(hdr)) { - for(via=(struct via_body*)hdr->parsed; via; via=via->next) { + for(hdr = msg->h_via1; hdr; hdr = next_sibling_hdr(hdr)) { + for(via = (struct via_body *)hdr->parsed; via; via = via->next) { i++; vlen = tps_skip_rw(via->name.s, via->bsize); if(ptsd->cp + vlen + 2 >= ptsd->cbuf + TPS_DATA_SIZE) { LM_ERR("no more space to pack via headers\n"); return -1; } - if(i>1) { + if(i > 1) { *ptsd->cp = ','; ptsd->cp++; - if(i>2) { + if(i > 2) { ptsd->x_via2.len++; } } memcpy(ptsd->cp, via->name.s, vlen); - if(i==1) { + if(i == 1) { ptsd->x_via1.s = ptsd->cp; ptsd->x_via1.len = vlen; - if(via->branch!=NULL) { - ptsd->x_vbranch1.s = ptsd->x_via1.s + (via->branch->value.s - via->name.s); + if(via->branch != NULL) { + ptsd->x_vbranch1.s = ptsd->x_via1.s + + (via->branch->value.s - via->name.s); ptsd->x_vbranch1.len = via->branch->value.len; } } else { - if(i==2) { + if(i == 2) { ptsd->x_via2.s = ptsd->cp; } ptsd->x_via2.len += vlen; @@ -426,35 +423,37 @@ int tps_pack_message(sip_msg_t *msg, tps_data_t *ptsd) } } LM_DBG("compacted headers - x_via1: [%.*s](%d) - x_via2: [%.*s](%d)" - " - x_vbranch1: [%.*s](%d)\n", + " - x_vbranch1: [%.*s](%d)\n", ptsd->x_via1.len, ZSW(ptsd->x_via1.s), ptsd->x_via1.len, ptsd->x_via2.len, ZSW(ptsd->x_via2.s), ptsd->x_via2.len, - ptsd->x_vbranch1.len, ZSW(ptsd->x_vbranch1.s), ptsd->x_vbranch1.len); + ptsd->x_vbranch1.len, ZSW(ptsd->x_vbranch1.s), + ptsd->x_vbranch1.len); ptsd->a_rr.len = 0; ptsd->s_rr.len = 0; i = 0; r2 = 0; - isreq = (msg->first_line.type==SIP_REQUEST)?1:0; - for(hdr=msg->record_route; hdr; hdr=next_sibling_hdr(hdr)) { - if (parse_rr(hdr) < 0) { + isreq = (msg->first_line.type == SIP_REQUEST) ? 1 : 0; + for(hdr = msg->record_route; hdr; hdr = next_sibling_hdr(hdr)) { + if(parse_rr(hdr) < 0) { LM_ERR("failed to parse RR\n"); return -1; } - for(rr =(rr_t*)hdr->parsed; rr; rr=rr->next) { + for(rr = (rr_t *)hdr->parsed; rr; rr = rr->next) { i++; - if(ptsd->cp + rr->nameaddr.uri.len + 4 >= ptsd->cbuf + TPS_DATA_SIZE) { + if(ptsd->cp + rr->nameaddr.uri.len + 4 + >= ptsd->cbuf + TPS_DATA_SIZE) { LM_ERR("no more space to pack rr headers\n"); return -1; } - if(isreq==1 || rr_update) { + if(isreq == 1 || rr_update) { /* sip request - get a+s-side record route */ - if(i>1) { - if(i==2 &&r2==0) { + if(i > 1) { + if(i == 2 && r2 == 0) { ptsd->s_rr.len = ptsd->a_rr.len; } - if(i==3 &&r2==1) { + if(i == 3 && r2 == 1) { ptsd->s_rr.len = ptsd->a_rr.len; } *ptsd->cp = ','; @@ -464,19 +463,19 @@ int tps_pack_message(sip_msg_t *msg, tps_data_t *ptsd) ptsd->b_rr.len++; } } - if(i==1 && rr_update) { + if(i == 1 && rr_update) { ptsd->b_rr.s = ptsd->cp; } *ptsd->cp = '<'; - if(i==1) { + if(i == 1) { ptsd->a_rr.s = ptsd->cp; ptsd->s_rr.s = ptsd->cp; } - if(i==2 && r2==0) { + if(i == 2 && r2 == 0) { ptsd->a_rr.s = ptsd->cp; ptsd->a_rr.len = 0; } - if(i==3 && r2==1) { + if(i == 3 && r2 == 1) { ptsd->a_rr.s = ptsd->cp; ptsd->a_rr.len = 0; } @@ -488,11 +487,12 @@ int tps_pack_message(sip_msg_t *msg, tps_data_t *ptsd) } memcpy(ptsd->cp, rr->nameaddr.uri.s, rr->nameaddr.uri.len); - if(i==1) { + if(i == 1) { ptsd->bs_contact.s = ptsd->cp; ptsd->bs_contact.len = rr->nameaddr.uri.len; if(_strnstr(ptsd->bs_contact.s, ";r2=on", - ptsd->bs_contact.len)==0) { + ptsd->bs_contact.len) + == 0) { LM_DBG("single record routing by proxy\n"); ptsd->as_contact.s = ptsd->cp; ptsd->as_contact.len = rr->nameaddr.uri.len; @@ -500,7 +500,7 @@ int tps_pack_message(sip_msg_t *msg, tps_data_t *ptsd) r2 = 1; } } else { - if(i==2 && ptsd->as_contact.len==0) { + if(i == 2 && ptsd->as_contact.len == 0) { LM_DBG("double record routing by proxy\n"); ptsd->as_contact.s = ptsd->cp; ptsd->as_contact.len = rr->nameaddr.uri.len; @@ -517,10 +517,10 @@ int tps_pack_message(sip_msg_t *msg, tps_data_t *ptsd) } } else { /* sip response - get b-side record route */ - if(i==1) { + if(i == 1) { ptsd->b_rr.s = ptsd->cp; } - if(i>1) { + if(i > 1) { *ptsd->cp = ','; ptsd->cp++; ptsd->b_rr.len++; @@ -537,26 +537,28 @@ int tps_pack_message(sip_msg_t *msg, tps_data_t *ptsd) } } } - if(isreq==1) { - if(i==1) { + if(isreq == 1) { + if(i == 1) { ptsd->s_rr.len = ptsd->a_rr.len; ptsd->a_rr.len = 0; } - if(i==2 && r2==1) { + if(i == 2 && r2 == 1) { ptsd->s_rr.len = ptsd->a_rr.len; ptsd->a_rr.len = 0; } } LM_DBG("compacted headers - a_rr: [%.*s](%d) - b_rr: [%.*s](%d)" - " - s_rr: [%.*s](%d)\n", - ptsd->a_rr.len, ZSW(ptsd->a_rr.s), ptsd->a_rr.len, - ptsd->b_rr.len, ZSW(ptsd->b_rr.s), ptsd->b_rr.len, - ptsd->s_rr.len, ZSW(ptsd->s_rr.s), ptsd->s_rr.len); - LM_DBG("compacted headers - as_contact: [%.*s](%d) - bs_contact: [%.*s](%d)\n", + " - s_rr: [%.*s](%d)\n", + ptsd->a_rr.len, ZSW(ptsd->a_rr.s), ptsd->a_rr.len, ptsd->b_rr.len, + ZSW(ptsd->b_rr.s), ptsd->b_rr.len, ptsd->s_rr.len, + ZSW(ptsd->s_rr.s), ptsd->s_rr.len); + LM_DBG("compacted headers - as_contact: [%.*s](%d) - bs_contact: " + "[%.*s](%d)\n", ptsd->as_contact.len, ZSW(ptsd->as_contact.s), ptsd->as_contact.len, - ptsd->bs_contact.len, ZSW(ptsd->bs_contact.s), ptsd->bs_contact.len); + ptsd->bs_contact.len, ZSW(ptsd->bs_contact.s), + ptsd->bs_contact.len); ptsd->x_rr = ptsd->a_rr; - if(isreq==0) { + if(isreq == 0) { if(msg->first_line.u.reply.statuscode >= 180 && msg->first_line.u.reply.statuscode < 199) { /* provisional replies that create early dialogs @@ -565,9 +567,9 @@ int tps_pack_message(sip_msg_t *msg, tps_data_t *ptsd) } } ptsd->s_method_id = get_cseq(msg)->method_id; - if(_tps_context_value.len>0) { + if(_tps_context_value.len > 0) { ptsd->x_context = _tps_context_value; - } else if(_tps_context_param.len>0) { + } else if(_tps_context_param.len > 0) { ptsd->x_context = _tps_context_param; } return 0; @@ -581,7 +583,7 @@ int tps_reinsert_via(sip_msg_t *msg, tps_data_t *ptsd, str *hbody) { str hname = str_init("Via"); - if(tps_add_headers(msg, &hname, hbody, 1)<0) { + if(tps_add_headers(msg, &hname, hbody, 1) < 0) { return -1; } @@ -595,11 +597,11 @@ int tps_reinsert_contact(sip_msg_t *msg, tps_data_t *ptsd, str *hbody) { str hname = str_init("Contact"); - if (get_cseq(msg)->method_id & _tps_methods_nocontact) { + if(get_cseq(msg)->method_id & _tps_methods_nocontact) { return 0; } - if(tps_add_headers(msg, &hname, hbody, 0)<0) { + if(tps_add_headers(msg, &hname, hbody, 0) < 0) { return -1; } @@ -612,17 +614,14 @@ int tps_reinsert_contact(sip_msg_t *msg, tps_data_t *ptsd, str *hbody) int tps_remove_name_headers(sip_msg_t *msg, str *hname) { hdr_field_t *hf; - struct lump* l; - for (hf=msg->headers; hf; hf=hf->next) - { - if (hf->name.len==hname->len - && strncasecmp(hf->name.s, hname->s, - hname->len)==0) - { - l=del_lump(msg, hf->name.s-msg->buf, hf->len, 0); - if (l==0) { - LM_ERR("unable to delete header [%.*s]\n", - hname->len, hname->s); + struct lump *l; + for(hf = msg->headers; hf; hf = hf->next) { + if(hf->name.len == hname->len + && strncasecmp(hf->name.s, hname->s, hname->len) == 0) { + l = del_lump(msg, hf->name.s - msg->buf, hf->len, 0); + if(l == 0) { + LM_ERR("unable to delete header [%.*s]\n", hname->len, + hname->s); return -1; } return 0; @@ -634,54 +633,58 @@ int tps_remove_name_headers(sip_msg_t *msg, str *hname) /** * */ -int tps_reappend_separate_header_values(sip_msg_t *msg, tps_data_t *ptsd, str *hbody, str *hname) +int tps_reappend_separate_header_values( + sip_msg_t *msg, tps_data_t *ptsd, str *hbody, str *hname) { - int i; - str sb; - char *p = NULL; - - if(hbody==NULL || hbody->s==NULL || hbody->len<=0 || hbody->s[0]=='\0') - return 0; - - sb.len = 1; - p = hbody->s; - for(i=0; ilen-1; i++) { - if(hbody->s[i]==',') { - if(sb.len>0) { - sb.s = p; - if(sb.s[sb.len-1]==',') sb.len--; - if(tps_add_headers(msg, hname, &sb, 0)<0) { - return -1; - } - } - sb.len = 0; - p = hbody->s + i + 1; - } - sb.len++; - } - - - if(sb.len>0) { - sb.s = p; - if(sb.s[sb.len-1]==',') sb.len--; - if(tps_add_headers(msg, hname, &sb, 0)<0) { - return -1; - } - } - - - return 0; + int i; + str sb; + char *p = NULL; + + if(hbody == NULL || hbody->s == NULL || hbody->len <= 0 + || hbody->s[0] == '\0') + return 0; + + sb.len = 1; + p = hbody->s; + for(i = 0; i < hbody->len - 1; i++) { + if(hbody->s[i] == ',') { + if(sb.len > 0) { + sb.s = p; + if(sb.s[sb.len - 1] == ',') + sb.len--; + if(tps_add_headers(msg, hname, &sb, 0) < 0) { + return -1; + } + } + sb.len = 0; + p = hbody->s + i + 1; + } + sb.len++; + } + + + if(sb.len > 0) { + sb.s = p; + if(sb.s[sb.len - 1] == ',') + sb.len--; + if(tps_add_headers(msg, hname, &sb, 0) < 0) { + return -1; + } + } + + + return 0; } int tps_reappend_via(sip_msg_t *msg, tps_data_t *ptsd, str *hbody) { str hname = str_init("Via"); - if (TPS_SPLIT_VIA & _tps_header_mode) - return tps_reappend_separate_header_values(msg, ptsd, hbody,&hname); + if(TPS_SPLIT_VIA & _tps_header_mode) + return tps_reappend_separate_header_values(msg, ptsd, hbody, &hname); - if(tps_add_headers(msg, &hname, hbody, 0)<0) { + if(tps_add_headers(msg, &hname, hbody, 0) < 0) { return -1; } @@ -693,9 +696,9 @@ int tps_reappend_via(sip_msg_t *msg, tps_data_t *ptsd, str *hbody) */ int tps_append_xbranch(sip_msg_t *msg, str *hbody) { - if(tps_add_headers(msg, &_sr_hname_xbranch, hbody, 0)<0) { - LM_ERR("failed to add xbranch header [%.*s]/%d\n", - hbody->len, hbody->s, hbody->len); + if(tps_add_headers(msg, &_sr_hname_xbranch, hbody, 0) < 0) { + LM_ERR("failed to add xbranch header [%.*s]/%d\n", hbody->len, hbody->s, + hbody->len); return -1; } @@ -716,19 +719,18 @@ int tps_remove_xbranch(sip_msg_t *msg) int tps_get_xbranch(sip_msg_t *msg, str *hbody) { hdr_field_t *hf; - if(parse_headers(msg, HDR_EOH_F, 0)<0) { + if(parse_headers(msg, HDR_EOH_F, 0) < 0) { return -1; } - for (hf=msg->headers; hf; hf=hf->next) - { - if(_sr_hname_xbranch.len==hf->name.len - && strncasecmp(_sr_hname_xbranch.s, hf->name.s, - hf->name.len)==0) { + for(hf = msg->headers; hf; hf = hf->next) { + if(_sr_hname_xbranch.len == hf->name.len + && strncasecmp(_sr_hname_xbranch.s, hf->name.s, hf->name.len) + == 0) { break; } } - if(hf!=NULL) { + if(hf != NULL) { *hbody = hf->body; return 0; } @@ -741,9 +743,9 @@ int tps_get_xbranch(sip_msg_t *msg, str *hbody) */ int tps_append_xuuid(sip_msg_t *msg, str *hbody) { - if(tps_add_headers(msg, &_sr_hname_xuuid, hbody, 0)<0) { - LM_ERR("failed to add xuuid header [%.*s]/%d\n", - hbody->len, hbody->s, hbody->len); + if(tps_add_headers(msg, &_sr_hname_xuuid, hbody, 0) < 0) { + LM_ERR("failed to add xuuid header [%.*s]/%d\n", hbody->len, hbody->s, + hbody->len); return -1; } @@ -764,19 +766,18 @@ int tps_remove_xuuid(sip_msg_t *msg) int tps_get_xuuid(sip_msg_t *msg, str *hbody) { hdr_field_t *hf; - if(parse_headers(msg, HDR_EOH_F, 0)<0) { + if(parse_headers(msg, HDR_EOH_F, 0) < 0) { return -1; } - for (hf=msg->headers; hf; hf=hf->next) - { - if(_sr_hname_xuuid.len==hf->name.len - && strncasecmp(_sr_hname_xuuid.s, hf->name.s, - hf->name.len)==0) { + for(hf = msg->headers; hf; hf = hf->next) { + if(_sr_hname_xuuid.len == hf->name.len + && strncasecmp(_sr_hname_xuuid.s, hf->name.s, hf->name.len) + == 0) { break; } } - if(hf!=NULL) { + if(hf != NULL) { *hbody = hf->body; return 0; } @@ -790,10 +791,10 @@ int tps_reappend_rr(sip_msg_t *msg, tps_data_t *ptsd, str *hbody) { str hname = str_init("Record-Route"); - if (TPS_SPLIT_RECORD_ROUTE & _tps_header_mode) - return tps_reappend_separate_header_values(msg, ptsd, hbody,&hname); + if(TPS_SPLIT_RECORD_ROUTE & _tps_header_mode) + return tps_reappend_separate_header_values(msg, ptsd, hbody, &hname); - if(tps_add_headers(msg, &hname, hbody, 0)<0) { + if(tps_add_headers(msg, &hname, hbody, 0) < 0) { return -1; } @@ -810,19 +811,21 @@ int tps_reappend_route(sip_msg_t *msg, tps_data_t *ptsd, str *hbody, int rev) int c; str sb; - if(hbody==NULL || hbody->s==NULL || hbody->len<=0 || hbody->s[0]=='\0') + if(hbody == NULL || hbody->s == NULL || hbody->len <= 0 + || hbody->s[0] == '\0') return 0; - if(rev==1) { + if(rev == 1) { c = 0; sb.len = 1; - for(i=hbody->len-2; i>=0; i--) { - if(hbody->s[i]==',') { + for(i = hbody->len - 2; i >= 0; i--) { + if(hbody->s[i] == ',') { c = 1; - if(sb.len>0) { + if(sb.len > 0) { sb.s = hbody->s + i + 1; - if(sb.s[sb.len-1]==',') sb.len--; - if(tps_add_headers(msg, &hname, &sb, 0)<0) { + if(sb.s[sb.len - 1] == ',') + sb.len--; + if(tps_add_headers(msg, &hname, &sb, 0) < 0) { return -1; } } @@ -830,11 +833,12 @@ int tps_reappend_route(sip_msg_t *msg, tps_data_t *ptsd, str *hbody, int rev) } sb.len++; } - if(c==1) { - if(sb.len>0) { + if(c == 1) { + if(sb.len > 0) { sb.s = hbody->s; - if(sb.s[sb.len-1]==',') sb.len--; - if(tps_add_headers(msg, &hname, &sb, 0)<0) { + if(sb.s[sb.len - 1] == ',') + sb.len--; + if(tps_add_headers(msg, &hname, &sb, 0) < 0) { return -1; } } @@ -843,13 +847,15 @@ int tps_reappend_route(sip_msg_t *msg, tps_data_t *ptsd, str *hbody, int rev) } sb = *hbody; - if(sb.len>0 && sb.s[sb.len-1]==',') sb.len--; + if(sb.len > 0 && sb.s[sb.len - 1] == ',') + sb.len--; trim_zeros_lr(&sb); trim(&sb); - if(sb.len>0 && sb.s[sb.len-1]==',') sb.len--; - if (TPS_SPLIT_ROUTE & _tps_header_mode) - return tps_reappend_separate_header_values(msg, ptsd, &sb,&hname); - if(tps_add_headers(msg, &hname, &sb, 0)<0) { + if(sb.len > 0 && sb.s[sb.len - 1] == ',') + sb.len--; + if(TPS_SPLIT_ROUTE & _tps_header_mode) + return tps_reappend_separate_header_values(msg, ptsd, &sb, &hname); + if(tps_add_headers(msg, &hname, &sb, 0) < 0) { return -1; } @@ -872,7 +878,7 @@ int tps_request_received(sip_msg_t *msg, int dialog) LM_DBG("handling incoming request\n"); - if(dialog==0) { + if(dialog == 0) { /* nothing to do for initial request */ return 0; } @@ -882,21 +888,21 @@ int tps_request_received(sip_msg_t *msg, int dialog) tps_unmask_callid(msg); - if(tps_pack_message(msg, &mtsd)<0) { + if(tps_pack_message(msg, &mtsd) < 0) { LM_ERR("failed to extract and pack the headers\n"); return -1; } ret = tps_dlg_message_update(msg, &mtsd, _tps_contact_mode); - if(ret<0) { + if(ret < 0) { LM_ERR("failed to update on dlg message\n"); return -1; } lkey = msg->callid->body; LM_DBG("callid [%.*s] - a_uuid [%.*s] - b_uuid [%.*s]\n", lkey.len, lkey.s, - mtsd.a_uuid.len, ((mtsd.a_uuid.len>0)?mtsd.a_uuid.s:""), - mtsd.b_uuid.len, ((mtsd.b_uuid.len>0)?mtsd.b_uuid.s:"")); + mtsd.a_uuid.len, ((mtsd.a_uuid.len > 0) ? mtsd.a_uuid.s : ""), + mtsd.b_uuid.len, ((mtsd.b_uuid.len > 0) ? mtsd.b_uuid.s : "")); tps_storage_lock_get(&lkey); @@ -904,10 +910,10 @@ int tps_request_received(sip_msg_t *msg, int dialog) goto error; } metid = get_cseq(msg)->method_id; - if((metid & (METHOD_BYE|METHOD_INFO|METHOD_PRACK|METHOD_UPDATE)) + if((metid & (METHOD_BYE | METHOD_INFO | METHOD_PRACK | METHOD_UPDATE)) && stsd.b_contact.len <= 0) { /* no B-side contact, look for INVITE transaction record */ - if(metid & (METHOD_BYE|METHOD_UPDATE)) { + if(metid & (METHOD_BYE | METHOD_UPDATE)) { /* detect direction - via from-tag */ if(tps_dlg_detect_direction(msg, &stsd, &direction) < 0) { goto error; @@ -941,8 +947,8 @@ int tps_request_received(sip_msg_t *msg, int dialog) nuri = stsd.b_contact; } } - if(nuri.len>0) { - if(rewrite_uri(msg, &nuri)<0) { + if(nuri.len > 0) { + if(rewrite_uri(msg, &nuri) < 0) { LM_ERR("failed to update r-uri\n"); return -1; } else { @@ -951,12 +957,14 @@ int tps_request_received(sip_msg_t *msg, int dialog) } if(use_branch) { - LM_DBG("use branch for routing information, request from direction %d\n", direction); + LM_DBG("use branch for routing information, request from direction " + "%d\n", + direction); if(tps_reappend_route(msg, &stsd, &stsd.s_rr, 1) < 0) { LM_ERR("failed to reappend s-route\n"); return -1; } - if (direction == TPS_DIR_UPSTREAM) { + if(direction == TPS_DIR_UPSTREAM) { if(tps_reappend_route(msg, &stsd, &stsd.x_rr, 0) < 0) { LM_ERR("failed to reappend a-route\n"); return -1; @@ -969,7 +977,8 @@ int tps_request_received(sip_msg_t *msg, int dialog) } } else { if(tps_reappend_route(msg, &stsd, &stsd.s_rr, - (direction == TPS_DIR_UPSTREAM) ? 0 : 1) < 0) { + (direction == TPS_DIR_UPSTREAM) ? 0 : 1) + < 0) { LM_ERR("failed to reappend s-route\n"); return -1; } @@ -985,15 +994,19 @@ int tps_request_received(sip_msg_t *msg, int dialog) } } } - if(dialog!=0) { + if(dialog != 0) { tps_append_xuuid(msg, &stsd.a_uuid); if(_tps_rr_update) { - if(tps_storage_update_dialog(msg, &mtsd, &stsd, TPS_DBU_RPLATTRS|TPS_DBU_BRR)<0) { + if(tps_storage_update_dialog( + msg, &mtsd, &stsd, TPS_DBU_RPLATTRS | TPS_DBU_BRR) + < 0) { goto error; } } if(metid & METHOD_SUBSCRIBE) { - if(tps_storage_update_dialog(msg, &mtsd, &stsd, TPS_DBU_CONTACT|TPS_DBU_TIME)<0) { + if(tps_storage_update_dialog( + msg, &mtsd, &stsd, TPS_DBU_CONTACT | TPS_DBU_TIME) + < 0) { goto error; } } @@ -1024,34 +1037,36 @@ int tps_response_received(sip_msg_t *msg) tps_unmask_callid(msg); - if(tps_pack_message(msg, &mtsd)<0) { + if(tps_pack_message(msg, &mtsd) < 0) { LM_ERR("failed to extract and pack the headers\n"); return -1; } lkey = msg->callid->body; tps_storage_lock_get(&lkey); - if(tps_storage_load_branch(msg, &mtsd, &btsd, 0)<0) { + if(tps_storage_load_branch(msg, &mtsd, &btsd, 0) < 0) { goto error; } - LM_DBG("loaded dialog a_uuid [%.*s]\n", - btsd.a_uuid.len, ZSW(btsd.a_uuid.s)); - if(tps_storage_load_dialog(msg, &btsd, &stsd)<0) { + LM_DBG("loaded dialog a_uuid [%.*s]\n", btsd.a_uuid.len, + ZSW(btsd.a_uuid.s)); + if(tps_storage_load_dialog(msg, &btsd, &stsd) < 0) { goto error; } /* detect direction - via from-tag */ - if(tps_dlg_detect_direction(msg, &stsd, &direction)<0) { + if(tps_dlg_detect_direction(msg, &stsd, &direction) < 0) { goto error; } mtsd.direction = direction; - if(tps_storage_update_branch(msg, &mtsd, &btsd, - TPS_DBU_CONTACT|TPS_DBU_RPLATTRS)<0) { + if(tps_storage_update_branch( + msg, &mtsd, &btsd, TPS_DBU_CONTACT | TPS_DBU_RPLATTRS) + < 0) { goto error; } if(tps_storage_update_dialog(msg, &mtsd, &stsd, - (_tps_rr_update)?(TPS_DBU_RPLATTRS|TPS_DBU_BRR|TPS_DBU_ARR) - :TPS_DBU_RPLATTRS)<0) { + (_tps_rr_update) ? (TPS_DBU_RPLATTRS | TPS_DBU_BRR | TPS_DBU_ARR) + : TPS_DBU_RPLATTRS) + < 0) { goto error; } tps_storage_lock_release(&lkey); @@ -1088,17 +1103,18 @@ int tps_request_sent(sip_msg_t *msg, int dialog, int local) memset(&stsd, 0, sizeof(tps_data_t)); ptsd = NULL; - if(tps_pack_message(msg, &mtsd)<0) { + if(tps_pack_message(msg, &mtsd) < 0) { LM_ERR("failed to extract and pack the headers\n"); return -1; } - if(dialog!=0) { - if(tps_get_xuuid(msg, &xuuid)<0) { - LM_DBG("no x-uuid header - local message only - Call-ID mask if downstream \n"); + if(dialog != 0) { + if(tps_get_xuuid(msg, &xuuid) < 0) { + LM_DBG("no x-uuid header - local message only - Call-ID mask if " + "downstream \n"); /* ACK and CANCEL go downstream so Call-ID mask required */ - if(get_cseq(msg)->method_id==METHOD_ACK - || get_cseq(msg)->method_id==METHOD_CANCEL) { + if(get_cseq(msg)->method_id == METHOD_ACK + || get_cseq(msg)->method_id == METHOD_CANCEL) { tps_mask_callid(msg); } return 0; @@ -1111,33 +1127,34 @@ int tps_request_sent(sip_msg_t *msg, int dialog, int local) tps_storage_lock_get(&lkey); - if(dialog!=0) { - if(tps_storage_load_dialog(msg, &mtsd, &stsd)==0) { + if(dialog != 0) { + if(tps_storage_load_dialog(msg, &mtsd, &stsd) == 0) { ptsd = &stsd; } /* detect direction - via from-tag */ - if(tps_dlg_detect_direction(msg, &stsd, &direction)<0) { + if(tps_dlg_detect_direction(msg, &stsd, &direction) < 0) { goto error; } mtsd.direction = direction; } - if(tps_storage_load_branch(msg, &mtsd, &btsd, 0)!=0) { - if(tps_storage_record(msg, &mtsd, dialog, direction)<0) { + if(tps_storage_load_branch(msg, &mtsd, &btsd, 0) != 0) { + if(tps_storage_record(msg, &mtsd, dialog, direction) < 0) { goto error; } } else { - if(ptsd==NULL) ptsd = &btsd; + if(ptsd == NULL) + ptsd = &btsd; } - if(ptsd==NULL) ptsd = &mtsd; + if(ptsd == NULL) + ptsd = &mtsd; /* local generated requests */ if(local) { /* ACK and CANCEL go downstream */ - if(get_cseq(msg)->method_id==METHOD_ACK - || get_cseq(msg)->method_id==METHOD_CANCEL - || local==2) { + if(get_cseq(msg)->method_id == METHOD_ACK + || get_cseq(msg)->method_id == METHOD_CANCEL || local == 2) { // ts_mask_callid(&msg); goto done; } else { @@ -1151,17 +1168,18 @@ int tps_request_sent(sip_msg_t *msg, int dialog, int local) tps_remove_headers(msg, HDR_VIA_T); tps_reinsert_via(msg, &mtsd, &mtsd.x_via1); - if(direction==TPS_DIR_UPSTREAM) { + if(direction == TPS_DIR_UPSTREAM) { tps_reinsert_contact(msg, ptsd, &ptsd->as_contact); } else { tps_reinsert_contact(msg, ptsd, &ptsd->bs_contact); } - if(dialog!=0) { + if(dialog != 0) { tps_storage_end_dialog(msg, &mtsd, ptsd); if(tps_storage_update_dialog(msg, &mtsd, &stsd, - (_tps_rr_update)?(TPS_DBU_CONTACT|TPS_DBU_ARR) - :TPS_DBU_CONTACT)<0) { + (_tps_rr_update) ? (TPS_DBU_CONTACT | TPS_DBU_ARR) + : TPS_DBU_CONTACT) + < 0) { goto error; } } @@ -1169,7 +1187,7 @@ int tps_request_sent(sip_msg_t *msg, int dialog, int local) done: tps_storage_lock_release(&lkey); if(direction == TPS_DIR_DOWNSTREAM) { - tps_mask_callid(msg); + tps_mask_callid(msg); } return 0; @@ -1198,19 +1216,19 @@ int tps_response_sent(sip_msg_t *msg) memset(&stsd, 0, sizeof(tps_data_t)); memset(&btsd, 0, sizeof(tps_data_t)); - if(tps_get_xbranch(msg, &xvbranch)<0) { + if(tps_get_xbranch(msg, &xvbranch) < 0) { LM_DBG("no x-branch header - nothing to do\n"); return 0; } - if(tps_pack_message(msg, &mtsd)<0) { + if(tps_pack_message(msg, &mtsd) < 0) { LM_ERR("failed to extract and pack the headers\n"); return -1; } mtsd.x_vbranch1 = xvbranch; tps_remove_xbranch(msg); - if(get_cseq(msg)->method_id==METHOD_MESSAGE) { + if(get_cseq(msg)->method_id == METHOD_MESSAGE) { tps_remove_headers(msg, HDR_RECORDROUTE_T); tps_remove_headers(msg, HDR_CONTACT_T); return 0; @@ -1219,18 +1237,18 @@ int tps_response_sent(sip_msg_t *msg) lkey = msg->callid->body; tps_storage_lock_get(&lkey); - if(tps_storage_load_branch(msg, &mtsd, &btsd, 0)<0) { + if(tps_storage_load_branch(msg, &mtsd, &btsd, 0) < 0) { goto error; } - LM_DBG("loaded branch a_uuid [%.*s]\n", - btsd.a_uuid.len, ZSW(btsd.a_uuid.s)); - if(tps_storage_load_dialog(msg, &btsd, &stsd)<0) { + LM_DBG("loaded branch a_uuid [%.*s]\n", btsd.a_uuid.len, + ZSW(btsd.a_uuid.s)); + if(tps_storage_load_dialog(msg, &btsd, &stsd) < 0) { goto error; } tps_storage_lock_release(&lkey); /* detect direction - via from-tag */ - if(tps_dlg_detect_direction(msg, &stsd, &direction)<0) { + if(tps_dlg_detect_direction(msg, &stsd, &direction) < 0) { goto error1; } mtsd.direction = direction; @@ -1238,23 +1256,23 @@ int tps_response_sent(sip_msg_t *msg) tps_remove_headers(msg, HDR_RECORDROUTE_T); /* keep contact without updates for redirect responses sent out */ - if(msg->first_line.u.reply.statuscode>=300 - && msg->first_line.u.reply.statuscode<400) { + if(msg->first_line.u.reply.statuscode >= 300 + && msg->first_line.u.reply.statuscode < 400) { contact_keep = 1; } - if(contact_keep==0 && msg->first_line.u.reply.statuscode>100 - && msg->first_line.u.reply.statuscode<200 - && msg->contact==NULL) { + if(contact_keep == 0 && msg->first_line.u.reply.statuscode > 100 + && msg->first_line.u.reply.statuscode < 200 + && msg->contact == NULL) { contact_keep = 1; } - if(contact_keep==0 && msg->first_line.u.reply.statuscode>=400 - && msg->first_line.u.reply.statuscode<500 - && msg->contact==NULL) { + if(contact_keep == 0 && msg->first_line.u.reply.statuscode >= 400 + && msg->first_line.u.reply.statuscode < 500 + && msg->contact == NULL) { contact_keep = 1; } - if(contact_keep==0) { + if(contact_keep == 0) { tps_remove_headers(msg, HDR_CONTACT_T); - if(direction==TPS_DIR_DOWNSTREAM) { + if(direction == TPS_DIR_DOWNSTREAM) { tps_reinsert_contact(msg, &stsd, &stsd.as_contact); } else { tps_reinsert_contact(msg, &stsd, &stsd.bs_contact); @@ -1262,15 +1280,15 @@ int tps_response_sent(sip_msg_t *msg) } tps_reappend_rr(msg, &btsd, &btsd.x_rr); - if(tps_storage_update_branch(msg, &mtsd, &btsd, TPS_DBU_CONTACT)<0) { + if(tps_storage_update_branch(msg, &mtsd, &btsd, TPS_DBU_CONTACT) < 0) { goto error; } - if(tps_storage_update_dialog(msg, &mtsd, &stsd, TPS_DBU_CONTACT)<0) { + if(tps_storage_update_dialog(msg, &mtsd, &stsd, TPS_DBU_CONTACT) < 0) { goto error1; } if(direction == TPS_DIR_UPSTREAM) { - tps_mask_callid(msg); + tps_mask_callid(msg); } return 0; diff --git a/src/modules/topos/tps_msg.h b/src/modules/topos/tps_msg.h index 3ff06894759..4f4c52552ba 100644 --- a/src/modules/topos/tps_msg.h +++ b/src/modules/topos/tps_msg.h @@ -31,12 +31,12 @@ #include "../../core/parser/msg_parser.h" -#define TPS_SPLIT_VIA (1<<0) -#define TPS_SPLIT_RECORD_ROUTE (1<<1) -#define TPS_SPLIT_ROUTE (1<<2) +#define TPS_SPLIT_VIA (1 << 0) +#define TPS_SPLIT_RECORD_ROUTE (1 << 1) +#define TPS_SPLIT_ROUTE (1 << 2) int tps_update_hdr_replaces(sip_msg_t *msg); -char* tps_msg_update(sip_msg_t *msg, unsigned int *olen); +char *tps_msg_update(sip_msg_t *msg, unsigned int *olen); int tps_skip_msg(sip_msg_t *msg); int tps_request_received(sip_msg_t *msg, int dialog); diff --git a/src/modules/topos/tps_storage.c b/src/modules/topos/tps_storage.c index e0649b683d3..70c003c944c 100644 --- a/src/modules/topos/tps_storage.c +++ b/src/modules/topos/tps_storage.c @@ -52,7 +52,7 @@ extern sruid_t _tps_sruid; -extern db1_con_t* _tps_db_handle; +extern db1_con_t *_tps_db_handle; extern db_func_t _tpsdbf; extern str _tps_contact_host; @@ -66,7 +66,7 @@ extern str _tps_xavu_field_contact_host; extern str _tps_context_param; extern str _tps_context_value; -#define TPS_STORAGE_LOCK_SIZE 1<<9 +#define TPS_STORAGE_LOCK_SIZE 1 << 9 static gen_lock_set_t *_tps_storage_lock_set = NULL; int _tps_branch_expire = 180; @@ -76,36 +76,35 @@ int tps_db_insert_dialog(tps_data_t *td); int tps_db_clean_dialogs(void); int tps_db_insert_branch(tps_data_t *td); int tps_db_clean_branches(void); -int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, - uint32_t mode); +int tps_db_load_branch( + sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, uint32_t mode); int tps_db_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd); -int tps_db_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, - uint32_t mode); -int tps_db_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, - uint32_t mode); +int tps_db_update_branch( + sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, uint32_t mode); +int tps_db_update_dialog( + sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, uint32_t mode); int tps_db_end_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd); /** * */ static tps_storage_api_t _tps_storage_api = { - .insert_dialog = tps_db_insert_dialog, - .clean_dialogs = tps_db_clean_dialogs, - .insert_branch = tps_db_insert_branch, - .clean_branches = tps_db_clean_branches, - .load_branch = tps_db_load_branch, - .load_dialog = tps_db_load_dialog, - .update_branch = tps_db_update_branch, - .update_dialog = tps_db_update_dialog, - .end_dialog = tps_db_end_dialog -}; + .insert_dialog = tps_db_insert_dialog, + .clean_dialogs = tps_db_clean_dialogs, + .insert_branch = tps_db_insert_branch, + .clean_branches = tps_db_clean_branches, + .load_branch = tps_db_load_branch, + .load_dialog = tps_db_load_dialog, + .update_branch = tps_db_update_branch, + .update_dialog = tps_db_update_dialog, + .end_dialog = tps_db_end_dialog}; /** * */ int tps_set_storage_api(tps_storage_api_t *tsa) { - if(tsa==NULL) + if(tsa == NULL) return -1; LM_DBG("setting new storage api: %p\n", tsa); memcpy(&_tps_storage_api, tsa, sizeof(tps_storage_api_t)); @@ -119,8 +118,8 @@ int tps_set_storage_api(tps_storage_api_t *tsa) int tps_storage_lock_set_init(void) { _tps_storage_lock_set = lock_set_alloc(TPS_STORAGE_LOCK_SIZE); - if(_tps_storage_lock_set==NULL - || lock_set_init(_tps_storage_lock_set)==NULL) { + if(_tps_storage_lock_set == NULL + || lock_set_init(_tps_storage_lock_set) == NULL) { LM_ERR("cannot initiate lock set\n"); return -1; } @@ -156,7 +155,7 @@ int tps_storage_lock_release(str *lkey) */ int tps_storage_lock_set_destroy(void) { - if(_tps_storage_lock_set!=NULL) { + if(_tps_storage_lock_set != NULL) { lock_set_destroy(_tps_storage_lock_set); lock_set_dealloc(_tps_storage_lock_set); } @@ -216,8 +215,8 @@ int tps_storage_branch_rm(sip_msg_t *msg, tps_data_t *td) /** * */ -int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir, - int ctmode) +int tps_storage_fill_contact( + sip_msg_t *msg, tps_data_t *td, str *uuid, int dir, int ctmode) { str sv; sip_uri_t puri, curi; @@ -226,38 +225,38 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir, int cparam_len; sr_xavp_t *vavu = NULL; - if(dir==TPS_DIR_DOWNSTREAM) { + if(dir == TPS_DIR_DOWNSTREAM) { sv = td->bs_contact; } else { sv = td->as_contact; } - if(sv.len<=0) { + if(sv.len <= 0) { /* no contact - skip */ return 0; } - if (parse_uri(sv.s, sv.len, &puri) < 0) { + if(parse_uri(sv.s, sv.len, &puri) < 0) { LM_ERR("failed to parse the uri\n"); return -1; } contact_len = sv.len; - if (_tps_contact_host.len) + if(_tps_contact_host.len) contact_len = sv.len - puri.host.len + _tps_contact_host.len; - if (ctmode == 1 || ctmode == 2) { + if(ctmode == 1 || ctmode == 2) { cparam_len = _tps_cparam_name.len; } else { cparam_len = 0; } - if(td->cp + 8 + (2*uuid->len) + cparam_len + contact_len >= td->cbuf - + TPS_DATA_SIZE) { + if(td->cp + 8 + (2 * uuid->len) + cparam_len + contact_len + >= td->cbuf + TPS_DATA_SIZE) { LM_ERR("insufficient data buffer\n"); return -1; } /* copy uuid */ - if(dir==TPS_DIR_DOWNSTREAM) { + if(dir == TPS_DIR_DOWNSTREAM) { td->b_uuid.s = td->cp; *td->cp = 'b'; td->cp++; @@ -280,28 +279,38 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir, *td->cp = '<'; td->cp++; /* look for sip: */ - for(i=0; icp = sv.s[i]; td->cp++; - if(sv.s[i]==':') break; + if(sv.s[i] == ':') + break; } - if (ctmode == 1 || ctmode == 2) { + if(ctmode == 1 || ctmode == 2) { /* create new URI parameter for Contact header */ - if (ctmode == 1) { - if (dir==TPS_DIR_DOWNSTREAM) { + if(ctmode == 1) { + if(dir == TPS_DIR_DOWNSTREAM) { /* extract the contact address */ - if(parse_headers(msg, HDR_CONTACT_F, 0) < 0 || msg->contact==NULL) { + if(parse_headers(msg, HDR_CONTACT_F, 0) < 0 + || msg->contact == NULL) { LM_WARN("bad sip message or missing Contact hdr\n"); return -1; } else { - if(parse_contact(msg->contact)<0 - || ((contact_body_t*)msg->contact->parsed)->contacts==NULL - || ((contact_body_t*)msg->contact->parsed)->contacts->next!=NULL) { + if(parse_contact(msg->contact) < 0 + || ((contact_body_t *)msg->contact->parsed) + ->contacts + == NULL + || ((contact_body_t *)msg->contact->parsed) + ->contacts->next + != NULL) { LM_ERR("bad Contact header\n"); return -1; } else { - if (parse_uri(((contact_body_t*)msg->contact->parsed)->contacts->uri.s, - ((contact_body_t*)msg->contact->parsed)->contacts->uri.len, &curi) < 0) { + if(parse_uri(((contact_body_t *)msg->contact->parsed) + ->contacts->uri.s, + ((contact_body_t *)msg->contact->parsed) + ->contacts->uri.len, + &curi) + < 0) { LM_ERR("failed to parse the contact uri\n"); return -1; } @@ -311,23 +320,24 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir, td->cp += curi.user.len; } else { /* extract the ruri */ - if(parse_sip_msg_uri(msg)<0) { + if(parse_sip_msg_uri(msg) < 0) { LM_ERR("failed to parse r-uri\n"); return -1; } - if(msg->parsed_uri.user.len==0) { + if(msg->parsed_uri.user.len == 0) { LM_ERR("no r-uri user\n"); return -1; } - memcpy(td->cp, msg->parsed_uri.user.s, msg->parsed_uri.user.len); + memcpy(td->cp, msg->parsed_uri.user.s, + msg->parsed_uri.user.len); td->cp += msg->parsed_uri.user.len; } - } else if (ctmode == 2) { - if (dir==TPS_DIR_DOWNSTREAM) { + } else if(ctmode == 2) { + if(dir == TPS_DIR_DOWNSTREAM) { /* extract the a contact */ - vavu = xavu_get_child_with_sval(&_tps_xavu_cfg, - &_tps_xavu_field_acontact); - if(vavu==NULL || vavu->val.v.s.len<=0) { + vavu = xavu_get_child_with_sval( + &_tps_xavu_cfg, &_tps_xavu_field_acontact); + if(vavu == NULL || vavu->val.v.s.len <= 0) { LM_ERR("could not evaluate a_contact xavu\n"); return -1; } @@ -335,9 +345,9 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir, td->cp += vavu->val.v.s.len; } else { /* extract the b contact */ - vavu = xavu_get_child_with_sval(&_tps_xavu_cfg, - &_tps_xavu_field_bcontact); - if(vavu==NULL || vavu->val.v.s.len<=0) { + vavu = xavu_get_child_with_sval( + &_tps_xavu_cfg, &_tps_xavu_field_bcontact); + if(vavu == NULL || vavu->val.v.s.len <= 0) { LM_ERR("could not evaluate b_contact xavu\n"); return -1; } @@ -346,23 +356,23 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir, } } - if (!((ctmode == 1) && (dir==TPS_DIR_DOWNSTREAM) - && (curi.user.len <= 0))) { + if(!((ctmode == 1) && (dir == TPS_DIR_DOWNSTREAM) + && (curi.user.len <= 0))) { *td->cp = '@'; td->cp++; } /* contact_host xavu takes preference, reset vavu */ vavu = NULL; - if (_tps_xavu_cfg.len>0 && _tps_xavu_field_contact_host.len>0) { - vavu = xavu_get_child_with_sval(&_tps_xavu_cfg, - &_tps_xavu_field_contact_host); + if(_tps_xavu_cfg.len > 0 && _tps_xavu_field_contact_host.len > 0) { + vavu = xavu_get_child_with_sval( + &_tps_xavu_cfg, &_tps_xavu_field_contact_host); } - if(vavu!=NULL && vavu->val.v.s.len>0) { + if(vavu != NULL && vavu->val.v.s.len > 0) { memcpy(td->cp, vavu->val.v.s.s, vavu->val.v.s.len); td->cp += vavu->val.v.s.len; } else { - if (_tps_contact_host.len) { + if(_tps_contact_host.len) { /* using configured hostname in the contact header */ memcpy(td->cp, _tps_contact_host.s, _tps_contact_host.len); td->cp += _tps_contact_host.len; @@ -371,13 +381,13 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir, td->cp += puri.host.len; } } - if(puri.port.len>0) { + if(puri.port.len > 0) { *td->cp = ':'; td->cp++; memcpy(td->cp, puri.port.s, puri.port.len); td->cp += puri.port.len; } - if(puri.transport_val.len>0) { + if(puri.transport_val.len > 0) { memcpy(td->cp, ";transport=", 11); td->cp += 11; memcpy(td->cp, puri.transport_val.s, puri.transport_val.len); @@ -390,7 +400,7 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir, td->cp += _tps_cparam_name.len; *td->cp = '='; td->cp++; - if(dir==TPS_DIR_DOWNSTREAM) { + if(dir == TPS_DIR_DOWNSTREAM) { *td->cp = 'b'; } else { *td->cp = 'a'; @@ -401,7 +411,7 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir, } else { /* create new user part for Contact header URI */ - if(dir==TPS_DIR_DOWNSTREAM) { + if(dir == TPS_DIR_DOWNSTREAM) { *td->cp = 'b'; } else { *td->cp = 'a'; @@ -413,15 +423,15 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir, td->cp++; /* contact_host xavu takes preference */ - if (_tps_xavu_cfg.len>0 && _tps_xavu_field_contact_host.len>0) { - vavu = xavu_get_child_with_sval(&_tps_xavu_cfg, - &_tps_xavu_field_contact_host); + if(_tps_xavu_cfg.len > 0 && _tps_xavu_field_contact_host.len > 0) { + vavu = xavu_get_child_with_sval( + &_tps_xavu_cfg, &_tps_xavu_field_contact_host); } - if(vavu!=NULL && vavu->val.v.s.len>0) { + if(vavu != NULL && vavu->val.v.s.len > 0) { memcpy(td->cp, vavu->val.v.s.s, vavu->val.v.s.len); td->cp += vavu->val.v.s.len; } else { - if (_tps_contact_host.len) { + if(_tps_contact_host.len) { /* using configured hostname in the contact header */ memcpy(td->cp, _tps_contact_host.s, _tps_contact_host.len); td->cp += _tps_contact_host.len; @@ -430,13 +440,13 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir, td->cp += puri.host.len; } } - if(puri.port.len>0) { + if(puri.port.len > 0) { *td->cp = ':'; td->cp++; memcpy(td->cp, puri.port.s, puri.port.len); td->cp += puri.port.len; } - if(puri.transport_val.len>0) { + if(puri.transport_val.len > 0) { memcpy(td->cp, ";transport=", 11); td->cp += 11; memcpy(td->cp, puri.transport_val.s, puri.transport_val.len); @@ -446,12 +456,12 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir, *td->cp = '>'; td->cp++; - if(dir==TPS_DIR_DOWNSTREAM) { + if(dir == TPS_DIR_DOWNSTREAM) { td->bs_contact.len = td->cp - td->bs_contact.s; - LM_DBG("td->bs %.*s\n", td->bs_contact.len, td->bs_contact.s); + LM_DBG("td->bs %.*s\n", td->bs_contact.len, td->bs_contact.s); } else { td->as_contact.len = td->cp - td->as_contact.s; - LM_DBG("td->as %.*s\n", td->as_contact.len, td->as_contact.s); + LM_DBG("td->as %.*s\n", td->as_contact.len, td->as_contact.s); } return 0; } @@ -463,7 +473,7 @@ int tps_storage_link_msg(sip_msg_t *msg, tps_data_t *td, int dir) { str stxt; - if(parse_headers(msg, HDR_EOH_F, 0)==-1) + if(parse_headers(msg, HDR_EOH_F, 0) == -1) return -1; /* callid */ @@ -472,27 +482,27 @@ int tps_storage_link_msg(sip_msg_t *msg, tps_data_t *td, int dir) td->a_callid = stxt; /* get from-tag */ - if(parse_from_header(msg)<0 || msg->from==NULL) { + if(parse_from_header(msg) < 0 || msg->from == NULL) { LM_ERR("failed getting 'from' header!\n"); goto error; } td->a_tag = get_from(msg)->tag_value; /* get to-tag */ - if(parse_to_header(msg)<0 || msg->to==NULL) { + if(parse_to_header(msg) < 0 || msg->to == NULL) { LM_ERR("failed getting 'to' header!\n"); goto error; } td->b_tag = get_to(msg)->tag_value; - if(dir==TPS_DIR_DOWNSTREAM) { + if(dir == TPS_DIR_DOWNSTREAM) { td->x_tag = td->a_tag; } else { td->x_tag = td->b_tag; } td->x_via = td->x_via2; - if(parse_headers(msg, HDR_CSEQ_F, 0)!=0 || msg->cseq==NULL) { + if(parse_headers(msg, HDR_CSEQ_F, 0) != 0 || msg->cseq == NULL) { LM_ERR("cannot parse cseq header\n"); return -1; /* should it be 0 ?!?! */ } @@ -500,19 +510,19 @@ int tps_storage_link_msg(sip_msg_t *msg, tps_data_t *td, int dir) td->s_cseq = get_cseq(msg)->number; /* extract the contact address */ - if(parse_headers(msg, HDR_CONTACT_F, 0)<0 || msg->contact==NULL) { + if(parse_headers(msg, HDR_CONTACT_F, 0) < 0 || msg->contact == NULL) { if((td->s_method_id != METHOD_INVITE) - && (td->s_method_id != METHOD_SUBSCRIBE)){ + && (td->s_method_id != METHOD_SUBSCRIBE)) { /* no mandatory contact unless is INVITE or SUBSCRIBE - done */ return 0; } - if(msg->first_line.type==SIP_REPLY) { - if(msg->first_line.u.reply.statuscode>=100 - && msg->first_line.u.reply.statuscode<200) { + if(msg->first_line.type == SIP_REPLY) { + if(msg->first_line.u.reply.statuscode >= 100 + && msg->first_line.u.reply.statuscode < 200) { /* provisional response with no mandatory contact header */ return 0; } - if(msg->first_line.u.reply.statuscode>=400) { + if(msg->first_line.u.reply.statuscode >= 400) { /* failure response with no mandatory contact header */ return 0; } @@ -520,39 +530,45 @@ int tps_storage_link_msg(sip_msg_t *msg, tps_data_t *td, int dir) LM_ERR("bad sip message or missing Contact hdr\n"); goto error; } - if(parse_contact(msg->contact)<0 - || ((contact_body_t*)msg->contact->parsed)->contacts==NULL - || ((contact_body_t*)msg->contact->parsed)->contacts->next!=NULL) { + if(parse_contact(msg->contact) < 0 + || ((contact_body_t *)msg->contact->parsed)->contacts == NULL + || ((contact_body_t *)msg->contact->parsed)->contacts->next + != NULL) { LM_ERR("bad Contact header\n"); return -1; } - if(msg->first_line.type==SIP_REQUEST) { - if(dir==TPS_DIR_DOWNSTREAM) { - td->a_contact = ((contact_body_t*)msg->contact->parsed)->contacts->uri; + if(msg->first_line.type == SIP_REQUEST) { + if(dir == TPS_DIR_DOWNSTREAM) { + td->a_contact = + ((contact_body_t *)msg->contact->parsed)->contacts->uri; } else { - td->b_contact = ((contact_body_t*)msg->contact->parsed)->contacts->uri; + td->b_contact = + ((contact_body_t *)msg->contact->parsed)->contacts->uri; } } else { - if(dir==TPS_DIR_DOWNSTREAM) { - td->b_contact = ((contact_body_t*)msg->contact->parsed)->contacts->uri; + if(dir == TPS_DIR_DOWNSTREAM) { + td->b_contact = + ((contact_body_t *)msg->contact->parsed)->contacts->uri; } else { - td->a_contact = ((contact_body_t*)msg->contact->parsed)->contacts->uri; + td->a_contact = + ((contact_body_t *)msg->contact->parsed)->contacts->uri; } } - if (td->s_method_id == METHOD_SUBSCRIBE) { - if(msg->expires && (msg->expires->body.len > 0) && (msg->expires->parsed - || (parse_expires(msg->expires) >= 0))) { + if(td->s_method_id == METHOD_SUBSCRIBE) { + if(msg->expires && (msg->expires->body.len > 0) + && (msg->expires->parsed + || (parse_expires(msg->expires) >= 0))) { td->expires = ((exp_body_t *)msg->expires->parsed)->val; } } LM_DBG("downstream: %s - acontact: [%.*s] - bcontact: [%.*s]\n", - (dir==TPS_DIR_DOWNSTREAM)?"yes":"no", - td->a_contact.len, (td->a_contact.len>0)?td->a_contact.s:"", - td->b_contact.len, (td->b_contact.len>0)?td->b_contact.s:""); + (dir == TPS_DIR_DOWNSTREAM) ? "yes" : "no", td->a_contact.len, + (td->a_contact.len > 0) ? td->a_contact.s : "", td->b_contact.len, + (td->b_contact.len > 0) ? td->b_contact.s : ""); return 0; @@ -569,19 +585,19 @@ int tps_storage_record(sip_msg_t *msg, tps_data_t *td, int dialog, int dir) str suid; str *sx = NULL; - if(_tps_context_value.len>0) { + if(_tps_context_value.len > 0) { sx = &_tps_context_value; - } else if(_tps_context_param.len>0) { + } else if(_tps_context_param.len > 0) { sx = &_tps_context_param; } - if(dialog==0) { + if(dialog == 0) { sruid_nextx(&_tps_sruid, sx); suid = _tps_sruid.uid; } else { - if(td->a_uuid.len>0) { + if(td->a_uuid.len > 0) { suid = td->a_uuid; - } else if(td->b_uuid.len>0) { + } else if(td->b_uuid.len > 0) { suid = td->b_uuid; } else { goto error; @@ -590,23 +606,29 @@ int tps_storage_record(sip_msg_t *msg, tps_data_t *td, int dialog, int dir) suid.len--; } - ret = tps_storage_fill_contact(msg, td, &suid, TPS_DIR_DOWNSTREAM, - _tps_contact_mode); - if(ret<0) goto error; - ret = tps_storage_fill_contact(msg, td, &suid, TPS_DIR_UPSTREAM, - _tps_contact_mode); - if(ret<0) goto error; + ret = tps_storage_fill_contact( + msg, td, &suid, TPS_DIR_DOWNSTREAM, _tps_contact_mode); + if(ret < 0) + goto error; + ret = tps_storage_fill_contact( + msg, td, &suid, TPS_DIR_UPSTREAM, _tps_contact_mode); + if(ret < 0) + goto error; ret = tps_storage_link_msg(msg, td, dir); - if(ret<0) goto error; + if(ret < 0) + goto error; ret = _tps_storage_api.insert_branch(td); - if(ret<0) goto error; - if(dialog==0) { + if(ret < 0) + goto error; + if(dialog == 0) { if(td->as_contact.len <= 0 && td->bs_contact.len <= 0) { - LM_WARN("no local address - do record routing for all initial requests\n"); + LM_WARN("no local address - do record routing for all initial " + "requests\n"); } ret = _tps_storage_api.insert_dialog(td); - if(ret<0) goto error; + if(ret < 0) + goto error; } return 0; @@ -667,11 +689,11 @@ str tt_col_s_method = str_init("s_method"); str tt_col_s_cseq = str_init("s_cseq"); str tt_col_x_context = str_init("x_context"); -#define TPS_NR_KEYS 48 +#define TPS_NR_KEYS 48 str _tps_empty = str_init(""); -#define TPS_STRZ(_s) ((_s).s)?(_s):(_tps_empty) +#define TPS_STRZ(_s) ((_s).s) ? (_s) : (_tps_empty) /** * */ @@ -681,13 +703,13 @@ int tps_db_insert_dialog(tps_data_t *td) db_val_t db_vals[TPS_NR_KEYS]; int nr_keys; - if (_tps_db_handle == NULL) { + if(_tps_db_handle == NULL) { LM_ERR("No database handle - misconfiguration?\n"); goto error; } - memset(db_keys, 0, TPS_NR_KEYS*sizeof(db_key_t)); - memset(db_vals, 0, TPS_NR_KEYS*sizeof(db_val_t)); + memset(db_keys, 0, TPS_NR_KEYS * sizeof(db_key_t)); + memset(db_vals, 0, TPS_NR_KEYS * sizeof(db_val_t)); nr_keys = 0; db_keys[nr_keys] = &td_col_rectime; @@ -795,14 +817,14 @@ int tps_db_insert_dialog(tps_data_t *td) db_vals[nr_keys].val.str_val = TPS_STRZ(td->s_cseq); nr_keys++; - if(td->x_context.len>0) { + if(td->x_context.len > 0) { db_keys[nr_keys] = &td_col_x_context; db_vals[nr_keys].type = DB1_STR; db_vals[nr_keys].val.str_val = TPS_STRZ(td->x_context); nr_keys++; } - if (_tpsdbf.use_table(_tps_db_handle, &td_table_name) < 0) { + if(_tpsdbf.use_table(_tps_db_handle, &td_table_name) < 0) { LM_ERR("failed to perform use table\n"); return -1; } @@ -825,10 +847,10 @@ int tps_db_clean_dialogs(void) { db_key_t db_keys[2]; db_val_t db_vals[2]; - db_op_t db_ops[2]; + db_op_t db_ops[2]; int nr_keys; - if (_tps_db_handle == NULL) { + if(_tps_db_handle == NULL) { LM_ERR("No database handle - misconfiguration?\n"); return -1; } @@ -844,12 +866,12 @@ int tps_db_clean_dialogs(void) db_vals[nr_keys].val.time_val = time(NULL) - _tps_dialog_expire; nr_keys++; - if (_tpsdbf.use_table(_tps_db_handle, &td_table_name) < 0) { + if(_tpsdbf.use_table(_tps_db_handle, &td_table_name) < 0) { LM_ERR("failed to perform use table\n"); return -1; } - if (_tpsdbf.delete(_tps_db_handle, db_keys, db_ops, db_vals, nr_keys) < 0) { + if(_tpsdbf.delete(_tps_db_handle, db_keys, db_ops, db_vals, nr_keys) < 0) { LM_DBG("failed to clean expired dialog records\n"); } @@ -863,7 +885,7 @@ int tps_db_clean_dialogs(void) db_vals[nr_keys].val.int_val = 0; nr_keys++; - if (_tpsdbf.delete(_tps_db_handle, db_keys, db_ops, db_vals, nr_keys) < 0) { + if(_tpsdbf.delete(_tps_db_handle, db_keys, db_ops, db_vals, nr_keys) < 0) { LM_DBG("failed to clean expired dialog records\n"); } @@ -879,13 +901,13 @@ int tps_db_insert_branch(tps_data_t *td) db_val_t db_vals[TPS_NR_KEYS]; int nr_keys; - if (_tps_db_handle == NULL) { + if(_tps_db_handle == NULL) { LM_ERR("No database handle - misconfiguration?\n"); goto error; } - memset(db_keys, 0, TPS_NR_KEYS*sizeof(db_key_t)); - memset(db_vals, 0, TPS_NR_KEYS*sizeof(db_val_t)); + memset(db_keys, 0, TPS_NR_KEYS * sizeof(db_key_t)); + memset(db_vals, 0, TPS_NR_KEYS * sizeof(db_val_t)); nr_keys = 0; db_keys[nr_keys] = &tt_col_rectime; @@ -988,14 +1010,14 @@ int tps_db_insert_branch(tps_data_t *td) db_vals[nr_keys].val.str_val = TPS_STRZ(td->b_tag); nr_keys++; - if(td->x_context.len>0) { + if(td->x_context.len > 0) { db_keys[nr_keys] = &tt_col_x_context; db_vals[nr_keys].type = DB1_STR; db_vals[nr_keys].val.str_val = TPS_STRZ(td->x_context); nr_keys++; } - if (_tpsdbf.use_table(_tps_db_handle, &tt_table_name) < 0) { + if(_tpsdbf.use_table(_tps_db_handle, &tt_table_name) < 0) { LM_ERR("failed to perform use table\n"); return -1; } @@ -1009,7 +1031,6 @@ int tps_db_insert_branch(tps_data_t *td) error: return -1; - } /** @@ -1019,10 +1040,10 @@ int tps_db_clean_branches(void) { db_key_t db_keys[2]; db_val_t db_vals[2]; - db_op_t db_ops[2]; + db_op_t db_ops[2]; int nr_keys; - if (_tps_db_handle == NULL) { + if(_tps_db_handle == NULL) { LM_ERR("No database handle - misconfiguration?\n"); return -1; } @@ -1038,12 +1059,12 @@ int tps_db_clean_branches(void) db_vals[nr_keys].val.time_val = time(NULL) - _tps_branch_expire; nr_keys++; - if (_tpsdbf.use_table(_tps_db_handle, &tt_table_name) < 0) { + if(_tpsdbf.use_table(_tps_db_handle, &tt_table_name) < 0) { LM_ERR("failed to perform use table\n"); return -1; } - if (_tpsdbf.delete(_tps_db_handle, db_keys, db_ops, db_vals, nr_keys) < 0) { + if(_tpsdbf.delete(_tps_db_handle, db_keys, db_ops, db_vals, nr_keys) < 0) { LM_DBG("failed to clean expired branch records\n"); } return 0; @@ -1052,59 +1073,63 @@ int tps_db_clean_branches(void) /** * */ -#define TPS_DATA_APPEND_DB(_sd, _res, _c, _s) \ - do { \ - if (RES_ROWS(_res)[0].values[_c].nul == 0) \ - { \ - str tmp; \ - switch(RES_ROWS(_res)[0].values[_c].type) \ - { \ - case DB1_STRING: \ - tmp.s=(char*)RES_ROWS(_res)[0].values[_c].val.string_val; \ - if(tmp.s) { \ - tmp.len=strlen(tmp.s); \ - } else { \ - tmp.len=0; \ - } \ - break; \ - case DB1_STR: \ - tmp.len=RES_ROWS(_res)[0].values[_c].val.str_val.len; \ - tmp.s=(char*)RES_ROWS(_res)[0].values[_c].val.str_val.s; \ - break; \ - case DB1_BLOB: \ - tmp.len=RES_ROWS(_res)[0].values[_c].val.blob_val.len; \ - tmp.s=(char*)RES_ROWS(_res)[0].values[_c].val.blob_val.s; \ - break; \ - default: \ - tmp.len=0; \ - tmp.s=NULL; \ - } \ - if((_sd)->cp + tmp.len >= (_sd)->cbuf + TPS_DATA_SIZE) { \ - LM_ERR("not enough space for %d\n", _c); \ - goto error; \ - } \ - if(tmp.len>0) { \ - (_s)->s = (_sd)->cp; \ - (_s)->len = tmp.len; \ - memcpy((_sd)->cp, tmp.s, tmp.len); \ - (_sd)->cp += tmp.len; \ - (_sd)->cp[0] = '\0'; \ - (_sd)->cp++; \ - } \ - } \ +#define TPS_DATA_APPEND_DB(_sd, _res, _c, _s) \ + do { \ + if(RES_ROWS(_res)[0].values[_c].nul == 0) { \ + str tmp; \ + switch(RES_ROWS(_res)[0].values[_c].type) { \ + case DB1_STRING: \ + tmp.s = (char *)RES_ROWS(_res)[0] \ + .values[_c] \ + .val.string_val; \ + if(tmp.s) { \ + tmp.len = strlen(tmp.s); \ + } else { \ + tmp.len = 0; \ + } \ + break; \ + case DB1_STR: \ + tmp.len = RES_ROWS(_res)[0].values[_c].val.str_val.len; \ + tmp.s = (char *)RES_ROWS(_res)[0] \ + .values[_c] \ + .val.str_val.s; \ + break; \ + case DB1_BLOB: \ + tmp.len = RES_ROWS(_res)[0].values[_c].val.blob_val.len; \ + tmp.s = (char *)RES_ROWS(_res)[0] \ + .values[_c] \ + .val.blob_val.s; \ + break; \ + default: \ + tmp.len = 0; \ + tmp.s = NULL; \ + } \ + if((_sd)->cp + tmp.len >= (_sd)->cbuf + TPS_DATA_SIZE) { \ + LM_ERR("not enough space for %d\n", _c); \ + goto error; \ + } \ + if(tmp.len > 0) { \ + (_s)->s = (_sd)->cp; \ + (_s)->len = tmp.len; \ + memcpy((_sd)->cp, tmp.s, tmp.len); \ + (_sd)->cp += tmp.len; \ + (_sd)->cp[0] = '\0'; \ + (_sd)->cp++; \ + } \ + } \ } while(0); /** * */ -int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, - uint32_t mode) +int tps_db_load_branch( + sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, uint32_t mode) { db_key_t db_keys[5]; - db_op_t db_ops[5]; + db_op_t db_ops[5]; db_val_t db_vals[5]; db_key_t db_cols[TPS_NR_KEYS]; - db1_res_t* db_res = NULL; + db1_res_t *db_res = NULL; str sinv = str_init("INVITE"); str ssub = str_init("SUBSCRIBE"); int bInviteDlg = 1; @@ -1113,7 +1138,7 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, int n; int ret = 0; - if(msg==NULL || md==NULL || sd==NULL || _tps_db_handle==NULL) + if(msg == NULL || md == NULL || sd == NULL || _tps_db_handle == NULL) return -1; nr_keys = 0; @@ -1121,72 +1146,72 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, if((get_cseq(msg)->method_id == METHOD_SUBSCRIBE) || ((get_cseq(msg)->method_id == METHOD_NOTIFY) - && (msg->event && msg->event->len > 0))) { + && (msg->event && msg->event->len > 0))) { bInviteDlg = 0; } - if(mode==0) { + if(mode == 0) { /* load same transaction using Via branch */ - db_keys[nr_keys]=&tt_col_x_vbranch; - db_ops[nr_keys]=OP_EQ; + db_keys[nr_keys] = &tt_col_x_vbranch; + db_ops[nr_keys] = OP_EQ; db_vals[nr_keys].type = DB1_STR; db_vals[nr_keys].nul = 0; db_vals[nr_keys].val.str_val = TPS_STRZ(md->x_vbranch1); nr_keys++; } else { /* load corresponding INVITE transaction using call-id + to-tag */ - db_keys[nr_keys]=&tt_col_a_callid; - db_ops[nr_keys]=OP_EQ; + db_keys[nr_keys] = &tt_col_a_callid; + db_ops[nr_keys] = OP_EQ; db_vals[nr_keys].type = DB1_STR; db_vals[nr_keys].nul = 0; db_vals[nr_keys].val.str_val = TPS_STRZ(md->a_callid); nr_keys++; - db_keys[nr_keys]=&tt_col_b_tag; - db_ops[nr_keys]=OP_EQ; + db_keys[nr_keys] = &tt_col_b_tag; + db_ops[nr_keys] = OP_EQ; db_vals[nr_keys].type = DB1_STR; db_vals[nr_keys].nul = 0; - if(md->direction==TPS_DIR_DOWNSTREAM) { + if(md->direction == TPS_DIR_DOWNSTREAM) { db_vals[nr_keys].val.str_val = TPS_STRZ(md->b_tag); } else { db_vals[nr_keys].val.str_val = TPS_STRZ(md->a_tag); } nr_keys++; - db_keys[nr_keys]=&tt_col_s_method; - db_ops[nr_keys]=OP_EQ; + db_keys[nr_keys] = &tt_col_s_method; + db_ops[nr_keys] = OP_EQ; db_vals[nr_keys].type = DB1_STR; db_vals[nr_keys].nul = 0; db_vals[nr_keys].val.str_val = bInviteDlg ? sinv : ssub; nr_keys++; - if(md->a_uuid.len>0) { - if(md->a_uuid.s[0]=='a') { - db_keys[nr_keys]=&tt_col_a_uuid; - db_ops[nr_keys]=OP_EQ; + if(md->a_uuid.len > 0) { + if(md->a_uuid.s[0] == 'a') { + db_keys[nr_keys] = &tt_col_a_uuid; + db_ops[nr_keys] = OP_EQ; db_vals[nr_keys].type = DB1_STR; db_vals[nr_keys].nul = 0; db_vals[nr_keys].val.str_val = TPS_STRZ(md->a_uuid); nr_keys++; - } else if(md->a_uuid.s[0]=='b') { - db_keys[nr_keys]=&tt_col_b_uuid; - db_ops[nr_keys]=OP_EQ; + } else if(md->a_uuid.s[0] == 'b') { + db_keys[nr_keys] = &tt_col_b_uuid; + db_ops[nr_keys] = OP_EQ; db_vals[nr_keys].type = DB1_STR; db_vals[nr_keys].nul = 0; db_vals[nr_keys].val.str_val = TPS_STRZ(md->a_uuid); nr_keys++; } - } else if(md->b_uuid.len>0) { - if(md->b_uuid.s[0]=='a') { - db_keys[nr_keys]=&tt_col_a_uuid; - db_ops[nr_keys]=OP_EQ; + } else if(md->b_uuid.len > 0) { + if(md->b_uuid.s[0] == 'a') { + db_keys[nr_keys] = &tt_col_a_uuid; + db_ops[nr_keys] = OP_EQ; db_vals[nr_keys].type = DB1_STR; db_vals[nr_keys].nul = 0; db_vals[nr_keys].val.str_val = TPS_STRZ(md->b_uuid); nr_keys++; - } else if(md->b_uuid.s[0]=='b') { - db_keys[nr_keys]=&tt_col_b_uuid; - db_ops[nr_keys]=OP_EQ; + } else if(md->b_uuid.s[0] == 'b') { + db_keys[nr_keys] = &tt_col_b_uuid; + db_ops[nr_keys] = OP_EQ; db_vals[nr_keys].type = DB1_STR; db_vals[nr_keys].nul = 0; db_vals[nr_keys].val.str_val = TPS_STRZ(md->b_uuid); @@ -1195,9 +1220,9 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, } } - if(msg->first_line.type==SIP_REQUEST && md->x_context.len>0) { - db_keys[nr_keys]=&tt_col_x_context; - db_ops[nr_keys]=OP_EQ; + if(msg->first_line.type == SIP_REQUEST && md->x_context.len > 0) { + db_keys[nr_keys] = &tt_col_x_context; + db_ops[nr_keys] = OP_EQ; db_vals[nr_keys].type = DB1_STR; db_vals[nr_keys].nul = 0; db_vals[nr_keys].val.str_val = TPS_STRZ(md->x_context); @@ -1224,29 +1249,30 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, db_cols[nr_cols++] = &tt_col_bs_contact; db_cols[nr_cols++] = &tt_col_a_tag; db_cols[nr_cols++] = &tt_col_b_tag; - if(md->x_context.len>0) { + if(md->x_context.len > 0) { db_cols[nr_cols++] = &tt_col_x_context; } - if (_tpsdbf.use_table(_tps_db_handle, &tt_table_name) < 0) { + if(_tpsdbf.use_table(_tps_db_handle, &tt_table_name) < 0) { LM_ERR("failed to perform use table\n"); return -1; } - if (_tpsdbf.query(_tps_db_handle, db_keys, db_ops, db_vals, db_cols, - nr_keys, nr_cols, NULL, &db_res) < 0) { + if(_tpsdbf.query(_tps_db_handle, db_keys, db_ops, db_vals, db_cols, nr_keys, + nr_cols, NULL, &db_res) + < 0) { LM_ERR("failed to query database\n"); goto error; } - if (RES_ROW_N(db_res) <= 0) { - if(mode==0) { - LM_DBG("no stored record for <%.*s>\n", - md->x_vbranch1.len, ZSW(md->x_vbranch1.s)); + if(RES_ROW_N(db_res) <= 0) { + if(mode == 0) { + LM_DBG("no stored record for <%.*s>\n", md->x_vbranch1.len, + ZSW(md->x_vbranch1.s)); } else { LM_DBG("no stored record for INVITE <%.*s ~ %.*s>\n", - md->a_callid.len, ZSW(md->a_callid.s), - md->b_tag.len, ZSW(md->b_tag.s)); + md->a_callid.len, ZSW(md->a_callid.s), md->b_tag.len, + ZSW(md->b_tag.s)); } ret = 1; goto done; @@ -1256,37 +1282,56 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, n = 0; n++; /*rectime*/ - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_callid); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_uuid); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_uuid); n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_callid); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_uuid); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_uuid); + n++; n++; /*direction*/ - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_via); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_vbranch1); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_rr); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->y_rr); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_rr); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_uri); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_tag); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_method); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_cseq); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_contact); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_contact); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->as_contact); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->bs_contact); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_tag); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_tag); n++; - if(md->x_context.len>0) { - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_context); n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_via); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_vbranch1); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_rr); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->y_rr); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_rr); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_uri); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_tag); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_method); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_cseq); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_contact); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_contact); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->as_contact); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->bs_contact); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_tag); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_tag); + n++; + if(md->x_context.len > 0) { + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_context); + n++; } done: - if ((db_res!=NULL) && _tpsdbf.free_result(_tps_db_handle, db_res)<0) + if((db_res != NULL) && _tpsdbf.free_result(_tps_db_handle, db_res) < 0) LM_ERR("failed to free result of query\n"); return ret; error: - if ((db_res!=NULL) && _tpsdbf.free_result(_tps_db_handle, db_res)<0) + if((db_res != NULL) && _tpsdbf.free_result(_tps_db_handle, db_res) < 0) LM_ERR("failed to free result of query\n"); return -1; @@ -1295,8 +1340,8 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, /** * */ -int tps_storage_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, - uint32_t mode) +int tps_storage_load_branch( + sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, uint32_t mode) { return _tps_storage_api.load_branch(msg, md, sd, mode); } @@ -1307,19 +1352,19 @@ int tps_storage_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, int tps_db_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd) { db_key_t db_keys[5]; - db_op_t db_ops[5]; + db_op_t db_ops[5]; db_val_t db_vals[5]; db_key_t db_cols[TPS_NR_KEYS]; - db1_res_t* db_res = NULL; + db1_res_t *db_res = NULL; int nr_keys; int nr_cols; int n; int ret = 0; - if(msg==NULL || md==NULL || sd==NULL || _tps_db_handle==NULL) + if(msg == NULL || md == NULL || sd == NULL || _tps_db_handle == NULL) return -1; - if(md->a_uuid.len<=0 && md->b_uuid.len<=0) { + if(md->a_uuid.len <= 0 && md->b_uuid.len <= 0) { LM_DBG("no dlg uuid provided\n"); return -1; } @@ -1327,36 +1372,36 @@ int tps_db_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd) nr_keys = 0; nr_cols = 0; - db_ops[nr_keys]=OP_EQ; + db_ops[nr_keys] = OP_EQ; db_vals[nr_keys].type = DB1_STR; db_vals[nr_keys].nul = 0; db_vals[nr_keys].val.str_val.len = 0; - if(md->a_uuid.len>0) { - if(md->a_uuid.s[0]=='a') { - db_keys[nr_keys]=&td_col_a_uuid; + if(md->a_uuid.len > 0) { + if(md->a_uuid.s[0] == 'a') { + db_keys[nr_keys] = &td_col_a_uuid; db_vals[nr_keys].val.str_val = TPS_STRZ(md->a_uuid); - } else if(md->a_uuid.s[0]=='b') { - db_keys[nr_keys]=&td_col_b_uuid; + } else if(md->a_uuid.s[0] == 'b') { + db_keys[nr_keys] = &td_col_b_uuid; db_vals[nr_keys].val.str_val = TPS_STRZ(md->a_uuid); } } else { - if(md->b_uuid.s[0]=='a') { - db_keys[nr_keys]=&td_col_a_uuid; + if(md->b_uuid.s[0] == 'a') { + db_keys[nr_keys] = &td_col_a_uuid; db_vals[nr_keys].val.str_val = TPS_STRZ(md->b_uuid); - } else if(md->b_uuid.s[0]=='b') { - db_keys[nr_keys]=&td_col_b_uuid; + } else if(md->b_uuid.s[0] == 'b') { + db_keys[nr_keys] = &td_col_b_uuid; db_vals[nr_keys].val.str_val = TPS_STRZ(md->b_uuid); } } - if(db_vals[nr_keys].val.str_val.len<=0) { + if(db_vals[nr_keys].val.str_val.len <= 0) { LM_ERR("invalid dlg uuid provided\n"); return -1; } nr_keys++; - if(md->x_context.len>0) { - db_keys[nr_keys]=&td_col_x_context; - db_ops[nr_keys]=OP_EQ; + if(md->x_context.len > 0) { + db_keys[nr_keys] = &td_col_x_context; + db_ops[nr_keys] = OP_EQ; db_vals[nr_keys].type = DB1_STR; db_vals[nr_keys].nul = 0; db_vals[nr_keys].val.str_val = TPS_STRZ(md->x_context); @@ -1384,24 +1429,25 @@ int tps_db_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd) db_cols[nr_cols++] = &td_col_b_srcaddr; db_cols[nr_cols++] = &td_col_s_method; db_cols[nr_cols++] = &td_col_s_cseq; - if(md->x_context.len>0) { + if(md->x_context.len > 0) { db_cols[nr_cols++] = &td_col_x_context; } - if (_tpsdbf.use_table(_tps_db_handle, &td_table_name) < 0) { + if(_tpsdbf.use_table(_tps_db_handle, &td_table_name) < 0) { LM_ERR("failed to perform use table\n"); return -1; } - if (_tpsdbf.query(_tps_db_handle, db_keys, db_ops, db_vals, db_cols, - nr_keys, nr_cols, NULL, &db_res) < 0) { + if(_tpsdbf.query(_tps_db_handle, db_keys, db_ops, db_vals, db_cols, nr_keys, + nr_cols, NULL, &db_res) + < 0) { LM_ERR("failed to query database\n"); goto error; } - if (RES_ROW_N(db_res) <= 0) { - LM_DBG("no stored record for <%.*s>\n", - md->a_uuid.len, ZSW(md->a_uuid.s)); + if(RES_ROW_N(db_res) <= 0) { + LM_DBG("no stored record for <%.*s>\n", md->a_uuid.len, + ZSW(md->a_uuid.s)); ret = 1; goto done; } @@ -1410,38 +1456,58 @@ int tps_db_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd) n = 0; n++; /*rectime*/ - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_callid); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_uuid); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_uuid); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_contact); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_contact); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->as_contact); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->bs_contact); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_tag); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_tag); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_rr); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_rr); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_rr); n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_callid); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_uuid); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_uuid); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_contact); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_contact); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->as_contact); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->bs_contact); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_tag); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_tag); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_rr); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_rr); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_rr); + n++; n++; /*iflags*/ - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_uri); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_uri); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->r_uri); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_srcaddr); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_srcaddr); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_method); n++; - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_cseq); n++; - if(md->x_context.len>0) { - TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_context); n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_uri); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_uri); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->r_uri); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_srcaddr); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_srcaddr); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_method); + n++; + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_cseq); + n++; + if(md->x_context.len > 0) { + TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_context); + n++; } done: - if ((db_res!=NULL) && _tpsdbf.free_result(_tps_db_handle, db_res)<0) + if((db_res != NULL) && _tpsdbf.free_result(_tps_db_handle, db_res) < 0) LM_ERR("failed to free result of query\n"); return ret; error: - if ((db_res!=NULL) && _tpsdbf.free_result(_tps_db_handle, db_res)<0) + if((db_res != NULL) && _tpsdbf.free_result(_tps_db_handle, db_res) < 0) LM_ERR("failed to free result of query\n"); return -1; @@ -1456,46 +1522,46 @@ int tps_storage_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd) } #define TPS_DB_ADD_STRV(dcol, dval, cnr, cname, cval) \ - do { \ - if(cval.len>0) { \ - dcol[cnr] = &cname; \ - dval[cnr].type = DB1_STR; \ - dval[cnr].val.str_val = TPS_STRZ(cval); \ - cnr++; \ - } \ + do { \ + if(cval.len > 0) { \ + dcol[cnr] = &cname; \ + dval[cnr].type = DB1_STR; \ + dval[cnr].val.str_val = TPS_STRZ(cval); \ + cnr++; \ + } \ } while(0) /** * */ -int tps_db_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, - uint32_t mode) +int tps_db_update_branch( + sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, uint32_t mode) { db_key_t db_keys[8]; - db_op_t db_ops[8]; + db_op_t db_ops[8]; db_val_t db_vals[8]; db_key_t db_ucols[TPS_NR_KEYS]; db_val_t db_uvals[TPS_NR_KEYS]; int nr_keys; int nr_ucols; - if(_tps_db_handle==NULL) + if(_tps_db_handle == NULL) return -1; - memset(db_ucols, 0, TPS_NR_KEYS*sizeof(db_key_t)); - memset(db_uvals, 0, TPS_NR_KEYS*sizeof(db_val_t)); + memset(db_ucols, 0, TPS_NR_KEYS * sizeof(db_key_t)); + memset(db_uvals, 0, TPS_NR_KEYS * sizeof(db_val_t)); nr_keys = 0; nr_ucols = 0; - db_keys[nr_keys]=&tt_col_a_uuid; - db_ops[nr_keys]=OP_EQ; + db_keys[nr_keys] = &tt_col_a_uuid; + db_ops[nr_keys] = OP_EQ; db_vals[nr_keys].type = DB1_STR; db_vals[nr_keys].nul = 0; - if(sd->a_uuid.len>0 && sd->a_uuid.s[0]=='a') { + if(sd->a_uuid.len > 0 && sd->a_uuid.s[0] == 'a') { db_vals[nr_keys].val.str_val = TPS_STRZ(sd->a_uuid); } else { - if(sd->b_uuid.len<=0) { + if(sd->b_uuid.len <= 0) { LM_ERR("no valid dlg uuid\n"); return -1; } @@ -1503,9 +1569,9 @@ int tps_db_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, } nr_keys++; - if(sd->x_context.len>0) { - db_keys[nr_keys]=&tt_col_x_context; - db_ops[nr_keys]=OP_EQ; + if(sd->x_context.len > 0) { + db_keys[nr_keys] = &tt_col_x_context; + db_ops[nr_keys] = OP_EQ; db_vals[nr_keys].type = DB1_STR; db_vals[nr_keys].nul = 0; db_vals[nr_keys].val.str_val = TPS_STRZ(sd->x_context); @@ -1513,15 +1579,15 @@ int tps_db_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, } if(mode & TPS_DBU_CONTACT) { - TPS_DB_ADD_STRV(db_ucols, db_uvals, nr_ucols, - tt_col_a_contact, md->a_contact); - TPS_DB_ADD_STRV(db_ucols, db_uvals, nr_ucols, - tt_col_b_contact, md->b_contact); + TPS_DB_ADD_STRV( + db_ucols, db_uvals, nr_ucols, tt_col_a_contact, md->a_contact); + TPS_DB_ADD_STRV( + db_ucols, db_uvals, nr_ucols, tt_col_b_contact, md->b_contact); } - if((mode & TPS_DBU_RPLATTRS) && msg->first_line.type==SIP_REPLY) { - if(msg->first_line.u.reply.statuscode>=180 - && msg->first_line.u.reply.statuscode<200) { + if((mode & TPS_DBU_RPLATTRS) && msg->first_line.type == SIP_REPLY) { + if(msg->first_line.u.reply.statuscode >= 180 + && msg->first_line.u.reply.statuscode < 200) { db_ucols[nr_ucols] = &tt_col_y_rr; db_uvals[nr_ucols].type = DB1_STR; @@ -1532,18 +1598,19 @@ int tps_db_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, db_ucols, db_uvals, nr_ucols, tt_col_b_tag, md->b_tag); } } - if(nr_ucols==0) { + if(nr_ucols == 0) { return 0; } - if (_tpsdbf.use_table(_tps_db_handle, &tt_table_name) < 0) { + if(_tpsdbf.use_table(_tps_db_handle, &tt_table_name) < 0) { LM_ERR("failed to perform use table\n"); return -1; } - if(_tpsdbf.update(_tps_db_handle, db_keys, db_ops, db_vals, - db_ucols, db_uvals, nr_keys, nr_ucols)!=0) { - LM_ERR("failed to do branch db update for [%.*s]!\n", - md->a_uuid.len, md->a_uuid.s); + if(_tpsdbf.update(_tps_db_handle, db_keys, db_ops, db_vals, db_ucols, + db_uvals, nr_keys, nr_ucols) + != 0) { + LM_ERR("failed to do branch db update for [%.*s]!\n", md->a_uuid.len, + md->a_uuid.s); return -1; } @@ -1553,12 +1620,12 @@ int tps_db_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, /** * */ -int tps_storage_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, - uint32_t mode) +int tps_storage_update_branch( + sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, uint32_t mode) { int ret; - if(msg==NULL || md==NULL || sd==NULL) + if(msg == NULL || md == NULL || sd == NULL) return -1; if((md->s_method_id != METHOD_INVITE) @@ -1566,7 +1633,7 @@ int tps_storage_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, return 0; } - if(msg->first_line.type==SIP_REPLY) { + if(msg->first_line.type == SIP_REPLY) { if(msg->first_line.u.reply.statuscode < 180 || msg->first_line.u.reply.statuscode >= 200) { return 0; @@ -1574,7 +1641,8 @@ int tps_storage_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, } ret = tps_storage_link_msg(msg, md, md->direction); - if(ret<0) return -1; + if(ret < 0) + return -1; return _tps_storage_api.update_branch(msg, md, sd, mode); } @@ -1582,46 +1650,46 @@ int tps_storage_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, /** * */ -int tps_db_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, - uint32_t mode) +int tps_db_update_dialog( + sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, uint32_t mode) { db_key_t db_keys[8]; - db_op_t db_ops[8]; + db_op_t db_ops[8]; db_val_t db_vals[8]; db_key_t db_ucols[TPS_NR_KEYS]; db_val_t db_uvals[TPS_NR_KEYS]; int nr_keys; int nr_ucols; - if(_tps_db_handle==NULL) + if(_tps_db_handle == NULL) return -1; - memset(db_ucols, 0, TPS_NR_KEYS*sizeof(db_key_t)); - memset(db_uvals, 0, TPS_NR_KEYS*sizeof(db_val_t)); + memset(db_ucols, 0, TPS_NR_KEYS * sizeof(db_key_t)); + memset(db_uvals, 0, TPS_NR_KEYS * sizeof(db_val_t)); nr_keys = 0; nr_ucols = 0; - db_keys[nr_keys]=&td_col_a_uuid; - db_ops[nr_keys]=OP_EQ; + db_keys[nr_keys] = &td_col_a_uuid; + db_ops[nr_keys] = OP_EQ; db_vals[nr_keys].type = DB1_STR; db_vals[nr_keys].nul = 0; - if(sd->a_uuid.len>0 && sd->a_uuid.s[0]=='a') { + if(sd->a_uuid.len > 0 && sd->a_uuid.s[0] == 'a') { db_vals[nr_keys].val.str_val = TPS_STRZ(sd->a_uuid); } else { - if(sd->b_uuid.len<=0) { - LM_ERR("no valid dlg uuid (%d:%.*s - %d:%.*s)\n", - sd->a_uuid.len, sd->a_uuid.len, ZSW(sd->a_uuid.s), - sd->b_uuid.len, sd->b_uuid.len, ZSW(sd->b_uuid.s)); + if(sd->b_uuid.len <= 0) { + LM_ERR("no valid dlg uuid (%d:%.*s - %d:%.*s)\n", sd->a_uuid.len, + sd->a_uuid.len, ZSW(sd->a_uuid.s), sd->b_uuid.len, + sd->b_uuid.len, ZSW(sd->b_uuid.s)); return -1; } db_vals[nr_keys].val.str_val = TPS_STRZ(sd->b_uuid); } nr_keys++; - if(sd->x_context.len>0) { - db_keys[nr_keys]=&td_col_x_context; - db_ops[nr_keys]=OP_EQ; + if(sd->x_context.len > 0) { + db_keys[nr_keys] = &td_col_x_context; + db_ops[nr_keys] = OP_EQ; db_vals[nr_keys].type = DB1_STR; db_vals[nr_keys].nul = 0; db_vals[nr_keys].val.str_val = TPS_STRZ(sd->x_context); @@ -1629,46 +1697,45 @@ int tps_db_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, } if(mode & TPS_DBU_CONTACT) { - TPS_DB_ADD_STRV(db_ucols, db_uvals, nr_ucols, - td_col_a_contact, md->a_contact); - TPS_DB_ADD_STRV(db_ucols, db_uvals, nr_ucols, - td_col_b_contact, md->b_contact); + TPS_DB_ADD_STRV( + db_ucols, db_uvals, nr_ucols, td_col_a_contact, md->a_contact); + TPS_DB_ADD_STRV( + db_ucols, db_uvals, nr_ucols, td_col_b_contact, md->b_contact); } - if((mode & TPS_DBU_RPLATTRS) && msg->first_line.type==SIP_REPLY) { - if(sd->b_tag.len<=0 - && msg->first_line.u.reply.statuscode>=200 - && msg->first_line.u.reply.statuscode<300) { + if((mode & TPS_DBU_RPLATTRS) && msg->first_line.type == SIP_REPLY) { + if(sd->b_tag.len <= 0 && msg->first_line.u.reply.statuscode >= 200 + && msg->first_line.u.reply.statuscode < 300) { - if((sd->iflags&TPS_IFLAG_DLGON) == 0) { + if((sd->iflags & TPS_IFLAG_DLGON) == 0) { db_ucols[nr_ucols] = &td_col_b_rr; db_uvals[nr_ucols].type = DB1_STR; db_uvals[nr_ucols].val.str_val = TPS_STRZ(md->b_rr); nr_ucols++; } - TPS_DB_ADD_STRV(db_ucols, db_uvals, nr_ucols, - td_col_b_tag, md->b_tag); + TPS_DB_ADD_STRV( + db_ucols, db_uvals, nr_ucols, td_col_b_tag, md->b_tag); db_ucols[nr_ucols] = &td_col_iflags; db_uvals[nr_ucols].type = DB1_INT; - db_uvals[nr_ucols].val.int_val = sd->iflags|TPS_IFLAG_DLGON; + db_uvals[nr_ucols].val.int_val = sd->iflags | TPS_IFLAG_DLGON; nr_ucols++; } } - if(sd->b_tag.len>0 && ((mode & TPS_DBU_BRR) || (mode & TPS_DBU_ARR))) { + if(sd->b_tag.len > 0 && ((mode & TPS_DBU_BRR) || (mode & TPS_DBU_ARR))) { if(((md->direction == TPS_DIR_DOWNSTREAM) - && (msg->first_line.type==SIP_REPLY)) + && (msg->first_line.type == SIP_REPLY)) || ((md->direction == TPS_DIR_UPSTREAM) - && (msg->first_line.type==SIP_REQUEST))) { - if(((sd->iflags&TPS_IFLAG_DLGON) == 0) && (mode & TPS_DBU_BRR)) { + && (msg->first_line.type == SIP_REQUEST))) { + if(((sd->iflags & TPS_IFLAG_DLGON) == 0) && (mode & TPS_DBU_BRR)) { db_ucols[nr_ucols] = &td_col_b_rr; db_uvals[nr_ucols].type = DB1_STR; db_uvals[nr_ucols].val.str_val = TPS_STRZ(md->b_rr); nr_ucols++; } } else { - if(((sd->iflags&TPS_IFLAG_DLGON) == 0) && (mode & TPS_DBU_ARR)) { + if(((sd->iflags & TPS_IFLAG_DLGON) == 0) && (mode & TPS_DBU_ARR)) { db_ucols[nr_ucols] = &td_col_a_rr; db_uvals[nr_ucols].type = DB1_STR; db_uvals[nr_ucols].val.str_val = TPS_STRZ(md->a_rr); @@ -1680,28 +1747,31 @@ int tps_db_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, } } } - if ((mode & TPS_DBU_TIME) && ((sd->b_tag.len > 0) - && ((md->direction == TPS_DIR_UPSTREAM) - && (msg->first_line.type==SIP_REQUEST)) - && (msg->first_line.u.request.method_value == METHOD_SUBSCRIBE))) { + if((mode & TPS_DBU_TIME) + && ((sd->b_tag.len > 0) + && ((md->direction == TPS_DIR_UPSTREAM) + && (msg->first_line.type == SIP_REQUEST)) + && (msg->first_line.u.request.method_value + == METHOD_SUBSCRIBE))) { db_ucols[nr_ucols] = &td_col_rectime; db_uvals[nr_ucols].type = DB1_DATETIME; db_uvals[nr_ucols].val.time_val = time(NULL); nr_ucols++; } - if(nr_ucols==0) { + if(nr_ucols == 0) { return 0; } - if (_tpsdbf.use_table(_tps_db_handle, &td_table_name) < 0) { + if(_tpsdbf.use_table(_tps_db_handle, &td_table_name) < 0) { LM_ERR("failed to perform use table\n"); return -1; } - if(_tpsdbf.update(_tps_db_handle, db_keys, db_ops, db_vals, - db_ucols, db_uvals, nr_keys, nr_ucols)!=0) { - LM_ERR("failed to do dialog db update for [%.*s]!\n", - md->a_uuid.len, md->a_uuid.s); + if(_tpsdbf.update(_tps_db_handle, db_keys, db_ops, db_vals, db_ucols, + db_uvals, nr_keys, nr_ucols) + != 0) { + LM_ERR("failed to do dialog db update for [%.*s]!\n", md->a_uuid.len, + md->a_uuid.s); return -1; } return 0; @@ -1710,18 +1780,19 @@ int tps_db_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, /** * */ -int tps_storage_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, - uint32_t mode) +int tps_storage_update_dialog( + sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, uint32_t mode) { int ret; - if(msg==NULL || md==NULL || sd==NULL) + if(msg == NULL || md == NULL || sd == NULL) return -1; - if((md->s_method_id != METHOD_INVITE) && (md->s_method_id != METHOD_SUBSCRIBE)) { + if((md->s_method_id != METHOD_INVITE) + && (md->s_method_id != METHOD_SUBSCRIBE)) { return 0; } - if(msg->first_line.type==SIP_REPLY) { + if(msg->first_line.type == SIP_REPLY) { if(msg->first_line.u.reply.statuscode < 200 || msg->first_line.u.reply.statuscode >= 300) { return 0; @@ -1729,7 +1800,8 @@ int tps_storage_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, } ret = tps_storage_link_msg(msg, md, md->direction); - if(ret<0) return -1; + if(ret < 0) + return -1; return _tps_storage_api.update_dialog(msg, md, sd, mode); } @@ -1740,35 +1812,35 @@ int tps_storage_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, int tps_db_end_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd) { db_key_t db_keys[4]; - db_op_t db_ops[4]; + db_op_t db_ops[4]; db_val_t db_vals[4]; db_key_t db_ucols[TPS_NR_KEYS]; db_val_t db_uvals[TPS_NR_KEYS]; int nr_keys; int nr_ucols; - if(msg==NULL || md==NULL || sd==NULL || _tps_db_handle==NULL) + if(msg == NULL || md == NULL || sd == NULL || _tps_db_handle == NULL) return -1; - if((md->s_method_id != METHOD_BYE) && !((md->s_method_id == METHOD_SUBSCRIBE) - && (md->expires == 0))) { + if((md->s_method_id != METHOD_BYE) + && !((md->s_method_id == METHOD_SUBSCRIBE) && (md->expires == 0))) { return 0; } - memset(db_ucols, 0, TPS_NR_KEYS*sizeof(db_key_t)); - memset(db_uvals, 0, TPS_NR_KEYS*sizeof(db_val_t)); + memset(db_ucols, 0, TPS_NR_KEYS * sizeof(db_key_t)); + memset(db_uvals, 0, TPS_NR_KEYS * sizeof(db_val_t)); nr_keys = 0; nr_ucols = 0; - db_keys[nr_keys]=&td_col_a_uuid; - db_ops[nr_keys]=OP_EQ; + db_keys[nr_keys] = &td_col_a_uuid; + db_ops[nr_keys] = OP_EQ; db_vals[nr_keys].type = DB1_STR; db_vals[nr_keys].nul = 0; - if(sd->a_uuid.len>0 && sd->a_uuid.s[0]=='a') { + if(sd->a_uuid.len > 0 && sd->a_uuid.s[0] == 'a') { db_vals[nr_keys].val.str_val = TPS_STRZ(sd->a_uuid); } else { - if(sd->b_uuid.len<=0) { + if(sd->b_uuid.len <= 0) { LM_ERR("no valid dlg uuid\n"); return -1; } @@ -1776,9 +1848,9 @@ int tps_db_end_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd) } nr_keys++; - if(sd->x_context.len>0) { - db_keys[nr_keys]=&td_col_x_context; - db_ops[nr_keys]=OP_EQ; + if(sd->x_context.len > 0) { + db_keys[nr_keys] = &td_col_x_context; + db_ops[nr_keys] = OP_EQ; db_vals[nr_keys].type = DB1_STR; db_vals[nr_keys].nul = 0; db_vals[nr_keys].val.str_val = TPS_STRZ(sd->x_context); @@ -1795,15 +1867,16 @@ int tps_db_end_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd) db_uvals[nr_ucols].val.int_val = 0; nr_ucols++; - if (_tpsdbf.use_table(_tps_db_handle, &td_table_name) < 0) { + if(_tpsdbf.use_table(_tps_db_handle, &td_table_name) < 0) { LM_ERR("failed to perform use table\n"); return -1; } - if(_tpsdbf.update(_tps_db_handle, db_keys, db_ops, db_vals, - db_ucols, db_uvals, nr_keys, nr_ucols)!=0) { - LM_ERR("failed to do db update for [%.*s]!\n", - md->a_uuid.len, md->a_uuid.s); + if(_tpsdbf.update(_tps_db_handle, db_keys, db_ops, db_vals, db_ucols, + db_uvals, nr_keys, nr_ucols) + != 0) { + LM_ERR("failed to do db update for [%.*s]!\n", md->a_uuid.len, + md->a_uuid.s); return -1; } return 0; @@ -1820,7 +1893,7 @@ int tps_storage_end_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd) /** * */ -void tps_storage_clean(unsigned int ticks, void* param) +void tps_storage_clean(unsigned int ticks, void *param) { _tps_storage_api.clean_branches(); _tps_storage_api.clean_dialogs(); diff --git a/src/modules/topos/tps_storage.h b/src/modules/topos/tps_storage.h index 0729632183a..4c2585a1ff6 100644 --- a/src/modules/topos/tps_storage.h +++ b/src/modules/topos/tps_storage.h @@ -31,21 +31,22 @@ #include "../../core/parser/msg_parser.h" -#define TPS_DIR_DOWNSTREAM 0 -#define TPS_DIR_UPSTREAM 1 +#define TPS_DIR_DOWNSTREAM 0 +#define TPS_DIR_UPSTREAM 1 -#define TPS_IFLAG_INIT 1 -#define TPS_IFLAG_DLGON 2 +#define TPS_IFLAG_INIT 1 +#define TPS_IFLAG_DLGON 2 -#define TPS_DBU_CONTACT (1<<0) -#define TPS_DBU_RPLATTRS (1<<1) -#define TPS_DBU_ARR (1<<2) -#define TPS_DBU_BRR (1<<3) -#define TPS_DBU_TIME (1<<4) -#define TPS_DBU_ALL (0xffffffff) +#define TPS_DBU_CONTACT (1 << 0) +#define TPS_DBU_RPLATTRS (1 << 1) +#define TPS_DBU_ARR (1 << 2) +#define TPS_DBU_BRR (1 << 3) +#define TPS_DBU_TIME (1 << 4) +#define TPS_DBU_ALL (0xffffffff) -#define TPS_DATA_SIZE 8192 -typedef struct tps_data { +#define TPS_DATA_SIZE 8192 +typedef struct tps_data +{ char cbuf[TPS_DATA_SIZE]; char *cp; str a_uuid; @@ -93,13 +94,13 @@ int tps_storage_branch_save(sip_msg_t *msg, tps_data_t *td); int tps_storage_branch_rm(sip_msg_t *msg, tps_data_t *td); int tps_storage_record(sip_msg_t *msg, tps_data_t *td, int dialog, int dir); -int tps_storage_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, - uint32_t mode); -int tps_storage_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, - uint32_t mode); +int tps_storage_load_branch( + sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, uint32_t mode); +int tps_storage_update_branch( + sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, uint32_t mode); int tps_storage_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd); -int tps_storage_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, - uint32_t mode); +int tps_storage_update_dialog( + sip_msg_t *msg, tps_data_t *md, tps_data_t *sd, uint32_t mode); int tps_storage_end_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd); int tps_storage_lock_set_init(void); @@ -109,6 +110,6 @@ int tps_storage_lock_set_destroy(void); int tps_storage_link_msg(sip_msg_t *msg, tps_data_t *td, int dir); -void tps_storage_clean(unsigned int ticks, void* param); +void tps_storage_clean(unsigned int ticks, void *param); #endif