Quellcode durchsuchen

- 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 vor 22 Jahren
Ursprung
Commit
e5f4cdaf27
5 geänderte Dateien mit 79 neuen und 30 gelöschten Zeilen
  1. 10 3
      cfg.lex
  2. 63 23
      cfg.y
  3. 1 2
      config.h
  4. 4 2
      fifo_server.c
  5. 1 0
      globals.h

+ 10 - 3
cfg.lex

@@ -41,6 +41,7 @@
  *  2003-10-02  added {,set_}advertised_{address,port} (andrei)
  *  2003-10-07  added hex and octal numbers support (andrei)
  *  2003-10-10  replaced len_gt w/ msg:len (andrei)
+ *  2003-10-13  added fifo_dir (andrei)
  */
 
 
@@ -163,6 +164,7 @@ SYN_BRANCH syn_branch
 MEMLOG		"memlog"|"mem_log"
 SIP_WARNING sip_warning
 FIFO fifo
+FIFO_DIR  fifo_dir
 FIFO_MODE fifo_mode
 SERVER_SIGNATURE server_signature
 REPLY_TO_VIA reply_to_via
@@ -222,6 +224,8 @@ RBRACE		\}
 LBRACK		\[
 RBRACK		\]
 COMMA		","
+COLON		":"
+STAR		\*
 DOT			\.
 CR			\n
 
@@ -330,6 +334,7 @@ EAT_ABLE	[\ \t\b\r]
 <INITIAL>{TLS_CA_LIST}	{ count(); yylval.strval=yytext; 
 										return TLS_CA_LIST; }
 <INITIAL>{FIFO}	{ count(); yylval.strval=yytext; return FIFO; }
+<INITIAL>{FIFO_DIR}	{ count(); yylval.strval=yytext; return FIFO_DIR; }
 <INITIAL>{FIFO_MODE}	{ count(); yylval.strval=yytext; return FIFO_MODE; }
 <INITIAL>{SERVER_SIGNATURE}	{ count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
 <INITIAL>{REPLY_TO_VIA}	{ count(); yylval.strval=yytext; return REPLY_TO_VIA; }
@@ -362,9 +367,9 @@ EAT_ABLE	[\ \t\b\r]
 							return NUMBER; }
 <INITIAL>{YES}			{ count(); yylval.intval=1; return NUMBER; }
 <INITIAL>{NO}			{ count(); yylval.intval=0; return NUMBER; }
-<INITIAL>{TCP}			{ count(); yylval.intval=PROTO_TCP; return NUMBER; }
-<INITIAL>{UDP}			{ count(); yylval.intval=PROTO_UDP; return NUMBER; }
-<INITIAL>{TLS}			{ count(); yylval.intval=PROTO_TLS; return NUMBER; }
+<INITIAL>{TCP}			{ count(); return TCP; }
+<INITIAL>{UDP}			{ count(); return UDP; }
+<INITIAL>{TLS}			{ count(); return TLS; }
 <INITIAL>{INET}			{ count(); yylval.intval=AF_INET; return NUMBER; }
 <INITIAL>{INET6}		{ count();
 						#ifdef USE_IPV6
@@ -380,6 +385,8 @@ EAT_ABLE	[\ \t\b\r]
 
 <INITIAL>{COMMA}		{ count(); return COMMA; }
 <INITIAL>{SEMICOLON}	{ count(); return SEMICOLON; }
+<INITIAL>{COLON}	{ count(); return COLON; }
+<INITIAL>{STAR}	{ count(); return STAR; }
 <INITIAL>{RPAREN}	{ count(); return RPAREN; }
 <INITIAL>{LPAREN}	{ count(); return LPAREN; }
 <INITIAL>{LBRACE}	{ count(); return LBRACE; }

+ 63 - 23
cfg.y

@@ -46,6 +46,7 @@
  * 2003-10-10  added <,>,<=,>=, != operators support
  *             added msg:len (andrei)
  * 2003-10-11  if(){} doesn't require a ';' after it anymore (andrei)
+ * 2003-10-13  added FIFO_DIR & proto:host:port listen/alias support (andrei)
  */
 
 
@@ -84,6 +85,8 @@
 
 struct id_list{
 	char* s;
+	int proto;
+	int port;
 	struct id_list* next;
 };
 
@@ -97,6 +100,7 @@ static int rt;  /* Type of route block for find_export */
 static str* str_tmp;
 
 void warn(char* s);
+static struct id_list* mk_listen_id(char*, int, int);
  
 
 %}
