diff options
| author | David Bremner <david@tethera.net> | 2020-08-08 11:16:36 -0300 |
|---|---|---|
| committer | David Bremner <david@tethera.net> | 2021-02-06 18:57:35 -0400 |
| commit | e5f3c3ed50247323ecbd2a50e3b24a8352d17f8d (patch) | |
| tree | 86adf8b40c3c3ca36755ddfe4213a8597dc35dc7 /lib/config.cc | |
| parent | 4743e87c2c79c37208bb60d6617ef203796fc5c2 (diff) | |
lib: add stub for notmuch_database_open_with_config
Initially document the intended API and copy the code from
notmuch_database_open_verbose. Most of the documented functionality is
not there yet.
Diffstat (limited to 'lib/config.cc')
| -rw-r--r-- | lib/config.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/config.cc b/lib/config.cc index c079d752..8bce7ba8 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -245,3 +245,37 @@ _notmuch_config_load_from_database (notmuch_database_t *notmuch) return status; } + +notmuch_status_t +_notmuch_config_load_from_file (notmuch_database_t *notmuch, + GKeyFile *file) +{ + notmuch_status_t status = NOTMUCH_STATUS_SUCCESS; + gchar **groups,**keys, *val; + + if (notmuch->config == NULL) + notmuch->config = _notmuch_string_map_create (notmuch); + + if (unlikely(notmuch->config == NULL)) { + status = NOTMUCH_STATUS_OUT_OF_MEMORY; + goto DONE; + } + + for (groups = g_key_file_get_groups (file, NULL); *groups; groups++) { + for (keys = g_key_file_get_keys (file, *groups, NULL, NULL); *keys; keys++) { + char *absolute_key = talloc_asprintf(notmuch, "%s.%s", *groups, *keys); + val = g_key_file_get_value (file, *groups, *keys, NULL); + if (! val) { + status = NOTMUCH_STATUS_FILE_ERROR; + goto DONE; + } + _notmuch_string_map_set (notmuch->config, absolute_key, val); + talloc_free (absolute_key); + if (status) + goto DONE; + } + } + + DONE: + return status; +} |
