2009-11-25 21:55:06 +01:00
|
|
|
/*
|
2010-01-01 14:56:45 +01:00
|
|
|
** Copyright (C) 2010 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 of the License, 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.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __MU_UTIL_H__
|
|
|
|
#define __MU_UTIL_H__
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
|
|
/**
|
2009-11-29 23:03:03 +01:00
|
|
|
* get the expanded path; ie. perform shell expansion on the path
|
2009-11-25 21:55:06 +01:00
|
|
|
*
|
|
|
|
* @param path path to expand
|
|
|
|
*
|
|
|
|
* @return the expanded path as a newly allocated string, or NULL in
|
|
|
|
* case of error
|
|
|
|
*/
|
2009-11-29 23:03:03 +01:00
|
|
|
char* mu_util_dir_expand (const char* path);
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2009-12-09 18:53:30 +01:00
|
|
|
/**
|
2010-01-25 12:27:02 +01:00
|
|
|
* guess the maildir; first try $MAILDIR; if it is unset or
|
|
|
|
* non-existant, try ~/Maildir if both fail, return NULL
|
2009-12-09 18:53:30 +01:00
|
|
|
*
|
|
|
|
* @return full path of the guessed Maildir, or NULL; must be freed (gfree)
|
|
|
|
*/
|
|
|
|
char* mu_util_guess_maildir (void);
|
|
|
|
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2010-01-04 19:15:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* if path exists, check that's a read/writeable dir; otherwise try to
|
|
|
|
* create it (with perms 0700)
|
|
|
|
*
|
|
|
|
* @param path path to the dir
|
|
|
|
*
|
|
|
|
* @return TRUE if a read/writeable directory `path' exists after
|
|
|
|
* leaving this function, FALSE otherwise
|
|
|
|
*/
|
|
|
|
gboolean mu_util_create_dir_maybe (const gchar *path);
|
|
|
|
|
2010-01-05 07:32:23 +01:00
|
|
|
|
2010-01-06 00:19:18 +01:00
|
|
|
/**
|
|
|
|
* check whether path is readable and/or writeable
|
|
|
|
*
|
|
|
|
* @param path dir path
|
|
|
|
* @param readable check for readability
|
|
|
|
* @param writeable check fro writability
|
|
|
|
*
|
|
|
|
* @return TRUE if dir exist and has the specified properties
|
|
|
|
*/
|
|
|
|
gboolean mu_util_check_dir (const gchar* path, gboolean readable,
|
|
|
|
gboolean writeable);
|
|
|
|
|
|
|
|
|
2010-01-05 07:32:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2010-01-06 00:19:18 +01:00
|
|
|
* don't repeat these catch blocks everywhere...
|
2010-01-05 07:32:23 +01:00
|
|
|
*
|
|
|
|
*/
|
2010-01-06 00:19:18 +01:00
|
|
|
#define MU_XAPIAN_CATCH_BLOCK \
|
2010-01-05 07:32:23 +01:00
|
|
|
catch (const Xapian::Error &err) { \
|
2010-01-10 11:11:38 +01:00
|
|
|
g_critical ("%s: caught xapian exception '%s'", \
|
2010-01-07 07:42:01 +01:00
|
|
|
__FUNCTION__, err.get_msg().c_str()); \
|
2010-01-05 07:32:23 +01:00
|
|
|
} catch (...) { \
|
2010-01-10 11:11:38 +01:00
|
|
|
g_critical ("%s: caught exception", __FUNCTION__); \
|
2010-01-05 07:32:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-06 00:19:18 +01:00
|
|
|
#define MU_XAPIAN_CATCH_BLOCK_RETURN(R) \
|
2010-01-05 07:32:23 +01:00
|
|
|
catch (const Xapian::Error &err) { \
|
2010-01-10 11:11:38 +01:00
|
|
|
g_critical ("%s: caught xapian exception '%s'", \
|
2010-01-07 07:42:01 +01:00
|
|
|
__FUNCTION__, err.get_msg().c_str()); \
|
2010-01-05 07:32:23 +01:00
|
|
|
return (R); \
|
|
|
|
} catch (...) { \
|
2010-01-10 11:11:38 +01:00
|
|
|
g_critical ("%s: caught exception", __FUNCTION__); \
|
2010-01-05 07:32:23 +01:00
|
|
|
return (R); \
|
|
|
|
}
|
|
|
|
|
2010-01-06 00:19:18 +01:00
|
|
|
/* the name of the (leaf) dir which has the xapian database */
|
2010-01-23 19:50:06 +01:00
|
|
|
#define MU_XAPIAN_DIR_NAME "xapian"
|
|
|
|
#define MU_XAPIAN_VERSION_KEY "db_version"
|
2010-01-05 07:32:23 +01:00
|
|
|
|
2010-01-06 00:19:18 +01:00
|
|
|
/**
|
|
|
|
* log something in the log file; note, we use G_LOG_LEVEL_INFO
|
|
|
|
* for such messages
|
|
|
|
*/
|
|
|
|
#ifdef G_HAVE_GNUC_VARARGS
|
|
|
|
#define MU_WRITE_LOG(format...) \
|
|
|
|
G_STMT_START { \
|
|
|
|
g_log (G_LOG_DOMAIN, \
|
|
|
|
G_LOG_LEVEL_INFO, \
|
|
|
|
format); \
|
|
|
|
} G_STMT_END
|
|
|
|
#else
|
|
|
|
#define MU_WRITE_LOG(x)
|
|
|
|
#endif /*G_HAVE_GNUC_VARARGS*/
|
2010-01-05 07:32:23 +01:00
|
|
|
|
2009-11-25 21:55:06 +01:00
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
#endif /*__MU_UTIL_H__*/
|