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 8JZ/K/mzLl/JAwAA0tVLHw (envelope-from ) for ; Sat, 08 Aug 2020 14:17:29 +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 ECpOJ/mzLl8mZQAA1q6Kng (envelope-from ) for ; Sat, 08 Aug 2020 14:17:29 +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) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id EE98C940366 for ; Sat, 8 Aug 2020 14:17:28 +0000 (UTC) Received: from [144.217.243.247] (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 3D64129ACD; Sat, 8 Aug 2020 10:17:12 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 5DB642711D for ; Sat, 8 Aug 2020 10:17:07 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 35A485FA6A; Sat, 8 Aug 2020 10:17:07 -0400 (EDT) Received: (nullmailer pid 1124261 invoked by uid 1000); Sat, 08 Aug 2020 14:17:04 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 03/19] lib: cache configuration information from database Date: Sat, 8 Aug 2020 11:16:37 -0300 Message-Id: <20200808141653.1124111-4-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: JK6VVT74H2YVTL3VOUCQ6XDHAK7OBOL3 X-Message-ID-Hash: JK6VVT74H2YVTL3VOUCQ6XDHAK7OBOL3 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 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Spam-Score: 0.03 X-TUID: Hmx7fgZgFr5y The main goal is to allow configuration information to be temporarily overridden by a separate config file. --- lib/config.cc | 25 +++++++++++++++++++++++++ lib/database-private.h | 3 +++ lib/database.cc | 4 ++++ lib/notmuch-private.h | 3 +++ 4 files changed, 35 insertions(+) diff --git a/lib/config.cc b/lib/config.cc index dae0ff0e..2d4c3801 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -194,3 +194,28 @@ notmuch_config_list_destroy (notmuch_config_list_t *list) { talloc_free (list); } + +notmuch_status_t +_notmuch_config_load_from_database (notmuch_database_t *notmuch) +{ + notmuch_status_t status = NOTMUCH_STATUS_SUCCESS; + notmuch_config_list_t *list; + + if (notmuch->config == NULL) + notmuch->config = _notmuch_string_map_create (notmuch); + + if (unlikely(notmuch->config == NULL)) + return NOTMUCH_STATUS_OUT_OF_MEMORY; + + status = notmuch_database_get_config_list (notmuch, "", &list); + if (status) + return status; + + for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) { + _notmuch_string_map_append (notmuch->config, + notmuch_config_list_key (list), + notmuch_config_list_value (list)); + } + + return status; +} diff --git a/lib/database-private.h b/lib/database-private.h index 041602cd..bfeef869 100644 --- a/lib/database-private.h +++ b/lib/database-private.h @@ -226,6 +226,9 @@ struct _notmuch_database { * here, but at least they are small */ notmuch_string_map_t *user_prefix; notmuch_string_map_t *user_header; + + /* Cached and possibly overridden configuration */ + notmuch_string_map_t *config; }; /* Prior to database version 3, features were implied by the database diff --git a/lib/database.cc b/lib/database.cc index acc686c0..350abb11 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -987,6 +987,7 @@ notmuch_database_open_with_config (const char *database_path, notmuch = talloc_zero (NULL, notmuch_database_t); notmuch->exception_reported = false; notmuch->status_string = NULL; + notmuch->config = NULL; notmuch->path = talloc_strdup (notmuch, database_path); strip_trailing (notmuch->path, '/'); @@ -1085,6 +1086,9 @@ notmuch_database_open_with_config (const char *database_path, } } status = _setup_user_query_fields (notmuch); + + if (status == NOTMUCH_STATUS_SUCCESS) + status = _notmuch_config_load_from_database (notmuch); } catch (const Xapian::Error &error) { IGNORE_RESULT (asprintf (&message, "A Xapian exception occurred opening database: %s\n", error.get_msg ().c_str ())); diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index 57ec7f72..0f26b371 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -699,6 +699,9 @@ struct _notmuch_indexopts { #define EMPTY_STRING(s) ((s)[0] == '\0') +/* config.cc */ +notmuch_status_t +_notmuch_config_load_from_database (notmuch_database_t * db); NOTMUCH_END_DECLS #ifdef __cplusplus -- 2.28.0