Diff for /embedaddon/lighttpd/src/configparser.y between versions 1.1.1.2 and 1.1.1.3

version 1.1.1.2, 2014/06/15 20:20:06 version 1.1.1.3, 2016/11/02 10:35:00
Line 3 Line 3
 %name configparser  %name configparser
   
 %include {  %include {
   #include "first.h"
 #include "configfile.h"  #include "configfile.h"
 #include "buffer.h"  #include "buffer.h"
 #include "array.h"  #include "array.h"
   #include "request.h" /* http_request_host_normalize() */
   
 #include <assert.h>  #include <assert.h>
   #include <ctype.h>
   #include <errno.h>
 #include <stdio.h>  #include <stdio.h>
 #include <string.h>  #include <string.h>
   
Line 17  static void configparser_push(config_t *ctx, data_conf Line 21  static void configparser_push(config_t *ctx, data_conf
     force_assert(dc->context_ndx > ctx->current->context_ndx);      force_assert(dc->context_ndx > ctx->current->context_ndx);
     array_insert_unique(ctx->all_configs, (data_unset *)dc);      array_insert_unique(ctx->all_configs, (data_unset *)dc);
     dc->parent = ctx->current;      dc->parent = ctx->current;
    array_insert_unique(dc->parent->childs, (data_unset *)dc);    vector_config_weak_push(&dc->parent->children, dc);
   }    }
  if (ctx->configs_stack->used > 0 && ctx->current->context_ndx == 0) {  if (ctx->configs_stack.used > 0 && ctx->current->context_ndx == 0) {
     fprintf(stderr, "Cannot use conditionals inside a global { ... } block\n");      fprintf(stderr, "Cannot use conditionals inside a global { ... } block\n");
     exit(-1);      exit(-1);
   }    }
  array_insert_unique(ctx->configs_stack, (data_unset *)ctx->current);  vector_config_weak_push(&ctx->configs_stack, ctx->current);
   ctx->current = dc;    ctx->current = dc;
 }  }
   
 static data_config *configparser_pop(config_t *ctx) {  static data_config *configparser_pop(config_t *ctx) {
   data_config *old = ctx->current;    data_config *old = ctx->current;
  ctx->current = (data_config *) array_pop(ctx->configs_stack);  ctx->current = vector_config_weak_pop(&ctx->configs_stack);
   return old;    return old;
 }  }
   
