|
@@ -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 @@ error:
|
|
|
*/
|
|
|
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 @@ done:
|
|
|
*/
|
|
|
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;
|