[sr-dev] git:kamailio_3.0: pv: $snd(xyz) - new pv class to handle dst filtering

Daniel-Constantin Mierla miconda at gmail.com
Thu Oct 22 23:06:08 CEST 2009


Module: sip-router
Branch: kamailio_3.0
Commit: be72d02a81f4508e6666e5992c52b788422cd398
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=be72d02a81f4508e6666e5992c52b788422cd398

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Thu Oct 22 23:02:50 2009 +0200

pv: $snd(xyz) - new pv class to handle dst filtering

- return attributes of destination address, valid in onsend_route
- woraround the DNS blacklisting from K 1.5 by using the new PVs and
  onsend_route
- inner name can be: ip, af, proto and port

---

 modules_k/pv/pv.c        |    2 +
 modules_k/pv/pv_branch.c |   67 ++++++++++++++++++++++++++++++++++++++++++++++
 modules_k/pv/pv_branch.h |    4 +++
 3 files changed, 73 insertions(+), 0 deletions(-)

diff --git a/modules_k/pv/pv.c b/modules_k/pv/pv.c
index 90fb460..46c25a6 100644
--- a/modules_k/pv/pv.c
+++ b/modules_k/pv/pv.c
@@ -68,6 +68,8 @@ static pv_export_t mod_pvs[] = {
 	{ {"sel", sizeof("sel")-1}, /* select */
 		PVT_OTHER, pv_get_select, 0,
 		pv_parse_select_name, 0, 0, 0 },
+	{{"snd", (sizeof("snd")-1)}, PVT_OTHER, pv_get_snd, 0,
+		pv_parse_snd_name, 0, 0, 0},
 
 	{{"avp", (sizeof("avp")-1)}, PVT_AVP, pv_get_avp, pv_set_avp,
 		pv_parse_avp_name, pv_parse_index, 0, 0},
diff --git a/modules_k/pv/pv_branch.c b/modules_k/pv/pv_branch.c
index d497ed4..fe8b4df 100644
--- a/modules_k/pv/pv_branch.c
+++ b/modules_k/pv/pv_branch.c
@@ -22,6 +22,7 @@
 
 
 #include "../../dset.h"
+#include "../../onsend.h"
 
 #include "pv_branch.h"
 
@@ -141,3 +142,69 @@ error:
 	return -1;
 }
 
+int pv_get_snd(struct sip_msg *msg, pv_param_t *param,
+		pv_value_t *res)
+{
+	struct onsend_info* snd_inf;
+
+	snd_inf=get_onsend_info();
+	if (! likely(snd_inf && snd_inf->send_sock))
+		return pv_get_null(msg, param, res);
+
+	switch(param->pvn.u.isname.name.n)
+	{
+		case 1: /* af */
+			return pv_get_uintval(msg, param, res,
+					(int)snd_inf->send_sock->address.af);
+		case 2: /* port */
+			return pv_get_uintval(msg, param, res,
+					(int)snd_inf->send_sock->port_no);
+		case 3: /* proto */
+			return pv_get_uintval(msg, param, res,
+					(int)snd_inf->send_sock->proto);
+		default:
+			/* 0 - ip */
+			return pv_get_strval(msg, param, res,
+					&snd_inf->send_sock->address_str);
+	}
+
+	return 0;
+}
+
+int pv_parse_snd_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, "ip", 2)==0)
+				sp->pvp.pvn.u.isname.name.n = 0;
+			else if(strncmp(in->s, "af", 2)==0)
+				sp->pvp.pvn.u.isname.name.n = 1;
+			else goto error;
+		break;
+		case 4:
+			if(strncmp(in->s, "port", 4)==0)
+				sp->pvp.pvn.u.isname.name.n = 2;
+			else goto error;
+		break;
+		case 5:
+			if(strncmp(in->s, "proto", 5)==0)
+				sp->pvp.pvn.u.isname.name.n = 3;
+			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 time name %.*s\n", in->len, in->s);
+	return -1;
+}
+
diff --git a/modules_k/pv/pv_branch.h b/modules_k/pv/pv_branch.h
index cfb32dc..7b22ba4 100644
--- a/modules_k/pv/pv_branch.h
+++ b/modules_k/pv/pv_branch.h
@@ -31,5 +31,9 @@ int pv_set_branchx(struct sip_msg* msg, pv_param_t *param,
 		int op, pv_value_t *val);
 int pv_parse_branchx_name(pv_spec_p sp, str *in);
 
+int pv_get_snd(struct sip_msg *msg, pv_param_t *param,
+		pv_value_t *res);
+int pv_parse_snd_name(pv_spec_p sp, str *in);
+
 #endif
 




More information about the sr-dev mailing list