... | ... |
@@ -57,6 +57,7 @@ const static char *proto_strings[] = { |
57 | 57 |
}; |
58 | 58 |
|
59 | 59 |
extern int path_sockname_mode; |
60 |
+extern str path_received_name; |
|
60 | 61 |
|
61 | 62 |
static char *path_strzdup(char *src, int len) |
62 | 63 |
{ |
... | ... |
@@ -105,8 +106,9 @@ static int prepend_path(sip_msg_t* _m, str *user, path_param_t param, |
105 | 106 |
struct hdr_field *hf; |
106 | 107 |
|
107 | 108 |
/* maximum possible length of suffix */ |
108 |
- suffix_len = sizeof(";lr;r2=on;received=sip::12345%3Btransport%3Dsctp;ob;>\r\n") |
|
109 |
- + IP_ADDR_MAX_STR_SIZE + 2 + (add_params ? add_params->len : 0) + 1; |
|
109 |
+ suffix_len = sizeof(";lr;r2=on;=sip::12345%3Btransport%3Dsctp;ob;>\r\n") |
|
110 |
+ + IP_ADDR_MAX_STR_SIZE + 2 + (add_params ? add_params->len : 0) |
|
111 |
+ + path_received_name.len + 1; |
|
110 | 112 |
|
111 | 113 |
cp = suffix = pkg_malloc(suffix_len); |
112 | 114 |
if (!suffix) { |
... | ... |
@@ -125,21 +127,21 @@ static int prepend_path(sip_msg_t* _m, str *user, path_param_t param, |
125 | 127 |
proto_str = NULL; |
126 | 128 |
} |
127 | 129 |
if(_m->rcv.src_ip.af==AF_INET6) { |
128 |
- cp += sprintf(cp, ";received=sip:[%s]:%hu%s", |
|
130 |
+ cp += sprintf(cp, ";%s=sip:[%s]:%hu%s", path_received_name.s, |
|
129 | 131 |
ip_addr2a(&_m->rcv.src_ip), |
130 | 132 |
_m->rcv.src_port, proto_str ? : ""); |
131 | 133 |
} else { |
132 |
- cp += sprintf(cp, ";received=sip:%s:%hu%s" |
|
133 |
- , ip_addr2a(&_m->rcv.src_ip), |
|
134 |
+ cp += sprintf(cp, ";%s=sip:%s:%hu%s", path_received_name.s, |
|
135 |
+ ip_addr2a(&_m->rcv.src_ip), |
|
134 | 136 |
_m->rcv.src_port, proto_str ? : ""); |
135 | 137 |
} |
136 | 138 |
} else { |
137 | 139 |
if(_m->rcv.src_ip.af==AF_INET6) { |
138 |
- cp += sprintf(cp, ";received=[%s]~%hu~%d", |
|
140 |
+ cp += sprintf(cp, ";%s=[%s]~%hu~%d", path_received_name.s, |
|
139 | 141 |
ip_addr2a(&_m->rcv.src_ip), |
140 | 142 |
_m->rcv.src_port, (int)_m->rcv.proto); |
141 | 143 |
} else { |
142 |
- cp += sprintf(cp, ";received=%s~%hu~%d", |
|
144 |
+ cp += sprintf(cp, ";%s=%s~%hu~%d", path_received_name.s, |
|
143 | 145 |
ip_addr2a(&_m->rcv.src_ip), |
144 | 146 |
_m->rcv.src_port, (int)_m->rcv.proto); |
145 | 147 |
} |
... | ... |
@@ -375,35 +377,58 @@ void path_rr_callback(struct sip_msg *_m, str *r_param, void *cb_param) |
375 | 377 |
{ |
376 | 378 |
param_hooks_t hooks; |
377 | 379 |
param_t *params; |
380 |
+ param_t *it; |
|
378 | 381 |
static char dst_uri_buf[MAX_URI_SIZE]; |
379 | 382 |
static str dst_uri; |
380 | 383 |
char *p; |
381 | 384 |
int n; |
382 | 385 |
int nproto; |
383 | 386 |
str sproto; |
387 |
+ str rcvuri = STR_NULL; |
|
384 | 388 |
|
385 |
- if (parse_params(r_param, CLASS_CONTACT, &hooks, ¶ms) != 0) { |
|
386 |
- LM_ERR("failed to parse route parameters\n"); |
|
387 |
- return; |
|
388 |
- } |
|
389 |
- |
|
390 |
- if (hooks.contact.received==NULL |
|
391 |
- || hooks.contact.received->body.len<=0) { |
|
392 |
- LM_DBG("no received parameter in route header\n"); |
|
393 |
- free_params(params); |
|
394 |
- return; |
|
389 |
+ if((path_received_name.len==8) |
|
390 |
+ && strncmp(path_received_name.s, "received", 8)==0) { |
|
391 |
+ if (parse_params(r_param, CLASS_CONTACT, &hooks, ¶ms) != 0) { |
|
392 |
+ LM_ERR("failed to parse route parameters\n"); |
|
393 |
+ return; |
|
394 |
+ } |
|
395 |
+ if (hooks.contact.received==NULL |
|
396 |
+ || hooks.contact.received->body.len<=0) { |
|
397 |
+ LM_DBG("no received parameter in route header\n"); |
|
398 |
+ free_params(params); |
|
399 |
+ return; |
|
400 |
+ } |
|
401 |
+ rcvuri = hooks.contact.received->body; |
|
402 |
+ } else { |
|
403 |
+ if (parse_params(r_param, CLASS_ANY, &hooks, ¶ms) != 0) { |
|
404 |
+ LM_ERR("failed to parse route parameters\n"); |
|
405 |
+ return; |
|
406 |
+ } |
|
407 |
+ for(it=params; it; it=it->next) { |
|
408 |
+ if((it->name.len==path_received_name.len) |
|
409 |
+ && strncmp(path_received_name.s, it->name.s, |
|
410 |
+ it->name.len)==0) { |
|
411 |
+ break; |
|
412 |
+ } |
|
413 |
+ } |
|
414 |
+ if (it==NULL || it->body.len<=0) { |
|
415 |
+ LM_DBG("no %s parameter in route header\n", path_received_name.s); |
|
416 |
+ free_params(params); |
|
417 |
+ return; |
|
418 |
+ } |
|
419 |
+ rcvuri = it->body; |
|
395 | 420 |
} |
396 | 421 |
|
397 | 422 |
/* 24 => sip:...;transport=sctp */ |
398 |
- if(hooks.contact.received->body.len + 24 >= MAX_URI_SIZE) { |
|
399 |
- LM_ERR("received uri is too long\n"); |
|
423 |
+ if(rcvuri.len + 24 >= MAX_URI_SIZE) { |
|
424 |
+ LM_ERR("received uri is too long: %d\n", rcvuri.len); |
|
400 | 425 |
goto done; |
401 | 426 |
} |
402 | 427 |
dst_uri.s = dst_uri_buf; |
403 | 428 |
dst_uri.len = MAX_URI_SIZE; |
404 | 429 |
if(path_received_format==0) { |
405 | 430 |
/* received=sip:...;transport... */ |
406 |
- if (unescape_user(&(hooks.contact.received->body), &dst_uri) < 0) { |
|
431 |
+ if (unescape_user(&rcvuri, &dst_uri) < 0) { |
|
407 | 432 |
LM_ERR("unescaping received failed\n"); |
408 | 433 |
free_params(params); |
409 | 434 |
return; |
... | ... |
@@ -411,9 +436,8 @@ void path_rr_callback(struct sip_msg *_m, str *r_param, void *cb_param) |
411 | 436 |
} else { |
412 | 437 |
/* received=ip~port~proto */ |
413 | 438 |
memcpy(dst_uri_buf, "sip:", 4); |
414 |
- memcpy(dst_uri_buf+4, hooks.contact.received->body.s, |
|
415 |
- hooks.contact.received->body.len); |
|
416 |
- dst_uri_buf[4+hooks.contact.received->body.len] = '\0'; |
|
439 |
+ memcpy(dst_uri_buf+4, rcvuri.s, rcvuri.len); |
|
440 |
+ dst_uri_buf[4+rcvuri.len] = '\0'; |
|
417 | 441 |
p = dst_uri_buf + 4; |
418 | 442 |
n = 0; |
419 | 443 |
while(*p!='\0') { |
... | ... |
@@ -67,6 +67,7 @@ int path_use_received = 0; |
67 | 67 |
int path_received_format = 0; |
68 | 68 |
int path_enable_r2 = 0; |
69 | 69 |
int path_sockname_mode = 0; |
70 |
+str path_received_name = str_init("received"); |
|
70 | 71 |
|
71 | 72 |
/*! \brief |
72 | 73 |
* Module initialization function prototype |
... | ... |
@@ -111,6 +112,7 @@ static param_export_t params[] = { |
111 | 112 |
{"received_format", INT_PARAM, &path_received_format }, |
112 | 113 |
{"enable_r2", INT_PARAM, &path_enable_r2 }, |
113 | 114 |
{"sockname_mode", INT_PARAM, &path_sockname_mode }, |
115 |
+ {"received_name", PARAM_STR, &path_received_name }, |
|
114 | 116 |
{ 0, 0, 0 } |
115 | 117 |
}; |
116 | 118 |
|