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 88
 	pv_item_t *pvj = NULL;
89 89
 	pv_item_t *pvn = NULL;
90 90
 	int found;
91
-	int pvid;
91
+	unsigned int pvid;
92 92
 
93 93
 	if(e==NULL || e->name.s==NULL || e->getf==NULL || e->type==PVT_NONE)
94 94
 	{
... ...
@@ -239,8 +240,7 @@ int pv_get_sintval(struct sip_msg *msg, pv_param_t *param,
239 239
 	if(res==NULL)
240 240
 		return -1;
241 241
 
242
-	// ch = sint2str(sival, &l);
243
-	ch = int2str(sival, &l);
242
+	ch = sint2str(sival, &l);
244 243
 	res->rs.s = ch;
245 244
 	res->rs.len = l;
246 245
 
... ...
@@ -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 978
 	return 0;
979 979
 }
980 980
 
981
+/**
982
+ *
983
+ */
984
+pvname_list_t* parse_pvname_list(str *in, unsigned int type)
985
+{
986
+	pvname_list_t* head = NULL;
987
+	pvname_list_t* al = NULL;
988
+	pvname_list_t* last = NULL;
989
+	char *p;
990
+	pv_spec_t spec;
991
+	str s;
992
+
993
+	if(in==NULL || in->s==NULL)
994
+	{
995
+		LM_ERR("bad parameters\n");
996
+		return NULL;
997
+	}
998
+
999
+	p = in->s;
1000
+	while(is_in_str(p, in))
1001
+	{
1002
+		while(is_in_str(p, in) && (*p==' '||*p=='\t'||*p==','||*p==';'))
1003
+			p++;
1004
+		if(!is_in_str(p, in))
1005
+		{
1006
+			if(head==NULL)
1007
+				LM_ERR("wrong item name list [%.*s]\n", in->len, in->s);
1008
+			return head;
1009
+		}
1010
+		s.s=p;
1011
+		s.len = in->s+in->len-p;
1012
+		p = pv_parse_spec(&s, &spec);
1013
+		if(p==NULL || (type && spec.type!=type))
1014
+		{
1015
+			LM_ERR("wrong item name list [%.*s]!\n", in->len, in->s);
1016
+			goto error;
1017
+		}
1018
+		al = (pvname_list_t*)pkg_malloc(sizeof(pvname_list_t));
1019
+		if(al==NULL)
1020
+		{
1021
+			LM_ERR("no more memory!\n");
1022
+			goto error;
1023
+		}
1024
+		memset(al, 0, sizeof(pvname_list_t));
1025
+		memcpy(&al->sname, &spec, sizeof(pv_spec_t));
1026
+
1027
+		if(last==NULL)
1028
+		{
1029
+			head = al;
1030
+			last = al;
1031
+		} else {
1032
+			last->next = al;
1033
+			last = al;
1034
+		}
1035
+	}
1036
+
1037
+	return head;
1038
+
1039
+error:
1040
+	while(head)
1041
+	{
1042
+		al = head;
1043
+		head=head->next;
1044
+		pkg_free(al);
1045
+	}
1046
+	return NULL;
1047
+}
981 1048
 
982 1049
 /**
983 1050
  *
... ...
@@ -1259,7 +1327,7 @@ int tr_table_add(tr_export_t *e)
1259 1259
 	tr_item_t *trj = NULL;
1260 1260
 	tr_item_t *trn = NULL;
1261 1261
 	int found;
1262
-	int trid;
1262
+	unsigned int trid;
1263 1263
 
1264 1264
 	if(e==NULL || e->tclass.s==NULL)
1265 1265
 	{
... ...
@@ -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*/