From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id aDRtCotIHWC6SAAA0tVLHw (envelope-from ) for ; Fri, 05 Feb 2021 13:30:51 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id mJ71BYtIHWDPbAAAbx9fmQ (envelope-from ) for ; Fri, 05 Feb 2021 13:30:51 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D86589404CE for ; Fri, 5 Feb 2021 13:30:50 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 217A126A20; Fri, 5 Feb 2021 08:28:31 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id D9F1A1FC6C for ; Fri, 5 Feb 2021 08:27:37 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id D47556067F; Fri, 5 Feb 2021 08:27:37 -0500 (EST) Received: (nullmailer pid 3258402 invoked by uid 1000); Fri, 05 Feb 2021 13:27:02 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 14/39] lib: add notmuch_config_get_bool Date: Fri, 5 Feb 2021 09:26:29 -0400 Message-Id: <20210205132654.3258292-15-david@tethera.net> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210205132654.3258292-1-david@tethera.net> References: <20210205132654.3258292-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: 4FZNC3T5BY74TQC4SC2JA334W555DCYH X-Message-ID-Hash: 4FZNC3T5BY74TQC4SC2JA334W555DCYH X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -1.04 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: D86589404CE X-Spam-Score: -1.04 X-Migadu-Scanner: scn1.migadu.com X-TUID: /wbl5O4KvLQE Booleans have no out of band values, so return a status for errors. --- lib/config.cc | 26 ++++++++++++++++++++++++++ lib/notmuch.h | 19 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/lib/config.cc b/lib/config.cc index b2957f0c..d14f5422 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) { diff --git a/lib/notmuch.h b/lib/notmuch.h index 39f39423..4a513b44 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -2532,6 +2532,25 @@ notmuch_config_values_start (notmuch_config_values_t *values); void notmuch_config_values_destroy (notmuch_config_values_t *values); +/** + * get a configuration value from an open database as Boolean + * + * This value reflects all configuration information given at the time + * the database was opened. + * + * @param[in] notmuch database + * @param[in] key configuration key + * @param[out] val configuration value, converted to Boolean + * + * @since libnotmuch 5.4 (notmuch 0.32) + * + * @retval #NOTMUCH_STATUS_ILLEGAL_ARGUMENT if either key is unknown + * or the corresponding value does not convert to Boolean. + */ +notmuch_status_t +notmuch_config_get_bool (notmuch_database_t *notmuch, + notmuch_config_key_t key, + notmuch_bool_t *val); /** * get the current default indexing options for a given database. * -- 2.30.0