From 39ccab64f0fba6cc9290cb095a00fa3d007eb51d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Wed, 14 Apr 2010 19:21:44 +0000 Subject: [PATCH] Web Services code updates: - fixed lb4agu example (certification test) - fixed fault processing for gsoap >= 2.7.10 (not default in glite 3.2) - duplicated code cleanup (client fault processing only in ws-test now) - small cleanups (warnings, memleaks in examples) --- org.glite.lb.server/src/ws_fault.c | 39 +--------------------- org.glite.lb.ws-test/examples/ws_fault.c | 20 +++++++---- org.glite.lb.ws-test/examples/ws_joblog.c | 26 +++++++-------- org.glite.lb.ws-test/examples/ws_jobstat.c | 1 + .../examples/ws_lb4agu_GetActivityInfo.c | 8 +++-- .../examples/ws_lb4agu_GetActivityStatus.c | 11 ++++-- 6 files changed, 41 insertions(+), 64 deletions(-) diff --git a/org.glite.lb.server/src/ws_fault.c b/org.glite.lb.server/src/ws_fault.c index 36dd455..581c11a 100644 --- a/org.glite.lb.server/src/ws_fault.c +++ b/org.glite.lb.server/src/ws_fault.c @@ -56,8 +56,7 @@ void edg_wll_ErrToFault(const edg_wll_Context ctx,struct soap *soap) free(ed); } -/* FIXME: assignment from incompatible pointer type */ - detail = soap_faultdetail(soap); + detail = (struct SOAP_ENV__Detail *)soap_faultdetail(soap); detail->__type = GFNUM; #if GSOAP_VERSION >= 20700 detail->fault = f; @@ -70,39 +69,3 @@ void edg_wll_ErrToFault(const edg_wll_Context ctx,struct soap *soap) if (soap->version == 2) soap->fault->SOAP_ENV__Detail = detail; else soap->fault->detail = detail; } - - -void edg_wll_FaultToErr(const struct soap *soap,edg_wll_Context ctx) -{ - struct SOAP_ENV__Detail *detail; - struct lbt__genericFault *f; - - if (!soap->fault) { - edg_wll_SetError(ctx,EINVAL,"SOAP: (no error info)"); - return; - } - - detail = soap->version == 2 ? soap->fault->SOAP_ENV__Detail : soap->fault->detail; - if (detail->__type == GFNUM) { -#if GSOAP_VERSION >= 20709 - f = (struct lbt__genericFault *)detail->fault; -#elif GSOAP_VERSION >= 20700 - f = ((struct _genericFault *) detail->fault) - ->lbe__genericFault; -#else - f = ((struct _genericFault *) detail->value) - ->lbe__genericFault; -#endif - if (f) edg_wll_SetError(ctx,f->code,f->description); - else edg_wll_SetError(ctx, EIO, "no or not parsable error from SOAP"); - } - else { - char *s; - - if (detail->__any) asprintf(&s, "SOAP: %s", detail->__any); - else asprintf(&s,"SOAP: %s", soap->version == 2 ? - GLITE_SECURITY_GSOAP_REASON(soap) : soap->fault->faultstring); - edg_wll_SetError(ctx,EINVAL,s); - free(s); - } -} diff --git a/org.glite.lb.ws-test/examples/ws_fault.c b/org.glite.lb.ws-test/examples/ws_fault.c index 650981c..9a48229 100644 --- a/org.glite.lb.ws-test/examples/ws_fault.c +++ b/org.glite.lb.ws-test/examples/ws_fault.c @@ -15,6 +15,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +#define _GNU_SOURCE 1 + #include #include @@ -26,10 +28,8 @@ limitations under the License. #if GSOAP_VERSION >= 20709 - #define GFITEM reason #define GFNUM SOAP_TYPE_lbt__genericFault #else - #define GFITEM lbe__genericFault #define GFNUM SOAP_TYPE__genericFault #endif @@ -40,14 +40,14 @@ int glite_lb_FaultToErr(const struct soap *soap,char **text) struct lbt__genericFault *f; if (!soap->fault) { - *text = NULL; + *text = strdup("SOAP: (no error info)"); return EINVAL; } detail = soap->version == 2 ? soap->fault->SOAP_ENV__Detail : soap->fault->detail; if (detail->__type == GFNUM) { #if GSOAP_VERSION >= 20709 - f = detail->lbe__genericFault; + f = (struct lbt__genericFault *)detail->fault; #elif GSOAP_VERSION >= 20700 f = ((struct _genericFault *) detail->fault) ->lbe__genericFault; @@ -55,11 +55,17 @@ int glite_lb_FaultToErr(const struct soap *soap,char **text) f = ((struct _genericFault *) detail->value) ->lbe__genericFault; #endif - *text = strdup(f->description); - return f->code; + if (f && (f->description || f->text)) { + *text = strdup(f->description ? : f->text); + return f->code; + } else { + *text = strdup("no or not parsable error from SOAP"); + return EINVAL; + } } else { - asprintf(text,"SOAP: %s", soap->version == 2 ? + if (detail->__any) asprintf(text, "SOAP: %s", detail->__any); + else asprintf(text,"SOAP: %s", soap->version == 2 ? GLITE_SECURITY_GSOAP_REASON(soap) : soap->fault->faultstring); return EINVAL; } diff --git a/org.glite.lb.ws-test/examples/ws_joblog.c b/org.glite.lb.ws-test/examples/ws_joblog.c index ca935ec..57ac405 100644 --- a/org.glite.lb.ws-test/examples/ws_joblog.c +++ b/org.glite.lb.ws-test/examples/ws_joblog.c @@ -52,14 +52,14 @@ int main(int argc,char** argv) struct soap *mydlo = soap_new(); struct _lbe__QueryEventsResponse out,*outp = &out; struct _lbe__QueryEvents in; - int opt, err, i; + int opt, err; char *server = "http://localhost:9003/", *jobid = NULL, *name = NULL; - struct lbt__queryConditions qc,*qcp; - struct lbt__queryRecord qr,*qrp; + struct lbt__queryConditions *qcp; + struct lbt__queryRecord *qrp; struct lbt__queryRecValue qv; name = strrchr(argv[0],'/'); @@ -89,21 +89,19 @@ int main(int argc,char** argv) return 1; } - qcp = &qc; - in.jobConditions = &qcp; - in.__sizejobConditions = 1; + GLITE_SECURITY_GSOAP_LIST_CREATE(mydlo, &in, jobConditions, struct lbt__queryConditions, 1); + qcp = GLITE_SECURITY_GSOAP_LIST_GET(in.jobConditions, 0); in.eventConditions = NULL; in.__sizeeventConditions = 0; - memset(&qc,0,sizeof qc); - qc.attr = lbt__queryAttr__JOBID; - qc.__sizerecord = 1; - qc.record = &qrp; - qrp = &qr; + memset(qcp,0,sizeof(*qcp)); + qcp->attr = lbt__queryAttr__JOBID; + GLITE_SECURITY_GSOAP_LIST_CREATE(mydlo, qcp, record, struct lbt__queryRecord, 1); + qrp = GLITE_SECURITY_GSOAP_LIST_GET(qcp->record, 0); - memset(&qr,0,sizeof qr); - qr.op = lbt__queryOp__EQUAL; - qr.value1 = &qv; + memset(qrp,0,sizeof(*qrp)); + qrp->op = lbt__queryOp__EQUAL; + qrp->value1 = &qv; GLITE_SECURITY_GSOAP_CHOICE_SET(&qv,c,lbt,queryRecValue,2,jobid); diff --git a/org.glite.lb.ws-test/examples/ws_jobstat.c b/org.glite.lb.ws-test/examples/ws_jobstat.c index 1e0f016..7c4d040 100644 --- a/org.glite.lb.ws-test/examples/ws_jobstat.c +++ b/org.glite.lb.ws-test/examples/ws_jobstat.c @@ -23,6 +23,7 @@ limitations under the License. #include "glite/security/glite_gscompat.h" #include "bk_ws_H.h" +#include "ws_fault.h" #if GSOAP_VERSION <= 20602 #define soap_call___lb__JobStatus soap_call___ns1__JobStatus diff --git a/org.glite.lb.ws-test/examples/ws_lb4agu_GetActivityInfo.c b/org.glite.lb.ws-test/examples/ws_lb4agu_GetActivityInfo.c index 2a35701..40921b6 100644 --- a/org.glite.lb.ws-test/examples/ws_lb4agu_GetActivityInfo.c +++ b/org.glite.lb.ws-test/examples/ws_lb4agu_GetActivityInfo.c @@ -23,6 +23,7 @@ limitations under the License. #include "glite/security/glite_gscompat.h" #include "bk_ws_H.h" +#include "ws_fault.h" #include "LoggingAndBookkeeping.nsmap" @@ -51,6 +52,7 @@ int main(int argc,char** argv) char *server = "http://localhost:9003/", *jobid = NULL, *name = NULL; + int ret_code = 1; name = strrchr(argv[0],'/'); @@ -97,6 +99,8 @@ int main(int argc,char** argv) soap_begin_send(outsoap); soap_put_PointerTo_lb4ague__GetActivityInfoResponse(outsoap,&out,"status","http://glite.org/wsdl/services/lb4agu:GetActivityInfoResponse"); soap_end_send(outsoap); + + ret_code = 0; } break; case SOAP_FAULT: @@ -107,8 +111,8 @@ int main(int argc,char** argv) err = glite_lb_FaultToErr(mydlo,&et); fprintf(stderr,"%s: %s (%s)\n",argv[0],strerror(err),et); - exit(1); } + break; default: fprintf(stderr,"err = %d\n",err); soap_print_fault(mydlo,stderr); @@ -119,5 +123,5 @@ int main(int argc,char** argv) free(mydlo); glite_gsplugin_free_context(gsplugin_ctx); - return 0; + return ret_code; } diff --git a/org.glite.lb.ws-test/examples/ws_lb4agu_GetActivityStatus.c b/org.glite.lb.ws-test/examples/ws_lb4agu_GetActivityStatus.c index ef00bd1..1a1daee 100644 --- a/org.glite.lb.ws-test/examples/ws_lb4agu_GetActivityStatus.c +++ b/org.glite.lb.ws-test/examples/ws_lb4agu_GetActivityStatus.c @@ -23,6 +23,7 @@ limitations under the License. #include "glite/security/glite_gscompat.h" #include "bk_ws_H.h" +#include "ws_fault.h" #include "LoggingAndBookkeeping.nsmap" @@ -51,6 +52,7 @@ int main(int argc,char** argv) char *server = "http://localhost:9003/", *jobid = NULL, *name = NULL; + int ret_code = 1; name = strrchr(argv[0],'/'); @@ -82,9 +84,10 @@ int main(int argc,char** argv) in = soap_malloc(mydlo, sizeof(*in)); - out = soap_malloc(mydlo, sizeof(*out)); + in->id = soap_malloc(mydlo, 1 * sizeof(char *)); in->id[0] = soap_strdup(mydlo, jobid); in->__sizeid = 1; + out = soap_malloc(mydlo, sizeof(*out)); switch (err = soap_call___lb4agu__GetActivityStatus(mydlo, server, "",in,out)) { case SOAP_OK: @@ -96,6 +99,8 @@ int main(int argc,char** argv) soap_begin_send(outsoap); soap_put_PointerTo_lb4ague__GetActivityStatusResponse(outsoap,&out,"status","http://glite.org/wsdl/services/lb4agu:GetActivityStatusResponse"); soap_end_send(outsoap); + + ret_code = 0; } break; case SOAP_FAULT: @@ -106,8 +111,8 @@ int main(int argc,char** argv) err = glite_lb_FaultToErr(mydlo,&et); fprintf(stderr,"%s: %s (%s)\n",argv[0],strerror(err),et); - exit(1); } + break; default: fprintf(stderr,"err = %d\n",err); soap_print_fault(mydlo,stderr); @@ -118,5 +123,5 @@ int main(int argc,char** argv) free(mydlo); glite_gsplugin_free_context(gsplugin_ctx); - return 0; + return ret_code; } -- 1.8.2.3