Experiments on alternative platform.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Sat, 31 Oct 2009 19:28:57 +0000 (19:28 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Sat, 31 Oct 2009 19:28:57 +0000 (19:28 +0000)
org.glite.lbjp-common.db/Makefile
org.glite.lbjp-common.db/examples/db_test.c
org.glite.lbjp-common.db/interface/db-int.h
org.glite.lbjp-common.db/src/db-mysql.c
org.glite.lbjp-common.db/src/db-pg.c
org.glite.lbjp-common.db/src/db.c
org.glite.lbjp-common.trio/interface/trio.h

index 71ffa8f..1915902 100644 (file)
@@ -42,7 +42,8 @@ CFLAGS:= \
        -I${stagedir}/include -I${top_srcdir}/src -I. \
        -I${top_srcdir}/interface \
        ${COVERAGE_FLAGS} \
-       -D_GNU_SOURCE
+       -D_GNU_SOURCE \
+       -DHAVE_SYSLOG_H=1
 
 ifdef LBS_DB_PROFILE
        CFLAGS:=${CFLAGS} -DLBS_DB_PROFILE
index 3e541f9..e1b639f 100644 (file)
@@ -18,6 +18,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <glite/lbu/trio.h>
+
 #include "db.h"
 
 #define CS "testuser/@localhost:test"
index 0d9d919..7a86c84 100644 (file)
@@ -1,3 +1,8 @@
+#ifdef WIN32
+#define asprintf(STR, FMT...) trio_asprintf((STR), ##FMT)
+#define vasprintf(STR, FMT, VARGS) trio_asprintf((STR), (FMT), (VARGS))
+#define strcasestr(H,N) strstr((H), (N))
+#endif
 
 #define dprintf(CTX, FMT...) if ((CTX)->caps & GLITE_LBU_DB_CAP_ERRORS) fprintf(stderr, ##FMT)
 
index 3678dcf..60468d7 100644 (file)
 #include <stdarg.h>
 #include <dlfcn.h>
 #include <pthread.h>
+#ifdef HAVE_SYSLOG_H
 #include <syslog.h>
+#endif
+
+#ifdef WIN32
+#include <windows.h>
+#ifndef STDCALL
+#define STDCALL __stdcall
+#endif
+#else
+#define STDCALL
+#endif
 
 #include <mysql.h>
 #include <mysqld_error.h>
@@ -96,36 +107,36 @@ typedef struct {
        void *lib;
        pthread_mutex_t lock;
 
-       void *(*mysql_init)(void *);
-       unsigned long (*mysql_get_client_version)(void);
-       int (*mysql_options)(MYSQL *mysql, enum mysql_option option, const char *arg);
-       unsigned int (*mysql_errno)(MYSQL *mysql);
-       const char *(*mysql_error)(MYSQL *mysql);
-       unsigned int (*mysql_stmt_errno)(MYSQL_STMT *stmt);
-       const char *(*mysql_stmt_error)(MYSQL_STMT *stmt);
-       MYSQL *(*mysql_real_connect)(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long client_flag);
-       void (*mysql_close)(MYSQL *mysql);
-       int (*mysql_query)(MYSQL *mysql, const char *stmt_str);
-       MYSQL_RES *(*mysql_store_result)(MYSQL *mysql);
-       void (*mysql_free_result)(MYSQL_RES *result);
-       my_ulonglong (*mysql_affected_rows)(MYSQL *mysql);
-       my_bool (*mysql_stmt_close)(MYSQL_STMT *);
-       unsigned int (*mysql_num_fields)(MYSQL_RES *result);
-       unsigned long *(*mysql_fetch_lengths)(MYSQL_RES *result);
-       my_bool (*mysql_stmt_bind_result)(MYSQL_STMT *stmt, MYSQL_BIND *bind);
-       int (*mysql_stmt_prepare)(MYSQL_STMT *stmt, const char *stmt_str, unsigned long length);
-       int (*mysql_stmt_store_result)(MYSQL_STMT *stmt);
-       MYSQL_ROW (*mysql_fetch_row)(MYSQL_RES *result);
-       MYSQL_FIELD *(*mysql_fetch_field)(MYSQL_RES *result);
-       const char *(*mysql_get_server_info)(MYSQL *mysql);
-       MYSQL_STMT *(*mysql_stmt_init)(MYSQL *mysql);
-       my_bool (*mysql_stmt_bind_param)(MYSQL_STMT *stmt, MYSQL_BIND *bind);
-       int (*mysql_stmt_execute)(MYSQL_STMT *stmt);
-       int (*mysql_stmt_fetch)(MYSQL_STMT *stmt);
-       my_ulonglong (*mysql_stmt_insert_id)(MYSQL_STMT *stmt);
-       my_ulonglong (*mysql_stmt_affected_rows)(MYSQL_STMT *stmt);
-       MYSQL_RES *(*mysql_stmt_result_metadata)(MYSQL_STMT *stmt);
-       int (*mysql_stmt_fetch_column)(MYSQL_STMT *stmt, MYSQL_BIND *bind, unsigned int column, unsigned long offset);
+       void * STDCALL(*mysql_init)(void *);
+       unsigned long STDCALL(*mysql_get_client_version)(void);
+       int STDCALL(*mysql_options)(MYSQL *mysql, enum mysql_option option, const char *arg);
+       unsigned int STDCALL(*mysql_errno)(MYSQL *mysql);
+       const char *STDCALL(*mysql_error)(MYSQL *mysql);
+       unsigned int STDCALL(*mysql_stmt_errno)(MYSQL_STMT *stmt);
+       const char *STDCALL(*mysql_stmt_error)(MYSQL_STMT *stmt);
+       MYSQL * STDCALL(*mysql_real_connect)(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long client_flag);
+       void STDCALL(*mysql_close)(MYSQL *mysql);
+       int STDCALL(*mysql_query)(MYSQL *mysql, const char *stmt_str);
+       MYSQL_RES *STDCALL(*mysql_store_result)(MYSQL *mysql);
+       void STDCALL(*mysql_free_result)(MYSQL_RES *result);
+       my_ulonglong STDCALL(*mysql_affected_rows)(MYSQL *mysql);
+       my_bool STDCALL(*mysql_stmt_close)(MYSQL_STMT *);
+       unsigned int STDCALL(*mysql_num_fields)(MYSQL_RES *result);
+       unsigned long *STDCALL(*mysql_fetch_lengths)(MYSQL_RES *result);
+       my_bool STDCALL(*mysql_stmt_bind_result)(MYSQL_STMT *stmt, MYSQL_BIND *bind);
+       int STDCALL(*mysql_stmt_prepare)(MYSQL_STMT *stmt, const char *stmt_str, unsigned long length);
+       int STDCALL(*mysql_stmt_store_result)(MYSQL_STMT *stmt);
+       MYSQL_ROW STDCALL(*mysql_fetch_row)(MYSQL_RES *result);
+       MYSQL_FIELD *STDCALL(*mysql_fetch_field)(MYSQL_RES *result);
+       const char *STDCALL(*mysql_get_server_info)(MYSQL *mysql);
+       MYSQL_STMT *STDCALL(*mysql_stmt_init)(MYSQL *mysql);
+       my_bool STDCALL(*mysql_stmt_bind_param)(MYSQL_STMT *stmt, MYSQL_BIND *bind);
+       int STDCALL(*mysql_stmt_execute)(MYSQL_STMT *stmt);
+       int STDCALL(*mysql_stmt_fetch)(MYSQL_STMT *stmt);
+       my_ulonglong STDCALL(*mysql_stmt_insert_id)(MYSQL_STMT *stmt);
+       my_ulonglong STDCALL(*mysql_stmt_affected_rows)(MYSQL_STMT *stmt);
+       MYSQL_RES *STDCALL(*mysql_stmt_result_metadata)(MYSQL_STMT *stmt);
+       int STDCALL(*mysql_stmt_fetch_column)(MYSQL_STMT *stmt, MYSQL_BIND *bind, unsigned int column, unsigned long offset);
 } mysql_module_t;
 
 
@@ -249,7 +260,9 @@ int glite_lbu_InitDBContextMysql(glite_lbu_DBContext *ctx_gen) {
                        ver_u = mysql_module.mysql_get_client_version();
                        if (ver_u != MYSQL_VERSION_ID) {
                                fprintf(stderr,"Warning: MySQL library version mismatch (compiled '%d', runtime '%d')", MYSQL_VERSION_ID, ver_u);
+#ifdef SYSLOG_H
                                syslog(LOG_WARNING,"MySQL library version mismatch (compiled '%d', runtime '%d')", MYSQL_VERSION_ID, ver_u);
+#endif
                        }
 
                        pthread_mutex_unlock(&mysql_module.lock);
index b17e6b1..6228aa3 100644 (file)
 #include "db.h"
 #include "db-int.h"
 
+#ifdef WIN32
+#define STDCALL __stdcall
+#else
+#define STDCALL
+#endif
+
 #define DB_CONNECT_TIMEOUT "20"
 
 #ifdef LOG
@@ -58,26 +64,26 @@ typedef struct {
        pthread_mutex_t lock;
 
        /* functions from 8.3.8 client library version (libpq-fe.h) */
-       PGconn *(*PQconnectdb)(const char *conninfo);
-       ConnStatusType (*PQstatus)(const PGconn *conn);
-       void (*PQfinish)(PGconn *conn);
-       char *(*PQerrorMessage)(const PGconn *conn);
-       int (*PQnfields)(const PGresult *res);
-       char *(*PQgetvalue)(const PGresult *res, int tup_num, int field_num);
-       int (*PQgetlength)(const PGresult *res, int tup_num, int field_num);
-       void (*PQclear)(PGresult *res);
-       PGresult *(*PQexec)(PGconn *conn, const char *query);
-       ExecStatusType (*PQresultStatus)(const PGresult *res);
-       char *(*PQresultErrorMessage)(const PGresult *res);
-       char *(*PQcmdTuples)(PGresult *res);
-       int (*PQntuples)(const PGresult *res);
-       char *(*PQfname)(const PGresult *res, int field_num);
-       unsigned char *(*PQescapeByteaConn)(PGconn *conn,
+       PGconn *STDCALL(*PQconnectdb)(const char *conninfo);
+       ConnStatusType STDCALL(*PQstatus)(const PGconn *conn);
+       void STDCALL(*PQfinish)(PGconn *conn);
+       char *STDCALL(*PQerrorMessage)(const PGconn *conn);
+       int STDCALL(*PQnfields)(const PGresult *res);
+       char *STDCALL(*PQgetvalue)(const PGresult *res, int tup_num, int field_num);
+       int STDCALL(*PQgetlength)(const PGresult *res, int tup_num, int field_num);
+       void STDCALL(*PQclear)(PGresult *res);
+       PGresult *STDCALL(*PQexec)(PGconn *conn, const char *query);
+       ExecStatusType STDCALL(*PQresultStatus)(const PGresult *res);
+       char *STDCALL(*PQresultErrorMessage)(const PGresult *res);
+       char *STDCALL(*PQcmdTuples)(PGresult *res);
+       int STDCALL(*PQntuples)(const PGresult *res);
+       char *STDCALL(*PQfname)(const PGresult *res, int field_num);
+       unsigned char *STDCALL(*PQescapeByteaConn)(PGconn *conn,
                const unsigned char *from, size_t from_length,
                size_t *to_length);
-       unsigned char *(*PQunescapeBytea)(const unsigned char *strtext,
+       unsigned char *STDCALL(*PQunescapeBytea)(const unsigned char *strtext,
                size_t *retbuflen);
-       void (*PQfreemem)(void *ptr);
+       void STDCALL(*PQfreemem)(void *ptr);
 } psql_module_t;
 
 
index 2b19aff..d65d5a8 100644 (file)
@@ -115,7 +115,7 @@ time_t glite_lbu_StrToTime(const char *str) {
        struct tm       tm;
 
        memset(&tm,0,sizeof(tm));
-       setenv("TZ","UTC",1); tzset();
+       putenv("TZ=UTC"); tzset();
        sscanf(str,"%4d-%02d-%02d %02d:%02d:%02d",
                &tm.tm_year,&tm.tm_mon,&tm.tm_mday,
                &tm.tm_hour,&tm.tm_min,&tm.tm_sec);
@@ -131,7 +131,7 @@ double glite_lbu_StrToTimestamp(const char *str) {
        double  sec;
 
        memset(&tm,0,sizeof(tm));
-       setenv("TZ","UTC",1); tzset();
+       putenv("TZ=UTC"); tzset();
        sscanf(str,"%4d-%02d-%02d %02d:%02d:%lf",
                &tm.tm_year,&tm.tm_mon,&tm.tm_mday,
                &tm.tm_hour,&tm.tm_min,&sec);
index 04f133c..b5e1969 100644 (file)
@@ -27,7 +27,7 @@ extern "C" {
 #endif
 
 /* make utility and C++ compiler in Windows NT fails to find this symbol */ 
-#if defined(WIN32) && !defined(isascii)
+#if defined(WIN32) && !defined(isascii) && !defined(HAVE_IASCII)
 # define isascii ((unsigned)(x) < 0x80)
 #endif