SET(MAILPATH CACHE STRING "Where new mail is spooled")
OPTION(WITH_GPGME "Use GPGME [default: on]" ON)
OPTION(WITH_IDN "Use GNU libidn for domain names [default: off]")
-
-OPTION(USE_FLOCK "Use flock to lock files [default: off]")
-OPTION(USE_FCNTL "Use fcntl to lock files [default: on]" ON)
OPTION(USE_HCACHE "Enable headers caching [default: off]")
FIND_FILE(SENDMAIL sendmail
LIST(APPEND MUTTLIBS -llockfile)
IF(USE_HCACHE)
- OPTION(WITH_QDBM "Use qdbm for header caching [default: on]" ON)
+ OPTION(WITH_TC "Use tokyocabinet for header caching [default: on]" ON)
OPTION(WITH_GDBM "Use gdbm for header caching [default: off]")
SET(USE_HCACHE)
- IF(WITH_QDBM)
- pkg_search_module(QDBM REQUIRED qdbm)
- ADD_DEFINITIONS(${QDBM_CFLAGS})
- SET(QDBM_LDFLAGS "${QDBM_LDFLAGS}")
- # LIST(APPEND MUTTLIBS ${QDBM_LDFLAGS})
- LIST(APPEND MUTTLIBS -lqdbm)
+ if(WITH_TC)
+ pkg_search_module(TC REQUIRED tokyocabinet)
+ ADD_DEFINITIONS(${TC_CFLAGS})
+ LIST(APPEND MUTTLIBS ${TC_LDFLAGS})
SET(USE_HCACHE 1)
- SET(HAVE_QDBM 1)
- ENDIF(WITH_QDBM)
+ SET(HAVE_TOKYOCABINET 1)
+ ENDIF(WITH_TC)
IF(NOT USE_HCACHE AND WITH_GDBM)
CHECK_LIBRARY_EXISTS(gdbm gdbm_open "" GDBM)
SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -Wno-unused-parameter")
# warn about variable use before initialization
SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -Wuninitialized")
+# let's read GPGME's Reference Manual
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FILE_OFFSET_BITS=64")
# }}}
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
#cmakedefine HAVE_GDBM 1
#cmakedefine HAVE_GPGME 1
#cmakedefine HAVE_LIBIDN 1
-#cmakedefine HAVE_QDBM 1
+#cmakedefine HAVE_TOKYOCABINET 1
#cmakedefine USE_FCNTL 1
#cmakedefine USE_FLOCK 1
#cmakedefine USE_HCACHE 1
static char *data_object_to_tempfile(gpgme_data_t data, FILE **ret_fp)
{
int err;
- char tempfile[_POSIX_PATH_MAX];
+ char tempfile[_POSIX_PATH_MAX], buf[BUFSIZ];
FILE *fp;
ssize_t nread = 0;
err = ((gpgme_data_seek (data, 0, SEEK_SET) == -1)
? gpgme_error_from_errno (errno) : 0);
- if (!err) {
- char buf[4096];
+ if (err) {
+ mutt_perror(_("Can't create temporary file"));
+ goto error;
+ }
- while ((nread = gpgme_data_read(data, buf, sizeof(buf)))) {
- if (fwrite (buf, nread, 1, fp) != 1) {
- mutt_perror (_("Can't create temporary file"));
- m_fclose(&fp);
- unlink (tempfile);
- return NULL;
- }
+ while ((nread = gpgme_data_read(data, buf, sizeof(buf)))) {
+ if (fwrite (buf, nread, 1, fp) != 1) {
+ mutt_perror (_("Can't create temporary file"));
+ goto error;
}
}
if (nread == -1) {
mutt_error (_("error reading data object: %s\n"), gpgme_strerror (err));
- unlink (tempfile);
- m_fclose(&fp);
- return NULL;
+ goto error;
}
if (ret_fp) {
rewind(fp);
m_fclose(&fp);
}
return m_strdup(tempfile);
+
+ error:
+ m_fclose(&fp);
+ unlink (tempfile);
+ return NULL;
}
}
-#if defined(HAVE_QDBM)
-# define HCACHE_BACKEND "qdbm"
-#elif defined(HAVE_GDBM)
+#if defined(HAVE_TOKYOCABINET)
+# define HCACHE_BACKEND "tokyocabinet"
+#elif defined(HAVE_QDBM)
# define HCACHE_BACKEND "gdbm"
#elif defined(HAVE_DB4)
# define HCACHE_BACKEND "db4"
{
int r;
- if ((r = mx_lock_file (ctx->realpath, fileno (fp), excl, 1, retry)) == 0)
+ if ((r = mx_lock_file (ctx->realpath, fileno (fp), excl, retry)) == 0)
ctx->locked = 1;
else if (retry && !excl) {
ctx->readonly = 1;
{
if (ctx->locked) {
fflush (fp);
-
- mx_unlock_file (ctx->realpath, fileno (fp), 1);
+ mx_unlock_file(ctx->realpath, fileno(fp));
ctx->locked = 0;
}
}
#ifdef USE_HCACHE
-#if defined(HAVE_QDBM)
-#include <depot.h>
-#include <cabin.h>
-#include <villa.h>
+#if defined(HAVE_TOKYOCABINET)
+#include <tcutil.h>
+#include <tchdb.h>
#elif defined(HAVE_GDBM)
#include <gdbm.h>
#else
-#error neither HAVE_QDBM nor HAVE_GDBM are set ?!
+#error no supported DB library found ?
#endif
#include "charset.h"
#include "hcache.h"
struct hcache_t {
-#if defined(HAVE_QDBM)
- VILLA *db;
+#if defined(HAVE_TOKYOCABINET)
+ TCHDB *db;
#elif defined(HAVE_GDBM)
GDBM_FILE db;
#endif
path = mutt_hcache_per_folder(mod_core.cachedir, folder);
{
-#if defined(HAVE_QDBM)
- h->db = vlopen(path, VL_OWRITER | VL_OCREAT, VL_CMPLEX);
+#if defined(HAVE_TOKYOCABINET)
+ h->db = tchdbnew();
+ if (!tchdbopen(h->db, path, HDBOWRITER | HDBOCREAT)) {
+ tchdbdel(h->db);
+ h->db = NULL;
+ }
#elif defined(HAVE_GDBM)
h->db = gdbm_open((char *) path, 16384, GDBM_WRCREAT, 00600, NULL);
#endif
if (!*db)
return;
-#if defined(HAVE_QDBM)
- vlclose((*db)->db);
+#if defined(HAVE_TOKYOCABINET)
+ tchdbdel((*db)->db);
+ (*db)->db = NULL;
#elif defined(HAVE_GDBM)
gdbm_close((*db)->db);
#endif
snprintf(path, sizeof(path), "%s%s", db->folder, filename);
{
-#if defined(HAVE_QDBM)
- int ksize = strlen(db->folder) + keylen(path + strlen(db->folder));
- data = vlget(db->db, path, ksize, NULL);
+ int ksize = keylen(path);
+#if defined(HAVE_TOKYOCABINET)
+ int unused;
+ data = tchdbget(db->db, path, ksize, &unused);
#elif defined(HAVE_GDBM)
- datum k = { .dptr = path, .dsize = keylen(path) };
+ datum k = { .dptr = path, .dsize = ksize };
data = gdbm_fetch(db->db, k).dtpr;
#endif
data = mutt_hcache_dump(db, header, uid_validity);
{
-#if defined(HAVE_QDBM)
- int ksize = strlen(db->folder) + keylen(path + strlen(db->folder));
-
- ret = vlput(db->db, path, ksize, data->data, data->len, VL_DOVER);
+ int ksize = keylen(path);
+#if defined(HAVE_TOKYOCABINET)
+ ret = !!tchdbput(db->db, path, ksize, data->data, data->len) - 1;
#elif defined(HAVE_GDBM)
- datum k = { .dptr = path, .dsize = keylen(path) };
+ datum k = { .dptr = path, .dsize = ksize };
datum v = { .dptr = data->data, .dsize = data->len };
ret = gdbm_store(db->db, k, v, GDBM_REPLACE);
return ret;
}
-int mutt_hcache_delete(hcache_t *db, const char *filename,
+void mutt_hcache_delete(hcache_t *db, const char *filename,
ssize_t (*keylen)(const char *fn))
{
char path[_POSIX_PATH_MAX];
snprintf(path, sizeof(path), "%s%s", db->folder, filename);
{
-#if defined(HAVE_QDBM)
- int ksize = strlen(db->folder) + keylen(path + strlen(db->folder));
- return vlout(db->db, path, ksize);
+ int ksize = keylen(path);
+#if defined(HAVE_TOKYOCABINET)
+ tchdbout(db->db, path, ksize);
#elif defined(HAVE_GDBM)
- datum k = { .dptr = path, .dsize = keylen(path) };
- return gdbm_delete(db->db, k);
+ datum k = { .dptr = path, .dsize = ksize };
+ gdbm_delete(db->db, k);
#endif
}
}
int mutt_hcache_store(hcache_t *db, const char *filename, HEADER *h,
long uid_validity,
ssize_t (*keylen)(const char *fn));
-int mutt_hcache_delete(hcache_t *db, const char *filename,
- ssize_t (*keylen)(const char *fn));
+void mutt_hcache_delete(hcache_t *db, const char *filename,
+ ssize_t (*keylen)(const char *fn));
#endif /* USE_HCACHE */
#endif /* !_MUTT_HCACHE_H */
{
int r;
- if ((r = mx_lock_file(ctx->path, fileno(ctx->fp), excl, 1, retry)) == 0)
+ if ((r = mx_lock_file(ctx->path, fileno(ctx->fp), excl, retry)) == 0)
ctx->locked = 1;
else if (retry && !excl) {
ctx->readonly = 1;
if (ctx->locked) {
fflush (ctx->fp);
- mx_unlock_file (ctx->path, fileno (ctx->fp), 1);
+ mx_unlock_file(ctx->path, fileno(ctx->fp));
ctx->locked = 0;
}
}
/* close a mailbox opened in write-mode */
int mbox_close_mailbox (CONTEXT * ctx)
{
- mx_unlock_file (ctx->path, fileno (ctx->fp), 1);
+ mx_unlock_file(ctx->path, fileno(ctx->fp));
if (ctx->cinfo)
mutt_slow_close_compressed (ctx);
#include <imap/imap.h>
#include "pop.h"
+#define MAXLOCKATTEMPT 5
+
+
static mx_t const *mxfmts[] = {
&mbox_mx,
&mh_mx,
/* Args:
* excl if excl != 0, request an exclusive lock
- * dot if dot != 0, try to dotlock the file
* time_out should retry locking?
*/
-int mx_lock_file (const char *path, int fd, int excl, int dot, int time_out)
+int mx_lock_file(const char *path, int fd, int excl, int time_out)
{
-#if defined (USE_FCNTL) || defined (USE_FLOCK)
- int count;
- int attempt;
- struct stat prev_sb;
-#endif
- int r = 0;
-
-#ifdef USE_FCNTL
- struct flock lck;
-
- p_clear(&lck, 1);
- lck.l_type = excl ? F_WRLCK : F_RDLCK;
- lck.l_whence = SEEK_SET;
-
- count = 0;
- attempt = 0;
- prev_sb.st_size = 0;
- while (fcntl (fd, F_SETLK, &lck) == -1) {
- struct stat sb;
+ int count = 0, attempt = 0;
+ struct flock lck = {
+ .l_type = excl ? F_WRLCK : F_RDLCK,
+ .l_whence = SEEK_SET,
+ };
+
+ if (dotlock_file(path, time_out) < 0)
+ return -1;
+ while (fcntl(fd, F_SETLK, &lck) == -1) {
if (errno != EAGAIN && errno != EACCES) {
- mutt_perror ("fcntl");
- return (-1);
+ mutt_perror("fcntl");
+ goto error;
}
- if (fstat (fd, &sb) != 0)
- sb.st_size = 0;
-
- if (count == 0)
- prev_sb = sb;
-
- /* only unlock file if it is unchanged */
- if (prev_sb.st_size == sb.st_size
- && ++count >= (time_out ? MAXLOCKATTEMPT : 0)) {
+ if (++count >= (time_out ? MAXLOCKATTEMPT : 0)) {
if (time_out)
mutt_error _("Timeout exceeded while attempting fcntl lock!");
-
- return (-1);
- }
-
- prev_sb = sb;
-
- mutt_message (_("Waiting for fcntl lock... %d"), ++attempt);
- mutt_sleep (1);
- }
-#endif /* USE_FCNTL */
-
-#ifdef USE_FLOCK
- count = 0;
- attempt = 0;
- while (flock (fd, (excl ? LOCK_EX : LOCK_SH) | LOCK_NB) == -1) {
- struct stat sb;
-
- if (errno != EWOULDBLOCK) {
- mutt_perror ("flock");
- r = -1;
- break;
- }
-
- if (fstat (fd, &sb) != 0)
- sb.st_size = 0;
-
- if (count == 0)
- prev_sb = sb;
-
- /* only unlock file if it is unchanged */
- if (prev_sb.st_size == sb.st_size
- && ++count >= (time_out ? MAXLOCKATTEMPT : 0)) {
- if (time_out)
- mutt_error _("Timeout exceeded while attempting flock lock!");
-
- r = -1;
- break;
+ goto error;
}
-
- prev_sb = sb;
-
- mutt_message (_("Waiting for flock attempt... %d"), ++attempt);
- mutt_sleep (1);
- }
-#endif /* USE_FLOCK */
-
- if (r == 0 && dot)
- r = dotlock_file(path, time_out);
-
- if (r == -1) {
- /* release any other locks obtained in this routine */
-
-#ifdef USE_FCNTL
- lck.l_type = F_UNLCK;
- fcntl (fd, F_SETLK, &lck);
-#endif /* USE_FCNTL */
-
-#ifdef USE_FLOCK
- flock (fd, LOCK_UN);
-#endif /* USE_FLOCK */
-
- return (-1);
+ mutt_message(_("Waiting for fcntl lock... %d"), ++attempt);
+ mutt_sleep(1);
}
-
return 0;
+
+ error:
+ undotlock_file(path);
+ return -1;
}
-int mx_unlock_file (const char *path, int fd, int dot)
+int mx_unlock_file(const char *path, int fd)
{
-#ifdef USE_FCNTL
struct flock unlockit;
p_clear(&unlockit, 1);
unlockit.l_type = F_UNLCK;
unlockit.l_whence = SEEK_SET;
- fcntl (fd, F_SETLK, &unlockit);
-#endif
-
-#ifdef USE_FLOCK
- flock (fd, LOCK_UN);
-#endif
-
- if (dot)
- undotlock_file (path);
-
+ fcntl(fd, F_SETLK, &unlockit);
+ undotlock_file(path);
return 0;
}
case M_MBOX:
if ((ctx->fp =
safe_fopen (ctx->path, flags & M_NEWFOLDER ? "w" : "a")) == NULL
- || mbox_lock_mailbox (ctx, 1, 1) != 0) {
+ || mbox_lock_mailbox(ctx, 1, 1) != 0) {
if (!ctx->fp)
mutt_perror (ctx->path);
else {
void mx_update_context (CONTEXT *, int);
void mx_update_tables (CONTEXT *, int);
-int mx_lock_file (const char *, int, int, int, int);
-int mx_unlock_file (const char *path, int fd, int dot);
+int mx_lock_file(const char *, int, int, int);
+int mx_unlock_file(const char *path, int fd);
void mutt_parse_mime_message (CONTEXT * ctx, HEADER *);
#endif /* !_MX_H */
#endif
#ifdef USE_HCACHE
-#if defined(HAVE_QDBM)
-#include <depot.h>
+#if defined(HAVE_TOKYOCABINET)
+#include <tcutil.h>
#elif defined(HAVE_GDBM)
#include <gdbm.h>
#endif
printf(" libidn %s\n", STRINGPREP_VERSION);
#endif
#ifdef USE_HCACHE
-#if defined(HAVE_QDBM)
- printf(" qdbm %s\n", dpversion);
+#if defined(HAVE_TOKYOCABINET)
+ printf(" tokyocabinet %s\n", tcversion);
#elif defined(HAVE_GDBM)
printf(" gdbm %s\n", gdbm_version);
#endif
puts (_("Compile Options:"));
puts (
-#ifdef USE_FCNTL
- " +USE_FCNTL"
-#else
- " -USE_FCNTL"
-#endif
-#ifdef USE_FLOCK
- " +USE_FLOCK"
-#else
- " -USE_FLOCK"
-#endif
#ifdef USE_HCACHE
" +USE_HCACHE"
#else