[SR-Dev] git:master: RURI manipulating functions have been fixed to preserve

Miklos Tirpak miklos at iptel.org
Wed Apr 29 16:03:01 CEST 2009


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

Author: Miklos Tirpak <miklos at iptel.org>
Committer: Miklos Tirpak <miklos at iptel.org>
Date:   Wed Apr 29 15:55:13 2009 +0200

RURI manipulating functions have been fixed to preserve
tel: URI parameters

- parameters of a tel: URI embedded in a sip URI had been lost
when SET_USER_T action was called for instance.
("sip:123;param=val at foo.com;user=phone"
became
"sip:456 at foo.com;user=phone"
after rewriting the user name.)
- sip_params variable is added to sip_uri structure to
store the original sip: URI parameters.

---

 action.c            |   37 ++++++++++++++++++++++---------------
 parser/msg_parser.h |    5 +++++
 parser/parse_uri.c  |    3 +++
 3 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/action.c b/action.c
index 1e89a64..ffc0051 100644
--- a/action.c
+++ b/action.c
@@ -123,7 +123,6 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
 	struct rvalue* rv1;
 	struct rval_cache c1;
 	str s;
-	int orig_p2t;
 
 	/* reset the value of error to E_UNSPEC so avoid unknowledgable
 	   functions to return with error (status<0) and not setting it
@@ -538,7 +537,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
 					ret=1;
 					break;
 				}
-				if ((msg->parsed_uri_ok==0) || ((uri.flags & URI_SIP_USER_PHONE)!=0)) {
+				if (msg->parsed_uri_ok==0) {
 					if (msg->new_uri.s) {
 						tmp=msg->new_uri.s;
 						len=msg->new_uri.len;
@@ -546,18 +545,12 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
 						tmp=msg->first_line.u.request.uri.s;
 						len=msg->first_line.u.request.uri.len;
 					}
-					/* don't convert sip:user=phone to tel, otherwise we loose parameters */
-					orig_p2t=phone2tel;
-					phone2tel=0;
-					msg->parsed_uri_ok=0;
 					if (parse_uri(tmp, len, &uri)<0){
-						phone2tel=orig_p2t;
 						LOG(L_ERR, "ERROR: do_action: bad uri <%s>, dropping"
 									" packet\n", tmp);
 						ret=E_UNSPEC;
 						break;
 					}
-					phone2tel=orig_p2t;
 				} else {
 					uri=msg->parsed_uri;
 				}
@@ -701,6 +694,17 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
 					*crt=':'; crt++;
 					memcpy(crt,tmp,len);crt+=len;
 				}
+				/* tel: URI parameters */
+				if ((uri.type==TEL_URI_T)
+					|| (uri.type==TELS_URI_T)
+				) {
+					tmp=uri.params.s;
+					if (tmp){
+						len=uri.params.len; if(crt+len+1>end) goto error_uri;
+						*crt=';'; crt++;
+						memcpy(crt,tmp,len);crt+=len;
+					}
+				}
 				/* host */
 				if ((a->type==SET_HOST_T)
 						|| (a->type==SET_HOSTPORT_T)
@@ -747,17 +751,20 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
 					memcpy(crt,tmp,len);crt+=len;
 				}
 				/* params */
-				if ((a->type==SET_HOSTPORTTRANS_T) && uri.transport.s) {
+				if ((a->type==SET_HOSTPORTTRANS_T)
+					&& uri.sip_params.s
+					&& uri.transport.s
+				) {
 					/* bypass the transport parameter */
-					if (uri.params.s < uri.transport.s) {
+					if (uri.sip_params.s < uri.transport.s) {
 						/* there are parameters before transport */
-						len = uri.transport.s - uri.params.s - 1;
+						len = uri.transport.s - uri.sip_params.s - 1;
 							/* ignore the ';' at the end */
 						if (crt+len+1>end) goto error_uri;
 						*crt=';'; crt++;
-						memcpy(crt,uri.params.s,len);crt+=len;
+						memcpy(crt,uri.sip_params.s,len);crt+=len;
 					}
-					len = (uri.params.s + uri.params.len) -
+					len = (uri.sip_params.s + uri.sip_params.len) -
 						(uri.transport.s + uri.transport.len);
 					if (len > 0) {
 						/* there are parameters after transport */
@@ -766,9 +773,9 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
 						memcpy(crt,tmp,len);crt+=len;
 					}
 				} else {
-					tmp=uri.params.s;
+					tmp=uri.sip_params.s;
 					if (tmp){
-						len=uri.params.len; if(crt+len+1>end) goto error_uri;
+						len=uri.sip_params.len; if(crt+len+1>end) goto error_uri;
 						*crt=';'; crt++;
 						memcpy(crt,tmp,len);crt+=len;
 					}
diff --git a/parser/msg_parser.h b/parser/msg_parser.h
index b8edc6b..ece6b18 100644
--- a/parser/msg_parser.h
+++ b/parser/msg_parser.h
@@ -188,6 +188,11 @@ struct sip_uri {
 	str host;     /* Host name */
 	str port;     /* Port number */
 	str params;   /* Parameters */
+	str sip_params; /* Parameters of the sip: URI.
+			  * (If a tel: URI is embedded in a sip: URI, then
+			  * params points to the parameters of the tel: URI,
+			  * and sip_params to the parameters of the sip: URI. 
+			  */
 	str headers;
 	unsigned short port_no;
 	unsigned short proto; /* from transport */
diff --git a/parser/parse_uri.c b/parser/parse_uri.c
index 85328f8..5b29710 100644
--- a/parser/parse_uri.c
+++ b/parser/parse_uri.c
@@ -1102,6 +1102,8 @@ int parse_uri(char* buf, int len, struct sip_uri* uri)
 	switch(uri->type){
 		case SIPS_URI_T:
 		case SIP_URI_T:
+			/* save the original sip: URI parameters in sip_params */
+			uri->sip_params=uri->params;
 			if ((phone2tel) &&
 			     (uri->user_param_val.len == 5) &&
 				 (strncmp(uri->user_param_val.s, "phone", 5) == 0)
@@ -1120,6 +1122,7 @@ int parse_uri(char* buf, int len, struct sip_uri* uri)
 					uri->params.len=uri->user.s+uri->user.len-uri->params.s;
 					uri->user.len=p-uri->user.s;
 				} else {
+					uri->params.s=0;
 					uri->params.len=0;
 				}
 			} else {




More information about the sr-dev mailing list