From d7329d5c4c1ec4cb4448d1b2fbd95611cfbcf496 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Wed, 28 Feb 2007 15:00:33 +0000 Subject: [PATCH] Gsoap compatiblity, 1. part: error handling and choice type. So compatible with 2.7.6b for now. --- org.glite.jp.index/examples/jpis-test.c | 82 ++++++++------------------------- org.glite.jp.index/src/soap_ops.c | 69 ++++++--------------------- org.glite.jp.index/src/soap_ps_calls.c | 2 +- org.glite.jp.index/src/ws_is_typeref.c | 11 +++-- org.glite.jp.index/src/ws_ps_typeref.c | 25 +++++----- 5 files changed, 54 insertions(+), 135 deletions(-) diff --git a/org.glite.jp.index/examples/jpis-test.c b/org.glite.jp.index/examples/jpis-test.c index ef926dd..8337355 100644 --- a/org.glite.jp.index/examples/jpis-test.c +++ b/org.glite.jp.index/examples/jpis-test.c @@ -17,15 +17,15 @@ #define soap_call___jpsrv__UpdateJobs soap_call___ns1__UpdateJobs #define soap_call___jpsrv__QueryJobs soap_call___ns1__QueryJobs #endif +#define dprintf(FMT, ARGS...) fprintf(stderr, FMT, ##ARGS); +#define check_fault(SOAP, ERR) glite_jp_clientCheckFault((SOAP), (ERR), NULL, 0) +#include "glite/jp/ws_fault.c" /* insert simulating FeedIndex call */ #define INSERT "insert into feeds value ('93', '12345', '8', '0' , 'http://localhost:8901', '2005-10-14 10:48:27', 'COND2');" #define DELETE "delete from feeds where feedid = '12345';" -static int check_fault(struct soap *soap,int err); - - int main(int argc,char *argv[]) { @@ -79,7 +79,7 @@ int main(int argc,char *argv[]) memset(&out, 0, sizeof(out)); in.feedId = soap_strdup(soap, "12345"); - in.feedDone = false_; + in.feedDone = GLITE_SECURITY_GSOAP_FALSE; in.__sizejobAttributes = 2; in.jobAttributes = soap_malloc(soap, in.__sizejobAttributes * sizeof(*(in.jobAttributes))); @@ -107,8 +107,8 @@ int main(int argc,char *argv[]) rec->attributes[0] = soap_malloc(soap, sizeof(*(rec->attributes[0]))); rec->attributes[0]->name = soap_strdup(soap, "http://egee.cesnet.cz/en/Schema/LB/Attributes:user"); rec->attributes[0]->value = soap_malloc(soap, sizeof(*(rec->attributes[0]->value))); - rec->attributes[0]->value->string = soap_strdup(soap, "CertSubj"); - rec->attributes[0]->value->blob = NULL; + GSOAP_STRING(rec->attributes[0]->value) = soap_strdup(soap, "CertSubj"); + GSOAP_BLOB(rec->attributes[0]->value) = NULL; rec->attributes[0]->timestamp = 333; rec->attributes[0]->origin = jptype__attrOrig__SYSTEM; rec->attributes[0]->originDetail = NULL; @@ -116,8 +116,8 @@ int main(int argc,char *argv[]) rec->attributes[1] = soap_malloc(soap, sizeof(*(rec->attributes[1]))); rec->attributes[1]->name = soap_strdup(soap, "http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus"); rec->attributes[1]->value = soap_malloc(soap, sizeof(*(rec->attributes[0]->value))); - rec->attributes[1]->value->string = soap_strdup(soap, "Done"); - rec->attributes[1]->value->blob = NULL; + GSOAP_STRING(rec->attributes[1]->value) = soap_strdup(soap, "Done"); + GSOAP_BLOB(rec->attributes[1]->value) = NULL; rec->attributes[1]->timestamp = 333; rec->attributes[1]->origin = jptype__attrOrig__SYSTEM; rec->attributes[1]->originDetail = NULL; @@ -137,16 +137,16 @@ int main(int argc,char *argv[]) rec->attributes[0] = soap_malloc(soap, sizeof(*(rec->attributes[0]))); rec->attributes[0]->name = soap_strdup(soap, "http://egee.cesnet.cz/en/Schema/LB/Attributes:user"); rec->attributes[0]->value = soap_malloc(soap, sizeof(*(rec->attributes[0]->value))); - rec->attributes[0]->value->string = soap_strdup(soap, "CertSubj"); - rec->attributes[0]->value->blob = NULL; + GSOAP_STRING(rec->attributes[0]->value) = soap_strdup(soap, "CertSubj"); + GSOAP_BLOB(rec->attributes[0]->value) = NULL; rec->attributes[0]->timestamp = 333; rec->attributes[0]->origin = jptype__attrOrig__USER; rec->attributes[0]->originDetail = NULL; rec->attributes[1] = soap_malloc(soap, sizeof(*(rec->attributes[1]))); rec->attributes[1]->name = soap_strdup(soap, "http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus"); rec->attributes[1]->value = soap_malloc(soap, sizeof(*(rec->attributes[0]->value))); - rec->attributes[1]->value->string = soap_strdup(soap, "Ready"); - rec->attributes[1]->value->blob = NULL; + GSOAP_STRING(rec->attributes[1]->value) = soap_strdup(soap, "Ready"); + GSOAP_BLOB(rec->attributes[1]->value) = NULL; rec->attributes[1]->timestamp = 333; rec->attributes[1]->origin = jptype__attrOrig__SYSTEM; rec->attributes[1]->originDetail = NULL; @@ -186,8 +186,8 @@ int main(int argc,char *argv[]) memset(rec, 0, sizeof(*rec)); rec->op = jptype__queryOp__EQUAL; rec->value = soap_malloc(soap, sizeof(*(rec->value))); - rec->value->string = soap_strdup(soap, "Done"); - rec->value->blob = NULL; + GSOAP_STRING(rec->value) = soap_strdup(soap, "Done"); + GSOAP_BLOB(rec->value) = NULL; cond->record[0] = rec; // OR equal to Ready @@ -195,8 +195,8 @@ int main(int argc,char *argv[]) memset(rec, 0, sizeof(*rec)); rec->op = jptype__queryOp__EQUAL; rec->value = soap_malloc(soap, sizeof(*(rec->value))); - rec->value->string = soap_strdup(soap, "Ready"); - rec->value->blob = NULL; + GSOAP_STRING(rec->value) = soap_strdup(soap, "Ready"); + GSOAP_BLOB(rec->value) = NULL; cond->record[1] = rec; in.conditions[0] = cond; @@ -215,8 +215,8 @@ int main(int argc,char *argv[]) memset(rec, 0, sizeof(*rec)); rec->op = jptype__queryOp__UNEQUAL; rec->value = soap_malloc(soap, sizeof(*(rec->value))); - rec->value->string = soap_strdup(soap, "God"); - rec->value->blob = NULL; + GSOAP_STRING(rec->value) = soap_strdup(soap, "God"); + GSOAP_BLOB(rec->value) = NULL; cond->record[0] = rec; in.conditions[1] = cond; @@ -241,7 +241,7 @@ int main(int argc,char *argv[]) for (i=0; i__sizeattributes; i++) { printf("\t%s = %s\n", out.jobs[j]->attributes[i]->name, - out.jobs[j]->attributes[i]->value->string); + GSOAP_STRING(out.jobs[j]->attributes[i]->value)); } } } @@ -250,49 +250,5 @@ int main(int argc,char *argv[]) } -static int check_fault(struct soap *soap,int err) { - struct SOAP_ENV__Detail *detail; - struct jptype__genericFault *f; - char *reason,indent[200] = " "; - - switch(err) { - case SOAP_OK: puts("OK"); - break; - case SOAP_FAULT: - case SOAP_SVR_FAULT: - if (soap->version == 2) { - detail = soap->fault->SOAP_ENV__Detail; - reason = soap->fault->SOAP_ENV__Reason; - } - else { - detail = soap->fault->detail; - reason = soap->fault->faultstring; - } - fputs(reason,stderr); - putc('\n',stderr); - assert(detail->__type == SOAP_TYPE__genericFault); -#if GSOAP_VERSION >=20700 - f = ((struct _genericFault *) detail->fault) -#else - f = ((struct _genericFault *) detail->value) -#endif - -> jpelem__genericFault; - - while (f) { - fprintf(stderr,"%s%s: %s (%s)\n",indent, - f->source,f->text,f->description); - f = f->reason; - strcat(indent," "); - } - return -1; - - default: soap_print_fault(soap,stderr); - return -1; - } - return 0; -} - - - /* XXX: we don't use it */ SOAP_NMAC struct Namespace namespaces[] = { {NULL,NULL} }; diff --git a/org.glite.jp.index/src/soap_ops.c b/org.glite.jp.index/src/soap_ops.c index d4ace40..c183019 100644 --- a/org.glite.jp.index/src/soap_ops.c +++ b/org.glite.jp.index/src/soap_ops.c @@ -11,6 +11,7 @@ #include "jpis_H.h" #include "jpis_.nsmap" #include "soap_version.h" +#include "glite/security/glite_gscompat.h" #include "db_ops.h" // XXX: avoid 2 wsdl collisions - work only because ws_ps_typeref.h // uses common types from jpis_H.h (awful) @@ -22,53 +23,13 @@ // XXX: 2 is only for debugging, replace with e.g. 100 #define JOBIDS_STRIDE 2 // how often realloc matched jobids result -#if GSOAP_VERSION >= 20706 -#define false_ xsd__boolean__false_ -#endif - /*------------------*/ /* Helper functions */ /*------------------*/ - -static struct jptype__genericFault *jp2s_error(struct soap *soap, - const glite_jp_error_t *err) -{ - struct jptype__genericFault *ret = NULL; - if (err) { - ret = soap_malloc(soap,sizeof *ret); - memset(ret,0,sizeof *ret); - ret->code = err->code; - ret->source = soap_strdup(soap,err->source); - ret->text = soap_strdup(soap,strerror(err->code)); - ret->description = soap_strdup(soap,err->desc); - ret->reason = jp2s_error(soap,err->reason); - } - return ret; -} - -static void err2fault(const glite_jp_context_t ctx,struct soap *soap) -{ - struct SOAP_ENV__Detail *detail = soap_malloc(soap,sizeof *detail); - struct _genericFault *f = soap_malloc(soap,sizeof *f); - - - f->jpelem__genericFault = jp2s_error(soap,ctx->error); - - detail->__type = SOAP_TYPE__genericFault; -#if GSOAP_VERSION >= 20700 - detail->fault = f; -#else - detail->value = f; -#endif - detail->__any = NULL; - - soap_receiver_fault(soap,"Oh, shit!",NULL); - if (soap->version == 2) soap->fault->SOAP_ENV__Detail = detail; - else soap->fault->detail = detail; -} - - +#define dprintf(x) +#include "glite/jp/ws_fault.c" +#define err2fault(CTX, SOAP) glite_jp_server_err2fault((CTX), (SOAP)) @@ -87,7 +48,7 @@ static int updateJob(glite_jpis_context_t ctx, const char *ps, struct jptype__jo lprintf("jobid='%s', attrs=%d\n", jobAttrs->jobid, jobAttrs->__sizeattributes); - if (jobAttrs->remove) assert(*(jobAttrs->remove) == false_); + if (jobAttrs->remove) assert(*(jobAttrs->remove) == GLITE_SECURITY_GSOAP_FALSE); if ((ret = glite_jpis_lazyInsertJob(ctx, ps, jobAttrs->jobid, jobAttrs->owner)) != 0) return ret; for (iattrs = 0; iattrs < jobAttrs->__sizeattributes; iattrs++) { @@ -279,9 +240,9 @@ static int get_jobids(struct soap *soap, glite_jpis_context_t ctx, struct _jpele if (get_op(in->conditions[i]->record[j]->op, &qop)) goto err; add_attr_table(attr_md5, &attr_tables); - if (in->conditions[i]->record[j]->value->string) { + if (GSOAP_STRING(in->conditions[i]->record[j]->value)) { attr.name = in->conditions[i]->attr; - attr.value = in->conditions[i]->record[j]->value->string; + attr.value = GSOAP_STRING(in->conditions[i]->record[j]->value); attr.binary = 0; glite_jpis_SoapToAttrOrig(soap, in->conditions[i]->origin, &(attr.origin)); @@ -293,9 +254,9 @@ static int get_jobids(struct soap *soap, glite_jpis_context_t ctx, struct _jpele } else { attr.name = in->conditions[i]->attr; - attr.value = in->conditions[i]->record[j]->value->blob->__ptr; + attr.value = GSOAP_BLOB(in->conditions[i]->record[j]->value)->__ptr; attr.binary = 1; - attr.size = in->conditions[i]->record[j]->value->blob->__size; + attr.size = GSOAP_BLOB(in->conditions[i]->record[j]->value)->__size; glite_jpis_SoapToAttrOrig(soap, in->conditions[i]->origin, &(attr.origin)); trio_asprintf(&qb,"%s %s attr_%|Ss.value %s \"%|Ss\"", @@ -422,15 +383,15 @@ static int get_attr(struct soap *soap, glite_jpis_context_t ctx, char *jobid, ch av[i]->value = soap_malloc(soap, sizeof(*(av[i]->value))); memset(av[i]->value, 0, sizeof(*(av[i]->value))); if (jav.binary) { - av[i]->value->blob = soap_malloc(soap, sizeof(*(av[i]->value->blob))); - memset(av[i]->value->blob, 0, sizeof(*(av[i]->value->blob))); - av[i]->value->blob->__ptr = soap_malloc(soap, jav.size); - memcpy(av[i]->value->blob->__ptr, jav.value, jav.size); - av[i]->value->blob->__size = jav.size; + GSOAP_BLOB(av[i]->value) = soap_malloc(soap, sizeof(*(GSOAP_BLOB(av[i]->value)))); + memset(GSOAP_BLOB(av[i]->value), 0, sizeof(*(GSOAP_BLOB(av[i]->value)))); + GSOAP_BLOB(av[i]->value)->__ptr = soap_malloc(soap, jav.size); + memcpy(GSOAP_BLOB(av[i]->value)->__ptr, jav.value, jav.size); + GSOAP_BLOB(av[i]->value)->__size = jav.size; // XXX: id, type, option - how to handle? } else { - av[i]->value->string = soap_strdup(soap, jav.value); + GSOAP_STRING(av[i]->value) = soap_strdup(soap, jav.value); } // XXX: load timestamp and origin from DB // need to add columns to DB diff --git a/org.glite.jp.index/src/soap_ps_calls.c b/org.glite.jp.index/src/soap_ps_calls.c index 41ae0be..0fe3d47 100644 --- a/org.glite.jp.index/src/soap_ps_calls.c +++ b/org.glite.jp.index/src/soap_ps_calls.c @@ -135,7 +135,7 @@ int MyFeedIndex(glite_jpis_context_t ctx, glite_jp_is_conf *conf, long int uniqu struct soap *soap = soap_new(); glite_gsplugin_Context plugin_ctx; glite_jp_error_t err; - char *src, hname[512]; + char *src; lprintf("MyFeedIndex for %s called\n", dest); glite_gsplugin_init_context(&plugin_ctx); diff --git a/org.glite.jp.index/src/ws_is_typeref.c b/org.glite.jp.index/src/ws_is_typeref.c index 7f2a50c..a9d91f1 100644 --- a/org.glite.jp.index/src/ws_is_typeref.c +++ b/org.glite.jp.index/src/ws_is_typeref.c @@ -8,6 +8,7 @@ #include "jpis_H.h" #include "ws_typemap.h" #include "ws_is_typeref.h" +#include "glite/jp/ws_fault.c" void glite_jpis_SoapToQueryOp(const enum jptype__queryOp in, glite_jp_queryop_t *out) @@ -53,17 +54,17 @@ static int SoapToQueryRecordVal( { assert(in); - if (in->string) { + if (GSOAP_STRING(in)) { *binary = 0; *size = 0; - *value = strdup(in->string); + *value = strdup(GSOAP_STRING(in)); return 0; } - else if (in->blob) { + else if (GSOAP_BLOB(in)) { *binary = 1; - *size = in->blob->__size; - memcpy(*value, in->blob->__ptr, in->blob->__size); + *size = GSOAP_BLOB(in)->__size; + memcpy(*value, GSOAP_BLOB(in)->__ptr, GSOAP_BLOB(in)->__size); // XXX how to handle id, type, option? return 0; diff --git a/org.glite.jp.index/src/ws_ps_typeref.c b/org.glite.jp.index/src/ws_ps_typeref.c index 3fea887..9131ca5 100644 --- a/org.glite.jp.index/src/ws_ps_typeref.c +++ b/org.glite.jp.index/src/ws_ps_typeref.c @@ -8,6 +8,7 @@ #include "jpps_H.h" #include "ws_typemap.h" #include "ws_ps_typeref.h" +#include "glite/jp/ws_fault.c" static void QueryOpToSoap(const glite_jp_queryop_t in, enum jptype__queryOp *out) @@ -55,16 +56,16 @@ static int QueryRecordValToSoap( memset(val, 0, sizeof(*val) ); 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); + GSOAP_STRING(val) = NULL; + if ( !(GSOAP_BLOB(val) = soap_malloc(soap, sizeof(*GSOAP_BLOB(val)))) ) return SOAP_FAULT; + GSOAP_BLOB(val)->__size = size; + if ( !(GSOAP_BLOB(val)->__ptr = soap_malloc(soap, GSOAP_BLOB(val)->__size)) ) return SOAP_FAULT; + memcpy(GSOAP_BLOB(val)->__ptr, in, GSOAP_BLOB(val)->__size); // XXX how to handle id, type, option? } else { - val->blob = NULL; - if ( !(val->string = soap_strdup(soap, in)) ) return SOAP_FAULT; + GSOAP_BLOB(val) = NULL; + if ( !(GSOAP_STRING(val) = soap_strdup(soap, in)) ) return SOAP_FAULT; } *out = val; @@ -122,14 +123,14 @@ static void SoapToAttrOrig(glite_jp_attr_orig_t *out, const enum jptype__attrOri void glite_jpis_SoapToAttrVal(glite_jp_attrval_t *av, const struct jptype__attrValue *attr) { memset(av, 0, sizeof(*av)); av->name = attr->name; - av->binary = attr->value->blob ? 1 : 0; - assert(av->binary || attr->value->string); + av->binary = GSOAP_BLOB(attr->value) ? 1 : 0; + assert(av->binary || GSOAP_STRING(attr->value)); if (av->binary) { - av->value = attr->value->blob->__ptr; - av->size =attr->value->blob->__size ; + av->value = GSOAP_BLOB(attr->value)->__ptr; + av->size = GSOAP_BLOB(attr->value)->__size ; } else { av->size = -1; - av->value = attr->value->string; + av->value = GSOAP_STRING(attr->value); } SoapToAttrOrig(&av->origin, attr->origin); av->origin_detail = attr->originDetail; -- 1.8.2.3