... | ... |
@@ -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){ |
... | ... |
@@ -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 | 903 |
error_too_short: |
903 | 904 |
LOG(L_ERR, "ERROR: parse_uri: uri too short: <%.*s> (%d)\n", |
904 | 905 |
len, buf, len); |
905 |
- return -1; |
|
906 |
+ ser_error=E_BAD_URI; |
|
907 |
+ return E_BAD_URI; |
|
906 | 908 |
error_bad_char: |
907 | 909 |
LOG(L_ERR, "ERROR: parse_uri: bad char '%c' in state %d" |
908 | 910 |
" parsed: <%.*s> (%d) / <%.*s> (%d)\n", |
909 | 911 |
*p, state, (p-buf), buf, (p-buf), len, buf, len); |
910 |
- return -1; |
|
912 |
+ return E_BAD_URI; |
|
911 | 913 |
error_bad_host: |
912 | 914 |
LOG(L_ERR, "ERROR: parse_uri: bad host in uri (error at char %c in" |
913 | 915 |
" state %d) parsed: <%.*s>(%d) /<%.*s> (%d)\n", |
914 | 916 |
*p, state, (p-buf), buf, (p-buf), len, buf, len); |
915 |
- return -1; |
|
917 |
+ ser_error=E_BAD_URI; |
|
918 |
+ return E_BAD_URI; |
|
916 | 919 |
error_bad_port: |
917 | 920 |
LOG(L_ERR, "ERROR: parse_uri: bad port in uri (error at char %c in" |
918 | 921 |
" state %d) parsed: <%.*s>(%d) /<%.*s> (%d)\n", |
919 | 922 |
*p, state, (p-buf), buf, (p-buf), len, buf, len); |
920 |
- return -1; |
|
923 |
+ ser_error=E_BAD_URI; |
|
924 |
+ return E_BAD_URI; |
|
921 | 925 |
error_bad_uri: |
922 | 926 |
LOG(L_ERR, "ERROR: parse_uri: bad uri, state %d" |
923 | 927 |
" parsed: <%.*s> (%d) / <%.*s> (%d)\n", |
924 | 928 |
state, (p-buf), buf, (p-buf), len, buf, len); |
925 |
- return -1; |
|
929 |
+ ser_error=E_BAD_URI; |
|
930 |
+ return E_BAD_URI; |
|
926 | 931 |
error_headers: |
927 | 932 |
LOG(L_ERR, "ERROR: parse_uri: bad uri headers: <%.*s>(%d)" |
928 | 933 |
" / <%.*s>(%d)\n", |
929 | 934 |
uri->headers.len, uri->headers.s, uri->headers.len, |
930 | 935 |
len, buf, len); |
931 |
- return -1; |
|
936 |
+ ser_error=E_BAD_URI; |
|
937 |
+ return E_BAD_URI; |
|
932 | 938 |
error_bug: |
933 | 939 |
LOG(L_CRIT, "BUG: parse_uri: bad state %d" |
934 | 940 |
" parsed: <%.*s> (%d) / <%.*s> (%d)\n", |
935 | 941 |
state, (p-buf), buf, (p-buf), len, buf, len); |
936 |
- return -1; |
|
942 |
+ ser_error=E_BAD_URI; |
|
943 |
+ return E_BAD_URI; |
|
937 | 944 |
} |
938 | 945 |
|
939 | 946 |
#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 | 94 |
|
94 | 95 |
|
95 | 96 |
/* 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) |
|
97 |
+ * (WARNING: ineficient, tries to reuse receive_msg but will go through |
|
98 |
+ * the headers twice [once here looking for Content-Length and for the end |
|
99 |
+ * of the headers and once in receive_msg]; a more speed eficient version will |
|
100 |
+ * result in either major code duplication or major changes to the receive code) |
|
100 | 101 |
* returns number of bytes read & sets r->state & r->body |
101 | 102 |
* when either r->body!=0 or r->state==H_BODY => |
102 | 103 |
* 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 | 185 |
case '\n': |
185 | 186 |
/* found LF LF */ |
186 | 187 |
r->state=H_BODY; |
187 |
- DBG("tcp_read_headers: switching to H_BODY (lflf)\n"); |
|
188 | 188 |
if (r->has_content_len){ |
189 | 189 |
r->body=p+1; |
190 | 190 |
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 | 366 |
again: |
368 | 367 |
if(req->complete==0 && req->error==TCP_REQ_OK){ |
369 | 368 |
bytes=tcp_read_headers(req, s); |
369 |
+#ifdef EXTRA_DEBUG |
|
370 | 370 |
/* if timeout state=0; goto end__req; */ |
371 | 371 |
DBG("read= %d bytes, parsed=%d, state=%d, error=%d\n", |
372 | 372 |
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 | 398 |
goto end_req; |
398 | 399 |
} |
399 | 400 |
if (req->complete){ |
401 |
+#ifdef EXTRA_DEBUG |
|
400 | 402 |
DBG("tcp_read_req: end of header part\n"); |
401 | 403 |
DBG("- received from: port %d, ip - ", con->rcv.src_port); |
402 | 404 |
print_ip(&con->rcv.src_ip); DBG("-\n"); |
403 | 405 |
DBG("tcp_read_req: headers:\n%.*s.\n", |
404 | 406 |
(int)(req->body-req->start), req->start); |
407 |
+#endif |
|
405 | 408 |
if (req->has_content_len){ |
406 | 409 |
DBG("tcp_read_req: content-length= %d\n", req->content_len); |
410 |
+#ifdef EXTRA_DEBUG |
|
407 | 411 |
DBG("tcp_read_req: body:\n%.*s\n", req->content_len,req->body); |
412 |
+#endif |
|
408 | 413 |
}else{ |
409 | 414 |
req->error=TCP_REQ_BAD_LEN; |
410 | 415 |
LOG(L_ERR, "ERROR: tcp_read_req: content length not present or" |
... | ... |
@@ -414,10 +419,13 @@ again: |
414 | 419 |
} |
415 | 420 |
/* if we are here everything is nice and ok*/ |
416 | 421 |
resp=CONN_RELEASE; |
422 |
+#ifdef EXTRA_DEBUG |
|
417 | 423 |
DBG("calling receive_msg(%p, %d, )\n", |
418 | 424 |
req->start, (int)(req->parsed-req->start)); |
419 |
- /* just for debugging use sendipv4 as receiving socket FIXME*/ |
|
425 |
+#endif |
|
426 |
+ /* rcv.bind_address should always be !=0 */ |
|
420 | 427 |
bind_address=con->rcv.bind_address; |
428 |
+ /* just for debugging use sendipv4 as receiving socket FIXME*/ |
|
421 | 429 |
/* |
422 | 430 |
if (con->rcv.dst_ip.af==AF_INET6){ |
423 | 431 |
bind_address=sendipv6_tcp; |
... | ... |
@@ -440,8 +448,10 @@ again: |
440 | 448 |
/* prepare for next request */ |
441 | 449 |
size=req->pos-req->parsed; |
442 | 450 |
if (size) memmove(req->buf, req->parsed, size); |
451 |
+#ifdef EXTRA_DEBUG |
|
443 | 452 |
DBG("tcp_read_req: preparing for new request, kept %ld bytes\n", |
444 | 453 |
size); |
454 |
+#endif |
|
445 | 455 |
req->pos=req->buf+size; |
446 | 456 |
req->parsed=req->buf; |
447 | 457 |
req->start=req->buf; |
... | ... |
@@ -520,7 +530,6 @@ void tcp_receive_loop(int unix_sock) |
520 | 530 |
continue; |
521 | 531 |
} |
522 | 532 |
if (FD_ISSET(unix_sock, &sel_set)){ |
523 |
- DBG("tcp receive: receiving fd from from 'main'\n"); |
|
524 | 533 |
nfds--; |
525 | 534 |
/* a new conn from "main" */ |
526 | 535 |
n=receive_fd(unix_sock, &con, sizeof(con), &s); |