Browse code

Merge commit 'origin/ser_core_cvs'

* commit 'origin/ser_core_cvs':
core: config parser listen if names fix
core: config parser listen fix
core: interface names in socket list port fix
core: startup socket list fix
core: parse_headers flags fix
tm: fifo access From fix
cfg framework: fix the group handles in the main process

Conflicts:
cfg.lex
cfg.y

Andrei Pelinescu-Onciul authored on 17/07/2009 16:09:01
Showing 5 changed files
... ...
@@ -124,6 +124,7 @@
124 124
 	int startline=1;
125 125
 	static int ign_lines=0;
126 126
 	static int ign_columns=0;
127
+	char* yy_number_str=0; /* str correspondent for the current NUMBER token */
127 128
 
128 129
 	static char* addchar(struct str_buf *, char);
129 130
 	static char* addstr(struct str_buf *, char*, int);
... ...
@@ -445,6 +446,7 @@ LETTER		[a-zA-Z]
445 446
 DIGIT		[0-9]
446 447
 ALPHANUM	{LETTER}|{DIGIT}|[_]
447 448
 ID			{LETTER}{ALPHANUM}*
449
+NUM_ID		{ALPHANUM}+
448 450
 HEX			[0-9a-fA-F]
449 451
 HEXNUMBER	0x{HEX}+
450 452
 OCTNUMBER	0[0-7]+
... ...
@@ -846,10 +848,14 @@ EAT_ABLE	[\ \t\b\r]
846 848
 <SELECT>{DOT}           { count(); return DOT; }
847 849
 <SELECT>{LBRACK}        { count(); return LBRACK; }
848 850
 <SELECT>{RBRACK}        { count(); return RBRACK; }
849
-<SELECT>{DECNUMBER}	{ count(); yylval.intval=atoi(yytext);return NUMBER; }
850
-<SELECT>{HEXNUMBER}	{ count(); yylval.intval=(int)strtol(yytext, 0, 16); return NUMBER; }
851
-<SELECT>{OCTNUMBER}	{ count(); yylval.intval=(int)strtol(yytext, 0, 8); return NUMBER; }
852
-<SELECT>{BINNUMBER}     { count(); yylval.intval=(int)strtol(yytext, 0, 2); return NUMBER; }
851
+<SELECT>{DECNUMBER}	{ count(); yylval.intval=atoi(yytext);
852
+						yy_number_str=yytext; return NUMBER; }
853
+<SELECT>{HEXNUMBER}	{ count(); yylval.intval=(int)strtol(yytext, 0, 16);
854
+						yy_number_str=yytext; return NUMBER; }
855
+<SELECT>{OCTNUMBER}	{ count(); yylval.intval=(int)strtol(yytext, 0, 8);
856
+						yy_number_str=yytext; return NUMBER; }
857
+<SELECT>{BINNUMBER}	{ count(); yylval.intval=(int)strtol(yytext, 0, 2);
858
+						yy_number_str=yytext; return NUMBER; }
853 859
 
854 860
 
855 861
 <INITIAL>{ATTR_MARK}    { count(); state = ATTR_S; BEGIN(ATTR);
... ...
@@ -867,7 +873,8 @@ EAT_ABLE	[\ \t\b\r]
867 873
 <ATTR>{LBRACK}          { count(); return LBRACK; }
868 874
 <ATTR>{RBRACK}          { count(); return RBRACK; }
869 875
 <ATTR>{STAR}			{ count(); return STAR; }
870
-<ATTR>{DECNUMBER}		{ count(); yylval.intval=atoi(yytext);return NUMBER; }
876
+<ATTR>{DECNUMBER}		{ count(); yylval.intval=atoi(yytext);
877
+							yy_number_str=yytext; return NUMBER; }
871 878
 <ATTR>{ID}				{ count(); addstr(&s_buf, yytext, yyleng);
872 879
 							yylval.strval=s_buf.s;
873 880
 							memset(&s_buf, 0, sizeof(s_buf));
... ...
@@ -950,26 +957,32 @@ EAT_ABLE	[\ \t\b\r]
950 957
 							}
951 958
 
952 959
 <INITIAL>{IPV6ADDR}		{ count(); yylval.strval=yytext; return IPV6ADDR; }
953
-<INITIAL>{DECNUMBER}		{ count(); yylval.intval=atoi(yytext);return NUMBER; }
960
+<INITIAL>{DECNUMBER}	{ count(); yylval.intval=atoi(yytext);
961
+								yy_number_str=yytext; return NUMBER; }
954 962
 <INITIAL>{HEXNUMBER}	{ count(); yylval.intval=(int)strtol(yytext, 0, 16);
955
-							return NUMBER; }
963
+							yy_number_str=yytext; return NUMBER; }
956 964
 <INITIAL>{OCTNUMBER}	{ count(); yylval.intval=(int)strtol(yytext, 0, 8);
957
-							return NUMBER; }
958
-<INITIAL>{BINNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 2); return NUMBER; }
959
-<INITIAL>{YES}			{ count(); yylval.intval=1; return NUMBER; }
960
-<INITIAL>{NO}			{ count(); yylval.intval=0; return NUMBER; }
965
+							yy_number_str=yytext; return NUMBER; }
966
+<INITIAL>{BINNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 2);
967
+							yy_number_str=yytext; return NUMBER; }
968
+<INITIAL>{YES}			{ count(); yylval.intval=1;
969
+							yy_number_str=yytext; return NUMBER; }
970
+<INITIAL>{NO}			{ count(); yylval.intval=0;
971
+							yy_number_str=yytext; return NUMBER; }
961 972
 <INITIAL>{TCP}			{ count(); return TCP; }
