X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=lib%2Fconfig.cc;h=fe67ef416a0d08083281d4890ed8d473155b85a4;hb=5232462dcfe77e6af475c9dd1a25513c43af53f3;hp=b2957f0c97c9a4fd0f9ca67d19b37ea204a40ffa;hpb=d071828bd5f8aee0437aeb4993ffeeaa803c367b;p=notmuch diff --git a/lib/config.cc b/lib/config.cc index b2957f0c..fe67ef41 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -359,6 +359,32 @@ _notmuch_config_load_from_file (notmuch_database_t *notmuch, return status; } +notmuch_status_t +notmuch_config_get_bool (notmuch_database_t *notmuch, notmuch_config_key_t key, notmuch_bool_t *val) +{ + const char *key_string, *val_string; + + key_string = _notmuch_config_key_to_string (key); + if (! key_string) { + return NOTMUCH_STATUS_ILLEGAL_ARGUMENT; + } + + val_string = _notmuch_string_map_get (notmuch->config, key_string); + if (! val_string) { + *val = FALSE; + return NOTMUCH_STATUS_SUCCESS; + } + + if (strcase_equal (val_string, "false") || strcase_equal (val_string, "no")) + *val = FALSE; + else if (strcase_equal (val_string, "true") || strcase_equal (val_string, "yes")) + *val = TRUE; + else + return NOTMUCH_STATUS_ILLEGAL_ARGUMENT; + + return NOTMUCH_STATUS_SUCCESS; +} + static const char * _notmuch_config_key_to_string (notmuch_config_key_t key) { switch (key) { @@ -438,3 +464,8 @@ notmuch_config_set (notmuch_database_t *notmuch, notmuch_config_key_t key, const return notmuch_database_set_config (notmuch, _notmuch_config_key_to_string (key), val); } + +void +_notmuch_config_cache (notmuch_database_t *notmuch, notmuch_config_key_t key, const char *val) { + _notmuch_string_map_set (notmuch->config, _notmuch_config_key_to_string (key), val); +}