浏览代码

- mode=debug => -DEXTRA_DEBUG
- a lot of the tcp debugging messages are displayed now only if EXTRA_DEBUG is
defined
- parse_uri sets now ser_error
- forward(uri:host,...) will use the protocol in the uri

Andrei Pelinescu-Onciul 22 年之前
父节点
当前提交
f2e456c301
共有 6 个文件被更改,包括 61 次插入17 次删除
  1. 5 1
      Makefile.defs
  2. 16 0
      action.c
  3. 2 0
      error.h
  4. 14 7
      parser/parse_uri.c
  5. 6 0
      tcp_main.c
  6. 18 9
      tcp_read.c

+ 5 - 1
Makefile.defs

@@ -21,7 +21,7 @@
 VERSION = 0
 VERSION = 0
 PATCHLEVEL = 8
 PATCHLEVEL = 8
 SUBLEVEL =   11
 SUBLEVEL =   11
-EXTRAVERSION = pre15-new_parse_uri
+EXTRAVERSION = pre16
 
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
@@ -213,6 +213,10 @@ ifeq ($(mode),)
 	mode = release
 	mode = release
 endif
 endif
 
 
+ifeq ($(mode),debug)
+	DEFS+= -DEXTRA_DEBUG
+endif
+
 # platform dependent settings
 # platform dependent settings
 
 
 
 

+ 16 - 0
action.c

@@ -141,6 +141,22 @@ int do_action(struct action* a, struct sip_msg* msg)
 							ret=E_UNSPEC;
 							ret=E_UNSPEC;
 							goto error_fwd_uri;
 							goto error_fwd_uri;
 				}
 				}
