Browse code

- 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 authored on 11/04/2003 16:58:29
Showing 6 changed files
... ...
@@ -21,7 +21,7 @@
21 21
 VERSION = 0
22 22
 PATCHLEVEL = 8
23 23
 SUBLEVEL =   11
24
-EXTRAVERSION = pre15-new_parse_uri
24
+EXTRAVERSION = pre16
25 25
 
26 26
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
27 27
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -213,6 +213,10 @@ ifeq ($(mode),)
213 213
 	mode = release
214 214
 endif
215 215
 
216
+ifeq ($(mode),debug)
217
+	DEFS+= -DEXTRA_DEBUG
218
+endif
219
+
216 220
 # platform dependent settings
217 221
 
218 222
 
... ...
@@ -141,6 +141,22 @@ int do_action(struct action* a, struct sip_msg* msg)
141 141
 							ret=E_UNSPEC;
142 142
 							goto error_fwd_uri;
143 143
 				}
144
+				switch(u->proto){
145
+					case PROTO_NONE:
146
+						proto=PROTO_UDP;
147
+						break;
148
+					case PROTO_UDP:
149
+#ifdef USE_TCP
150
+					case PROTO_TCP:
151
+#endif
152
+						proto=u->proto;
153
+						break;
154
+					default:
155
+						LOG(L_ERR,"ERROR: do action: forward: bad uri protocol"
156
+								" %d\n", u->proto);
157
+						ret=E_BAD_PROTO;
158
+						goto error_fwd_uri;
159
+				}
144 160
 				/* create a temporary proxy*/
145 161
 				p=mk_proxy(&u->host, port, proto);
146 162
 				if (p==0){
... ...
@@ -55,6 +55,8 @@
55 55
 #define E_BAD_ADDRESS -478
56 56
 /* unparseable URI */
57 57
 #define E_BAD_URI 	  -479
58
+/* bad protocol, like */
59
+#define E_BAD_PROTO	  -480
58 60
 /* misformated request */
59 61
 #define E_BAD_REQ	  -400
60 62
 
... ...
@@ -30,6 +30,7 @@
30 30
  *             introduced (jiri)
31 31
  * 2003-04-11  new parse_uri introduced (better, parses also some parameters,
32 32
  *              works in one pass) (andrei)
33
+ * 2003-04-11  ser_error is now set in parse_uri (andrei)
33 34
  */
34 35
 
35 36
 
... ...
@@ -902,38 +903,44 @@ int parse_uri(char* buf, int len, struct sip_uri* uri)
902 902
 error_too_short:
903 903
 	LOG(L_ERR, "ERROR: parse_uri: uri too short: <%.*s> (%d)\n",
904 904
 			len, buf, len);
905
-	return -1;
905
+	ser_error=E_BAD_URI;
906
+	return E_BAD_URI;
906 907
 error_bad_char:
907 908
 	LOG(L_ERR, "ERROR: parse_uri: bad char '%c' in state %d"
908 909
 			" parsed: <%.*s> (%d) / <%.*s> (%d)\n",
909 910
 			*p, state, (p-buf), buf, (p-buf), len, buf, len);
910
-	return -1;
911
+	return E_BAD_URI;
911 912
 error_bad_host:
912 913
 	LOG(L_ERR, "ERROR: parse_uri: bad host in uri (error at char %c in"
913 914
 			" state %d) parsed: <%.*s>(%d) /<%.*s> (%d)\n",
914 915
 			*p, state, (p-buf), buf, (p-buf), len, buf, len);
915
-	return -1;
916
+	ser_error=E_BAD_URI;
917
+	return E_BAD_URI;
916 918
 error_bad_port:
917 919
 	LOG(L_ERR, "ERROR: parse_uri: bad port in uri (error at char %c in"
918 920
 			" state %d) parsed: <%.*s>(%d) /<%.*s> (%d)\n",
919 921
 			*p, state, (p-buf), buf, (p-buf), len, buf, len);
920
-	return -1;
922
+	ser_error=E_BAD_URI;
923
+	return E_BAD_URI;
921 924
 error_bad_uri:
922 925
 	LOG(L_ERR, "ERROR: parse_uri: bad uri,  state %d"
923 926
 			" parsed: <%.*s> (%d) / <%.*s> (%d)\n",
924 927
 			 state, (p-buf), buf, (p-buf), len, buf, len);
925
-	return -1;
928
+	ser_error=E_BAD_URI;
929
+	return E_BAD_URI;
926 930
 error_headers:
927 931
 	LOG(L_ERR, "ERROR: parse_uri: bad uri headers: <%.*s>(%d)"
928 932
 			" / <%.*s>(%d)\n",
929 933
 			uri->headers.len, uri->headers.s, uri->headers.len,
930 934
 			len, buf, len);
931
-	return -1;
935
+	ser_error=E_BAD_URI;
936
+	return E_BAD_URI;
932 937
 error_bug:
933 938
 	LOG(L_CRIT, "BUG: parse_uri: bad  state %d"
934 939
 			" parsed: <%.*s> (%d) / <%.*s> (%d)\n",
935 940
 			 state, (p-buf), buf, (p-buf), len, buf, len);
936
-	return -1;
941
+	ser_error=E_BAD_URI;
942
+	return E_BAD_URI;
937 943
 }
