Browse code

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()

Daniel-Constantin Mierla authored on 19/04/2010 19:07:28
Showing 5 changed files
... ...
@@ -216,9 +216,6 @@ static pv_export_t mod_pvs[] = {
216 216
 	{{"ml", (sizeof("ml")-1)}, /* */
217 217
 		PVT_OTHER, pv_get_msg_len, 0,
218 218
 		0, 0, 0, 0},
219
-	{{"null", (sizeof("null")-1)}, /* */
220
-		PVT_NULL, pv_get_null, 0,
221
-		0, 0, 0, 0},
222 219
 	{{"od", (sizeof("od")-1)}, /* */
223 220
 		PVT_OTHER, pv_get_ouri_attr, 0,
224 221
 		0, 0, pv_init_iname, 2},
... ...
@@ -2081,46 +2081,3 @@ error:
2081 2081
 	return -1;
2082 2082
 }
2083 2083
 
2084
-
2085
-int pv_parse_avp_name(pv_spec_p sp, str *in)
2086
-{
2087
-	char *p;
2088
-	char *s;
2089
-	pv_spec_p nsp = 0;
2090
-
2091
-	if(in==NULL || in->s==NULL || sp==NULL)
2092
-		return -1;
2093
-	p = in->s;
2094
-	if(*p==PV_MARKER)
2095
-	{
2096
-		nsp = (pv_spec_p)pkg_malloc(sizeof(pv_spec_t));
2097
-		if(nsp==NULL)
2098
-		{
2099
-			LM_ERR("no more memory\n");
2100
-			return -1;
2101
-		}
2102
-		s = pv_parse_spec(in, nsp);
2103
-		if(s==NULL)
2104
-		{
2105
-			LM_ERR("invalid name [%.*s]\n", in->len, in->s);
2106
-			pv_spec_free(nsp);
2107
-			return -1;
2108
-		}
2109
-		//LM_ERR("dynamic name [%.*s]\n", in->len, in->s);
2110
-		//pv_print_spec(nsp);
2111
-		sp->pvp.pvn.type = PV_NAME_PVAR;
2112
-		sp->pvp.pvn.u.dname = (void*)nsp;
2113
-		return 0;
2114
-	}
2115
-	/*LM_DBG("static name [%.*s]\n", in->len, in->s);*/
2116
-	if(km_parse_avp_spec(in, &sp->pvp.pvn.u.isname.type,
2117
-					  &sp->pvp.pvn.u.isname.name)!=0)
2118
-	{
2119
-		LM_ERR("bad avp name [%.*s]\n", in->len, in->s);
2120
-		return -1;
2121
-	}
2122
-	sp->pvp.pvn.type = PV_NAME_INTSTR;
2123
-	return 0;
2124
-}
2125
-
2126
-
... ...
@@ -234,7 +234,5 @@ int pv_parse_scriptvar_name(pv_spec_p sp, str *in);
234 234
 
235 235
 int pv_parse_hdr_name(pv_spec_p sp, str *in);
236 236
 
237
-int pv_parse_avp_name(pv_spec_p sp, str *in);
238
-
239 237
 #endif
240 238
 
... ...
@@ -316,6 +316,9 @@ int pv_get_null(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
316 316
 	return 0;
317 317
 }
318 318
 
319
+/**
320
+ *
321
+ */
319 322
 pv_export_t* pv_lookup_spec_name(str *pvname, pv_spec_p e)
320 323
 {
321 324
 	pv_item_t *pvi;
... ...
@@ -353,6 +356,9 @@ pv_export_t* pv_lookup_spec_name(str *pvname, pv_spec_p e)
353 356
 	return NULL;
354 357
 }
355 358
 
359
+/**
360
+ *
361
+ */
356 362
 int pv_parse_index(pv_spec_p sp, str *in)
357 363
 {
358 364
 	char *p;
... ...
@@ -409,6 +415,9 @@ int pv_parse_index(pv_spec_p sp, str *in)
409 415
 	return 0;
410 416
 }
411 417
 
418
+/**
419
+ *
420
+ */
412 421
 int pv_init_iname(pv_spec_p sp, int param)
413 422
 {
414 423
 	if(sp==NULL)
... ...
@@ -418,6 +427,9 @@ int pv_init_iname(pv_spec_p sp, int param)
418 427
 	return 0;
419 428
 }
420 429
 
430
+/**
431
+ *
432
+ */
421 433
 char* pv_parse_spec2(str *in, pv_spec_p e, int silent)
422 434
 {
423 435
 	char *p;
... ...
@@ -787,6 +799,9 @@ error:
787 799
 	return -1;
788 800
 }
789 801
 
802
+/**
803
+ *
804
+ */
790 805
 int pv_get_spec_name(struct sip_msg* msg, pv_param_p ip, pv_value_t *name)
791 806
 {
792 807
 	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)
822 837
 	return -1;
823 838
 }
824 839
 
