1 /*
2  *  Copyright (C) 2004-2008 Christos Tsantilas
3  *
4  *  This program is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU Lesser General Public
6  *  License as published by the Free Software Foundation; either
7  *  version 2.1 of the License, or (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  *  Lesser General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Lesser General Public
15  *  License along with this library; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17  *  MA  02110-1301  USA.
18  */
19 
20 
21 #ifndef __CFG_PARAM_H
22 #define __CFG_PARAM_H
23 #include "c-icap.h"
24 #include "array.h"
25 
26 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30 
31 struct ci_magics_db;
32 struct ci_port;
33 
34 /**
35  \defgroup CONFIG c-icap server configuration API
36  \ingroup API
37  *
38  */
39 
40 
41 /**
42  * This struct holds the basic configurations of c-icap server. It passed as
43  * argument to services and modules inititalization functions
44  \ingroup CONFIG
45  *
46  * Do not use directly this struct but better use the documended macros and
47  * functions.
48  */
49 struct ci_server_conf {
50     ci_vector_t  *PORTS;
51     char *TMPDIR;
52     char *PIDFILE;
53     char *COMMANDS_SOCKET;
54     char *RUN_USER;
55     char *RUN_GROUP;
56     char *cfg_file;
57     char *magics_file;
58     struct ci_magics_db *MAGIC_DB;
59     char *SERVICES_DIR;
60     char *MODULES_DIR;
61     char *SERVER_ADMIN;
62     char *SERVER_NAME;
63     int START_SERVERS;
64     int MAX_SERVERS;
65     int THREADS_PER_CHILD;
66     int MIN_SPARE_THREADS;
67     int MAX_SPARE_THREADS;
68 
69 #ifdef USE_OPENSSL
70     char *TLS_PASSPHRASE;
71     int TLS_ENABLED;
72 #endif
73 };
74 
75 /**
76  * This struct holds a configuration parameter of c-icap server.
77  \ingroup CONFIG
78  * An array of ci_conf_entry structs can be used to define the configuration
79  * directives of a service or module which can be set in c-icap configuration
80  * file.
81  \code
82  int AParam;
83  struct ci_conf_entry conf_table[] = {
84     {"Aparameter", &AParam, ci_cfg_set_int, "This is a simple configuration parameter"},
85     {NULL,NULL,NULL,NULL}
86  }
87  \endcode
88  * In the above example the  ci_cfg_set_int function is predefined.
89  * If the table "conf_table" attached to the service "AService" then the AParam
90  * integer variable can be set from the c-icap configuration file using the
91  * directive "AService.Aparameter"
92  */
93 struct ci_conf_entry {
94     /**
95      * The configuration directive
96      */
97     const char *name;
98     /**
99      * A pointer to the configuration data
100      */
101     void *data;
102     /**
103      * Pointer to the function which will be used to set configuration data.
104      \param name is the configuration directive.It passed as argument by the
105      *      c-icap server
106      \param argv is a NULL termined string array which holds the list of
107      *      arguments of configuration parameter
108      \param setdata is o pointer to set data which passed as argument by
109      *      c-icap server
110      \return Non zero on success, zero otherwise
111      */
112     int (*action)(const char *name, const char **argv,void *setdata);
113     /**
114      * A description message
115      */
116     const char *msg;
117 };
118 
119 /* Command line options implementation structure */
120 struct ci_options_entry {
121     const char *name;
122     const char *parameter;
123     void *data;
124     int (*action)(const char *name, const char **argv,void *setdata);
125     const char *msg;
126 };
127 
128 /*Struct for storing default parameter values*/
129 struct cfg_default_value {
130     void *param;
131     void *value;
132     int size;
133     struct cfg_default_value *next;
134 };
135 
136 #define MAIN_TABLE 1
137 #define ALIAS_TABLE 2
138 
139 #ifndef CI_BUILD_LIB
140 extern struct ci_server_conf CI_CONF;
141 
142 struct cfg_default_value * cfg_default_value_store(void *param, void *value,int size);
143 struct cfg_default_value * cfg_default_value_replace(void *param, void *value);
144 void *                     cfg_default_value_restore(void *value);
145 struct cfg_default_value * cfg_default_value_search(void *param);
146 
147 int register_conf_table(const char *name,struct ci_conf_entry *table,int type);
148 struct ci_conf_entry * unregister_conf_table(const char *name);
149 int config(int argc, char **argv);
150 
151 int intl_cfg_set_str(const char *directive,const char **argv,void *setdata);
152 int intl_cfg_set_int(const char *directive,const char **argv,void *setdata);
153 int intl_cfg_onoff(const char *directive,const char **argv,void *setdata);
154 int intl_cfg_disable(const char *directive,const char **argv,void *setdata);
155 int intl_cfg_enable(const char *directive,const char **argv,void *setdata);
156 int intl_cfg_size_off(const char *directive,const char **argv,void *setdata);
157 int intl_cfg_size_long(const char *directive,const char **argv,void *setdata);
158 #endif
159 
160 
161 CI_DECLARE_FUNC(void)   ci_cfg_lib_init();
162 CI_DECLARE_FUNC(void)   ci_cfg_lib_reset();
163 CI_DECLARE_FUNC(void)   ci_cfg_lib_destroy();
164 CI_DECLARE_FUNC(void *) ci_cfg_alloc_mem(int size);
165 
166 /**
167  * Sets a string configuration parameter. The setdata are a pointer to a
168  * string pointer
169  \ingroup CONFIG
170  */
171 CI_DECLARE_FUNC(int) ci_cfg_set_str(const char *directive,const char **argv,void *setdata);
172 
173 /**
174  * Sets an int configuration parameter. The setdata is a pointer to an integer
175  \ingroup CONFIG
176  */
177 CI_DECLARE_FUNC(int) ci_cfg_set_int(const char *directive,const char **argv,void *setdata);
178 
179 /**
180  * Sets an on/off configuration parameter. The setdata is a pointer to an
181  * integer, which when the argument is "on" it is set to 1 and when the
182  * argument is "off" it is set to 0.
183  \ingroup CONFIG
184  */
185 CI_DECLARE_FUNC(int) ci_cfg_onoff(const char *directive,const char **argv,void *setdata);
186 
187 /**
188  * Can used with configuration parameters which does not takes arguments but
189  * when defined just disable a feature.
190  * The setdata is a pointer to an int which is set to zero.
191  \ingroup CONFIG
192  */
193 CI_DECLARE_FUNC(int) ci_cfg_disable(const char *directive,const char **argv,void *setdata);
194 
195 /**
196  * Can used with configuration parameters which does not takes arguments but
197  * when defined just enable a feature.
198  * The setdata is a pointer to an int which is set to non zero.
199  \ingroup CONFIG
200  */
201 CI_DECLARE_FUNC(int) ci_cfg_enable(const char *directive,const char **argv,void *setdata);
202 
203 /**
204  * Sets a configuration parameter of type ci_off_t (typedef of off_t type).
205  \ingroup CONFIG
206  */
207 CI_DECLARE_FUNC(int) ci_cfg_size_off(const char *directive,const char **argv,void *setdata);
208 
209 /**
210  * Sets a configuration parameter of type long.
211  \ingroup CONFIG
212  */
213 CI_DECLARE_FUNC(int) ci_cfg_size_long(const char *directive,const char **argv,void *setdata);
214 
215 /**
216  * Sets a configuration parameter of type int to 1 and prints c-icap version.
217  \ingroup CONFIG
218  */
219 CI_DECLARE_FUNC(int) ci_cfg_version(const char *directive, const char **argv, void *setdata);
220 
221 /**
222  * Sets a configuration parameter of type int to 1 and prints c-icap build
223  * information.
224  \ingroup CONFIG
225  */
226 CI_DECLARE_FUNC(int) ci_cfg_build_info(const char *directive, const char **argv, void *setdata);
227 
228 CI_DECLARE_FUNC(void) ci_args_usage(const char *progname,struct ci_options_entry *options);
229 CI_DECLARE_FUNC(int)  ci_args_apply(int argc, char *argv[],struct ci_options_entry *options);
230 
231 
232 #ifdef __CI_COMPAT
233 #define  icap_server_conf   ci_server_conf
234 #define  conf_entry         ci_conf_entry
235 #define  options_entry      ci_options_entry
236 #endif
237 
238 #ifdef __cplusplus
239 }
240 #endif
241 
242 #endif
243