938 944
 
939 945
 #else /* PARSE_URI_OLD */
... ...
@@ -277,21 +277,27 @@ struct tcp_connection* _tcpconn_find(int id, struct ip_addr* ip, int port)
277 277
 	struct tcp_connection *c;
278 278
 	unsigned hash;
279 279
 	
280
+#ifdef EXTRA_DEBUG
280 281
 	DBG("tcpconn_find: %d ",id ); print_ip(ip); DBG(" %d\n", port);
282
+#endif
281 283
 	if (id){
282 284
 		hash=tcp_id_hash(id);
283 285
 		for (c=tcpconn_id_hash[hash]; c; c=c->id_next){
286
+#ifdef EXTRA_DEBUG
284 287
 			DBG("c=%p, c->id=%d, ip=",c, c->id);
285 288
 			print_ip(&c->rcv.src_ip);
286 289
 			DBG(" port=%d\n", c->rcv.src_port);
290
+#endif
287 291
 			if ((id==c->id)&&(!c->bad)) return c;
288 292
 		}
289 293
 	}else if (ip){
290 294
 		hash=tcp_addr_hash(ip, port);
291 295
 		for (c=tcpconn_addr_hash[hash]; c; c=c->next){
296
+#ifdef EXTRA_DEBUG
292 297
 			DBG("c=%p, c->id=%d, ip=",c, c->id);
293 298
 			print_ip(&c->rcv.src_ip);
294 299
 			DBG(" port=%d\n", c->rcv.src_port);
300
+#endif
295 301
 			if ( (!c->bad) && (port==c->rcv.src_port) &&
296 302
 					(ip_addr_cmp(ip, &c->rcv.src_ip)) )
297 303
 				return c;
... ...
@@ -84,8 +84,9 @@ again:
84 84
 			return -1;
85 85
 		}
86 86
 	}
87
+#ifdef EXTRA_DEBUG
87 88
 	DBG("tcp_read: read %d bytes:\n%.*s\n", bytes_read, bytes_read, r->pos);
88
-	
89
+#endif
89 90
 	r->pos+=bytes_read;
90 91
 	return bytes_read;
91 92
 }
... ...
@@ -93,10 +94,10 @@ again:
93 93
 
94 94
 
95 95
 /* reads all headers (until double crlf), & parses the content-length header
96
- * (WARNING: highly ineficient, tries to reuse receive_msg but will parse
97
- *  all the header names twice [once here & once in receive_msg]; a more
98
- *  speed eficient version will result in either major code duplication or
99
- *  major changes to the receive code - TODO)
96
+ * (WARNING: ineficient, tries to reuse receive_msg but will go through
97
+ * the headers twice [once here looking for Content-Length and for the end
98
+ * of the headers and once in receive_msg]; a more speed eficient version will
99
+ * result in either major code duplication or major changes to the receive code)
100 100
  * returns number of bytes read & sets r->state & r->body
101 101
  * when either r->body!=0 or r->state==H_BODY =>
102 102
  * 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)
184 184
 					case '\n':
185 185
 						/* found LF LF */
186 186
 						r->state=H_BODY;
