2011-05-21 19:20:07 +02:00
|
|
|
/* -*-mode: c++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8-*- */
|
2009-11-25 21:55:06 +01:00
|
|
|
/*
|
2017-01-02 23:37:19 +01:00
|
|
|
** Copyright (C) 2008-2017 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2009-11-25 21:55:06 +01:00
|
|
|
**
|
|
|
|
** This program is free software; you can redistribute it and/or modify it
|
|
|
|
** under the terms of the GNU General Public License as published by the
|
|
|
|
** Free Software Foundation; either version 3, or (at your option) any
|
|
|
|
** later version.
|
|
|
|
**
|
|
|
|
** This program is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with this program; if not, write to the Free Software Foundation,
|
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2010-11-11 21:05:55 +01:00
|
|
|
#if HAVE_CONFIG_H
|
2009-11-25 21:55:06 +01:00
|
|
|
#include "config.h"
|
|
|
|
#endif /*HAVE_CONFIG_H*/
|
|
|
|
|
2010-01-22 18:18:23 +01:00
|
|
|
#include <cstdio>
|
|
|
|
#include <xapian.h>
|
2010-09-12 15:28:34 +02:00
|
|
|
#include <cstring>
|
2011-03-22 22:37:01 +01:00
|
|
|
#include <stdexcept>
|
2012-03-26 20:17:38 +02:00
|
|
|
#include <unistd.h>
|
2010-01-22 18:18:23 +01:00
|
|
|
|
2011-08-29 22:35:12 +02:00
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "mu-store.h"
|
|
|
|
#include "mu-store-priv.hh" /* _MuStore */
|
|
|
|
|
2009-11-25 21:55:06 +01:00
|
|
|
#include "mu-msg.h"
|
2011-05-21 15:06:52 +02:00
|
|
|
#include "mu-msg-part.h"
|
2010-08-25 20:55:08 +02:00
|
|
|
#include "mu-store.h"
|
2010-01-05 07:32:23 +01:00
|
|
|
#include "mu-util.h"
|
2010-11-22 23:44:18 +01:00
|
|
|
#include "mu-str.h"
|
2011-07-20 23:38:28 +02:00
|
|
|
#include "mu-date.h"
|
2011-08-11 21:44:23 +02:00
|
|
|
#include "mu-flags.h"
|
2011-03-01 23:13:24 +01:00
|
|
|
#include "mu-contacts.h"
|
2011-01-12 22:13:03 +01:00
|
|
|
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2011-08-30 21:02:28 +02:00
|
|
|
|
|
|
|
MuStore*
|
|
|
|
mu_store_ref (MuStore *store)
|
2010-11-20 13:43:04 +01:00
|
|
|
{
|
2011-08-30 21:02:28 +02:00
|
|
|
g_return_val_if_fail (store, NULL);
|
|
|
|
store->ref();
|
|
|
|
return store;
|
2010-11-20 13:43:04 +01:00
|
|
|
}
|
|
|
|
|
2011-08-30 21:02:28 +02:00
|
|
|
MuStore*
|
|
|
|
mu_store_unref (MuStore *store)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (store, NULL);
|
|
|
|
|
|
|
|
if (store->unref() == 0) {
|
|
|
|
try { delete store; } MU_XAPIAN_CATCH_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-29 22:35:12 +02:00
|
|
|
static char*
|
|
|
|
xapian_get_metadata (const gchar *xpath, const gchar *key)
|
2011-01-12 22:13:03 +01:00
|
|
|
{
|
2011-08-29 22:35:12 +02:00
|
|
|
g_return_val_if_fail (xpath, NULL);
|
2011-01-12 22:13:03 +01:00
|
|
|
g_return_val_if_fail (key, NULL);
|
|
|
|
|
2015-12-15 12:40:40 +01:00
|
|
|
if (access(xpath, F_OK) != 0) {
|
2011-08-29 22:35:12 +02:00
|
|
|
g_warning ("cannot access %s: %s", xpath, strerror(errno));
|
|
|
|
return NULL;
|
2010-01-05 08:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-01-06 00:20:30 +01:00
|
|
|
try {
|
2011-08-29 22:35:12 +02:00
|
|
|
Xapian::Database db (xpath);
|
|
|
|
const std::string val(db.get_metadata (key));
|
|
|
|
return val.empty() ? NULL : g_strdup (val.c_str());
|
2010-01-06 00:20:30 +01:00
|
|
|
|
|
|
|
} MU_XAPIAN_CATCH_BLOCK;
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2011-08-29 22:35:12 +02:00
|
|
|
return NULL;
|
2011-05-21 15:06:52 +02:00
|
|
|
}
|
|
|
|
|
2011-08-29 22:35:12 +02:00
|
|
|
char*
|
|
|
|
mu_store_database_version (const gchar *xpath)
|
2011-05-21 15:06:52 +02:00
|
|
|
{
|
2011-08-29 22:35:12 +02:00
|
|
|
g_return_val_if_fail (xpath, NULL);
|
2011-05-21 15:06:52 +02:00
|
|
|
|
2011-08-29 22:35:12 +02:00
|
|
|
return xapian_get_metadata (xpath, MU_STORE_VERSION_KEY);
|
2009-11-25 21:55:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-12 22:13:03 +01:00
|
|
|
gboolean
|
2011-08-29 22:35:12 +02:00
|
|
|
mu_store_database_is_locked (const gchar *xpath)
|
2009-11-25 21:55:06 +01:00
|
|
|
{
|
2011-08-29 22:35:12 +02:00
|
|
|
g_return_val_if_fail (xpath, FALSE);
|
2010-01-03 22:53:04 +01:00
|
|
|
|
|
|
|
try {
|
2011-08-29 22:35:12 +02:00
|
|
|
Xapian::WritableDatabase db (xpath, Xapian::DB_OPEN);
|
|
|
|
} catch (const Xapian::DatabaseLockError& xer) {
|
|
|
|
return TRUE;
|
|
|
|
} catch (const Xapian::Error &xer) {
|
2015-04-22 20:06:31 +02:00
|
|
|
g_warning ("%s: error: %s", __func__,
|
2011-08-29 22:35:12 +02:00
|
|
|
xer.get_msg().c_str());
|
|
|
|
}
|
2010-01-03 22:53:04 +01:00
|
|
|
|
2011-08-29 22:35:12 +02:00
|
|
|
return FALSE;
|
2010-01-03 22:53:04 +01:00
|
|
|
}
|
2012-06-19 16:59:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
mu_store_set_my_addresses (MuStore *store, const char **my_addresses)
|
|
|
|
{
|
|
|
|
g_return_if_fail (store);
|
|
|
|
|
|
|
|
store->set_my_addresses (my_addresses);
|
|
|
|
}
|