2 * Copyright (c) 2002-2005 MontaVista Software, Inc.
6 * Author: Steven Dake (sdake@mvista.com)
8 * This software licensed under BSD license, the text of which follows:
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
13 * - Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * - Neither the name of the MontaVista Software, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived from this
20 * software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
39 #include <sys/socket.h>
40 #include <netinet/in.h>
41 #include <arpa/inet.h>
43 #include "../include/saAis.h"
44 #include "../include/list.h"
46 #include "mainconfig.h"
52 static char error_string_response
[512];
54 /* This just makes the code below a little neater */
55 static inline int objdb_get_string (
56 struct objdb_iface_ver0
*objdb
,
57 unsigned int object_service_handle
,
58 char *key
, char **value
)
63 if ( !(res
= objdb
->object_key_get (object_service_handle
,
76 static inline void objdb_get_int (
77 struct objdb_iface_ver0
*objdb
, unsigned int object_service_handle
,
78 char *key
, unsigned int *intvalue
)
82 if (!objdb
->object_key_get (object_service_handle
,
89 *intvalue
= atoi(value
);
94 static struct logsys_config_struct
{
96 unsigned int priority
;
100 int openais_main_config_read (
101 struct objdb_iface_ver0
*objdb
,
103 struct main_config
*main_config
)
105 unsigned int object_service_handle
;
106 unsigned int object_logger_subsys_handle
;
108 char *error_reason
= error_string_response
;
110 memset (main_config
, 0, sizeof (struct main_config
));
112 objdb
->object_find_reset (OBJECT_PARENT_HANDLE
);
114 main_config
->logmode
= LOG_MODE_FLUSH_AFTER_CONFIG
;
115 if (objdb
->object_find (
116 OBJECT_PARENT_HANDLE
,
119 &object_service_handle
) == 0) {
121 if (!objdb_get_string (objdb
,object_service_handle
, "to_file", &value
)) {
122 if (strcmp (value
, "yes") == 0) {
123 main_config
->logmode
|= LOG_MODE_OUTPUT_FILE
;
125 if (strcmp (value
, "no") == 0) {
126 main_config
->logmode
&= ~LOG_MODE_OUTPUT_FILE
;
129 if (!objdb_get_string (objdb
,object_service_handle
, "to_syslog", &value
)) {
130 if (strcmp (value
, "yes") == 0) {
131 main_config
->logmode
|= LOG_MODE_OUTPUT_SYSLOG_THREADED
;
133 if (strcmp (value
, "no") == 0) {
134 main_config
->logmode
&= ~LOG_MODE_OUTPUT_SYSLOG_THREADED
;
137 if (!objdb_get_string (objdb
,object_service_handle
, "to_stderr", &value
)) {
138 if (strcmp (value
, "yes") == 0) {
139 main_config
->logmode
|= LOG_MODE_OUTPUT_STDERR
;
141 if (strcmp (value
, "no") == 0) {
142 main_config
->logmode
&= ~LOG_MODE_OUTPUT_STDERR
;
146 if (!objdb_get_string (objdb
,object_service_handle
, "debug", &value
)) {
147 if (strcmp (value
, "on") == 0) {
148 main_config
->logmode
|= LOG_MODE_DISPLAY_DEBUG
;
150 if (strcmp (value
, "off") == 0) {
151 main_config
->logmode
&= ~LOG_MODE_DISPLAY_DEBUG
;
156 if (!objdb_get_string (objdb
,object_service_handle
, "timestamp", &value
)) {
157 if (strcmp (value
, "on") == 0) {
158 main_config
->logmode
|= LOG_MODE_DISPLAY_TIMESTAMP
;
160 if (strcmp (value
, "off") == 0) {
161 main_config
->logmode
&= ~LOG_MODE_DISPLAY_TIMESTAMP
;
166 if (!objdb_get_string (objdb
,object_service_handle
, "logfile", &value
)) {
167 main_config
->logfile
= strdup (value
);
170 if (!objdb_get_string (objdb
,object_service_handle
, "fileline", &value
)) {
171 if (strcmp (value
, "on") == 0) {
172 main_config
->logmode
|= LOG_MODE_DISPLAY_FILELINE
;
174 if (strcmp (value
, "off") == 0) {
175 main_config
->logmode
&= ~LOG_MODE_DISPLAY_FILELINE
;
181 if (!objdb_get_string (objdb
,object_service_handle
, "syslog_facility", &value
)) {
182 if (strcmp (value
, "daemon") == 0) {
183 main_config
->syslog_facility
= LOG_DAEMON
;
185 if (strcmp (value
, "local0") == 0) {
186 main_config
->syslog_facility
= LOG_LOCAL0
;
188 if (strcmp (value
, "local1") == 0) {
189 main_config
->syslog_facility
= LOG_LOCAL1
;
191 if (strcmp (value
, "local2") == 0) {
192 main_config
->syslog_facility
= LOG_LOCAL2
;
194 if (strcmp (value
, "local3") == 0) {
195 main_config
->syslog_facility
= LOG_LOCAL3
;
197 if (strcmp (value
, "local4") == 0) {
198 main_config
->syslog_facility
= LOG_LOCAL4
;
200 if (strcmp (value
, "local5") == 0) {
201 main_config
->syslog_facility
= LOG_LOCAL5
;
203 if (strcmp (value
, "local6") == 0) {
204 main_config
->syslog_facility
= LOG_LOCAL6
;
206 if (strcmp (value
, "local7") == 0) {
207 main_config
->syslog_facility
= LOG_LOCAL7
;
209 error_reason
= "unknown syslog facility specified";
214 while (objdb
->object_find (object_service_handle
,
216 strlen ("logger_subsys"),
217 &object_logger_subsys_handle
) == 0) {
219 if (!objdb_get_string (objdb
,
220 object_logger_subsys_handle
,
223 strncpy (logsys_logger
.subsys
, value
,
224 sizeof (logsys_logger
.subsys
));
227 error_reason
= "subsys required for logger directive";
230 if (!objdb_get_string (objdb
, object_logger_subsys_handle
, "debug", &value
)) {
231 if (strcmp (value
, "on") == 0) {
232 logsys_logger
.priority
= LOG_LEVEL_DEBUG
;
234 if (strcmp (value
, "off") == 0) {
235 logsys_logger
.priority
&= ~LOG_LEVEL_DEBUG
;
240 if (!objdb_get_string (objdb
, object_logger_subsys_handle
, "tags", &value
)) {
241 char *token
= strtok (value
, "|");
243 while (token
!= NULL
) {
244 if (strcmp (token
, "enter") == 0) {
245 logsys_logger
.tags
|= LOGSYS_TAG_ENTER
;
246 } else if (strcmp (token
, "leave") == 0) {
247 logsys_logger
.tags
|= LOGSYS_TAG_LEAVE
;
248 } else if (strcmp (token
, "trace1") == 0) {
249 logsys_logger
.tags
|= LOGSYS_TAG_TRACE1
;
250 } else if (strcmp (token
, "trace2") == 0) {
251 logsys_logger
.tags
|= LOGSYS_TAG_TRACE2
;
252 } else if (strcmp (token
, "trace3") == 0) {
253 logsys_logger
.tags
|= LOGSYS_TAG_TRACE3
;
254 } else if (strcmp (token
, "trace4") == 0) {
255 logsys_logger
.tags
|= LOGSYS_TAG_TRACE4
;
256 } else if (strcmp (token
, "trace5") == 0) {
257 logsys_logger
.tags
|= LOGSYS_TAG_TRACE5
;
258 } else if (strcmp (token
, "trace6") == 0) {
259 logsys_logger
.tags
|= LOGSYS_TAG_TRACE6
;
260 } else if (strcmp (token
, "trace7") == 0) {
261 logsys_logger
.tags
|= LOGSYS_TAG_TRACE7
;
262 } else if (strcmp (token
, "trace8") == 0) {
263 logsys_logger
.tags
|= LOGSYS_TAG_TRACE8
;
265 error_reason
= "bad tags value";
269 token
= strtok(NULL
, "|");
273 * set individual logger configurations
275 logsys_config_subsys_set (
276 logsys_logger
.subsys
,
278 logsys_logger
.priority
);
283 objdb
->object_find_reset (OBJECT_PARENT_HANDLE
);
284 if (objdb
->object_find (
285 OBJECT_PARENT_HANDLE
,
288 &object_service_handle
) == 0) {
290 if (!objdb_get_string (objdb
,object_service_handle
, "user", &value
)) {
291 main_config
->user
= strdup(value
);
293 if (!objdb_get_string (objdb
,object_service_handle
, "group", &value
)) {
294 main_config
->group
= strdup(value
);
298 /* Default user/group */
299 if (!main_config
->user
)
300 main_config
->user
= "ais";
302 if (!main_config
->group
)
303 main_config
->group
= "ais";
305 if ((main_config
->logmode
& LOG_MODE_OUTPUT_FILE
) &&
306 (main_config
->logfile
== NULL
)) {
307 error_reason
= "logmode set to 'file' but no logfile specified";
311 if (main_config
->syslog_facility
== 0)
312 main_config
->syslog_facility
= LOG_DAEMON
;
317 sprintf (error_string_response
,
318 "parse error in config: %s.\n",
321 *error_string
= error_string_response
;