Module: sip-router
Branch: master
Commit: d4cc410326a5b0662f267ed5dc5bba3b67c901f6
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d4cc410326a5b0662f267ed5dc5bba3b67c901f6

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date:   Tue May 25 10:48:54 2010 +0200

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

---

 cfg.lex       |    3 +++
 cfg.y         |    9 +++++++++
 tcp_options.h |    1 +
 tcp_read.c    |   22 ++++++++++++++++------
 4 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/cfg.lex b/cfg.lex
index b265559..e4b5486 100644
--- a/cfg.lex
+++ b/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; }
diff --git a/cfg.y b/cfg.y
index f4e32ed..5052078 100644
--- a/cfg.y
+++ b/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;
diff --git a/tcp_options.h b/tcp_options.h
index a82a574..ae8215c 100644
--- a/tcp_options.h
+++ b/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;
diff --git a/tcp_read.c b/tcp_read.c
index c5fc575..fc9552a 100644
--- a/tcp_read.c
+++ b/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;


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to