Skip to content

Commit

Permalink
Lots of moving things around to make sort
Browse files Browse the repository at this point in the history
fit with the loadable module framework.


git-svn-id: https://svn.ic-s.nl/svn/dbmail/trunk/dbmail@1929 7b491191-dbf0-0310-aff6-d879d4d69008
  • Loading branch information
aaron committed Nov 29, 2005
1 parent 6014be2 commit 0092ca5
Show file tree
Hide file tree
Showing 18 changed files with 375 additions and 105 deletions.
10 changes: 5 additions & 5 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

SUBDIRS = modules sort man lib
SUBDIRS = modules man lib

if SIEVE
SIEVEPROGS = dbmail-sievecmd dbmail-timsieved
Expand All @@ -42,6 +42,7 @@ COMMON = dbmail-user.c \
db.c \
dbmodule.c \
authmodule.c \
sortmodule.c \
misc.c \
mime.c \
pidfile.c
Expand All @@ -53,14 +54,15 @@ SERVER = server.c \

DELIVER = pipe.c \
forward.c \
dsn.c
dsn.c \
sort.c

# CFLAGS
#AM_CFLAGS = -fomit-frame-pointer

INCLUDES = -I$(top_srcdir)

LDFLAGS = -Wl,--export-dynamic
AM_LDFLAGS = -Wl,--export-dynamic

dbmail_smtp_SOURCES = main.c
dbmail_smtp_LDADD = libdbmail.la
Expand Down Expand Up @@ -89,8 +91,6 @@ dbmail_sievecmd_LDADD = libdbmail.la

dbmail_timsieved_SOURCES = timsieve.c timsieved.c
dbmail_timsieved_LDADD = libdbmail.la

AM_CFLAGS += -DSIEVE
endif

