From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id ABmdNZzaQGB1bgAA0tVLHw (envelope-from ) for ; Thu, 04 Mar 2021 13:03:24 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 2LhWMZzaQGBwRAAAB5/wlQ (envelope-from ) for ; Thu, 04 Mar 2021 13:03:24 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1C1AF15FE2 for ; Thu, 4 Mar 2021 14:03:24 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id CA16127589; Thu, 4 Mar 2021 08:02:17 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 06C1F27076 for ; Thu, 4 Mar 2021 08:01:58 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id F1D345FA96; Thu, 4 Mar 2021 08:01:57 -0500 (EST) Received: (nullmailer pid 4047171 invoked by uid 1000); Thu, 04 Mar 2021 13:01:45 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 05/27] lib/config: add notmuch_config_get_values_string Date: Thu, 4 Mar 2021 09:01:17 -0400 Message-Id: <20210304130139.4046183-6-david@tethera.net> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210304130139.4046183-1-david@tethera.net> References: <20210304130139.4046183-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: ZC7GEC3MCVY3QQVXNEYY7QUEHJN55GDU X-Message-ID-Hash: ZC7GEC3MCVY3QQVXNEYY7QUEHJN55GDU 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1614863004; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=7RqZgFnG40ox37JZxAXEkwYFNzNkGWo4uYnj8g8No58=; b=BBk4pMeLTB56oSs68a0NPVWFxpFoN0HDjECSiqpfobn4RuR/KZZvqyZca4A1C+Tf3Cftwr 1Rt1d55br7Zf4uoxVmAmbogxTgdz3kf8yAEKNU8a9/Tw5CrgVIQbvZngQaqX5e2TkkW4A0 hfYaB3IT0SoIPN7209MdmQKDEXhpxRf3sTB9Ey5YTbSO6mEWiUOI1G8nzBW1nDFcOVmjIB qO29ycph52g+9Gel4p+RZY0i50FbQoDMcA5jMeLfliDlC7yRHwJUGPWyLuQdsTifZw109K zJOIBUVD6noymwzZ/0dyr7Iw7P7CN9hd/PvbD90OZb3VGUP9hJhsqHWoAtvqAQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1614863004; a=rsa-sha256; cv=none; b=ekT1jt1CVKA5U5Ouv1YPk2ebrfuSZPzCvt1ogScfepv5BwahHJRJfv4MYG7jZX4oy94qOK Wj959Ip0ExQ3Nb5WDAcPmq7J0rHwEi0SIsgooMG7TTKx4dXW6fLcV+JugZWly0EN+UlQhW c5FH4pstlEYNz3gXKQ+MMru9lS/tYDvrbqWD3SLJEdOZdSisOSf8dhyUu/vv245DSzBjJp yAMTVEn1xcYEKtJFnxG0aJuzkAiMnG3mpnO1RrFR6EV44i1zCbo42FdBeP+FWnLhGF0Lrz O9jegO+h6U5bAVWHJEAeQ40mJ9i+T+IOK77uVugFqZVe1nWzwjUr8K20xlgUaA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -0.80 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 1C1AF15FE2 X-Spam-Score: -0.80 X-Migadu-Scanner: scn0.migadu.com X-TUID: guTRFluotiRN This is to support the less common (at least in the notmuch codebase) case of accessing a ;-delimited list config value with an arbitrary string key. --- lib/config.cc | 14 ++++++++++---- lib/notmuch.h | 17 ++++++++++++++++- test/T590-libconfig.sh | 23 +++++++++++++++++++++++ 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/lib/config.cc b/lib/config.cc index 32ed6f8f..cec2e9de 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -258,13 +258,19 @@ _notmuch_config_load_from_database (notmuch_database_t *notmuch) notmuch_config_values_t * notmuch_config_get_values (notmuch_database_t *notmuch, notmuch_config_key_t key) { - notmuch_config_values_t *values = NULL; - bool ok = false; - const char *key_str = _notmuch_config_key_to_string (key); if (! key_str) - goto DONE; + return NULL; + + return notmuch_config_get_values_string (notmuch, key_str); +} + +notmuch_config_values_t * +notmuch_config_get_values_string (notmuch_database_t *notmuch, const char *key_str) +{ + notmuch_config_values_t *values = NULL; + bool ok = false; values = talloc (notmuch, notmuch_config_values_t); if (unlikely(! values)) diff --git a/lib/notmuch.h b/lib/notmuch.h index 8d4a4716..9a4f94f5 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -2493,7 +2493,6 @@ notmuch_config_list_move_to_next (notmuch_config_list_t *config_list); void notmuch_config_list_destroy (notmuch_config_list_t *config_list); - /** * Configuration keys known to libnotmuch */ @@ -2564,6 +2563,22 @@ notmuch_config_set (notmuch_database_t *notmuch, notmuch_config_key_t key, const notmuch_config_values_t * notmuch_config_get_values (notmuch_database_t *notmuch, notmuch_config_key_t key); +/** + * Returns an iterator for a ';'-delimited list of configuration values + * + * These values reflect all configuration information given at the + * time the database was opened. + * + * @param[in] notmuch database + * @param[in] key configuration key + * + * @since libnotmuch 5.4 (notmuch 0.32) + * + * @retval NULL in case of error. + */ +notmuch_config_values_t * +notmuch_config_get_values_string (notmuch_database_t *notmuch, const char *key); + /** * Is the given 'config_values' iterator pointing at a valid element. * diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh index dc9964cf..edbba6c4 100755 --- a/test/T590-libconfig.sh +++ b/test/T590-libconfig.sh @@ -255,6 +255,29 @@ EOF test_expect_equal_file EXPECTED OUTPUT restore_database +test_begin_subtest "notmuch_config_get_values_string" +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL% +{ + notmuch_config_values_t *values; + EXPECT0(notmuch_database_set_config (db, "test.list", "x;y;z")); + for (values = notmuch_config_get_values_string (db, "test.list"); + notmuch_config_values_valid (values); + notmuch_config_values_move_to_next (values)) + { + puts (notmuch_config_values_get (values)); + } +} +EOF +cat <<'EOF' >EXPECTED +== stdout == +x +y +z +== stderr == +EOF +test_expect_equal_file EXPECTED OUTPUT +restore_database + test_begin_subtest "notmuch_config_get_values (restart)" cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL% { -- 2.30.1