Fixed SEGV for condition with EXISTS operation.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 22 Mar 2007 18:41:22 +0000 (18:41 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 22 Mar 2007 18:41:22 +0000 (18:41 +0000)
Implemented origin queries with according tests.

14 files changed:
org.glite.jp.index/Makefile
org.glite.jp.index/examples/jpis-client.c
org.glite.jp.index/examples/query-tests/authz.out
org.glite.jp.index/examples/query-tests/complex_query.out
org.glite.jp.index/examples/query-tests/dump1.sql
org.glite.jp.index/examples/query-tests/jobid_query.out
org.glite.jp.index/examples/query-tests/origin_query.in [new file with mode: 0644]
org.glite.jp.index/examples/query-tests/origin_query.out [new file with mode: 0644]
org.glite.jp.index/examples/query-tests/run-test.sh
org.glite.jp.index/examples/query-tests/simple_query.out
org.glite.jp.index/src/context.c
org.glite.jp.index/src/context.h
org.glite.jp.index/src/db_ops.c
org.glite.jp.index/src/soap_ops.c

index 3950c24..34dd4ac 100644 (file)
@@ -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}
index aeb5395..f35c670 100644 (file)
@@ -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);
index 21458e0..a3d8c20 100644 (file)
@@ -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
-<?xml version="1.0" encoding="UTF-8"?><jpisclient:QueryJobsResponse xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jptype="http://glite.org/wsdl/types/jp" xmlns:jpsrv="http://glite.org/wsdl/services/jp" xmlns:jpelem="http://glite.org/wsdl/elements/jp" xmlns:jpisclient="http://glite.org/xsd/types/jpisclient"></jpisclient:QueryJobsResponse>
\ No newline at end of file
+<?xml version="1.0" encoding="UTF-8"?><jpisclient:QueryJobsResponse xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jptype="http://glite.org/wsdl/types/jp" xmlns:jpsrv="http://glite.org/wsdl/services/jp" xmlns:jpelem="http://glite.org/wsdl/elements/jp" xmlns:jpisclient="http://glite.org/xsd/types/jpisclient"></jpisclient:QueryJobsResponse>
index 1acd133..a16cd61 100644 (file)
@@ -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
index 5551181..814b5e4 100644 (file)
@@ -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 */;
 
index 36e4164..2450fbe 100644 (file)
@@ -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 (file)
index 0000000..47bdec3
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jpisclient:QueryJobs xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jptype="http://glite.org/wsdl/types/jp" xmlns:jpsrv="http://glite.org/wsdl/services/jp" xmlns:jpelem="http://glite.org/wsdl/elements/jp" xmlns:jpisclient="http://glite.org/xsd/types/jpisclient">
+
+       <conditions>
+               <attr>http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus</attr>
+               <origin>FILE</origin>
+               <record>
+                       <op>EQUAL</op>
+                       <value>
+                               <string>Done</string>
+                       </value>
+               </record>
+       </conditions>
+
+       <attributes>http://egee.cesnet.cz/en/Schema/JP/System:owner</attributes>
+       <attributes>http://egee.cesnet.cz/en/Schema/JP/System:jobId</attributes>
+       <attributes>http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus</attributes>
+       <attributes>http://egee.cesnet.cz/en/Schema/LB/Attributes:user</attributes>
+
+</jpisclient:QueryJobs>
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 (file)
index 0000000..bd8e3a7
--- /dev/null
@@ -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
+<?xml version="1.0" encoding="UTF-8"?><jpisclient:QueryJobsResponse xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jptype="http://glite.org/wsdl/types/jp" xmlns:jpsrv="http://glite.org/wsdl/services/jp" xmlns:jpelem="http://glite.org/wsdl/elements/jp" xmlns:jpisclient="http://glite.org/xsd/types/jpisclient"><jobs><jobid>https://localhost:7846/pokus1</jobid><owner>/O=CESNET/O=Masaryk University/CN=Milos Mulac</owner><attributes><name>http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus</name><value><string>Done</string></value><timestamp>1970-01-01T02:00:01Z</timestamp><origin>FILE</origin></attributes><attributes><name>http://egee.cesnet.cz/en/Schema/LB/Attributes:user</name><value><string>CertSubj</string></value><timestamp>1970-01-01T02:00:01Z</timestamp><origin>FILE</origin></attributes><primaryStorage>http://localhost:8901</primaryStorage></jobs></jpisclient:QueryJobsResponse>
\ No newline at end of file
index 36cbb99..0e8ce22 100755 (executable)
@@ -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;
index 4972f0f..7cd54fb 100644 (file)
@@ -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
index 0f09b40..d6f1379 100644 (file)
 
 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;
 }
index cd144fd..d67445a 100644 (file)
@@ -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{
index 71f1291..44649a0 100644 (file)
@@ -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);
index 68bf149..2c29a25 100644 (file)
@@ -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);