[SR-Dev] git:daniel/pv: fix pv&t lookup due to signness

Daniel-Constantin Mierla miconda at gmail.com
Tue Dec 9 17:14:38 CET 2008


Module: sip-router
Branch: daniel/pv
Commit: 0f09145b733ba72c2b0cd5747bf5f2b404bed6fe
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0f09145b733ba72c2b0cd5747bf5f2b404bed6fe

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Tue Dec  9 18:12:53 2008 +0200

fix pv&t lookup due to signness

- added missing functions from K

---

 pvapi.c |   80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 ut.h    |   21 ++++++++++++++++
 2 files changed, 95 insertions(+), 6 deletions(-)

diff --git a/pvapi.c b/pvapi.c
index 816bbab..9bb1de4 100644
--- a/pvapi.c
+++ b/pvapi.c
@@ -38,11 +38,11 @@
 #include "pvar.h"
 
 #define is_in_str(p, in) (p<in->s+in->len && *p)
+#define core_hash(in, a, b) get_hash1_raw((in)->s, (in)->len)
 
 #define PV_TABLE_SIZE	16
 #define TR_TABLE_SIZE	4
 
-#define core_hash(in, a, b) get_hash1_raw((in)->s, (in)->len);
 
 void tr_destroy(trans_t *t);
 void tr_free(trans_t *t);
@@ -57,6 +57,7 @@ typedef struct _pv_item
 static pv_item_t* _pv_table[PV_TABLE_SIZE];
 static int _pv_table_set = 0;
 
+
 /**
  *
  */
@@ -88,7 +89,7 @@ int pv_table_add(pv_export_t *e)
 	pv_item_t *pvj = NULL;
 	pv_item_t *pvn = NULL;
 	int found;
-	int pvid;
+	unsigned int pvid;
 
 	if(e==NULL || e->name.s==NULL || e->getf==NULL || e->type==PVT_NONE)
 	{
@@ -239,8 +240,7 @@ int pv_get_sintval(struct sip_msg *msg, pv_param_t *param,
 	if(res==NULL)
 		return -1;
 
-	// ch = sint2str(sival, &l);
-	ch = int2str(sival, &l);
+	ch = sint2str(sival, &l);
 	res->rs.s = ch;
 	res->rs.len = l;
 
@@ -822,7 +822,8 @@ int pv_get_avp_name(struct sip_msg* msg, pv_param_p ip, int_str *avp_name,
 			*name_type |= AVP_NAME_STR;
 		} else {
 			avp_name->n = ip->pvn.u.isname.name.n;
-			*name_type = 0; // &= AVP_SCRIPT_MASK;
+			/* *name_type &= AVP_SCRIPT_MASK; */
+			*name_type = 0;
 		}
 		return 0;
 	}
@@ -978,6 +979,73 @@ done:
 	return 0;
 }
 
+/**
+ *
+ */
+pvname_list_t* parse_pvname_list(str *in, unsigned int type)
+{
+	pvname_list_t* head = NULL;
+	pvname_list_t* al = NULL;
+	pvname_list_t* last = NULL;
+	char *p;
+	pv_spec_t spec;
+	str s;
+
+	if(in==NULL || in->s==NULL)
+	{
+		LM_ERR("bad parameters\n");
+		return NULL;
+	}
+
+	p = in->s;
+	while(is_in_str(p, in))
+	{
+		while(is_in_str(p, in) && (*p==' '||*p=='\t'||*p==','||*p==';'))
+			p++;
+		if(!is_in_str(p, in))
+		{
+			if(head==NULL)
+				LM_ERR("wrong item name list [%.*s]\n", in->len, in->s);
+			return head;
+		}
+		s.s=p;
+		s.len = in->s+in->len-p;
+		p = pv_parse_spec(&s, &spec);
+		if(p==NULL || (type && spec.type!=type))
+		{
+			LM_ERR("wrong item name list [%.*s]!\n", in->len, in->s);
+			goto error;
+		}
+		al = (pvname_list_t*)pkg_malloc(sizeof(pvname_list_t));
+		if(al==NULL)
+		{
+			LM_ERR("no more memory!\n");
+			goto error;
+		}
+		memset(al, 0, sizeof(pvname_list_t));
+		memcpy(&al->sname, &spec, sizeof(pv_spec_t));
+
+		if(last==NULL)
+		{
+			head = al;
+			last = al;
+		} else {
+			last->next = al;
+			last = al;
+		}
+	}
+
+	return head;
+
+error:
+	while(head)
+	{
+		al = head;
+		head=head->next;
+		pkg_free(al);
+	}
+	return NULL;
+}
 
 /**
  *
@@ -1259,7 +1327,7 @@ int tr_table_add(tr_export_t *e)
 	tr_item_t *trj = NULL;
 	tr_item_t *trn = NULL;
 	int found;
-	int trid;
+	unsigned int trid;
 
 	if(e==NULL || e->tclass.s==NULL)
 	{
diff --git a/ut.h b/ut.h
index 45cf559..db2c1f5 100644
--- a/ut.h
+++ b/ut.h
@@ -297,6 +297,27 @@ static inline char* int2str(unsigned int l, int* len)
 	return &r[i+1];
 }
 
+/* Signed INTeger-TO-STRing: convers a long to a string
+ * returns a pointer to a static buffer containing l in asciiz & sets len */
+static inline char* sint2str(long l, int* len)
+{
+	int sign;
+	char *p;
+
+	sign = 0;
+	if(l<0) {
+		sign = 1;
+		l = -l;
+	}
+	p = int2str((unsigned long)l, len);
+	if(sign) {
+		*(--p) = '-';
+		if (len) (*len)++;
+	}
+	return p;
+}
+
+
 
 
 #define USHORT2SBUF_MAX_LEN  5 /* 65535*/




More information about the sr-dev mailing list