From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id QJpSI7sRbWDYIAEAgWs5BA (envelope-from ) for ; Wed, 07 Apr 2021 03:58:19 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id uDVFHbsRbWC1FQAA1q6Kng (envelope-from ) for ; Wed, 07 Apr 2021 01:58:19 +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) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 2939EA11A for ; Wed, 7 Apr 2021 03:58:19 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id D3D23290D7; Tue, 6 Apr 2021 21:56:54 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 0692729052 for ; Tue, 6 Apr 2021 21:56:06 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id F1B635FA96; Tue, 6 Apr 2021 21:56:05 -0400 (EDT) Received: (nullmailer pid 2964215 invoked by uid 1000); Wed, 07 Apr 2021 01:55:35 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 06/28] lib/config: add notmuch_config_get_values_string Date: Tue, 6 Apr 2021 22:55:08 -0300 Message-Id: <20210407015530.2964017-7-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210407015530.2964017-1-david@tethera.net> References: <20210407015530.2964017-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: Y3W3Y57FJFKUVI4L5I7LU44VJ6J7M55H X-Message-ID-Hash: Y3W3Y57FJFKUVI4L5I7LU44VJ6J7M55H 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=1617760699; 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=3DYhI5mFI2n2waglELocJkMBq9CXyhXatLBvrd5iL5w=; b=Bt5gmmIUP/7CWKzRXczpNME/tMyVhRxo2HD0vbW2mruMAj7TrBkvA1t1TMbGSsHBE+FeFV yHZyGlalxEWwXH6arYCkBB5oX7eDHKg7hAlbtagN78eyc2QeSdE12MDrQ91oSt8rjrQAPS lVI0sdKT6b45IgbaPqebXKCs4TYKswpcUK3/s1CzwiSxGYcc2B9KJZkFuY9tLPjxzmU+PT CbFy0UVFhZlMRg4fjCrOeRYzAo2bqYTfl+rX5+xh1pn4mphnOls2V/YhhFk1RT5XUtDD6p zi6dNZ0w7m+5Bn+uuKYwjBrVXgf3UA4sXXt4qN24cChgH7dayawbV6z07b3lrg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1617760699; a=rsa-sha256; cv=none; b=fE8/9v50UYpq/wmxgRPcGHEnYrfcWajmyxnlB8hW7NlX60wGJSCAxrDFp2RoiBP8nSEmfZ jWJDtzkktF7zORkM6YC1bKxhQ2qlvPiEsg+IhfnvCXl2yNhsy7o0I+4HwgZssoPHFujhXs y61bhdvbUvv+Ojs/ntD3DGD7G6EBRzls9z5D2m+LJ2qoDFt9taN39cdYXB7u8vHXroIHgj aEXv6FPt36GFmk+GAcS76OzPjsGpWjKwRIT1IC4d0x8DoBb8YxJaKvwz7kahXViX7SDcof 77IEUw5lZFbrLt+GRLoETe2aDLeLo38ZcikyzJA/pBEKVo6m2djBc4LhF5YyZg== ARC-Authentication-Results: i=1; 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-Spam-Score: -0.99 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: 2939EA11A X-Spam-Score: -0.99 X-Migadu-Scanner: scn0.migadu.com X-TUID: k2T5O/u2GqqN 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 8bd3c35a..24418f98 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -261,13 +261,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 da556e50..dd3d06a1 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -2494,7 +2494,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 */ @@ -2565,6 +2564,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.2