|
@@ -1,6 +1,4 @@
|
|
/**
|
|
/**
|
|
- * $Id$
|
|
|
|
- *
|
|
|
|
* Copyright (C) 2009 SIP-Router.org
|
|
* Copyright (C) 2009 SIP-Router.org
|
|
*
|
|
*
|
|
* This file is part of Extensible SIP Router, a free SIP server.
|
|
* This file is part of Extensible SIP Router, a free SIP server.
|
|
@@ -44,7 +42,9 @@
|
|
#include "../../tcp_options.h"
|
|
#include "../../tcp_options.h"
|
|
#include "../../ut.h"
|
|
#include "../../ut.h"
|
|
#include "../../forward.h"
|
|
#include "../../forward.h"
|
|
|
|
+#include "../../config.h"
|
|
#include "../../parser/msg_parser.h"
|
|
#include "../../parser/msg_parser.h"
|
|
|
|
+#include "../../parser/parse_uri.h"
|
|
#include "../../parser/parse_to.h"
|
|
#include "../../parser/parse_to.h"
|
|
#include "../../parser/parse_from.h"
|
|
#include "../../parser/parse_from.h"
|
|
|
|
|
|
@@ -60,7 +60,7 @@ MODULE_VERSION
|
|
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("10.1.1.10");
|
|
|
|
|
|
+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-");
|
|
str th_vparam_name = str_init("branch");
|
|
str th_vparam_name = str_init("branch");
|
|
@@ -74,6 +74,7 @@ int th_param_mask_callid = 0;
|
|
|
|
|
|
int th_sanity_checks = 0;
|
|
int th_sanity_checks = 0;
|
|
sanity_api_t scb;
|
|
sanity_api_t scb;
|
|
|
|
+int th_mask_addr_myself = 0;
|
|
|
|
|
|
int th_msg_received(void *data);
|
|
int th_msg_received(void *data);
|
|
int th_msg_sent(void *data);
|
|
int th_msg_sent(void *data);
|
|
@@ -84,13 +85,13 @@ static int mod_init(void);
|
|
static param_export_t params[]={
|
|
static param_export_t params[]={
|
|
{"mask_key", PARAM_STR, &_th_key},
|
|
{"mask_key", PARAM_STR, &_th_key},
|
|
{"mask_ip", PARAM_STR, &th_ip},
|
|
{"mask_ip", PARAM_STR, &th_ip},
|
|
- {"mask_callid", INT_PARAM, &th_param_mask_callid},
|
|
|
|
|
|
+ {"mask_callid", PARAM_INT, &th_param_mask_callid},
|
|
{"uparam_name", PARAM_STR, &th_uparam_name},
|
|
{"uparam_name", PARAM_STR, &th_uparam_name},
|
|
{"uparam_prefix", PARAM_STR, &th_uparam_prefix},
|
|
{"uparam_prefix", PARAM_STR, &th_uparam_prefix},
|
|
{"vparam_name", PARAM_STR, &th_vparam_name},
|
|
{"vparam_name", PARAM_STR, &th_vparam_name},
|
|
{"vparam_prefix", PARAM_STR, &th_vparam_prefix},
|
|
{"vparam_prefix", PARAM_STR, &th_vparam_prefix},
|
|
{"callid_prefix", PARAM_STR, &th_callid_prefix},
|
|
{"callid_prefix", PARAM_STR, &th_callid_prefix},
|
|
- {"sanity_checks", INT_PARAM, &th_sanity_checks},
|
|
|
|
|
|
+ {"sanity_checks", PARAM_INT, &th_sanity_checks},
|
|
{0,0,0}
|
|
{0,0,0}
|
|
};
|
|
};
|
|
|
|
|
|
@@ -116,6 +117,9 @@ struct module_exports exports= {
|
|
*/
|
|
*/
|
|
static int mod_init(void)
|
|
static int mod_init(void)
|
|
{
|
|
{
|
|
|
|
+ sip_uri_t puri;
|
|
|
|
+ char buri[MAX_URI_SIZE];
|
|
|
|
+
|
|
if(th_sanity_checks!=0)
|
|
if(th_sanity_checks!=0)
|
|
{
|
|
{
|
|
if(sanity_load_api(&scb)<0)
|
|
if(sanity_load_api(&scb)<0)
|
|
@@ -129,11 +133,25 @@ static int mod_init(void)
|
|
LM_ERR("mask IP parameter is invalid\n");
|
|
LM_ERR("mask IP parameter is invalid\n");
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
- if(check_self(&th_ip, 0, 0)==1)
|
|
|
|
- {
|
|
|
|
- LM_ERR("mask IP must be different than SIP server local IP\n");
|
|
|
|
|
|
+
|
|
|
|
+ if(th_ip.len + 32 >= MAX_URI_SIZE) {
|
|
|
|
+ LM_ERR("mask address is too long\n");
|
|
|
|
+ goto error;
|
|
|
|
+ }
|
|
|
|
+ memcpy(buri, "sip:", 4);
|
|
|
|
+ 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) {
|
|
|
|
+ LM_ERR("mask uri is invalid\n");
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
|
|
+ if(check_self(&puri.host, puri.port_no, 0)==1)
|
|
|
|
+ {
|
|
|
|
+ th_mask_addr_myself = 1;
|
|
|
|
+ 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_via_prefix.len = 12 + th_ip.len + 1 + th_vparam_name.len + 1
|
|
@@ -328,6 +346,8 @@ int th_msg_received(void *data)
|
|
th_cookie_value.len = 2;
|
|
th_cookie_value.len = 2;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ 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);
|
|
|
|
|