Explorar el Código

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 hace 15 años
padre
commit
d4cc410326
Se han modificado 4 ficheros con 29 adiciones y 6 borrados
  1. 3 0
      cfg.lex
  2. 9 0
      cfg.y
  3. 1 0
      tcp_options.h
  4. 16 6
      tcp_read.c

+ 3 - 0
cfg.lex

@@ -418,6 +418,7 @@ TCP_OPT_KEEPIDLE	"tcp_keepidle"
 TCP_OPT_KEEPINTVL	"tcp_keepintvl"
 TCP_OPT_KEEPCNT		"tcp_keepcnt"
 TCP_OPT_CRLF_PING	"tcp_crlf_ping"
+TCP_OPT_ACCEPT_NO_CL	"tcp_accept_no_cl"
 DISABLE_TLS		"disable_tls"|"tls_disable"
 ENABLE_TLS		"enable_tls"|"tls_enable"
 TLSLOG			"tlslog"|"tls_log"
@@ -792,6 +793,8 @@ SUBST       subst
 									return TCP_OPT_KEEPCNT; }
 <INITIAL>{TCP_OPT_CRLF_PING}	{ count(); yylval.strval=yytext;
 									return TCP_OPT_CRLF_PING; }
+<INITIAL>{TCP_OPT_ACCEPT_NO_CL}	{ count(); yylval.strval=yytext;
+									return TCP_OPT_ACCEPT_NO_CL; }
 <INITIAL>{DISABLE_TLS}	{ count(); yylval.strval=yytext; return DISABLE_TLS; }
 <INITIAL>{ENABLE_TLS}	{ count(); yylval.strval=yytext; return ENABLE_TLS; }
 <INITIAL>{TLSLOG}		{ count(); yylval.strval=yytext; return TLS_PORT_NO; }

+ 9 - 0
cfg.y

@@ -461,6 +461,7 @@ extern char *finame;
 %token TCP_OPT_KEEPINTVL
 %token TCP_OPT_KEEPCNT
 %token TCP_OPT_CRLF_PING
+%token TCP_OPT_ACCEPT_NO_CL
 %token DISABLE_TLS
 %token ENABLE_TLS
 %token TLSLOG
@@ -1172,6 +1173,14 @@ assign_stm:
 		#endif
 	}
 	| TCP_OPT_CRLF_PING EQUAL error { yyerror("boolean value expected"); }
+	| TCP_OPT_ACCEPT_NO_CL EQUAL NUMBER {
+		#ifdef USE_TCP
+			tcp_default_cfg.accept_no_cl=$3;
+		#else
+			warn("tcp support not compiled in");
+		#endif
+	}
+	| TCP_OPT_ACCEPT_NO_CL EQUAL error { yyerror("boolean value expected"); }
 	| DISABLE_TLS EQUAL NUMBER {
 		#ifdef USE_TLS
 			tls_disable=$3;

+ 1 - 0
tcp_options.h

@@ -141,6 +141,7 @@ struct cfg_group_tcp{
 	/* internal, "fixed" vars */
 	unsigned int rd_buf_size; /* read buffer size (should be > max. datagram)*/
 	unsigned int wq_blk_size; /* async write block size (debugging use) */
+	int accept_no_cl;  /* on/off - accpet messages without content-lenght */
 };
 
 extern struct cfg_group_tcp tcp_default_cfg;

+ 16 - 6
tcp_read.c

@@ -370,9 +370,17 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
 							goto skip;
 						}
 					}else{
-						DBG("tcp_read_headers: ERROR: no clen, p=%X\n",
+						if (cfg_get(tcp, tcp_cfg, accept_no_cl)!=0) {
+							r->body=p+1;
+							r->bytes_to_go=0;
+							r->flags|=F_TCP_REQ_COMPLETE;
+							p++;
+							goto skip;
+						} else {
+							DBG("tcp_read_headers: ERROR: no clen, p=%X\n",
 									*p);
-						r->error=TCP_REQ_BAD_LEN;
+							r->error=TCP_REQ_BAD_LEN;
+						}
 					}
 				}else r->state=H_SKIP;
 				p++;
@@ -719,11 +727,13 @@ again:
 				DBG("tcp_read_req: body:\n%.*s\n", req->content_len,req->body);
 #endif
 			}else{
-				req->error=TCP_REQ_BAD_LEN;
-				LOG(L_ERR, "ERROR: tcp_read_req: content length not present or"
+				if (cfg_get(tcp, tcp_cfg, accept_no_cl)==0) {
+					req->error=TCP_REQ_BAD_LEN;
+					LOG(L_ERR, "ERROR: tcp_read_req: content length not present or"
 						" unparsable\n");
-				resp=CONN_ERROR;
-				goto end_req;
+					resp=CONN_ERROR;
+					goto end_req;
+				}
 			}
 			/* if we are here everything is nice and ok*/
 			resp=CONN_RELEASE;