Diff for /libaitcfg/src/aitcfg.c between versions 1.4 and 1.4.4.1

version 1.4, 2011/05/01 17:24:28 version 1.4.4.1, 2012/04/02 14:39:02
Line 12  terms: Line 12  terms:
 All of the documentation and software included in the ELWIX and AITNET  All of the documentation and software included in the ELWIX and AITNET
 Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>  Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
   
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
         by Michael Pounov <misho@elwix.org>.  All rights reserved.          by Michael Pounov <misho@elwix.org>.  All rights reserved.
   
 Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
Line 49  SUCH DAMAGE. Line 49  SUCH DAMAGE.
   
 #pragma GCC visibility push(hidden)  #pragma GCC visibility push(hidden)
   
int cfgErrno;int cfg_Errno;
char cfgError[MAX_STR + 1];char cfg_Error[STRSIZ];
   
   inline int
   cfg_tree_cmp(struct tagCfg *a, struct tagCfg *b)
   {
           int ret;
   
           assert(a && b);
   
           ret = ((AIT_KEY(&a->cfg_sec) << 16) | AIT_KEY(&a->cfg_attr)) - 
                   ((AIT_KEY(&b->cfg_sec) << 16) | AIT_KEY(&b->cfg_attr));
   
           if (ret < 0)
                   return -1;
           else if (ret > 0)
                   return 1;
   
           return ret;
   }
   
   RB_GENERATE(tagRC, tagCfg, cfg_node, cfg_tree_cmp);
   
 #pragma GCC visibility pop  #pragma GCC visibility pop
   
   
/*// cfg_GetErrno() Get error code of last operation
 * InitConfig() Head initializing function for configinline int
 * @cfg = New head element for initcfg_GetErrno()
 * return: 0 ok; -1 error:: new head element is null 
*/ 
inline int InitConfig(sl_config * __restrict cfg) 
 {  {
        if (!cfg)        return cfg_Errno;
                return -1;}
   
        cfg->slh_first = NULL;// cfg_GetError() Get error text of last operation
        return 0;inline const char *
 cfg_GetError()
 {
         return cfg_Error;
 }  }
   
   // cfg_SetErr() Set error to variables for internal use!!!
   inline void
   cfg_SetErr(int eno, char *estr, ...)
   {
           va_list lst;
   
           cfg_Errno = eno;
           memset(cfg_Error, 0, sizeof cfg_Error);
           va_start(lst, estr);
           vsnprintf(cfg_Error, sizeof cfg_Error, estr, lst);
           va_end(lst);
   }
   
   
 /*  /*
 * LoadConfig() Load config from file * cfgLoadConfig() - Load config from file
 * @csConfigName = Filename of config *
 * @cfg = Head list element * @cfgName = Config filename
 * return: 0 ok; -1 error:: can`t load config * @cfg = Config root
*/ * return: -1 error or 0 ok
int LoadConfig(const char *csConfigName, sl_config * __restrict cfg) */
 int
 cfgLoadConfig(const char *cfgName, cfg_root_t * __restrict cfg)
 {  {
         FILE *f;          FILE *f;
         int ret;          int ret;
   
        if (!csConfigName || !cfg)        if (!cfgName || !cfg) {
                 cfg_SetErr(EINVAL, "Invalid parameter(s)");
                 return -1;                  return -1;
        } else {
        InitConfig(cfg);#ifdef HAVE_LIBPTHREAD
        if (access(csConfigName, R_OK)) {                pthread_mutex_init(&cfg->rc_mtx, NULL);
                LOGERR;#endif
                return -1;                SLIST_INIT(cfg);
                 RB_INIT(cfg);
         }          }
   
        f = fopen(csConfigName, "rt");        f = fopen(cfgName, "r");
         if (!f) {          if (!f) {
                 LOGERR;                  LOGERR;
                 return -1;                  return -1;
         }          }
           
         ret ^= ret;  
         ret = ReadConfig(f, cfg);  
   
           ret = cfgReadConfig(f, cfg);
   
         fclose(f);          fclose(f);
         return ret;          return ret;
 }  }
   
 /*  /*
 * UnloadConfig() Unload config from memory and free resources * cfgUnloadConfig() - Unload config from memory and free resources
 * @cfg = Head list element *
*/ * @cfg = Config root
void UnloadConfig(sl_config * __restrict cfg) * return: none
  */
 void
 cfgUnloadConfig(cfg_root_t * __restrict cfg)
 {  {
        struct tagPair *av;        struct tagCfg *av;
   
        if (!cfg->slh_first)        if (!cfg)
                 return;                  return;
   
        while ((av = cfg->slh_first)) {        CFG_RC_LOCK(cfg);
                cfg->slh_first = cfg->slh_first->sle_next;        while ((av = SLIST_FIRST(cfg))) {
                 SLIST_REMOVE_HEAD(cfg, cfg_next);
   
                if (av->psValue)                AIT_FREE_VAL(&av->cfg_val);
                        free(av->psValue);                AIT_FREE_VAL(&av->cfg_attr);
                if (av->psAttribute)                AIT_FREE_VAL(&av->cfg_sec);
                        free(av->psAttribute); 
                if (av->psSection) 
                        free(av->psSection); 
                 free(av);                  free(av);
         }          }
           cfg->rbh_root = NULL;
           CFG_RC_UNLOCK(cfg);
   
   #ifdef HAVE_LIBPTHREAD
           pthread_mutex_destroy(&cfg->rc_mtx);
   #endif
 }  }
   
   #if 0
 /*  /*
  * CreateConfig() Create config file from memory   * CreateConfig() Create config file from memory
  * @csConfigName = New config filename   * @csConfigName = New config filename
Line 179  int cfg_CreateConfig(const char *csConfigName, sl_conf Line 224  int cfg_CreateConfig(const char *csConfigName, sl_conf
         fclose(f);          fclose(f);
         return ret;          return ret;
 }  }
#endif
// ----------------------------------------------------------- 
 
// 
// Error maintenance functions ... 
// 
 
// cfg_GetErrno() Get error code of last operation 
inline int cfg_GetErrno() 
{ 
        return cfgErrno; 
} 
 
// cfg_GetError() Get error text of last operation 
inline const char *cfg_GetError() 
{ 
        return cfgError; 
} 

Removed from v.1.4  
changed lines
  Added in v.1.4.4.1


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