[Dovecot] [PATCH] Split sql drivers from lib-sql to plugins

Tomas Janousek tjanouse at redhat.com
Fri Apr 13 16:27:31 EEST 2007


Hi,

a new version of the sql split patch attached, should be smaller, cleaner,
better.

-- 
Tomas Janousek, SW Engineer, Red Hat, Inc.
-------------- next part --------------
--- dovecot-1.0.rc32/src/dict/main.c.split	2007-02-22 15:32:11.000000000 +0100
+++ dovecot-1.0.rc32/src/dict/main.c	2007-04-13 13:56:55.000000000 +0200
@@ -22,6 +22,7 @@
 
 static struct io *log_io;
 static struct module *modules;
+static struct module *sql_modules;
 static struct dict_server *dict_server;
 
 static void sig_die(int signo, void *context __attr_unused__)
@@ -50,6 +51,8 @@
 	/* Load built-in SQL drivers (if any) */
 	sql_drivers_init();
 	sql_drivers_register_all();
+	sql_modules = sql_drivers_modules_load();
+	module_dir_init(sql_modules);
 
 	restrict_access_by_env(FALSE);
 }
@@ -100,6 +103,7 @@
 	dict_sql_unregister();
 	dict_client_unregister();
 
+	module_dir_unload(&sql_modules);
 	sql_drivers_deinit();
 	random_deinit();
 	lib_signals_deinit();
--- dovecot-1.0.rc32/src/lib-sql/Makefile.am.split	2007-02-22 22:09:16.000000000 +0100
+++ dovecot-1.0.rc32/src/lib-sql/Makefile.am	2007-04-13 15:11:18.000000000 +0200
@@ -1,21 +1,66 @@
 noinst_LIBRARIES = libsql.a
 
+if DYNAMIC_SQL
+if BUILD_MYSQL
+MYSQL_LIB=libdriver_mysql.la
+endif
+if BUILD_PGSQL
+PGSQL_LIB=libdriver_pgsql.la
+endif
+if BUILD_SQLITE
+SQLITE_LIB=libdriver_sqlite.la
+endif
+
+sql_module_LTLIBRARIES = \
+	$(MYSQL_LIB) \
+	$(PGSQL_LIB) \
+	$(SQLITE_LIB)
+
+sql_moduledir = $(moduledir)/sql
+endif
+
 sql_drivers = @sql_drivers@
 
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/lib \
+	-DMODULEDIR=\""$(moduledir)"\" \
 	$(SQL_CFLAGS)
 
 dist_sources = \
+	sql-api.c
+
+if ! DYNAMIC_SQL
+driver_sources = \
 	driver-mysql.c \
 	driver-pgsql.c \
-	driver-sqlite.c \
-	sql-api.c
+	driver-sqlite.c
+endif
 
 libsql_a_SOURCES = \
 	$(dist_sources) \
+	$(driver_sources) \
 	sql-drivers-register.c
 
+if DYNAMIC_SQL
+libdriver_mysql_la_LDFLAGS = -module -avoid-version
+libdriver_mysql_la_LIBADD = $(MYSQL_LIBS)
+libdriver_mysql_la_CPPFLAGS = -I$(top_srcdir)/src/lib $(MYSQL_CFLAGS)
+libdriver_mysql_la_SOURCES = \
+	driver-mysql.c
+
+libdriver_pgsql_la_LDFLAGS = -module -avoid-version
+libdriver_pgsql_la_LIBADD = $(PGSQL_LIBS)
+libdriver_pgsql_la_CPPFLAGS = -I$(top_srcdir)/src/lib $(PGSQL_CFLAGS)
+libdriver_pgsql_la_SOURCES = \
+	driver-pgsql.c
+
+libdriver_sqlite_la_LDFLAGS = -module -avoid-version
+libdriver_sqlite_la_LIBADD = $(SQLITE_LIBS)
+libdriver_sqlite_la_CPPFLAGS = -I$(top_srcdir)/src/lib $(SQLITE_CFLAGS)
+libdriver_sqlite_la_SOURCES = \
+	driver-sqlite.c
+endif
+
 headers = \
 	sql-api.h \
 	sql-api-private.h
@@ -32,17 +77,21 @@
 	echo '/* this file automatically generated by Makefile */' >$@
 	echo '#include "lib.h"' >>$@
 	echo '#include "sql-api.h"' >>$@
+if ! DYNAMIC_SQL
 	for i in $(sql_drivers) null; do \
 	  if [ "$${i}" != "null" ]; then \
 	        echo "extern struct sql_db driver_$${i}_db;" >>$@ ; \
 	  fi \
 	done
+endif
 	echo 'void sql_drivers_register_all(void) {' >>$@
