libmcs  0.6.0
mcs.h
Go to the documentation of this file.
1 /*
2  * This is mcs; a modular configuration system.
3  *
4  * Copyright (c) 2007 William Pitcock <nenolod -at- sacredspiral.co.uk>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. The name of the author may not be used to endorse or promote products
18  * derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef __LIBMCS_MCS_H__
34 #define __LIBMCS_MCS_H__
35 
36 #include <unistd.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <sys/stat.h>
40 #include <sys/types.h>
41 #include <dirent.h>
42 #include <stdio.h>
43 #include <limits.h>
44 #include <stdarg.h>
45 #include <errno.h>
46 
47 #ifndef __WIN32__
48 #include <dlfcn.h>
49 #endif
50 
51 #include <mowgli.h>
52 
53 #ifdef _MCS_CORE
54 # include <libmcs/mcs_config.h>
55 #endif
56 
57 #ifndef PATH_MAX
58 #define PATH_MAX 4096
59 #endif
60 
62 typedef enum {
66 
68 typedef struct mcs_handle_ mcs_handle_t;
69 
83 typedef struct {
84  void *handle;
97  const char *name;
98 
99  /* constructors and destructors */
100 
114  mcs_handle_t *(*mcs_new)(char *domain);
115 
125  void (*mcs_destroy)(mcs_handle_t *handle);
126 
127  /* retrieval */
128 
138  const char *section,
139  const char *key,
140  char **value);
141 
151  const char *section,
152  const char *key,
153  int *value);
154 
164  const char *section,
165  const char *key,
166  int *value);
167 
177  const char *section,
178  const char *key,
179  float *value);
180 
190  const char *section,
191  const char *key,
192  double *value);
193 
194  /* setting data */
195 
205  const char *section,
206  const char *key,
207  const char *value);
208 
218  const char *section,
219  const char *key,
220  int value);
221 
231  const char *section,
232  const char *key,
233  int value);
234 
244  const char *section,
245  const char *key,
246  float value);
247 
257  const char *section,
258  const char *key,
259  double value);
260 
261  /* unset */
262 
271  const char *section,
272  const char *key);
273 
274  /* key request */
275 
282  mowgli_queue_t *(*mcs_get_keys)(mcs_handle_t *handle,
283  const char *section);
284 
285  /* sections request */
286 
292  mowgli_queue_t *(*mcs_get_sections)(mcs_handle_t *handle);
293 } mcs_backend_t;
294 
298 struct mcs_handle_ {
299  mowgli_object_t object;
302 };
303 
304 /*
305  * These functions have to do with initialization of the
306  * library.
307  */
308 
309 extern void mcs_init(void);
310 extern void mcs_fini(void);
311 extern char *mcs_version(void);
312 extern void mcs_handle_class_init(void);
313 
314 /*
315  * These functions have to do with registration of MCS backends.
316  */
319 extern mowgli_queue_t * mcs_backend_get_list(void);
320 extern const char * mcs_backend_select(void);
321 
322 /*
323  * These functions provide the public interface for creating and closing MCS
324  * handles.
325  *
326  * Please note that if a handle is not closed, the data may not be saved to
327  * disk.
328  */
329 extern mcs_handle_t *mcs_new(char *domain);
330 extern void mcs_destroy(mcs_handle_t *handle);
331 
332 /*
333  * These functions provide the public interface for querying and setting data.
334  */
335 /* retrieval */
337  const char *section,
338  const char *key,
339  char **value);
340 
342  const char *section,
343  const char *key,
344  int *value);
345 
347  const char *section,
348  const char *key,
349  int *value);
350 
352  const char *section,
353  const char *key,
354  float *value);
355 
357  const char *section,
358  const char *key,
359  double *value);
360 
361 /* setting data */
363  const char *section,
364  const char *key,
365  const char *value);
366 
368  const char *section,
369  const char *key,
370  int value);
371 
373  const char *section,
374  const char *key,
375  int value);
376 
378  const char *section,
379  const char *key,
380  float value);
381 
383  const char *section,
384  const char *key,
385  double value);
386 
387 /* unset */
389  const char *section,
390  const char *key);
391 
392 /* key request */
393 extern mowgli_queue_t *mcs_get_keys(mcs_handle_t *handle,
394  const char *section);
395 
396 extern mowgli_queue_t *mcs_get_sections(mcs_handle_t *handle);
397 
398 /*
399  * These functions have to do with the plugin loader.
400  */
401 extern void mcs_load_plugins(void);
402 extern void mcs_unload_plugins(mowgli_queue_t *l);
403 
404 /*
405  * These functions are utility functions.
406  */
407 extern size_t mcs_strnlen(const char *str, size_t len);
408 extern char * mcs_strndup(const char *str, size_t len);
409 extern int mcs_create_directory(const char *path, mode_t mode);
410 extern size_t mcs_strlcat(char *dest, const char *src, size_t count);
411 extern size_t mcs_strlcpy(char *dest, const char *src, size_t count);
412 
413 #endif