diff --git a/src/modules/topos/topos_mod.c b/src/modules/topos/topos_mod.c index 0d36058188c..8bde83ba826 100644 --- a/src/modules/topos/topos_mod.c +++ b/src/modules/topos/topos_mod.c @@ -56,12 +56,15 @@ #include "../../core/onsend.h" #include "../../core/mod_fix.h" #include "../../core/kemi.h" +#include "../../core/data_lump.h" #include "../../lib/srdb1/db.h" #include "../../core/utils/sruid.h" #include "../../modules/sanity/api.h" +#include "../topoh/api.h" + #include "tps_storage.h" #include "tps_msg.h" #include "api.h" @@ -91,6 +94,8 @@ str _tps_methods_nocontact_list = str_init(""); extern unsigned int _tps_methods_noinitial; str _tps_methods_noinitial_list = str_init(""); +static topoh_api_t thb = {0}; + int _tps_clean_interval = 60; #define TPS_EVENTRT_OUTGOING 1 @@ -276,6 +281,14 @@ static int mod_init(void) " 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) { + LM_ERR("cannot bind to topoh API\n"); + return -1; + } + } sr_event_register_cb(SREV_NET_DATA_IN, tps_msg_received); sr_event_register_cb(SREV_NET_DATA_OUT, tps_msg_sent); @@ -737,4 +750,110 @@ int mod_register(char *path, int *dlflags, void *p1, void *p2) return 0; } +/** + * MASK CallID + */ + +int tps_mask_callid(sip_msg_t *msg) +{ + struct lump* l; + str out; + str in; + + if(_tps_param_mask_callid==0) + return 0; + + if(msg->callid==NULL) + { + LM_ERR("cannot get Call-Id header\n"); + return -1; + } + LM_DBG("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"); + return -1; + } + + + LM_DBG("Updated CALL-ID : [%.*s]\n",out.len, out.s); + 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) + { + LM_ERR("failed deleting callid\n"); + pkg_free(out.s); + return -1; + } + 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; + } + + return 0; +} + +/** + * UNMASK CallID + */ +int tps_unmask_callid(sip_msg_t *msg) +{ + struct lump* l; + str out; + str in; + int umask_ret; + + + if(_tps_param_mask_callid==0) + return 0; + + if(msg->callid==NULL) + { + LM_ERR("cannot get Call-Id header\n"); + return -1; + } + + + + LM_DBG("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; + }else if(umask_ret != 0) { + LM_ERR("cannot decode callid\n"); + return -1; + } + LM_DBG("Updated (unmasked) CALL-ID : [%.*s]\n",out.len, out.s); + 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) + { + LM_ERR("failed deleting callid\n"); + pkg_free(out.s); + return -1; + } + 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; + } + + return 0; +} + + /** @} */ diff --git a/src/modules/topos/tps_msg.c b/src/modules/topos/tps_msg.c index a11d544f777..4e5491366f4 100644 --- a/src/modules/topos/tps_msg.c +++ b/src/modules/topos/tps_msg.c @@ -43,6 +43,8 @@ #include "../../core/parser/parse_via.h" #include "../../core/parser/contact/parse_contact.h" #include "../../core/parser/parse_refer_to.h" + + #include "tps_msg.h" #include "tps_storage.h" @@ -882,7 +884,10 @@ int tps_request_received(sip_msg_t *msg, int dialog) LM_ERR("failed to extract and pack the headers\n"); return -1; } - + + tps_unmask_callid(msg); + LM_DBG("Request message after CALLID Unmask-> [%.*s] \n",msg->len,msg->buf); + ret = tps_dlg_message_update(msg, &mtsd, _tps_contact_mode); if(ret<0) { LM_ERR("failed to update on dlg message\n"); @@ -1017,13 +1022,16 @@ int tps_response_received(sip_msg_t *msg) memset(&mtsd, 0, sizeof(tps_data_t)); memset(&stsd, 0, sizeof(tps_data_t)); memset(&btsd, 0, sizeof(tps_data_t)); - - lkey = msg->callid->body; - + if(tps_pack_message(msg, &mtsd)<0) { LM_ERR("failed to extract and pack the headers\n"); return -1; } + tps_unmask_callid(msg); + LM_DBG("Response message after CALLID Unmask-> [%.*s] \n",msg->len,msg->buf); + + lkey = msg->callid->body; + tps_storage_lock_get(&lkey); if(tps_storage_load_branch(msg, &mtsd, &btsd, 0)<0) { goto error; @@ -1089,7 +1097,12 @@ int tps_request_sent(sip_msg_t *msg, int dialog, int local) if(dialog!=0) { if(tps_get_xuuid(msg, &xuuid)<0) { - LM_DBG("no x-uuid header - nothing to do\n"); + 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) { + tps_mask_callid(msg); + } return 0; } mtsd.a_uuid = xuuid; @@ -1157,6 +1170,13 @@ int tps_request_sent(sip_msg_t *msg, int dialog, int local) done: tps_storage_lock_release(&lkey); + /*DownStream Request sent MASK CALLID */ + if(direction == TPS_DIR_DOWNSTREAM) { + /* mask CallID */ + tps_mask_callid(msg); + LM_DBG("SENT message after CALLID CHG->[%.*s] \n",msg->len,msg->buf); + } + return 0; error: @@ -1253,6 +1273,13 @@ int tps_response_sent(sip_msg_t *msg) if(tps_storage_update_dialog(msg, &mtsd, &stsd, TPS_DBU_CONTACT)<0) { goto error1; } + + /*DownStream Response sent MASK CALLID */ + if(direction == TPS_DIR_UPSTREAM) { + /* mask CallID */ + tps_mask_callid(msg); + LM_DBG("SENT Response message after CALLID CHG->[%.*s] \n",msg->len,msg->buf); + } return 0; error: diff --git a/src/modules/topos/tps_msg.h b/src/modules/topos/tps_msg.h index 93f768462fe..3ff06894759 100644 --- a/src/modules/topos/tps_msg.h +++ b/src/modules/topos/tps_msg.h @@ -43,4 +43,6 @@ int tps_request_received(sip_msg_t *msg, int dialog); int tps_response_received(sip_msg_t *msg); int tps_request_sent(sip_msg_t *msg, int dialog, int local); int tps_response_sent(sip_msg_t *msg); +int tps_mask_callid(sip_msg_t *msg); +int tps_unmask_callid(sip_msg_t *msg); #endif