+				switch(u->proto){
+					case PROTO_NONE:
+						proto=PROTO_UDP;
+						break;
+					case PROTO_UDP:
+#ifdef USE_TCP
+					case PROTO_TCP:
+#endif
+						proto=u->proto;
+						break;
+					default:
+						LOG(L_ERR,"ERROR: do action: forward: bad uri protocol"
+								" %d\n", u->proto);
+						ret=E_BAD_PROTO;
+						goto error_fwd_uri;
+				}
 				/* create a temporary proxy*/
 				/* create a temporary proxy*/
 				p=mk_proxy(&u->host, port, proto);
 				p=mk_proxy(&u->host, port, proto);
 				if (p==0){
 				if (p==0){

+ 2 - 0
error.h

@@ -55,6 +55,8 @@
 #define E_BAD_ADDRESS -478
 #define E_BAD_ADDRESS -478
 /* unparseable URI */
 /* unparseable URI */
 #define E_BAD_URI 	  -479
 #define E_BAD_URI 	  -479
+/* bad protocol, like */
+#define E_BAD_PROTO	  -480
 /* misformated request */
 /* misformated request */
 #define E_BAD_REQ	  -400
 #define E_BAD_REQ	  -400
 
 

+ 14 - 7
parser/parse_uri.c

@@ -30,6 +30,7 @@
  *             introduced (jiri)
  *             introduced (jiri)
  * 2003-04-11  new parse_uri introduced (better, parses also some parameters,
  * 2003-04-11  new parse_uri introduced (better, parses also some parameters,
  *              works in one pass) (andrei)
  *              works in one pass) (andrei)
+ * 2003-04-11  ser_error is now set in parse_uri (andrei)
  */
  */
 
 
 
 
@@ -902,38 +903,44 @@ int parse_uri(char* buf, int len, struct sip_uri* uri)
 error_too_short:
 error_too_short:
 	LOG(L_ERR, "ERROR: parse_uri: uri too short: <%.*s> (%d)\n",
 	LOG(L_ERR, "ERROR: parse_uri: uri too short: <%.*s> (%d)\n",
 			len, buf, len);
 			len, buf, len);
-	return -1;
+	ser_error=E_BAD_URI;
+	return E_BAD_URI;
 error_bad_char:
 error_bad_char:
 	LOG(L_ERR, "ERROR: parse_uri: bad char '%c' in state %d"
 	LOG(L_ERR, "ERROR: parse_uri: bad char '%c' in state %d"
 			" parsed: <%.*s> (%d) / <%.*s> (%d)\n",
 			" parsed: <%.*s> (%d) / <%.*s> (%d)\n",
 			*p, state, (p-buf), buf, (p-buf), len, buf, len);
 			*p, state, (p-buf), buf, (p-buf), len, buf, len);
-	return -1;
+	return E_BAD_URI;
 error_bad_host:
 error_bad_host:
 	LOG(L_ERR, "ERROR: parse_uri: bad host in uri (error at char %c in"
 	LOG(L_ERR, "ERROR: parse_uri: bad host in uri (error at char %c in"
 			" state %d) parsed: <%.*s>(%d) /<%.*s> (%d)\n",
 			" state %d) parsed: <%.*s>(%d) /<%.*s> (%d)\n",
 			*p, state, (p-buf), buf, (p-buf), len, buf, len);
 			*p, state, (p-buf), buf, (p-buf), len, buf, len);
-	return -1;
+	ser_error=E_BAD_URI;
+	return E_BAD_URI;
 error_bad_port:
 error_bad_port:
 	LOG(L_ERR, "ERROR: parse_uri: bad port in uri (error at char %c in"
 	LOG(L_ERR, "ERROR: parse_uri: bad port in uri (error at char %c in"
 			" state %d) parsed: <%.*s>(%d) /<%.*s> (%d)\n",
 			" state %d) parsed: <%.*s>(%d) /<%.*s> (%d)\n",
 			*p, state, (p-buf), buf, (p-buf), len, buf, len);
 			*p, state, (p-buf), buf, (p-buf), len, buf, len);
-	return -1;
+	ser_error=E_BAD_URI;
+	return E_BAD_URI;
 error_bad_uri:
 error_bad_uri:
 	LOG(L_ERR, "ERROR: parse_uri: bad uri,  state %d"
 	LOG(L_ERR, "ERROR: parse_uri: bad uri,  state %d"
 			" parsed: <%.*s> (%d) / <%.*s> (%d)\n",
 			" parsed: <%.*s> (%d) / <%.*s> (%d)\n",
 			 state, (p-buf), buf, (p-buf), len, buf, len);
 			 state, (p-buf), buf, (p-buf), len, buf, len);
-	return -1;
+	ser_error=E_BAD_URI;
+	return E_BAD_URI;
 error_headers:
 error_headers:
 	LOG(L_ERR, "ERROR: parse_uri: bad uri headers: <%.*s>(%d)"
 	LOG(L_ERR, "ERROR: parse_uri: bad uri headers: <%.*s>(%d)"
 			" / <%.*s>(%d)\n",
 			" / <%.*s>(%d)\n",
 			uri->headers.len, uri->headers.s, uri->headers.len,
 			uri->headers.len, uri->headers.s, uri->headers.len,
 			len, buf, len);
 			len, buf, len);
-	return -1;
+	ser_error=E_BAD_URI;
+	return E_BAD_URI;
 error_bug:
 error_bug:
 	LOG(L_CRIT, "BUG: parse_uri: bad  state %d"
 	LOG(L_CRIT, "BUG: parse_uri: bad  state %d"
 			" parsed: <%.*s> (%d) / <%.*s> (%d)\n",
 			" parsed: <%.*s> (%d) / <%.*s> (%d)\n",
 			 state, (p-buf), buf, (p-buf), len, buf, len);
 			 state, (p-buf), buf, (p-buf), len, buf, len);
-	return -1;
+	ser_error=E_BAD_URI;
+	return E_BAD_URI;
 }
 }
 
 
 #else /* PARSE_URI_OLD */
 #else /* PARSE_URI_OLD */

+ 6 - 0
tcp_main.c

@@ -277,21 +277,27 @@ struct tcp_connection* _tcpconn_find(int id, struct ip_addr* ip, int port)
 	struct tcp_connection *c;
 	struct tcp_connection *c;
 	unsigned hash;
 	unsigned hash;
 	
 	
+#ifdef EXTRA_DEBUG
 	DBG("tcpconn_find: %d ",id ); print_ip(ip); DBG(" %d\n", port);
 	DBG("tcpconn_find: %d ",id ); print_ip(ip); DBG(" %d\n", port);
