Is there a disadvantage of this function vs add_contact_alias()? If not,
maybe we should always use set_contact_alias() instead of
add_contact_alias().
klaus
On 04.10.2013 10:56, Daniel-Constantin Mierla wrote:
Module: sip-router
Branch: master
Commit: 58659b0cabb623c6420c186755c968b4550ff09c
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=58659b0…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Thu Oct 3 09:16:38 2013 +0200
nathelper: add_contact_alias() new function for adding alias parameter to contact uri
- similar to add_contact_alias(), but this works like
fix_nated_contact(), in the way that new contact uri is immediately
visible to other modules (e.g., dialog, presence)
---
modules/nathelper/nathelper.c | 70 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 70 insertions(+), 0 deletions(-)
diff --git a/modules/nathelper/nathelper.c b/modules/nathelper/nathelper.c
index 7cccdc1..6f0d28e 100644
--- a/modules/nathelper/nathelper.c
+++ b/modules/nathelper/nathelper.c
@@ -288,6 +288,7 @@ static int nat_uac_test_f(struct sip_msg* msg, char* str1, char*
str2);
static int fix_nated_contact_f(struct sip_msg *, char *, char *);
static int add_contact_alias_0_f(struct sip_msg *, char *, char *);
static int add_contact_alias_3_f(struct sip_msg *, char *, char *, char *);
+static int set_contact_alias_f(struct sip_msg* msg, char* str1, char* str2);
static int handle_ruri_alias_f(struct sip_msg *, char *, char *);
static int pv_get_rr_count_f(struct sip_msg *, pv_param_t *, pv_value_t *);
static int pv_get_rr_top_count_f(struct sip_msg *, pv_param_t *, pv_value_t *);
@@ -368,6 +369,9 @@ static cmd_export_t cmds[] = {
REQUEST_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
{"add_contact_alias", (cmd_function)add_contact_alias_3_f, 3,
fixup_add_contact_alias, 0,
+ REQUEST_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE},
+ {"set_contact_alias", (cmd_function)set_contact_alias_f, 0,
+ 0, 0,
REQUEST_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
{"handle_ruri_alias", (cmd_function)handle_ruri_alias_f, 0,
0, 0,
@@ -846,6 +850,72 @@ fix_nated_contact_f(struct sip_msg* msg, char* str1, char* str2)
return 1;
}
+/*
+ * Replaces ip:port pair in the Contact: field with the source address
+ * of the packet.
+ */
+static int
+set_contact_alias_f(struct sip_msg* msg, char* str1, char* str2)
+{
+ char nbuf[MAX_URI_SIZE];
+ str nuri;
+ int br;
+
+ int offset, len;
+ char *buf;
+ contact_t *c;
+ struct lump *anchor;
+ struct sip_uri uri;
+
+ nuri.s = nbuf;
+ nuri.len = MAX_URI_SIZE;
+ if (get_contact_uri(msg, &uri, &c) == -1)
+ return -1;
+ if ((c->uri.s < msg->buf) || (c->uri.s > (msg->buf + msg->len)))
{
+ LM_ERR("you can't update contact twice, check your config!\n");
+ return -1;
+ }
+
+ if(uri_add_rcv_alias(msg, &c->uri, &nuri)<0) {
+ LM_DBG("cannot add the alias parameter\n");
+ return -1;
+ }
+
+ br = 1;
+ if(c->uri.s[-1]=='<')
+ br = 0;
+
+
+ len = nuri.len + 2*br;
+ buf = pkg_malloc(len + 1);
+ if (buf == NULL) {
+ LM_ERR("out of pkg memory\n");
+ return -1;
+ }
+ if(br==1) {
+ buf[0] = '<';
+ strncpy(buf+1, nuri.s, nuri.len);
+ buf[len-1] = '>';
+ } else {
+ strncpy(buf, nuri.s, nuri.len);
+ }
+ buf[len] = '\0';
+
+ offset = c->uri.s - msg->buf;
+ anchor = del_lump(msg, offset, c->uri.len, HDR_CONTACT_T);
+ if (anchor == 0)
+ return -1;
+
+ if (insert_new_lump_after(anchor, buf, len, HDR_CONTACT_T) == 0) {
+ pkg_free(buf);
+ return -1;
+ }
+ c->uri.s = buf;
+ c->uri.len = len;
+
+ return 1;
+}
+
#define SALIAS ";alias="
#define SALIAS_LEN (sizeof(SALIAS) - 1)
_______________________________________________
sr-dev mailing list
sr-dev(a)lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev