|
@@ -65,7 +65,7 @@ MODULE_VERSION
|
|
/** module parameters */
|
|
/** module parameters */
|
|
str _th_key = str_init("aL9.n8~Hm]Z");
|
|
str _th_key = str_init("aL9.n8~Hm]Z");
|
|
str th_cookie_name = str_init("TH"); /* lost parameter? */
|
|
str th_cookie_name = str_init("TH"); /* lost parameter? */
|
|
-str th_cookie_value = {0, 0}; /* lost parameter? */
|
|
|
|
|
|
+str th_cookie_value = {0, 0}; /* lost parameter? */
|
|
str th_ip = str_init("127.0.0.8");
|
|
str th_ip = str_init("127.0.0.8");
|
|
str th_uparam_name = str_init("line");
|
|
str th_uparam_name = str_init("line");
|
|
str th_uparam_prefix = str_init("sr-");
|
|
str th_uparam_prefix = str_init("sr-");
|
|
@@ -88,14 +88,14 @@ sanity_api_t scb;
|
|
|
|
|
|
int th_msg_received(sr_event_param_t *evp);
|
|
int th_msg_received(sr_event_param_t *evp);
|
|
int th_msg_sent(sr_event_param_t *evp);
|
|
int th_msg_sent(sr_event_param_t *evp);
|
|
-int th_execute_event_route(sip_msg_t *msg, sr_event_param_t *evp,
|
|
|
|
- int evtype, int evidx, str *evname);
|
|
|
|
|
|
+int th_execute_event_route(sip_msg_t *msg, sr_event_param_t *evp, int evtype,
|
|
|
|
+ int evidx, str *evname);
|
|
|
|
|
|
/** module functions */
|
|
/** module functions */
|
|
static int mod_init(void);
|
|
static int mod_init(void);
|
|
|
|
|
|
#define TH_EVENTRT_OUTGOING 1
|
|
#define TH_EVENTRT_OUTGOING 1
|
|
-#define TH_EVENTRT_SENDING 2
|
|
|
|
|
|
+#define TH_EVENTRT_SENDING 2
|
|
static int _th_eventrt_mode = TH_EVENTRT_OUTGOING | TH_EVENTRT_SENDING;
|
|
static int _th_eventrt_mode = TH_EVENTRT_OUTGOING | TH_EVENTRT_SENDING;
|
|
static int _th_eventrt_outgoing = -1;
|
|
static int _th_eventrt_outgoing = -1;
|
|
static str _th_eventrt_callback = STR_NULL;
|
|
static str _th_eventrt_callback = STR_NULL;
|
|
@@ -103,42 +103,37 @@ static str _th_eventrt_outgoing_name = str_init("topoh:msg-outgoing");
|
|
static int _th_eventrt_sending = -1;
|
|
static int _th_eventrt_sending = -1;
|
|
static str _th_eventrt_sending_name = str_init("topoh:msg-sending");
|
|
static str _th_eventrt_sending_name = str_init("topoh:msg-sending");
|
|
|
|
|
|
-static param_export_t params[]={
|
|
|
|
- {"mask_key", PARAM_STR, &_th_key},
|
|
|
|
- {"mask_ip", PARAM_STR, &th_ip},
|
|
|
|
- {"mask_callid", PARAM_INT, &th_param_mask_callid},
|
|
|
|
- {"mask_mode", PARAM_INT, &th_param_mask_mode},
|
|
|
|
- {"uparam_name", PARAM_STR, &th_uparam_name},
|
|
|
|
- {"uparam_prefix", PARAM_STR, &th_uparam_prefix},
|
|
|
|
- {"vparam_name", PARAM_STR, &th_vparam_name},
|
|
|
|
- {"vparam_prefix", PARAM_STR, &th_vparam_prefix},
|
|
|
|
- {"callid_prefix", PARAM_STR, &th_callid_prefix},
|
|
|
|
- {"sanity_checks", PARAM_INT, &th_sanity_checks},
|
|
|
|
- {"uri_prefix_checks", PARAM_INT, &th_uri_prefix_checks},
|
|
|
|
- {"event_callback", PARAM_STR, &_th_eventrt_callback},
|
|
|
|
- {"event_mode", PARAM_INT, &_th_eventrt_mode},
|
|
|
|
- {"use_mode", PARAM_INT, &_th_use_mode},
|
|
|
|
- {0,0,0}
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-static cmd_export_t cmds[]={
|
|
|
|
- {"bind_topoh", (cmd_function)bind_topoh, 0,
|
|
|
|
- 0, 0, 0},
|
|
|
|
- {0, 0, 0, 0, 0, 0}
|
|
|
|
-};
|
|
|
|
|
|
+static param_export_t params[] = {{"mask_key", PARAM_STR, &_th_key},
|
|
|
|
+ {"mask_ip", PARAM_STR, &th_ip},
|
|
|
|
+ {"mask_callid", PARAM_INT, &th_param_mask_callid},
|
|
|
|
+ {"mask_mode", PARAM_INT, &th_param_mask_mode},
|
|
|
|
+ {"uparam_name", PARAM_STR, &th_uparam_name},
|
|
|
|
+ {"uparam_prefix", PARAM_STR, &th_uparam_prefix},
|
|
|
|
+ {"vparam_name", PARAM_STR, &th_vparam_name},
|
|
|
|
+ {"vparam_prefix", PARAM_STR, &th_vparam_prefix},
|
|
|
|
+ {"callid_prefix", PARAM_STR, &th_callid_prefix},
|
|
|
|
+ {"sanity_checks", PARAM_INT, &th_sanity_checks},
|
|
|
|
+ {"uri_prefix_checks", PARAM_INT, &th_uri_prefix_checks},
|
|
|
|
+ {"event_callback", PARAM_STR, &_th_eventrt_callback},
|
|
|
|
+ {"event_mode", PARAM_INT, &_th_eventrt_mode},
|
|
|
|
+ {"use_mode", PARAM_INT, &_th_use_mode}, {0, 0, 0}};
|
|
|
|
+
|
|
|
|
+static cmd_export_t cmds[] = {
|
|
|
|
+ {"bind_topoh", (cmd_function)bind_topoh, 0, 0, 0, 0},
|
|
|
|
+ {0, 0, 0, 0, 0, 0}};
|
|
|
|
|
|
/** module exports */
|
|
/** module exports */
|
|
-struct module_exports exports= {
|
|
|
|
- "topoh", /* 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 init function */
|
|
|
|
- 0, /* per-child init function */
|
|
|
|
- 0 /* module destroy function */
|
|
|
|
|
|
+struct module_exports exports = {
|
|
|
|
+ "topoh", /* 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 init function */
|
|
|
|
+ 0, /* per-child init function */
|
|
|
|
+ 0 /* module destroy function */
|
|
};
|
|
};
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -149,38 +144,34 @@ static int mod_init(void)
|
|
sip_uri_t puri;
|
|
sip_uri_t puri;
|
|
char buri[MAX_URI_SIZE];
|
|
char buri[MAX_URI_SIZE];
|
|
|
|
|
|
- if(_th_use_mode==1) {
|
|
|
|
|
|
+ if(_th_use_mode == 1) {
|
|
/* use in library mode, not for processing sip messages */
|
|
/* use in library mode, not for processing sip messages */
|
|
th_mask_init();
|
|
th_mask_init();
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
_th_eventrt_outgoing = route_lookup(&event_rt, _th_eventrt_outgoing_name.s);
|
|
_th_eventrt_outgoing = route_lookup(&event_rt, _th_eventrt_outgoing_name.s);
|
|
- if(_th_eventrt_outgoing<0
|
|
|
|
- || event_rt.rlist[_th_eventrt_outgoing]==NULL) {
|
|
|
|
|
|
+ if(_th_eventrt_outgoing < 0
|
|
|
|
+ || event_rt.rlist[_th_eventrt_outgoing] == NULL) {
|
|
_th_eventrt_outgoing = -1;
|
|
_th_eventrt_outgoing = -1;
|
|
}
|
|
}
|
|
_th_eventrt_sending = route_lookup(&event_rt, _th_eventrt_sending_name.s);
|
|
_th_eventrt_sending = route_lookup(&event_rt, _th_eventrt_sending_name.s);
|
|
- if(_th_eventrt_sending<0
|
|
|
|
- || event_rt.rlist[_th_eventrt_sending]==NULL) {
|
|
|
|
|
|
+ if(_th_eventrt_sending < 0 || event_rt.rlist[_th_eventrt_sending] == NULL) {
|
|
_th_eventrt_sending = -1;
|
|
_th_eventrt_sending = -1;
|
|
}
|
|
}
|
|
|
|
|
|
- if(faked_msg_init()<0) {
|
|
|
|
|
|
+ if(faked_msg_init() < 0) {
|
|
LM_ERR("failed to init fmsg\n");
|
|
LM_ERR("failed to init fmsg\n");
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
- if(th_sanity_checks!=0)
|
|
|
|
- {
|
|
|
|
- if(sanity_load_api(&scb)<0)
|
|
|
|
- {
|
|
|
|
|
|
+ if(th_sanity_checks != 0) {
|
|
|
|
+ if(sanity_load_api(&scb) < 0) {
|
|
LM_ERR("cannot bind to sanity module\n");
|
|
LM_ERR("cannot bind to sanity module\n");
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if(th_ip.len<=0)
|
|
|
|
- {
|
|
|
|
|
|
+ if(th_ip.len <= 0) {
|
|
LM_ERR("mask IP parameter is invalid\n");
|
|
LM_ERR("mask IP parameter is invalid\n");
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
@@ -190,57 +181,54 @@ static int mod_init(void)
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
memcpy(buri, "sip:", 4);
|
|
memcpy(buri, "sip:", 4);
|
|
- memcpy(buri+4, th_ip.s, th_ip.len);
|
|
|
|
- buri[th_ip.len+8] = '\0';
|
|
|
|
|
|
+ memcpy(buri + 4, th_ip.s, th_ip.len);
|
|
|
|
+ buri[th_ip.len + 8] = '\0';
|
|
|
|
|
|
- if(parse_uri(buri, th_ip.len+4, &puri)<0) {
|
|
|
|
|
|
+ if(parse_uri(buri, th_ip.len + 4, &puri) < 0) {
|
|
LM_ERR("mask uri is invalid\n");
|
|
LM_ERR("mask uri is invalid\n");
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
- if(check_self(&puri.host, puri.port_no, 0)==1)
|
|
|
|
- {
|
|
|
|
|
|
+ if(check_self(&puri.host, puri.port_no, 0) == 1) {
|
|
th_mask_addr_myself = 1;
|
|
th_mask_addr_myself = 1;
|
|
- LM_INFO("mask address matches myself [%.*s]\n",
|
|
|
|
- th_ip.len, th_ip.s);
|
|
|
|
|
|
+ LM_INFO("mask address matches myself [%.*s]\n", th_ip.len, th_ip.s);
|
|
}
|
|
}
|
|
|
|
|
|
/* 'SIP/2.0/UDP ' + ip + ';' + param + '=' + prefix (+ '\0') */
|
|
/* 'SIP/2.0/UDP ' + ip + ';' + param + '=' + prefix (+ '\0') */
|
|
- th_via_prefix.len = 12 + th_ip.len + 1 + th_vparam_name.len + 1
|
|
|
|
- + th_vparam_prefix.len;
|
|
|
|
- th_via_prefix.s = (char*)pkg_malloc(th_via_prefix.len+1);
|
|
|
|
- if(th_via_prefix.s==NULL)
|
|
|
|
- {
|
|
|
|
|
|
+ th_via_prefix.len =
|
|
|
|
+ 12 + th_ip.len + 1 + th_vparam_name.len + 1 + th_vparam_prefix.len;
|
|
|
|
+ th_via_prefix.s = (char *)pkg_malloc(th_via_prefix.len + 1);
|
|
|
|
+ if(th_via_prefix.s == NULL) {
|
|
PKG_MEM_ERROR_FMT("via prefix parameter\n");
|
|
PKG_MEM_ERROR_FMT("via prefix parameter\n");
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
/* 'sip:' + ip + ';' + param + '=' + prefix (+ '\0') */
|
|
/* 'sip:' + ip + ';' + param + '=' + prefix (+ '\0') */
|
|
- th_uri_prefix.len = 4 + th_ip.len + 1 + th_uparam_name.len + 1
|
|
|
|
- + th_uparam_prefix.len;
|
|
|
|
- th_uri_prefix.s = (char*)pkg_malloc(th_uri_prefix.len+1);
|
|
|
|
- if(th_uri_prefix.s==NULL)
|
|
|
|
- {
|
|
|
|
|
|
+ th_uri_prefix.len =
|
|
|
|
+ 4 + th_ip.len + 1 + th_uparam_name.len + 1 + th_uparam_prefix.len;
|
|
|
|
+ th_uri_prefix.s = (char *)pkg_malloc(th_uri_prefix.len + 1);
|
|
|
|
+ if(th_uri_prefix.s == NULL) {
|
|
pkg_free(th_via_prefix.s);
|
|
pkg_free(th_via_prefix.s);
|
|
PKG_MEM_ERROR_FMT("uri prefix parameter\n");
|
|
PKG_MEM_ERROR_FMT("uri prefix parameter\n");
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
/* build via prefix */
|
|
/* build via prefix */
|
|
memcpy(th_via_prefix.s, "SIP/2.0/UDP ", 12);
|
|
memcpy(th_via_prefix.s, "SIP/2.0/UDP ", 12);
|
|
- memcpy(th_via_prefix.s+12, th_ip.s, th_ip.len);
|
|
|
|
- th_via_prefix.s[12+th_ip.len] = ';';
|
|
|
|
- memcpy(th_via_prefix.s+12+th_ip.len+1, th_vparam_name.s,
|
|
|
|
|
|
+ memcpy(th_via_prefix.s + 12, th_ip.s, th_ip.len);
|
|
|
|
+ th_via_prefix.s[12 + th_ip.len] = ';';
|
|
|
|
+ memcpy(th_via_prefix.s + 12 + th_ip.len + 1, th_vparam_name.s,
|
|
th_vparam_name.len);
|
|
th_vparam_name.len);
|
|
- th_via_prefix.s[12+th_ip.len+1+th_vparam_name.len] = '=';
|
|
|
|
- memcpy(th_via_prefix.s+12+th_ip.len+1+th_vparam_name.len+1,
|
|
|
|
|
|
+ th_via_prefix.s[12 + th_ip.len + 1 + th_vparam_name.len] = '=';
|
|
|
|
+ memcpy(th_via_prefix.s + 12 + th_ip.len + 1 + th_vparam_name.len + 1,
|
|
th_vparam_prefix.s, th_vparam_prefix.len);
|
|
th_vparam_prefix.s, th_vparam_prefix.len);
|
|
th_via_prefix.s[th_via_prefix.len] = '\0';
|
|
th_via_prefix.s[th_via_prefix.len] = '\0';
|
|
LM_DBG("VIA prefix: [%s]\n", th_via_prefix.s);
|
|
LM_DBG("VIA prefix: [%s]\n", th_via_prefix.s);
|
|
/* build uri prefix */
|
|
/* build uri prefix */
|
|
memcpy(th_uri_prefix.s, "sip:", 4);
|
|
memcpy(th_uri_prefix.s, "sip:", 4);
|
|
- memcpy(th_uri_prefix.s+4, th_ip.s, th_ip.len);
|
|
|
|
- th_uri_prefix.s[4+th_ip.len] = ';';
|
|
|
|
- memcpy(th_uri_prefix.s+4+th_ip.len+1, th_uparam_name.s, th_uparam_name.len);
|
|
|
|
- th_uri_prefix.s[4+th_ip.len+1+th_uparam_name.len] = '=';
|
|
|
|
- memcpy(th_uri_prefix.s+4+th_ip.len+1+th_uparam_name.len+1,
|
|
|
|
|
|
+ memcpy(th_uri_prefix.s + 4, th_ip.s, th_ip.len);
|
|
|
|
+ th_uri_prefix.s[4 + th_ip.len] = ';';
|
|
|
|
+ memcpy(th_uri_prefix.s + 4 + th_ip.len + 1, th_uparam_name.s,
|
|
|
|
+ th_uparam_name.len);
|
|
|
|
+ th_uri_prefix.s[4 + th_ip.len + 1 + th_uparam_name.len] = '=';
|
|
|
|
+ memcpy(th_uri_prefix.s + 4 + th_ip.len + 1 + th_uparam_name.len + 1,
|
|
th_uparam_prefix.s, th_uparam_prefix.len);
|
|
th_uparam_prefix.s, th_uparam_prefix.len);
|
|
th_uri_prefix.s[th_uri_prefix.len] = '\0';
|
|
th_uri_prefix.s[th_uri_prefix.len] = '\0';
|
|
LM_DBG("URI prefix: [%s]\n", th_uri_prefix.s);
|
|
LM_DBG("URI prefix: [%s]\n", th_uri_prefix.s);
|
|
@@ -261,22 +249,18 @@ error:
|
|
*/
|
|
*/
|
|
int th_prepare_msg(sip_msg_t *msg)
|
|
int th_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!");
|
|
LM_DBG("outbuf buffer parsing failed!");
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
- if(msg->first_line.type==SIP_REQUEST)
|
|
|
|
- {
|
|
|
|
- if(!IS_SIP(msg))
|
|
|
|
- {
|
|
|
|
|
|
+ if(msg->first_line.type == SIP_REQUEST) {
|
|
|
|
+ if(!IS_SIP(msg)) {
|
|
LM_DBG("non sip request message\n");
|
|
LM_DBG("non sip request message\n");
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
- } else if(msg->first_line.type==SIP_REPLY) {
|
|
|
|
- if(!IS_SIP_REPLY(msg))
|
|
|
|
- {
|
|
|
|
|
|
+ } else if(msg->first_line.type == SIP_REPLY) {
|
|
|
|
+ if(!IS_SIP_REPLY(msg)) {
|
|
LM_DBG("non sip reply message\n");
|
|
LM_DBG("non sip reply message\n");
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
@@ -285,41 +269,35 @@ int th_prepare_msg(sip_msg_t *msg)
|
|
return 1;
|
|
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;
|
|
return 2;
|
|
}
|
|
}
|
|
|
|
|
|
/* force 2nd via parsing here - it helps checking it later */
|
|
/* force 2nd via parsing here - it helps checking it later */
|
|
- if (parse_headers(msg, HDR_VIA2_F, 0)==-1
|
|
|
|
- || (msg->via2==0) || (msg->via2->error!=PARSE_OK))
|
|
|
|
- {
|
|
|
|
|
|
+ if(parse_headers(msg, HDR_VIA2_F, 0) == -1 || (msg->via2 == 0)
|
|
|
|
+ || (msg->via2->error != PARSE_OK)) {
|
|
LM_DBG("no second via in this message \n");
|
|
LM_DBG("no second via in this message \n");
|
|
}
|
|
}
|
|
|
|
|
|
- if(parse_from_header(msg)<0)
|
|
|
|
- {
|
|
|
|
|
|
+ if(parse_from_header(msg) < 0) {
|
|
LM_ERR("cannot parse FROM header\n");
|
|
LM_ERR("cannot parse FROM header\n");
|
|
return 3;
|
|
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");
|
|
LM_ERR("cannot parse TO header\n");
|
|
return 3;
|
|
return 3;
|
|
}
|
|
}
|
|
|
|
|
|
- if(get_to(msg)==NULL)
|
|
|
|
- {
|
|
|
|
|
|
+ if(get_to(msg) == NULL) {
|
|
LM_ERR("cannot get TO header\n");
|
|
LM_ERR("cannot get TO header\n");
|
|
return 3;
|
|
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;
|
|
return 4;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -337,72 +315,61 @@ int th_msg_received(sr_event_param_t *evp)
|
|
int direction;
|
|
int direction;
|
|
int dialog;
|
|
int dialog;
|
|
|
|
|
|
- obuf = (str*)evp->data;
|
|
|
|
|
|
+ obuf = (str *)evp->data;
|
|
memset(&msg, 0, sizeof(sip_msg_t));
|
|
memset(&msg, 0, sizeof(sip_msg_t));
|
|
msg.buf = obuf->s;
|
|
msg.buf = obuf->s;
|
|
msg.len = obuf->len;
|
|
msg.len = obuf->len;
|
|
|
|
|
|
- if(th_prepare_msg(&msg)!=0)
|
|
|
|
- {
|
|
|
|
|
|
+ if(th_prepare_msg(&msg) != 0) {
|
|
goto done;
|
|
goto done;
|
|
}
|
|
}
|
|
|
|
|
|
- if(th_skip_msg(&msg))
|
|
|
|
- {
|
|
|
|
|
|
+ if(th_skip_msg(&msg)) {
|
|
goto done;
|
|
goto done;
|
|
}
|
|
}
|
|
|
|
|
|
direction = 0;
|
|
direction = 0;
|
|
th_cookie_value.s = "xx";
|
|
th_cookie_value.s = "xx";
|
|
th_cookie_value.len = 2;
|
|
th_cookie_value.len = 2;
|
|
- if(msg.first_line.type==SIP_REQUEST)
|
|
|
|
- {
|
|
|
|
- if(th_sanity_checks!=0)
|
|
|
|
- {
|
|
|
|
- if(scb.check_defaults(&msg)<1)
|
|
|
|
- {
|
|
|
|
|
|
+ if(msg.first_line.type == SIP_REQUEST) {
|
|
|
|
+ if(th_sanity_checks != 0) {
|
|
|
|
+ if(scb.check_defaults(&msg) < 1) {
|
|
LM_ERR("sanity checks failed\n");
|
|
LM_ERR("sanity checks failed\n");
|
|
goto done;
|
|
goto done;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- dialog = (get_to(&msg)->tag_value.len>0)?1:0;
|
|
|
|
- if(dialog)
|
|
|
|
- {
|
|
|
|
|
|
+ dialog = (get_to(&msg)->tag_value.len > 0) ? 1 : 0;
|
|
|
|
+ if(dialog) {
|
|
direction = th_route_direction(&msg);
|
|
direction = th_route_direction(&msg);
|
|
- if(direction<0)
|
|
|
|
- {
|
|
|
|
|
|
+ if(direction < 0) {
|
|
LM_ERR("not able to detect direction\n");
|
|
LM_ERR("not able to detect direction\n");
|
|
goto done;
|
|
goto done;
|
|
}
|
|
}
|
|
- th_cookie_value.s = (direction==0)?"dc":"uc";
|
|
|
|
|
|
+ th_cookie_value.s = (direction == 0) ? "dc" : "uc";
|
|
} else {
|
|
} else {
|
|
th_cookie_value.s = "di";
|
|
th_cookie_value.s = "di";
|
|
}
|
|
}
|
|
- if(dialog)
|
|
|
|
- {
|
|
|
|
|
|
+ if(dialog) {
|
|
/* dialog request */
|
|
/* dialog request */
|
|
th_unmask_ruri(&msg);
|
|
th_unmask_ruri(&msg);
|
|
th_unmask_route(&msg);
|
|
th_unmask_route(&msg);
|
|
th_unmask_refer_to(&msg);
|
|
th_unmask_refer_to(&msg);
|
|
- if(direction==1)
|
|
|
|
- {
|
|
|
|
|
|
+ if(direction == 1) {
|
|
th_unmask_callid(&msg);
|
|
th_unmask_callid(&msg);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
/* reply */
|
|
/* reply */
|
|
- if(msg.via2==0)
|
|
|
|
- {
|
|
|
|
|
|
+ if(msg.via2 == 0) {
|
|
/* one Via in received reply -- it is for local generated request
|
|
/* one Via in received reply -- it is for local generated request
|
|
* - nothing to unhide unless is CANCEL/ACK */
|
|
* - nothing to unhide unless is CANCEL/ACK */
|
|
- if(!((get_cseq(&msg)->method_id)&(METHOD_CANCEL)))
|
|
|
|
|
|
+ if(!((get_cseq(&msg)->method_id) & (METHOD_CANCEL)))
|
|
goto done;
|
|
goto done;
|
|
}
|
|
}
|
|
|
|
|
|
th_unmask_via(&msg, &th_cookie_value);
|
|
th_unmask_via(&msg, &th_cookie_value);
|
|
th_flip_record_route(&msg, 0);
|
|
th_flip_record_route(&msg, 0);
|
|
- if(th_cookie_value.s[0]=='u')
|
|
|
|
- {
|
|
|
|
|
|
+ if(th_cookie_value.s[0] == 'u') {
|
|
th_cookie_value.s = "dc";
|
|
th_cookie_value.s = "dc";
|
|
} else {
|
|
} else {
|
|
th_cookie_value.s = "uc";
|
|
th_cookie_value.s = "uc";
|
|
@@ -414,10 +381,9 @@ int th_msg_received(sr_event_param_t *evp)
|
|
LM_DBG("adding cookie: %.*s\n", th_cookie_value.len, th_cookie_value.s);
|
|
LM_DBG("adding cookie: %.*s\n", th_cookie_value.len, th_cookie_value.s);
|
|
|
|
|
|
th_add_cookie(&msg);
|
|
th_add_cookie(&msg);
|
|
- nbuf = th_msg_update(&msg, (unsigned int*)&obuf->len);
|
|
|
|
|
|
+ nbuf = th_msg_update(&msg, (unsigned int *)&obuf->len);
|
|
|
|
|
|
- if(obuf->len>=BUF_SIZE)
|
|
|
|
- {
|
|
|
|
|
|
+ if(obuf->len >= BUF_SIZE) {
|
|
LM_ERR("new buffer overflow (%d)\n", obuf->len);
|
|
LM_ERR("new buffer overflow (%d)\n", obuf->len);
|
|
pkg_free(nbuf);
|
|
pkg_free(nbuf);
|
|
return -1;
|
|
return -1;
|
|
@@ -426,7 +392,7 @@ int th_msg_received(sr_event_param_t *evp)
|
|
obuf->s[obuf->len] = '\0';
|
|
obuf->s[obuf->len] = '\0';
|
|
|
|
|
|
done:
|
|
done:
|
|
- if(nbuf!=NULL)
|
|
|
|
|
|
+ if(nbuf != NULL)
|
|
pkg_free(nbuf);
|
|
pkg_free(nbuf);
|
|
free_sip_msg(&msg);
|
|
free_sip_msg(&msg);
|
|
return 0;
|
|
return 0;
|
|
@@ -444,10 +410,11 @@ int th_msg_sent(sr_event_param_t *evp)
|
|
int local;
|
|
int local;
|
|
str nbuf = STR_NULL;
|
|
str nbuf = STR_NULL;
|
|
|
|
|
|
- obuf = (str*)evp->data;
|
|
|
|
|
|
+ obuf = (str *)evp->data;
|
|
|
|
|
|
if(th_execute_event_route(NULL, evp, TH_EVENTRT_OUTGOING,
|
|
if(th_execute_event_route(NULL, evp, TH_EVENTRT_OUTGOING,
|
|
- _th_eventrt_outgoing, &_th_eventrt_outgoing_name)==1) {
|
|
|
|
|
|
+ _th_eventrt_outgoing, &_th_eventrt_outgoing_name)
|
|
|
|
+ == 1) {
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -455,7 +422,7 @@ int th_msg_sent(sr_event_param_t *evp)
|
|
msg.buf = obuf->s;
|
|
msg.buf = obuf->s;
|
|
msg.len = obuf->len;
|
|
msg.len = obuf->len;
|
|
|
|
|
|
- if(th_prepare_msg(&msg)!=0) {
|
|
|
|
|
|
+ if(th_prepare_msg(&msg) != 0) {
|
|
goto done;
|
|
goto done;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -465,35 +432,39 @@ int th_msg_sent(sr_event_param_t *evp)
|
|
|
|
|
|
th_cookie_value.s = th_get_cookie(&msg, &th_cookie_value.len);
|
|
th_cookie_value.s = th_get_cookie(&msg, &th_cookie_value.len);
|
|
LM_DBG("the COOKIE is [%.*s]\n", th_cookie_value.len, th_cookie_value.s);
|
|
LM_DBG("the COOKIE is [%.*s]\n", th_cookie_value.len, th_cookie_value.s);
|
|
- if(th_cookie_value.s[0]!='x') {
|
|
|
|
|
|
+ if(th_cookie_value.s[0] != 'x') {
|
|
th_del_cookie(&msg);
|
|
th_del_cookie(&msg);
|
|
}
|
|
}
|
|
|
|
|
|
if(th_execute_event_route(&msg, evp, TH_EVENTRT_SENDING,
|
|
if(th_execute_event_route(&msg, evp, TH_EVENTRT_SENDING,
|
|
- _th_eventrt_sending, &_th_eventrt_sending_name)==1) {
|
|
|
|
|
|
+ _th_eventrt_sending, &_th_eventrt_sending_name)
|
|
|
|
+ == 1) {
|
|
goto done;
|
|
goto done;
|
|
}
|
|
}
|
|
|
|
|
|
- if(msg.first_line.type==SIP_REQUEST) {
|
|
|
|
- direction = (th_cookie_value.s[0]=='u')?1:0; /* upstream/downstram */
|
|
|
|
- dialog = (get_to(&msg)->tag_value.len>0)?1:0;
|
|
|
|
|
|
+ if(msg.first_line.type == SIP_REQUEST) {
|
|
|
|
+ direction =
|
|
|
|
+ (th_cookie_value.s[0] == 'u') ? 1 : 0; /* upstream/downstram */
|
|
|
|
+ dialog = (get_to(&msg)->tag_value.len > 0) ? 1 : 0;
|
|
|
|
|
|
- if(msg.via2==0) {
|
|
|
|
|
|
+ if(msg.via2 == 0) {
|
|
local = 1;
|
|
local = 1;
|
|
- if(direction==0 && th_cookie_value.s[1]=='l') {
|
|
|
|
|
|
+ if(direction == 0 && th_cookie_value.s[1] == 'l') {
|
|
/* downstream local request (e.g., dlg bye) */
|
|
/* downstream local request (e.g., dlg bye) */
|
|
local = 2;
|
|
local = 2;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
/* more than one Via, but no received th cookie */
|
|
/* more than one Via, but no received th cookie */
|
|
- local = (th_cookie_value.s[0]!='d' && th_cookie_value.s[0]!='u')?1:0;
|
|
|
|
|
|
+ local = (th_cookie_value.s[0] != 'd' && th_cookie_value.s[0] != 'u')
|
|
|
|
+ ? 1
|
|
|
|
+ : 0;
|
|
}
|
|
}
|
|
/* local generated requests */
|
|
/* local generated requests */
|
|
if(local) {
|
|
if(local) {
|
|
/* ACK and CANCEL go downstream */
|
|
/* 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) {
|
|
th_mask_callid(&msg);
|
|
th_mask_callid(&msg);
|
|
goto ready;
|
|
goto ready;
|
|
} else {
|
|
} else {
|
|
@@ -506,7 +477,7 @@ int th_msg_sent(sr_event_param_t *evp)
|
|
th_mask_record_route(&msg);
|
|
th_mask_record_route(&msg);
|
|
if(dialog) {
|
|
if(dialog) {
|
|
/* dialog request */
|
|
/* dialog request */
|
|
- if(direction==0) {
|
|
|
|
|
|
+ if(direction == 0) {
|
|
/* downstream */
|
|
/* downstream */
|
|
th_mask_callid(&msg);
|
|
th_mask_callid(&msg);
|
|
}
|
|
}
|
|
@@ -517,13 +488,13 @@ int th_msg_sent(sr_event_param_t *evp)
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
/* reply */
|
|
/* reply */
|
|
- if(th_cookie_value.s[th_cookie_value.len-1]=='x') {
|
|
|
|
|
|
+ if(th_cookie_value.s[th_cookie_value.len - 1] == 'x') {
|
|
/* ?!?! - we should have a cookie in any reply case */
|
|
/* ?!?! - we should have a cookie in any reply case */
|
|
goto done;
|
|
goto done;
|
|
}
|
|
}
|
|
- if(th_cookie_value.s[th_cookie_value.len-1]=='v') {
|
|
|
|
|
|
+ if(th_cookie_value.s[th_cookie_value.len - 1] == 'v') {
|
|
/* reply generated locally - direction was set by request */
|
|
/* reply generated locally - direction was set by request */
|
|
- if(th_cookie_value.s[0]=='u') {
|
|
|
|
|
|
+ if(th_cookie_value.s[0] == 'u') {
|
|
th_mask_callid(&msg);
|
|
th_mask_callid(&msg);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
@@ -533,15 +504,15 @@ int th_msg_sent(sr_event_param_t *evp)
|
|
|| msg.first_line.u.reply.statuscode > 399) {
|
|
|| msg.first_line.u.reply.statuscode > 399) {
|
|
th_mask_contact(&msg);
|
|
th_mask_contact(&msg);
|
|
}
|
|
}
|
|
- if(th_cookie_value.s[0]=='d') {
|
|
|
|
|
|
+ if(th_cookie_value.s[0] == 'd') {
|
|
th_mask_callid(&msg);
|
|
th_mask_callid(&msg);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
ready:
|
|
ready:
|
|
- nbuf.s = th_msg_update(&msg, (unsigned int*)&nbuf.len);
|
|
|
|
- if(nbuf.s!=NULL) {
|
|
|
|
|
|
+ nbuf.s = th_msg_update(&msg, (unsigned int *)&nbuf.len);
|
|
|
|
+ if(nbuf.s != NULL) {
|
|
LM_DBG("new outbound buffer generated\n");
|
|
LM_DBG("new outbound buffer generated\n");
|
|
pkg_free(obuf->s);
|
|
pkg_free(obuf->s);
|
|
obuf->s = nbuf.s;
|
|
obuf->s = nbuf.s;
|
|
@@ -558,8 +529,8 @@ done:
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
-int th_execute_event_route(sip_msg_t *msg, sr_event_param_t *evp,
|
|
|
|
- int evtype, int evidx, str *evname)
|
|
|
|
|
|
+int th_execute_event_route(sip_msg_t *msg, sr_event_param_t *evp, int evtype,
|
|
|
|
+ int evidx, str *evname)
|
|
{
|
|
{
|
|
struct sip_msg *fmsg;
|
|
struct sip_msg *fmsg;
|
|
struct run_act_ctx ctx;
|
|
struct run_act_ctx ctx;
|
|
@@ -571,10 +542,10 @@ int th_execute_event_route(sip_msg_t *msg, sr_event_param_t *evp,
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
- if(evidx<0) {
|
|
|
|
- if(_th_eventrt_callback.s!=NULL || _th_eventrt_callback.len>0) {
|
|
|
|
|
|
+ if(evidx < 0) {
|
|
|
|
+ if(_th_eventrt_callback.s != NULL || _th_eventrt_callback.len > 0) {
|
|
keng = sr_kemi_eng_get();
|
|
keng = sr_kemi_eng_get();
|
|
- if(keng==NULL) {
|
|
|
|
|
|
+ if(keng == NULL) {
|
|
LM_DBG("event callback (%s) set, but no cfg engine\n",
|
|
LM_DBG("event callback (%s) set, but no cfg engine\n",
|
|
_th_eventrt_callback.s);
|
|
_th_eventrt_callback.s);
|
|
goto done;
|
|
goto done;
|
|
@@ -582,17 +553,16 @@ int th_execute_event_route(sip_msg_t *msg, sr_event_param_t *evp,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if(evidx<0 && keng==NULL) {
|
|
|
|
|
|
+ if(evidx < 0 && keng == NULL) {
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
- LM_DBG("executing event_route[topoh:...] (%d)\n",
|
|
|
|
- _th_eventrt_outgoing);
|
|
|
|
|
|
+ LM_DBG("executing event_route[topoh:...] (%d)\n", _th_eventrt_outgoing);
|
|
fmsg = faked_msg_next();
|
|
fmsg = faked_msg_next();
|
|
|
|
|
|
onsnd_info.to = &evp->dst->to;
|
|
onsnd_info.to = &evp->dst->to;
|
|
onsnd_info.send_sock = evp->dst->send_sock;
|
|
onsnd_info.send_sock = evp->dst->send_sock;
|
|
- if(msg!=NULL) {
|
|
|
|
|
|
+ if(msg != NULL) {
|
|
onsnd_info.buf = msg->buf;
|
|
onsnd_info.buf = msg->buf;
|
|
onsnd_info.len = msg->len;
|
|
onsnd_info.len = msg->len;
|
|
onsnd_info.msg = msg;
|
|
onsnd_info.msg = msg;
|
|
@@ -606,36 +576,37 @@ int th_execute_event_route(sip_msg_t *msg, sr_event_param_t *evp,
|
|
rtb = get_route_type();
|
|
rtb = get_route_type();
|
|
set_route_type(REQUEST_ROUTE);
|
|
set_route_type(REQUEST_ROUTE);
|
|
init_run_actions_ctx(&ctx);
|
|
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 {
|
|
} else {
|
|
- if(keng!=NULL) {
|
|
|
|
- if(sr_kemi_ctx_route(keng, &ctx, (msg)?msg:fmsg, EVENT_ROUTE,
|
|
|
|
- &_th_eventrt_callback, evname)<0) {
|
|
|
|
|
|
+ if(keng != NULL) {
|
|
|
|
+ if(sr_kemi_ctx_route(keng, &ctx, (msg) ? msg : fmsg, EVENT_ROUTE,
|
|
|
|
+ &_th_eventrt_callback, evname)
|
|
|
|
+ < 0) {
|
|
LM_ERR("error running event route kemi callback\n");
|
|
LM_ERR("error running event route kemi callback\n");
|
|
- p_onsend=NULL;
|
|
|
|
|
|
+ p_onsend = NULL;
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set_route_type(rtb);
|
|
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");
|
|
LM_DBG("exit due to 'drop' in event route\n");
|
|
- p_onsend=NULL;
|
|
|
|
|
|
+ p_onsend = NULL;
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
done:
|
|
done:
|
|
- p_onsend=NULL;
|
|
|
|
|
|
+ p_onsend = NULL;
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
-int bind_topoh(topoh_api_t* api)
|
|
|
|
|
|
+int bind_topoh(topoh_api_t *api)
|
|
{
|
|
{
|
|
- if (!api) {
|
|
|
|
|
|
+ if(!api) {
|
|
ERR("Invalid parameter value\n");
|
|
ERR("Invalid parameter value\n");
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|