ソースを参照

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
Daniel-Constantin Mierla 16 年 前
コミット
be72d02a81
3 ファイル変更73 行追加0 行削除
  1. 2 0
      modules_k/pv/pv.c
  2. 67 0
      modules_k/pv/pv_branch.c
  3. 4 0
      modules_k/pv/pv_branch.h

+ 2 - 0
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},

+ 67 - 0
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;
+}
+

+ 4 - 0
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