src/server/config/objconf.c

Sat, 26 Nov 2022 17:07:08 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 26 Nov 2022 17:07:08 +0100
changeset 438
22eca559aded
parent 425
6440171c257f
child 453
4586d534f9b5
permissions
-rw-r--r--

refactore http listener creation

16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
44
3da1f7b6847f added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
4 * Copyright 2013 Olaf Wintermann. All rights reserved.
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "objconf.h"
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
33 #include <cx/utils.h>
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
34
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 /* dev notes:
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 *
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 * to free ObjectConfig, free:
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 * line dlist
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 * mempool
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 * object
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 */
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 ObjectConfig *load_object_config(char *file) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 FILE *in = fopen(file, "r");
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 if(in == NULL) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 return NULL;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 ObjectConfig *conf = malloc(sizeof(ObjectConfig));
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 conf->parser.parse = objconf_parse;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 conf->file = file;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
52 //conf->conditions = NULL;
23
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
53 conf->levels = NULL;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
54 conf->objects = cxPointerLinkedListCreate(cxDefaultAllocator, cx_cmp_ptr);
79
f48cea237ec3 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
55 //conf->lines = NULL;
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 int r = cfg_parse_basic_file((ConfigParser*)conf, in);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 if(r != 0) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 // TODO: free
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 return NULL;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 }
62
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
62
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
63 fclose(in);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 return conf;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67
419
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
68 ObjectConfig2* objectconf_load(const char *file) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
69 CxMempool *mp = cxBasicMempoolCreate(512);
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
70 if(!mp) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
71 return NULL;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
72 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
73
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
74 // setup parser
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
75 ConfigParser2 parser;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
76 memset(&parser, 0, sizeof(ConfigParser2));
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
77 parser.mp = mp;
425
6440171c257f make config parser delimiters configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 419
diff changeset
78 parser.delim = "()/*%";
419
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
79 parser.validateDirective = objectconf_validate_directive;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
80 parser.validateObjBegin = objectconf_validate_objbegin;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
81 parser.validateObjEnd = objectconf_validate_objend;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
82 parser.allow_hierarchy = 1;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
83
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
84 ConfigNode *obj_config = serverconfig_load_file(&parser, file);
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
85 if(!obj_config) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
86 cxMempoolDestroy(mp);
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
87 return NULL;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
88 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
89
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
90 ObjectConfig2 *conf = cxMalloc(mp->allocator, sizeof(ObjectConfig2));
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
91 if(!conf) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
92 cxMempoolDestroy(mp);
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
93 return NULL;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
94 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
95
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
96 conf->mp = mp;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
97 conf->root = obj_config;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
98
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
99 return conf;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
100 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
101
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
102 void objectconf_free(ObjectConfig2 *objconf) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
103 cxMempoolDestroy(objconf->mp);
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
104 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
105
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
106 int objectconf_validate_directive(ConfigParser2 *parser, ConfigNode *node) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
107 // It is possible that this function is called for Objects
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
108 // if { is on the next line
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
109 // It may be possible to fix the parser to not do that, but it is fine
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
110 // to just deal with that here
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
111
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
112 // ignore if node->name is an Object name like
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
113 // Object, Client, If, Else IfElse
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
114 const char *objnames[] = { "Object", "Client", "If", "ElseIf", "Else" };
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
115 size_t typeindex;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
116 if(!serverconfig_validate_directive_name(node, objnames, 5, &typeindex)) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
117 return 0;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
118 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
119
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
120 // now check directive type
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
121 const char *dirtypes[] = { "AuthTrans", "NameTrans", "PathCheck", "ObjectType", "Service", "AddLog", "Error" };
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
122 if(serverconfig_validate_directive_name(node, dirtypes, 7, &typeindex)) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
123 return 1;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
124 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
125
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
126 // directives must have parameter names
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
127 ConfigParam *param_err;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
128 if(serverconfig_check_param_names(node, &param_err)) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
129 return 1;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
130 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
131
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
132 // check if the fn parameter exists
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
133 cxstring fn = serverconfig_directive_get_arg(node, cx_str("fn"));
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
134 if(fn.length == 0) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
135 return 1;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
136 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
137
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
138 return 0;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
139 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
140
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
141 static int validate_else_node(ConfigNode *node) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
142 // previous node must be "If" or "ElseIf"
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
143 ConfigNode *prev = serverconfig_previous_dir_or_obj(node);
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
144 const char *allowed_prev_types[] = { "If", "ElseIf" };
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
145 size_t typeindex;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
146 if(serverconfig_validate_directive_name(prev, allowed_prev_types, 2, &typeindex)) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
147 return 1; // prevous node (not counting space, comments) is not "If" or "Else"
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
148 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
149
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
150 // "Else" must have no args
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
151 return node->args ? 1 : 0;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
152 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
153
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
154 static int validate_elseif_node(ConfigNode *node) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
155 // the previous node must be "If" or "IfElse"
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
156 // in case if "IfElse", we also have to check all previous nodes, until
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
157 // we find the starting "If" node
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
158 const char *allowed_prev_types[] = { "If", "ElseIf" };
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
159 size_t typeindex;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
160 ConfigNode *prev = serverconfig_previous_dir_or_obj(node);
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
161 while(prev) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
162 if(serverconfig_validate_directive_name(prev, allowed_prev_types, 2, &typeindex)) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
163 return 1; // previous node was not "If" or "ElseIf"
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
164 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
165 // we found a valid "If" node, the whole construct is valid
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
166 if(typeindex == 0) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
167 return 0;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
168 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
169
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
170 prev = serverconfig_previous_dir_or_obj(node);
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
171 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
172 // at this point we found only "IfElse" nodes, but no "If" node
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
173 return 1;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
174 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
175
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
176 int objectconf_validate_objbegin(ConfigParser2 *parser, ConfigNode *node) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
177 // get object type
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
178 const char *objnames[] = { "Object", "Client", "If", "ElseIf", "Else" };
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
179 size_t typeindex;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
180 if(serverconfig_validate_directive_name(node, objnames, 5, &typeindex)) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
181 return 1; // unknown object type
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
182 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
183
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
184 // some special requirements for "Else" node
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
185 if(typeindex == 4) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
186 // type is "Else"
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
187 return validate_else_node(node);
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
188 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
189
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
190 // check "ElseIf" was used after "If" or "IfElse"
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
191 if(typeindex == 3 && validate_elseif_node(node)) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
192 return 1;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
193 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
194
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
195 // only Object must have a name/value arg, other types can have more
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
196 // complex parameters
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
197 if(typeindex == 0) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
198 // type is "Object"
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
199 ConfigParam *err;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
200 if(serverconfig_check_param_names(node, &err)) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
201 return 1;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
202 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
203 return 0;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
204 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
205
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
206 // all remaining object types must have arguments, but don't check more
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
207 return node->args ? 0 : 1;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
208 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
209
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
210 int objectconf_validate_objend(ConfigParser2 *parser, ConfigNode *node) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
211 return 0;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
212 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
213
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
214
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
215 void free_object_config(ObjectConfig *conf) {
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
216 // free other lists
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
217 if(conf->levels) {
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
218 //ucx_list_free(conf->levels);
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
219 }
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
220
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
221 // free mempool
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
222 //ucx_mempool_destroy(conf->parser.mp->pool);
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
223 free(conf);
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
224 }
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
225
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
228 int objconf_parse(void *p, ConfigLine *begin, ConfigLine *end, cxmutstr line) {
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 ObjectConfig *conf = p;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
231 begin->type = cfg_get_line_type(line);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 switch(begin->type) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 case LINE_BEGIN_TAG: {
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
234 ConfigTag *tag = cfg_parse_begin_tag(line, conf->parser.mp);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 if(tag == NULL) {
115
51d9a15eac98 improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
236 log_ereport(LOG_FAILURE, "Parse error in %s", conf->file);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 exit(-1); // TODO: better error handling
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 tag->begin = begin;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 tag->end = end;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
241 tag->type_num = cfg_get_tag_type(cx_strcast(tag->name));
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
242 //printf("line {%s}\n", cx_strdub(ll).ptr);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 if(objconf_on_begin_tag(conf, tag) != 0) {
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
244 fprintf(stderr, "1error\n");
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 exit(-1);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 break;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 case LINE_END_TAG: {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
250 cxmutstr tag = cfg_get_end_tag_name(line);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 if(objconf_on_end_tag(conf, tag) != 0) {
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
252 fprintf(stderr, "2error\n");
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 exit(-1);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 break;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 case LINE_DIRECTIVE: {
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
259 ConfigDirective *dir = cfg_parse_directive(
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 line,
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 conf->parser.mp);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 dir->begin = begin;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 dir->end = end;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 if(objconf_on_directive(conf, dir) != 0) {
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
265 fprintf(stderr, "3error\n");
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 exit(-1);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 return 0;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 int objconf_on_begin_tag(ObjectConfig *conf, ConfigTag *tag) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
274 CxAllocator *mp = conf->parser.mp;
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 if(tag->type_num != TAG_OBJECT) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
276 ConfigParserLevel *l = conf->levels;
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277 if(l->tag->type_num != TAG_OBJECT) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278 tag->parent = l->tag;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 switch(tag->type_num) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 case TAG_OBJECT: {
83
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
285 ConfigObject *obj = OBJ_NEW_N(mp, ConfigObject);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286 obj->begin = tag->begin;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 obj->end = tag->end;
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
288
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
289 obj->name = cfg_param_get(tag->param, cx_str("name"));
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
290 obj->ppath = cfg_param_get(tag->param, cx_str("ppath"));
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 conf->obj = obj;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
293 //conf->objects = ucx_list_append_a(mp, conf->objects, obj);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
294 cxListAdd(conf->objects, obj);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 // create tree level object
83
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
297 ConfigParserLevel *lvl = OBJ_NEW(mp, ConfigParserLevel);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 lvl->iftag = NULL;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 lvl->levelnum = 1;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 lvl->tag = tag;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
301 lvl->next = NULL;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
302 //conf->levels = ucx_list_prepend_a(mp, conf->levels, lvl);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
303 CFG_LEVEL_PREPEND(&conf->levels, lvl);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305 break;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307 case TAG_IF: {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 // create tree level object
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
309 ConfigParserLevel *last_lvl = conf->levels;
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310
83
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
311 ConfigParserLevel *lvl = OBJ_NEW(mp, ConfigParserLevel);
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
312
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313 lvl->iftag = NULL;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314 lvl->levelnum = last_lvl->levelnum + 1;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315 lvl->tag = tag;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
316 //conf->levels = ucx_list_prepend_a(mp, conf->levels, lvl);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
317 CFG_LEVEL_PREPEND(&conf->levels, lvl);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
318 last_lvl->iftag = tag;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
320 break;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
321 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
322 case TAG_ELSEIF: {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
323 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
324 case TAG_ELSE: {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
325 // create tree level object
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
326 ConfigParserLevel *last_lvl = conf->levels;
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327 tag->iftag = last_lvl->iftag;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329 ConfigParserLevel *lvl = OBJ_NEW(
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
330 conf->parser.mp,
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
331 ConfigParserLevel);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
332
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
333 lvl->iftag = last_lvl->tag;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 lvl->levelnum = last_lvl->levelnum + 1;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 lvl->tag = tag;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
336 //conf->levels = ucx_list_prepend(conf->levels, lvl);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
337 CFG_LEVEL_PREPEND(&conf->levels, lvl);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339 break;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
341 case TAG_CLIENT: {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 // create tree level object
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
343
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344 // TODO
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346 break;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
347 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
348 default: {
115
51d9a15eac98 improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
349 log_ereport(LOG_FAILURE, "objconf: unknown tag");
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
350 return 1;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
351 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
352 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
353
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
354 return 0;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
355 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
356
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
357 int objconf_on_end_tag(ObjectConfig *conf, cxmutstr tagname) {
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
358 int type = cfg_get_tag_type(cx_strcast(tagname));
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
359 if(type == -1) {
115
51d9a15eac98 improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
360 log_ereport(LOG_FAILURE, "objconf: unknown tag");
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
361 return 1;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
362 } else {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
363 if(type == TAG_OBJECT) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
364 conf->obj = NULL;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
365 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
366
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
367 // remove level
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
368 /*
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
369 conf->levels = ucx_list_remove_a(
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
370 conf->parser.mp,
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
371 conf->levels,
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
372 conf->levels);
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
373 */
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
374 conf->levels = conf->levels->next;
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
375 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
376
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
377 return 0;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
378 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
379
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
380 int objconf_on_directive(ObjectConfig *conf, ConfigDirective *dir) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
381 ConfigParserLevel *lvl = conf->levels;
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
382
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
383 // check if we have a condition for the directive
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
384 // if the level tag is not an object tag, use it as condition
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
385 if(lvl->tag->type_num != TAG_OBJECT) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
386 dir->condition = lvl->tag;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
387 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
388
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
389 // add directive to current object
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
390 /*
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
391 conf->obj->directives[dir->type_num] = ucx_list_append_a(
79
f48cea237ec3 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
392 conf->parser.mp,
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
393 conf->obj->directives[dir->type_num],
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
394 dir);
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
395 */
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
396
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
397 ConfigDirectiveList *dir_entry = cxMalloc(conf->parser.mp, sizeof(ConfigDirectiveList));
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
398 dir_entry->directive = dir;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
399 dir_entry->next = NULL;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
400 CFG_DIRECTIVES_ADD(&conf->obj->directives[dir->type_num], dir_entry);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
401
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
402 return 0;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
403 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
404

mercurial