Browse code

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@foo.com;user=phone"
became
"sip:456@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.

Miklos Tirpak authored on 29/04/2009 13:55:13
Showing 3 changed files
... ...
@@ -123,7 +123,6 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
123 123
 	struct rvalue* rv1;
124 124
 	struct rval_cache c1;
125 125
 	str s;
126
-	int orig_p2t;
127 126
 
128 127
 	/* reset the value of error to E_UNSPEC so avoid unknowledgable
129 128
 	   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)
538 538
 					ret=1;
539 539
 					break;
540 540
 				}
541
-				if ((msg->parsed_uri_ok==0) || ((uri.flags & URI_SIP_USER_PHONE)!=0)) {
541
+				if (msg->parsed_uri_ok==0) {
542 542
 					if (msg->new_uri.s) {
543 543
 						tmp=msg->new_uri.s;
544 544
 						len=msg->new_uri.len;
... ...
@@ -546,18 +545,12 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
546 546
 						tmp=msg->first_line.u.request.uri.s;
547 547
 						len=msg->first_line.u.request.uri.len;
548 548
 					}
549
-					/* don't convert sip:user=phone to tel, otherwise we loose parameters */
550
-					orig_p2t=phone2tel;
551
-					phone2tel=0;
552
-					msg->parsed_uri_ok=0;
553 549
 					if (parse_uri(tmp, len, &uri)<0){
554
-						phone2tel=orig_p2t;
555 550
 						LOG(L_ERR, "ERROR: do_action: bad uri <%s>, dropping"
556 551
 									" packet\n", tmp);
557 552
 						ret=E_UNSPEC;
558 553
 						break;
559 554
 					}
560
-					phone2tel=orig_p2t;
561 555
 				} else {
562 556
 					uri=msg->parsed_uri;
563 557
 				}
... ...
@@ -701,6 +694,17 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
701 701
 					*crt=':'; crt++;
702 702
 					memcpy(crt,tmp,len);crt+=len;
703 703
 				}
704
+				/* tel: URI parameters */
705
+				if ((uri.type==TEL_URI_T)
706
+					|| (uri.type==TELS_URI_T)
707
+				) {
708
+					tmp=uri.params.s;
709
+					if (tmp){
710
+						len=uri.params.len; if(crt+len+1>end) goto error_uri;
711
+						*crt=';'; crt++;
712
+						memcpy(crt,tmp,len);crt+=len;
713
+					}
714
+				}
704 715
 				/* host */
705 716
 				if ((a->type==SET_HOST_T)
706 717
 						|| (a->type==SET_HOSTPORT_T)
... ...
@@ -747,17 +751,20 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
747 747
 					memcpy(crt,tmp,len);crt+=len;
748 748
 				}
749 749
 				/* params */
750
-				if ((a->type==SET_HOSTPORTTRANS_T) && uri.transport.s) {
750
+				if ((a->type==SET_HOSTPORTTRANS_T)
751
+					&& uri.sip_params.s
752
+					&& uri.transport.s
753
+				) {
751 754
 					/* bypass the transport parameter */
752
-					if (uri.params.s < uri.transport.s) {
755
+					if (uri.sip_params.s < uri.transport.s) {
753 756
 						/* there are parameters before transport */
754
-						len = uri.transport.s - uri.params.s - 1;
757
+						len = uri.transport.s - uri.sip_params.s - 1;
755 758
 							/* ignore the ';' at the end */
756 759
 						if (crt+len+1>end) goto error_uri;
757 760
 						*crt=';'; crt++;
758
-						memcpy(crt,uri.params.s,len);crt+=len;
761
+						memcpy(crt,uri.sip_params.s,len);crt+=len;
759 762
 					}
760
-					len = (uri.params.s + uri.params.len) -
763
+					len = (uri.sip_params.s + uri.sip_params.len) -
761 764
 						(uri.transport.s + uri.transport.len);
762 765
 					if (len > 0) {
763 766
 						/* there are parameters after transport */
... ...
@@ -766,9 +773,9 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
766 766
 						memcpy(crt,tmp,len);crt+=len;
767 767
 					}
768 768
 				} else {
769
-					tmp=uri.params.s;
769
+					tmp=uri.sip_params.s;
770 770
 					if (tmp){
771
-						len=uri.params.len; if(crt+len+1>end) goto error_uri;
771
+						len=uri.sip_params.len; if(crt+len+1>end) goto error_uri;
772 772
 						*crt=';'; crt++;
773 773
 						memcpy(crt,tmp,len);crt+=len;
774 774
 					}
... ...
@@ -188,6 +188,11 @@ struct sip_uri {
188 188
 	str host;     /* Host name */
189 189
 	str port;     /* Port number */
190 190
 	str params;   /* Parameters */
191
+	str sip_params; /* Parameters of the sip: URI.
192
+			  * (If a tel: URI is embedded in a sip: URI, then
193
+			  * params points to the parameters of the tel: URI,
194
+			  * and sip_params to the parameters of the sip: URI. 
195
+			  */
191 196
 	str headers;
192 197
 	unsigned short port_no;
193 198
 	unsigned short proto; /* from transport */
... ...
@@ -1102,6 +1102,8 @@ int parse_uri(char* buf, int len, struct sip_uri* uri)
1102 1102
 	switch(uri->type){
1103 1103
 		case SIPS_URI_T:
1104 1104
 		case SIP_URI_T:
1105
+			/* save the original sip: URI parameters in sip_params */
1106
+			uri->sip_params=uri->params;
1105 1107
 			if ((phone2tel) &&
1106 1108
 			     (uri->user_param_val.len == 5) &&
1107 1109
 				 (strncmp(uri->user_param_val.s, "phone", 5) == 0)
... ...
@@ -1120,6 +1122,7 @@ int parse_uri(char* buf, int len, struct sip_uri* uri)
1120 1120
 					uri->params.len=uri->user.s+uri->user.len-uri->params.s;
1121 1121
 					uri->user.len=p-uri->user.s;
1122 1122
 				} else {
1123
+					uri->params.s=0;
1123 1124
 					uri->params.len=0;
1124 1125
 				}
1125 1126
 			} else {