962 973
 <INITIAL>{UDP}			{ count(); return UDP; }
963 974
 <INITIAL>{TLS}			{ count(); return TLS; }
964 975
 <INITIAL>{SCTP}			{ count(); return SCTP; }
965
-<INITIAL>{INET}			{ count(); yylval.intval=AF_INET; return NUMBER; }
976
+<INITIAL>{INET}			{ count(); yylval.intval=AF_INET;
977
+							yy_number_str=yytext; return NUMBER; }
966 978
 <INITIAL>{INET6}		{ count();
967 979
 						#ifdef USE_IPV6
968 980
 						  yylval.intval=AF_INET6;
969 981
 						#else
970 982
 						  yylval.intval=-1; /* no match*/
971 983
 						#endif
972
-						  return NUMBER; }
984
+						yy_number_str=yytext;
985
+						return NUMBER; }
973 986
 <INITIAL>{SSLv23}		{ count(); yylval.strval=yytext; return SSLv23; }
974 987
 <INITIAL>{SSLv2}		{ count(); yylval.strval=yytext; return SSLv2; }
975 988
 <INITIAL>{SSLv3}		{ count(); yylval.strval=yytext; return SSLv3; }
... ...
@@ -1068,6 +1081,10 @@ EAT_ABLE	[\ \t\b\r]
1068 1081
 									yylval.strval=s_buf.s;
1069 1082
 									memset(&s_buf, 0, sizeof(s_buf));
1070 1083
 									return ID; }
1084
+<INITIAL>{NUM_ID}			{ count(); addstr(&s_buf, yytext, yyleng);
1085
+									yylval.strval=s_buf.s;
1086
+									memset(&s_buf, 0, sizeof(s_buf));
1087
+									return NUM_ID; }
1071 1088
 
1072 1089
 <SELECT>.               { unput(yytext[0]); state = INITIAL_S; BEGIN(INITIAL); } /* Rescan the token in INITIAL state */
1073 1090
 
... ...
@@ -193,6 +193,9 @@
193 193
 
194 194
 
195 195
 extern int yylex();
196
+/* safer then using yytext which can be array or pointer */
197
+extern char* yy_number_str;
198
+
196 199
 static void yyerror(char* s, ...);
197 200
 static void yyerror_at(struct cfg_pos* pos, char* s, ...);
198 201
 static char* tmp;
... ...
@@ -526,6 +529,7 @@ static int case_check_default(struct case_stms* stms);
526 529
 /* values */
527 530
 %token <intval> NUMBER
528 531
 %token <strval> ID
532
+%token <strval> NUM_ID
529 533
 %token <strval> STRING
530 534
 %token <strval> IPV6ADDR
531 535
 %token <strval> PVAR
... ...
@@ -556,7 +560,7 @@ static int case_check_default(struct case_stms* stms);
556 560
 %type <case_stms> single_case case_stms
557 561
 %type <ipaddr> ipv4 ipv6 ipv6addr ip
558 562
 %type <ipnet> ipnet
559
-%type <strval> host
563
+%type <strval> host host_or_if host_if_id
560 564
 %type <strval> listen_id
561 565
 %type <name_l> listen_id_lst
562 566
 %type <name_l> listen_id2
... ...
@@ -618,18 +622,20 @@ statement:
618 622
 	;
619 623
 listen_id:
