[sr-dev] git:master: core: Changed HTTP_REPLY_HACK from a compile-time to a run-time option

Peter Dunkley peter.dunkley at crocodile-rcs.com
Tue Mar 6 19:36:27 CET 2012


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

Author: Peter Dunkley <peter.dunkley at crocodile-rcs.com>
Committer: Peter Dunkley <peter.dunkley at crocodile-rcs.com>
Date:   Tue Mar  6 18:33:42 2012 +0000

core: Changed HTTP_REPLY_HACK from a compile-time to a run-time option

- By default it is off, to turn it on set http_reply_hack=yes in kamailio.cfg
- You need to turn this on if you use xhttp _and_ event_route[sl:local-response].
  This is because HTTP responses are stateless responses and when the
  event_route is run it has to parse the response.  Without HTTP_REPLY_HACK
  Kamailio can't actually parse HTTP responses.

---

 cfg.lex              |    3 +++
 cfg.y                |    3 +++
 globals.h            |    1 +
 parser/parse_fline.c |   36 +++++++++++++++---------------------
 ver_defs.h           |   10 ++--------
 5 files changed, 24 insertions(+), 29 deletions(-)

diff --git a/cfg.lex b/cfg.lex
index 68766d1..00a55e0 100644
--- a/cfg.lex
+++ b/cfg.lex
@@ -494,6 +494,7 @@ KILL_TIMEOUT	"exit_timeout"|"ser_kill_timeout"
 MAX_WLOOPS		"max_while_loops"
 PVBUFSIZE		"pv_buffer_size"
 PVBUFSLOTS		"pv_buffer_slots"
+HTTP_REPLY_HACK		"http_reply_hack"
 
 /* stun config variables */
 STUN_REFRESH_INTERVAL "stun_refresh_interval"
@@ -961,6 +962,8 @@ IMPORTFILE      "import_file"
 									return PVBUFSIZE; }
 <INITIAL>{PVBUFSLOTS}			{	count(); yylval.strval=yytext;
 									return PVBUFSLOTS; }
+<INITIAL>{HTTP_REPLY_HACK}		{	count(); yylval.strval=yytext;
+									return HTTP_REPLY_HACK; }
 <INITIAL>{SERVER_ID}  { count(); yylval.strval=yytext; return SERVER_ID;}
 <INITIAL>{CFG_DESCRIPTION}	{ count(); yylval.strval=yytext; return CFG_DESCRIPTION; }
 <INITIAL>{LOADMODULE}	{ count(); yylval.strval=yytext; return LOADMODULE; }
diff --git a/cfg.y b/cfg.y
index 0e684c1..9edd0fde 100644
--- a/cfg.y
+++ b/cfg.y
@@ -556,6 +556,7 @@ extern char *finame;
 %token MAX_WLOOPS
 %token PVBUFSIZE
 %token PVBUFSLOTS
+%token HTTP_REPLY_HACK
 %token CFG_DESCRIPTION
 %token SERVER_ID
 
@@ -1661,6 +1662,8 @@ assign_stm:
 	| PVBUFSIZE EQUAL error { yyerror("number expected"); }
 	| PVBUFSLOTS EQUAL NUMBER { pv_set_buffer_slots($3); }
 	| PVBUFSLOTS EQUAL error { yyerror("number expected"); }
+	| HTTP_REPLY_HACK EQUAL NUMBER { http_reply_hack=$3; }
+	| HTTP_REPLY_HACK EQUAL error { yyerror("boolean value expected"); }
 	| STUN_REFRESH_INTERVAL EQUAL NUMBER { IF_STUN(stun_refresh_interval=$3); }
 	| STUN_REFRESH_INTERVAL EQUAL error{ yyerror("number expected"); }
 	| STUN_ALLOW_STUN EQUAL NUMBER { IF_STUN(stun_allow_stun=$3); }
diff --git a/globals.h b/globals.h
index 39c3616..49b8345 100644
--- a/globals.h
+++ b/globals.h
@@ -213,6 +213,7 @@ extern int rt_timer2_prio;  /* "slow" timer */
 extern int rt_timer1_policy; /* "fast" timer, SCHED_OTHER */
 extern int rt_timer2_policy; /* "slow" timer, SCHED_OTHER */
 
+extern int http_reply_hack;
 
 #ifdef USE_DNS_CACHE
 extern int dns_cache_init; /* if 0, the DNS cache is not initialized at startup */
