Bladeren bron

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 13 jaren geleden
bovenliggende
commit
c715121205
5 gewijzigde bestanden met toevoegingen van 24 en 29 verwijderingen
  1. 3 0
      cfg.lex
  2. 3 0
      cfg.y
  3. 1 0
      globals.h
  4. 15 21
      parser/parse_fline.c
  5. 2 8
      ver_defs.h

+ 3 - 0
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; }

+ 3 - 0
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); }

+ 1 - 0
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 */

+ 15 - 21
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' )

+ 2 - 8
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