[sr-dev] git:master:30460e26: pv: $su use the common core function to get the source address as uri

Luis Azedo luis at 2600hz.com
Thu Feb 19 09:27:14 CET 2015


a typo here ?

+       {{"su", (sizeof("sut")-1)}, /* */   ====>>> should be "sut" ?
+               PVT_OTHER, pv_get_srcaddr_uri_full, 0,
+               0, 0, 0, 0},
________________________________________
From: sr-dev [sr-dev-bounces at lists.sip-router.org] on behalf of Daniel-Constantin Mierla [miconda at gmail.com]
Sent: Thursday, February 19, 2015 12:22 AM
To: sr-dev at lists.sip-router.org
Subject: [sr-dev] git:master:30460e26: pv: $su use the common core function     to get the source address as uri

Module: kamailio
Branch: master
Commit: 30460e263b9b5492872f1f1437fefdfbba69f92b
URL: https://github.com/kamailio/kamailio/commit/30460e263b9b5492872f1f1437fefdfbba69f92b

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2015-02-19T09:19:56+01:00

pv: $su use the common core function to get the source address as uri

- it has same value as received uri built by nathelper
- $sut - new variable that returns full uri for source address (it adds
  transport=udp - missing transport will be equivalent, use $su if you
  want that)

---

Modified: modules/pv/pv.c
Modified: modules/pv/pv_core.c
Modified: modules/pv/pv_core.h

---

Diff:  https://github.com/kamailio/kamailio/commit/30460e263b9b5492872f1f1437fefdfbba69f92b.diff
Patch: https://github.com/kamailio/kamailio/commit/30460e263b9b5492872f1f1437fefdfbba69f92b.patch

---

diff --git a/modules/pv/pv.c b/modules/pv/pv.c
index 3c229f0..af9728f 100644
--- a/modules/pv/pv.c
+++ b/modules/pv/pv.c
@@ -381,6 +381,9 @@ static pv_export_t mod_pvs[] = {
        {{"td", (sizeof("td")-1)}, /* */
                PVT_OTHER, pv_get_to_attr, pv_set_to_domain,
                0, 0, pv_init_iname, 3},
+       {{"su", (sizeof("sut")-1)}, /* */
+               PVT_OTHER, pv_get_srcaddr_uri_full, 0,
+               0, 0, 0, 0},
        {{"to.domain", (sizeof("to.domain")-1)}, /* */
                PVT_OTHER, pv_get_to_attr, pv_set_to_domain,
                0, 0, pv_init_iname, 3},
diff --git a/modules/pv/pv_core.c b/modules/pv/pv_core.c
index 7c2e662..dececb6 100644
--- a/modules/pv/pv_core.c
+++ b/modules/pv/pv_core.c
@@ -110,36 +110,6 @@ int pv_get_return_code(struct sip_msg *msg, pv_param_t *param,
 }
 */

-int pv_get_known_proto_string(int proto, str *sproto)
-{
-       switch(proto) {
-               case PROTO_UDP:
-                       sproto->s = "udp";
-                       sproto->len = 3;
-               return 0;
-               case PROTO_TCP:
-                       sproto->s = "tcp";
-                       sproto->len = 3;
-               return 0;
-               case PROTO_TLS:
-                       sproto->s = "tls";
-                       sproto->len = 3;
-               return 0;
-               case PROTO_SCTP:
-                       sproto->s = "sctp";
-                       sproto->len = 4;
-               return 0;
-               case PROTO_WS:
-                       sproto->s = "ws";
-                       sproto->len = 2;
-               return 0;
-               case PROTO_WSS:
-                       sproto->s = "wss";
-                       sproto->len = 3;
-               return 0;
-       }
-       return -1;
-}

 int pv_get_pid(struct sip_msg *msg, pv_param_t *param,
                pv_value_t *res)
@@ -689,35 +659,44 @@ int pv_get_srcport(struct sip_msg *msg, pv_param_t *param,
        return pv_get_uintval(msg, param, res, msg->rcv.src_port);
 }

-int pv_get_srcaddr_uri(struct sip_msg *msg, pv_param_t *param,
-               pv_value_t *res)
+int pv_get_srcaddr_uri_helper(struct sip_msg *msg, pv_param_t *param,
+               int tmode, pv_value_t *res)
 {
-       str sip;
-       str sproto;
+       str uri;
        str sr;

        if(msg==NULL)
                return -1;

-       if(pv_get_known_proto_string(msg->rcv.proto, &sproto)<0)
+       if(get_src_uri(msg, tmode, &uri)<0)
                return pv_get_null(msg, param, res);

-       sip.s = ip_addr2a(&msg->rcv.src_ip);
-       sip.len = strlen(sip.s);
-       if (sip.len + sproto.len + 32 >= pv_get_buffer_size())
+       if (uri.len + 1 >= pv_get_buffer_size())
        {
                LM_ERR("local buffer size exceeded\n");
                return pv_get_null(msg, param, res);
        }

        sr.s = pv_get_buffer();
-       sr.len = snprintf(sr.s, pv_get_buffer_size(),
-                       "sip:%.*s:%d;transport=%.*s", sip.len, sip.s,
-                       msg->rcv.src_port, sproto.len, sproto.s);
+       strncpy(sr.s, uri.s, uri.len);
+       sr.len = uri.len;
+       sr.s[sr.len] = '\0';

        return pv_get_strval(msg, param, res, &sr);
 }

+int pv_get_srcaddr_uri(struct sip_msg *msg, pv_param_t *param,
+               pv_value_t *res)
+{
+       return pv_get_srcaddr_uri_helper(msg, param, 0, res);
+}
+
+int pv_get_srcaddr_uri_full(struct sip_msg *msg, pv_param_t *param,
+               pv_value_t *res)
+{
+       return pv_get_srcaddr_uri_helper(msg, param, 1, res);
+}
+
 int pv_get_rcvip(struct sip_msg *msg, pv_param_t *param,
                pv_value_t *res)
 {
@@ -1098,9 +1077,9 @@ int pv_get_proto(struct sip_msg *msg, pv_param_t *param,
        if(msg==NULL)
                return -1;

-       if(pv_get_known_proto_string(msg->rcv.proto, &s)<0)
+       if(get_valid_proto_string(msg->rcv.proto, 0, 0, &s)<0)
        {
-               s.s = "NONE";
+               s.s = "none";
                s.len = 4;
        }

diff --git a/modules/pv/pv_core.h b/modules/pv/pv_core.h
index 02615b9..6d6c1a5 100644
--- a/modules/pv/pv_core.h
+++ b/modules/pv/pv_core.h
@@ -133,6 +133,9 @@ int pv_get_srcport(struct sip_msg *msg, pv_param_t *param,
 int pv_get_srcaddr_uri(struct sip_msg *msg, pv_param_t *param,
                pv_value_t *res);

+int pv_get_srcaddr_uri_full(struct sip_msg *msg, pv_param_t *param,
+               pv_value_t *res);
+
 int pv_get_rcvip(struct sip_msg *msg, pv_param_t *param,
                pv_value_t *res);



_______________________________________________
sr-dev mailing list
sr-dev at lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev



More information about the sr-dev mailing list