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 164
 MEMLOG		"memlog"|"mem_log"
164 165
 SIP_WARNING sip_warning
165 166
 FIFO fifo
167
+FIFO_DIR  fifo_dir
166 168
 FIFO_MODE fifo_mode
167 169
 SERVER_SIGNATURE server_signature
168 170
 REPLY_TO_VIA reply_to_via
... ...
@@ -222,6 +224,8 @@ RBRACE		\}
222 224
 LBRACK		\[
223 225
 RBRACK		\]
224 226
 COMMA		","
227
+COLON		":"
228
+STAR		\*
225 229
 DOT			\.
226 230
 CR			\n
227 231
 
... ...
@@ -330,6 +334,7 @@ EAT_ABLE	[\ \t\b\r]
330 334
 <INITIAL>{TLS_CA_LIST}	{ count(); yylval.strval=yytext; 
331 335
 										return TLS_CA_LIST; }
332 336
 <INITIAL>{FIFO}	{ count(); yylval.strval=yytext; return FIFO; }
337
+<INITIAL>{FIFO_DIR}	{ count(); yylval.strval=yytext; return FIFO_DIR; }
333 338
 <INITIAL>{FIFO_MODE}	{ count(); yylval.strval=yytext; return FIFO_MODE; }
334 339
 <INITIAL>{SERVER_SIGNATURE}	{ count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
335 340
 <INITIAL>{REPLY_TO_VIA}	{ count(); yylval.strval=yytext; return REPLY_TO_VIA; }
... ...
@@ -362,9 +367,9 @@ EAT_ABLE	[\ \t\b\r]
362 367
 							return NUMBER; }
363 368
 <INITIAL>{YES}			{ count(); yylval.intval=1; return NUMBER; }
364 369
 <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; }
370
+<INITIAL>{TCP}			{ count(); return TCP; }
371
+<INITIAL>{UDP}			{ count(); return UDP; }
372
+<INITIAL>{TLS}			{ count(); return TLS; }
368 373
 <INITIAL>{INET}			{ count(); yylval.intval=AF_INET; return NUMBER; }
369 374
 <INITIAL>{INET6}		{ count();
370 375
 						#ifdef USE_IPV6
... ...
@@ -380,6 +385,8 @@ EAT_ABLE	[\ \t\b\r]
380 385
 
381 386
 <INITIAL>{COMMA}		{ count(); return COMMA; }
382 387
 <INITIAL>{SEMICOLON}	{ count(); return SEMICOLON; }
388
+<INITIAL>{COLON}	{ count(); return COLON; }
389
+<INITIAL>{STAR}	{ count(); return STAR; }
383 390
 <INITIAL>{RPAREN}	{ count(); return RPAREN; }
384 391
 <INITIAL>{LPAREN}	{ count(); return LPAREN; }
385 392
 <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 85
 
85 86
 struct id_list{
86 87
 	char* s;
88
+	int proto;
89
+	int port;
87 90
 	struct id_list* next;
88 91
 };
89 92
 
... ...
@@ -97,6 +100,7 @@ static int rt;  /* Type of route block for find_export */
97 100
 static str* str_tmp;
98 101
 
99 102
 void warn(char* s);
103
+static struct id_list* mk_listen_id(char*, int, int);
100 104
  
101 105
 
102 106
 %}
... ...
@@ -161,6 +165,9 @@ void warn(char* s);
161 165
 %token AF
162 166
 %token MYSELF
163 167
 %token MSGLEN 
168
+%token UDP
169
+%token TCP
170
+%token TLS
164 171
 
165 172
 /* config vars. */
166 173
 %token DEBUG
... ...
@@ -178,6 +185,7 @@ void warn(char* s);
178 185
 %token MEMLOG
179 186
 %token SIP_WARNING
180 187
 %token FIFO
188
+%token FIFO_DIR
181 189
 %token FIFO_MODE
182 190
 %token SERVER_SIGNATURE
