Browse code

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.

Peter Dunkley authored on 06/03/2012 18:33:42
Showing 5 changed files
... ...
@@ -494,6 +494,7 @@ KILL_TIMEOUT	"exit_timeout"|"ser_kill_timeout"
494 494
 MAX_WLOOPS		"max_while_loops"
495 495
 PVBUFSIZE		"pv_buffer_size"
496 496
 PVBUFSLOTS		"pv_buffer_slots"
497
+HTTP_REPLY_HACK		"http_reply_hack"
497 498
 
498 499
 /* stun config variables */
499 500
 STUN_REFRESH_INTERVAL "stun_refresh_interval"
... ...
@@ -961,6 +962,8 @@ IMPORTFILE      "import_file"
961 961
 									return PVBUFSIZE; }
962 962
 <INITIAL>{PVBUFSLOTS}			{	count(); yylval.strval=yytext;
963 963
 									return PVBUFSLOTS; }
964
+<INITIAL>{HTTP_REPLY_HACK}		{	count(); yylval.strval=yytext;
965
+									return HTTP_REPLY_HACK; }
964 966
 <INITIAL>{SERVER_ID}  { count(); yylval.strval=yytext; return SERVER_ID;}
965 967
 <INITIAL>{CFG_DESCRIPTION}	{ count(); yylval.strval=yytext; return CFG_DESCRIPTION; }
966 968
 <INITIAL>{LOADMODULE}	{ count(); yylval.strval=yytext; return LOADMODULE; }
... ...
@@ -556,6 +556,7 @@ extern char *finame;
556 556
 %token MAX_WLOOPS
557 557
 %token PVBUFSIZE
558 558
 %token PVBUFSLOTS
559
+%token HTTP_REPLY_HACK
559 560
 %token CFG_DESCRIPTION
560 561
 %token SERVER_ID
561 562
 
... ...
@@ -1661,6 +1662,8 @@ assign_stm:
1661 1661
 	| PVBUFSIZE EQUAL error { yyerror("number expected"); }
1662 1662
 	| PVBUFSLOTS EQUAL NUMBER { pv_set_buffer_slots($3); }
1663 1663
 	| PVBUFSLOTS EQUAL error { yyerror("number expected"); }
1664
+	| HTTP_REPLY_HACK EQUAL NUMBER { http_reply_hack=$3; }
1665
+	| HTTP_REPLY_HACK EQUAL error { yyerror("boolean value expected"); }
1664 1666
 	| STUN_REFRESH_INTERVAL EQUAL NUMBER { IF_STUN(stun_refresh_interval=$3); }
1665 1667
 	| STUN_REFRESH_INTERVAL EQUAL error{ yyerror("number expected"); }
1666 1668
 	| STUN_ALLOW_STUN EQUAL NUMBER { IF_STUN(stun_allow_stun=$3); }
... ...
@@ -213,6 +213,7 @@ extern int rt_timer2_prio;  /* "slow" timer */
213 213
 extern int rt_timer1_policy; /* "fast" timer, SCHED_OTHER */
214 214
 extern int rt_timer2_policy; /* "slow" timer, SCHED_OTHER */
215 215
 
216
+extern int http_reply_hack;
216 217
 
217 218
 #ifdef USE_DNS_CACHE
218 219
 extern int dns_cache_init; /* if 0, the DNS cache is not initialized at startup */
... ...
@@ -48,12 +48,7 @@
48 48
 #include "../mem/mem.h"
49 49
 #include "../ut.h"
50 50
 
51
-
52
-#ifdef NO_HTTP_REPLY_HACK
53
-#undef HTTP_REPLY_HACK
54
-#else
55
-/* #define HTTP_REPLY_HACK */ /* allow HTTP replies */
56
-#endif
51
+int http_reply_hack = 0;
57 52
 