187
-						DBG("tcp_read_headers: switching to H_BODY (lflf)\n");
188 187
 						if (r->has_content_len){
189 188
 							r->body=p+1;
190 189
 							r->bytes_to_go=r->content_len;
... ...
@@ -209,7 +209,6 @@ int tcp_read_headers(struct tcp_req *r, int fd)
209 209
 				if (*p=='\n'){
210 210
 					/* found LF CR LF */
211 211
 					r->state=H_BODY;
212
-					DBG("tcp_read_headers: switching to H_BODY (lfcrlf)\n");
213 212
 					if (r->has_content_len){
214 213
 						r->body=p+1;
215 214
 						r->bytes_to_go=r->content_len;
... ...
@@ -367,6 +366,7 @@ int tcp_read_req(struct tcp_connection* con)
367 367
 again:
368 368
 		if(req->complete==0 && req->error==TCP_REQ_OK){
369 369
 			bytes=tcp_read_headers(req, s);
370
+#ifdef EXTRA_DEBUG
370 371
 						/* if timeout state=0; goto end__req; */
371 372
 			DBG("read= %d bytes, parsed=%d, state=%d, error=%d\n",
372 373
 					bytes, (int)(req->parsed-req->start), req->state,
... ...
@@ -374,6 +374,7 @@ again:
374 374
 			DBG("tcp_read_req: last char=%X, parsed msg=\n%.*s\n",
375 375
 					*(req->parsed-1), (int)(req->parsed-req->start),
376 376
 					req->start);
377
+#endif
377 378
 			if (bytes==-1){
378 379
 				LOG(L_ERR, "ERROR: tcp_read_req: error reading \n");
379 380
 				resp=CONN_ERROR;
... ...
@@ -397,14 +398,18 @@ again:
397 397
 			goto end_req;
398 398
 		}
399 399
 		if (req->complete){
400
+#ifdef EXTRA_DEBUG
400 401
 			DBG("tcp_read_req: end of header part\n");
401 402
 			DBG("- received from: port %d, ip - ", con->rcv.src_port);
402 403
 			print_ip(&con->rcv.src_ip); DBG("-\n");
403 404
 			DBG("tcp_read_req: headers:\n%.*s.\n",
404 405
 					(int)(req->body-req->start), req->start);
406
+#endif
405 407
 			if (req->has_content_len){
406 408
 				DBG("tcp_read_req: content-length= %d\n", req->content_len);
409
+#ifdef EXTRA_DEBUG
407 410
 				DBG("tcp_read_req: body:\n%.*s\n", req->content_len,req->body);
411
+#endif
408 412
 			}else{
409 413
 				req->error=TCP_REQ_BAD_LEN;
410 414
 				LOG(L_ERR, "ERROR: tcp_read_req: content length not present or"
... ...
@@ -414,10 +419,13 @@ again:
414 414
 			}
415 415
 			/* if we are here everything is nice and ok*/
416 416
 			resp=CONN_RELEASE;
417
+#ifdef EXTRA_DEBUG
417 418
 			DBG("calling receive_msg(%p, %d, )\n",
418 419
 					req->start, (int)(req->parsed-req->start));
419
-			/* just for debugging use sendipv4 as receiving socket  FIXME*/
420
+#endif
421
+			/* rcv.bind_address should always be !=0 */
420 422
 			bind_address=con->rcv.bind_address;
423
+			/* just for debugging use sendipv4 as receiving socket  FIXME*/
421 424
 			/*
422 425
 			if (con->rcv.dst_ip.af==AF_INET6){
423 426
 				bind_address=sendipv6_tcp;
... ...
@@ -440,8 +448,10 @@ again:
440 440
 			/* prepare for next request */
441 441
 			size=req->pos-req->parsed;
442 442
 			if (size) memmove(req->buf, req->parsed, size);
443
+#ifdef EXTRA_DEBUG
443 444
 			DBG("tcp_read_req: preparing for new request, kept %ld bytes\n",
444 445
 					size);
446
+#endif
445 447
 			req->pos=req->buf+size;
446 448
 			req->parsed=req->buf;
447 449
 			req->start=req->buf;
... ...
@@ -520,7 +530,6 @@ void tcp_receive_loop(int unix_sock)
520 520
 				continue;
521 521
 			}
522 522
 			if (FD_ISSET(unix_sock, &sel_set)){
523
-				DBG("tcp receive: receiving fd from from 'main'\n");
524 523
 				nfds--;
525 524
 				/* a new conn from "main" */
526 525
 				n=receive_fd(unix_sock, &con, sizeof(con), &s);