From 8f53bdb966ba02d64236ac50f57e4b575d393156 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Thu, 22 Mar 2007 18:41:22 +0000 Subject: [PATCH] Fixed SEGV for condition with EXISTS operation. Implemented origin queries with according tests. --- org.glite.jp.index/Makefile | 3 +- org.glite.jp.index/examples/jpis-client.c | 14 +++++-- org.glite.jp.index/examples/query-tests/authz.out | 5 ++- .../examples/query-tests/complex_query.out | 8 ++-- org.glite.jp.index/examples/query-tests/dump1.sql | 4 +- .../examples/query-tests/jobid_query.out | 3 +- .../examples/query-tests/origin_query.in | 20 ++++++++++ .../examples/query-tests/origin_query.out | 14 +++++++ .../examples/query-tests/run-test.sh | 8 ++++ .../examples/query-tests/simple_query.out | 3 +- org.glite.jp.index/src/context.c | 9 +++++ org.glite.jp.index/src/context.h | 2 + org.glite.jp.index/src/db_ops.c | 37 +++++++++--------- org.glite.jp.index/src/soap_ops.c | 45 +++++++++------------- 14 files changed, 117 insertions(+), 58 deletions(-) create mode 100644 org.glite.jp.index/examples/query-tests/origin_query.in create mode 100644 org.glite.jp.index/examples/query-tests/origin_query.out diff --git a/org.glite.jp.index/Makefile b/org.glite.jp.index/Makefile index 3950c24..34dd4ac 100644 --- a/org.glite.jp.index/Makefile +++ b/org.glite.jp.index/Makefile @@ -49,7 +49,8 @@ INSTALL:=libtool --mode=install install daemon:=glite-jp-indexd examples:=glite-jpis-test glite-jpis-client test:=run-test.sh -test_files:=dump1.sql simple_query.in simple_query.out complex_query.in complex_query.out authz.out jobid_query.in jobid_query.out +test_files:=dump1.sql simple_query.in simple_query.out complex_query.in complex_query.out authz.out jobid_query.in jobid_query.out origin_query.in origin_query.out + MANS1:=glite-jpis-client.1 MANS8:=glite-jp-indexd.8 MANS:=${MANS1} ${MANS8} diff --git a/org.glite.jp.index/examples/jpis-client.c b/org.glite.jp.index/examples/jpis-client.c index aeb5395..f35c670 100644 --- a/org.glite.jp.index/examples/jpis-client.c +++ b/org.glite.jp.index/examples/jpis-client.c @@ -24,7 +24,7 @@ #define soap_serialize__jpisclient__QueryJobsResponse soap_serialize__jpelem__QueryJobsResponse #define DEFAULT_JPIS "http://localhost:8902" -//#define USE_GMT 1 +#define USE_GMT 1 /* namespaces[] not used here but needed to prevent linker to complain... */ @@ -138,7 +138,8 @@ static void query_example_fill(struct soap *soap, struct _jpisclient__QueryJobs cond = soap_malloc(soap, sizeof(*cond)); memset(cond, 0, sizeof(*cond)); cond->attr = soap_strdup(soap, "http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus"); - cond->origin = NULL; + cond->origin = soap_malloc(soap, sizeof(*(cond->origin))); + *(cond->origin) = jptype__attrOrig__SYSTEM; cond->__sizerecord = 2; cond->record = soap_malloc(soap, cond->__sizerecord * sizeof(*(cond->record))); @@ -228,11 +229,18 @@ static void query_print(FILE *out, const struct _jpisclient__QueryJobs *in) { fprintf(out, "Conditions:\n"); for (i = 0; i < in->__sizeconditions; i++) { fprintf(out, "\t%s\n", in->conditions[i]->attr); + if (in->conditions[i]->origin) { + for (k = 0; k <= NUMBER_ORIG; k++) + if (origins[k].orig == *(in->conditions[i]->origin)) break; + fprintf(out, "\t\torigin == %s\n", origins[k].name); + } else { + fprintf(out, "\t\torigin IS ANY\n"); + } for (j = 0; j < in->conditions[i]->__sizerecord; j++) { rec = in->conditions[i]->record[j]; for (k = 0; k <= NUMBER_OP; k++) if (operations[k].op == rec->op) break; - fprintf(out, "\t\t%s", operations[k].name); + fprintf(out, "\t\tvalue %s", operations[k].name); if (rec->value) { fprintf(out, " "); value_print(out, rec->value); diff --git a/org.glite.jp.index/examples/query-tests/authz.out b/org.glite.jp.index/examples/query-tests/authz.out index 21458e0..a3d8c20 100644 --- a/org.glite.jp.index/examples/query-tests/authz.out +++ b/org.glite.jp.index/examples/query-tests/authz.out @@ -2,7 +2,8 @@ query: using JPIS http://localhost:10000 Conditions: http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus - == Ready + origin IS ANY + value == Ready Attributes: http://egee.cesnet.cz/en/Schema/JP/System:owner http://egee.cesnet.cz/en/Schema/JP/System:jobId @@ -10,4 +11,4 @@ Attributes: http://egee.cesnet.cz/en/Schema/LB/Attributes:user OK - \ No newline at end of file + diff --git a/org.glite.jp.index/examples/query-tests/complex_query.out b/org.glite.jp.index/examples/query-tests/complex_query.out index 1acd133..a16cd61 100644 --- a/org.glite.jp.index/examples/query-tests/complex_query.out +++ b/org.glite.jp.index/examples/query-tests/complex_query.out @@ -2,10 +2,12 @@ query: using JPIS http://localhost:10000 Conditions: http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus - == Done - == Ready + origin IS ANY + value == Done + value == Ready http://egee.cesnet.cz/en/Schema/LB/Attributes:user - <> God + origin IS ANY + value <> God Attributes: http://egee.cesnet.cz/en/Schema/JP/System:owner http://egee.cesnet.cz/en/Schema/JP/System:jobId diff --git a/org.glite.jp.index/examples/query-tests/dump1.sql b/org.glite.jp.index/examples/query-tests/dump1.sql index 5551181..814b5e4 100644 --- a/org.glite.jp.index/examples/query-tests/dump1.sql +++ b/org.glite.jp.index/examples/query-tests/dump1.sql @@ -303,7 +303,7 @@ CREATE TABLE `attr_9892f81a8175c09bd00afcb152f510ad` ( /*!40000 ALTER TABLE `attr_9892f81a8175c09bd00afcb152f510ad` DISABLE KEYS */; LOCK TABLES `attr_9892f81a8175c09bd00afcb152f510ad` WRITE; -INSERT INTO `attr_9892f81a8175c09bd00afcb152f510ad` VALUES ('593e62a063231f8c623b74406b3e12b0','CertSubj','S:3601:F::CertSubj',1),('9276789a0093ad44457655ef03ade36a','CertSubj','S:3601:S::CertSubj',2); +INSERT INTO `attr_9892f81a8175c09bd00afcb152f510ad` VALUES ('593e62a063231f8c623b74406b3e12b0','CertSubj','S:7201:F::CertSubj',3),('9276789a0093ad44457655ef03ade36a','CertSubj','S:7201:S::CertSubj',2); UNLOCK TABLES; /*!40000 ALTER TABLE `attr_9892f81a8175c09bd00afcb152f510ad` ENABLE KEYS */; @@ -352,7 +352,7 @@ CREATE TABLE `attr_a1e9e0a1b7943cc041fefb5da65868f9` ( /*!40000 ALTER TABLE `attr_a1e9e0a1b7943cc041fefb5da65868f9` DISABLE KEYS */; LOCK TABLES `attr_a1e9e0a1b7943cc041fefb5da65868f9` WRITE; -INSERT INTO `attr_a1e9e0a1b7943cc041fefb5da65868f9` VALUES ('593e62a063231f8c623b74406b3e12b0','Done','S:3601:F::Done',1),('9276789a0093ad44457655ef03ade36a','Ready','S:3601:S::Ready',1); +INSERT INTO `attr_a1e9e0a1b7943cc041fefb5da65868f9` VALUES ('593e62a063231f8c623b74406b3e12b0','Done','S:7201:F::Done',3),('9276789a0093ad44457655ef03ade36a','Ready','S:7201:S::Ready',1); UNLOCK TABLES; /*!40000 ALTER TABLE `attr_a1e9e0a1b7943cc041fefb5da65868f9` ENABLE KEYS */; diff --git a/org.glite.jp.index/examples/query-tests/jobid_query.out b/org.glite.jp.index/examples/query-tests/jobid_query.out index 36e4164..2450fbe 100644 --- a/org.glite.jp.index/examples/query-tests/jobid_query.out +++ b/org.glite.jp.index/examples/query-tests/jobid_query.out @@ -2,7 +2,8 @@ query: using JPIS http://localhost:12002 Conditions: http://egee.cesnet.cz/en/Schema/JP/System:jobId - == https://localhost:7846/pokus1 + origin IS ANY + value == https://localhost:7846/pokus1 Attributes: http://egee.cesnet.cz/en/Schema/JP/System:owner http://egee.cesnet.cz/en/Schema/JP/System:jobId diff --git a/org.glite.jp.index/examples/query-tests/origin_query.in b/org.glite.jp.index/examples/query-tests/origin_query.in new file mode 100644 index 0000000..47bdec3 --- /dev/null +++ b/org.glite.jp.index/examples/query-tests/origin_query.in @@ -0,0 +1,20 @@ + + + + + http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus + FILE + + EQUAL + + Done + + + + + http://egee.cesnet.cz/en/Schema/JP/System:owner + http://egee.cesnet.cz/en/Schema/JP/System:jobId + http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus + http://egee.cesnet.cz/en/Schema/LB/Attributes:user + + diff --git a/org.glite.jp.index/examples/query-tests/origin_query.out b/org.glite.jp.index/examples/query-tests/origin_query.out new file mode 100644 index 0000000..bd8e3a7 --- /dev/null +++ b/org.glite.jp.index/examples/query-tests/origin_query.out @@ -0,0 +1,14 @@ +query: using JPIS http://localhost:12002 + +Conditions: + http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus + origin == FILE + value == Done +Attributes: + http://egee.cesnet.cz/en/Schema/JP/System:owner + http://egee.cesnet.cz/en/Schema/JP/System:jobId + http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus + http://egee.cesnet.cz/en/Schema/LB/Attributes:user + +OK +https://localhost:7846/pokus1/O=CESNET/O=Masaryk University/CN=Milos Mulachttp://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatusDone1970-01-01T02:00:01ZFILEhttp://egee.cesnet.cz/en/Schema/LB/Attributes:userCertSubj1970-01-01T02:00:01ZFILEhttp://localhost:8901 \ No newline at end of file diff --git a/org.glite.jp.index/examples/query-tests/run-test.sh b/org.glite.jp.index/examples/query-tests/run-test.sh index 36cbb99..0e8ce22 100755 --- a/org.glite.jp.index/examples/query-tests/run-test.sh +++ b/org.glite.jp.index/examples/query-tests/run-test.sh @@ -229,3 +229,11 @@ import_db $GLITE_LOCATION/examples/query-tests/dump1.sql; run_test_query $GLITE_LOCATION/examples/query-tests/jobid_query.in $GLITE_LOCATION/examples/query-tests/jobid_query.out; drop_db; kill_is; + +echo -n "Origin test........... " +create_db; +run_is "-n"; +import_db $GLITE_LOCATION/examples/query-tests/dump1.sql; +run_test_query $GLITE_LOCATION/examples/query-tests/origin_query.in $GLITE_LOCATION/examples/query-tests/origin_query.out; +drop_db; +kill_is; diff --git a/org.glite.jp.index/examples/query-tests/simple_query.out b/org.glite.jp.index/examples/query-tests/simple_query.out index 4972f0f..7cd54fb 100644 --- a/org.glite.jp.index/examples/query-tests/simple_query.out +++ b/org.glite.jp.index/examples/query-tests/simple_query.out @@ -2,7 +2,8 @@ query: using JPIS http://localhost:10000 Conditions: http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus - == Ready + origin IS ANY + value == Ready Attributes: http://egee.cesnet.cz/en/Schema/JP/System:owner http://egee.cesnet.cz/en/Schema/JP/System:jobId diff --git a/org.glite.jp.index/src/context.c b/org.glite.jp.index/src/context.c index 0f09b40..d6f1379 100644 --- a/org.glite.jp.index/src/context.c +++ b/org.glite.jp.index/src/context.c @@ -10,12 +10,21 @@ int glite_jpis_init_context(glite_jpis_context_t *isctx, glite_jp_context_t jpctx, glite_jp_is_conf *conf) { char hname[512]; + char *op_args; if ((*isctx = calloc(sizeof(**isctx), 1)) != NULL) { (*isctx)->jpctx = jpctx; (*isctx)->conf = conf; globus_libc_gethostname(hname, sizeof hname); asprintf(&(*isctx)->hname, "https://%s:%s", hname, (conf && conf->port) ? conf->port : GLITE_JPIS_DEFAULT_PORT_STR); + + op_args = (*isctx)->op_args; + op_args[GLITE_JP_QUERYOP_WITHIN] = 2; + op_args[GLITE_JP_QUERYOP_UNDEF] = 0; + op_args[GLITE_JP_QUERYOP_EQUAL] = 1; + op_args[GLITE_JP_QUERYOP_LESS] = 1; + op_args[GLITE_JP_QUERYOP_GREATER] = 1; + op_args[GLITE_JP_QUERYOP_EXISTS] = 0; return 0; } else return ENOMEM; } diff --git a/org.glite.jp.index/src/context.h b/org.glite.jp.index/src/context.h index cd144fd..d67445a 100644 --- a/org.glite.jp.index/src/context.h +++ b/org.glite.jp.index/src/context.h @@ -17,6 +17,8 @@ typedef struct _glite_jpis_context { void *param_expires; char *hname; + + char op_args[GLITE_JP_QUERYOP__LAST]; } *glite_jpis_context_t; typedef struct _slave_data_t{ diff --git a/org.glite.jp.index/src/db_ops.c b/org.glite.jp.index/src/db_ops.c index 71f1291..44649a0 100644 --- a/org.glite.jp.index/src/db_ops.c +++ b/org.glite.jp.index/src/db_ops.c @@ -60,23 +60,24 @@ static int is_indexed(glite_jp_is_conf *conf, const char *attr) { } -static size_t db_arg2_length(glite_jp_query_rec_t *query) { +static size_t db_arg1_length(glite_jpis_context_t isctx, glite_jp_query_rec_t *query) { size_t len; assert(query->op > GLITE_JP_QUERYOP_UNDEF && query->op <= GLITE_JP_QUERYOP__LAST); - len = 0; - switch (query->op) { - case GLITE_JP_QUERYOP_WITHIN: - len = query->binary ? query->size2 : strlen(query->value2) + 1; - case GLITE_JP_QUERYOP_UNDEF: - case GLITE_JP_QUERYOP_EQUAL: - case GLITE_JP_QUERYOP_UNEQUAL: - case GLITE_JP_QUERYOP_LESS: - case GLITE_JP_QUERYOP_GREATER: - case GLITE_JP_QUERYOP_EXISTS: - case GLITE_JP_QUERYOP__LAST: - len = 0; - } + if (isctx->op_args[query->op] >= 1) + len = query->binary ? query->size : (query->value ? strlen(query->value) + 1 : 0); + else len = 0; + + return len; +} + +static size_t db_arg2_length(glite_jpis_context_t isctx, glite_jp_query_rec_t *query) { + size_t len; + + assert(query->op > GLITE_JP_QUERYOP_UNDEF && query->op <= GLITE_JP_QUERYOP__LAST); + if (isctx->op_args[query->op] >= 1) + len = query->binary ? query->size2 : (query->value2 ? strlen(query->value2) + 1 : 0); + else len = 0; return len; } @@ -141,7 +142,7 @@ static void *array_get(void **data, size_t data_len) { } -static int glite_jpis_db_queries_serialize(void **blob, size_t *len, glite_jp_query_rec_t **queries) { +static int glite_jpis_db_queries_serialize(glite_jpis_context_t isctx, void **blob, size_t *len, glite_jp_query_rec_t **queries) { size_t maxlen; glite_jp_query_rec_t *query; int ret; @@ -157,12 +158,12 @@ static int glite_jpis_db_queries_serialize(void **blob, size_t *len, glite_jp_qu if ((ret = array_add_long(blob, len, &maxlen, query->op)) != 0) goto fail; if ((ret = array_add_long(blob, len, &maxlen, query->binary ? 1 : 0)) != 0) goto fail; - datalen = query->binary ? query->size : strlen(query->value) + 1; + datalen = db_arg1_length(isctx, query); if ((ret = array_add_long(blob, len, &maxlen, datalen)) != 0) goto fail; if (datalen) if ((ret = array_add(blob, len, &maxlen, query->value, datalen)) != 0) goto fail; - datalen = db_arg2_length(query); + datalen = db_arg2_length(isctx, query); if ((ret = array_add_long(blob, len, &maxlen, datalen)) != 0) goto fail; if (datalen) if ((ret = array_add(blob, len, &maxlen, query->value2, datalen)) != 0) goto fail; @@ -327,7 +328,7 @@ int glite_jpis_initDatabase(glite_jpis_context_t ctx) { (feeds[i]->continuous ? GLITE_JP_IS_STATE_CONT : 0); locked = 0; GLITE_JPIS_PARAM(source, source_len, feeds[i]->PS_URL); - assert(glite_jpis_db_queries_serialize(&conds, &conds_len, feeds[i]->query) == 0); + assert(glite_jpis_db_queries_serialize(ctx, &conds, &conds_len, feeds[i]->query) == 0); assert(conds_len <= sizeof(dbconds)); dbconds_len = conds_len; memcpy(dbconds, conds, conds_len); diff --git a/org.glite.jp.index/src/soap_ops.c b/org.glite.jp.index/src/soap_ops.c index 68bf149..2c29a25 100644 --- a/org.glite.jp.index/src/soap_ops.c +++ b/org.glite.jp.index/src/soap_ops.c @@ -247,44 +247,35 @@ static int get_jobids(struct soap *soap, glite_jpis_context_t ctx, struct _jpele int i, j, ret; glite_jp_db_stmt_t stmt; glite_jp_attrval_t attr; + glite_jp_attr_orig_t orig; qwhere = strdup(""); for (i=0; i < in->__sizeconditions; i++) { -/* XXX: deal with jobIds diferently (they are not in attr_X table, but in jobs) - if (strcmp(in->conditions[i]->attr,GLITE_JP_ATTR_JOBID)) { - trio_asprintf(&qa,"%s (", (i ? "AND" : "") ); - - for (j=0; j < in->conditions[i]->__sizerecord; j++) { - if (get_op(in->conditions[i]->record[j]->op, &qop)) goto err; - - attr.name = in->conditions[i]->attr; - attr.value = in->conditions[i]->record[j]->value->string; - attr.binary = 0; - glite_jpis_SoapToAttrOrig(soap, - in->conditions[i]->origin, &(attr.origin)); - trio_asprintf(&qb,"%s%sjobs.dg_jobid %s \"%|Ss\"", - qa, (j ? " OR " : ""), attr_md5, qop, - glite_jp_attrval_to_db_index(ctx->jpctx, &attr, 255)); - free(qop); - free(qa); qa = qb; qb = NULL; - - } - else -*/ { + /* attr name */ if (strcmp(in->conditions[i]->attr, GLITE_JP_ATTR_JOBID) == 0) { /* no subset from attr_ table, used jobs table instead */ attr_md5 = NULL; qa = strdup("("); } else { - /* select given records in attr_ table */ attr_md5 = str2md5(in->conditions[i]->attr); - trio_asprintf(&qa,"%s jobs.jobid = attr_%|Ss.jobid AND (", - (i ? "AND" : ""), attr_md5); + + /* origin */ + if (in->conditions[i]->origin) { + glite_jpis_SoapToAttrOrig(soap, in->conditions[i]->origin, &orig); + trio_asprintf(&qb, "attr_%|Ss.origin = %d AND ", attr_md5, orig); + } else + trio_asprintf(&qb, ""); + + /* select given records in attr_ table */ + trio_asprintf(&qa,"%s%s jobs.jobid = attr_%|Ss.jobid AND (", + (i ? "AND" : ""), qb, attr_md5); + + free(qb); } - /* inside part of the condition - ORs */ + /* inside part of the condition: record list (ORs) */ for (j=0; j < in->conditions[i]->__sizerecord; j++) { if (get_op(in->conditions[i]->record[j]->op, &qop)) goto err; if (attr_md5) add_attr_table(attr_md5, &attr_tables); @@ -325,10 +316,10 @@ static int get_jobids(struct soap *soap, glite_jpis_context_t ctx, struct _jpele } if (ctx->conf->no_auth) { - trio_asprintf(&query, "SELECT DISTINCT dg_jobid,ps FROM jobs%s WHERE %s;", qa, qwhere); + trio_asprintf(&query, "SELECT DISTINCT dg_jobid,ps FROM jobs%s WHERE %s", qa, qwhere); } else { - trio_asprintf(&query, "SELECT DISTINCT dg_jobid,ps FROM jobs,users%s WHERE (jobs.ownerid = users.userid AND users.cert_subj='%s') AND %s;", qa, ctx->jpctx->peer, qwhere); + trio_asprintf(&query, "SELECT DISTINCT dg_jobid,ps FROM jobs,users%s WHERE (jobs.ownerid = users.userid AND users.cert_subj='%s') AND %s", qa, ctx->jpctx->peer, qwhere); } printf("Incomming QUERY:\n %s\n", query); free(qwhere); -- 1.8.2.3