mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-09-12 21:35:30 +00:00
Conditional compile MySQL and PostgreSQL support.
This commit is contained in:
@@ -5,7 +5,19 @@ noinst_LTLIBRARIES = libdbwrapper.la
|
|||||||
|
|
||||||
noinst_HEADERS = db-wrapper.h mysql-db-ops.h sqlite-db-ops.h pgsql-db-ops.h
|
noinst_HEADERS = db-wrapper.h mysql-db-ops.h sqlite-db-ops.h pgsql-db-ops.h
|
||||||
|
|
||||||
libdbwrapper_la_SOURCES = db-wrapper.c mysql-db-ops.c sqlite-db-ops.c pgsql-db-ops.c
|
if WITH_MYSQL
|
||||||
|
MYSQL_DB_SRC = mysql-db-ops.c
|
||||||
|
else
|
||||||
|
MYSQL_DB_SRC =
|
||||||
|
endif
|
||||||
|
|
||||||
|
if WITH_POSTGRESQL
|
||||||
|
PGSQL_DB_SRC = pgsql-db-ops.c
|
||||||
|
else
|
||||||
|
PGSQL_DB_SRC =
|
||||||
|
endif
|
||||||
|
|
||||||
|
libdbwrapper_la_SOURCES = db-wrapper.c sqlite-db-ops.c $(MYSQL_DB_SRC) $(PGSQL_DB_SRC)
|
||||||
|
|
||||||
libdbwrapper_la_LDFLAGS = -Wl,-z -Wl,defs
|
libdbwrapper_la_LDFLAGS = -Wl,-z -Wl,defs
|
||||||
libdbwrapper_la_LIBADD = @SSL_LIBS@ @GLIB2_LIBS@ @MYSQL_LIBS@ -lsqlite3 @PGSQL_LIBS@
|
libdbwrapper_la_LIBADD = @SSL_LIBS@ @GLIB2_LIBS@ @MYSQL_LIBS@ -lsqlite3 @PGSQL_LIBS@
|
||||||
|
@@ -1,9 +1,15 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
#include "db-wrapper.h"
|
#include "db-wrapper.h"
|
||||||
#include "mysql-db-ops.h"
|
|
||||||
#include "sqlite-db-ops.h"
|
#include "sqlite-db-ops.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_MYSQL
|
||||||
|
#include "mysql-db-ops.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_POSTGRESQL
|
||||||
#include "pgsql-db-ops.h"
|
#include "pgsql-db-ops.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct DBOperations {
|
typedef struct DBOperations {
|
||||||
void (*db_conn_pool_free) (DBConnPool *);
|
void (*db_conn_pool_free) (DBConnPool *);
|
||||||
@@ -40,6 +46,8 @@ init_conn_pool_common (DBConnPool *pool, int max_connections)
|
|||||||
pool->max_connections = max_connections;
|
pool->max_connections = max_connections;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_MYSQL
|
||||||
|
|
||||||
DBConnPool *
|
DBConnPool *
|
||||||
db_conn_pool_new_mysql (const char *host,
|
db_conn_pool_new_mysql (const char *host,
|
||||||
const char *user,
|
const char *user,
|
||||||
@@ -81,6 +89,10 @@ db_conn_pool_new_mysql (const char *host,
|
|||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_POSTGRESQL
|
||||||
|
|
||||||
DBConnPool *
|
DBConnPool *
|
||||||
db_conn_pool_new_pgsql (const char *host,
|
db_conn_pool_new_pgsql (const char *host,
|
||||||
const char *user,
|
const char *user,
|
||||||
@@ -118,6 +130,8 @@ db_conn_pool_new_pgsql (const char *host,
|
|||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
DBConnPool *
|
DBConnPool *
|
||||||
db_conn_pool_new_sqlite (const char *db_path, int max_connections)
|
db_conn_pool_new_sqlite (const char *db_path, int max_connections)
|
||||||
{
|
{
|
||||||
|
@@ -21,6 +21,8 @@ struct SeafDBTrans {
|
|||||||
DBConnection *conn;
|
DBConnection *conn;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef HAVE_MYSQL
|
||||||
|
|
||||||
SeafDB *
|
SeafDB *
|
||||||
seaf_db_new_mysql (const char *host,
|
seaf_db_new_mysql (const char *host,
|
||||||
int port,
|
int port,
|
||||||
@@ -48,6 +50,10 @@ seaf_db_new_mysql (const char *host,
|
|||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_POSTGRESQL
|
||||||
|
|
||||||
SeafDB *
|
SeafDB *
|
||||||
seaf_db_new_pgsql (const char *host,
|
seaf_db_new_pgsql (const char *host,
|
||||||
const char *user,
|
const char *user,
|
||||||
@@ -72,6 +78,8 @@ seaf_db_new_pgsql (const char *host,
|
|||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
SeafDB *
|
SeafDB *
|
||||||
seaf_db_new_sqlite (const char *db_path, int max_connections)
|
seaf_db_new_sqlite (const char *db_path, int max_connections)
|
||||||
{
|
{
|
||||||
|
@@ -52,6 +52,8 @@ sqlite_db_start (SeafileSession *session)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_MYSQL
|
||||||
|
|
||||||
#define MYSQL_DEFAULT_PORT 3306
|
#define MYSQL_DEFAULT_PORT 3306
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -125,6 +127,10 @@ mysql_db_start (SeafileSession *session)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_POSTGRESQL
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pgsql_db_start (SeafileSession *session)
|
pgsql_db_start (SeafileSession *session)
|
||||||
{
|
{
|
||||||
@@ -174,6 +180,8 @@ pgsql_db_start (SeafileSession *session)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
load_database_config (SeafileSession *session)
|
load_database_config (SeafileSession *session)
|
||||||
{
|
{
|
||||||
@@ -185,11 +193,18 @@ load_database_config (SeafileSession *session)
|
|||||||
/* Default to use sqlite if not set. */
|
/* Default to use sqlite if not set. */
|
||||||
if (!type || strcasecmp (type, "sqlite") == 0) {
|
if (!type || strcasecmp (type, "sqlite") == 0) {
|
||||||
ret = sqlite_db_start (session);
|
ret = sqlite_db_start (session);
|
||||||
} else if (strcasecmp (type, "mysql") == 0) {
|
}
|
||||||
|
#ifdef HAVE_MYSQL
|
||||||
|
else if (strcasecmp (type, "mysql") == 0) {
|
||||||
ret = mysql_db_start (session);
|
ret = mysql_db_start (session);
|
||||||
} else if (strcasecmp (type, "pgsql") == 0) {
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_POSTGRESQL
|
||||||
|
else if (strcasecmp (type, "pgsql") == 0) {
|
||||||
ret = pgsql_db_start (session);
|
ret = pgsql_db_start (session);
|
||||||
} else {
|
}
|
||||||
|
#endif
|
||||||
|
else {
|
||||||
seaf_warning ("Unsupported db type %s.\n", type);
|
seaf_warning ("Unsupported db type %s.\n", type);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
@@ -268,17 +268,19 @@ if test "xyes" = "x$mysql"; then
|
|||||||
tmp_LDFLAGS=$LDFLAGS
|
tmp_LDFLAGS=$LDFLAGS
|
||||||
CPPFLAGS="`$MYSQLCONFIG --include` $CPPFLAGS"
|
CPPFLAGS="`$MYSQLCONFIG --include` $CPPFLAGS"
|
||||||
LDFLAGS="`$MYSQLCONFIG --libs` $LDFLAGS"
|
LDFLAGS="`$MYSQLCONFIG --libs` $LDFLAGS"
|
||||||
AC_CHECK_HEADERS([mysql.h])
|
AC_CHECK_HEADERS([mysql.h], [], [mysql="no"])
|
||||||
if test "xyes" = "x$mysql"; then
|
if test "xyes" = "x$mysql"; then
|
||||||
echo "found mysql client library"
|
echo "found mysql client library"
|
||||||
MYSQL_CFLAGS=`$MYSQLCONFIG --include`
|
MYSQL_CFLAGS=`$MYSQLCONFIG --include`
|
||||||
MYSQL_LIBS=`$MYSQLCONFIG --libs`
|
MYSQL_LIBS=`$MYSQLCONFIG --libs`
|
||||||
AC_SUBST(MYSQL_CFLAGS)
|
AC_SUBST(MYSQL_CFLAGS)
|
||||||
AC_SUBST(MYSQL_LIBS)
|
AC_SUBST(MYSQL_LIBS)
|
||||||
|
AC_DEFINE([HAVE_MYSQL], 1, [Define to 1 to enable mysql])
|
||||||
fi
|
fi
|
||||||
CPPFLAGS=$tmp_CPPFLAGS
|
CPPFLAGS=$tmp_CPPFLAGS
|
||||||
LDFLAGS=$tmp_LDFLAGS
|
LDFLAGS=$tmp_LDFLAGS
|
||||||
fi
|
fi
|
||||||
|
AM_CONDITIONAL([WITH_MYSQL], test "xyes" = "x$mysql")
|
||||||
|
|
||||||
postgresql="yes"
|
postgresql="yes"
|
||||||
check_postgres_config()
|
check_postgres_config()
|
||||||
@@ -320,10 +322,12 @@ if test "xyes" = "x$postgresql"; then
|
|||||||
PGSQL_LIBS="-L`$PGCONFIG --libdir` -lpq"
|
PGSQL_LIBS="-L`$PGCONFIG --libdir` -lpq"
|
||||||
AC_SUBST(PGSQL_CFLAGS)
|
AC_SUBST(PGSQL_CFLAGS)
|
||||||
AC_SUBST(PGSQL_LIBS)
|
AC_SUBST(PGSQL_LIBS)
|
||||||
|
AC_DEFINE([HAVE_POSTGRESQL], 1, [Define to 1 to enable postgresql])
|
||||||
fi
|
fi
|
||||||
CPPFLAGS=$tmp_CPPFLAGS
|
CPPFLAGS=$tmp_CPPFLAGS
|
||||||
LDFLAGS=$tmp_LDFLAGS
|
LDFLAGS=$tmp_LDFLAGS
|
||||||
fi
|
fi
|
||||||
|
AM_CONDITIONAL([WITH_POSTGRESQL], test "xyes" = "x$postgresql")
|
||||||
|
|
||||||
if test "${compile_fuse}" = "yes"; then
|
if test "${compile_fuse}" = "yes"; then
|
||||||
PKG_CHECK_MODULES(FUSE, [fuse >= $FUSE_REQUIRED])
|
PKG_CHECK_MODULES(FUSE, [fuse >= $FUSE_REQUIRED])
|
||||||
|
Reference in New Issue
Block a user