浏览代码

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;[email protected];user=phone"
became
"sip:[email protected];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 16 年之前
父节点
当前提交
773f8568be
共有 3 个文件被更改,包括 30 次插入15 次删除
  1. 22 15
      action.c
  2. 5 0
      parser/msg_parser.h
  3. 3 0
      parser/parse_uri.c

+ 22 - 15
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;
 					}

+ 5 - 0
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 */

+ 3 - 0
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 {