Browse code

tcp: new parameter to accept messages without CL

- some non-sip messages with empty body do not carry content-length
- useful for http traffic handled locally
- global parameter name: tcp_accept_no_cl
- default is 0 (report error of CL is missing, default behaviour so far)
- value can be changed at runtime

Daniel-Constantin Mierla authored on 25/05/2010 08:48:54
Showing 4 changed files
... ...
@@ -418,6 +418,7 @@ TCP_OPT_KEEPIDLE	"tcp_keepidle"
418 418
 TCP_OPT_KEEPINTVL	"tcp_keepintvl"
419 419
 TCP_OPT_KEEPCNT		"tcp_keepcnt"
420 420
 TCP_OPT_CRLF_PING	"tcp_crlf_ping"
421
+TCP_OPT_ACCEPT_NO_CL	"tcp_accept_no_cl"
421 422
 DISABLE_TLS		"disable_tls"|"tls_disable"
422 423
 ENABLE_TLS		"enable_tls"|"tls_enable"
423 424
 TLSLOG			"tlslog"|"tls_log"
... ...
@@ -792,6 +793,8 @@ SUBST       subst
792 792
 									return TCP_OPT_KEEPCNT; }
793 793
 <INITIAL>{TCP_OPT_CRLF_PING}	{ count(); yylval.strval=yytext;
794 794
 									return TCP_OPT_CRLF_PING; }
795
+<INITIAL>{TCP_OPT_ACCEPT_NO_CL}	{ count(); yylval.strval=yytext;
796
+									return TCP_OPT_ACCEPT_NO_CL; }
795 797
 <INITIAL>{DISABLE_TLS}	{ count(); yylval.strval=yytext; return DISABLE_TLS; }
796 798
 <INITIAL>{ENABLE_TLS}	{ count(); yylval.strval=yytext; return ENABLE_TLS; }
797 799
 <INITIAL>{TLSLOG}		{ count(); yylval.strval=yytext; return TLS_PORT_NO; }
... ...
@@ -461,6 +461,7 @@ extern char *finame;
461 461
 %token TCP_OPT_KEEPINTVL
462 462
 %token TCP_OPT_KEEPCNT
463 463
 %token TCP_OPT_CRLF_PING
464
+%token TCP_OPT_ACCEPT_NO_CL
464 465
 %token DISABLE_TLS
465 466
 %token ENABLE_TLS
466 467
 %token TLSLOG
... ...
@@ -1172,6 +1173,14 @@ assign_stm:
1172 1172
 		#endif
1173 1173
 	}
1174 1174
 	| TCP_OPT_CRLF_PING EQUAL error { yyerror("boolean value expected"); }
1175
+	| TCP_OPT_ACCEPT_NO_CL EQUAL NUMBER {
1176
+		#ifdef USE_TCP
1177
+			tcp_default_cfg.accept_no_cl=$3;
1178
+		#else
1179
+			warn("tcp support not compiled in");
1180
+		#endif
1181
+	}
1182
+	| TCP_OPT_ACCEPT_NO_CL EQUAL error { yyerror("boolean value expected"); }
1175 1183
 	| DISABLE_TLS EQUAL NUMBER {
1176 1184
 		#ifdef USE_TLS
1177 1185
 			tls_disable=$3;
... ...
@@ -141,6 +141,7 @@ struct cfg_group_tcp{
141 141
 	/* internal, "fixed" vars */
142 142
 	unsigned int rd_buf_size; /* read buffer size (should be > max. datagram)*/
143 143
 	unsigned int wq_blk_size; /* async write block size (debugging use) */
144
+	int accept_no_cl;  /* on/off - accpet messages without content-lenght */
144 145
 };
145 146
 
146 147
 extern struct cfg_group_tcp tcp_default_cfg;
... ...
@@ -370,9 +370,17 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
370 370
 							goto skip;
371 371
 						}
372 372
 					}else{
373
-						DBG("tcp_read_headers: ERROR: no clen, p=%X\n",
373
+						if (cfg_get(tcp, tcp_cfg, accept_no_cl)!=0) {
374
+							r->body=p+1;
375
+							r->bytes_to_go=0;
376
+							r->flags|=F_TCP_REQ_COMPLETE;
377
+							p++;
378
+							goto skip;
379
+						} else {
380
+							DBG("tcp_read_headers: ERROR: no clen, p=%X\n",
374 381
 									*p);
375
-						r->error=TCP_REQ_BAD_LEN;
382
+							r->error=TCP_REQ_BAD_LEN;
383
+						}
376 384
 					}
377 385
 				}else r->state=H_SKIP;
378 386
 				p++;
... ...
@@ -719,11 +727,13 @@ again:
719 719
 				DBG("tcp_read_req: body:\n%.*s\n", req->content_len,req->body);
720 720
 #endif
721 721
 			}else{
722
-				req->error=TCP_REQ_BAD_LEN;
723
-				LOG(L_ERR, "ERROR: tcp_read_req: content length not present or"
722
+				if (cfg_get(tcp, tcp_cfg, accept_no_cl)==0) {
723
+					req->error=TCP_REQ_BAD_LEN;
724
+					LOG(L_ERR, "ERROR: tcp_read_req: content length not present or"
724 725
 						" unparsable\n");
725
-				resp=CONN_ERROR;
726
-				goto end_req;
726
+					resp=CONN_ERROR;
727
+					goto end_req;
728
+				}
727 729
 			}
728 730
 			/* if we are here everything is nice and ok*/
729 731
 			resp=CONN_RELEASE;