1 Return-Path: <tomi.ollila@iki.fi>
\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 1C3186DE026C
\r
6 for <notmuch@notmuchmail.org>; Sat, 7 May 2016 10:04:03 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=0.601 tagged_above=-999 required=5 tests=[AWL=-0.051,
\r
12 SPF_NEUTRAL=0.652] 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 qr1U5KtbQ6OU for <notmuch@notmuchmail.org>;
\r
16 Sat, 7 May 2016 10:03:54 -0700 (PDT)
\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])
\r
18 by arlo.cworth.org (Postfix) with ESMTP id BA2E16DE00EB
\r
19 for <notmuch@notmuchmail.org>; Sat, 7 May 2016 10:03:53 -0700 (PDT)
\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])
\r
21 by guru.guru-group.fi (Postfix) with ESMTP id A9CED100063;
\r
22 Sat, 7 May 2016 20:03:51 +0300 (EEST)
\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
24 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
\r
25 Subject: Re: [Patch v3 05/11] lib: provide config API
\r
26 In-Reply-To: <1462065879-29860-6-git-send-email-david@tethera.net>
\r
27 References: <1462065879-29860-1-git-send-email-david@tethera.net>
\r
28 <1462065879-29860-6-git-send-email-david@tethera.net>
\r
29 User-Agent: Notmuch/0.22+9~gb26b5ad (http://notmuchmail.org) Emacs/24.3.1
\r
30 (x86_64-unknown-linux-gnu)
\r
31 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL
\r
32 $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F
\r
33 !)g;OY^,BjTbr)Np:%c_o'jj,Z
\r
34 Date: Sat, 07 May 2016 20:03:51 +0300
\r
35 Message-ID: <m2zis1er60.fsf@guru.guru-group.fi>
\r
37 Content-Type: text/plain; charset=utf-8
\r
38 Content-Transfer-Encoding: quoted-printable
\r
39 X-BeenThere: notmuch@notmuchmail.org
\r
40 X-Mailman-Version: 2.1.20
\r
42 List-Id: "Use and development of the notmuch mail system."
\r
43 <notmuch.notmuchmail.org>
\r
44 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
47 List-Post: <mailto:notmuch@notmuchmail.org>
\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
49 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
51 X-List-Received-Date: Sat, 07 May 2016 17:04:03 -0000
\r
53 On Sun, May 01 2016, David Bremner <david@tethera.net> wrote:
\r
57 > This is a thin wrapper around the Xapian metadata API. The job of this
\r
58 > layer is to keep the config key value pairs from colliding with other
\r
59 > metadata by transparently prefixing the keys, along with the usual glue
\r
60 > to provide a C interface.
\r
62 > The split of _get_config into two functions is to allow returning of the
\r
63 > return value with different memory ownership semantics.
\r
65 > lib/Makefile.local | 1 +
\r
66 > lib/config.cc | 90 ++++++++++++++++++++++++++++++++++++++++++++=
\r
68 > lib/notmuch.h | 20 +++++++++++
\r
69 > test/T590-libconfig.sh | 58 ++++++++++++++++++++++++++++++++
\r
70 > 4 files changed, 169 insertions(+)
\r
71 > create mode 100644 lib/config.cc
\r
72 > create mode 100755 test/T590-libconfig.sh
\r
74 > diff --git a/lib/Makefile.local b/lib/Makefile.local
\r
75 > index 36c3924..76b57cb 100644
\r
76 > --- a/lib/Makefile.local
\r
77 > +++ b/lib/Makefile.local
\r
78 > @@ -49,6 +49,7 @@ libnotmuch_cxx_srcs =3D \
\r
80 > $(dir)/message.cc \
\r
82 > + $(dir)/config.cc \
\r
85 > libnotmuch_modules :=3D $(libnotmuch_c_srcs:.c=3D.o) $(libnotmuch_cxx_sr=
\r
87 > diff --git a/lib/config.cc b/lib/config.cc
\r
88 > new file mode 100644
\r
89 > index 0000000..af00d6f
\r
91 > +++ b/lib/config.cc
\r
93 > +/* metadata.cc - API for database metadata
\r
95 config.cc or metadata.cc -- decide ! ;D
\r
98 > + * Copyright =C2=A9 2015 David Bremner
\r
100 this could be 2016 now (?) (like it matters)
\r
103 > + * This program is free software: you can redistribute it and/or modify
\r
104 > + * it under the terms of the GNU General Public License as published by
\r
105 > + * the Free Software Foundation, either version 3 of the License, or
\r
106 > + * (at your option) any later version.
\r
108 > + * This program is distributed in the hope that it will be useful,
\r
109 > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
110 > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
111 > + * GNU General Public License for more details.
\r
113 > + * You should have received a copy of the GNU General Public License
\r
114 > + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
116 > + * Author: David Bremner <david@tethera.net>
\r
119 > +#include "notmuch.h"
\r
120 > +#include "notmuch-private.h"
\r
121 > +#include "database-private.h"
\r
123 > +static const std::string CONFIG_PREFIX=3D"C";
\r
125 spacing. e.g. CONFIG_PREFIX =3D "C";
\r
128 > +notmuch_status_t
\r
129 > +notmuch_database_set_config (notmuch_database_t *notmuch,
\r
130 > + const char *key,
\r
131 > + const char *value)
\r
133 > + notmuch_status_t status;
\r
134 > + Xapian::WritableDatabase *db;
\r
136 > + status =3D _notmuch_database_ensure_writable (notmuch);
\r
141 > + db =3D static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);
\r
142 > + db->set_metadata (CONFIG_PREFIX+key, value);
\r
143 > + } catch (const Xapian::Error &error) {
\r
144 > + status =3D NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
145 > + notmuch->exception_reported =3D TRUE;
\r
146 > + if (! notmuch->exception_reported) {
\r
147 > + _notmuch_database_log (notmuch, "Error: A Xapian exception occurred=
\r
148 setting metadata: %s\n",
\r
150 The above goes up to column 104, but probably nothing is to be done there.
\r
152 > + error.get_msg().c_str());
\r
155 > + return NOTMUCH_STATUS_SUCCESS;
\r
158 > +static notmuch_status_t
\r
159 > +_metadata_value (notmuch_database_t *notmuch,
\r
160 > + const char *key,
\r
161 > + std::string &value)
\r
163 > + notmuch_status_t status =3D NOTMUCH_STATUS_SUCCESS;
\r
166 > + value =3D notmuch->xapian_db->get_metadata (CONFIG_PREFIX+key);
\r
168 spacing: e.g. (CONFIG_PREFIX + key);
\r
170 > + } catch (const Xapian::Error &error) {
\r
171 > + status =3D NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
172 > + notmuch->exception_reported =3D TRUE;
\r
173 > + if (! notmuch->exception_reported) {
\r
174 > + _notmuch_database_log (notmuch, "Error: A Xapian exception occurred=
\r
175 getting metadata: %s\n",
\r
176 > + error.get_msg().c_str());
\r
182 > +notmuch_status_t
\r
183 > +notmuch_database_get_config (notmuch_database_t *notmuch,
\r
184 > + const char *key,
\r
185 > + char **value) {
\r
187 In functions IIRC we always have opening brace in its own line.
\r
189 > + std::string strval;
\r
190 > + notmuch_status_t status;
\r
193 > + return NOTMUCH_STATUS_NULL_POINTER;
\r
195 > + status =3D _metadata_value (notmuch, key, strval);
\r
199 > + *value =3D strdup (strval.c_str ());
\r
201 > + return NOTMUCH_STATUS_SUCCESS;
\r