Ver código fonte

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"
Daniel-Constantin Mierla 13 anos atrás
pai
commit
a2de5aba01
3 arquivos alterados com 63 adições e 0 exclusões
  1. 2 0
      modules_k/pv/pv.c
  2. 57 0
      modules_k/pv/pv_core.c
  3. 4 0
      modules_k/pv/pv_core.h

+ 2 - 0
modules_k/pv/pv.c

@@ -60,6 +60,8 @@ static tr_export_t mod_trans[] = {
 };
 };
 
 
 static pv_export_t mod_pvs[] = {
 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 */
 	{ {"branch", sizeof("branch")-1}, /* branch attributes */
 		PVT_CONTEXT, pv_get_branchx, pv_set_branchx,
 		PVT_CONTEXT, pv_get_branchx, pv_set_branchx,
 		pv_parse_branchx_name, pv_parse_index, 0, 0 },
 		pv_parse_branchx_name, pv_parse_index, 0, 0 },

+ 57 - 0
modules_k/pv/pv_core.c

@@ -60,6 +60,11 @@ static str pv_uri_scheme[] = {
 		{ 0, 0 }
 		{ 0, 0 }
 	};
 	};
 
 
+static str pv_af_list[] = {
+		{ "IPv4",  4 },
+		{ "IPv6",  4 },
+		{ 0, 0 }
+	};
 int _pv_pid = 0;
 int _pv_pid = 0;
 
 
 #define PV_FIELD_DELIM ", "
 #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);
 			&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,
 int pv_get_force_sock(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res)
 		pv_value_t *res)
 {
 {

+ 4 - 0
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_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
 #endif