2 Copyright (C) 2005 Georgia Public Library Service
3 Bill Erickson <highfalutin@gmail.com>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
16 #ifndef _OSRF_CONFIG_H
17 #define _OSRF_CONFIG_H
19 #include <opensrf/xml_utils.h>
20 #include <opensrf/utils.h>
21 #include <opensrf/string_array.h>
22 #include <opensrf/osrf_json.h>
31 Parses a new config file. Caller is responsible for freeing the returned
32 config object when finished.
33 @param configFile The XML config file to parse.
34 @param configContext Optional root of the subtree in the config file where
35 we will look for values. If it's not provided, searches will be
36 performed from the root of the config file
37 @return The config object if the file parses successfully. Otherwise
40 osrfConfig* osrfConfigInit(char* configFile, char* configContext);
43 @return True if we have a default config defined
45 int osrfConfigHasDefaultConfig();
48 Replaces the config object's objson object. This is useful
49 if you have an ojbson object already and not an XML config
51 @param cfg The config object to alter
52 @param obj The objson objet to use when searching values
54 void osrfConfigReplaceConfig(osrfConfig* cfg, const jsonObject* obj);
56 /** Deallocates a config object
57 @param cfg The config object to free
59 void osrfConfigFree(osrfConfig* cfg);
62 /* Assigns the default config file. This file will be used whenever
63 NULL is passed to config retrieval functions
64 @param cfg The config object to use as the default config
66 void osrfConfigSetDefaultConfig(osrfConfig* cfg);
68 /* frees the default config if one exists */
69 void osrfConfigCleanup();
73 Returns the value in the config found at 'path'.
74 If the value found at 'path' is a long or a double,
75 the value is stringified and then returned.
76 The caller must free the returned char*
78 if there is a configContext, then it will be appended to
79 the front of the path like so: //<configContext>/<path>
80 if no configContext was provided to osfConfigSetFile, then
81 the path is interpreted literally.
82 @param cfg The config file to search or NULL if the default
84 @param path The search path
86 char* osrfConfigGetValue(osrfConfig* cfg, char* path, ...);
89 Puts the list of values found at 'path' into the pre-allocated
91 Note that the config node found at 'path' must be an array.
92 @param cfg The config file to search or NULL if the default
94 @param arr An allocated string_array where the values will
96 @param path The search path
97 @return the number of values added to the string array;
100 int osrfConfigGetValueList(osrfConfig* cfg, osrfStringArray* arr, char* path, ...);