#include "db_ops.h"
+#define LOG_SQL 0
+
#define TABLE_PREFIX_DATA "attr_"
#define SQLCMD_DROP_DATA_TABLE "DROP TABLE " TABLE_PREFIX_DATA "%s"
#define SQLCMD_CREATE_DATA_TABLE "CREATE TABLE " TABLE_PREFIX_DATA "%s (\n\
// insert
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);
+ sql[sizeof(sql) - 1] = '\0';
+ snprintf(sql, sizeof(sql) - 1, SQLCMD_CREATE_DATA_TABLE, attrid, type_index, type_full);
+ llprintf(LOG_SQL, "creating table: '%s'\n", sql);
if ((glite_jp_db_execstmt(jpctx, sql, NULL)) == -1) goto fail;
i++;
memcpy(dbconds, conds, conds_len);
free(conds);
if (glite_jp_db_execute(stmt) == -1) goto fail_conds;
+ feeds[i]->uniqueid = glite_jp_db_lastid(stmt);
i++;
}
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);
+ llprintf(LOG_SQL, "dropping '%s' ==> '%s'\n", attrid, sql);
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;
free(table);
free(value);
free(full_value);
- lprintf("(%s) sql=%s\n", av->name, sql);
+ llprintf(LOG_SQL, "(%s) sql=%s\n", av->name, sql);
if (glite_jp_db_execstmt(ctx->jpctx, sql, NULL) != 1) {
free(sql);
return ctx->jpctx->error->code;
/* Helper functions */
/*------------------*/
-#define dprintf(FMT, ARGS...)
+int debug = 0;
+#define dprintf(FMT, ARGS...) if (debug) fprintf(stderr, FMT, ##ARGS)
#include "glite/jp/ws_fault.c"
#define check_fault(SOAP, ERR) glite_jp_clientCheckFault((SOAP), (ERR), NULL, 0)
-#if 0
-
-static struct jptype__genericFault *jp2s_error(struct soap *soap,
- const glite_jp_error_t *err)
-{
- struct jptype__genericFault *ret = NULL;
- if (err) {
- ret = soap_malloc(soap,sizeof *ret);
- memset(ret,0,sizeof *ret);
- ret->code = err->code;
- ret->source = soap_strdup(soap,err->source);
- ret->text = soap_strdup(soap,strerror(err->code));
- ret->description = soap_strdup(soap,err->desc);
- ret->reason = jp2s_error(soap,err->reason);
- }
- return ret;
-}
-
-static void err2fault(const glite_jp_context_t ctx,struct soap *soap)
-{
- struct SOAP_ENV__Detail *detail = soap_malloc(soap,sizeof *detail);
- struct _genericFault *f = soap_malloc(soap,sizeof *f);
-
-
- f->jpelem__genericFault = jp2s_error(soap,ctx->error);
-
- detail->__type = SOAP_TYPE__genericFault;
-#if GSOAP_VERSION >= 20700
- detail->fault = f;
-#else
- detail->value = f;
-#endif
- detail->__any = NULL;
-
- soap_receiver_fault(soap,"Oh, shit!",NULL);
- if (soap->version == 2) soap->fault->SOAP_ENV__Detail = detail;
- else soap->fault->detail = detail;
-}
-
-
-static int check_fault(struct soap *soap,int err) {
- struct SOAP_ENV__Detail *detail;
- struct jptype__genericFault *f;
- char *reason,indent[200] = " ";
-
- switch(err) {
- case SOAP_OK: puts("OK");
- break;
- case SOAP_FAULT:
- case SOAP_SVR_FAULT:
- if (soap->version == 2) {
- detail = soap->fault->SOAP_ENV__Detail;
-#if GSOAP_VERSION >= 20706
- reason = soap->fault->SOAP_ENV__Reason->SOAP_ENV__Text;
-#else
- reason = soap->fault->SOAP_ENV__Reason;
-#endif
- }
- else {
- detail = soap->fault->detail;
- reason = soap->fault->faultstring;
- }
- fputs(reason,stderr);
- putc('\n',stderr);
- assert(detail->__type == SOAP_TYPE__genericFault);
-#if GSOAP_VERSION >= 20700
- f = ((struct _genericFault *) detail->fault)
-#else
- f = ((struct _genericFault *) detail->value)
-#endif
- -> jpelem__genericFault;
-
- while (f) {
- fprintf(stderr,"%s%s: %s (%s)\n",indent,
- f->source,f->text,f->description);
- f = f->reason;
- strcat(indent," ");
- }
- return -1;
-
- default: soap_print_fault(soap,stderr);
- return -1;
- }
- return 0;
-}
-#endif
/*----------------------*/
/* PS WSDL client calls */
/*----------------------*/
-static int find_dest_index(glite_jp_is_conf *conf, char *dest)
+static int find_dest_index(glite_jp_is_conf *conf, long int uniqueid)
{
int i;
for (i=0; conf->feeds[i]; i++)
- if (!strcmp(dest, conf->feeds[i]->PS_URL)) return(i);
+ if (conf->feeds[i]->uniqueid == uniqueid) return(i);
return -1;
}
struct soap *soap = soap_new();
glite_gsplugin_Context plugin_ctx;
glite_jp_error_t err;
- char *src;
+ char *src, *desc = NULL;
+
+ lprintf("(%ld) for %s called\n", uniqueid, dest);
+ debug = conf->debug;
-lprintf("MyFeedIndex for %s called\n", dest);
glite_gsplugin_init_context(&plugin_ctx);
if (ctx->conf->server_key) plugin_ctx->key_filename = strdup(ctx->conf->server_key);
if (ctx->conf->server_cert) plugin_ctx->cert_filename = strdup(ctx->conf->server_cert);
in.__sizeattributes = i;
in.attributes = conf->attrs;
- if ((dest_index = find_dest_index(conf, dest)) < 0) goto err;
+ if ((dest_index = find_dest_index(conf, uniqueid)) < 0) goto err;
for (i=0; conf->feeds[dest_index]->query[i]; i++);
GLITE_SECURITY_GSOAP_LIST_CREATE(soap, &in, conditions, struct jptype__primaryQuery, i);
in.history = conf->feeds[dest_index]->history;
in.continuous = conf->feeds[dest_index]->continuous;
in.destination = ctx->hname;
- fprintf(stderr, "%s:%s\n", __FUNCTION__, ctx->hname);
+ lprintf("(%ld) destination IS: %s\n", uniqueid, ctx->hname);
if (check_fault(soap,soap_call___jpsrv__FeedIndex(soap,dest,"", &in, &out)) != 0) {
fprintf(stderr, "\n");
glite_jpis_unlockFeed(ctx, uniqueid);
err.code = EIO;
- err.desc = "soap_call___jpsrv__FeedIndex() returned error";
+ asprintf(&desc, "soap_call___jpsrv__FeedIndex() returned error %d", soap->error);
+ err.desc = desc;
asprintf(&src, "%s/%s():%d", __FILE__, __FUNCTION__, __LINE__);
fprintf(stderr, "%s\n", err.desc);
goto err;
}
else {
- lprintf("FeedId: %s\nExpires: %s\n",out.feedId,ctime(&out.feedExpires));
+ lprintf("(%ld) FeedId: %s\n", uniqueid, out.feedId);
+ lprintf("(%ld) Expires: %s", uniqueid, ctime(&out.feedExpires));
glite_jpis_initFeed(ctx, uniqueid, out.feedId, out.feedExpires);
glite_jpis_unlockFeed(ctx, uniqueid);
}
err.source = src;
glite_jp_stack_error(ctx->jpctx, &err);
free(src);
+ free(desc);
soap_end(soap);
soap_done(soap);