[sr-dev] git:master: pv: $null exported by pv api

Daniel-Constantin Mierla miconda at gmail.com
Mon Apr 19 21:37:38 CEST 2010


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Mon Apr 19 21:07:28 2010 +0200

pv: $null exported by pv api

- core pv api can export pvs - $null and $$ are generic and can be used
  without pv module
- pv_parse_avp_name() moved together with pv_get_avp_name()

---

 modules_k/pv/pv.c      |    3 --
 modules_k/pv/pv_core.c |   43 ----------------------
 modules_k/pv/pv_core.h |    2 -
 pvapi.c                |   91 +++++++++++++++++++++++++++++++++++++++++++++++-
 pvar.h                 |    1 +
 5 files changed, 91 insertions(+), 49 deletions(-)

diff --git a/modules_k/pv/pv.c b/modules_k/pv/pv.c
index 2076de0..76e590c 100644
--- a/modules_k/pv/pv.c
+++ b/modules_k/pv/pv.c
@@ -216,9 +216,6 @@ static pv_export_t mod_pvs[] = {
 	{{"ml", (sizeof("ml")-1)}, /* */
 		PVT_OTHER, pv_get_msg_len, 0,
 		0, 0, 0, 0},
-	{{"null", (sizeof("null")-1)}, /* */
-		PVT_NULL, pv_get_null, 0,
-		0, 0, 0, 0},
 	{{"od", (sizeof("od")-1)}, /* */
 		PVT_OTHER, pv_get_ouri_attr, 0,
 		0, 0, pv_init_iname, 2},
diff --git a/modules_k/pv/pv_core.c b/modules_k/pv/pv_core.c
index 966bed8..10d378f 100644
--- a/modules_k/pv/pv_core.c
+++ b/modules_k/pv/pv_core.c
@@ -2081,46 +2081,3 @@ error:
 	return -1;
 }
 
-
-int pv_parse_avp_name(pv_spec_p sp, str *in)
-{
-	char *p;
-	char *s;
-	pv_spec_p nsp = 0;
-
-	if(in==NULL || in->s==NULL || sp==NULL)
-		return -1;
-	p = in->s;
-	if(*p==PV_MARKER)
-	{
-		nsp = (pv_spec_p)pkg_malloc(sizeof(pv_spec_t));
-		if(nsp==NULL)
-		{
-			LM_ERR("no more memory\n");
-			return -1;
-		}
-		s = pv_parse_spec(in, nsp);
-		if(s==NULL)
-		{
-			LM_ERR("invalid name [%.*s]\n", in->len, in->s);
-			pv_spec_free(nsp);
-			return -1;
-		}
-		//LM_ERR("dynamic name [%.*s]\n", in->len, in->s);
-		//pv_print_spec(nsp);
-		sp->pvp.pvn.type = PV_NAME_PVAR;
-		sp->pvp.pvn.u.dname = (void*)nsp;
-		return 0;
-	}
-	/*LM_DBG("static name [%.*s]\n", in->len, in->s);*/
-	if(km_parse_avp_spec(in, &sp->pvp.pvn.u.isname.type,
-					  &sp->pvp.pvn.u.isname.name)!=0)
-	{
-		LM_ERR("bad avp name [%.*s]\n", in->len, in->s);
-		return -1;
-	}
-	sp->pvp.pvn.type = PV_NAME_INTSTR;
-	return 0;
-}
-
-
diff --git a/modules_k/pv/pv_core.h b/modules_k/pv/pv_core.h
index 1831071..32b6b37 100644
--- a/modules_k/pv/pv_core.h
+++ b/modules_k/pv/pv_core.h
@@ -234,7 +234,5 @@ int pv_parse_scriptvar_name(pv_spec_p sp, str *in);
 
 int pv_parse_hdr_name(pv_spec_p sp, str *in);
 
-int pv_parse_avp_name(pv_spec_p sp, str *in);
-
 #endif
 
diff --git a/pvapi.c b/pvapi.c
index 72024cd..bbd4b87 100644
--- a/pvapi.c
+++ b/pvapi.c
@@ -316,6 +316,9 @@ int pv_get_null(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
 	return 0;
 }
 
+/**
+ *
+ */
 pv_export_t* pv_lookup_spec_name(str *pvname, pv_spec_p e)
 {
 	pv_item_t *pvi;
@@ -353,6 +356,9 @@ pv_export_t* pv_lookup_spec_name(str *pvname, pv_spec_p e)
 	return NULL;
 }
 
+/**
+ *
+ */
 int pv_parse_index(pv_spec_p sp, str *in)
 {
 	char *p;
@@ -409,6 +415,9 @@ int pv_parse_index(pv_spec_p sp, str *in)
 	return 0;
 }
 
+/**
+ *
+ */
 int pv_init_iname(pv_spec_p sp, int param)
 {
 	if(sp==NULL)
@@ -418,6 +427,9 @@ int pv_init_iname(pv_spec_p sp, int param)
 	return 0;
 }
 
+/**
+ *
+ */
 char* pv_parse_spec2(str *in, pv_spec_p e, int silent)
 {
 	char *p;
@@ -787,6 +799,9 @@ error:
 	return -1;
 }
 
