Module: sip-router
Branch: master
Commit: a2de5aba014c34fa0d37c1d527ff241e3969e897
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a2de5ab…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Tue Sep 25 23:13:50 2012 +0200
pv: new pv class - $af(key)
- return address family for received message
- key can be:
- id: return integer representation for IPv4 or IPv6 (value of AF_INET and AF_INET6)
- name: return "IPv4" or "IPv6"
---
modules_k/pv/pv.c | 2 +
modules_k/pv/pv_core.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++
modules_k/pv/pv_core.h | 4 +++
3 files changed, 63 insertions(+), 0 deletions(-)
diff --git a/modules_k/pv/pv.c b/modules_k/pv/pv.c
index aff1ee1..8ee7cfa 100644
--- a/modules_k/pv/pv.c
+++ b/modules_k/pv/pv.c
@@ -60,6 +60,8 @@ static tr_export_t mod_trans[] = {
};
static pv_export_t mod_pvs[] = {
+ { {"af", (sizeof("af")-1)}, PVT_OTHER, pv_get_af, 0,
+ pv_parse_af_name, 0, 0, 0 },
{ {"branch", sizeof("branch")-1}, /* branch attributes */
PVT_CONTEXT, pv_get_branchx, pv_set_branchx,
pv_parse_branchx_name, pv_parse_index, 0, 0 },
diff --git a/modules_k/pv/pv_core.c b/modules_k/pv/pv_core.c
index d0c7628..3d3f121 100644
--- a/modules_k/pv/pv_core.c
+++ b/modules_k/pv/pv_core.c
@@ -60,6 +60,11 @@ static str pv_uri_scheme[] = {
{ 0, 0 }
};
+static str pv_af_list[] = {
+ { "IPv4", 4 },
+ { "IPv6", 4 },
+ { 0, 0 }
+ };
int _pv_pid = 0;
#define PV_FIELD_DELIM ", "
@@ -642,6 +647,58 @@ int pv_get_rcvport(struct sip_msg *msg, pv_param_t *param,
&msg->rcv.bind_address->port_no_str);
}
+/**
+ *
+ */
+int pv_parse_af_name(pv_spec_p sp, str *in)
+{
+ if(sp==NULL || in==NULL || in->len<=0)
+ return -1;
+
+ switch(in->len)
+ {
+ case 2:
+ if(strncmp(in->s, "id", 2)==0)
+ sp->pvp.pvn.u.isname.name.n = 0;
+ else goto error;
+ break;
+ case 4:
+ if(strncmp(in->s, "name", 4)==0)
+ sp->pvp.pvn.u.isname.name.n = 1;
+ else goto error;
+ break;
+ default:
+ goto error;
+ }
+ sp->pvp.pvn.type = PV_NAME_INTSTR;
+ sp->pvp.pvn.u.isname.type = 0;
+
+ return 0;
+
+error:
+ LM_ERR("unknown PV af key: %.*s\n", in->len, in->s);
+ return -1;
+}
+
+/**
+ *
+ */
+int pv_get_af(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
+{
+ if(msg==NULL || param==NULL)
+ return -1;
+
+ switch(param->pvn.u.isname.name.n)
+ {
+ case 1:
+ if(msg->rcv.bind_address->address.af==AF_INET6)
+ return pv_get_strval(msg, param, res, &pv_af_list[1]);
+ return pv_get_strval(msg, param, res, &pv_af_list[0]);
+ default:
+ return pv_get_uintval(msg, param, res, msg->rcv.bind_address->address.af);
+ }
+}
+
int pv_get_force_sock(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res)
{
diff --git a/modules_k/pv/pv_core.h b/modules_k/pv/pv_core.h
index 0149d24..a9e864c 100644
--- a/modules_k/pv/pv_core.h
+++ b/modules_k/pv/pv_core.h
@@ -276,5 +276,9 @@ int pv_parse_hdr_name(pv_spec_p sp, str *in);
int pv_parse_cnt_name(pv_spec_p sp, str *in);
+int pv_parse_af_name(pv_spec_p sp, str *in);
+
+int pv_get_af(sip_msg_t *msg, pv_param_t *param,
+ pv_value_t *res);
#endif