summaryrefslogtreecommitdiff
path: root/src/configparser.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/configparser.c')
-rw-r--r--src/configparser.c969
1 files changed, 531 insertions, 438 deletions
diff --git a/src/configparser.c b/src/configparser.c
index 2ce169a..a13d729 100644
--- a/src/configparser.c
+++ b/src/configparser.c
@@ -4,18 +4,16 @@
/* First off, code is include which follows the "include" declaration
** in the input file. */
#include <stdio.h>
-#line 5 "./configparser.y"
+#line 5 "../../src/configparser.y"
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
#include "configfile.h"
#include "buffer.h"
#include "array.h"
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+
static void configparser_push(config_t *ctx, data_config *dc, int isnew) {
if (isnew) {
dc->context_ndx = ctx->all_configs->used;
@@ -24,6 +22,10 @@ static void configparser_push(config_t *ctx, data_config *dc, int isnew) {
dc->parent = ctx->current;
array_insert_unique(dc->parent->childs, (data_unset *)dc);
}
+ if (ctx->configs_stack->used > 0 && ctx->current->context_ndx == 0) {
+ fprintf(stderr, "Cannot use conditionals inside a global { ... } block\n");
+ exit(-1);
+ }
array_insert_unique(ctx->configs_stack, (data_unset *)ctx->current);
ctx->current = dc;
}
@@ -36,43 +38,25 @@ static data_config *configparser_pop(config_t *ctx) {
/* return a copied variable */
static data_unset *configparser_get_variable(config_t *ctx, const buffer *key) {
- if (strncmp(key->ptr, "env.", sizeof("env.") - 1) == 0) {
- char *env;
-
- if (NULL != (env = getenv(key->ptr + 4))) {
- data_string *ds;
- ds = data_string_init();
- buffer_append_string(ds->value, env);
- return (data_unset *)ds;
- }
-
- fprintf(stderr, "Undefined env variable: %s\n", key->ptr + 4);
- ctx->ok = 0;
-
- return NULL;
- } else {
- data_unset *du;
- data_config *dc;
+ data_unset *du;
+ data_config *dc;
#if 0
- fprintf(stderr, "get var %s\n", key->ptr);
+ fprintf(stderr, "get var %s\n", key->ptr);
#endif
- for (dc = ctx->current; dc; dc = dc->parent) {
+ for (dc = ctx->current; dc; dc = dc->parent) {
#if 0
- fprintf(stderr, "get var on block: %s\n", dc->key->ptr);
- array_print(dc->value, 0);
+ fprintf(stderr, "get var on block: %s\n", dc->key->ptr);
+ array_print(dc->value, 0);
#endif
- if (NULL != (du = array_get_element(dc->value, key->ptr))) {
- return du->copy(du);
- }
+ if (NULL != (du = array_get_element(dc->value, key->ptr))) {
+ return du->copy(du);
}
- fprintf(stderr, "Undefined config variable: %s\n", key->ptr);
- ctx->ok = 0;
- return NULL;
}
+ return NULL;
}
-/* op1 is to be eat/return by this function, op1->key is not cared
+/* op1 is to be eat/return by this function if success, op1->key is not cared
op2 is left untouch, unreferenced
*/
data_unset *configparser_merge_data(data_unset *op1, const data_unset *op2) {
@@ -89,8 +73,7 @@ data_unset *configparser_merge_data(data_unset *op1, const data_unset *op2) {
op1->free(op1);
return (data_unset *)ds;
} else {
- fprintf(stderr, "data type mismatch, cannot be merge\n");
- op1->free(op1);
+ fprintf(stderr, "data type mismatch, cannot merge\n");
return NULL;
}
}
@@ -124,14 +107,14 @@ data_unset *configparser_merge_data(data_unset *op1, const data_unset *op2) {
}
-#line 128 "configparser.c"
+#line 111 "configparser.c"
/* Next is all token values, in a form suitable for use by makeheaders.
** This section will be null unless lemon is run with the -m switch.
*/
-/*
+/*
** These constants (all generated automatically by the parser generator)
** specify the various kinds of tokens (terminals) that the parser
-** understands.
+** understands.
**
** Each symbol here is a terminal symbol in the grammar.
*/
@@ -148,7 +131,7 @@ data_unset *configparser_merge_data(data_unset *op1, const data_unset *op2) {
** and nonterminals. "int" is used otherwise.
** YYNOCODE is a number of type YYCODETYPE which corresponds
** to no legal terminal or nonterminal number. This
-** number is used to fill in empty slots of the hash
+** number is used to fill in empty slots of the hash
** table.
** YYFALLBACK If defined, this indicates that one or more tokens
** have fall-back values which should be used if the
@@ -157,7 +140,7 @@ data_unset *configparser_merge_data(data_unset *op1, const data_unset *op2) {
** and nonterminal numbers. "unsigned char" is
** used if there are fewer than 250 rules and
** states combined. "int" is used otherwise.
-** configparserTOKENTYPE is the data type used for minor tokens given
+** configparserTOKENTYPE is the data type used for minor tokens given
** directly to the parser from the tokenizer.
** YYMINORTYPE is the data type used for all minor tokens.
** This is typically a union of many types, one of
@@ -175,27 +158,27 @@ data_unset *configparser_merge_data(data_unset *op1, const data_unset *op2) {
*/
/*  */
#define YYCODETYPE unsigned char
-#define YYNOCODE 45
+#define YYNOCODE 48
#define YYACTIONTYPE unsigned char
#define configparserTOKENTYPE buffer *
typedef union {
configparserTOKENTYPE yy0;
- buffer * yy1;
- config_cond_t yy29;
- data_unset * yy43;
- data_config * yy74;
- array * yy78;
- int yy89;
+ config_cond_t yy27;
+ array * yy40;
+ data_unset * yy41;
+ buffer * yy43;
+ data_config * yy78;
+ int yy95;
} YYMINORTYPE;
#define YYSTACKDEPTH 100
#define configparserARG_SDECL config_t *ctx;
#define configparserARG_PDECL ,config_t *ctx
#define configparserARG_FETCH config_t *ctx = yypParser->ctx
#define configparserARG_STORE yypParser->ctx = ctx
-#define YYNSTATE 56
-#define YYNRULE 36
-#define YYERRORSYMBOL 25
-#define YYERRSYMDT yy89
+#define YYNSTATE 63
+#define YYNRULE 40
+#define YYERRORSYMBOL 26
+#define YYERRSYMDT yy95
#define YY_NO_ACTION (YYNSTATE+YYNRULE+2)
#define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1)
#define YY_ERROR_ACTION (YYNSTATE+YYNRULE)
@@ -203,7 +186,7 @@ typedef union {
/* Next are that tables used to determine what action to take based on the
** current state and lookahead token. These tables are used to implement
** functions that take a state number and lookahead value and return an
-** action integer.
+** action integer.
**
** Suppose the action integer is N. Then the action is determined as
** follows
@@ -228,7 +211,7 @@ typedef union {
** If the index value yy_shift_ofst[S]+X is out of range or if the value
** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S]
** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
-** and that yy_default[S] should be used instead.
+** and that yy_default[S] should be used instead.
**
** The formula above is for computing the action when the lookahead is
** a terminal symbol. If the lookahead is a non-terminal (as occurs after
@@ -248,62 +231,69 @@ typedef union {
** yy_default[] Default action for each state.
*/
static YYACTIONTYPE yy_action[] = {
- /* 0 */ 2, 3, 4, 12, 13, 56, 14, 6, 38, 19,
- /* 10 */ 79, 15, 27, 26, 35, 9, 28, 24, 21, 32,
- /* 20 */ 40, 14, 93, 1, 19, 27, 26, 31, 52, 54,
- /* 30 */ 24, 21, 32, 7, 39, 40, 48, 49, 50, 51,
- /* 40 */ 27, 43, 18, 52, 54, 24, 21, 44, 27, 43,
- /* 50 */ 84, 27, 43, 24, 21, 53, 24, 21, 55, 19,
- /* 60 */ 40, 22, 23, 25, 27, 17, 27, 34, 33, 24,
- /* 70 */ 21, 24, 21, 5, 27, 37, 10, 27, 47, 24,
- /* 80 */ 21, 20, 24, 21, 80, 8, 24, 21, 16, 36,
- /* 90 */ 18, 11, 9, 29, 30, 18, 89, 41, 45, 42,
- /* 100 */ 46,
+ /* 0 */ 2, 3, 4, 5, 13, 14, 63, 15, 7, 45,
+ /* 10 */ 20, 88, 16, 46, 28, 49, 41, 10, 40, 25,
+ /* 20 */ 22, 50, 46, 8, 15, 104, 1, 20, 28, 18,
+ /* 30 */ 58, 60, 6, 25, 22, 40, 47, 62, 11, 46,
+ /* 40 */ 20, 9, 23, 24, 26, 29, 89, 58, 60, 10,
+ /* 50 */ 17, 38, 28, 27, 37, 19, 30, 25, 22, 34,
+ /* 60 */ 15, 100, 20, 20, 23, 24, 26, 12, 19, 31,
+ /* 70 */ 32, 40, 19, 44, 43, 46, 95, 35, 90, 89,
+ /* 80 */ 28, 49, 42, 58, 60, 25, 22, 59, 28, 27,
+ /* 90 */ 33, 48, 52, 25, 22, 34, 28, 49, 51, 28,
+ /* 100 */ 36, 25, 22, 61, 25, 22, 89, 28, 39, 89,
+ /* 110 */ 89, 89, 25, 22, 54, 55, 56, 57, 89, 28,
+ /* 120 */ 53, 21, 89, 89, 25, 22, 25, 22,
};
static YYCODETYPE yy_lookahead[] = {
- /* 0 */ 28, 29, 30, 31, 32, 0, 1, 42, 36, 4,
- /* 10 */ 12, 39, 33, 34, 35, 43, 37, 38, 39, 40,
- /* 20 */ 15, 1, 26, 27, 4, 33, 34, 35, 23, 24,
- /* 30 */ 38, 39, 40, 12, 14, 15, 19, 20, 21, 22,
- /* 40 */ 33, 34, 5, 23, 24, 38, 39, 40, 33, 34,
- /* 50 */ 13, 33, 34, 38, 39, 40, 38, 39, 40, 4,
- /* 60 */ 15, 6, 7, 8, 33, 34, 33, 34, 11, 38,
- /* 70 */ 39, 38, 39, 1, 33, 34, 13, 33, 34, 38,
- /* 80 */ 39, 33, 38, 39, 12, 36, 38, 39, 2, 3,
- /* 90 */ 5, 27, 43, 9, 10, 5, 11, 16, 18, 17,
- /* 100 */ 41,
+ /* 0 */ 29, 30, 31, 32, 33, 34, 0, 1, 44, 38,
+ /* 10 */ 4, 15, 41, 16, 35, 36, 45, 46, 12, 40,
+ /* 20 */ 41, 42, 16, 15, 1, 27, 28, 4, 35, 36,
+ /* 30 */ 24, 25, 1, 40, 41, 12, 17, 14, 13, 16,
+ /* 40 */ 4, 38, 6, 7, 8, 9, 15, 24, 25, 46,
+ /* 50 */ 2, 3, 35, 36, 37, 5, 39, 40, 41, 42,
+ /* 60 */ 1, 11, 4, 4, 6, 7, 8, 28, 5, 9,
+ /* 70 */ 10, 12, 5, 14, 28, 16, 13, 11, 13, 47,
+ /* 80 */ 35, 36, 13, 24, 25, 40, 41, 42, 35, 36,
+ /* 90 */ 37, 18, 43, 40, 41, 42, 35, 36, 19, 35,
+ /* 100 */ 36, 40, 41, 42, 40, 41, 47, 35, 36, 47,
+ /* 110 */ 47, 47, 40, 41, 20, 21, 22, 23, 47, 35,
+ /* 120 */ 36, 35, 47, 47, 40, 41, 40, 41,
};
-#define YY_SHIFT_USE_DFLT (-3)
+#define YY_SHIFT_USE_DFLT (-5)
static signed char yy_shift_ofst[] = {
- /* 0 */ -3, 5, -3, -3, 72, -2, 21, 45, -3, 63,
- /* 10 */ -3, 20, -3, -3, -3, 86, 55, 90, 55, -3,
- /* 20 */ -3, -3, -3, -3, -3, 55, 85, -3, 84, -3,
- /* 30 */ 55, -3, 57, 55, 90, -3, 55, 90, -3, -3,
- /* 40 */ 81, 82, 55, 90, 80, 17, 55, 37, -3, -3,
- /* 50 */ -3, -3, 55, -3, 55, -3,
+ /* 0 */ -5, 6, -5, -5, -5, 31, -4, 8, -3, -5,
+ /* 10 */ 25, -5, 23, -5, -5, -5, 48, 58, 67, 58,
+ /* 20 */ -5, -5, -5, -5, -5, -5, 36, 50, -5, -5,
+ /* 30 */ 60, -5, 58, -5, 66, 58, 67, -5, 58, 67,
+ /* 40 */ 65, 69, -5, 59, -5, -5, 19, 73, 58, 67,
+ /* 50 */ 79, 94, 58, 63, -5, -5, -5, -5, 58, -5,
+ /* 60 */ 58, -5, -5,
};
-#define YY_REDUCE_USE_DFLT (-36)
+#define YY_REDUCE_USE_DFLT (-37)
static signed char yy_reduce_ofst[] = {
- /* 0 */ -4, -28, -36, -36, -35, -36, -36, 49, -36, -36,
- /* 10 */ 64, -28, -36, -36, -36, -36, 31, -36, 48, -36,
- /* 20 */ -36, -36, -36, -36, -36, -21, -36, -36, -36, -36,
- /* 30 */ -8, -36, -36, 33, -36, -36, 41, -36, -36, -36,
- /* 40 */ -36, -36, 7, -36, -36, 59, 44, -36, -36, -36,
- /* 50 */ -36, -36, 15, -36, 18, -36,
+ /* 0 */ -2, -29, -37, -37, -37, -36, -37, -37, 3, -37,
+ /* 10 */ -37, 39, -29, -37, -37, -37, -37, -7, -37, 86,
+ /* 20 */ -37, -37, -37, -37, -37, -37, 17, -37, -37, -37,
+ /* 30 */ -37, -37, 53, -37, -37, 64, -37, -37, 72, -37,
+ /* 40 */ -37, -37, 46, -29, -37, -37, -37, -37, -21, -37,
+ /* 50 */ -37, 49, 84, -37, -37, -37, -37, -37, 45, -37,
+ /* 60 */ 61, -37, -37,
};
static YYACTIONTYPE yy_default[] = {
- /* 0 */ 58, 92, 57, 59, 92, 60, 92, 92, 81, 92,
- /* 10 */ 58, 92, 61, 62, 63, 92, 92, 64, 92, 66,
- /* 20 */ 67, 69, 70, 71, 72, 92, 77, 68, 92, 73,
- /* 30 */ 75, 74, 92, 92, 78, 76, 92, 65, 82, 83,
- /* 40 */ 92, 92, 92, 89, 92, 92, 92, 92, 85, 86,
- /* 50 */ 87, 88, 92, 90, 92, 91,
+ /* 0 */ 65, 103, 64, 66, 67, 103, 68, 103, 103, 92,
+ /* 10 */ 103, 65, 103, 69, 70, 71, 103, 103, 72, 103,
+ /* 20 */ 74, 75, 77, 78, 79, 80, 103, 86, 76, 81,
+ /* 30 */ 103, 82, 84, 83, 103, 103, 87, 85, 103, 73,
+ /* 40 */ 103, 103, 65, 103, 91, 93, 103, 103, 103, 100,
+ /* 50 */ 103, 103, 103, 103, 96, 97, 98, 99, 103, 101,
+ /* 60 */ 103, 102, 94,
};
#define YY_SZ_ACTTAB (sizeof(yy_action)/sizeof(yy_action[0]))
/* The next table maps tokens into fallback tokens. If a construct
** like the following:
-**
+**
** %fallback ID X Y Z.
**
** appears in the grammer, then ID becomes a fallback token for X, Y,
@@ -349,15 +339,15 @@ typedef struct yyParser yyParser;
#ifndef NDEBUG
#include <stdio.h>
-static FILE *yyTraceFILE = 0;
-static char *yyTracePrompt = 0;
+static FILE *yyTraceFILE = NULL;
+static char *yyTracePrompt = NULL;
#endif /* NDEBUG */
#ifndef NDEBUG
-/*
+/*
** Turn parser tracing on by giving a stream to which to write the trace
** and a prompt to preface each trace message. Tracing is turned off
-** by making either argument NULL
+** by making either argument NULL
**
** Inputs:
** <ul>
@@ -371,29 +361,32 @@ static char *yyTracePrompt = 0;
** Outputs:
** None.
*/
+#if 0
void configparserTrace(FILE *TraceFILE, char *zTracePrompt){
yyTraceFILE = TraceFILE;
yyTracePrompt = zTracePrompt;
if( yyTraceFILE==0 ) yyTracePrompt = 0;
else if( yyTracePrompt==0 ) yyTraceFILE = 0;
}
+#endif
#endif /* NDEBUG */
#ifndef NDEBUG
/* For tracing shifts, the names of all terminals and nonterminals
** are required. The following table supplies these names */
-static const char *yyTokenName[] = {
+static const char *yyTokenName[] = {
"$", "EOL", "ASSIGN", "APPEND",
"LKEY", "PLUS", "STRING", "INTEGER",
"LPARAN", "RPARAN", "COMMA", "ARRAY_ASSIGN",
- "ELSE", "LCURLY", "RCURLY", "DOLLAR",
- "SRVVARNAME", "LBRACKET", "RBRACKET", "EQ",
- "MATCH", "NE", "NOMATCH", "INCLUDE",
- "INCLUDE_SHELL", "error", "input", "metalines",
- "metaline", "varline", "condlines", "include",
- "include_shell", "value", "expression", "aelement",
- "condline", "aelements", "array", "key",
- "stringop", "cond", "eols", "context",
+ "GLOBAL", "LCURLY", "RCURLY", "ELSE",
+ "DOLLAR", "SRVVARNAME", "LBRACKET", "RBRACKET",
+ "EQ", "MATCH", "NE", "NOMATCH",
+ "INCLUDE", "INCLUDE_SHELL", "error", "input",
+ "metalines", "metaline", "varline", "global",
+ "condlines", "include", "include_shell", "value",
+ "expression", "aelement", "condline", "aelements",
+ "array", "key", "stringop", "cond",
+ "eols", "globalstart", "context",
};
#endif /* NDEBUG */
@@ -405,38 +398,42 @@ static const char *yyRuleName[] = {
/* 1 */ "metalines ::= metalines metaline",
/* 2 */ "metalines ::=",
/* 3 */ "metaline ::= varline",
- /* 4 */ "metaline ::= condlines EOL",
- /* 5 */ "metaline ::= include",
- /* 6 */ "metaline ::= include_shell",
- /* 7 */ "metaline ::= EOL",
- /* 8 */ "varline ::= key ASSIGN expression",
- /* 9 */ "varline ::= key APPEND expression",
- /* 10 */ "key ::= LKEY",
- /* 11 */ "expression ::= expression PLUS value",
- /* 12 */ "expression ::= value",
- /* 13 */ "value ::= key",
- /* 14 */ "value ::= STRING",
- /* 15 */ "value ::= INTEGER",
- /* 16 */ "value ::= array",
- /* 17 */ "array ::= LPARAN aelements RPARAN",
- /* 18 */ "aelements ::= aelements COMMA aelement",
- /* 19 */ "aelements ::= aelements COMMA",
- /* 20 */ "aelements ::= aelement",
- /* 21 */ "aelement ::= expression",
- /* 22 */ "aelement ::= stringop ARRAY_ASSIGN expression",
- /* 23 */ "eols ::= EOL",
- /* 24 */ "eols ::=",
- /* 25 */ "condlines ::= condlines eols ELSE condline",
- /* 26 */ "condlines ::= condline",
- /* 27 */ "condline ::= context LCURLY metalines RCURLY",
- /* 28 */ "context ::= DOLLAR SRVVARNAME LBRACKET stringop RBRACKET cond expression",
- /* 29 */ "cond ::= EQ",
- /* 30 */ "cond ::= MATCH",
- /* 31 */ "cond ::= NE",
- /* 32 */ "cond ::= NOMATCH",
- /* 33 */ "stringop ::= expression",
- /* 34 */ "include ::= INCLUDE stringop",
- /* 35 */ "include_shell ::= INCLUDE_SHELL stringop",
+ /* 4 */ "metaline ::= global",
+ /* 5 */ "metaline ::= condlines EOL",
+ /* 6 */ "metaline ::= include",
+ /* 7 */ "metaline ::= include_shell",
+ /* 8 */ "metaline ::= EOL",
+ /* 9 */ "varline ::= key ASSIGN expression",
+ /* 10 */ "varline ::= key APPEND expression",
+ /* 11 */ "key ::= LKEY",
+ /* 12 */ "expression ::= expression PLUS value",
+ /* 13 */ "expression ::= value",
+ /* 14 */ "value ::= key",
+ /* 15 */ "value ::= STRING",
+ /* 16 */ "value ::= INTEGER",
+ /* 17 */ "value ::= array",
+ /* 18 */ "array ::= LPARAN RPARAN",
+ /* 19 */ "array ::= LPARAN aelements RPARAN",
+ /* 20 */ "aelements ::= aelements COMMA aelement",
+ /* 21 */ "aelements ::= aelements COMMA",
+ /* 22 */ "aelements ::= aelement",
+ /* 23 */ "aelement ::= expression",
+ /* 24 */ "aelement ::= stringop ARRAY_ASSIGN expression",
+ /* 25 */ "eols ::= EOL",
+ /* 26 */ "eols ::=",
+ /* 27 */ "globalstart ::= GLOBAL",
+ /* 28 */ "global ::= globalstart LCURLY metalines RCURLY",
+ /* 29 */ "condlines ::= condlines eols ELSE condline",
+ /* 30 */ "condlines ::= condline",
+ /* 31 */ "condline ::= context LCURLY metalines RCURLY",
+ /* 32 */ "context ::= DOLLAR SRVVARNAME LBRACKET stringop RBRACKET cond expression",
+ /* 33 */ "cond ::= EQ",
+ /* 34 */ "cond ::= MATCH",
+ /* 35 */ "cond ::= NE",
+ /* 36 */ "cond ::= NOMATCH",
+ /* 37 */ "stringop ::= expression",
+ /* 38 */ "include ::= INCLUDE stringop",
+ /* 39 */ "include_shell ::= INCLUDE_SHELL stringop",
};
#endif /* NDEBUG */
@@ -444,9 +441,10 @@ static const char *yyRuleName[] = {
** This function returns the symbolic name associated with a token
** value.
*/
+#if 0
const char *configparserTokenName(int tokenType){
#ifndef NDEBUG
- if( tokenType>0 && tokenType<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){
+ if( tokenType>0 && (size_t)tokenType<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){
return yyTokenName[tokenType];
}else{
return "Unknown";
@@ -455,8 +453,9 @@ const char *configparserTokenName(int tokenType){
return "";
#endif
}
+#endif
-/*
+/*
** This function allocates a new parser.
** The only argument is a pointer to a function which works like
** malloc.
@@ -487,7 +486,7 @@ static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){
/* Here is inserted the actions which take place when a
** terminal or non-terminal is destroyed. This can happen
** when the symbol is popped from the stack during a
- ** reduce or during error processing or when a parser is
+ ** reduce or during error processing or when a parser is
** being destroyed before it is finished parsing.
**
** Note: during a reduce, the only symbols destroyed are those
@@ -518,43 +517,44 @@ static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){
case 22:
case 23:
case 24:
-#line 159 "./configparser.y"
+ case 25:
+#line 144 "../../src/configparser.y"
{ buffer_free((yypminor->yy0)); }
#line 523 "configparser.c"
break;
- case 33:
-#line 150 "./configparser.y"
-{ (yypminor->yy43)->free((yypminor->yy43)); }
+ case 35:
+#line 135 "../../src/configparser.y"
+{ (yypminor->yy41)->free((yypminor->yy41)); }
#line 528 "configparser.c"
break;
- case 34:
-#line 151 "./configparser.y"
-{ (yypminor->yy43)->free((yypminor->yy43)); }
+ case 36:
+#line 136 "../../src/configparser.y"
+{ (yypminor->yy41)->free((yypminor->yy41)); }
#line 533 "configparser.c"
break;
- case 35:
-#line 152 "./configparser.y"
-{ (yypminor->yy43)->free((yypminor->yy43)); }
+ case 37:
+#line 137 "../../src/configparser.y"
+{ (yypminor->yy41)->free((yypminor->yy41)); }
#line 538 "configparser.c"
break;
- case 37:
-#line 153 "./configparser.y"
-{ array_free((yypminor->yy78)); }
+ case 39:
+#line 138 "../../src/configparser.y"
+{ array_free((yypminor->yy40)); }
#line 543 "configparser.c"
break;
- case 38:
-#line 154 "./configparser.y"
-{ array_free((yypminor->yy78)); }
+ case 40:
+#line 139 "../../src/configparser.y"
+{ array_free((yypminor->yy40)); }
#line 548 "configparser.c"
break;
- case 39:
-#line 155 "./configparser.y"
-{ buffer_free((yypminor->yy1)); }
+ case 41:
+#line 140 "../../src/configparser.y"
+{ buffer_free((yypminor->yy43)); }
#line 553 "configparser.c"
break;
- case 40:
-#line 156 "./configparser.y"
-{ buffer_free((yypminor->yy1)); }
+ case 42:
+#line 141 "../../src/configparser.y"
+{ buffer_free((yypminor->yy43)); }
#line 558 "configparser.c"
break;
default: break; /* If no destructor action specified: do nothing */
@@ -587,7 +587,7 @@ static int yy_pop_parser_stack(yyParser *pParser){
return yymajor;
}
-/*
+/*
** Deallocate and destroy a parser. Destructors are all called for
** all stack elements before shutting the parser down.
**
@@ -604,7 +604,7 @@ void configparserFree(
void (*freeProc)(void*) /* Function used to reclaim memory */
){
yyParser *pParser = (yyParser*)p;
- if( pParser==0 ) return;
+ if( pParser==NULL ) return;
while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser);
(*freeProc)((void*)pParser);
}
@@ -623,7 +623,7 @@ static int yy_find_shift_action(
){
int i;
int stateno = pParser->yystack[pParser->yyidx].stateno;
-
+
/* if( pParser->yyidx<0 ) return YY_NO_ACTION; */
i = yy_shift_ofst[stateno];
if( i==YY_SHIFT_USE_DFLT ){
@@ -633,7 +633,7 @@ static int yy_find_shift_action(
return YY_NO_ACTION;
}
i += iLookAhead;
- if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
+ if( i<0 || (size_t)i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
#ifdef YYFALLBACK
int iFallback; /* Fallback token */
if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
@@ -667,7 +667,7 @@ static int yy_find_reduce_action(
){
int i;
int stateno = pParser->yystack[pParser->yyidx].stateno;
-
+
i = yy_reduce_ofst[stateno];
if( i==YY_REDUCE_USE_DFLT ){
return yy_default[stateno];
@@ -676,7 +676,7 @@ static int yy_find_reduce_action(
return YY_NO_ACTION;
}
i += iLookAhead;
- if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
+ if( i<0 || (size_t)i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
return yy_default[stateno];
}else{
return yy_action[i];
@@ -731,42 +731,46 @@ static struct {
YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
unsigned char nrhs; /* Number of right-hand side symbols in the rule */
} yyRuleInfo[] = {
- { 26, 1 },
- { 27, 2 },
- { 27, 0 },
- { 28, 1 },
+ { 27, 1 },
{ 28, 2 },
- { 28, 1 },
- { 28, 1 },
- { 28, 1 },
- { 29, 3 },
- { 29, 3 },
+ { 28, 0 },
+ { 29, 1 },
+ { 29, 1 },
+ { 29, 2 },
+ { 29, 1 },
+ { 29, 1 },
+ { 29, 1 },
+ { 30, 3 },
+ { 30, 3 },
+ { 41, 1 },
+ { 36, 3 },
+ { 36, 1 },
+ { 35, 1 },
+ { 35, 1 },
+ { 35, 1 },
+ { 35, 1 },
+ { 40, 2 },
+ { 40, 3 },
+ { 39, 3 },
+ { 39, 2 },
{ 39, 1 },
- { 34, 3 },
- { 34, 1 },
- { 33, 1 },
- { 33, 1 },
- { 33, 1 },
- { 33, 1 },
- { 38, 3 },
- { 37, 3 },
- { 37, 2 },
{ 37, 1 },
- { 35, 1 },
- { 35, 3 },
+ { 37, 3 },
+ { 44, 1 },
+ { 44, 0 },
+ { 45, 1 },
+ { 31, 4 },
+ { 32, 4 },
+ { 32, 1 },
+ { 38, 4 },
+ { 46, 7 },
+ { 43, 1 },
+ { 43, 1 },
+ { 43, 1 },
+ { 43, 1 },
{ 42, 1 },
- { 42, 0 },
- { 30, 4 },
- { 30, 1 },
- { 36, 4 },
- { 43, 7 },
- { 41, 1 },
- { 41, 1 },
- { 41, 1 },
- { 41, 1 },
- { 40, 1 },
- { 31, 2 },
- { 32, 2 },
+ { 33, 2 },
+ { 34, 2 },
};
static void yy_accept(yyParser*); /* Forward Declaration */
@@ -787,8 +791,8 @@ static void yy_reduce(
configparserARG_FETCH;
yymsp = &yypParser->yystack[yypParser->yyidx];
#ifndef NDEBUG
- if( yyTraceFILE && yyruleno>=0
- && yyruleno<sizeof(yyRuleName)/sizeof(yyRuleName[0]) ){
+ if( yyTraceFILE && yyruleno>=0
+ && (size_t)yyruleno<sizeof(yyRuleName)/sizeof(yyRuleName[0]) ){
fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
yyRuleName[yyruleno]);
}
@@ -816,287 +820,359 @@ static void yy_reduce(
/* No destructor defined for varline */
break;
case 4:
-#line 133 "./configparser.y"
-{ yymsp[-1].minor.yy74 = NULL; }
-#line 821 "configparser.c"
- yy_destructor(1,&yymsp[0].minor);
+ /* No destructor defined for global */
break;
case 5:
- /* No destructor defined for include */
+#line 117 "../../src/configparser.y"
+{ yymsp[-1].minor.yy78 = NULL; }
+#line 828 "configparser.c"
+ yy_destructor(1,&yymsp[0].minor);
break;
case 6:
- /* No destructor defined for include_shell */
+ /* No destructor defined for include */
break;
case 7:
- yy_destructor(1,&yymsp[0].minor);
+ /* No destructor defined for include_shell */
break;
case 8:
-#line 161 "./configparser.y"
+ yy_destructor(1,&yymsp[0].minor);
+ break;
+ case 9:
+#line 146 "../../src/configparser.y"
{
- buffer_copy_string_buffer(yymsp[0].minor.yy43->key, yymsp[-2].minor.yy1);
- if (NULL == array_get_element(ctx->current->value, yymsp[0].minor.yy43->key->ptr)) {
- array_insert_unique(ctx->current->value, yymsp[0].minor.yy43);
- yymsp[0].minor.yy43 = NULL;
- } else {
- fprintf(stderr, "Duplicate config variable in conditional %d %s: %s\n",
- ctx->current->context_ndx,
- ctx->current->key->ptr, yymsp[0].minor.yy43->key->ptr);
- ctx->ok = 0;
- yymsp[0].minor.yy43->free(yymsp[0].minor.yy43);
- yymsp[0].minor.yy43 = NULL;
+ if (ctx->ok) {
+ buffer_copy_string_buffer(yymsp[0].minor.yy41->key, yymsp[-2].minor.yy43);
+ if (strncmp(yymsp[-2].minor.yy43->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, yymsp[-2].minor.yy43->ptr);
+ ctx->ok = 0;
+ } else if (NULL == array_get_element(ctx->current->value, yymsp[0].minor.yy41->key->ptr)) {
+ array_insert_unique(ctx->current->value, yymsp[0].minor.yy41);
+ yymsp[0].minor.yy41 = NULL;
+ } else {
+ fprintf(stderr, "Duplicate config variable in conditional %d %s: %s\n",
+ ctx->current->context_ndx,
+ ctx->current->key->ptr, yymsp[0].minor.yy41->key->ptr);
+ ctx->ok = 0;
+ yymsp[0].minor.yy41->free(yymsp[0].minor.yy41);
+ yymsp[0].minor.yy41 = NULL;
+ }
}
- buffer_free(yymsp[-2].minor.yy1);
- yymsp[-2].minor.yy1 = NULL;
+ buffer_free(yymsp[-2].minor.yy43);
+ yymsp[-2].minor.yy43 = NULL;
}
-#line 851 "configparser.c"
+#line 865 "configparser.c"
yy_destructor(2,&yymsp[-1].minor);
break;
- case 9:
-#line 178 "./configparser.y"
+ case 10:
+#line 170 "../../src/configparser.y"
{
array *vars = ctx->current->value;
data_unset *du;
- if (NULL != (du = array_get_element(vars, yymsp[-2].minor.yy1->ptr))) {
+ if (strncmp(yymsp[-2].minor.yy43->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, yymsp[-2].minor.yy43->ptr);
+ ctx->ok = 0;
+ } else if (NULL != (du = array_get_element(vars, yymsp[-2].minor.yy43->ptr))) {
/* exists in current block */
- du = configparser_merge_data(du, yymsp[0].minor.yy43);
+ du = configparser_merge_data(du, yymsp[0].minor.yy41);
if (NULL == du) {
ctx->ok = 0;
}
else {
- buffer_copy_string_buffer(du->key, yymsp[-2].minor.yy1);
+ buffer_copy_string_buffer(du->key, yymsp[-2].minor.yy43);
array_replace(vars, du);
}
- } else if (NULL != (du = configparser_get_variable(ctx, yymsp[-2].minor.yy1))) {
- du = configparser_merge_data(du, yymsp[0].minor.yy43);
+ yymsp[0].minor.yy41->free(yymsp[0].minor.yy41);
+ } else if (NULL != (du = configparser_get_variable(ctx, yymsp[-2].minor.yy43))) {
+ du = configparser_merge_data(du, yymsp[0].minor.yy41);
if (NULL == du) {
ctx->ok = 0;
}
else {
- buffer_copy_string_buffer(du->key, yymsp[-2].minor.yy1);
+ buffer_copy_string_buffer(du->key, yymsp[-2].minor.yy43);
array_insert_unique(ctx->current->value, du);
}
+ yymsp[0].minor.yy41->free(yymsp[0].minor.yy41);
} else {
- fprintf(stderr, "Undefined config variable in conditional %d %s: %s\n",
- ctx->current->context_ndx,
- ctx->current->key->ptr, yymsp[-2].minor.yy1->ptr);
- ctx->ok = 0;
+ buffer_copy_string_buffer(yymsp[0].minor.yy41->key, yymsp[-2].minor.yy43);
+ array_insert_unique(ctx->current->value, yymsp[0].minor.yy41);
}
- buffer_free(yymsp[-2].minor.yy1);
- yymsp[-2].minor.yy1 = NULL;
- yymsp[0].minor.yy43->free(yymsp[0].minor.yy43);
- yymsp[0].minor.yy43 = NULL;
+ buffer_free(yymsp[-2].minor.yy43);
+ yymsp[-2].minor.yy43 = NULL;
+ yymsp[0].minor.yy41 = NULL;
}
-#line 890 "configparser.c"
+#line 908 "configparser.c"
yy_destructor(3,&yymsp[-1].minor);
break;
- case 10:
-#line 213 "./configparser.y"
+ case 11:
+#line 209 "../../src/configparser.y"
{
if (strchr(yymsp[0].minor.yy0->ptr, '.') == NULL) {
- yygotominor.yy1 = buffer_init_string("var.");
- buffer_append_string_buffer(yygotominor.yy1, yymsp[0].minor.yy0);
+ yygotominor.yy43 = buffer_init_string("var.");
+ buffer_append_string_buffer(yygotominor.yy43, yymsp[0].minor.yy0);
buffer_free(yymsp[0].minor.yy0);
yymsp[0].minor.yy0 = NULL;
} else {
- yygotominor.yy1 = yymsp[0].minor.yy0;
+ yygotominor.yy43 = yymsp[0].minor.yy0;
yymsp[0].minor.yy0 = NULL;
}
}
-#line 906 "configparser.c"
+#line 924 "configparser.c"
break;
- case 11:
-#line 225 "./configparser.y"
+ case 12:
+#line 221 "../../src/configparser.y"
{
- yygotominor.yy43 = configparser_merge_data(yymsp[-2].minor.yy43, yymsp[0].minor.yy43);
- if (NULL == yygotominor.yy43) {
+ yygotominor.yy41 = configparser_merge_data(yymsp[-2].minor.yy41, yymsp[0].minor.yy41);
+ if (NULL == yygotominor.yy41) {
ctx->ok = 0;
}
- yymsp[-2].minor.yy43 = NULL;
- yymsp[0].minor.yy43->free(yymsp[0].minor.yy43);
- yymsp[0].minor.yy43 = NULL;
+ yymsp[-2].minor.yy41 = NULL;
+ yymsp[0].minor.yy41->free(yymsp[0].minor.yy41);
+ yymsp[0].minor.yy41 = NULL;
}
-#line 919 "configparser.c"
+#line 937 "configparser.c"
yy_destructor(5,&yymsp[-1].minor);
break;
- case 12:
-#line 235 "./configparser.y"
+ case 13:
+#line 231 "../../src/configparser.y"
{
- yygotominor.yy43 = yymsp[0].minor.yy43;
- yymsp[0].minor.yy43 = NULL;
+ yygotominor.yy41 = yymsp[0].minor.yy41;
+ yymsp[0].minor.yy41 = NULL;
}
-#line 928 "configparser.c"
+#line 946 "configparser.c"
break;
- case 13:
-#line 240 "./configparser.y"
+ case 14:
+#line 236 "../../src/configparser.y"
{
- yygotominor.yy43 = configparser_get_variable(ctx, yymsp[0].minor.yy1);
- if (!yygotominor.yy43) {
+ yygotominor.yy41 = NULL;
+ if (strncmp(yymsp[0].minor.yy43->ptr, "env.", sizeof("env.") - 1) == 0) {
+ char *env;
+
+ if (NULL != (env = getenv(yymsp[0].minor.yy43->ptr + 4))) {
+ data_string *ds;
+ ds = data_string_init();
+ buffer_append_string(ds->value, env);
+ yygotominor.yy41 = (data_unset *)ds;
+ }
+ else {
+ fprintf(stderr, "Undefined env variable: %s\n", yymsp[0].minor.yy43->ptr + 4);
+ ctx->ok = 0;
+ }
+ } else if (NULL == (yygotominor.yy41 = configparser_get_variable(ctx, yymsp[0].minor.yy43))) {
+ fprintf(stderr, "Undefined config variable: %s\n", yymsp[0].minor.yy43->ptr);
+ ctx->ok = 0;
+ }
+ if (!yygotominor.yy41) {
/* make a dummy so it won't crash */
- yygotominor.yy43 = (data_unset *)data_string_init();
+ yygotominor.yy41 = (data_unset *)data_string_init();
}
- buffer_free(yymsp[0].minor.yy1);
- yymsp[0].minor.yy1 = NULL;
+ buffer_free(yymsp[0].minor.yy43);
+ yymsp[0].minor.yy43 = NULL;
}
-#line 941 "configparser.c"
+#line 976 "configparser.c"
break;
- case 14:
-#line 250 "./configparser.y"
+ case 15:
+#line 263 "../../src/configparser.y"
{
- yygotominor.yy43 = (data_unset *)data_string_init();
- buffer_copy_string_buffer(((data_string *)(yygotominor.yy43))->value, yymsp[0].minor.yy0);
+ yygotominor.yy41 = (data_unset *)data_string_init();
+ buffer_copy_string_buffer(((data_string *)(yygotominor.yy41))->value, yymsp[0].minor.yy0);
buffer_free(yymsp[0].minor.yy0);
yymsp[0].minor.yy0 = NULL;
}
-#line 951 "configparser.c"
+#line 986 "configparser.c"
break;
- case 15:
-#line 257 "./configparser.y"
+ case 16:
+#line 270 "../../src/configparser.y"
{
- yygotominor.yy43 = (data_unset *)data_integer_init();
- ((data_integer *)(yygotominor.yy43))->value = strtol(yymsp[0].minor.yy0->ptr, NULL, 10);
+ yygotominor.yy41 = (data_unset *)data_integer_init();
+ ((data_integer *)(yygotominor.yy41))->value = strtol(yymsp[0].minor.yy0->ptr, NULL, 10);
buffer_free(yymsp[0].minor.yy0);
yymsp[0].minor.yy0 = NULL;
}
-#line 961 "configparser.c"
+#line 996 "configparser.c"
break;
- case 16:
-#line 263 "./configparser.y"
+ case 17:
+#line 276 "../../src/configparser.y"
{
- yygotominor.yy43 = (data_unset *)data_array_init();
- array_free(((data_array *)(yygotominor.yy43))->value);
- ((data_array *)(yygotominor.yy43))->value = yymsp[0].minor.yy78;
- yymsp[0].minor.yy78 = NULL;
+ yygotominor.yy41 = (data_unset *)data_array_init();
+ array_free(((data_array *)(yygotominor.yy41))->value);
+ ((data_array *)(yygotominor.yy41))->value = yymsp[0].minor.yy40;
+ yymsp[0].minor.yy40 = NULL;
}
-#line 971 "configparser.c"
+#line 1006 "configparser.c"
break;
- case 17:
-#line 269 "./configparser.y"
+ case 18:
+#line 282 "../../src/configparser.y"
{
- yygotominor.yy78 = yymsp[-1].minor.yy78;
- yymsp[-1].minor.yy78 = NULL;
+ yygotominor.yy40 = array_init();
}
-#line 979 "configparser.c"
+#line 1013 "configparser.c"
+ yy_destructor(8,&yymsp[-1].minor);
+ yy_destructor(9,&yymsp[0].minor);
+ break;
+ case 19:
+#line 285 "../../src/configparser.y"
+{
+ yygotominor.yy40 = yymsp[-1].minor.yy40;
+ yymsp[-1].minor.yy40 = NULL;
+}
+#line 1023 "configparser.c"
yy_destructor(8,&yymsp[-2].minor);
yy_destructor(9,&yymsp[0].minor);
break;
- case 18:
-#line 274 "./configparser.y"
+ case 20:
+#line 290 "../../src/configparser.y"
{
- if (buffer_is_empty(yymsp[0].minor.yy43->key) ||
- NULL == array_get_element(yymsp[-2].minor.yy78, yymsp[0].minor.yy43->key->ptr)) {
- array_insert_unique(yymsp[-2].minor.yy78, yymsp[0].minor.yy43);
- yymsp[0].minor.yy43 = NULL;
+ if (buffer_is_empty(yymsp[0].minor.yy41->key) ||
+ NULL == array_get_element(yymsp[-2].minor.yy40, yymsp[0].minor.yy41->key->ptr)) {
+ array_insert_unique(yymsp[-2].minor.yy40, yymsp[0].minor.yy41);
+ yymsp[0].minor.yy41 = NULL;
} else {
- fprintf(stderr, "Duplicate array-key: %s\n",
- yymsp[0].minor.yy43->key->ptr);
+ fprintf(stderr, "Duplicate array-key: %s\n",
+ yymsp[0].minor.yy41->key->ptr);
ctx->ok = 0;
- yymsp[0].minor.yy43->free(yymsp[0].minor.yy43);
- yymsp[0].minor.yy43 = NULL;
+ yymsp[0].minor.yy41->free(yymsp[0].minor.yy41);
+ yymsp[0].minor.yy41 = NULL;
}
-
- yygotominor.yy78 = yymsp[-2].minor.yy78;
- yymsp[-2].minor.yy78 = NULL;
+
+ yygotominor.yy40 = yymsp[-2].minor.yy40;
+ yymsp[-2].minor.yy40 = NULL;
}
-#line 1001 "configparser.c"
+#line 1045 "configparser.c"
yy_destructor(10,&yymsp[-1].minor);
break;
- case 19:
-#line 291 "./configparser.y"
+ case 21:
+#line 307 "../../src/configparser.y"
{
- yygotominor.yy78 = yymsp[-1].minor.yy78;
- yymsp[-1].minor.yy78 = NULL;
+ yygotominor.yy40 = yymsp[-1].minor.yy40;
+ yymsp[-1].minor.yy40 = NULL;
}
-#line 1010 "configparser.c"
+#line 1054 "configparser.c"
yy_destructor(10,&yymsp[0].minor);
break;
- case 20:
-#line 296 "./configparser.y"
+ case 22:
+#line 312 "../../src/configparser.y"
{
- yygotominor.yy78 = array_init();
- array_insert_unique(yygotominor.yy78, yymsp[0].minor.yy43);
- yymsp[0].minor.yy43 = NULL;
+ yygotominor.yy40 = array_init();
+ array_insert_unique(yygotominor.yy40, yymsp[0].minor.yy41);
+ yymsp[0].minor.yy41 = NULL;
}
-#line 1020 "configparser.c"
+#line 1064 "configparser.c"
break;
- case 21:
-#line 302 "./configparser.y"
+ case 23:
+#line 318 "../../src/configparser.y"
{
- yygotominor.yy43 = yymsp[0].minor.yy43;
- yymsp[0].minor.yy43 = NULL;
+ yygotominor.yy41 = yymsp[0].minor.yy41;
+ yymsp[0].minor.yy41 = NULL;
}
-#line 1028 "configparser.c"
+#line 1072 "configparser.c"
break;
- case 22:
-#line 306 "./configparser.y"
+ case 24:
+#line 322 "../../src/configparser.y"
{
- buffer_copy_string_buffer(yymsp[0].minor.yy43->key, yymsp[-2].minor.yy1);
- buffer_free(yymsp[-2].minor.yy1);
- yymsp[-2].minor.yy1 = NULL;
-
- yygotominor.yy43 = yymsp[0].minor.yy43;
- yymsp[0].minor.yy43 = NULL;
+ buffer_copy_string_buffer(yymsp[0].minor.yy41->key, yymsp[-2].minor.yy43);
+ buffer_free(yymsp[-2].minor.yy43);
+ yymsp[-2].minor.yy43 = NULL;
+
+ yygotominor.yy41 = yymsp[0].minor.yy41;
+ yymsp[0].minor.yy41 = NULL;
}
-#line 1040 "configparser.c"
+#line 1084 "configparser.c"
yy_destructor(11,&yymsp[-1].minor);
break;
- case 23:
+ case 25:
yy_destructor(1,&yymsp[0].minor);
break;
- case 24:
+ case 26:
break;
- case 25:
-#line 318 "./configparser.y"
+ case 27:
+#line 334 "../../src/configparser.y"
{
- assert(yymsp[-3].minor.yy74->context_ndx < yymsp[0].minor.yy74->context_ndx);
- yymsp[0].minor.yy74->prev = yymsp[-3].minor.yy74;
- yymsp[-3].minor.yy74->next = yymsp[0].minor.yy74;
- yygotominor.yy74 = yymsp[0].minor.yy74;
- yymsp[-3].minor.yy74 = NULL;
- yymsp[0].minor.yy74 = NULL;
+ data_config *dc;
+ dc = (data_config *)array_get_element(ctx->srv->config_context, "global");
+ assert(dc);
+ configparser_push(ctx, dc, 0);
}
-#line 1058 "configparser.c"
+#line 1100 "configparser.c"
+ yy_destructor(12,&yymsp[0].minor);
+ break;
+ case 28:
+#line 341 "../../src/configparser.y"
+{
+ data_config *cur;
+
+ cur = ctx->current;
+ configparser_pop(ctx);
+
+ assert(cur && ctx->current);
+
+ yygotominor.yy78 = cur;
+}
+#line 1115 "configparser.c"
+ /* No destructor defined for globalstart */
+ yy_destructor(13,&yymsp[-2].minor);
+ /* No destructor defined for metalines */
+ yy_destructor(14,&yymsp[0].minor);
+ break;
+ case 29:
+#line 352 "../../src/configparser.y"
+{
+ if (yymsp[-3].minor.yy78->context_ndx >= yymsp[0].minor.yy78->context_ndx) {
+ fprintf(stderr, "unreachable else condition\n");
+ ctx->ok = 0;
+ }
+ yymsp[0].minor.yy78->prev = yymsp[-3].minor.yy78;
+ yymsp[-3].minor.yy78->next = yymsp[0].minor.yy78;
+ yygotominor.yy78 = yymsp[0].minor.yy78;
+ yymsp[-3].minor.yy78 = NULL;
+ yymsp[0].minor.yy78 = NULL;
+}
+#line 1134 "configparser.c"
/* No destructor defined for eols */
- yy_destructor(12,&yymsp[-1].minor);
+ yy_destructor(15,&yymsp[-1].minor);
break;
- case 26:
-#line 327 "./configparser.y"
+ case 30:
+#line 364 "../../src/configparser.y"
{
- yygotominor.yy74 = yymsp[0].minor.yy74;
- yymsp[0].minor.yy74 = NULL;
+ yygotominor.yy78 = yymsp[0].minor.yy78;
+ yymsp[0].minor.yy78 = NULL;
}
-#line 1068 "configparser.c"
+#line 1144 "configparser.c"
break;
- case 27:
-#line 332 "./configparser.y"
+ case 31:
+#line 369 "../../src/configparser.y"
{
data_config *cur;
-
+
cur = ctx->current;
configparser_pop(ctx);
assert(cur && ctx->current);
- yygotominor.yy74 = cur;
+ yygotominor.yy78 = cur;
}
-#line 1082 "configparser.c"
+#line 1158 "configparser.c"
/* No destructor defined for context */
yy_destructor(13,&yymsp[-2].minor);
/* No destructor defined for metalines */
yy_destructor(14,&yymsp[0].minor);
break;
- case 28:
-#line 343 "./configparser.y"
+ case 32:
+#line 380 "../../src/configparser.y"
{
data_config *dc;
buffer *b, *rvalue, *op;
- if (ctx->ok && yymsp[0].minor.yy43->type != TYPE_STRING) {
+ if (ctx->ok && yymsp[0].minor.yy41->type != TYPE_STRING) {
fprintf(stderr, "rvalue must be string");
ctx->ok = 0;
}
- switch(yymsp[-1].minor.yy29) {
+ switch(yymsp[-1].minor.yy27) {
case CONFIG_COND_NE:
op = buffer_init_string("!=");
break;
@@ -1118,11 +1194,11 @@ static void yy_reduce(
buffer_copy_string_buffer(b, ctx->current->key);
buffer_append_string(b, "/");
buffer_append_string_buffer(b, yymsp[-5].minor.yy0);
- buffer_append_string_buffer(b, yymsp[-3].minor.yy1);
+ buffer_append_string_buffer(b, yymsp[-3].minor.yy43);
buffer_append_string_buffer(b, op);
- rvalue = ((data_string*)yymsp[0].minor.yy43)->value;
+ rvalue = ((data_string*)yymsp[0].minor.yy41)->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 {
@@ -1135,23 +1211,30 @@ static void yy_reduce(
{ COMP_HTTP_URL, CONST_STR_LEN("HTTP[\"url\"]" ) },
{ COMP_HTTP_HOST, CONST_STR_LEN("HTTP[\"host\"]" ) },
{ COMP_HTTP_REFERER, CONST_STR_LEN("HTTP[\"referer\"]" ) },
- { COMP_HTTP_USERAGENT, 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_LANGUAGE, CONST_STR_LEN("HTTP[\"language\"]" ) },
{ COMP_HTTP_COOKIE, CONST_STR_LEN("HTTP[\"cookie\"]" ) },
- { COMP_HTTP_REMOTEIP, 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_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;
dc = data_config_init();
-
+
buffer_copy_string_buffer(dc->key, b);
buffer_copy_string_buffer(dc->op, op);
buffer_copy_string_buffer(dc->comp_key, yymsp[-5].minor.yy0);
buffer_append_string_len(dc->comp_key, CONST_STR_LEN("[\""));
- buffer_append_string_buffer(dc->comp_key, yymsp[-3].minor.yy1);
+ buffer_append_string_buffer(dc->comp_key, yymsp[-3].minor.yy43);
buffer_append_string_len(dc->comp_key, CONST_STR_LEN("\"]"));
- dc->cond = yymsp[-1].minor.yy29;
-
+ dc->cond = yymsp[-1].minor.yy27;
+
for (i = 0; comps[i].comp_key; i ++) {
if (buffer_is_equal_string(
dc->comp_key, comps[i].comp_key, comps[i].len)) {
@@ -1164,7 +1247,7 @@ static void yy_reduce(
ctx->ok = 0;
}
- switch(yymsp[-1].minor.yy29) {
+ switch(yymsp[-1].minor.yy27) {
case CONFIG_COND_NE:
case CONFIG_COND_EQ:
dc->string = buffer_init_buffer(rvalue);
@@ -1173,42 +1256,50 @@ static void yy_reduce(
case CONFIG_COND_MATCH: {
#ifdef HAVE_PCRE_H
const char *errptr;
- int erroff;
-
- if (NULL == (dc->regex =
+ 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",
+ 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)) &&
+ pcre_study(dc->regex, 0, &errptr)) &&
errptr != NULL) {
- fprintf(stderr, "studying regex failed: %s -> %s\n",
+ 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",
- yymsp[-5].minor.yy0->ptr, yymsp[-3].minor.yy1->ptr);
+ "(perhaps just a missing pcre-devel package ?) \n",
+ yymsp[-5].minor.yy0->ptr, yymsp[-3].minor.yy43->ptr);
ctx->ok = 0;
#endif
break;
}
default:
- fprintf(stderr, "unknown condition for $%s[%s]\n",
- yymsp[-5].minor.yy0->ptr, yymsp[-3].minor.yy1->ptr);
+ fprintf(stderr, "unknown condition for $%s[%s]\n",
+ yymsp[-5].minor.yy0->ptr, yymsp[-3].minor.yy43->ptr);
ctx->ok = 0;
break;
}
-
+
configparser_push(ctx, dc, 1);
}
@@ -1216,95 +1307,95 @@ static void yy_reduce(
buffer_free(op);
buffer_free(yymsp[-5].minor.yy0);
yymsp[-5].minor.yy0 = NULL;
- buffer_free(yymsp[-3].minor.yy1);
- yymsp[-3].minor.yy1 = NULL;
- yymsp[0].minor.yy43->free(yymsp[0].minor.yy43);
- yymsp[0].minor.yy43 = NULL;
+ buffer_free(yymsp[-3].minor.yy43);
+ yymsp[-3].minor.yy43 = NULL;
+ yymsp[0].minor.yy41->free(yymsp[0].minor.yy41);
+ yymsp[0].minor.yy41 = NULL;
}
-#line 1224 "configparser.c"
- yy_destructor(15,&yymsp[-6].minor);
- yy_destructor(17,&yymsp[-4].minor);
- yy_destructor(18,&yymsp[-2].minor);
+#line 1315 "configparser.c"
+ yy_destructor(16,&yymsp[-6].minor);
+ yy_destructor(18,&yymsp[-4].minor);
+ yy_destructor(19,&yymsp[-2].minor);
break;
- case 29:
-#line 477 "./configparser.y"
-{
- yygotominor.yy29 = CONFIG_COND_EQ;
-}
-#line 1234 "configparser.c"
- yy_destructor(19,&yymsp[0].minor);
- break;
- case 30:
-#line 480 "./configparser.y"
+ case 33:
+#line 529 "../../src/configparser.y"
{
- yygotominor.yy29 = CONFIG_COND_MATCH;
+ yygotominor.yy27 = CONFIG_COND_EQ;
}
-#line 1242 "configparser.c"
+#line 1325 "configparser.c"
yy_destructor(20,&yymsp[0].minor);
break;
- case 31:
-#line 483 "./configparser.y"
+ case 34:
+#line 532 "../../src/configparser.y"
{
- yygotominor.yy29 = CONFIG_COND_NE;
+ yygotominor.yy27 = CONFIG_COND_MATCH;
}
-#line 1250 "configparser.c"
+#line 1333 "configparser.c"
yy_destructor(21,&yymsp[0].minor);
break;
- case 32:
-#line 486 "./configparser.y"
+ case 35:
+#line 535 "../../src/configparser.y"
{
- yygotominor.yy29 = CONFIG_COND_NOMATCH;
+ yygotominor.yy27 = CONFIG_COND_NE;
}
-#line 1258 "configparser.c"
+#line 1341 "configparser.c"
yy_destructor(22,&yymsp[0].minor);
break;
- case 33:
-#line 490 "./configparser.y"
+ case 36:
+#line 538 "../../src/configparser.y"
+{
+ yygotominor.yy27 = CONFIG_COND_NOMATCH;
+}
+#line 1349 "configparser.c"
+ yy_destructor(23,&yymsp[0].minor);
+ break;
+ case 37:
+#line 542 "../../src/configparser.y"
{
- yygotominor.yy1 = NULL;
+ yygotominor.yy43 = NULL;
if (ctx->ok) {
- if (yymsp[0].minor.yy43->type == TYPE_STRING) {
- yygotominor.yy1 = buffer_init_buffer(((data_string*)yymsp[0].minor.yy43)->value);
- } else if (yymsp[0].minor.yy43->type == TYPE_INTEGER) {
- yygotominor.yy1 = buffer_init();
- buffer_copy_long(yygotominor.yy1, ((data_integer *)yymsp[0].minor.yy43)->value);
+ if (yymsp[0].minor.yy41->type == TYPE_STRING) {
+ yygotominor.yy43 = buffer_init_buffer(((data_string*)yymsp[0].minor.yy41)->value);
+ } else if (yymsp[0].minor.yy41->type == TYPE_INTEGER) {
+ yygotominor.yy43 = buffer_init();
+ buffer_copy_long(yygotominor.yy43, ((data_integer *)yymsp[0].minor.yy41)->value);
} else {
fprintf(stderr, "operand must be string");
ctx->ok = 0;
}
}
- yymsp[0].minor.yy43->free(yymsp[0].minor.yy43);
- yymsp[0].minor.yy43 = NULL;
+ yymsp[0].minor.yy41->free(yymsp[0].minor.yy41);
+ yymsp[0].minor.yy41 = NULL;
}
-#line 1279 "configparser.c"
+#line 1370 "configparser.c"
break;
- case 34:
-#line 507 "./configparser.y"
+ case 38:
+#line 559 "../../src/configparser.y"
{
if (ctx->ok) {
- if (0 != config_parse_file(ctx->srv, ctx, yymsp[0].minor.yy1->ptr)) {
+ if (0 != config_parse_file(ctx->srv, ctx, yymsp[0].minor.yy43->ptr)) {
ctx->ok = 0;
}
- buffer_free(yymsp[0].minor.yy1);
- yymsp[0].minor.yy1 = NULL;
+ buffer_free(yymsp[0].minor.yy43);
+ yymsp[0].minor.yy43 = NULL;
}
}
-#line 1292 "configparser.c"
- yy_destructor(23,&yymsp[-1].minor);
+#line 1383 "configparser.c"
+ yy_destructor(24,&yymsp[-1].minor);
break;
- case 35:
-#line 517 "./configparser.y"
+ case 39:
+#line 569 "../../src/configparser.y"
{
if (ctx->ok) {
- if (0 != config_parse_cmd(ctx->srv, ctx, yymsp[0].minor.yy1->ptr)) {
+ if (0 != config_parse_cmd(ctx->srv, ctx, yymsp[0].minor.yy43->ptr)) {
ctx->ok = 0;
}
- buffer_free(yymsp[0].minor.yy1);
- yymsp[0].minor.yy1 = NULL;
+ buffer_free(yymsp[0].minor.yy43);
+ yymsp[0].minor.yy43 = NULL;
}
}
-#line 1306 "configparser.c"
- yy_destructor(24,&yymsp[-1].minor);
+#line 1397 "configparser.c"
+ yy_destructor(25,&yymsp[-1].minor);
break;
};
yygoto = yyRuleInfo[yyruleno].lhs;
@@ -1333,11 +1424,11 @@ static void yy_parse_failed(
while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
/* Here code is inserted which will be executed whenever the
** parser fails */
-#line 125 "./configparser.y"
+#line 108 "../../src/configparser.y"
ctx->ok = 0;
-#line 1340 "configparser.c"
+#line 1431 "configparser.c"
configparserARG_STORE; /* Suppress warning about unused %extra_argument variable */
}
@@ -1350,6 +1441,8 @@ static void yy_syntax_error(
YYMINORTYPE yyminor /* The minor type of the error token */
){
configparserARG_FETCH;
+ UNUSED(yymajor);
+ UNUSED(yyminor);
#define TOKEN (yyminor.yy0)
configparserARG_STORE; /* Suppress warning about unused %extra_argument variable */
}
@@ -1444,7 +1537,7 @@ void configparser(
#ifdef YYERRORSYMBOL
/* A syntax error has occurred.
** The response to an error depends upon whether or not the
- ** grammar defines an error token "ERROR".
+ ** grammar defines an error token "ERROR".
**
** This is what we do if the grammar does define ERROR:
**