pv: new config variable $sas
authorDaniel-Constantin Mierla <miconda@gmail.com>
Tue, 10 Apr 2018 11:29:01 +0000 (13:29 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Tue, 10 Apr 2018 11:29:01 +0000 (13:29 +0200)
- return source address in socket format (proto:address:port)

src/modules/pv/pv.c
src/modules/pv/pv_core.c
src/modules/pv/pv_core.h

index 5743dd6..258be56 100644 (file)
@@ -400,6 +400,9 @@ static pv_export_t mod_pvs[] = {
        {{"RAut", (sizeof("RAut")-1)}, /* */
                PVT_OTHER, pv_get_rcvadv_uri_full, 0,
                0, 0, 0, 0},
+       {{"sas", (sizeof("sas")-1)}, /* */
+               PVT_OTHER, pv_get_srcaddr_socket, 0,
+               0, 0, 0, 0},
        {{"sf", (sizeof("sf")-1)}, /* */
                PVT_OTHER, pv_get_sflags, pv_set_sflags,
                0, 0, 0, 0},
index b087f5a..098d543 100644 (file)
@@ -726,6 +726,31 @@ int pv_get_srcaddr_uri_helper(struct sip_msg *msg, pv_param_t *param,
        return pv_get_strval(msg, param, res, &sr);
 }
 
+int pv_get_srcaddr_socket(struct sip_msg *msg, pv_param_t *param,
+               pv_value_t *res)
+{
+       str ssock;
+       str sr;
+
+       if(msg==NULL)
+               return -1;
+
+       if(get_src_address_socket(msg, &ssock)<0)
+               return pv_get_null(msg, param, res);
+
+       if (ssock.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();
+       strncpy(sr.s, ssock.s, ssock.len);
+       sr.len = ssock.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)
 {
index 898b3a8..148e87f 100644 (file)
@@ -142,6 +142,9 @@ int pv_get_srcaddr_uri(struct sip_msg *msg, pv_param_t *param,
 int pv_get_srcaddr_uri_full(struct sip_msg *msg, pv_param_t *param,
                pv_value_t *res);
 
+int pv_get_srcaddr_socket(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);