Line 61  data_unset *configparser_merge_data(data_unset *op1, c Line 65  data_unset *configparser_merge_data(data_unset *op1, c
   if (op1->type != op2->type) {    if (op1->type != op2->type) {
     if (op1->type == TYPE_STRING && op2->type == TYPE_INTEGER) {      if (op1->type == TYPE_STRING && op2->type == TYPE_INTEGER) {
       data_string *ds = (data_string *)op1;        data_string *ds = (data_string *)op1;
      buffer_append_long(ds->value, ((data_integer*)op2)->value);      buffer_append_int(ds->value, ((data_integer*)op2)->value);
       return op1;        return op1;
     } else if (op1->type == TYPE_INTEGER && op2->type == TYPE_STRING) {      } else if (op1->type == TYPE_INTEGER && op2->type == TYPE_STRING) {
       data_string *ds = data_string_init();        data_string *ds = data_string_init();
      buffer_append_long(ds->value, ((data_integer*)op1)->value);      buffer_append_int(ds->value, ((data_integer*)op1)->value);
       buffer_append_string_buffer(ds->value, ((data_string*)op2)->value);        buffer_append_string_buffer(ds->value, ((data_string*)op2)->value);
       op1->free(op1);        op1->free(op1);
       return (data_unset *)ds;        return (data_unset *)ds;
     } else {      } else {
       fprintf(stderr, "data type mismatch, cannot merge\n");        fprintf(stderr, "data type mismatch, cannot merge\n");
         op1->free(op1);
       return NULL;        return NULL;
     }      }
   }    }
Line 91  data_unset *configparser_merge_data(data_unset *op1, c Line 96  data_unset *configparser_merge_data(data_unset *op1, c
       for (i = 0; i < src->used; i ++) {        for (i = 0; i < src->used; i ++) {
         du = (data_unset *)src->data[i];          du = (data_unset *)src->data[i];
         if (du) {          if (du) {
          array_insert_unique(dst, du->copy(du));          if (du->is_index_key || buffer_is_empty(du->key) || !array_get_element(dst, du->key->ptr)) {
             array_insert_unique(dst, du->copy(du));
           } else {
             fprintf(stderr, "Duplicate array-key '%s'\n", du->key->ptr);
             op1->free(op1);
             return NULL;
           }
         }          }
       }        }
       break;        break;
Line 103  data_unset *configparser_merge_data(data_unset *op1, c Line 114  data_unset *configparser_merge_data(data_unset *op1, c
   return op1;    return op1;
 }  }
   
   static int configparser_remoteip_normalize_compat(buffer *rvalue) {
     /* $HTTP["remoteip"] IPv6 accepted with or without '[]' for config compat
      * http_request_host_normalize() expects IPv6 with '[]',
      * and config processing at runtime expects COMP_HTTP_REMOTE_IP
      * compared without '[]', so strip '[]' after normalization */
     buffer *b = buffer_init();
     int rc;
   
     if (rvalue->ptr[0] != '[') {
         buffer_append_string_len(b, CONST_STR_LEN("["));
         buffer_append_string_buffer(b, rvalue);
         buffer_append_string_len(b, CONST_STR_LEN("]"));
     } else {
         buffer_append_string_buffer(b, rvalue);
     }
   
     rc = http_request_host_normalize(b);
   
     if (0 == rc) {
       /* remove surrounding '[]' */
       size_t blen = buffer_string_length(b);
       if (blen > 1) buffer_copy_string_len(rvalue, b->ptr+1, blen-2);
     }
   
     buffer_free(b);
     return rc;
 }  }
   
   }
   
 %parse_failure {  %parse_failure {
   ctx->ok = 0;    ctx->ok = 0;
 }  }
Line 124  metaline ::= EOL. Line 163  metaline ::= EOL.
 %type       aelement               {data_unset *}  %type       aelement               {data_unset *}
 %type       condline               {data_config *}  %type       condline               {data_config *}
 %type       condlines              {data_config *}  %type       condlines              {data_config *}
 %type       global                 {data_config *}  
 %type       aelements              {array *}  %type       aelements              {array *}
 %type       array                  {array *}  %type       array                  {array *}
 %type       key                    {buffer *}  %type       key                    {buffer *}
Line 132  metaline ::= EOL. Line 170  metaline ::= EOL.
   
 %type       cond                   {config_cond_t }  %type       cond                   {config_cond_t }
   
%destructor value                  { $$->free($$); }%destructor value                  { if ($$) $$->free($$); }
%destructor expression             { $$->free($$); }%destructor expression             { if ($$) $$->free($$); }
%destructor aelement               { $$->free($$); }%destructor aelement               { if ($$) $$->free($$); }
 %destructor aelements              { array_free($$); }  %destructor aelements              { array_free($$); }
 %destructor array                  { array_free($$); }  %destructor array                  { array_free($$); }
 %destructor key                    { buffer_free($$); }  %destructor key                    { buffer_free($$); }
Line 145  metaline ::= EOL. Line 183  metaline ::= EOL.
   
 varline ::= key(A) ASSIGN expression(B). {  varline ::= key(A) ASSIGN expression(B). {
   if (ctx->ok) {    if (ctx->ok) {
    buffer_copy_string_buffer(B->key, A);    buffer_copy_buffer(B->key, A);
     if (strncmp(A->ptr, "env.", sizeof("env.") - 1) == 0) {      if (strncmp(A->ptr, "env.", sizeof("env.") - 1) == 0) {
       fprintf(stderr, "Setting env variable is not supported in conditional %d %s: %s\n",        fprintf(stderr, "Setting env variable is not supported in conditional %d %s: %s\n",
           ctx->current->context_ndx,            ctx->current->context_ndx,
Line 168  varline ::= key(A) ASSIGN expression(B). { Line 206  varline ::= key(A) ASSIGN expression(B). {
 }  }
   
 varline ::= key(A) APPEND expression(B). {  varline ::= key(A) APPEND expression(B). {
  array *vars = ctx->current->value;  if (ctx->ok) {
  data_unset *du;    array *vars = ctx->current->value;
     data_unset *du;
   
  if (strncmp(A->ptr, "env.", sizeof("env.") - 1) == 0) {    if (strncmp(A->ptr, "env.", sizeof("env.") - 1) == 0) {
    fprintf(stderr, "Appending env variable is not supported in conditional %d %s: %s\n",      fprintf(stderr, "Appending env variable is not supported in conditional %d %s: %s\n",
        ctx->current->context_ndx,          ctx->current->context_ndx,
        ctx->current->key->ptr, A->ptr);          ctx->current->key->ptr, A->ptr);
    ctx->ok = 0; 
  } else if (NULL != (du = array_get_element(vars, A->ptr))) { 
    /* exists in current block */ 
    du = configparser_merge_data(du, B); 
    if (NULL == du) { 
       ctx->ok = 0;        ctx->ok = 0;
       } else if (NULL != (du = array_extract_element(vars, A->ptr)) || NULL != (du = configparser_get_variable(ctx, A))) {
         du = configparser_merge_data(du, B);
         if (NULL == du) {
           ctx->ok = 0;
         }
         else {
           buffer_copy_buffer(du->key, A);
           array_insert_unique(ctx->current->value, du);
         }
         B->free(B);
       } else {
         buffer_copy_buffer(B->key, A);
         array_insert_unique(ctx->current->value, B);
     }      }
    else {    buffer_free(A);
      buffer_copy_string_buffer(du->key, A);    A = NULL;
      array_replace(vars, du);    B = NULL;
    } 
    B->free(B); 
  } else if (NULL != (du = configparser_get_variable(ctx, A))) { 
    du = configparser_merge_data(du, B); 
    if (NULL == du) { 
      ctx->ok = 0; 
    } 
    else { 
      buffer_copy_string_buffer(du->key, A); 
      array_insert_unique(ctx->current->value, du); 
    } 
    B->free(B); 
  } else { 
    buffer_copy_string_buffer(B->key, A); 
    array_insert_unique(ctx->current->value, B); 
   }    }
   buffer_free(A);  
   A = NULL;  
   B = NULL;  
 }  }
   
 key(A) ::= LKEY(B). {  key(A) ::= LKEY(B). {
Line 219  key(A) ::= LKEY(B). { Line 248  key(A) ::= LKEY(B). {
 }  }
   
 expression(A) ::= expression(B) PLUS value(C). {  expression(A) ::= expression(B) PLUS value(C). {
  A = configparser_merge_data(B, C);  A = NULL;
  if (NULL == A) {  if (ctx->ok) {
    ctx->ok = 0;    A = configparser_merge_data(B, C);
     if (NULL == A) {
       ctx->ok = 0;
     }
     B = NULL;
     C->free(C);
     C = NULL;
   }    }
   B = NULL;  
   C->free(C);  
   C = NULL;  
 }  }
   
 expression(A) ::= value(B). {  expression(A) ::= value(B). {
Line 235  expression(A) ::= value(B). { Line 267  expression(A) ::= value(B). {
   
 value(A) ::= key(B). {  value(A) ::= key(B). {
   A = NULL;    A = NULL;
  if (strncmp(B->ptr, "env.", sizeof("env.") - 1) == 0) {  if (ctx->ok) {
    char *env;    if (strncmp(B->ptr, "env.", sizeof("env.") - 1) == 0) {
       char *env;
   
    if (NULL != (env = getenv(B->ptr + 4))) {      if (NULL != (env = getenv(B->ptr + 4))) {
      data_string *ds;        data_string *ds;
      ds = data_string_init();        ds = data_string_init();
      buffer_append_string(ds->value, env);        buffer_append_string(ds->value, env);
      A = (data_unset *)ds;        A = (data_unset *)ds;
    }      }
    else {      else {
      fprintf(stderr, "Undefined env variable: %s\n", B->ptr + 4);        fprintf(stderr, "Undefined env variable: %s\n", B->ptr + 4);
         ctx->ok = 0;
       }
     } else if (NULL == (A = configparser_get_variable(ctx, B))) {
       fprintf(stderr, "Undefined config variable: %s\n", B->ptr);
       ctx->ok = 0;        ctx->ok = 0;
     }      }
  } else if (NULL == (A = configparser_get_variable(ctx, B))) {    buffer_free(B);
    fprintf(stderr, "Undefined config variable: %s\n", B->ptr);    B = NULL;
    ctx->ok = 0; 
   }    }
   if (!A) {  
     /* make a dummy so it won't crash */  
     A = (data_unset *)data_string_init();  
   }  
   buffer_free(B);  
   B = NULL;  
 }  }
   
 value(A) ::= STRING(B). {  value(A) ::= STRING(B). {
   A = (data_unset *)data_string_init();    A = (data_unset *)data_string_init();
  buffer_copy_string_buffer(((data_string *)(A))->value, B);  buffer_copy_buffer(((data_string *)(A))->value, B);
   buffer_free(B);    buffer_free(B);
   B = NULL;    B = NULL;
 }  }
   
 value(A) ::= INTEGER(B). {  value(A) ::= INTEGER(B). {
     char *endptr;
   A = (data_unset *)data_integer_init();    A = (data_unset *)data_integer_init();
  ((data_integer *)(A))->value = strtol(B->ptr, NULL, 10);  errno = 0;
   ((data_integer *)(A))->value = strtol(B->ptr, &endptr, 10);
   /* skip trailing whitespace */
   if (endptr != B->ptr) while (isspace(*endptr)) endptr++;
   if (0 != errno || *endptr != '\0') {
     fprintf(stderr, "error parsing number: '%s'\n", B->ptr);
     ctx->ok = 0;
   }
   buffer_free(B);    buffer_free(B);
   B = NULL;    B = NULL;
 }  }
Line 288  array(A) ::= LPARAN aelements(B) RPARAN. { Line 326  array(A) ::= LPARAN aelements(B) RPARAN. {
 }  }
   
 aelements(A) ::= aelements(C) COMMA aelement(B). {  aelements(A) ::= aelements(C) COMMA aelement(B). {
  if (buffer_is_empty(B->key) ||  A = NULL;
      NULL == array_get_element(C, B->key->ptr)) {  if (ctx->ok) {
    array_insert_unique(C, B);    if (buffer_is_empty(B->key) ||
    B = NULL;        NULL == array_get_element(C, B->key->ptr)) {
  } else {      array_insert_unique(C, B);
    fprintf(stderr, "Duplicate array-key: %s\n",      B = NULL;
            B->key->ptr);    } else {
    ctx->ok = 0;      fprintf(stderr, "Error: duplicate array-key: %s. Please get rid of the duplicate entry.\n",
    B->free(B);              B->key->ptr);
    B = NULL;      ctx->ok = 0;
  }      B->free(B);
       B = NULL;
     }
   
  A = C;    A = C;
  C = NULL;    C = NULL;
   }
 }  }
   
 aelements(A) ::= aelements(C) COMMA. {  aelements(A) ::= aelements(C) COMMA. {
Line 310  aelements(A) ::= aelements(C) COMMA. { Line 351  aelements(A) ::= aelements(C) COMMA. {
 }  }
   
 aelements(A) ::= aelement(B). {  aelements(A) ::= aelement(B). {
  A = array_init();  A = NULL;
  array_insert_unique(A, B);  if (ctx->ok) {
  B = NULL;    A = array_init();
     array_insert_unique(A, B);
     B = NULL;
   }
 }  }
   
 aelement(A) ::= expression(B). {  aelement(A) ::= expression(B). {
Line 320  aelement(A) ::= expression(B). { Line 364  aelement(A) ::= expression(B). {
   B = NULL;    B = NULL;
 }  }
 aelement(A) ::= stringop(B) ARRAY_ASSIGN expression(C). {  aelement(A) ::= stringop(B) ARRAY_ASSIGN expression(C). {
  buffer_copy_string_buffer(C->key, B);  A = NULL;
  buffer_free(B);  if (ctx->ok) {
  B = NULL;    buffer_copy_buffer(C->key, B);
     buffer_free(B);
     B = NULL;
   
  A = C;    A = C;
  C = NULL;    C = NULL;
   }
 }  }
   
 eols ::= EOL.  eols ::= EOL.
Line 338  globalstart ::= GLOBAL. { Line 385  globalstart ::= GLOBAL. {
   configparser_push(ctx, dc, 0);    configparser_push(ctx, dc, 0);
 }  }
   
global(A) ::= globalstart LCURLY metalines RCURLY. {global ::= globalstart LCURLY metalines RCURLY. {
  data_config *cur;  force_assert(ctx->current);
 
  cur = ctx->current; 
   configparser_pop(ctx);    configparser_pop(ctx);
  force_assert(ctx->current);
  force_assert(cur && ctx->current); 
 
  A = cur; 
 }  }
   
 condlines(A) ::= condlines(B) eols ELSE condline(C). {  condlines(A) ::= condlines(B) eols ELSE condline(C). {
  if (B->context_ndx >= C->context_ndx) {  A = NULL;
    fprintf(stderr, "unreachable else condition\n");  if (ctx->ok) {
    ctx->ok = 0;    if (B->context_ndx >= C->context_ndx) {
       fprintf(stderr, "unreachable else condition\n");
       ctx->ok = 0;
     }
     C->prev = B;
     B->next = C;
     A = C;
     B = NULL;
     C = NULL;
   }    }
   C->prev = B;  
   B->next = C;  
   A = C;  
   B = NULL;  
   C = NULL;  
 }  }
   
 condlines(A) ::= condline(B). {  condlines(A) ::= condline(B). {
Line 367  condlines(A) ::= condline(B). { Line 412  condlines(A) ::= condline(B). {
 }  }
   
 condline(A) ::= context LCURLY metalines RCURLY. {  condline(A) ::= context LCURLY metalines RCURLY. {
  data_config *cur;  A = NULL;
   if (ctx->ok) {
     data_config *cur;
   
  cur = ctx->current;    cur = ctx->current;
  configparser_pop(ctx);    configparser_pop(ctx);
   
  force_assert(cur && ctx->current);    force_assert(cur && ctx->current);
   
  A = cur;    A = cur;
   }
 }  }
   
 context ::= DOLLAR SRVVARNAME(B) LBRACKET stringop(C) RBRACKET cond(E) expression(D). {  context ::= DOLLAR SRVVARNAME(B) LBRACKET stringop(C) RBRACKET cond(E) expression(D). {
Line 386  context ::= DOLLAR SRVVARNAME(B) LBRACKET stringop(C)  Line 434  context ::= DOLLAR SRVVARNAME(B) LBRACKET stringop(C) 
     ctx->ok = 0;      ctx->ok = 0;
   }    }
   
  switch(E) {  if (ctx->ok) {
  case CONFIG_COND_NE:    switch(E) {
    op = buffer_init_string("!=");    case CONFIG_COND_NE:
    break;      op = buffer_init_string("!=");
  case CONFIG_COND_EQ:      break;
    op = buffer_init_string("==");    case CONFIG_COND_EQ:
    break;      op = buffer_init_string("==");
  case CONFIG_COND_NOMATCH:      break;
    op = buffer_init_string("!~");    case CONFIG_COND_NOMATCH:
    break;      op = buffer_init_string("!~");
  case CONFIG_COND_MATCH:      break;
    op = buffer_init_string("=~");    case CONFIG_COND_MATCH:
    break;      op = buffer_init_string("=~");
  default:      break;
    force_assert(0);    default:
    return;      force_assert(0);
  }      return; /* unreachable */
     }
   
  b = buffer_init();    b = buffer_init();
  buffer_copy_string_buffer(b, ctx->current->key);    buffer_copy_buffer(b, ctx->current->key);
  buffer_append_string(b, "/");    buffer_append_string(b, "/");
  buffer_append_string_buffer(b, B);    buffer_append_string_buffer(b, B);
  buffer_append_string_buffer(b, C);    buffer_append_string_buffer(b, C);
  buffer_append_string_buffer(b, op);    buffer_append_string_buffer(b, op);
  rvalue = ((data_string*)D)->value;    rvalue = ((data_string*)D)->value;
  buffer_append_string_buffer(b, rvalue);    buffer_append_string_buffer(b, rvalue);
   
  if (NULL != (dc = (data_config *)array_get_element(ctx->all_configs, b->ptr))) {    if (NULL != (dc = (data_config *)array_get_element(ctx->all_configs, b->ptr))) {
    configparser_push(ctx, dc, 0);      configparser_push(ctx, dc, 0);
  } else {    } else {
    struct {      static const struct {
      comp_key_t comp;        comp_key_t comp;
      char *comp_key;        char *comp_key;
      size_t len;        size_t len;
    } comps[] = {      } comps[] = {
      { COMP_SERVER_SOCKET,      CONST_STR_LEN("SERVER[\"socket\"]"   ) },        { COMP_SERVER_SOCKET,      CONST_STR_LEN("SERVER[\"socket\"]"   ) },
      { COMP_HTTP_URL,           CONST_STR_LEN("HTTP[\"url\"]"        ) },        { COMP_HTTP_URL,           CONST_STR_LEN("HTTP[\"url\"]"        ) },
      { COMP_HTTP_HOST,          CONST_STR_LEN("HTTP[\"host\"]"       ) },        { COMP_HTTP_HOST,          CONST_STR_LEN("HTTP[\"host\"]"       ) },
      { COMP_HTTP_REFERER,       CONST_STR_LEN("HTTP[\"referer\"]"    ) },        { COMP_HTTP_REFERER,       CONST_STR_LEN("HTTP[\"referer\"]"    ) },
      { COMP_HTTP_USER_AGENT,    CONST_STR_LEN("HTTP[\"useragent\"]"  ) },        { COMP_HTTP_USER_AGENT,    CONST_STR_LEN("HTTP[\"useragent\"]"  ) },
      { COMP_HTTP_USER_AGENT,    CONST_STR_LEN("HTTP[\"user-agent\"]"  ) },        { COMP_HTTP_USER_AGENT,    CONST_STR_LEN("HTTP[\"user-agent\"]"  ) },
      { COMP_HTTP_LANGUAGE,      CONST_STR_LEN("HTTP[\"language\"]"   ) },        { COMP_HTTP_LANGUAGE,      CONST_STR_LEN("HTTP[\"language\"]"   ) },
      { COMP_HTTP_COOKIE,        CONST_STR_LEN("HTTP[\"cookie\"]"     ) },        { COMP_HTTP_COOKIE,        CONST_STR_LEN("HTTP[\"cookie\"]"     ) },
      { COMP_HTTP_REMOTE_IP,     CONST_STR_LEN("HTTP[\"remoteip\"]"   ) },        { COMP_HTTP_REMOTE_IP,     CONST_STR_LEN("HTTP[\"remoteip\"]"   ) },
      { COMP_HTTP_REMOTE_IP,     CONST_STR_LEN("HTTP[\"remote-ip\"]"   ) },        { COMP_HTTP_REMOTE_IP,     CONST_STR_LEN("HTTP[\"remote-ip\"]"   ) },
      { COMP_HTTP_QUERY_STRING,  CONST_STR_LEN("HTTP[\"querystring\"]") },        { COMP_HTTP_QUERY_STRING,  CONST_STR_LEN("HTTP[\"querystring\"]") },
      { COMP_HTTP_QUERY_STRING,  CONST_STR_LEN("HTTP[\"query-string\"]") },        { COMP_HTTP_QUERY_STRING,  CONST_STR_LEN("HTTP[\"query-string\"]") },
      { COMP_HTTP_REQUEST_METHOD, CONST_STR_LEN("HTTP[\"request-method\"]") },        { COMP_HTTP_REQUEST_METHOD, CONST_STR_LEN("HTTP[\"request-method\"]") },
      { COMP_HTTP_SCHEME,        CONST_STR_LEN("HTTP[\"scheme\"]"     ) },        { COMP_HTTP_SCHEME,        CONST_STR_LEN("HTTP[\"scheme\"]"     ) },
      { COMP_UNSET, NULL, 0 },        { COMP_UNSET, NULL, 0 },
    };      };
    size_t i;      size_t i;
   
    dc = data_config_init();      dc = data_config_init();
   
    buffer_copy_string_buffer(dc->key, b);      buffer_copy_buffer(dc->key, b);
    buffer_copy_string_buffer(dc->op, op);      buffer_copy_buffer(dc->op, op);
    buffer_copy_string_buffer(dc->comp_key, B);      buffer_copy_buffer(dc->comp_key, B);
    buffer_append_string_len(dc->comp_key, CONST_STR_LEN("[\""));      buffer_append_string_len(dc->comp_key, CONST_STR_LEN("[\""));
    buffer_append_string_buffer(dc->comp_key, C);      buffer_append_string_buffer(dc->comp_key, C);
    buffer_append_string_len(dc->comp_key, CONST_STR_LEN("\"]"));      buffer_append_string_len(dc->comp_key, CONST_STR_LEN("\"]"));
    dc->cond = E;      dc->cond = E;
   
    for (i = 0; comps[i].comp_key; i ++) {      for (i = 0; comps[i].comp_key; i ++) {
      if (buffer_is_equal_string(        if (buffer_is_equal_string(
            dc->comp_key, comps[i].comp_key, comps[i].len)) {              dc->comp_key, comps[i].comp_key, comps[i].len)) {
        dc->comp = comps[i].comp;          dc->comp = comps[i].comp;
        break;          break;
         }
       }        }
    }      if (COMP_UNSET == dc->comp) {
    if (COMP_UNSET == dc->comp) {        fprintf(stderr, "error comp_key %s", dc->comp_key->ptr);
      fprintf(stderr, "error comp_key %s", dc->comp_key->ptr);        ctx->ok = 0;
      ctx->ok = 0;      }
    }      else if (COMP_HTTP_REMOTE_IP == dc->comp
                && (dc->cond == CONFIG_COND_EQ || dc->cond == CONFIG_COND_NE)) {
         char * const slash = strchr(rvalue->ptr, '/'); /* CIDR mask */
         char * const colon = strchr(rvalue->ptr, ':'); /* IPv6 */
         if (NULL != slash && slash == rvalue->ptr){/*(skip AF_UNIX /path/file)*/
         }
         else if (NULL != slash) {
           char *nptr;
           const unsigned long nm_bits = strtoul(slash + 1, &nptr, 10);
           if (*nptr || 0 == nm_bits || nm_bits > (NULL != colon ? 128 : 32)) {
             /*(also rejects (slash+1 == nptr) which results in nm_bits = 0)*/
             fprintf(stderr, "invalid or missing netmask: %s\n", rvalue->ptr);
             ctx->ok = 0;
           }
           else {
             int rc;
             buffer_string_set_length(rvalue, (size_t)(slash - rvalue->ptr)); /*(truncate)*/
             rc = (NULL == colon)
               ? http_request_host_normalize(rvalue)
               : configparser_remoteip_normalize_compat(rvalue);
             buffer_append_string_len(rvalue, CONST_STR_LEN("/"));
             buffer_append_int(rvalue, (int)nm_bits);
             if (0 != rc) {
               fprintf(stderr, "invalid IP addr: %s\n", rvalue->ptr);
               ctx->ok = 0;
             }
           }
         }
         else {
           int rc = (NULL == colon)
             ? http_request_host_normalize(rvalue)
             : configparser_remoteip_normalize_compat(rvalue);
           if (0 != rc) {
             fprintf(stderr, "invalid IP addr: %s\n", rvalue->ptr);
             ctx->ok = 0;
           }
         }
       }
       else if (COMP_SERVER_SOCKET == dc->comp) {
         /*(redundant with parsing in network.c; not actually required here)*/
         if (rvalue->ptr[0] != ':' /*(network.c special-cases ":" and "[]")*/
             && !(rvalue->ptr[0] == '[' && rvalue->ptr[1] == ']')) {
           if (http_request_host_normalize(rvalue)) {
             fprintf(stderr, "invalid IP addr: %s\n", rvalue->ptr);
             ctx->ok = 0;
           }
         }
       }
       else if (COMP_HTTP_HOST == dc->comp) {
         if (dc->cond == CONFIG_COND_EQ || dc->cond == CONFIG_COND_NE) {
           if (http_request_host_normalize(rvalue)) {
             fprintf(stderr, "invalid IP addr: %s\n", rvalue->ptr);
             ctx->ok = 0;
           }
         }
       }
   
    switch(E) {      if (ctx->ok) switch(E) {
    case CONFIG_COND_NE:      case CONFIG_COND_NE:
    case CONFIG_COND_EQ:      case CONFIG_COND_EQ:
      dc->string = buffer_init_buffer(rvalue);        dc->string = buffer_init_buffer(rvalue);
      break;        break;
    case CONFIG_COND_NOMATCH:      case CONFIG_COND_NOMATCH:
    case CONFIG_COND_MATCH: {      case CONFIG_COND_MATCH: {
 #ifdef HAVE_PCRE_H  #ifdef HAVE_PCRE_H
      const char *errptr;        const char *errptr;
      int erroff, captures;        int erroff, captures;
   
      if (NULL == (dc->regex =        if (NULL == (dc->regex =
          pcre_compile(rvalue->ptr, 0, &errptr, &erroff, NULL))) {            pcre_compile(rvalue->ptr, 0, &errptr, &erroff, NULL))) {
        dc->string = buffer_init_string(errptr);          dc->string = buffer_init_string(errptr);
        dc->cond = CONFIG_COND_UNSET;          dc->cond = CONFIG_COND_UNSET;
   
        fprintf(stderr, "parsing regex failed: %s -> %s at offset %d\n",          fprintf(stderr, "parsing regex failed: %s -> %s at offset %d\n",
            rvalue->ptr, errptr, erroff);              rvalue->ptr, errptr, erroff);
   
             ctx->ok = 0;
           } else if (NULL == (dc->regex_study =
               pcre_study(dc->regex, 0, &errptr)) &&
                      errptr != NULL) {
             fprintf(stderr, "studying regex failed: %s -> %s\n",
                 rvalue->ptr, errptr);
             ctx->ok = 0;
           } else if (0 != (pcre_fullinfo(dc->regex, dc->regex_study, PCRE_INFO_CAPTURECOUNT, &captures))) {
             fprintf(stderr, "getting capture count for regex failed: %s\n",
                 rvalue->ptr);
             ctx->ok = 0;
           } else if (captures > 9) {
             fprintf(stderr, "Too many captures in regex, use (?:...) instead of (...): %s\n",
                 rvalue->ptr);
             ctx->ok = 0;
           } else {
             dc->string = buffer_init_buffer(rvalue);
           }
   #else
           fprintf(stderr, "can't handle '$%s[%s] =~ ...' as you compiled without pcre support. \n"
                           "(perhaps just a missing pcre-devel package ?) \n",
                           B->ptr, C->ptr);
         ctx->ok = 0;          ctx->ok = 0;
      } else if (NULL == (dc->regex_study = #endif
          pcre_study(dc->regex, 0, &errptr)) &&        break;
                 errptr != NULL) {      }
        fprintf(stderr, "studying regex failed: %s -> %s\n",
            rvalue->ptr, errptr);      default:
         fprintf(stderr, "unknown condition for $%s[%s]\n",
                         B->ptr, C->ptr);
         ctx->ok = 0;          ctx->ok = 0;
      } else if (0 != (pcre_fullinfo(dc->regex, dc->regex_study, PCRE_INFO_CAPTURECOUNT, &captures))) {        break;
        fprintf(stderr, "getting capture count for regex failed: %s\n",      }
            rvalue->ptr);
        ctx->ok = 0;      if (ctx->ok) {
      } else if (captures > 9) {        configparser_push(ctx, dc, 1);
        fprintf(stderr, "Too many captures in regex, use (?:...) instead of (...): %s\n", 
            rvalue->ptr); 
        ctx->ok = 0; 
       } else {        } else {
        dc->string = buffer_init_buffer(rvalue);        dc->free((data_unset*) dc);
       }        }
 #else  
       fprintf(stderr, "can't handle '$%s[%s] =~ ...' as you compiled without pcre support. \n"  
                       "(perhaps just a missing pcre-devel package ?) \n",  
                       B->ptr, C->ptr);  
       ctx->ok = 0;  
 #endif  
       break;  
     }      }
   
    default:    buffer_free(b);
      fprintf(stderr, "unknown condition for $%s[%s]\n",    buffer_free(op);
                      B->ptr, C->ptr);    buffer_free(B);
      ctx->ok = 0;    B = NULL;
      break;    buffer_free(C);
    }    C = NULL;
    D->free(D);
    configparser_push(ctx, dc, 1);    D = NULL;
   }    }
   
   buffer_free(b);  
   buffer_free(op);  
   buffer_free(B);  
   B = NULL;  
   buffer_free(C);  
   C = NULL;  
   D->free(D);  
   D = NULL;  
 }  }
 cond(A) ::= EQ. {  cond(A) ::= EQ. {
   A = CONFIG_COND_EQ;    A = CONFIG_COND_EQ;
Line 546  stringop(A) ::= expression(B). { Line 656  stringop(A) ::= expression(B). {
       A = buffer_init_buffer(((data_string*)B)->value);        A = buffer_init_buffer(((data_string*)B)->value);
     } else if (B->type == TYPE_INTEGER) {      } else if (B->type == TYPE_INTEGER) {
       A = buffer_init();        A = buffer_init();
      buffer_copy_long(A, ((data_integer *)B)->value);      buffer_copy_int(A, ((data_integer *)B)->value);
     } else {      } else {
       fprintf(stderr, "operand must be string");        fprintf(stderr, "operand must be string");
       ctx->ok = 0;        ctx->ok = 0;

Removed from v.1.1.1.2  
changed lines
  Added in v.1.1.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>