File:  [ELWIX - Embedded LightWeight unIX -] / libaitcfg / inc / aitcfg.h
Revision 1.2.2.1: download - view: text, annotated - select for diffs - revision graph
Wed Sep 9 09:29:37 2009 UTC (14 years, 9 months ago) by misho
Branches: cfg3_1
Diff to: branchpoint 1.2: preferred, unified
added new func

    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: aitcfg.h,v 1.2.2.1 2009/09/09 09:29:37 misho Exp $
    7: *
    8: *************************************************************************/
    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:  * cfg_WriteConfig() Write to file from items in config list without whitespaces!
   77:  * @f = file resource
   78:  * @cfg = Head list element
   79:  * return: 0 ok; -1 error:: can`t write to file
   80: */
   81: int cfg_WriteConfig(FILE *f, sl_config * __restrict cfg);
   82: 
   83: 
   84: /*
   85:  * cfg_FindAttribute() Find attribute position in config list
   86:  * @cfg = Head list element
   87:  * @csSec = Config section //[{csSec}]
   88:  * @csAttr = Config attribute //{csAttr} = ...
   89:  * return: 0 not found item; -1 error: null parameters; >0 position in list
   90: */
   91: inline int cfg_FindAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
   92: /*
   93:  * cfg_SetAttribute() Set item in config list or add new item if not exists
   94:  * @cfg = Head list element
   95:  * @csSec = Config section //[{csSec}], if NULL set in *default* section
   96:  * @csAttr = Config attribute //{csAttr} = ..., if NULL set as *any* attribute
   97:  * @csVal = Config value //... = {csVal} to setup
   98:  * return: 0 nothing changed, -1 error: not enough memory; 1 find and update item; 2 added new item
   99: */
  100: int cfg_SetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr, const u_char *csVal);
  101: /*
  102:  * cfg_UnsetAttribute() Unset item from config list and free resources
  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: 0 item not found, -1 error: null parameters; >0 position in list
  107: */
  108: int cfg_UnsetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
  109: /*
  110:  * cfg_GetAttribute() Get item from config list and return his value
  111:  * @cfg = Head list element
  112:  * @csSec = Config section //[{csSec}], if NULL unset in *default* section
  113:  * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
  114:  * return: NULL item not found or null parameters; !=NULL value const string
  115: */
  116: inline const u_char *cfg_GetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
  117: 
  118: /*
  119:  * cfg_LoadAttribute() Extended get attribute, if not found item return *default value*
  120:  * @cfg = Head list element
  121:  * @csSec = Config section //[{csSec}], if NULL unset in *default* section
  122:  * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
  123:  * @psVal = Return buffer for item Value //... = {psVal}
  124:  * @ValLen = Length of buffer //{psVal} for return
  125:  * @csDefValue = *Default Value* for return in //{psVal}, if not found item in config list
  126:  * return: 0 item not found, -1 error: null parameters; >0 number of copied bytes in //{psVal}
  127: */
  128: int cfg_LoadAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr, 
  129: 		u_char * __restrict psVal, int ValLen, const char *csDefValue);
  130: 
  131: 
  132: #endif

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