Merge commit 'origin/ser_core_cvs'
authorAndrei Pelinescu-Onciul <andrei@iptel.org>
Fri, 17 Jul 2009 16:09:01 +0000 (18:09 +0200)
committerAndrei Pelinescu-Onciul <andrei@iptel.org>
Fri, 17 Jul 2009 16:09:01 +0000 (18:09 +0200)
* 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

1  2 
cfg.lex
cfg.y
modules/tm/t_fifo.c
parser/msg_parser.c
socket_info.c

diff --cc cfg.lex
+++ b/cfg.lex
        int line=1;
        int column=1;
        int startcolumn=1;
 +      int startline=1;
 +      static int ign_lines=0;
 +      static int ign_columns=0;
+       char* yy_number_str=0; /* str correspondent for the current NUMBER token */
  
        static char* addchar(struct str_buf *, char);
        static char* addstr(struct str_buf *, char*, int);
@@@ -846,14 -786,17 +848,18 @@@ EAT_ABLE        [\ \t\b\r
  <SELECT>{DOT}           { count(); return DOT; }
  <SELECT>{LBRACK}        { count(); return LBRACK; }
  <SELECT>{RBRACK}        { count(); return RBRACK; }
- <SELECT>{DECNUMBER}   { count(); yylval.intval=atoi(yytext);return NUMBER; }
- <SELECT>{HEXNUMBER}   { count(); yylval.intval=(int)strtol(yytext, 0, 16); return NUMBER; }
- <SELECT>{OCTNUMBER}   { count(); yylval.intval=(int)strtol(yytext, 0, 8); return NUMBER; }
- <SELECT>{BINNUMBER}     { count(); yylval.intval=(int)strtol(yytext, 0, 2); return NUMBER; }
+ <SELECT>{DECNUMBER}   { count(); yylval.intval=atoi(yytext);
+                                               yy_number_str=yytext; return NUMBER; }
+ <SELECT>{HEXNUMBER}   { count(); yylval.intval=(int)strtol(yytext, 0, 16);
+                                               yy_number_str=yytext; return NUMBER; }
+ <SELECT>{OCTNUMBER}   { count(); yylval.intval=(int)strtol(yytext, 0, 8);
+                                               yy_number_str=yytext; return NUMBER; }
+ <SELECT>{BINNUMBER}   { count(); yylval.intval=(int)strtol(yytext, 0, 2);
+                                               yy_number_str=yytext; return NUMBER; }
  
  
 -<INITIAL>{ATTR_MARK}    { count(); state = ATTR_S; BEGIN(ATTR); return ATTR_MARK; }
 +<INITIAL>{ATTR_MARK}    { count(); state = ATTR_S; BEGIN(ATTR);
 +                                                      return ATTR_MARK; }
  <ATTR>{ATTR_FROM}       { count(); return ATTR_FROM; }
  <ATTR>{ATTR_TO}         { count(); return ATTR_TO; }
  <ATTR>{ATTR_FROMURI}    { count(); return ATTR_FROMURI; }
  <ATTR>{DOT}             { count(); return DOT; }
  <ATTR>{LBRACK}          { count(); return LBRACK; }
  <ATTR>{RBRACK}          { count(); return RBRACK; }
 -<ATTR>{STAR}          { count(); return STAR; }
 -<ATTR>{DECNUMBER}     { count(); yylval.intval=atoi(yytext);
 -                                              yy_number_str=yytext; return NUMBER; }
 -<ATTR>{ID}            { count(); addstr(&s_buf, yytext, yyleng);
 -                           yylval.strval=s_buf.s;
 -                         memset(&s_buf, 0, sizeof(s_buf));
 -                           state = INITIAL_S;
 -                           BEGIN(INITIAL);
 -                         return ID;
 -                        }
 +<ATTR>{STAR}                  { count(); return STAR; }
- <ATTR>{DECNUMBER}             { count(); yylval.intval=atoi(yytext);return NUMBER; }
++<ATTR>{DECNUMBER}             { count(); yylval.intval=atoi(yytext);
++                                                      yy_number_str=yytext; return NUMBER; }
 +<ATTR>{ID}                            { count(); addstr(&s_buf, yytext, yyleng);
 +                                                      yylval.strval=s_buf.s;
 +                                                      memset(&s_buf, 0, sizeof(s_buf));
 +                                                      state = INITIAL_S;
 +                                                      BEGIN(INITIAL);
 +                                                      return ID;
 +                                              }
 +
 +<INITIAL>{VAR_MARK}{LPAREN}   {
 +                                                              switch(sr_cfg_compat){
 +                                                                      case SR_COMPAT_SER:
 +                                                                              state=ATTR_S; BEGIN(ATTR);
 +                                                                              yyless(1);
 +                                                                              count();
 +                                                                              return ATTR_MARK;
 +                                                                              break;
 +                                                                      case SR_COMPAT_KAMAILIO:
 +                                                                      case SR_COMPAT_MAX:
 +                                                                      default:
 +                                                                              state = PVAR_P_S; BEGIN(PVAR_P);
 +                                                                              p_nest=1; yymore();
 +                                                                              break;
 +                                                              }
 +                                                      }
 +      /* eat everything between 2 () and return PVAR token and a string
 +         containing everything (including $ and ()) */
 +<PVAR_P>{RPAREN}                      {       p_nest--;
 +                                                              if (p_nest==0){
 +                                                                      count();
 +                                                                      addstr(&s_buf, yytext, yyleng);
 +                                                                      yylval.strval=s_buf.s;
 +                                                                      memset(&s_buf, 0, sizeof(s_buf));
 +                                                                      state=INITIAL_S;
 +                                                                      BEGIN(INITIAL);
 +                                                                      return PVAR;
 +                                                              }
 +                                                              yymore();
 +                                                      }
 +<PVAR_P>{LPAREN}                      { p_nest++; yymore(); }
 +<PVAR_P>.                                     { yymore(); }
 +
 +<PVARID>{ID}|'.'                      {yymore(); }
 +<PVARID>{LPAREN}                      {       state = PVAR_P_S; BEGIN(PVAR_P);
 +                                                              p_nest=1; yymore(); }
 +<PVARID>.                                     { yyless(0); state=INITIAL_S; BEGIN(INITIAL);
 +                                                              return PVAR;
 +                                                      }
 +
 +
 +<INITIAL>{VAR_MARK}                   {
 +                                                              switch(sr_cfg_compat){
 +                                                                      case SR_COMPAT_SER:
 +                                                                              count();
 +                                                                              state=ATTR_S; BEGIN(ATTR);
 +                                                                              return ATTR_MARK;
 +                                                                              break;
 +                                                                      case SR_COMPAT_KAMAILIO:
 +                                                                              state=PVARID_S; BEGIN(PVARID);
 +                                                                              yymore();
 +                                                                              break;
 +                                                                      case SR_COMPAT_MAX:
 +                                                                      default: 
 +                                                                              state=AVP_PVAR_S; BEGIN(AVP_PVAR);
 +                                                                              yymore();
 +                                                                              break;
 +                                                              }
 +                                                      }
 +      /* avp prefix detected -> go to avp mode */
 +<AVP_PVAR>{AVP_PREF}          |
 +<AVP_PVAR>{ID}{LBRACK}                { state = ATTR_S; BEGIN(ATTR); yyless(1); count();
 +                                                        return ATTR_MARK; }
 +<AVP_PVAR>{ID}{LPAREN}                { state = PVAR_P_S; p_nest=1; BEGIN(PVAR_P);
 +                                                              yymore(); }
 +<AVP_PVAR>{ID}                                {       count(); addstr(&s_buf, yytext, yyleng);
 +                                                              yylval.strval=s_buf.s;
 +                                                              memset(&s_buf, 0, sizeof(s_buf));
 +                                                              state = INITIAL_S;
 +                                                              BEGIN(INITIAL);
 +                                                              return AVP_OR_PVAR;
 +                                                      }
  
  <INITIAL>{IPV6ADDR}           { count(); yylval.strval=yytext; return IPV6ADDR; }
- <INITIAL>{DECNUMBER}          { count(); yylval.intval=atoi(yytext);return NUMBER; }
+ <INITIAL>{DECNUMBER}  { count(); yylval.intval=atoi(yytext);
+                                                               yy_number_str=yytext; return NUMBER; }
  <INITIAL>{HEXNUMBER}  { count(); yylval.intval=(int)strtol(yytext, 0, 16);
-                                                       return NUMBER; }
+                                                       yy_number_str=yytext; return NUMBER; }
  <INITIAL>{OCTNUMBER}  { count(); yylval.intval=(int)strtol(yytext, 0, 8);
--                                                      return NUMBER; }
- <INITIAL>{BINNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 2); return NUMBER; }
- <INITIAL>{YES}                        { count(); yylval.intval=1; return NUMBER; }
- <INITIAL>{NO}                 { count(); yylval.intval=0; return NUMBER; }
++                                                      yy_number_str=yytext; return NUMBER; }
+ <INITIAL>{BINNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 2);
+                                                       yy_number_str=yytext; return NUMBER; }
+ <INITIAL>{YES}                        { count(); yylval.intval=1;
+                                                       yy_number_str=yytext; return NUMBER; }
+ <INITIAL>{NO}                 { count(); yylval.intval=0;
+                                                       yy_number_str=yytext; return NUMBER; }
  <INITIAL>{TCP}                        { count(); return TCP; }
  <INITIAL>{UDP}                        { count(); return UDP; }
  <INITIAL>{TLS}                        { count(); return TLS; }
