#ident "$Header$"
#include "glite/security/glite_gss.h"
+#include "glite/lbu/db.h"
#include "glite/lb/jobstat.h"
#include "glite/lb/query_rec.h"
#include "glite/lb/lb_plain_io.h"
/* server part */
- void *mysql;
+ glite_lbu_DBContext dbctx;
+ int dbcaps;
edg_wll_Connections *connections;
edg_wll_ConnPool *connPoolNotif; /* hold _one_ connection from notif-interlogger */
edg_wll_ConnProxy *connProxy; /* holds one plain connection */
edg_wll_SeqCode p_seqcode;
int count_statistics;
- /* TODO: belongs to database part */
- int use_transactions;
-
int greyjobs;
};
ifdef LB_PROF
SRVBONES_LIB:= ${stagedir}/lib/libglite_lbu_server_bones.la
LB_COMMON_LIB:=${stagedir}/lib/libglite_lb_common_${nothrflavour}.la
+ LB_UTILS_DB_LIB:=${stagedir}/lib/libglite_lbu_db.la
CFLAGS:=${CFLAGS} -pg -g
LDFLAGS:=${LDFLAGS} -pg
else
SRVBONES_LIB:= -L${stagedir}/lib -lglite_lbu_server_bones
LB_COMMON_LIB:=-lglite_lb_common_${nothrflavour}
+ LB_UTILS_DB_LIB:=-lglite_lbu_db
LDFLAGS:= -L${stagedir}/lib
endif
PLUGIN_LIBS:= -L${stagedir}/lib -lglite_lb_common_${nothrflavour} -lglite_lbu_trio \
${classadslib} -lstdc++ ${expatlib} -lexpat\
-PLUGIN_LOBJS:= lb_plugin.lo jobstat_supp.lo process_event.lo lbs_db_supp.lo process_event_pbs.lo process_event_condor.lo
+PLUGIN_LOBJS:= lb_plugin.lo jobstat_supp.lo process_event.lo process_event_pbs.lo process_event_condor.lo
BKSERVER_BASE_OBJS:= \
bkserverd.o il_lbproxy.o get_events.o index.o jobstat.o jobstat_supp.o process_event.o process_event_pbs.o process_event_condor.o \
- seqcode.o write2rgma.o lbs_db.o lbs_db_supp.o lb_html.o lb_http.o lb_proto.o lb_xml_parse.o \
+ seqcode.o write2rgma.o lb_html.o lb_http.o lb_proto.o lb_xml_parse.o \
lb_xml_parse_V21.o \
lock.o openserver.o query.o userjobs.o db_store.o request.o store.o \
stored_master.o srv_purge.o server_state.o dump.o lb_authz.o load.o \
- notification.o il_notification.o notif_match.o stats.o db_calls.o
+ notification.o il_notification.o notif_match.o stats.o db_calls.o db_supp.o
dotless_gsoap_ver:=${shell echo ${gsoap_version} | tr -d . }
GSOAP_LIB:=-L${stagedir}/lib -lglite_security_gsoap_plugin_${dotless_gsoap_ver}_${nothrflavour}
BKSERVER_LIBS= \
${SRVBONES_LIB} \
${LB_COMMON_LIB} \
+ ${LB_UTILS_DB_LIB} \
${GSOAP_LIB} \
${EXT_LIBS}
else
BKSERVER_LIBS= \
${SRVBONES_LIB} \
${LB_COMMON_LIB} \
+ ${LB_UTILS_DB_LIB} \
-lglite_security_gss_${nothrflavour} \
${EXT_LIBS}
endif
-INDEX_OBJS:= index.o index_parse.o jobstat_supp.o lbs_db.o lbs_db_supp.o openserver.o \
+INDEX_OBJS:= index.o index_parse.o jobstat_supp.o openserver.o \
jobstat.o process_event.o process_event_pbs.o process_event_condor.o query.o lock.o get_events.o write2rgma.o index_lex.o \
lb_authz.o store.o bkindex.o stats.o\
- request.o db_store.o srv_purge.o notif_match.o il_lbproxy.o dump.o lb_xml_parse.o il_notification.o lb_proto.o server_state.o lb_xml_parse_V21.o lb_html.o notification.o seqcode.o userjobs.o load.o db_calls.o
+ request.o db_store.o srv_purge.o notif_match.o il_lbproxy.o dump.o lb_xml_parse.o il_notification.o lb_proto.o server_state.o lb_xml_parse_V21.o lb_html.o notification.o seqcode.o userjobs.o load.o db_calls.o db_supp.lo
-INDEX_LIBS:= ${SRVBONES_LIB} ${COMMON_LIBS} ${EXT_LIBS}
+INDEX_LIBS:= ${SRVBONES_LIB} ${COMMON_LIBS} ${EXT_LIBS} ${LB_UTILS_DB_LIB}
WS_CLIENT_OBJS:= $(GSOAP_FILES_PREFIX)C.o $(GSOAP_FILES_PREFIX)Client.o ws_fault.o ws_typeref.o
WS_CLIENT_LIBS:= ${GSOAP_LIB} -lglite_lb_common_${nothrflavour} \
# ${EXT_LIBS}
#
-HDRS=index.h lb_authz.h lbs_db.h store.h
+HDRS=index.h lb_authz.h store.h
MAN_GZ:=glite-lb-mon-db.1.gz
MAN = $(MAN_GZ:.gz=)
LIB_OBJS_BK:= \
il_lbproxy.o get_events.o index.o jobstat.o jobstat_supp.o process_event.o process_event_pbs.o process_event_condor.o \
- seqcode.o lbs_db.o lbs_db_supp.o lb_html.o lb_http.o lb_proto.o lb_xml_parse.o \
+ seqcode.o lb_html.o lb_http.o lb_proto.o lb_xml_parse.o \
lb_xml_parse_V21.o \
lock.o openserver.o query.o userjobs.o db_store.o request.o store.o \
stored_master.o srv_purge.o server_state.o dump.o lb_authz.o load.o \
notification.o il_notification.o notif_match.o stats.o write2rgma.o \
- db_calls.o
+ db_calls.o db_supp.o
MONDB_OBJS:=mon-db.o ${LIB_OBJS_BK}
-MONDB_LIBS:=${COMMON_LIBS} ${EXT_LIBS}
+MONDB_LIBS:=${COMMON_LIBS} ${LB_UTILS_DB_LIB} ${EXT_LIBS}
glite-lb-bkserverd: ${NSMAP} ${BKSERVER_OBJS}
${LINKXX} -o $@ ${BKSERVER_OBJS} ${BKSERVER_LIBS}
./test_query_events
#query_events_objs:=`echo ${BKSERVER_BASE_OBJS} |sed 's/lbs_db\.o//;s/lbs_db_supp\.o//;s/bkserverd\.o//;s/db_store\.o//;s/stored_master\.o//;s/store\.o//;s/srv_purge\.o//;s/load\.o//;s/dump\.o//;s/lb_proto\.o//;s/lb_html\.o//;s/lb_http\.o//;'`
-query_events_objs:=`echo ${BKSERVER_BASE_OBJS} |sed 's/lbs_db\.o//;s/lbs_db_supp\.o//;s/bkserverd\.o//;'`
+query_events_objs:=`echo ${BKSERVER_BASE_OBJS} |sed 's/bkserverd\.o//;'`
test_query_events: test_query_events.o
${LINKXX} -o $@ test_query_events.o ${query_events_objs} \
+++ /dev/null
-#ifndef GLITE_LB_LBS_DB_H
-#define GLITE_LB_LBS_DB_H
-
-#ident "$Header$"
-
-#include <sys/types.h>
-#include <sys/time.h>
-
-#include "glite/lb/context.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define EDG_WLL_MYSQL_VERSION 40001
-#define BUF_INSERT_ROW_ALLOC_BLOCK 1000
-
-
-#define DEFAULTCS "lbserver/@localhost:lbserver20"
-
-typedef struct _edg_wll_Stmt *edg_wll_Stmt;
-
-edg_wll_ErrorCode edg_wll_DBConnect(
- edg_wll_Context, /* INOUT: */
- const char * /* IN: connect string user/password@host:database */
-);
-
-
-/*
- * structure holds date for multi-rows insert
- */
-typedef struct _edg_wll_bufInsert {
- edg_wll_Context ctx;
- char *table_name;
- char *columns; /* names of columns to be inserted into
- * (values separated with commas) */
- char **rows; /* each row hold string of one row to be inserted
- * (values separated with commas) */
- long rec_num, /* actual number of rows in structure */
- rec_size; /* approx. size of a real insert string */
- long size_limit, /* size and # of records limit which trigger */
- record_limit; /* real insert; zero means unlimitted */
-} edg_wll_bufInsert;
-
-
-void edg_wll_DBClose(edg_wll_Context);
-
-
-/* Parse and execute SQL statement. Returns number of rows selected, created
- * or affected by update, or -1 on error */
-
-int edg_wll_ExecStmt(
- edg_wll_Context, /* INOUT: */
- char *, /* IN: SQL statement */
- edg_wll_Stmt * /* OUT: statement handle. Usable for select only */
-);
-
-
-/* Fetch next row of select statement.
- * All columns are returned as fresh allocated strings
- *
- * return values:
- * >0 - number of fields of the retrieved row
- * 0 - no more rows
- * -1 - error
- *
- * Errors are stored in context passed to previous edg_wll_ExecStmt() */
-
-int edg_wll_FetchRow(
- edg_wll_Stmt, /* IN: statement */
- char ** /* OUT: array of fetched values.
- * As number of columns is fixed and known,
- * expects allocated array of pointers here */
-);
-
-/* Retrieve column names of a query statement */
-
-int edg_wll_QueryColumns(
- edg_wll_Stmt, /* IN: statement */
- char ** /* OUT: result set column names. Expects allocated array. */
-);
-
-/* Free the statement structure */
-
-void edg_wll_FreeStmt(
- edg_wll_Stmt * /* INOUT: statement */
-);
-
-
-/**
- * convert time_t into database-specific time string
- *
- * returns pointer to dynamic area which should be freed
- */
-char *edg_wll_TimeToDB(time_t);
-time_t edg_wll_DBToTime(char *);
-
-extern edg_wll_ErrorCode edg_wll_Open(edg_wll_Context ctx, char *cs);
-
-/**
- * Check database version.
- */
-int edg_wll_DBCheckVersion(edg_wll_Context, const char *);
-
-int edg_wll_Transaction(edg_wll_Context ctx);
-int edg_wll_Commit(edg_wll_Context ctx);
-int edg_wll_Rollback(edg_wll_Context ctx);
-
-/**
- * Init data structure for buffered insert
- *
- * takes table_name and columns string for future multirow insert
- * when insert string oversize size_limit or number of rows to be inserted
- * overcome record_limit, the real insert is triggered
- */
-edg_wll_ErrorCode edg_wll_bufferedInsertInit(edg_wll_Context ctx, edg_wll_bufInsert *bi, void *mysql, char *table_name, long size_limit, long record_limit, char * columns);
-
-/**
- * adds row of n values into n columns into an insert buffer
- * if num. of rows or size of data oversteps the limits, real
- * multi-row insert is done
- */
-edg_wll_ErrorCode edg_wll_bufferedInsert(edg_wll_bufInsert *bi, char *row);
-
-/**
- * flush buffered data and free bi structure
- */
-edg_wll_ErrorCode edg_wll_bufferedInsertClose(edg_wll_bufInsert *bi);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* GLITE_LB_LBS_DB_H */
#include <errno.h>
#include "glite/jobid/strmd5.h"
+#include "glite/lbu/trio.h"
#include "glite/lb/context-int.h"
#include "index.h"
-#include "lbs_db.h"
#include "jobstat.h"
+#include "db_supp.h"
#ifdef LB_PERF
#include "glite/lb/lb_perftest.h"
}
edg_wll_InitContext(&ctx);
+ glite_lbu_InitDBContext(&ctx->dbctx);
+ if (!dbstring) dbstring = DEFAULTCS;
if (edg_wll_Open(ctx,dbstring)) do_exit(ctx,EX_UNAVAILABLE);
- if (edg_wll_DBCheckVersion(ctx,dbstring)) do_exit(ctx,EX_SOFTWARE);
+ if ((ctx->dbcaps = glite_lbu_DBQueryCaps(ctx->dbctx)) == -1) do_exit(ctx, EX_SOFTWARE);
+ if (!(ctx->dbcaps & GLITE_LBU_DB_CAP_INDEX)) {
+ edg_wll_SetError(ctx, EDG_WLL_ERROR_DB_CALL, "index capability not available");
+ do_exit(ctx, EX_SOFTWARE);
+ }
if (edg_wll_QueryJobIndices(ctx,&old_indices,&index_names)) do_exit(ctx,EX_SOFTWARE);
if (dump) {
for (i=0; index_names && index_names[i]; i++) {
asprintf(&stmt,"alter table states drop index `%s`",index_names[i]);
if (verbose) putchar('.');
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE);
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE);
free(stmt);
}
if (verbose) puts(" done");
char *cname = edg_wll_QueryRecToColumn(old_indices[i]);
asprintf(&stmt,"alter table states drop column `%s`",cname);
if (verbose) putchar('.');
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE);
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE);
free(stmt);
free(cname);
}
}
if (really) {
asprintf(&stmt,"alter table states drop index `%s`",index_names[drop_indices[i]]);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE);
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE);
free(stmt);
}
if (verbose) puts(really ? "done" : "");
if (verbose) printf("\t%s\n",cname);
if (really) {
asprintf(&stmt,"alter table states drop column `%s`",cname);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE);
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE);
free(stmt);
}
free(cname);
if (really) {
char *ctype = db_col_type(new_columns[i]);
asprintf(&stmt,"alter table states add `%s` %s",cname,ctype);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE);
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE);
free(stmt);
}
memcpy(&added_icols[nadd_icols].qrec, new_columns[i], sizeof(edg_wll_QueryRec));
if (really) {
asprintf(&stmt,"create index `%s` on states(%s)",n,l);
free(n); free(l);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE);
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE);
free(stmt);
}
if (verbose) puts(really ? "done" : "");
}
+ edg_wll_Close(ctx);
+
return 0;
}
edg_wll_Error(ctx,&et,&ed);
fprintf(stderr,"edg-bkindex: %s (%s)\n",et,ed);
+ edg_wll_Close(ctx);
+ edg_wll_FreeContext(ctx);
exit(code);
}
edg_wll_ErrorCode edg_wll_RefreshIColumns(edg_wll_Context ctx, void *job_index_cols) {
- edg_wll_Stmt sh, sh2;
+ glite_lbu_Statement sh;
int njobs, ret = -1;
intJobStat *stat;
edg_wlc_JobId jobid;
edg_wll_ResetError(ctx);
if (!job_index_cols) return 0;
- if ((njobs = edg_wll_ExecStmt(ctx, "select s.jobid,s.int_status,s.seq,s.version,j.dg_jobid"
+ if ((njobs = edg_wll_ExecSQL(ctx, "select s.jobid,s.int_status,s.seq,s.version,j.dg_jobid"
" from states s, jobs j where s.jobid=j.jobid",&sh)) < 0) {
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
return edg_wll_Error(ctx, NULL, NULL);
}
- while ((ret=edg_wll_FetchRow(sh,res)) >0) {
+ while ((ret=edg_wll_FetchRow(ctx,sh,sizeof(res)/sizeof(res[0]),NULL,res)) >0) {
if (strcmp(res[3], INTSTAT_VERSION)) {
stat = NULL;
if (!edg_wlc_JobIdParse(res[4], &jobid)) {
if (rest == NULL) stat = NULL;
}
if (stat == NULL) {
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
return edg_wll_SetError(ctx, EDG_WLL_ERROR_SERVER_RESPONSE,
"cannot decode int_status from states DB table");
}
edg_wll_IColumnsSQLPart(ctx, job_index_cols, stat, 0, NULL, &icvalues);
trio_asprintf(&stmt, "update states set seq=%s%s where jobid='%|Ss'", res[2], icvalues, res[0]);
- ret = edg_wll_ExecStmt(ctx, stmt, &sh2);
- edg_wll_FreeStmt(&sh2);
+ ret = edg_wll_ExecSQL(ctx, stmt, NULL);
for (i = 0; i < 5; i++) free(res[i]);
destroy_intJobStat(stat); free(stat);
if (ret < 0) return edg_wll_Error(ctx, NULL, NULL);
}
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
return edg_wll_Error(ctx, NULL, NULL);
}
#include "lb_http.h"
#include "lb_proto.h"
#include "index.h"
-#include "lbs_db.h"
#include "lb_authz.h"
#include "il_notification.h"
#include "stats.h"
#include "db_calls.h"
+#include "db_supp.h"
#ifdef GLITE_LB_SERVER_WITH_WS
# if GSOAP_VERSION < 20700
static int hardEventsLimit = 0;
static int hardRespSizeLimit = 0;
static char *dbstring = NULL,*fake_host = NULL;
-int transactions = -1, use_transactions = -1;
+int transactions = -1;
+int use_dbcaps = 0;
static int fake_port = 0;
static char **super_users = NULL;
static int slaves = 10,
#ifdef GLITE_LB_SERVER_WITH_WS
struct soap *soap;
#endif /* GLITE_LB_SERVER_WITH_WS */
- int use_transactions;
- void *mysql;
+ glite_lbu_DBContext dbctx;
+ int dbcaps;
edg_wll_QueryRec **job_index;
edg_wll_IColumnRec *job_index_cols;
int mode;
/* Just check the database and let it be. The slaves do the job. */
edg_wll_InitContext(&ctx);
+ glite_lbu_InitDBContext(&ctx->dbctx);
wait_for_open(ctx, dbstring);
- if (edg_wll_DBCheckVersion(ctx, dbstring))
+ if ((ctx->dbcaps = glite_lbu_DBQueryCaps(ctx->dbctx)) == -1)
{
char *et,*ed;
- edg_wll_Error(ctx,&et,&ed);
+ glite_lbu_DBError(ctx->dbctx,&et,&ed);
fprintf(stderr,"%s: open database: %s (%s)\n",argv[0],et,ed);
+ free(et); free(ed);
return 1;
}
+ edg_wll_Close(ctx);
+ ctx->dbctx = NULL;
fprintf(stderr, "[%d]: DB '%s'\n", getpid(), dbstring);
- if (count_statistics) edg_wll_InitStatistics(ctx);
- if (!ctx->use_transactions && transactions != 0) {
- fprintf(stderr, "[%d]: transactions aren't supported!\n", getpid());
+
+ if ((ctx->dbcaps & GLITE_LBU_DB_CAP_INDEX) == 0) {
+ fprintf(stderr,"%s: missing index support in DB layer\n",argv[0]);
+ return 1;
}
+ if ((ctx->dbcaps & GLITE_LBU_DB_CAP_TRANSACTIONS) == 0)
+ fprintf(stderr, "[%d]: transactions aren't supported!\n", getpid());
if (transactions >= 0) {
- fprintf(stderr, "[%d]: transactions forced from %d to %d\n", getpid(), ctx->use_transactions, transactions);
- ctx->use_transactions = transactions;
+ fprintf(stderr, "[%d]: transactions forced from %d to %d\n", getpid(), ctx->dbcaps & GLITE_LBU_DB_CAP_TRANSACTIONS ? 1 : 0, transactions);
+ ctx->dbcaps &= ~GLITE_LBU_DB_CAP_TRANSACTIONS;
+ ctx->dbcaps |= transactions ? GLITE_LBU_DB_CAP_TRANSACTIONS : 0;
}
- use_transactions = ctx->use_transactions;
- edg_wll_Close(ctx);
+ use_dbcaps = ctx->dbcaps;
+
+ if (count_statistics) edg_wll_InitStatistics(ctx);
edg_wll_FreeContext(ctx);
if ( !debug ) {
dprintf(("[%d] opening database ...\n", getpid()));
wait_for_open(ctx, dbstring);
- cdata->mysql = ctx->mysql;
- cdata->use_transactions = ctx->use_transactions;
+ glite_lbu_DBSetCaps(ctx->dbctx, use_dbcaps);
+ cdata->dbctx = ctx->dbctx;
+ cdata->dbcaps = use_dbcaps;
if ( edg_wll_QueryJobIndices(ctx, &job_index, NULL) )
{
*/
ctx->serverRunning = cdata->mode & SERVICE_SERVER;
ctx->proxyRunning = cdata->mode & SERVICE_PROXY;
- ctx->mysql = cdata->mysql;
- ctx->use_transactions = cdata->use_transactions;
+ ctx->dbctx = cdata->dbctx;
+ ctx->dbcaps = cdata->dbcaps;
ctx->job_index_cols = cdata->job_index_cols;
ctx->job_index = cdata->job_index;
*/
ctx->serverRunning = cdata->mode & SERVICE_SERVER;
ctx->proxyRunning = cdata->mode & SERVICE_PROXY;
- ctx->mysql = cdata->mysql;
+ ctx->dbctx = cdata->dbctx;
+ ctx->dbcaps = cdata->dbcaps;
/* set globals
*/
char *errt,*errd;
if (dbfail_string1) free(dbfail_string1);
- edg_wll_Error(ctx,&errt,&errd);
+ glite_lbu_DBError(ctx->dbctx,&errt,&errd);
asprintf(&dbfail_string1,"%s (%s)\n",errt,errd);
if (dbfail_string1 != NULL) {
if (dbfail_string2 == NULL || strcmp(dbfail_string1,dbfail_string2)) {
dprintf(("[%d]: DB connection established\n",getpid()));
if (!debug) syslog(LOG_INFO,"DB connection established\n");
}
-
- ctx->use_transactions = use_transactions;
}
static void free_hostent(struct hostent *h){
#include "glite/lb/context-int.h"
-#include "lbs_db.h"
#include "db_calls.h"
+# include "db_supp.h"
/** Returns bitmask of job membership in common server/proxy database
*/
{
char *dbjob;
char *stmt = NULL;
- edg_wll_Stmt q;
+ glite_lbu_Statement q;
int ret, result = -1;
char *res[2] = { NULL, NULL};
dbjob = edg_wlc_JobIdGetUnique(job);
trio_asprintf(&stmt,"select proxy,server from jobs where jobid = '%|Ss'",dbjob);
- ret = edg_wll_ExecStmt(ctx,stmt,&q);
+ ret = edg_wll_ExecSQL(ctx,stmt,&q);
if (ret <= 0) {
if (ret == 0) {
fprintf(stderr,"%s: no such job\n",dbjob);
}
free(stmt); stmt = NULL;
- if ((ret = edg_wll_FetchRow(q,res)) > 0) {
+ if ((ret = edg_wll_FetchRow(ctx,q,sizeof(res)/sizeof(res[0]),NULL,res)) > 0) {
result = 0;
if (strcmp(res[0],"0")) result += DB_PROXY_JOB;
if (strcmp(res[1],"0")) result += DB_SERVER_JOB;
edg_wll_SetError(ctx,ENOENT,dbjob);
}
}
- edg_wll_FreeStmt(&q);
+ glite_lbu_FreeStmt(&q);
clean:
free(res[0]); free(res[1]);
#include "glite/lb/lb_maildir.h"
#include "purge.h"
#include "store.h"
-#include "lbs_db.h"
#include "lock.h"
#include "il_lbproxy.h"
#include "jobstat.h"
--- /dev/null
+#include <stdlib.h>
+#include <errno.h>
+
+#include "glite/lbu/db.h"
+#include "glite/lb/context-int.h"
+
+int edg_wll_SetErrorDB(edg_wll_Context ctx) {
+ int code;
+ char *ed;
+
+ if (ctx->dbctx) {
+ code = glite_lbu_DBError(ctx->dbctx, NULL, &ed);
+ edg_wll_SetError(ctx, code, ed);
+ free(ed);
+ } else {
+ code = EINVAL;
+ edg_wll_SetError(ctx, EINVAL, "DB context isn't created");
+ }
+
+ return code;
+}
+
+
+int edg_wll_ExecSQL(edg_wll_Context ctx, const char *cmd, glite_lbu_Statement *stmt) {
+ int retval;
+
+ if ((retval = glite_lbu_ExecSQL(ctx->dbctx, cmd, stmt)) < 0) edg_wll_SetErrorDB(ctx);
+ return retval;
+}
+
+
+int edg_wll_FetchRow(edg_wll_Context ctx, glite_lbu_Statement stmt, unsigned int n, unsigned long *lengths, char **results) {
+ int retval;
+
+ if ((retval = glite_lbu_FetchRow(stmt, n, lengths, results)) < 0) edg_wll_SetErrorDB(ctx);
+ return retval;
+}
+
+int edg_wll_bufferedInsertInit(edg_wll_Context ctx, glite_lbu_bufInsert *bi, const char *table_name, long size_limit, long record_limit, const char *columns) {
+ int retval;
+
+ if ((retval = glite_lbu_bufferedInsertInit(ctx->dbctx, bi, table_name, size_limit, record_limit, columns)) != 0) edg_wll_SetErrorDB(ctx);
+ return retval;
+}
+
+int edg_wll_bufferedInsert(edg_wll_Context ctx, glite_lbu_bufInsert bi, const char *row) {
+ int retval;
+
+ if ((retval = glite_lbu_bufferedInsert(bi, row)) != 0) edg_wll_SetErrorDB(ctx);
+ return retval;
+}
+
+int edg_wll_bufferedInsertClose(edg_wll_Context ctx, glite_lbu_bufInsert bi) {
+ int retval;
+
+ if ((retval = glite_lbu_bufferedInsertClose(bi)) != 0) edg_wll_SetErrorDB(ctx);
+ return retval;
+}
+
+int edg_wll_Transaction(edg_wll_Context ctx) {
+ int retval;
+
+ if ((retval = glite_lbu_Transaction(ctx->dbctx)) != 0) edg_wll_SetErrorDB(ctx);
+ return retval;
+}
+
+int edg_wll_Commit(edg_wll_Context ctx) {
+ int retval;
+
+ if ((retval = glite_lbu_Commit(ctx->dbctx)) != 0) edg_wll_SetErrorDB(ctx);
+ return retval;
+}
+
+int edg_wll_Rollback(edg_wll_Context ctx) {
+ int retval;
+
+ if ((retval = glite_lbu_Rollback(ctx->dbctx)) != 0) edg_wll_SetErrorDB(ctx);
+ return retval;
+}
--- /dev/null
+#ifndef EDG_WLL_DB_SUPP_H
+#define EDG_WLL_DB_SUPP_H
+
+#ident "$Header:"
+
+#include "glite/lbu/db.h"
+
+#define DEFAULTCS "lbserver/@localhost:lbserver20"
+
+/**
+ * Set the current database error.
+ */
+int edg_wll_SetErrorDB(edg_wll_Context ctx);
+
+int edg_wll_ExecSQL(edg_wll_Context ctx, const char *cmd, glite_lbu_Statement *stmt);
+int edg_wll_FetchRow(edg_wll_Context ctx, glite_lbu_Statement stmt, unsigned int n, unsigned long *lengths, char **results);
+
+int edg_wll_bufferedInsertInit(edg_wll_Context ctx, glite_lbu_bufInsert *bi, const char *table_name, long size_limit, long record_limit, const char *columns);
+int edg_wll_bufferedInsert(edg_wll_Context ctx, glite_lbu_bufInsert bi, const char *row);
+int edg_wll_bufferedInsertClose(edg_wll_Context ctx, glite_lbu_bufInsert bi);
+
+int edg_wll_Transaction(edg_wll_Context ctx);
+int edg_wll_Commit(edg_wll_Context ctx);
+int edg_wll_Rollback(edg_wll_Context ctx);
+
+#endif
#include "glite/lb/events_parse.h"
#include "glite/lb/ulm_parse.h"
-#include "lbs_db.h"
#include "query.h"
#include "get_events.h"
#include "server_state.h"
#include "purge.h"
+#include "db_supp.h"
static char *time_to_string(time_t t, char **ptr);
static int handle_specials(edg_wll_Context,time_t *);
char *from_s, *to_s, *stmt, *time_s, *ptr;
char *tmpfname;
time_t start,end;
- edg_wll_Stmt q = NULL;
+ glite_lbu_Statement q = NULL;
char *res[10];
int event;
edg_wll_Event e;
return edg_wll_Error(ctx,NULL,NULL);
}
- from_s = strdup(edg_wll_TimeToDB(from));
- to_s = strdup(edg_wll_TimeToDB(to));
+ glite_lbu_TimeToDB(from, &from_s);
+ glite_lbu_TimeToDB(to, &to_s);
trio_asprintf(&stmt,
"select event,dg_jobid,code,prog,host,u.cert_subj,time_stamp,usec,level,arrived "
ctx->srvName,ctx->srvPort,
from_s,to_s);
- if (edg_wll_ExecStmt(ctx,stmt,&q) < 0) goto clean;
+ if (edg_wll_ExecSQL(ctx,stmt,&q) < 0) goto clean;
- while ((ret = edg_wll_FetchRow(q,res)) > 0) {
+ while ((ret = edg_wll_FetchRow(ctx,q,sizeof(res)/sizeof(res[0]),NULL,res)) > 0) {
assert(ret == sizofa(res));
event = atoi(res[0]); free(res[0]); res[0] = NULL;
clean:
edg_wll_FreeEvent(&e);
- edg_wll_FreeStmt(&q);
+ glite_lbu_FreeStmt(&q);
free(stmt);
free(from_s);
case ENOENT: *t = 0;
edg_wll_ResetError(ctx);
break;
- case 0: *t = edg_wll_DBToTime(time_s);
+ case 0: *t = glite_lbu_DBToTime(time_s);
assert(*t >= 0);
break;
default: break;
static char *time_to_string(time_t t, char **ptr) {
char *s;
- s = edg_wll_TimeToDB(t);
+ glite_lbu_TimeToDB(t, &s);
s[strlen(s) - 1] = '\0';
*ptr = s;
#include "get_events.h"
#include "glite/lb/context-int.h"
#include "glite/lb/events_parse.h"
+#include "db_supp.h"
static void edg_wll_set_event_field(edg_wll_Event *,char *,char *);
static void edg_wll_set_event_field_warn(edg_wll_Event *,char *,char *);
{
char *jobid = edg_wlc_JobIdGetUnique(e->any.jobId),
*q = NULL,*nameval[2];
- edg_wll_Stmt sh;
+ glite_lbu_Statement sh;
int ret,t;
const char *tables[] = { "short_fields","long_fields" };
"where jobid = '%|Ss' and event = %d ",
tables[t],jobid,n);
- if ((ret=edg_wll_ExecStmt(ctx,q,&sh)) < 0) goto cleanup;
+ if ((ret=edg_wll_ExecSQL(ctx,q,&sh)) < 0) goto cleanup;
- while ((ret=edg_wll_FetchRow(sh,nameval)) > 0) {
+ while ((ret=edg_wll_FetchRow(ctx,sh,sizeof(nameval)/sizeof(nameval[0]),NULL,nameval)) > 0) {
edg_wll_set_event_field(e,nameval[0],nameval[1]);
free(nameval[0]);
/* XXX: nameval[1] freed in edg_wll_set_event_field
}
if (ret<0) goto cleanup;
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
free(q); q=NULL;
}
ret=edg_wll_CheckEvent(ctx,e);
cleanup:
- if (sh) edg_wll_FreeStmt(&sh);
+ if (sh) glite_lbu_FreeStmt(&sh);
free(jobid);
free(q);
#include "glite/lb/events.h"
#include "glite/lb/query_rec.h"
-/* Internal functions for getting event sets from the LB database */
-#include "lbs_db.h"
-
#ifdef __cplusplus
extern "C" {
#endif
#include <assert.h>
#include <errno.h>
+#include "glite/lbu/db.h"
#include "glite/lb/context-int.h"
-#include "lbs_db.h"
#include "index.h"
extern int debug;
int edg_wll_QueryJobIndices(edg_wll_Context ctx,edg_wll_QueryRec *** index_out,char ***keys_out)
{
edg_wll_QueryRec **idx = NULL;
- edg_wll_Stmt stmt = NULL;
-
- int i,j,ret;
static const char *built_in_indices[] = {
"PRIMARY",
NULL
};
-/* XXX: "show index from" columns. Matches at least MySQL 4.0.11 */
-
- char *showcol[12];
- int Key_name,Seq_in_index,Column_name,Sub_part;
-
char **keys = NULL;
int *cols = NULL;
- char **col_names = NULL;
+ char ***column_names = NULL;
+ int i, j;
int nkeys = 0;
- Key_name = Seq_in_index = Column_name = Sub_part = -1;
-
- if (edg_wll_ExecStmt(ctx,"show index from states",&stmt)<0)
- return edg_wll_Error(ctx,NULL,NULL);
- while ((ret = edg_wll_FetchRow(stmt,showcol))) {
- if (ret < 0) return edg_wll_Error(ctx,NULL,NULL);
- assert(ret <= sizeof showcol/sizeof showcol[0]);
-
- if (!col_names) {
- col_names = malloc(ret * sizeof col_names[0]);
- edg_wll_QueryColumns(stmt,col_names);
- for (i=0; i<ret; i++)
- if (!strcasecmp(col_names[i],"Key_name")) Key_name = i;
- else if (!strcasecmp(col_names[i],"Seq_in_index")) Seq_in_index = i;
- else if (!strcasecmp(col_names[i],"Column_name")) Column_name = i;
- else if (!strcasecmp(col_names[i],"Sub_part")) Sub_part = i;
-
- assert(Key_name >= 0 && Seq_in_index >= 0 &&
- Column_name >= 0 && Sub_part >= 0);
+ if (glite_lbu_QueryIndices(ctx->dbctx, "states", &keys, &column_names) != 0) {
+ edg_wll_SetErrorDB(ctx);
+ return -1;
+ }
+ for (i = 0; keys[i]; i++) {
+ // skip builtin indices
+ for (j = 0; built_in_indices[j]; j++) {
+ if (strcasecmp(keys[i], built_in_indices[j]) == 0)
+ goto next_index;
}
+ cols = realloc(cols,(nkeys+1) * sizeof cols[0]);
+ cols[nkeys] = 0;
+ idx = realloc(idx,(nkeys+2) * sizeof idx[0]);
+ idx[nkeys] = idx[nkeys+1] = NULL;
- for (j=0; built_in_indices[j]; j++) {
- if (strcasecmp(showcol[Key_name],built_in_indices[j]) == 0) {
- for (i=0; i<ret; i++) free(showcol[i]);
- goto continue_fetch_index;
+ for (j = 0; column_names[i][j]; j++) {
+ if (cols[nkeys] <= j) {
+ cols[nkeys] = j+1;
+ idx[nkeys] = realloc(idx[nkeys],(j+2)*sizeof idx[nkeys][0]);
+ memset(&idx[nkeys][j+1],0,sizeof idx[nkeys][0]);
}
- }
- for (i=0; i<nkeys && strcasecmp(showcol[Key_name],keys[i]); i++);
-
- if (i == nkeys) {
- keys = realloc(keys,(i+2) * sizeof keys[0]);
- keys[i] = showcol[Key_name];
- keys[i+1] = NULL;
- cols = realloc(cols,(i+1) * sizeof cols[0]);
- cols[i] = 0;
- idx = realloc(idx,(i+2) * sizeof idx[0]);
- idx[i] = idx[i+1] = NULL;
- showcol[Key_name] = NULL;
- nkeys++;
- }
-
- j = atoi(showcol[Seq_in_index])-1;
- if (cols[i] <= j) {
- cols[i] = j+1;
- idx[i] = realloc(idx[i],(j+2)*sizeof idx[i][0]);
- memset(&idx[i][j+1],0,sizeof idx[i][0]);
- }
-
- if (edg_wll_ColumnToQueryRec(showcol[Column_name],&idx[i][j])) {
- char ed[300];
- sprintf(ed,"%s(%s): unsupported column",keys[i],showcol[Column_name]);
- return edg_wll_SetError(ctx,EINVAL,ed);
+ if (edg_wll_ColumnToQueryRec(column_names[i][j],&idx[nkeys][j])) {
+ int code;
+ char *ed;
+
+ asprintf(&ed, "%s(%s): unsupported column", keys[i], column_names[i][j]);
+ code = edg_wll_SetError(ctx, EINVAL, ed);
+ free(ed);
+ return code;
+ }
+#warning: TODO: needed Sub_part in value???
+// else idx[nkeys][j].value.i = atoi(showcol[Sub_part]);
}
- else idx[i][j].value.i = atoi(showcol[Sub_part]);
-
- for (i=0; i<ret; i++) free(showcol[i]);
-continue_fetch_index:
- // just for escaping from nested cycles
- ; /* prevent compiler to complain */
+ nkeys++;
+next_index:
+ for (j = 0; column_names[i][j]; j++) free(column_names[i][j]);
+ free(column_names[i]);
+ column_names[i] = NULL;
+ // just for escaping from nested cycles
+ ; /* prevent compiler to complain */
}
- edg_wll_FreeStmt(&stmt);
free(cols);
- free(col_names);
if (keys_out) *keys_out = keys;
else {
for (i=0; i<nkeys; i++) free(keys[i]);
#include "glite/lb/context-int.h"
-#include "lbs_db.h"
#include "index.h"
#define yyerror(x) {}
#include "store.h"
#include "lock.h"
#include "index.h"
-#include "lbs_db.h"
#include "jobstat.h"
#include "lb_authz.h"
#include "stats.h"
+#include "db_supp.h"
#define DAG_ENABLE 1
char *stat_str, *s_out;
intJobStat *js;
char *out[1];
- edg_wll_Stmt sh;
+ glite_lbu_Statement sh;
int num_sub, num_f, i, ii;
edg_wll_ResetError(ctx);
" AND version='%|Ss'",
md5_jobid, INTSTAT_VERSION);
if (stmt != NULL) {
- num_sub = edg_wll_ExecStmt(ctx, stmt, &sh);
+ num_sub = edg_wll_ExecSQL(ctx, stmt, &sh);
if (num_sub >=0 ) {
i = 0;
stat->children_states = calloc(num_sub+1, sizeof(edg_wll_JobStat));
if (stat->children_states == NULL) {
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
goto dag_enomem;
}
- while ((num_f = edg_wll_FetchRow(sh, &stat_str)) == 1
+ while ((num_f = edg_wll_FetchRow(ctx, sh, 1, NULL, &stat_str)) == 1
&& i < num_sub) {
js = dec_intJobStat(stat_str, &s_out);
if (s_out != NULL && js != NULL) {
}
free(stat_str);
}
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
}
free(stmt);
} else goto dag_enomem;
md5_jobid, INTSTAT_VERSION);
out[1] = NULL;
if (stmt != NULL) {
- num_sub = edg_wll_ExecStmt(ctx, stmt, &sh);
+ num_sub = edg_wll_ExecSQL(ctx, stmt, &sh);
if (num_sub >=0 ) {
- while ((num_f = edg_wll_FetchRow(sh, out)) == 1 ) {
+ while ((num_f = edg_wll_FetchRow(ctx, sh, sizeof(out)/sizeof(out[0]), NULL, out)) == 1 ) {
num_f = atoi(out[0]);
if (num_f > EDG_WLL_JOB_UNDEF && num_f < EDG_WLL_NUMBER_OF_STATCODES)
stat->children_hist[num_f+1]++;
free(out[0]);
}
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
}
free(stmt);
} else goto dag_enomem;
"WHERE s.parent_job='%|Ss' AND s.version='%|Ss' AND s.jobid=j.jobid",
md5_jobid, INTSTAT_VERSION);
if (stmt != NULL) {
- num_sub = edg_wll_ExecStmt(ctx, stmt, &sh);
+ num_sub = edg_wll_ExecSQL(ctx, stmt, &sh);
if (num_sub >=0 ) {
- while (edg_wll_FetchRow(sh, out) == 1 ) {
+ while (edg_wll_FetchRow(ctx, sh, sizeof(out)/sizeof(out[0]), NULL, out) == 1 ) {
add_stringlist(&stat->children, out[0]);
free(out[0]);
}
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
}
free(stmt);
} else goto dag_enomem;
static char *job_owner(edg_wll_Context ctx,char *md5_jobid)
{
char *stmt = NULL,*out = NULL;
- edg_wll_Stmt sh;
+ glite_lbu_Statement sh;
int f = -1;
edg_wll_ResetError(ctx);
edg_wll_SetError(ctx,ENOMEM, NULL);
return NULL;
}
- if (edg_wll_ExecStmt(ctx,stmt,&sh) >= 0) {
- f=edg_wll_FetchRow(sh,&out);
+ if (edg_wll_ExecSQL(ctx,stmt,&sh) >= 0) {
+ f=edg_wll_FetchRow(ctx,sh,1,NULL,&out);
if (f == 0) {
if (out) free(out);
out = NULL;
edg_wll_SetError(ctx,ENOENT,md5_jobid);
}
}
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
free(stmt);
return out;
"(jobid,seq,name,value) values "
"('%|Ss',%d,'%|Ss','%|Ss')",
jobid_md5, seq, (*tagp).tag, (*tagp).value);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) {
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) {
if (EEXIST == edg_wll_Error(ctx, NULL, NULL)) {
/* XXX: this should not happen */
edg_wll_ResetError(ctx);
jobid_md5);
free(icvalues);
- if ((dbret = edg_wll_ExecStmt(ctx,stmt,NULL)) < 0) goto cleanup;
+ if ((dbret = edg_wll_ExecSQL(ctx,stmt,NULL)) < 0) goto cleanup;
if (dbret == 0) {
edg_wll_IColumnsSQLPart(ctx, ctx->job_index_cols, stat, 1, &icnames, &icvalues);
INTSTAT_VERSION, parent_md5, icvalues);
free(icnames); free(icvalues);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) goto cleanup;
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto cleanup;
}
if (update) {
trio_asprintf(&stmt, "delete from states "
"where jobid ='%|Ss' and ( seq<%d or version !='%|Ss')",
jobid_md5, seq, INTSTAT_VERSION);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) goto cleanup;
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto cleanup;
}
if (update) {
trio_asprintf(&stmt, "delete from status_tags "
"where jobid ='%|Ss' and seq<%d", jobid_md5, seq);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) goto cleanup;
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto cleanup;
}
cleanup:
edg_wlc_JobId jobid,
char *icnames,
char *values,
- edg_wll_bufInsert *bi)
+ glite_lbu_bufInsert *bi)
{
char *stmt = NULL;
"values (%s)",
icnames, values);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) goto cleanup;
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto cleanup;
#endif
cleanup:
{
char *jobid_md5;
char *stmt;
- edg_wll_Stmt sh;
+ glite_lbu_Statement sh;
char *res, *res_rest;
int nstates;
return edg_wll_SetError(ctx, ENOMEM, NULL);
}
- if ((nstates = edg_wll_ExecStmt(ctx,stmt,&sh)) < 0) goto cleanup;
+ if ((nstates = edg_wll_ExecSQL(ctx,stmt,&sh)) < 0) goto cleanup;
if (nstates == 0) {
edg_wll_SetError(ctx,ENOENT,"no state in DB");
goto cleanup;
}
- if (edg_wll_FetchRow(sh,&res) < 0) goto cleanup;
+ if (edg_wll_FetchRow(ctx,sh,1,NULL,&res) < 0) goto cleanup;
*stat = dec_intJobStat(res, &res_rest);
if (res_rest == NULL) {
free(res);
cleanup:
free(jobid_md5);
- free(stmt); edg_wll_FreeStmt(&sh);
+ free(stmt); glite_lbu_FreeStmt(&sh);
return edg_wll_Error(ctx,NULL,NULL);
}
{
char *stmt = NULL,*out = NULL, *rest = NULL;
- edg_wll_Stmt sh;
+ glite_lbu_Statement sh;
int f = -1, i;
char *jobid_md5;
intJobStat *ijs = NULL;
return edg_wll_SetError(ctx,ENOMEM, NULL);
}
- if (edg_wll_ExecStmt(ctx,stmt,&sh) >= 0) {
- f=edg_wll_FetchRow(sh,&out);
+ if (edg_wll_ExecSQL(ctx,stmt,&sh) >= 0) {
+ f=edg_wll_FetchRow(ctx,sh,1,NULL,&out);
if (f == 0) {
if (out) free(out);
out = NULL;
for (i=0;i<=EDG_WLL_NUMBER_OF_STATCODES;i++) hist[i] = ijs->pub.children_hist[i];
}
}
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
free(stmt);
if (rest==NULL) free(rest);
if (ijs==NULL) free(rest);
//printf ("\n\n\n Would like to run SQL statament: %s\n\n\n\n", stmt);
- if ((dbret = edg_wll_ExecStmt(ctx,stmt,NULL)) < 0) goto cleanup;
+ if ((dbret = edg_wll_ExecSQL(ctx,stmt,NULL)) < 0) goto cleanup;
assert(dbret); /* update should come through OK as the record exists */
#ident "$Header$"
#include "glite/lb/jobstat.h"
-#include "lbs_db.h"
/*
* Internal representation of job state
edg_wll_ErrorCode edg_wll_RefreshIColumns(edg_wll_Context, void *);
int edg_wll_intJobStatus( edg_wll_Context, const edg_wlc_JobId, int, intJobStat *, int);
edg_wll_ErrorCode edg_wll_StoreIntState(edg_wll_Context, intJobStat *, int);
-edg_wll_ErrorCode edg_wll_StoreIntStateEmbryonic(edg_wll_Context, edg_wlc_JobId, char *icnames, char *values, edg_wll_bufInsert *bi);
+edg_wll_ErrorCode edg_wll_StoreIntStateEmbryonic(edg_wll_Context, edg_wlc_JobId, char *icnames, char *values, glite_lbu_bufInsert *bi);
edg_wll_ErrorCode edg_wll_LoadIntState(edg_wll_Context , edg_wlc_JobId , int, intJobStat **);
edg_wll_ErrorCode edg_wll_StepIntStateParent(edg_wll_Context,edg_wlc_JobId,edg_wll_Event *,int,intJobStat *,edg_wll_JobStat *);
#include "glite/jobid/cjobid.h"
#include "glite/lbu/trio.h"
+#include "glite/lbu/db.h"
#include "glite/lb/context-int.h"
#include "store.h"
#include "index.h"
-#include "lbs_db.h"
#include "jobstat.h"
#include "get_events.h"
break;
case EDG_WLL_QUERY_ATTR_TIME:
if (stat->pub.stateEnterTimes)
- data = strdup(edg_wll_TimeToDB(stat->pub.stateEnterTimes[
- job_index_cols[i].qrec.attr_id.state+1]));
+ glite_lbu_TimeToDB(stat->pub.stateEnterTimes[job_index_cols[i].qrec.attr_id.state+1], &data);
else data = strdup("0");
break;
case EDG_WLL_QUERY_ATTR_RESUBMITTED:
#include "glite/jobid/strmd5.h"
#include "glite/jobid/cjobid.h"
#include "glite/lbu/trio.h"
-#include "lbs_db.h"
+#include "db_supp.h"
/* XXX should be defined in gridsite-gacl.h */
GRSTgaclEntry *GACLparseEntry(xmlNodePtr cur);
for ( ; ; )
{
- if ( edg_wll_ExecStmt(ctx, q1, NULL) > 0 )
+ if ( edg_wll_ExecSQL(ctx, q1, NULL) > 0 )
goto end;
if ( edg_wll_Error(ctx,NULL,NULL) != EEXIST )
"update acls set refcnt = refcnt+%d "
"where aclid = '%|Ss'",
incr, aclid);
- if ( edg_wll_ExecStmt(ctx, q2, NULL) < 0 )
+ if ( edg_wll_ExecSQL(ctx, q2, NULL) < 0 )
continue;
goto end;
"where aclid='%|Ss' and refcnt>=%d",
-incr, aclid, -incr);
- if ( edg_wll_ExecStmt(ctx, q1, NULL) > 0 )
+ if ( edg_wll_ExecSQL(ctx, q1, NULL) > 0 )
{
trio_asprintf(&q2,
"delete from acls "
"where aclid='%|Ss' and refcnt=0",
aclid);
- edg_wll_ExecStmt(ctx, q2, NULL);
+ edg_wll_ExecSQL(ctx, q2, NULL);
}
else
{
trio_asprintf(&stmt,
"update jobs set aclid='%|Ss' where jobid='%|Ss' and ISNULL(aclid)",
new_aclid, md5_jobid);
- updated = edg_wll_ExecStmt(ctx, stmt, NULL);
+ updated = edg_wll_ExecSQL(ctx, stmt, NULL);
free(stmt); stmt = NULL;
if (updated > 0)
char *q = NULL;
char *acl_id = NULL;
char *acl_str = NULL;
- edg_wll_Stmt stmt = NULL;
+ glite_lbu_Statement stmt = NULL;
int ret;
GRSTgaclAcl *gacl = NULL;
char *jobstr = edg_wlc_JobIdGetUnique(jobid);
trio_asprintf(&q,
"select aclid from jobs where jobid = '%|Ss'", jobstr);
- if (edg_wll_ExecStmt(ctx, q, &stmt) < 0 ||
- edg_wll_FetchRow(stmt, &acl_id) < 0) {
+ if (edg_wll_ExecSQL(ctx, q, &stmt) < 0 ||
+ edg_wll_FetchRow(ctx, stmt, 1, NULL, &acl_id) < 0) {
goto end;
}
- edg_wll_FreeStmt(&stmt); stmt = NULL;
+ glite_lbu_FreeStmt(&stmt); stmt = NULL;
free(q); q = NULL;
if (acl_id == NULL || *acl_id == '\0') {
trio_asprintf(&q,
"select value from acls where aclid = '%|Ss'", acl_id);
- if (edg_wll_ExecStmt(ctx, q, &stmt) < 0 ||
- edg_wll_FetchRow(stmt, &acl_str) < 0) {
+ if (edg_wll_ExecSQL(ctx, q, &stmt) < 0 ||
+ edg_wll_FetchRow(ctx, stmt, 1, NULL, &acl_str) < 0) {
goto end;
}
end:
if (q) free(q);
- if (stmt) edg_wll_FreeStmt(&stmt);
+ if (stmt) glite_lbu_FreeStmt(&stmt);
if (acl_id) free(acl_id);
if (acl_str) free(acl_str);
/* XXX if (gacl) GRSTgaclAclFree(gacl); */
+++ /dev/null
-#ident "$Header$"
-
-#include "mysql.h" // MySql header file
-#include "mysqld_error.h"
-#include "errmsg.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <time.h>
-#include <assert.h>
-#include <stdarg.h>
-
-#include "glite/lbu/trio.h"
-#include "lbs_db.h"
-#include "glite/lb/context-int.h"
-
-#define my_err() edg_wll_SetError(ctx,EDG_WLL_ERROR_DB_CALL,mysql_error((MYSQL *) ctx->mysql))
-
-struct _edg_wll_Stmt {
- MYSQL_RES *result;
- edg_wll_Context ctx;
-};
-
-
-static edg_wll_ErrorCode db_connect(edg_wll_Context ctx, const char *cs, MYSQL **mysql)
-{
- char *buf = NULL;
- char *host,*user,*pw,*db;
- char *slash,*at,*colon;
-
- if (!cs) cs = DEFAULTCS;
-
- if (!(*mysql = mysql_init(NULL)))
- return edg_wll_SetError(ctx,ENOMEM,NULL);
-
- mysql_options(*mysql, MYSQL_READ_DEFAULT_FILE, "my");
-
- host = user = pw = db = NULL;
-
- buf = strdup(cs);
- slash = strchr(buf,'/');
- at = strrchr(buf,'@');
- colon = strrchr(buf,':');
-
- if (!slash || !at || !colon) {
- free(buf);
- return edg_wll_SetError(ctx,EINVAL,"DB connect string");
- }
-
- *slash = *at = *colon = 0;
- host = at+1;
- user = buf;
- pw = slash+1;
- db = colon+1;
-
- /* ljocha: CLIENT_FOUND_ROWS added to make authorization check
- * working in update_notif().
- * Hope it does not break anything else */
- if (!mysql_real_connect(*mysql,host,user,pw,db,0,NULL,CLIENT_FOUND_ROWS)) {
- free(buf);
- return my_err();
- }
-
- free(buf);
- return edg_wll_ResetError(ctx);
-}
-
-
-static void db_close(MYSQL *mysql) {
- mysql_close(mysql);
-}
-
-
-static int transaction_test(edg_wll_Context ctx, MYSQL *m2) {
- MYSQL *m1;
- char *desc, *cmd_create, *cmd_insert, *cmd_select, *cmd_drop;
- int retval;
- edg_wll_ErrorCode err;
- pid_t pid;
-
- ctx->use_transactions = 1;
- pid = getpid();
-
- asprintf(&cmd_create, "create table test%d (item int) engine='innodb'", pid);
- asprintf(&cmd_insert, "insert into test%d (item) values (1)", pid);
- asprintf(&cmd_select, "select item from test%d", pid);
- asprintf(&cmd_drop, "drop table test%d", pid);
-
- m1 = (MYSQL *)ctx->mysql;
- edg_wll_ExecStmt(ctx, cmd_drop, NULL);
- if (edg_wll_ExecStmt(ctx, cmd_create, NULL) != 0) {
- edg_wll_ResetError(ctx);
- goto err1;
- }
- if (edg_wll_Transaction(ctx) != 0) goto err2;
- if (edg_wll_ExecStmt(ctx, cmd_insert, NULL) != 1) goto err2;
-
- ctx->mysql = (void *)m2;
- if ((retval = edg_wll_ExecStmt(ctx, cmd_select, NULL)) == -1) goto err2;
- ctx->use_transactions = (retval == 0);
-
- ctx->mysql = (void *)m1;
- if (edg_wll_Commit(ctx) != 0) goto err2;
- if (edg_wll_ExecStmt(ctx, cmd_drop, NULL) != 0) goto err1;
-
-#ifdef LBS_DB_PROFILE
- fprintf(stderr, "[%d] use_transactions = %d\n", getpid(), ctx->use_transactions);
-#endif
-
- goto ok;
-err2:
- err = edg_wll_Error(ctx, NULL, &desc);
- edg_wll_ExecStmt(ctx, cmd_drop, NULL);
- edg_wll_SetError(ctx, err, desc);
-err1:
- ctx->use_transactions = 0;
-ok:
- free(cmd_create);
- free(cmd_insert);
- free(cmd_select);
- free(cmd_drop);
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-
-edg_wll_ErrorCode edg_wll_DBConnect(edg_wll_Context ctx, const char *cs)
-{
- return db_connect(ctx, cs, (MYSQL **)&ctx->mysql);
-}
-
-
-void edg_wll_DBClose(edg_wll_Context ctx)
-{
- db_close((MYSQL *) ctx->mysql);
- ctx->mysql = NULL;
-}
-
-
-int edg_wll_ExecStmt(edg_wll_Context ctx,char *txt,edg_wll_Stmt *stmt)
-{
- int err;
- int retry_nr = 0;
- int do_reconnect = 0;
-#ifdef LBS_DB_PROFILE
- struct timeval start,end;
- int pid;
-
- static struct timeval sum = {
- tv_sec: 0,
- tv_usec: 0
- };
-#endif
-
- edg_wll_ResetError(ctx);
-
- if (stmt) {
- *stmt = NULL;
- }
-/*
-fputs(txt,stderr);
-putc(10,stderr);
-*/
-
-#ifdef LBS_DB_PROFILE
- gettimeofday(&start,NULL);
-#endif
-
- while (retry_nr == 0 || do_reconnect) {
- do_reconnect = 0;
- if (mysql_query((MYSQL *) ctx->mysql,txt)) {
- /* error occured */
- switch (err = mysql_errno((MYSQL *) ctx->mysql)) {
- case 0:
- break;
- case ER_DUP_ENTRY:
- edg_wll_SetError(ctx,EEXIST,mysql_error((MYSQL *) ctx->mysql));
- return -1;
- break;
- case CR_SERVER_LOST:
- if (retry_nr <= 0)
- do_reconnect = 1;
- break;
- default:
- my_err();
- return -1;
- break;
- }
- }
- retry_nr++;
- }
-
- if (stmt) {
- *stmt = malloc(sizeof(**stmt));
- if (!*stmt) {
- edg_wll_SetError(ctx,ENOMEM,NULL);
- return -1;
- }
- memset(*stmt,0,sizeof(**stmt));
- (**stmt).ctx = ctx;
- (**stmt).result = mysql_store_result((MYSQL *) ctx->mysql);
- if (!(**stmt).result) {
- if (mysql_errno((MYSQL *) ctx->mysql)) {
- my_err();
- return -1;
- }
- }
- } else {
- MYSQL_RES *r = mysql_store_result((MYSQL *) ctx->mysql);
- mysql_free_result(r);
- }
-#ifdef LBS_DB_PROFILE
- pid = getpid();
- gettimeofday(&end,NULL);
- end.tv_usec -= start.tv_usec;
- end.tv_sec -= start.tv_sec;
- if (end.tv_usec < 0) { end.tv_sec--; end.tv_usec += 1000000; }
-
- sum.tv_usec += end.tv_usec;
- sum.tv_sec += end.tv_sec + sum.tv_usec / 1000000;
- sum.tv_usec -= 1000000 * (sum.tv_usec / 1000000);
- fprintf(stderr,"[%d] %s\n[%d] %3ld.%06ld (sum: %3ld.%06ld)\n",pid,txt,pid,end.tv_sec,end.tv_usec,sum.tv_sec,sum.tv_usec);
-#endif
-
- return mysql_affected_rows((MYSQL *) ctx->mysql);
-}
-
-int edg_wll_FetchRow(edg_wll_Stmt stmt,char **res)
-{
- MYSQL_ROW row;
- edg_wll_Context ctx = stmt->ctx;
- int nr,i;
- unsigned long *len;
-
- edg_wll_ResetError(ctx);
-
- if (!stmt->result) return 0;
-
- if (!(row = mysql_fetch_row(stmt->result))) {
- if (mysql_errno((MYSQL *) ctx->mysql)) {
- my_err();
- return -1;
- } else return 0;
- }
-
- nr = mysql_num_fields(stmt->result);
- len = mysql_fetch_lengths(stmt->result);
- for (i=0; i<nr; i++) res[i] = len[i] ? strdup(row[i]) : strdup("");
-
- return nr;
-}
-
-int edg_wll_QueryColumns(edg_wll_Stmt stmt,char **cols)
-{
- int i = 0;
- MYSQL_FIELD *f;
-
- while ((f = mysql_fetch_field(stmt->result))) cols[i++] = f->name;
- return i == 0;
-}
-
-void edg_wll_FreeStmt(edg_wll_Stmt *stmt)
-{
- if (*stmt) {
- if ((**stmt).result) mysql_free_result((**stmt).result);
- free(*stmt);
- *stmt = NULL;
- }
-}
-
-int edg_wll_DBCheckVersion(edg_wll_Context ctx, const char *cs)
-{
- MYSQL *m = (MYSQL *) ctx->mysql;
- MYSQL *m2;
- const char *ver_s = mysql_get_server_info(m);
- int major,minor,sub,version;
-
- if (!ver_s || 3 != sscanf(ver_s,"%d.%d.%d",&major,&minor,&sub))
- return edg_wll_SetError(ctx,EINVAL,"retreiving MySQL version");
-
- version = 10000*major + 100*minor + sub;
-
- if (version < EDG_WLL_MYSQL_VERSION) {
- char msg[300];
-
- snprintf(msg,sizeof msg,"Your MySQL version is %d. At least %d required.",version,EDG_WLL_MYSQL_VERSION);
- return edg_wll_SetError(ctx,EINVAL,msg);
- }
-
- edg_wll_ResetError(ctx);
-
- if (db_connect(ctx, cs, &m2) == 0) {
- transaction_test(ctx, m2);
- db_close(m2);
- }
-
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-
-int edg_wll_Transaction(edg_wll_Context ctx) {
- if (ctx->use_transactions) {
- if (edg_wll_ExecStmt(ctx, "set autocommit=0", NULL) < 0) goto err;
- if (edg_wll_ExecStmt(ctx, "begin", NULL) < 0) goto err;
- }
-err:
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-
-int edg_wll_Commit(edg_wll_Context ctx) {
- if (ctx->use_transactions) {
- if (edg_wll_ExecStmt(ctx, "commit", NULL) < 0) goto err;
- if (edg_wll_ExecStmt(ctx, "set autocommit=1", NULL) < 0) goto err;
- }
-err:
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-
-int edg_wll_Rollback(edg_wll_Context ctx) {
- if (ctx->use_transactions) {
- if (edg_wll_ExecStmt(ctx, "rollback", NULL) < 0) goto err;
- if (edg_wll_ExecStmt(ctx, "set autocommit=1", NULL) < 0) goto err;
- }
-err:
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-
-edg_wll_ErrorCode edg_wll_bufferedInsertInit(edg_wll_Context ctx, edg_wll_bufInsert *bi, void *mysql, char *table_name, long size_limit, long record_limit, char *columns)
-{
- bi->ctx = ctx;
- bi->table_name = strdup(table_name);
- bi->columns = strdup(columns);
- bi->rec_num = 0;
- bi->rec_size = 0;
- bi->rows = calloc(record_limit, sizeof(*(bi->rows)) );;
- bi->size_limit = size_limit;
- bi->record_limit = record_limit;
-
- return edg_wll_Error(bi->ctx,NULL,NULL);
-;
-}
-
-
-#if 0
-static int string_add(char *what, long *used_size, long *alloc_size, char **where)
-{
- long what_len = strlen(what);
- int reall = 0;
-
- while (*used_size + what_len >= *alloc_size) {
- *alloc_size += BUF_INSERT_ROW_ALLOC_BLOCK;
- reall = 1;
- }
-
- if (reall)
- *where = realloc(*where, *alloc_size * sizeof(char));
-
- what_len = sprintf(*where + *used_size, "%s", what);
- if (what_len < 0) /* ENOMEM? */ return -1;
-
- *used_size += what_len;
-
- return 0;
-}
-#endif
-
-
-static int flush_bufferd_insert(edg_wll_bufInsert *bi)
-{
- char *stmt, *vals, *temp;
- long i;
-
-
- if (!bi->rec_num)
- return edg_wll_Error(bi->ctx,NULL,NULL);
-
- asprintf(&vals,"(%s)", bi->rows[0]);
- for (i=1; i < bi->rec_num; i++) {
- // XXX: use string add (preallocated memory)
- asprintf(&temp,"%s,(%s)", vals, bi->rows[i]);
- free(vals); vals = temp; temp = NULL;
- free(bi->rows[i]);
- bi->rows[i] = NULL;
- }
-
- trio_asprintf(&stmt, "insert into %|Ss(%|Ss) values %s;",
- bi->table_name, bi->columns, vals);
-
- if (edg_wll_ExecStmt(bi->ctx,stmt,NULL) < 0) {
- if (edg_wll_Error(bi->ctx,NULL,NULL) == EEXIST)
- edg_wll_ResetError(bi->ctx);
- }
-
- /* reset bi counters */
- bi->rec_size = 0;
- bi->rec_num = 0;
-
- free(vals);
- free(stmt);
-
- return edg_wll_Error(bi->ctx,NULL,NULL);
-}
-
-
-/*
- * adds row of n values into n columns into an insert buffer
- * if num. of rows or size of data oversteps the limits, real
- * multi-row insert is done
- */
-edg_wll_ErrorCode edg_wll_bufferedInsert(edg_wll_bufInsert *bi, char *row)
-{
- bi->rows[bi->rec_num++] = strdup(row);
- bi->rec_size += strlen(row);
-
- if ((bi->size_limit && bi->rec_size >= bi->size_limit) ||
- (bi->record_limit && bi->rec_num >= bi->record_limit))
- {
- if (flush_bufferd_insert(bi))
- return edg_wll_Error(bi->ctx,NULL,NULL);
- }
-
- return edg_wll_ResetError(bi->ctx);
-}
-
-static void free_buffered_insert(edg_wll_bufInsert *bi) {
- long i;
-
- free(bi->table_name);
- free(bi->columns);
- for (i=0; i < bi->rec_num; i++) {
- free(bi->rows[i]);
- }
- free(bi->rows);
-}
-
-edg_wll_ErrorCode edg_wll_bufferedInsertClose(edg_wll_bufInsert *bi)
-{
- if (flush_bufferd_insert(bi))
- return edg_wll_Error(bi->ctx,NULL,NULL);
- free_buffered_insert(bi);
-
- return edg_wll_ResetError(bi->ctx);
-}
-
+++ /dev/null
-#ident "$Header$"
-
-#include <time.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-char *edg_wll_TimeToDB(time_t t)
-{
- struct tm *tm = gmtime(&t);
- char tbuf[256];
-
- sprintf(tbuf,"'%4d-%02d-%02d %02d:%02d:%02d'",tm->tm_year+1900,tm->tm_mon+1,
- tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
-
- return strdup(tbuf);
-}
-
-time_t edg_wll_DBToTime(char *t)
-{
- struct tm tm;
-
- memset(&tm,0,sizeof(tm));
- setenv("TZ","UTC",1); tzset();
- sscanf(t,"%4d-%02d-%02d %02d:%02d:%02d",
- &tm.tm_year,&tm.tm_mon,&tm.tm_mday,
- &tm.tm_hour,&tm.tm_min,&tm.tm_sec);
- tm.tm_year -= 1900;
- tm.tm_mon--;
-
- return mktime(&tm);
-}
#include "store.h"
#include "purge.h"
-#include "lbs_db.h"
#include "query.h"
#include "get_events.h"
#include "server_state.h"
+#include "db_supp.h"
static int read_line(char **buff, size_t *maxsize, int fd);
#include "glite/jobid/strmd5.h"
#include "glite/lb/context-int.h"
#include "glite/lb/jobstat.h"
-
-#include "lbs_db.h"
+#include "db_supp.h"
static struct option opts[] = {
{ "mysql",1,NULL,'m' },
int main(int argc,char **argv)
{
- int opt;
+ int opt, caps;
char *dbstring = getenv("LBDB");
int verbose = 0, rows = 0, fields = 0, njobs = 0, i;
edg_wll_Context ctx;
char *stmt = NULL, *status = NULL;
char *str[2];
- edg_wll_Stmt sh;
+ glite_lbu_Statement sh;
int jobs[EDG_WLL_NUMBER_OF_STATCODES];
me = strdup(argv[0]);
edg_wll_InitContext(&ctx);
for (i = 1; i<EDG_WLL_NUMBER_OF_STATCODES; i++) jobs[i] = 0;
if (edg_wll_Open(ctx,dbstring)) do_exit(ctx,EX_UNAVAILABLE);
- if (edg_wll_DBCheckVersion(ctx,dbstring)) do_exit(ctx,EX_SOFTWARE);
+ if ((caps = glite_lbu_DBQueryCaps(ctx->dbctx)) < 0 || !(caps & GLITE_LBU_DB_CAP_INDEX)) do_exit(ctx,EX_SOFTWARE);
if (asprintf(&stmt,"SELECT status,count(status) FROM states GROUP BY status;") < 0) do_exit(ctx,EX_OSERR);
if (verbose) fprintf(stderr,"mysql query: %s\n",stmt);
- if ((rows = edg_wll_ExecStmt(ctx,stmt,&sh)) < 0) do_exit(ctx,EX_SOFTWARE);
+ if ((rows = edg_wll_ExecSQL(ctx,stmt,&sh)) < 0) do_exit(ctx,EX_SOFTWARE);
if (verbose) fprintf(stderr,"number of states returned: %d\n",rows);
if (rows > 0) fprintf(stdout,"Number of jobs in each state: \n");
for (i = 0; i < rows; i++) {
- fields = edg_wll_FetchRow(sh, str);
+ fields = edg_wll_FetchRow(ctx, sh, sizeof(str)/sizeof(str[0]),NULL,str);
if (fields != 2) {
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
do_exit(ctx,EX_SOFTWARE);
}
jobs[atoi(str[0])] = atoi(str[1]);
fprintf(stdout,"Total number of jobs: %d\n",njobs);
if (stmt) free(stmt);
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
edg_wll_FreeContext(ctx);
return 0;
#include "glite/lb/context-int.h"
#include "glite/lbu/trio.h"
-#include "lbs_db.h"
#include "lb_authz.h"
#include "lb_xml_parse.h"
#include "query.h"
#include "il_notification.h"
+#include "db_supp.h"
static int notif_match_conditions(edg_wll_Context,const edg_wll_JobStat *,const char *);
static int notif_check_acl(edg_wll_Context,const edg_wll_JobStat *,const char *);
{
edg_wll_NotifId nid = NULL;
char *jobq,*ju = NULL,*jobc[5];
- edg_wll_Stmt jobs = NULL;
+ glite_lbu_Statement jobs = NULL;
int ret,i;
time_t now = time(NULL);
free(ju);
- if (edg_wll_ExecStmt(ctx,jobq,&jobs) < 0) goto err;
+ if (edg_wll_ExecSQL(ctx,jobq,&jobs) < 0) goto err;
- while ((ret = edg_wll_FetchRow(jobs,jobc)) > 0) {
- if (now > edg_wll_DBToTime(jobc[2]))
+ while ((ret = edg_wll_FetchRow(ctx,jobs,sizeof(jobc)/sizeof(jobc[0]),NULL,jobc)) > 0) {
+ if (now > glite_lbu_DBToTime(jobc[2]))
edg_wll_NotifExpired(ctx,jobc[0]);
else if (notif_match_conditions(ctx,stat,jobc[4]) &&
notif_check_acl(ctx,stat,jobc[3]))
err:
if ( nid ) edg_wll_NotifIdFree(nid);
free(jobq);
- edg_wll_FreeStmt(&jobs);
+ glite_lbu_FreeStmt(&jobs);
return edg_wll_Error(ctx,NULL,NULL);
}
#include "glite/lb/xml_parse.h"
#include "il_notification.h"
-#include "lbs_db.h"
#include "query.h"
+#include "db_supp.h"
static char *get_user(edg_wll_Context ctx, int create);
*valid = ctx->peerProxyValidity;
else
*valid += ctx->notifDuration;
-
- if ( !(time_s = strdup(edg_wll_TimeToDB(*valid))) )
+
+ glite_lbu_TimeToDB(*valid, &time_s);
+ if ( !time_s )
{
edg_wll_SetError(ctx, errno, NULL);
goto cleanup;
"values ('%|Ss','%|Ss',%s,'%|Ss', '<and>%|Ss</and>')",
nid_s, addr_s? addr_s: address_override, time_s, owner, xml_conds);
- if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 )
+ if ( edg_wll_ExecSQL(ctx, q, NULL) < 0 )
goto cleanup;
if (jobs) for ( i = 0; jobs[i]; i++ )
trio_asprintf(&q,
"insert into notif_jobs(notifid,jobid) values ('%|Ss','%|Ss')",
nid_s, jobs[i]);
- if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 )
+ if ( edg_wll_ExecSQL(ctx, q, NULL) < 0 )
{
/* XXX: Remove uncoplete registration?
* Which error has to be returned?
*/
free(q);
trio_asprintf(&q, "delete from notif_jobs where notifid='%|Ss'", nid_s);
- edg_wll_ExecStmt(ctx, q, NULL);
+ edg_wll_ExecSQL(ctx, q, NULL);
free(q);
trio_asprintf(&q, "delete from notif_registrations where notifid='%|Ss'", nid_s);
- edg_wll_ExecStmt(ctx, q, NULL);
+ edg_wll_ExecSQL(ctx, q, NULL);
goto cleanup;
}
}
else {
trio_asprintf(&q,"insert into notif_jobs(notifid,jobid) values ('%|Ss','%|Ss')",
nid_s,NOTIF_ALL_JOBS);
- if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 ) goto cleanup;
+ if ( edg_wll_ExecSQL(ctx, q, NULL) < 0 ) goto cleanup;
}
else
*valid += ctx->notifDuration;
- if ( !(time_s = strdup(edg_wll_TimeToDB(*valid))) )
+ glite_lbu_TimeToDB(*valid, &time_s);
+ if ( !time_s )
{
edg_wll_SetError(ctx, errno, "Formating validity time");
goto cleanup;
/* Format DB insert statement
*/
trio_asprintf(&q, "delete from notif_jobs where notifid='%|Ss'", nid_s);
- if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 )
+ if ( edg_wll_ExecSQL(ctx, q, NULL) < 0 )
goto cleanup;
for ( i = 0; jobs[i]; i++ )
trio_asprintf(&q,
"insert into notif_jobs(notifid,jobid) values ('%|Ss','%|Ss')",
nid_s, jobs[i]);
- if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 )
+ if ( edg_wll_ExecSQL(ctx, q, NULL) < 0 )
{
/* XXX: Remove uncoplete registration?
* Which error has to be returned?
*/
free(q);
trio_asprintf(&q, "delete from notif_jobs where notifid='%|Ss'", nid_s);
- edg_wll_ExecStmt(ctx, q, NULL);
+ edg_wll_ExecSQL(ctx, q, NULL);
free(q);
trio_asprintf(&q,"delete from notif_registrations where notifid='%|Ss'", nid_s);
- edg_wll_ExecStmt(ctx, q, NULL);
+ edg_wll_ExecSQL(ctx, q, NULL);
goto cleanup;
}
}
else
*valid += ctx->notifDuration;
- if ( !(time_s = strdup(edg_wll_TimeToDB(*valid))) )
+ glite_lbu_TimeToDB(*valid, &time_s);
+ if ( !time_s )
{
edg_wll_SetError(ctx, errno, "Formating validity time");
goto cleanup;
goto cleanup;
trio_asprintf(&stmt, "delete from notif_registrations where notifid='%|Ss'", nid_s);
- if ( (ret = edg_wll_ExecStmt(ctx, stmt, NULL)) < 0 )
+ if ( (ret = edg_wll_ExecSQL(ctx, stmt, NULL)) < 0 )
goto cleanup;
free(stmt);
trio_asprintf(&stmt, "delete from notif_jobs where notifid='%|Ss'", nid_s);
- edg_wll_ExecStmt(ctx, stmt, NULL);
+ edg_wll_ExecSQL(ctx, stmt, NULL);
edg_wll_NotifCancelRegId(ctx, nid);
cleanup:
static char *get_user(edg_wll_Context ctx, int create)
{
- edg_wll_Stmt stmt = NULL;
+ glite_lbu_Statement stmt = NULL;
char *userid = NULL,
*q = NULL;
int ret;
goto cleanup;
}
trio_asprintf(&q, "select userid from users where cert_subj='%|Ss'", ctx->peerName);
- if ( edg_wll_ExecStmt(ctx, q, &stmt) < 0 )
+ if ( edg_wll_ExecSQL(ctx, q, &stmt) < 0 )
goto cleanup;
/* returned value:
* >0 user found - return selected value
* <0 SQL error
*/
- if ( ((ret = edg_wll_FetchRow(stmt, &userid)) != 0) || !create )
+ if ( ((ret = edg_wll_FetchRow(ctx, stmt, 1, NULL, &userid)) != 0) || !create )
goto cleanup;
if ( !(userid = strdup(strmd5(ctx->peerName, NULL))) )
free(q);
trio_asprintf(&q, "insert into users(userid,cert_subj) values ('%|Ss','%|Ss')",
userid, ctx->peerName);
- if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 )
+ if ( edg_wll_ExecSQL(ctx, q, NULL) < 0 )
{
if ( edg_wll_Error(ctx,NULL,NULL) != EEXIST )
{
cleanup:
if ( q ) free(q);
- if ( stmt ) edg_wll_FreeStmt(&stmt);
+ if ( stmt ) glite_lbu_FreeStmt(&stmt);
return userid;
}
"where notifid='%|Ss' and userid='%|Ss'",
nid_s, user);
- if ( (ret = edg_wll_ExecStmt(ctx, stmt, NULL)) < 0 )
+ if ( (ret = edg_wll_ExecSQL(ctx, stmt, NULL)) < 0 )
goto cleanup;
if ( ret == 0 )
{
free(stmt);
trio_asprintf(&stmt,
"select notifid from notif_registrations where notifid='%|Ss'", nid_s);
- ret = edg_wll_ExecStmt(ctx, stmt, NULL);
+ ret = edg_wll_ExecSQL(ctx, stmt, NULL);
if ( ret == 0 )
edg_wll_SetError(ctx, ENOENT, "Unknown notification ID");
else if ( ret > 0 )
free(stmt);
stmt = aux;
- if ( (ret = edg_wll_ExecStmt(ctx, stmt, NULL)) < 0 )
+ if ( (ret = edg_wll_ExecSQL(ctx, stmt, NULL)) < 0 )
goto cleanup;
if ( ret == 0 )
{
free(stmt);
trio_asprintf(&stmt,
"select notifid from notif_registrations where notifid='%|Ss'", nid_s);
- ret = edg_wll_ExecStmt(ctx, stmt, NULL);
+ ret = edg_wll_ExecSQL(ctx, stmt, NULL);
if ( ret == 0 )
edg_wll_SetError(ctx, ENOENT, "Unknown notification ID");
/*
#ident "$Header$"
+#include "glite/lbu/db.h"
#include "glite/lb/context-int.h"
-#include "lbs_db.h"
-
edg_wll_ErrorCode edg_wll_Open(edg_wll_Context ctx, char *cs)
{
- return edg_wll_DBConnect(ctx,cs) ? edg_wll_Error(ctx,NULL,NULL) : 0;
+ glite_lbu_InitDBContext(&ctx->dbctx);
+ return glite_lbu_DBConnect(ctx->dbctx,cs) ? edg_wll_SetErrorDB(ctx) : 0;
}
edg_wll_ErrorCode edg_wll_Close(edg_wll_Context ctx)
{
+ glite_lbu_DBClose(ctx->dbctx);
+ glite_lbu_FreeDBContext(ctx->dbctx);
+ ctx->dbctx = NULL;
return edg_wll_ResetError(ctx);
}
#include "query.h"
#include "store.h"
#include "lb_authz.h"
+#include "db_supp.h"
#define FL_SEL_STATUS 1
#define FL_SEL_TAGS (1<<1)
*q = NULL,
*res[11];
edg_wll_Event *out = NULL;
- edg_wll_Stmt sh = NULL;
+ glite_lbu_Statement sh = NULL;
int i = 0,
ret = 0,
offset = 0, limit = 0,
q = qbase;
// printf("\nquery: %s\n\n", q);
- ret = edg_wll_ExecStmt(ctx, q, &sh);
+ ret = edg_wll_ExecSQL(ctx, q, &sh);
if ( limit )
free(q);
if ( ret < 0 )
{
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
goto cleanup;
}
if ( ret == 0 )
limit_loop = 0;
offset += ret;
- while ( (ret = edg_wll_FetchRow(sh, res)) == sizofa(res) )
+ while ( (ret = edg_wll_FetchRow(ctx, sh, sizofa(res), NULL, res)) == sizofa(res) )
{
int n = atoi(res[0]);
free(res[0]);
free(res[1]);
free(res[2]);
memset(out+i, 0, sizeof(*out));
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
goto cleanup;
}
j_old=res[2];
}
limit_cycle_cleanup:
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
} while ( limit_loop );
if ( i == 0 && eperm )
*res[3];
edg_wlc_JobId *jobs_out = NULL;
edg_wll_JobStat *states_out = NULL;
- edg_wll_Stmt sh;
+ glite_lbu_Statement sh;
int i = 0,
ret = 0,
eperm = 0,
q = qbase;
// printf("\nquery: %s\n\n", q);
- ret = edg_wll_ExecStmt(ctx, q, &sh);
+ ret = edg_wll_ExecSQL(ctx, q, &sh);
if ( limit )
free(q);
if ( ret < 0 )
{
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
goto cleanup;
}
if ( ret == 0 )
limit_loop = 0;
offset += ret;
- while ( (ret=edg_wll_FetchRow(sh,res)) > 0 )
+ while ( (ret=edg_wll_FetchRow(ctx,sh,sizofa(res),NULL,res)) > 0 )
{
if ( (ret = edg_wlc_JobIdParse(res[0], jobs_out+i)) )
{ /* unlikely to happen, internal inconsistency */
jobs_out[i] = NULL;
}
limit_cycle_cleanup:
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
} while ( limit_loop );
if ( !*jobs_out ) {
for ( n = 0; ec[m][n].attr; n++ ) switch ( ec[m][n].attr )
{
case EDG_WLL_QUERY_ATTR_TIME:
- dbt = edg_wll_TimeToDB(ec[m][n].value.t.tv_sec);
+ glite_lbu_TimeToDB(ec[m][n].value.t.tv_sec, &dbt);
if ( conds )
{
if ( ec[m][n].op == EDG_WLL_QUERY_OP_WITHIN )
{
trio_asprintf(&aux, "%s", dbt);
- dbt = edg_wll_TimeToDB(ec[m][n].value2.t.tv_sec);
+ free(dbt);
+ glite_lbu_TimeToDB(ec[m][n].value2.t.tv_sec, &dbt);
trio_asprintf(&out, "%s OR (e.time_stamp >= %s AND e.time_stamp <= %s)", conds, aux, dbt);
+ free(dbt);
free(aux);
}
else if (ec[m][n].op == EDG_WLL_QUERY_OP_EQUAL) {
else if ( ec[m][n].op == EDG_WLL_QUERY_OP_WITHIN )
{
trio_asprintf(&aux, "%s", dbt);
- dbt = edg_wll_TimeToDB(ec[m][n].value2.t.tv_sec);
+ free(dbt);
+ glite_lbu_TimeToDB(ec[m][n].value2.t.tv_sec, &dbt);
trio_asprintf(&conds, "(e.time_stamp >= %s AND e.time_stamp <= %s)", aux, dbt);
+ free(dbt);
free(aux);
}
else if (ec[m][n].op == EDG_WLL_QUERY_OP_EQUAL) {
*where_flags |= FL_SEL_STATUS;
- dbt = edg_wll_TimeToDB(jc[m][n].value.t.tv_sec);
+ glite_lbu_TimeToDB(jc[m][n].value.t.tv_sec, &dbt);
if ( conds )
{
if ( jc[m][n].op == EDG_WLL_QUERY_OP_WITHIN )
{
trio_asprintf(&aux, "%s", dbt);
- dbt = edg_wll_TimeToDB(jc[m][n].value2.t.tv_sec);
+ free(dbt);
+ glite_lbu_TimeToDB(jc[m][n].value2.t.tv_sec, &dbt);
trio_asprintf(&tmps, "%s OR (s.%s >= %s AND s.%s <= %s)", conds, cname, aux, cname, dbt);
+ free(dbt);
free(aux);
}
else
else if ( jc[m][n].op == EDG_WLL_QUERY_OP_WITHIN )
{
trio_asprintf(&aux, "%s", dbt);
- dbt = edg_wll_TimeToDB(jc[m][n].value2.t.tv_sec);
+ free(dbt);
+ glite_lbu_TimeToDB(jc[m][n].value2.t.tv_sec, &dbt);
trio_asprintf(&conds, "(s.%s >= %s AND s.%s <= %s)", cname, aux, cname, dbt);
+ free(dbt);
free(aux);
}
else
e->any.user = f[4];
f[4] = NULL;
- e->any.timestamp.tv_sec = edg_wll_DBToTime(f[5]);
+ e->any.timestamp.tv_sec = glite_lbu_DBToTime(f[5]);
free(f[5]); f[5] = NULL;
e->any.timestamp.tv_usec = atoi(f[6]);
e->any.level = atoi(f[7]);
free(f[7]); f[7] = NULL;
- e->any.arrived.tv_sec = edg_wll_DBToTime(f[8]);
+ e->any.arrived.tv_sec = glite_lbu_DBToTime(f[8]);
e->any.arrived.tv_usec = 0;
free(f[8]); f[8] = NULL;
#include "glite/lb/context-int.h"
#include "store.h"
-#include "lbs_db.h"
+#include "db_supp.h"
#ifdef __GNUC__
#define UNUSED_VAR __attribute__((unused))
/*
#include "lb_authz.h"
*/
+#include "db_supp.h"
int edg_wll_QuerySequenceCodeServer(edg_wll_Context ctx, edg_wlc_JobId jobid, const char *source, char **seqcode)
{
- edg_wll_Stmt sh;
+ glite_lbu_Statement sh;
intJobStat *istat = NULL;
char *jobid_md5 = NULL,
*stmt = NULL,
if ( stmt == NULL ) return edg_wll_SetError(ctx, ENOMEM, NULL);
- if ( (nstates = edg_wll_ExecStmt(ctx, stmt, &sh)) < 0 ) goto cleanup;
+ if ( (nstates = edg_wll_ExecSQL(ctx, stmt, &sh)) < 0 ) goto cleanup;
if ( nstates == 0 ) {
edg_wll_SetError(ctx, ENOENT, "no state in DB");
goto cleanup;
}
- if ( edg_wll_FetchRow(sh, &res) < 0 ) goto cleanup;
+ if ( edg_wll_FetchRow(ctx, sh, 1, NULL, &res) < 0 ) goto cleanup;
istat = dec_intJobStat(res, &res_rest);
if ( res_rest && istat ) {
free(res);
free(jobid_md5);
free(stmt);
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
if ( istat ) {
destroy_intJobStat(istat);
free(istat);
#include "glite/lbu/trio.h"
#include "glite/lb/context-int.h"
-#include "lbs_db.h"
#include "server_state.h"
+#include "db_supp.h"
int edg_wll_GetServerState(edg_wll_Context ctx,const char *name,char **val)
{
char *stmt = NULL;
- edg_wll_Stmt q = NULL;
+ glite_lbu_Statement q = NULL;
trio_asprintf(&stmt,"select value from server_state "
"where prefix = 'https://%|Ss:%d' and name = '%|Ss'",
ctx->srvName,ctx->srvPort,name);
- switch (edg_wll_ExecStmt(ctx,stmt,&q)) {
+ switch (edg_wll_ExecSQL(ctx,stmt,&q)) {
case 0: edg_wll_SetError(ctx,ENOENT,name); break;
case -1: break;
- default: edg_wll_FetchRow(q,val); break;
+ default: edg_wll_FetchRow(ctx,q,sizeof(val)/sizeof(val[0]),NULL,val); break;
}
- edg_wll_FreeStmt(&q);
+ glite_lbu_FreeStmt(&q);
free(stmt);
return edg_wll_Error(ctx,NULL,NULL);
}
"values ('https://%|Ss:%d','%|Ss','%|Ss')",
ctx->srvName,ctx->srvPort,name,val);
- switch(edg_wll_ExecStmt(ctx,stmt,NULL)) {
+ switch(edg_wll_ExecSQL(ctx,stmt,NULL)) {
case 1: break;
case -1: if (edg_wll_Error(ctx,NULL,NULL) == EEXIST) {
free(stmt);
"where prefix = 'https://%|Ss:%d' "
"and name = '%|Ss'",
val,ctx->srvName,ctx->srvPort,name);
- edg_wll_ExecStmt(ctx,stmt,NULL);
+ edg_wll_ExecSQL(ctx,stmt,NULL);
}
break;
#include "lb_proto.h"
#include "store.h"
#include "lock.h"
-#include "lbs_db.h"
#include "query.h"
#include "get_events.h"
#include "purge.h"
#include "lb_xml_parse.h"
#include "db_calls.h"
+#include "db_supp.h"
#define DUMP_FILE_STORAGE "/tmp/"
static int purge_one(edg_wll_Context ctx,const edg_wlc_JobId,int,int);
static int unset_proxy_flag(edg_wll_Context ctx, edg_wlc_JobId job);
-/**
- * return job membership in DB table jobs (proxy, server, both)
- */
-static int edg_wll_jobMembership(edg_wll_Context ctx, edg_wlc_JobId job);
-
int edg_wll_CreateTmpFileStorage(edg_wll_Context ctx, char *prefix, char **fname)
{
case DB_SERVER_JOB:
// should not happen, however, no action needed
// proxy flag is unset already
+ edg_wll_ResetError(ctx);
+ return 0;
break;
case DB_PROXY_JOB+DB_SERVER_JOB:
return(unset_proxy_flag(ctx, job));
}
}
else {
- edg_wll_Stmt s;
+ glite_lbu_Statement s;
char *job_s;
int res;
time_t timeout[EDG_WLL_NUMBER_OF_STATCODES],
for (i=0; i<EDG_WLL_NUMBER_OF_STATCODES; i++)
timeout[i] = request->timeout[i] < 0 ? ctx->purge_timeout[i] : request->timeout[i];
- if (edg_wll_ExecStmt(ctx,"select dg_jobid from jobs",&s) < 0) goto abort;
- while ((res = edg_wll_FetchRow(s,&job_s)) > 0) {
+ if (edg_wll_ExecSQL(ctx,"select dg_jobid from jobs",&s) < 0) goto abort;
+ while ((res = edg_wll_FetchRow(ctx,s,1,NULL,&job_s)) > 0) {
if (edg_wlc_JobIdParse(job_s,&job)) {
fprintf(stderr,"%s: parse error (internal inconsistency !)\n",job_s);
parse = 1;
free(job_s);
}
}
- edg_wll_FreeStmt(&s);
+ glite_lbu_FreeStmt(&s);
abort:
// just for escaping from nested cycles
; /* prevent compiler to complain */
{
char *dbjob;
char *stmt = NULL;
- edg_wll_Stmt q;
+ glite_lbu_Statement q;
int ret,dumped = 0;
edg_wll_ResetError(ctx);
if ( purge )
{
trio_asprintf(&stmt,"delete from jobs where jobid = '%|Ss'",dbjob);
- ret = edg_wll_ExecStmt(ctx,stmt,NULL);
+ ret = edg_wll_ExecSQL(ctx,stmt,NULL);
if (ret <= 0) {
unlock_and_check(ctx,job);
if (ret == 0) {
free(stmt); stmt = NULL;
trio_asprintf(&stmt,"delete from states where jobid = '%|Ss'",dbjob);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) {
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) {
unlock_and_check(ctx,job);
goto clean;
}
/* Why on earth ?
trio_asprintf(&stmt,"delete from states where jobid = '%|Ss'",dbjob);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) {
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) {
unlock_and_check(ctx,job);
goto clean;
}
if ( purge )
{
trio_asprintf(&stmt,"delete from status_tags where jobid = '%|Ss'",dbjob);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) goto unlock;
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto unlock;
free(stmt); stmt = NULL;
}
"order by event", dbjob);
/* check for events repeatedly -- new one may have arrived in the meantime */
- while ((ret = edg_wll_ExecStmt(ctx,stmt,&q)) > 0) {
+ while ((ret = edg_wll_ExecSQL(ctx,stmt,&q)) > 0) {
char *res[9];
dumped = 1;
- while ((ret = edg_wll_FetchRow(q,res)) > 0) {
+ while ((ret = edg_wll_FetchRow(ctx,q,sizofa(res),NULL,res)) > 0) {
int event;
event = atoi(res[0]);
}
}
}
- edg_wll_FreeStmt(&q);
+ glite_lbu_FreeStmt(&q);
if (ret < 0 || !purge) break;
}
- edg_wll_FreeStmt(&q);
+ glite_lbu_FreeStmt(&q);
unlock:
if (ctx->strict_locking) unlock_and_check(ctx,job);
trio_asprintf(&stmt,"update jobs set proxy='0' where jobid='%|Ss'", dbjob);
- return(edg_wll_ExecStmt(ctx,stmt,NULL));
+ return(edg_wll_ExecSQL(ctx,stmt,NULL));
}
#include "store.h"
#include "get_events.h"
-#include "lbs_db.h"
#include "lock.h"
#include "lb_authz.h"
#include "jobstat.h"
#include "db_calls.h"
+#include "db_supp.h"
static int store_user(edg_wll_Context,const char *,const char *);
static int store_job(edg_wll_Context,const edg_wlc_JobId,const char *, int, int);
#ifdef LB_BUF
-static int store_job_block(edg_wll_Context, const edg_wlc_JobId, const char *, edg_wll_bufInsert *, int, int);
+static int store_job_block(edg_wll_Context, const edg_wlc_JobId, const char *, glite_lbu_bufInsert *, int, int);
#endif
static int store_job_grey(edg_wll_Context,const edg_wlc_JobId,time_t);
static int store_flesh(edg_wll_Context,edg_wll_Event *,char *,int);
edg_wll_ErrorCode err = 0;
char *userid = NULL,*jobid,*stmt;
char *select_max,*ssrc;
- edg_wll_Stmt sh = NULL;
+ glite_lbu_Statement sh = NULL;
int next = 0xDEAD;
int lbproxy_notreg = 0;
char *now_s = NULL;
ssrc = jobid = stmt = select_max = NULL;
if ( ctx->event_load )
- now_s = strdup(edg_wll_TimeToDB(e->any.arrived.tv_sec));
+ glite_lbu_TimeToDB(e->any.arrived.tv_sec, &now_s);
else
- now_s = strdup(edg_wll_TimeToDB(time(NULL)));
+ glite_lbu_TimeToDB(time(NULL), &now_s);
edg_wll_ResetError(ctx);
switch (err = check_auth(ctx,e)) {
trio_asprintf(&stmt,"select userid from jobs where jobid='%|Ss'", jobid);
- if (edg_wll_ExecStmt(ctx,stmt,&sh) < 0 || edg_wll_FetchRow(sh,&userid) < 0) goto clean;
- if (sh) edg_wll_FreeStmt(&sh);
+ if (edg_wll_ExecSQL(ctx,stmt,&sh) < 0 || edg_wll_FetchRow(ctx,sh,1,NULL,&userid) < 0) goto clean;
+ if (sh) glite_lbu_FreeStmt(&sh);
/* obtain next event sequence number */
/* try to insert (someone else may be doing the same) */
while (1) {
- char *max;
+ char *max, *stamp;
- if (edg_wll_ExecStmt(ctx,select_max,&sh) < 0 ||
- edg_wll_FetchRow(sh,&max) < 0)
+ if (edg_wll_ExecSQL(ctx,select_max,&sh) < 0 ||
+ edg_wll_FetchRow(ctx,sh,1,NULL,&max) < 0)
{
err = edg_wll_Error(ctx,NULL,NULL);
goto clean;
}
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
next = max && *max ? atoi(max)+1 : 0;
* 1) when using transactions:
* Store the whole event right now.
*
- * 2) when not using transaction:
+ * 2) when not using transactions:
* Store an UNDEF event first in order to prevent race condition
* with readers and update event code later.
*/
+ glite_lbu_TimeToDB(e->any.timestamp.tv_sec, &stamp);
trio_asprintf(&stmt,
"insert into events(jobid,event,code,prog,host,time_stamp,usec,arrived,level,userid) "
"values ('%|Ss',%d,%d,'%|Ss','%|Ss',%s,%d,%s,%d,'%|Ss')",
jobid,next,
- ctx->use_transactions ? (int) e->any.type : EDG_WLL_EVENT_UNDEF,
+ ctx->dbcaps & GLITE_LBU_DB_CAP_TRANSACTIONS ? (int) e->any.type : EDG_WLL_EVENT_UNDEF,
ssrc,e->any.host,
- edg_wll_TimeToDB(e->any.timestamp.tv_sec),e->any.timestamp.tv_usec,
+ stamp,e->any.timestamp.tv_usec,
now_s, e->any.level,userid);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) {
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) {
if ((err = edg_wll_Error(ctx,NULL,NULL)) != EEXIST)
goto clean;
} else break; /* successful insert */
edg_wll_SetError(ctx,oerr,desc);
free(desc);
} else
- if (!ctx->use_transactions) {
+ if (!(ctx->dbcaps & GLITE_LBU_DB_CAP_TRANSACTIONS)) {
/* emulate commit, i.e. swith to a real event type to make
* the record valid */
trio_asprintf(&stmt,
"update events set code=%d "
"where jobid='%|Ss' and event=%d",
(int) e->any.type,jobid,next);
- switch (edg_wll_ExecStmt(ctx,stmt,NULL)) {
+ switch (edg_wll_ExecSQL(ctx,stmt,NULL)) {
case 0: if (ctx->strict_locking)
err = edg_wll_SetError(ctx,ENOENT,"event disappeared on store while strict locking");
/* purge in progres: drop the garbage, ignore errors */
trio_asprintf(&stmt,
"select 'x' from jobs where jobid='%|Ss'",
jobid);
- switch (edg_wll_ExecStmt(ctx,stmt,NULL)) {
+ switch (edg_wll_ExecSQL(ctx,stmt,NULL)) {
case 1: break;
case 0: /* purge in progres */
edg_wll_delete_event(ctx,jobid,next);
"more event records, what is that?");
break;
}
- } /* if !ctx->use_transactions */
+ } /* if !transactions */
if (err == 0 &&
e->any.type == EDG_WLL_EVENT_REGJOB &&
free(stmt);
free(ssrc);
free(select_max);
- if (sh) edg_wll_FreeStmt(&sh);
+ if (sh) glite_lbu_FreeStmt(&sh);
if (!err && seq) *seq = next;
return err;
}
trio_asprintf(&stmt,"insert into users(userid,cert_subj) "
"values ('%|Ss','%|Ss')",userid,subj);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) {
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) {
if (edg_wll_Error(ctx,NULL,NULL) == EEXIST)
edg_wll_ResetError(ctx);
}
trio_asprintf(&stmt,"insert into jobs(jobid,dg_jobid,userid,proxy,server) "
"values ('%|Ss','%|Ss','%|Ss', '%|Sd', '%|Sd')",jobid,jobstr,userid,proxy,server);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) {
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) {
if (edg_wll_Error(ctx,NULL,NULL) == EEXIST)
edg_wll_ResetError(ctx);
}
if (ctx->greyjobs) {
trio_asprintf(&stmt,"delete from grey_jobs where jobid = '%|Ss'",jobid);
- edg_wll_ExecStmt(ctx,stmt,NULL); /* XXX: error propagates */
+ edg_wll_ExecSQL(ctx,stmt,NULL); /* XXX: error propagates */
free(stmt);
}
}
#ifdef LB_BUF
-static int store_job_block(edg_wll_Context ctx,const edg_wlc_JobId job,const char *userid, edg_wll_bufInsert *bi, int proxy, int server)
+static int store_job_block(edg_wll_Context ctx,const edg_wlc_JobId job,const char *userid, glite_lbu_bufInsert *bi, int proxy, int server)
{
char *jobstr = edg_wlc_JobIdUnparse(job);
char *jobid = edg_wlc_JobIdGetUnique(job);
{
char *jobstr = edg_wlc_JobIdUnparse(job);
char *jobid = edg_wlc_JobIdGetUnique(job);
- char *stmt;
+ char *stmt, *s_etime;
if (jobid == NULL || jobstr == NULL)
return edg_wll_SetError(ctx,EINVAL,"store_job_grey()");
edg_wll_ResetError(ctx);
+ glite_lbu_TimeToDB(etime, &s_etime);
trio_asprintf(&stmt,"insert into grey_jobs(jobid,dg_jobid,time_stamp) "
"values ('%|Ss','%|Ss',%s)",
- jobid,jobstr,edg_wll_TimeToDB(etime));
+ jobid,jobstr,s_etime);
+ free(s_etime);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) {
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) {
if (edg_wll_Error(ctx,NULL,NULL) == EEXIST)
edg_wll_ResetError(ctx);
}
{
char *unique = edg_wlc_JobIdGetUnique(event->any.jobId);
char *q = NULL, *owner = NULL, *userid = NULL;
- edg_wll_Stmt stmt = NULL;
+ glite_lbu_Statement stmt = NULL;
int nar;
trio_asprintf(&q,"update jobs set proxy=1 where jobid='%|Ss'",
unique);
- nar = edg_wll_ExecStmt(ctx, q, NULL);
+ nar = edg_wll_ExecSQL(ctx, q, NULL);
if (nar == 0) {
/* job isn't registered yet */
trio_asprintf(&q,"update jobs set jobid='%|Ss' where jobid='%|Ss'",
unique, unique);
/* does the job exists ? */
- if (edg_wll_ExecStmt(ctx,q,NULL) < 0) {
+ if (edg_wll_ExecSQL(ctx,q,NULL) < 0) {
edg_wll_SetError(ctx, ENOENT, "job not registered");
goto err;
}
trio_asprintf(&q,"update jobs set jobid='%|Ss' where jobid='%|Ss'",
unique, unique);
/* does the job exists ? now we require registration on proxy too */
- if (edg_wll_ExecStmt(ctx,q,NULL) < 0) {
+ if (edg_wll_ExecSQL(ctx,q,NULL) < 0) {
edg_wll_SetError(ctx, ENOENT, "job not registered");
goto err;
}
if (event->any.type == EDG_WLL_EVENT_REGJOB) {
trio_asprintf(&q,"select cert_subj from jobs,users where jobs.jobid='%|Ss'"
" AND jobs.userid=users.userid",unique);
- if ( (nar = edg_wll_ExecStmt(ctx,q,&stmt)) < 0 || edg_wll_FetchRow(stmt,&owner) < 0 )
+ if ( (nar = edg_wll_ExecSQL(ctx,q,&stmt)) < 0 || edg_wll_FetchRow(ctx,stmt,1,NULL,&owner) < 0 )
goto err;
if (nar) {
trio_asprintf(&q,"update jobs set server=1, userid='%|Ss' where jobid='%|Ss'",
userid, unique);
- edg_wll_ExecStmt(ctx, q, NULL);
+ edg_wll_ExecSQL(ctx, q, NULL);
}
else { } /* re-registration, no action needed */
}
}
err:
- if (stmt) edg_wll_FreeStmt(&stmt);
+ if (stmt) glite_lbu_FreeStmt(&stmt);
free(unique);
free(userid);
free(q);
"values ('%|Ss',%d,'SEQCODE','%|Ss')",
jobid,no,e->any.seqcode);
- ret = edg_wll_ExecStmt(ctx,stmt,NULL);
+ ret = edg_wll_ExecSQL(ctx,stmt,NULL);
free(stmt);
free(jobid);
strlen(f[i].val) <= SHORT_LEN ? "short_fields" : "long_fields",
jobid,no,f[i].key,f[i].val);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) err = edg_wll_Error(ctx,NULL,NULL);
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) err = edg_wll_Error(ctx,NULL,NULL);
free(stmt);
}
for (i=0; i<sizeof(f)/sizeof(f[0]); i++) free(f[i].val);
trio_asprintf(&stmt,"insert into short_fields(jobid,event,name,value) "
"values ('%|Ss',%d,'SRC_INSTANCE','%|Ss')",
jobid,no,e->any.src_instance);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) err = edg_wll_Error(ctx,NULL,NULL);
+ if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) err = edg_wll_Error(ctx,NULL,NULL);
free(stmt);
}
{
char *jobid = edg_wlc_JobIdGetUnique(e->any.jobId);
char *q = NULL,*owner = NULL;
- edg_wll_Stmt stmt = NULL;
+ glite_lbu_Statement stmt = NULL;
char *user;
edg_wll_ResetError(ctx);
trio_asprintf(&q,"select userid from jobs where jobid='%|Ss'",jobid);
- if (edg_wll_ExecStmt(ctx,q,&stmt) < 0
- || edg_wll_FetchRow(stmt,&owner) < 0
+ if (edg_wll_ExecSQL(ctx,q,&stmt) < 0
+ || edg_wll_FetchRow(ctx,stmt,1,NULL,&owner) < 0
) goto clean;
if (!owner) {
clean:
- if (stmt) edg_wll_FreeStmt(&stmt);
+ if (stmt) glite_lbu_FreeStmt(&stmt);
free(q);
free(owner);
return edg_wll_Error(ctx,NULL,NULL);
char *jobid_md5, *jobid_md5_old;
size_t jobid_len;
#ifdef LB_BUF
- edg_wll_bufInsert bi_j;
- edg_wll_bufInsert *bi_jobs = &bi_j;
+ glite_lbu_bufInsert bi_j;
+ glite_lbu_bufInsert *bi_jobs = &bi_j;
char *states_cols;
#endif
- edg_wll_bufInsert bi_s, *bi_states = &bi_s;
+ glite_lbu_bufInsert bi_s, *bi_states = &bi_s;
char *icnames, *values;
int server, proxy, membership = 0;
trio_asprintf(&stmt,
"delete from short_fields where jobid='%|Ss' and event=%d",
jobid,event);
- edg_wll_ExecStmt(ctx,stmt,NULL);
+ edg_wll_ExecSQL(ctx,stmt,NULL);
free(stmt);
trio_asprintf(&stmt,
"delete from long_fields where jobid='%|Ss' and event=%d",
jobid,event);
- edg_wll_ExecStmt(ctx,stmt,NULL);
+ edg_wll_ExecSQL(ctx,stmt,NULL);
free(stmt);
trio_asprintf(&stmt,
"delete from events where jobid='%|Ss' and event=%d",
jobid,event);
- edg_wll_ExecStmt(ctx,stmt,NULL);
+ edg_wll_ExecSQL(ctx,stmt,NULL);
free (stmt);
return edg_wll_Error(ctx,NULL,NULL);
#include "glite/lbu/trio.h"
#include "glite/lb/context-int.h"
-#include "lbs_db.h"
+#include "jobstat.h"
+#include "db_supp.h"
int edg_wll_UserJobs(
edg_wll_Context ctx,
*res = NULL;
int njobs = 0,ret,i,j;
edg_wlc_JobId *out = NULL;
- edg_wll_Stmt sth = NULL;
+ glite_lbu_Statement sth = NULL;
edg_wll_ErrorCode err = 0;
edg_wll_ResetError(ctx);
trio_asprintf(&stmt,"select cert_subj from users where userid = '%|Ss'",userid);
- switch (edg_wll_ExecStmt(ctx,stmt,&sth)) {
+ switch (edg_wll_ExecSQL(ctx,stmt,&sth)) {
case 0: edg_wll_SetError(ctx,ENOENT,ctx->peerName);
case -1: goto err;
default:
- if (edg_wll_FetchRow(sth,&res) < 0) goto err;
+ if (edg_wll_FetchRow(ctx,sth,1,NULL,&res) < 0) goto err;
if (strcmp(ctx->peerName,res)) {
edg_wll_SetError(ctx,EDG_WLL_ERROR_MD5_CLASH,ctx->peerName);
goto err;
}
}
- edg_wll_FreeStmt(&sth);
+ glite_lbu_FreeStmt(&sth);
free(stmt); stmt = NULL;
free(res); res = NULL;
trio_asprintf(&stmt,"select dg_jobid from jobs where userid = '%|Ss'",userid);
- switch (njobs = edg_wll_ExecStmt(ctx,stmt,&sth)) {
+ switch (njobs = edg_wll_ExecSQL(ctx,stmt,&sth)) {
case 0: edg_wll_SetError(ctx,ENOENT,ctx->peerName);
case -1: goto err;
}
out = malloc(sizeof(*out)*(njobs+1));
memset(out,0,sizeof(*out)*(njobs+1));
- for (i=0; (ret = edg_wll_FetchRow(sth,&res)); i++) {
+ for (i=0; (ret = edg_wll_FetchRow(ctx,sth,1,NULL,&res)); i++) {
if (ret < 0) goto err;
if ((ret = edg_wlc_JobIdParse(res,out+i))) {
edg_wll_SetError(ctx,errno,res);
err:
free(res);
free(stmt);
- edg_wll_FreeStmt(&sth);
+ glite_lbu_FreeStmt(&sth);
if ((err = edg_wll_Error(ctx,NULL,NULL))) {
if (out) {
for (i=0; i<njobs; i++)
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
+#include <glite/lbu/db.h>
#include <glite/lb/query_rec.h>
#include <glite/lb/context-int.h>
-#include "lbs_db.h"
#include "get_events.h"
using namespace std;
public:
void oneJob();
- int ExecStmt(const char *, edg_wll_Stmt *);
+ int ExecStmt(const char *, glite_lbu_Statement *);
void setUp() {
edg_wll_InitContext(&ctx);
- ctx->mysql = (void *) this; /* XXX */
+ ctx->dbctx = (glite_lbu_DBContext) this; /* XXX */
+ ctx->dbcaps = 0;
}
+ void tearDown() {
+ edg_wll_FreeContext(ctx);
+ }
};
void QueryEventsTest::oneJob()
edg_wll_QueryRec job[2];
const edg_wll_QueryRec *jobs[2] = { job,NULL} ;
edg_wll_Event *events;
+ int i;
job[0].attr = EDG_WLL_QUERY_ATTR_JOBID;
job[0].op = EDG_WLL_QUERY_OP_EQUAL ;
qry_file.close();
CPPUNIT_ASSERT(!edg_wll_QueryEventsServer(ctx,1,jobs,NULL,&events));
+ edg_wlc_JobIdFree(job[0].value.j);
+ for (i = 0; events[i].type; i++) edg_wll_FreeEvent(&events[i]);
+ free(events);
}
-int QueryEventsTest::ExecStmt(const char *qry, edg_wll_Stmt *stmt_out)
+int QueryEventsTest::ExecStmt(const char *qry, glite_lbu_Statement *stmt_out)
{
vector<pair<string,vector<string> > >::iterator stmt = queries.begin();
}
vector<string>::iterator *rows = new vector<string>::iterator(stmt->second.begin());
- *stmt_out = (edg_wll_Stmt) rows;
+ *stmt_out = (glite_lbu_Statement) rows;
+//cerr << (*rows)->c_str() << endl;
+//cerr << stmt->second.size()-1 << endl;
return stmt->second.size()-1;
}
extern "C" {
+int glite_lbu_InitDBContext(glite_lbu_DBContext *ctx) { return 0; }
+void glite_lbu_FreeDBContext(glite_lbu_DBContext ctx) { }
+int glite_lbu_DBConnect(glite_lbu_DBContext ctx, const char*str) { return 0; }
+void glite_lbu_DBClose(glite_lbu_DBContext ctx) { }
-int edg_wll_ExecStmt(edg_wll_Context ctx,char *qry,edg_wll_Stmt *stmt)
+int glite_lbu_ExecSQL(glite_lbu_DBContext ctx,const char *qry,glite_lbu_Statement *stmt)
{
- cout << "edg_wll_ExecStmt: " << qry << endl;
+ cout << "glite_lbu_ExecSQL: " << qry << endl;
- class QueryEventsTest *tst = (class QueryEventsTest *)(ctx->mysql);
+ class QueryEventsTest *tst = (class QueryEventsTest *)ctx;
return tst->ExecStmt(qry, stmt);
}
-int edg_wll_FetchRow(edg_wll_Stmt stmt, char **cols)
+int glite_lbu_FetchRow(glite_lbu_Statement stmt, unsigned int n, unsigned long int *lengths, char **cols)
{
vector<string>::iterator *rows = (vector<string>::iterator *) stmt;
char *row,*p,i=0;
(*rows)++;
for (p = strtok(row,"\t"); p; p = strtok(NULL,"\t"))
cols[i++] = strdup(p);
+ free(row);
return i;
}
-void edg_wll_FreeStmt(edg_wll_Stmt *) {}
+void glite_lbu_FreeStmt(glite_lbu_Statement *) {}
int debug;
-int edg_wll_QueryColumns(edg_wll_Stmt stmt, char**cols) { return 0; }
-char *edg_wll_TimeToDB(long t) { return NULL; }
-
-time_t edg_wll_DBToTime(char *c) { return (time_t)-1; }
-edg_wll_ErrorCode edg_wll_DBConnect(edg_wll_Context ctx, const char*str) {
- return (edg_wll_ErrorCode)0;
-}
+int glite_lbu_QueryColumns(glite_lbu_Statement stmt, char**cols) { return 0; }
+void glite_lbu_TimeToDB(long t, char **s) { *s = NULL; }
+time_t glite_lbu_DBToTime(const char *c) { return (time_t)-1; }
-int edg_wll_Transaction(edg_wll_Context ctx) { return 0; }
-int edg_wll_Commit(edg_wll_Context ctx) { return 0; }
-int edg_wll_Rollback(edg_wll_Context ctx) { return 0; }
+int glite_lbu_Transaction(glite_lbu_DBContext ctx) { return 0; }
+int glite_lbu_Commit(glite_lbu_DBContext ctx) { return 0; }
+int glite_lbu_Rollback(glite_lbu_DBContext ctx) { return 0; }
-edg_wll_ErrorCode edg_wll_bufferedInsert(edg_wll_bufInsert *bi, char *row) { return (edg_wll_ErrorCode) 0; };
-
+int glite_lbu_bufferedInsertInit(glite_lbu_DBContext ctx, glite_lbu_bufInsert *bi, const char *table_name, long size_limit, long record_limit, const char * columns) { return 0; }
+int glite_lbu_bufferedInsert(glite_lbu_bufInsert bi, const char *row) { return 0; }
+int glite_lbu_bufferedInsertClose(glite_lbu_bufInsert bi) { return 0; }
+int glite_lbu_QueryIndices(glite_lbu_DBContext ctx, const char *table, char ***key_names, char ****column_names) { return 0; }
+int glite_lbu_DBError(glite_lbu_DBContext ctx, char **s1, char **s2) { return 0; }
}
CPPUNIT_TEST_SUITE_REGISTRATION(QueryEventsTest);
/**
+ * Returns the last automatically generated id, if any.
+ */
+long int glite_lbu_Lastid(glite_lbu_Statement stmt);
+
+
+/**
* @} database group
*/
static int transaction_test(glite_lbu_DBContext ctx);
static int FetchRowSimple(glite_lbu_DBContext ctx, MYSQL_RES *result, unsigned long *lengths, char **results);
static int FetchRowPrepared(glite_lbu_DBContext ctx, glite_lbu_Statement stmt, unsigned int n, unsigned long *lengths, char **results);
-void set_time(MYSQL_TIME *mtime, const time_t time);
-time_t get_time(const MYSQL_TIME *mtime);
+static void set_time(MYSQL_TIME *mtime, const time_t time);
/* ---- common ---- */
void glite_lbu_DBClose(glite_lbu_DBContext ctx) {
db_close(ctx->mysql);
ctx->mysql = NULL;
+ CLR_ERR(ctx);
}
int glite_lbu_Transaction(glite_lbu_DBContext ctx) {
+ CLR_ERR(ctx);
if (USE_TRANS(ctx)) {
if (glite_lbu_ExecSQL(ctx, "SET AUTOCOMMIT=0", NULL) < 0) goto err;
if (glite_lbu_ExecSQL(ctx, "BEGIN", NULL) < 0) goto err;
int glite_lbu_Commit(glite_lbu_DBContext ctx) {
+ CLR_ERR(ctx);
if (USE_TRANS(ctx)) {
if (glite_lbu_ExecSQL(ctx, "COMMIT", NULL) < 0) goto err;
if (glite_lbu_ExecSQL(ctx, "SET AUTOCOMMIT=1", NULL) < 0) goto err;
int glite_lbu_Rollback(glite_lbu_DBContext ctx) {
+ CLR_ERR(ctx);
if (USE_TRANS(ctx)) {
if (glite_lbu_ExecSQL(ctx, "ROLLBACK", NULL) < 0) goto err;
if (glite_lbu_ExecSQL(ctx, "SET AUTOCOMMIT=1", NULL) < 0) goto err;
int i,j,ret;
/* XXX: "show index from" columns. Matches at least MySQL 4.0.11 */
- char *showcol[12];
+ char *sql, *showcol[12];
int Key_name,Seq_in_index,Column_name,Sub_part;
char **keys = NULL;
Key_name = Seq_in_index = Column_name = Sub_part = -1;
- if (glite_lbu_ExecSQL(ctx,"show index from states",&stmt)<0)
+ asprintf(&sql, "show index from %s", table);
+ if (glite_lbu_ExecSQL(ctx,sql,&stmt)<0) {
+ free(sql);
return STATUS(ctx);
+ }
+ free(sql);
while ((ret = glite_lbu_FetchRow(stmt,sizeof(showcol)/sizeof(showcol[0]),NULL,showcol)) > 0) {
assert(ret <= (int)(sizeof showcol/sizeof showcol[0]));
int i = 0;
MYSQL_FIELD *f;
+ CLR_ERR(stmt->ctx);
if (!stmt->result) return ERR(stmt->ctx, EINVAL, "QueryColumns implemented only for simple API");
while ((f = mysql_fetch_field(stmt->result))) cols[i++] = f->name;
return i == 0;
}
+long int glite_lbu_Lastid(glite_lbu_Statement stmt) {
+ my_ulonglong i;
+
+ CLR_ERR(stmt->ctx);
+ i = mysql_stmt_insert_id(stmt->stmt);
+ assert(i < ((unsigned long int)-1) >> 1);
+ return (long int)i;
+}
+
+
/*
* helping compatibility function: clear error from the context
*/
/*
- * Ehelping function: error handle
+ * helping function: error handle
*
* \return -1 failed
* \return 0 retry
if (*retry > 0) {
(*retry)--;
return 0;
- } else
+ } else {
+ myerrstmt(stmt, source, line);
return -1;
+ }
break;
default:
myerrstmt(stmt, source, line);
free(buf);
ctx->cs = cs;
- return 0;
+ return CLR_ERR(ctx);
}
}
-void set_time(MYSQL_TIME *mtime, const time_t time) {
+static void set_time(MYSQL_TIME *mtime, const time_t time) {
struct tm tm;
gmtime_r(&time, &tm);
mtime->minute = tm.tm_min;
mtime->second = tm.tm_sec;
}
-
-
-time_t get_time(const MYSQL_TIME *mtime) {
- struct tm tm;
-
- memset(&tm, 0, sizeof(tm));
- setenv("TZ","UTC",1); tzset();
- tm.tm_year = mtime->year - 1900;
- tm.tm_mon = mtime->month - 1;
- tm.tm_mday = mtime->day;
- tm.tm_hour = mtime->hour;
- tm.tm_min = mtime->minute;
- tm.tm_sec = mtime->second;
-
- return mktime(&tm);
-}