Sun, 15 Sep 2024 09:47:36 +0200
improve sessionhandler trace logging
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:
39
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 "conf.h" |
453
4586d534f9b5
fix build on macos
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
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 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | int cfg_parse_basic_file(ConfigParser *parser, FILE *in) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
35 | parser->lines_begin = NULL; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
36 | parser->lines_end = NULL; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
37 | CxMempool *mp = cxBasicMempoolCreate(512); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
38 | CxAllocator *a = (CxAllocator*)mp->allocator; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
39 | parser->mp = a; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | // one logical line over many lines |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
42 | cxmutstr mline; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | mline.ptr = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | mline.length = 0; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
45 | ConfigLine *start_line = NULL; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
46 | ConfigLine *end_line = NULL; |
25
5dee29c7c530
Fixed config parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
47 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | // read file |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
49 | cxmutstr l; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | while((l = cfg_readln(in)).ptr != NULL) { |
25
5dee29c7c530
Fixed config parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
51 | void *org_ptr = l.ptr; |
5dee29c7c530
Fixed config parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
52 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | // put the line to the list |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | ConfigLine *line = OBJ_NEW(parser->mp, ConfigLine); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
55 | line->line = cx_strdup_a(parser->mp, cx_strcast(l)); // TODO: check for 0-len str |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | line->object = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | line->type = LINE_OTHER; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
58 | CFG_LINE_ADD(&parser->lines_begin, &parser->lines_end, line); |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | // check if the line contains something |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | l = cfg_trim_comment(l); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | line->type = cfg_get_basic_type(l); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | if(line->type == LINE_OTHER) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | // check for multi line |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | if(mline.ptr != NULL) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | // concate lines |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
68 | char *ptr = cxMalloc(a, mline.length + l.length + 1); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
69 | // TODO: maybe we can use cx_strcat |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | memcpy(ptr, mline.ptr, mline.length); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | memcpy(ptr + mline.length - 1, l.ptr, l.length); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | mline.length += l.length; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | free(mline.ptr); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | mline.ptr = ptr; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | mline.ptr[mline.length] = 0; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | end_line = line; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | line->type = LINE_MULTI; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | if(l.ptr[l.length - 1] == '\\') { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | if(mline.ptr == NULL) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
83 | mline = cx_strdup_a(parser->mp, cx_strcast(l)); |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | start_line = line; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | } else { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | // this line is complete so we can parse it |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
88 | cxmutstr ll; // we parse this line |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | if(mline.ptr == NULL) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | // single line |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | ll = l; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | start_line = line; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | end_line = line; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | } else { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | ll = mline; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | } |
25
5dee29c7c530
Fixed config parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
98 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | // parse |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | int r = parser->parse(parser, start_line, end_line, ll); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | // clean up |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | if(mline.ptr != NULL) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | free(mline.ptr); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | mline.ptr = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | mline.length = 0; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | start_line = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | end_line = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | if(r != 0) { |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
112 | free(org_ptr); |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | return -1; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | } |
25
5dee29c7c530
Fixed config parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
117 | |
5dee29c7c530
Fixed config parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
118 | free(org_ptr); |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | return 0; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
124 | cxmutstr cfg_readln(FILE *file) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
125 | cxmutstr ns; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | ns.ptr = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | ns.length = 0; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | if(!feof(file)) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | char buf[512]; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | buf[0] = 0; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | int len = 512; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | if(fgets(buf, len, file) == NULL) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | return ns; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | if(*buf == 0) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | printf("???\n"); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | return ns; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | char *ptr; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | if((ptr = strrchr(buf, '\n'))) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | ptr[0] = 0; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
148 | cxmutstr line = cx_mutstr(buf); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
149 | return cx_strdup(cx_strcast(line)); |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
152 | cxmutstr s; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | s.ptr = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | s.length = 0; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | return s; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | /* |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | * removes a comment from the line |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | */ |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
162 | cxmutstr cfg_trim_comment(cxmutstr line) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
163 | cxmutstr nl = line; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | for(int i=0;i<line.length;i++) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | if(line.ptr[i] == '#') { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | if(i > 0) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | nl.ptr = line.ptr + i - 1; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | nl.length = i; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | break; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | } else { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | nl.ptr = line.ptr; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | nl.length = 0; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | break; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
177 | return cx_strtrim_m(nl); |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | /* |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | * gets the first parameter in the params string and returns a new string |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | * containing the other parameters or an empty string, if there are no more |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | * parameters |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | */ |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
185 | cxmutstr cfg_param(cxmutstr params, cxmutstr *name, cxmutstr *value) { |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | name->ptr = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | name->length = 0; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | value->ptr = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | value->length = 0; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | // get name |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | int i; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | for(i=0;i<params.length;i++) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | char c = params.ptr[i]; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | if(c == '=') { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | break; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | } else if(c < 33) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | // no '=' means there is only a name, no value |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | name->ptr = params.ptr; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | name->length = i; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | params.ptr = params.ptr + i; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | params.length -= i; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
204 | return cx_strtrim_m(params); |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | name->ptr = params.ptr; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | name->length = i; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | i++; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | // get value |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | if(i>=params.length) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
214 | cxmutstr ns; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | ns.ptr = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | ns.length = 0; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | return ns; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | int quote = 0; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | value->ptr = params.ptr + i; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | for(;i<params.length;i++) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | char c = params.ptr[i]; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | if(c == '"') { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | if(quote) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | break; // end of quoted value |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | } else { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | quote = 1; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | value->ptr++; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | } else if(!quote && c < 33) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | break; // end of value |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | } |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
235 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
236 | if(quote) { |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
237 | // if the value is quoted, i points to the last quote char |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
238 | value->length = i - name->length - 2; // subtract the quotes |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
239 | i++; // set i behind the last quote |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
240 | } else { |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
241 | // i points to a white space char, which must be subtraced |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
242 | value->length = i - name->length - 1; |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
243 | } |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | if(value->length <= 0) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | value->length = 0; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | value->ptr = NULL; |
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 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | // create new params string |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251 | params.ptr += i; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | params.length -= i; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
253 | return cx_strtrim_m(params); |
16
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 | /* |
51 | 257 | * gets a value from a parameter |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
258 | */ |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
259 | cxmutstr cfg_param_get(ConfigParam *param, cxstring name) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
260 | while(param != NULL) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
261 | if(!cx_strcmp((cxstring){param->name.ptr, param->name.length}, name)) { |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | return param->value; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
264 | param = param->next; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
265 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
266 | return (cxmutstr){ NULL, 0 }; |
16
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 | /* |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
270 | * parses a line containing a directive and returns a ConfigDirective object |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
271 | * or NULL if an error occurs |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
272 | */ |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
273 | ConfigDirective* cfg_parse_directive(cxmutstr line, CxAllocator *mp) { |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
274 | if(line.length < 6) { |
453
4586d534f9b5
fix build on macos
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
275 | ws_cfg_log(LOG_FAILURE, "cfg_parse_directive: line too short"); |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
276 | return NULL; // line too short |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
277 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
278 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
279 | cxstring name; |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
280 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
281 | int i; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
282 | for(i=0;i<line.length;i++) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
283 | if(line.ptr[i] < 33) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
284 | break; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
285 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
286 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
287 | name.ptr = line.ptr; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
288 | name.length = i; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
289 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
290 | // create directive object |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
291 | ConfigDirective *directive = OBJ_NEW(mp, ConfigDirective); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
292 | directive->directive_type = cx_strdup_a(mp, name); |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
293 | directive->type_num = cfg_get_directive_type_num(name); |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
294 | directive->condition = NULL; // set later by main parsing function |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
295 | //directive->param = NULL; |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
296 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
297 | cxstring param_str; |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
298 | param_str.ptr = name.ptr + i; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
299 | param_str.length = line.length - i; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
300 | param_str = cx_strtrim(param_str); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
301 | directive->value = cx_strdup_a(mp, param_str); |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
302 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
303 | /* |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
304 | cxmutstr pname; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
305 | cxmutstr pvalue; |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
306 | for(;;) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
307 | param_str = cfg_param(param_str, &pname, &pvalue); |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
308 | if(pname.length <= 0) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
309 | break; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
310 | } |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
311 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
312 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
313 | // create param object |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
314 | ConfigParam *param = OBJ_NEW(mp, ConfigParam); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
315 | param->name = cx_strdup_mp(mp, pname); |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
316 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
317 | if(pvalue.length > 0) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
318 | param->value = cx_strdup_mp(mp, pvalue); |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
319 | } else { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
320 | param->value.ptr = NULL; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
321 | param->value.length = 0; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
322 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
323 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
324 | // add param to list |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
325 | |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
326 | //directive->param = ucx_list_append(directive->param, param); |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
327 | } |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
328 | */ |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
329 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
330 | return directive; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
331 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
332 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
333 | ConfigParam* cfg_param_list(cxmutstr param_str, CxAllocator *mp) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
334 | cxmutstr pname; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
335 | cxmutstr pvalue; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
336 | ConfigParam *plist_begin = NULL; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
337 | ConfigParam *plist_end = NULL; |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
338 | for(;;) { |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
339 | param_str = cfg_param(param_str, &pname, &pvalue); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
340 | if(pname.length <= 0) { |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
341 | break; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
342 | } |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
343 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
344 | // create param object |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
345 | ConfigParam *param = OBJ_NEW(mp, ConfigParam); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
346 | param->name = cx_strdup_a(mp, cx_strcast(pname)); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
347 | param->next = NULL; |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
348 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
349 | if(pvalue.length > 0) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
350 | param->value = cx_strdup_a(mp, cx_strcast(pvalue)); |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
351 | } else { |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
352 | param->value.ptr = NULL; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
353 | param->value.length = 0; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
354 | } |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
355 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
356 | // add param to list |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
357 | CFG_PARAM_ADD(&plist_begin, &plist_end, param); |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
358 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
359 | return plist_begin; |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
360 | } |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
361 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
362 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
363 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
364 | /* |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
365 | * gets the directive type number from a type string |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
366 | * valid types are: |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
367 | * AuthTrans 0 |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
368 | * NameTrans 1 |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
369 | * PathCheck 2 |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
370 | * ObjectType 3 |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
371 | * Service 4 |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
372 | * AddLog 5 |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
373 | * Init 6 |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
374 | */ |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
375 | int cfg_get_directive_type_num(cxstring type) { |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
376 | /* get nsapi function type */ |
95
74a81d9e19d0
added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
377 | |
74a81d9e19d0
added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
378 | // TODO: replace hard coded numbers |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
379 | int dt = -1; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
380 | if(cx_strcmp(type, cx_str("AuthTrans")) == 0) { |
95
74a81d9e19d0
added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
381 | dt = NSAPIAuthTrans; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
382 | } else if(cx_strcmp(type, cx_str("NameTrans")) == 0) { |
95
74a81d9e19d0
added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
383 | dt = NSAPINameTrans; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
384 | } else if(cx_strcmp(type, cx_str("PathCheck")) == 0) { |
95
74a81d9e19d0
added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
385 | dt = NSAPIPathCheck; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
386 | } else if(cx_strcmp(type, cx_str("ObjectType")) == 0) { |
95
74a81d9e19d0
added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
387 | dt = NSAPIObjectType; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
388 | } else if(cx_strcmp(type, cx_str("Service")) == 0) { |
95
74a81d9e19d0
added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
389 | dt = NSAPIService; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
390 | } else if(cx_strcmp(type, cx_str("Error")) == 0) { |
95
74a81d9e19d0
added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
391 | dt = NSAPIError; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
392 | } else if(cx_strcmp(type, cx_str("AddLog")) == 0) { |
95
74a81d9e19d0
added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
393 | dt = NSAPIAddLog; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
394 | } else if(cx_strcmp(type, cx_str("Init")) == 0) { |
95
74a81d9e19d0
added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
395 | dt = INIT_DIRECTIVE; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
396 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
397 | return dt; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
398 | } |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
399 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
400 | /* |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
401 | * checks if the line contains only a comment or space |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
402 | */ |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
403 | int cfg_get_basic_type(cxmutstr line) { |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
404 | if(line.length == 0) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
405 | return LINE_NOCONTENT; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
406 | } else if(line.ptr[0] == '#') { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
407 | return LINE_NOCONTENT; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
408 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
409 | return LINE_OTHER; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
410 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
411 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
412 | /* |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
413 | * checks if the line contains a begin/end tag or a directive |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
414 | */ |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
415 | int cfg_get_line_type(cxmutstr line) { |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
416 | if(line.length < 3) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
417 | // this line is to short to be correct |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
418 | return LINE_ERROR; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
419 | } |
25
5dee29c7c530
Fixed config parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
420 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
421 | if(line.ptr[0] == '<') { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
422 | // start or end tag |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
423 | // TODO: check for space between '<' and '/' |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
424 | if(line.ptr[1] == '/') { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
425 | return LINE_END_TAG; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
426 | } else { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
427 | return LINE_BEGIN_TAG; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
428 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
429 | } else { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
430 | return LINE_DIRECTIVE; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
431 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
432 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
433 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
434 | int cfg_get_tag_type(cxstring tag) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
435 | if(!cx_strcmp(tag, cx_str("Object"))) { |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
436 | return TAG_OBJECT; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
437 | } else if(!cx_strcmp(tag, cx_str("If"))) { |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
438 | return TAG_IF; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
439 | } else if(!cx_strcmp(tag, cx_str("ElseIf"))) { |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
440 | return TAG_ELSEIF; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
441 | } else if(!cx_strcmp(tag, cx_str("Else"))) { |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
442 | return TAG_ELSE; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
443 | } else if(!cx_strcmp(tag, cx_str("Client"))) { |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
444 | return TAG_CLIENT; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
445 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
446 | return -1; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
447 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
448 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
449 | /* |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
450 | * returns the name of the ending tag |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
451 | * on error, this functions returns a zero length string |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
452 | */ |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
453 | cxmutstr cfg_get_end_tag_name(cxmutstr line) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
454 | cxmutstr ns; |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
455 | ns.ptr = NULL; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
456 | ns.length = 0; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
457 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
458 | if(line.length < 4) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
459 | // minimum of 4 chars: </a> |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
460 | return ns; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
461 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
462 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
463 | cxmutstr name; |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
464 | name.ptr = line.ptr + 2; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
465 | name.length = line.length - 3; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
466 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
467 | // check for </ > frame |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
468 | if(line.ptr[0] != '<' |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
469 | || line.ptr[1] != '/' |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
470 | || line.ptr[line.length - 1] != '>') |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
471 | { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
472 | return ns; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
473 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
474 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
475 | return cx_strtrim_m(name); |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
476 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
477 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
478 | ConfigTag* cfg_parse_begin_tag(cxmutstr line, CxAllocator *mp) { |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
479 | if(line.length < 4) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
480 | return NULL; // this line can't contain a valid tag |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
481 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
482 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
483 | if(line.ptr[0] != '<' || line.ptr[line.length - 1] != '>') { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
484 | return NULL; // syntax error |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
485 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
486 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
487 | cxmutstr name; |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
488 | name.ptr = line.ptr + 1; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
489 | int i; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
490 | for(i=1;i<line.length - 1;i++) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
491 | if(line.ptr[i] < 33) { // char is space |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
492 | break; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
493 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
494 | } |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
495 | name.length = i - 1; |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
496 | if(name.length < 1) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
497 | return NULL; // syntax error |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
498 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
499 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
500 | // create tag object |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
501 | ConfigTag *tag = OBJ_NEW(mp, ConfigTag); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
502 | tag->name = cx_strdup_a(mp, cx_strcast(name)); |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
503 | tag->param = NULL; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
504 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
505 | // parse parameters |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
506 | cxmutstr param_str; |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
507 | param_str.ptr = line.ptr + i; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
508 | param_str.length = line.length - name.length - 2; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
509 | param_str = cx_strtrim_m(param_str); |
83
28433f06d5ee
added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
510 | if(param_str.length == 0) { |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
511 | return tag; // no parameters |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
512 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
513 | tag->param_str = cx_strdup_a(mp, cx_strcast(param_str)); |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
514 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
515 | cxmutstr pname; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
516 | cxmutstr pvalue; |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
517 | for(;;) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
518 | param_str = cfg_param(param_str, &pname, &pvalue); |
83
28433f06d5ee
added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
519 | if(pname.length == 0) { |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
520 | break; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
521 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
522 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
523 | // create param object |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
524 | ConfigParam *param = OBJ_NEW(mp, ConfigParam); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
525 | param->next = NULL; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
526 | param->name = cx_strdup_a(mp, cx_strcast(pname)); |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
527 | if(pvalue.length > 0) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
528 | param->value = cx_strdup_a(mp, cx_strcast(pvalue)); |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
529 | } else { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
530 | param->value.ptr = NULL; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
531 | param->value.length = 0; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
532 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
533 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
534 | // add param to list |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
535 | CFG_PARAM_ADD(&tag->param, NULL, param); |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
536 | } |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
537 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
538 | return tag; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
539 | } |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
540 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
541 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
542 | /* directive functions */ |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
543 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
544 | /* |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
545 | * gets a ConfigDirective with a specific name from a List of directives |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
546 | * returns a directive or NULL, if the directive cannot be found |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
547 | */ |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
548 | // TODO: remove |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
549 | /* |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
550 | ConfigDirective* cfg_directivelist_get(UcxList *dirs, cxmutstr name) { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
551 | while(dirs != NULL) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
552 | ConfigDirective *d = dirs->data; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
553 | if(d != NULL) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
554 | if(!cx_strcmp(d->directive_type, name)) { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
555 | return d; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
556 | } |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
557 | } |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
558 | dirs = dirs->next; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
559 | } |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
560 | return NULL; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
561 | } |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
562 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
563 | cxmutstr cfg_directivelist_get_str(UcxList *dirs, cxmutstr name) { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
564 | ConfigDirective *d = cfg_directivelist_get(dirs, name); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
565 | if(d == NULL) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
566 | cxmutstr n; |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
567 | n.ptr = NULL; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
568 | n.length = 0; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
569 | return n; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
570 | } |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
571 | //return cfg_directive_pstr1(d); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
572 | return d->value; |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
573 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
574 | */ |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
575 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
576 | /* |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
577 | * returns the name of the first parameter of the directive |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
578 | * useful for 'name value' directives |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
579 | */ |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
580 | /* |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
581 | cxmutstr cfg_directive_pstr1(ConfigDirective *dir) { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
582 | if(dir->param == NULL) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
583 | fprintf(stderr, "%s", "Error: cfg_directive_pstr1: param is NULL\n"); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
584 | cxmutstr n; |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
585 | n.ptr = NULL; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
586 | n.length = 0; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
587 | return n; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
588 | } |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
589 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
590 | ConfigParam *p = dir->param->data; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
591 | return p->name; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
592 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
593 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
594 | |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
595 | static void cfg_list_free(void *list) { |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
596 | ucx_list_free(list); |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
597 | } |
91 | 598 | |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
599 | static void cfg_map_free(void *map) { |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
600 | ucx_map_free(map); |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
601 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
602 | */ |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
603 | |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
604 | |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
605 | |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
606 |