+#endif
 	if (id){
 	if (id){
 		hash=tcp_id_hash(id);
 		hash=tcp_id_hash(id);
 		for (c=tcpconn_id_hash[hash]; c; c=c->id_next){
 		for (c=tcpconn_id_hash[hash]; c; c=c->id_next){
+#ifdef EXTRA_DEBUG
 			DBG("c=%p, c->id=%d, ip=",c, c->id);
 			DBG("c=%p, c->id=%d, ip=",c, c->id);
 			print_ip(&c->rcv.src_ip);
 			print_ip(&c->rcv.src_ip);
 			DBG(" port=%d\n", c->rcv.src_port);
 			DBG(" port=%d\n", c->rcv.src_port);
+#endif
 			if ((id==c->id)&&(!c->bad)) return c;
 			if ((id==c->id)&&(!c->bad)) return c;
 		}
 		}
 	}else if (ip){
 	}else if (ip){
 		hash=tcp_addr_hash(ip, port);
 		hash=tcp_addr_hash(ip, port);
 		for (c=tcpconn_addr_hash[hash]; c; c=c->next){
 		for (c=tcpconn_addr_hash[hash]; c; c=c->next){
+#ifdef EXTRA_DEBUG
 			DBG("c=%p, c->id=%d, ip=",c, c->id);
 			DBG("c=%p, c->id=%d, ip=",c, c->id);
 			print_ip(&c->rcv.src_ip);
 			print_ip(&c->rcv.src_ip);
 			DBG(" port=%d\n", c->rcv.src_port);
 			DBG(" port=%d\n", c->rcv.src_port);
+#endif
 			if ( (!c->bad) && (port==c->rcv.src_port) &&
 			if ( (!c->bad) && (port==c->rcv.src_port) &&
 					(ip_addr_cmp(ip, &c->rcv.src_ip)) )
 					(ip_addr_cmp(ip, &c->rcv.src_ip)) )
 				return c;
 				return c;

+ 18 - 9
tcp_read.c

@@ -84,8 +84,9 @@ again:
 			return -1;
 			return -1;
 		}
 		}
 	}
 	}
+#ifdef EXTRA_DEBUG
 	DBG("tcp_read: read %d bytes:\n%.*s\n", bytes_read, bytes_read, r->pos);
 	DBG("tcp_read: read %d bytes:\n%.*s\n", bytes_read, bytes_read, r->pos);
-	
+#endif
 	r->pos+=bytes_read;
 	r->pos+=bytes_read;
 	return bytes_read;
 	return bytes_read;
 }
 }
@@ -93,10 +94,10 @@ again:
 
 
 
 
 /* reads all headers (until double crlf), & parses the content-length header
 /* reads all headers (until double crlf), & parses the content-length header
- * (WARNING: highly ineficient, tries to reuse receive_msg but will parse
- *  all the header names twice [once here & once in receive_msg]; a more
- *  speed eficient version will result in either major code duplication or
- *  major changes to the receive code - TODO)
+ * (WARNING: ineficient, tries to reuse receive_msg but will go through
+ * the headers twice [once here looking for Content-Length and for the end
+ * of the headers and once in receive_msg]; a more speed eficient version will
+ * result in either major code duplication or major changes to the receive code)
  * returns number of bytes read & sets r->state & r->body
  * returns number of bytes read & sets r->state & r->body
  * when either r->body!=0 or r->state==H_BODY =>
  * when either r->body!=0 or r->state==H_BODY =>
  * all headers have been read. It should be called in a while loop.
  * all headers have been read. It should be called in a while loop.
@@ -184,7 +185,6 @@ int tcp_read_headers(struct tcp_req *r, int fd)
 					case '\n':
 					case '\n':
 						/* found LF LF */
 						/* found LF LF */
 						r->state=H_BODY;
 						r->state=H_BODY;