183 191
 %token REPLY_TO_VIA
... ...
@@ -242,16 +250,20 @@ void warn(char* s);
242 250
 %token SLASH
243 251
 %token DOT
244 252
 %token CR
253
+%token COLON
254
+%token STAR
245 255
 
246 256
 
247 257
 /*non-terminals */
248 258
 %type <expr> exp exp_elem /*, condition*/
249 259
 %type <action> action actions cmd if_cmd stm
250
-%type <ipaddr> ipv4 ipv6 ip
260
+%type <ipaddr> ipv4 ipv6 ipv6addr ip
251 261
 %type <ipnet> ipnet
252 262
 %type <strval> host
253 263
 %type <strval> listen_id
254 264
 %type <idlst>  id_lst
265
+%type <idlst>  phostport
266
+%type <intval> proto port
255 267
 %type <intval> equalop strop intop
256 268
 /*%type <route_el> rules;
257 269
   %type <route_el> rule;
... ...
@@ -312,23 +324,24 @@ listen_id:	ip			{	tmp=ip_addr2a($1);
312 324
 						}
313 325
 	;
314 326
 
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
-							}
327
+proto:	  UDP	{ $$=PROTO_UDP; }
328
+		| TCP	{ $$=PROTO_TCP; }
329
+		| TLS	{ $$=PROTO_TLS; }
330
+		;
331
+
332
+port:	  NUMBER	{ $$=$1; }
333
+		| STAR		{ $$=0; }
334
+;
335
+
336
+phostport:	listen_id				{ $$=mk_listen_id($1, 0, 0); }
337
+			| listen_id COLON port	{ $$=mk_listen_id($1, 0, $3); }
338
+			| proto COLON listen_id	{ $$=mk_listen_id($3, $1, 0); }
339
+			| proto COLON listen_id COLON port	{ $$=mk_listen_id($3, $1, $5);}
340
+			| listen_id COLON error { $$=0; yyerror(" port number expected"); }
341
+			;
342
+
343
+id_lst:		phostport		{  $$=$1 ; }
344
+		| phostport id_lst	{ $$=$1; $$->next=$2; }
332 345
 		;
333 346
 
334 347
 
... ...
@@ -366,6 +379,8 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
366 379
 		| SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
367 380
 		| FIFO EQUAL STRING { fifo=$3; }
368 381
 		| FIFO EQUAL error { yyerror("string value expected"); }
382
+		| FIFO_DIR EQUAL STRING { fifo_dir=$3; }
383
+		| FIFO_DIR EQUAL error { yyerror("string value expected"); }
369 384
 		| FIFO_MODE EQUAL NUMBER { fifo_mode=$3; }
370 385
 		| FIFO_MODE EQUAL error { yyerror("int value expected"); }
371 386
 		| USER EQUAL STRING     { user=$3; }
... ...
@@ -519,7 +534,8 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
519 534
 												strlen(lst_tmp->s)+1);
520 535
 										sock_info[sock_no].name.len=
521 536
 													strlen(lst_tmp->s);
522
-										sock_info[sock_no].port_no=port_no;
537
+										sock_info[sock_no].port_no=
538
+													lst_tmp->port;
523 539
 										sock_no++;
524 540
 									}
525 541
 								}else{
... ...
@@ -534,7 +550,8 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
534 550
 						"expected"); }
535 551
 		| ALIAS EQUAL  id_lst { 
536 552
 							for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next)
537
-								add_alias(lst_tmp->s, strlen(lst_tmp->s), 0);
553
+								add_alias(lst_tmp->s, strlen(lst_tmp->s), 
554
+											lst_tmp->port);
538 555
 							  }
539 556
 		| ALIAS  EQUAL error  { yyerror(" hostname expected"); }
540 557
 		| ADVERTISED_ADDRESS EQUAL listen_id {
... ...
@@ -619,7 +636,7 @@ ipv4:	NUMBER DOT NUMBER DOT NUMBER DOT NUMBER {
619 636
 												}
620 637
 	;
621 638
 
622
-ipv6:	IPV6ADDR {
639
+ipv6addr:	IPV6ADDR {
623 640
 					$$=pkg_malloc(sizeof(struct ip_addr));
624 641
 					if ($$==0){
625 642
 						LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
... ...
@@ -639,6 +656,10 @@ ipv6:	IPV6ADDR {
639 656
 				}
640 657
 	;
641 658
 
659
+ipv6:	ipv6addr { $$=$1; }
660
+	| LBRACK ipv6addr RBRACK {$$=$2; }
661
+;
662
+
642 663
 
643 664
 route_stm:  ROUTE LBRACE actions RBRACE { push($3, &rlist[DEFAULT_RT]); }
644 665
 
... ...
@@ -747,9 +768,11 @@ exp_elem:	METHOD strop STRING	{$$= mk_elem(	$2, STRING_ST,
747 768
 												DSTPORT_O, (void *) $3 ); }
748 769
 		| DSTPORT intop error { $$=0; yyerror("number expected"); }
749 770
 		| DSTPORT error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
750
-		| PROTO intop NUMBER	{ $$=mk_elem(	$2, NUMBER_ST,
771
+		| PROTO intop proto	{ $$=mk_elem(	$2, NUMBER_ST,
751 772
 												PROTO_O, (void *) $3 ); }
752
-		| PROTO intop error { $$=0; yyerror("number expected"); }
773
+		| PROTO intop error { $$=0;
774
+								yyerror("protocol expected (udp, tcp or tls)");
775
+							}
753 776
 		| PROTO error { $$=0; yyerror("equal/!= operator expected"); }
754 777
 		| AF intop NUMBER	{ $$=mk_elem(	$2, NUMBER_ST,
755 778
 												AF_O, (void *) $3 ); }
... ...
@@ -1478,6 +1501,23 @@ void yyerror(char* s)
1478 1501
 	cfg_errors++;
1479 1502
 }
1480 1503
 
1504
+
1505
+static struct id_list* mk_listen_id(char* host, int proto, int port)
1506
+{
1507
+	struct id_list* l;
1508
+	l=pkg_malloc(sizeof(struct id_list));
1509
+	if (l==0){
1510
+		LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
1511
+	}else{
1512
+		l->s=host;
1513
+		l->port=port;
1514
+		l->proto=proto;
1515
+		l->next=0;
1516
+	}
1517
+	return l;
1518
+}
1519
+
1520
+
1481 1521
 /*
1482 1522
 int main(int argc, char ** argv)
1483 1523
 {
... ...
@@ -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 90
 
90 91
 /* FIFO server vars */
91 92
 char *fifo=0; /* FIFO name */
93
+char* fifo_dir=DEFAULT_FIFO_DIR; /* dir where reply fifos are allowed */
92 94
 int fifo_mode=S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP ;
93 95
 pid_t fifo_pid;
94 96
 /* file descriptors */
... ...
@@ -286,14 +288,14 @@ static char *trim_filename( char * file )
286 288
 			, file);
287 289
 		return 0;
288 290
 	}
289
-	prefix_len=strlen(FIFO_DIR); fn_len=strlen(file);
291
+	prefix_len=strlen(fifo_dir); fn_len=strlen(file);
290 292
 	new_fn=pkg_malloc(prefix_len+fn_len+1);
291 293
 	if (new_fn==0) {
292 294
 		LOG(L_ERR, "ERROR: trim_filename: no mem\n");
293 295
 		return 0;
294 296
 	}
295 297
 
296
-	memcpy(new_fn, FIFO_DIR, prefix_len);
298
+	memcpy(new_fn, fifo_dir, prefix_len);
297 299
 	memcpy(new_fn+prefix_len, file, fn_len );
298 300
 	new_fn[prefix_len+fn_len]=0;
299 301
 
... ...
@@ -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;