فهرست منبع

siputils: exported $pcv(name) var and sip_p_charing_vector() func

- based on GH #215
- $pcv(all) = whole field
- $pcv(value) = icid-value field (see RFC3455 section 5.6)
- $pcv(genaddr) = icid-generated-at field (see RFC3455 section 5.6)
Emmanuel BUU 9 سال پیش
والد
کامیت
2a9b4da18e
3فایلهای تغییر یافته به همراه47 افزوده شده و 1 حذف شده
  1. 35 0
      modules/siputils/chargingvector.c
  2. 1 0
      modules/siputils/chargingvector.h
  3. 11 1
      modules/siputils/siputils.c

+ 35 - 0
modules/siputils/chargingvector.c

@@ -454,3 +454,38 @@ int pv_get_charging_vector(struct sip_msg *msg, pv_param_t *param, pv_value_t *r
 
 	return pv_get_null(msg, param, res);
 }
+
+int pv_parse_charging_vector_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, "all", 3)==0)
+				sp->pvp.pvn.u.isname.name.n = 1;
+			else goto error;
+		break;
+		case 5:
+			if(strncmp(in->s, "value", 5)==0)
+				sp->pvp.pvn.u.isname.name.n = 3;
+			else goto error;
+		break;
+		case 7:
+			if(strncmp(in->s, "genaddr", 7)==0)
+				sp->pvp.pvn.u.isname.name.n = 2;
+			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 pcv name %.*s\n", in->len, in->s);
+	return -1;
+}

+ 1 - 0
modules/siputils/chargingvector.h

@@ -42,4 +42,5 @@
 int sip_handle_pcv(sip_msg_t *msg, char *flags, char *str2);
 
 int pv_get_charging_vector(sip_msg_t *msg, pv_param_t *param, pv_value_t *res);
+int pv_parse_charging_vector_name(pv_spec_p sp, str *in);
 #endif

+ 11 - 1
modules/siputils/siputils.c

@@ -77,6 +77,7 @@
 #include "contact_ops.h"
 #include "sipops.h"
 #include "config.h"
+#include "chargingvector.h"
 
 MODULE_VERSION
 
@@ -177,6 +178,8 @@ static cmd_export_t cmds[]={
 		0, ANY_ROUTE},
 	{"is_numeric", (cmd_function)is_numeric,                 1, fixup_spve_null,
 		0, ANY_ROUTE},
+	{"sip_p_charging_vector", (cmd_function)sip_handle_pcv,  1, fixup_spve_null,
+		fixup_free_spve_null, ANY_ROUTE},
 	{0,0,0,0,0,0}
 };
 
@@ -194,6 +197,13 @@ static param_export_t params[] = {
 };
 
 
+ static pv_export_t mod_pvs[] =  {
+	{ {"pcv", (sizeof("pvc")-1)}, PVT_OTHER, pv_get_charging_vector,
+		0, pv_parse_charging_vector_name, 0, 0, 0},
+
+	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
+};
+
 struct module_exports exports= {
 	"siputils",
 	DEFAULT_DLFLAGS, /* dlopen flags */
@@ -201,7 +211,7 @@ struct module_exports exports= {
 	params,          /* param exports */
 	0,               /* exported statistics */
 	0,               /* exported MI functions */
-	0,               /* exported pseudo-variables */
+	mod_pvs,         /* exported pseudo-variables */
 	0,               /* extra processes */
 	mod_init,        /* initialization function */
 	0,               /* Response function */