+/**
+ *
+ */
 int pv_get_spec_name(struct sip_msg* msg, pv_param_p ip, pv_value_t *name)
 {
 	if(msg==NULL || ip==NULL || name==NULL)
@@ -822,6 +837,55 @@ int pv_get_spec_name(struct sip_msg* msg, pv_param_p ip, pv_value_t *name)
 	return -1;
 }
 
+/**
+ * parse AVP name
+ * @return 0 on success, -1 on error
+ */
+int pv_parse_avp_name(pv_spec_p sp, str *in)
+{
+	char *p;
+	char *s;
+	pv_spec_p nsp = 0;
+
+	if(in==NULL || in->s==NULL || sp==NULL)
+		return -1;
+	p = in->s;
+	if(*p==PV_MARKER)
+	{
+		nsp = (pv_spec_p)pkg_malloc(sizeof(pv_spec_t));
+		if(nsp==NULL)
+		{
+			LM_ERR("no more memory\n");
+			return -1;
+		}
+		s = pv_parse_spec(in, nsp);
+		if(s==NULL)
+		{
+			LM_ERR("invalid name [%.*s]\n", in->len, in->s);
+			pv_spec_free(nsp);
+			return -1;
+		}
+		//LM_ERR("dynamic name [%.*s]\n", in->len, in->s);
+		//pv_print_spec(nsp);
+		sp->pvp.pvn.type = PV_NAME_PVAR;
+		sp->pvp.pvn.u.dname = (void*)nsp;
+		return 0;
+	}
+	/*LM_DBG("static name [%.*s]\n", in->len, in->s);*/
+	if(km_parse_avp_spec(in, &sp->pvp.pvn.u.isname.type,
+					  &sp->pvp.pvn.u.isname.name)!=0)
+	{
+		LM_ERR("bad avp name [%.*s]\n", in->len, in->s);
+		return -1;
+	}
+	sp->pvp.pvn.type = PV_NAME_INTSTR;
+	return 0;
+}
+
+/**
+ * fill avp name details (id and type)
+ * @return 0 on success, -1 on error
+ */
 int pv_get_avp_name(struct sip_msg* msg, pv_param_p ip, int_str *avp_name,
 		unsigned short *name_type)
 {
@@ -867,7 +931,9 @@ int pv_get_avp_name(struct sip_msg* msg, pv_param_p ip, int_str *avp_name,
 	return 0;
 }
 
-
+/**
+ *
+ */
 int pv_get_spec_index(struct sip_msg* msg, pv_param_p ip, int *idx, int *flags)
 {
 	pv_value_t tv;
@@ -903,6 +969,9 @@ int pv_get_spec_index(struct sip_msg* msg, pv_param_p ip, int *idx, int *flags)
 	return 0;
 }
 
+/**
+ *
+ */
 int pv_get_spec_value(struct sip_msg* msg, pv_spec_p sp, pv_value_t *value)
 {
 	int ret = 0;
@@ -925,6 +994,9 @@ int pv_get_spec_value(struct sip_msg* msg, pv_spec_p sp, pv_value_t *value)
 	return ret;
 }
 
+/**
+ *
+ */
 int pv_set_spec_value(struct sip_msg* msg, pv_spec_p sp, int op,
 		pv_value_t *value)
 {
@@ -1456,6 +1528,9 @@ int tr_table_free(void)
 	return 0;
 }
 
+/**
+ *
+ */
 tr_export_t* tr_lookup_class(str *tclass)
 {
 	tr_item_t *tri;
@@ -1483,6 +1558,18 @@ tr_export_t* tr_lookup_class(str *tclass)
 }
 
 
+/********************************************************
+ * core PVs, initialization and destroy APIs
+ ********************************************************/
+
+static pv_export_t _core_pvs[] = {
+	{{"null", (sizeof("null")-1)}, /* */
+		PVT_NULL, pv_get_null, 0,
+		0, 0, 0, 0},
+
+	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
+};
+
 /** init pv api (optional).
  * @return 0 on success, -1 on error
  */
@@ -1490,6 +1577,8 @@ int init_pv_api(void)
 {
 	pv_init_table();
 	tr_init_table();
+	if(register_pvars_mod("core", _core_pvs)<0)
+		return -1;
 	return 0;
 }
 
diff --git a/pvar.h b/pvar.h
index 19b9310..58fe38b 100644
--- a/pvar.h
+++ b/pvar.h
@@ -179,6 +179,7 @@ int pv_spec_dbg(pv_spec_p sp);
 int pv_get_spec_index(struct sip_msg* msg, pv_param_p ip, int *idx, int *flags);
 int pv_get_avp_name(struct sip_msg* msg, pv_param_p ip, int_str *avp_name,
 		unsigned short *name_type);
+int pv_parse_avp_name(pv_spec_p sp, str *in);
 int pv_get_spec_name(struct sip_msg* msg, pv_param_p ip, pv_value_t *name);
 int pv_parse_format(str *in, pv_elem_p *el);
 int pv_parse_index(pv_spec_p sp, str *in);




More information about the sr-dev mailing list