Browse Source

MT#62053 add config file groups callback

Add a callback type to read config groups and their contents based on a
group prefix.

Unused at this point.

Change-Id: I7d9e043e96f48e599bc4da2d8ef4079559cb8b47
pull/1910/head
Richard Fuchs 11 months ago
parent
commit
119ca4b105
2 changed files with 40 additions and 0 deletions
  1. +34
    -0
      lib/auxlib.c
  2. +6
    -0
      lib/auxlib.h

+ 34
- 0
lib/auxlib.c View File

@ -178,6 +178,36 @@ static void section_keys_callback(GKeyFile *kf,
} }
} }
static void file_groups_callback(GKeyFile *kf,
const char *group_prefix,
void (*callback)(const char *name, charp_ht, union rtpenging_config_callback_arg),
union rtpenging_config_callback_arg arg)
{
if (!group_prefix)
return;
size_t pref_len = strlen(group_prefix);
g_autoptr(char_p) groups = g_key_file_get_groups(kf, NULL);
for (char **group = groups; *group; group++) {
// check for groups starting with "PREFIX-.."
if (memcmp(*group, group_prefix, pref_len))
continue;
char *ident = *group + pref_len;
if (*ident != '-')
continue;
ident++;
if (*ident == '\0')
continue;
// read all keys and put them in a hash table
g_auto(charp_ht) ht = charp_ht_new();
section_keys_callback(kf, *group, add_c_str_to_ht, ht);
callback(ident, ht, arg);
}
}
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GOptionEntry, free) G_DEFINE_AUTOPTR_CLEANUP_FUNC(GOptionEntry, free)
typedef char *char_p_shallow; typedef char *char_p_shallow;
G_DEFINE_AUTOPTR_CLEANUP_FUNC(char_p_shallow, g_free) G_DEFINE_AUTOPTR_CLEANUP_FUNC(char_p_shallow, g_free)
@ -394,6 +424,10 @@ void config_load_ext(int *argc, char ***argv, GOptionEntry *app_entries, const c
case RCC_SECTION_KEYS: case RCC_SECTION_KEYS:
section_keys_callback(kf, *cb->section_keys.name, cb->section_keys.callback, cb->arg); section_keys_callback(kf, *cb->section_keys.name, cb->section_keys.callback, cb->arg);
continue; continue;
case RCC_FILE_GROUPS:
file_groups_callback(kf, *cb->file_groups.prefix, cb->file_groups.callback, cb->arg);
continue;
} }
break; break;
} }


+ 6
- 0
lib/auxlib.h View File

@ -62,6 +62,7 @@ struct rtpenging_config_callback {
enum { enum {
RCC_END = 0, RCC_END = 0,
RCC_SECTION_KEYS, RCC_SECTION_KEYS,
RCC_FILE_GROUPS,
} type; } type;
union rtpenging_config_callback_arg arg; union rtpenging_config_callback_arg arg;
union { union {
@ -70,6 +71,11 @@ struct rtpenging_config_callback {
void (*callback)(const char *key, char *value, void (*callback)(const char *key, char *value,
union rtpenging_config_callback_arg); union rtpenging_config_callback_arg);
} section_keys; } section_keys;
struct {
char * const *prefix;
void (*callback)(const char *name, charp_ht,
union rtpenging_config_callback_arg);
} file_groups;
}; };
}; };


Loading…
Cancel
Save