[sr-dev] git:master: core/select: fixed @via... without header index

Daniel-Constantin Mierla miconda at gmail.com
Thu May 31 14:48:17 CEST 2012


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Thu May 31 14:44:19 2012 +0200

core/select: fixed @via... without header index

- reported by Iñaki Baz Castillo, fixes FS#138

---

 select.c      |    1 +
 select_core.c |   45 +++++++++++++++++++++++++++------------------
 2 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/select.c b/select.c
index f247687..36ae814 100644
--- a/select.c
+++ b/select.c
@@ -223,6 +223,7 @@ int parse_select (char** p, select_t** s)
 		ERR("parse_select: no free memory\n");
 		return -1;
 	}
+	memset(sel, 0, sizeof(select_t));
 	if (w_parse_select(p, sel)<0) {
 		pkg_free(sel);
 		return -2;
diff --git a/select_core.c b/select_core.c
index 94fa162..4c0ae9f 100644
--- a/select_core.c
+++ b/select_core.c
@@ -336,8 +336,9 @@ int select_via(str* res, select_t* s, struct sip_msg* msg)
 {
 	struct via_body *p = NULL;
 	
-	if (((s->n == 1) || (s->params[1].type == SEL_PARAM_STR)) && (parse_via_header(msg, 1, &p)<0)) return -1;
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
+	if ((s->n == 1) || (s->params[1].type == SEL_PARAM_STR)) {
+		if (parse_via_header(msg, 1, &p)<0) return -1;
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
 	if (!p) return -1;
 	res->s=p->name.s;
 	res->len=p->bsize;
@@ -350,8 +351,9 @@ int select_via_name(str* res, select_t* s, struct sip_msg* msg)
 	struct via_body *p = NULL;
 	
 	// it's not neccessary to test if (s->n > 1)
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
+	if (s->params[1].type == SEL_PARAM_STR) {
+		if(parse_via_header(msg, 1, &p)<0) return -1;
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
 	if (!p) return -1;
 	RETURN0_res(p->name);
 }
@@ -361,8 +363,9 @@ int select_via_version(str* res, select_t* s, struct sip_msg* msg)
 	struct via_body *p = NULL;
 	
 	// it's not neccessary to test if (s->n > 1)
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
+	if (s->params[1].type == SEL_PARAM_STR) {
+		if (parse_via_header(msg, 1, &p)<0) return -1;
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
 	if (!p) return -1;
 	RETURN0_res(p->version);
 }
@@ -372,8 +375,9 @@ int select_via_transport(str* res, select_t* s, struct sip_msg* msg)
 	struct via_body *p = NULL;
 	
 	// it's not neccessary to test if (s->n > 1)
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
+	if (s->params[1].type == SEL_PARAM_STR) {
+		if(parse_via_header(msg, 1, &p)<0) return -1;
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
 	if (!p) return -1;
 	RETURN0_res(p->transport);
 }
@@ -383,8 +387,9 @@ int select_via_host(str* res, select_t* s, struct sip_msg* msg)
 	struct via_body *p = NULL;
 	
 	// it's not neccessary to test if (s->n > 1)
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
+	if (s->params[1].type == SEL_PARAM_STR) {
+		if (parse_via_header(msg, 1, &p)<0) return -1;
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
 	if (!p) return -1;
 	RETURN0_res(p->host);
 }
@@ -394,8 +399,9 @@ int select_via_port(str* res, select_t* s, struct sip_msg* msg)
 	struct via_body *p = NULL;
 	
 	// it's not neccessary to test if (s->n > 1)
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
+	if (s->params[1].type == SEL_PARAM_STR) {
+		if (parse_via_header(msg, 1, &p)<0) return -1;
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
 	if (!p) return -1;
 	RETURN0_res(p->port_str);
 }
@@ -405,8 +411,9 @@ int select_via_comment(str* res, select_t* s, struct sip_msg* msg)
 	struct via_body *p = NULL;
 	
 	// it's not neccessary to test if (s->n > 1)
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
+	if (s->params[1].type == SEL_PARAM_STR) {
+		if(parse_via_header(msg, 1, &p)<0) return -1;
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
 	if (!p) return -1;
 	RETURN0_res(p->comment);
 }
@@ -417,8 +424,9 @@ int select_via_params(str* res, select_t* s, struct sip_msg* msg)
 	struct via_param *q;
 
 	// it's not neccessary to test if (s->n > 1)
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
+	if (s->params[1].type == SEL_PARAM_STR) {
+		if (parse_via_header(msg, 1, &p)<0) return -1;
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
 	if (!p) return -1;
 	
 	for (q = p->param_lst;q;q=q->next) {
@@ -440,8 +448,9 @@ int select_via_params_spec(str* res, select_t* s, struct sip_msg* msg)
 	}
 	
 	// it's not neccessary to test if (s->n > 1)
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
+	if (s->params[1].type != SEL_PARAM_INT) {
+		if(parse_via_header(msg, 1, &p)<0) return -1;
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
 	if (!p) return -1;
 	
 	switch (s->params[s->n-1].v.i) {




More information about the sr-dev mailing list