Browse code

fix pv&t lookup due to signness

- added missing functions from K

Daniel-Constantin Mierla authored on 09/12/2008 16:12:53
Showing 2 changed files
... ...
@@ -38,11 +38,11 @@
38 38
 #include "pvar.h"
39 39
 
40 40
 #define is_in_str(p, in) (p<in->s+in->len && *p)
41
+#define core_hash(in, a, b) get_hash1_raw((in)->s, (in)->len)
41 42
 
42 43
 #define PV_TABLE_SIZE	16
43 44
 #define TR_TABLE_SIZE	4
44 45
 
45
-#define core_hash(in, a, b) get_hash1_raw((in)->s, (in)->len);
46 46
 
47 47
 void tr_destroy(trans_t *t);
48 48
 void tr_free(trans_t *t);
... ...
@@ -57,6 +57,7 @@ typedef struct _pv_item
57 57
 static pv_item_t* _pv_table[PV_TABLE_SIZE];
58 58
 static int _pv_table_set = 0;
59 59
 
60
+
60 61
 /**
61 62
  *
62 63
  */
... ...
@@ -88,7 +89,7 @@ int pv_table_add(pv_export_t *e)
88 89
 	pv_item_t *pvj = NULL;
89 90
 	pv_item_t *pvn = NULL;
90 91
 	int found;
91
-	int pvid;
92
+	unsigned int pvid;
92 93
 
93 94
 	if(e==NULL || e->name.s==NULL || e->getf==NULL || e->type==PVT_NONE)
94 95
 	{
... ...
@@ -239,8 +240,7 @@ int pv_get_sintval(struct sip_msg *msg, pv_param_t *param,
239 240
 	if(res==NULL)
240 241
 		return -1;
241 242
 
242
-	// ch = sint2str(sival, &l);
243
-	ch = int2str(sival, &l);
243
+	ch = sint2str(sival, &l);
244 244
 	res->rs.s = ch;
245 245
 	res->rs.len = l;
246 246
 
... ...
@@ -822,7 +822,8 @@ int pv_get_avp_name(struct sip_msg* msg, pv_param_p ip, int_str *avp_name,
822 822
 			*name_type |= AVP_NAME_STR;
823 823
 		} else {
824 824
 			avp_name->n = ip->pvn.u.isname.name.n;
825
-			*name_type = 0; // &= AVP_SCRIPT_MASK;
825
+			/* *name_type &= AVP_SCRIPT_MASK; */
826
+			*name_type = 0;
826 827
 		}
827 828
 		return 0;
828 829
 	}
... ...
@@ -978,6 +979,73 @@ done:
978 979
 	return 0;
979 980
 }
980 981
 
982
+/**
983
+ *
984
+ */
985
+pvname_list_t* parse_pvname_list(str *in, unsigned int type)
986
+{
987
+	pvname_list_t* head = NULL;
988
+	pvname_list_t* al = NULL;
989
+	pvname_list_t* last = NULL;
990
+	char *p;
991
+	pv_spec_t spec;
992
+	str s;
993
+
994
+	if(in==NULL || in->s==NULL)
995
+	{
996
+		LM_ERR("bad parameters\n");
997
+		return NULL;
998
+	}
999
+
1000
+	p = in->s;
1001
+	while(is_in_str(p, in))
1002
+	{
1003
+		while(is_in_str(p, in) && (*p==' '||*p=='\t'||*p==','||*p==';'))
1004
+			p++;
1005
+		if(!is_in_str(p, in))
1006
+		{
1007
+			if(head==NULL)
1008
+				LM_ERR("wrong item name list [%.*s]\n", in->len, in->s);
1009
+			return head;
1010
+		}
1011
+		s.s=p;
1012
+		s.len = in->s+in->len-p;
1013
+		p = pv_parse_spec(&s, &spec);
1014
+		if(p==NULL || (type && spec.type!=type))
1015
+		{
1016
+			LM_ERR("wrong item name list [%.*s]!\n", in->len, in->s);
1017
+			goto error;
1018
+		}
1019
+		al = (pvname_list_t*)pkg_malloc(sizeof(pvname_list_t));
1020
+		if(al==NULL)
1021
+		{
1022
+			LM_ERR("no more memory!\n");
1023
+			goto error;
1024
+		}
1025
+		memset(al, 0, sizeof(pvname_list_t));
1026
+		memcpy(&al->sname, &spec, sizeof(pv_spec_t));
1027
+
1028
+		if(last==NULL)
1029
+		{
1030
+			head = al;
1031
+			last = al;
1032
+		} else {
1033
+			last->next = al;
1034
+			last = al;
1035
+		}
1036
+	}
1037
+
1038
+	return head;
1039
+
1040
+error:
1041
+	while(head)
1042
+	{
1043
+		al = head;
1044
+		head=head->next;
1045
+		pkg_free(al);
1046
+	}
1047
+	return NULL;
1048
+}
981 1049
 
982 1050
 /**
983 1051
  *
... ...
@@ -1259,7 +1327,7 @@ int tr_table_add(tr_export_t *e)
1259 1327
 	tr_item_t *trj = NULL;
1260 1328
 	tr_item_t *trn = NULL;
1261 1329
 	int found;
1262
-	int trid;
1330
+	unsigned int trid;
1263 1331
 
1264 1332
 	if(e==NULL || e->tclass.s==NULL)
1265 1333
 	{
... ...
@@ -297,6 +297,27 @@ static inline char* int2str(unsigned int l, int* len)
297 297
 	return &r[i+1];
298 298
 }
299 299
 
300
+/* Signed INTeger-TO-STRing: convers a long to a string
301
+ * returns a pointer to a static buffer containing l in asciiz & sets len */
302
+static inline char* sint2str(long l, int* len)
303
+{
304
+	int sign;
305
+	char *p;
306
+
307
+	sign = 0;
308
+	if(l<0) {
309
+		sign = 1;
310
+		l = -l;
311
+	}
312
+	p = int2str((unsigned long)l, len);
313
+	if(sign) {
314
+		*(--p) = '-';
315
+		if (len) (*len)++;
316
+	}
317
+	return p;
318
+}
319
+
320
+
300 321
 
301 322
 
302 323
 #define USHORT2SBUF_MAX_LEN  5 /* 65535*/