- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,200 +0,0 @@ |
1 |
-/* |
|
2 |
- * Standalone Configuration File Parser |
|
3 |
- * |
|
4 |
- * Copyright (C) 2008 iptelorg GmbH |
|
5 |
- * Written by Jan Janak <jan@iptel.org> |
|
6 |
- * |
|
7 |
- * This file is part of Kamailio, a free SIP server. |
|
8 |
- * |
|
9 |
- * Kamailio is free software; you can redistribute it and/or modify it under the |
|
10 |
- * terms of the GNU General Public License as published by the Free Software |
|
11 |
- * Foundation; either version 2 of the License, or (at your option) any later |
|
12 |
- * version. |
|
13 |
- * |
|
14 |
- * Kamailio is distributed in the hope that it will be useful, but WITHOUT ANY |
|
15 |
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
16 |
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
17 |
- * details. |
|
18 |
- * |
|
19 |
- * You should have received a copy of the GNU General Public License along |
|
20 |
- * with this program; if not, write to the Free Software Foundation, Inc., |
|
21 |
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
22 |
- */ |
|
23 |
- |
|
24 |
-/*! |
|
25 |
- * \file |
|
26 |
- * \brief Kamailio core :: Standalone Configuration File Parser |
|
27 |
- * Written by Jan Janak <jan@iptel.org> |
|
28 |
- * |
|
29 |
- * \ingroup core |
|
30 |
- * Module: \ref core |
|
31 |
- * |
|
32 |
- * See \ref ConfigEngine |
|
33 |
- */ |
|
34 |
- |
|
35 |
-#ifndef _CFG_PARSER_H |
|
36 |
-#define _CFG_PARSER_H |
|
37 |
- |
|
38 |
-#include "str.h" |
|
39 |
-#include <stdio.h> |
|
40 |
- |
|
41 |
-#define MAX_TOKEN_LEN 512 /*!< Token names cannot be longer than this value */ |
|
42 |
- |
|
43 |
- |
|
44 |
-/*! \brief Configuration flags */ |
|
45 |
-typedef enum cfg_flags { |
|
46 |
- /*! \brief Extended tokens can contain also delimiters, in addition to |
|
47 |
- * alpha-numeric characters, this is used on the righ side of assignments |
|
48 |
- * where no quotes are used. |
|
49 |
- */ |
|
50 |
- CFG_EXTENDED_ALPHA = (1 << 0), |
|
51 |
- |
|
52 |
- /*! \brief The parser performs case-insensitive comparisons of token strings by |
|
53 |
- * default. The parser will use case-sensitive comparison instead if this |
|
54 |
- * flag is set. |
|
55 |
- */ |
|
56 |
- CFG_CASE_SENSITIVE = (1 << 1), |
|
57 |
- |
|
58 |
- /*! \brief This is a flag that can be set in the last element of cfg_option |
|
59 |
- * arrays (this is the one with 0 as token name). When this flag is set |
|
60 |
- * then the value or parsing function of the element will be used for |
|
61 |
- * options that do not match any other element in the array. |
|
62 |
- */ |
|
63 |
- CFG_DEFAULT = (1 << 2), |
|
64 |
- |
|
65 |
- |
|
66 |
- /*! \brief When this flag is set then the name of the options is a prefix and all |
|
67 |
- * options that have the same prefix will be matched by this entry. |
|
68 |
- */ |
|
69 |
- CFG_PREFIX = (1 << 3), |
|
70 |
- |
|
71 |
- /*! \brief The result of cfg_parse_str_val will be in a buffer allocated by |
|
72 |
- * pkg_malloc, if the destination variable contains a pointer to a buffer |
|
73 |
- * already then it will be freed with pkg_free first. |
|
74 |
- */ |
|
75 |
- CFG_STR_PKGMEM = (1 << 4), |
|
76 |
- |
|
77 |
- /*! \brief The result of cfg_parse_str_val will be in a buffer allocated by |
|
78 |
- * shm_malloc, if the destination variable contains a pointer to a buffer |
|
79 |
- * already then it will be freed with shm_free first. |
|
80 |
- */ |
|
81 |
- CFG_STR_SHMMEM = (1 << 5), |
|
82 |
- |
|
83 |
- /*! \brief The result of cfg_parse_str_val will be in a buffer allocated by |
|
84 |
- * malloc, if the destination variable contains a pointer to a buffer |
|
85 |
- * already then it will be freed with free first. |
|
86 |
- */ |
|
87 |
- CFG_STR_MALLOC = (1 << 6), |
|
88 |
- |
|
89 |
- /*! \brief The result of cfg_parse_str_val will be copied into a pre-allocated |
|
90 |
- * buffer with a fixed size, a pointer to str variable which contains the |
|
91 |
- * buffer and its size is passed to the function in parameter 'param'. |
|
92 |
- */ |
|
93 |
- CFG_STR_STATIC = (1 << 7), |
|
94 |
- |
|
95 |
-} cfg_flags_t; |
|
96 |
- |
|
97 |
- |
|
98 |
-enum cfg_token_type { |
|
99 |
- CFG_TOKEN_EOF = -1, |
|
100 |
- CFG_TOKEN_ALPHA = -2, |
|
101 |
- CFG_TOKEN_STRING = -3 |
|
102 |
-}; |
|
103 |
- |
|
104 |
- |
|
105 |
-/*! \brief Structure representing a lexical token */ |
|
106 |
-typedef struct cfg_token { |
|
107 |
- char buf [MAX_TOKEN_LEN]; |
|
108 |
- int type; /*!< Token type */ |
|
109 |
- str val; /*!< Token value */ |
|
110 |
- struct { /*!< Position of first and last character of token in file */ |
|
111 |
- int line; /*!< The starting/ending line of the token */ |
|
112 |
- int col; /*!< The starting/ending column of the token */ |
|
113 |
- } start, end; |
|
114 |
-} cfg_token_t; |
|
115 |
- |
|
116 |
- |
|
117 |
-struct cfg_parser; |
|
118 |
- |
|
119 |
-typedef int (*cfg_func_f)(void* param, struct cfg_parser* st, |
|
120 |
- unsigned int flags); |
|
121 |
- |
|
122 |
- |
|
123 |
-/*! \brief Token mapping structure. |
|
124 |
- * |
|
125 |
- * This structure is used to map tokens to values or function calls. Arrays of |
|
126 |
- * such structures are typically provided by the caller of the parser. |
|
127 |
- */ |
|
128 |
-typedef struct cfg_option { |
|
129 |
- char* name; /*!< Token name */ |
|
130 |
- unsigned int flags; |
|
131 |
- void* param; /*!< Pointer to the destination variable */ |
|
132 |
- int val; /*!< Value */ |
|
133 |
- cfg_func_f f; /*!< Parser function to be called */ |
|
134 |
-} cfg_option_t; |
|
135 |
- |
|
136 |
- |
|
137 |
-/*! \brief Parser state */ |
|
138 |
-typedef struct cfg_parser { |
|
139 |
- FILE* f; /*!< Handle of the currently open file */ |
|
140 |
- char* file; /*!< Current file name */ |
|
141 |
- int line; /*!< Current line */ |
|
142 |
- int col; /*!< Column index */ |
|
143 |
- struct cfg_option* options; /*!< Array of supported options */ |
|
144 |
- struct { |
|
145 |
- cfg_func_f parser; /*!< Section parser function */ |
|
146 |
- void* param; /*!< Parameter value for the parser function */ |
|
147 |
- } section; |
|
148 |
- struct cfg_token* cur_opt; /*!< Current option */ |
|
149 |
-} cfg_parser_t; |
|
150 |
- |
|
151 |
- |
|
152 |
-extern struct cfg_option cfg_bool_values[]; |
|
153 |
- |
|
154 |
-struct cfg_parser* cfg_parser_init(str* basedir, str* filename); |
|
155 |
- |
|
156 |
-void cfg_section_parser(struct cfg_parser* st, cfg_func_f parser, void* param); |
|
157 |
- |
|
158 |
-void cfg_set_options(struct cfg_parser* st, struct cfg_option* options); |
|
159 |
- |
|
160 |
-int sr_cfg_parse(struct cfg_parser* st); |
|
161 |
- |
|
162 |
-void cfg_parser_close(struct cfg_parser* st); |
|
163 |
- |
|
164 |
-struct cfg_option* cfg_lookup_token(struct cfg_option* options, str* token); |
|
165 |
- |
|
166 |
-/*! ! \brief Interface to the lexical scanner */ |
|
167 |
-int cfg_get_token(struct cfg_token* token, struct cfg_parser* st, unsigned int flags); |
|
168 |
- |
|
169 |
-/* Commonly needed parser functions */ |
|
170 |
- |
|
171 |
-int cfg_eat_equal(struct cfg_parser* st, unsigned int flags); |
|
172 |
- |
|
173 |
-int cfg_eat_eol(struct cfg_parser* st, unsigned int flags); |
|
174 |
- |
|
175 |
-/*! \brief Parse section identifier of form [section]. The function expects parameter |
|
176 |
- * param to be of type (str*). The result string is allocated using pkg_malloc |
|
177 |
- * and is zero terminated. To free the memory use pkg_free(((str*)param)->s) |
|
178 |
- */ |
|
179 |
-int cfg_parse_section(void* param, struct cfg_parser* st, unsigned int flags); |
|
180 |
- |
|
181 |
-/*! \brief Parse string parameter value, either quoted or unquoted */ |
|
182 |
-int cfg_parse_str_opt(void* param, struct cfg_parser* st, unsigned int flags); |
|
183 |
- |
|
184 |
-int cfg_parse_str(void* param, struct cfg_parser* st, unsigned int flags); |
|
185 |
- |
|
186 |
-int cfg_parse_enum_opt(void* param, struct cfg_parser* st, unsigned int flags); |
|
187 |
- |
|
188 |
-int cfg_parse_enum(void* param, struct cfg_parser* st, unsigned int flags); |
|
189 |
- |
|
190 |
-/*! \brief Parser integer parameter value */ |
|
191 |
-int cfg_parse_int_opt(void* param, struct cfg_parser* st, unsigned int flags); |
|
192 |
- |
|
193 |
-int cfg_parse_int(void* param, struct cfg_parser* st, unsigned int flags); |
|
194 |
- |
|
195 |
-/*! \brief Parse boolean parameter value */ |
|
196 |
-int cfg_parse_bool_opt(void* param, struct cfg_parser* st, unsigned int flags); |
|
197 |
- |
|
198 |
-int cfg_parse_bool(void* param, struct cfg_parser* st, unsigned int flags); |
|
199 |
- |
|
200 |
-#endif /* _CFG_PARSER_H */ |
... | ... |
@@ -69,7 +69,7 @@ typedef enum cfg_flags { |
69 | 69 |
CFG_PREFIX = (1 << 3), |
70 | 70 |
|
71 | 71 |
/*! \brief The result of cfg_parse_str_val will be in a buffer allocated by |
72 |
- * pkg_malloc, if the destination varaiable contains a pointer to a buffer |
|
72 |
+ * pkg_malloc, if the destination variable contains a pointer to a buffer |
|
73 | 73 |
* already then it will be freed with pkg_free first. |
74 | 74 |
*/ |
75 | 75 |
CFG_STR_PKGMEM = (1 << 4), |
... | ... |
@@ -1,18 +1,17 @@ |
1 | 1 |
/* |
2 |
- * $Id$ |
|
3 | 2 |
* Standalone Configuration File Parser |
4 | 3 |
* |
5 | 4 |
* Copyright (C) 2008 iptelorg GmbH |
6 | 5 |
* Written by Jan Janak <jan@iptel.org> |
7 | 6 |
* |
8 |
- * This file is part of SER, a free SIP server. |
|
7 |
+ * This file is part of Kamailio, a free SIP server. |
|
9 | 8 |
* |
10 |
- * SER is free software; you can redistribute it and/or modify it under the |
|
9 |
+ * Kamailio is free software; you can redistribute it and/or modify it under the |
|
11 | 10 |
* terms of the GNU General Public License as published by the Free Software |
12 | 11 |
* Foundation; either version 2 of the License, or (at your option) any later |
13 | 12 |
* version. |
14 | 13 |
* |
15 |
- * SER is distributed in the hope that it will be useful, but WITHOUT ANY |
|
14 |
+ * Kamailio is distributed in the hope that it will be useful, but WITHOUT ANY |
|
16 | 15 |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
17 | 16 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
18 | 17 |
* details. |
... | ... |
@@ -25,6 +24,7 @@ |
25 | 24 |
/*! |
26 | 25 |
* \file |
27 | 26 |
* \brief SIP-router core :: Standalone Configuration File Parser |
27 |
+ * Written by Jan Janak <jan@iptel.org> |
|
28 | 28 |
* |
29 | 29 |
* \ingroup core |
30 | 30 |
* Module: \ref core |
... | ... |
@@ -19,7 +19,7 @@ |
19 | 19 |
* |
20 | 20 |
* You should have received a copy of the GNU General Public License along |
21 | 21 |
* with this program; if not, write to the Free Software Foundation, Inc., |
22 |
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
22 |
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
23 | 23 |
*/ |
24 | 24 |
|
25 | 25 |
/*! |
... | ... |
@@ -163,7 +163,7 @@ void cfg_parser_close(struct cfg_parser* st); |
163 | 163 |
|
164 | 164 |
struct cfg_option* cfg_lookup_token(struct cfg_option* options, str* token); |
165 | 165 |
|
166 |
-/*! ! \briefInterface to the lexical scanner */ |
|
166 |
+/*! ! \brief Interface to the lexical scanner */ |
|
167 | 167 |
int cfg_get_token(struct cfg_token* token, struct cfg_parser* st, unsigned int flags); |
168 | 168 |
|
169 | 169 |
/* Commonly needed parser functions */ |
Allow relative parhs in the cfg_parser framework (used by the tls
module, ldap(s) and iptrtpproxy), by adding a new "basedir"
parameter to cfg_parser_init().
If basedir == 0 and the filename does not start with '/', the
filename path will be considered to be relative to the main ser
config file (e.g. ser -f /etc/ser/ser.cfg => relative to /etc/ser/ ).
This was the previous behaviour.
If basedir == "" the filename path will be considered to be
relative to the working directory (ser -w /tmp => relative to
/tmp).
For other basedir values, the filename path will be considered to
be relative to basedir.
... | ... |
@@ -151,7 +151,7 @@ typedef struct cfg_parser { |
151 | 151 |
|
152 | 152 |
extern struct cfg_option cfg_bool_values[]; |
153 | 153 |
|
154 |
-struct cfg_parser* cfg_parser_init(str* filename); |
|
154 |
+struct cfg_parser* cfg_parser_init(str* basedir, str* filename); |
|
155 | 155 |
|
156 | 156 |
void cfg_section_parser(struct cfg_parser* st, cfg_func_f parser, void* param); |
157 | 157 |
|
... | ... |
@@ -21,6 +21,15 @@ |
21 | 21 |
* with this program; if not, write to the Free Software Foundation, Inc., |
22 | 22 |
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 | 23 |
*/ |
24 |
+/*! |
|
25 |
+ * \file |
|
26 |
+ * \brief SIP-router core :: Standalone Configuration File Parser |
|
27 |
+ * |
|
28 |
+ * \ingroup core |
|
29 |
+ * Module: \ref core |
|
30 |
+ * |
|
31 |
+ * See \ref ConfigEngine |
|
32 |
+ */ |
|
24 | 33 |
|
25 | 34 |
#ifndef _CFG_PARSER_H |
26 | 35 |
#define _CFG_PARSER_H |
... | ... |
@@ -28,23 +37,24 @@ |
28 | 37 |
#include "str.h" |
29 | 38 |
#include <stdio.h> |
30 | 39 |
|
31 |
-#define MAX_TOKEN_LEN 512 /**< Token names cannot be longer than this value */ |
|
40 |
+#define MAX_TOKEN_LEN 512 /*!< Token names cannot be longer than this value */ |
|
32 | 41 |
|
33 | 42 |
|
43 |
+/*! \brief Configuration flags */ |
|
34 | 44 |
typedef enum cfg_flags { |
35 |
- /** Extended tokens can contain also delimiters, in addition to |
|
45 |
+ /*! \brief Extended tokens can contain also delimiters, in addition to |
|
36 | 46 |
* alpha-numeric characters, this is used on the righ side of assignments |
37 | 47 |
* where no quotes are used. |
38 | 48 |
*/ |
39 | 49 |
CFG_EXTENDED_ALPHA = (1 << 0), |
40 | 50 |
|
41 |
- /** The parser performs case-insensitive comparisons of token strings by |
|
51 |
+ /*! \brief The parser performs case-insensitive comparisons of token strings by |
|
42 | 52 |
* default. The parser will use case-sensitive comparison instead if this |
43 | 53 |
* flag is set. |
44 | 54 |
*/ |
45 | 55 |
CFG_CASE_SENSITIVE = (1 << 1), |
46 | 56 |
|
47 |
- /** This is a flag that can be set in the last element of cfg_option |
|
57 |
+ /*! \brief This is a flag that can be set in the last element of cfg_option |
|
48 | 58 |
* arrays (this is the one with 0 as token name). When this flag is set |
49 | 59 |
* then the value or parsing function of the element will be used for |
50 | 60 |
* options that do not match any other element in the array. |
... | ... |
@@ -52,30 +62,30 @@ typedef enum cfg_flags { |
52 | 62 |
CFG_DEFAULT = (1 << 2), |
53 | 63 |
|
54 | 64 |
|
55 |
- /** When this flag is set then the name of the options is a prefix and all |
|
65 |
+ /*! \brief When this flag is set then the name of the options is a prefix and all |
|
56 | 66 |
* options that have the same prefix will be matched by this entry. |
57 | 67 |
*/ |
58 | 68 |
CFG_PREFIX = (1 << 3), |
59 | 69 |
|
60 |
- /** The result of cfg_parse_str_val will be in a buffer allocated by |
|
70 |
+ /*! \brief The result of cfg_parse_str_val will be in a buffer allocated by |
|
61 | 71 |
* pkg_malloc, if the destination varaiable contains a pointer to a buffer |
62 | 72 |
* already then it will be freed with pkg_free first. |
63 | 73 |
*/ |
64 | 74 |
CFG_STR_PKGMEM = (1 << 4), |
65 | 75 |
|
66 |
- /** The result of cfg_parse_str_val will be in a buffer allocated by |
|
76 |
+ /*! \brief The result of cfg_parse_str_val will be in a buffer allocated by |
|
67 | 77 |
* shm_malloc, if the destination variable contains a pointer to a buffer |
68 | 78 |
* already then it will be freed with shm_free first. |
69 | 79 |
*/ |
70 | 80 |
CFG_STR_SHMMEM = (1 << 5), |
71 | 81 |
|
72 |
- /** The result of cfg_parse_str_val will be in a buffer allocated by |
|
82 |
+ /*! \brief The result of cfg_parse_str_val will be in a buffer allocated by |
|
73 | 83 |
* malloc, if the destination variable contains a pointer to a buffer |
74 | 84 |
* already then it will be freed with free first. |
75 | 85 |
*/ |
76 | 86 |
CFG_STR_MALLOC = (1 << 6), |
77 | 87 |
|
78 |
- /** The result of cfg_parse_str_val will be copied into a pre-allocated |
|
88 |
+ /*! \brief The result of cfg_parse_str_val will be copied into a pre-allocated |
|
79 | 89 |
* buffer with a fixed size, a pointer to str variable which contains the |
80 | 90 |
* buffer and its size is passed to the function in parameter 'param'. |
81 | 91 |
*/ |
... | ... |
@@ -91,14 +101,14 @@ enum cfg_token_type { |
91 | 101 |
}; |
92 | 102 |
|
93 | 103 |
|
94 |
-/** Structure representing a lexical token */ |
|
104 |
+/*! \brief Structure representing a lexical token */ |
|
95 | 105 |
typedef struct cfg_token { |
96 | 106 |
char buf [MAX_TOKEN_LEN]; |
97 |
- int type; /**< Token type */ |
|
98 |
- str val; /**< Token value */ |
|
99 |
- struct { /**< Position of first and last character of token in file */ |
|
100 |
- int line; /**< The starting/ending line of the token */ |
|
101 |
- int col; /**< The starting/ending column of the token */ |
|
107 |
+ int type; /*!< Token type */ |
|
108 |
+ str val; /*!< Token value */ |
|
109 |
+ struct { /*!< Position of first and last character of token in file */ |
|
110 |
+ int line; /*!< The starting/ending line of the token */ |
|
111 |
+ int col; /*!< The starting/ending column of the token */ |
|
102 | 112 |
} start, end; |
103 | 113 |
} cfg_token_t; |
104 | 114 |
|
... | ... |
@@ -109,31 +119,32 @@ typedef int (*cfg_func_f)(void* param, struct cfg_parser* st, |
109 | 119 |
unsigned int flags); |
110 | 120 |
|
111 | 121 |
|
112 |
-/** Token mapping structure. |
|
122 |
+/*! \brief Token mapping structure. |
|
123 |
+ * |
|
113 | 124 |
* This structure is used to map tokens to values or function calls. Arrays of |
114 | 125 |
* such structures are typically provided by the caller of the parser. |
115 | 126 |
*/ |
116 | 127 |
typedef struct cfg_option { |
117 |
- char* name; /**< Token name */ |
|
128 |
+ char* name; /*!< Token name */ |
|
118 | 129 |
unsigned int flags; |
119 |
- void* param; /**< Pointer to the destination variable */ |
|
120 |
- int val; /**< Value */ |
|
121 |
- cfg_func_f f; /**< Parser function to be called */ |
|
130 |
+ void* param; /*!< Pointer to the destination variable */ |
|
131 |
+ int val; /*!< Value */ |
|
132 |
+ cfg_func_f f; /*!< Parser function to be called */ |
|
122 | 133 |
} cfg_option_t; |
123 | 134 |
|
124 | 135 |
|
125 |
-/* Parser state */ |
|
136 |
+/*! \brief Parser state */ |
|
126 | 137 |
typedef struct cfg_parser { |
127 |
- FILE* f; /**< Handle of the currently open file */ |
|
128 |
- char* file; /**< Current file name */ |
|
129 |
- int line; /**< Current line */ |
|
130 |
- int col; /**< Column index */ |
|
131 |
- struct cfg_option* options; /**< Array of supported options */ |
|
138 |
+ FILE* f; /*!< Handle of the currently open file */ |
|
139 |
+ char* file; /*!< Current file name */ |
|
140 |
+ int line; /*!< Current line */ |
|
141 |
+ int col; /*!< Column index */ |
|
142 |
+ struct cfg_option* options; /*!< Array of supported options */ |
|
132 | 143 |
struct { |
133 |
- cfg_func_f parser; /**< Section parser function */ |
|
134 |
- void* param; /**< Parameter value for the parser function */ |
|
144 |
+ cfg_func_f parser; /*!< Section parser function */ |
|
145 |
+ void* param; /*!< Parameter value for the parser function */ |
|
135 | 146 |
} section; |
136 |
- struct cfg_token* cur_opt; /**< Current option */ |
|
147 |
+ struct cfg_token* cur_opt; /*!< Current option */ |
|
137 | 148 |
} cfg_parser_t; |
138 | 149 |
|
139 | 150 |
|
... | ... |
@@ -151,7 +162,7 @@ void cfg_parser_close(struct cfg_parser* st); |
151 | 162 |
|
152 | 163 |
struct cfg_option* cfg_lookup_token(struct cfg_option* options, str* token); |
153 | 164 |
|
154 |
-/** Interface to the lexical scanner */ |
|
165 |
+/*! ! \briefInterface to the lexical scanner */ |
|
155 | 166 |
int cfg_get_token(struct cfg_token* token, struct cfg_parser* st, unsigned int flags); |
156 | 167 |
|
157 | 168 |
/* Commonly needed parser functions */ |
... | ... |
@@ -160,13 +171,13 @@ int cfg_eat_equal(struct cfg_parser* st, unsigned int flags); |
160 | 171 |
|
161 | 172 |
int cfg_eat_eol(struct cfg_parser* st, unsigned int flags); |
162 | 173 |
|
163 |
-/* Parse section identifier of form [section]. The function expects parameter |
|
174 |
+/*! \brief Parse section identifier of form [section]. The function expects parameter |
|
164 | 175 |
* param to be of type (str*). The result string is allocated using pkg_malloc |
165 | 176 |
* and is zero terminated. To free the memory use pkg_free(((str*)param)->s) |
166 | 177 |
*/ |
167 | 178 |
int cfg_parse_section(void* param, struct cfg_parser* st, unsigned int flags); |
168 | 179 |
|
169 |
-/* Parse string parameter value, either quoted or unquoted */ |
|
180 |
+/*! \brief Parse string parameter value, either quoted or unquoted */ |
|
170 | 181 |
int cfg_parse_str_opt(void* param, struct cfg_parser* st, unsigned int flags); |
171 | 182 |
|
172 | 183 |
int cfg_parse_str(void* param, struct cfg_parser* st, unsigned int flags); |
... | ... |
@@ -175,12 +186,12 @@ int cfg_parse_enum_opt(void* param, struct cfg_parser* st, unsigned int flags); |
175 | 186 |
|
176 | 187 |
int cfg_parse_enum(void* param, struct cfg_parser* st, unsigned int flags); |
177 | 188 |
|
178 |
-/* Parser integer parameter value */ |
|
189 |
+/*! \brief Parser integer parameter value */ |
|
179 | 190 |
int cfg_parse_int_opt(void* param, struct cfg_parser* st, unsigned int flags); |
180 | 191 |
|
181 | 192 |
int cfg_parse_int(void* param, struct cfg_parser* st, unsigned int flags); |
182 | 193 |
|
183 |
-/* Parse boolean parameter value */ |
|
194 |
+/*! \brief Parse boolean parameter value */ |
|
184 | 195 |
int cfg_parse_bool_opt(void* param, struct cfg_parser* st, unsigned int flags); |
185 | 196 |
|
186 | 197 |
int cfg_parse_bool(void* param, struct cfg_parser* st, unsigned int flags); |
- fix overlapping symbols for the libconfuse library used from carrierroute,
added 'sr_' prefix to cfg_init and cfg_parse core functions
- fix all modules that called this functions
... | ... |
@@ -145,7 +145,7 @@ void cfg_section_parser(struct cfg_parser* st, cfg_func_f parser, void* param); |
145 | 145 |
|
146 | 146 |
void cfg_set_options(struct cfg_parser* st, struct cfg_option* options); |
147 | 147 |
|
148 |
-int cfg_parse(struct cfg_parser* st); |
|
148 |
+int sr_cfg_parse(struct cfg_parser* st); |
|
149 | 149 |
|
150 | 150 |
void cfg_parser_close(struct cfg_parser* st); |
151 | 151 |
|
... | ... |
@@ -156,7 +156,9 @@ int cfg_get_token(struct cfg_token* token, struct cfg_parser* st, unsigned int f |
156 | 156 |
|
157 | 157 |
/* Commonly needed parser functions */ |
158 | 158 |
|
159 |
-int cfg_eat_equal(struct cfg_parser* st); |
|
159 |
+int cfg_eat_equal(struct cfg_parser* st, unsigned int flags); |
|
160 |
+ |
|
161 |
+int cfg_eat_eol(struct cfg_parser* st, unsigned int flags); |
|
160 | 162 |
|
161 | 163 |
/* Parse section identifier of form [section]. The function expects parameter |
162 | 164 |
* param to be of type (str*). The result string is allocated using pkg_malloc |
... | ... |
@@ -165,14 +167,22 @@ int cfg_eat_equal(struct cfg_parser* st); |
165 | 167 |
int cfg_parse_section(void* param, struct cfg_parser* st, unsigned int flags); |
166 | 168 |
|
167 | 169 |
/* Parse string parameter value, either quoted or unquoted */ |
168 |
-int cfg_parse_str_val(void* param, struct cfg_parser* st, unsigned int flags); |
|
170 |
+int cfg_parse_str_opt(void* param, struct cfg_parser* st, unsigned int flags); |
|
171 |
+ |
|
172 |
+int cfg_parse_str(void* param, struct cfg_parser* st, unsigned int flags); |
|
173 |
+ |
|
174 |
+int cfg_parse_enum_opt(void* param, struct cfg_parser* st, unsigned int flags); |
|
169 | 175 |
|
170 |
-int cfg_parse_enum_val(void* param, struct cfg_parser* st, unsigned int flags); |
|
176 |
+int cfg_parse_enum(void* param, struct cfg_parser* st, unsigned int flags); |
|
171 | 177 |
|
172 | 178 |
/* Parser integer parameter value */ |
173 |
-int cfg_parse_int_val(void* param, struct cfg_parser* st, unsigned int flags); |
|
179 |
+int cfg_parse_int_opt(void* param, struct cfg_parser* st, unsigned int flags); |
|
180 |
+ |
|
181 |
+int cfg_parse_int(void* param, struct cfg_parser* st, unsigned int flags); |
|
174 | 182 |
|
175 | 183 |
/* Parse boolean parameter value */ |
176 |
-int cfg_parse_bool_val(void* param, struct cfg_parser* st, unsigned int flags); |
|
184 |
+int cfg_parse_bool_opt(void* param, struct cfg_parser* st, unsigned int flags); |
|
185 |
+ |
|
186 |
+int cfg_parse_bool(void* param, struct cfg_parser* st, unsigned int flags); |
|
177 | 187 |
|
178 | 188 |
#endif /* _CFG_PARSER_H */ |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,178 @@ |
1 |
+/* |
|
2 |
+ * $Id$ |
|
3 |
+ * Standalone Configuration File Parser |
|
4 |
+ * |
|
5 |
+ * Copyright (C) 2008 iptelorg GmbH |
|
6 |
+ * Written by Jan Janak <jan@iptel.org> |
|
7 |
+ * |
|
8 |
+ * This file is part of SER, a free SIP server. |
|
9 |
+ * |
|
10 |
+ * SER is free software; you can redistribute it and/or modify it under the |
|
11 |
+ * terms of the GNU General Public License as published by the Free Software |
|
12 |
+ * Foundation; either version 2 of the License, or (at your option) any later |
|
13 |
+ * version. |
|
14 |
+ * |
|
15 |
+ * SER is distributed in the hope that it will be useful, but WITHOUT ANY |
|
16 |
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
17 |
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
18 |
+ * details. |
|
19 |
+ * |
|
20 |
+ * You should have received a copy of the GNU General Public License along |
|
21 |
+ * with this program; if not, write to the Free Software Foundation, Inc., |
|
22 |
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
+ */ |
|
24 |
+ |
|
25 |
+#ifndef _CFG_PARSER_H |
|
26 |
+#define _CFG_PARSER_H |
|
27 |
+ |
|
28 |
+#include "str.h" |
|
29 |
+#include <stdio.h> |
|
30 |
+ |
|
31 |
+#define MAX_TOKEN_LEN 512 /**< Token names cannot be longer than this value */ |
|
32 |
+ |
|
33 |
+ |
|
34 |
+typedef enum cfg_flags { |
|
35 |
+ /** Extended tokens can contain also delimiters, in addition to |
|
36 |
+ * alpha-numeric characters, this is used on the righ side of assignments |
|
37 |
+ * where no quotes are used. |
|
38 |
+ */ |
|
39 |
+ CFG_EXTENDED_ALPHA = (1 << 0), |
|
40 |
+ |
|
41 |
+ /** The parser performs case-insensitive comparisons of token strings by |
|
42 |
+ * default. The parser will use case-sensitive comparison instead if this |
|
43 |
+ * flag is set. |
|
44 |
+ */ |
|
45 |
+ CFG_CASE_SENSITIVE = (1 << 1), |
|
46 |
+ |
|
47 |
+ /** This is a flag that can be set in the last element of cfg_option |
|
48 |
+ * arrays (this is the one with 0 as token name). When this flag is set |
|
49 |
+ * then the value or parsing function of the element will be used for |
|
50 |
+ * options that do not match any other element in the array. |
|
51 |
+ */ |
|
52 |
+ CFG_DEFAULT = (1 << 2), |
|
53 |
+ |
|
54 |
+ |
|
55 |
+ /** When this flag is set then the name of the options is a prefix and all |
|
56 |
+ * options that have the same prefix will be matched by this entry. |
|
57 |
+ */ |
|
58 |
+ CFG_PREFIX = (1 << 3), |
|
59 |
+ |
|
60 |
+ /** The result of cfg_parse_str_val will be in a buffer allocated by |
|
61 |
+ * pkg_malloc, if the destination varaiable contains a pointer to a buffer |
|
62 |
+ * already then it will be freed with pkg_free first. |
|
63 |
+ */ |
|
64 |
+ CFG_STR_PKGMEM = (1 << 4), |
|
65 |
+ |
|
66 |
+ /** The result of cfg_parse_str_val will be in a buffer allocated by |
|
67 |
+ * shm_malloc, if the destination variable contains a pointer to a buffer |
|
68 |
+ * already then it will be freed with shm_free first. |
|
69 |
+ */ |
|
70 |
+ CFG_STR_SHMMEM = (1 << 5), |
|
71 |
+ |
|
72 |
+ /** The result of cfg_parse_str_val will be in a buffer allocated by |
|
73 |
+ * malloc, if the destination variable contains a pointer to a buffer |
|
74 |
+ * already then it will be freed with free first. |
|
75 |
+ */ |
|
76 |
+ CFG_STR_MALLOC = (1 << 6), |
|
77 |
+ |
|
78 |
+ /** The result of cfg_parse_str_val will be copied into a pre-allocated |
|
79 |
+ * buffer with a fixed size, a pointer to str variable which contains the |
|
80 |
+ * buffer and its size is passed to the function in parameter 'param'. |
|
81 |
+ */ |
|
82 |
+ CFG_STR_STATIC = (1 << 7), |
|
83 |
+ |
|
84 |
+} cfg_flags_t; |
|
85 |
+ |
|
86 |
+ |
|
87 |
+enum cfg_token_type { |
|
88 |
+ CFG_TOKEN_EOF = -1, |
|
89 |
+ CFG_TOKEN_ALPHA = -2, |
|
90 |
+ CFG_TOKEN_STRING = -3 |
|
91 |
+}; |
|
92 |
+ |
|
93 |
+ |
|
94 |
+/** Structure representing a lexical token */ |
|
95 |
+typedef struct cfg_token { |
|
96 |
+ char buf [MAX_TOKEN_LEN]; |
|
97 |
+ int type; /**< Token type */ |
|
98 |
+ str val; /**< Token value */ |
|
99 |
+ struct { /**< Position of first and last character of token in file */ |
|
100 |
+ int line; /**< The starting/ending line of the token */ |
|
101 |
+ int col; /**< The starting/ending column of the token */ |
|
102 |
+ } start, end; |
|
103 |
+} cfg_token_t; |
|
104 |
+ |
|
105 |
+ |
|
106 |
+struct cfg_parser; |
|
107 |
+ |
|
108 |
+typedef int (*cfg_func_f)(void* param, struct cfg_parser* st, |
|
109 |
+ unsigned int flags); |
|
110 |
+ |
|
111 |
+ |
|
112 |
+/** Token mapping structure. |
|
113 |
+ * This structure is used to map tokens to values or function calls. Arrays of |
|
114 |
+ * such structures are typically provided by the caller of the parser. |
|
115 |
+ */ |
|
116 |
+typedef struct cfg_option { |
|
117 |
+ char* name; /**< Token name */ |
|
118 |
+ unsigned int flags; |
|
119 |
+ void* param; /**< Pointer to the destination variable */ |
|
120 |
+ int val; /**< Value */ |
|
121 |
+ cfg_func_f f; /**< Parser function to be called */ |
|
122 |
+} cfg_option_t; |
|
123 |
+ |
|
124 |
+ |
|
125 |
+/* Parser state */ |
|
126 |
+typedef struct cfg_parser { |
|
127 |
+ FILE* f; /**< Handle of the currently open file */ |
|
128 |
+ char* file; /**< Current file name */ |
|
129 |
+ int line; /**< Current line */ |
|
130 |
+ int col; /**< Column index */ |
|
131 |
+ struct cfg_option* options; /**< Array of supported options */ |
|
132 |
+ struct { |
|
133 |
+ cfg_func_f parser; /**< Section parser function */ |
|
134 |
+ void* param; /**< Parameter value for the parser function */ |
|
135 |
+ } section; |
|
136 |
+ struct cfg_token* cur_opt; /**< Current option */ |
|
137 |
+} cfg_parser_t; |
|
138 |
+ |
|
139 |
+ |
|
140 |
+extern struct cfg_option cfg_bool_values[]; |
|
141 |
+ |
|
142 |
+struct cfg_parser* cfg_parser_init(str* filename); |
|
143 |
+ |
|
144 |
+void cfg_section_parser(struct cfg_parser* st, cfg_func_f parser, void* param); |
|
145 |
+ |
|
146 |
+void cfg_set_options(struct cfg_parser* st, struct cfg_option* options); |
|
147 |
+ |
|
148 |
+int cfg_parse(struct cfg_parser* st); |
|
149 |
+ |
|
150 |
+void cfg_parser_close(struct cfg_parser* st); |
|
151 |
+ |
|
152 |
+struct cfg_option* cfg_lookup_token(struct cfg_option* options, str* token); |
|
153 |
+ |
|
154 |
+/** Interface to the lexical scanner */ |
|
155 |
+int cfg_get_token(struct cfg_token* token, struct cfg_parser* st, unsigned int flags); |
|
156 |
+ |
|
157 |
+/* Commonly needed parser functions */ |
|
158 |
+ |
|
159 |
+int cfg_eat_equal(struct cfg_parser* st); |
|
160 |
+ |
|
161 |
+/* Parse section identifier of form [section]. The function expects parameter |
|
162 |
+ * param to be of type (str*). The result string is allocated using pkg_malloc |
|
163 |
+ * and is zero terminated. To free the memory use pkg_free(((str*)param)->s) |
|
164 |
+ */ |
|
165 |
+int cfg_parse_section(void* param, struct cfg_parser* st, unsigned int flags); |
|
166 |
+ |
|
167 |
+/* Parse string parameter value, either quoted or unquoted */ |
|
168 |
+int cfg_parse_str_val(void* param, struct cfg_parser* st, unsigned int flags); |
|
169 |
+ |
|
170 |
+int cfg_parse_enum_val(void* param, struct cfg_parser* st, unsigned int flags); |
|
171 |
+ |
|
172 |
+/* Parser integer parameter value */ |
|
173 |
+int cfg_parse_int_val(void* param, struct cfg_parser* st, unsigned int flags); |
|
174 |
+ |
|
175 |
+/* Parse boolean parameter value */ |
|
176 |
+int cfg_parse_bool_val(void* param, struct cfg_parser* st, unsigned int flags); |
|
177 |
+ |
|
178 |
+#endif /* _CFG_PARSER_H */ |
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,30 +0,0 @@ |
1 |
-/* |
|
2 |
- * $Id$ |
|
3 |
- */ |
|
4 |
- |
|
5 |
-#ifndef cfg_parser_h |
|
6 |
-#define cfg_parser_h |
|
7 |
- |
|
8 |
-#include <stdio.h> |
|
9 |
- |
|
10 |
-#define CFG_EMPTY 0 |
|
11 |
-#define CFG_COMMENT 1 |
|
12 |
-#define CFG_SKIP 2 |
|
13 |
-#define CFG_RULE 3 |
|
14 |
-#define CFG_ERROR -1 |
|
15 |
- |
|
16 |
-#define MAX_LINE_SIZE 800 |
|
17 |
- |
|
18 |
-struct cfg_line{ |
|
19 |
- int type; |
|
20 |
- char* method; |
|
21 |
- char* uri; |
|
22 |
- char* address; |
|
23 |
- short int port; |
|
24 |
-}; |
|
25 |
- |
|
26 |
- |
|
27 |
-int cfg_parse_line(char* line, struct cfg_line* cl); |
|
28 |
-int cfg_parse_stream(FILE* stream); |
|
29 |
- |
|
30 |
-#endif |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,29 @@ |
1 |
+/* |
|
2 |
+ * $Id$ |
|
3 |
+ */ |
|
4 |
+ |
|
5 |
+#ifndef cfg_parser_h |
|
6 |
+#define cfg_parser_h |
|
7 |
+ |
|
8 |
+#include <stdio.h> |
|
9 |
+ |
|
10 |
+#define CFG_EMPTY 0 |
|
11 |
+#define CFG_COMMENT 1 |
|
12 |
+#define CFG_SKIP 2 |
|
13 |
+#define CFG_RULE 3 |
|
14 |
+#define CFG_ERROR -1 |
|
15 |
+ |
|
16 |
+#define MAX_LINE_SIZE 800 |
|
17 |
+ |
|
18 |
+struct cfg_line{ |
|
19 |
+ int type; |
|
20 |
+ char* method; |
|
21 |
+ char* uri; |
|
22 |
+ char* address; |
|
23 |
+}; |
|
24 |
+ |
|
25 |
+ |
|
26 |
+int cfg_parse_line(char* line, struct cfg_line* cl); |
|
27 |
+int cfg_parse_stream(FILE* stream); |
|
28 |
+ |
|
29 |
+#endif |