diff --git a/parser/parse_fline.c b/parser/parse_fline.c
index 48ab09b..15a1a7a 100644
--- a/parser/parse_fline.c
+++ b/parser/parse_fline.c
@@ -48,12 +48,7 @@
 #include "../mem/mem.h"
 #include "../ut.h"
 
-
-#ifdef NO_HTTP_REPLY_HACK
-#undef HTTP_REPLY_HACK
-#else
-/* #define HTTP_REPLY_HACK */ /* allow HTTP replies */
-#endif
+int http_reply_hack = 0;
 
 /* grammar:
 	request  =  method SP uri SP version CRLF
@@ -106,21 +101,20 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start * fl)
 			fl->type=SIP_REPLY;
 			fl->u.reply.version.len=SIP_VERSION_LEN;
 			tmp=buffer+SIP_VERSION_LEN;
-#ifdef HTTP_REPLY_HACK
-	}else if ( 	(*tmp=='H' || *tmp=='h') &&
-		/* 'HTTP/1.' */
-		strncasecmp( tmp+1, HTTP_VERSION+1, HTTP_VERSION_LEN-1)==0 &&
-		/* [0|1] */
-		((*(tmp+HTTP_VERSION_LEN)=='0') || (*(tmp+HTTP_VERSION_LEN)=='1')) &&
-		(*(tmp+HTTP_VERSION_LEN+1)==' ')  ){ 
-		/* ugly hack to be able to route http replies
-		 * Note: - the http reply must have a via
-		 *       - the message is marked as SIP_REPLY (ugly)
-		 */
-			fl->type=SIP_REPLY;
-			fl->u.reply.version.len=HTTP_VERSION_LEN+1 /*include last digit*/;
-			tmp=buffer+HTTP_VERSION_LEN+1 /* last digit */;
-#endif
+	} else if (http_reply_hack != 0 && 
+		 	(*tmp=='H' || *tmp=='h') &&
+			/* 'HTTP/1.' */
+			strncasecmp( tmp+1, HTTP_VERSION+1, HTTP_VERSION_LEN-1)==0 &&
+			/* [0|1] */
+			((*(tmp+HTTP_VERSION_LEN)=='0') || (*(tmp+HTTP_VERSION_LEN)=='1')) &&
+			(*(tmp+HTTP_VERSION_LEN+1)==' ')  ){ 
+			/* ugly hack to be able to route http replies
+			 * Note: - the http reply must have a via
+			 *       - the message is marked as SIP_REPLY (ugly)
+			 */
+				fl->type=SIP_REPLY;
+				fl->u.reply.version.len=HTTP_VERSION_LEN+1 /*include last digit*/;
+				tmp=buffer+HTTP_VERSION_LEN+1 /* last digit */;
 	} else IFISMETHOD( INVITE, 'I' )
 	else IFISMETHOD( CANCEL, 'C')
 	else IFISMETHOD( ACK, 'A' )
diff --git a/ver_defs.h b/ver_defs.h
index 1284881..957bb69 100644
--- a/ver_defs.h
+++ b/ver_defs.h
@@ -303,12 +303,6 @@
 #define HAVE_RESOLV_RES_STR ""
 #endif
 
-#ifdef HTTP_REPLY_HACK 
-#define HTTP_REPLY_HACK_STR ", HTTP_REPLY_HACK"
-#else
-#define HTTP_REPLY_HACK_STR ""
-#endif
-
 #ifdef QM_JOIN_FREE 
 #define QM_JOIN_FREE_STR ", QM_JOIN_FREE"
 #else
@@ -353,8 +347,8 @@
 	FAST_LOCK_STR NOSMP_STR USE_PTHREAD_MUTEX_STR USE_POSIX_SEM_STR \
 	USE_SYSV_SEM_STR USE_COMP_STR USE_DNS_CACHE_STR USE_DNS_FAILOVER_STR \
 	DNS_WATCHDOG_SUPPORT_STR USE_NAPTR_STR USE_DST_BLACKLIST_STR \
-	HAVE_RESOLV_RES_STR HTTP_REPLY_HACK_STR SYSLOG_CALLBACK_SUPPORT_STR \
-	MYSQL_FAKE_NULL_STR USE_DST_BLACKLIST_STATS_STR USE_DNS_CACHE_STATS_STR
+	HAVE_RESOLV_RES_STR SYSLOG_CALLBACK_SUPPORT_STR MYSQL_FAKE_NULL_STR \
+	USE_DST_BLACKLIST_STATS_STR USE_DNS_CACHE_STATS_STR
 
 
 #endif




More information about the sr-dev mailing list