ThingWorx C SDK
cfuconf.h
1 /*
2  * cfuconf.h - This file is part of the libcfu library
3  *
4  * Copyright (c) 2005 Don Owens. All rights reserved.
5  *
6  * This code is released under the BSD license:
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * * Neither the name of the author nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
35  * OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef CFU_CONF_H_
39 #define CFU_CONF_H_
40 
41 #include <cfu.h>
42 #include <cfuhash.h>
43 #include <cfulist.h>
44 #include <cfustring.h>
45 
46 CFU_BEGIN_DECLS
47 
48 typedef struct cfuconf cfuconf_t;
49 
50 /* Apache-style conf files contain directives and containers.
51  Directives are simple one line specifications with or without
52  arguments, e.g.,
53 
54  Doit
55  Expires On
56  LoadModule my_mod modules/my_mod.so
57 
58  Containers have a type and a name associated with them and they
59  in turn contain directives and/or containers, e.g.,
60 
61  <MyContainer test1>
62  Expires Off
63  <DB devdb>
64  DBHost db.example.com
65  DBUser test_user
66  </DB>
67  </MyContainer>
68 
69  Values may be quoted, e.g.
70 
71  DBUser "test user"
72 
73  But must be specified on a single line. To escape quotes
74  within a quoted string, use the '\' character.
75 
76  */
77 
78 
79 /* Parse the apache-like conf file specified by file_path,
80  * returning a pointer to a cfuconf_t structure in conf. Returns
81  * zero on success, less than zero on error. If an error occurs
82  * and error is not NULL, it will be set to an error message
83  * (which must be free()'d by the caller).
84  */
85 int cfuconf_parse_file(char *file_path, cfuconf_t **conf, char **error);
86 
87 /* Same as cfuconf_parse_file(), except assume the contents of the
88  * file are already in buffer.
89 */
90 int cfuconf_parse_buffer(char *buffer, cfuconf_t **conf, char **error);
91 
92 /* Free all resources used by the cfuconf_t structure */
93 void cfuconf_destroy(cfuconf_t *conf);
94 
95 /* Get a hash of containers at the top level of conf */
96 cfuhash_table_t * cfuconf_get_containers(cfuconf_t *conf);
97 
98 /* Get a hash of directives at the to level */
99 cfuhash_table_t * cfuconf_get_directives(cfuconf_t *conf);
100 
101 /* Get the value of the given directive, assuming there is only one argument */
102 int cfuconf_get_directive_one_arg(cfuconf_t *conf, char *directive, char **rvalue);
103 
104 /* Get the value of the given directive, assuming there are two arguments */
105 int cfuconf_get_directive_two_args(cfuconf_t *conf, char *directive, char **rvalue,
106  char **rvalue2);
107 
108 /* Get the value of the given directives, with n arguments */
109 int cfuconf_get_directive_n_args(cfuconf_t *conf, char *directive, size_t n, ...);
110 
111 /* Print out a representation of the parsed configuration */
112 void cfuconf_pretty_print_conf(cfuconf_t *conf, FILE *fp, size_t indent_level);
113 
114 CFU_END_DECLS
115 
116 #endif
Definition: cfuconf.c:66