Module: sip-router
Branch: master
Commit: ed5859fcd482d803cb2896cf58e3ef19ad8c2a2d
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ed5859f…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Tue Sep 25 23:43:48 2012 +0200
pv: new pv class - $K(key)
- return the value for internal constant keywords
- key can be:
- IPv4 - returns AF_INET
- IPv6 - returns AF_INET6
- UDP - return PROTO_UDP
- TCP - return PROTO_TCP
- TLS - return PROTO_TLS
- SCTP - return PROTO_SCTP
- it can be used to compare the values from other pvs, such as $af(id),
$snd(af), $snd(proto), ...
---
modules_k/pv/pv.c | 2 +
modules_k/pv/pv_core.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++
modules_k/pv/pv_core.h | 6 ++++
3 files changed, 75 insertions(+), 0 deletions(-)
diff --git a/modules_k/pv/pv.c b/modules_k/pv/pv.c
index 8ee7cfa..6bd0feb 100644
--- a/modules_k/pv/pv.c
+++ b/modules_k/pv/pv.c
@@ -411,6 +411,8 @@ static pv_export_t mod_pvs[] = {
0, pv_parse_nh_name, 0, 0, 0},
{ {"version", (sizeof("version")-1)}, PVT_OTHER, pv_get_sr_version,
0, pv_parse_sr_version_name, 0, 0, 0},
+ { {"K", (sizeof("K")-1)}, PVT_OTHER, pv_get_K, 0,
+ pv_parse_K_name, 0, 0, 0 },
{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
};
diff --git a/modules_k/pv/pv_core.c b/modules_k/pv/pv_core.c
index 3d3f121..d67278f 100644
--- a/modules_k/pv/pv_core.c
+++ b/modules_k/pv/pv_core.c
@@ -2523,3 +2523,70 @@ error:
pkg_free(pv);
return -1;
}
+
+
+/**
+ *
+ */
+int pv_parse_K_name(pv_spec_p sp, str *in)
+{
+ if(sp==NULL || in==NULL || in->len<=0)
+ return -1;
+
+ switch(in->len)
+ {
+ case 3:
+ if(strncmp(in->s, "UDP", 3)==0)
+ sp->pvp.pvn.u.isname.name.n = 2;
+ else if(strncmp(in->s, "TCP", 3)==0)
+ sp->pvp.pvn.u.isname.name.n = 3;
+ else if(strncmp(in->s, "TLS", 3)==0)
+ sp->pvp.pvn.u.isname.name.n = 4;
+ else goto error;
+ break;
+ case 4:
+ if(strncmp(in->s, "IPv4", 4)==0)
+ sp->pvp.pvn.u.isname.name.n = 0;
+ else if(strncmp(in->s, "IPv6", 4)==0)
+ sp->pvp.pvn.u.isname.name.n = 1;
+ else if(strncmp(in->s, "SCTP", 4)==0)
+ sp->pvp.pvn.u.isname.name.n = 5;
+ 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_K(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
+{
+ if(param==NULL)
+ return -1;
+
+ switch(param->pvn.u.isname.name.n)
+ {
+ case 1:
+ return pv_get_uintval(msg, param, res, AF_INET6);
+ case 2:
+ return pv_get_uintval(msg, param, res, PROTO_UDP);
+ case 3:
+ return pv_get_uintval(msg, param, res, PROTO_TCP);
+ case 4:
+ return pv_get_uintval(msg, param, res, PROTO_TLS);
+ case 5:
+ return pv_get_uintval(msg, param, res, PROTO_SCTP);
+ default:
+ return pv_get_uintval(msg, param, res, AF_INET);
+ }
+}
diff --git a/modules_k/pv/pv_core.h b/modules_k/pv/pv_core.h
index a9e864c..9fb802c 100644
--- a/modules_k/pv/pv_core.h
+++ b/modules_k/pv/pv_core.h
@@ -280,5 +280,11 @@ 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);
+
+int pv_parse_K_name(pv_spec_p sp, str *in);
+
+int pv_get_K(sip_msg_t *msg, pv_param_t *param,
+ pv_value_t *res);
+
#endif