620 624
 	ip {
621
-		tmp=ip_addr2a($1);
622
-		if (tmp==0) {
623
-			LOG(L_CRIT, "ERROR: cfg. parser: bad ip "
624
-					"address.\n");
625
-			$$=0;
626
-		} else {
627
-			$$=pkg_malloc(strlen(tmp)+1);
628
-			if ($$==0) {
629
-				LOG(L_CRIT, "ERROR: cfg. parser: out of "
630
-						"memory.\n");
625
+		if ($1){
626
+			tmp=ip_addr2a($1);
627
+			if (tmp==0) {
628
+				LOG(L_CRIT, "ERROR: cfg. parser: bad ip "
629
+						"address.\n");
630
+				$$=0;
631 631
 			} else {
632
-				strncpy($$, tmp, strlen(tmp)+1);
632
+				$$=pkg_malloc(strlen(tmp)+1);
633
+				if ($$==0) {
634
+					LOG(L_CRIT, "ERROR: cfg. parser: out of "
635
+							"memory.\n");
636
+				} else {
637
+					strncpy($$, tmp, strlen(tmp)+1);
638
+				}
633 639
 			}
634 640
 		}
635 641
 	}
... ...
@@ -642,13 +648,15 @@ listen_id:
642 648
 				strncpy($$, $1, strlen($1)+1);
643 649
 		}
644 650
 	}
645
-	| host {
646
-		$$=pkg_malloc(strlen($1)+1);
647
-		if ($$==0) {
648
-				LOG(L_CRIT, "ERROR: cfg. parser: out of "
649
-						"memory.\n");
650
-		} else {
651
-				strncpy($$, $1, strlen($1)+1);
651
+	| host_or_if {
652
+		if ($1){
653
+			$$=pkg_malloc(strlen($1)+1);
654
+			if ($$==0) {
655
+					LOG(L_CRIT, "ERROR: cfg. parser: out of "
656
+							"memory.\n");
657
+			} else {
658
+					strncpy($$, $1, strlen($1)+1);
659
+			}
652 660
 		}
653 661
 	}
654 662
 	;
... ...
@@ -695,7 +703,7 @@ listen_phostport:
695 703
 
696 704
 id_lst:
697 705
 	listen_phostport		{  $$=$1 ; }
698
-	| listen_phostport id_lst	{ $$=$1; $$->next=$2; }
706
+	| listen_phostport id_lst	{ $$=$1;  if ($$) $$->next=$2; }
699 707
 	;
700 708
 
701 709
 intno: NUMBER
... ...
@@ -1366,7 +1374,8 @@ assign_stm:
1366 1374
 		}
1367 1375
 		free_socket_id_lst($3);
1368 1376
 	}
1369
-	| LISTEN EQUAL  error { yyerror("ip address or hostname expected"); }
1377
+	| LISTEN EQUAL  error { yyerror("ip address, interface name or"
1378
+									" hostname expected"); }
1370 1379
 	| ALIAS EQUAL  id_lst {
1371 1380
 		for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next){
1372 1381
 			add_alias(	lst_tmp->addr_lst->name,
... ...
@@ -1382,8 +1391,10 @@ assign_stm:
1382 1391
 	| SR_AUTO_ALIASES EQUAL NUMBER { sr_auto_aliases=$3; }
1383 1392
 	| SR_AUTO_ALIASES EQUAL error  { yyerror("boolean value expected"); }
1384 1393
 	| ADVERTISED_ADDRESS EQUAL listen_id {
1385
-		default_global_address.s=$3;
1386
-		default_global_address.len=strlen($3);
1394
+		if ($3){
1395
+			default_global_address.s=$3;
1396
+			default_global_address.len=strlen($3);
1397
+		}
1387 1398
 	}
1388 1399
 	| ADVERTISED_ADDRESS EQUAL error {yyerror("ip address or hostname expected"); }
1389 1400
 	| ADVERTISED_PORT EQUAL NUMBER {
... ...
@@ -1908,33 +1919,83 @@ ipnet:
1908 1919
 host:
1909 1920
 	ID { $$=$1; }
1910 1921
 	| host DOT ID {
1911
-		$$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
1912
-		if ($$==0) {
1913
-			LOG(L_CRIT, "ERROR: cfg. parser: memory allocation failure while parsing host\n");
1914
-		} else {
1915
-			memcpy($$, $1, strlen($1));
1916
-			$$[strlen($1)]='.';
1917
-			memcpy($$+strlen($1)+1, $3, strlen($3));
1918
-			$$[strlen($1)+1+strlen($3)]=0;
1922
+		if ($1){
1923
+			$$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
1924
+			if ($$==0) {
1925
+				LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
1926
+							" failure while parsing host\n");
1927
+			} else {
1928
+				memcpy($$, $1, strlen($1));
1929
+				$$[strlen($1)]='.';
1930
+				memcpy($$+strlen($1)+1, $3, strlen($3));
1931
+				$$[strlen($1)+1+strlen($3)]=0;
1932
+			}
1933
+			pkg_free($1);
1919 1934
 		}
1920
-		pkg_free($1);
1921
-		pkg_free($3);
1922 1935
 	}
1923 1936
 	| host MINUS ID {
1924
-		$$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
1925
-		if ($$==0) {
1926
-			LOG(L_CRIT, "ERROR: cfg. parser: memory allocation failure while parsing host\n");
1927
-		} else {
1928
-			memcpy($$, $1, strlen($1));
1929
-			$$[strlen($1)]='-';
1930
-			memcpy($$+strlen($1)+1, $3, strlen($3));
1931
-			$$[strlen($1)+1+strlen($3)]=0;
1937
+		if ($1){
1938
+			$$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
1939
+			if ($$==0) {
1940
+				LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
1941
+							" failure while parsing host\n");
1942
+			} else {
1943
+				memcpy($$, $1, strlen($1));
1944
+				$$[strlen($1)]='-';
1945
+				memcpy($$+strlen($1)+1, $3, strlen($3));
1946
+				$$[strlen($1)+1+strlen($3)]=0;
1947
+			}
1948
+			pkg_free($1);
1932 1949
 		}
1933
-		pkg_free($1);
1934
-		pkg_free($3);
1935 1950
 	}
1936 1951
 	| host DOT error { $$=0; pkg_free($1); yyerror("invalid hostname"); }
1952
+	| host MINUS error { $$=0; pkg_free($1); yyerror("invalid hostname"); }
1953
+	;
1954
+
1955
+host_if_id: ID
1956
+		| NUM_ID
1957
+		| NUMBER { $$=yy_number_str /* text version */; }
1958
+		;
1959
+
1960
+host_or_if:
1961
+	host_if_id { $$=$1; }
1962
+	| host_or_if DOT host_if_id {
1963
+		if ($1){
1964
+			$$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
1965
+			if ($$==0) {
1966
+				LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
1967
+							" failure while parsing host/interface name\n");
1968
+			} else {
1969
+				memcpy($$, $1, strlen($1));
1970
+				$$[strlen($1)]='.';
1971
+				memcpy($$+strlen($1)+1, $3, strlen($3));
1972
+				$$[strlen($1)+1+strlen($3)]=0;
1973
+			}
1974
+			pkg_free($1);
1975
+		}
1976
+	}
1977
+	| host_or_if MINUS host_if_id {
1978
+		if ($1){
1979
+			$$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
1980
+			if ($$==0) {
1981
+				LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
1982
+							" failure while parsing host/interface name\n");
1983
+			} else {
1984
+				memcpy($$, $1, strlen($1));
1985
+				$$[strlen($1)]='-';
1986
+				memcpy($$+strlen($1)+1, $3, strlen($3));
1987
+				$$[strlen($1)+1+strlen($3)]=0;
1988
+			}
1989
+			pkg_free($1);
1990
+		}
1991
+	}
1992
+	| host_or_if DOT error { $$=0; pkg_free($1);
1993
+								yyerror("invalid host or interface name"); }
1994
+	| host_or_if MINUS error { $$=0; pkg_free($1);
1995
+								yyerror("invalid host or interface name"); }
1937 1996
 	;
1997
+
1998
+
1938 1999
 /* filtered cmd */
1939 2000
 fcmd:
1940 2001
 	cmd {
... ...
@@ -2834,7 +2895,7 @@ cmd:
2834 2895
 			LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
2835 2896
 		} else {
2836 2897
 			str_tmp->s=$3;
2837
-			str_tmp->len=strlen($3);
2898
+			str_tmp->len=$3?strlen($3):0;
2838 2899
 			$$=mk_action(SET_ADV_ADDR_T, 1, STR_ST, str_tmp);
2839 2900
 		}
2840 2901
 	}
... ...
@@ -3194,6 +3255,7 @@ static int warn_ct_rve(struct rval_expr *rve, char* name)
3194 3255
 static struct name_lst* mk_name_lst(char* host, int flags)
3195 3256
 {
3196 3257
 	struct name_lst* l;
3258
+	if (host==0) return 0;
3197 3259
 	l=pkg_malloc(sizeof(struct name_lst));
3198 3260
 	if (l==0) {
3199 3261
 		LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
... ...
@@ -3209,6 +3271,7 @@ static struct name_lst* mk_name_lst(char* host, int flags)
3209 3271
 static struct socket_id* mk_listen_id(char* host, int proto, int port)
3210 3272
 {
3211 3273
 	struct socket_id* l;
3274
+	if (host==0) return 0;
3212 3275
 	l=pkg_malloc(sizeof(struct socket_id));
3213 3276
 	if (l==0) {
3214 3277
 		LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
... ...
@@ -3243,6 +3306,7 @@ static struct socket_id* mk_listen_id2(struct name_lst* addr_l, int proto,
3243 3306
 										int port)
3244 3307
 {
3245 3308
 	struct socket_id* l;
3309
+	if (addr_l==0) return 0;
3246 3310
 	l=pkg_malloc(sizeof(struct socket_id));
3247 3311
 	if (l==0) {
3248 3312
 		LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
... ...
@@ -690,7 +690,7 @@ static int assemble_msg(struct sip_msg* msg, struct tw_info *twi)
690 690
 	}
691 691
 
692 692
 	 /* parse from header */
693
-	if (msg->from->parsed==0 && parse_from_header(msg)==-1 ) {
693
+	if (msg->from==0 || (msg->from->parsed==0 && parse_from_header(msg)==-1)) {
694 694
 		LOG(L_ERR,"assemble_msg: while parsing <From:> header\n");
695 695
 		goto error;
696 696
 	}
... ...
@@ -309,13 +309,15 @@ int parse_headers(struct sip_msg* msg, hdr_flags_t flags, int next)
309 309
 	end=msg->buf+msg->len;
310 310
 	tmp=msg->unparsed;
311 311
 
312
-	if (next) {
312
+	if (unlikely(next)) {
313 313
 		orig_flag = msg->parsed_flag;
314 314
 		msg->parsed_flag &= ~flags;
315 315
 	}else
316 316
 		orig_flag=0;
317 317
 
318
+#ifdef EXTRA_DEBUG
318 319
 	DBG("parse_headers: flags=%llx\n", (unsigned long long)flags);
320
+#endif
319 321
 	while( tmp<end && (flags & msg->parsed_flag) != flags){
320 322
 		prefetch_loc_r(tmp+64, 1);
321 323
 		hf=pkg_malloc(sizeof(struct hdr_field));
... ...
@@ -549,12 +551,15 @@ int parse_headers(struct sip_msg* msg, hdr_flags_t flags, int next)
549 551
 	}
550 552
 skip:
551 553
 	msg->unparsed=tmp;
554
+	/* restore original flags */
555
+	msg->parsed_flag |= orig_flag;
552 556
 	return 0;
553 557
 
554 558
 error:
555 559
 	ser_error=E_BAD_REQ;
556 560
 	if (hf) pkg_free(hf);
557
-	if (next) msg->parsed_flag |= orig_flag;
561
+	/* restore original flags */
562
+	msg->parsed_flag |= orig_flag;
558 563
 	return -1;
559 564
 }
560 565
 
... ...
@@ -939,7 +939,7 @@ static int addr_info_to_si_lst(struct addr_info* ai_lst, unsigned short port,
939 939
 	struct addr_info* ail;
940 940
 	
941 941
 	for (ail=ai_lst; ail; ail=ail->next){
942
-		if(new_sock2list(ail->name.s, 0, port_no, proto, ail->flags | flags,
942
+		if(new_sock2list(ail->name.s, 0, port, proto, ail->flags | flags,
943 943
 							list)==0)
944 944
 			return -1;
945 945
 	}
... ...
@@ -961,7 +961,7 @@ static int addr_info_to_si_lst_after(struct addr_info* ai_lst,
961 961
 	struct socket_info* new_si;
962 962
 	
963 963
 	for (ail=ai_lst; ail; ail=ail->next){
964
-		if((new_si=new_sock2list_after(ail->name.s, 0, port_no, proto,
964
+		if((new_si=new_sock2list_after(ail->name.s, 0, port, proto,
965 965
 								ail->flags | flags, el))==0)
966 966
 			return -1;
967 967
 		el=new_si;
... ...
@@ -1148,7 +1148,9 @@ static int fix_socket_list(struct socket_info **list, int* type_flags)
1148 1148
 					)
1149 1149
 					add_alias(del_si->name.s, del_si->name.len,
1150 1150
 								l->port_no, l->proto);
1151
-						
1151
+				/* make sure next_si doesn't point to del_si */
1152
+				if (del_si==next_si)
1153
+					next_si=next_si->next;
1152 1154
 				/* remove del_si*/
1153 1155
 				sock_listrm(list, del_si);
1154 1156
 				free_sock_info(del_si);