QueryCond C -> SOAP conversions
authorMiloš Mulač <mulac@civ.zcu.cz>
Fri, 2 Sep 2005 13:03:35 +0000 (13:03 +0000)
committerMiloš Mulač <mulac@civ.zcu.cz>
Fri, 2 Sep 2005 13:03:35 +0000 (13:03 +0000)
org.glite.jp.index/Makefile
org.glite.jp.index/src/soap_ps_calls.c
org.glite.jp.index/src/ws_typemap.h [new file with mode: 0644]
org.glite.jp.index/src/ws_typeref.c [new file with mode: 0644]

index 711de56..dc62793 100644 (file)
@@ -46,7 +46,7 @@ example:=jpis-test
 is_prefix:=jpis_
 ps_prefix:=jpps_
 
-SRCS:= conf.c bones_server.c soap_ops.c soap_ps_calls.c \
+SRCS:= conf.c bones_server.c soap_ops.c soap_ps_calls.c ws_typeref.c\
        ${is_prefix}ServerLib.c \
        ${ps_prefix}ClientLib.c ${ps_prefix}C.c
 
index 8bbdef8..be58808 100644 (file)
@@ -12,6 +12,9 @@
 
 #include "stdsoap2.h"
 
+extern int glite_jpis_QueryCondToSoap(struct soap *soap, glite_jp_query_rec_t *in, struct jptype__primaryQuery **out);
+
+
 /*------------------*/
 /* Helper functions */
 /*------------------*/
@@ -85,6 +88,7 @@ printf("MyFeedIndex for %s called\n", dest);
        in.__sizeattributes = i;
        in.attributes = conf->attrs;
 
+/*
        // XXX: we need C -> WSDL conversion function !
        query.attr = conf->query[0][0].attr;
        query.op = conf->query[0][0].op;        // XXX: nasty, needs conversion
@@ -96,9 +100,18 @@ printf("MyFeedIndex for %s called\n", dest);
        value.blob = NULL;
        query.value = &value;
        query.value2 = NULL;
+*/
+       for (i=0; conf->query[i]; i++);
+       in.__sizeconditions = i;
+       in.conditions = malloc(i * sizeof(*in.conditions));
+
+       for (i=0; conf->query[i]; i++) {
+               if (glite_jpis_QueryCondToSoap(soap, conf->query[i], &(in.conditions[i])) != SOAP_OK) {
+                       printf("MyFeedIndex() - error during conds conversion\n");
+                       goto err;
+               }
+       }
 
-       in.__sizeconditions = 1;
-       in.conditions = malloc(sizeof(*in.conditions));
        in.conditions[0] = &query;      // XXX: supp. only one dimensional queries ! (no ORs)
                                        // for 2D queries one more _sizeconditions needed IMO
 
@@ -106,11 +119,14 @@ printf("MyFeedIndex for %s called\n", dest);
        in.continuous = conf->continuous;
 
        //if (!check_fault(soap,soap_call_jpsrv___FeedIndex(soap,dest,"",
-       if (soap_call___jpsrv__FeedIndex(soap,dest,"", &in, &out))
+       if (soap_call___jpsrv__FeedIndex(soap,dest,"", &in, &out)) {
                printf("soap_call___jpsrv__FeedIndex() returned error\n");
+               goto err;
+       }
        else
                printf("FeedId: %s\nExpires: %s\n",out.feedId,ctime(&out.feedExpires));
        
+err:
        soap_end(soap);
 }
 
