]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/osrfConfig.h
75490f7680f2883f19dc949a6918852ccc4ee4b3
[OpenSRF.git] / include / opensrf / 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 /**
20         @file osrfConfig.h
21         @brief Routines for loading, storing, and searching configurations.
22
23         A configuration file, encoded as XML, is loaded and translated into a jsonObject.  This
24         object is stored in an osrfConfig, along with an optional context string which, if
25         present, restricts subsequent searches to a subset of the jsonObject.
26
27         In theory the context string could identify multiple subtrees of the total configuration.
28         In practice it is used to partition a configuration file into different pieces, each piece
29         to be used by a different application.
30
31         Normally an application loads a default configuration, accessible from every linked
32         module.  It is also possible, although seldom useful, to create and search a configuration
33         distinct from the default configuration.
34 */
35
36 #include <opensrf/xml_utils.h>
37 #include <opensrf/utils.h>
38 #include <opensrf/string_array.h>
39 #include <opensrf/osrf_json.h>
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 /**
46         @brief Represents a configuration; normally loaded from an XML configuration file.
47 */
48 typedef struct {
49         jsonObject* config;   /**< Represents the contents of the XML configuration file. */
50         char* configContext;  /**< Context string (optional). */
51 } osrfConfig;
52
53 osrfConfig* osrfConfigInit(const char* configFile, const char* configContext);
54
55 int osrfConfigHasDefaultConfig( void );
56
57 void osrfConfigReplaceConfig(osrfConfig* cfg, const jsonObject* obj);
58
59 void osrfConfigFree(osrfConfig* cfg);
60
61 void osrfConfigSetDefaultConfig(osrfConfig* cfg);
62
63 void osrfConfigCleanup( void );
64
65 char* osrfConfigGetValue(const osrfConfig* cfg, const char* path, ...);
66
67 jsonObject* osrfConfigGetValueObject(osrfConfig* cfg, const char* path, ...);
68
69 int osrfConfigGetValueList(const osrfConfig* cfg, osrfStringArray* arr,
70                 const char* path, ...);
71
72 #ifdef __cplusplus
73 }
74 #endif
75
76 #endif