@@ -161,6 +165,9 @@ void warn(char* s);
 %token AF
 %token MYSELF
 %token MSGLEN 
+%token UDP
+%token TCP
+%token TLS
 
 /* config vars. */
 %token DEBUG
@@ -178,6 +185,7 @@ void warn(char* s);
 %token MEMLOG
 %token SIP_WARNING
 %token FIFO
+%token FIFO_DIR
 %token FIFO_MODE
 %token SERVER_SIGNATURE
 %token REPLY_TO_VIA
@@ -242,16 +250,20 @@ void warn(char* s);
 %token SLASH
 %token DOT
 %token CR
+%token COLON
+%token STAR
 
 
 /*non-terminals */
 %type <expr> exp exp_elem /*, condition*/
 %type <action> action actions cmd if_cmd stm
-%type <ipaddr> ipv4 ipv6 ip
+%type <ipaddr> ipv4 ipv6 ipv6addr ip
 %type <ipnet> ipnet
 %type <strval> host
 %type <strval> listen_id
 %type <idlst>  id_lst
+%type <idlst>  phostport
+%type <intval> proto port
 %type <intval> equalop strop intop
 /*%type <route_el> rules;
   %type <route_el> rule;
@@ -312,23 +324,24 @@ listen_id:	ip			{	tmp=ip_addr2a($1);
 						}
 	;
 
-id_lst:	  listen_id	{	$$=pkg_malloc(sizeof(struct id_list));
-						if ($$==0){
-							LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
-						}else{
-							$$->s=$1;
-							$$->next=0;
-						}
-					}
-		| listen_id id_lst	{
-						$$=pkg_malloc(sizeof(struct id_list));
-						if ($$==0){
-							LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
-						}else{
-							$$->s=$1;
-							$$->next=$2;
-						}
-							}
+proto:	  UDP	{ $$=PROTO_UDP; }
+		| TCP	{ $$=PROTO_TCP; }
+		| TLS	{ $$=PROTO_TLS; }
+		;
+
+port:	  NUMBER	{ $$=$1; }
+		| STAR		{ $$=0; }
+;
+
+phostport:	listen_id				{ $$=mk_listen_id($1, 0, 0); }
+			| listen_id COLON port	{ $$=mk_listen_id($1, 0, $3); }
+			| proto COLON listen_id	{ $$=mk_listen_id($3, $1, 0); }
+			| proto COLON listen_id COLON port	{ $$=mk_listen_id($3, $1, $5);}
+			| listen_id COLON error { $$=0; yyerror(" port number expected"); }
+			;
+
+id_lst:		phostport		{  $$=$1 ; }
+		| phostport id_lst	{ $$=$1; $$->next=$2; }
 		;
 
 
@@ -366,6 +379,8 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
 		| SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
 		| FIFO EQUAL STRING { fifo=$3; }
 		| FIFO EQUAL error { yyerror("string value expected"); }
+		| FIFO_DIR EQUAL STRING { fifo_dir=$3; }
+		| FIFO_DIR EQUAL error { yyerror("string value expected"); }
 		| FIFO_MODE EQUAL NUMBER { fifo_mode=$3; }
 		| FIFO_MODE EQUAL error { yyerror("int value expected"); }
 		| USER EQUAL STRING     { user=$3; }
@@ -519,7 +534,8 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
 												strlen(lst_tmp->s)+1);
 										sock_info[sock_no].name.len=
 													strlen(lst_tmp->s);
-										sock_info[sock_no].port_no=port_no;
+										sock_info[sock_no].port_no=
+													lst_tmp->port;
 										sock_no++;
 									}
 								}else{
@@ -534,7 +550,8 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
 						"expected"); }
 		| ALIAS EQUAL  id_lst { 
 							for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next)
-								add_alias(lst_tmp->s, strlen(lst_tmp->s), 0);
+								add_alias(lst_tmp->s, strlen(lst_tmp->s), 
+											lst_tmp->port);
 							  }
 		| ALIAS  EQUAL error  { yyerror(" hostname expected"); }
 		| ADVERTISED_ADDRESS EQUAL listen_id {
@@ -619,7 +636,7 @@ ipv4:	NUMBER DOT NUMBER DOT NUMBER DOT NUMBER {
 												}
 	;
 
-ipv6:	IPV6ADDR {
+ipv6addr:	IPV6ADDR {
 					$$=pkg_malloc(sizeof(struct ip_addr));
 					if ($$==0){
 						LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
@@ -639,6 +656,10 @@ ipv6:	IPV6ADDR {
 				}
 	;
 
+ipv6:	ipv6addr { $$=$1; }
+	| LBRACK ipv6addr RBRACK {$$=$2; }
+;
+
 
 route_stm:  ROUTE LBRACE actions RBRACE { push($3, &rlist[DEFAULT_RT]); }
 
@@ -747,9 +768,11 @@ exp_elem:	METHOD strop STRING	{$$= mk_elem(	$2, STRING_ST,
 												DSTPORT_O, (void *) $3 ); }
 		| DSTPORT intop error { $$=0; yyerror("number expected"); }
 		| DSTPORT error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
-		| PROTO intop NUMBER	{ $$=mk_elem(	$2, NUMBER_ST,
+		| PROTO intop proto	{ $$=mk_elem(	$2, NUMBER_ST,
 												PROTO_O, (void *) $3 ); }
-		| PROTO intop error { $$=0; yyerror("number expected"); }
+		| PROTO intop error { $$=0;
+								yyerror("protocol expected (udp, tcp or tls)");
+							}
 		| PROTO error { $$=0; yyerror("equal/!= operator expected"); }
 		| AF intop NUMBER	{ $$=mk_elem(	$2, NUMBER_ST,
 												AF_O, (void *) $3 ); }
@@ -1478,6 +1501,23 @@ void yyerror(char* s)
 	cfg_errors++;
 }
 
+
+static struct id_list* mk_listen_id(char* host, int proto, int port)
+{
+	struct id_list* l;
+	l=pkg_malloc(sizeof(struct id_list));
+	if (l==0){
+		LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
+	}else{
+		l->s=host;
+		l->port=port;
+		l->proto=proto;
+		l->next=0;
+	}
+	return l;
+}
+
+
 /*
 int main(int argc, char ** argv)
 {

+ 1 - 2
config.h

@@ -151,8 +151,7 @@
 /* buffer dimensions for FIFO server */
 #define MAX_CONSUME_BUFFER 1024
 /* where reply pipes may be opened */
