Browse code

core: new global parameter return_mode

- control the return code evaluation mode:
- 0 (default) - evaluation is like so far (negative is false, positive
is true)
- 1 - propagate return value and evaluation has to be done with >0 or
<0, otherwise value!=0 is evaluated to true no matter is negative
or positive

Daniel-Constantin Mierla authored on 17/11/2022 12:05:59
Showing 1 changed files
... ...
@@ -147,6 +147,7 @@ FORWARD_SCTP	forward_sctp
147 147
 DROP	"drop"
148 148
 EXIT	"exit"
149 149
 RETURN	"return"
150
+RETURN_MODE	"return_mode"
150 151
 BREAK	"break"
151 152
 LOG		log
152 153
 ERROR	error
... ...
@@ -1049,6 +1050,7 @@ IMPORTFILE      "import_file"
1049 1050
 <INITIAL>{CFGENGINE}	{ count(); yylval.strval=yytext; return CFGENGINE; }
1050 1051
 <INITIAL>{URI_HOST_EXTRA_CHARS}	{ yylval.strval=yytext; return URI_HOST_EXTRA_CHARS; }
1051 1052
 <INITIAL>{HDR_NAME_EXTRA_CHARS}	{ yylval.strval=yytext; return HDR_NAME_EXTRA_CHARS; }
1053
+<INITIAL>{RETURN_MODE}	{ count(); yylval.strval=yytext; return RETURN_MODE; }
1052 1054
 
1053 1055
 <INITIAL>{EQUAL}	{ count(); return EQUAL; }
1054 1056
 <INITIAL>{ADDEQ}          { count(); return ADDEQ; }
Browse code

core: added #!defexps preprocessor directive

- similar to #!defexp but the resulted value is enclosed in double
quotes

Daniel-Constantin Mierla authored on 22/09/2022 07:34:05
Showing 1 changed files
... ...
@@ -576,6 +576,7 @@ ENDIF        endif
576 576
 TRYDEF       "trydefine"|"trydef"
577 577
 REDEF        "redefine"|"redef"
578 578
 DEFEXP       defexp
579
+DEFEXPS      defexps
579 580
 DEFENV       defenv
580 581
 DEFENVS      defenvs
581 582
 TRYDEFENV    trydefenv
... ...
@@ -1344,6 +1345,10 @@ IMPORTFILE      "import_file"
1344 1345
 											ksr_cfg_print_part(yytext);
1345 1346
 											pp_define_set_type(KSR_PPDEF_DEFEXP);
1346 1347
 											state = DEFINE_S; BEGIN(DEFINE_ID); }
