Annotation of libaitcfg/inc/aitcfg.h, revision 1.6

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     ! misho       6: * $Id: aitcfg.h,v 1.5.2.1 2011/05/01 17:23:29 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: 
        !            15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
        !            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: 
                     50: struct tagPair {
                     51:        unsigned int    uLine;
                     52:        unsigned char   *psSection;
                     53:        unsigned char   *psAttribute;
                     54:        unsigned char   *psValue;
                     55:        struct tagPair *sle_next;
                     56: };
                     57: 
                     58: struct tagHead {
                     59:        struct tagPair *slh_first;
                     60: };
                     61: typedef struct tagHead sl_config;
                     62: 
                     63: 
                     64: /*
1.4       misho      65:  * Macros for config library. Typecast string to specific config string format.
                     66: */
                     67: #define CFG(x)         (unsigned char *)(x)
                     68: 
                     69: #define CFG_ISSET(x)   ((long) cfg_FirstItem((x)))
                     70: 
                     71: 
                     72: /*
1.1       misho      73:  * InitConfig() Head initializing function for config
                     74:  * @cfg = New head element for init
                     75:  * return: 0 ok; -1 error:: new head element is null
                     76: */
                     77: inline int InitConfig(sl_config * __restrict cfg);
                     78: /*
1.3       misho      79:  * cfg_CreateConfig() Create config file from memory without whitespaces!
                     80:  * @csConfigName = New config filename
                     81:  * @cfg = Head list element
                     82:  * return: 0 ok; -1 error:: can`t save new config
                     83: */
                     84: int cfg_CreateConfig(const char *csConfigName, sl_config * __restrict cfg);
                     85: /*
1.1       misho      86:  * CreateConfig() Create config file from memory
                     87:  * @csConfigName = New config filename
                     88:  * @cfg = Head list element
                     89:  * return: 0 ok; -1 error:: can`t save new config
                     90: */
                     91: int CreateConfig(const char *csConfigName, sl_config * __restrict cfg);
                     92: /*
                     93:  * LoadConfig() Load config from file
                     94:  * @csConfigName = Filename of config
                     95:  * @cfg = Head list element
                     96:  * return: 0 ok; -1 error:: can`t load config
                     97: */
                     98: int LoadConfig(const char *csConfigName, sl_config * __restrict cfg);
                     99: /*
                    100:  * UnloadConfig() Unload config from memory and free resources
                    101:  * @cfg = Head list element
                    102: */
                    103: void UnloadConfig(sl_config * __restrict cfg);
                    104: 
                    105: 
                    106: // cfg_GetErrno() Get error code of last operation
                    107: inline int cfg_GetErrno();
                    108: // cfg_GetError() Get error text of last operation
                    109: inline const char *cfg_GetError();
                    110: 
                    111: 
                    112: /*
                    113:  * ReadConfig() Read from file and add new item to config list
                    114:  * @f = file resource
                    115:  * @cfg = Head list element
                    116:  * return: 0 ok; -1 error:: can`t allocate memory
                    117: */
                    118: int ReadConfig(FILE *f, sl_config * __restrict cfg);
                    119: /*
                    120:  * WriteConfig() Write to file from items in config list
                    121:  * @f = file resource
                    122:  * @cfg = Head list element
                    123:  * return: 0 ok; -1 error:: can`t write to file
                    124: */
                    125: int WriteConfig(FILE *f, sl_config * __restrict cfg);
                    126: 
1.3       misho     127: /*
                    128:  * cfg_WriteConfig() Write to file from items in config list without whitespaces!
                    129:  * @f = file resource
                    130:  * @cfg = Head list element
                    131:  * return: 0 ok; -1 error:: can`t write to file
                    132: */
                    133: int cfg_WriteConfig(FILE *f, sl_config * __restrict cfg);
                    134: 
                    135: /*
                    136:  * ConcatConfig() Concat two list in one
                    137:  * @cfg = Head list element of main list
                    138:  * @add_cfg = Head list element of added list
                    139:  * return: 0 ok; -1 error:: can`t concat lists
                    140: */
                    141: int ConcatConfig(sl_config * __restrict cfg, sl_config * __restrict add_cfg);
                    142: 
                    143: /*
                    144:  * MergeConfig() Marge two list in one cfg and destroy add_cfg
                    145:  * @cfg = Head list element of main list
                    146:  * @add_cfg = Head list element of merged list (destroy after all!)
                    147:  * return: 0 ok; -1 error:: can`t merge lists
                    148: */
                    149: int MergeConfig(sl_config * __restrict cfg, sl_config * __restrict add_cfg);
                    150: 
1.1       misho     151: 
                    152: /*
                    153:  * cfg_FindAttribute() Find attribute position in config list
                    154:  * @cfg = Head list element
                    155:  * @csSec = Config section //[{csSec}]
                    156:  * @csAttr = Config attribute //{csAttr} = ...
                    157:  * return: 0 not found item; -1 error: null parameters; >0 position in list
                    158: */
                    159: inline int cfg_FindAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
                    160: /*
                    161:  * cfg_SetAttribute() Set item in config list or add new item if not exists
                    162:  * @cfg = Head list element
                    163:  * @csSec = Config section //[{csSec}], if NULL set in *default* section
                    164:  * @csAttr = Config attribute //{csAttr} = ..., if NULL set as *any* attribute
                    165:  * @csVal = Config value //... = {csVal} to setup
                    166:  * return: 0 nothing changed, -1 error: not enough memory; 1 find and update item; 2 added new item
                    167: */
                    168: int cfg_SetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr, const u_char *csVal);
                    169: /*
                    170:  * cfg_UnsetAttribute() Unset item from config list and free resources
                    171:  * @cfg = Head list element
                    172:  * @csSec = Config section //[{csSec}], if NULL unset in *default* section
                    173:  * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
                    174:  * return: 0 item not found, -1 error: null parameters; >0 position in list
                    175: */
                    176: int cfg_UnsetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
                    177: /*
                    178:  * cfg_GetAttribute() Get item from config list and return his value
                    179:  * @cfg = Head list element
                    180:  * @csSec = Config section //[{csSec}], if NULL unset in *default* section
                    181:  * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
                    182:  * return: NULL item not found or null parameters; !=NULL value const string
                    183: */
                    184: inline const u_char *cfg_GetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
                    185: 
                    186: /*
1.4       misho     187:  * cfg_FirstItem() Get first item from config list and return his value
                    188:  * @cfg = Head list element
                    189:  * return: NULL if no items in list; !=NULL first pair item
                    190: */
                    191: inline struct tagPair *cfg_FirstItem(sl_config * __restrict cfg);
                    192: 
                    193: /*
1.1       misho     194:  * cfg_LoadAttribute() Extended get attribute, if not found item return *default value*
                    195:  * @cfg = Head list element
                    196:  * @csSec = Config section //[{csSec}], if NULL unset in *default* section
                    197:  * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
                    198:  * @psVal = Return buffer for item Value //... = {psVal}
                    199:  * @ValLen = Length of buffer //{psVal} for return
                    200:  * @csDefValue = *Default Value* for return in //{psVal}, if not found item in config list
                    201:  * return: 0 item not found, -1 error: null parameters; >0 number of copied bytes in //{psVal}
                    202: */
                    203: int cfg_LoadAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr, 
                    204:                u_char * __restrict psVal, int ValLen, const char *csDefValue);
                    205: 
                    206: 
                    207: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>