Diff for /libaitcfg/src/aitcfg.c between versions 1.11 and 1.12

version 1.11, 2014/01/30 08:30:47 version 1.12, 2014/03/03 09:41:09
Line 118  cfg_SetErr(int eno, char *estr, ...) Line 118  cfg_SetErr(int eno, char *estr, ...)
 /*  /*
  * cfgInitConfig() - Init config root   * cfgInitConfig() - Init config root
  *   *
 * @cfg = Config root * return: NULL error or !=NULL allocated config root
 * return: -1 error or 0 ok 
  */   */
intcfg_root_t *
cfgInitConfig(cfg_root_t * __restrict cfg)cfgInitConfig()
 {  {
        if (!cfg)        cfg_root_t *cfg = NULL;
                return -1; 
   
           cfg = e_malloc(sizeof(cfg_root_t));
           if (!cfg) {
                   cfg_SetErr(elwix_GetErrno(), "%s", elwix_GetError());
                   return NULL;
           } else
                   memset(cfg, 0, sizeof(cfg_root_t));
   
         pthread_mutex_init(&cfg->rc_mtx, NULL);          pthread_mutex_init(&cfg->rc_mtx, NULL);
   
         TAILQ_INIT(cfg);          TAILQ_INIT(cfg);
         RB_INIT(cfg);          RB_INIT(cfg);
        return 0;        return cfg;
 }  }
   
 /*  /*
    * cfgEndConfig() - Free resources & config root
    *
    * @pcfg = Config root
    * return: none
    */
   void
   cfgEndConfig(cfg_root_t **pcfg)
   {
           if (pcfg && *pcfg) {
                   cfgClearConfig(*pcfg);
                   pthread_mutex_destroy(&(*pcfg)->rc_mtx);
                   e_free(*pcfg);
                   *pcfg = NULL;
           }
   }
   
   /*
  * cfgLoadConfig() - Load config from file   * cfgLoadConfig() - Load config from file
  *   *
  * @cfgName = Config filename   * @cfgName = Config filename
Line 150  cfgLoadConfig(const char *cfgName, cfg_root_t * __rest Line 172  cfgLoadConfig(const char *cfgName, cfg_root_t * __rest
         if (!cfgName || !cfg) {          if (!cfgName || !cfg) {
                 cfg_SetErr(EINVAL, "Invalid parameter(s)");                  cfg_SetErr(EINVAL, "Invalid parameter(s)");
                 return -1;                  return -1;
        } else        } else {
                cfgInitConfig(cfg);                pthread_mutex_init(&cfg->rc_mtx, NULL);
   
                   TAILQ_INIT(cfg);
                   RB_INIT(cfg);
           }
   
         f = fopen(cfgName, "r");          f = fopen(cfgName, "r");
         if (!f) {          if (!f) {
                 LOGERR;                  LOGERR;
Line 240  cfgCreateConfig(const char *csConfigName, cfg_root_t * Line 266  cfgCreateConfig(const char *csConfigName, cfg_root_t *
 /*  /*
  * cfgInitPasswd() - Init password root   * cfgInitPasswd() - Init password root
  *   *
 * @pwd = Password root * return: NULL error or !=NULL allocated password root
 * return: -1 error or 0 ok 
  */   */
intpwd_root_t *
cfgInitPasswd(pwd_root_t * __restrict pwd)cfgInitPasswd()
 {  {
        if (!pwd)        pwd_root_t *pwd = NULL;
                return -1; 
   
           pwd = e_malloc(sizeof(pwd_root_t));
           if (!pwd) {
                   cfg_SetErr(elwix_GetErrno(), "%s", elwix_GetError());
                   return NULL;
           } else
                   memset(pwd, 0, sizeof(pwd_root_t));
   
         pthread_mutex_init(&pwd->pwd_mtx, NULL);          pthread_mutex_init(&pwd->pwd_mtx, NULL);
   
         SLIST_INIT(pwd);          SLIST_INIT(pwd);
Line 257  cfgInitPasswd(pwd_root_t * __restrict pwd) Line 288  cfgInitPasswd(pwd_root_t * __restrict pwd)
 }  }
   
 /*  /*
    * cfgEndPasswd() - Free resources & password root
    *
    * @ppwd = Password root
    * return: none
    */
   void
   cfgEndPasswd(pwd_root_t **ppwd)
   {
           if (ppwd && *ppwd) {
                   cfgClearPasswd(*ppwd);
                   pthread_mutex_destroy(&(*ppwd)->pwd_mtx);
                   e_free(*ppwd);
                   *ppwd = NULL;
           }
   }
   
   /*
  * cfgLoadPasswd() - Load passwords from file   * cfgLoadPasswd() - Load passwords from file
  *   *
  * @pwdName = Passwords filename   * @pwdName = Passwords filename
Line 272  cfgLoadPasswd(const char *pwdName, pwd_root_t * __rest Line 320  cfgLoadPasswd(const char *pwdName, pwd_root_t * __rest
         if (!pwdName || !pwd) {          if (!pwdName || !pwd) {
                 cfg_SetErr(EINVAL, "Invalid parameter(s)");                  cfg_SetErr(EINVAL, "Invalid parameter(s)");
                 return -1;                  return -1;
        } else        } else {
                cfgInitPasswd(pwd);                pthread_mutex_init(&pwd->pwd_mtx, NULL);
 
                 SLIST_INIT(pwd);
                 RB_INIT(pwd);
         }
   
         f = fopen(pwdName, "r");          f = fopen(pwdName, "r");
         if (!f) {          if (!f) {

Removed from v.1.11  
changed lines
  Added in v.1.12


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