Code teased, getting connection string moved behing config API.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 6 Oct 2005 14:27:36 +0000 (14:27 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 6 Oct 2005 14:27:36 +0000 (14:27 +0000)
13 files changed:
org.glite.jp.index/Makefile
org.glite.jp.index/examples/jpis-db-internal.c
org.glite.jp.index/examples/jpis-test.c
org.glite.jp.index/src/bones_server.c
org.glite.jp.index/src/conf.c
org.glite.jp.index/src/conf.h
org.glite.jp.index/src/context.c [new file with mode: 0644]
org.glite.jp.index/src/context.h [new file with mode: 0644]
org.glite.jp.index/src/db_ops.c
org.glite.jp.index/src/db_ops.h
org.glite.jp.index/src/soap_ops.c
org.glite.jp.index/src/soap_ps_calls.c
org.glite.jp.index/src/soap_ps_calls.h

index 78e3d53..014e4b9 100644 (file)
@@ -48,11 +48,11 @@ is_prefix:=jpis_
 ps_prefix:=jpps_
 
 SRCS:= conf.c bones_server.c soap_ops.c soap_ps_calls.c \
-       ws_ps_typeref.c ws_is_typeref.c db_ops.c \
+       ws_ps_typeref.c ws_is_typeref.c db_ops.c context.c \
        ${is_prefix}ServerLib.c \
        ${ps_prefix}ClientLib.c ${ps_prefix}C.c \
 
-EXA_SRCS:=jpis-test.c ${is_prefix}C.c ${is_prefix}Client.c
+EXA_SRCS:=jpis-test.c ${is_prefix}C.c ${is_prefix}Client.c context.c
 
 OBJS:=${SRCS:.c=.o}
 EXA_OBJS:=${EXA_SRCS:.c=.o}
@@ -86,7 +86,7 @@ ${daemon}: ${OBJS}
 ${example}: ${EXA_OBJS}
        ${LINK} -o $@ ${EXA_OBJS} ${GSOAPLIB} ${GLOBUS_LIBS}
 
-jpis-db-internal: jpis-db-internal.o db_ops.o conf.o
+jpis-db-internal: jpis-db-internal.o db_ops.o conf.o context.o
        ${LINK} -o $@ $+ ${COMMONLIB} ${SRVCOMMONLIB} ${GLOBUS_LIBS}
 
 JobProvenanceIS.xh: JobProvenanceIS.wsdl JobProvenanceTypes.wsdl typemap.dat
index 4b9016c..39aa48a 100644 (file)
@@ -33,15 +33,19 @@ int main(int argc, char *argv[]) {
        long int uniqueid;
        char *ps, *feedid;
 
+       jpctx = NULL;
+       isctx = NULL;
+       conf = NULL;
        glite_jp_init_context(&jpctx);
-       if (glite_jpis_init_context(&isctx, jpctx) != 0) goto fail;
+       if (glite_jp_get_conf(argc, argv, NULL, &conf) != 0) goto fail;
+       if (glite_jpis_init_context(&isctx, jpctx, conf) != 0) goto fail;
+       if (glite_jpis_init_db(isctx) != 0) goto fail;
 
        printf("dropping...\n");
-       if (glite_jpis_dropDatabase(jpctx) != 0) goto faildb;
+       if (glite_jpis_dropDatabase(isctx) != 0) goto faildb;
 
        printf("initializing...\n");
-       if (glite_jp_get_conf(argc, argv, NULL, &conf) != 0) goto faildb;
-       if (glite_jpis_initDatabase(jpctx, conf) != 0) goto failconf;
+       if (glite_jpis_initDatabase(isctx) != 0) goto faildb;
 
        printf("locking...\n");
        do {
@@ -53,30 +57,33 @@ int main(int argc, char *argv[]) {
                        asprintf(&feedid, "feed://%lu", uniqueid + 3);
                        if (glite_jpis_initFeed(isctx, uniqueid, feedid, (time_t)10000) != 0) {
                                free(feedid);
-                               goto failconf;
+                               goto faildb;
                        }
                        free(feedid);
 
-                       if (glite_jpis_unlockFeed(isctx, uniqueid) != 0) goto failconf;
+                       if (glite_jpis_unlockFeed(isctx, uniqueid) != 0) goto faildb;
                }
        } while (ret == 0);
 
-       if (glite_jpis_tryReconnectFeed(isctx, uniqueid, time(NULL) + 10) != 0) goto failconf;
+       if (glite_jpis_tryReconnectFeed(isctx, uniqueid, time(NULL) + 10) != 0) goto faildb;
 
-       glite_jp_free_conf(conf);
+       glite_jpis_free_db(isctx);
        glite_jpis_free_context(isctx);
+       glite_jp_free_conf(conf);
        glite_jp_free_context(jpctx);
 
        return 0;
 
-failconf:
-       glite_jp_free_conf(conf);
 faildb:
-       glite_jpis_free_context(isctx);
+       glite_jpis_free_db(isctx);
 fail:
        printf("failed\n");
-       print_err(jpctx);
-       glite_jp_free_context(jpctx);
+       glite_jpis_free_context(isctx);
+       glite_jp_free_conf(conf);
+       if (jpctx) {
+               print_err(jpctx);
+               glite_jp_free_context(jpctx);
+       }
 
        return 1;
 #endif
index 185a35a..2f70656 100644 (file)
@@ -64,7 +64,6 @@ static int check_fault(struct soap *soap,int err) {
 int main(int argc,char *argv[])
 {
        char    *server = "http://localhost:8902";
-       int     opt;
        struct soap     *soap = soap_new();
 
        soap_init(soap);        
index 92dc535..25a4f18 100644 (file)
@@ -18,6 +18,7 @@
 #include "conf.h"
 #include "db_ops.h"
 #include "soap_ps_calls.h"
+#include "context.h"
 
 #include "soap_version.h"
 #include "jpis_H.h"
@@ -53,6 +54,7 @@ static struct glite_srvbones_service stab = {
 
 typedef struct {
        glite_jpis_context_t ctx;
+       glite_jp_is_conf *conf;
        struct soap *soap;
 } slave_data_t;
 
@@ -71,7 +73,7 @@ static glite_jp_is_conf               *conf;  // Let's make configuration visible to all slave
 
 int main(int argc, char *argv[])
 {
-       int                     one = 1,opt,i;
+       int                     one = 1,i;
        edg_wll_GssStatus       gss_code;
        struct sockaddr_in      a;
        char                    *config_file;
@@ -79,16 +81,21 @@ int main(int argc, char *argv[])
 
 
        glite_jp_init_context(&ctx);
-       if (glite_jpis_init_context(&isctx, ctx) != 0) {
-               fprintf(stderr, "Connect DB failed: %s (%s)\n", ctx->error->desc, ctx->error->source);
-               glite_jp_free_context(ctx);
-               return 1;
-       }
 
        /* Read config options/file */
        // XXX: need add something meaningfull to src/conf.c !
        config_file = NULL;
        glite_jp_get_conf(argc, argv, config_file, &conf);
+       glite_jpis_init_context(&isctx, ctx, conf);
+
+       /* connect to DB */
+       if (glite_jpis_init_db(isctx) != 0) {
+               fprintf(stderr, "Connect DB failed: %s (%s)\n", ctx->error->desc, ctx->error->source);
+               glite_jpis_free_context(isctx);
+               glite_jp_free_context(ctx);
+               glite_jp_free_conf(conf);
+               return 1;
+       }
 
        /* XXX preliminary support for plugins 
        for (i=0; conf->plugins[i]; i++)
@@ -96,17 +103,21 @@ int main(int argc, char *argv[])
        */
        
 
-       if (glite_jpis_dropDatabase(ctx) != 0) {
+       if (glite_jpis_dropDatabase(isctx) != 0) {
                fprintf(stderr, "Drop DB failed: %s (%s)\n", ctx->error->desc, ctx->error->source);
+               glite_jpis_free_db(isctx);
                glite_jpis_free_context(isctx);
                glite_jp_free_context(ctx);
+               glite_jp_free_conf(conf);
                return 1;
        }
 
-       if (glite_jpis_initDatabase(ctx, conf) != 0) {
+       if (glite_jpis_initDatabase(isctx) != 0) {
                fprintf(stderr, "Init DB failed: %s (%s)\n", ctx->error->desc, ctx->error->source);
+               glite_jpis_free_db(isctx);
                glite_jpis_free_context(isctx);
                glite_jp_free_context(ctx);
+               glite_jp_free_conf(conf);
                return 1;
        }
 
@@ -169,6 +180,7 @@ int main(int argc, char *argv[])
        glite_srvbones_run(data_init,&stab,1 /* XXX: entries in stab */,debug);
 
 
+       glite_jpis_free_db(isctx);
        glite_jp_free_conf(conf);
        glite_jpis_free_context(isctx);
        glite_jp_free_context(ctx);
@@ -184,7 +196,8 @@ static int data_init(void **data)
        long int        uniqueid;
 
        private = calloc(sizeof(*private), 1);
-       if (glite_jpis_init_context(&private->ctx, ctx) != 0) {
+       glite_jpis_init_context(&private->ctx, ctx, conf);
+       if (glite_jpis_init_db(private->ctx) != 0) {
                printf("[%d] slave_init(): DB error: %s (%s)\n",getpid(),ctx->error->desc,ctx->error->source);
                return -1;
        }
@@ -201,6 +214,7 @@ static int data_init(void **data)
                                // error during locking
                                printf("[%d] slave_init(): Locking error.\n",getpid());
                                free(PS_URL);
+                               glite_jpis_free_db(private->ctx);
                                glite_jpis_free_context(private->ctx);
                                return -1;
                        case ENOTCONN:
@@ -299,6 +313,7 @@ static int newconn(int conn,struct timeval *to,void *data)
        return 0;
 
 cleanup:
+       glite_jpis_free_db(private->ctx);
        glite_jpis_free_context(private->ctx);
        glite_gsplugin_free_context(plugin_ctx);
        soap_end(soap);
@@ -363,6 +378,7 @@ static int disconn(int conn,struct timeval *to,void *data)
        slave_data_t            *private = (slave_data_t *)data;
        struct soap             *soap = private->soap;
 
+       glite_jpis_free_db(private->ctx);
        glite_jpis_free_context(private->ctx);
        soap_end(soap); // clean up everything and close socket
        
index 903fb8d..4bab10e 100644 (file)
@@ -56,6 +56,7 @@ int glite_jp_get_conf(int argc, char **argv, char *config_file, glite_jp_is_conf
 
        conf->feeds[1] = NULL;
 
+       conf->cs = getenv("GLITE_JPIS_DB");
 
        *configuration = conf;
 
index 21fd23f..17543d5 100644 (file)
@@ -24,6 +24,8 @@ typedef struct _glite_jp_is_conf {
        char    **plugins;              // list of plugin.so's
 
        glite_jp_is_feed        **feeds;        // null terminated list of feeds
+
+       char    *cs;
 } glite_jp_is_conf;
 
 
diff --git a/org.glite.jp.index/src/context.c b/org.glite.jp.index/src/context.c
new file mode 100644 (file)
index 0000000..959a185
--- /dev/null
@@ -0,0 +1,19 @@
+#include <stdlib.h>
+#include <errno.h>
+
+#include "conf.h"
+#include "context.h"
+
+
+int glite_jpis_init_context(glite_jpis_context_t *isctx, glite_jp_context_t jpctx, glite_jp_is_conf *conf) {
+       if ((*isctx = calloc(sizeof(**isctx), 1)) != NULL) {
+               (*isctx)->jpctx = jpctx;
+               (*isctx)->conf = conf;
+               return 0;
+       } else return ENOMEM;
+}
+
+
+void glite_jpis_free_context(glite_jpis_context_t ctx) {
+       free(ctx);
+}
diff --git a/org.glite.jp.index/src/context.h b/org.glite.jp.index/src/context.h
new file mode 100644 (file)
index 0000000..ff70a3a
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef GLITE_JP_IS_CONTEXT_H
+#define GLITE_JP_IS_CONTEXT_H
+
+#include <glite/jp/types.h>
+#include <glite/jp/context.h>
+#include <glite/jp/db.h>
+#include "conf.h"
+
+
+typedef struct _glite_jpis_context {
+       glite_jp_context_t jpctx;
+       glite_jp_is_conf *conf;
+       glite_jp_db_stmt_t select_unlocked_feed_stmt, lock_feed_stmt, init_feed_stmt, unlock_feed_stmt, select_info_feed_stmt, update_state_feed_stmt, update_error_feed_stmt, select_info_attrs_indexed;
+       long int param_uniqueid, param_state;
+       char param_feedid[33], param_ps[256], param_indexed[256];
+       unsigned long param_ps_len, param_feedid_len, param_indexed_len;
+       void *param_expires;
+} *glite_jpis_context_t;
+
+int glite_jpis_init_context(glite_jpis_context_t *isctx, glite_jp_context_t jpctx, glite_jp_is_conf *conf);
+void glite_jpis_free_context(glite_jpis_context_t ctx);
+#endif
index d896575..3dbc8d9 100644 (file)
@@ -15,6 +15,7 @@
 #include <glite/jp/strmd5.h>
 
 #include "conf.h"
+#include "context.h"
 #include "db_ops.h"
 
 
@@ -263,8 +264,7 @@ char *glite_jpis_attr_name2id(const char *name) {
  * \retval non-zero JP error code
  */
 
-int glite_jpis_initDatabase(glite_jp_context_t ctx, glite_jp_is_conf *conf) {
-       glite_jp_db_stmt_t stmt;
+int glite_jpis_initDatabase(glite_jpis_context_t ctx) {
        char **attrs, *tmp;
        const char *type_index, *type_full;
        size_t i;
@@ -276,22 +276,25 @@ int glite_jpis_initDatabase(glite_jp_context_t ctx, glite_jp_is_conf *conf) {
        char sql[512];
        glite_jp_is_feed **feeds;
        void *conds;
+       glite_jp_context_t jpctx = ctx->jpctx;
+       glite_jp_db_stmt_t stmt = NULL;
 
+       jpctx = ctx->jpctx;
        glite_jp_db_create_params(&param, 4,
                GLITE_JP_DB_TYPE_VARCHAR, attrid, &attrid_len,
                GLITE_JP_DB_TYPE_VARCHAR, name, &name_len,
                GLITE_JP_DB_TYPE_INT, &indexed,
                GLITE_JP_DB_TYPE_VARCHAR, type, &type_len);
-       if (glite_jp_db_prepare(ctx, "INSERT INTO attrs (attrid, name, indexed, type) VALUES (?, ?, ?, ?)", &stmt, param, NULL) != 0) goto fail;
+       if (glite_jp_db_prepare(jpctx, "INSERT INTO attrs (attrid, name, indexed, type) VALUES (?, ?, ?, ?)", &stmt, param, NULL) != 0) goto fail;
 
        memset(attrid, 0, sizeof(attrid));
 
        // attrs table and attrid_* tables
-       attrs = conf->attrs;
+       attrs = ctx->conf->attrs;
        i = 0;
        while (attrs[i]) {
-               type_full = glite_jp_attrval_db_type_full(ctx, attrs[i]);
-               type_index = glite_jp_attrval_db_type_index(ctx, attrs[i], INDEX_LENGTH);
+               type_full = glite_jp_attrval_db_type_full(jpctx, attrs[i]);
+               type_index = glite_jp_attrval_db_type_index(jpctx, attrs[i], INDEX_LENGTH);
 
                // attrid column
                tmp = glite_jpis_attr_name2id(attrs[i]);
@@ -302,16 +305,16 @@ int glite_jpis_initDatabase(glite_jp_context_t ctx, glite_jp_is_conf *conf) {
                strncpy(name, attrs[i], sizeof(name) - 1);
                name_len = strlen(name);
                // indexed column
-               indexed = is_indexed(conf, name);
+               indexed = is_indexed(ctx->conf, name);
                // type column
                strncpy(type, type_full, sizeof(type) - 1);
                type_len = strlen(type);
                // insert
-               if (glite_jp_db_execute(stmt) == -1) goto fail_stmt;
+               if (glite_jp_db_execute(stmt) == -1) goto fail;
 
                snprintf(sql, sizeof(sql), SQLCMD_CREATE_DATA_TABLE, attrid, type_index, type_full);
                lprintf("creating table: '%s'\n", sql);
-               if ((glite_jp_db_execstmt(ctx, sql, NULL)) == -1) goto fail_stmt;
+               if ((glite_jp_db_execstmt(jpctx, sql, NULL)) == -1) goto fail;
 
                i++;
        }
@@ -323,8 +326,8 @@ int glite_jpis_initDatabase(glite_jp_context_t ctx, glite_jp_is_conf *conf) {
                GLITE_JP_DB_TYPE_INT, &locked,
                GLITE_JP_DB_TYPE_VARCHAR, source, &source_len,
                GLITE_JP_DB_TYPE_MEDIUMBLOB, dbconds, &dbconds_len);
-       if (glite_jp_db_prepare(ctx, "INSERT INTO feeds (state, locked, source, condition) VALUES (?, ?, ?, ?)", &stmt, param, NULL) != 0) goto fail;
-       feeds = conf->feeds;
+       if (glite_jp_db_prepare(jpctx, "INSERT INTO feeds (state, locked, source, condition) VALUES (?, ?, ?, ?)", &stmt, param, NULL) != 0) goto fail;
+       feeds = ctx->conf->feeds;
        i = 0;
        memset(source, 0, sizeof(source));
        while (feeds[i]) {
@@ -348,10 +351,9 @@ int glite_jpis_initDatabase(glite_jp_context_t ctx, glite_jp_is_conf *conf) {
 
 fail_conds:
        free(conds);
-fail_stmt:
-       glite_jp_db_freestmt(&stmt);
 fail:
-       return ctx->error->code;
+       glite_jp_db_freestmt(&stmt);
+       return jpctx->error->code;
 }
 
 
@@ -361,133 +363,114 @@ fail:
  * \retval non-zero JP error code
  */
 
-int glite_jpis_dropDatabase(glite_jp_context_t ctx) {
-       glite_jp_db_stmt_t stmt_tabs;
+int glite_jpis_dropDatabase(glite_jpis_context_t ctx) {
        void *res;
        char attrid[33], sql[256];
        unsigned long len;
        int ret;
+       glite_jp_context_t jpctx = ctx->jpctx;
+       glite_jp_db_stmt_t stmt_tabs = NULL;
 
        // search data tables and drop them
        glite_jp_db_create_results(&res, 1, GLITE_JP_DB_TYPE_CHAR, NULL, attrid, sizeof(attrid), &len);
-       if (glite_jp_db_prepare(ctx, "SELECT attrid FROM attrs", &stmt_tabs, NULL, res) != 0) goto fail;
-       if (glite_jp_db_execute(stmt_tabs) == -1) goto fail_tabs;
+       if (glite_jp_db_prepare(jpctx, "SELECT attrid FROM attrs", &stmt_tabs, NULL, res) != 0) goto fail;
+       if (glite_jp_db_execute(stmt_tabs) == -1) goto fail;
        while ((ret = glite_jp_db_fetch(stmt_tabs)) == 0) {
                snprintf(sql, sizeof(sql), SQLCMD_DROP_DATA_TABLE, attrid);
                lprintf("dropping '%s' ==> '%s'\n", attrid, sql);
-               if (glite_jp_db_execstmt(ctx, sql, NULL) == -1) printf("warning: can't drop table '" TABLE_PREFIX_DATA "%s': %s (%s)\n", attrid, ctx->error->desc, ctx->error->source);
+               if (glite_jp_db_execstmt(jpctx, sql, NULL) == -1) printf("warning: can't drop table '" TABLE_PREFIX_DATA "%s': %s (%s)\n", attrid, jpctx->error->desc, jpctx->error->source);
        }
-       if (ret != ENODATA) goto fail_tabs;
+       if (ret != ENODATA) goto fail;
        glite_jp_db_freestmt(&stmt_tabs);
 
        // drop feeds and atributes
-       if (glite_jp_db_execstmt(ctx, "DELETE FROM attrs", NULL) == -1) goto fail;
-       if (glite_jp_db_execstmt(ctx, "DELETE FROM feeds", NULL) == -1) goto fail;
+       if (glite_jp_db_execstmt(jpctx, "DELETE FROM attrs", NULL) == -1) goto fail;
+       if (glite_jp_db_execstmt(jpctx, "DELETE FROM feeds", NULL) == -1) goto fail;
 
        return 0;
 
-fail_tabs:
-       glite_jp_db_freestmt(&stmt_tabs);
 fail:
-       return ctx->error->code;
+       glite_jp_db_freestmt(&stmt_tabs);
+       return jpctx->error->code;
 }
 
 
-int glite_jpis_init_context(glite_jpis_context_t *isctx, glite_jp_context_t jpctx) {
+int glite_jpis_init_db(glite_jpis_context_t isctx) {
        int ret;
        void *myparam;
        void *myres;
        const char *cs;
+       glite_jp_context_t jpctx;
 
-       *isctx = calloc(sizeof(**isctx), 1);
-       
-       (*isctx)->jpctx = jpctx;
-       if ((cs = getenv("GLITE_JPIS_DB")) == NULL) cs = GLITE_JP_IS_DEFAULTCS;
+       jpctx = isctx->jpctx;
+       if ((cs = isctx->conf->cs) == NULL) cs = GLITE_JP_IS_DEFAULTCS;
        if ((ret = glite_jp_db_connect(jpctx, cs)) != 0) goto fail;
 
        // sql command: select an uninitialized unlocked feed
-       glite_jp_db_create_params(&myparam, 1, GLITE_JP_DB_TYPE_DATETIME, &(*isctx)->param_expires);
+       glite_jp_db_create_params(&myparam, 1, GLITE_JP_DB_TYPE_DATETIME, &isctx->param_expires);
        glite_jp_db_create_results(&myres, 2,
-               GLITE_JP_DB_TYPE_INT, NULL, &((*isctx)->param_uniqueid),
-               GLITE_JP_DB_TYPE_VARCHAR, NULL, (*isctx)->param_ps, sizeof((*isctx)->param_ps), &(*isctx)->param_ps_len);
-       if ((ret = glite_jp_db_prepare(jpctx, "SELECT uniqueid, source FROM feeds WHERE (locked=0) AND (feedid IS NULL) AND ((state <> " GLITE_JP_IS_STATE_ERROR_STR ") OR (expires >= ?))", &(*isctx)->select_unlocked_feed_stmt, myparam, myres)) != 0) goto fail_connect;
+               GLITE_JP_DB_TYPE_INT, NULL, &(isctx->param_uniqueid),
+               GLITE_JP_DB_TYPE_VARCHAR, NULL, isctx->param_ps, sizeof(isctx->param_ps), &isctx->param_ps_len);
+       if ((ret = glite_jp_db_prepare(jpctx, "SELECT uniqueid, source FROM feeds WHERE (locked=0) AND (feedid IS NULL) AND ((state <> " GLITE_JP_IS_STATE_ERROR_STR ") OR (expires >= ?))", &isctx->select_unlocked_feed_stmt, myparam, myres)) != 0) goto fail;
 
        // sql command: lock the feed (via uniqueid)
-       glite_jp_db_create_params(&myparam, 1, GLITE_JP_DB_TYPE_INT, &(*isctx)->param_uniqueid);
-       if ((ret = glite_jp_db_prepare(jpctx, "UPDATE feeds SET locked=1 WHERE (locked = 0) AND (uniqueid = ?)", &(*isctx)->lock_feed_stmt, myparam, NULL)) != 0) goto fail_cmd;
+       glite_jp_db_create_params(&myparam, 1, GLITE_JP_DB_TYPE_INT, &isctx->param_uniqueid);
+       if ((ret = glite_jp_db_prepare(jpctx, "UPDATE feeds SET locked=1 WHERE (locked = 0) AND (uniqueid = ?)", &isctx->lock_feed_stmt, myparam, NULL)) != 0) goto fail;
 
        // sql command: assign the feed (via uniqueid)
        glite_jp_db_create_params(&myparam, 3,
-               GLITE_JP_DB_TYPE_VARCHAR, (*isctx)->param_feedid, &(*isctx)->param_feedid_len,
-               GLITE_JP_DB_TYPE_DATETIME, &(*isctx)->param_expires,
-               GLITE_JP_DB_TYPE_INT, &(*isctx)->param_uniqueid);
-       if ((ret = glite_jp_db_prepare(jpctx, "UPDATE feeds SET feedid=?, expires=? WHERE (uniqueid=?)", &(*isctx)->init_feed_stmt, myparam, NULL)) != 0) goto fail_cmd2;
+               GLITE_JP_DB_TYPE_VARCHAR, isctx->param_feedid, &isctx->param_feedid_len,
+               GLITE_JP_DB_TYPE_DATETIME, &isctx->param_expires,
+               GLITE_JP_DB_TYPE_INT, &isctx->param_uniqueid);
+       if ((ret = glite_jp_db_prepare(jpctx, "UPDATE feeds SET feedid=?, expires=? WHERE (uniqueid=?)", &isctx->init_feed_stmt, myparam, NULL)) != 0) goto fail;
 
        // sql command: unlock the feed (via uniqueid)
-       glite_jp_db_create_params(&myparam, 1, GLITE_JP_DB_TYPE_INT, &(*isctx)->param_uniqueid);
-       if ((ret = glite_jp_db_prepare(jpctx, "UPDATE feeds SET locked=0 WHERE (uniqueid=?)", &(*isctx)->unlock_feed_stmt, myparam, NULL)) != 0) goto fail_cmd3;
+       glite_jp_db_create_params(&myparam, 1, GLITE_JP_DB_TYPE_INT, &isctx->param_uniqueid);
+       if ((ret = glite_jp_db_prepare(jpctx, "UPDATE feeds SET locked=0 WHERE (uniqueid=?)", &isctx->unlock_feed_stmt, myparam, NULL)) != 0) goto fail;
 
        // sql command: get info about the feed (via feedid)
-       glite_jp_db_create_params(&myparam, 1, GLITE_JP_DB_TYPE_CHAR, (*isctx)->param_feedid, &(*isctx)->param_feedid_len);
+       glite_jp_db_create_params(&myparam, 1, GLITE_JP_DB_TYPE_CHAR, isctx->param_feedid, &isctx->param_feedid_len);
        glite_jp_db_create_results(&myres, 2,
-               GLITE_JP_DB_TYPE_INT, NULL, &(*isctx)->param_uniqueid,
-               GLITE_JP_DB_TYPE_INT, NULL, &(*isctx)->param_state);
-       if ((ret = glite_jp_db_prepare(jpctx, "SELECT uniqueid, state FROM feeds WHERE (feedid=?)", &(*isctx)->select_info_feed_stmt, myparam, myres)) != 0) goto fail_cmd4;
+               GLITE_JP_DB_TYPE_INT, NULL, &isctx->param_uniqueid,
+               GLITE_JP_DB_TYPE_INT, NULL, &isctx->param_state);
+       if ((ret = glite_jp_db_prepare(jpctx, "SELECT uniqueid, state FROM feeds WHERE (feedid=?)", &isctx->select_info_feed_stmt, myparam, myres)) != 0) goto fail;
 
        // sql command: update state of the feed (via uniqueid)
        glite_jp_db_create_params(&myparam, 2, 
-               GLITE_JP_DB_TYPE_INT, &(*isctx)->param_state,
-               GLITE_JP_DB_TYPE_INT, &(*isctx)->param_uniqueid);
-       if ((ret = glite_jp_db_prepare(jpctx, "UPDATE feeds SET state=? WHERE (uniqueid=?)", &(*isctx)->update_state_feed_stmt, myparam, NULL)) != 0) goto fail_cmd5;
+               GLITE_JP_DB_TYPE_INT, &isctx->param_state,
+               GLITE_JP_DB_TYPE_INT, &isctx->param_uniqueid);
+       if ((ret = glite_jp_db_prepare(jpctx, "UPDATE feeds SET state=? WHERE (uniqueid=?)", &isctx->update_state_feed_stmt, myparam, NULL)) != 0) goto fail;
 
        // sql command: set the error on feed
        glite_jp_db_create_params(&myparam, 3, 
-               GLITE_JP_DB_TYPE_INT, &(*isctx)->param_state,
-               GLITE_JP_DB_TYPE_DATETIME, &(*isctx)->param_expires,
-               GLITE_JP_DB_TYPE_INT, &(*isctx)->param_uniqueid);
-       if ((ret = glite_jp_db_prepare(jpctx, "UPDATE feeds SET state=?, expires=? WHERE (uniqueid=?)", &(*isctx)->update_error_feed_stmt, myparam, NULL)) != 0) goto fail_cmd6;
+               GLITE_JP_DB_TYPE_INT, &isctx->param_state,
+               GLITE_JP_DB_TYPE_DATETIME, &isctx->param_expires,
+               GLITE_JP_DB_TYPE_INT, &isctx->param_uniqueid);
+       if ((ret = glite_jp_db_prepare(jpctx, "UPDATE feeds SET state=?, expires=? WHERE (uniqueid=?)", &isctx->update_error_feed_stmt, myparam, NULL)) != 0) goto fail;
 
        // sql command: get info about indexed attributes
        glite_jp_db_create_results(&myres, 1,
-               GLITE_JP_DB_TYPE_VARCHAR, NULL, &(*isctx)->param_indexed,  sizeof((*isctx)->param_indexed), &(*isctx)->param_indexed_len);
-       if ((ret = glite_jp_db_prepare(jpctx, "SELECT name FROM attrs WHERE (indexed=1)", &(*isctx)->select_info_attrs_indexed, NULL, myres)) != 0) goto fail_cmd7;
-
+               GLITE_JP_DB_TYPE_VARCHAR, NULL, &isctx->param_indexed,  sizeof(isctx->param_indexed), &isctx->param_indexed_len);
+       if ((ret = glite_jp_db_prepare(jpctx, "SELECT name FROM attrs WHERE (indexed=1)", &isctx->select_info_attrs_indexed, NULL, myres)) != 0) goto fail;
 
        return 0;
 
-       
-fail_cmd7:
-       glite_jp_db_freestmt(&(*isctx)->update_error_feed_stmt);
-fail_cmd6:
-       glite_jp_db_freestmt(&(*isctx)->update_state_feed_stmt);
-fail_cmd5:
-       glite_jp_db_freestmt(&(*isctx)->select_info_feed_stmt);
-fail_cmd4:
-       glite_jp_db_freestmt(&(*isctx)->unlock_feed_stmt);
-fail_cmd3:
-       glite_jp_db_freestmt(&(*isctx)->init_feed_stmt);
-fail_cmd2:
-       glite_jp_db_freestmt(&(*isctx)->lock_feed_stmt);
-fail_cmd:
-       glite_jp_db_freestmt(&(*isctx)->select_unlocked_feed_stmt);
-fail_connect:
-       glite_jp_db_close((*isctx)->jpctx);
-fail:
-       free(*isctx);
+fail:  
+       glite_jpis_free_db(isctx);
        return ret;
 }
 
 
-void glite_jpis_free_context(glite_jpis_context_t ctx) {
-       glite_jp_db_freestmt(&ctx->update_error_feed_stmt);
+void glite_jpis_free_db(glite_jpis_context_t ctx) {
        glite_jp_db_freestmt(&ctx->select_unlocked_feed_stmt);
        glite_jp_db_freestmt(&ctx->lock_feed_stmt);
        glite_jp_db_freestmt(&ctx->init_feed_stmt);
        glite_jp_db_freestmt(&ctx->unlock_feed_stmt);
        glite_jp_db_freestmt(&ctx->select_info_feed_stmt);
        glite_jp_db_freestmt(&ctx->update_state_feed_stmt);
+       glite_jp_db_freestmt(&ctx->update_error_feed_stmt);
+       glite_jp_db_freestmt(&ctx->select_info_attrs_indexed);
        glite_jp_db_close(ctx->jpctx);
-       free(ctx);
 }
 
 
index 227a51c..9ebbab2 100644 (file)
@@ -3,10 +3,10 @@
 #ifndef _DB_OPS_H
 #define _DB_OPS_H
 
+
 #include <glite/jp/types.h>
 #include <glite/jp/context.h>
-#include <glite/jp/db.h>
-#include "conf.h"
+#include "context.h"
 
 
 #define GLITE_JP_IS_DEFAULTCS "jpis/@localhost:jpis1"
 #define GLITE_JP_IS_STATE_ERROR_STR "8"
 
 
-typedef struct _glite_jpis_context {
-       glite_jp_context_t jpctx;
-       glite_jp_db_stmt_t select_unlocked_feed_stmt, lock_feed_stmt, init_feed_stmt, unlock_feed_stmt, select_info_feed_stmt, update_state_feed_stmt, update_error_feed_stmt, select_info_attrs_indexed;
-       long int param_uniqueid, param_state;
-       char param_feedid[33], param_ps[256], param_indexed[256];
-       unsigned long param_ps_len, param_feedid_len, param_indexed_len;
-       void *param_expires;
-} *glite_jpis_context_t;
-
 char *glite_jpis_attr_name2id(const char *name);
 
-int glite_jpis_initDatabase(glite_jp_context_t ctx, glite_jp_is_conf *conf);
-int glite_jpis_dropDatabase(glite_jp_context_t ctx);
+int glite_jpis_initDatabase(glite_jpis_context_t ctx);
+int glite_jpis_dropDatabase(glite_jpis_context_t ctx);
 
-int glite_jpis_init_context(glite_jpis_context_t *isctx, glite_jp_context_t jpctx);
-void glite_jpis_free_context(glite_jpis_context_t ctx);
+int glite_jpis_init_db(glite_jpis_context_t isctx);
+void glite_jpis_free_db(glite_jpis_context_t ctx);
 
 int glite_jpis_lockUninitializedFeed(glite_jpis_context_t ctx, long int *uinqueid, char **PS_URL);
 int glite_jpis_initFeed(glite_jpis_context_t ctx, long int uniqueid, char *feedId, time_t feedExpires);
index d142dcd..d46b3a4 100644 (file)
@@ -16,6 +16,7 @@
 // uses common types from jpis_H.h (awful)
 #include "ws_ps_typeref.h"
 #include "ws_is_typeref.h"
+#include "context.h"
 
 #define        INDEXED_STRIDE  2       // how often realloc indexed attr result
                                // XXX: 2 is only for debugging, replace with e.g. 100
index b6ca2b5..3d6bb30 100644 (file)
@@ -11,6 +11,7 @@
 #include "conf.h"
 #include "db_ops.h"
 #include "ws_ps_typeref.h"
+#include "context.h"
 
 #include "stdsoap2.h"
 
index cb2c992..f8ffb61 100644 (file)
@@ -3,6 +3,7 @@
 #ifndef _SOAP_PS_CALLS_H
 #define _SOAP_PS_CALLS_H
 
+#include "context.h"
 #include "conf.h"
 
 void MyFeedIndex(glite_jpis_context_t ctx, glite_jp_is_conf *conf, long int uniqueid, char *dest);