-#define FIFO_DIR "/tmp/"
-#define FIFO_DIR_LEN 5
+#define DEFAULT_FIFO_DIR "/tmp/"
 /* max length of the text of fifo 'print' command */
 #define MAX_PRINT_TEXT 256
 

+ 4 - 2
fifo_server.c

@@ -58,6 +58,7 @@
  *  2003-01-29  new built-in fifo commands: arg and pwd (jiri)
  *  2003-10-07  fifo security fixes: permissions, always delete old fifo,
  *               reply fifo checks -- added fifo_check (andrei)
+ *  2003-10-13  addef fifo_dir for reply fifos (andrei)
  */
 
 
@@ -89,6 +90,7 @@
 
 /* FIFO server vars */
 char *fifo=0; /* FIFO name */
+char* fifo_dir=DEFAULT_FIFO_DIR; /* dir where reply fifos are allowed */
 int fifo_mode=S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP ;
 pid_t fifo_pid;
 /* file descriptors */
@@ -286,14 +288,14 @@ static char *trim_filename( char * file )
 			, file);
 		return 0;
 	}
-	prefix_len=strlen(FIFO_DIR); fn_len=strlen(file);
+	prefix_len=strlen(fifo_dir); fn_len=strlen(file);
 	new_fn=pkg_malloc(prefix_len+fn_len+1);
 	if (new_fn==0) {
 		LOG(L_ERR, "ERROR: trim_filename: no mem\n");
 		return 0;
 	}
 
-	memcpy(new_fn, FIFO_DIR, prefix_len);
+	memcpy(new_fn, fifo_dir, prefix_len);
 	memcpy(new_fn+prefix_len, file, fn_len );
 	new_fn[prefix_len+fn_len]=0;
 

+ 1 - 0
globals.h

@@ -110,6 +110,7 @@ extern unsigned int shm_mem_size;
 /* FIFO server config */
 char extern *fifo; /* FIFO name */
 extern int fifo_mode;
+char extern *fifo_dir; /* dir. where  reply fifos are allowed */
 
 /* moved to pt.h
 extern int *pids;