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

1.1.1.1.2.1! misho       1: /*************************************************************************
        !             2: * (C) 2008 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
        !             3: *  by Michael Pounov <misho@openbsd-bg.org>
        !             4: *
        !             5: * $Author: misho $
        !             6: * $Id: global.h,v 4.0.2.3 2008/03/06 10:08:48 misho Exp $
        !             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: /*
                     34:  * CreateConfig() Create config file from memory
                     35:  * @csConfigName = New config filename
                     36:  * @cfg = Head list element
                     37:  * return: 0 ok; -1 error:: can`t save new config
                     38: */
                     39: int CreateConfig(const char *csConfigName, sl_config * __restrict cfg);
                     40: /*
                     41:  * LoadConfig() Load config from file
                     42:  * @csConfigName = Filename of config
                     43:  * @cfg = Head list element
                     44:  * return: 0 ok; -1 error:: can`t load config
                     45: */
                     46: int LoadConfig(const char *csConfigName, sl_config * __restrict cfg);
                     47: /*
                     48:  * UnloadConfig() Unload config from memory and free resources
                     49:  * @cfg = Head list element
                     50: */
                     51: void UnloadConfig(sl_config * __restrict cfg);
                     52: 
                     53: 
                     54: // cfg_GetErrno() Get error code of last operation
                     55: inline int cfg_GetErrno();
                     56: // cfg_GetError() Get error text of last operation
                     57: inline const char *cfg_GetError();
                     58: 
                     59: 
                     60: /*
                     61:  * ReadConfig() Read from file and add new item to config list
                     62:  * @f = file resource
                     63:  * @cfg = Head list element
                     64:  * return: 0 ok; -1 error:: can`t allocate memory
                     65: */
                     66: int ReadConfig(FILE *f, sl_config * __restrict cfg);
                     67: /*
                     68:  * WriteConfig() Write to file from items in config list
                     69:  * @f = file resource
                     70:  * @cfg = Head list element
                     71:  * return: 0 ok; -1 error:: can`t write to file
                     72: */
                     73: int WriteConfig(FILE *f, sl_config * __restrict cfg);
                     74: 
                     75: 
                     76: /*
                     77:  * cfg_FindAttribute() Find attribute position in config list
                     78:  * @cfg = Head list element
                     79:  * @csSec = Config section //[{csSec}]
                     80:  * @csAttr = Config attribute //{csAttr} = ...
                     81:  * return: 0 not found item; -1 error: null parameters; >0 position in list
                     82: */
                     83: inline int cfg_FindAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
                     84: /*
                     85:  * cfg_SetAttribute() Set item in config list or add new item if not exists
                     86:  * @cfg = Head list element
                     87:  * @csSec = Config section //[{csSec}], if NULL set in *default* section
                     88:  * @csAttr = Config attribute //{csAttr} = ..., if NULL set as *any* attribute
                     89:  * @csVal = Config value //... = {csVal} to setup
                     90:  * return: 0 nothing changed, -1 error: not enough memory; 1 find and update item; 2 added new item
                     91: */
                     92: int cfg_SetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr, const u_char *csVal);
                     93: /*
                     94:  * cfg_UnsetAttribute() Unset item from config list and free resources
                     95:  * @cfg = Head list element
                     96:  * @csSec = Config section //[{csSec}], if NULL unset in *default* section
                     97:  * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
                     98:  * return: 0 item not found, -1 error: null parameters; >0 position in list
                     99: */
                    100: int cfg_UnsetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
                    101: /*
                    102:  * cfg_GetAttribute() Get item from config list and return his value
                    103:  * @cfg = Head list element
                    104:  * @csSec = Config section //[{csSec}], if NULL unset in *default* section
                    105:  * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
                    106:  * return: NULL item not found or null parameters; !=NULL value const string
                    107: */
                    108: inline const u_char *cfg_GetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
                    109: 
                    110: /*
                    111:  * cfg_LoadAttribute() Extended get attribute, if not found item return *default value*
                    112:  * @cfg = Head list element
                    113:  * @csSec = Config section //[{csSec}], if NULL unset in *default* section
                    114:  * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
                    115:  * @psVal = Return buffer for item Value //... = {psVal}
                    116:  * @ValLen = Length of buffer //{psVal} for return
                    117:  * @csDefValue = *Default Value* for return in //{psVal}, if not found item in config list
                    118:  * return: 0 item not found, -1 error: null parameters; >0 number of copied bytes in //{psVal}
                    119: */
                    120: int cfg_LoadAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr, 
                    121:                u_char * __restrict psVal, int ValLen, const char *csDefValue);
                    122: 
                    123: 
                    124: #endif

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