From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id MJ77Fxe0Ll8wBQAA0tVLHw (envelope-from ) for ; Sat, 08 Aug 2020 14:17:59 +0000 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 4XDPExe0Ll/MZgAA1q6Kng (envelope-from ) for ; Sat, 08 Aug 2020 14:17:59 +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 F12DE94028F for ; Sat, 8 Aug 2020 14:17:58 +0000 (UTC) Received: from [144.217.243.247] (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id E091329B13; Sat, 8 Aug 2020 10:17:31 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 1661129AE2 for ; Sat, 8 Aug 2020 10:17:15 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 060205FA66; Sat, 8 Aug 2020 10:17:14 -0400 (EDT) Received: (nullmailer pid 1124288 invoked by uid 1000); Sat, 08 Aug 2020 14:17:04 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 15/19] WIP: add config values iterator Date: Sat, 8 Aug 2020 11:16:49 -0300 Message-Id: <20200808141653.1124111-16-david@tethera.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200808141653.1124111-1-david@tethera.net> References: <20200808141653.1124111-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: INDEZ2U54PBGQ6MFPW4AS6JSAX7LIBDX X-Message-ID-Hash: INDEZ2U54PBGQ6MFPW4AS6JSAX7LIBDX 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-Scanner: scn0 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-Spam-Score: 0.03 X-TUID: U5C7S0COdCQd --- lib/config.cc | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/notmuch.h | 17 +++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/lib/config.cc b/lib/config.cc index ca7ac2a8..dd042ab2 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -31,6 +31,11 @@ struct _notmuch_config_list { char *current_val; }; +struct _notmuch_config_values { + const char *iterator; + size_t tok_len; +}; + static int _notmuch_config_list_destroy (notmuch_config_list_t *list) { @@ -232,6 +237,50 @@ notmuch_config_get (notmuch_database_t *notmuch, const char *key) { return _notmuch_string_map_get (notmuch->config, key); } +notmuch_config_values_t * +notmuch_config_get_values (notmuch_database_t *notmuch, const char *key) +{ + notmuch_config_values_t *values; + + const char *str; + str = _notmuch_string_map_get (notmuch->config, key); + if (! str) + return NULL; + + values = talloc (notmuch, notmuch_config_values_t); + if (unlikely(! values)) + return NULL; + + values->iterator = str; + values->tok_len = 0; + return values; +} + +notmuch_bool_t +notmuch_config_values_valid (notmuch_config_values_t *values) { + if (! values) + return false; + + return (values->iterator != NULL); +} + +const char * +notmuch_config_values_get (notmuch_config_values_t *values) { + return talloc_strndup (values, values->iterator, values->tok_len); +} + +void +notmuch_config_values_move_to_next (notmuch_config_values_t *values) { + values->iterator += values->tok_len; + values->iterator = strsplit_len (values->iterator, ';', &(values->tok_len)); +} + +void +notmuch_config_values_destroy (notmuch_config_values_t *values) { + talloc_free (values); +} + + notmuch_status_t notmuch_config_set (notmuch_database_t *notmuch, const char *key, diff --git a/lib/notmuch.h b/lib/notmuch.h index e147d5e6..7ae69265 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -236,6 +236,7 @@ typedef struct _notmuch_tags notmuch_tags_t; typedef struct _notmuch_directory notmuch_directory_t; typedef struct _notmuch_filenames notmuch_filenames_t; typedef struct _notmuch_config_list notmuch_config_list_t; +typedef struct _notmuch_config_values notmuch_config_values_t; typedef struct _notmuch_indexopts notmuch_indexopts_t; #endif /* __DOXYGEN__ */ @@ -2405,6 +2406,22 @@ notmuch_config_set (notmuch_database_t *notmuch, const char *key, const char *val, notmuch_bool_t write_through); + +notmuch_config_values_t * +notmuch_config_get_values (notmuch_database_t *notmuch, const char *key); + +notmuch_bool_t +notmuch_config_values_valid (notmuch_config_values_t *values); + +const char * +notmuch_config_values_get (notmuch_config_values_t *values); + +void +notmuch_config_values_move_to_next (notmuch_config_values_t *values); + +void +notmuch_config_values_destroy (notmuch_config_values_t *values); + /** * get the current default indexing options for a given database. * -- 2.28.0