67 #include <sys/types.h> 85 grp = gw_malloc(
sizeof(*grp));
118 cfgloc = gw_malloc(
sizeof(*cfgloc));
128 if (cfgloc != NULL) {
186 #define OCTSTR(name) \ 187 if (octstr_compare(octstr_imm(#name), variable) == 0) \ 189 #define SINGLE_GROUP(name, fields) \ 190 if (octstr_compare(octstr_imm(#name), group) == 0) { \ 191 if (octstr_compare(groupstr, variable) == 0) \ 196 #define MULTI_GROUP(name, fields) \ 197 if (octstr_compare(octstr_imm(#name), group) == 0) { \ 198 if (octstr_compare(groupstr, variable) == 0) \ 213 #define SINGLE_GROUP(name, fields) \ 214 if (octstr_compare(octstr_imm(#name), query) == 0) \ 216 #define MULTI_GROUP(name, fields) \ 217 if (octstr_compare(octstr_imm(#name), query) == 0) \ 232 r = (x == -1 ? (r == -1 ? x : r) : (r == -1 ? x : r + x));
268 if (groupname == NULL) {
269 error(0,
"Group does not contain variable 'group'.");
280 error(0,
"Group '%s' may not contain field '%s'.",
288 error(0,
"Group '%s' is no valid group identifier.",
322 cfg = gw_malloc(
sizeof(*
cfg));
466 loc = loc_inc = NULL;
473 panic(0,
"Failed to load main configuration file `%s'. Aborting!",
485 err_loc = loc; loc = NULL;
492 error(0,
"An equals sign ('=') is missing on line %ld of file %s.",
494 err_loc = loc; loc = NULL;
504 struct stat filestat;
512 error(errno,
"lstat failed: couldn't stat `%s'",
514 panic(0,
"Failed to include `%s' " 515 "(on line %ld of file %s). Aborting!",
525 if (S_ISDIR(filestat.st_mode)) {
527 struct dirent *diritem;
529 debug(
"gwlib.cfg", 0,
"Loading include dir `%s' " 530 "(on line %ld of file %s).",
535 while ((diritem = readdir(dh))) {
543 if (!S_ISDIR(filestat.st_mode)) {
561 debug(
"gwlib.cfg", 0,
"Recursive/multiple include for config file `%s' detected " 562 "(on line %ld of file %s), ignore this file.",
570 debug(
"gwlib.cfg", 0,
"Loading include file `%s' (on line %ld of file %s).",
582 panic(0,
"Failed to load whole configuration. Aborting!");
628 if (err_loc != NULL) {
629 error(0,
"Error found on line %ld of file `%s'.",
669 Octstr *ret, *os, *key, *val;
670 List *exclude, *keys;
681 while ((os = va_arg(args,
Octstr*)) != NULL) {
693 panic(0,
"%s: multiple config variables with same name `%s'?!", __func__,
723 long line,
const char *func)
728 panic(0,
"Trying to fetch variable `%s' in non-existing group",
732 panic(0,
"Trying to fetch variable `%s' in group `%s', not allowed.",
783 warning(0,
"bool variable set to strange value, assuming 'true'");
817 if (grp->
name == NULL)
818 debug(
"gwlib.cfg", 0,
" dumping group (name not set):");
820 debug(
"gwlib.cfg", 0,
" dumping group (%s):",
825 debug(
"gwlib.cfg", 0,
" <%s> = <%s>",
842 debug(
"gwlib.cfg", 0,
"Dumping Cfg %p", (
void *)
cfg);
843 debug(
"gwlib.cfg", 0,
" filename = <%s>",
865 debug(
"gwlib.cfg", 0,
"Dump ends.");
871 #define OCTSTR(name) \ 872 printf("%s = <please consult user doc>\n", #name); 873 #define SINGLE_GROUP(name, fields) \ 874 printf("#\n# Single Group\n#\n"); \ 875 printf("group = %s\n", #name); \ 878 #define MULTI_GROUP(name, fields) \ 879 printf("#\n# Multi Group\n#\n"); \ 880 printf("group = %s\n", #name); \ Dict * dict_create(long size_hint, void(*destroy_value)(void *))
void error(int err, const char *fmt,...)
Octstr * md5(Octstr *data)
void * gwlist_search(List *list, void *pattern, int(*cmp)(void *, void *))
static List * expand_file(Octstr *file, int forward)
static int add_group(Cfg *cfg, CfgGroup *grp)
void dict_put(Dict *dict, Octstr *key, void *value)
void gwlist_append(List *list, void *item)
static void cfgloc_destroy(CfgLoc *cfgloc)
static List * allowed_hooks
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
List * cfg_get_list(CfgGroup *grp, Octstr *varname)
long gwlist_len(List *list)
static void destroy_group_list(void *arg)
Octstr * cfg_get_configfile(CfgGroup *grp)
void * gwlist_get(List *list, long pos)
void gwlist_sort(List *list, int(*cmp)(const void *, const void *))
static CfgLoc * cfgloc_create(Octstr *filename)
static int core_is_single_group(Octstr *query)
void octstr_append_char(Octstr *ostr, int ch)
Octstr * cfg_get_group_checksum(CfgGroup *grp,...)
long octstr_search(const Octstr *haystack, const Octstr *needle, long pos)
#define cfg_get(grp, varname)
void octstr_append_cstr(Octstr *ostr, const char *cstr)
void octstr_strip_blanks(Octstr *text)
#define octstr_get_cstr(ostr)
#define octstr_copy(ostr, from, len)
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Cfg * cfg_create(Octstr *filename)
static int octstr_cmp_cb(void *a, void *b)
Octstr * octstr_imm(const char *cstr)
void cfg_add_hooks(void *allowed, void *single)
void cfg_destroy(Cfg *cfg)
void * gwlist_extract_first(List *list)
Octstr * cfg_get_real(CfgGroup *grp, Octstr *varname, const char *file, long line, const char *func)
void grp_dump(CfgGroup *grp)
void * dict_get(Dict *dict, Octstr *key)
void octstr_delete(Octstr *ostr1, long pos, long len)
static int octstr_sort_cb(const void *a, const void *b)
static int core_is_allowed_in_group(Octstr *group, Octstr *variable)
#define octstr_duplicate(ostr)
List * cfg_get_multi_group(Cfg *cfg, Octstr *name)
static void destroy_group(void *arg)
long gwlist_delete_equal(List *list, void *item)
int octstr_item_match(void *item, void *pattern)
int octstr_case_compare(const Octstr *os1, const Octstr *os2)
void warning(int err, const char *fmt,...)
List * octstr_split_words(const Octstr *ostr)
void octstr_destroy(Octstr *ostr)
static List * single_hooks
char filename[FILENAME_MAX+1]
#define octstr_create(cstr)
void octstr_destroy_item(void *os)
void gwlist_insert(List *list, long pos, void *item)
void cfg_set(CfgGroup *grp, Octstr *varname, Octstr *value)
Octstr * octstr_read_file(const char *filename)
Octstr * cfg_get_group_name(CfgGroup *grp)
long octstr_len(const Octstr *ostr)
void dict_destroy(Dict *dict)
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
void debug(const char *place, int err, const char *fmt,...)
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
static CfgGroup * create_group(void)
long octstr_parse_long(long *nump, Octstr *ostr, long pos, int base)
static int is_single_group(Octstr *query)
List * dict_keys(Dict *dict)
void octstr_truncate(Octstr *ostr, int new_len)
static void set_group_name(CfgGroup *grp, Octstr *name)
CfgGroup * cfg_get_single_group(Cfg *cfg, Octstr *name)
int octstr_get_char(const Octstr *ostr, long pos)
List * octstr_split(const Octstr *os, const Octstr *sep)
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
static int is_allowed_in_group(Octstr *group, Octstr *variable)
static void parse_value(Octstr *value)
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)