Annotation of libaitcfg/inc/aitcfg.h, revision 1.6.4.1
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.6.4.1 ! misho 6: * $Id: aitcfg.h,v 1.6 2011/05/01 17:24: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.6.4.1 ! misho 15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
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.6.4.1 ! misho 50: #include <aitio.h>
! 51: #include <atree.h>
! 52:
! 53:
! 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.6.4.1 ! misho 59: SLIST_ENTRY(tagCfg) cfg_next;
! 60: RB_ENTRY(tagCfg) cfg_node;
1.1 misho 61: };
1.6.4.1 ! misho 62: typedef struct tagRC {
! 63: #ifdef HAVE_LIBPTHREAD
! 64: pthread_mutex_t rc_mtx;
! 65: #endif
! 66: struct tagCfg *slh_first;
! 67: struct tagCfg *rbh_root;
! 68: } cfg_root_t;
! 69: #ifdef HAVE_LIBPTHREAD
! 70: #define CFG_RC_LOCK(x) pthread_mutex_lock(&(x)->rc_mtx)
! 71: #define CFG_RC_UNLOCK(x) pthread_mutex_unlock(&(x)->rc_mtx)
! 72: #else
! 73: #define CFG_RC_LOCK(x)
! 74: #define CFG_RC_UNLOCK(x)
! 75: #endif
! 76:
! 77:
! 78: // cfg_GetErrno() Get error code of last operation
! 79: inline int cfg_GetErrno();
! 80: // cfg_GetError() Get error text of last operation
! 81: inline const char *cfg_GetError();
1.1 misho 82:
83:
84: /*
1.6.4.1 ! misho 85: * Macros for config library.
1.4 misho 86: */
1.6.4.1 ! misho 87: #define CFG_ISEMPTY(x) RB_EMPTY((x))
1.4 misho 88:
89:
1.6.4.1 ! misho 90: /*
! 91: * cfgLoadConfig() - Load config from file
! 92: *
! 93: * @cfgName = Config filename
! 94: * @cfg = Config root
! 95: * return: -1 error or 0 ok
! 96: */
! 97: int cfgLoadConfig(const char *cfgName, cfg_root_t * __restrict cfg);
! 98: /*
! 99: * cfgUnloadConfig() - Unload config from memory and free resources
! 100: *
! 101: * @cfg = Config root
! 102: * return: none
! 103: */
! 104: void cfgUnloadConfig(cfg_root_t * __restrict cfg);
1.4 misho 105:
106: /*
1.6.4.1 ! misho 107: * cfgReadConfig() - Read file and add new item at config root
! 108: *
! 109: * @f = File resource
! 110: * @cfg = Config root
! 111: * return: -1 error or 0 ok
! 112: */
! 113: int cfgReadConfig(FILE *f, cfg_root_t * __restrict cfg);
! 114:
! 115: #if 0
1.1 misho 116: /*
1.3 misho 117: * cfg_CreateConfig() Create config file from memory without whitespaces!
118: * @csConfigName = New config filename
119: * @cfg = Head list element
120: * return: 0 ok; -1 error:: can`t save new config
121: */
122: int cfg_CreateConfig(const char *csConfigName, sl_config * __restrict cfg);
123: /*
1.1 misho 124: * CreateConfig() Create config file from memory
125: * @csConfigName = New config filename
126: * @cfg = Head list element
127: * return: 0 ok; -1 error:: can`t save new config
128: */
129: int CreateConfig(const char *csConfigName, sl_config * __restrict cfg);
130:
131:
132: /*
133: * WriteConfig() Write to file from items in config list
134: * @f = file resource
135: * @cfg = Head list element
136: * return: 0 ok; -1 error:: can`t write to file
137: */
138: int WriteConfig(FILE *f, sl_config * __restrict cfg);
139:
1.3 misho 140: /*
141: * cfg_WriteConfig() Write to file from items in config list without whitespaces!
142: * @f = file resource
143: * @cfg = Head list element
144: * return: 0 ok; -1 error:: can`t write to file
145: */
146: int cfg_WriteConfig(FILE *f, sl_config * __restrict cfg);
147:
148: /*
149: * ConcatConfig() Concat two list in one
150: * @cfg = Head list element of main list
151: * @add_cfg = Head list element of added list
152: * return: 0 ok; -1 error:: can`t concat lists
153: */
154: int ConcatConfig(sl_config * __restrict cfg, sl_config * __restrict add_cfg);
155:
156: /*
157: * MergeConfig() Marge two list in one cfg and destroy add_cfg
158: * @cfg = Head list element of main list
159: * @add_cfg = Head list element of merged list (destroy after all!)
160: * return: 0 ok; -1 error:: can`t merge lists
161: */
162: int MergeConfig(sl_config * __restrict cfg, sl_config * __restrict add_cfg);
1.6.4.1 ! misho 163: #endif
1.1 misho 164:
165: /*
1.6.4.1 ! misho 166: * cfg_findAttribute() - Find attribute position in config file
! 167: *
! 168: * @cfg = Config root
1.1 misho 169: * @csSec = Config section //[{csSec}]
170: * @csAttr = Config attribute //{csAttr} = ...
171: * return: 0 not found item; -1 error: null parameters; >0 position in list
1.6.4.1 ! misho 172: */
! 173: inline int cfg_findAttribute(cfg_root_t * __restrict cfg,
! 174: const char *csSec, const char *csAttr);
! 175: /*
! 176: * cfg_getAttribute() - Get item from config and return value from it
! 177: *
! 178: * @cfg = Config root
! 179: * @csSec = Config section //[{csSec}], if NULL unset in *default* section
! 180: * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
! 181: * return: NULL item not found or null parameters; !=NULL value const string
! 182: */
! 183: inline const char *cfg_getAttribute(cfg_root_t * __restrict cfg,
! 184: const char *csSec, const char *csAttr);
! 185:
! 186: #if 0
1.1 misho 187: /*
188: * cfg_SetAttribute() Set item in config list or add new item if not exists
189: * @cfg = Head list element
190: * @csSec = Config section //[{csSec}], if NULL set in *default* section
191: * @csAttr = Config attribute //{csAttr} = ..., if NULL set as *any* attribute
192: * @csVal = Config value //... = {csVal} to setup
193: * return: 0 nothing changed, -1 error: not enough memory; 1 find and update item; 2 added new item
194: */
195: int cfg_SetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr, const u_char *csVal);
196: /*
197: * cfg_UnsetAttribute() Unset item from config list and free resources
198: * @cfg = Head list element
199: * @csSec = Config section //[{csSec}], if NULL unset in *default* section
200: * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
201: * return: 0 item not found, -1 error: null parameters; >0 position in list
202: */
203: int cfg_UnsetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
204: /*
205: * cfg_GetAttribute() Get item from config list and return his value
206: * @cfg = Head list element
207: * @csSec = Config section //[{csSec}], if NULL unset in *default* section
208: * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
209: * return: NULL item not found or null parameters; !=NULL value const string
210: */
211: inline const u_char *cfg_GetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
212:
213: /*
214: * cfg_LoadAttribute() Extended get attribute, if not found item return *default value*
215: * @cfg = Head list element
216: * @csSec = Config section //[{csSec}], if NULL unset in *default* section
217: * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
218: * @psVal = Return buffer for item Value //... = {psVal}
219: * @ValLen = Length of buffer //{psVal} for return
220: * @csDefValue = *Default Value* for return in //{psVal}, if not found item in config list
221: * return: 0 item not found, -1 error: null parameters; >0 number of copied bytes in //{psVal}
222: */
223: int cfg_LoadAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr,
224: u_char * __restrict psVal, int ValLen, const char *csDefValue);
1.6.4.1 ! misho 225: #endif
1.1 misho 226:
227:
228: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>