-						DBG("tcp_read_headers: switching to H_BODY (lflf)\n");
 						if (r->has_content_len){
 						if (r->has_content_len){
 							r->body=p+1;
 							r->body=p+1;
 							r->bytes_to_go=r->content_len;
 							r->bytes_to_go=r->content_len;
@@ -209,7 +209,6 @@ int tcp_read_headers(struct tcp_req *r, int fd)
 				if (*p=='\n'){
 				if (*p=='\n'){
 					/* found LF CR LF */
 					/* found LF CR LF */
 					r->state=H_BODY;
 					r->state=H_BODY;
-					DBG("tcp_read_headers: switching to H_BODY (lfcrlf)\n");
 					if (r->has_content_len){
 					if (r->has_content_len){
 						r->body=p+1;
 						r->body=p+1;
 						r->bytes_to_go=r->content_len;
 						r->bytes_to_go=r->content_len;
@@ -367,6 +366,7 @@ int tcp_read_req(struct tcp_connection* con)
 again:
 again:
 		if(req->complete==0 && req->error==TCP_REQ_OK){
 		if(req->complete==0 && req->error==TCP_REQ_OK){
 			bytes=tcp_read_headers(req, s);
 			bytes=tcp_read_headers(req, s);
+#ifdef EXTRA_DEBUG
 						/* if timeout state=0; goto end__req; */
 						/* if timeout state=0; goto end__req; */
 			DBG("read= %d bytes, parsed=%d, state=%d, error=%d\n",
 			DBG("read= %d bytes, parsed=%d, state=%d, error=%d\n",
 					bytes, (int)(req->parsed-req->start), req->state,
 					bytes, (int)(req->parsed-req->start), req->state,
@@ -374,6 +374,7 @@ again:
 			DBG("tcp_read_req: last char=%X, parsed msg=\n%.*s\n",
 			DBG("tcp_read_req: last char=%X, parsed msg=\n%.*s\n",
 					*(req->parsed-1), (int)(req->parsed-req->start),
 					*(req->parsed-1), (int)(req->parsed-req->start),
 					req->start);
 					req->start);
+#endif
 			if (bytes==-1){
 			if (bytes==-1){
 				LOG(L_ERR, "ERROR: tcp_read_req: error reading \n");
 				LOG(L_ERR, "ERROR: tcp_read_req: error reading \n");
 				resp=CONN_ERROR;
 				resp=CONN_ERROR;
@@ -397,14 +398,18 @@ again:
 			goto end_req;
 			goto end_req;
 		}
 		}
 		if (req->complete){
 		if (req->complete){
+#ifdef EXTRA_DEBUG
 			DBG("tcp_read_req: end of header part\n");
 			DBG("tcp_read_req: end of header part\n");
 			DBG("- received from: port %d, ip - ", con->rcv.src_port);
 			DBG("- received from: port %d, ip - ", con->rcv.src_port);
 			print_ip(&con->rcv.src_ip); DBG("-\n");
 			print_ip(&con->rcv.src_ip); DBG("-\n");
 			DBG("tcp_read_req: headers:\n%.*s.\n",
 			DBG("tcp_read_req: headers:\n%.*s.\n",
 					(int)(req->body-req->start), req->start);
 					(int)(req->body-req->start), req->start);
+#endif
 			if (req->has_content_len){
 			if (req->has_content_len){
 				DBG("tcp_read_req: content-length= %d\n", req->content_len);
 				DBG("tcp_read_req: content-length= %d\n", req->content_len);
+#ifdef EXTRA_DEBUG
 				DBG("tcp_read_req: body:\n%.*s\n", req->content_len,req->body);
 				DBG("tcp_read_req: body:\n%.*s\n", req->content_len,req->body);
+#endif
 			}else{
 			}else{
 				req->error=TCP_REQ_BAD_LEN;
 				req->error=TCP_REQ_BAD_LEN;
 				LOG(L_ERR, "ERROR: tcp_read_req: content length not present or"
 				LOG(L_ERR, "ERROR: tcp_read_req: content length not present or"
@@ -414,10 +419,13 @@ again:
 			}
 			}
 			/* if we are here everything is nice and ok*/
 			/* if we are here everything is nice and ok*/
 			resp=CONN_RELEASE;
 			resp=CONN_RELEASE;
+#ifdef EXTRA_DEBUG
 			DBG("calling receive_msg(%p, %d, )\n",
 			DBG("calling receive_msg(%p, %d, )\n",
 					req->start, (int)(req->parsed-req->start));
 					req->start, (int)(req->parsed-req->start));
-			/* just for debugging use sendipv4 as receiving socket  FIXME*/
+#endif
+			/* rcv.bind_address should always be !=0 */
 			bind_address=con->rcv.bind_address;
 			bind_address=con->rcv.bind_address;
+			/* just for debugging use sendipv4 as receiving socket  FIXME*/
 			/*
 			/*
 			if (con->rcv.dst_ip.af==AF_INET6){
 			if (con->rcv.dst_ip.af==AF_INET6){
 				bind_address=sendipv6_tcp;
 				bind_address=sendipv6_tcp;
@@ -440,8 +448,10 @@ again:
 			/* prepare for next request */
 			/* prepare for next request */
 			size=req->pos-req->parsed;
 			size=req->pos-req->parsed;
 			if (size) memmove(req->buf, req->parsed, size);
 			if (size) memmove(req->buf, req->parsed, size);
+#ifdef EXTRA_DEBUG
 			DBG("tcp_read_req: preparing for new request, kept %ld bytes\n",
 			DBG("tcp_read_req: preparing for new request, kept %ld bytes\n",
 					size);
 					size);
+#endif
 			req->pos=req->buf+size;
 			req->pos=req->buf+size;
 			req->parsed=req->buf;
 			req->parsed=req->buf;
 			req->start=req->buf;
 			req->start=req->buf;
@@ -520,7 +530,6 @@ void tcp_receive_loop(int unix_sock)
 				continue;
 				continue;
 			}
 			}
 			if (FD_ISSET(unix_sock, &sel_set)){
 			if (FD_ISSET(unix_sock, &sel_set)){
-				DBG("tcp receive: receiving fd from from 'main'\n");
 				nfds--;
 				nfds--;
 				/* a new conn from "main" */
 				/* a new conn from "main" */
 				n=receive_fd(unix_sock, &con, sizeof(con), &s);
 				n=receive_fd(unix_sock, &con, sizeof(con), &s);