+if ! DYNAMIC_SQL
 	for i in $(sql_drivers) null; do \
 	  if [ "$${i}" != "null" ]; then \
 	        echo "sql_driver_register(&driver_$${i}_db);" >>$@ ; \
 	  fi \
 	done
+endif
 	echo '}' >>$@
 
 DISTFILES = $(DIST_COMMON) $(dist_sources) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
--- dovecot-1.0.rc32/src/lib-sql/sql-api.h.split	2006-07-01 19:23:52.000000000 +0200
+++ dovecot-1.0.rc32/src/lib-sql/sql-api.h	2007-04-13 13:56:55.000000000 +0200
@@ -20,6 +20,8 @@
 
 /* register all built-in SQL drivers */
 void sql_drivers_register_all(void);
+struct module;
+struct module *sql_drivers_modules_load(void);
 
 void sql_driver_register(const struct sql_db *driver);
 void sql_driver_unregister(const struct sql_db *driver);
--- dovecot-1.0.rc32/src/lib-sql/sql-api.c.split	2006-07-01 19:23:52.000000000 +0200
+++ dovecot-1.0.rc32/src/lib-sql/sql-api.c	2007-04-13 13:56:55.000000000 +0200
@@ -2,6 +2,7 @@
 
 #include "lib.h"
 #include "array.h"
+#include "module-dir.h"
 #include "sql-api-private.h"
 
 array_t ARRAY_DEFINE(sql_drivers, const struct sql_db *);
@@ -16,6 +17,12 @@
 	array_free(&sql_drivers);
 }
 
