1 /* config.cc - API for database metadata
3 * Copyright © 2016 David Bremner
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see http://www.gnu.org/licenses/ .
18 * Author: David Bremner <david@tethera.net>
22 #include "notmuch-private.h"
23 #include "database-private.h"
25 static const std::string CONFIG_PREFIX = "C";
28 notmuch_database_set_config (notmuch_database_t *notmuch,
32 notmuch_status_t status;
33 Xapian::WritableDatabase *db;
35 status = _notmuch_database_ensure_writable (notmuch);
40 db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);
41 db->set_metadata (CONFIG_PREFIX + key, value);
42 } catch (const Xapian::Error &error) {
43 status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
44 notmuch->exception_reported = TRUE;
45 _notmuch_database_log (notmuch, "Error: A Xapian exception occurred setting metadata: %s\n",
46 error.get_msg().c_str());
48 return NOTMUCH_STATUS_SUCCESS;
51 static notmuch_status_t
52 _metadata_value (notmuch_database_t *notmuch,
56 notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
59 value = notmuch->xapian_db->get_metadata (CONFIG_PREFIX + key);
60 } catch (const Xapian::Error &error) {
61 status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
62 notmuch->exception_reported = TRUE;
63 _notmuch_database_log (notmuch, "Error: A Xapian exception occurred getting metadata: %s\n",
64 error.get_msg().c_str());
70 notmuch_database_get_config (notmuch_database_t *notmuch,
75 notmuch_status_t status;
78 return NOTMUCH_STATUS_NULL_POINTER;
80 status = _metadata_value (notmuch, key, strval);
84 *value = strdup (strval.c_str ());
86 return NOTMUCH_STATUS_SUCCESS;