58 53
 /* grammar:
59 54
 	request  =  method SP uri SP version CRLF
... ...
@@ -106,21 +101,20 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start * fl)
106 106
 			fl->type=SIP_REPLY;
107 107
 			fl->u.reply.version.len=SIP_VERSION_LEN;
108 108
 			tmp=buffer+SIP_VERSION_LEN;
109
-#ifdef HTTP_REPLY_HACK
110
-	}else if ( 	(*tmp=='H' || *tmp=='h') &&
111
-		/* 'HTTP/1.' */
112
-		strncasecmp( tmp+1, HTTP_VERSION+1, HTTP_VERSION_LEN-1)==0 &&
113
-		/* [0|1] */
114
-		((*(tmp+HTTP_VERSION_LEN)=='0') || (*(tmp+HTTP_VERSION_LEN)=='1')) &&
115
-		(*(tmp+HTTP_VERSION_LEN+1)==' ')  ){ 
116
-		/* ugly hack to be able to route http replies
117
-		 * Note: - the http reply must have a via
118
-		 *       - the message is marked as SIP_REPLY (ugly)
119
-		 */
120
-			fl->type=SIP_REPLY;
121
-			fl->u.reply.version.len=HTTP_VERSION_LEN+1 /*include last digit*/;
122
-			tmp=buffer+HTTP_VERSION_LEN+1 /* last digit */;
123
-#endif
109
+	} else if (http_reply_hack != 0 && 
110
+		 	(*tmp=='H' || *tmp=='h') &&
111
+			/* 'HTTP/1.' */
112
+			strncasecmp( tmp+1, HTTP_VERSION+1, HTTP_VERSION_LEN-1)==0 &&
113
+			/* [0|1] */
114
+			((*(tmp+HTTP_VERSION_LEN)=='0') || (*(tmp+HTTP_VERSION_LEN)=='1')) &&
115
+			(*(tmp+HTTP_VERSION_LEN+1)==' ')  ){ 
116
+			/* ugly hack to be able to route http replies
117
+			 * Note: - the http reply must have a via
118
+			 *       - the message is marked as SIP_REPLY (ugly)
119
+			 */
120
+				fl->type=SIP_REPLY;
121
+				fl->u.reply.version.len=HTTP_VERSION_LEN+1 /*include last digit*/;
122
+				tmp=buffer+HTTP_VERSION_LEN+1 /* last digit */;
124 123
 	} else IFISMETHOD( INVITE, 'I' )
125 124
 	else IFISMETHOD( CANCEL, 'C')
126 125
 	else IFISMETHOD( ACK, 'A' )
... ...
@@ -303,12 +303,6 @@
303 303
 #define HAVE_RESOLV_RES_STR ""
304 304
 #endif
305 305
 
306
-#ifdef HTTP_REPLY_HACK 
307
-#define HTTP_REPLY_HACK_STR ", HTTP_REPLY_HACK"
308
-#else
309
-#define HTTP_REPLY_HACK_STR ""
310
-#endif
311
-
312 306
 #ifdef QM_JOIN_FREE 
313 307
 #define QM_JOIN_FREE_STR ", QM_JOIN_FREE"
314 308
 #else
... ...
@@ -353,8 +347,8 @@
353 353
 	FAST_LOCK_STR NOSMP_STR USE_PTHREAD_MUTEX_STR USE_POSIX_SEM_STR \
354 354
 	USE_SYSV_SEM_STR USE_COMP_STR USE_DNS_CACHE_STR USE_DNS_FAILOVER_STR \
355 355
 	DNS_WATCHDOG_SUPPORT_STR USE_NAPTR_STR USE_DST_BLACKLIST_STR \
356
-	HAVE_RESOLV_RES_STR HTTP_REPLY_HACK_STR SYSLOG_CALLBACK_SUPPORT_STR \
357
-	MYSQL_FAKE_NULL_STR USE_DST_BLACKLIST_STATS_STR USE_DNS_CACHE_STATS_STR
356
+	HAVE_RESOLV_RES_STR SYSLOG_CALLBACK_SUPPORT_STR MYSQL_FAKE_NULL_STR \
357
+	USE_DST_BLACKLIST_STATS_STR USE_DNS_CACHE_STATS_STR
358 358
 
359 359
 
360 360
 #endif