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

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.2.2.2 ! misho       6: * $Id: aitcfg.h,v 1.2.2.1 2009/09/09 09:29:37 misho Exp $
1.2       misho       7: *
                      8: *************************************************************************/
1.1       misho       9: #ifndef __AITCFG_H
                     10: #define __AITCFG_H
                     11: 
                     12: 
                     13: struct tagPair {
                     14:        unsigned int    uLine;
                     15:        unsigned char   *psSection;
                     16:        unsigned char   *psAttribute;
                     17:        unsigned char   *psValue;
                     18:        struct tagPair *sle_next;
                     19: };
                     20: 
                     21: struct tagHead {
                     22:        struct tagPair *slh_first;
                     23: };
                     24: typedef struct tagHead sl_config;
                     25: 
                     26: 
                     27: /*
                     28:  * InitConfig() Head initializing function for config
                     29:  * @cfg = New head element for init
                     30:  * return: 0 ok; -1 error:: new head element is null
                     31: */
                     32: inline int InitConfig(sl_config * __restrict cfg);
                     33: /*
1.2.2.2 ! misho      34:  * cfg_CreateConfig() Create config file from memory without whitespaces!
        !            35:  * @csConfigName = New config filename
        !            36:  * @cfg = Head list element
        !            37:  * return: 0 ok; -1 error:: can`t save new config
        !            38: */
        !            39: int cfg_CreateConfig(const char *csConfigName, sl_config * __restrict cfg);
        !            40: /*
1.1       misho      41:  * CreateConfig() Create config file from memory
                     42:  * @csConfigName = New config filename
                     43:  * @cfg = Head list element
                     44:  * return: 0 ok; -1 error:: can`t save new config
                     45: */
                     46: int CreateConfig(const char *csConfigName, sl_config * __restrict cfg);
                     47: /*
                     48:  * LoadConfig() Load config from file
                     49:  * @csConfigName = Filename of config
                     50:  * @cfg = Head list element
                     51:  * return: 0 ok; -1 error:: can`t load config
                     52: */
                     53: int LoadConfig(const char *csConfigName, sl_config * __restrict cfg);
                     54: /*
                     55:  * UnloadConfig() Unload config from memory and free resources
                     56:  * @cfg = Head list element
                     57: */
                     58: void UnloadConfig(sl_config * __restrict cfg);
                     59: 
                     60: 
                     61: // cfg_GetErrno() Get error code of last operation
                     62: inline int cfg_GetErrno();
                     63: // cfg_GetError() Get error text of last operation
                     64: inline const char *cfg_GetError();
                     65: 
                     66: 
                     67: /*
                     68:  * ReadConfig() Read from file and add new item to config list
                     69:  * @f = file resource
                     70:  * @cfg = Head list element
                     71:  * return: 0 ok; -1 error:: can`t allocate memory
                     72: */
                     73: int ReadConfig(FILE *f, sl_config * __restrict cfg);
                     74: /*
                     75:  * WriteConfig() Write to file from items in config list
                     76:  * @f = file resource
                     77:  * @cfg = Head list element
                     78:  * return: 0 ok; -1 error:: can`t write to file
                     79: */
                     80: int WriteConfig(FILE *f, sl_config * __restrict cfg);
                     81: 
1.2.2.1   misho      82: /*
                     83:  * cfg_WriteConfig() Write to file from items in config list without whitespaces!
                     84:  * @f = file resource
                     85:  * @cfg = Head list element
                     86:  * return: 0 ok; -1 error:: can`t write to file
                     87: */
                     88: int cfg_WriteConfig(FILE *f, sl_config * __restrict cfg);
                     89: 
1.1       misho      90: 
                     91: /*
                     92:  * cfg_FindAttribute() Find attribute position in config list
                     93:  * @cfg = Head list element
                     94:  * @csSec = Config section //[{csSec}]
                     95:  * @csAttr = Config attribute //{csAttr} = ...
                     96:  * return: 0 not found item; -1 error: null parameters; >0 position in list
                     97: */
                     98: inline int cfg_FindAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
                     99: /*
                    100:  * cfg_SetAttribute() Set item in config list or add new item if not exists
                    101:  * @cfg = Head list element
                    102:  * @csSec = Config section //[{csSec}], if NULL set in *default* section
                    103:  * @csAttr = Config attribute //{csAttr} = ..., if NULL set as *any* attribute
                    104:  * @csVal = Config value //... = {csVal} to setup
                    105:  * return: 0 nothing changed, -1 error: not enough memory; 1 find and update item; 2 added new item
                    106: */
                    107: int cfg_SetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr, const u_char *csVal);
                    108: /*
                    109:  * cfg_UnsetAttribute() Unset item from config list and free resources
                    110:  * @cfg = Head list element
                    111:  * @csSec = Config section //[{csSec}], if NULL unset in *default* section
                    112:  * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
                    113:  * return: 0 item not found, -1 error: null parameters; >0 position in list
                    114: */
                    115: int cfg_UnsetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
                    116: /*
                    117:  * cfg_GetAttribute() Get item from config list and return his value
                    118:  * @cfg = Head list element
                    119:  * @csSec = Config section //[{csSec}], if NULL unset in *default* section
                    120:  * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
                    121:  * return: NULL item not found or null parameters; !=NULL value const string
                    122: */
                    123: inline const u_char *cfg_GetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
                    124: 
                    125: /*
                    126:  * cfg_LoadAttribute() Extended get attribute, if not found item return *default value*
                    127:  * @cfg = Head list element
                    128:  * @csSec = Config section //[{csSec}], if NULL unset in *default* section
                    129:  * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
                    130:  * @psVal = Return buffer for item Value //... = {psVal}
                    131:  * @ValLen = Length of buffer //{psVal} for return
                    132:  * @csDefValue = *Default Value* for return in //{psVal}, if not found item in config list
                    133:  * return: 0 item not found, -1 error: null parameters; >0 number of copied bytes in //{psVal}
                    134: */
                    135: int cfg_LoadAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr, 
                    136:                u_char * __restrict psVal, int ValLen, const char *csDefValue);
                    137: 
                    138: 
                    139: #endif

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