noinst_LTLIBRARIES = libdbmail.la
Expand Down
13 changes: 7 additions & 6 deletions acinclude.m4
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,23 @@ AC_MSG_RESULT([checking for sorting configuration])
AC_ARG_WITH(sieve,[ --with-sieve=PATH full path to libSieve header directory (don't use, not stable)],
sieveheadername="$withval$")
dnl This always needs to be defined
SORTALIB="sort/.libs/libsortdbmail.a"
SORTLTLIB="sort/libsortdbmail.la"
SORTALIB="modules/.libs/libsortsieve.a"
SORTLTLIB="modules/libsortsieve.la"
WARN=0
if test ! "${sieveheadername-x}" = "x"
then
# --with-sieve was specified
AC_MSG_RESULT([using Sieve sorting])
CFLAGS="$CFLAGS -DSIEVE"
if test "$withval" != "yes"
then
AC_MSG_CHECKING([for sieve2.h (user supplied)])
if test -r "$sieveheadername/sieve2.h"
then
# found
AC_MSG_RESULT([$sieveheadername/sieve2.h])
SIEVEINC=$sieveheadername
SIEVEINC="-I$sieveheadername"
else
# Not found
AC_MSG_RESULT([not found])
Expand All @@ -166,7 +167,7 @@ then
do
if test -r "$sievepaths/sieve2.h"
then
SIEVEINC="$sievepaths"
SIEVEINC="-I$sievepaths"
AC_MSG_RESULT([$sievepaths/sieve2.h])
break
fi
Expand Down Expand Up @@ -226,7 +227,7 @@ then
then
# found
AC_MSG_RESULT([$authldapheadername/ldap.h])
LDAPINC=$authldapheadername
LDAPINC="-I$authldapheadername"
else
# Not found
AC_MSG_RESULT([not found])
Expand All @@ -241,7 +242,7 @@ then
do
if test -r "$ldappath/ldap.h"
then
LDAPINC="$ldappath"
LDAPINC="-I$ldappath"
AC_MSG_RESULT([$ldappath/ldap.h])
break
fi
Expand Down
26 changes: 20 additions & 6 deletions authmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ int auth_load_driver(void)
char *lib = NULL;
char *driver = NULL;

if (!g_module_supported())
if (!g_module_supported()) {
trace(TRACE_FATAL, "sort_init: loadable modules unsupported on this platform");
return 1;
}

auth = (auth_func_t *)dm_malloc(sizeof(auth_func_t));
if (!auth) {
Expand All @@ -51,10 +53,22 @@ int auth_load_driver(void)
" please choose from SQL or LDAP",
_db_params.authdriver);

if (! (lib = g_module_build_path("modules/.libs", driver)))
lib = g_module_build_path("/usr/lib/dbmail", driver);

module = g_module_open(lib, 0); // non-lazy bind.
/* Try local build area, then dbmail lib paths, then system lib path. */
int i;
char *lib_path[] = {
"modules/.libs",
"/usr/lib/dbmail",
"/usr/local/lib/dbmail",
NULL };
for (i = 0; i < 4; i++) {
lib = g_module_build_path(lib_path[i], driver);
module = g_module_open(lib, 0); // non-lazy bind.
if (module)
break;
printf( "not found in %s\n", lib_path[i] );
}

/* If the list is exhausted without opening a module, we'll catch it. */
if (!module) {
trace(TRACE_FATAL, "auth_init: cannot load %s: %s", lib, g_module_error());
return -1;
Expand Down Expand Up @@ -84,7 +98,7 @@ int auth_load_driver(void)
|| !g_module_symbol(module, "auth_addalias_ext", &auth->addalias_ext )
|| !g_module_symbol(module, "auth_removealias", &auth->removealias )
|| !g_module_symbol(module, "auth_removealias_ext", &auth->removealias_ext )) {
trace(TRACE_FATAL, "auth_init: error loading %s: %s", lib, g_module_error());
trace(TRACE_FATAL, "auth_init: cannot find function: %s: %s", lib, g_module_error());
return -2;
}

Expand Down
10 changes: 5 additions & 5 deletions authmodule.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* Dynamic loading of the database backend.
/* Dynamic loading of the authentication backend.
* We use GLib's multiplatform dl() wrapper
* to open up libdbmysql or libdbpgsql and
* populate the global 'db' structure.
* to open up auth_sql.so or auth_ldap.so and
* populate the global 'auth' structure.
*
* (c) 2005 Aaron Stone <aaron@serendipity.cx>
*/

#ifndef DBMODULE_H
#define DBMODULE_H
#ifndef AUTHMODULE_H
#define AUTHMODULE_H

/* Prototypes must match with those in auth.h
* and in the authentication drivers. */
Expand Down
3 changes: 3 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ void GetDBParams(db_param_t * db_params)
if (config_get_value("authdriver", "DBMAIL", db_params->authdriver) < 0)
trace(TRACE_FATAL, "%s,%s: error getting config!",
__FILE__, __func__);
if (config_get_value("sortdriver", "DBMAIL", db_params->sortdriver) < 0)
trace(TRACE_FATAL, "%s,%s: error getting config!",
__FILE__, __func__);
if (config_get_value("host", "DBMAIL", db_params->host) < 0)
trace(TRACE_FATAL, "%s,%s: error getting config!",
__FILE__, __func__);
Expand Down
4 changes: 2 additions & 2 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ AC_SUBST(LDAPINC)
# libtool patch
AC_PROG_LIBTOOL

AC_OUTPUT(Makefile modules/Makefile sort/Makefile man/Makefile
lib/Makefile lib/iniparser-2.14/Makefile lib/iniparser-2.14/src/Makefile)
AC_OUTPUT(Makefile modules/Makefile man/Makefile lib/Makefile
lib/iniparser-2.14/Makefile lib/iniparser-2.14/src/Makefile)

51 changes: 0 additions & 51 deletions dbmail-message.c
Original file line number Diff line number Diff line change
Expand Up @@ -1006,57 +1006,6 @@ void dbmail_message_cache_referencesfield(const struct DbmailMessage *self)
}


/* Run the user's sorting rules on this message
* Retrieve the action list as either
* a linked list of things to do, or a
* single thing to do. Not sure yet...
*
* Then do it!
* */
dsn_class_t sort_and_deliver(struct DbmailMessage *message, u64_t useridnr,
const char *mailbox, mailbox_source_t source)
{
u64_t mboxidnr, newmsgidnr;

size_t msgsize = (u64_t)dbmail_message_get_size(message, FALSE);
u64_t msgidnr = message->id;

/* This is the only condition when called from pipe.c, actually. */
if (! mailbox) {
mailbox = "INBOX";
source = BOX_DEFAULT;
}

/* FIXME: This is where we call the sorting engine into action. */

if (db_find_create_mailbox(mailbox, source, useridnr, &mboxidnr) != 0) {
trace(TRACE_ERROR, "%s,%s: mailbox [%s] not found",
__FILE__, __func__,
mailbox);
return DSN_CLASS_FAIL;
} else {
switch (db_copymsg(msgidnr, mboxidnr, useridnr, &newmsgidnr)) {
case -2:
trace(TRACE_DEBUG, "%s, %s: error copying message to user [%llu],"
"maxmail exceeded",
__FILE__, __func__,
useridnr);
return DSN_CLASS_QUOTA;
case -1:
trace(TRACE_ERROR, "%s, %s: error copying message to user [%llu]",
__FILE__, __func__,
useridnr);
return DSN_CLASS_TEMP;
default:
trace(TRACE_MESSAGE, "%s, %s: message id=%llu, size=%d is inserted",
__FILE__, __func__,
newmsgidnr, msgsize);
message->id = newmsgidnr;
return DSN_CLASS_OK;
}
}
}

/* old stuff moved here from dbmsgbuf.c */

struct DbmailMessage * db_init_fetch(u64_t msg_idnr, int filter)
Expand Down
2 changes: 0 additions & 2 deletions dbmail-message.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ struct DbmailMessage * dbmail_message_init_with_string(struct DbmailMessage *sel
int dbmail_message_store(struct DbmailMessage *message);
int dbmail_message_headers_cache(const struct DbmailMessage *message);

dsn_class_t sort_and_deliver(struct DbmailMessage *self, u64_t useridnr, const char *mailbox, mailbox_source_t source);

struct DbmailMessage * dbmail_message_retrieve(struct DbmailMessage *self, u64_t physid, int filter);

/*
Expand Down
6 changes: 4 additions & 2 deletions dbmail.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#include "pipe.h"
#include "db.h"
#include "auth.h"
#include "sort.h"
#include "imap4.h"
#include "imapcommands.h"
#include "memblock.h"
Expand All @@ -107,10 +108,11 @@
#ifdef SIEVE
#include <sieve2.h>
#include <sieve2_error.h>
#endif

#include "modules/sortsieve.h"
#include "sievecmd.h"
#include "sort/sortsieve.h"
#include "timsieve.h"
#endif

#ifdef HAVE_CRYPT_H
#include <crypt.h>
Expand Down
1 change: 1 addition & 0 deletions dbmailtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ typedef char timestring_t[TIMESTRING_SIZE];
typedef struct {
field_t driver; /**< database driver: mysql, pgsql, sqlite */
field_t authdriver; /**< authentication driver: sql, ldap */
field_t sortdriver; /**< sort driver: sieve or nothing at all */
field_t host; /**< hostname or ip address of database server */
field_t user; /**< username to connect with */
field_t pass; /**< password of user */
Expand Down
26 changes: 21 additions & 5 deletions dbmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* populate the global 'db' structure.
*
* (c) 2005 Aaron Stone <aaron@serendipity.cx>
*
* $Id: $
*/

#include <gmodule.h>
Expand All @@ -30,8 +32,10 @@ int db_load_driver(void)
char *lib = NULL;
char *driver = NULL;

if (!g_module_supported())
if (!g_module_supported()) {
trace(TRACE_FATAL, "db_init: loadable modules unsupported on this platform");
return 1;
}

db = (db_func_t *)dm_malloc(sizeof(db_func_t));
if (!db) {
Expand All @@ -53,10 +57,22 @@ int db_load_driver(void)
" please choose from MySQL, PGSQL, SQLite",
_db_params.driver);

if (! (lib = g_module_build_path("modules/.libs", driver)))
lib = g_module_build_path("/usr/lib/dbmail", driver);
/* Try local build area, then dbmail lib paths, then system lib path. */
int i;
char *lib_path[] = {
"modules/.libs",
"/usr/lib/dbmail",
"/usr/local/lib/dbmail",
NULL };
for (i = 0; i < 4; i++) {
lib = g_module_build_path(lib_path[i], driver);
module = g_module_open(lib, 0); // non-lazy bind.
if (module)
break;
printf( "not found in %s\n", lib_path[i] );
}

module = g_module_open(lib, 0); // non-lazy bind.
/* If the list is exhausted without opening a module, we'll catch it. */
if (!module) {
trace(TRACE_FATAL, "db_init: cannot load %s: %s", lib, g_module_error());
return -1;
Expand All @@ -79,7 +95,7 @@ int db_load_driver(void)
|| !g_module_symbol(module, "db_use_msgbuf_result", &db->use_msgbuf_result )
|| !g_module_symbol(module, "db_store_msgbuf_result", &db->store_msgbuf_result )
|| !g_module_symbol(module, "db_set_result_set", &db->set_result_set )) {
trace(TRACE_FATAL, "db_init: error loading %s: %s", lib, g_module_error());
trace(TRACE_FATAL, "db_init: cannot find function: %s: %s", lib, g_module_error());
return -2;
}

Expand Down
4 changes: 2 additions & 2 deletions dbmodule.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Dynamic loading of the database backend.
* We use GLib's multiplatform dl() wrapper
* to open up libdbmysql or libdbpgsql and
* populate the global 'db' structure.
* to open up db_mysql.so, db_pgsql.so or db_sqlite.so
* and populate the global 'db' structure.
*
* (c) 2005 Aaron Stone <aaron@serendipity.cx>
*/
Expand Down
13 changes: 10 additions & 3 deletions modules/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

INCLUDES = -I$(top_srcdir)
AM_CFLAGS = @MYSQLINC@ @PGSQLINC@ @SQLITEINC@ -fomit-frame-pointer
AM_CFLAGS = @MYSQLINC@ @PGSQLINC@ @SQLITEINC@ @LDAPINC@ @SIEVEINC@ -fomit-frame-pointer

LDFLAGS = -Wl,--export-dynamic
AM_LDFLAGS = -Wl,--export-dynamic

pkglib_LTLIBRARIES = libdbmysql.la \
libdbpgsql.la \
libdbsqlite.la \
libauthsql.la \
libauthldap.la
libauthldap.la \
libsortsieve.la

if MYSQL
libdbmysql_la_SOURCES = dbmysql.c
Expand All @@ -43,10 +44,16 @@ if LDAP
libauthldap_la_SOURCES = authldap.c
endif

# This one is always built.
libauthsql_la_SOURCES = authsql.c

if SIEVE
libsortsieve_la_SOURCES = sortsieve.c
endif

libdbmysql_la_LIBADD = @MYSQLLIB@
libdbpgsql_la_LIBADD = @PGSQLLIB@
libdbsqlite_la_LIBADD = @SQLITELIB@
libauthsql_la_LIBADD = -lcrypt @MYSQLLIB@ @PGSQLLIB@ @SQLITELIB@
libauthldap_la_LIBADD = -lcrypt @LDAPLIB@ @MYSQLLIB@ @PGSQLLIB@ @SQLITELIB@
libsortsieve_la_LIBADD = @SORTLIB@
Loading

0 comments on commit 0092ca5

Please sign in to comment.