浏览代码

- forward_{udp,tcp,tls} fix: if one of them is used (instead of simple forward) force the corresponding protocol and don't use the uri one

Andrei Pelinescu-Onciul 21 年之前
父节点
当前提交
87deb93ff8
共有 2 个文件被更改,包括 30 次插入25 次删除
  1. 1 1
      Makefile.defs
  2. 29 24
      action.c

+ 1 - 1
Makefile.defs

@@ -48,7 +48,7 @@ MAIN_NAME=ser
 VERSION = 0
 PATCHLEVEL = 8
 SUBLEVEL =   99
-EXTRAVERSION = -dev1
+EXTRAVERSION = -dev2
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")

+ 29 - 24
action.c

@@ -120,7 +120,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 #ifdef USE_TLS
 			else if (a->type==FORWARD_TLS_T) proto= PROTO_TLS;
 #endif
-			else proto=msg->rcv.proto;
+			else proto= PROTO_NONE;
 			if (a->p1_type==URIHOST_ST){
 				/*parse uri*/
 
@@ -151,36 +151,39 @@ int do_action(struct action* a, struct sip_msg* msg)
 							ret=E_UNSPEC;
 							goto error_fwd_uri;
 				}
-				switch(u->proto){
-					case PROTO_NONE:
-						proto=PROTO_UDP;
-						break;
-					case PROTO_UDP:
+				if (proto == PROTO_NONE){ /* only if proto not set get it
+											 from the uri */
+					switch(u->proto){
+						case PROTO_NONE:
+							proto=PROTO_UDP;
+							break;
+						case PROTO_UDP:
 #ifdef USE_TCP
-					case PROTO_TCP:
+						case PROTO_TCP:
 #endif
 #ifdef USE_TLS
-					case PROTO_TLS:
+						case PROTO_TLS:
 #endif
-						proto=u->proto;
-						break;
-					default:
-						LOG(L_ERR,"ERROR: do action: forward: bad uri"
-								" transport %d\n", u->proto);
-						ret=E_BAD_PROTO;
-						goto error_fwd_uri;
-				}
+							proto=u->proto;
+							break;
+						default:
+							LOG(L_ERR,"ERROR: do action: forward: bad uri"
+									" transport %d\n", u->proto);
+							ret=E_BAD_PROTO;
+							goto error_fwd_uri;
+					}
 #ifdef USE_TLS
-				if (u->secure){
-					if (u->proto==PROTO_UDP){
-						LOG(L_ERR, "ERROR: do_action: forward: secure uri"
-								" incompatible with transport %d\n", u->proto);
-						ret=E_BAD_PROTO;
-						goto error_fwd_uri;
+					if (u->secure){
+						if (u->proto==PROTO_UDP){
+							LOG(L_ERR, "ERROR: do_action: forward: secure uri"
+									" incompatible with transport %d\n", u->proto);
+							ret=E_BAD_PROTO;
+							goto error_fwd_uri;
+						}
+						proto=PROTO_TLS;
 					}
-					proto=PROTO_TLS;
-				}
 #endif
+				}
 				/* create a temporary proxy*/
 				p=mk_proxy(&u->host, port, proto);
 				if (p==0){
@@ -195,6 +198,8 @@ int do_action(struct action* a, struct sip_msg* msg)
 				pkg_free(p);
 				if (ret>=0) ret=1;
 			}else if ((a->p1_type==PROXY_ST) && (a->p2_type==NUMBER_ST)){
+				if (proto==PROTO_NONE)
+					proto=msg->rcv.proto;
 				ret=forward_request(msg,(struct proxy_l*)a->p1.data, proto);
 				if (ret>=0) ret=1;
 			}else{