src/server/config/objconf.c

Sat, 25 Feb 2023 11:38:33 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 25 Feb 2023 11:38:33 +0100
changeset 457
982e67c997e1
parent 453
4586d534f9b5
child 459
f21b4ff81c01
permissions
-rw-r--r--

update ldflags

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"
453
4586d534f9b5 fix build on macos
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 425
diff changeset
30 #include "logging.h"
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <string.h>
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
34 #include <cx/utils.h>
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
35
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 /* dev notes:
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 *
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 * to free ObjectConfig, free:
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 * line dlist
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 * mempool
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 * object
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
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 ObjectConfig *load_object_config(char *file) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 FILE *in = fopen(file, "r");
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 if(in == NULL) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 return NULL;
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
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 ObjectConfig *conf = malloc(sizeof(ObjectConfig));
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 conf->parser.parse = objconf_parse;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 conf->file = file;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
53 //conf->conditions = NULL;
23
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
54 conf->levels = NULL;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
55 conf->objects = cxPointerLinkedListCreate(cxDefaultAllocator, cx_cmp_ptr);
79
f48cea237ec3 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
56 //conf->lines = NULL;
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 int r = cfg_parse_basic_file((ConfigParser*)conf, in);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 if(r != 0) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 // TODO: free
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 return NULL;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 }
62
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
63
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
64 fclose(in);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 return conf;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68
419
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
69 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
70 CxMempool *mp = cxBasicMempoolCreate(512);
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
71 if(!mp) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
72 return NULL;
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
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
75 // setup parser
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
76 ConfigParser2 parser;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
77 memset(&parser, 0, sizeof(ConfigParser2));
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
78 parser.mp = mp;
425
6440171c257f make config parser delimiters configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 419
diff changeset
79 parser.delim = "()/*%";
419
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
80 parser.validateDirective = objectconf_validate_directive;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
81 parser.validateObjBegin = objectconf_validate_objbegin;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
82 parser.validateObjEnd = objectconf_validate_objend;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
83 parser.allow_hierarchy = 1;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
84
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
85 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
86 if(!obj_config) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
87 cxMempoolDestroy(mp);
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
88 return NULL;
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
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
91 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
92 if(!conf) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
93 cxMempoolDestroy(mp);
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
94 return NULL;
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
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
97 conf->mp = mp;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
98 conf->root = obj_config;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
99
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
100 return conf;
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
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
103 void objectconf_free(ObjectConfig2 *objconf) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
104 cxMempoolDestroy(objconf->mp);
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
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
107 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
108 // 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
109 // 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
110 // 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
111 // 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
112
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
113 // 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
114 // Object, Client, If, Else IfElse
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
115 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
116 size_t typeindex;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
117 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
118 return 0;
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
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
121 // now check directive type
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
122 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
123 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
124 return 1;
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
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
127 // directives must have parameter names
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
128 ConfigParam *param_err;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
129 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
130 return 1;
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
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
133 // 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
134 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
135 if(fn.length == 0) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
136 return 1;
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
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
139 return 0;
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
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
142 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
143 // 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
144 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
145 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
146 size_t typeindex;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
147 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
148 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
149 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
150
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
151 // "Else" must have no args
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
152 return node->args ? 1 : 0;
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
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
155 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
156 // 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
157 // 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
158 // 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
159 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
160 size_t typeindex;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
161 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
162 while(prev) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
163 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
164 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
165 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
166 // 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
167 if(typeindex == 0) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
168 return 0;
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
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
171 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
172 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
173 // 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
174 return 1;
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
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
177 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
178 // get object type
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
179 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
180 size_t typeindex;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
181 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
182 return 1; // unknown object type
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
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
185 // 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
186 if(typeindex == 4) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
187 // type is "Else"
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
188 return validate_else_node(node);
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
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
191 // 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
192 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
193 return 1;
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
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
196 // 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
197 // complex parameters
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
198 if(typeindex == 0) {
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
199 // type is "Object"
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
200 ConfigParam *err;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
201 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
202 return 1;
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
203 }
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
204 return 0;
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
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
207 // 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
208 return node->args ? 0 : 1;
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
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
211 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
212 return 0;
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
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
215
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
216 void free_object_config(ObjectConfig *conf) {
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
217 // free other lists
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
218 if(conf->levels) {
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
219 //ucx_list_free(conf->levels);
17
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
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
222 // free mempool
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
223 //ucx_mempool_destroy(conf->parser.mp->pool);
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
224 free(conf);
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
225 }
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
226
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
229 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
230 ObjectConfig *conf = p;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
232 begin->type = cfg_get_line_type(line);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 switch(begin->type) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 case LINE_BEGIN_TAG: {
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
235 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
236 if(tag == NULL) {
453
4586d534f9b5 fix build on macos
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 425
diff changeset
237 ws_cfg_log(LOG_FAILURE, "Parse error in %s", conf->file);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 exit(-1); // TODO: better error handling
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 tag->begin = begin;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 tag->end = end;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
242 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
243 //printf("line {%s}\n", cx_strdub(ll).ptr);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 if(objconf_on_begin_tag(conf, tag) != 0) {
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
245 fprintf(stderr, "1error\n");
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 exit(-1);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 break;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 case LINE_END_TAG: {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
251 cxmutstr tag = cfg_get_end_tag_name(line);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252 if(objconf_on_end_tag(conf, tag) != 0) {
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
253 fprintf(stderr, "2error\n");
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 exit(-1);
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
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 break;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 case LINE_DIRECTIVE: {
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
260 ConfigDirective *dir = cfg_parse_directive(
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 line,
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 conf->parser.mp);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 dir->begin = begin;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 dir->end = end;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 if(objconf_on_directive(conf, dir) != 0) {
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
266 fprintf(stderr, "3error\n");
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 exit(-1);
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 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 return 0;
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
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274 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
275 CxAllocator *mp = conf->parser.mp;
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276 if(tag->type_num != TAG_OBJECT) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
277 ConfigParserLevel *l = conf->levels;
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278 if(l->tag->type_num != TAG_OBJECT) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 tag->parent = l->tag;
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
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 switch(tag->type_num) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 case TAG_OBJECT: {
83
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
286 ConfigObject *obj = OBJ_NEW_N(mp, ConfigObject);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 obj->begin = tag->begin;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 obj->end = tag->end;
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
289
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
290 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
291 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
292
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 conf->obj = obj;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
294 //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
295 cxListAdd(conf->objects, obj);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 // create tree level object
83
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
298 ConfigParserLevel *lvl = OBJ_NEW(mp, ConfigParserLevel);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 lvl->iftag = NULL;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 lvl->levelnum = 1;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301 lvl->tag = tag;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
302 lvl->next = NULL;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
303 //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
304 CFG_LEVEL_PREPEND(&conf->levels, lvl);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 break;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 case TAG_IF: {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309 // create tree level object
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
310 ConfigParserLevel *last_lvl = conf->levels;
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311
83
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
312 ConfigParserLevel *lvl = OBJ_NEW(mp, ConfigParserLevel);
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
313
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314 lvl->iftag = NULL;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315 lvl->levelnum = last_lvl->levelnum + 1;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
316 lvl->tag = tag;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
317 //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
318 CFG_LEVEL_PREPEND(&conf->levels, lvl);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319 last_lvl->iftag = tag;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
320
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
321 break;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
322 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
323 case TAG_ELSEIF: {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
324 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
325 case TAG_ELSE: {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 // create tree level object
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
327 ConfigParserLevel *last_lvl = conf->levels;
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328 tag->iftag = last_lvl->iftag;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
330 ConfigParserLevel *lvl = OBJ_NEW(
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
331 conf->parser.mp,
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
332 ConfigParserLevel);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
333
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 lvl->iftag = last_lvl->tag;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 lvl->levelnum = last_lvl->levelnum + 1;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336 lvl->tag = tag;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
337 //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
338 CFG_LEVEL_PREPEND(&conf->levels, lvl);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 break;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
341 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 case TAG_CLIENT: {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
343 // create tree level object
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345 // TODO
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
347 break;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
348 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
349 default: {
453
4586d534f9b5 fix build on macos
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 425
diff changeset
350 ws_cfg_log(LOG_FAILURE, "objconf: unknown tag");
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
351 return 1;
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
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
355 return 0;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
356 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
357
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
358 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
359 int type = cfg_get_tag_type(cx_strcast(tagname));
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
360 if(type == -1) {
453
4586d534f9b5 fix build on macos
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 425
diff changeset
361 ws_cfg_log(LOG_FAILURE, "objconf: unknown tag");
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
362 return 1;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
363 } else {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
364 if(type == TAG_OBJECT) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
365 conf->obj = NULL;
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
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
368 // remove level
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
369 /*
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
370 conf->levels = ucx_list_remove_a(
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
371 conf->parser.mp,
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
372 conf->levels,
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
373 conf->levels);
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
374 */
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
375 conf->levels = conf->levels->next;
16
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
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
378 return 0;
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
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
381 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
382 ConfigParserLevel *lvl = conf->levels;
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
383
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
384 // check if we have a condition for the directive
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
385 // 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
386 if(lvl->tag->type_num != TAG_OBJECT) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
387 dir->condition = lvl->tag;
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
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
390 // add directive to current object
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
391 /*
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
392 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
393 conf->parser.mp,
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
394 conf->obj->directives[dir->type_num],
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
395 dir);
415
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
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
398 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
399 dir_entry->directive = dir;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
400 dir_entry->next = NULL;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
401 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
402
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
403 return 0;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
404 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
405

mercurial