+struct module *sql_drivers_modules_load(void)
+{
+	return module_dir_load(MODULEDIR"/sql",
+			NULL, TRUE, PACKAGE_VERSION);
+}
+
 void sql_driver_register(const struct sql_db *driver)
 {
 	array_append(&sql_drivers, &driver, 1);
--- dovecot-1.0.rc32/src/auth/main.c.split	2007-03-15 16:48:13.000000000 +0100
+++ dovecot-1.0.rc32/src/auth/main.c	2007-04-13 13:56:55.000000000 +0200
@@ -10,6 +10,7 @@
 #include "sql-api.h"
 #include "randgen.h"
 #include "password-scheme.h"
+#include "module-dir.h"
 #include "mech.h"
 #include "auth.h"
 #include "auth-request-handler.h"
@@ -35,6 +36,8 @@
 static struct auth *auth;
 static struct auth_worker_client *worker_client;
 
+static struct module *sql_modules;
+
 static void sig_die(int signo, void *context __attr_unused__)
 {
 	/* warn about being killed because of some signal, except SIGINT (^C)
@@ -189,6 +192,8 @@
 	/* Load built-in SQL drivers (if any) */
 	sql_drivers_init();
 	sql_drivers_register_all();
+	sql_modules = sql_drivers_modules_load();
+	module_dir_init(sql_modules);
 
 	/* Initialize databases so their configuration files can be readable
 	   only by root. Also load all modules here. */
@@ -287,6 +292,7 @@
 	mech_deinit();
 
         password_schemes_deinit();
+	module_dir_unload(&sql_modules);
 	sql_drivers_deinit();
 	random_deinit();
 
--- dovecot-1.0.rc32/configure.in.split	2007-04-12 19:16:36.000000000 +0200
+++ dovecot-1.0.rc32/configure.in	2007-04-13 13:56:55.000000000 +0200
@@ -225,6 +225,15 @@
 	fi,
 	want_sqlite=no)
 
+AC_ARG_WITH(dynamic-sql,
+[  --with-dynamic-sql    Build SQL modules as shared libs],
+	if test x$withval = xno; then
+		want_dynamic_sql=no
+	else
+		want_dynamic_sql=yes
+	fi,
+	want_dynamic_sql=no)
+
 AC_ARG_WITH(ssl,
 [  --with-ssl=[gnutls|openssl] Build with GNUTLS or OpenSSL (default)],
 	if test x$withval = xno; then
@@ -1559,12 +1568,12 @@
 		fi
 		AC_CHECK_HEADER(libpq-fe.h, [
 			if test "$PGSQL_INCLUDE" != ""; then
-				SQL_CFLAGS="$SQL_CFLAGS -I$PGSQL_INCLUDE"
+				PGSQL_CFLAGS="$PGSQL_CFLAGS -I$PGSQL_INCLUDE"
 			fi
 			if test "$PGSQL_LIBDIR" != ""; then
-				SQL_LIBS="$SQL_LIBS -L$PGSQL_LIBDIR"
+				PGSQL_LIBS="$PGSQL_LIBS -L$PGSQL_LIBDIR"
 			fi
-			SQL_LIBS="$SQL_LIBS -lpq"
+			PGSQL_LIBS="$PGSQL_LIBS -lpq"
 			AC_DEFINE(HAVE_PGSQL,, Build with PostgreSQL support)
 			found_sql_drivers="$found_sql_drivers pgsql"
 
@@ -1610,12 +1619,12 @@
 		fi
 		AC_CHECK_HEADER(mysql.h, [
 			if test "$MYSQL_INCLUDE" != ""; then
-				SQL_CFLAGS="$SQL_CFLAGS -I$MYSQL_INCLUDE"
+				MYSQL_CFLAGS="$MYSQL_CFLAGS -I$MYSQL_INCLUDE"
 			fi
 			if test "$MYSQL_LIBDIR" != ""; then
-				SQL_LIBS="$SQL_LIBS -L$MYSQL_LIBDIR"
+				MYSQL_LIBS="$MYSQL_LIBS -L$MYSQL_LIBDIR"
 			fi
-			SQL_LIBS="$SQL_LIBS $mysql_lib"
+			MYSQL_LIBS="$MYSQL_LIBS $mysql_lib"
 
 			AC_CHECK_LIB(mysqlclient, mysql_ssl_set, [
 				AC_DEFINE(HAVE_MYSQL_SSL,, Define if your MySQL library has SSL functions)
@@ -1646,13 +1655,18 @@
 if test $want_sqlite = yes; then
 	AC_CHECK_LIB(sqlite3, sqlite3_open, [
 		AC_CHECK_HEADER(sqlite3.h, [
-			SQL_LIBS="$SQL_LIBS -lsqlite3 -lz"
+			SQLITE_LIBS="$SQLITE_LIBS -lsqlite3 -lz"
 
 			AC_DEFINE(HAVE_SQLITE,, Build with SQLite3 support)
 			found_sql_drivers="$found_sql_drivers sqlite"
 		])
 	])
 fi
+	
+SQL_CFLAGS="$MYSQL_CFLAGS $PGSQL_CFLAGS $SQLITE_CFLAGS"
+if test "$want_dynamic_sql" = "no"; then
+	SQL_LIBS="$MYSQL_LIBS $PGSQL_LIBS $SQLITE_LIBS"
+fi
 
 if test "$found_sql_drivers" != "" -o "$want_sql" = "yes"; then
 	if test "$all_sql_drivers" = "yes"; then
@@ -1716,6 +1730,12 @@
 AC_SUBST(AUTH_LIBS)
 AC_SUBST(SQL_CFLAGS)
 AC_SUBST(SQL_LIBS)
+AC_SUBST(MYSQL_CFLAGS)
+AC_SUBST(MYSQL_LIBS)
+AC_SUBST(PGSQL_CFLAGS)
+AC_SUBST(PGSQL_LIBS)
+AC_SUBST(SQLITE_CFLAGS)
+AC_SUBST(SQLITE_LIBS)
 
 dnl **
 dnl ** Index file compatibility flags
@@ -1783,17 +1803,27 @@
 dnl ** SQL drivers
 dnl **
 
+build_pgsql=no
+build_mysql=no
+build_sqlite=no
 for driver in $sql_drivers; do
   if test "$driver" = "pgsql"; then
     AC_DEFINE(BUILD_PGSQL,, Built-in PostgreSQL support)
+    build_pgsql=yes
   elif test "$driver" = "mysql"; then
     AC_DEFINE(BUILD_MYSQL,, Built-in MySQL support)
+    build_mysql=yes
   elif test "$driver" = "sqlite"; then
     AC_DEFINE(BUILD_SQLITE,, Built-in SQLite support)
+    build_sqlite=yes
   fi
 done
 
 AC_SUBST(sql_drivers)
+AM_CONDITIONAL(BUILD_PGSQL, test "$build_pgsql" = "yes")
+AM_CONDITIONAL(BUILD_MYSQL, test "$build_mysql" = "yes")
+AM_CONDITIONAL(BUILD_SQLITE, test "$build_sqlite" = "yes")
+AM_CONDITIONAL(DYNAMIC_SQL, test "$want_dynamic_sql" = "yes")
 
 dnl **
 dnl ** Plugins
@@ -1873,4 +1903,8 @@
 echo "Building with GSSAPI support ........ : $have_gssapi"
 echo "Building with user database modules . :$userdb"
 echo "Building with password lookup modules :$passdb"
-echo "Building with SQL drivers ............:$sql_drivers"
+if test "$want_dynamic_sql" = "yes"; then
+	echo "Building with SQL drivers ............:$sql_drivers (dynamic)"
+else
+	echo "Building with SQL drivers ............:$sql_drivers"
+fi


More information about the dovecot mailing list