|
version 1.16.6.2, 2025/08/19 11:06:32
|
version 1.17.4.1, 2026/08/04 18:51:43
|
|
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 - 2025 | Copyright 2004 - 2026 |
| 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 160 cfgEndConfig(cfg_root_t **pcfg)
|
Line 160 cfgEndConfig(cfg_root_t **pcfg)
|
| * cfgInitConfigExt() - Init existed config root |
* cfgInitConfigExt() - Init existed config root |
| * |
* |
| * @cfg = Config root |
* @cfg = Config root |
| * return: NULL error or !=NULL inited config root | * return: -1 error or 0 inited config root |
| */ |
*/ |
| cfg_root_t * | int |
| cfgInitConfigExt(cfg_root_t * __restrict cfg) |
cfgInitConfigExt(cfg_root_t * __restrict cfg) |
| { |
{ |
| pthread_mutex_t mtx = { 0 }; | if (!cfg) { |
| | cfg_SetErr(EINVAL, "Invalid parameter"); |
| | return -1; |
| | } |
| |
|
| if (!TAILQ_EMPTY(cfg) || !RB_EMPTY(cfg) || |
|
| memcmp(&cfg->rc_mtx, &mtx, sizeof mtx)) |
|
| cfgUnloadConfig(cfg); |
|
| |
|
| memset(cfg, 0, sizeof(cfg_root_t)); |
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 cfg; | return 0; |
| } |
} |
| |
|
| /* |
/* |
|
Line 192 cfgLoadConfig(const char *cfgName, cfg_root_t * __rest
|
Line 191 cfgLoadConfig(const char *cfgName, cfg_root_t * __rest
|
| { |
{ |
| FILE *f; |
FILE *f; |
| int ret; |
int ret; |
| pthread_mutex_t mtx = { 0 }; |
|
| |
|
| if (!cfgName || !cfg) { | if (!cfgName || cfgInitConfigExt(cfg)) { |
| cfg_SetErr(EINVAL, "Invalid parameter(s)"); |
cfg_SetErr(EINVAL, "Invalid parameter(s)"); |
| return -1; |
return -1; |
| } else { | } |
| if (!TAILQ_EMPTY(cfg) || !RB_EMPTY(cfg) || | |
| memcmp(&cfg->rc_mtx, &mtx, sizeof mtx)) | |
| cfgUnloadConfig(cfg); | |
| |
|
| memset(cfg, 0, sizeof(cfg_root_t)); | f = fopen(cfgName, "r"); |
| | if (!f) { |
| | LOGERR; |
| | return -1; |
| | } |
| |
|
| pthread_mutex_init(&cfg->rc_mtx, NULL); | ret = cfg_ReadConfig(f, cfg, 1); |
| |
|
| TAILQ_INIT(cfg); | fclose(f); |
| RB_INIT(cfg); | return ret; |
| | } |
| | |
| | /* |
| | * cfgLoadConfigExt() - Load config from file with recursion level of includes |
| | * |
| | * @cfgName = Config filename |
| | * @cfg = Config root |
| | * @lvl = Level of include recursion |
| | * return: -1 error or 0 ok |
| | */ |
| | int |
| | cfgLoadConfigExt(const char *cfgName, cfg_root_t * __restrict cfg, int lvl) |
| | { |
| | FILE *f; |
| | int ret; |
| | |
| | if (!cfgName || cfgInitConfigExt(cfg)) { |
| | cfg_SetErr(EINVAL, "Invalid parameter(s)"); |
| | return -1; |
| } |
} |
| |
|
| f = fopen(cfgName, "r"); |
f = fopen(cfgName, "r"); |
|
Line 216 cfgLoadConfig(const char *cfgName, cfg_root_t * __rest
|
Line 234 cfgLoadConfig(const char *cfgName, cfg_root_t * __rest
|
| return -1; |
return -1; |
| } |
} |
| |
|
| ret = cfgReadConfig(f, cfg); | ret = cfg_ReadConfig(f, cfg, lvl); |
| |
|
| fclose(f); |
fclose(f); |
| return ret; |
return ret; |
| } |
} |
| |
|
| /* |
/* |
| * cfgClearConfig() - Clear config and free resources |
* cfgClearConfig() - Clear config and free resources |
| * |
* |
|
Line 263 cfgUnloadConfig(cfg_root_t * __restrict cfg)
|
Line 280 cfgUnloadConfig(cfg_root_t * __restrict cfg)
|
| |
|
| cfgClearConfig(cfg); |
cfgClearConfig(cfg); |
| pthread_mutex_destroy(&cfg->rc_mtx); |
pthread_mutex_destroy(&cfg->rc_mtx); |
| |
memset(&cfg->rc_mtx, 0, sizeof cfg->rc_mtx); |
| } |
} |
| |
|
| /* |
/* |