1 Return-Path: <bremner@tethera.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by arlo.cworth.org (Postfix) with ESMTP id 5A92B6DE02C9
\r
6 for <notmuch@notmuchmail.org>; Sat, 9 Jan 2016 18:51:56 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.311 tagged_above=-999 required=5 tests=[AWL=0.240,
\r
12 RP_MATCHES_RCVD=-0.55, SPF_PASS=-0.001] autolearn=disabled
\r
13 Received: from arlo.cworth.org ([127.0.0.1])
\r
14 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id BoS80j-V-ETt for <notmuch@notmuchmail.org>;
\r
16 Sat, 9 Jan 2016 18:51:53 -0800 (PST)
\r
17 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])
\r
18 by arlo.cworth.org (Postfix) with ESMTPS id 79B206DE028A
\r
19 for <notmuch@notmuchmail.org>; Sat, 9 Jan 2016 18:51:53 -0800 (PST)
\r
20 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)
\r
21 (envelope-from <bremner@tethera.net>)
\r
22 id 1aI66Y-0007Cy-PY; Sat, 09 Jan 2016 21:51:42 -0500
\r
23 Received: (nullmailer pid 29640 invoked by uid 1000);
\r
24 Sun, 10 Jan 2016 02:51:47 -0000
\r
25 From: David Bremner <david@tethera.net>
\r
26 To: notmuch@notmuchmail.org
\r
27 Subject: [WIP patch 2/9] lib: notmuch_metadata_t: iterators for metadata
\r
28 Date: Sat, 9 Jan 2016 22:51:34 -0400
\r
29 Message-Id: <1452394301-29499-3-git-send-email-david@tethera.net>
\r
30 X-Mailer: git-send-email 2.6.4
\r
31 In-Reply-To: <1452394301-29499-1-git-send-email-david@tethera.net>
\r
32 References: <1452394301-29499-1-git-send-email-david@tethera.net>
\r
33 X-BeenThere: notmuch@notmuchmail.org
\r
34 X-Mailman-Version: 2.1.20
\r
36 List-Id: "Use and development of the notmuch mail system."
\r
37 <notmuch.notmuchmail.org>
\r
38 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
39 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
41 List-Post: <mailto:notmuch@notmuchmail.org>
\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
43 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
45 X-List-Received-Date: Sun, 10 Jan 2016 02:51:56 -0000
\r
47 The rough idea is to give a C interface to the Xapian::TermIterator class.
\r
49 lib/metadata.cc | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++
\r
50 lib/notmuch.h | 12 ++++++++++
\r
51 test/T590-metadata.sh | 15 ++++++++++++
\r
52 3 files changed, 90 insertions(+)
\r
54 diff --git a/lib/metadata.cc b/lib/metadata.cc
\r
55 index a068ed1..5d319c5 100644
\r
56 --- a/lib/metadata.cc
\r
57 +++ b/lib/metadata.cc
\r
59 #include "notmuch-private.h"
\r
60 #include "database-private.h"
\r
62 +struct _notmuch_metadata {
\r
63 + notmuch_database_t *notmuch;
\r
64 + Xapian::TermIterator *iterator;
\r
65 + notmuch_metadata_class_t mclass;
\r
69 +_notmuch_metadata_destroy (notmuch_metadata_t *list) {
\r
70 + delete list->iterator;
\r
75 _find_metadata_prefix (notmuch_metadata_class_t mclass)
\r
76 @@ -148,3 +159,55 @@ notmuch_database_get_metadata (notmuch_database_t *notmuch,
\r
78 return NOTMUCH_STATUS_SUCCESS;
\r
82 +notmuch_database_get_all_metadata (notmuch_database_t *notmuch,
\r
83 + notmuch_metadata_class_t mclass,
\r
84 + notmuch_metadata_t **out)
\r
86 + notmuch_metadata_t *list = NULL;
\r
87 + notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
\r
89 + const char *prefix = _find_metadata_prefix (mclass);
\r
91 + list = talloc (notmuch, notmuch_metadata_t);
\r
93 + status = NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
97 + talloc_set_destructor(list, _notmuch_metadata_destroy);
\r
98 + list->iterator = new Xapian::TermIterator;
\r
99 + list->notmuch = notmuch;
\r
100 + list->mclass = mclass;
\r
104 + *list->iterator = notmuch->xapian_db->metadata_keys_begin();
\r
105 + list->iterator->skip_to (prefix);
\r
107 + } catch (const Xapian::Error &error) {
\r
108 + _notmuch_database_log (notmuch, "A Xapian exception occurred getting metadata iterator: %s.\n",
\r
109 + error.get_msg().c_str());
\r
110 + notmuch->exception_reported = TRUE;
\r
111 + status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
117 + if (status && list)
\r
118 + talloc_free (list);
\r
124 +notmuch_metadata_valid (notmuch_metadata_t *metadata)
\r
126 + const char *prefix = _find_metadata_prefix (metadata->mclass);
\r
127 + if (*(metadata->iterator) == metadata->notmuch->xapian_db->metadata_keys_end())
\r
130 + return (strncmp((**(metadata->iterator)).c_str (), prefix, strlen (prefix)) == 0);
\r
132 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
133 index 448f405..a2b7040 100644
\r
134 --- a/lib/notmuch.h
\r
135 +++ b/lib/notmuch.h
\r
136 @@ -197,6 +197,7 @@ typedef struct _notmuch_message notmuch_message_t;
\r
137 typedef struct _notmuch_tags notmuch_tags_t;
\r
138 typedef struct _notmuch_directory notmuch_directory_t;
\r
139 typedef struct _notmuch_filenames notmuch_filenames_t;
\r
140 +typedef struct _notmuch_metadata notmuch_metadata_t;
\r
141 #endif /* __DOXYGEN__ */
\r
144 @@ -1854,6 +1855,17 @@ notmuch_database_set_metadata (notmuch_database_t *db, notmuch_metadata_class_t
\r
146 notmuch_database_get_metadata (notmuch_database_t *db, notmuch_metadata_class_t mclass, const char *key, char **value);
\r
149 + * get all metadata of a given class
\r
152 +notmuch_database_get_all_metadata (notmuch_database_t *db, notmuch_metadata_class_t mclass, notmuch_metadata_t **out);
\r
155 + * Is 'metadata' iterator valid (i.e. _key, _value, _move_to_next can be called).
\r
158 +notmuch_metadata_valid (notmuch_metadata_t *metadata);
\r
162 diff --git a/test/T590-metadata.sh b/test/T590-metadata.sh
\r
163 index 29aeaa2..c36a7d7 100755
\r
164 --- a/test/T590-metadata.sh
\r
165 +++ b/test/T590-metadata.sh
\r
166 @@ -55,4 +55,19 @@ testkey2 = testvalue2
\r
168 test_expect_equal_file EXPECTED OUTPUT
\r
170 +test_begin_subtest "notmuch_database_get_all_metadata initially valid"
\r
171 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
173 + notmuch_metadata_t *meta;
\r
174 + RUN(notmuch_database_get_all_metadata (db, NOTMUCH_METADATA_CONFIG, &meta));
\r
175 + printf("valid = %d\n", notmuch_metadata_valid (meta));
\r
178 +cat <<'EOF' >EXPECTED
\r
183 +test_expect_equal_file EXPECTED OUTPUT
\r