File:  [ELWIX - Embedded LightWeight unIX -] / libaitcfg / inc / aitcfg.h
Revision 1.5: download - view: text, annotated - select for diffs - revision graph
Mon Mar 22 15:15:48 2010 UTC (14 years, 2 months ago) by misho
Branches: MAIN
CVS tags: cfg4_0, HEAD, CFG3_2
new version corrected mirge 3.2

    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.5 2010/03/22 15:15:48 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:  * Macros for config library. Typecast string to specific config string format.
   29: */
   30: #define CFG(x)		(unsigned char *)(x)
   31: 
   32: #define CFG_ISSET(x)	((long) cfg_FirstItem((x)))
   33: 
   34: 
   35: /*
   36:  * InitConfig() Head initializing function for config
   37:  * @cfg = New head element for init
   38:  * return: 0 ok; -1 error:: new head element is null
   39: */
   40: inline int InitConfig(sl_config * __restrict cfg);
   41: /*
   42:  * cfg_CreateConfig() Create config file from memory without whitespaces!
   43:  * @csConfigName = New config filename
   44:  * @cfg = Head list element
   45:  * return: 0 ok; -1 error:: can`t save new config
   46: */
   47: int cfg_CreateConfig(const char *csConfigName, sl_config * __restrict cfg);
   48: /*
   49:  * CreateConfig() Create config file from memory
   50:  * @csConfigName = New config filename
   51:  * @cfg = Head list element
   52:  * return: 0 ok; -1 error:: can`t save new config
   53: */
   54: int CreateConfig(const char *csConfigName, sl_config * __restrict cfg);
   55: /*
   56:  * LoadConfig() Load config from file
   57:  * @csConfigName = Filename of config
   58:  * @cfg = Head list element
   59:  * return: 0 ok; -1 error:: can`t load config
   60: */
   61: int LoadConfig(const char *csConfigName, sl_config * __restrict cfg);
   62: /*
   63:  * UnloadConfig() Unload config from memory and free resources
   64:  * @cfg = Head list element
   65: */
   66: void UnloadConfig(sl_config * __restrict cfg);
   67: 
   68: 
   69: // cfg_GetErrno() Get error code of last operation
   70: inline int cfg_GetErrno();
   71: // cfg_GetError() Get error text of last operation
   72: inline const char *cfg_GetError();
   73: 
   74: 
   75: /*
   76:  * ReadConfig() Read from file and add new item to config list
   77:  * @f = file resource
   78:  * @cfg = Head list element
   79:  * return: 0 ok; -1 error:: can`t allocate memory
   80: */
   81: int ReadConfig(FILE *f, sl_config * __restrict cfg);
   82: /*
   83:  * WriteConfig() Write to file from items in config list
   84:  * @f = file resource
   85:  * @cfg = Head list element
   86:  * return: 0 ok; -1 error:: can`t write to file
   87: */
   88: int WriteConfig(FILE *f, sl_config * __restrict cfg);
   89: 
   90: /*
   91:  * cfg_WriteConfig() Write to file from items in config list without whitespaces!
   92:  * @f = file resource
   93:  * @cfg = Head list element
   94:  * return: 0 ok; -1 error:: can`t write to file
   95: */
   96: int cfg_WriteConfig(FILE *f, sl_config * __restrict cfg);
   97: 
   98: /*
   99:  * ConcatConfig() Concat two list in one
  100:  * @cfg = Head list element of main list
  101:  * @add_cfg = Head list element of added list
  102:  * return: 0 ok; -1 error:: can`t concat lists
  103: */
  104: int ConcatConfig(sl_config * __restrict cfg, sl_config * __restrict add_cfg);
  105: 
  106: /*
  107:  * MergeConfig() Marge two list in one cfg and destroy add_cfg
  108:  * @cfg = Head list element of main list
  109:  * @add_cfg = Head list element of merged list (destroy after all!)
  110:  * return: 0 ok; -1 error:: can`t merge lists
  111: */
  112: int MergeConfig(sl_config * __restrict cfg, sl_config * __restrict add_cfg);
  113: 
  114: 
  115: /*
  116:  * cfg_FindAttribute() Find attribute position in config list
  117:  * @cfg = Head list element
  118:  * @csSec = Config section //[{csSec}]
  119:  * @csAttr = Config attribute //{csAttr} = ...
  120:  * return: 0 not found item; -1 error: null parameters; >0 position in list
  121: */
  122: inline int cfg_FindAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
  123: /*
  124:  * cfg_SetAttribute() Set item in config list or add new item if not exists
  125:  * @cfg = Head list element
  126:  * @csSec = Config section //[{csSec}], if NULL set in *default* section
  127:  * @csAttr = Config attribute //{csAttr} = ..., if NULL set as *any* attribute
  128:  * @csVal = Config value //... = {csVal} to setup
  129:  * return: 0 nothing changed, -1 error: not enough memory; 1 find and update item; 2 added new item
  130: */
  131: int cfg_SetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr, const u_char *csVal);
  132: /*
  133:  * cfg_UnsetAttribute() Unset item from config list and free resources
  134:  * @cfg = Head list element
  135:  * @csSec = Config section //[{csSec}], if NULL unset in *default* section
  136:  * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
  137:  * return: 0 item not found, -1 error: null parameters; >0 position in list
  138: */
  139: int cfg_UnsetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
  140: /*
  141:  * cfg_GetAttribute() Get item from config list and return his value
  142:  * @cfg = Head list element
  143:  * @csSec = Config section //[{csSec}], if NULL unset in *default* section
  144:  * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
  145:  * return: NULL item not found or null parameters; !=NULL value const string
  146: */
  147: inline const u_char *cfg_GetAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr);
  148: 
  149: /*
  150:  * cfg_FirstItem() Get first item from config list and return his value
  151:  * @cfg = Head list element
  152:  * return: NULL if no items in list; !=NULL first pair item
  153: */
  154: inline struct tagPair *cfg_FirstItem(sl_config * __restrict cfg);
  155: 
  156: /*
  157:  * cfg_LoadAttribute() Extended get attribute, if not found item return *default value*
  158:  * @cfg = Head list element
  159:  * @csSec = Config section //[{csSec}], if NULL unset in *default* section
  160:  * @csAttr = Config attribute //{csAttr} = ..., if NULL unset as *any* attribute
  161:  * @psVal = Return buffer for item Value //... = {psVal}
  162:  * @ValLen = Length of buffer //{psVal} for return
  163:  * @csDefValue = *Default Value* for return in //{psVal}, if not found item in config list
  164:  * return: 0 item not found, -1 error: null parameters; >0 number of copied bytes in //{psVal}
  165: */
  166: int cfg_LoadAttribute(sl_config * __restrict cfg, const u_char *csSec, const u_char *csAttr, 
  167: 		u_char * __restrict psVal, int ValLen, const char *csDefValue);
  168: 
  169: 
  170: #endif

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