]> git.evergreen-ils.org Git - working/Evergreen.git/blob - OpenSRF/src/libstack/osrfConfig.h
0d184fe5188838b8a163a33ce58ebb1d973d1ff6
[working/Evergreen.git] / OpenSRF / src / libstack / osrfConfig.h
1 /*
2 Copyright (C) 2005  Georgia Public Library Service 
3 Bill Erickson <highfalutin@gmail.com>
4
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.
9
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.
14 */
15
16 #ifndef _OSRF_CONFIG_H
17 #define _OSRF_CONFIG_H
18
19 #include "xml_utils.h"
20 #include "utils.h"
21 #include "string_array.h"
22 #include "objson/object.h"
23
24 typedef struct {
25         jsonObject* config;
26         char* configContext;
27 } osrfConfig;
28
29
30 /**
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
38                 it returns NULL;
39 */
40 osrfConfig* osrfConfigInit(char* configFile, char* configContext);
41
42 /**
43         @return True if we have a default config defined
44 */
45 int osrfConfigHasDefaultConfig();
46
47 /**
48         Replaces the config object's objson object.  This is useful
49         if you have an ojbson object already and not an XML config
50         file to parse.
51         @param cfg The config object to alter
52         @param obj The objson objet to use when searching values
53 */
54 void osrfConfigReplaceConfig(osrfConfig* cfg, const jsonObject* obj);
55
56 /** Deallocates a config object 
57         @param cfg The config object to free
58 */
59 void osrfConfigFree(osrfConfig* cfg);
60
61
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
65 */
66 void osrfConfigSetDefaultConfig(osrfConfig* cfg);
67
68 /* frees the default config if one exists */
69 void osrfConfigCleanup();
70
71
72 /** 
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* 
77
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
83                 config should be used
84         @param path The search path
85 */
86 char* osrfConfigGetValue(osrfConfig* cfg, char* path, ...);
87
88 /** 
89         Puts the list of values found at 'path' into the pre-allocated 
90         string array.  
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
93                 config should be used
94         @param arr An allocated string_array where the values will
95                 be stored
96         @param path The search path
97         @return the number of values added to the string array;
98 */
99
100 int osrfConfigGetValueList(osrfConfig* cfg, osrfStringArray* arr, char* path, ...);
101
102
103 #endif