1348
+<INITIAL,CFGPRINTMODE>{PREP_START}{DEFEXPS}{EAT_ABLE}+	{	count();
1349
+											ksr_cfg_print_part(yytext);
1350
+											pp_define_set_type(KSR_PPDEF_DEFEXPS);
1351
+											state = DEFINE_S; BEGIN(DEFINE_ID); }
1347 1352
 <DEFINE_ID>{ID}{MINUS}          {	count();
1348 1353
 									ksr_cfg_print_part(yytext);
1349 1354
 									LM_CRIT(
... ...
@@ -2150,8 +2155,13 @@ int pp_define_set(int len, char *text, int mode)
2150 2155
 		return -1;
2151 2156
 	}
2152 2157
 
2153
-	if(pp_defines[ppos].dtype == KSR_PPDEF_DEFEXP) {
2154
-		sval = pp_defexp_eval(text, len);
2158
+	if(pp_defines[ppos].dtype == KSR_PPDEF_DEFEXP
2159
+			|| pp_defines[ppos].dtype == KSR_PPDEF_DEFEXPS) {
2160
+		if(pp_defines[ppos].dtype == KSR_PPDEF_DEFEXP) {
2161
+			sval = pp_defexp_eval(text, len, 0);
2162
+		} else {
2163
+			sval = pp_defexp_eval(text, len, 1);
2164
+		}
2155 2165
 		if(sval==NULL) {
2156 2166
 			LM_NOTICE("no value returned to set the defexp [%.*s]\n",
2157 2167
 				pp_defines[ppos].name.len, pp_defines[ppos].name.s);
Browse code

core: added #!defexp ID STM preprocessor directive

- abity to set a defined it to the result of snexpr statement
- example:

#!define ADDR 127.0.0.1
#!defexp SIPURI "sip:" + ADDR + ":5060"

Daniel-Constantin Mierla authored on 20/09/2022 15:41:36
Showing 1 changed files
... ...
@@ -575,6 +575,7 @@ IFEXP        ifexp
575 575
 ENDIF        endif
576 576
 TRYDEF       "trydefine"|"trydef"
577 577
 REDEF        "redefine"|"redef"
578
+DEFEXP       defexp
578 579
 DEFENV       defenv
579 580
 DEFENVS      defenvs
580 581
 TRYDEFENV    trydefenv
... ...
@@ -1339,6 +1340,10 @@ IMPORTFILE      "import_file"
1339 1340
 											ksr_cfg_print_part(yytext);
1340 1341
 											pp_define_set_type(KSR_PPDEF_REDEF);
1341 1342
 											state = DEFINE_S; BEGIN(DEFINE_ID); }
1343
+<INITIAL,CFGPRINTMODE>{PREP_START}{DEFEXP}{EAT_ABLE}+	{	count();
1344
+											ksr_cfg_print_part(yytext);
1345
+											pp_define_set_type(KSR_PPDEF_DEFEXP);
1346
+											state = DEFINE_S; BEGIN(DEFINE_ID); }
1342 1347
 <DEFINE_ID>{ID}{MINUS}          {	count();
1343 1348
 									ksr_cfg_print_part(yytext);
1344 1349
 									LM_CRIT(
... ...
@@ -2107,6 +2112,7 @@ int pp_define(int len, const char *text)
2107 2112
 int pp_define_set(int len, char *text, int mode)
2108 2113
 {
2109 2114
 	int ppos;
2115
+	char *sval = NULL;
2110 2116
 
2111 2117
 	if(pp_define_index == -2) {
2112 2118
 		/* #!trydef that should be ignored */
... ...
@@ -2144,17 +2150,28 @@ int pp_define_set(int len, char *text, int mode)
2144 2150
 		return -1;
2145 2151
 	}
2146 2152
 
2147
-	pp_defines[ppos].value.s = (char*)pkg_malloc(len+1);
2148
-	if (pp_defines[ppos].value.s == NULL) {
2149
-		LM_ERR("no more memory to define %.*s [%d]\n",
2150
-			pp_defines[ppos].name.len,
2151
-			pp_defines[ppos].name.s, ppos);
2152
-		return -1;
2153
-	}
2153
+	if(pp_defines[ppos].dtype == KSR_PPDEF_DEFEXP) {
2154
+		sval = pp_defexp_eval(text, len);
2155
+		if(sval==NULL) {
2156
+			LM_NOTICE("no value returned to set the defexp [%.*s]\n",
2157
+				pp_defines[ppos].name.len, pp_defines[ppos].name.s);
2158
+			return 0;
2159
+		}
2160
+		pp_defines[ppos].value.s = sval;
2161
+		pp_defines[ppos].value.len = strlen(sval);
2162
+	} else {
2163
+		pp_defines[ppos].value.s = (char*)pkg_malloc(len+1);
2164
+		if (pp_defines[ppos].value.s == NULL) {
2165
+			LM_ERR("no more memory to define %.*s [%d]\n",
2166
+				pp_defines[ppos].name.len,
2167
+				pp_defines[ppos].name.s, ppos);
2168
+			return -1;
2169
+		}
2154 2170
 
2155
-	memcpy(pp_defines[ppos].value.s, text, len);
2156
-	pp_defines[ppos].value.s[len] = '\0';
2157
-	pp_defines[ppos].value.len = len;
2171
+		memcpy(pp_defines[ppos].value.s, text, len);
2172
+		pp_defines[ppos].value.s[len] = '\0';
2173
+		pp_defines[ppos].value.len = len;
2174
+	}
2158 2175
 	LM_DBG("### setting define ID [%.*s] value [%.*s] (mode: %d)\n",
2159 2176
 			pp_defines[ppos].name.len,
2160 2177
 			pp_defines[ppos].name.s,
Browse code

core: clone values for defines

Daniel-Constantin Mierla authored on 20/09/2022 09:01:56
Showing 1 changed files
... ...
@@ -2144,8 +2144,17 @@ int pp_define_set(int len, char *text, int mode)
2144 2144
 		return -1;
2145 2145
 	}
2146 2146
 
2147
+	pp_defines[ppos].value.s = (char*)pkg_malloc(len+1);
2148
+	if (pp_defines[ppos].value.s == NULL) {
2149
+		LM_ERR("no more memory to define %.*s [%d]\n",
2150
+			pp_defines[ppos].name.len,
2151
+			pp_defines[ppos].name.s, ppos);
2152
+		return -1;
2153
+	}
2154
+
2155
+	memcpy(pp_defines[ppos].value.s, text, len);
2156
+	pp_defines[ppos].value.s[len] = '\0';
2147 2157
 	pp_defines[ppos].value.len = len;
2148
-	pp_defines[ppos].value.s = text;
2149 2158
 	LM_DBG("### setting define ID [%.*s] value [%.*s] (mode: %d)\n",
2150 2159
 			pp_defines[ppos].name.len,
2151 2160
 			pp_defines[ppos].name.s,
Browse code

core: use defines for types of preprocessor defs

Daniel-Constantin Mierla authored on 20/09/2022 08:52:42
Showing 1 changed files
... ...
@@ -1329,15 +1329,15 @@ IMPORTFILE      "import_file"
1329 1329
 
1330 1330
 <INITIAL,CFGPRINTMODE>{PREP_START}{DEFINE}{EAT_ABLE}+	{	count();
1331 1331
 											ksr_cfg_print_part(yytext);
1332
-											pp_define_set_type(0);
1332
+											pp_define_set_type(KSR_PPDEF_DEFINE);
1333 1333
 											state = DEFINE_S; BEGIN(DEFINE_ID); }
1334 1334
 <INITIAL,CFGPRINTMODE>{PREP_START}{TRYDEF}{EAT_ABLE}+	{	count();
1335 1335
 											ksr_cfg_print_part(yytext);
1336
-											pp_define_set_type(1);
1336
+											pp_define_set_type(KSR_PPDEF_TRYDEF);
1337 1337
 											state = DEFINE_S; BEGIN(DEFINE_ID); }
1338 1338
 <INITIAL,CFGPRINTMODE>{PREP_START}{REDEF}{EAT_ABLE}+	{	count();
1339 1339
 											ksr_cfg_print_part(yytext);
1340
-											pp_define_set_type(2);
1340
+											pp_define_set_type(KSR_PPDEF_REDEF);
1341 1341
 											state = DEFINE_S; BEGIN(DEFINE_ID); }
1342 1342
 <DEFINE_ID>{ID}{MINUS}          {	count();
1343 1343
 									ksr_cfg_print_part(yytext);
... ...
@@ -1665,7 +1665,7 @@ static void ksr_cfg_print_define_module(char *modpath, int modpathlen)
1665 1665
 	}
1666 1666
 	memcpy(defmod, "MOD_", 4);
1667 1667
 	memcpy(defmod+4, modname.s, modname.len);
1668
-	pp_define_set_type(0);
1668
+	pp_define_set_type(KSR_PPDEF_DEFINE);
1669 1669
 	if(pp_define(modname.len + 4, defmod)<0) {
1670 1670
 		printf("\n# ***** ERROR: unable to set cfg define for module: %s\n",
1671 1671
 				modpath);
... ...
@@ -2067,11 +2067,11 @@ int pp_define(int len, const char *text)
2067 2067
 	pp_define_index = -1;
2068 2068
 	ppos = pp_lookup(len, text);
2069 2069
 	if(ppos >= 0) {
2070
-		if(pp_define_type==1) {
2070
+		if(pp_define_type==KSR_PPDEF_TRYDEF) {
2071 2071
 			LM_DBG("ignoring - already defined: %.*s\n", len, text);
2072 2072
 			pp_define_index = -2;
2073 2073
 			return 0;
2074
-		} else if(pp_define_type==2) {
2074
+		} else if(pp_define_type==KSR_PPDEF_REDEF) {
2075 2075
 			LM_DBG("redefining: %.*s\n", len, text);
2076 2076
 			pp_define_index = ppos;
2077 2077
 			if(pp_defines[ppos].value.s != NULL) {
... ...
@@ -2187,7 +2187,7 @@ int pp_define_env(const char *text, int len, int qmode, int vmode)
2187 2187
 	}
2188 2188
 	defvalue.len = strlen(defvalue.s);
2189 2189
 
2190
-	pp_define_set_type(0);
2190
+	pp_define_set_type(KSR_PPDEF_DEFINE);
2191 2191
 	if(pp_define(defname.len, defname.s)<0) {
2192 2192
 		LM_ERR("cannot set define name [%s]\n", (char*)text);
2193 2193
 		return -1;
Browse code

core: added preprocessor directive #!ifexp stm

- conditional evaluation of the statement as an expression with strings
and numbers
- example:

#!ifexp KAMAILIO_VERSION >= 5006000
...
#!else
...
#!endif

- defined IDs can be used inside the expression
- if not defined, value 0 is used
- if defined with value, the value is used
- if defined with no value, value 1 is used
- if expression is evaluated to !=0 or non-empty string, then it is considered true

Daniel-Constantin Mierla authored on 14/09/2022 06:17:30
Showing 1 changed files
... ...
@@ -130,8 +130,8 @@
130 130
 /* start conditions */
131 131
 %x STRING1 STRING2 STR_BETWEEN COMMENT COMMENT_LN ATTR SELECT AVP_PVAR PVAR_P
132 132
 %x PVARID INCLF IMPTF EVRTNAME CFGPRINTMODE CFGPRINTLOADMOD DEFENV_ID DEFENVS_ID
133
-%x TRYDEFENV_ID TRYDEFENVS_ID LINECOMMENT DEFINE_ID DEFINE_EOL DEFINE_DATA 
134
-%x IFDEF_ID IFDEF_EOL IFDEF_SKIP
133
+%x TRYDEFENV_ID TRYDEFENVS_ID LINECOMMENT DEFINE_ID DEFINE_EOL DEFINE_DATA
134
+%x IFDEF_ID IFDEF_EOL IFDEF_SKIP IFEXP_STM
135 135
 
136 136
 /* config script types : #!SER  or #!KAMAILIO or #!MAX_COMPAT */
137 137
 SER_CFG			SER
... ...
@@ -571,6 +571,7 @@ PREP_START	"#!"|"!!"
571 571
 DEFINE       "define"|"def"
572 572
 IFDEF        ifdef
573 573
 IFNDEF       ifndef
574
+IFEXP        ifexp
574 575
 ENDIF        endif
575 576
 TRYDEF       "trydefine"|"trydef"
576 577
 REDEF        "redefine"|"redef"
... ...
@@ -1381,6 +1382,9 @@ IMPORTFILE      "import_file"
1381 1382
 <INITIAL,CFGPRINTMODE,IFDEF_SKIP>{PREP_START}{IFNDEF}{EAT_ABLE}+    { count();
1382 1383
 								if (pp_ifdef_type(0)) return 1;
1383 1384
 								state = IFDEF_S; BEGIN(IFDEF_ID); }
1385
+<INITIAL,CFGPRINTMODE,IFDEF_SKIP>{PREP_START}{IFEXP}{EAT_ABLE}+    { count();
1386
+								if (pp_ifdef_type(1)) return 1;
1387
+								state = IFDEF_S; BEGIN(IFEXP_STM); }
1384 1388
 <IFDEF_ID>{ID}{MINUS}           { count();
1385 1389
 									LM_CRIT(
1386 1390
 										"error at %s line %d: '-' not allowed\n",
... ...
@@ -1390,6 +1394,11 @@ IMPORTFILE      "import_file"
1390 1394
 <IFDEF_ID>{ID}                { count();
1391 1395
 								pp_ifdef_var(yyleng, yytext);
1392 1396
 								state = IFDEF_EOL_S; BEGIN(IFDEF_EOL); }
1397
+<IFEXP_STM>.*{CR}        { count();
1398
+								pp_ifexp_eval(yytext, yyleng);
1399
+								state = IFDEF_EOL_S; BEGIN(IFDEF_EOL);
1400
+								pp_ifdef();
1401
+								}
1393 1402
 <IFDEF_EOL>{EAT_ABLE}*{CR}    { count(); pp_ifdef(); }
1394 1403
 
1395 1404
 <INITIAL,CFGPRINTMODE,IFDEF_SKIP>{PREP_START}{ELSE}{EAT_ABLE}*{CR}    { count(); pp_else(); }
... ...
@@ -2016,7 +2025,7 @@ ksr_ppdefine_t* pp_get_define(int idx)
2016 2025
 	return &pp_defines[idx];
2017 2026
 }
2018 2027
 
2019
-static int pp_lookup(int len, const char *text)
2028
+int pp_lookup(int len, const char *text)
2020 2029
 {
2021 2030
 	str var = {(char *)text, len};
2022 2031
 	int i;
... ...
@@ -2245,6 +2254,11 @@ static void pp_ifdef_var(int len, const char *text)
2245 2254
 	pp_ifdef_stack[pp_sptr] ^= (pp_lookup(len, text) < 0);
2246 2255
 }
2247 2256
 
2257
+void pp_ifexp_state(int state)
2258
+{
2259
+	pp_ifdef_stack[pp_sptr] = state;
2260
+}
2261
+
2248 2262
 static void pp_update_state()
2249 2263
 {
2250 2264
 	int i;
Browse code

core: aliased dns_rev_via to rev_dns

Daniel-Constantin Mierla authored on 23/08/2022 07:57:43
Showing 1 changed files
... ...
@@ -312,7 +312,7 @@ DOMAIN		domain
312 312
 SR_AUTO_ALIASES	auto_aliases
313 313
 SR_AUTO_DOMAINS auto_domains
314 314
 DNS		 dns
315
-REV_DNS	 rev_dns
315
+REV_DNS	 rev_dns|dns_rev_via
316 316
 DNS_TRY_IPV6	dns_try_ipv6
317 317
 DNS_TRY_NAPTR	dns_try_naptr
318 318
 DNS_SRV_LB		dns_srv_lb|dns_srv_loadbalancing
Browse code

core: aliased dns_use_failover to use_dns_failover

Daniel-Constantin Mierla authored on 23/08/2022 07:50:28
Showing 1 changed files
... ...
@@ -330,7 +330,7 @@ DNS_NAPTR_IGNORE_RFC	dns_naptr_ignore_rfc
330 330
 /* dns cache */
331 331
 DNS_CACHE_INIT	dns_cache_init
332 332
 DNS_USE_CACHE	use_dns_cache|dns_use_cache
333
-DNS_USE_FAILOVER	use_dns_failover
333
+DNS_USE_FAILOVER	use_dns_failover|dns_use_failover
334 334
 DNS_CACHE_FLAGS		dns_cache_flags
335 335
 DNS_CACHE_NEG_TTL	dns_cache_negative_ttl
336 336
 DNS_CACHE_MIN_TTL	dns_cache_min_ttl
Browse code

core: aliased dns_use_cache to use_dns_cache

Daniel-Constantin Mierla authored on 23/08/2022 07:44:38
Showing 1 changed files
... ...
@@ -329,7 +329,7 @@ DNS_SEARCH_FMATCH	dns_search_full_match
329 329
 DNS_NAPTR_IGNORE_RFC	dns_naptr_ignore_rfc
330 330
 /* dns cache */
331 331
 DNS_CACHE_INIT	dns_cache_init
332
-DNS_USE_CACHE	use_dns_cache
332
+DNS_USE_CACHE	use_dns_cache|dns_use_cache
333 333
 DNS_USE_FAILOVER	use_dns_failover
334 334
 DNS_CACHE_FLAGS		dns_cache_flags
335 335
 DNS_CACHE_NEG_TTL	dns_cache_negative_ttl
Browse code

core: added domain and auto_domains as variants for alias and auto_aliases

Daniel-Constantin Mierla authored on 17/06/2022 07:53:01
Showing 1 changed files
... ...
@@ -308,7 +308,9 @@ ADVERTISE	advertise|ADVERTISE
308 308
 VIRTUAL		virtual
309 309
 STRNAME		name|NAME
310 310
 ALIAS		alias
311
+DOMAIN		domain
311 312
 SR_AUTO_ALIASES	auto_aliases
313
+SR_AUTO_DOMAINS auto_domains
312 314
 DNS		 dns
313 315
 REV_DNS	 rev_dns
314 316
 DNS_TRY_IPV6	dns_try_ipv6
... ...
@@ -750,8 +752,11 @@ IMPORTFILE      "import_file"
750 752
 <INITIAL>{VIRTUAL}	{ count(); yylval.strval=yytext; return VIRTUAL; }
751 753
 <INITIAL>{STRNAME}	{ count(); yylval.strval=yytext; return STRNAME; }
752 754
 <INITIAL>{ALIAS}	{ count(); yylval.strval=yytext; return ALIAS; }
755
+<INITIAL>{DOMAIN}	{ count(); yylval.strval=yytext; return DOMAIN; }
753 756
 <INITIAL>{SR_AUTO_ALIASES}	{ count(); yylval.strval=yytext;
754 757
 									return SR_AUTO_ALIASES; }
758
+<INITIAL>{SR_AUTO_DOMAINS}	{ count(); yylval.strval=yytext;
759
+									return SR_AUTO_DOMAINS; }
755 760
 <INITIAL>{DNS}	{ count(); yylval.strval=yytext; return DNS; }
756 761
 <INITIAL>{REV_DNS}	{ count(); yylval.strval=yytext; return REV_DNS; }
757 762
 <INITIAL>{DNS_TRY_IPV6}	{ count(); yylval.strval=yytext;
Browse code

core: new socket global parameter to set listen attributes with a structure style

- alternative to listen when a usual bind address is provided
- example:

socket = {
bind = udp:127.0.0.1:5060;
advertise = 1.2.3.4:5080;
name = "udp0";
}

Daniel-Constantin Mierla authored on 01/06/2022 06:24:50
Showing 1 changed files
... ...
@@ -361,6 +361,9 @@ STATS_NAMESEP	stats_name_separator
361 361
 MAXBUFFER maxbuffer
362 362
 SQL_BUFFER_SIZE sql_buffer_size
363 363
 CHILDREN children
364
+SOCKET socket
365
+BIND bind
366
+WORKERS workers
364 367
 SOCKET_WORKERS socket_workers
365 368
 ASYNC_WORKERS async_workers
366 369
 ASYNC_USLEEP async_usleep
... ...
@@ -832,6 +835,8 @@ IMPORTFILE      "import_file"
832 835
 <INITIAL>{MAXBUFFER}	{ count(); yylval.strval=yytext; return MAXBUFFER; }
833 836
 <INITIAL>{SQL_BUFFER_SIZE}	{ count(); yylval.strval=yytext; return SQL_BUFFER_SIZE; }
834 837
 <INITIAL>{CHILDREN}	{ count(); yylval.strval=yytext; return CHILDREN; }
838
+<INITIAL>{SOCKET}	{ count(); yylval.strval=yytext; return SOCKET; }
839
+<INITIAL>{BIND}	{ count(); yylval.strval=yytext; return BIND; }
835 840
 <INITIAL>{SOCKET_WORKERS}	{ count(); yylval.strval=yytext; return SOCKET_WORKERS; }
836 841
 <INITIAL>{ASYNC_WORKERS}	{ count(); yylval.strval=yytext; return ASYNC_WORKERS; }
837 842
 <INITIAL>{ASYNC_USLEEP}	{ count(); yylval.strval=yytext; return ASYNC_USLEEP; }
Browse code

core: add an option to trigger also an RST on tcp connection close

- This gives an option to also send RST in case kamailio closes the
connection. There are cases where a FIN,ACK back forth leaves
the connection in the host in TIME_WAIT state, but the ports on both
sides are fixed. This leads to no request can send until
the TIME_WAIT state is gone.

Rick Barenthin authored on 03/05/2022 17:42:31 • Daniel-Constantin Mierla committed on 16/05/2022 06:01:02
Showing 1 changed files
... ...
@@ -421,6 +421,7 @@ TCP_OPT_CRLF_PING	"tcp_crlf_ping"
421 421
 TCP_OPT_ACCEPT_NO_CL	"tcp_accept_no_cl"
422 422
 TCP_OPT_ACCEPT_HEP3	"tcp_accept_hep3"
423 423
 TCP_OPT_ACCEPT_HAPROXY	"tcp_accept_haproxy"
424
+TCP_OPT_CLOSE_RST	"tcp_close_rst"
424 425
 TCP_CLONE_RCVBUF	"tcp_clone_rcvbuf"
425 426
 TCP_REUSE_PORT		"tcp_reuse_port"
426 427
 TCP_WAIT_DATA	"tcp_wait_data"
... ...
@@ -917,6 +918,7 @@ IMPORTFILE      "import_file"
917 918
 									return TCP_OPT_ACCEPT_HEP3; }
918 919
 <INITIAL>{TCP_OPT_ACCEPT_HAPROXY}	{ count(); yylval.strval=yytext;
919 920
 									return TCP_OPT_ACCEPT_HAPROXY; }
921
+<INITIAL>{TCP_OPT_CLOSE_RST}	{ count(); yylval.strval=yytext; return TCP_OPT_CLOSE_RST; }
920 922
 <INITIAL>{TCP_CLONE_RCVBUF}		{ count(); yylval.strval=yytext;
921 923
 									return TCP_CLONE_RCVBUF; }
922 924
 <INITIAL>{TCP_REUSE_PORT}	{ count(); yylval.strval=yytext; return TCP_REUSE_PORT; }
Browse code

core: added tcp_script_mode global parameter

- control if the tcp connection should be closed if received message
processing resulted in error return code

Daniel-Constantin Mierla authored on 14/02/2022 07:49:57
Showing 1 changed files
... ...
@@ -424,6 +424,7 @@ TCP_OPT_ACCEPT_HAPROXY	"tcp_accept_haproxy"
424 424
 TCP_CLONE_RCVBUF	"tcp_clone_rcvbuf"
425 425
 TCP_REUSE_PORT		"tcp_reuse_port"
426 426
 TCP_WAIT_DATA	"tcp_wait_data"
427
+TCP_SCRIPT_MODE	"tcp_script_mode"
427 428
 DISABLE_TLS		"disable_tls"|"tls_disable"
428 429
 ENABLE_TLS		"enable_tls"|"tls_enable"
429 430
 TLSLOG			"tlslog"|"tls_log"
... ...
@@ -921,6 +922,7 @@ IMPORTFILE      "import_file"
921 922
 <INITIAL>{TCP_REUSE_PORT}	{ count(); yylval.strval=yytext; return TCP_REUSE_PORT; }
922 923
 <INITIAL>{TCP_WAIT_DATA}	{ count(); yylval.strval=yytext;
923 924
 									return TCP_WAIT_DATA; }
925
+<INITIAL>{TCP_SCRIPT_MODE}	{ count(); yylval.strval=yytext; return TCP_SCRIPT_MODE; }
924 926
 <INITIAL>{DISABLE_TLS}	{ count(); yylval.strval=yytext; return DISABLE_TLS; }
925 927
 <INITIAL>{ENABLE_TLS}	{ count(); yylval.strval=yytext; return ENABLE_TLS; }
926 928
 <INITIAL>{TLSLOG}		{ count(); yylval.strval=yytext; return TLS_PORT_NO; }
Browse code

core: listen can now have a "virtual" flag to check for nonlocal floating IPs.

A new option to "listen" has been added called "virtual". This sets a flag on the listening socket to modify the behaviour of grep_sock_info.
When this flag is set, grep_sock_info will only consider the listening IP a match if the IP is found in the system's current list of
local IP addresses. If the IP is not currently local, then the matching IP is ignored.
If the virtual flag is not set on the socket then existing behaviour used instead.

This is useful in scenarios with an active/active cluster where Kamailio must know if a floating IP is currently local or not.

Rhys Hanrahan authored on 22/12/2021 11:13:47 • Daniel-Constantin Mierla committed on 07/01/2022 11:27:25
Showing 1 changed files
... ...
@@ -305,6 +305,7 @@ XAVPVIAPARAMS	xavp_via_params
305 305
 XAVPVIAFIELDS	xavp_via_fields
306 306
 LISTEN		listen
307 307
 ADVERTISE	advertise|ADVERTISE
308
+VIRTUAL		virtual
308 309
 STRNAME		name|NAME
309 310
 ALIAS		alias
310 311
 SR_AUTO_ALIASES	auto_aliases
... ...
@@ -741,6 +742,7 @@ IMPORTFILE      "import_file"
741 742
 <INITIAL>{XAVPVIAFIELDS}	{ yylval.strval=yytext; return XAVPVIAFIELDS; }
742 743
 <INITIAL>{LISTEN}	{ count(); yylval.strval=yytext; return LISTEN; }
743 744
 <INITIAL>{ADVERTISE}	{ count(); yylval.strval=yytext; return ADVERTISE; }
745
+<INITIAL>{VIRTUAL}	{ count(); yylval.strval=yytext; return VIRTUAL; }
744 746
 <INITIAL>{STRNAME}	{ count(); yylval.strval=yytext; return STRNAME; }
745 747
 <INITIAL>{ALIAS}	{ count(); yylval.strval=yytext; return ALIAS; }
746 748
 <INITIAL>{SR_AUTO_ALIASES}	{ count(); yylval.strval=yytext;
Browse code

core: tcp - added core parameter tcp_wait_data

- specify how long to wait (in milliseconds) to wait for data on tcp
connections in certain cases
- default is 5000ms (5secs)
- now applies when reading on tcp connection for haproxy protocol

Daniel-Constantin Mierla authored on 13/12/2021 13:42:50
Showing 1 changed files
... ...
@@ -422,6 +422,7 @@ TCP_OPT_ACCEPT_HEP3	"tcp_accept_hep3"
422 422
 TCP_OPT_ACCEPT_HAPROXY	"tcp_accept_haproxy"
423 423
 TCP_CLONE_RCVBUF	"tcp_clone_rcvbuf"
424 424
 TCP_REUSE_PORT		"tcp_reuse_port"
425
+TCP_WAIT_DATA	"tcp_wait_data"
425 426
 DISABLE_TLS		"disable_tls"|"tls_disable"
426 427
 ENABLE_TLS		"enable_tls"|"tls_enable"
427 428
 TLSLOG			"tlslog"|"tls_log"
... ...
@@ -916,6 +917,8 @@ IMPORTFILE      "import_file"
916 917
 <INITIAL>{TCP_CLONE_RCVBUF}		{ count(); yylval.strval=yytext;
917 918
 									return TCP_CLONE_RCVBUF; }
918 919
 <INITIAL>{TCP_REUSE_PORT}	{ count(); yylval.strval=yytext; return TCP_REUSE_PORT; }
920
+<INITIAL>{TCP_WAIT_DATA}	{ count(); yylval.strval=yytext;
921
+									return TCP_WAIT_DATA; }
919 922
 <INITIAL>{DISABLE_TLS}	{ count(); yylval.strval=yytext; return DISABLE_TLS; }
920 923
 <INITIAL>{ENABLE_TLS}	{ count(); yylval.strval=yytext; return ENABLE_TLS; }
921 924
 <INITIAL>{TLSLOG}		{ count(); yylval.strval=yytext; return TLS_PORT_NO; }
Browse code

core: cfg.lex - renamed defenv value mode parameter

Daniel-Constantin Mierla authored on 10/12/2021 11:11:00
Showing 1 changed files
... ...
@@ -1453,7 +1453,7 @@ IMPORTFILE      "import_file"
1453 1453
 <DEFENV_ID>[^ \t\r\n]+   { /* get the define id of environment variable */
1454 1454
 				count();
1455 1455
 				ksr_cfg_print_part(yytext);
1456
-				if(pp_define_env(yytext, yyleng, KSR_PPDEF_NORMAL, KSR_PPDEF_NONULL) < 0) {
1456
+				if(pp_define_env(yytext, yyleng, KSR_PPDEF_NORMAL, KSR_PPDEF_VALREQ) < 0) {
1457 1457
 					LM_CRIT("error at %s line %d\n", (finame)?finame:"cfg", line);
1458 1458
 					ksr_exit(-1);
1459 1459
 				}
... ...
@@ -1474,7 +1474,7 @@ IMPORTFILE      "import_file"
1474 1474
 <DEFENVS_ID>[^ \t\r\n]+   { /* get the define id of environment variable */
1475 1475
 				count();
1476 1476
 				ksr_cfg_print_part(yytext);
1477
-				if(pp_define_env(yytext, yyleng, KSR_PPDEF_QUOTED, KSR_PPDEF_NONULL) < 0) {
1477
+				if(pp_define_env(yytext, yyleng, KSR_PPDEF_QUOTED, KSR_PPDEF_VALREQ) < 0) {
1478 1478
 					LM_CRIT("error at %s line %d\n", (finame)?finame:"cfg", line);
1479 1479
 					ksr_exit(-1);
1480 1480
 				}
... ...
@@ -1482,7 +1482,7 @@ IMPORTFILE      "import_file"
1482 1482
 				ksr_cfg_print_initial_state();
1483 1483
 }
1484 1484
 
1485
-<INITIAL,CFGPRINTMODE>{PREP_START}{TRYDEFENV}  { count(); 
1485
+<INITIAL,CFGPRINTMODE>{PREP_START}{TRYDEFENV}  { count();
1486 1486
 			ksr_cfg_print_part(yytext);
1487 1487
 			state = DEFINE_S;
1488 1488
 			BEGIN(TRYDEFENV_ID);
... ...
@@ -1495,7 +1495,7 @@ IMPORTFILE      "import_file"
1495 1495
 <TRYDEFENV_ID>[^ \t\r\n]+   { /* get the define id of environment variable */
1496 1496
 				count();
1497 1497
 				ksr_cfg_print_part(yytext);
1498
-				if(pp_define_env(yytext, yyleng, KSR_PPDEF_NORMAL, KSR_PPDEF_NULLABLE) < 0) {
1498
+				if(pp_define_env(yytext, yyleng, KSR_PPDEF_NORMAL, KSR_PPDEF_VALTRY) < 0) {
1499 1499
 					LM_CRIT("error at %s line %d\n", (finame)?finame:"cfg", line);
1500 1500
 					ksr_exit(-1);
1501 1501
 				}
... ...
@@ -1503,7 +1503,7 @@ IMPORTFILE      "import_file"
1503 1503
 				ksr_cfg_print_initial_state();
1504 1504
 }
1505 1505
 
1506
-<INITIAL,CFGPRINTMODE>{PREP_START}{TRYDEFENVS}  { count(); 
1506
+<INITIAL,CFGPRINTMODE>{PREP_START}{TRYDEFENVS}  { count();
1507 1507
 			ksr_cfg_print_part(yytext);
1508 1508
 			state = DEFINE_S;
1509 1509
 			BEGIN(TRYDEFENVS_ID);
... ...
@@ -1516,7 +1516,7 @@ IMPORTFILE      "import_file"
1516 1516
 <TRYDEFENVS_ID>[^ \t\r\n]+   { /* get the define id of environment variable */
1517 1517
 				count();
1518 1518
 				ksr_cfg_print_part(yytext);
1519
-				if(pp_define_env(yytext, yyleng, KSR_PPDEF_QUOTED, KSR_PPDEF_NULLABLE) < 0) {
1519
+				if(pp_define_env(yytext, yyleng, KSR_PPDEF_QUOTED, KSR_PPDEF_VALTRY) < 0) {
1520 1520
 					LM_CRIT("error at %s line %d\n", (finame)?finame:"cfg", line);
1521 1521
 					ksr_exit(-1);
1522 1522
 				}
... ...
@@ -2127,7 +2127,7 @@ int pp_define_set(int len, char *text, int mode)
2127 2127
 	return 0;
2128 2128
 }
2129 2129
 
2130
-int pp_define_env(const char *text, int len, int qmode, int nullable )
2130
+int pp_define_env(const char *text, int len, int qmode, int vmode)
2131 2131
 {
2132 2132
 	char *r;
2133 2133
 	str defname;
... ...
@@ -2151,7 +2151,7 @@ int pp_define_env(const char *text, int len, int qmode, int nullable )
2151 2151
 	defvalue.s = getenv(r);
2152 2152
 
2153 2153
 	if(defvalue.s == NULL) {
2154
-        if( nullable == KSR_PPDEF_NULLABLE ) {
2154
+        if(vmode == KSR_PPDEF_VALTRY) {
2155 2155
             return 0;
2156 2156
         }
2157 2157
 		LM_ERR("env variable not defined [%s]\n", (char*)text);
Browse code

core: cfg.lex support for undefned env vars

Feature Request GH #2967 for undefined defenv

Add new keywords for preprocessing:

- #!trydefenv - The same as #!defenv, except if the variable is
undefined, the def value will be undefined as well.

- #!trydefenvs - The same as #!defenvs, except if the variable is
undefined, the def value will be undefined as well.

Ben Kaufman authored on 09/12/2021 19:37:53 • Daniel-Constantin Mierla committed on 10/12/2021 11:01:19
Showing 1 changed files
... ...
@@ -130,7 +130,8 @@
130 130
 /* start conditions */
131 131
 %x STRING1 STRING2 STR_BETWEEN COMMENT COMMENT_LN ATTR SELECT AVP_PVAR PVAR_P
132 132
 %x PVARID INCLF IMPTF EVRTNAME CFGPRINTMODE CFGPRINTLOADMOD DEFENV_ID DEFENVS_ID
133
-%x LINECOMMENT DEFINE_ID DEFINE_EOL DEFINE_DATA IFDEF_ID IFDEF_EOL IFDEF_SKIP
133
+%x TRYDEFENV_ID TRYDEFENVS_ID LINECOMMENT DEFINE_ID DEFINE_EOL DEFINE_DATA 
134
+%x IFDEF_ID IFDEF_EOL IFDEF_SKIP
134 135
 
135 136
 /* config script types : #!SER  or #!KAMAILIO or #!MAX_COMPAT */
136 137
 SER_CFG			SER
... ...
@@ -566,6 +567,8 @@ TRYDEF       "trydefine"|"trydef"
566 567
 REDEF        "redefine"|"redef"
567 568
 DEFENV       defenv
568 569
 DEFENVS      defenvs
570
+TRYDEFENV    trydefenv
571
+TRYDEFENVS   trydefenvs
569 572
 
570 573
 /* else is already defined */
571 574
 
... ...
@@ -1450,7 +1453,7 @@ IMPORTFILE      "import_file"
1450 1453
 <DEFENV_ID>[^ \t\r\n]+   { /* get the define id of environment variable */
1451 1454
 				count();
1452 1455
 				ksr_cfg_print_part(yytext);
1453
-				if(pp_define_env(yytext, yyleng, KSR_PPDEF_NORMAL) < 0) {
1456
+				if(pp_define_env(yytext, yyleng, KSR_PPDEF_NORMAL, KSR_PPDEF_NONULL) < 0) {
1454 1457
 					LM_CRIT("error at %s line %d\n", (finame)?finame:"cfg", line);
1455 1458
 					ksr_exit(-1);
1456 1459
 				}
... ...
@@ -1471,7 +1474,49 @@ IMPORTFILE      "import_file"
1471 1474
 <DEFENVS_ID>[^ \t\r\n]+   { /* get the define id of environment variable */
1472 1475
 				count();
1473 1476
 				ksr_cfg_print_part(yytext);
1474
-				if(pp_define_env(yytext, yyleng, KSR_PPDEF_QUOTED) < 0) {
1477
+				if(pp_define_env(yytext, yyleng, KSR_PPDEF_QUOTED, KSR_PPDEF_NONULL) < 0) {
1478
+					LM_CRIT("error at %s line %d\n", (finame)?finame:"cfg", line);
1479
+					ksr_exit(-1);
1480
+				}
1481
+				state = INITIAL;
1482
+				ksr_cfg_print_initial_state();
1483
+}
1484
+
1485
+<INITIAL,CFGPRINTMODE>{PREP_START}{TRYDEFENV}  { count(); 
1486
+			ksr_cfg_print_part(yytext);
1487
+			state = DEFINE_S;
1488
+			BEGIN(TRYDEFENV_ID);
1489
+}
1490
+
1491
+<TRYDEFENV_ID>[ \t]*      { /* eat the whitespace */
1492
+				count();
1493
+				ksr_cfg_print_part(yytext);
1494
+			}
1495
+<TRYDEFENV_ID>[^ \t\r\n]+   { /* get the define id of environment variable */
1496
+				count();
1497
+				ksr_cfg_print_part(yytext);
1498
+				if(pp_define_env(yytext, yyleng, KSR_PPDEF_NORMAL, KSR_PPDEF_NULLABLE) < 0) {
1499
+					LM_CRIT("error at %s line %d\n", (finame)?finame:"cfg", line);
1500
+					ksr_exit(-1);
1501
+				}
1502
+				state = INITIAL;
1503
+				ksr_cfg_print_initial_state();
1504
+}
1505
+
1506
+<INITIAL,CFGPRINTMODE>{PREP_START}{TRYDEFENVS}  { count(); 
1507
+			ksr_cfg_print_part(yytext);
1508
+			state = DEFINE_S;
1509
+			BEGIN(TRYDEFENVS_ID);
1510
+}
1511
+
1512
+<TRYDEFENVS_ID>[ \t]*      { /* eat the whitespace */
1513
+				count();
1514
+				ksr_cfg_print_part(yytext);
1515
+			}
1516
+<TRYDEFENVS_ID>[^ \t\r\n]+   { /* get the define id of environment variable */
1517
+				count();
1518
+				ksr_cfg_print_part(yytext);
1519
+				if(pp_define_env(yytext, yyleng, KSR_PPDEF_QUOTED, KSR_PPDEF_NULLABLE) < 0) {
1475 1520
 					LM_CRIT("error at %s line %d\n", (finame)?finame:"cfg", line);
1476 1521
 					ksr_exit(-1);
1477 1522
 				}
... ...
@@ -2082,7 +2127,7 @@ int pp_define_set(int len, char *text, int mode)
2082 2127
 	return 0;
2083 2128
 }
2084 2129
 
2085
-int pp_define_env(const char *text, int len, int qmode)
2130
+int pp_define_env(const char *text, int len, int qmode, int nullable )
2086 2131
 {
2087 2132
 	char *r;
2088 2133
 	str defname;
... ...
@@ -2106,6 +2151,9 @@ int pp_define_env(const char *text, int len, int qmode)
2106 2151
 	defvalue.s = getenv(r);
2107 2152
 
2108 2153
 	if(defvalue.s == NULL) {
2154
+        if( nullable == KSR_PPDEF_NULLABLE ) {
2155
+            return 0;
2156
+        }
2109 2157
 		LM_ERR("env variable not defined [%s]\n", (char*)text);
2110 2158
 		return -1;
2111 2159
 	}
Browse code

core: enclose in quotes the value for #!defenvs

Daniel-Constantin Mierla authored on 09/12/2021 09:41:41
Showing 1 changed files
... ...
@@ -2087,6 +2087,7 @@ int pp_define_env(const char *text, int len, int qmode)
2087 2087
 	char *r;
2088 2088
 	str defname;
2089 2089
 	str defvalue;
2090
+	str newval;
2090 2091
 
2091 2092
 	r = strchr(text, '=');
2092 2093
 
... ...
@@ -2115,6 +2116,13 @@ int pp_define_env(const char *text, int len, int qmode)
2115 2116
 		LM_ERR("cannot set define name [%s]\n", (char*)text);
2116 2117
 		return -1;
2117 2118
 	}
2119
+	if(qmode==KSR_PPDEF_QUOTED) {
2120
+		if(pp_def_qvalue(&defvalue, &newval) < 0) {
2121
+			LM_ERR("failed to enclose in quotes the value\n");
2122
+			return -1;
2123
+		}
2124
+		defvalue = newval;
2125
+	}
2118 2126
 	if(pp_define_set(defvalue.len, defvalue.s, qmode)<0) {
2119 2127
 		LM_ERR("cannot set define value [%s]\n", (char*)text);
2120 2128
 		return -1;
Browse code

core: added #!defenvs preprocessor directive

- similar to #!defenv, but the value is enclosed in double quotes to
make it covenient to be used as a string token

Daniel-Constantin Mierla authored on 30/11/2021 10:10:43
Showing 1 changed files
... ...
@@ -129,7 +129,7 @@
129 129
 
130 130
 /* start conditions */
131 131
 %x STRING1 STRING2 STR_BETWEEN COMMENT COMMENT_LN ATTR SELECT AVP_PVAR PVAR_P
132
-%x PVARID INCLF IMPTF EVRTNAME CFGPRINTMODE CFGPRINTLOADMOD DEFENV_ID
132
+%x PVARID INCLF IMPTF EVRTNAME CFGPRINTMODE CFGPRINTLOADMOD DEFENV_ID DEFENVS_ID
133 133
 %x LINECOMMENT DEFINE_ID DEFINE_EOL DEFINE_DATA IFDEF_ID IFDEF_EOL IFDEF_SKIP
134 134
 
135 135
 /* config script types : #!SER  or #!KAMAILIO or #!MAX_COMPAT */
... ...
@@ -565,6 +565,7 @@ ENDIF        endif
565 565
 TRYDEF       "trydefine"|"trydef"
566 566
 REDEF        "redefine"|"redef"
567 567
 DEFENV       defenv
568
+DEFENVS      defenvs
568 569
 
569 570
 /* else is already defined */
570 571
 
... ...
@@ -1449,7 +1450,28 @@ IMPORTFILE      "import_file"
1449 1450
 <DEFENV_ID>[^ \t\r\n]+   { /* get the define id of environment variable */
1450 1451
 				count();
1451 1452
 				ksr_cfg_print_part(yytext);
1452
-				if(pp_define_env(yytext, yyleng) < 0) {
1453
+				if(pp_define_env(yytext, yyleng, KSR_PPDEF_NORMAL) < 0) {
1454
+					LM_CRIT("error at %s line %d\n", (finame)?finame:"cfg", line);
1455
+					ksr_exit(-1);
1456
+				}
1457
+				state = INITIAL;
1458
+				ksr_cfg_print_initial_state();
1459
+}
1460
+
1461
+<INITIAL,CFGPRINTMODE>{PREP_START}{DEFENVS}  { count();
1462
+			ksr_cfg_print_part(yytext);
1463
+			state = DEFINE_S;
1464
+			BEGIN(DEFENVS_ID);
1465
+}
1466
+
1467
+<DEFENVS_ID>[ \t]*      { /* eat the whitespace */
1468
+				count();
1469
+				ksr_cfg_print_part(yytext);
1470
+			}
1471
+<DEFENVS_ID>[^ \t\r\n]+   { /* get the define id of environment variable */
1472
+				count();
1473
+				ksr_cfg_print_part(yytext);
1474
+				if(pp_define_env(yytext, yyleng, KSR_PPDEF_QUOTED) < 0) {
1453 1475
 					LM_CRIT("error at %s line %d\n", (finame)?finame:"cfg", line);
1454 1476
 					ksr_exit(-1);
1455 1477
 				}
... ...
@@ -2060,7 +2082,7 @@ int pp_define_set(int len, char *text, int mode)
2060 2082
 	return 0;
2061 2083
 }
2062 2084
 
2063
-int pp_define_env(const char *text, int len)
2085
+int pp_define_env(const char *text, int len, int qmode)
2064 2086
 {
2065 2087
 	char *r;
2066 2088
 	str defname;
... ...
@@ -2093,7 +2115,7 @@ int pp_define_env(const char *text, int len)
2093 2115
 		LM_ERR("cannot set define name [%s]\n", (char*)text);
2094 2116
 		return -1;
2095 2117
 	}
2096
-	if(pp_define_set(defvalue.len, defvalue.s, KSR_PPDEF_NORMAL)<0) {
2118
+	if(pp_define_set(defvalue.len, defvalue.s, qmode)<0) {
2097 2119
 		LM_ERR("cannot set define value [%s]\n", (char*)text);
2098 2120
 		return -1;
2099 2121
 	}
Browse code

core: add new param sip_parser_log_oneline

To log SIP headers with . instead of \r\n.

Stefan Mititelu authored on 25/10/2021 06:08:36
Showing 1 changed files
... ...
@@ -373,6 +373,7 @@ MEMSAFETY	"mem_safety"
373 373
 MEMJOIN		"mem_join"
374 374
 MEMSTATUSMODE		"mem_status_mode"
375 375
 CORELOG		"corelog"|"core_log"
376
+SIP_PARSER_LOG_ONELINE "sip_parser_log_oneline"
376 377
 SIP_PARSER_LOG "sip_parser_log"
377 378
 SIP_PARSER_MODE "sip_parser_mode"
378 379
 SIP_WARNING sip_warning
... ...
@@ -835,6 +836,7 @@ IMPORTFILE      "import_file"
835 836
 <INITIAL>{MEMSAFETY}	{ count(); yylval.strval=yytext; return MEMSAFETY; }
836 837
 <INITIAL>{MEMJOIN}	{ count(); yylval.strval=yytext; return MEMJOIN; }
837 838
 <INITIAL>{MEMSTATUSMODE}	{ count(); yylval.strval=yytext; return MEMSTATUSMODE; }
839
+<INITIAL>{SIP_PARSER_LOG_ONELINE}  { count(); yylval.strval=yytext; return SIP_PARSER_LOG_ONELINE; }
838 840
 <INITIAL>{SIP_PARSER_LOG}  { count(); yylval.strval=yytext; return SIP_PARSER_LOG; }
839 841
 <INITIAL>{SIP_PARSER_MODE}  { count(); yylval.strval=yytext; return SIP_PARSER_MODE; }
840 842
 <INITIAL>{CORELOG}	{ count(); yylval.strval=yytext; return CORELOG; }
Browse code

core: fix building quoted value for #!subsdefs

Daniel-Constantin Mierla authored on 01/07/2021 09:17:56
Showing 1 changed files
... ...
@@ -2049,11 +2049,12 @@ int pp_define_set(int len, char *text, int mode)
2049 2049
 
2050 2050
 	pp_defines[ppos].value.len = len;
2051 2051
 	pp_defines[ppos].value.s = text;
2052
-	LM_DBG("### setting define ID [%.*s] value [%.*s]\n",
2052
+	LM_DBG("### setting define ID [%.*s] value [%.*s] (mode: %d)\n",
2053 2053
 			pp_defines[ppos].name.len,
2054 2054
 			pp_defines[ppos].name.s,
2055 2055
 			pp_defines[ppos].value.len,
2056
-			pp_defines[ppos].value.s);
2056
+			pp_defines[ppos].value.s,
2057
+			mode);
2057 2058
 	return 0;
2058 2059
 }
2059 2060
 
Browse code

core: cfg.lex - accept IPv4/6 as alternative keywords for INET/6

Daniel-Constantin Mierla authored on 09/06/2021 10:19:24
Showing 1 changed files
... ...
@@ -512,8 +512,8 @@ TLS			"tls"|"TLS"
512 512
 SCTP		"sctp"|"SCTP"
513 513
 WS		"ws"|"WS"
514 514
 WSS		"wss"|"WSS"
515
-INET		"inet"|"INET"
516
-INET6		"inet6"|"INET6"
515
+INET		"inet"|"INET"|"ipv4"|"IPv4"|"IPV4"
516
+INET6		"inet6"|"INET6"|"ipv6"|"IPv6"|"IPV6"
517 517
 SSLv23			"sslv23"|"SSLv23"|"SSLV23"
518 518
 SSLv2			"sslv2"|"SSLv2"|"SSLV2"
519 519
 SSLv3			"sslv3"|"SSLv3"|"SSLV3"
Browse code

core: clone define value to avoid losing the reference

- impacted also by substdef
- GH #2736

Daniel-Constantin Mierla authored on 25/05/2021 08:24:23
Showing 1 changed files
... ...
@@ -1337,7 +1337,7 @@ IMPORTFILE      "import_file"
1337 1337
 <DEFINE_DATA>\\{CR}		{	count(); ksr_cfg_print_part(yytext); } /* eat the escaped CR */
1338 1338
 <DEFINE_DATA>{CR}		{	count();
1339 1339
 							ksr_cfg_print_part(yytext);
1340
-							if (pp_define_set(strlen(s_buf.s), s_buf.s)) return 1;
1340
+							if (pp_define_set(strlen(s_buf.s), s_buf.s, KSR_PPDEF_NORMAL)) return 1;
1341 1341
 							memset(&s_buf, 0, sizeof(s_buf));
1342 1342
 							state = INITIAL;
1343 1343
 							ksr_cfg_print_initial_state();
... ...
@@ -2007,7 +2007,7 @@ int pp_define(int len, const char *text)
2007 2007
 	return 0;
2008 2008
 }
2009 2009
 
2010
-int pp_define_set(int len, char *text)
2010
+int pp_define_set(int len, char *text, int mode)
2011 2011
 {
2012 2012
 	int ppos;
2013 2013
 
... ...
@@ -2090,7 +2090,7 @@ int pp_define_env(const char *text, int len)
2090 2090
 		LM_ERR("cannot set define name [%s]\n", (char*)text);
2091 2091
 		return -1;
2092 2092
 	}
2093
-	if(pp_define_set(defvalue.len, defvalue.s)<0) {
2093
+	if(pp_define_set(defvalue.len, defvalue.s, KSR_PPDEF_NORMAL)<0) {
2094 2094
 		LM_ERR("cannot set define value [%s]\n", (char*)text);
2095 2095
 		return -1;
2096 2096
 	}
Browse code

core: cfg.lex - free after log message

Daniel-Constantin Mierla authored on 08/04/2021 07:36:02
Showing 1 changed files
... ...
@@ -1802,13 +1802,14 @@ static int sr_push_yy_state(char *fin, int mode)
1802 1802
 		fp = fopen(newf, "r" );
1803 1803
 		if ( fp==NULL )
1804 1804
 		{
1805
-			pkg_free(newf);
1806 1805
 			if(mode==0)
1807 1806
 			{
1808 1807
 				LM_CRIT("cannot open included file: %s (%s)\n", fbuf, newf);
1808
+				pkg_free(newf);
1809 1809
 				return -1;
1810 1810
 			} else {
1811 1811
 				LM_DBG("importing file ignored: %s (%s)\n", fbuf, newf);
1812
+				pkg_free(newf);
1812 1813
 				return 0;
1813 1814
 			}
1814 1815
 		}
Browse code

core: checks for trying to define empty or null ids

- use found pointer to compute the lenght of ID for -A parameter to save
a strlen()

Daniel-Constantin Mierla authored on 05/04/2021 15:50:31
Showing 1 changed files
... ...
@@ -1927,11 +1927,16 @@ ksr_ppdefine_t* pp_get_define(int idx)
1927 1927
 	return &pp_defines[idx];
1928 1928
 }
1929 1929
 
1930
-static int pp_lookup(int len, const char * text)
1930
+static int pp_lookup(int len, const char *text)
1931 1931
 {
1932 1932
 	str var = {(char *)text, len};
1933 1933
 	int i;
1934 1934
 
1935
+	if(len<=0 || text==NULL) {
1936
+		LM_ERR("invalid parameters");
1937
+		return -1;
1938
+	}
1939
+
1935 1940
 	for (i=0; i<pp_num_defines; i++)
1936 1941
 		if (STR_EQ(pp_defines[i].name, var))
1937 1942
 			return i;
... ...
@@ -1945,10 +1950,15 @@ int pp_define_set_type(int type)
1945 1950
 	return 0;
1946 1951
 }
1947 1952
 
1948
-int pp_define(int len, const char * text)
1953
+int pp_define(int len, const char *text)
1949 1954
 {
1950 1955
 	int ppos;
1951 1956
 
1957
+	if(len<=0 || text==NULL) {
1958
+		LM_ERR("invalid parameters");
1959
+		return -1;
1960
+	}
1961
+
1952 1962
 	LM_DBG("defining id: %.*s\n", len, text);
1953 1963
 
1954 1964
 	if (pp_num_defines == MAX_DEFINES) {
... ...
@@ -2010,7 +2020,7 @@ int pp_define_set(int len, char *text)
2010 2020
 		LM_BUG("BUG: the index in define table not set yet\n");
2011 2021
 		return -1;
2012 2022
 	}
2013
-	if(len<=0) {
2023
+	if(len<=0 || text==NULL) {
2014 2024
 		LM_DBG("no define value - ignoring\n");
2015 2025
 		return 0;
2016 2026
 	}
... ...
@@ -2046,7 +2056,7 @@ int pp_define_set(int len, char *text)
2046 2056
 	return 0;
2047 2057
 }
2048 2058
 
2049
-int pp_define_env(const char * text, int len)
2059
+int pp_define_env(const char *text, int len)
2050 2060
 {
2051 2061
 	char *r;
2052 2062
 	str defname;
... ...
@@ -2087,7 +2097,7 @@ int pp_define_env(const char * text, int len)
2087 2097
 	return 0;
2088 2098
 }
2089 2099
 
2090
-str *pp_define_get(int len, const char * text)
2100
+str *pp_define_get(int len, const char *text)
2091 2101
 {
2092 2102
 	str var = {(char *)text, len};
2093 2103
 	int i;
... ...
@@ -2129,7 +2139,7 @@ static int pp_ifdef_type(int type)
2129 2139
  * ifndef defined   -> 0
2130 2140
  * ifndef undefined -> 1
2131 2141
  */
2132
-static void pp_ifdef_var(int len, const char * text)
2142
+static void pp_ifdef_var(int len, const char *text)
2133 2143
 {
2134 2144
 	pp_ifdef_stack[pp_sptr] ^= (pp_lookup(len, text) < 0);
2135 2145
 }
Browse code

core: cfg.len - sanitizer safety check of target buffer

Daniel-Constantin Mierla authored on 05/04/2021 15:31:48
Showing 1 changed files
... ...
@@ -1593,7 +1593,7 @@ static char* addchar(struct str_buf* dst, char c)
1593 1593
 
1594 1594
 static char* addstr(struct str_buf* dst_b, char* src, int len)
1595 1595
 {
1596
-	char *tmp;
1596
+	char *tmp = NULL;
1597 1597
 	unsigned size;
1598 1598
 	unsigned used;
1599 1599
 
... ...
@@ -1612,6 +1612,10 @@ static char* addstr(struct str_buf* dst_b, char* src, int len)
1612 1612
 		dst_b->crt=dst_b->s+used;
1613 1613
 		dst_b->left=size-used;
1614 1614
 	}
1615
+	if(dst_b->crt==NULL) {
1616
+		LM_CRIT("unexpected null dst buffer\n");
1617
+		ksr_exit(-1);
1618
+	}
1615 1619
 	memcpy(dst_b->crt, src, len);
1616 1620
 	dst_b->crt+=len;
1617 1621
 	*(dst_b->crt)=0;
Browse code

core: renamed recent params wait_child1_* to wait_worker1_*

- consistent with the event route name

Daniel-Constantin Mierla authored on 16/03/2021 08:33:04
Showing 1 changed files
... ...
@@ -467,9 +467,9 @@ VERBOSE_STARTUP		"verbose_startup"
467 467
 
468 468
 SERVER_ID     "server_id"
469 469
 ROUTE_LOCKS_SIZE     "route_locks_size"
470
-WAIT_CHILD1_MODE     "wait_child1_mode"
471
-WAIT_CHILD1_TIME     "wait_child1_time"
472
-WAIT_CHILD1_USLEEP   "wait_child1_usleep"
470
+WAIT_WORKER1_MODE     "wait_worker1_mode"
471
+WAIT_WORKER1_TIME     "wait_worker1_time"
472
+WAIT_WORKER1_USLEEP   "wait_worker1_usleep"
473 473
 
474 474
 KEMI     "kemi"
475 475
 ONSEND_ROUTE_CALLBACK	"onsend_route_callback"
... ...
@@ -992,9 +992,9 @@ IMPORTFILE      "import_file"
992 992
 <INITIAL>{VERBOSE_STARTUP}		{	count(); yylval.strval=yytext;
993 993
 									return VERBOSE_STARTUP; }
994 994
 <INITIAL>{ROUTE_LOCKS_SIZE}  { count(); yylval.strval=yytext; return ROUTE_LOCKS_SIZE; }
995
-<INITIAL>{WAIT_CHILD1_MODE}  { count(); yylval.strval=yytext; return WAIT_CHILD1_MODE; }
996
-<INITIAL>{WAIT_CHILD1_TIME}  { count(); yylval.strval=yytext; return WAIT_CHILD1_TIME; }
997
-<INITIAL>{WAIT_CHILD1_USLEEP}  { count(); yylval.strval=yytext; return WAIT_CHILD1_USLEEP; }
995
+<INITIAL>{WAIT_WORKER1_MODE}  { count(); yylval.strval=yytext; return WAIT_WORKER1_MODE; }
996
+<INITIAL>{WAIT_WORKER1_TIME}  { count(); yylval.strval=yytext; return WAIT_WORKER1_TIME; }
997
+<INITIAL>{WAIT_WORKER1_USLEEP}  { count(); yylval.strval=yytext; return WAIT_WORKER1_USLEEP; }
998 998
 <INITIAL>{SERVER_ID}  { count(); yylval.strval=yytext; return SERVER_ID;}
999 999
 <INITIAL>{KEMI}  { count(); yylval.strval=yytext; return KEMI;}
1000 1000
 <INITIAL>{REPLY_ROUTE_CALLBACK}  { count(); yylval.strval=yytext; return REPLY_ROUTE_CALLBACK;}
Browse code

core: global parameters to enable waiting for child one worker initialization

- new paramters:
- wait_child1_mode=[0|1] - set to wait or not
- wait_child1_time=1000000 (micro-seconds) - how long to wait over all
- wait_child1_usleep=100000 (micro-seconds) - step to wait before
checking if initialization completed

Daniel-Constantin Mierla authored on 15/03/2021 11:29:08
Showing 1 changed files
... ...
@@ -467,6 +467,9 @@ VERBOSE_STARTUP		"verbose_startup"
467 467
 
468 468
 SERVER_ID     "server_id"
469 469
 ROUTE_LOCKS_SIZE     "route_locks_size"
470
+WAIT_CHILD1_MODE     "wait_child1_mode"
471
+WAIT_CHILD1_TIME     "wait_child1_time"
472
+WAIT_CHILD1_USLEEP   "wait_child1_usleep"
470 473
 
471 474
 KEMI     "kemi"
472 475
 ONSEND_ROUTE_CALLBACK	"onsend_route_callback"
... ...
@@ -989,6 +992,9 @@ IMPORTFILE      "import_file"
989 992
 <INITIAL>{VERBOSE_STARTUP}		{	count(); yylval.strval=yytext;
990 993
 									return VERBOSE_STARTUP; }
991 994
 <INITIAL>{ROUTE_LOCKS_SIZE}  { count(); yylval.strval=yytext; return ROUTE_LOCKS_SIZE; }
995
+<INITIAL>{WAIT_CHILD1_MODE}  { count(); yylval.strval=yytext; return WAIT_CHILD1_MODE; }
996
+<INITIAL>{WAIT_CHILD1_TIME}  { count(); yylval.strval=yytext; return WAIT_CHILD1_TIME; }
997
+<INITIAL>{WAIT_CHILD1_USLEEP}  { count(); yylval.strval=yytext; return WAIT_CHILD1_USLEEP; }
992 998
 <INITIAL>{SERVER_ID}  { count(); yylval.strval=yytext; return SERVER_ID;}
993 999
 <INITIAL>{KEMI}  { count(); yylval.strval=yytext; return KEMI;}
994 1000
 <INITIAL>{REPLY_ROUTE_CALLBACK}  { count(); yylval.strval=yytext; return REPLY_ROUTE_CALLBACK;}
Browse code

cfg.lex: removed yynoreturn attribute for ksr_yy_fatal_error()

- it is defined only by newer flex version, resulting in compile
failure on older versions (e.g., centos 7)

Daniel-Constantin Mierla authored on 10/02/2021 07:27:58
Showing 1 changed files
... ...
@@ -42,7 +42,7 @@
42 42
 	#include "daemonize.h"
43 43
 	#include "ppcfg.h"
44 44
 
45
-	static void yynoreturn ksr_yy_fatal_error(const char* msg);
45
+	static void ksr_yy_fatal_error(const char* msg);
46 46
 	#define YY_FATAL_ERROR(msg) ksr_yy_fatal_error(msg);
47 47
 
48 48
 	/* states */
... ...
@@ -2167,7 +2167,7 @@ static void pp_endif()
2167 2167
 	pp_update_state();
2168 2168
 }
2169 2169
 
2170
-static void yynoreturn ksr_yy_fatal_error(const char* msg)
2170
+static void ksr_yy_fatal_error(const char* msg)
2171 2171
 {
2172 2172
 	if(ksr_atexit_mode==1) {
2173 2173
 		yy_fatal_error(msg);
Browse code

core: cfg.lex - removed __attribute__((unused))

- not supported on some distros
- workaround to avoid unused warning

Daniel-Constantin Mierla authored on 09/02/2021 20:16:52
Showing 1 changed files
... ...
@@ -42,7 +42,6 @@
42 42
 	#include "daemonize.h"
43 43
 	#include "ppcfg.h"
44 44
 
45