From 0ccd2fc08e81003ddee42dbbe55bb3cebaa3a6b8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Fri, 14 Oct 2005 07:44:06 +0000 Subject: [PATCH] Symplified and improved preparing DB params. Correct including of one header. Phony targets, manually header dependencies. --- org.glite.jp.index/Makefile | 10 +++++++++ org.glite.jp.index/src/db_ops.c | 40 +++++++++------------------------- org.glite.jp.index/src/db_ops.h | 6 +++++ org.glite.jp.index/src/soap_ops.c | 3 +-- org.glite.jp.index/src/ws_is_typeref.c | 2 +- 5 files changed, 28 insertions(+), 33 deletions(-) diff --git a/org.glite.jp.index/Makefile b/org.glite.jp.index/Makefile index c4021d7..d21b89c 100644 --- a/org.glite.jp.index/Makefile +++ b/org.glite.jp.index/Makefile @@ -157,3 +157,13 @@ soap_version.h: perl -ne '$$. == 2 && /.*([0-9])\.([0-9])\.([0-9]).*/ && printf "#define GSOAP_VERSION %d%02d%02d\n",$$1,$$2,$$3' soapH.h >$@ -rm soapC.cpp soapH.h soapStub.h soapClient.cpp soapServer.cpp soapClientLib.cpp soapServerLib.cpp +db_ops.h: context.h +context.h: conf.h +db_ops.o: db_ops.c conf.h context.h db_ops.h +context.o: context.c conf.h context.h +soap_ps_calls.o: soap_ps_calls.c jpps_H.h jpps_.nsmap soap_version.h conf.h db_ops.h ws_ps_typeref.h context.h +soap_ops.o: soap_ops.c jpis_H.h jpis_.nsmap soap_version.h db_ops.h ws_ps_typeref.h ws_is_typeref.h context.h +ws_ps_typeref.o: ws_ps_typeref.c jpis_H.h ws_typemap.h ws_ps_typeref.h +ws_is_typeref.o: ws_is_typeref.c jpis_H.h ws_typemap.h ws_is_typeref.h + +.PHONY: default all compile check doc stage dist distsrc distbin install clean diff --git a/org.glite.jp.index/src/db_ops.c b/org.glite.jp.index/src/db_ops.c index 911e891..3c63f2e 100644 --- a/org.glite.jp.index/src/db_ops.c +++ b/org.glite.jp.index/src/db_ops.c @@ -287,8 +287,6 @@ int glite_jpis_initDatabase(glite_jpis_context_t ctx) { GLITE_JP_DB_TYPE_VARCHAR, type, &type_len); 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 = ctx->conf->attrs; i = 0; @@ -298,17 +296,13 @@ int glite_jpis_initDatabase(glite_jpis_context_t ctx) { // attrid column tmp = glite_jpis_attr_name2id(attrs[i]); - strncpy(attrid, tmp, sizeof(attrid) - 1); + GLITE_JPIS_PARAM(attrid, attrid_len, tmp); free(tmp); - attrid_len = strlen(attrid); - // attr name column - strncpy(name, attrs[i], sizeof(name) - 1); - name_len = strlen(name); + GLITE_JPIS_PARAM(name, name_len, attrs[i]); // indexed column indexed = is_indexed(ctx->conf, name); // type column - strncpy(type, type_full, sizeof(type) - 1); - type_len = strlen(type); + GLITE_JPIS_PARAM(type, type_len, type_full); // insert if (glite_jp_db_execute(stmt) == -1) goto fail; @@ -329,13 +323,11 @@ int glite_jpis_initDatabase(glite_jpis_context_t ctx) { 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]) { state = (feeds[i]->history ? GLITE_JP_IS_STATE_HIST : 0) | (feeds[i]->continuous ? GLITE_JP_IS_STATE_CONT : 0); locked = 0; - strncpy(source, feeds[i]->PS_URL, sizeof(source) - 1); - source_len = strlen(source); + GLITE_JPIS_PARAM(source, source_len, feeds[i]->PS_URL); assert(glite_jpis_db_queries_serialize(&conds, &conds_len, feeds[i]->query) == 0); assert(conds_len <= sizeof(dbconds)); dbconds_len = conds_len; @@ -545,9 +537,7 @@ int glite_jpis_initFeed(glite_jpis_context_t ctx, long int uniqueid, char *feedI { int ret; - memset(ctx->param_feedid, 0, sizeof(ctx->param_feedid)); - strncpy(ctx->param_feedid, feedId, sizeof(ctx->param_feedid) - 1); - ctx->param_feedid_len = strlen(ctx->param_feedid); + GLITE_JPIS_PARAM(ctx->param_feedid, ctx->param_feedid_len, feedId); glite_jp_db_set_time(ctx->param_expires, feedExpires); ctx->param_uniqueid = uniqueid; @@ -613,20 +603,14 @@ int glite_jpis_lazyInsertJob(glite_jpis_context_t ctx, const char *feedid, const lprintf("%s\n", __FUNCTION__); md5_jobid = str2md5(jobid); - memset(ctx->param_jobid, 0, sizeof(ctx->param_jobid)); - strncpy(ctx->param_jobid, md5_jobid, sizeof(ctx->param_jobid) - 1); - ctx->param_jobid_len = strlen(ctx->param_jobid); + GLITE_JPIS_PARAM(ctx->param_jobid, ctx->param_jobid_len, md5_jobid); switch (ret = glite_jp_db_execute(ctx->select_jobid_stmt)) { case 1: lprintf("jobid '%s' found\n", jobid); goto ok0; case 0: lprintf("%s:inserting jobid %s (%s)\n", __FUNCTION__, jobid, md5_jobid); - memset(ctx->param_dg_jobid, 0, sizeof(ctx->param_dg_jobid)); - memset(ctx->param_feedid, 0, sizeof(ctx->param_feedid)); - strncpy(ctx->param_dg_jobid, jobid, sizeof(ctx->param_dg_jobid) - 1); - strncpy(ctx->param_feedid, feedid, sizeof(ctx->param_feedid) - 1); - ctx->param_dg_jobid_len = strlen(ctx->param_dg_jobid); - ctx->param_feedid_len = strlen(ctx->param_feedid); + GLITE_JPIS_PARAM(ctx->param_dg_jobid, ctx->param_dg_jobid_len, jobid); + GLITE_JPIS_PARAM(ctx->param_feedid, ctx->param_feedid_len, feedid); if (glite_jp_db_execute(ctx->insert_job_stmt) != 1) goto fail; break; default: assert(ret != 1); break; @@ -634,17 +618,13 @@ int glite_jpis_lazyInsertJob(glite_jpis_context_t ctx, const char *feedid, const ok0: md5_cert = str2md5(owner); - memset(ctx->param_ownerid, 0, sizeof(ctx->param_ownerid)); - strncpy(ctx->param_ownerid, md5_cert, sizeof(ctx->param_ownerid) - 1); - ctx->param_ownerid_len = strlen(ctx->param_ownerid); + GLITE_JPIS_PARAM(ctx->param_ownerid, ctx->param_ownerid_len, md5_cert); switch (ret = glite_jp_db_execute(ctx->select_user_stmt)) { case 1: lprintf("%s:jobid '%s' found\n", __FUNCTION__, jobid); goto ok; case 0: lprintf("%s:inserting user %s (%s)\n", __FUNCTION__, owner, md5_cert); - memset(ctx->param_cert, 0, sizeof(ctx->param_cert)); - strncpy(ctx->param_cert, owner, sizeof(ctx->param_cert) - 1); - ctx->param_cert_len = strlen(ctx->param_cert); + GLITE_JPIS_PARAM(ctx->param_cert, ctx->param_cert_len, owner); if (glite_jp_db_execute(ctx->insert_user_stmt) != 1) goto fail; break; default: assert(ret != 1); break; diff --git a/org.glite.jp.index/src/db_ops.h b/org.glite.jp.index/src/db_ops.h index 6beac34..5aabae9 100644 --- a/org.glite.jp.index/src/db_ops.h +++ b/org.glite.jp.index/src/db_ops.h @@ -17,6 +17,12 @@ #define GLITE_JP_IS_STATE_ERROR 8 #define GLITE_JP_IS_STATE_ERROR_STR "8" +#define GLITE_JPIS_PARAM(DEST, DEST_LEN, SRC) do { \ + (DEST)[sizeof((DEST)) - 1] = '\0'; \ + strncpy((DEST), (SRC), sizeof((DEST)) - 1); \ + (DEST_LEN) = strlen((SRC)); \ +} while(0) + char *glite_jpis_attr_name2id(const char *name); diff --git a/org.glite.jp.index/src/soap_ops.c b/org.glite.jp.index/src/soap_ops.c index 8a470a8..a63d4c7 100644 --- a/org.glite.jp.index/src/soap_ops.c +++ b/org.glite.jp.index/src/soap_ops.c @@ -114,8 +114,7 @@ SOAP_FMAC5 int SOAP_FMAC6 __jpsrv__UpdateJobs( // get info about the feed feedid = jpelem__UpdateJobs->feedId; - memset(ctx->param_feedid, 0, sizeof(ctx->param_feedid)); - strncpy(ctx->param_feedid, feedid, sizeof(ctx->param_feedid) - 1); + GLITE_JPIS_PARAM(ctx->param_feedid, ctx->param_feedid_len, feedid); if ((ret = glite_jp_db_execute(ctx->select_info_feed_stmt)) != 1) { fprintf(stderr, "can't get info about '%s', returned %d records: %s (%s)\n", feedid, ret, jpctx->error->desc, jpctx->error->source); goto fail; diff --git a/org.glite.jp.index/src/ws_is_typeref.c b/org.glite.jp.index/src/ws_is_typeref.c index 3e8824c..a1b8346 100644 --- a/org.glite.jp.index/src/ws_is_typeref.c +++ b/org.glite.jp.index/src/ws_is_typeref.c @@ -7,7 +7,7 @@ #include "jpis_H.h" #include "ws_typemap.h" -#include "ws_ps_typeref.h" +#include "ws_is_typeref.h" void glite_jpis_SoapToQueryOp(const enum jptype__queryOp in, glite_jp_queryop_t *out) -- 1.8.2.3