diff --git a/org.glite.jp.index/src/ws_typemap.h b/org.glite.jp.index/src/ws_typemap.h
new file mode 100644 (file)
index 0000000..e662e93
--- /dev/null
@@ -0,0 +1,24 @@
+// XXX: may be glued with org.glite.jp.primary/src/jptype_map.h?
+
+#include "soap_version.h"
+
+#if GSOAP_VERSION >= 20700
+
+#define SYSTEM jptype__attrOrig__SYSTEM
+#define USER jptype__attrOrig__USER
+#define FILE jptype__attrOrig__FILE_
+
+#define EQUAL jptype__queryOp__EQUAL
+#define UNEQUAL jptype__queryOp__UNEQUAL
+#define LESS jptype__queryOp__LESS
+#define GREATER jptype__queryOp__GREATER
+#define WITHIN jptype__queryOp__WITHIN
+#define EXISTS jptype__queryOp__EXISTS
+
+#else
+
+#define __jpsrv__UpdateJobs __ns1__UpdateJobs
+#define __jpsrv__QueryJobs __ns1__QueryJobs
+
+#endif
+
diff --git a/org.glite.jp.index/src/ws_typeref.c b/org.glite.jp.index/src/ws_typeref.c
new file mode 100644 (file)
index 0000000..ae10272
--- /dev/null
@@ -0,0 +1,112 @@
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdsoap2.h>
+
+#include "glite/jp/types.h"
+
+#include "jpps_H.h"
+#include "ws_typemap.h"
+
+
+
+static void QueryOpToSoap(const glite_jp_queryop_t in, enum jptype__queryOp *out)
+{
+        switch ( in )
+        {
+        case GLITE_JP_QUERYOP_EQUAL: *out = EQUAL; break;
+        case GLITE_JP_QUERYOP_UNEQUAL: *out = UNEQUAL; break;
+        case GLITE_JP_QUERYOP_LESS: *out = LESS; break;
+        case GLITE_JP_QUERYOP_GREATER: *out = GREATER; break;
+        case GLITE_JP_QUERYOP_WITHIN: *out = WITHIN; break;
+        case GLITE_JP_QUERYOP_EXISTS: *out = EXISTS; break;
+        default: assert(0); break;
+        }
+}
+
+static void OrigToSoap(struct soap *soap, const glite_jp_attr_orig_t in, enum jptype__attrOrig **out)
+{
+       enum jptype__attrOrig   *o = soap_malloc(soap, sizeof(*o));
+
+        switch ( in )
+        {
+        case GLITE_JP_ATTR_ORIG_ANY: o = NULL; break;
+        case GLITE_JP_ATTR_ORIG_SYSTEM: *o = SYSTEM; break;
+        case GLITE_JP_ATTR_ORIG_USER: *o = USER; break;
+        case GLITE_JP_ATTR_ORIG_FILE: *o = FILE; break;
+        default: assert(0); break;
+        }
+       
+       *out = o;
+}
+
+
+static int QueryValToSoap(
+        struct soap                    *soap,
+       int                             binary,
+       size_t                          size,
+        char                           *in,
+        struct jptype__stringOrBlob    **out)
+{
+       struct jptype__stringOrBlob     *val;
+
+       
+        assert(in); assert(out);
+       if ( !(val = soap_malloc(soap, sizeof(*val))) ) return SOAP_FAULT;
+
+        if (binary) {
+               val->string = NULL;
+               if ( !(val->blob = soap_malloc(soap, sizeof(*val->blob))) ) return SOAP_FAULT;
+               val->blob->__size = size;
+               if ( !(val->blob->__ptr = soap_malloc(soap, val->blob->__size)) ) return SOAP_FAULT;
+               memcpy(val->blob->__ptr, in, val->blob->__size);
+               // XXX how to handle id, type, option?
+       }
+       else {
+               val->blob = NULL;
+               if ( !(val->string = soap_strdup(soap, in)) )  return SOAP_FAULT;
+       }
+
+       return SOAP_OK;
+}
+
+
+/**
+ * Translate JP query condition from C query_rec to Soap
+ *
+ * \param IN in glite_jp_query_rec_t query record
+ * \param OUT Soap structure
+ */
+int glite_jpis_QueryCondToSoap(
+       struct soap                     *soap,
+       glite_jp_query_rec_t            *in, 
+       struct jptype__primaryQuery     **out)
+{
+       struct jptype__primaryQuery     *qr;
+
+       assert(in); assert(out);
+       if ( !(qr = soap_malloc(soap, sizeof(*qr))) ) return SOAP_FAULT;
+       memset(qr, 0, sizeof(*qr));
+
+       if ( !(qr->attr = soap_strdup(soap, in->attr)) ) return SOAP_FAULT;
+       QueryOpToSoap(in->op, &(qr->op));
+       OrigToSoap(soap, in->origin, &(qr->origin));
+       
+       switch ( in->op ) {
+       case GLITE_JP_QUERYOP_WITHIN:
+               if (QueryValToSoap(soap, in->binary, in->size2, in->value2, &qr->value2)) 
+                       return SOAP_FAULT;
+       default:
+               if (QueryValToSoap(soap, in->binary, in->size, in->value, &qr->value)) 
+                        return SOAP_FAULT;
+               break;
+       }
+
+       *out = qr;
+               
+       return SOAP_OK;
+}
+
+
+
+