diff --cc cfg.y
--- 1/cfg.y
--- 2/cfg.y
+++ b/cfg.y
  
  
  extern int yylex();
 -static void yyerror(char* s);
+ /* safer then using yytext which can be array or pointer */
+ extern char* yy_number_str;
 +static void yyerror(char* s, ...);
 +static void yyerror_at(struct cfg_pos* pos, char* s, ...);
  static char* tmp;
  static int i_tmp;
 +static unsigned u_tmp;
  static struct socket_id* lst_tmp;
  static struct name_lst*  nl_tmp;
  static int rt;  /* Type of route block for find_export */
@@@ -526,12 -480,9 +529,13 @@@ static int case_check_default(struct ca
  /* values */
  %token <intval> NUMBER
  %token <strval> ID
+ %token <strval> NUM_ID
  %token <strval> STRING
  %token <strval> IPV6ADDR
 +%token <strval> PVAR
 +/* not clear yet if this is an avp or pvar */
 +%token <strval> AVP_OR_PVAR
 +%token <strval> EVENT_RT_NAME
  
  /* other */
  %token COMMA
  
  
  /*non-terminals */
 -%type <expr> exp exp_elem /*, condition*/
 -%type <action> action actions cmd fcmd if_cmd stm exp_stm assign_action
 +/*%type <expr> exp */
 +%type <expr> exp_elem
 +%type <intval> intno eint_op eint_op_onsend
 +%type <intval> eip_op eip_op_onsend
 +%type <action> action actions cmd fcmd if_cmd stm /*exp_stm*/ assign_action
 +%type <action> switch_cmd while_cmd ret_cmd
 +%type <case_stms> single_case case_stms
  %type <ipaddr> ipv4 ipv6 ipv6addr ip
  %type <ipnet> ipnet
- %type <strval> host
+ %type <strval> host host_or_if host_if_id
  %type <strval> listen_id
  %type <name_l> listen_id_lst
  %type <name_l> listen_id2
@@@ -695,13 -641,9 +703,13 @@@ listen_phostport
  
  id_lst:
        listen_phostport                {  $$=$1 ; }
-       | listen_phostport id_lst       { $$=$1; $$->next=$2; }
+       | listen_phostport id_lst       { $$=$1;  if ($$) $$->next=$2; }
        ;
  
 +intno: NUMBER
 +      |  MINUS %prec NOT NUMBER { $$=-$2; }
 +      ;
 +
  flags_decl:           FLAGS_DECL      flag_list
                        |       FLAGS_DECL error { yyerror("flag list expected\n"); }
  ;
@@@ -1379,11 -1322,11 +1388,13 @@@ assign_stm
                free_socket_id_lst($3);
        }
        | ALIAS  EQUAL error  { yyerror(" hostname expected"); }
 +      | SR_AUTO_ALIASES EQUAL NUMBER { sr_auto_aliases=$3; }
 +      | SR_AUTO_ALIASES EQUAL error  { yyerror("boolean value expected"); }
        | ADVERTISED_ADDRESS EQUAL listen_id {
-               default_global_address.s=$3;
-               default_global_address.len=strlen($3);
+               if ($3){
+                       default_global_address.s=$3;
+                       default_global_address.len=strlen($3);
+               }
        }
        | ADVERTISED_ADDRESS EQUAL error {yyerror("ip address or hostname expected"); }
        | ADVERTISED_PORT EQUAL NUMBER {
@@@ -1907,34 -1906,55 +1918,84 @@@ ipnet
  
  host:
        ID { $$=$1; }
 -      | host host_sep ID {
 +      | host DOT ID {
-               $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
-               if ($$==0) {
-                       LOG(L_CRIT, "ERROR: cfg. parser: memory allocation failure while parsing host\n");
-               } else {
-                       memcpy($$, $1, strlen($1));
-                       $$[strlen($1)]='.';
-                       memcpy($$+strlen($1)+1, $3, strlen($3));
-                       $$[strlen($1)+1+strlen($3)]=0;
++              if ($1){
++                      $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
++                      if ($$==0) {
++                              LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
++                                                      " failure while parsing host\n");
++                      } else {
++                              memcpy($$, $1, strlen($1));
++                              $$[strlen($1)]='.';
++                              memcpy($$+strlen($1)+1, $3, strlen($3));
++                              $$[strlen($1)+1+strlen($3)]=0;
++                      }
++                      pkg_free($1);
 +              }
-               pkg_free($1);
-               pkg_free($3);
 +      }
 +      | host MINUS ID {
-               $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
-               if ($$==0) {
-                       LOG(L_CRIT, "ERROR: cfg. parser: memory allocation failure while parsing host\n");
-               } else {
-                       memcpy($$, $1, strlen($1));
-                       $$[strlen($1)]='-';
-                       memcpy($$+strlen($1)+1, $3, strlen($3));
-                       $$[strlen($1)+1+strlen($3)]=0;
+               if ($1){
+                       $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
+                       if ($$==0) {
+                               LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
+                                                       " failure while parsing host\n");
+                       } else {
+                               memcpy($$, $1, strlen($1));
 -                              $$[strlen($1)]=*$2;
++                              $$[strlen($1)]='-';
+                               memcpy($$+strlen($1)+1, $3, strlen($3));
+                               $$[strlen($1)+1+strlen($3)]=0;
+                       }
+                       pkg_free($1);
                }
-               pkg_free($1);
-               pkg_free($3);
        }
        | host DOT error { $$=0; pkg_free($1); yyerror("invalid hostname"); }
 -      | host_or_if host_sep host_if_id {
++      | host MINUS error { $$=0; pkg_free($1); yyerror("invalid hostname"); }
+       ;
+ host_if_id: ID
+               | NUM_ID
+               | NUMBER { $$=yy_number_str /* text version */; }
+               ;
+ host_or_if:
+       host_if_id { $$=$1; }
 -                              $$[strlen($1)]=*$2;
++      | host_or_if DOT host_if_id {
+               if ($1){
+                       $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
+                       if ($$==0) {
+                               LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
+                                                       " failure while parsing host/interface name\n");
+                       } else {
+                               memcpy($$, $1, strlen($1));
 -      | host_or_if host_sep error { $$=0; pkg_free($1);
++                              $$[strlen($1)]='.';
+                               memcpy($$+strlen($1)+1, $3, strlen($3));
+                               $$[strlen($1)+1+strlen($3)]=0;
+                       }
+                       pkg_free($1);
+               }
+       }
++      | host_or_if MINUS host_if_id {
++              if ($1){
++                      $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
++                      if ($$==0) {
++                              LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
++                                                      " failure while parsing host/interface name\n");
++                      } else {
++                              memcpy($$, $1, strlen($1));
++                              $$[strlen($1)]='-';
++                              memcpy($$+strlen($1)+1, $3, strlen($3));
++                              $$[strlen($1)+1+strlen($3)]=0;
++                      }
++                      pkg_free($1);
++              }
++      }
++      | host_or_if DOT error { $$=0; pkg_free($1);
++                                                              yyerror("invalid host or interface name"); }
++      | host_or_if MINUS error { $$=0; pkg_free($1);
+                                                               yyerror("invalid host or interface name"); }
        ;
  /* filtered cmd */
  fcmd:
        cmd {
Simple merge
Simple merge
diff --cc socket_info.c
Simple merge