Pressed send too soon, here is the patch missing from previous mail. Comments
welcome.
Alex.
On Tuesday 06 September 2011, Alex Hermann wrote:
> On Tuesday 06 September 2011, Klaus Darilion wrote:
> > Am 06.09.2011 12:19, schrieb Alex Hermann:
> > > On Tuesday 06 September 2011, Alex Hermann wrote:
> > >> There seems to be another issue, sorry for the noise.
> > >
> > > Or not...
> > >
> > > When the contact has no <>, these are added by the add_contact_alias()
> > > function, but as header parameters instead of uri paramater. My
> > > attempted fix doesn't work either.
> > >
> > > I think the problem is with the lumps. When the <> are missing, 3 lumps
> > > are added to the contact: "<", ">" and ";alias=X" parameter, which
> > > seems to mess up the position of the alias parameter. This looks like
> > > the infamous problem that one can't manipulate the same part of the
> > > message multiple times.
> >
> > Maybe you can workaround it by adding just 2 lumps? E.g. "<" and
> > ";alias=X>".
>
> That might work. Just have to make sure that existing parameters in the
> contact without <> have to be moved outside the > because they are header
> parameters (according to rfc3261 section 20, last paragraph).
>
> If i understood correctly the following cases must be supported:
>
> These go wrong at the moment:
>
> Contact: sip:192.168.1.10:5678
> should become
> Contact: <sip:192.168.1.10:5678;alias=X>
>
> Contact: sip:192.168.1.10:5678;header-param
> should become
> Contact: <sip:192.168.1.10:5678;alias=X>header-param
>
>
> These are already correctly supported:
>
> Contact: <sip:192.168.1.10:5678>
> should become
> Contact: <sip:192.168.1.10:5678;alias=X>
>
> Contact: <sip:192.168.1.10:5678;uri-param>
> should become
> Contact: <sip:192.168.1.10:5678;alias=X;uri-param>
>
> Contact: <sip:192.168.1.10:5678>;header-param
> should become
> Contact: <sip:192.168.1.10:5678;alias=X>header-param
>
> Contact: <sip:192.168.1.10:5678;uri-param>;header-param
> should become
> Contact: <sip:192.168.1.10:5678;alias=X;uri-param>header-param
diff --git a/modules_k/nathelper/nathelper.c b/modules_k/nathelper/nathelper.c
index 35328a3..5972622 100644
--- a/modules_k/nathelper/nathelper.c
+++ b/modules_k/nathelper/nathelper.c
@@ -790,7 +790,7 @@ add_contact_alias_f(struct sip_msg* msg, char* str1, char* str2)
struct lump *anchor;
struct sip_uri uri;
struct ip_addr *ip;
- char *lt, *gt, *param, *at, *port, *start;
+ char *bracket, *lt, *param, *at, *port, *start;
/* Do nothing if Contact header does not exist */
if (!msg->contact) {
@@ -827,9 +827,9 @@ add_contact_alias_f(struct sip_msg* msg, char* str1, char* str2)
}
/* Check if Contact URI needs to be enclosed in <>s */
- lt = gt = param = NULL;
- at = memchr(msg->contact->body.s, '<', msg->contact->body.len);
- if (at == NULL) {
+ bracket = memchr(msg->contact->body.s, '<', msg->contact->body.len);
+ if (bracket == NULL) {
+ /* add opening < */
lt = (char*)pkg_malloc(1);
if (!lt) {
LM_ERR("no pkg memory left for lt sign\n");
@@ -845,33 +845,18 @@ add_contact_alias_f(struct sip_msg* msg, char* str1, char* str2)
LM_ERR("insert_new_lump_before for \"<\" failed\n");
goto err;
}
- gt = (char*)pkg_malloc(1);
- if (!gt) {
- LM_ERR("no pkg memory left for gt sign\n");
- goto err;
- }
- *gt = '>';
- anchor = anchor_lump(msg, msg->contact->body.s +
- msg->contact->body.len - msg->buf, 0, 0);
- if (anchor == NULL) {
- LM_ERR("anchor_lump for end of contact body failed\n");
- goto err;
- }
- if (insert_new_lump_before(anchor, gt, 1, 0) == 0) {
- LM_ERR("insert_new_lump_before for \">\" failed\n");
- goto err;
- }
}
/* Create ;alias param */
param_len = SALIAS_LEN + IP6_MAX_STR_SIZE + 1 /* ~ */ + 5 /* port */ +
- 1 /* ~ */ + 1 /* proto */;
+ 1 /* ~ */ + 1 /* proto */ + 1 /* closing > */;
param = (char*)pkg_malloc(param_len);
if (!param) {
LM_ERR("no pkg memory left for alias param\n");
goto err;
}
at = param;
+ /* ip address */
append_str(at, SALIAS, SALIAS_LEN);
ip_len = ip_addr2sbuf(&(msg->rcv.src_ip), at, param_len - SALIAS_LEN);
if (ip_len <= 0) {
@@ -879,24 +864,30 @@ add_contact_alias_f(struct sip_msg* msg, char* str1, char* str2)
goto err;
}
at = at + ip_len;
+ /* port */
append_chr(at, '~');
port = int2str(msg->rcv.src_port, &len);
append_str(at, port, len);
+ /* proto */
append_chr(at, '~');
if ((msg->rcv.proto < PROTO_UDP) || (msg->rcv.proto > PROTO_SCTP)) {
LM_ERR("invalid transport protocol\n");
goto err;
}
append_chr(at, msg->rcv.proto + '0');
+ /* closing > */
+ if (bracket == NULL) {
+ append_chr(at, '>');
+ }
param_len = at - param;
+
+ /* Add ;alias param */
LM_DBG("adding param <%.*s>\n", param_len, param);
if (uri.port.len > 0) {
start = uri.port.s + uri.port.len;
} else {
start = uri.host.s + uri.host.len;
}
-
- /* Add ;alias param */
anchor = anchor_lump(msg, start - msg->buf, 0, 0);
if (anchor == NULL) {
LM_ERR("anchor_lump for ;alias param failed\n");
@@ -910,7 +901,6 @@ add_contact_alias_f(struct sip_msg* msg, char* str1, char* str2)
err:
if (lt) pkg_free(lt);
- if (gt) pkg_free(gt);
if (param) pkg_free(param);
return -1;
}
_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev