Browse code

- added fifo_dir to the cfg. files (default /tmp, fifo replies dir) - preliminary proto:host:port suport in cfg.{y,lex}: proto:host:port supported (but only the port is used for now) - e.g: tcp:[fec0::1]:5060 or listen= eth0:5062 eth1 127.0.0.1:5060

Andrei Pelinescu-Onciul authored on 14/10/2003 14:49:42
Showing 5 changed files
... ...
@@ -41,6 +41,7 @@
41 41
  *  2003-10-02  added {,set_}advertised_{address,port} (andrei)
42 42
  *  2003-10-07  added hex and octal numbers support (andrei)
43 43
  *  2003-10-10  replaced len_gt w/ msg:len (andrei)
44
+ *  2003-10-13  added fifo_dir (andrei)
44 45
  */
45 46
 
46 47
 
... ...
@@ -163,6 +164,7 @@ SYN_BRANCH syn_branch
163 163
 MEMLOG		"memlog"|"mem_log"
164 164
 SIP_WARNING sip_warning
165 165
 FIFO fifo
166
+FIFO_DIR  fifo_dir
166 167
 FIFO_MODE fifo_mode
167 168
 SERVER_SIGNATURE server_signature
168 169
 REPLY_TO_VIA reply_to_via
... ...
@@ -222,6 +224,8 @@ RBRACE		\}
222 222
 LBRACK		\[
223 223
 RBRACK		\]
224 224
 COMMA		","
225
+COLON		":"
226
+STAR		\*
225 227
 DOT			\.
226 228
 CR			\n
227 229
 
... ...
@@ -330,6 +334,7 @@ EAT_ABLE	[\ \t\b\r]
330 330
 <INITIAL>{TLS_CA_LIST}	{ count(); yylval.strval=yytext; 
331 331
 										return TLS_CA_LIST; }
332 332
 <INITIAL>{FIFO}	{ count(); yylval.strval=yytext; return FIFO; }
333
+<INITIAL>{FIFO_DIR}	{ count(); yylval.strval=yytext; return FIFO_DIR; }
333 334
 <INITIAL>{FIFO_MODE}	{ count(); yylval.strval=yytext; return FIFO_MODE; }
334 335
 <INITIAL>{SERVER_SIGNATURE}	{ count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
335 336
 <INITIAL>{REPLY_TO_VIA}	{ count(); yylval.strval=yytext; return REPLY_TO_VIA; }
... ...
@@ -362,9 +367,9 @@ EAT_ABLE	[\ \t\b\r]
362 362
 							return NUMBER; }
363 363
 <INITIAL>{YES}			{ count(); yylval.intval=1; return NUMBER; }
364 364
 <INITIAL>{NO}			{ count(); yylval.intval=0; return NUMBER; }
365
-<INITIAL>{TCP}			{ count(); yylval.intval=PROTO_TCP; return NUMBER; }
366
-<INITIAL>{UDP}			{ count(); yylval.intval=PROTO_UDP; return NUMBER; }
367
-<INITIAL>{TLS}			{ count(); yylval.intval=PROTO_TLS; return NUMBER; }
365
+<INITIAL>{TCP}			{ count(); return TCP; }
366
+<INITIAL>{UDP}			{ count(); return UDP; }
367
+<INITIAL>{TLS}			{ count(); return TLS; }
368 368
 <INITIAL>{INET}			{ count(); yylval.intval=AF_INET; return NUMBER; }
369 369
 <INITIAL>{INET6}		{ count();
370 370
 						#ifdef USE_IPV6
... ...
@@ -380,6 +385,8 @@ EAT_ABLE	[\ \t\b\r]
380 380
 
381 381
 <INITIAL>{COMMA}		{ count(); return COMMA; }
382 382
 <INITIAL>{SEMICOLON}	{ count(); return SEMICOLON; }
383
+<INITIAL>{COLON}	{ count(); return COLON; }
384
+<INITIAL>{STAR}	{ count(); return STAR; }
383 385
 <INITIAL>{RPAREN}	{ count(); return RPAREN; }
384 386
 <INITIAL>{LPAREN}	{ count(); return LPAREN; }
385 387
 <INITIAL>{LBRACE}	{ count(); return LBRACE; }
... ...
@@ -46,6 +46,7 @@
46 46
  * 2003-10-10  added <,>,<=,>=, != operators support
47 47
  *             added msg:len (andrei)
48 48
  * 2003-10-11  if(){} doesn't require a ';' after it anymore (andrei)
49
+ * 2003-10-13  added FIFO_DIR & proto:host:port listen/alias support (andrei)
49 50
  */
50 51
 
51 52
 
... ...
@@ -84,6 +85,8 @@
84 84
 
85 85
 struct id_list{
86 86
 	char* s;
87
+	int proto;
88
+	int port;
87 89
 	struct id_list* next;
88 90
 };
89 91
 
... ...
@@ -97,6 +100,7 @@ static int rt;  /* Type of route block for find_export */
97 97
 static str* str_tmp;
98 98
 
99 99
 void warn(char* s);
100
+static struct id_list* mk_listen_id(char*, int, int);
100 101
  
101 102
 
102 103
 %}
... ...
@@ -161,6 +165,9 @@ void warn(char* s);
161 161
 %token AF
162 162
 %token MYSELF
163 163
 %token MSGLEN 
164
+%token UDP
165
+%token TCP
166
+%token TLS
164 167
 
165 168
 /* config vars. */
166 169
 %token DEBUG
... ...
@@ -178,6 +185,7 @@ void warn(char* s);
178 178
 %token MEMLOG
179 179
 %token SIP_WARNING
180 180
 %token FIFO
181
+%token FIFO_DIR
181 182
 %token FIFO_MODE
182 183
 %token SERVER_SIGNATURE
183 184
 %token REPLY_TO_VIA
... ...
@@ -242,16 +250,20 @@ void warn(char* s);
242 242
 %token SLASH
243 243
 %token DOT
244 244
 %token CR
245
+%token COLON
246
+%token STAR
245 247
 
246 248
 
247 249
 /*non-terminals */
248 250
 %type <expr> exp exp_elem /*, condition*/
249 251
 %type <action> action actions cmd if_cmd stm
250
-%type <ipaddr> ipv4 ipv6 ip
252
+%type <ipaddr> ipv4 ipv6 ipv6addr ip
251 253
 %type <ipnet> ipnet
252 254
 %type <strval> host
253 255
 %type <strval> listen_id
254 256
 %type <idlst>  id_lst
257
+%type <idlst>  phostport
258
+%type <intval> proto port
255 259
 %type <intval> equalop strop intop
256 260
 /*%type <route_el> rules;
257 261
   %type <route_el> rule;
... ...
@@ -312,23 +324,24 @@ listen_id:	ip			{	tmp=ip_addr2a($1);
312 312
 						}
313 313
 	;
314 314
 
315
-id_lst:	  listen_id	{	$$=pkg_malloc(sizeof(struct id_list));
316
-						if ($$==0){
317
-							LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
318
-						}else{
319
-							$$->s=$1;
320
-							$$->next=0;
321
-						}
322
-					}
323
-		| listen_id id_lst	{
324
-						$$=pkg_malloc(sizeof(struct id_list));
325
-						if ($$==0){
326
-							LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
327
-						}else{
328
-							$$->s=$1;
329
-							$$->next=$2;
330
-						}
331
-							}
315
+proto:	  UDP	{ $$=PROTO_UDP; }
316
+		| TCP	{ $$=PROTO_TCP; }
317
+		| TLS	{ $$=PROTO_TLS; }
318
+		;
319
+
320
+port:	  NUMBER	{ $$=$1; }
321
+		| STAR		{ $$=0; }
322
+;
323
+
324
+phostport:	listen_id				{ $$=mk_listen_id($1, 0, 0); }
325
+			| listen_id COLON port	{ $$=mk_listen_id($1, 0, $3); }
326
+			| proto COLON listen_id	{ $$=mk_listen_id($3, $1, 0); }
327
+			| proto COLON listen_id COLON port	{ $$=mk_listen_id($3, $1, $5);}
328
+			| listen_id COLON error { $$=0; yyerror(" port number expected"); }
329
+			;
330
+
331
+id_lst:		phostport		{  $$=$1 ; }
332
+		| phostport id_lst	{ $$=$1; $$->next=$2; }
332 333
 		;
333 334
 
334 335
 
... ...
@@ -366,6 +379,8 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
366 366
 		| SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
367 367
 		| FIFO EQUAL STRING { fifo=$3; }
368 368
 		| FIFO EQUAL error { yyerror("string value expected"); }
369
+		| FIFO_DIR EQUAL STRING { fifo_dir=$3; }
370
+		| FIFO_DIR EQUAL error { yyerror("string value expected"); }
369 371
 		| FIFO_MODE EQUAL NUMBER { fifo_mode=$3; }
370 372
 		| FIFO_MODE EQUAL error { yyerror("int value expected"); }
371 373
 		| USER EQUAL STRING     { user=$3; }
... ...
@@ -519,7 +534,8 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
519 519
 												strlen(lst_tmp->s)+1);
520 520
 										sock_info[sock_no].name.len=
521 521
 													strlen(lst_tmp->s);
522
-										sock_info[sock_no].port_no=port_no;
522
+										sock_info[sock_no].port_no=
523
+													lst_tmp->port;
523 524
 										sock_no++;
524 525
 									}
525 526
 								}else{
... ...
@@ -534,7 +550,8 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
534 534
 						"expected"); }
535 535
 		| ALIAS EQUAL  id_lst { 
536 536
 							for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next)
537
-								add_alias(lst_tmp->s, strlen(lst_tmp->s), 0);
537
+								add_alias(lst_tmp->s, strlen(lst_tmp->s), 
538
+											lst_tmp->port);
538 539
 							  }
539 540
 		| ALIAS  EQUAL error  { yyerror(" hostname expected"); }
540 541
 		| ADVERTISED_ADDRESS EQUAL listen_id {
... ...
@@ -619,7 +636,7 @@ ipv4:	NUMBER DOT NUMBER DOT NUMBER DOT NUMBER {
619 619
 												}
620 620
 	;
621 621
 
622
-ipv6:	IPV6ADDR {
622
+ipv6addr:	IPV6ADDR {
623 623
 					$$=pkg_malloc(sizeof(struct ip_addr));
624 624
 					if ($$==0){
625 625
 						LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
... ...
@@ -639,6 +656,10 @@ ipv6:	IPV6ADDR {
639 639
 				}
640 640
 	;
641 641
 
642
+ipv6:	ipv6addr { $$=$1; }
643
+	| LBRACK ipv6addr RBRACK {$$=$2; }
644
+;
645
+
642 646
 
643 647
 route_stm:  ROUTE LBRACE actions RBRACE { push($3, &rlist[DEFAULT_RT]); }
644 648
 
... ...
@@ -747,9 +768,11 @@ exp_elem:	METHOD strop STRING	{$$= mk_elem(	$2, STRING_ST,
747 747
 												DSTPORT_O, (void *) $3 ); }
748 748
 		| DSTPORT intop error { $$=0; yyerror("number expected"); }
749 749
 		| DSTPORT error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
750
-		| PROTO intop NUMBER	{ $$=mk_elem(	$2, NUMBER_ST,
750
+		| PROTO intop proto	{ $$=mk_elem(	$2, NUMBER_ST,
751 751
 												PROTO_O, (void *) $3 ); }
752
-		| PROTO intop error { $$=0; yyerror("number expected"); }
752
+		| PROTO intop error { $$=0;
753
+								yyerror("protocol expected (udp, tcp or tls)");
754
+							}
753 755
 		| PROTO error { $$=0; yyerror("equal/!= operator expected"); }
754 756
 		| AF intop NUMBER	{ $$=mk_elem(	$2, NUMBER_ST,
755 757
 												AF_O, (void *) $3 ); }
... ...
@@ -1478,6 +1501,23 @@ void yyerror(char* s)
1478 1478
 	cfg_errors++;
1479 1479
 }
1480 1480
 
1481
+
1482
+static struct id_list* mk_listen_id(char* host, int proto, int port)
1483
+{
1484
+	struct id_list* l;
1485
+	l=pkg_malloc(sizeof(struct id_list));
1486
+	if (l==0){
1487
+		LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
1488
+	}else{
1489
+		l->s=host;
1490
+		l->port=port;
1491
+		l->proto=proto;
1492
+		l->next=0;
1493
+	}
1494
+	return l;
1495
+}
1496
+
1497
+
1481 1498
 /*
1482 1499
 int main(int argc, char ** argv)
1483 1500
 {
... ...
@@ -151,8 +151,7 @@
151 151
 /* buffer dimensions for FIFO server */
152 152
 #define MAX_CONSUME_BUFFER 1024
153 153
 /* where reply pipes may be opened */
154
-#define FIFO_DIR "/tmp/"
155
-#define FIFO_DIR_LEN 5
154
+#define DEFAULT_FIFO_DIR "/tmp/"
156 155
 /* max length of the text of fifo 'print' command */
157 156
 #define MAX_PRINT_TEXT 256
158 157
 
... ...
@@ -58,6 +58,7 @@
58 58
  *  2003-01-29  new built-in fifo commands: arg and pwd (jiri)
59 59
  *  2003-10-07  fifo security fixes: permissions, always delete old fifo,
60 60
  *               reply fifo checks -- added fifo_check (andrei)
61
+ *  2003-10-13  addef fifo_dir for reply fifos (andrei)
61 62
  */
62 63
 
63 64
 
... ...
@@ -89,6 +90,7 @@
89 89
 
90 90
 /* FIFO server vars */
91 91
 char *fifo=0; /* FIFO name */
92
+char* fifo_dir=DEFAULT_FIFO_DIR; /* dir where reply fifos are allowed */
92 93
 int fifo_mode=S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP ;
93 94
 pid_t fifo_pid;
94 95
 /* file descriptors */
... ...
@@ -286,14 +288,14 @@ static char *trim_filename( char * file )
286 286
 			, file);
287 287
 		return 0;
288 288
 	}
289
-	prefix_len=strlen(FIFO_DIR); fn_len=strlen(file);
289
+	prefix_len=strlen(fifo_dir); fn_len=strlen(file);
290 290
 	new_fn=pkg_malloc(prefix_len+fn_len+1);
291 291
 	if (new_fn==0) {
292 292
 		LOG(L_ERR, "ERROR: trim_filename: no mem\n");
293 293
 		return 0;
294 294
 	}
295 295
 
296
-	memcpy(new_fn, FIFO_DIR, prefix_len);
296
+	memcpy(new_fn, fifo_dir, prefix_len);
297 297
 	memcpy(new_fn+prefix_len, file, fn_len );
298 298
 	new_fn[prefix_len+fn_len]=0;
299 299
 
... ...
@@ -110,6 +110,7 @@ extern unsigned int shm_mem_size;
110 110
 /* FIFO server config */
111 111
 char extern *fifo; /* FIFO name */
112 112
 extern int fifo_mode;
113
+char extern *fifo_dir; /* dir. where  reply fifos are allowed */
113 114
 
114 115
 /* moved to pt.h
115 116
 extern int *pids;