2005-02-20 14:27:00 +00:00
|
|
|
%token_prefix TK_
|
|
|
|
%extra_argument {config_t *ctx}
|
|
|
|
%name configparser
|
|
|
|
|
|
|
|
%include {
|
2016-03-19 15:14:35 +00:00
|
|
|
#include "first.h"
|
2005-02-20 14:27:00 +00:00
|
|
|
#include "configfile.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "array.h"
|
2016-05-19 23:15:47 +00:00
|
|
|
#include "request.h" /* http_request_host_normalize() */
|
2005-08-08 13:48:33 +00:00
|
|
|
|
2016-03-26 10:58:49 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
2009-10-11 14:31:42 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2005-08-08 13:48:33 +00:00
|
|
|
static void configparser_push(config_t *ctx, data_config *dc, int isnew) {
|
|
|
|
if (isnew) {
|
|
|
|
dc->context_ndx = ctx->all_configs->used;
|
2014-02-16 13:08:20 +00:00
|
|
|
force_assert(dc->context_ndx > ctx->current->context_ndx);
|
2005-08-08 13:48:33 +00:00
|
|
|
array_insert_unique(ctx->all_configs, (data_unset *)dc);
|
2005-08-08 14:40:47 +00:00
|
|
|
dc->parent = ctx->current;
|
2016-03-19 15:27:38 +00:00
|
|
|
vector_config_weak_push(&dc->parent->children, dc);
|
2005-08-08 13:48:33 +00:00
|
|
|
}
|
2016-03-19 15:27:38 +00:00
|
|
|
if (ctx->configs_stack.used > 0 && ctx->current->context_ndx == 0) {
|
2008-08-01 20:31:43 +00:00
|
|
|
fprintf(stderr, "Cannot use conditionals inside a global { ... } block\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
2016-03-19 15:27:38 +00:00
|
|
|
vector_config_weak_push(&ctx->configs_stack, ctx->current);
|
2005-08-08 13:48:33 +00:00
|
|
|
ctx->current = dc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static data_config *configparser_pop(config_t *ctx) {
|
|
|
|
data_config *old = ctx->current;
|
2016-03-19 15:27:38 +00:00
|
|
|
ctx->current = vector_config_weak_pop(&ctx->configs_stack);
|
2005-08-08 13:48:33 +00:00
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
2005-08-08 17:25:55 +00:00
|
|
|
/* return a copied variable */
|
|
|
|
static data_unset *configparser_get_variable(config_t *ctx, const buffer *key) {
|
2006-09-07 10:19:29 +00:00
|
|
|
data_unset *du;
|
|
|
|
data_config *dc;
|
2005-08-08 14:40:47 +00:00
|
|
|
|
|
|
|
#if 0
|
2006-09-07 10:19:29 +00:00
|
|
|
fprintf(stderr, "get var %s\n", key->ptr);
|
2005-08-08 14:40:47 +00:00
|
|
|
#endif
|
2006-09-07 10:19:29 +00:00
|
|
|
for (dc = ctx->current; dc; dc = dc->parent) {
|
2005-08-08 14:40:47 +00:00
|
|
|
#if 0
|
2006-09-07 10:19:29 +00:00
|
|
|
fprintf(stderr, "get var on block: %s\n", dc->key->ptr);
|
|
|
|
array_print(dc->value, 0);
|
2005-08-08 14:40:47 +00:00
|
|
|
#endif
|
2006-09-07 10:19:29 +00:00
|
|
|
if (NULL != (du = array_get_element(dc->value, key->ptr))) {
|
|
|
|
return du->copy(du);
|
2005-08-08 14:40:47 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-07 10:19:29 +00:00
|
|
|
return NULL;
|
2005-08-08 14:40:47 +00:00
|
|
|
}
|
|
|
|
|
2008-02-25 06:57:32 +00:00
|
|
|
/* op1 is to be eat/return by this function if success, op1->key is not cared
|
2005-08-08 14:40:47 +00:00
|
|
|
op2 is left untouch, unreferenced
|
|
|
|
*/
|
2005-08-23 14:35:01 +00:00
|
|
|
data_unset *configparser_merge_data(data_unset *op1, const data_unset *op2) {
|
2005-08-08 14:40:47 +00:00
|
|
|
/* type mismatch */
|
|
|
|
if (op1->type != op2->type) {
|
|
|
|
if (op1->type == TYPE_STRING && op2->type == TYPE_INTEGER) {
|
|
|
|
data_string *ds = (data_string *)op1;
|
2015-02-08 12:37:10 +00:00
|
|
|
buffer_append_int(ds->value, ((data_integer*)op2)->value);
|
2005-08-08 14:40:47 +00:00
|
|
|
return op1;
|
2005-08-08 16:44:25 +00:00
|
|
|
} else if (op1->type == TYPE_INTEGER && op2->type == TYPE_STRING) {
|
2005-08-08 14:40:47 +00:00
|
|
|
data_string *ds = data_string_init();
|
2015-02-08 12:37:10 +00:00
|
|
|
buffer_append_int(ds->value, ((data_integer*)op1)->value);
|
2005-08-08 14:40:47 +00:00
|
|
|
buffer_append_string_buffer(ds->value, ((data_string*)op2)->value);
|
|
|
|
op1->free(op1);
|
|
|
|
return (data_unset *)ds;
|
2005-08-08 16:44:25 +00:00
|
|
|
} else {
|
2009-07-21 20:35:27 +00:00
|
|
|
fprintf(stderr, "data type mismatch, cannot merge\n");
|
2016-03-15 18:41:59 +00:00
|
|
|
op1->free(op1);
|
2005-08-08 14:40:47 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (op1->type) {
|
|
|
|
case TYPE_STRING:
|
|
|
|
buffer_append_string_buffer(((data_string *)op1)->value, ((data_string *)op2)->value);
|
|
|
|
break;
|
|
|
|
case TYPE_INTEGER:
|
|
|
|
((data_integer *)op1)->value += ((data_integer *)op2)->value;
|
|
|
|
break;
|
|
|
|
case TYPE_ARRAY: {
|
|
|
|
array *dst = ((data_array *)op1)->value;
|
|
|
|
array *src = ((data_array *)op2)->value;
|
|
|
|
data_unset *du;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < src->used; i ++) {
|
|
|
|
du = (data_unset *)src->data[i];
|
|
|
|
if (du) {
|
2016-03-15 18:56:05 +00:00
|
|
|
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;
|
|
|
|
}
|
2005-08-08 14:40:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2014-02-16 13:08:20 +00:00
|
|
|
force_assert(0);
|
2005-08-08 14:40:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return op1;
|
|
|
|
}
|
|
|
|
|
2016-07-21 05:42:35 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-04-25 15:12:53 +00:00
|
|
|
rc = http_request_host_normalize(b, 0);
|
2016-07-21 05:42:35 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
%parse_failure {
|
|
|
|
ctx->ok = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
input ::= metalines.
|
|
|
|
metalines ::= metalines metaline.
|
|
|
|
metalines ::= .
|
|
|
|
metaline ::= varline.
|
2006-01-20 08:45:07 +00:00
|
|
|
metaline ::= global.
|
2005-08-08 16:44:25 +00:00
|
|
|
metaline ::= condlines(A) EOL. { A = NULL; }
|
2005-08-08 14:40:47 +00:00
|
|
|
metaline ::= include.
|
2005-08-09 06:42:33 +00:00
|
|
|
metaline ::= include_shell.
|
2005-02-20 14:27:00 +00:00
|
|
|
metaline ::= EOL.
|
|
|
|
|
2005-08-08 16:44:25 +00:00
|
|
|
%type value {data_unset *}
|
|
|
|
%type expression {data_unset *}
|
|
|
|
%type aelement {data_unset *}
|
|
|
|
%type condline {data_config *}
|
2016-10-09 13:20:37 +00:00
|
|
|
%type cond_else {data_config *}
|
2005-08-08 16:44:25 +00:00
|
|
|
%type condlines {data_config *}
|
|
|
|
%type aelements {array *}
|
|
|
|
%type array {array *}
|
|
|
|
%type key {buffer *}
|
2005-08-09 06:42:33 +00:00
|
|
|
%type stringop {buffer *}
|
2005-08-08 16:44:25 +00:00
|
|
|
|
|
|
|
%type cond {config_cond_t }
|
|
|
|
|
2016-02-19 15:49:06 +00:00
|
|
|
%destructor value { if ($$) $$->free($$); }
|
|
|
|
%destructor expression { if ($$) $$->free($$); }
|
|
|
|
%destructor aelement { if ($$) $$->free($$); }
|
2005-08-08 16:44:25 +00:00
|
|
|
%destructor aelements { array_free($$); }
|
|
|
|
%destructor array { array_free($$); }
|
|
|
|
%destructor key { buffer_free($$); }
|
2005-08-09 06:42:33 +00:00
|
|
|
%destructor stringop { buffer_free($$); }
|
2005-08-08 16:44:25 +00:00
|
|
|
|
|
|
|
%token_type {buffer *}
|
|
|
|
%token_destructor { buffer_free($$); }
|
2005-02-20 14:27:00 +00:00
|
|
|
|
2005-08-08 14:40:47 +00:00
|
|
|
varline ::= key(A) ASSIGN expression(B). {
|
2008-02-25 06:57:32 +00:00
|
|
|
if (ctx->ok) {
|
2015-02-08 12:37:10 +00:00
|
|
|
buffer_copy_buffer(B->key, A);
|
2008-02-25 06:57:32 +00:00
|
|
|
if (strncmp(A->ptr, "env.", sizeof("env.") - 1) == 0) {
|
|
|
|
fprintf(stderr, "Setting env variable is not supported in conditional %d %s: %s\n",
|
|
|
|
ctx->current->context_ndx,
|
|
|
|
ctx->current->key->ptr, A->ptr);
|
|
|
|
ctx->ok = 0;
|
|
|
|
} else if (NULL == array_get_element(ctx->current->value, B->key->ptr)) {
|
|
|
|
array_insert_unique(ctx->current->value, B);
|
|
|
|
B = NULL;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Duplicate config variable in conditional %d %s: %s\n",
|
|
|
|
ctx->current->context_ndx,
|
|
|
|
ctx->current->key->ptr, B->key->ptr);
|
|
|
|
ctx->ok = 0;
|
|
|
|
B->free(B);
|
|
|
|
B = NULL;
|
|
|
|
}
|
2005-04-14 21:20:29 +00:00
|
|
|
}
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer_free(A);
|
2005-08-08 16:44:25 +00:00
|
|
|
A = NULL;
|
2005-02-20 14:27:00 +00:00
|
|
|
}
|
|
|
|
|
2017-03-23 04:11:27 +00:00
|
|
|
varline ::= key(A) FORCE_ASSIGN expression(B). {
|
|
|
|
if (ctx->ok) {
|
|
|
|
if (strncmp(A->ptr, "env.", sizeof("env.") - 1) == 0) {
|
|
|
|
fprintf(stderr, "Setting env variable is not supported in conditional %d %s: %s\n",
|
|
|
|
ctx->current->context_ndx,
|
|
|
|
ctx->current->key->ptr, A->ptr);
|
|
|
|
ctx->ok = 0;
|
|
|
|
} else {
|
|
|
|
buffer_copy_buffer(B->key, A);
|
|
|
|
array_replace(ctx->current->value, B);
|
|
|
|
B = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buffer_free(A);
|
|
|
|
A = NULL;
|
|
|
|
}
|
|
|
|
|
2005-08-08 14:40:47 +00:00
|
|
|
varline ::= key(A) APPEND expression(B). {
|
2016-02-19 15:49:06 +00:00
|
|
|
if (ctx->ok) {
|
|
|
|
array *vars = ctx->current->value;
|
|
|
|
data_unset *du;
|
2005-08-08 14:40:47 +00:00
|
|
|
|
2016-02-19 15:49:06 +00:00
|
|
|
if (strncmp(A->ptr, "env.", sizeof("env.") - 1) == 0) {
|
|
|
|
fprintf(stderr, "Appending env variable is not supported in conditional %d %s: %s\n",
|
|
|
|
ctx->current->context_ndx,
|
|
|
|
ctx->current->key->ptr, A->ptr);
|
2005-08-23 14:35:01 +00:00
|
|
|
ctx->ok = 0;
|
2016-03-15 18:56:02 +00:00
|
|
|
} else if (NULL != (du = array_extract_element(vars, A->ptr)) || NULL != (du = configparser_get_variable(ctx, A))) {
|
2016-02-19 15:49:06 +00:00
|
|
|
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);
|
2005-08-23 14:35:01 +00:00
|
|
|
}
|
2016-02-19 15:49:06 +00:00
|
|
|
buffer_free(A);
|
|
|
|
A = NULL;
|
|
|
|
B = NULL;
|
2005-08-08 14:40:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
key(A) ::= LKEY(B). {
|
2005-08-08 14:40:47 +00:00
|
|
|
if (strchr(B->ptr, '.') == NULL) {
|
|
|
|
A = buffer_init_string("var.");
|
|
|
|
buffer_append_string_buffer(A, B);
|
2005-08-08 16:44:25 +00:00
|
|
|
buffer_free(B);
|
|
|
|
B = NULL;
|
|
|
|
} else {
|
2005-08-08 14:40:47 +00:00
|
|
|
A = B;
|
|
|
|
B = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
expression(A) ::= expression(B) PLUS value(C). {
|
2016-02-19 15:49:06 +00:00
|
|
|
A = NULL;
|
|
|
|
if (ctx->ok) {
|
|
|
|
A = configparser_merge_data(B, C);
|
|
|
|
if (NULL == A) {
|
|
|
|
ctx->ok = 0;
|
|
|
|
}
|
|
|
|
B = NULL;
|
|
|
|
C->free(C);
|
|
|
|
C = NULL;
|
2005-08-23 14:35:01 +00:00
|
|
|
}
|
2005-08-08 14:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expression(A) ::= value(B). {
|
2005-02-20 14:27:00 +00:00
|
|
|
A = B;
|
|
|
|
B = NULL;
|
|
|
|
}
|
|
|
|
|
2005-08-08 14:40:47 +00:00
|
|
|
value(A) ::= key(B). {
|
2007-09-06 21:19:25 +00:00
|
|
|
A = NULL;
|
2016-02-19 15:49:06 +00:00
|
|
|
if (ctx->ok) {
|
|
|
|
if (strncmp(B->ptr, "env.", sizeof("env.") - 1) == 0) {
|
|
|
|
char *env;
|
|
|
|
|
|
|
|
if (NULL != (env = getenv(B->ptr + 4))) {
|
|
|
|
data_string *ds;
|
|
|
|
ds = data_string_init();
|
|
|
|
buffer_append_string(ds->value, env);
|
|
|
|
A = (data_unset *)ds;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
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);
|
2006-09-07 10:19:29 +00:00
|
|
|
ctx->ok = 0;
|
|
|
|
}
|
2016-02-19 15:49:06 +00:00
|
|
|
buffer_free(B);
|
|
|
|
B = NULL;
|
2005-08-08 14:40:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
value(A) ::= STRING(B). {
|
|
|
|
A = (data_unset *)data_string_init();
|
2015-02-08 12:37:10 +00:00
|
|
|
buffer_copy_buffer(((data_string *)(A))->value, B);
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer_free(B);
|
2005-08-08 16:44:25 +00:00
|
|
|
B = NULL;
|
2005-02-20 14:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
value(A) ::= INTEGER(B). {
|
2016-03-26 10:58:49 +00:00
|
|
|
char *endptr;
|
2005-02-20 14:27:00 +00:00
|
|
|
A = (data_unset *)data_integer_init();
|
2016-03-26 10:58:49 +00:00
|
|
|
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;
|
|
|
|
}
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer_free(B);
|
2005-08-08 16:44:25 +00:00
|
|
|
B = NULL;
|
2005-02-20 14:27:00 +00:00
|
|
|
}
|
|
|
|
value(A) ::= array(B). {
|
|
|
|
A = (data_unset *)data_array_init();
|
|
|
|
array_free(((data_array *)(A))->value);
|
|
|
|
((data_array *)(A))->value = B;
|
2005-08-08 16:44:25 +00:00
|
|
|
B = NULL;
|
2005-02-20 14:27:00 +00:00
|
|
|
}
|
2006-09-23 07:15:07 +00:00
|
|
|
array(A) ::= LPARAN RPARAN. {
|
|
|
|
A = array_init();
|
|
|
|
}
|
2005-02-20 14:27:00 +00:00
|
|
|
array(A) ::= LPARAN aelements(B) RPARAN. {
|
|
|
|
A = B;
|
|
|
|
B = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
aelements(A) ::= aelements(C) COMMA aelement(B). {
|
2016-02-19 15:49:06 +00:00
|
|
|
A = NULL;
|
|
|
|
if (ctx->ok) {
|
|
|
|
if (buffer_is_empty(B->key) ||
|
|
|
|
NULL == array_get_element(C, B->key->ptr)) {
|
|
|
|
array_insert_unique(C, B);
|
|
|
|
B = NULL;
|
|
|
|
} else {
|
2016-02-23 17:05:10 +00:00
|
|
|
fprintf(stderr, "Error: duplicate array-key: %s. Please get rid of the duplicate entry.\n",
|
2016-02-19 15:49:06 +00:00
|
|
|
B->key->ptr);
|
|
|
|
ctx->ok = 0;
|
|
|
|
B->free(B);
|
|
|
|
B = NULL;
|
|
|
|
}
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2016-02-19 15:49:06 +00:00
|
|
|
A = C;
|
|
|
|
C = NULL;
|
|
|
|
}
|
2005-02-20 14:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aelements(A) ::= aelements(C) COMMA. {
|
|
|
|
A = C;
|
2005-08-08 16:44:25 +00:00
|
|
|
C = NULL;
|
2005-02-20 14:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aelements(A) ::= aelement(B). {
|
2016-02-19 15:49:06 +00:00
|
|
|
A = NULL;
|
|
|
|
if (ctx->ok) {
|
|
|
|
A = array_init();
|
|
|
|
array_insert_unique(A, B);
|
|
|
|
B = NULL;
|
|
|
|
}
|
2005-02-20 14:27:00 +00:00
|
|
|
}
|
|
|
|
|
2005-08-08 14:40:47 +00:00
|
|
|
aelement(A) ::= expression(B). {
|
2005-02-20 14:27:00 +00:00
|
|
|
A = B;
|
|
|
|
B = NULL;
|
|
|
|
}
|
2005-09-22 13:45:33 +00:00
|
|
|
aelement(A) ::= stringop(B) ARRAY_ASSIGN expression(C). {
|
2016-02-19 15:49:06 +00:00
|
|
|
A = NULL;
|
|
|
|
if (ctx->ok) {
|
|
|
|
buffer_copy_buffer(C->key, B);
|
|
|
|
buffer_free(B);
|
|
|
|
B = NULL;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2016-02-19 15:49:06 +00:00
|
|
|
A = C;
|
|
|
|
C = NULL;
|
|
|
|
}
|
2005-02-20 14:27:00 +00:00
|
|
|
}
|
2005-08-08 13:48:33 +00:00
|
|
|
|
|
|
|
eols ::= EOL.
|
|
|
|
eols ::= .
|
|
|
|
|
2006-01-20 08:45:07 +00:00
|
|
|
globalstart ::= GLOBAL. {
|
|
|
|
data_config *dc;
|
|
|
|
dc = (data_config *)array_get_element(ctx->srv->config_context, "global");
|
2014-02-16 13:08:20 +00:00
|
|
|
force_assert(dc);
|
2006-01-20 08:45:07 +00:00
|
|
|
configparser_push(ctx, dc, 0);
|
|
|
|
}
|
|
|
|
|
2016-02-19 15:49:06 +00:00
|
|
|
global ::= globalstart LCURLY metalines RCURLY. {
|
|
|
|
force_assert(ctx->current);
|
2006-01-20 08:45:07 +00:00
|
|
|
configparser_pop(ctx);
|
2016-02-19 15:49:06 +00:00
|
|
|
force_assert(ctx->current);
|
2006-01-20 08:45:07 +00:00
|
|
|
}
|
|
|
|
|
2005-08-08 16:34:49 +00:00
|
|
|
condlines(A) ::= condlines(B) eols ELSE condline(C). {
|
2016-02-19 15:49:06 +00:00
|
|
|
A = NULL;
|
|
|
|
if (ctx->ok) {
|
|
|
|
if (B->context_ndx >= C->context_ndx) {
|
|
|
|
fprintf(stderr, "unreachable else condition\n");
|
|
|
|
ctx->ok = 0;
|
|
|
|
}
|
2016-10-09 12:05:26 +00:00
|
|
|
if (B->cond == CONFIG_COND_ELSE) {
|
|
|
|
fprintf(stderr, "unreachable condition following else catch-all\n");
|
|
|
|
ctx->ok = 0;
|
|
|
|
}
|
2016-02-19 15:49:06 +00:00
|
|
|
C->prev = B;
|
|
|
|
B->next = C;
|
|
|
|
A = C;
|
|
|
|
B = NULL;
|
|
|
|
C = NULL;
|
2009-10-12 08:48:08 +00:00
|
|
|
}
|
2005-08-08 13:48:33 +00:00
|
|
|
}
|
|
|
|
|
2016-10-09 13:20:37 +00:00
|
|
|
condlines(A) ::= condlines(B) eols ELSE cond_else(C). {
|
|
|
|
A = NULL;
|
|
|
|
if (ctx->ok) {
|
|
|
|
if (B->context_ndx >= C->context_ndx) {
|
|
|
|
fprintf(stderr, "unreachable else condition\n");
|
|
|
|
ctx->ok = 0;
|
|
|
|
}
|
|
|
|
if (B->cond == CONFIG_COND_ELSE) {
|
|
|
|
fprintf(stderr, "unreachable condition following else catch-all\n");
|
|
|
|
ctx->ok = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ctx->ok) {
|
|
|
|
size_t pos;
|
|
|
|
data_config *dc;
|
|
|
|
dc = (data_config *)array_extract_element(ctx->all_configs, C->key->ptr);
|
|
|
|
force_assert(C == dc);
|
|
|
|
buffer_copy_buffer(C->key, B->key);
|
|
|
|
/*buffer_copy_buffer(C->comp_key, B->comp_key);*/
|
|
|
|
/*C->string = buffer_init_buffer(B->string);*/
|
|
|
|
pos = buffer_string_length(C->key)-buffer_string_length(B->string)-2;
|
|
|
|
switch(B->cond) {
|
|
|
|
case CONFIG_COND_NE:
|
|
|
|
C->key->ptr[pos] = '='; /* opposite cond */
|
|
|
|
/*buffer_copy_string_len(C->op, CONST_STR_LEN("=="));*/
|
|
|
|
break;
|
|
|
|
case CONFIG_COND_EQ:
|
|
|
|
C->key->ptr[pos] = '!'; /* opposite cond */
|
|
|
|
/*buffer_copy_string_len(C->op, CONST_STR_LEN("!="));*/
|
|
|
|
break;
|
|
|
|
case CONFIG_COND_NOMATCH:
|
|
|
|
C->key->ptr[pos] = '='; /* opposite cond */
|
|
|
|
/*buffer_copy_string_len(C->op, CONST_STR_LEN("=~"));*/
|
|
|
|
break;
|
|
|
|
case CONFIG_COND_MATCH:
|
|
|
|
C->key->ptr[pos] = '!'; /* opposite cond */
|
|
|
|
/*buffer_copy_string_len(C->op, CONST_STR_LEN("!~"));*/
|
|
|
|
break;
|
|
|
|
default: /* should not happen; CONFIG_COND_ELSE checked further above */
|
|
|
|
force_assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL == (dc = (data_config *)array_get_element(ctx->all_configs, C->key->ptr))) {
|
|
|
|
/* re-insert into ctx->all_configs with new C->key */
|
|
|
|
array_insert_unique(ctx->all_configs, (data_unset *)C);
|
|
|
|
C->prev = B;
|
|
|
|
B->next = C;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "unreachable else condition\n");
|
|
|
|
ctx->ok = 0;
|
|
|
|
C->free((data_unset *)C);
|
|
|
|
C = dc;
|
|
|
|
}
|
|
|
|
|
|
|
|
A = C;
|
|
|
|
B = NULL;
|
|
|
|
C = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-08 13:48:33 +00:00
|
|
|
condlines(A) ::= condline(B). {
|
|
|
|
A = B;
|
|
|
|
B = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
condline(A) ::= context LCURLY metalines RCURLY. {
|
2016-02-19 15:49:06 +00:00
|
|
|
A = NULL;
|
|
|
|
if (ctx->ok) {
|
|
|
|
data_config *cur;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2016-02-19 15:49:06 +00:00
|
|
|
cur = ctx->current;
|
|
|
|
configparser_pop(ctx);
|
2005-08-08 13:48:33 +00:00
|
|
|
|
2016-02-19 15:49:06 +00:00
|
|
|
force_assert(cur && ctx->current);
|
2005-08-08 13:48:33 +00:00
|
|
|
|
2016-02-19 15:49:06 +00:00
|
|
|
A = cur;
|
|
|
|
}
|
2005-02-20 14:27:00 +00:00
|
|
|
}
|
|
|
|
|
2016-10-09 13:20:37 +00:00
|
|
|
cond_else(A) ::= context_else LCURLY metalines RCURLY. {
|
|
|
|
A = NULL;
|
|
|
|
if (ctx->ok) {
|
|
|
|
data_config *cur;
|
|
|
|
|
|
|
|
cur = ctx->current;
|
|
|
|
configparser_pop(ctx);
|
|
|
|
|
|
|
|
force_assert(cur && ctx->current);
|
|
|
|
|
|
|
|
A = cur;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-22 13:45:33 +00:00
|
|
|
context ::= DOLLAR SRVVARNAME(B) LBRACKET stringop(C) RBRACKET cond(E) expression(D). {
|
2005-02-20 14:27:00 +00:00
|
|
|
data_config *dc;
|
2005-08-08 17:25:55 +00:00
|
|
|
buffer *b, *rvalue, *op;
|
2005-08-08 14:40:47 +00:00
|
|
|
|
|
|
|
if (ctx->ok && D->type != TYPE_STRING) {
|
|
|
|
fprintf(stderr, "rvalue must be string");
|
|
|
|
ctx->ok = 0;
|
|
|
|
}
|
|
|
|
|
2016-02-19 15:49:06 +00:00
|
|
|
if (ctx->ok) {
|
2005-02-20 14:27:00 +00:00
|
|
|
switch(E) {
|
|
|
|
case CONFIG_COND_NE:
|
2016-02-19 15:49:06 +00:00
|
|
|
op = buffer_init_string("!=");
|
|
|
|
break;
|
2005-02-20 14:27:00 +00:00
|
|
|
case CONFIG_COND_EQ:
|
2016-02-19 15:49:06 +00:00
|
|
|
op = buffer_init_string("==");
|
2005-02-20 14:27:00 +00:00
|
|
|
break;
|
|
|
|
case CONFIG_COND_NOMATCH:
|
2016-02-19 15:49:06 +00:00
|
|
|
op = buffer_init_string("!~");
|
|
|
|
break;
|
|
|
|
case CONFIG_COND_MATCH:
|
|
|
|
op = buffer_init_string("=~");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
force_assert(0);
|
|
|
|
return; /* unreachable */
|
|
|
|
}
|
2005-08-08 14:40:47 +00:00
|
|
|
|
2016-02-19 15:49:06 +00:00
|
|
|
b = buffer_init();
|
|
|
|
buffer_copy_buffer(b, ctx->current->key);
|
|
|
|
buffer_append_string(b, "/");
|
|
|
|
buffer_append_string_buffer(b, B);
|
|
|
|
buffer_append_string_buffer(b, C);
|
|
|
|
buffer_append_string_buffer(b, op);
|
|
|
|
rvalue = ((data_string*)D)->value;
|
|
|
|
buffer_append_string_buffer(b, rvalue);
|
|
|
|
|
|
|
|
if (NULL != (dc = (data_config *)array_get_element(ctx->all_configs, b->ptr))) {
|
|
|
|
configparser_push(ctx, dc, 0);
|
|
|
|
} else {
|
|
|
|
static const struct {
|
|
|
|
comp_key_t comp;
|
|
|
|
char *comp_key;
|
|
|
|
size_t len;
|
|
|
|
} comps[] = {
|
|
|
|
{ COMP_SERVER_SOCKET, CONST_STR_LEN("SERVER[\"socket\"]" ) },
|
|
|
|
{ COMP_HTTP_URL, CONST_STR_LEN("HTTP[\"url\"]" ) },
|
|
|
|
{ COMP_HTTP_HOST, CONST_STR_LEN("HTTP[\"host\"]" ) },
|
2017-01-20 14:59:21 +00:00
|
|
|
{ COMP_HTTP_REQUEST_HEADER,CONST_STR_LEN("HTTP[\"referer\"]" ) },
|
2016-02-19 15:49:06 +00:00
|
|
|
{ COMP_HTTP_USER_AGENT, CONST_STR_LEN("HTTP[\"useragent\"]" ) },
|
2017-01-20 14:59:21 +00:00
|
|
|
{ COMP_HTTP_REQUEST_HEADER,CONST_STR_LEN("HTTP[\"user-agent\"]" ) },
|
2016-02-19 15:49:06 +00:00
|
|
|
{ COMP_HTTP_LANGUAGE, CONST_STR_LEN("HTTP[\"language\"]" ) },
|
2017-01-20 14:59:21 +00:00
|
|
|
{ COMP_HTTP_REQUEST_HEADER,CONST_STR_LEN("HTTP[\"cookie\"]" ) },
|
2016-02-19 15:49:06 +00:00
|
|
|
{ COMP_HTTP_REMOTE_IP, CONST_STR_LEN("HTTP[\"remoteip\"]" ) },
|
|
|
|
{ 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[\"query-string\"]") },
|
|
|
|
{ COMP_HTTP_REQUEST_METHOD, CONST_STR_LEN("HTTP[\"request-method\"]") },
|
|
|
|
{ COMP_HTTP_SCHEME, CONST_STR_LEN("HTTP[\"scheme\"]" ) },
|
|
|
|
{ COMP_UNSET, NULL, 0 },
|
|
|
|
};
|
|
|
|
size_t i;
|
2005-08-08 14:40:47 +00:00
|
|
|
|
2016-02-19 15:49:06 +00:00
|
|
|
dc = data_config_init();
|
|
|
|
|
|
|
|
buffer_copy_buffer(dc->key, b);
|
|
|
|
buffer_copy_buffer(dc->op, op);
|
2017-01-20 14:59:21 +00:00
|
|
|
buffer_copy_buffer(dc->comp_tag, C);
|
2016-02-19 15:49:06 +00:00
|
|
|
buffer_copy_buffer(dc->comp_key, B);
|
|
|
|
buffer_append_string_len(dc->comp_key, CONST_STR_LEN("[\""));
|
|
|
|
buffer_append_string_buffer(dc->comp_key, C);
|
|
|
|
buffer_append_string_len(dc->comp_key, CONST_STR_LEN("\"]"));
|
|
|
|
dc->cond = E;
|
|
|
|
|
|
|
|
for (i = 0; comps[i].comp_key; i ++) {
|
|
|
|
if (buffer_is_equal_string(
|
|
|
|
dc->comp_key, comps[i].comp_key, comps[i].len)) {
|
|
|
|
dc->comp = comps[i].comp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (COMP_UNSET == dc->comp) {
|
2017-01-20 14:59:21 +00:00
|
|
|
if (buffer_is_equal_string(B, CONST_STR_LEN("REQUEST_HEADER"))) {
|
|
|
|
dc->comp = COMP_HTTP_REQUEST_HEADER;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "error comp_key %s", dc->comp_key->ptr);
|
|
|
|
ctx->ok = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (COMP_HTTP_LANGUAGE == dc->comp) {
|
|
|
|
dc->comp = COMP_HTTP_REQUEST_HEADER;
|
|
|
|
buffer_copy_string_len(dc->comp_tag, CONST_STR_LEN("Accept-Language"));
|
|
|
|
}
|
|
|
|
else if (COMP_HTTP_USER_AGENT == dc->comp) {
|
|
|
|
dc->comp = COMP_HTTP_REQUEST_HEADER;
|
|
|
|
buffer_copy_string_len(dc->comp_tag, CONST_STR_LEN("User-Agent"));
|
2016-02-19 15:49:06 +00:00
|
|
|
}
|
2016-05-19 23:15:47 +00:00
|
|
|
else if (COMP_HTTP_REMOTE_IP == dc->comp
|
|
|
|
&& (dc->cond == CONFIG_COND_EQ || dc->cond == CONFIG_COND_NE)) {
|
2016-07-21 05:42:35 +00:00
|
|
|
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) {
|
2016-05-19 23:15:47 +00:00
|
|
|
char *nptr;
|
|
|
|
const unsigned long nm_bits = strtoul(slash + 1, &nptr, 10);
|
2016-07-21 05:42:35 +00:00
|
|
|
if (*nptr || 0 == nm_bits || nm_bits > (NULL != colon ? 128 : 32)) {
|
2016-05-19 23:15:47 +00:00
|
|
|
/*(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;
|
2016-05-23 18:12:24 +00:00
|
|
|
buffer_string_set_length(rvalue, (size_t)(slash - rvalue->ptr)); /*(truncate)*/
|
2016-07-21 05:42:35 +00:00
|
|
|
rc = (NULL == colon)
|
2017-04-25 15:12:53 +00:00
|
|
|
? http_request_host_normalize(rvalue, 0)
|
2016-07-21 05:42:35 +00:00
|
|
|
: configparser_remoteip_normalize_compat(rvalue);
|
2016-05-19 23:15:47 +00:00
|
|
|
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 {
|
2016-07-21 05:42:35 +00:00
|
|
|
int rc = (NULL == colon)
|
2017-04-25 15:12:53 +00:00
|
|
|
? http_request_host_normalize(rvalue, 0)
|
2016-07-21 05:42:35 +00:00
|
|
|
: configparser_remoteip_normalize_compat(rvalue);
|
|
|
|
if (0 != rc) {
|
2016-05-19 23:15:47 +00:00
|
|
|
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] == ']')) {
|
2017-04-25 15:12:53 +00:00
|
|
|
if (http_request_host_normalize(rvalue, 0)) {
|
2016-05-19 23:15:47 +00:00
|
|
|
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) {
|
2017-04-25 15:12:53 +00:00
|
|
|
if (http_request_host_normalize(rvalue, 0)) {
|
2016-05-19 23:15:47 +00:00
|
|
|
fprintf(stderr, "invalid IP addr: %s\n", rvalue->ptr);
|
|
|
|
ctx->ok = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx->ok) switch(E) {
|
2016-02-19 15:49:06 +00:00
|
|
|
case CONFIG_COND_NE:
|
|
|
|
case CONFIG_COND_EQ:
|
|
|
|
dc->string = buffer_init_buffer(rvalue);
|
|
|
|
break;
|
|
|
|
case CONFIG_COND_NOMATCH:
|
|
|
|
case CONFIG_COND_MATCH: {
|
|
|
|
#ifdef HAVE_PCRE_H
|
|
|
|
const char *errptr;
|
|
|
|
int erroff, captures;
|
|
|
|
|
|
|
|
if (NULL == (dc->regex =
|
|
|
|
pcre_compile(rvalue->ptr, 0, &errptr, &erroff, NULL))) {
|
|
|
|
dc->string = buffer_init_string(errptr);
|
|
|
|
dc->cond = CONFIG_COND_UNSET;
|
|
|
|
|
|
|
|
fprintf(stderr, "parsing regex failed: %s -> %s at offset %d\n",
|
|
|
|
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);
|
2009-08-28 19:30:48 +00:00
|
|
|
ctx->ok = 0;
|
2016-02-19 15:49:06 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "unknown condition for $%s[%s]\n",
|
|
|
|
B->ptr, C->ptr);
|
2009-08-28 19:30:48 +00:00
|
|
|
ctx->ok = 0;
|
2016-02-19 15:49:06 +00:00
|
|
|
break;
|
2005-02-20 14:27:00 +00:00
|
|
|
}
|
2005-08-08 13:48:33 +00:00
|
|
|
|
2016-03-26 13:57:03 +00:00
|
|
|
if (ctx->ok) {
|
|
|
|
configparser_push(ctx, dc, 1);
|
|
|
|
} else {
|
|
|
|
dc->free((data_unset*) dc);
|
|
|
|
}
|
2005-02-20 14:27:00 +00:00
|
|
|
}
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2016-02-19 15:49:06 +00:00
|
|
|
buffer_free(b);
|
|
|
|
buffer_free(op);
|
|
|
|
buffer_free(B);
|
|
|
|
B = NULL;
|
|
|
|
buffer_free(C);
|
|
|
|
C = NULL;
|
|
|
|
D->free(D);
|
|
|
|
D = NULL;
|
2005-02-20 14:27:00 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-09 12:05:26 +00:00
|
|
|
|
2016-10-09 13:20:37 +00:00
|
|
|
context_else ::= . {
|
2016-10-09 12:05:26 +00:00
|
|
|
if (ctx->ok) {
|
|
|
|
data_config *dc = data_config_init();
|
|
|
|
buffer_copy_buffer(dc->key, ctx->current->key);
|
|
|
|
buffer_append_string_len(dc->key, CONST_STR_LEN("/"));
|
2016-10-09 13:20:37 +00:00
|
|
|
buffer_append_string_len(dc->key, CONST_STR_LEN("else_tmp_token"));
|
2016-10-09 12:05:26 +00:00
|
|
|
dc->cond = CONFIG_COND_ELSE;
|
2016-10-09 13:20:37 +00:00
|
|
|
configparser_push(ctx, dc, 1);
|
2016-10-09 12:05:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
cond(A) ::= EQ. {
|
|
|
|
A = CONFIG_COND_EQ;
|
|
|
|
}
|
|
|
|
cond(A) ::= MATCH. {
|
|
|
|
A = CONFIG_COND_MATCH;
|
|
|
|
}
|
|
|
|
cond(A) ::= NE. {
|
|
|
|
A = CONFIG_COND_NE;
|
|
|
|
}
|
|
|
|
cond(A) ::= NOMATCH. {
|
|
|
|
A = CONFIG_COND_NOMATCH;
|
|
|
|
}
|
2005-08-08 14:40:47 +00:00
|
|
|
|
2005-08-09 06:42:33 +00:00
|
|
|
stringop(A) ::= expression(B). {
|
|
|
|
A = NULL;
|
2005-08-08 14:40:47 +00:00
|
|
|
if (ctx->ok) {
|
2005-09-22 13:45:33 +00:00
|
|
|
if (B->type == TYPE_STRING) {
|
|
|
|
A = buffer_init_buffer(((data_string*)B)->value);
|
|
|
|
} else if (B->type == TYPE_INTEGER) {
|
|
|
|
A = buffer_init();
|
2015-02-08 12:37:10 +00:00
|
|
|
buffer_copy_int(A, ((data_integer *)B)->value);
|
2005-09-22 13:45:33 +00:00
|
|
|
} else {
|
2005-08-09 06:42:33 +00:00
|
|
|
fprintf(stderr, "operand must be string");
|
2005-08-08 14:40:47 +00:00
|
|
|
ctx->ok = 0;
|
|
|
|
}
|
|
|
|
}
|
2005-08-09 06:42:33 +00:00
|
|
|
B->free(B);
|
|
|
|
B = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
include ::= INCLUDE stringop(A). {
|
|
|
|
if (ctx->ok) {
|
|
|
|
if (0 != config_parse_file(ctx->srv, ctx, A->ptr)) {
|
|
|
|
ctx->ok = 0;
|
|
|
|
}
|
|
|
|
buffer_free(A);
|
|
|
|
A = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
include_shell ::= INCLUDE_SHELL stringop(A). {
|
|
|
|
if (ctx->ok) {
|
|
|
|
if (0 != config_parse_cmd(ctx->srv, ctx, A->ptr)) {
|
|
|
|
ctx->ok = 0;
|
|
|
|
}
|
|
|
|
buffer_free(A);
|
|
|
|
A = NULL;
|
|
|
|
}
|
2005-08-08 14:40:47 +00:00
|
|
|
}
|