840
+/**
841
+ * parse AVP name
842
+ * @return 0 on success, -1 on error
843
+ */
844
+int pv_parse_avp_name(pv_spec_p sp, str *in)
845
+{
846
+	char *p;
847
+	char *s;
848
+	pv_spec_p nsp = 0;
849
+
850
+	if(in==NULL || in->s==NULL || sp==NULL)
851
+		return -1;
852
+	p = in->s;
853
+	if(*p==PV_MARKER)
854
+	{
855
+		nsp = (pv_spec_p)pkg_malloc(sizeof(pv_spec_t));
856
+		if(nsp==NULL)
857
+		{
858
+			LM_ERR("no more memory\n");
859
+			return -1;
860
+		}
861
+		s = pv_parse_spec(in, nsp);
862
+		if(s==NULL)
863
+		{
864
+			LM_ERR("invalid name [%.*s]\n", in->len, in->s);
865
+			pv_spec_free(nsp);
866
+			return -1;
867
+		}
868
+		//LM_ERR("dynamic name [%.*s]\n", in->len, in->s);
869
+		//pv_print_spec(nsp);
870
+		sp->pvp.pvn.type = PV_NAME_PVAR;
871
+		sp->pvp.pvn.u.dname = (void*)nsp;
872
+		return 0;
873
+	}
874
+	/*LM_DBG("static name [%.*s]\n", in->len, in->s);*/
875
+	if(km_parse_avp_spec(in, &sp->pvp.pvn.u.isname.type,
876
+					  &sp->pvp.pvn.u.isname.name)!=0)
877
+	{
878
+		LM_ERR("bad avp name [%.*s]\n", in->len, in->s);
879
+		return -1;
880
+	}
881
+	sp->pvp.pvn.type = PV_NAME_INTSTR;
882
+	return 0;
883
+}
884
+
885
+/**
886
+ * fill avp name details (id and type)
887
+ * @return 0 on success, -1 on error
888
+ */
825 889
 int pv_get_avp_name(struct sip_msg* msg, pv_param_p ip, int_str *avp_name,
826 890
 		unsigned short *name_type)
827 891
 {
... ...
@@ -867,7 +931,9 @@ int pv_get_avp_name(struct sip_msg* msg, pv_param_p ip, int_str *avp_name,
867 931
 	return 0;
868 932
 }
869 933
 
870
-
934
+/**
935
+ *
936
+ */
871 937
 int pv_get_spec_index(struct sip_msg* msg, pv_param_p ip, int *idx, int *flags)
872 938
 {
873 939
 	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)
903 969
 	return 0;
904 970
 }
905 971
 
972
+/**
973
+ *
974
+ */
906 975
 int pv_get_spec_value(struct sip_msg* msg, pv_spec_p sp, pv_value_t *value)
907 976
 {
908 977
 	int ret = 0;
... ...
@@ -925,6 +994,9 @@ int pv_get_spec_value(struct sip_msg* msg, pv_spec_p sp, pv_value_t *value)
925 994
 	return ret;
926 995
 }
927 996
 
997
+/**
998
+ *
999
+ */
928 1000
 int pv_set_spec_value(struct sip_msg* msg, pv_spec_p sp, int op,
929 1001
 		pv_value_t *value)
930 1002
 {
... ...
@@ -1456,6 +1528,9 @@ int tr_table_free(void)
1456 1528
 	return 0;
1457 1529
 }
1458 1530
 
1531
+/**
1532
+ *
1533
+ */
1459 1534
 tr_export_t* tr_lookup_class(str *tclass)
1460 1535
 {
1461 1536
 	tr_item_t *tri;
... ...
@@ -1483,6 +1558,18 @@ tr_export_t* tr_lookup_class(str *tclass)
1483 1558
 }
1484 1559
 
1485 1560
 
1561
+/********************************************************
1562
+ * core PVs, initialization and destroy APIs
1563
+ ********************************************************/
1564
+
1565
+static pv_export_t _core_pvs[] = {
1566
+	{{"null", (sizeof("null")-1)}, /* */
1567
+		PVT_NULL, pv_get_null, 0,
1568
+		0, 0, 0, 0},
1569
+
1570
+	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
1571
+};
1572
+
1486 1573
 /** init pv api (optional).
1487 1574
  * @return 0 on success, -1 on error
1488 1575
  */
... ...
@@ -1490,6 +1577,8 @@ int init_pv_api(void)
1490 1577
 {
1491 1578
 	pv_init_table();
1492 1579
 	tr_init_table();
1580
+	if(register_pvars_mod("core", _core_pvs)<0)
1581
+		return -1;
1493 1582
 	return 0;
1494 1583
 }
1495 1584
 
... ...
@@ -179,6 +179,7 @@ int pv_spec_dbg(pv_spec_p sp);
179 179
 int pv_get_spec_index(struct sip_msg* msg, pv_param_p ip, int *idx, int *flags);
180 180
 int pv_get_avp_name(struct sip_msg* msg, pv_param_p ip, int_str *avp_name,
181 181
 		unsigned short *name_type);
182
+int pv_parse_avp_name(pv_spec_p sp, str *in);
182 183
 int pv_get_spec_name(struct sip_msg* msg, pv_param_p ip, pv_value_t *name);
183 184
 int pv_parse_format(str *in, pv_elem_p *el);
184 185
 int pv_parse_index(pv_spec_p sp, str *in);