Commit a1b914b0 a1b914b0c326dd4d5bb4d4fde83ca694e820bc40 by Wojciech Polak

Add Tokyo Cabinet DBM support.

* configure.ac: Add new option --with-tokyocabinet.
* lib/mu_dbm.c: Add Tokyo Cabinet support.
* lib/mu_dbm.h: Likewise.
* pop3d/popauth.c: Likewise.
1 parent 6c358357
......@@ -274,9 +274,13 @@ use DBM-based mail box quotas with maildag.
Use NDBM
--with-tokyocabinet
Use Tokyo Cabinet DBM
Only one dbm option may be specified. Which one depends on
the flavor of DBM you are using. GDBM is most common for GNU
system.
system.
Use following options to disable support for particular protocols or
features:
......@@ -312,7 +316,7 @@ by visiting http://mail.gnu.org/mailman/listinfo/bug-mailutils.
* Copyright information:
Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009 Free Software Foundation, Inc.
Permission is granted to anyone to make or distribute verbatim
copies of this document as received, in any medium, provided that
......
......@@ -378,6 +378,16 @@ case "${withval}" in
*) AC_MSG_ERROR(bad value ${withval} for --with-ndbm) ;;
esac])
AC_ARG_WITH([tokyocabinet],
AC_HELP_STRING([--with-tokyocabinet],
[use Tokyo Cabinet]),
[
case "${withval}" in
yes) use_dbm=TC ;;
no) use_dbm=no ;;
*) AC_MSG_ERROR(bad value ${withval} for --with-tokyocabinet) ;;
esac])
AC_MSG_CHECKING(for log facility)
log_facility="LOG_MAIL"
AC_ARG_WITH([log-facility],
......@@ -1043,6 +1053,14 @@ NDBM)
[Enable use of NDBM]))
LIBS="$LIBS -lndbm"
status_dbm="NDBM"]);;
TC)
AC_CHECK_LIB(tokyocabinet, tchdbnew,
[AC_CHECK_HEADERS(tchdb.h,
AC_DEFINE(WITH_TOKYOCABINET,1,
[Enable use of Tokyo Cabinet]))
LIBS="$LIBS -ltokyocabinet -lz -lbz2 -lrt"
status_dbm="Tokyo Cabinet"]);;
esac
AC_SUBST(POPAUTH)
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2006,
2007 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 2001, 2002, 2006, 2007, 2009
Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -141,7 +141,7 @@ mu_dbm_open (char *name, DBM_FILE *db, int flags, int mode)
errno = EINVAL;
return 1;
}
*db = gdbm_open(pfname, 512, f, mode, NULL);
*db = gdbm_open (pfname, 512, f, mode, NULL);
free (pfname);
return *db == NULL;
}
......@@ -156,7 +156,7 @@ mu_dbm_close (DBM_FILE db)
int
mu_dbm_fetch (DBM_FILE db, DBM_DATUM key, DBM_DATUM *ret)
{
*ret = gdbm_fetch(db, key);
*ret = gdbm_fetch (db, key);
return ret->dptr == NULL;
}
......@@ -169,8 +169,8 @@ mu_dbm_delete (DBM_FILE db, DBM_DATUM key)
int
mu_dbm_insert (DBM_FILE db, DBM_DATUM key, DBM_DATUM contents, int replace)
{
return gdbm_store(db, key, contents,
replace ? GDBM_REPLACE : GDBM_INSERT);
return gdbm_store (db, key, contents,
replace ? GDBM_REPLACE : GDBM_INSERT);
}
DBM_DATUM
......@@ -304,16 +304,16 @@ mu_dbm_firstkey (DBM_FILE db)
DBT key, data;
int ret;
memset(&key, 0, sizeof key);
memset(&data, 0, sizeof data);
memset (&key, 0, sizeof key);
memset (&data, 0, sizeof data);
if (!db->dbc)
{
if (db->db->cursor(db->db, NULL, &db->dbc BDB2_CURSOR_LASTARG) != 0)
if (db->db->cursor (db->db, NULL, &db->dbc BDB2_CURSOR_LASTARG) != 0)
return key;
}
if ((ret = db->dbc->c_get(db->dbc, &key, &data, DB_FIRST)) != 0)
if ((ret = db->dbc->c_get (db->dbc, &key, &data, DB_FIRST)) != 0)
{
key.data = NULL;
key.size = 0;
......@@ -331,13 +331,13 @@ mu_dbm_nextkey (DBM_FILE db, DBM_DATUM pkey /*unused*/)
DBT key, data;
int ret;
memset(&key, 0, sizeof key);
memset(&data, 0, sizeof data);
memset (&key, 0, sizeof key);
memset (&data, 0, sizeof data);
if (!db->dbc)
return key;
if ((ret = db->dbc->c_get(db->dbc, &key, &data, DB_NEXT)) != 0)
if ((ret = db->dbc->c_get (db->dbc, &key, &data, DB_NEXT)) != 0)
{
key.data = NULL;
key.size = 0;
......@@ -452,5 +452,125 @@ mu_dbm_datum_free (DBM_DATUM *datum)
{
/* empty */
}
#elif defined(WITH_TOKYOCABINET)
#define DB_SUFFIX ".tch"
int
mu_dbm_stat (char *name, struct stat *sb)
{
int rc;
char *pfname = make_db_name (name, DB_SUFFIX);
rc = stat (pfname, sb);
free (pfname);
return rc;
}
int
mu_dbm_open (char *name, DBM_FILE *db, int flags, int mode)
{
int f, ecode;
char *pfname = make_db_name (name, DB_SUFFIX);
if (mu_check_perm (pfname, mode))
{
free (pfname);
return -1;
}
switch (flags)
{
case MU_STREAM_CREAT:
f = HDBOWRITER | HDBOCREAT;
break;
case MU_STREAM_READ:
f = HDBOREADER;
break;
case MU_STREAM_RDWR:
f = HDBOREADER | HDBOWRITER;
break;
default:
free (pfname);
errno = EINVAL;
return 1;
}
*db = malloc (sizeof **db);
if (!*db)
{
errno = ENOMEM;
return -1;
}
(*db)->hdb = tchdbnew ();
if (!tchdbopen ((*db)->hdb, pfname, f))
ecode = tchdbecode ((*db)->hdb);
free (pfname);
return 0;
}
int
mu_dbm_close (DBM_FILE db)
{
tchdbclose (db->hdb);
tchdbdel (db->hdb);
return 0;
}
int
mu_dbm_fetch (DBM_FILE db, DBM_DATUM key, DBM_DATUM *ret)
{
ret->data = tchdbget (db->hdb, key.data, key.size, &ret->size);
return ret->data == NULL;
}
int
mu_dbm_delete (DBM_FILE db, DBM_DATUM key)
{
return !tchdbout (db->hdb, key.data, key.size);
}
int
mu_dbm_insert (DBM_FILE db, DBM_DATUM key, DBM_DATUM contents, int replace)
{
if (replace)
return !tchdbput (db->hdb, key.data, key.size, contents.data, contents.size);
else
return !tchdbputkeep (db->hdb, key.data, key.size,
contents.data, contents.size);
}
DBM_DATUM
mu_dbm_firstkey (DBM_FILE db)
{
DBM_DATUM key;
memset (&key, 0, sizeof key);
tchdbiterinit (db->hdb);
key.data = tchdbiternext (db->hdb, &key.size);
return key;
}
DBM_DATUM
mu_dbm_nextkey (DBM_FILE db, DBM_DATUM unused)
{
DBM_DATUM key;
memset (&key, 0, sizeof key);
key.data = tchdbiternext (db->hdb, &key.size);
return key;
}
void
mu_dbm_datum_free (DBM_DATUM *datum)
{
/* empty */
}
#endif
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2005, 2007 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 2001, 2002, 2005, 2007, 2009
Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -52,6 +53,27 @@ typedef datum DBM_DATUM;
#define MU_DATUM_SIZE(d) (d).dsize
#define MU_DATUM_PTR(d) (d).dptr
#elif defined(WITH_TOKYOCABINET)
#include <tcutil.h>
#include <tchdb.h>
#define USE_DBM
struct tokyocabinet_file
{
TCHDB *hdb;
};
struct tokyocabinet_datum {
void *data;
int size;
};
typedef struct tokyocabinet_file *DBM_FILE;
typedef struct tokyocabinet_datum DBM_DATUM;
#define MU_DATUM_SIZE(d) (d).size
#define MU_DATUM_PTR(d) (d).data
#endif
#ifdef USE_DBM
......@@ -65,7 +87,7 @@ int mu_dbm_delete (DBM_FILE db, DBM_DATUM key);
DBM_DATUM mu_dbm_firstkey (DBM_FILE db);
DBM_DATUM mu_dbm_nextkey (DBM_FILE db, DBM_DATUM key);
void mu_dbm_datum_free(DBM_DATUM *datum);
#endif
#endif /* USE_DBM */
int mu_fcheck_perm (int fd, int mode);
int mu_check_perm (const char *name, int mode);
......
......@@ -592,9 +592,11 @@ popauth_version (FILE *stream, struct argp_state *state)
#elif defined(WITH_BDB)
# define FORMAT "Berkeley DB"
#elif defined(WITH_NDBM)
# define FORMAT "NDBM"
# define FORMAT "NDBM"
#elif defined(WITH_OLD_DBM)
# define FORMAT "Old DBM"
# define FORMAT "Old DBM"
#elif defined(WITH_TOKYOCABINET)
# define FORMAT "Tokyo Cabinet"
#endif
printf ("%s\n", argp_program_version);
printf (_("Database format: %s\n"), FORMAT);
......