Annotation of libaitcfg/inc/aitcfg.h, revision 1.14
1.2 misho 1: /*************************************************************************
2: * (C) 2008 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
3: * by Michael Pounov <misho@openbsd-bg.org>
4: *
5: * $Author: misho $
1.14 ! misho 6: * $Id: aitcfg.h,v 1.13.2.1 2014/03/03 09:40:28 misho Exp $
1.2 misho 7: *
1.6 misho 8: **************************************************************************
9: The ELWIX and AITNET software is distributed under the following
10: terms:
11:
12: All of the documentation and software included in the ELWIX and AITNET
13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
14:
1.12 misho 15: Copyright 2004 - 2014
1.6 misho 16: by Michael Pounov <misho@elwix.org>. All rights reserved.
17:
18: Redistribution and use in source and binary forms, with or without
19: modification, are permitted provided that the following conditions
20: are met:
21: 1. Redistributions of source code must retain the above copyright
22: notice, this list of conditions and the following disclaimer.
23: 2. Redistributions in binary form must reproduce the above copyright
24: notice, this list of conditions and the following disclaimer in the
25: documentation and/or other materials provided with the distribution.
26: 3. All advertising materials mentioning features or use of this software
27: must display the following acknowledgement:
28: This product includes software developed by Michael Pounov <misho@elwix.org>
29: ELWIX - Embedded LightWeight unIX and its contributors.
30: 4. Neither the name of AITNET nor the names of its contributors
31: may be used to endorse or promote products derived from this software
32: without specific prior written permission.
33:
34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37: ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44: SUCH DAMAGE.
45: */
1.1 misho 46: #ifndef __AITCFG_H
47: #define __AITCFG_H
48:
49:
1.7 misho 50: #include <pthread.h>
1.11 misho 51: #include <elwix.h>
1.1 misho 52:
53:
1.7 misho 54: struct tagCfg {
55: ait_val_t cfg_sec;
56: ait_val_t cfg_attr;
57: ait_val_t cfg_val;
1.1 misho 58:
1.13 misho 59: TAILQ_ENTRY(tagCfg) cfg_next;
1.7 misho 60: RB_ENTRY(tagCfg) cfg_node;
61: };
62: typedef struct tagRC {
63: pthread_mutex_t rc_mtx;
1.4 misho 64:
1.13 misho 65: struct tagCfg *tqh_first;
66: struct tagCfg **tqh_last;
1.7 misho 67: struct tagCfg *rbh_root;
68: } cfg_root_t;
69: #define CFG_RC_LOCK(x) pthread_mutex_lock(&(x)->rc_mtx)
70: #define CFG_RC_UNLOCK(x) pthread_mutex_unlock(&(x)->rc_mtx)
1.1 misho 71:
72:
73: // cfg_GetErrno() Get error code of last operation
1.11 misho 74: int cfg_GetErrno();
1.1 misho 75: // cfg_GetError() Get error text of last operation
1.11 misho 76: const char *cfg_GetError();
1.1 misho 77:
78:
79: /*
1.7 misho 80: * Macros for config library.
81: */
82: #define CFG_ISEMPTY(x) RB_EMPTY((x))
1.1 misho 83:
1.3 misho 84:
85: /*
1.7 misho 86: * cfgInitConfig() - Init config root
87: *
1.14 ! misho 88: * return: NULL error or !=NULL allocated config root
! 89: */
! 90: cfg_root_t *cfgInitConfig();
! 91: /*
! 92: * cfgEndConfig() - Free resources & config root
! 93: *
! 94: * @pcfg = Config root
! 95: * return: none
1.7 misho 96: */
1.14 ! misho 97: void cfgEndConfig(cfg_root_t **pcfg);
1.7 misho 98: /*
99: * cfgLoadConfig() - Load config from file
100: *
101: * @cfgName = Config filename
102: * @cfg = Config root
103: * return: -1 error or 0 ok
104: */
105: int cfgLoadConfig(const char *cfgName, cfg_root_t * __restrict cfg);
106: /*
1.8 misho 107: * cfgUnloadConfig() - Unload config from memory and destroy resources
1.7 misho 108: *
109: * @cfg = Config root
110: * return: none
111: */
112: void cfgUnloadConfig(cfg_root_t * __restrict cfg);
1.3 misho 113: /*
1.8 misho 114: * cfgClearConfig() - Clear config and free resources
115: *
116: * @cfg = Config root
117: * return: none
118: */
119: void cfgClearConfig(cfg_root_t * __restrict cfg);
120: /*
1.7 misho 121: * cfgCreateConfig() - Create config file from memory
122: *
123: * @csConfigName = New config filename
124: * @cfg = Config root
125: * @whitespace = Additional whitespace characters to file
126: * return: -1 error or 0 ok
127: */
128: int cfgCreateConfig(const char *csConfigName, cfg_root_t * __restrict cfg,
129: int whitespace);
130:
131: /*
1.9 misho 132: * cfgReadLines() - Read custom lines and add new item at config root
133: *
134: * @f = File resource
135: * @delim = Custom delimiter, if =NULL default is '='
136: * @end = Custom user end of file, if =NULL default is EOF
137: * @cfg = Config root
138: * return: -1 error or 0 ok
139: */
140: int cfgReadLines(FILE *f, const char *delim, const char *end,
141: cfg_root_t * __restrict cfg);
142: /*
1.10 misho 143: * cfgWriteLines() - Write custom lines and export data to variable
144: *
145: * @f = File resource
146: * @delim = Custom delimiter, if =NULL default is '='
147: * @eol = End of line string, if =NULL default is "\n"
148: * @section = Export only section, if =NULL default is all
149: * @cfg = Config root
1.11 misho 150: * return: =NULL error or !=NULL exported data, must be free after use with ait_freeVar()
1.10 misho 151: */
152: ait_val_t *cfgWriteLines(FILE *f, const char *delim, const char *eol,
153: const char *section, cfg_root_t * __restrict cfg);
154: /*
1.7 misho 155: * cfgReadConfig() - Read file and add new item at config root
156: *
157: * @f = File resource
158: * @cfg = Config root
159: * return: -1 error or 0 ok
160: */
161: int cfgReadConfig(FILE *f, cfg_root_t * __restrict cfg);
162: /*
163: * cfgWriteConfig() - Write config from memory
164: *
165: * @f = File handle
166: * @cfg = Config root
167: * @whitespace = Additional whitespace characters to file
168: * return: -1 error or 0 ok
169: */
170: int cfgWriteConfig(FILE *f, cfg_root_t * __restrict cfg, int whitespace);
171: /*
172: * cfgConcatConfig() - Concat two configs into one
173: *
174: * @cfg = Config root
175: * @add_cfg = Concated config will be destroy after merge
176: * return: -1 error or 0 ok
177: */
178: int cfgConcatConfig(cfg_root_t * __restrict cfg, cfg_root_t * __restrict add_cfg);
179: /*
180: * cfgMergeConfig() - Marge two list in one cfg and destroy add_cfg
181: *
182: * @cfg = Config root of main list
183: * @add_cfg = Merged config will be destroy after merge
184: * return: -1 error or 0 ok
185: */
186: int cfgMergeConfig(cfg_root_t * __restrict cfg, cfg_root_t * __restrict add_cfg);
187:
188: /*
189: * cfg_findAttribute() - Find attribute position in config file
190: *
191: * @cfg = Config root
1.1 misho 192: * @csSec = Config section //[{csSec}]
193: * @csAttr = Config attribute //{csAttr} = ...
1.7 misho 194: * return: 0 not found item, -1 error or >0 position in list
195: */
1.11 misho 196: int cfg_findAttribute(cfg_root_t * __restrict cfg,
1.7 misho 197: const char *csSec, const char *csAttr);
198: /*
199: * cfg_getAttribute() - Get item from config and return value from it
200: *
201: * @cfg = Config root
202: * @csSec = Config section //[{csSec}], if NULL unset in *default* section
203: * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
204: * return: NULL item not found or null parameters, !=NULL value const string
205: */
1.11 misho 206: const char *cfg_getAttribute(cfg_root_t * __restrict cfg,
1.7 misho 207: const char *csSec, const char *csAttr);
208: /*
209: * cfg_setAttribute() - Set item in config or adding new item if not exists
210: *
211: * @cfg = Config root
1.1 misho 212: * @csSec = Config section //[{csSec}], if NULL set in *default* section
1.7 misho 213: * @csAttr = Config attribute //{csAttr} = ...
1.1 misho 214: * @csVal = Config value //... = {csVal} to setup
1.7 misho 215: * return: 0 nothing changed, -1 error, 1 found and updated item or 2 added new item
216: */
217: int cfg_setAttribute(cfg_root_t * __restrict cfg, const char *csSec,
218: const char *csAttr, const char *csVal);
219: /*
220: * cfg_unsetAttribute() - Unset item from config and free resources
221: *
222: * @cfg = Config root
1.1 misho 223: * @csSec = Config section //[{csSec}], if NULL unset in *default* section
1.7 misho 224: * @csAttr = Config attribute //{csAttr} = ...
225: * return: 0 item not found, -1 error or 1 removed item
226: */
227: int cfg_unsetAttribute(cfg_root_t * __restrict cfg, const char *csSec,
228: const char *csAttr);
1.1 misho 229:
230: /*
1.7 misho 231: * cfg_loadAttribute() - Get guarded attribute, if not found item return *default value*
232: *
233: * @cfg = Config root
1.1 misho 234: * @csSec = Config section //[{csSec}], if NULL unset in *default* section
1.7 misho 235: * @csAttr = Config attribute //{csAttr} = ...
236: * @val = Return buffer for item Value //... = {val}
237: * @csDefValue = *Default Value* for return in //{val}, if not found item in config
238: * return: 0 item not found, -1 error or >0 number of copied bytes in //{val}
239: */
240: int cfg_loadAttribute(cfg_root_t * __restrict cfg, const char *csSec,
241: const char *csAttr, ait_val_t * __restrict val, const char *csDefValue);
1.1 misho 242:
243:
244: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>