You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(8) |
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(7) |
Feb
|
Mar
|
Apr
(6) |
May
(14) |
Jun
|
Jul
|
Aug
|
Sep
(3) |
Oct
(7) |
Nov
(1) |
Dec
|
2009 |
Jan
(3) |
Feb
(2) |
Mar
(3) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
|
2010 |
Jan
|
Feb
(5) |
Mar
|
Apr
(4) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(9) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <cs...@us...> - 2009-02-04 22:52:08
|
Revision: 67 http://bespp.svn.sourceforge.net/bespp/?rev=67&view=rev Author: csmith Date: 2009-02-04 22:52:05 +0000 (Wed, 04 Feb 2009) Log Message: ----------- - decouple from generated soapStub.h Modified Paths: -------------- tags/release-1.1.0/besclient/jsdl.h Modified: tags/release-1.1.0/besclient/jsdl.h =================================================================== --- tags/release-1.1.0/besclient/jsdl.h 2009-02-04 22:51:31 UTC (rev 66) +++ tags/release-1.1.0/besclient/jsdl.h 2009-02-04 22:52:05 UTC (rev 67) @@ -23,7 +23,7 @@ #ifndef _JSDL_H #define _JSDL_H -#include "soapStub.h" +#include <stdsoap2.h> #ifdef __cplusplus extern "C" { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2009-02-04 22:51:33
|
Revision: 66 http://bespp.svn.sourceforge.net/bespp/?rev=66&view=rev Author: csmith Date: 2009-02-04 22:51:31 +0000 (Wed, 04 Feb 2009) Log Message: ----------- - decouple from generated soapStub.h Modified Paths: -------------- trunk/besclient/jsdl.h Modified: trunk/besclient/jsdl.h =================================================================== --- trunk/besclient/jsdl.h 2009-01-12 10:55:43 UTC (rev 65) +++ trunk/besclient/jsdl.h 2009-02-04 22:51:31 UTC (rev 66) @@ -23,7 +23,7 @@ #ifndef _JSDL_H #define _JSDL_H -#include "soapStub.h" +#include <stdsoap2.h> #ifdef __cplusplus extern "C" { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2009-01-12 10:55:47
|
Revision: 65 http://bespp.svn.sourceforge.net/bespp/?rev=65&view=rev Author: csmith Date: 2009-01-12 10:55:43 +0000 (Mon, 12 Jan 2009) Log Message: ----------- Tagging release 1.1.0 Added Paths: ----------- tags/release-1.1.0/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2009-01-12 10:48:11
|
Revision: 64 http://bespp.svn.sourceforge.net/bespp/?rev=64&view=rev Author: csmith Date: 2009-01-12 10:48:08 +0000 (Mon, 12 Jan 2009) Log Message: ----------- - updated copyright dates in preparation for release Modified Paths: -------------- trunk/README.txt trunk/besclient/bes.c trunk/besclient/bes.h trunk/besclient/besclient.c trunk/besclient/jsdl.c trunk/besclient/jsdl.h trunk/besclient/namespaces.h trunk/besserver/auth.c trunk/besserver/auth.h trunk/besserver/besserver.c trunk/besserver/faults.c trunk/besserver/faults.h trunk/besserver/job.c trunk/besserver/job.h trunk/besserver/namespaces.h trunk/besserver/rm.h trunk/besserver/rm_lsf.c trunk/config.h Modified: trunk/README.txt =================================================================== --- trunk/README.txt 2009-01-12 10:27:26 UTC (rev 63) +++ trunk/README.txt 2009-01-12 10:48:08 UTC (rev 64) @@ -262,6 +262,6 @@ ========= BES++ is copyrighted by Platform Computing Corp. -Copyright (C) 2007-2008 Platform Computing Corp. +Copyright (C) 2007-2009 Platform Computing Corp. All Rights Reserved Modified: trunk/besclient/bes.c =================================================================== --- trunk/besclient/bes.c 2009-01-12 10:27:26 UTC (rev 63) +++ trunk/besclient/bes.c 2009-01-12 10:48:08 UTC (rev 64) @@ -3,7 +3,7 @@ * * Client library of the OGSA Basic Execution Services * - * Copyright (C) 2006-2008, Platform Computing Corporation. All Rights Reserved. + * Copyright (C) 2006-2009, Platform Computing Corporation. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by Modified: trunk/besclient/bes.h =================================================================== --- trunk/besclient/bes.h 2009-01-12 10:27:26 UTC (rev 63) +++ trunk/besclient/bes.h 2009-01-12 10:48:08 UTC (rev 64) @@ -3,7 +3,7 @@ * * Header file of BES++ client library * - * Copyright (C) 2006-2008, Platform Computing Corporation. All Rights Reserved. + * Copyright (C) 2006-2009, Platform Computing Corporation. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by Modified: trunk/besclient/besclient.c =================================================================== --- trunk/besclient/besclient.c 2009-01-12 10:27:26 UTC (rev 63) +++ trunk/besclient/besclient.c 2009-01-12 10:48:08 UTC (rev 64) @@ -3,7 +3,7 @@ * * Client implementation of the OGSA Basic Execution Services * - * Copyright (C) 2006-2008, Platform Computing Corporation. All Rights Reserved. + * Copyright (C) 2006-2009, Platform Computing Corporation. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by Modified: trunk/besclient/jsdl.c =================================================================== --- trunk/besclient/jsdl.c 2009-01-12 10:27:26 UTC (rev 63) +++ trunk/besclient/jsdl.c 2009-01-12 10:48:08 UTC (rev 64) @@ -1,7 +1,7 @@ /* ---------------------------------------------------------------- * jsdl.c * - * Copyright (C) 2006-2007, Platform Computing Corporation. All Rights Reserved. + * Copyright (C) 2006-2009, Platform Computing Corporation. All Rights Reserved. * * * Client library of the OGSA Basic Execution Services Modified: trunk/besclient/jsdl.h =================================================================== --- trunk/besclient/jsdl.h 2009-01-12 10:27:26 UTC (rev 63) +++ trunk/besclient/jsdl.h 2009-01-12 10:48:08 UTC (rev 64) @@ -3,7 +3,7 @@ * * Header file of BES++ client library * - * Copyright (C) 2006-2008, Platform Computing Corporation. All Rights Reserved. + * Copyright (C) 2006-2009, Platform Computing Corporation. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by Modified: trunk/besclient/namespaces.h =================================================================== --- trunk/besclient/namespaces.h 2009-01-12 10:27:26 UTC (rev 63) +++ trunk/besclient/namespaces.h 2009-01-12 10:48:08 UTC (rev 64) @@ -3,7 +3,7 @@ * * Header file of BES++ client library * - * Copyright (C) 2006-2008, Platform Computing Corporation. All Rights Reserved. + * Copyright (C) 2006-2009, Platform Computing Corporation. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by Modified: trunk/besserver/auth.c =================================================================== --- trunk/besserver/auth.c 2009-01-12 10:27:26 UTC (rev 63) +++ trunk/besserver/auth.c 2009-01-12 10:48:08 UTC (rev 64) @@ -1,3 +1,26 @@ +/* ---------------------------------------------------------------- + * auth.c + * + * Copyright (C) 2006-2009, Platform Computing Corporation. All Rights Reserved. + * + * + * This file is part of BESserver. + * + * BESserver is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ #include "../config.h" #ifdef MACOSX Modified: trunk/besserver/auth.h =================================================================== --- trunk/besserver/auth.h 2009-01-12 10:27:26 UTC (rev 63) +++ trunk/besserver/auth.h 2009-01-12 10:48:08 UTC (rev 64) @@ -1,7 +1,7 @@ /* ---------------------------------------------------------------- * auth.h * - * Copyright (C) 2006-2007, Platform Computing Corporation. All Rights Reserved. + * Copyright (C) 2006-2009, Platform Computing Corporation. All Rights Reserved. * * * This file is part of BESserver. Modified: trunk/besserver/besserver.c =================================================================== --- trunk/besserver/besserver.c 2009-01-12 10:27:26 UTC (rev 63) +++ trunk/besserver/besserver.c 2009-01-12 10:48:08 UTC (rev 64) @@ -3,7 +3,7 @@ * * Server implementation of the OGSA Basic Execution Services * - * Copyright (C) 2006-2007, Platform Computing Corporation. All Rights Reserved. + * Copyright (C) 2006-2009, Platform Computing Corporation. All Rights Reserved. * * * This file is part of BESserver. Modified: trunk/besserver/faults.c =================================================================== --- trunk/besserver/faults.c 2009-01-12 10:27:26 UTC (rev 63) +++ trunk/besserver/faults.c 2009-01-12 10:48:08 UTC (rev 64) @@ -1,7 +1,7 @@ /* ---------------------------------------------------------------- * faults.c * - * Copyright (C) 2006-2007, Platform Computing Corporation. All Rights Reserved. + * Copyright (C) 2006-2009, Platform Computing Corporation. All Rights Reserved. * * * This file is part of BESserver. Modified: trunk/besserver/faults.h =================================================================== --- trunk/besserver/faults.h 2009-01-12 10:27:26 UTC (rev 63) +++ trunk/besserver/faults.h 2009-01-12 10:48:08 UTC (rev 64) @@ -1,7 +1,7 @@ /* ---------------------------------------------------------------- * faults.h * - * Copyright (C) 2006-2007, Platform Computing Corporation. All Rights Reserved. + * Copyright (C) 2006-2009, Platform Computing Corporation. All Rights Reserved. * * * This file is part of BESserver. Modified: trunk/besserver/job.c =================================================================== --- trunk/besserver/job.c 2009-01-12 10:27:26 UTC (rev 63) +++ trunk/besserver/job.c 2009-01-12 10:48:08 UTC (rev 64) @@ -1,7 +1,7 @@ /* ---------------------------------------------------------------- * job.c * - * Copyright (C) 2006-2007, Platform Computing Corporation. All Rights Reserved. + * Copyright (C) 2006-2009, Platform Computing Corporation. All Rights Reserved. * * * This file is part of BESserver. Modified: trunk/besserver/job.h =================================================================== --- trunk/besserver/job.h 2009-01-12 10:27:26 UTC (rev 63) +++ trunk/besserver/job.h 2009-01-12 10:48:08 UTC (rev 64) @@ -1,7 +1,7 @@ /* ---------------------------------------------------------------- * job.h * - * Copyright (C) 2006-2007, Platform Computing Corporation. All Rights Reserved. + * Copyright (C) 2006-2009, Platform Computing Corporation. All Rights Reserved. * * * This file is part of BESserver. Modified: trunk/besserver/namespaces.h =================================================================== --- trunk/besserver/namespaces.h 2009-01-12 10:27:26 UTC (rev 63) +++ trunk/besserver/namespaces.h 2009-01-12 10:48:08 UTC (rev 64) @@ -1,7 +1,7 @@ /* ---------------------------------------------------------------- * namespaces.h * - * Copyright (C) 2006-2007, Platform Computing Corporation. All Rights Reserved. + * Copyright (C) 2006-2009, Platform Computing Corporation. All Rights Reserved. * * * This file is part of BESserver. Modified: trunk/besserver/rm.h =================================================================== --- trunk/besserver/rm.h 2009-01-12 10:27:26 UTC (rev 63) +++ trunk/besserver/rm.h 2009-01-12 10:48:08 UTC (rev 64) @@ -1,3 +1,26 @@ +/* ---------------------------------------------------------------- + * rm.h + * + * Copyright (C) 2006-2009, Platform Computing Corporation. All Rights Reserved. + * + * + * This file is part of BESserver. + * + * BESserver is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ #ifndef _RM_H #define _RM_H Modified: trunk/besserver/rm_lsf.c =================================================================== --- trunk/besserver/rm_lsf.c 2009-01-12 10:27:26 UTC (rev 63) +++ trunk/besserver/rm_lsf.c 2009-01-12 10:48:08 UTC (rev 64) @@ -1,3 +1,26 @@ +/* ---------------------------------------------------------------- + * rm_lsf.c + * + * Copyright (C) 2006-2009, Platform Computing Corporation. All Rights Reserved. + * + * + * This file is part of BESserver. + * + * BESserver is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ #include <stdlib.h> #include <stdio.h> #include <sys/types.h> Modified: trunk/config.h =================================================================== --- trunk/config.h 2009-01-12 10:27:26 UTC (rev 63) +++ trunk/config.h 2009-01-12 10:48:08 UTC (rev 64) @@ -8,10 +8,10 @@ /* You probably don't need to change these. */ /* Setting the VERSION_STRING macro determines what is output */ /* when using the -V option to besclient and besserver */ -#define VERSION_STRING "BES++ 1.0.1, 2008-04-09" +#define VERSION_STRING "BES++ 1.1.0, 2009-01-12" /* Don't change this one */ -#define COPYRIGHT "Copyright (C) 2006-2008 Platform Computing Corporation" +#define COPYRIGHT "Copyright (C) 2006-2009 Platform Computing Corporation" #endif /* _CONFIG_H */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2009-01-12 10:27:32
|
Revision: 63 http://bespp.svn.sourceforge.net/bespp/?rev=63&view=rev Author: csmith Date: 2009-01-12 10:27:26 +0000 (Mon, 12 Jan 2009) Log Message: ----------- - added bes_setSOAPLogfiles function to set location of gSOAP logs - by default, libbes will not log messages - fixed core dump in dom traversal routines Modified Paths: -------------- trunk/besclient/bes.c trunk/besclient/bes.h Modified: trunk/besclient/bes.c =================================================================== --- trunk/besclient/bes.c 2008-11-03 19:35:22 UTC (rev 62) +++ trunk/besclient/bes.c 2009-01-12 10:27:26 UTC (rev 63) @@ -26,6 +26,7 @@ #include <string.h> #include <sys/types.h> #include <sys/stat.h> +#include <sys/param.h> #include <fcntl.h> #include <errno.h> @@ -92,24 +93,21 @@ return BESE_BAD_ARG; } - *context = NULL; - ctx = (struct bes_context *)malloc(sizeof(struct bes_context)); if (ctx == NULL) { return BESE_SYS_ERR; } + memset(ctx, 0, sizeof(struct bes_context)); - soap = (struct soap *)malloc(sizeof(struct soap)); + soap_ssl_init(); + soap = soap_new1(SOAP_C_UTFSTRING); if (soap == NULL) { free(ctx); return BESE_SYS_ERR; } - - memset(ctx, 0, sizeof(struct bes_context)); - - soap_ssl_init(); - soap_init(soap); - soap_set_mode(soap, SOAP_C_UTFSTRING); + soap_set_recv_logfile(soap, NULL); + soap_set_sent_logfile(soap, NULL); + soap_set_test_logfile(soap, NULL); soap_register_plugin(soap, soap_wsse); soap_set_namespaces(soap, default_namespaces); soap_header(soap); @@ -120,6 +118,55 @@ return BESE_OK; } +void +bes_setSOAPLogfiles(struct bes_context *context, int files, char *path) +{ + char pathname[MAXPATHLEN]; + char sep[2]; + + if (context == NULL) + return; + + if (path) { + if (path[strlen(path)-1] != '/') { + sprintf(sep, "%s", "/"); + } + if (strlen(path) + strlen(sep) + strlen("libbes_test.log") + 1 > MAXPATHLEN) + return; + } + + if (files & BES_LOG_SOAP_MESSAGES) { +#ifdef SOAP_DEBUG + if (path) { + sprintf(pathname, "%s%slibbes_recv.log", path, sep); + soap_set_recv_logfile(context->soap, pathname); + } + else { + soap_set_recv_logfile(context->soap, NULL); + } + if (path) { + sprintf(pathname, "%s%slibbes_sent.log", path, sep); + soap_set_sent_logfile(context->soap, pathname); + } + else { + soap_set_sent_logfile(context->soap, NULL); + } +#endif + } + + if (files & BES_LOG_SOAP_DEBUG) { +#ifdef SOAP_DEBUG + if (path) { + sprintf(pathname, "%s%slibbes_test.log", path, sep); + soap_set_test_logfile(context->soap, pathname); + } + else { + soap_set_test_logfile(context->soap, NULL); + } +#endif + } +} + int bes_security(struct bes_context *context, char *x509cert, @@ -1153,7 +1200,7 @@ fprintf(stdout, "<%s", node->name); /* if we don't have a current namespace, or if the current */ /* namespace is different from this node, emit an xmlns attribute */ - if (!current_nstr || strcmp(current_nstr, node->nstr)) { + if (node->nstr && (!current_nstr || strcmp(current_nstr, node->nstr))) { fprintf(stdout, " xmlns=\"%s\"", node->nstr); } attr = node->atts; @@ -1211,7 +1258,7 @@ /* if we don't have a current namespace, or if the current */ /* namespace is different from this node, emit an xmlns attribute */ - if (!current_nstr || strcmp(current_nstr, node->nstr)) { + if (node->nstr && (!current_nstr || strcmp(current_nstr, node->nstr))) { size += strlen(" xmlns=\"\"") + strlen(node->nstr); } @@ -1243,7 +1290,7 @@ sprintf(str, "%s<%s", str, node->name); /* if we don't have a current namespace, or if the current */ /* namespace is different from this node, emit an xmlns attribute */ - if (!current_nstr || strcmp(current_nstr, node->nstr)) { + if (node->nstr && (!current_nstr || strcmp(current_nstr, node->nstr))) { sprintf(str, "%s xmlns=\"%s\"", str, node->nstr); } attr = node->atts; Modified: trunk/besclient/bes.h =================================================================== --- trunk/besclient/bes.h 2008-11-03 19:35:22 UTC (rev 62) +++ trunk/besclient/bes.h 2009-01-12 10:27:26 UTC (rev 63) @@ -109,6 +109,11 @@ char *bes_getEPRString(epr_t); void bes_freeActivityStatus(struct bes_activity_status *); +#define BES_LOG_SOAP_MESSAGES 0x1 +#define BES_LOG_SOAP_DEBUG 0x2 +#define BES_LOG_SOAP_ALL BES_LOG_SOAP_MESSAGES|BES_LOG_SOAP_DEBUG +void bes_setSOAPLogfiles(struct bes_context *, int, char*); + #ifdef __cplusplus } #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-11-03 19:35:25
|
Revision: 62 http://bespp.svn.sourceforge.net/bespp/?rev=62&view=rev Author: csmith Date: 2008-11-03 19:35:22 +0000 (Mon, 03 Nov 2008) Log Message: ----------- - added extern "C" to header files for use in C++ programs Modified Paths: -------------- trunk/besclient/bes.h trunk/besclient/jsdl.h Modified: trunk/besclient/bes.h =================================================================== --- trunk/besclient/bes.h 2008-10-31 21:40:42 UTC (rev 61) +++ trunk/besclient/bes.h 2008-11-03 19:35:22 UTC (rev 62) @@ -25,6 +25,10 @@ #include "jsdl.h" +#ifdef __cplusplus +extern "C" { +#endif + #define MAX_ERRSTR_LEN 256 typedef void* epr_t; @@ -105,5 +109,9 @@ char *bes_getEPRString(epr_t); void bes_freeActivityStatus(struct bes_activity_status *); +#ifdef __cplusplus +} +#endif + #endif /* _BES_H */ Modified: trunk/besclient/jsdl.h =================================================================== --- trunk/besclient/jsdl.h 2008-10-31 21:40:42 UTC (rev 61) +++ trunk/besclient/jsdl.h 2008-11-03 19:35:22 UTC (rev 62) @@ -25,6 +25,10 @@ #include "soapStub.h" +#ifdef __cplusplus +extern "C" { +#endif + enum jsdl_application_type { JSDL_POSIX_APPLICATION = 1, JSDL_HPC_PROFILE_APPLICATION = 2, @@ -199,4 +203,8 @@ int jsdl_generateJobDefinitionDOM(struct jsdl_job_definition *, struct soap_dom_element **); void jsdl_freeJobDefinitionDOM(struct soap_dom_element *); +#ifdef __cplusplus +} +#endif + #endif /* _JSDL_H */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-10-31 21:44:44
|
Revision: 60 http://bespp.svn.sourceforge.net/bespp/?rev=60&view=rev Author: csmith Date: 2008-10-31 21:36:04 +0000 (Fri, 31 Oct 2008) Log Message: ----------- - fixed bug when freeing jsdl_job_definition - added routine to help allocate empty jsdl_job_definition - added routines to help create and manage jsdl_range_value types - added new program (libtests) used to help test the library functions Modified Paths: -------------- trunk/besclient/Makefile trunk/besclient/bes.c trunk/besclient/jsdl.c trunk/besclient/jsdl.h Added Paths: ----------- trunk/besclient/libtests.c Property Changed: ---------------- trunk/besclient/ Property changes on: trunk/besclient ___________________________________________________________________ Modified: svn:ignore - .project .cproject .gdb_history .settings *.log soapClient.c soapC.c soapStub.h soapH.h bes-factory.h BESFactoryBinding.nsmap bes-factory.xsd bes-factory.wsdl besclient libbes.a + .project .cproject .gdb_history .settings *.log soapClient.c soapC.c soapStub.h soapH.h bes-factory.h BESFactoryBinding.nsmap bes-factory.xsd bes-factory.wsdl besclient libtests libbes.a Modified: trunk/besclient/Makefile =================================================================== --- trunk/besclient/Makefile 2008-10-31 18:03:49 UTC (rev 59) +++ trunk/besclient/Makefile 2008-10-31 21:36:04 UTC (rev 60) @@ -26,15 +26,19 @@ SERVER_OBJ = soapServer.o soapC.o $(GSOAP_OBJ) CLIENT_OBJ = soapClient.o soapC.o $(GSOAP_OBJ) -all: libbes.a besclient +all: libbes.a besclient libtests besclient: besclient.o libbes.a $(CC) $(LDFLAGS) -o besclient besclient.o $(LIBS) +libtests: libtests.o libbes.a + $(CC) $(LDFLAGS) -o libtests libtests.o $(LIBS) + libbes.a: bes.o jsdl.o $(CLIENT_OBJ) ar -rsv libbes.a bes.o jsdl.o $(CLIENT_OBJ) besclient.o: besclient.c bes.h +libtests.o: libtests.c bes.h bes.o: bes.c bes.h jsdl.h $(SOAP_NS) jsdl.o: jsdl.c jsdl.h $(SOAP_NS) soapServer.o: soapServer.c @@ -68,7 +72,7 @@ rm -f $(SOAP_C_FILES) rm -f *.nsmap rm -f *.res.xml *.req.xml - rm -f besclient libbes.a *.o *~ + rm -f besclient libtests libbes.a *.o *~ rm -f $(BES_HEADER) rm -f *.log rm -f *.wsdl *.xsd Modified: trunk/besclient/bes.c =================================================================== --- trunk/besclient/bes.c 2008-10-31 18:03:49 UTC (rev 59) +++ trunk/besclient/bes.c 2008-10-31 21:36:04 UTC (rev 60) @@ -81,7 +81,6 @@ void sprintDom(struct soap_dom_element *, char *, char *); int getActivityDocumentsDOM(struct bes_context *, epr_t, epr_t, struct soap_dom_element **); int getActivityDocumentFromDOM(struct bes_context *, struct soap_dom_element *, struct bes_activity_document **); -int getJSDLFromDOM(struct bes_context *, struct soap_dom_element *, struct jsdl_job_definition **); int bes_init(struct bes_context **context) @@ -792,8 +791,9 @@ doc->activityepr = (epr_t)epr; if (isElement(jsdl_dom, BES_NS, "JobDefinition")) { - ret = getJSDLFromDOM(context, jsdl_dom, &doc->activity); + ret = jsdl_processJobDefinition(jsdl_dom, &doc->activity); if (ret != BESE_OK) { + setErrorString(context, NULL, ret); return ret; } } @@ -804,39 +804,6 @@ return BESE_OK; } -int -getJSDLFromDOM(struct bes_context *context, - struct soap_dom_element *dom, - struct jsdl_job_definition **jsdl) -{ - struct jsdl_job_definition *jd; - int rc; - - if (dom == NULL - || jsdl == NULL) { - setErrorString(context, NULL, BESE_BAD_ARG); - return BESE_BAD_ARG; - } - - jd = (struct jsdl_job_definition*)malloc(sizeof(struct jsdl_job_definition)); - if (jd == NULL) { - setErrorString(context, NULL, BESE_MEM_ALLOC); - return BESE_MEM_ALLOC; - } - memset(jd, 0, sizeof(struct jsdl_job_definition)); - - rc = jsdl_processJobDefinition(dom, jd); - if (rc != BESE_OK) { - jsdl_freeJobDefinition(jd); - setErrorString(context, NULL, rc); - return rc; - } - - *jsdl = jd; - - return BESE_OK; -} - void bes_freeActivityDocument(struct bes_activity_document *adoc) { Modified: trunk/besclient/jsdl.c =================================================================== --- trunk/besclient/jsdl.c 2008-10-31 18:03:49 UTC (rev 59) +++ trunk/besclient/jsdl.c 2008-10-31 21:36:04 UTC (rev 60) @@ -181,11 +181,8 @@ struct soap_dom_element *user, *pass; struct hpcp_credential *new_cred = NULL; - printf("----%s\n", dom->name); - while (cur) { if (isElement(cur, WSSE_NS, "UsernameToken")) { - printf("-----%s\n", cur->name); user = cur->elts; if (!isElement(user, WSSE_NS, "Username")) { return BESE_XML_FORMAT; @@ -263,8 +260,6 @@ return BESE_BAD_ARG; } - printf("----%s\n", dom->name); - app = (struct jsdl_hpcp_application*)malloc(sizeof(struct jsdl_hpcp_application)); if (app == NULL) { return BESE_MEM_ALLOC; @@ -273,7 +268,6 @@ while (cur) { if (isElement(cur, JSDL_HPCPA_NS, "Executable")) { - printf("-----Executable = %s\n", cur->data); if (cur->data && strlen(cur->data)) { app->Executable = strdup(cur->data); if (app->Executable == NULL) { @@ -287,14 +281,12 @@ } } else if (isElement(cur, JSDL_HPCPA_NS, "Argument")) { - printf("-----Argument = %s\n", cur->data); if ((rc = jsdl_addArg(jsdl, cur->data)) != BESE_OK) { jsdl_freeHPCProfileApplication(app); return rc; } } else if (isElement(cur, JSDL_HPCPA_NS, "Input")) { - printf("-----Input = %s\n", cur->data); if (cur->data && strlen(cur->data)) { app->Input = strdup(cur->data); if (app->Input == NULL) { @@ -308,7 +300,6 @@ } } else if (isElement(cur, JSDL_HPCPA_NS, "Output")) { - printf("-----Output = %s\n", cur->data); if (cur->data && strlen(cur->data)) { app->Output = strdup(cur->data); if (app->Output == NULL) { @@ -322,7 +313,6 @@ } } else if (isElement(cur, JSDL_HPCPA_NS, "Error")) { - printf("-----Error = %s\n", cur->data); if (cur->data && strlen(cur->data)) { app->Error = strdup(cur->data); if (app->Error == NULL) { @@ -336,7 +326,6 @@ } } else if (isElement(cur, JSDL_HPCPA_NS, "WorkingDirectory")) { - printf("-----WorkingDirectory = %s\n", cur->data); if (cur->data && strlen(cur->data)) { app->WorkingDirectory = strdup(cur->data); if (app->WorkingDirectory == NULL) { @@ -350,14 +339,12 @@ } } else if (isElement(cur, JSDL_HPCPA_NS, "Environment")) { - printf("-----Environment\n"); if ((rc = jsdl_addEnv(jsdl, cur)) != BESE_OK) { jsdl_freeHPCProfileApplication(app); return rc; } } else if (isElement(cur, JSDL_HPCPA_NS, "UserName")) { - printf("-----UserName = %s\n", cur->data); if (cur->data && strlen(cur->data)) { app->UserName = strdup(cur->data); if (app->UserName == NULL) { @@ -386,28 +373,23 @@ struct soap_dom_element *cur = dom->elts; int rc; - printf("---%s\n", dom->name); - while (cur) { if (isElement(cur, JSDL_NS, "JobName")) { - printf("----JobName = %s\n", cur->data); jsdl->JobName = strdup(cur->data); if (jsdl->JobName == NULL) { return BESE_MEM_ALLOC; } } else if (isElement(cur, JSDL_NS, "Description")) { - printf("----Description = %s\n", cur->data); + ; } else if (isElement(cur, JSDL_NS, "JobAnnotation")) { - printf("----JobAnnotation = %s\n", cur->data); jsdl->JobAnnotation = strdup(cur->data); if (jsdl->JobAnnotation == NULL) { return BESE_MEM_ALLOC; } } else if (isElement(cur, JSDL_NS, "JobProject")) { - printf("----JobProject = %s\n", cur->data); jsdl->JobProject = strdup(cur->data); if (jsdl->JobProject == NULL) { return BESE_MEM_ALLOC; @@ -426,18 +408,15 @@ struct soap_dom_element *cur = dom->elts; int rc; - printf("---%s\n", dom->name); while (cur) { if (isElement(cur, JSDL_NS, "ApplicationName")) { - printf("----ApplicationName = %s\n", cur->data); jsdl->ApplicationName = strdup(cur->data); if (jsdl->ApplicationName == NULL) { return BESE_MEM_ALLOC; } } else if (isElement(cur, JSDL_NS, "ApplicationVersion")) { - printf("----ApplicationVersion = %s\n", cur->data); jsdl->ApplicationVersion = strdup(cur->data); if (jsdl->ApplicationVersion == NULL) { return BESE_MEM_ALLOC; @@ -454,6 +433,147 @@ return BESE_OK; } +int +jsdl_newRangeValue(struct jsdl_range_value **rangeval) +{ + struct jsdl_range_value *rval; + + if (rangeval == NULL) { + return BESE_BAD_ARG; + } + + rval = (struct jsdl_range_value*)malloc(sizeof(struct jsdl_range_value)); + if (rval == NULL) { + return BESE_MEM_ALLOC; + } + memset(rval, 0, sizeof(struct jsdl_range_value)); + + *rangeval = rval; + + return BESE_OK; +} + +int +jsdl_addUpperBound(struct jsdl_range_value *rval, double value, int exclusive) +{ + struct jsdl_bound *upper; + + if (rval == NULL) { + return BESE_BAD_ARG; + } + + upper = (struct jsdl_bound*)malloc(sizeof(struct jsdl_bound)); + if (upper == NULL) { + return BESE_MEM_ALLOC; + } + upper->value = value; + upper->exclusive = exclusive; + + if (rval->UpperBoundedRange) { + free(rval->UpperBoundedRange); + } + + rval->UpperBoundedRange = upper; + + return BESE_OK; +} + +int +jsdl_addLowerBound(struct jsdl_range_value *rval, double value, int exclusive) +{ + struct jsdl_bound *lower; + + if (rval == NULL) { + return BESE_BAD_ARG; + } + + lower = (struct jsdl_bound*)malloc(sizeof(struct jsdl_bound)); + if (lower == NULL) { + return BESE_MEM_ALLOC; + } + lower->value = value; + lower->exclusive = exclusive; + + if (rval->LowerBoundedRange) { + free(rval->LowerBoundedRange); + } + + rval->LowerBoundedRange = lower; + + return BESE_OK; +} + +int +jsdl_addExact(struct jsdl_range_value *rval, double value, double epsilon) +{ + struct jsdl_exact *exact, *cur; + + if (rval == NULL) { + return BESE_BAD_ARG; + } + + exact = (struct jsdl_exact*)malloc(sizeof(struct jsdl_exact)); + if (exact == NULL) { + return BESE_MEM_ALLOC; + } + exact->next = NULL; + exact->value = value; + exact->epsilon = epsilon; + + if (cur = rval->Exact) { + while (cur->next) { + cur = cur->next; + } + cur->next = exact; + } + else { + rval->Exact = exact; + } + + return BESE_OK; +} + +int +jsdl_addRange(struct jsdl_range_value *rval, + double lowerBound, + int lowerExclusive, + double upperBound, + int upperExclusive) +{ + struct jsdl_range *range, *cur; + struct jsdl_bound *lower, *upper; + + if (rval == NULL) { + return BESE_BAD_ARG; + } + + range = (struct jsdl_range*)malloc(sizeof(struct jsdl_range)); + lower = (struct jsdl_bound*)malloc(sizeof(struct jsdl_bound)); + upper = (struct jsdl_bound*)malloc(sizeof(struct jsdl_bound)); + if (range == NULL || lower == NULL || upper == NULL) { + return BESE_MEM_ALLOC; + } + + lower->value = lowerBound; + lower->exclusive = lowerExclusive; + upper->value = upperBound; + upper->exclusive = upperExclusive; + range->LowerBound = lower; + range->UpperBound = upper; + range->next = NULL; + if (cur = rval->Range) { + while (cur->next) { + cur = cur->next; + } + cur->next = range; + } + else { + rval->Range = range; + } + + return BESE_OK; +} + void jsdl_freeRangeValue(struct jsdl_range_value *value) { @@ -463,16 +583,20 @@ if (value == NULL) return; + if (value->UpperBoundedRange) free(value->UpperBoundedRange); + + if (value->LowerBoundedRange) free(value->LowerBoundedRange); + exact = value->Exact; while (exact) { - next_exact = exact; + next_exact = exact->next; free(exact); exact = next_exact; } range = value->Range; while (range) { - next_range = range; + next_range = range->next; free(range); range = next_range; } @@ -482,16 +606,91 @@ return; } +int +jsdl_processRange(struct soap_dom_element *dom, + struct jsdl_range **range) +{ + struct jsdl_range *r; + struct jsdl_bound *lower, *upper; + struct soap_dom_element *cur; + struct soap_dom_attribute *attr; + + if (!dom || !range) { + return BESE_BAD_ARG; + } + + r = (struct jsdl_range*)malloc(sizeof(struct jsdl_range)); + if (r == NULL) { + return BESE_MEM_ALLOC; + } + memset(r, 0, sizeof(struct jsdl_range)); + + cur = dom->elts; + + if (!isElement(cur, JSDL_NS, "LowerBound")) { + free(r); + return BESE_XML_FORMAT; + } + + lower = (struct jsdl_bound*)malloc(sizeof(struct jsdl_bound)); + if (lower == NULL) { + free(r); + return BESE_MEM_ALLOC; + } + lower->value = strtod(cur->data, NULL); + lower->exclusive = 0; + for (attr = cur->atts; attr; attr = attr->next) { + if (!strcmp(attr->name, "exclusiveBound")) { + if (!strcmp(attr->data, "true")) { + lower->exclusive = 1; + } + } + } + + cur = cur->next; + + if (!isElement(cur, JSDL_NS, "UpperBound")) { + free(r); + free(lower); + return BESE_XML_FORMAT; + } + + upper = (struct jsdl_bound*)malloc(sizeof(struct jsdl_bound)); + if (upper == NULL) { + free(r); + free(lower); + return BESE_MEM_ALLOC; + } + upper->value = strtod(cur->data, NULL); + upper->exclusive = 0; + for (attr = cur->atts; attr; attr = attr->next) { + if (!strcmp(attr->name, "exclusiveBound")) { + if (!strcmp(attr->data, "true")) { + upper->exclusive = 1; + } + } + } + + r->next = NULL; + r->LowerBound = lower; + r->UpperBound = upper; + *range = r; + + return BESE_OK; +} + int jsdl_processRangeValue(struct soap_dom_element *dom, struct jsdl_range_value **value) { struct jsdl_range_value *val; - struct jsdl_exact *new_exact, *exact; + struct jsdl_exact *new_exact, *exact = NULL; + struct jsdl_range *new_range, *range = NULL; struct jsdl_bound *bound; struct soap_dom_element *cur; struct soap_dom_attribute *attr; char *endptr; + int rc; if (!dom || !value) { return BESE_BAD_ARG; @@ -553,19 +752,26 @@ break; } } - if (val->Exact) { - exact = val->Exact; - while (exact->next) { - exact = exact->next; - } + if (exact) { exact->next = new_exact; } else { val->Exact = new_exact; } + exact = new_exact; } else if (isElement(cur, JSDL_NS, "Range")) { - ; + if (rc = jsdl_processRange(cur, &new_range)) { + jsdl_freeRangeValue(val); + return rc; + } + if (range) { + range->next = new_range; + } + else { + val->Range = new_range; + } + range = new_range; } cur = cur->next; @@ -628,8 +834,6 @@ return BESE_BAD_ARG; } - printf("----%s\n", dom->name); - os = (struct jsdl_operating_system*)malloc(sizeof(struct jsdl_operating_system)); if (os == NULL) { return BESE_MEM_ALLOC; @@ -688,8 +892,6 @@ return BESE_BAD_ARG; } - printf("----%s\n", dom->name); - arch = (struct jsdl_cpu_architecture*)malloc(sizeof(struct jsdl_cpu_architecture)); if (arch == NULL) { return BESE_MEM_ALLOC; @@ -727,8 +929,6 @@ struct soap_dom_element *cur = dom->elts; int rc; - printf("---%s\n", dom->name); - while (cur) { if (isElement(cur, JSDL_NS, "CandidateHosts")) { if ((rc = jsdl_processCandidateHosts(cur, jsdl)) != BESE_OK) { @@ -736,7 +936,6 @@ } } else if (isElement(cur, JSDL_NS, "ExclusiveExecution")) { - printf("----ExclusiveExecution = %s\n", cur->data); if (!strcmp(cur->data, "true")) { jsdl->ExclusiveExecution = 1; } @@ -752,31 +951,26 @@ } } else if (isElement(cur, JSDL_NS, "IndividualCPUCount")) { - printf("----IndividualCPUCount\n"); if ((rc = jsdl_processRangeValue(cur, &jsdl->IndividualCPUCount)) != BESE_OK) { return rc; } } else if (isElement(cur, JSDL_NS, "IndividualPhysicalMemory")) { - printf("----IndividualPhysicalMemory\n"); if ((rc = jsdl_processRangeValue(cur, &jsdl->IndividualPhysicalMemory)) != BESE_OK) { return rc; } } else if (isElement(cur, JSDL_NS, "IndividualVirtualMemory")) { - printf("----IndividualVirtualMemory\n"); if ((rc = jsdl_processRangeValue(cur, &jsdl->IndividualVirtualMemory)) != BESE_OK) { return rc; } } else if (isElement(cur, JSDL_NS, "TotalCPUCount")) { - printf("----TotalCPUCount\n"); if ((rc = jsdl_processRangeValue(cur, &jsdl->TotalCPUCount)) != BESE_OK) { return rc; } } else if (isElement(cur, JSDL_NS, "TotalResourceCount")) { - printf("----TotalResourceCount\n"); if ((rc = jsdl_processRangeValue(cur, &jsdl->TotalResourceCount)) != BESE_OK) { return rc; } @@ -816,8 +1010,6 @@ struct hpcp_credential *cred; int rc; - printf("---%s\n", dom->name); - file = (struct jsdl_data_staging *)malloc(sizeof(struct jsdl_data_staging)); if (file == NULL) { return BESE_MEM_ALLOC; @@ -827,7 +1019,6 @@ while (cur) { if (isElement(cur, JSDL_NS, "FileName")) { - printf("----FileName\n"); file->FileName = strdup(cur->data); if (file->FileName == NULL) { jsdl_freeDataStaging(file); @@ -835,7 +1026,6 @@ } } else if (isElement(cur, JSDL_NS, "FileSystemName")) { - printf("----FileSystemName\n"); file->FileSystemName = strdup(cur->data); if (file->FileSystemName == NULL) { jsdl_freeDataStaging(file); @@ -843,7 +1033,6 @@ } } else if (isElement(cur, JSDL_NS, "CreationFlag")) { - printf("----CreationFlag\n"); if (!strcmp(cur->data, "overwrite")) { file->CreationFlag = jsdl_overwrite; } @@ -855,13 +1044,11 @@ } } else if (isElement(cur, JSDL_NS, "DeleteOnTermination")) { - printf("----DeleteOnTermination\n"); if (!strcmp(cur->data, "true")) { file->DeleteOnTermination = 1; } } else if (isElement(cur, JSDL_NS, "Source")) { - printf("----Source\n"); if (isElement(cur->elts, JSDL_NS, "URI")) { file->SourceURI = strdup(cur->elts->data); if (file->SourceURI == NULL) { @@ -875,7 +1062,6 @@ } } else if (isElement(cur, JSDL_NS, "Target")) { - printf("----Target\n"); if (isElement(cur->elts, JSDL_NS, "URI")) { file->TargetURI = strdup(cur->elts->data); if (file->TargetURI == NULL) { @@ -921,8 +1107,6 @@ struct soap_dom_element *cur = dom->elts; int rc; - printf("--%s\n", dom->name); - while (cur) { if (isElement(cur, JSDL_NS, "JobIdentification")) { if ((rc = jsdl_processJobIdentification(cur, jsdl)) != BESE_OK) { @@ -949,14 +1133,30 @@ int jsdl_processJobDefinition(struct soap_dom_element *dom, - struct jsdl_job_definition *jsdl) + struct jsdl_job_definition **jsdl) { struct soap_dom_element *cur = dom->elts; + struct jsdl_job_definition *jd; + int rc; - printf("-%s\n", dom->name); + if (jsdl == NULL || dom == NULL) { + return BESE_BAD_ARG; + } + jd = (struct jsdl_job_definition*)malloc(sizeof(struct jsdl_job_definition)); + if (jd == NULL) { + return BESE_MEM_ALLOC; + } + memset(jd, 0, sizeof(struct jsdl_job_definition)); + if (isElement(cur, JSDL_NS, "JobDescription")) { - return jsdl_processJobDescription(cur, jsdl); + rc = jsdl_processJobDescription(cur, jd); + if (rc != BESE_OK) { + jsdl_freeJobDefinition(jd); + return rc; + } + *jsdl = jd; + return BESE_OK; } else { return BESE_XML_FORMAT; } @@ -1022,6 +1222,61 @@ free(jsdl); } +int +jsdl_newJobDefinition(enum jsdl_application_type app_type, struct jsdl_job_definition **jsdl) +{ + struct jsdl_job_definition *jd; + struct jsdl_posix_application *posix; + struct jsdl_hpcp_application *hpcp; + void *app; + + if (jsdl == NULL) { + return BESE_BAD_ARG; + } + + switch (app_type) { + + case JSDL_POSIX_APPLICATION: + posix = (struct jsdl_posix_application*)malloc(sizeof(struct jsdl_posix_application)); + if (posix == NULL) { + return BESE_MEM_ALLOC; + } + memset(posix, 0, sizeof(struct jsdl_posix_application)); + app = (void*)posix; + break; + + case JSDL_HPC_PROFILE_APPLICATION: + hpcp = (struct jsdl_hpcp_application*)malloc(sizeof(struct jsdl_hpcp_application)); + if (hpcp == NULL) { + return BESE_MEM_ALLOC; + } + memset(hpcp, 0, sizeof(struct jsdl_hpcp_application)); + app = (void*)hpcp; + break; + + default: + return BESE_BAD_ARG;; + } + + jd = (struct jsdl_job_definition*)malloc(sizeof(struct jsdl_job_definition)); + if (jd == NULL) { + free(app); + return BESE_MEM_ALLOC; + } + memset(jd, 0, sizeof(struct jsdl_job_definition)); + + jd->Application = app; + jd->ApplicationType = app_type; + + *jsdl = jd; + + return BESE_OK; +} + +/* + * Functions below here are used to turn a jsdl_job_definition + * into a gSOAP DOM tree + */ struct soap_dom_element * jsdl_generateDomElement(struct soap *s, char *nstr, char *name) { Modified: trunk/besclient/jsdl.h =================================================================== --- trunk/besclient/jsdl.h 2008-10-31 18:03:49 UTC (rev 59) +++ trunk/besclient/jsdl.h 2008-10-31 21:36:04 UTC (rev 60) @@ -188,7 +188,13 @@ struct jsdl_data_staging *DataStaging; }; -int jsdl_processJobDefinition(struct soap_dom_element*, struct jsdl_job_definition*); +int jsdl_newJobDefinition(enum jsdl_application_type, struct jsdl_job_definition**); +int jsdl_newRangeValue(struct jsdl_range_value**); +int jsdl_addUpperBound(struct jsdl_range_value*, double, int); +int jsdl_addLowerBound(struct jsdl_range_value*, double, int); +int jsdl_addExact(struct jsdl_range_value*, double, double); +int jsdl_addRange(struct jsdl_range_value*, double, int, double, int); +int jsdl_processJobDefinition(struct soap_dom_element*, struct jsdl_job_definition**); void jsdl_freeJobDefinition(struct jsdl_job_definition *); int jsdl_generateJobDefinitionDOM(struct jsdl_job_definition *, struct soap_dom_element **); void jsdl_freeJobDefinitionDOM(struct soap_dom_element *); Added: trunk/besclient/libtests.c =================================================================== --- trunk/besclient/libtests.c (rev 0) +++ trunk/besclient/libtests.c 2008-10-31 21:36:04 UTC (rev 60) @@ -0,0 +1,100 @@ +#include <stdlib.h> +#include <stdio.h> + +#include "bes.h" + +int +main(int argc, char *argv[]) +{ + struct jsdl_job_definition *jd; + struct jsdl_hpcp_application *app; + struct jsdl_range_value rval; + struct jsdl_exact exact; + struct bes_context *ctx; + struct bes_activity_status status; + struct bes_activity_document *document; + epr_t endpoint, activity; + char *user = "myuser"; + char *pass = "mypass"; + char *capath = "./certs"; + char *endpoint_file = "endpoint.xml"; + char *args[] = { "1" }; + int rc, interval = 1; + + if (rc = bes_init(&ctx)) { + return rc; + } + + if (rc = bes_security(ctx, NULL, NULL, capath, user, pass)) { + fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); + return rc; + } + + if (rc = bes_readEPRFromFile(ctx, endpoint_file, &endpoint)) { + fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); + return rc; + } + + if (rc = jsdl_newJobDefinition(JSDL_HPC_PROFILE_APPLICATION, &jd)) { + fprintf(stderr, "Can't allocate JobDefinition\n"); + return rc; + } + exact.value = 1.0; + exact.epsilon = 0.0; + exact.next = NULL; + memset(&rval, 0, sizeof(rval)); + rval.Exact = &exact; + jd->JobName = "BESLibTest"; + jd->JobProject = "BES"; + jd->TotalCPUCount = &rval; + app = (struct jsdl_hpcp_application*)jd->Application; + app->Executable = "sleep"; + app->num_args = 1; + app->Argument = args; + app->Output = "/dev/null"; + app->WorkingDirectory = "/tmp"; + + if (rc = bes_createActivity(ctx, endpoint, jd, &activity)) { + fprintf(stderr, "createActivity: %s\n", bes_get_lasterror(ctx)); + return rc; + } + + while (1) { + + if (rc = bes_add_usertoken(ctx, user, pass)) { + fprintf(stderr, "add_usertoken: %s\n", bes_get_lasterror(ctx)); + return rc; + } + + if (rc = bes_getActivityStatuses(ctx, endpoint, activity, &status)) { + fprintf(stderr, "getActivityStatuses: %s\n", bes_get_lasterror(ctx)); + return rc; + } + + if (status.state == BES_Cancelled + || status.state == BES_Failed + || status.state == BES_Finished) { + break; + } + + printf("."); + fflush(stdout); + sleep(interval); + } + + printf("\n"); + + if (rc = bes_add_usertoken(ctx, user, pass)) { + fprintf(stderr, "add_usertoken: %s\n", bes_get_lasterror(ctx)); + return rc; + } + if (rc = bes_getActivityDocuments(ctx, endpoint, activity, &document)) { + fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); + return rc; + } + bes_freeActivityDocument(document); + + bes_finalize(&ctx); + + return rc; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-10-31 21:44:35
|
Revision: 61 http://bespp.svn.sourceforge.net/bespp/?rev=61&view=rev Author: csmith Date: 2008-10-31 21:40:42 +0000 (Fri, 31 Oct 2008) Log Message: ----------- - updated libtests.c to use range value utility routines Modified Paths: -------------- trunk/besclient/libtests.c Modified: trunk/besclient/libtests.c =================================================================== --- trunk/besclient/libtests.c 2008-10-31 21:36:04 UTC (rev 60) +++ trunk/besclient/libtests.c 2008-10-31 21:40:42 UTC (rev 61) @@ -8,8 +8,7 @@ { struct jsdl_job_definition *jd; struct jsdl_hpcp_application *app; - struct jsdl_range_value rval; - struct jsdl_exact exact; + struct jsdl_range_value *cpucount; struct bes_context *ctx; struct bes_activity_status status; struct bes_activity_document *document; @@ -35,18 +34,23 @@ return rc; } + if (rc = jsdl_newRangeValue(&cpucount)) { + fprintf(stderr, "Can't allocate RangeValue\n"); + return rc; + } + if (rc = jsdl_addExact(cpucount, 1.0, 0.0)) { + fprintf(stderr, "Can't add Exact to RangeValue\n"); + return rc; + } + if (rc = jsdl_newJobDefinition(JSDL_HPC_PROFILE_APPLICATION, &jd)) { fprintf(stderr, "Can't allocate JobDefinition\n"); return rc; } - exact.value = 1.0; - exact.epsilon = 0.0; - exact.next = NULL; - memset(&rval, 0, sizeof(rval)); - rval.Exact = &exact; + jd->JobName = "BESLibTest"; jd->JobProject = "BES"; - jd->TotalCPUCount = &rval; + jd->TotalCPUCount = cpucount; app = (struct jsdl_hpcp_application*)jd->Application; app->Executable = "sleep"; app->num_args = 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-10-31 18:03:53
|
Revision: 59 http://bespp.svn.sourceforge.net/bespp/?rev=59&view=rev Author: csmith Date: 2008-10-31 18:03:49 +0000 (Fri, 31 Oct 2008) Log Message: ----------- - added function to free up the bes_activity_document Modified Paths: -------------- trunk/besclient/bes.c trunk/besclient/bes.h Modified: trunk/besclient/bes.c =================================================================== --- trunk/besclient/bes.c 2008-10-28 22:34:49 UTC (rev 58) +++ trunk/besclient/bes.c 2008-10-31 18:03:49 UTC (rev 59) @@ -837,6 +837,26 @@ return BESE_OK; } +void +bes_freeActivityDocument(struct bes_activity_document *adoc) +{ + if (adoc == NULL) { + return; + } + if (adoc->activityepr) { + bes_freeEPR(&adoc->activityepr); + adoc->activityepr = NULL; + } + if (adoc->activity) { + jsdl_freeJobDefinition(adoc->activity); + adoc->activity = NULL; + } + if (adoc->fault) { + free(adoc->fault); + adoc->fault = NULL; + } +} + int bes_getFactoryAttributesDocument(struct bes_context *context, epr_t endpointepr, Modified: trunk/besclient/bes.h =================================================================== --- trunk/besclient/bes.h 2008-10-28 22:34:49 UTC (rev 58) +++ trunk/besclient/bes.h 2008-10-31 18:03:49 UTC (rev 59) @@ -96,6 +96,7 @@ int bes_getActivityStatuses(struct bes_context *, epr_t, epr_t, struct bes_activity_status *); int bes_getActivityDocumentsXML(struct bes_context *, epr_t, epr_t, char **); int bes_getActivityDocuments(struct bes_context *, epr_t, epr_t, struct bes_activity_document **); +void bes_freeActivityDocument(struct bes_activity_document *); int bes_getFactoryAttributesDocument(struct bes_context *, epr_t, char **); void bes_freeEPR(epr_t *epr); int bes_writeEPRToFile(struct bes_context *, char *, epr_t); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-10-28 22:34:59
|
Revision: 58 http://bespp.svn.sourceforge.net/bespp/?rev=58&view=rev Author: csmith Date: 2008-10-28 22:34:49 +0000 (Tue, 28 Oct 2008) Log Message: ----------- - created new library routines to call CreateActivity with a struct jsdl_job_definition from the jsdl.h header file Modified Paths: -------------- trunk/besclient/bes.c trunk/besclient/bes.h trunk/besclient/besclient.c trunk/besclient/jsdl.c trunk/besclient/jsdl.h Modified: trunk/besclient/bes.c =================================================================== --- trunk/besclient/bes.c 2008-10-21 03:14:56 UTC (rev 57) +++ trunk/besclient/bes.c 2008-10-28 22:34:49 UTC (rev 58) @@ -253,12 +253,85 @@ int bes_createActivity(struct bes_context *context, epr_t endpointepr, - char *jsdlfile, + struct jsdl_job_definition *jsdl, epr_t *activityepr) { struct soap *s; struct bes__CreateActivityType req; struct bes__CreateActivityResponseType rsp; + struct soap_dom_element *dom, *tmpdom; + struct bes_epr *epr; + int ret = BESE_OK; + char *endpoint; + + if (context == NULL + || endpointepr == NULL + || jsdl == NULL + || activityepr == NULL) { + return BESE_BAD_ARG; + } + + s = context->soap; + + if (ret = generateAddressingHeaders(context, endpointepr, CREATE_ACT, &endpoint)) { + setErrorString(context, NULL, ret); + return ret; + } + + if (ret = jsdl_generateJobDefinitionDOM(jsdl, &dom)) { + setErrorString(context, NULL, ret); + return ret; + } + + memset(&req, 0, sizeof(struct bes__CreateActivityType)); + memset(&rsp, 0, sizeof(struct bes__CreateActivityResponseType)); + + req.bes__ActivityDocument.__any = dom; + + if (soap_call___bes__CreateActivity(s, endpoint, CREATE_ACT, &req, &rsp) != SOAP_OK) { + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; + goto end; + } + else { + tmpdom = rsp.__any; + + cleanDom(tmpdom); + + epr = (struct bes_epr *)malloc(sizeof(struct bes_epr)); + if (!epr) { + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; + goto end; + } + memset(epr, 0, sizeof(struct bes_epr)); + + epr->str = generateEPRString(tmpdom, NULL); + if (!epr->str) { + free(epr); + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; + goto end; + } + epr->dom = tmpdom; + *activityepr = (epr_t)epr; + } + + end: + jsdl_freeJobDefinitionDOM(dom); + + return ret; +} + +int +bes_createActivityFromFile(struct bes_context *context, + epr_t endpointepr, + char *jsdlfile, + epr_t *activityepr) +{ + struct soap *s; + struct bes__CreateActivityType req; + struct bes__CreateActivityResponseType rsp; struct soap_dom_element dom, *tmpdom; struct soap_dom_attribute *attr; struct bes_epr *epr; @@ -333,8 +406,7 @@ end: soap_end(dom.soap); - soap_done(dom.soap); - free(dom.soap); + soap_free(dom.soap); return ret; } Modified: trunk/besclient/bes.h =================================================================== --- trunk/besclient/bes.h 2008-10-21 03:14:56 UTC (rev 57) +++ trunk/besclient/bes.h 2008-10-28 22:34:49 UTC (rev 58) @@ -89,7 +89,8 @@ int bes_finalize(struct bes_context **); const char* bes_get_lasterror(struct bes_context *context); -int bes_createActivity(struct bes_context *, epr_t, char *, epr_t *); +int bes_createActivity(struct bes_context *, epr_t, struct jsdl_job_definition *, epr_t *); +int bes_createActivityFromFile(struct bes_context *, epr_t, char *, epr_t *); int bes_createActivityFromString(struct bes_context *, epr_t, char *, epr_t *); int bes_terminateActivities(struct bes_context *, epr_t, epr_t); int bes_getActivityStatuses(struct bes_context *, epr_t, epr_t, struct bes_activity_status *); Modified: trunk/besclient/besclient.c =================================================================== --- trunk/besclient/besclient.c 2008-10-21 03:14:56 UTC (rev 57) +++ trunk/besclient/besclient.c 2008-10-28 22:34:49 UTC (rev 58) @@ -153,7 +153,7 @@ if (!strcmp(command, "create")) { epr_t new_activityepr; - if (bes_createActivity(ctx, endpointepr, argv[1], &new_activityepr)) { + if (bes_createActivityFromFile(ctx, endpointepr, argv[1], &new_activityepr)) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; } @@ -318,3 +318,4 @@ return password; } + Modified: trunk/besclient/jsdl.c =================================================================== --- trunk/besclient/jsdl.c 2008-10-21 03:14:56 UTC (rev 57) +++ trunk/besclient/jsdl.c 2008-10-28 22:34:49 UTC (rev 58) @@ -488,6 +488,7 @@ { struct jsdl_range_value *val; struct jsdl_exact *new_exact, *exact; + struct jsdl_bound *bound; struct soap_dom_element *cur; struct soap_dom_attribute *attr; char *endptr; @@ -506,24 +507,36 @@ while (cur) { if (isElement(cur, JSDL_NS, "UpperBoundedRange")) { - val->UpperBoundedRange = strtod(cur->data, NULL); + bound = (struct jsdl_bound*)malloc(sizeof(struct jsdl_bound)); + if (bound == NULL) { + jsdl_freeRangeValue(val); + return BESE_MEM_ALLOC; + } + bound->value = strtod(cur->data, NULL); for (attr = cur->atts; attr; attr = attr->next) { if (!strcmp(attr->name, "exclusiveBound")) { if (!strcmp(attr->data, "true")) { - val->exclusiveUpperBound = 1; + bound->exclusive = 1; } } } + val->UpperBoundedRange = bound; } else if (isElement(cur, JSDL_NS, "LowerBoundedRange")) { - val->LowerBoundedRange = strtod(cur->data, NULL); + bound = (struct jsdl_bound*)malloc(sizeof(struct jsdl_bound)); + if (bound == NULL) { + jsdl_freeRangeValue(val); + return BESE_MEM_ALLOC; + } + bound->value = strtod(cur->data, NULL); for (attr = cur->atts; attr; attr = attr->next) { if (!strcmp(attr->name, "exclusiveBound")) { if (!strcmp(attr->data, "true")) { - val->exclusiveLowerBound = 1; + bound->exclusive = 1; } } } + val->LowerBoundedRange = bound; } else if (isElement(cur, JSDL_NS, "Exact")) { new_exact = (struct jsdl_exact*)malloc(sizeof(struct jsdl_exact)); @@ -588,6 +601,12 @@ if (fs == NULL) return; + if (fs->name) free(fs->name); + if (fs->MountPoint) free(fs->MountPoint); + if (fs->DiskSpace) jsdl_freeRangeValue(fs->DiskSpace); + + free(fs); + } int @@ -1003,175 +1022,1548 @@ free(jsdl); } -#if 0 +struct soap_dom_element * +jsdl_generateDomElement(struct soap *s, char *nstr, char *name) +{ + struct soap_dom_element *dom; + + dom = (struct soap_dom_element*)soap_malloc(s, sizeof(struct soap_dom_element)); + if (dom == NULL) { + return NULL; + } + memset(dom, 0, sizeof(struct soap_dom_element)); + dom->nstr = soap_strdup(s, nstr); + dom->name = soap_strdup(s, name); + if (!dom->nstr || !dom->name) { + return NULL; + } + + return dom; +} + +struct soap_dom_attribute * +jsdl_generateDomAttribute(struct soap *s, char *name) +{ + struct soap_dom_attribute *attr; + + attr = (struct soap_dom_attribute*)soap_malloc(s, sizeof(struct soap_dom_attribute)); + if (attr == NULL) { + return NULL; + } + memset(attr, 0, sizeof(struct soap_dom_attribute)); + attr->name = soap_strdup(s, name); + if (attr->name == NULL) { + return NULL; + } + + return attr; +} + +struct soap_dom_element * +jsdl_generateOperatingSystem(struct soap *s, struct jsdl_operating_system *jsdl_os) +{ + struct soap_dom_element *os, *ostype, *osname, *osver; + + if (jsdl_os == NULL) { + return NULL; + } + + os = jsdl_generateDomElement(s, JSDL_NS, "OperatingSystem"); + if (os == NULL) { + return NULL; + } + + osname = NULL; + if (jsdl_os->OperatingSystemName) { + ostype = jsdl_generateDomElement(s, JSDL_NS, "OperatingSystemType"); + if (ostype == NULL) { + return NULL; + } + ostype->prnt = os; + osname = jsdl_generateDomElement(s, JSDL_NS, "OperatingSystemName"); + if (osname == NULL) { + return NULL; + } + osname->prnt = ostype; + osname->data = soap_strdup(s, jsdl_os->OperatingSystemName); + if (osname->data == NULL) { + return NULL; + } + ostype->elts = osname; + } + + if (jsdl_os->OperatingSystemVersion) { + osver = jsdl_generateDomElement(s, JSDL_NS, "OperatingSystemVersion"); + if (osver == NULL) { + return NULL; + } + osver->prnt = os; + osver->data = soap_strdup(s, jsdl_os->OperatingSystemVersion); + if (osver->data == NULL) { + return NULL; + } + if (ostype) { + ostype->next = osver; + } + else { + os->elts = osver; + } + } + + return os; +} + +struct soap_dom_element * +jsdl_generateCPUArchitecture(struct soap *s, struct jsdl_cpu_architecture *arch) +{ + struct soap_dom_element *cpuname, *cpu; + + if (arch == NULL) { + return NULL; + } + + cpu = jsdl_generateDomElement(s, JSDL_NS, "CPUArchitecture"); + if (cpu == NULL) { + return NULL; + } + + if (arch->CPUArchitectureName) { + cpuname = jsdl_generateDomElement(s, JSDL_NS, "CPUArchitectureName"); + if (cpuname == NULL) { + return NULL; + } + cpuname->prnt = cpu; + cpuname->data = soap_strdup(s, arch->CPUArchitectureName); + if (cpuname->data == NULL) { + return NULL; + } + cpu->elts = cpuname; + } + + return cpu; +} + +struct soap_dom_element * +jsdl_generateRangeValue(struct soap *s, struct jsdl_range_value *rangeval, char *name) +{ + struct soap_dom_element *rval, *first, *cur, *dom; + struct jsdl_exact *exact; + struct jsdl_range *range; + char buf[512]; + + if (rangeval == NULL || name == NULL) { + return NULL; + } + + rval = jsdl_generateDomElement(s, JSDL_NS, name); + if (rval == NULL) { + return NULL; + } + + first = cur = NULL; + + if (rangeval->UpperBoundedRange) { + dom = jsdl_generateDomElement(s, JSDL_NS, "UpperBoundedRange"); + if (dom == NULL) { + return NULL; + } + dom->prnt = rval; + sprintf(buf, "%f", rangeval->UpperBoundedRange->value); + dom->data = soap_strdup(s, buf); + if (dom->data == NULL) { + return NULL; + } + if (rangeval->UpperBoundedRange->exclusive) { + dom->atts = jsdl_generateDomAttribute(s, "exclusiveBound"); + if (dom->atts == NULL) { + return NULL; + } + dom->atts->data = soap_strdup(s, "true"); + if (dom->atts->data == NULL) { + return NULL; + } + } + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (rangeval->LowerBoundedRange) { + dom = jsdl_generateDomElement(s, JSDL_NS, "LowerBoundedRange"); + if (dom == NULL) { + return NULL; + } + dom->prnt = rval; + sprintf(buf, "%f", rangeval->LowerBoundedRange->value); + dom->data = soap_strdup(s, buf); + if (dom->data == NULL) { + return NULL; + } + if (rangeval->LowerBoundedRange->exclusive) { + dom->atts = jsdl_generateDomAttribute(s, "exclusiveBound"); + if (dom->atts == NULL) { + return NULL; + } + dom->atts->data = soap_strdup(s, "true"); + if (dom->atts->data == NULL) { + return NULL; + } + } + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + exact = rangeval->Exact; + while (exact) { + dom = jsdl_generateDomElement(s, JSDL_NS, "Exact"); + if (dom == NULL) { + return NULL; + } + dom->prnt = rval; + sprintf(buf, "%f", exact->value); + dom->data = soap_strdup(s, buf); + if (dom->data == NULL) { + return NULL; + } + if (exact->epsilon) { + dom->atts = jsdl_generateDomAttribute(s, "epsilon"); + if (dom->atts == NULL) { + return NULL; + } + sprintf(buf, "%f", exact->epsilon); + dom->atts->data = soap_strdup(s, buf); + if (dom->atts->data == NULL) { + return NULL; + } + } + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + exact = exact->next; + } + + range = rangeval->Range; + while (range) { + if (!range->LowerBound || !range->UpperBound) { + return NULL; + } + dom = jsdl_generateDomElement(s, JSDL_NS, "Range"); + if (dom == NULL) { + return NULL; + } + dom->prnt = rval; + dom->elts = jsdl_generateDomElement(s, JSDL_NS, "LowerBound"); + if (dom->elts == NULL) { + return NULL; + } + dom->elts->prnt = dom; + sprintf(buf, "%f", range->LowerBound->value); + dom->elts->data = soap_strdup(s, buf); + if (dom->elts->data == NULL) { + return NULL; + } + if (range->LowerBound->exclusive) { + dom->elts->atts = jsdl_generateDomAttribute(s, "exclusiveBound"); + if (dom->elts->atts == NULL) { + return NULL; + } + dom->elts->atts->data = soap_strdup(s, "true"); + if (dom->elts->atts->data == NULL) { + return NULL; + } + } + dom->elts->next = jsdl_generateDomElement(s, JSDL_NS, "UpperBound"); + if (dom->elts->next == NULL) { + return NULL; + } + dom->elts->next->prnt = dom; + sprintf(buf, "%f", range->UpperBound->value); + dom->elts->next->data = soap_strdup(s, buf); + if (dom->elts->next->data == NULL) { + return NULL; + } + if (range->UpperBound->exclusive) { + dom->elts->next->atts = jsdl_generateDomAttribute(s, "exclusiveBound"); + if (dom->elts->next->atts == NULL) { + return NULL; + } + dom->elts->next->atts->data = soap_strdup(s, "true"); + if (dom->elts->next->atts->data == NULL) { + return NULL; + } + } + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + range = range->next; + } + + if (!first) { + return NULL; + } + + rval->elts = first; + + return rval; +} + +struct soap_dom_element * +jsdl_generateFileSystem(struct soap *s, struct jsdl_file_system *fs) +{ + struct soap_dom_element *new_fs, *first, *cur, *dom; + + if (fs == NULL) { + return NULL; + } + + new_fs = jsdl_generateDomElement(s, JSDL_NS, "FileSystem"); + if (new_fs == NULL) { + return NULL; + } + + if (fs->name) { + new_fs->atts = jsdl_generateDomAttribute(s, "name"); + if (new_fs->atts == NULL) { + return NULL; + } + new_fs->atts->data = soap_strdup(s, fs->name); + if (new_fs->atts->data == NULL) { + return NULL; + } + } + + first = cur = NULL; + + if (fs->type) { + dom = jsdl_generateDomElement(s, JSDL_NS, "FileSystemType"); + if (dom == NULL) { + return NULL; + } + dom->prnt = new_fs; + switch (fs->type) { + case jsdl_swap: + dom->data = "swap"; + break; + case jsdl_temporary: + dom->data = "temporary"; + break; + case jsdl_spool: + dom->data = "spool"; + break; + case jsdl_normal: + dom->data = "normal"; + break; + default: + return NULL; + } + first = dom; + cur = dom; + } + + if (fs->MountPoint) { + dom = jsdl_generateDomElement(s, JSDL_NS, "MountPoint"); + if (dom == NULL) { + return NULL; + } + dom->data = soap_strdup(s, fs->MountPoint); + if (dom->data == NULL) { + return NULL; + } + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (fs->DiskSpace) { + dom = jsdl_generateRangeValue(s, fs->DiskSpace, "DiskSpace"); + if (dom == NULL) { + return NULL; + } + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + new_fs->elts = first; + + return new_fs; +} + +struct soap_dom_element * +jsdl_generateCandidateHosts(struct soap *s, struct jsdl_job_definition *jd) +{ + struct soap_dom_element *cand, *first, *cur, *dom; + int i; + + if (jd == NULL || jd->num_hosts == 0) { + return NULL; + } + + cand = jsdl_generateDomElement(s, JSDL_NS, "CandidateHosts"); + if (cand == NULL) { + return NULL; + } + + first = cur = NULL; + + for (i = 0; i < jd->num_hosts; i++) { + dom = jsdl_generateDomElement(s, JSDL_NS, "HostName"); + if (dom == NULL) { + return NULL; + } + dom->prnt = cand; + dom->data = soap_strdup(s, jd->HostName[i]); + if (dom->data == NULL) { + return NULL; + } + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + cand->elts = first; + + return cand; +} + struct soap_dom_element * -getHPCProfileApplication(struct jsdl_job_definition *job) +jsdl_generateHPCProfileApplication(struct soap *s, struct jsdl_job_definition *jd) { - struct soap_dom_element *dom, *cur, *next; + struct soap_dom_element *hpcpa, *first, *cur, *dom; + struct jsdl_hpcp_application *app; + struct jsdl_envvar *envvar; char *nstr; int i; - nstr = strdup(JSDL_HPCPA_NS); - if (!nstr) { + if (jd == NULL || jd->Application == NULL) { return NULL; } - dom = (struct soap_dom_element*)soap_malloc(s, - sizeof(struct soap_dom_element)); - if (!dom) { + app = (struct jsdl_hpcp_application*)jd->Application; + + hpcpa = jsdl_generateDomElement(s, JSDL_HPCPA_NS, "HPCProfileApplication"); + if (hpcpa == NULL) { return NULL; } - memset(dom, 0, sizeof(struct soap_dom_element)); - dom->nstr = nstr; - dom->name = strdup("HPCProfileApplication"); - if (!dom->name) { + + first = cur = NULL; + + if (app->Executable) { + dom = jsdl_generateDomElement(s, JSDL_HPCPA_NS, "Executable"); + if (dom == NULL) { + return NULL; + } + dom->prnt = hpcpa; + dom->data = soap_strdup(s, app->Executable); + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + for (i = 0; i < app->num_args; i++ ) { + dom = jsdl_generateDomElement(s, JSDL_HPCPA_NS, "Argument"); + if (dom == NULL) { + return NULL; + } + dom->prnt = hpcpa; + dom->data = soap_strdup(s, app->Argument[i]); + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (app->Input) { + dom = jsdl_generateDomElement(s, JSDL_HPCPA_NS, "Input"); + if (dom == NULL) { + return NULL; + } + dom->prnt = hpcpa; + dom->data = soap_strdup(s, app->Input); + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (app->Output) { + dom = jsdl_generateDomElement(s, JSDL_HPCPA_NS, "Output"); + if (dom == NULL) { + return NULL; + } + dom->prnt = hpcpa; + dom->data = soap_strdup(s, app->Output); + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (app->Error) { + dom = jsdl_generateDomElement(s, JSDL_HPCPA_NS, "Error"); + if (dom == NULL) { + return NULL; + } + dom->prnt = hpcpa; + dom->data = soap_strdup(s, app->Error); + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (app->WorkingDirectory) { + dom = jsdl_generateDomElement(s, JSDL_HPCPA_NS, "WorkingDirectory"); + if (dom == NULL) { + return NULL; + } + dom->prnt = hpcpa; + dom->data = soap_strdup(s, app->WorkingDirectory); + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (app->Environment) { + envvar = app->Environment; + while (envvar) { + dom = jsdl_generateDomElement(s, JSDL_HPCPA_NS, "Environment"); + if (dom == NULL) { + return NULL; + } + dom->prnt = hpcpa; + dom->atts = jsdl_generateDomAttribute(s, "name"); + if (dom->atts == NULL) { + return NULL; + } + dom->atts->data = soap_strdup(s, envvar->name); + dom->data = soap_strdup(s, envvar->val); + if (dom->atts->data == NULL || dom->data == NULL) { + return NULL; + } + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + envvar = envvar->next; + } + } + + if (app->UserName) { + dom = jsdl_generateDomElement(s, JSDL_HPCPA_NS, "UserName"); + if (dom == NULL) { + return NULL; + } + dom->prnt = hpcpa; + dom->data = soap_strdup(s, app->UserName); + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (first == NULL) { return NULL; } - cur = (struct soap_dom_element*)soap_malloc(s, - sizeof(struct soap_dom_element)); - if (cur == NULL) { + hpcpa->elts = first; + + return hpcpa; +} + +struct soap_dom_element * +jsdl_generatePosixApplication(struct soap *s, struct jsdl_job_definition *jd) +{ + struct soap_dom_element *posix, *first, *cur, *dom; + struct jsdl_posix_application *app; + struct jsdl_envvar *envvar; + char *nstr; + int i; + + if (jd == NULL || jd->Application == NULL) { return NULL; } - memset(cur, 0, sizeof(struct soap_dom_element)); - cur->nstr = nstr; - cur->prnt = dom; - cur->name = strdup("Executable"); - if (!cur->name) { + + app = (struct jsdl_posix_application*)jd->Application; + + posix = jsdl_generateDomElement(s, JSDL_POSIX_NS, "POSIXApplication"); + if (posix == NULL) { return NULL; } - cur->data = strdup(job->executable); - if (!cur->data) { + + first = cur = NULL; + + if (app->Executable) { + dom = jsdl_generateDomElement(s, JSDL_POSIX_NS, "Executable"); + if (dom == NULL) { + return NULL; + } + dom->prnt = posix; + dom->data = soap_strdup(s, app->Executable); + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + for (i = 0; i < app->num_args; i++ ) { + dom = jsdl_generateDomElement(s, JSDL_POSIX_NS, "Argument"); + if (dom == NULL) { + return NULL; + } + dom->prnt = posix; + dom->data = soap_strdup(s, app->Argument[i]); + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (app->Input) { + dom = jsdl_generateDomElement(s, JSDL_POSIX_NS, "Input"); + if (dom == NULL) { + return NULL; + } + dom->prnt = posix; + dom->data = soap_strdup(s, app->Input); + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (app->Output) { + dom = jsdl_generateDomElement(s, JSDL_POSIX_NS, "Output"); + if (dom == NULL) { + return NULL; + } + dom->prnt = posix; + dom->data = soap_strdup(s, app->Output); + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (app->Error) { + dom = jsdl_generateDomElement(s, JSDL_POSIX_NS, "Error"); + if (dom == NULL) { + return NULL; + } + dom->prnt = posix; + dom->data = soap_strdup(s, app->Error); + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (app->WorkingDirectory) { + dom = jsdl_generateDomElement(s, JSDL_POSIX_NS, "WorkingDirectory"); + if (dom == NULL) { + return NULL; + } + dom->prnt = posix; + dom->data = soap_strdup(s, app->WorkingDirectory); + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (app->Environment) { + envvar = app->Environment; + while (envvar) { + dom = jsdl_generateDomElement(s, JSDL_POSIX_NS, "Environment"); + if (dom == NULL) { + return NULL; + } + dom->prnt = posix; + dom->atts = jsdl_generateDomAttribute(s, "name"); + if (dom->atts == NULL) { + return NULL; + } + dom->atts->data = soap_strdup(s, envvar->name); + dom->data = soap_strdup(s, envvar->val); + if (dom->atts->data == NULL || dom->data == NULL) { + return NULL; + } + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + envvar = envvar->next; + } + } + + if (app->UserName) { + dom = jsdl_generateDomElement(s, JSDL_POSIX_NS, "UserName"); + if (dom == NULL) { + return NULL; + } + dom->prnt = posix; + dom->data = soap_strdup(s, app->UserName); + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (app->GroupName) { + dom = jsdl_generateDomElement(s, JSDL_POSIX_NS, "GroupName"); + if (dom == NULL) { + return NULL; + } + dom->prnt = posix; + dom->data = soap_strdup(s, app->GroupName); + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (first == NULL) { return NULL; } - dom->elts = cur; - for (i = 0; i < job->num_args; i++ ) { - next = (struct soap_dom_element*)soap_malloc(s, - sizeof(struct soap_dom_element)); - if (next == NULL) { + posix->elts = first; + + return posix; +} + +struct soap_dom_element* +jsdl_generateJobIdentification(struct soap *s, struct jsdl_job_definition *jd) +{ + struct soap_dom_element *id, *first, *cur, *dom; + + id = jsdl_generateDomElement(s, JSDL_NS, "JobIdentification"); + if (id == NULL) { + return NULL; + } + + cur = first = NULL; + + if (jd->JobName) { + dom = jsdl_generateDomElement(s, JSDL_NS, "JobName"); + if (dom == NULL) { return NULL; } - memset(next, 0, sizeof(struct soap_dom_element)); - next->nstr = nstr; - next->prnt = dom; - next->name = strdup("Argument"); - if (!next->name) { + dom->data = soap_strdup(s, jd->JobName); + dom->prnt = id; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (jd->JobAnnotation) { + dom = jsdl_generateDomElement(s, JSDL_NS, "JobAnnotation"); + if (dom == NULL) { return NULL; } - next->data = strdup(job->args[i]); - if (!next->data) { + dom->data = soap_strdup(s, jd->JobAnnotation); + dom->prnt = id; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (jd->JobProject) { + dom = jsdl_generateDomElement(s, JSDL_NS, "JobProject"); + if (dom == NULL) { return NULL; } - cur->next = next; - cur = next; + dom->data = soap_strdup(s, jd->JobProject); + dom->prnt = id; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; } - if (job->input) { - next = (struct soap_dom_element*)soap_malloc(s, - sizeof(struct soap_dom_element)); - if (next == NULL) { + if (first == NULL) { + return NULL; + } + id->elts = first; + + return id; +} + +struct soap_dom_element* +jsdl_generateApplication(struct soap *s, struct jsdl_job_definition *jd) +{ + struct soap_dom_element *app, *first, *cur, *dom; + + app = jsdl_generateDomElement(s, JSDL_NS, "Application"); + if (app == NULL) { + return NULL; + } + + cur = first = NULL; + + if (jd->ApplicationName) { + dom = jsdl_generateDomElement(s, JSDL_NS, "ApplicationName"); + if (dom == NULL) { return NULL; } - memset(next, 0, sizeof(struct soap_dom_element)); - next->nstr = nstr; - next->prnt = dom; - next->name = strdup("Input"); - if (!next->name) { + dom->data = soap_strdup(s, jd->ApplicationName); + dom->prnt = app; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (jd->ApplicationVersion) { + dom = jsdl_generateDomElement(s, JSDL_NS, "ApplicationVersion"); + if (dom == NULL) { return NULL; } - next->data = strdup(job->input); - if (!next->data) { + dom->data = soap_strdup(s, jd->ApplicationVersion); + dom->prnt = app; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (jd->Application) { + if (jd->ApplicationType == JSDL_POSIX_APPLICATION) { + dom = jsdl_generatePosixApplication(s, jd); + } + else if (jd->ApplicationType == JSDL_HPC_PROFILE_APPLICATION) { + dom = jsdl_generateHPCProfileApplication(s, jd); + } + else { return NULL; } - cur->next = next; - cur = next; + if (dom == NULL) { + return NULL; + } + dom->prnt = app; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; } - if (job->output) { - next = (struct soap_dom_element*)soap_malloc(s, - sizeof(struct soap_dom_element)); - if (next == NULL) { + if (first == NULL) { + return NULL; + } + app->elts = first; + + return app; +} + +struct soap_dom_element* +jsdl_generateResources(struct soap *s, struct jsdl_job_definition *jd) +{ + struct soap_dom_element *res, *first, *cur, *dom; + struct jsdl_file_system *fs; + + res = jsdl_generateDomElement(s, JSDL_NS, "Resources"); + if (res == NULL) { + return NULL; + } + + cur = first = NULL; + + if (jd->num_hosts) { + dom = jsdl_generateCandidateHosts(s, jd); + if (dom == NULL) { return NULL; } - memset(next, 0, sizeof(struct soap_dom_element)); - next->nstr = nstr; - next->prnt = dom; - next->name = strdup("Output"); - if (!next->name) { + dom->prnt = res; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + fs = jd->FileSystem; + while (fs) { + dom = jsdl_generateFileSystem(s, fs); + if (dom == NULL) { return NULL; } - next->data = strdup(job->output); - if (!next->data) { + dom->prnt = res; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + fs = fs->next; + } + + if (jd->ExclusiveExecution) { + dom = jsdl_generateDomElement(s, JSDL_NS, "ExclusiveExecution"); + if (dom == NULL) { return NULL; } - cur->next = next; - cur = next; + dom->prnt = res; + dom->data = soap_strdup(s, "true"); + if (dom->data == NULL) { + return NULL; + } + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; } - if (job->error) { - next = (struct soap_dom_element*)soap_malloc(s, - sizeof(struct soap_dom_element)); - if (next == NULL) { + if (jd->OperatingSystemType) { + dom = jsdl_generateOperatingSystem(s, jd->OperatingSystemType); + if (dom == NULL) { return NULL; } - memset(next, 0, sizeof(struct soap_dom_element)); - next->nstr = nstr; - next->prnt = dom; - next->name = strdup("Error"); - if (!next->name) { + dom->prnt = res; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (jd->CPUArchitecture) { + dom = jsdl_generateCPUArchitecture(s, jd->CPUArchitecture); + if (dom == NULL) { return NULL; } - next->data = strdup(job->error); - if (!next->data) { + dom->prnt = res; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (jd->IndividualCPUSpeed) { + dom = jsdl_generateRangeValue(s, jd->IndividualCPUSpeed, "IndividualCPUSpeed"); + if (dom == NULL) { return NULL; } - cur->next = next; - cur = next; + dom->prnt = res; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; } - if (job->wd) { - next = (struct soap_dom_element*)soap_malloc(s, - sizeof(struct soap_dom_element)); - if (next == NULL) { + if (jd->IndividualCPUTime) { + dom = jsdl_generateRangeValue(s, jd->IndividualCPUTime, "IndividualCPUTime"); + if (dom == NULL) { return NULL; } - memset(next, 0, sizeof(struct soap_dom_element)); - next->nstr = nstr; - next->prnt = dom; - next->name = strdup("WorkingDirectory"); - if (!next->name) { + dom->prnt = res; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (jd->IndividualCPUCount) { + dom = jsdl_generateRangeValue(s, jd->IndividualCPUCount, "IndividualCPUCount"); + if (dom == NULL) { return NULL; } - next->data = strdup(job->wd); - if (!next->data) { + dom->prnt = res; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (jd->IndividualNetworkBandwidth) { + dom = jsdl_generateRangeValue(s, jd->IndividualNetworkBandwidth, "IndividualNetworkBandwidth"); + if (dom == NULL) { return NULL; } - cur->next = next; - cur = next; + dom->prnt = res; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; } - if (job->username) { - next = (struct soap_dom_element*)soap_malloc(s, - sizeof(struct soap_dom_element)); - if (next == NULL) { + if (jd->IndividualPhysicalMemory) { + dom = jsdl_generateRangeValue(s, jd->IndividualPhysicalMemory, "IndividualPhysicalMemory"); + if (dom == NULL) { return NULL; } - memset(next, 0, sizeof(struct soap_dom_element)); - next->nstr = nstr; - next->prnt = dom; - next->name = strdup("UserName"); - if (!next->name) { + dom->prnt = res; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (jd->IndividualVirtualMemory) { + dom = jsdl_generateRangeValue(s, jd->IndividualVirtualMemory, "IndividualVirtualMemory"); + if (dom == NULL) { return NULL; } - next->data = strdup(job->username); - if (!next->data) { + dom->prnt = res; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (jd->IndividualDiskSpace) { + dom = jsdl_generateRangeValue(s, jd->IndividualDiskSpace, "IndividualDiskSpace"); + if (dom == NULL) { return NULL; } - cur->next = next; - cur = next; + dom->prnt = res; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; } - return dom; + if (jd->TotalCPUTime) { + dom = jsdl_generateRangeValue(s, jd->TotalCPUTime, "TotalCPUTime"); + if (dom == NULL) { + return NULL; + } + dom->prnt = res; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (jd->TotalCPUCount) { + dom = jsdl_generateRangeValue(s, jd->TotalCPUCount, "TotalCPUCount"); + if (dom == NULL) { + return NULL; + } + dom->prnt = res; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (jd->TotalPhysicalMemory) { + dom = jsdl_generateRangeValue(s, jd->TotalPhysicalMemory, "TotalPhysicalMemory"); + if (dom == NULL) { + return NULL; + } + dom->prnt = res; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (jd->TotalVirtualMemory) { + dom = jsdl_generateRangeValue(s, jd->TotalVirtualMemory, "TotalVirtualMemory"); + if (dom == NULL) { + return NULL; + } + dom->prnt = res; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (jd->TotalDiskSpace) { + dom = jsdl_generateRangeValue(s, jd->TotalDiskSpace, "TotalDiskSpace"); + if (dom == NULL) { + return NULL; + } + dom->prnt = res; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (jd->TotalResourceCount) { + dom = jsdl_generateRangeValue(s, jd->TotalResourceCount, "TotalResourceCount"); + if (dom == NULL) { + return NULL; + } + dom->prnt = res; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (first == NULL) { + return NULL; + } + res->elts = first; + + return res; } -#endif + +struct soap_dom_element * +jsdl_generateHPCPCredential(struct soap *s, struct hpcp_credential *cred) +{ + struct soap_dom_element *new_cred, *token, *user, *pass; + + if (cred == NULL || cred->username == NULL) { + return NULL; + } + + new_cred = jsdl_generateDomElement(s, HPCP_AC_NS, "Credential"); + token = jsdl_generateDomElement(s, WSSE_NS, "UsernameToken"); + user = jsdl_generateDomElement(s, WSSE_NS, "Username"); + if (new_cred == NULL || token == NULL || user == NULL) { + return NULL; + } + + user->data = soap_strdup(s, cred->username); + if (user->data == NULL) { + return NULL; + } + + new_cred->elts = token; + token->prnt = new_cred; + token->elts = user; + user->prnt = token; + + if (cred->password) { + pass = jsdl_generateDomElement(s, WSSE_NS, "Password"); + if (pass == NULL) { + return NULL; + } + pass->data = soap_strdup(s, cred->password); + if (pass->data == NULL) { + return NULL; + } + pass->prnt = token; + user->next = pass; + } + + return new_cred; +} + +struct soap_dom_element * +jsdl_generateDataStaging(struct soap *s, struct jsdl_data_staging *ds) +{ + struct soap_dom_element *data, *first, *cur, *dom; + + if (ds == NULL) { + return NULL; + } + + data = jsdl_generateDomElement(s, JSDL_NS, "DataStaging"); + if (data == NULL) { + return NULL; + } + + if (ds->name) { + data->atts = jsdl_generateDomAttribute(s, "name"); + if (data->atts == NULL) { + return NULL; + } + data->atts->data = soap_strdup(s, ds->name); + if (data->atts->data == NULL) { + return NULL; + } + } + + cur = first = NULL; + + if (ds->FileName) { + dom = jsdl_generateDomElement(s, JSDL_NS, "FileName"); + if (dom == NULL) { + return NULL; + } + dom->data = soap_strdup(s, ds->FileName); + if (dom->data == NULL) { + return NULL; + } + dom->prnt = data; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (ds->FileSystemName) { + dom = jsdl_generateDomElement(s, JSDL_NS, "FileSystemName"); + if (dom == NULL) { + return NULL; + } + dom->data = soap_strdup(s, ds->FileSystemName); + if (dom->data == NULL) { + return NULL; + } + dom->prnt = data; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (ds->CreationFlag) { + dom = jsdl_generateDomElement(s, JSDL_NS, "CreationFlag"); + if (dom == NULL) { + return NULL; + } + dom->prnt = data; + switch (ds->CreationFlag) { + case jsdl_overwrite: + dom->data = "overwrite"; + break; + case jsdl_dontOverwrite: + dom->data = "dontOverwrite"; + break; + case jsdl_append: + dom->data = "append"; + break; + default: + return NULL; + } + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (ds->DeleteOnTermination) { + dom = jsdl_generateDomElement(s, JSDL_NS, "DeleteOnTermination"); + if (dom == NULL) { + return NULL; + } + dom->data = soap_strdup(s, "true"); + if (dom->data == NULL) { + return NULL; + } + dom->prnt = data; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (ds->SourceURI) { + dom = jsdl_generateDomElement(s, JSDL_NS, "SourceURI"); + if (dom == NULL) { + return NULL; + } + dom->data = soap_strdup(s, ds->SourceURI); + if (dom->data == NULL) { + return NULL; + } + dom->prnt = data; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (ds->TargetURI) { + dom = jsdl_generateDomElement(s, JSDL_NS, "TargetURI"); + if (dom == NULL) { + return NULL; + } + dom->data = soap_strdup(s, ds->TargetURI); + if (dom->data == NULL) { + return NULL; + } + dom->prnt = data; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (ds->Credential) { + dom = jsdl_generateHPCPCredential(s, ds->Credential); + if (dom == NULL) { + return NULL; + } + dom->prnt = data; + if (!first) { + first = dom; + } + else { + cur->next = dom; + } + cur = dom; + } + + if (first == NULL) { + return NULL; + } + + data->elts = first; + + return data; +} + +int +jsdl_generateJobDefinitionDOM(struct jsdl_job_definition *jd, struct soap_dom_element **jsdl_dom) +{ + struct soap_dom_element *job_def, *job_desc; + struct soap_dom_element *id, *app, *res, *data; + struct soap_dom_element *first, *cur; + struct jsdl_data_staging *ds; + struct soap *s; + + if (jd == NULL || jsdl_dom == NULL) { + return BESE_BAD_ARG; + } + + s = soap_new1(SOAP_DOM_TREE|SOAP_C_UTFSTRING); + if (s == NULL) { + return BESE_MEM_ALLOC; + } + + job_def = jsdl_generateDomElement(s, JSDL_NS, "JobDefinition"); + if (job_def == NULL) { + return BESE_MEM_ALLOC; + } + + job_desc = jsdl_generateDomElement(s, JSDL_NS, "JobDescription"); + if (job_desc == NULL) { + return BESE_MEM_ALLOC; + } + job_desc->prnt = job_def; + + cur = first = NULL; + + id = jsdl_generateJobIdentification(s, jd); + if (id) { + id->prnt = job_desc; + first = id; + cur = id; + } + + app = jsdl_generateApplication(s, jd); + if (app) { + app->prnt = job_desc; + if (!first) { + first = app; + } + else { + cur->next = app; + } + cur = app; + } + + res = jsdl_generateResources(s, jd); + if (res) { + app->prnt = job_desc; + if (!first) { + first = res; + } + else { + cur->next = res; + } + cur = res; + } + + ds = jd->DataStaging; + while (ds) { + data = jsdl_generateDataStaging(s, ds); + if (data) { + data->prnt = job_desc; + if (!first) { + first = data; + } + else { + cur->next = data; + } + cur = data; + } + ds = ds->next; + } + + job_desc->elts = first; + job_def->elts = job_desc; + + *jsdl_dom = job_def; + + return BESE_OK; +} + +void +jsdl_freeJobDefinitionDOM(struct soap_dom_element *dom) +{ + struct soap *s; + + if (dom == NULL) { + return; + } + s = dom->soap; + soap_end(s); + soap_free(s); +} Modified: trunk/besclient/jsdl.h =================================================================== --- trunk/besclient/jsdl.h 2008-10-21 03:14:56 UTC (rev 57) +++ trunk/besclient/jsdl.h 2008-10-28 22:34:49 UTC (rev 58) @@ -26,8 +26,8 @@ #include "soapStub.h" enum jsdl_application_type { - JSDL_POSIX_APPLICATION = 0, - JSDL_HPC_PROFILE_APPLICATION = 1, + JSDL_POSIX_APPLICATION = 1, + JSDL_HPC_PROFILE_APPLICATION = 2, }; struct jsdl_envvar { @@ -74,6 +74,11 @@ char *GroupName; }; +struct jsdl_bound { + double value; + int exclusive; +}; + struct jsdl_exact { struct jsdl_exact *next; double value; @@ -82,22 +87,19 @@ struct jsdl_range { struct jsdl_range *next; - double LowerBound; - int lowerExclusive; - double UpperBound; - int upperExclusive; + struct jsdl_bound *LowerBound; + struct jsdl_bound *UpperBound; }; struct jsdl_range_value { - double UpperBoundedRange; - int exclusiveUpperBound; - double LowerBoundedRange; - int exclusiveLowerBound; + struct jsdl_bound *UpperBoundedRange; + struct jsdl_bound *LowerBoundedRange; struct jsdl_exact *Exact; struct jsdl_range *Range; }; enum jsdl_file_system_types { + jsdl_nofstype = 0, jsdl_swap, jsdl_temporary, jsdl_spool, @@ -109,7 +111,7 @@ char *name; enum jsdl_file_system_types type; char *MountPoint; - struct jsdl_range_value DiskSpace; + struct jsdl_range_value *DiskSpace; }; struct jsdl_operating_system { @@ -124,6 +126,7 @@ }; enum jsdl_creation_flags { + jsdl_nocreationflag = 0, jsdl_overwrite, jsdl_dontOverwrite, jsdl_append, @@ -187,5 +190,7 @@ int jsdl_processJobDefinition(struct soap_dom_element*, struct jsdl_job_definition*); void jsdl_freeJobDefinition(struct jsdl_job_definition *); +int jsdl_generateJobDefinitionDOM(struct jsdl_job_definition *, struct soap_dom_element **); +void jsdl_freeJobDefinitionDOM(struct soap_dom_element *); #endif /* _JSDL_H */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-10-21 03:15:05
|
Revision: 57 http://bespp.svn.sourceforge.net/bespp/?rev=57&view=rev Author: csmith Date: 2008-10-21 03:14:56 +0000 (Tue, 21 Oct 2008) Log Message: ----------- - added some utility routines for parsing JSDL docs and EPRs from strings Modified Paths: -------------- trunk/besclient/bes.c trunk/besclient/bes.h Modified: trunk/besclient/bes.c =================================================================== --- trunk/besclient/bes.c 2008-10-21 02:54:10 UTC (rev 56) +++ trunk/besclient/bes.c 2008-10-21 03:14:56 UTC (rev 57) @@ -340,6 +340,107 @@ } int +bes_createActivityFromString(struct bes_context *context, + epr_t endpointepr, + char *jsdl, + epr_t *activityepr) +{ + struct soap *s; + struct bes__CreateActivityType req; + struct bes__CreateActivityResponseType rsp; + struct soap_dom_element dom, *tmpdom; + struct soap_dom_attribute *attr; + struct bes_epr *epr; + int jsdl_fd, size = 0, ret = BESE_OK; + char *endpoint, filename[] = "/tmp/XXXXXX"; + + if (context == NULL + || endpointepr == NULL + || jsdl == NULL + || activityepr == NULL) { + return BESE_BAD_ARG; + } + + if ((jsdl_fd = mkstemp(filename)) < 0) { + setErrorString(context, NULL, BESE_SYS_ERR); + return BESE_SYS_ERR; + } + unlink(filename); + + if (write(jsdl_fd, jsdl, strlen(jsdl)) < 0) { + close(jsdl_fd); + setErrorString(context, NULL, BESE_SYS_ERR); + return BESE_SYS_ERR; + } + + if (lseek(jsdl_fd, 0, SEEK_SET) == -1) { + close(jsdl_fd); + setErrorString(context, NULL, BESE_SYS_ERR); + return BESE_SYS_ERR; + } + + s = context->soap; + + if (ret = generateAddressingHeaders(context, endpointepr, CREATE_ACT, &endpoint)) { + return ret; + } + + memset(&dom, 0, sizeof(struct soap_dom_element)); + dom.soap = soap_new1(SOAP_DOM_TREE|SOAP_C_UTFSTRING); + dom.soap->recvfd = jsdl_fd; + if (soap_begin_recv(dom.soap) + || soap_in_xsd__anyType(dom.soap, NULL, &dom, NULL) == NULL + || soap_end_recv(dom.soap)) { + setErrorString(context, dom.soap, BESE_SOAP_ERR); + close(jsdl_fd); + ret = BESE_SOAP_ERR; + goto end; + } + close(jsdl_fd); + + memset(&req, 0, sizeof(struct bes__CreateActivityType)); + memset(&rsp, 0, sizeof(struct bes__CreateActivityResponseType)); + + req.bes__ActivityDocument.__any = &dom; + + if (soap_call___bes__CreateActivity(s, endpoint, CREATE_ACT, &req, &rsp) != SOAP_OK) { + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; + goto end; + } + else { + tmpdom = rsp.__any; + + cleanDom(tmpdom); + + epr = (struct bes_epr *)malloc(sizeof(struct bes_epr)); + if (!epr) { + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; + goto end; + } + memset(epr, 0, sizeof(struct bes_epr)); + + epr->str = generateEPRString(tmpdom, NULL); + if (!epr->str) { + free(epr); + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; + goto end; + } + epr->dom = tmpdom; + *activityepr = (epr_t)epr; + } + + end: + soap_end(dom.soap); + soap_done(dom.soap); + free(dom.soap); + + return ret; +} + +int bes_terminateActivities(struct bes_context *context, epr_t endpointepr, epr_t activityepr) @@ -708,6 +809,19 @@ return ret; } +void +bes_freeActivityStatus(struct bes_activity_status *status) +{ + if (!status) { + return; + } + + if (status->substate) { + free(status->substate); + status->substate = NULL; + } +} + void bes_freeEPR(epr_t *epr) { @@ -849,6 +963,111 @@ return ret; } +int +bes_readEPRFromString(struct bes_context *context, char *str, epr_t *epr) +{ + int fd, size = 0, ret = BESE_OK; + struct soap_dom_element *dom; + struct bes_epr *tmpEPR; + struct stat fileStat; + char filename[] = "/tmp/XXXXXX"; + + if (context == NULL || epr == NULL || str == NULL) { + return BESE_BAD_ARG; + } + + fd = mkstemp(filename); + if (fd == -1) { + setErrorString(context, NULL, BESE_SYS_ERR); + return BESE_SYS_ERR; + } + unlink(filename); + + if (write(fd, str, strlen(str)) < 0) { + close(fd); + setErrorString(context, NULL, BESE_SYS_ERR); + return BESE_SYS_ERR; + } + + if (lseek(fd, 0, SEEK_SET) == -1) { + close(fd); + setErrorString(context, NULL, BESE_SYS_ERR); + return BESE_SYS_ERR; + } + + dom = (struct soap_dom_element *)soap_malloc(context->soap, sizeof(struct soap_dom_element)); + if (!dom) { + close(fd); + setErrorString(context, NULL, BESE_MEM_ALLOC); + return BESE_MEM_ALLOC; + } + + dom->soap = soap_new1(SOAP_DOM_TREE|SOAP_C_UTFSTRING); + dom->soap->recvfd = fd; + if (soap_begin_recv(dom->soap) + || soap_in_xsd__anyType(dom->soap, NULL, dom, NULL) == NULL + || soap_end_recv(dom->soap)) { + setErrorString(context, dom->soap, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; + goto error_end; + } + + tmpEPR = (struct bes_epr *)malloc(sizeof(struct bes_epr)); + if (!tmpEPR) { + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; + goto error_end; + } + memset(tmpEPR, 0, sizeof(struct bes_epr)); + + if (lseek(fd, 0, SEEK_SET) == -1) { + free(tmpEPR); + setErrorString(context, NULL, BESE_SYS_ERR); + ret = BESE_SYS_ERR; + goto error_end; + } + + if (fstat(fd, &fileStat)) { + free(tmpEPR); + setErrorString(context, NULL, BESE_SYS_ERR); + ret = BESE_SYS_ERR; + goto error_end; + } + + size = fileStat.st_size; + tmpEPR->str = (char *)malloc(size + 1); + if (!tmpEPR->str) { + free(tmpEPR); + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; + goto error_end; + } + memset(tmpEPR->str, 0, size + 1); + + if (read(fd, tmpEPR->str, size) == -1) { + free(tmpEPR); + setErrorString(context, NULL, BESE_SYS_ERR); + ret = BESE_SYS_ERR; + goto error_end; + } + + close(fd); + + tmpEPR->dom = dom; + tmpEPR->domCreateFlag = FromMalloc; + *epr = (epr_t)tmpEPR; + + return BESE_OK; + + error_end: + close(fd); + soap_end(dom->soap); + soap_done(dom->soap); + free(dom->soap); + + return ret; +} + char * bes_getEPRString(epr_t epr) { Modified: trunk/besclient/bes.h =================================================================== --- trunk/besclient/bes.h 2008-10-21 02:54:10 UTC (rev 56) +++ trunk/besclient/bes.h 2008-10-21 03:14:56 UTC (rev 57) @@ -90,6 +90,7 @@ const char* bes_get_lasterror(struct bes_context *context); int bes_createActivity(struct bes_context *, epr_t, char *, epr_t *); +int bes_createActivityFromString(struct bes_context *, epr_t, char *, epr_t *); int bes_terminateActivities(struct bes_context *, epr_t, epr_t); int bes_getActivityStatuses(struct bes_context *, epr_t, epr_t, struct bes_activity_status *); int bes_getActivityDocumentsXML(struct bes_context *, epr_t, epr_t, char **); @@ -98,7 +99,9 @@ void bes_freeEPR(epr_t *epr); int bes_writeEPRToFile(struct bes_context *, char *, epr_t); int bes_readEPRFromFile(struct bes_context *, char *, epr_t *); +int bes_readEPRFromString(struct bes_context *, char *, epr_t *); char *bes_getEPRString(epr_t); +void bes_freeActivityStatus(struct bes_activity_status *); #endif /* _BES_H */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-10-21 02:54:19
|
Revision: 56 http://bespp.svn.sourceforge.net/bespp/?rev=56&view=rev Author: csmith Date: 2008-10-21 02:54:10 +0000 (Tue, 21 Oct 2008) Log Message: ----------- - remove dead code Modified Paths: -------------- trunk/besserver/job.c Modified: trunk/besserver/job.c =================================================================== --- trunk/besserver/job.c 2008-10-21 02:53:40 UTC (rev 55) +++ trunk/besserver/job.c 2008-10-21 02:54:10 UTC (rev 56) @@ -29,22 +29,6 @@ #include "job.h" int -processElement(struct soap *s, struct soap_dom_element *dom, - struct jobcard *jc) -{ - struct soap_dom_element *iter; - - for (iter = dom; iter; iter = iter->next) { - printf("**%s\n", iter->name); - if (iter->elts) { - processElement(s, iter->elts, jc); - } - } - - return SOAP_OK; -} - -int addArg(struct soap *s, struct jobcard *jc, char *arg) { char *cp, **cpp; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-10-21 02:53:55
|
Revision: 55 http://bespp.svn.sourceforge.net/bespp/?rev=55&view=rev Author: csmith Date: 2008-10-21 02:53:40 +0000 (Tue, 21 Oct 2008) Log Message: ----------- - added some new C structs to represent JSDL documents - added new API to get activity documents parsed into new structs Modified Paths: -------------- trunk/besclient/Makefile trunk/besclient/bes.h trunk/besclient/besclient.c Added Paths: ----------- trunk/besclient/bes.c trunk/besclient/jsdl.c trunk/besclient/jsdl.h trunk/besclient/namespaces.h Removed Paths: ------------- trunk/besclient/libbes.c Modified: trunk/besclient/Makefile =================================================================== --- trunk/besclient/Makefile 2008-09-23 01:13:18 UTC (rev 54) +++ trunk/besclient/Makefile 2008-10-21 02:53:40 UTC (rev 55) @@ -31,11 +31,12 @@ besclient: besclient.o libbes.a $(CC) $(LDFLAGS) -o besclient besclient.o $(LIBS) -libbes.a: libbes.o $(CLIENT_OBJ) - ar -rsv libbes.a libbes.o $(CLIENT_OBJ) +libbes.a: bes.o jsdl.o $(CLIENT_OBJ) + ar -rsv libbes.a bes.o jsdl.o $(CLIENT_OBJ) besclient.o: besclient.c bes.h -libbes.o: libbes.c bes.h $(SOAP_NS) +bes.o: bes.c bes.h jsdl.h $(SOAP_NS) +jsdl.o: jsdl.c jsdl.h $(SOAP_NS) soapServer.o: soapServer.c soapClient.o: soapClient.c soapC.o: soapC.c Added: trunk/besclient/bes.c =================================================================== --- trunk/besclient/bes.c (rev 0) +++ trunk/besclient/bes.c 2008-10-21 02:53:40 UTC (rev 55) @@ -0,0 +1,1334 @@ +/* ---------------------------------------------------------------- + * bes.c + * + * Client library of the OGSA Basic Execution Services + * + * Copyright (C) 2006-2008, Platform Computing Corporation. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ +#include "../config.h" + +#include <stdio.h> +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> + +#include "bes.h" +#include "jsdl.h" +#include "namespaces.h" +#include "wsseapi.h" +#include "BESFactoryBinding.nsmap" + +#define CREATE_ACT "http://schemas.ggf.org/bes/2006/08/bes-factory/BESFactoryPortType/CreateActivity" +#define STATUS_ACT "http://schemas.ggf.org/bes/2006/08/bes-factory/BESFactoryPortType/GetActivityStatuses" +#define TERMINATE_ACT "http://schemas.ggf.org/bes/2006/08/bes-factory/BESFactoryPortType/TerminateActivities" +#define ACTIVITIES_ACT "http://schemas.ggf.org/bes/2006/08/bes-factory/BESFactoryPortType/GetActivityDocuments" +#define FACTORY_ACT "http://schemas.ggf.org/bes/2006/08/bes-factory/BESFactoryPortType/GetFactoryAttributesDocument" + +#define NL "\n" + +struct Namespace default_namespaces[] = +{ + {"SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org/*/soap-envelope", NULL}, + {"wsu", WSU_NS, NULL, NULL}, + {"wsse", WSSE_NS, NULL, NULL}, + {"wsa", WSA_NS, NULL, NULL}, + {"bes", BES_NS, NULL, NULL}, + {"jsdl", JSDL_NS, NULL, NULL}, + {"app", JSDL_HPCPA_NS, NULL, NULL}, + {NULL, NULL, NULL, NULL} +}; + +struct Namespace epr_namespaces[] = { + {"wsa", WSA_NS, NULL, NULL }, + {"bes", BES_NS, NULL, NULL }, + {"xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance", NULL}, + {NULL, NULL, NULL, NULL} +}; + +struct bes_epr { + char *str; + struct soap_dom_element *dom; + int domCreateFlag; +}; + +#define FromMalloc 1 + +int isElement(struct soap_dom_element *, char *, char *); +int isAttribute(struct soap_dom_attribute *, char *, char *); +int generateAddressingHeaders(struct bes_context *, epr_t, char *, char **); +void printDom(struct soap_dom_element*, char *, int); +void cleanDom(struct soap_dom_element*); +void setErrorString(struct bes_context *, struct soap *, int); +char *generateEPRString(struct soap_dom_element *, char *); +int calcDomSize(struct soap_dom_element *, char *); +void sprintDom(struct soap_dom_element *, char *, char *); +int getActivityDocumentsDOM(struct bes_context *, epr_t, epr_t, struct soap_dom_element **); +int getActivityDocumentFromDOM(struct bes_context *, struct soap_dom_element *, struct bes_activity_document **); +int getJSDLFromDOM(struct bes_context *, struct soap_dom_element *, struct jsdl_job_definition **); + +int +bes_init(struct bes_context **context) +{ + struct bes_context *ctx; + struct soap *soap; + + if (context == NULL) { + return BESE_BAD_ARG; + } + + *context = NULL; + + ctx = (struct bes_context *)malloc(sizeof(struct bes_context)); + if (ctx == NULL) { + return BESE_SYS_ERR; + } + + soap = (struct soap *)malloc(sizeof(struct soap)); + if (soap == NULL) { + free(ctx); + return BESE_SYS_ERR; + } + + memset(ctx, 0, sizeof(struct bes_context)); + + soap_ssl_init(); + soap_init(soap); + soap_set_mode(soap, SOAP_C_UTFSTRING); + soap_register_plugin(soap, soap_wsse); + soap_set_namespaces(soap, default_namespaces); + soap_header(soap); + + ctx->soap = soap; + *context = ctx; + + return BESE_OK; +} + +int +bes_security(struct bes_context *context, + char *x509cert, + char *x509pass, + char *capath, + char *user, + char *pass) +{ + struct soap *soap; + + if (context == NULL) { + return BESE_BAD_ARG; + } + + soap = context->soap; + + if (soap_ssl_client_context(soap, SOAP_SSL_DEFAULT|SOAP_SSL_SKIP_HOST_CHECK, + x509cert, x509pass, NULL, capath, NULL)) { + setErrorString(context, context->soap, BESE_SOAP_ERR); + return BESE_SOAP_ERR; + } + + if (user) { + if (soap_wsse_add_UsernameTokenText(soap, NULL, user, pass)) { + setErrorString(context, context->soap, BESE_SOAP_ERR); + return BESE_SOAP_ERR; + } + if (soap_wsse_add_Timestamp(soap, NULL, 60)) { + setErrorString(context, context->soap, BESE_SOAP_ERR); + return BESE_SOAP_ERR; + } + } + + if (x509cert) { + if (context->x509cert) free(context->x509cert); + context->x509cert = strdup(x509cert); + } + + if (x509pass) { + if (context->x509pass) free(context->x509pass); + context->x509pass = strdup(x509pass); + } + + if (capath) { + if (context->capath) free(context->capath); + context->capath = strdup(capath); + } + + if (user) { + if (context->user) free(context->user); + context->user = strdup(user); + } + + if (pass) { + if (context->pass) free(context->pass); + context->pass = strdup(pass); + } + + return BESE_OK; +} + +int +bes_add_usertoken(struct bes_context *context, + char *user, + char *pass) +{ + if (context == NULL) { + return BESE_BAD_ARG; + } + + if (soap_wsse_add_UsernameTokenText(context->soap, NULL, user, pass)) { + setErrorString(context, context->soap, BESE_SOAP_ERR); + return BESE_SOAP_ERR; + } + if (soap_wsse_add_Timestamp(context->soap, NULL, 60)) { + setErrorString(context, context->soap, BESE_SOAP_ERR); + return BESE_SOAP_ERR; + } + + return BESE_OK; +} + +int +bes_finalize(struct bes_context **context) +{ + struct bes_context *ctx; + + if (context == NULL || *context == NULL) { + return BESE_BAD_ARG; + } + + ctx = *context; + + soap_end(ctx->soap); + soap_done(ctx->soap); + + free(ctx->soap); + + if (ctx->x509cert) { + free(ctx->x509cert); + } + + if (ctx->x509pass) { + free(ctx->x509pass); + } + + if (ctx->capath) { + free(ctx->capath); + } + + if (ctx->user) { + free(ctx->user); + } + + free(ctx); + *context = NULL; + + return BESE_OK; +} + +const char* +bes_get_lasterror(struct bes_context *context) +{ + if (context) { + return context->error_string; + } + return "No valid BES Context."; +} + +int +bes_createActivity(struct bes_context *context, + epr_t endpointepr, + char *jsdlfile, + epr_t *activityepr) +{ + struct soap *s; + struct bes__CreateActivityType req; + struct bes__CreateActivityResponseType rsp; + struct soap_dom_element dom, *tmpdom; + struct soap_dom_attribute *attr; + struct bes_epr *epr; + int jsdl, size = 0, ret = BESE_OK; + char *endpoint; + + if (context == NULL + || endpointepr == NULL + || jsdlfile == NULL + || activityepr == NULL) { + return BESE_BAD_ARG; + } + + s = context->soap; + + if (ret = generateAddressingHeaders(context, endpointepr, CREATE_ACT, &endpoint)) { + return ret; + } + + jsdl = open(jsdlfile, O_RDONLY, 0); + if (jsdl == -1) { + setErrorString(context, NULL, BESE_SYS_ERR); + return BESE_SYS_ERR; + } + + memset(&dom, 0, sizeof(struct soap_dom_element)); + dom.soap = soap_new1(SOAP_DOM_TREE|SOAP_C_UTFSTRING); + dom.soap->recvfd = jsdl; + if (soap_begin_recv(dom.soap) + || soap_in_xsd__anyType(dom.soap, NULL, &dom, NULL) == NULL + || soap_end_recv(dom.soap)) { + setErrorString(context, dom.soap, BESE_SOAP_ERR); + close(jsdl); + ret = BESE_SOAP_ERR; + goto end; + } + close(jsdl); + + memset(&req, 0, sizeof(struct bes__CreateActivityType)); + memset(&rsp, 0, sizeof(struct bes__CreateActivityResponseType)); + + req.bes__ActivityDocument.__any = &dom; + + if (soap_call___bes__CreateActivity(s, endpoint, CREATE_ACT, &req, &rsp) != SOAP_OK) { + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; + goto end; + } + else { + tmpdom = rsp.__any; + + cleanDom(tmpdom); + + epr = (struct bes_epr *)malloc(sizeof(struct bes_epr)); + if (!epr) { + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; + goto end; + } + memset(epr, 0, sizeof(struct bes_epr)); + + epr->str = generateEPRString(tmpdom, NULL); + if (!epr->str) { + free(epr); + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; + goto end; + } + epr->dom = tmpdom; + *activityepr = (epr_t)epr; + } + + end: + soap_end(dom.soap); + soap_done(dom.soap); + free(dom.soap); + + return ret; +} + +int +bes_terminateActivities(struct bes_context *context, + epr_t endpointepr, + epr_t activityepr) +{ + struct soap *s; + struct bes__TerminateActivitiesType req; + struct bes__TerminateActivitiesResponseType rsp; + struct bes_epr *epr; + int i, ret = BESE_OK; + char *endpoint; + + if (context == NULL || activityepr == NULL || endpointepr == NULL) { + return BESE_BAD_ARG; + } + + s = context->soap; + epr = (struct bes_epr *)activityepr; + + if (ret = generateAddressingHeaders(context, endpointepr, TERMINATE_ACT, &endpoint)) { + return BES_FALSE; + } + + memset(&req, 0, sizeof(struct bes__TerminateActivitiesType)); + memset(&rsp, 0, sizeof(struct bes__TerminateActivitiesResponseType)); + + req.__any = epr->dom; + if (soap_call___bes__TerminateActivities(s, endpoint, TERMINATE_ACT, req, &rsp) != SOAP_OK) { + setErrorString(context, s, BESE_SOAP_ERR); + ret = BES_FALSE; + } + else { + for (i = 0; i < rsp.__sizeResponse; i++) { + if (rsp.Response[i].Cancelled == true_) { + ret = BES_TRUE; + } + else { + ret = BES_FALSE; + } + } + } + + return ret; +} + +int +bes_getActivityStatuses(struct bes_context *context, + epr_t endpointepr, + epr_t activityepr, + struct bes_activity_status *status) +{ + struct soap *s; + struct bes__GetActivityStatusesType req; + struct bes__GetActivityStatusesResponseType rsp; + struct bes_epr *epr; + int ret = BESE_OK; + char *endpoint; + + if (context == NULL + || activityepr == NULL + || status == NULL + || endpointepr == NULL) { + return BESE_BAD_ARG; + } + + s = context->soap; + epr = (struct bes_epr *)activityepr; + + memset(status, 0, sizeof(struct bes_activity_status)); + + if (ret = generateAddressingHeaders(context, endpointepr, STATUS_ACT, &endpoint)) { + return ret; + } + + memset(&req, 0, sizeof(struct bes__GetActivityStatusesType)); + memset(&rsp, 0, sizeof(struct bes__GetActivityStatusesResponseType)); + + req.__any = epr->dom; + if (soap_call___bes__GetActivityStatuses(s, endpoint, STATUS_ACT, req, &rsp) != SOAP_OK) { + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; + goto end; + } + else { + if ((rsp.__any!=NULL)&&(!strcmp(rsp.__any->name,"Response"))) { + struct soap_dom_element *element = rsp.__any->elts; + int size; + + while (element != NULL) { + if (!strcmp(element->name,"ActivityStatus")) { + if(element->atts!=NULL) { + struct soap_dom_attribute *attributes=element->atts; + + while (attributes != NULL) { + if((attributes->name!=NULL)&&(!strcmp(attributes->name,"state"))) { + if((attributes->data!=NULL)&&(!strcmp(attributes->data,"Pending"))) { + status->state = BES_Pending; + } + else if((attributes->data!=NULL)&&(!strcmp(attributes->data,"Running"))) { + status->state = BES_Running; + } + else if((attributes->data!=NULL)&&(!strcmp(attributes->data,"Cancelled"))) { + status->state = BES_Cancelled; + } + else if((attributes->data!=NULL)&&(!strcmp(attributes->data,"Failed"))) { + status->state = BES_Failed; + } + else if((attributes->data!=NULL)&&(!strcmp(attributes->data,"Finished"))) { + status->state = BES_Finished; + } + break; + } + attributes=attributes->next; + } + + if (element->elts) { + size = calcDomSize(element->elts, NULL); + + status->substate = (char *)malloc(size + 1); + if (!status->substate) { + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; + goto end; + } + + memset(status->substate, 0, size + 1); + sprintDom(element->elts, status->substate, NULL); + } + } + + break; + } + else if(!strcmp(element->name,"Fault")) { + setErrorString(context, NULL, BESE_GETSTATUS_ERR); + ret = BESE_GETSTATUS_ERR; + goto end; + } + else { + element=element->next; + } + } + } + } + + end: + return ret; +} + +int +getActivityDocumentsDOM(struct bes_context *context, + epr_t endpointepr, + epr_t activityepr, + struct soap_dom_element **dom) +{ + struct soap *s; + struct bes__GetActivityDocumentsType req; + struct bes__GetActivityDocumentsResponseType rsp; + struct bes_epr *epr; + int size = 0, ret = BESE_OK; + char *endpoint, *str; + + if (context == NULL + || endpointepr == NULL + || activityepr == NULL + || dom == NULL) { + return BESE_BAD_ARG; + } + + s = context->soap; + epr = (struct bes_epr *)activityepr; + + if (ret = generateAddressingHeaders(context, endpointepr, ACTIVITIES_ACT, &endpoint)) { + return ret; + } + + memset(&req, 0, sizeof(struct bes__GetActivityDocumentsType)); + memset(&rsp, 0, sizeof(struct bes__GetActivityDocumentsResponseType)); + + req.__any = epr->dom; + if (soap_call___bes__GetActivityDocuments(s, endpoint, ACTIVITIES_ACT, req, &rsp) != SOAP_OK) { + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; + goto end; + } + + *dom = rsp.__any; + + end: + return ret; +} + +int +bes_getActivityDocumentsXML(struct bes_context *context, + epr_t endpointepr, + epr_t activityepr, + char **strDoc) +{ + struct soap_dom_element *dom; + int size = 0, ret = BESE_OK; + char *str; + + if (strDoc == NULL) { + setErrorString(context, NULL, BESE_BAD_ARG); + return BESE_BAD_ARG; + } + + ret = getActivityDocumentsDOM(context, endpointepr, activityepr, &dom); + if (ret != BESE_OK) { + return ret; + } + + size = calcDomSize(dom, NULL); + + str = (char *)malloc(size + 1); + if (!str) { + setErrorString(context, NULL, BESE_MEM_ALLOC); + return BESE_MEM_ALLOC; + } + memset(str, 0, size + 1); + + sprintDom(dom, str, NULL); + + *strDoc = str; + + return BESE_OK; +} + +int +bes_getActivityDocuments(struct bes_context *context, + epr_t endpointepr, + epr_t activityepr, + struct bes_activity_document **activity) +{ + struct soap_dom_element *dom, *epr_dom, *jsdl_dom; + struct bes_activity_document *doc; + struct bes_epr *epr; + int size = 0, ret = BESE_OK; + char *str; + + if (activity == NULL) { + setErrorString(context, NULL, BESE_BAD_ARG); + return BESE_BAD_ARG; + } + + ret = getActivityDocumentsDOM(context, endpointepr, activityepr, &dom); + if (ret != BESE_OK) { + return ret; + } + cleanDom(dom); + + doc = (struct bes_activity_document*)malloc(sizeof(struct bes_activity_document)); + if (doc == NULL) { + setErrorString(context, NULL, BESE_MEM_ALLOC); + return BESE_MEM_ALLOC; + } + memset(doc, 0, sizeof(struct bes_activity_document)); + + epr = (struct bes_epr*)malloc(sizeof(struct bes_epr)); + if (epr == NULL) { + free(doc); + setErrorString(context, NULL, BESE_MEM_ALLOC); + return BESE_MEM_ALLOC; + } + memset(epr, 0, sizeof(struct bes_epr)); + + epr_dom = dom->elts; + jsdl_dom = epr_dom->next; + epr_dom->next = NULL; + + epr->str = generateEPRString(epr_dom, NULL); + if (epr->str == NULL) { + free(epr); + free(doc); + setErrorString(context, NULL, BESE_MEM_ALLOC); + return BESE_MEM_ALLOC; + } + + doc->activityepr = (epr_t)epr; + + if (isElement(jsdl_dom, BES_NS, "JobDefinition")) { + ret = getJSDLFromDOM(context, jsdl_dom, &doc->activity); + if (ret != BESE_OK) { + return ret; + } + } + /* need to process the fault in an else clause */ + + *activity = doc; + + return BESE_OK; +} + +int +getJSDLFromDOM(struct bes_context *context, + struct soap_dom_element *dom, + struct jsdl_job_definition **jsdl) +{ + struct jsdl_job_definition *jd; + int rc; + + if (dom == NULL + || jsdl == NULL) { + setErrorString(context, NULL, BESE_BAD_ARG); + return BESE_BAD_ARG; + } + + jd = (struct jsdl_job_definition*)malloc(sizeof(struct jsdl_job_definition)); + if (jd == NULL) { + setErrorString(context, NULL, BESE_MEM_ALLOC); + return BESE_MEM_ALLOC; + } + memset(jd, 0, sizeof(struct jsdl_job_definition)); + + rc = jsdl_processJobDefinition(dom, jd); + if (rc != BESE_OK) { + jsdl_freeJobDefinition(jd); + setErrorString(context, NULL, rc); + return rc; + } + + *jsdl = jd; + + return BESE_OK; +} + +int +bes_getFactoryAttributesDocument(struct bes_context *context, + epr_t endpointepr, + char **strDoc) +{ + struct soap *s; + struct bes__GetFactoryAttributesDocumentType req; + struct bes__GetFactoryAttributesDocumentResponseType rsp; + char *endpoint, *str; + int size = 0, ret = BESE_OK; + + if (context == NULL || endpointepr == NULL || strDoc == NULL) { + return BESE_BAD_ARG; + } + + s = context->soap; + + if (ret = generateAddressingHeaders(context, endpointepr, FACTORY_ACT, &endpoint)) { + return ret; + } + + memset(&req, 0, sizeof(struct bes__GetFactoryAttributesDocumentType)); + memset(&rsp, 0, sizeof(struct bes__GetFactoryAttributesDocumentResponseType)); + + if (soap_call___bes__GetFactoryAttributesDocument(s, endpoint, FACTORY_ACT, &req, &rsp) != SOAP_OK) { + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; + } + else { + size = calcDomSize(rsp.__any, NULL); + str = (char *)malloc(size + 1); + if (!str) { + setErrorString(context, NULL, BESE_MEM_ALLOC); + return BESE_MEM_ALLOC; + } + memset(str, 0, size + 1); + + sprintDom(rsp.__any, str, NULL); + *strDoc = str; + } + + return ret; +} + +void +bes_freeEPR(epr_t *epr) +{ + struct bes_epr *tmpEPR; + + if (!epr || !(*epr)) { + return; + } + + tmpEPR = (struct bes_epr *)(*epr); + + if (tmpEPR->domCreateFlag == FromMalloc) { + soap_end(tmpEPR->dom->soap); + soap_done(tmpEPR->dom->soap); + free(tmpEPR->dom->soap); + } + + free(tmpEPR->str); + free(tmpEPR); + + *epr = NULL; +} + +int +bes_writeEPRToFile(struct bes_context *context, char *filename, epr_t epr) +{ + struct bes_epr *tmpEPR; + int fd; + + if (context == NULL || epr == NULL || filename == NULL) { + return BESE_BAD_ARG; + } + + tmpEPR = (struct bes_epr *)(epr); + + fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); + if (fd == -1) { + setErrorString(context, NULL, BESE_SYS_ERR); + return BESE_SYS_ERR; + } + + if (write(fd, tmpEPR->str, strlen(tmpEPR->str)) == -1) { + setErrorString(context, NULL, BESE_SYS_ERR); + return BESE_SYS_ERR; + } + + close(fd); + return BESE_OK; +} + +int +bes_readEPRFromFile(struct bes_context *context, char *filename, epr_t *epr) +{ + int fd, size = 0, ret = BESE_OK; + struct soap_dom_element *dom; + struct bes_epr *tmpEPR; + struct stat fileStat; + + if (context == NULL || epr == NULL || filename == NULL) { + return BESE_BAD_ARG; + } + + fd = open(filename, O_RDONLY, 0); + if (fd == -1) { + setErrorString(context, NULL, BESE_SYS_ERR); + return BESE_SYS_ERR; + } + + dom = (struct soap_dom_element *)soap_malloc(context->soap, sizeof(struct soap_dom_element)); + if (!dom) { + close(fd); + setErrorString(context, NULL, BESE_MEM_ALLOC); + return BESE_MEM_ALLOC; + } + + dom->soap = soap_new1(SOAP_DOM_TREE|SOAP_C_UTFSTRING); + dom->soap->recvfd = fd; + if (soap_begin_recv(dom->soap) + || soap_in_xsd__anyType(dom->soap, NULL, dom, NULL) == NULL + || soap_end_recv(dom->soap)) { + setErrorString(context, dom->soap, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; + goto error_end; + } + + tmpEPR = (struct bes_epr *)malloc(sizeof(struct bes_epr)); + if (!tmpEPR) { + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; + goto error_end; + } + memset(tmpEPR, 0, sizeof(struct bes_epr)); + + if (lseek(fd, 0, SEEK_SET) == -1) { + free(tmpEPR); + setErrorString(context, NULL, BESE_SYS_ERR); + ret = BESE_SYS_ERR; + goto error_end; + } + + if (fstat(fd, &fileStat)) { + free(tmpEPR); + setErrorString(context, NULL, BESE_SYS_ERR); + ret = BESE_SYS_ERR; + goto error_end; + } + + size = fileStat.st_size; + tmpEPR->str = (char *)malloc(size + 1); + if (!tmpEPR->str) { + free(tmpEPR); + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; + goto error_end; + } + memset(tmpEPR->str, 0, size + 1); + + if (read(fd, tmpEPR->str, size) == -1) { + free(tmpEPR); + setErrorString(context, NULL, BESE_SYS_ERR); + ret = BESE_SYS_ERR; + goto error_end; + } + + close(fd); + + tmpEPR->dom = dom; + tmpEPR->domCreateFlag = FromMalloc; + *epr = (epr_t)tmpEPR; + + return BESE_OK; + + error_end: + close(fd); + soap_end(dom->soap); + soap_done(dom->soap); + free(dom->soap); + + return ret; +} + +char * +bes_getEPRString(epr_t epr) +{ + if (!epr) { + return NULL; + } + return ((struct bes_epr*)epr)->str; +} + +void +printDom(struct soap_dom_element *node, + char *current_nstr, + int depth) +{ + struct soap_dom_attribute *attr; + int i; + + if (node == NULL) { + return; + } + + for (i = 0; i < depth; i++) + fprintf(stdout, " "); + fprintf(stdout, "<%s", node->name); + /* if we don't have a current namespace, or if the current */ + /* namespace is different from this node, emit an xmlns attribute */ + if (!current_nstr || strcmp(current_nstr, node->nstr)) { + fprintf(stdout, " xmlns=\"%s\"", node->nstr); + } + attr = node->atts; + while (attr) { + /* xmlns was handled earlier */ + if (strcmp(attr->name, "xmlns")) { + fprintf(stdout, " %s=\"%s\"", attr->name, attr->data); + } + attr = attr->next; + } + fprintf(stdout, ">\n"); + + if (node->data && strlen(node->data)) { + for (i = 0; i < depth; i++) + fprintf(stdout, " "); + fprintf(stdout, " %s\n", node->data); + } + + if (node->elts) + printDom(node->elts, (char*)node->nstr, depth+1); + + for (i = 0; i < depth; i++) + fprintf(stdout, " "); + fprintf(stdout, "</%s>\n", node->name); + + if (node->next) + printDom(node->next, current_nstr, depth); + +} + +int +calcDomSize(struct soap_dom_element *node, + char *current_nstr) +{ + struct soap_dom_attribute *attr; + int i, size = 0; + + if (node == NULL) { + return 0; + } + + if (node->elts) { + size += calcDomSize(node->elts, (char*)node->nstr); + } + + if (node->next) { + size += calcDomSize(node->next, current_nstr); + } + + /* element name, data and closing element) */ + size += 2*strlen(node->name) + strlen("<></>"); + if (node->data) { + size += strlen(node->data); + } + + /* if we don't have a current namespace, or if the current */ + /* namespace is different from this node, emit an xmlns attribute */ + if (!current_nstr || strcmp(current_nstr, node->nstr)) { + size += strlen(" xmlns=\"\"") + strlen(node->nstr); + } + + /* attributes */ + attr = node->atts; + while (attr) { + /* xmlns was handled earlier */ + if (strcmp(attr->name, "xmlns")) { + size += strlen("=\"\"") + strlen(attr->name) + strlen(attr->data); + } + attr = attr->next; + } + + return size; +} + +void +sprintDom(struct soap_dom_element *node, + char *str, + char *current_nstr) +{ + struct soap_dom_attribute *attr; + int i; + + if (node == NULL) { + return; + } + + sprintf(str, "%s<%s", str, node->name); + /* if we don't have a current namespace, or if the current */ + /* namespace is different from this node, emit an xmlns attribute */ + if (!current_nstr || strcmp(current_nstr, node->nstr)) { + sprintf(str, "%s xmlns=\"%s\"", str, node->nstr); + } + attr = node->atts; + while (attr) { + /* xmlns was handled earlier */ + if (strcmp(attr->name, "xmlns")) { + sprintf(str, "%s %s=\"%s\"", str, attr->name, attr->data); + } + attr = attr->next; + } + sprintf(str, "%s>", str); + + if (node->data && strlen(node->data)) { + sprintf(str, "%s%s", str, node->data); + } + + if (node->elts) + sprintDom(node->elts, str, (char*)node->nstr); + + sprintf(str, "%s</%s>", str, node->name); + + if (node->next) + sprintDom(node->next, str, current_nstr); + +} + +char * +generateEPRString(struct soap_dom_element *node, + char *current_nstr) +{ + struct soap_dom_attribute *attr; + char *epr_buf; + int i, epr_len; + + if (node == NULL) { + return NULL; + } + + epr_len = calcDomSize(node, current_nstr); + epr_buf = (char*)malloc(epr_len+1); + if (epr_buf == NULL) { + perror("generateEPRSTring: malloc"); + return NULL; + } + memset(epr_buf, 0, epr_len+1); + + sprintDom(node, epr_buf, current_nstr); + + return epr_buf; +} + +void +cleanDom(struct soap_dom_element *node) +{ + struct soap_dom_attribute *attr; + char *cp; + + if (node == NULL) { + return; + } + cp = strchr(node->name, ':'); + if (cp) { + cp++; + node->name = cp; + } + if (node->nstr && strlen(node->nstr) == 0) + node->nstr = NULL; + attr = node->atts; + while (attr) { + cp = strchr(attr->name, ':'); + if (cp) { + cp++; + attr->name = cp; + } + if (attr->nstr && strlen(attr->nstr) == 0) + attr->nstr = NULL; + attr = attr->next; + } + if (node->elts) + cleanDom(node->elts); + if (node->next) + cleanDom(node->next); +} + +int +generateAddressHeader(struct bes_context *context, + epr_t endpointepr, + char *action, + char **endpoint_ret) +{ + struct soap *s; + struct soap_dom_element *dom, *iter; + struct bes_epr *epr; + char *endpoint; + + s = context->soap; + epr = (struct bes_epr *)endpointepr; + dom = epr->dom; + + iter = dom->elts; + if (!iter || !isElement(iter, WSA_NS, "Address")) { + setErrorString(context, NULL, BESE_ENDPOINT_ERR); + return BESE_ENDPOINT_ERR; + } + endpoint = soap_strdup(s, iter->data); + if (endpoint == NULL) { + setErrorString(context, s, BESE_SOAP_ERR); + return BESE_SOAP_ERR; + } + + s->header->wsa__To.__item = endpoint; + *endpoint_ret = endpoint; + + s->header->wsa__Action.__item = soap_strdup(s, action); + if (s->header->wsa__Action.__item == NULL) { + setErrorString(context, s, BESE_SOAP_ERR); + return BESE_SOAP_ERR; + } + + return BESE_OK; +} + + +int +generateAddressingHeaders(struct bes_context *context, + epr_t endpointepr, + char *action, + char **endpoint_ret) +{ + struct soap *s; + struct soap_dom_element *dom, *iter; + struct soap_dom_element *refparams, *refparam; + struct soap_dom_attribute *isrefparam; + struct bes_epr *epr; + char *endpoint; + int i, numrefparams, ret = BESE_OK; + + s = context->soap; + epr = (struct bes_epr*)endpointepr; + dom = epr->dom; + + iter = dom->elts; + if (!iter || !isElement(iter, WSA_NS, "Address")) { + setErrorString(context, NULL, BESE_ENDPOINT_ERR); + ret = BESE_ENDPOINT_ERR; + goto end; + } + endpoint = soap_strdup(s, iter->data); + if (endpoint == NULL) { + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; + goto end; + } + s->header->wsa__To.__item = endpoint; + + s->header->wsa__Action.__item = soap_strdup(s, action); + if (s->header->wsa__Action.__item == NULL) { + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; + goto end; + } + + iter = iter->next; + while (iter) { + if (isElement(iter, WSA_NS, "ReferenceParameters")) { + isrefparam = (struct soap_dom_attribute*)soap_malloc(s, sizeof(struct soap_dom_attribute)); + if (isrefparam == NULL) { + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; + goto end; + } + memset(isrefparam, 0, sizeof(struct soap_dom_attribute)); + isrefparam->soap = s; + isrefparam->nstr = WSA_NS; + isrefparam->name = soap_strdup(s, "wsa:IsReferenceParameter"); + isrefparam->data = soap_strdup(s, "true"); + if (!isrefparam->name || !isrefparam->data) { + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; + goto end; + } + + refparam = iter->elts; + numrefparams = 0; + while (refparam) { + if (refparam->atts) { + struct soap_dom_attribute *last, *attr = refparam->atts; + while (attr) { + if (isAttribute(attr, WSA_NS, "IsReferenceParameter")) { + attr->nstr = isrefparam->nstr; + attr->name = isrefparam->name; + attr->data = isrefparam->data; + break; + } + last = attr; + attr = attr->next; + } + if (!attr) { + last->next = isrefparam; + } + } + else { + refparam->atts = isrefparam; + } + refparam = refparam->next; + numrefparams++; + } + + refparams = (struct soap_dom_element*)soap_malloc(s, sizeof(struct soap_dom_element)*numrefparams); + if (refparams == NULL) { + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; + goto end; + } + memset(refparams, 0, sizeof(struct soap_dom_element)*numrefparams); + refparam = iter->elts; + for (i = 0; i < numrefparams; i++) { + refparams[i].nstr = refparam->nstr; + refparams[i].name = refparam->name; + refparams[i].data = refparam->data; + refparams[i].atts = refparam->atts; + refparams[i].soap = refparam->soap; + refparams[i].elts = refparam->elts; + refparam = refparam->next; + } + + s->header->__size = numrefparams; + s->header->__any = refparams; + } + + iter = iter->next; + } + + if (endpoint_ret) *endpoint_ret = endpoint; + + end: + return ret; +} + +int +isElement(struct soap_dom_element *dom, + char *ns, + char *elt) +{ + char *cp; + + if (!dom || !ns || !elt) { + return 0; + } + if (strcmp(dom->nstr, ns)) { + return 0; + } + cp = strchr(dom->name, ':'); + if (cp) { + cp++; + } + else { + cp = dom->name; + } + if (strcmp(cp, elt)) { + return 0; + } + + return 1; +} + +int +isAttribute(struct soap_dom_attribute *attr, + char *ns, + char *elt) +{ + char *cp; + + if (!attr || !ns || !elt) { + return 0; + } + if (strcmp(attr->nstr, ns)) { + return 0; + } + cp = strchr(attr->name, ':'); + if (cp) { + cp++; + } + else { + cp = attr->name; + } + if (strcmp(cp, elt)) { + return 0; + } + + return 1; +} + +void +setErrorString(struct bes_context *context, + struct soap *s, + int error_code) +{ + switch (error_code) { + case BESE_SOAP_ERR: + soap_sprint_fault(s, context->error_string, MAX_ERRSTR_LEN); + break; + + case BESE_SYS_ERR: + snprintf(context->error_string, MAX_ERRSTR_LEN, "System error: %s", strerror(errno)); + break; + + case BESE_ENDPOINT_ERR: + snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BESE_ENDPOINT_STRING); + break; + + case BESE_MEM_ALLOC: + snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BESE_MEM_STRING); + break; + + case BESE_GETSTATUS_ERR: + snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BESE_GETSTATUS_STRING); + break; + + case BESE_BAD_ARG: + snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BESE_BAD_ARG_STRING); + break; + + case BESE_UNSUPPORTED: + snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BESE_UNSUPPORTED_STRING); + break; + + case BESE_XML_FORMAT: + snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BESE_XML_FORMAT_STRING); + break; + + default: + break; + } +} + + +/* + * Don't know why these aren't being generated, but .... + */ +struct soap_dom_element * +soap_in__bes__CreateActivityFaultMessage(struct soap *s, + const char *tag, + struct soap_dom_element *node, + const char *type) +{ + return soap_in_xsd__anyType(s, tag, node, type); +} + +int +soap_out__bes__CreateActivityFaultMessage(struct soap *s, + const char *tag, + int id, + const struct soap_dom_element *node, + const char *type) +{ + return soap_out_xsd__anyType(s, tag, id, node, type); +} + +void +soap_serialize__bes__CreateActivityFaultMessage(struct soap *s, + const struct soap_dom_element *node) +{ + soap_serialize_xsd__anyType(s, node); +} + Modified: trunk/besclient/bes.h =================================================================== --- trunk/besclient/bes.h 2008-09-23 01:13:18 UTC (rev 54) +++ trunk/besclient/bes.h 2008-10-21 02:53:40 UTC (rev 55) @@ -23,8 +23,12 @@ #ifndef _BES_H #define _BES_H +#include "jsdl.h" + #define MAX_ERRSTR_LEN 256 +typedef void* epr_t; + struct bes_context { struct soap *soap; @@ -37,21 +41,25 @@ char error_string[MAX_ERRSTR_LEN]; }; -enum activity_state { - BES_Pending = 0, - BES_Running = 1, - BES_Cancelled = 2, - BES_Failed = 3, - BES_Finished = 4, - BES_State_Num, +enum bes_activity_state { + BES_Pending = 0, + BES_Running = 1, + BES_Cancelled = 2, + BES_Failed = 3, + BES_Finished = 4, + BES_State_Num, }; struct bes_activity_status { - enum activity_state state; - char *substate; + enum bes_activity_state state; + char *substate; }; -typedef void* epr_t; +struct bes_activity_document { + epr_t activityepr; + struct jsdl_job_definition *activity; + char *fault; +}; /* Error code */ #define BESE_OK 0 @@ -61,12 +69,16 @@ #define BESE_MEM_ALLOC 4 #define BESE_GETSTATUS_ERR 5 #define BESE_BAD_ARG 6 +#define BESE_UNSUPPORTED 7 +#define BESE_XML_FORMAT 8 /*Error strings*/ -#define BESE_ENDPOINT_STRING "The endpoint.xml does not contain a valid EPR" -#define BESE_MEM_STRING "Memory allocation error" -#define BESE_GETSTATUS_STRING "Failed to get the status of activity" -#define BESE_BAD_ARG_STRING "Bad arguments for the function" +#define BESE_ENDPOINT_STRING "The endpoint.xml does not contain a valid EPR" +#define BESE_MEM_STRING "Memory allocation error" +#define BESE_GETSTATUS_STRING "Failed to get the status of activity" +#define BESE_BAD_ARG_STRING "Bad arguments for the function" +#define BESE_UNSUPPORTED_STRING "Feature is unsupported by BES++ at this time" +#define BESE_XML_FORMAT_STRING "Format error in XML request/response" #define BES_FALSE 0 #define BES_TRUE 1 @@ -80,7 +92,8 @@ int bes_createActivity(struct bes_context *, epr_t, char *, epr_t *); int bes_terminateActivities(struct bes_context *, epr_t, epr_t); int bes_getActivityStatuses(struct bes_context *, epr_t, epr_t, struct bes_activity_status *); -int bes_getActivityDocuments(struct bes_context *, epr_t, epr_t, char **); +int bes_getActivityDocumentsXML(struct bes_context *, epr_t, epr_t, char **); +int bes_getActivityDocuments(struct bes_context *, epr_t, epr_t, struct bes_activity_document **); int bes_getFactoryAttributesDocument(struct bes_context *, epr_t, char **); void bes_freeEPR(epr_t *epr); int bes_writeEPRToFile(struct bes_context *, char *, epr_t); Modified: trunk/besclient/besclient.c =================================================================== --- trunk/besclient/besclient.c 2008-09-23 01:13:18 UTC (rev 54) +++ trunk/besclient/besclient.c 2008-10-21 02:53:40 UTC (rev 55) @@ -196,7 +196,7 @@ else if (!strcmp(command, "activity")) { char *strDoc; - if (bes_getActivityDocuments(ctx, endpointepr, activityepr, &strDoc)) { + if (bes_getActivityDocumentsXML(ctx, endpointepr, activityepr, &strDoc)) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; } Added: trunk/besclient/jsdl.c =================================================================== --- trunk/besclient/jsdl.c (rev 0) +++ trunk/besclient/jsdl.c 2008-10-21 02:53:40 UTC (rev 55) @@ -0,0 +1,1177 @@ +/* ---------------------------------------------------------------- + * jsdl.c + * + * Copyright (C) 2006-2007, Platform Computing Corporation. All Rights Reserved. + * + * + * Client library of the OGSA Basic Execution Services + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ +#include "../config.h" +#include <stdlib.h> +#include <string.h> +#include "jsdl.h" +#include "bes.h" +#include "namespaces.h" +#include "soapStub.h" + + +char *jsdl_operating_system_names[] = { + "Unknown", "MACOS", "ATTUNIX", "DGUX", "DECNT", "Tru64_UNIX", "OpenVMS", + "HPUX", "AIX", "MVS", "OS400", "OS_2", "JavaVM", "MSDOS", "WIN3x", "WIN95", + "WIN98", "WINNT", "WINCE", "NCR3000", "NetWare", "OSF", "DC_OS", + "Reliant_UNIX", "SCO_UnixWare", "SCO_OpenServer", "Sequent", "IRIX", + "Solaris", "SunOS", "U6000", "ASERIES", "TandemNSK", "TandemNT", + "BS2000", "LINUX", "Lynx", "XENIX", "VM", "Interactive_UNIX", "BSDUNIX", + "FreeBSD", "NetBSD", "GNU_Hurd", "OS9", "MACH_Kernel", "Inferno", "QNX", + "EPOC", "IxWorks", "VxWorks", "MiNT", "BeOS", "HP_MPE", "NextStep", + "PalmPilot", "Rhapsody", "Windows_2000", "Dedicated", "OS_390", "VSE", + "TPF", "Windows_R_Me", "Caldera_Open_UNIX", "OpenBSD", "Not_Applicable", + "Windows_XP", "z_OS", "other", NULL, +}; + +char *jsdl_processor_architectures[] = { + "sparc", "powerpc", "x86", "x86_32", "x86_64", + "parisc", "mips", "ia64", "arm", "other", NULL, +}; + + +int +jsdl_addArg(struct jsdl_job_definition *jsdl, char *arg) +{ + struct jsdl_hpcp_application *app; + char *cp, **cpp; + int i; + + if (!jsdl || !arg) { + return BESE_BAD_ARG; + } + + app = (struct jsdl_hpcp_application*)jsdl->Application; + + cp = strdup(arg); + if (cp == NULL) { + return BESE_MEM_ALLOC; + } + + cpp = (char**)malloc(sizeof(char*)*(app->num_args+1)); + if (cpp == NULL) { + free(cp); + return BESE_MEM_ALLOC; + } + + for (i = 0; i < app->num_args; i++) + cpp[i] = app->Argument[i]; + cpp[i] = cp; + + if (app->Argument) { + free(app->Argument); + } + + app->Argument = cpp; + app->num_args++; + + return BESE_OK; +} + +int +jsdl_addEnv(struct jsdl_job_definition *jsdl, struct soap_dom_element *dom) +{ + struct jsdl_hpcp_application *app; + struct jsdl_envvar *newvar, *cur; + struct soap_dom_attribute *attr; + + if (!jsdl || !dom) { + return BESE_BAD_ARG; + } + + app = (struct jsdl_hpcp_application*)jsdl->Application; + + newvar = (struct jsdl_envvar*)malloc(sizeof(struct jsdl_envvar)); + if (newvar == NULL) { + return BESE_MEM_ALLOC; + } + + newvar->val = strdup(dom->data); + if (newvar->val == NULL) { + free(newvar); + return BESE_MEM_ALLOC; + } + + newvar->name = NULL; + for (attr = dom->atts; attr; attr = attr->next) { + if (!strcmp(attr->name, "name")) { + newvar->name = strdup(attr->data); + if (newvar->name == NULL) { + free(newvar->val); + free(newvar); + return BESE_MEM_ALLOC; + } + } + } + if (newvar->name == NULL) { + free(newvar->val); + free(newvar); + return BESE_XML_FORMAT; + } + + cur = app->Environment; + while (cur->next) { + cur = cur->next; + } + cur->next = newvar; + + return BESE_OK; +} + +int +jsdl_addHost(struct jsdl_job_definition *jsdl, char *host) +{ + char *cp, **cpp; + int i; + + if (!jsdl || !host) { + return BESE_BAD_ARG; + } + + cp = strdup(host); + if (cp == NULL) { + return BESE_MEM_ALLOC; + } + + cpp = (char**)malloc(sizeof(char*)*(jsdl->num_hosts+1)); + if (cpp == NULL) { + free(cp); + return BESE_MEM_ALLOC; + } + + for (i = 0; i < jsdl->num_hosts; i++) + cpp[i] = jsdl->HostName[i]; + cpp[i] = cp; + + if (jsdl->HostName) { + free(jsdl->HostName); + } + + jsdl->HostName = cpp; + jsdl->num_hosts++; + + return BESE_OK; +} + +int +jsdl_processCredential(struct soap_dom_element *dom, + struct hpcp_credential **cred) +{ + struct soap_dom_element *cur = dom->elts; + struct soap_dom_element *user, *pass; + struct hpcp_credential *new_cred = NULL; + + printf("----%s\n", dom->name); + + while (cur) { + if (isElement(cur, WSSE_NS, "UsernameToken")) { + printf("-----%s\n", cur->name); + user = cur->elts; + if (!isElement(user, WSSE_NS, "Username")) { + return BESE_XML_FORMAT; + } + pass = user->next; + if (!isElement(pass, WSSE_NS, "Password")) { + return BESE_XML_FORMAT; + } + new_cred = (struct hpcp_credential*)malloc(sizeof(struct hpcp_credential)); + if (new_cred == NULL) { + return BESE_MEM_ALLOC; + } + new_cred->username = strdup(user->data); + if (new_cred->username == NULL) { + free(new_cred); + return BESE_MEM_ALLOC; + } + new_cred->password = strdup(pass->data); + if (!new_cred->password) { + free(new_cred->username); + free(new_cred); + return BESE_MEM_ALLOC; + } + *cred = new_cred; + } + else { + return BESE_UNSUPPORTED; + } + cur = cur->next; + } + return BESE_OK; +} + +void +jsdl_freeHPCProfileApplication(struct jsdl_hpcp_application *app) +{ + struct jsdl_envvar *cur, *next; + int i; + + if (!app) return; + if (app->Executable) free(app->Executable); + if (app->Argument) { + for (i = 0; i < app->num_args; i++) { + if (app->Argument[i]) free(app->Argument[i]); + } + free(app->Argument); + } + if (app->Input) free(app->Input); + if (app->Output) free(app->Output); + if (app->Error) free(app->Error); + if (app->WorkingDirectory) free(app->WorkingDirectory); + if (app->UserName) free(app->UserName); + cur = app->Environment; + while (cur) { + if (cur->name) free(cur->name); + if (cur->val) free(cur->val); + next = cur; + free(cur); + cur = next; + } + free(app); + + return; +} + +int +jsdl_processHPCProfileApplication(struct soap_dom_element *dom, + struct jsdl_job_definition *jsdl) +{ + struct jsdl_hpcp_application *app; + struct soap_dom_element *cur = dom->elts; + int rc; + + if (!dom || !jsdl) { + return BESE_BAD_ARG; + } + + printf("----%s\n", dom->name); + + app = (struct jsdl_hpcp_application*)malloc(sizeof(struct jsdl_hpcp_application)); + if (app == NULL) { + return BESE_MEM_ALLOC; + } + memset(app, 0, sizeof(struct jsdl_hpcp_application)); + + while (cur) { + if (isElement(cur, JSDL_HPCPA_NS, "Executable")) { + printf("-----Executable = %s\n", cur->data); + if (cur->data && strlen(cur->data)) { + app->Executable = strdup(cur->data); + if (app->Executable == NULL) { + jsdl_freeHPCProfileApplication(app); + return BESE_MEM_ALLOC; + } + } + else { + jsdl_freeHPCProfileApplication(app); + return BESE_XML_FORMAT; + } + } + else if (isElement(cur, JSDL_HPCPA_NS, "Argument")) { + printf("-----Argument = %s\n", cur->data); + if ((rc = jsdl_addArg(jsdl, cur->data)) != BESE_OK) { + jsdl_freeHPCProfileApplication(app); + return rc; + } + } + else if (isElement(cur, JSDL_HPCPA_NS, "Input")) { + printf("-----Input = %s\n", cur->data); + if (cur->data && strlen(cur->data)) { + app->Input = strdup(cur->data); + if (app->Input == NULL) { + jsdl_freeHPCProfileApplication(app); + return BESE_MEM_ALLOC; + } + } + else { + jsdl_freeHPCProfileApplication(app); + return BESE_XML_FORMAT; + } + } + else if (isElement(cur, JSDL_HPCPA_NS, "Output")) { + printf("-----Output = %s\n", cur->data); + if (cur->data && strlen(cur->data)) { + app->Output = strdup(cur->data); + if (app->Output == NULL) { + jsdl_freeHPCProfileApplication(app); + return BESE_MEM_ALLOC; + } + } + else { + jsdl_freeHPCProfileApplication(app); + return BESE_XML_FORMAT; + } + } + else if (isElement(cur, JSDL_HPCPA_NS, "Error")) { + printf("-----Error = %s\n", cur->data); + if (cur->data && strlen(cur->data)) { + app->Error = strdup(cur->data); + if (app->Error == NULL) { + jsdl_freeHPCProfileApplication(app); + return BESE_MEM_ALLOC; + } + } + else { + jsdl_freeHPCProfileApplication(app); + return BESE_XML_FORMAT; + } + } + else if (isElement(cur, JSDL_HPCPA_NS, "WorkingDirectory")) { + printf("-----WorkingDirectory = %s\n", cur->data); + if (cur->data && strlen(cur->data)) { + app->WorkingDirectory = strdup(cur->data); + if (app->WorkingDirectory == NULL) { + jsdl_freeHPCProfileApplication(app); + return BESE_MEM_ALLOC; + } + } + else { + jsdl_freeHPCProfileApplication(app); + return BESE_XML_FORMAT; + } + } + else if (isElement(cur, JSDL_HPCPA_NS, "Environment")) { + printf("-----Environment\n"); + if ((rc = jsdl_addEnv(jsdl, cur)) != BESE_OK) { + jsdl_freeHPCProfileApplication(app); + return rc; + } + } + else if (isElement(cur, JSDL_HPCPA_NS, "UserName")) { + printf("-----UserName = %s\n", cur->data); + if (cur->data && strlen(cur->data)) { + app->UserName = strdup(cur->data); + if (app->UserName == NULL) { + jsdl_freeHPCProfileApplication(app); + return BESE_MEM_ALLOC; + } + } + else { + jsdl_freeHPCProfileApplication(app); + return BESE_XML_FORMAT; + } + } + cur = cur->next; + } + + jsdl->ApplicationType = JSDL_HPC_PROFILE_APPLICATION; + jsdl->Application = (void*)app; + + return BESE_OK; +} + +int +jsdl_processJobIdentification(struct soap_dom_element *dom, + struct jsdl_job_definition *jsdl) +{ + struct soap_dom_element *cur = dom->elts; + int rc; + + printf("---%s\n", dom->name); + + while (cur) { + if (isElement(cur, JSDL_NS, "JobName")) { + printf("----JobName = %s\n", cur->data); + jsdl->JobName = strdup(cur->data); + if (jsdl->JobName == NULL) { + return BESE_MEM_ALLOC; + } + } + else if (isElement(cur, JSDL_NS, "Description")) { + printf("----Description = %s\n", cur->data); + } + else if (isElement(cur, JSDL_NS, "JobAnnotation")) { + printf("----JobAnnotation = %s\n", cur->data); + jsdl->JobAnnotation = strdup(cur->data); + if (jsdl->JobAnnotation == NULL) { + return BESE_MEM_ALLOC; + } + } + else if (isElement(cur, JSDL_NS, "JobProject")) { + printf("----JobProject = %s\n", cur->data); + jsdl->JobProject = strdup(cur->data); + if (jsdl->JobProject == NULL) { + return BESE_MEM_ALLOC; + } + } + cur = cur->next; + } + + return BESE_OK; +} + +int +jsdl_processApplication(struct soap_dom_element *dom, + struct jsdl_job_definition *jsdl) +{ + struct soap_dom_element *cur = dom->elts; + int rc; + + printf("---%s\n", dom->name); + + while (cur) { + if (isElement(cur, JSDL_NS, "ApplicationName")) { + printf("----ApplicationName = %s\n", cur->data); + jsdl->ApplicationName = strdup(cur->data); + if (jsdl->ApplicationName == NULL) { + return BESE_MEM_ALLOC; + } + } + else if (isElement(cur, JSDL_NS, "ApplicationVersion")) { + printf("----ApplicationVersion = %s\n", cur->data); + jsdl->ApplicationVersion = strdup(cur->data); + if (jsdl->ApplicationVersion == NULL) { + return BESE_MEM_ALLOC; + } + } + else if (isElement(cur, JSDL_HPCPA_NS, "HPCProfileApplication")) { + if ((rc = jsdl_processHPCProfileApplication(cur, jsdl)) != BESE_OK) { + return rc; + } + } + cur = cur->next; + } + + return BESE_OK; +} + +void +jsdl_freeRangeValue(struct jsdl_range_value *value) +{ + struct jsdl_exact *exact, *next_exact; + struct jsdl_range *range, *next_range; + + if (value == NULL) + return; + + exact = value->Exact; + while (exact) { + next_exact = exact; + free(exact); + exact = next_exact; + } + + range = value->Range; + while (range) { + next_range = range; + free(range); + range = next_range; + } + + free(value); + + return; +} + +int +jsdl_processRangeValue(struct soap_dom_element *dom, + struct jsdl_range_value **value) +{ + struct jsdl_range_value *val; + struct jsdl_exact *new_exact, *exact; + struct soap_dom_element *cur; + struct soap_dom_attribute *attr; + char *endptr; + + if (!dom || !value) { + return BESE_BAD_ARG; + } + + val = (struct jsdl_range_value*)malloc(sizeof(struct jsdl_range_value)); + if (val == NULL) { + return BESE_MEM_ALLOC; + } + memset(val, 0, sizeof(struct jsdl_range_value)); + + cur = dom->elts; + + while (cur) { + if (isElement(cur, JSDL_NS, "UpperBoundedRange")) { + val->UpperBoundedRange = strtod(cur->data, NULL); + for (attr = cur->atts; attr; attr = attr->next) { + if (!strcmp(attr->name, "exclusiveBound")) { + if (!strcmp(attr->data, "true")) { + val->exclusiveUpperBound = 1; + } + } + } + } + else if (isElement(cur, JSDL_NS, "LowerBoundedRange")) { + val->LowerBoundedRange = strtod(cur->data, NULL); + for (attr = cur->atts; attr; attr = attr->next) { + if (!strcmp(attr->name, "exclusiveBound")) { + if (!strcmp(attr->data, "true")) { + val->exclusiveLowerBound = 1; + } + } + } + } + else if (isElement(cur, JSDL_NS, "Exact")) { + new_exact = (struct jsdl_exact*)malloc(sizeof(struct jsdl_exact)); + if (new_exact == NULL) { + jsdl_freeRangeValue(val); + return BESE_MEM_ALLOC; + } + new_exact->next = NULL; + new_exact->value = strtod(cur->data, NULL); + new_exact->epsilon = 0.0; + for (attr = cur->atts; attr; attr = attr->next) { + if (!strcmp(attr->name, "epsilon")) { + new_exact->epsilon = strtod(attr->data, NULL); + break; + } + } + if (val->Exact) { + exact = val->Exact; + while (exact->next) { + exact = exact->next; + } + exact->next = new_exact; + } + else { + val->Exact = new_exact; + } + } + else if (isElement(cur, JSDL_NS, "Range")) { + ; + } + + cur = cur->next; + } + + *value = val; + + return BESE... [truncated message content] |
From: <cs...@us...> - 2008-09-23 01:13:30
|
Revision: 54 http://bespp.svn.sourceforge.net/bespp/?rev=54&view=rev Author: csmith Date: 2008-09-23 01:13:18 +0000 (Tue, 23 Sep 2008) Log Message: ----------- - changed job ids to strings in preparation for RM independent interface - implemented new RM independent interface (rm.h) - moved LSF-specific code to LSF module (rm_lsf.c) Modified Paths: -------------- trunk/Make.config trunk/besserver/Makefile trunk/besserver/besserver.c trunk/besserver/faults.h trunk/besserver/job.c trunk/besserver/job.h Added Paths: ----------- trunk/besserver/rm.h trunk/besserver/rm_lsf.c Modified: trunk/Make.config =================================================================== --- trunk/Make.config 2008-09-11 23:22:27 UTC (rev 53) +++ trunk/Make.config 2008-09-23 01:13:18 UTC (rev 54) @@ -7,6 +7,17 @@ GSOAP_TOP = /home/csmith/src/gsoap-2.7/gsoap # +# Which resource manager back end to use. Also need to set the +# locations of resource manager specific includes and libraries +# +RM = rm_lsf +#RM = rm_pbs +#RM = rm_sge + +RM_INC = $(LSF_INC) +RM_LIBS = $(LSF_LIBS) + +# # LSF related variables # # LSF_LOC is where the 'include' and architecture specific Modified: trunk/besserver/Makefile =================================================================== --- trunk/besserver/Makefile 2008-09-11 23:22:27 UTC (rev 53) +++ trunk/besserver/Makefile 2008-09-23 01:13:18 UTC (rev 54) @@ -11,14 +11,14 @@ # http://schemas.ggf.org/jsdl/2005/11/jsdl-posix CC = gcc -CFLAGS = -g $(GSOAP_DEF) -I. $(GSOAP_INC) $(LSF_INC) $(EXTRA_INC) +CFLAGS = -g $(GSOAP_DEF) -I. $(GSOAP_INC) $(RM_INC) $(EXTRA_INC) LDFLAGS = -g $(EXTRA_LIB) -LIBS = -lssl -lcrypto -lpam $(LSF_LIBS) $(EXTRA_LIBS) +LIBS = -lssl -lcrypto -lpam $(RM_LIBS) $(EXTRA_LIBS) BES_WSDL = bes-factory.wsdl BES_HEADER = bes-factory.h -BES_H_FILES = job.h namespaces.h faults.h auth.h -BES_OBJ = besserver.o job.o faults.o auth.o +BES_H_FILES = job.h namespaces.h faults.h auth.h rm.h +BES_OBJ = besserver.o job.o faults.o auth.o $(RM).o SOAP_NS = BESFactoryBinding.nsmap SOAP_H_FILES = soapH.h soapStub.h @@ -37,6 +37,7 @@ job.o: job.c $(BES_H_FILES) $(SOAP_NS) faults.o: faults.c $(BES_H_FILES) $(SOAP_NS) auth.o: auth.c $(BES_H_FILES) $(SOAP_NS) +$(RM).o: $(RM).c $(BES_H_FILES) $(SOAP_NS) soapServer.o: soapServer.c soapClient.o: soapClient.c Modified: trunk/besserver/besserver.c =================================================================== --- trunk/besserver/besserver.c 2008-09-11 23:22:27 UTC (rev 53) +++ trunk/besserver/besserver.c 2008-09-23 01:13:18 UTC (rev 54) @@ -35,9 +35,6 @@ #include <paths.h> #include <time.h> -#include <lsf/lsf.h> -#include <lsf/lsbatch.h> - #include "wsseapi.h" #include "BESFactoryBinding.nsmap" @@ -45,6 +42,7 @@ #include "job.h" #include "namespaces.h" #include "faults.h" +#include "rm.h" #define USERNAMELEN 256 @@ -52,11 +50,10 @@ #define clear_header(x) if (x->header) memset(x->header, 0, sizeof(struct SOAP_ENV__Header)); -int isElement(struct soap_dom_element *, char *, char *); -int makeActivityEPR(struct soap*, char *, int, struct wsa__EndpointReferenceType*); -int makeActivityDomEPR(struct soap*, char *, int, struct soap_dom_element**); -int getJobIdFromEPR(struct soap*, struct wsa__EndpointReferenceType*, int*); -int getContainedResources(struct soap*, struct bes__FactoryResourceAttributesDocumentType*, int); +int isElement(struct soap_dom_element*, char*, char*); +int makeActivityEPR(struct soap*, char*, char*, struct wsa__EndpointReferenceType*); +int makeActivityDomEPR(struct soap*, char*, char*, struct soap_dom_element**); +int getJobIdFromEPR(struct soap*, struct wsa__EndpointReferenceType*, char**); int processHeaders(struct soap*, char*, int); @@ -174,15 +171,8 @@ exit(1); } - if (lsb_init("besserver")) { - lsb_perror("main: lsb_init"); - exit(1); - } - soap_ssl_init(); - soap_init(&soap); - soap_set_mode(&soap, SOAP_C_UTFSTRING|SOAP_IO_STORE); soap_register_plugin(&soap, soap_wsse); @@ -202,6 +192,11 @@ sprintf(service_endpoint, "https://%s%s%s", host, strlen(portstr)?":":"", portstr); } + if (rm_initialize(&soap, NULL)) { + fprintf(stderr, "Couldn't initialize the resource manager\n"); + exit(1); + } + m = soap_bind(&soap, host, port, 100); if (m < 0) { soap_print_fault(&soap, stderr); @@ -259,9 +254,9 @@ static char fname[] = "__bes__CreateActivity"; struct jobcard *jc; struct soap_dom_element *dom; - int rc, jobid; + int rc; struct SOAP_ENV__Fault *fault; - char username[USERNAMELEN]; + char username[USERNAMELEN], *jobid; fprintf(stderr, "In %s...\n", fname); @@ -287,13 +282,13 @@ return bes_send_fault(s, fault); } - rc = submitLSFJob(jc, &jobid, username); + rc = rm_submitJob(s, jc, username, &jobid); if (rc != BESE_OK) { if (rc == BESE_PERMISSION) { fault = bes_NotAuthorizedFault(s, lsb_sysmsg()); return bes_send_fault(s, fault); } else { - return soap_receiver_fault(s, LSF_LIB_ERROR, NULL); + return soap_receiver_fault(s, BACKEND_ERROR, NULL); } } @@ -317,8 +312,8 @@ struct wsa__EndpointReferenceType *cur; struct bes__TerminateActivityResponseType *resp_array; struct soap_dom_element *fault; - int i, rc, jobid; - char username[USERNAMELEN]; + int i, rc; + char username[USERNAMELEN], *jobid; fprintf(stderr, "In %s...\n", fname); @@ -345,7 +340,8 @@ cur = &(req->ActivityIdentifier[0]); resp_array[i].ActivityIdentifier = cur; - if (rc = getJobIdFromEPR(s, cur, &jobid)) { + jobid = NULL; + if (getJobIdFromEPR(s, cur, &jobid) || !jobid) { resp_array[i].__any = bes_InvalidActivityFaultDOM(s, "Malformed EPR", "Malformed EPR"); if (resp_array[i].__any == NULL) { return soap_receiver_fault(s, MEM_ALLOC, NULL); @@ -355,9 +351,9 @@ continue; } - fprintf(stderr, "Terminating job %d\n", jobid); + fprintf(stderr, "Terminating job %s\n", jobid); - rc = terminateLSFJob(jobid, username); + rc = rm_terminateJob(s, jobid, username); if (rc != BESE_OK) { if (rc == BESE_NO_ACTIVITY) { fault = bes_InvalidActivityFaultDOM(s, "Unknown Activity", "Unknown Activity"); @@ -392,11 +388,9 @@ struct wsa__EndpointReferenceType *cur; struct bes__GetActivityStatusResponseType *resp_array; struct bes__ActivityStatusType *status; - struct bes__ActivityStateType *state; - struct jobInfoEnt *job; struct soap_dom_element *fault; - int i, rc, jobid; - char username[USERNAMELEN]; + int i, rc; + char username[USERNAMELEN], *jobid; fprintf(stderr, "In %s...\n", fname); @@ -423,7 +417,8 @@ cur = &(req->ActivityIdentifier[0]); resp_array[i].ActivityIdentifier = cur; - if (rc = getJobIdFromEPR(s, cur, &jobid)) { + jobid = NULL; + if (getJobIdFromEPR(s, cur, &jobid) || !jobid) { resp_array[i].__any = bes_InvalidActivityFaultDOM(s, "Malformed EPR", "Malformed EPR"); if (resp_array[i].__any == NULL) { return soap_receiver_fault(s, MEM_ALLOC, NULL); @@ -432,14 +427,14 @@ continue; } - fprintf(stderr, "Getting status for job %d\n", jobid); + fprintf(stderr, "Getting status for job %s\n", jobid); - rc = lsb_openjobinfo(jobid, NULL, "all", NULL, NULL, ALL_JOB); - if (rc == -1) { - lsb_perror("GetActivityStatuses: lsb_openjobinfo"); - if (lsberrno == LSBE_NO_JOB) { + rc = rm_getJobStatus(s, jobid, username, &status); + if (rc != BESE_OK) { + if (rc == BESE_NO_ACTIVITY) { fault = bes_InvalidActivityFaultDOM(s, "Unknown Activity", "Unknown Activity"); - } else { + } + else { fault = bes_backend_errorDOM(s); } if (fault == NULL) { @@ -450,35 +445,8 @@ continue; } - job = lsb_readjobinfo(NULL); - if (job == NULL) { - lsb_perror("GetActivityStatuses: lsb_readjobinfo"); - resp_array[i].__any = bes_backend_errorDOM(s); - if (resp_array[i].__any == NULL) { - return soap_receiver_fault(s, MEM_ALLOC, NULL); - } - resp_array[i].__size = 1; - continue; - } - - status = (struct bes__ActivityStatusType*)soap_malloc(s, - sizeof(struct bes__ActivityStatusType)); - if (status == NULL) { - return soap_receiver_fault(s, MEM_ALLOC, NULL); - } - memset(status, 0, sizeof(struct bes__ActivityStatusType)); - - if (IS_PEND(job->status)) { - status->state = Pending; - } else if (IS_START(job->status)) { - status->state = Running; - } else if (IS_FINISH(job->status)) { - status->state = Finished; - } - resp_array[i].bes__ActivityStatus = status; - lsb_closejobinfo(); } resp->__sizeResponse = req->__sizeActivityIdentifier; @@ -495,10 +463,10 @@ static char fname[] = "__bes__GetActivityDocuments"; struct wsa__EndpointReferenceType *cur; struct bes__GetActivityDocumentResponseType *resp_array; - struct jobInfoEnt *job; + struct jobcard *job_info; struct soap_dom_element *fault; - int i, rc, jobid; - char username[USERNAMELEN]; + int i, rc; + char username[USERNAMELEN], *jobid; fprintf(stderr, "In %s...\n", fname); @@ -525,7 +493,8 @@ cur = &(req->ActivityIdentifier[0]); resp_array[i].ActivityIdentifier = cur; - if (getJobIdFromEPR(s, cur, &jobid) < 0) { + jobid = NULL; + if (getJobIdFromEPR(s, cur, &jobid) || !jobid) { resp_array[i].__any = bes_InvalidActivityFaultDOM(s, "Malformed EPR", "Malformed EPR"); if (resp_array[i].__any == NULL) { return soap_receiver_fault(s, MEM_ALLOC, NULL); @@ -534,14 +503,14 @@ continue; } - fprintf(stderr, "Getting information for job %d\n", jobid); + fprintf(stderr, "Getting information for job %s\n", jobid); - rc = lsb_openjobinfo(jobid, NULL, "all", NULL, NULL, ALL_JOB); - if (rc == -1) { - lsb_perror("GetActivityStatuses: lsb_openjobinfo"); - if (lsberrno == LSBE_NO_JOB) { + rc = rm_getJobInfo(s, jobid, username, &job_info); + if (rc != BESE_OK) { + if (rc == BESE_NO_ACTIVITY) { fault = bes_InvalidActivityFaultDOM(s, "Unknown Activity", "Unknown Activity"); - } else { + } + else { fault = bes_backend_errorDOM(s); } if (fault == NULL) { @@ -552,23 +521,11 @@ continue; } - job = lsb_readjobinfo(NULL); - if (job == NULL) { - lsb_perror("GetActivityStatuses: lsb_readjobinfo"); - resp_array[i].__any = bes_backend_errorDOM(s); - if (resp_array[i].__any == NULL) { - return soap_receiver_fault(s, MEM_ALLOC, NULL); - } - resp_array[i].__size = 1; - continue; - } - - rc = getJSDLFromJobInfo(s, job, &resp_array[i].JobDefinition); + rc = getJSDLFromJobInfo(s, job_info, &resp_array[i].JobDefinition); if (rc) { return rc; } - lsb_closejobinfo(); } resp->__sizeResponse = req->__sizeActivityIdentifier; @@ -585,9 +542,12 @@ static char fname[] = "__bes__GetFactoryAttributesDocument"; struct bes__FactoryResourceAttributesDocumentType *attrs; struct wsa_EndpointReferenceType *epr; - struct jobInfoEnt *jinfo; - char *clustername; - int num_jobs, i, rc; + struct rm_clusterInfo *cinfo; + struct rm_job *joblist, *job; + struct rm_resource *resourcelist, *resource; + struct soap_dom_element *contained_resources; + struct bes__BasicResourceAttributesDocumentType *res; + int num_jobs, num_resources, i, rc; char username[USERNAMELEN]; fprintf(stderr, "In %s....\n", fname); @@ -604,89 +564,115 @@ } memset(attrs, 0, sizeof(struct bes__FactoryResourceAttributesDocumentType)); - /* IsAcceptingNewActivities */ - attrs->IsAcceptingNewActivities = true_; - /* CommonName */ - clustername = ls_getclustername(); - if (clustername == NULL) { - fprintf(stderr, "%s: %s: %s", fname, "ls_getclustername", ls_sysmsg()); - return soap_receiver_fault(s, LSF_LIB_ERROR, NULL); + if ((rc = rm_getClusterInfo(s, &cinfo)) != BESE_OK) { + if (rc == BESE_MEM_ALLOC) { + return soap_receiver_fault(s, MEM_ALLOC, NULL); + } + else if (rc == BESE_BACKEND) { + return soap_receiver_fault(s, BACKEND_ERROR, NULL); + } + else { + return soap_receiver_fault(s, UNKNOWN_ERROR, NULL); + } } - attrs->CommonName = soap_strdup(s, clustername); - if (attrs->CommonName == NULL) { + + /* attributes from the backend */ + attrs->IsAcceptingNewActivities = cinfo->IsAcceptingNewActivities; + attrs->CommonName = cinfo->CommonName; + attrs->LongDescription = cinfo->LongDescription; + attrs->__sizeBESExtension = cinfo->num_extensions; + attrs->BESExtension = cinfo->BESExtensions; + attrs->LocalResourceManagerType = cinfo->LocalResourceManagerType; + + /* Only support basic EPRs, no WS-Names */ + attrs->__sizeNamingProfile = 1; + attrs->NamingProfile = (char**)soap_malloc(s, sizeof(char*)); + attrs->NamingProfile[0] = soap_strdup(s, + "http://schemas.ogf.org/bes/2006/08/bes/naming/BasicWSAddressing"); + if (attrs->NamingProfile == NULL) { soap_print_fault(s, stderr); return soap_receiver_fault(s, MEM_ALLOC, NULL); } - /* LongDescription */ - /* TotalNumberOfActivities and ActivityReference */ - num_jobs = lsb_openjobinfo(0, NULL, "all", NULL, NULL, ALL_JOB); - if (num_jobs == -1) { - if (lsberrno != LSBE_NO_JOB) { - fprintf(stderr, "%s: %s: %s", fname, "lsb_openjobinfo", lsb_sysmsg()); - return soap_receiver_fault(s, LSF_LIB_ERROR, NULL); - } else { - num_jobs = 0; + rc = rm_getJobList(s, NULL, &joblist, &num_jobs); + if (rc != BESE_OK) { + if (rc == BESE_MEM_ALLOC) { + return soap_receiver_fault(s, MEM_ALLOC, NULL); } + else if (rc == BESE_BACKEND) { + return soap_receiver_fault(s, BACKEND_ERROR, NULL); + } + else { + return soap_receiver_fault(s, UNKNOWN_ERROR, NULL); + } } attrs->TotalNumberOfActivities = num_jobs; - attrs->__sizeActivityReference = num_jobs; - attrs->ActivityReference = (struct wsa__EndpointReferenceType*)soap_malloc( - s, sizeof(struct wsa__EndpointReferenceType)*num_jobs); - if (attrs->ActivityReference == NULL) { - soap_print_fault(s, stderr); - return soap_receiver_fault(s, MEM_ALLOC, NULL); - } - for (i = 0; i < num_jobs; i++) { - jinfo = lsb_readjobinfo(NULL); - if (jinfo == NULL) { - fprintf(stderr, "%s: %s: %s\n", fname, "lsb_readjobinfo", lsb_sysmsg()); - return soap_receiver_fault(s, LSF_LIB_ERROR, NULL); - } - rc = makeActivityEPR(s, service_endpoint, jinfo->jobId, - &(attrs->ActivityReference[i])); - if (rc) { + if (num_jobs) { + attrs->__sizeActivityReference = num_jobs; + attrs->ActivityReference = (struct wsa__EndpointReferenceType*)soap_malloc(s, sizeof(struct wsa__EndpointReferenceType)*num_jobs); + if (attrs->ActivityReference == NULL) { soap_print_fault(s, stderr); - return rc; + return soap_receiver_fault(s, MEM_ALLOC, NULL); } + job = joblist; + for (i = 0; i < num_jobs; i++) { + rc = makeActivityEPR(s, service_endpoint, job->jobid, + &(attrs->ActivityReference[i])); + if (rc) { + soap_print_fault(s, stderr); + return rc; + } + job = job->next; + } } /* TotalNumberOfContainedResources and ContainedResource */ - if ((rc = getContainedResources(s, attrs, 1))) { + rc = rm_getResourceList(s, NULL, &resourcelist, &num_resources); + if (rc != BESE_OK) { if (rc == BESE_MEM_ALLOC) { return soap_receiver_fault(s, MEM_ALLOC, NULL); } - if (rc == BESE_BACKEND) { - return soap_receiver_fault(s, LSF_LIB_ERROR, NULL); + else if (rc == BESE_BACKEND) { + return soap_receiver_fault(s, BACKEND_ERROR, NULL); } - return soap_receiver_fault(s, UNKNOWN_ERROR, NULL); + else { + return soap_receiver_fault(s, UNKNOWN_ERROR, NULL); + } } - - /* NamingProfile */ - attrs->__sizeNamingProfile = 1; - attrs->NamingProfile = (char**)soap_malloc(s, sizeof(char*)); - attrs->NamingProfile[0] = soap_strdup(s, - "http://schemas.ogf.org/bes/2006/08/bes/naming/BasicWSAddressing"); - if (attrs->NamingProfile == NULL) { - soap_print_fault(s, stderr); - return soap_receiver_fault(s, MEM_ALLOC, NULL); - } + attrs->TotalNumberOfContainedResources = num_resources; + if (num_resources) { + contained_resources = (struct soap_dom_element*)soap_malloc(s, + sizeof(struct soap_dom_element)*num_resources); + if (!contained_resources) { + return soap_receiver_fault(s, MEM_ALLOC, NULL); + } + memset(contained_resources, 0, sizeof(struct soap_dom_element) + *num_resources); + resource = resourcelist; + for (i = 0; i < num_resources; i++) { + res = (struct bes__BasicResourceAttributesDocumentType*)soap_malloc(s, sizeof(struct bes__BasicResourceAttributesDocumentType)); + if (!res) { + return soap_receiver_fault(s, MEM_ALLOC, NULL); + } + memset(res, 0, sizeof(struct bes__BasicResourceAttributesDocumentType)); - /* BESExtension */ + res->ResourceName = resource->ResourceName; + res->CPUCount = resource->CPUCount; + res->CPUSpeed = resource->CPUSpeed; + res->PhysicalMemory = resource->PhysicalMemory; + res->VirtualMemory = resource->VirtualMemory; - /* LocalResourceManagerType */ - attrs->LocalResourceManagerType = (char*)soap_malloc(s, - strlen("http://www.platform.com/bes/2006/08/resourcemanager/LSF") - + strlen(LSF_CURRENT_VERSION)+1); - if (attrs->LocalResourceManagerType == NULL) { - soap_print_fault(s, stderr); - return soap_receiver_fault(s, MEM_ALLOC, NULL); + contained_resources[i].type + = SOAP_TYPE_bes__BasicResourceAttributesDocumentType; + contained_resources[i].node = res; + contained_resources[i].soap = s; + resource = resource->next; + } + attrs->ContainedResource = contained_resources; + attrs->__sizeContainedResource = num_resources; } - sprintf(attrs->LocalResourceManagerType, - "http://www.platform.com/bes/2006/08/resourcemanager/LSF%s", - LSF_CURRENT_VERSION); resp->bes__FactoryResourceAttributesDocument = attrs; @@ -719,14 +705,11 @@ } int -makeActivityEPR(struct soap *s, char *endpoint, int jobid, +makeActivityEPR(struct soap *s, char *endpoint, char *jobid, struct wsa__EndpointReferenceType *epr) { static char fname[] = "makeActivityEPR"; - char id[64]; - sprintf(id, "%d", jobid); - memset(epr, 0, sizeof(wsa__EndpointReferenceType)); epr->Address = (wsa__AttributedURIType*)soap_malloc(s, sizeof(wsa__AttributedURIType)); @@ -734,25 +717,22 @@ return soap_receiver_fault(s, MEM_ALLOC, NULL); } memset(epr->Address, 0, sizeof(wsa__AttributedURIType)); - epr->Address->__item = (char*)soap_malloc(s, strlen(endpoint)+strlen(id)+2); + epr->Address->__item = (char*)soap_malloc(s, strlen(endpoint)+strlen(jobid)+2); if (epr->Address->__item == NULL) { return soap_receiver_fault(s, MEM_ALLOC, NULL); } - sprintf(epr->Address->__item, "%s/%s", endpoint, id); + sprintf(epr->Address->__item, "%s/%s", endpoint, jobid); return SOAP_OK; } int -makeActivityDomEPR(struct soap *s, char *endpoint, int jobid, +makeActivityDomEPR(struct soap *s, char *endpoint, char *jobid, struct soap_dom_element **ret) { - static char fname[] = "makeActivityEPR"; + static char fname[] = "makeActivityDomEPR"; struct soap_dom_element *activityid, *addr; - char id[64]; - sprintf(id, "%d", jobid); - activityid = (struct soap_dom_element*)soap_malloc(s, sizeof(struct soap_dom_element)); addr = (struct soap_dom_element*)soap_malloc(s, @@ -773,11 +753,11 @@ addr->name = soap_strdup(s, "Address"); addr->nstr = soap_strdup(s, WSA_NS); - addr->data = (char*)soap_malloc(s, strlen(endpoint) + strlen(id) + 2); + addr->data = (char*)soap_malloc(s, strlen(endpoint) + strlen(jobid) + 2); if (!addr->name || !addr->nstr || !addr->data) { return soap_receiver_fault(s, MEM_ALLOC, NULL); } - sprintf(addr->data, "%s/%s", endpoint, id); + sprintf(addr->data, "%s/%s", endpoint, jobid); addr->soap = s; addr->prnt = activityid; @@ -785,99 +765,9 @@ return SOAP_OK; } -int -getContainedResources(struct soap *s, - struct bes__FactoryResourceAttributesDocumentType *attrs, - int return_hosts) -{ - static char fname[] = "getContainedResources"; - struct soap_dom_element *contained_resources; - struct bes__BasicResourceAttributesDocumentType *resource; - int num_contained_resources = 0; - struct hostInfo *hinfo; - char *cpuarch, *osname, *osver; - int numhosts = 0, numres = 0; - int i, j; - - if (!s || !attrs) { - return BESE_BAD_ARG; - } - - hinfo = ls_gethostinfo(NULL, &numhosts, NULL, 0, 0); - if (hinfo == NULL) { - fprintf(stderr, "%s: ls_gethostinfo error: %s\n", fname, ls_sysmsg()); - return BESE_BACKEND; - } - for (i = 0; i < numhosts; i++) { - if (hinfo[i].maxCpus == 0) { - /* host is unavailable at this time */ - continue; - } - num_contained_resources++; - } - - if (return_hosts) { - contained_resources = (struct soap_dom_element*)soap_malloc(s, - sizeof(struct soap_dom_element)*num_contained_resources); - if (!contained_resources) { - return BESE_MEM_ALLOC; - } - memset(contained_resources, 0, sizeof(struct soap_dom_element) - *num_contained_resources); - for (j = 0, i = 0; i < numhosts; i++) { - if (hinfo[i].maxCpus == 0) { - continue; - } - resource = (struct bes__BasicResourceAttributesDocumentType*)soap_malloc( - s, sizeof(struct bes__BasicResourceAttributesDocumentType)); - if (!resource) { - return BESE_MEM_ALLOC; - } - memset(resource, 0, - sizeof(struct bes__BasicResourceAttributesDocumentType)); - - resource->ResourceName = soap_strdup(s, hinfo[i].hostName); - if (!resource->ResourceName) { - return BESE_MEM_ALLOC; - } - - resource->CPUCount = (double*)soap_malloc(s, sizeof(double)); - if (!resource->CPUCount) { - return BESE_MEM_ALLOC; - } - *resource->CPUCount = (double)hinfo[i].maxCpus; - - resource->PhysicalMemory = (double*)soap_malloc(s, sizeof(double)); - if (!resource->PhysicalMemory) { - return BESE_MEM_ALLOC; - } - *resource->PhysicalMemory = 1024.0*1024.0*(double)hinfo[i].maxMem; - - resource->VirtualMemory = (double*)soap_malloc(s, sizeof(double)); - if (!resource->VirtualMemory) { - return BESE_MEM_ALLOC; - } - *resource->VirtualMemory = 1024.0*1024.0*(double)hinfo[i].maxSwap; - - contained_resources[j].type - = SOAP_TYPE_bes__BasicResourceAttributesDocumentType; - contained_resources[j].node = resource; - contained_resources[j].soap = s; - j++; - } - attrs->ContainedResource = contained_resources; - attrs->__sizeContainedResource = j; - } - - attrs->TotalNumberOfContainedResources = num_contained_resources; - - return BESE_OK; -} - - int getJobIdFromEPR(struct soap *s, struct wsa__EndpointReferenceType *epr, - int *jobid) + char **jobid) { static char fname[] = "getJobIdFromEPR"; char *cp; @@ -891,7 +781,8 @@ if (!cp) { return -1; } - *jobid = atoi(++cp); + cp++; + *jobid = soap_strdup(s, cp); return 0; } Modified: trunk/besserver/faults.h =================================================================== --- trunk/besserver/faults.h 2008-09-11 23:22:27 UTC (rev 53) +++ trunk/besserver/faults.h 2008-09-23 01:13:18 UTC (rev 54) @@ -44,6 +44,7 @@ #define UNKNOWN_ERROR "Unknown error" #define ELEMENT_UNSUPPORTED "Element is unsupported" #define ELEMENT_UNKNOWN "Element is unrecognized" +#define BACKEND_ERROR "Failed in a call to the backend resource manager" #define BES_FAULT_NOT_AUTHORIZED "bes:NotAuthorizedFault" #define BES_FAULT_NOT_ACCEPTING "bes:NotAcceptingNewActivitiesFault" Modified: trunk/besserver/job.c =================================================================== --- trunk/besserver/job.c 2008-09-11 23:22:27 UTC (rev 53) +++ trunk/besserver/job.c 2008-09-23 01:13:18 UTC (rev 54) @@ -753,10 +753,11 @@ } struct soap_dom_element * -getHPCProfileApplication(struct soap *s, struct jobInfoEnt *job) +getHPCProfileApplication(struct soap *s, struct jobcard *job) { struct soap_dom_element *dom, *cur, *next; - char *nstr, *cp, **cpp, *command; + char *nstr; + int i; nstr = soap_strdup(s, JSDL_HPCPA_NS); if (!nstr) { @@ -775,10 +776,6 @@ return NULL; } - command = soap_strdup(s, job->submit.command); - if (!command) { - return NULL; - } cur = (struct soap_dom_element*)soap_malloc(s, sizeof(struct soap_dom_element)); if (cur == NULL) { @@ -791,15 +788,13 @@ if (!cur->name) { return NULL; } - cpp = &command; - cp = strsep(cpp, " \t"); - cur->data = soap_strdup(s, cp); + cur->data = soap_strdup(s, job->executable); if (!cur->data) { return NULL; } dom->elts = cur; - while (cp = strsep(cpp, " \t")) { + for (i = 0; i < job->num_args; i++ ) { next = (struct soap_dom_element*)soap_malloc(s, sizeof(struct soap_dom_element)); if (next == NULL) { @@ -812,7 +807,7 @@ if (!next->name) { return NULL; } - next->data = soap_strdup(s, cp); + next->data = soap_strdup(s, job->args[i]); if (!next->data) { return NULL; } @@ -820,7 +815,7 @@ cur = next; } - if (job->submit.inFile) { + if (job->input) { next = (struct soap_dom_element*)soap_malloc(s, sizeof(struct soap_dom_element)); if (next == NULL) { @@ -833,7 +828,7 @@ if (!next->name) { return NULL; } - next->data = soap_strdup(s, job->submit.inFile); + next->data = soap_strdup(s, job->input); if (!next->data) { return NULL; } @@ -841,7 +836,7 @@ cur = next; } - if (job->submit.outFile) { + if (job->output) { next = (struct soap_dom_element*)soap_malloc(s, sizeof(struct soap_dom_element)); if (next == NULL) { @@ -854,7 +849,7 @@ if (!next->name) { return NULL; } - next->data = soap_strdup(s, job->submit.outFile); + next->data = soap_strdup(s, job->output); if (!next->data) { return NULL; } @@ -862,7 +857,7 @@ cur = next; } - if (job->submit.errFile) { + if (job->error) { next = (struct soap_dom_element*)soap_malloc(s, sizeof(struct soap_dom_element)); if (next == NULL) { @@ -875,7 +870,7 @@ if (!next->name) { return NULL; } - next->data = soap_strdup(s, job->submit.errFile); + next->data = soap_strdup(s, job->error); if (!next->data) { return NULL; } @@ -883,7 +878,7 @@ cur = next; } - if (job->execCwd) { + if (job->wd) { next = (struct soap_dom_element*)soap_malloc(s, sizeof(struct soap_dom_element)); if (next == NULL) { @@ -896,7 +891,7 @@ if (!next->name) { return NULL; } - next->data = soap_strdup(s, job->execCwd); + next->data = soap_strdup(s, job->wd); if (!next->data) { return NULL; } @@ -904,7 +899,7 @@ cur = next; } - if (job->execUsername) { + if (job->username) { next = (struct soap_dom_element*)soap_malloc(s, sizeof(struct soap_dom_element)); if (next == NULL) { @@ -917,7 +912,7 @@ if (!next->name) { return NULL; } - next->data = soap_strdup(s, job->execUsername); + next->data = soap_strdup(s, job->username); if (!next->data) { return NULL; } @@ -929,7 +924,7 @@ } int -getJSDLFromJobInfo(struct soap *s, struct jobInfoEnt *job, +getJSDLFromJobInfo(struct soap *s, struct jobcard *job, struct jsdl__JobDefinition_USCOREType **jsdl_return) { struct jsdl__JobDefinition_USCOREType *jsdl; @@ -975,38 +970,38 @@ memset(tcpu, 0, sizeof(struct jsdl__RangeValue_USCOREType)); memset(exact, 0, sizeof(struct jsdl__Exact_USCOREType)); - ident->jsdl__JobName = soap_strdup(s, job->submit.jobName); + ident->jsdl__JobName = soap_strdup(s, job->jobname); ident->__sizeJobProject = 1; ident->jsdl__JobProject = (char**)soap_malloc(s, sizeof(char*)); - cp = soap_strdup(s, job->submit.projectName); + cp = soap_strdup(s, job->jobproject); if (!ident->jsdl__JobName || !ident->jsdl__JobProject || !cp) { return soap_receiver_fault(s, MEM_ALLOC, NULL); } ident->jsdl__JobProject[0] = cp; jdesc->jsdl__JobIdentification = ident; - if (job->numExHosts) { - hosts->__sizeHostName = job->numExHosts; + if (job->num_hostnames) { + hosts->__sizeHostName = job->num_hostnames; hosts->jsdl__HostName = (char**)soap_malloc(s, sizeof(char*) - *job->numExHosts); + *job->num_hostnames); if (!hosts->jsdl__HostName) { return soap_receiver_fault(s, MEM_ALLOC, NULL); } - for (i = 0; i < job->numExHosts; i++) { - hosts->jsdl__HostName[i] = soap_strdup(s, job->exHosts[i]); + for (i = 0; i < job->num_hostnames; i++) { + hosts->jsdl__HostName[i] = soap_strdup(s, job->hostnames[i]); if (hosts->jsdl__HostName[i] == NULL) { return soap_receiver_fault(s, MEM_ALLOC, NULL); } } res->jsdl__CandidateHosts = hosts; - exact->__item = job->numExHosts; + exact->__item = job->num_hostnames; } else { exact->__item = 0; } tcpu->Exact = exact; tcpu->__sizeExact = 1; res->jsdl__TotalCPUCount = tcpu; - if (job->submit.options & SUB_EXCLUSIVE) { + if (job->exclusive) { res->jsdl__ExclusiveExecution = (enum xsd__boolean*)soap_malloc(s, sizeof(enum xsd__boolean)); if (!res->jsdl__ExclusiveExecution) { @@ -1028,431 +1023,3 @@ return SOAP_OK; } -int -runBsubScriptAsUser(char *scriptname, char *user) -{ - static char fname[] = "runBsubScriptAsUser"; - FILE *fp; - pid_t pid; - int pfd[2], jobid = 0; - struct passwd *pw; - char *arg0, buf[512]; - - if (!scriptname || !user) { - return -1; - } - - if ((pw = getpwnam(user)) == NULL) { - fprintf(stderr, "%s: couldn't get user %s from passwd\n", fname, user); - return -1; - } - - if (pipe(pfd) < 0) { - perror("runBsubScriptAsUser: pipe"); - return -1; - } - - if ((pid = fork()) < 0) { - perror("runBsubScriptAsUser: fork"); - return -1; - } - - if (pid == 0) { - /* child process */ - close(pfd[0]); - if (pfd[1] != STDOUT_FILENO) { - if (dup2(pfd[1], STDOUT_FILENO) != STDOUT_FILENO) { - perror("runBsubScriptAsUser (child): dup2"); - _exit(1); - } - close(pfd[1]); - } - if (seteuid(0)) { - perror("runBsubScriptAsUser (child): seteuid 0"); - _exit(1); - } - if (setgid(pw->pw_gid)) { - perror("runBsubScriptAsUser (child): setgid"); - _exit(1); - } - if (setuid(pw->pw_uid)) { - perror("runBsubScriptAsUser (child): setuid"); - _exit(1); - } - arg0 = strrchr(scriptname, '/'); - if (arg0) arg0++; - execl(scriptname, arg0, NULL); - perror("runBsubScriptAsUser (child): execl"); - _exit(1); - } - - /* In the parent */ - close(pfd[1]); - fp = fdopen(pfd[0], "r"); - if (fp == NULL) { - perror("runBsubScriptAsUser: fdopen"); - } - while (fgets(buf, 512, fp)) { - sscanf(buf, "Job <%d> is submitted to default queue <%*s>.\n", &jobid); - } - fclose(fp); - - if (waitpid(pid, NULL, 0) < 0) { - perror("runBsubScriptAsUser: waitpid"); - return -1; - } - - return jobid; -} - -int -createJobWrapperScript(struct jobcard *jc, char *osuser, char *scriptname, int namelen) -{ - static char fname[] = "createJobWrapperScript"; - char wrappername[MAXPATHLEN]; - FILE *wrapper; - int fd, i; - struct passwd *pw; - uid_t service_uid; - struct fileStage *file; - char *cp; - - if (!jc || !osuser || !scriptname) { - return BESE_OTHER; - } - - if ((pw = getpwnam(osuser)) == NULL) { - fprintf(stderr, "%s: couldn't get user %s from passwd\n", fname, osuser); - return BESE_BAD_ARG; - } - - service_uid = geteuid(); - - if (seteuid(0)) { - perror("createJobWrapperScript: seteuid 0 (1)"); - return BESE_SYS_ERR; - } - - if (seteuid(pw->pw_uid)) { - perror("createJobWrapperScript: seteuid user"); - return BESE_SYS_ERR; - } - - if (strlen(pw->pw_dir) + strlen("/jobscript.XXXXXX") + 1 > MAXPATHLEN) { - fprintf(stderr, "%s: cannot generate wrapper script: path too long\n", fname); - return BESE_SYS_ERR; - } - - sprintf(wrappername, "%s/jobscript.XXXXXX", pw->pw_dir); - fd = mkstemp(wrappername); - if (fd == -1) { - perror("createJobWrapperScript: mkstemp"); - return BESE_SYS_ERR; - } - - if (fchmod(fd, S_IRWXU)) { - perror("createJobWrapperScript: fchmod"); - unlink(wrappername); - return BESE_SYS_ERR; - } - - wrapper = fdopen(fd, "w"); - if (wrapper == NULL) { - perror("createJobWrapperScript: fdopen"); - unlink(wrappername); - return BESE_SYS_ERR; - } - - fprintf(wrapper, "#!/bin/sh\n"); - - file = jc->files; - while (file) { - if (file->source) { - cp = strstr(file->source, "ftp://"); - if (!cp) { - fprintf(stderr, "%s: malformed source URI for file transfer %s\n", fname, file->source); - fprintf(stderr, "%s: only support ftp URIs at this time\n", fname); - unlink(wrappername); - return BESE_OTHER; - } - cp = cp + strlen("ftp://"); - - fprintf(wrapper, "%s -o %s ftp://", FTP_PROGRAM, file->filename); - if (file->credential) { - fprintf(wrapper, "%s:%s@", file->credential->username, file->credential->password); - } - fprintf(wrapper, "%s\n", cp); - } - file = file->next; - } - - if (jc->executable) { - fprintf(wrapper, "%s", jc->executable); - } - for (i = 0; i < jc->num_args; i++) { - fprintf(wrapper, " %s", jc->args[i]); - } - fprintf(wrapper, "\n"); - - fprintf(wrapper, "rc=$?\n"); - - file = jc->files; - while (file) { - if (file->target) { - cp = strstr(file->target, "ftp://"); - if (!cp) { - fprintf(stderr, "%s: malformed target URI for file transfer %s\n", fname, file->target); - fprintf(stderr, "%s: only support ftp URIs at this time\n", fname); - unlink(wrappername); - return BESE_OTHER; - } - cp = cp + strlen("ftp://"); - - fprintf(wrapper, "%s -u ftp://", FTP_PROGRAM); - if (file->credential) { - fprintf(wrapper, "%s:%s@", file->credential->username, file->credential->password); - } - fprintf(wrapper, "%s %s\n", cp, file->filename); - } - file = file->next; - } - - fprintf(wrapper, "rm $0\n"); - - fprintf(wrapper, "exit $rc\n"); - - fclose(wrapper); - - if (seteuid(0)) { - perror("createJobWrapperScript: seteuid 0 (2)"); - unlink(wrappername); - return BESE_SYS_ERR; - } - - if (seteuid(service_uid)) { - perror("createJobWrapperScript: seteuid service_uid"); - unlink(wrappername); - return BESE_SYS_ERR; - } - - strncpy(scriptname, wrappername, namelen-1); - - return BESE_OK; -} - -int -submitLSFJob(struct jobcard *jc, int *return_jobid, char *osuser) -{ - static char fname[] = "submitLSFJob"; - char scriptname[MAXPATHLEN], wrappername[MAXPATHLEN]; - char buf[512]; - int fd, i, rc, jobid = 0, rr = 0; - FILE *script; - struct envvar *cur; - - fprintf(stderr, "In submitLSFJob...\n"); - - if (!jc || !jc->executable) { - fprintf(stderr, "%s: Need to have the executable name\n", fname); - return BESE_OTHER; - } - if (!osuser) { - fprintf(stderr, "%s: Need to have the os user\n", fname); - return BESE_OTHER; - } - - strcpy(scriptname, "/tmp/besserver.XXXXXX"); - fd = mkstemp(scriptname); - if (fd == -1) { - perror("submitLSFJob: mkstemp"); - return BESE_OTHER; - } - script = fdopen(fd, "w"); - if (script == NULL) { - perror("submitLSFJob: fdopen"); - return BESE_OTHER; - } - - fprintf(script, "#!/bin/sh\n"); - if (jc->wd) - fprintf(script, "LSB_JOB_LONG_CWD=%s; export LSB_JOB_LONG_CWD\n", - jc->wd); - for (cur = jc->environment; cur; cur = cur->next) { - fprintf(script, "%s=%s; export %s\n", cur->name, cur->val, cur->name); - } - fprintf(script, "bsub "); - if (jc->appname) { - fprintf(script, "-a %s ", jc->appname); - if (LSF_VERSION >= 17) { - fprintf(script, "-app %s ", jc->appname); - } - } - if (jc->jobname) - fprintf(script, "-J %s ", jc->jobname); - if (jc->jobproject) - fprintf(script, "-P %s ", jc->jobproject); - if (jc->num_hostnames) { - fprintf(script, "-m \""); - for (i = 0; i < jc->num_hostnames; i++) - fprintf(script, "%s ", jc->hostnames[i]); - fprintf(script, "\" "); - } - if (jc->exclusive) - fprintf(script, "-x "); - if (jc->tcpu) - fprintf(script, "-n %d ", jc->tcpu); - if (jc->input) - fprintf(script, "-i %s ", jc->input); - if (jc->output) - fprintf(script, "-o %s ", jc->output); - if (jc->error) - fprintf(script, "-e %s ", jc->error); - if (jc->osname) { - if (!rr) { - fprintf(script, "-R \""); - rr = 1; - } else { - fprintf(script, " && "); - } - fprintf(script, "osname == %s", jc->osname); - } - if (jc->osver) { - if (!rr) { - fprintf(script, "-R \""); - rr = 1; - } else { - fprintf(script, " && "); - } - fprintf(script, "osver == %s", jc->osver); - } - if (jc->cpuarch) { - if (!rr) { - fprintf(script, "-R \""); - rr = 1; - } else { - fprintf(script, " && "); - } - fprintf(script, "cpuarch == %s", jc->cpuarch); - } - if (rr) { - fprintf(script, "\" "); - } - - if ((rc = createJobWrapperScript(jc, osuser, wrappername, MAXPATHLEN)) != BESE_OK) { - fclose(script); - unlink(scriptname); - return rc; - } - - fprintf(script, "%s\n", wrappername); - - fclose(script); - - if (chmod(scriptname, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)) { - perror("submitLSFJob: chmod"); - unlink(wrappername); - unlink(scriptname); - return BESE_OTHER; - } - - jobid = runBsubScriptAsUser(scriptname, osuser); - - unlink(scriptname); - - if (jobid < 1) { - return BESE_OTHER; - } - - *return_jobid = jobid; - - return BESE_OK; -} - -int -terminateLSFJob(int jobid, char *osuser) -{ - static char fname[] = "terminateLSFJob"; - struct passwd *pw; - pid_t pid; - int pfd[2], lsb_rc = LSBE_NO_ERROR; - - if (!osuser) { - fprintf(stderr, "%s: need to provide os user", fname); - return BESE_BAD_ARG; - } - - if ((pw = getpwnam(osuser)) == NULL) { - fprintf(stderr, "%s: couldn't get user %s from passwd\n", fname, osuser); - return BESE_SYS_ERR; - } - - if (pipe(pfd) < 0) { - perror("terminateLSFJob: pipe"); - return BESE_SYS_ERR; - } - - if ((pid = fork()) < 0) { - perror("terminateLSFJob: fork"); - return BESE_SYS_ERR; - } - - if (pid == 0) { - /* child process */ - close(pfd[0]); - - if (seteuid(0)) { - perror("terminateLSFJob (child): seteuid 0"); - _exit(1); - } - if (setgid(pw->pw_gid)) { - perror("terminateLSFJob (child): setgid"); - _exit(1); - } - if (setuid(pw->pw_uid)) { - perror("terminateLSFJob (child): setuid"); - _exit(1); - } - - if (lsb_signaljob(jobid, SIGKILL)) { - lsb_perror("terminateLSFJob (child)"); - lsb_rc = lsberrno; - } - - if (write(pfd[1], (void*)&lsb_rc, sizeof(lsb_rc)) != sizeof(lsb_rc)) { - perror("terminateLSFJob (child): write"); - _exit(1); - } - _exit(0); - } - - /* In the parent */ - close(pfd[1]); - if (read(pfd[0], (void*)&lsb_rc, sizeof(lsb_rc)) != sizeof(lsb_rc)) { - perror("terminateLSFJob: read"); - lsb_rc = -1; - } - close(pfd[0]); - - if (waitpid(pid, NULL, 0) < 0) { - perror("terminateLSFJob: waitpid"); - return BESE_SYS_ERR; - } - - switch (lsb_rc) { - case -1: - return BESE_SYS_ERR; - break; - case LSBE_NO_ERROR: - return BESE_OK; - break; - case LSBE_PERMISSION: - return BESE_PERMISSION; - break; - case LSBE_NO_JOB: - return BESE_NO_ACTIVITY; - break; - default: - return BESE_BACKEND; - } -} - Modified: trunk/besserver/job.h =================================================================== --- trunk/besserver/job.h 2008-09-11 23:22:27 UTC (rev 53) +++ trunk/besserver/job.h 2008-09-23 01:13:18 UTC (rev 54) @@ -92,8 +92,6 @@ }; int processJobDefinition(struct soap*, struct soap_dom_element*, struct jobcard*); -int getJSDLFromJobInfo(struct soap*, struct jobInfoEnt*, struct jsdl__JobDefinition_USCOREType**); -int submitLSFJob(struct jobcard*, int*, char*); -int terminateLSFJob(int, char*); +int getJSDLFromJobInfo(struct soap*, struct jobcard*, struct jsdl__JobDefinition_USCOREType**); #endif /* _JOB_H */ Added: trunk/besserver/rm.h =================================================================== --- trunk/besserver/rm.h (rev 0) +++ trunk/besserver/rm.h 2008-09-23 01:13:18 UTC (rev 54) @@ -0,0 +1,54 @@ +#ifndef _RM_H +#define _RM_H + +#include "soapH.h" +#include "job.h" + +struct rm_resource { + char *ResourceName; + char *OperatingSystemName; + char *OperatingSystemVersion; + char *CPUArchitecture; + double *CPUCount; + double *CPUSpeed; + double *PhysicalMemory; + double *VirtualMemory; + struct rm_resource *next; +}; + +struct rm_filter { + char *user; + char *state; + long startRange; + long endRange; + char *startTime; + char *endTime; + char *CompactResources; +}; + +struct rm_job { + char *jobid; + struct rm_job *next; +}; + +struct rm_clusterInfo { + enum xsd__boolean IsAcceptingNewActivities; + char *CommonName; + char *LongDescription; + int num_extensions; + char **BESExtensions; + char *LocalResourceManagerType; +}; + +int rm_initialize(struct soap*, char*); +int rm_submitJob(struct soap*, struct jobcard*, char*, char**); +int rm_terminateJob(struct soap*, char*, char *); +int rm_getJobInfo(struct soap*, char*, char*, struct jobcard**); +int rm_getJobStatus(struct soap*, char*, char*, struct bes__ActivityStatusType**); +int rm_getResourceList(struct soap *, struct rm_filter*, struct rm_resource**, int*); +int rm_getJobsList(struct soap*, struct rm_filter*, struct rm_job**, int*); +int rm_getClusterInfo(struct soap*, struct rm_clusterInfo**); + + +#endif /* _RM_H */ + Added: trunk/besserver/rm_lsf.c =================================================================== --- trunk/besserver/rm_lsf.c (rev 0) +++ trunk/besserver/rm_lsf.c 2008-09-23 01:13:18 UTC (rev 54) @@ -0,0 +1,792 @@ +#include <stdlib.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <pwd.h> + +#include <lsf/lsf.h> +#include <lsf/lsbatch.h> + +#include "rm.h" + +int +rm_initialize(struct soap *s, char *servername) +{ + if (lsb_init("besserver")) { + lsb_perror("rm_initialize: lsb_init"); + return -1; + } + return 0; +} + +static int +createJobWrapperScript(struct jobcard *jc, char *osuser, char *scriptname, int namelen) +{ + static char fname[] = "createJobWrapperScript"; + char wrappername[MAXPATHLEN]; + FILE *wrapper; + int fd, i; + struct passwd *pw; + uid_t service_uid; + struct fileStage *file; + char *cp; + + if (!jc || !osuser || !scriptname) { + return BESE_OTHER; + } + + if ((pw = getpwnam(osuser)) == NULL) { + fprintf(stderr, "%s: couldn't get user %s from passwd\n", fname, osuser); + return BESE_BAD_ARG; + } + + service_uid = geteuid(); + + if (seteuid(0)) { + perror("createJobWrapperScript: seteuid 0 (1)"); + return BESE_SYS_ERR; + } + + if (seteuid(pw->pw_uid)) { + perror("createJobWrapperScript: seteuid user"); + return BESE_SYS_ERR; + } + + if (strlen(pw->pw_dir) + strlen("/jobscript.XXXXXX") + 1 > MAXPATHLEN) { + fprintf(stderr, "%s: cannot generate wrapper script: path too long\n", fname); + return BESE_SYS_ERR; + } + + sprintf(wrappername, "%s/jobscript.XXXXXX", pw->pw_dir); + fd = mkstemp(wrappername); + if (fd == -1) { + perror("createJobWrapperScript: mkstemp"); + return BESE_SYS_ERR; + } + + if (fchmod(fd, S_IRWXU)) { + perror("createJobWrapperScript: fchmod"); + unlink(wrappername); + return BESE_SYS_ERR; + } + + wrapper = fdopen(fd, "w"); + if (wrapper == NULL) { + perror("createJobWrapperScript: fdopen"); + unlink(wrappername); + return BESE_SYS_ERR; + } + + fprintf(wrapper, "#!/bin/sh\n"); + + file = jc->files; + while (file) { + if (file->source) { + cp = strstr(file->source, "ftp://"); + if (!cp) { + fprintf(stderr, "%s: malformed source URI for file transfer %s\n", fname, file->source); + fprintf(stderr, "%s: only support ftp URIs at this time\n", fname); + unlink(wrappername); + return BESE_OTHER; + } + cp = cp + strlen("ftp://"); + + fprintf(wrapper, "%s -o %s ftp://", FTP_PROGRAM, file->filename); + if (file->credential) { + fprintf(wrapper, "%s:%s@", file->credential->username, file->credential->password); + } + fprintf(wrapper, "%s\n", cp); + } + file = file->next; + } + + if (jc->executable) { + fprintf(wrapper, "%s", jc->executable); + } + for (i = 0; i < jc->num_args; i++) { + fprintf(wrapper, " %s", jc->args[i]); + } + fprintf(wrapper, "\n"); + + fprintf(wrapper, "rc=$?\n"); + + file = jc->files; + while (file) { + if (file->target) { + cp = strstr(file->target, "ftp://"); + if (!cp) { + fprintf(stderr, "%s: malformed target URI for file transfer %s\n", fname, file->target); + fprintf(stderr, "%s: only support ftp URIs at this time\n", fname); + unlink(wrappername); + return BESE_OTHER; + } + cp = cp + strlen("ftp://"); + + fprintf(wrapper, "%s -u ftp://", FTP_PROGRAM); + if (file->credential) { + fprintf(wrapper, "%s:%s@", file->credential->username, file->credential->password); + } + fprintf(wrapper, "%s %s\n", cp, file->filename); + } + file = file->next; + } + + fprintf(wrapper, "rm $0\n"); + + fprintf(wrapper, "exit $rc\n"); + + fclose(wrapper); + + if (seteuid(0)) { + perror("createJobWrapperScript: seteuid 0 (2)"); + unlink(wrappername); + return BESE_SYS_ERR; + } + + if (seteuid(service_uid)) { + perror("createJobWrapperScript: seteuid service_uid"); + unlink(wrappername); + return BESE_SYS_ERR; + } + + strncpy(scriptname, wrappername, namelen-1); + + return BESE_OK; +} + +static int +runBsubScriptAsUser(char *scriptname, char *user) +{ + static char fname[] = "runBsubScriptAsUser"; + FILE *fp; + pid_t pid; + int pfd[2], jobid = 0; + struct passwd *pw; + char *arg0, buf[512]; + + if (!scriptname || !user) { + return -1; + } + + if ((pw = getpwnam(user)) == NULL) { + fprintf(stderr, "%s: couldn't get user %s from passwd\n", fname, user); + return -1; + } + + if (pipe(pfd) < 0) { + perror("runBsubScriptAsUser: pipe"); + return -1; + } + + if ((pid = fork()) < 0) { + perror("runBsubScriptAsUser: fork"); + return -1; + } + + if (pid == 0) { + /* child process */ + close(pfd[0]); + if (pfd[1] != STDOUT_FILENO) { + if (dup2(pfd[1], STDOUT_FILENO) != STDOUT_FILENO) { + perror("runBsubScriptAsUser (child): dup2"); + _exit(1); + } + close(pfd[1]); + } + if (seteuid(0)) { + perror("runBsubScriptAsUser (child): seteuid 0"); + _exit(1); + } + if (setgid(pw->pw_gid)) { + perror("runBsubScriptAsUser (child): setgid"); + _exit(1); + } + if (setuid(pw->pw_uid)) { + perror("runBsubScriptAsUser (child): setuid"); + _exit(1); + } + arg0 = strrchr(scriptname, '/'); + if (arg0) arg0++; + execl(scriptname, arg0, NULL); + perror("runBsubScriptAsUser (child): execl"); + _exit(1); + } + + /* In the parent */ + close(pfd[1]); + fp = fdopen(pfd[0], "r"); + if (fp == NULL) { + perror("runBsubScriptAsUser: fdopen"); + } + while (fgets(buf, 512, fp)) { + sscanf(buf, "Job <%d> is submitted to default queue <%*s>.\n", &jobid); + } + fclose(fp); + + if (waitpid(pid, NULL, 0) < 0) { + perror("runBsubScriptAsUser: waitpid"); + return -1; + } + + return jobid; +} + +int +rm_submitJob(struct soap *s, struct jobcard *jc, + char *osuser, char **return_jobid) +{ + static char fname[] = "rm_submitJob"; + char scriptname[MAXPATHLEN], wrappername[MAXPATHLEN]; + char buf[512]; + int fd, i, rc, jobid = 0, rr = 0; + FILE *script; + struct envvar *cur; + + fprintf(stderr, "In rm_submitJob...\n"); + + if (!jc || !jc->executable) { + fprintf(stderr, "%s: Need to have the executable name\n", fname); + return BESE_OTHER; + } + if (!osuser) { + fprintf(stderr, "%s: Need to have the os user\n", fname); + return BESE_OTHER; + } + + strcpy(scriptname, "/tmp/besserver.XXXXXX"); + fd = mkstemp(scriptname); + if (fd == -1) { + perror("rm_submitJob: mkstemp"); + return BESE_OTHER; + } + script = fdopen(fd, "w"); + if (script == NULL) { + perror("rm_submitJob: fdopen"); + return BESE_OTHER; + } + + fprintf(script, "#!/bin/sh\n"); + if (jc->wd) + fprintf(script, "LSB_JOB_LONG_CWD=%s; export LSB_JOB_LONG_CWD\n", + jc->wd); + for (cur = jc->environment; cur; cur = cur->next) { + fprintf(script, "%s=%s; export %s\n", cur->name, cur->val, cur->name); + } + fprintf(script, "bsub "); + if (jc->appname) { + fprintf(script, "-a %s ", jc->appname); + if (LSF_VERSION >= 17) { + fprintf(script, "-app %s ", jc->appname); + } + } + if (jc->jobname) + fprintf(script, "-J %s ", jc->jobname); + if (jc->jobproject) + fprintf(script, "-P %s ", jc->jobproject); + if (jc->num_hostnames) { + fprintf(script, "-m \""); + for (i = 0; i < jc->num_hostnames; i++) + fprintf(script, "%s ", jc->hostnames[i]); + fprintf(script, "\" "); + } + if (jc->exclusive) + fprintf(script, "-x "); + if (jc->tcpu) + fprintf(script, "-n %d ", jc->tcpu); + if (jc->input) + fprintf(script, "-i %s ", jc->input); + if (jc->output) + fprintf(script, "-o %s ", jc->output); + if (jc->error) + fprintf(script, "-e %s ", jc->error); + if (jc->osname) { + if (!rr) { + fprintf(script, "-R \""); + rr = 1; + } else { + fprintf(script, " && "); + } + fprintf(script, "osname == %s", jc->osname); + } + if (jc->osver) { + if (!rr) { + fprintf(script, "-R \""); + rr = 1; + } else { + fprintf(script, " && "); + } + fprintf(script, "osver == %s", jc->osver); + } + if (jc->cpuarch) { + if (!rr) { + fprintf(script, "-R \""); + rr = 1; + } else { + fprintf(script, " && "); + } + fprintf(script, "cpuarch == %s", jc->cpuarch); + } + if (rr) { + fprintf(script, "\" "); + } + + if ((rc = createJobWrapperScript(jc, osuser, wrappername, MAXPATHLEN)) != BESE_OK) { + fclose(script); + unlink(scriptname); + return rc; + } + + fprintf(script, "%s\n", wrappername); + + fclose(script); + + if (chmod(scriptname, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)) { + perror("submitLSFJob: chmod"); + unlink(wrappername); + unlink(scriptname); + return BESE_OTHER; + } + + jobid = runBsubScriptAsUser(scriptname, osuser); + + unlink(scriptname); + + if (jobid < 1) { + return BESE_OTHER; + } + + sprintf(buf, "%ld", jobid); + *return_jobid = soap_strdup(s, buf); + if (!*return_jobid) { + return BESE_MEM_ALLOC; + } + + return BESE_OK; +} + +int +rm_terminateJob(struct soap *s, char *job_id, char *osuser) +{ + static char fname[] = "rm_terminateJob"; + struct passwd *pw; + pid_t pid; + int pfd[2], lsb_rc = LSBE_NO_ERROR; + LS_LONG_INT jobid; + + if (!job_id) { + fprintf(stderr, "%s: missing job id\n", fname); + return BESE_BAD_ARG; + } + jobid = strtol(job_id, NULL, 0); + if (errno == ERANGE || errno == EINVAL) { + fprintf(stderr, "%s: job id should be an integer\n", fname); + return BESE_BAD_ARG; + } + + if (!osuser) { + fprintf(stderr, "%s: need to provide os user\n", fname); + return BESE_BAD_ARG; + } + + if ((pw = getpwnam(osuser)) == NULL) { + fprintf(stderr, "%s: couldn't get user %s from passwd\n", fname, osuser); + return BESE_SYS_ERR; + } + + if (pipe(pfd) < 0) { + perror("rm_terminateJob: pipe"); + return BESE_SYS_ERR; + } + + if ((pid = fork()) < 0) { + perror("rm_terminateJob: fork"); + return BESE_SYS_ERR; + } + + if (pid == 0) { + /* child process */ + close(pfd[0]); + + if (seteuid(0)) { + perror("rm_terminateJob (child): seteuid 0"); + _exit(1); + } + if (setgid(pw->pw_gid)) { + perror("rm_terminateJob (child): setgid"); + _exit(1); + } + if (setuid(pw->pw_uid)) { + perror("rm_terminateJob (child): setuid"); + _exit(1); + } + + if (lsb_signaljob(jobid, SIGKILL)) { + lsb_perror("rm_terminateJob (child)"); + lsb_rc = lsberrno; + } + + if (write(pfd[1], (void*)&lsb_rc, sizeof(lsb_rc)) != sizeof(lsb_rc)) { + perror("rm_terminateJob (child): write"); + _exit(1); + } + _exit(0); + } + + /* In the parent */ + close(pfd[1]); + if (read(pfd[0], (void*)&lsb_rc, sizeof(lsb_rc)) != sizeof(lsb_rc)) { + perror("rm_terminateJob: read"); + lsb_rc = -1; + } + close(pfd[0]); + + if (waitpid(pid, NULL, 0) < 0) { + perror("rm_terminateJob: waitpid"); + return BESE_SYS_ERR; + } + + switch (lsb_rc) { + case -1: + return BESE_SYS_ERR; + break; + case LSBE_NO_ERROR: + return BESE_OK; + break; + case LSBE_PERMISSION: + return BESE_PERMISSION; + break; + case LSBE_NO_JOB: + return BESE_NO_ACTIVITY; + break; + default: + return BESE_BACKEND; + } +} + +int +rm_getJobStatus(struct soap *s, char *job_id, char *osuser, + struct bes__ActivityStatusType **job_status) +{ + struct jobInfoEnt *job; + struct bes__ActivityStatusType *status; + int rc; + LS_LONG_INT jobid; + + if (!job_id || !job_status) { + return BESE_BAD_ARG; + } + jobid = strtol(job_id, NULL, 0); + if (errno == ERANGE || errno == EINVAL) { + fprintf(stderr, "rm_getJobStatus: job id should be an integer\n"); + return BESE_BAD_ARG; + } + + rc = lsb_openjobinfo(jobid, NULL, "all", NULL, NULL, ALL_JOB); + if (rc == -1) { + if (lsberrno == LSBE_NO_JOB) { + return BESE_NO_ACTIVITY; + } + lsb_perror("rm_getJobStatus: lsb_openjobinfo"); + return BESE_BACKEND; + } + + job = lsb_readjobinfo(NULL); + if (job == NULL) { + lsb_perror("rm_getJobStatus: lsb_readjobinfo"); + lsb_closejobinfo(); + return BESE_BACKEND; + } + + status = (struct bes__ActivityStatusType*)soap_malloc(s, sizeof(struct bes__ActivityStatusType)); + if (status == NULL) { + return BESE_MEM_ALLOC; + } + memset(status, 0, sizeof(struct bes__ActivityStatusType)); + + if (IS_PEND(job->status)) { + status->state = Pe... [truncated message content] |
From: <cs...@us...> - 2008-09-11 23:22:16
|
Revision: 53 http://bespp.svn.sourceforge.net/bespp/?rev=53&view=rev Author: csmith Date: 2008-09-11 23:22:27 +0000 (Thu, 11 Sep 2008) Log Message: ----------- - removed remote application stuff that was hacked for SC06 demo Modified Paths: -------------- trunk/besserver/besserver.c Property Changed: ---------------- trunk/besserver/ Property changes on: trunk/besserver ___________________________________________________________________ Modified: svn:ignore - server.pem .project .cproject .gdb_history .settings *.log soapServer.c soapC.c soapH.h soapStub.h bes-factory.h BESFactoryBinding.nsmap bes-factory.xsd bes-factory.wsdl besserver + server.pem .project .cproject .gdb_history .settings *.log soapServer.c soapC.c soapH.h soapStub.h bes-factory.h BESFactoryBinding.nsmap bes-factory.xsd bes-factory.wsdl besserver .job.h.swp Modified: trunk/besserver/besserver.c =================================================================== --- trunk/besserver/besserver.c 2008-09-11 21:29:53 UTC (rev 52) +++ trunk/besserver/besserver.c 2008-09-11 23:22:27 UTC (rev 53) @@ -56,8 +56,6 @@ int makeActivityEPR(struct soap*, char *, int, struct wsa__EndpointReferenceType*); int makeActivityDomEPR(struct soap*, char *, int, struct soap_dom_element**); int getJobIdFromEPR(struct soap*, struct wsa__EndpointReferenceType*, int*); -int isRemoteApplication(struct jobcard*); -int getRemoteEPR(struct soap*, int, struct soap_dom_element**); int getContainedResources(struct soap*, struct bes__FactoryResourceAttributesDocumentType*, int); int processHeaders(struct soap*, char*, int); @@ -66,11 +64,6 @@ char *generic_user = NULL; uid_t service_uid; -char *remoteApplications[] = { - "WRF", - NULL -}; - struct Namespace default_namespaces[] = { {"SOAP-ENV", SOAP_ENV_NS, SOAP_ENV_NS_WILDCARD, NULL}, {"wsse", WSSE_NS, NULL, NULL}, @@ -304,18 +297,9 @@ } } - /* This is a special case for the SC06 demo where the remote */ - /* EPR needed to be returned to the client to show job forwarding */ - if (isRemoteApplication(jc)) { - rc = getRemoteEPR(s, jobid, &dom); - if (rc) { - return rc; - } - } else { - rc = makeActivityDomEPR(s, service_endpoint, jobid, &dom); - if (rc) { - return rc; - } + rc = makeActivityDomEPR(s, service_endpoint, jobid, &dom); + if (rc) { + return rc; } resp->__size = 1; @@ -913,75 +897,6 @@ } int -isRemoteApplication(struct jobcard *jc) -{ - int i = 0; - - if (!jc || !jc->appname) - return 0; - - while (remoteApplications[i]) { - if (!strcmp(jc->appname, remoteApplications[i])) - return 1; - i++; - } - - return 0; -} - -int -getRemoteEPR(struct soap *s, int jobid, struct soap_dom_element **ret) -{ - struct jobExternalMsgReq req; - struct jobExternalMsgReply rsp; - struct soap_dom_element *dom; - int eprfd, ntries = 20; - - memset(&req, 0, sizeof(struct jobExternalMsgReq)); - memset(&rsp, 0, sizeof(struct jobExternalMsgReply)); - - req.options = EXT_MSG_READ|EXT_ATTA_READ; - req.jobId = jobid; - - while (ntries--) { - eprfd = lsb_readjobmsg(&req, &rsp); - if (eprfd == -1 && lsberrno != LSBE_BAD_EXT_MSGID) { - lsb_perror("lsb_readjobmsg"); - return soap_receiver_fault(s, LSF_LIB_ERROR, NULL); - } else if (eprfd > 0) { - break; - } - sleep(2); - } - if (eprfd <= 0) { - return soap_receiver_fault(s, "Cannot get remote EPR", NULL); - } - - dom = (struct soap_dom_element*)soap_malloc(s, - sizeof(struct soap_dom_element)); - if (dom == NULL) { - return soap_receiver_fault(s, MEM_ALLOC, NULL); - } - memset(dom, 0, sizeof(struct soap_dom_element)); - - dom->soap = soap_new1(SOAP_DOM_TREE|SOAP_C_UTFSTRING); - if (dom->soap == NULL) { - return soap_receiver_fault(s, MEM_ALLOC, NULL); - } - dom->soap->recvfd = eprfd; - if (soap_begin_recv(dom->soap) || soap_in_xsd__anyType(dom->soap, NULL, - dom, NULL) == NULL || soap_end_recv(dom->soap)) { - soap_print_fault(dom->soap, stderr); - return soap_receiver_fault(s, "Error getting remote EPR", NULL); - } - dom->soap = s; - - *ret = dom; - - return SOAP_OK; -} - -int processHeaders(struct soap *s, char *username, int usernamelen) { int rc = SOAP_OK; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-09-11 21:29:44
|
Revision: 52 http://bespp.svn.sourceforge.net/bespp/?rev=52&view=rev Author: csmith Date: 2008-09-11 21:29:53 +0000 (Thu, 11 Sep 2008) Log Message: ----------- - process headers in separate function - added created/expired timestamps to WS-Security header on reply - GetFactoryAttributesDocument now returns list of ContainedResources Modified Paths: -------------- trunk/besclient/libbes.c trunk/besserver/auth.c trunk/besserver/auth.h trunk/besserver/besserver-typemap.dat trunk/besserver/besserver.c Modified: trunk/besclient/libbes.c =================================================================== --- trunk/besclient/libbes.c 2008-05-19 15:33:33 UTC (rev 51) +++ trunk/besclient/libbes.c 2008-09-11 21:29:53 UTC (rev 52) @@ -47,6 +47,7 @@ struct Namespace default_namespaces[] = { {"SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org/*/soap-envelope", NULL}, + {"wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", NULL, NULL}, {"wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", NULL, NULL}, {"wsa", "http://www.w3.org/2005/08/addressing", NULL, NULL}, {"bes", "http://schemas.ggf.org/bes/2006/08/bes-factory", NULL, NULL}, @@ -145,25 +146,34 @@ setErrorString(context, context->soap, BESE_SOAP_ERR); return BESE_SOAP_ERR; } + if (soap_wsse_add_Timestamp(soap, NULL, 60)) { + setErrorString(context, context->soap, BESE_SOAP_ERR); + return BESE_SOAP_ERR; + } } if (x509cert) { + if (context->x509cert) free(context->x509cert); context->x509cert = strdup(x509cert); } if (x509pass) { + if (context->x509pass) free(context->x509pass); context->x509pass = strdup(x509pass); } if (capath) { + if (context->capath) free(context->capath); context->capath = strdup(capath); } if (user) { + if (context->user) free(context->user); context->user = strdup(user); } if (pass) { + if (context->pass) free(context->pass); context->pass = strdup(pass); } @@ -183,6 +193,10 @@ setErrorString(context, context->soap, BESE_SOAP_ERR); return BESE_SOAP_ERR; } + if (soap_wsse_add_Timestamp(context->soap, NULL, 60)) { + setErrorString(context, context->soap, BESE_SOAP_ERR); + return BESE_SOAP_ERR; + } return BESE_OK; } Modified: trunk/besserver/auth.c =================================================================== --- trunk/besserver/auth.c 2008-05-19 15:33:33 UTC (rev 51) +++ trunk/besserver/auth.c 2008-09-11 21:29:53 UTC (rev 52) @@ -104,7 +104,7 @@ } int -authenticate(struct soap *s, char *username, int namelen) +authenticate(struct soap *s, char *username, int namelen, int *sslauth) { static char fname[] = "authenticate"; struct _wsse__UsernameToken *token; @@ -117,6 +117,7 @@ clientcert = SSL_get_peer_certificate(s->ssl); if (clientcert) { + if (sslauth) *sslauth = 1; if (SSL_get_verify_result(s->ssl) != X509_V_OK) { return soap_wsse_fault(s, wsse__FailedAuthentication, NULL); } @@ -135,7 +136,8 @@ return SOAP_OK; } - + if (sslauth) *sslauth = 0; + /* no X.509 certificate ... look for WS-Security tokens */ token = soap_wsse_UsernameToken(s, NULL); if (token) { Modified: trunk/besserver/auth.h =================================================================== --- trunk/besserver/auth.h 2008-05-19 15:33:33 UTC (rev 51) +++ trunk/besserver/auth.h 2008-09-11 21:29:53 UTC (rev 52) @@ -34,6 +34,6 @@ char *password; }; -int authenticate(struct soap*, char *, int); +int authenticate(struct soap*, char *, int, int*); #endif /*AUTH_H_*/ Modified: trunk/besserver/besserver-typemap.dat =================================================================== --- trunk/besserver/besserver-typemap.dat 2008-05-19 15:33:33 UTC (rev 51) +++ trunk/besserver/besserver-typemap.dat 2008-09-11 21:29:53 UTC (rev 52) @@ -76,7 +76,7 @@ SOAP_ENV__Header =\ struct SOAP_ENV__Header\n\ {\n\ - mustUnderstand _wsse__Security *wsse__Security 0;\n\ + _wsse__Security *wsse__Security 0;\n\ _wsa__MessageID wsa__MessageID 0;\n\ _wsa__RelatesTo *wsa__RelatesTo 0;\n\ _wsa__From *wsa__From 0;\n\ Modified: trunk/besserver/besserver.c =================================================================== --- trunk/besserver/besserver.c 2008-05-19 15:33:33 UTC (rev 51) +++ trunk/besserver/besserver.c 2008-09-11 21:29:53 UTC (rev 52) @@ -59,6 +59,7 @@ int isRemoteApplication(struct jobcard*); int getRemoteEPR(struct soap*, int, struct soap_dom_element**); int getContainedResources(struct soap*, struct bes__FactoryResourceAttributesDocumentType*, int); +int processHeaders(struct soap*, char*, int); char *service_endpoint = NULL; @@ -271,13 +272,10 @@ fprintf(stderr, "In %s...\n", fname); - if ((rc = authenticate(s, username, USERNAMELEN))) { - clear_header(s); + if ((rc = processHeaders(s, username, USERNAMELEN))) { return rc; } - clear_header(s); - jc = (struct jobcard*)soap_malloc(s, sizeof(struct jobcard)); if (jc == NULL) { return soap_receiver_fault(s, MEM_ALLOC, NULL); @@ -340,12 +338,10 @@ fprintf(stderr, "In %s...\n", fname); - if ((rc = authenticate(s, username, USERNAMELEN))) { + if ((rc = processHeaders(s, username, USERNAMELEN))) { return rc; } - clear_header(s); - if (req->__sizeActivityIdentifier == 0) { resp->__sizeResponse = 0; resp->Response = NULL; @@ -420,12 +416,10 @@ fprintf(stderr, "In %s...\n", fname); - if ((rc = authenticate(s, username, USERNAMELEN))) { + if ((rc = processHeaders(s, username, USERNAMELEN))) { return rc; } - clear_header(s); - if (req->__sizeActivityIdentifier == 0) { resp->__sizeResponse = 0; resp->Response = NULL; @@ -524,12 +518,10 @@ fprintf(stderr, "In %s...\n", fname); - if ((rc = authenticate(s, username, USERNAMELEN))) { + if ((rc = processHeaders(s, username, USERNAMELEN))) { return rc; } - clear_header(s); - if (req->__sizeActivityIdentifier == 0) { resp->__sizeResponse = 0; resp->Response = NULL; @@ -608,7 +600,7 @@ { static char fname[] = "__bes__GetFactoryAttributesDocument"; struct bes__FactoryResourceAttributesDocumentType *attrs; - struct wsa_EndpointReferenceType *epr; + struct wsa_EndpointReferenceType *epr; struct jobInfoEnt *jinfo; char *clustername; int num_jobs, i, rc; @@ -616,12 +608,10 @@ fprintf(stderr, "In %s....\n", fname); - if ((rc = authenticate(s, username, USERNAMELEN))) { + if ((rc = processHeaders(s, username, USERNAMELEN))) { return rc; } - clear_header(s); - attrs = (struct bes__FactoryResourceAttributesDocumentType*)soap_malloc(s, sizeof(struct bes__FactoryResourceAttributesDocumentType)); if (attrs == NULL) { @@ -680,7 +670,7 @@ } /* TotalNumberOfContainedResources and ContainedResource */ - if ((rc = getContainedResources(s, attrs, 0))) { + if ((rc = getContainedResources(s, attrs, 1))) { if (rc == BESE_MEM_ALLOC) { return soap_receiver_fault(s, MEM_ALLOC, NULL); } @@ -716,8 +706,6 @@ resp->bes__FactoryResourceAttributesDocument = attrs; - clear_header(s); - return SOAP_OK; } @@ -853,6 +841,9 @@ memset(contained_resources, 0, sizeof(struct soap_dom_element) *num_contained_resources); for (j = 0, i = 0; i < numhosts; i++) { + if (hinfo[i].maxCpus == 0) { + continue; + } resource = (struct bes__BasicResourceAttributesDocumentType*)soap_malloc( s, sizeof(struct bes__BasicResourceAttributesDocumentType)); if (!resource) { @@ -990,6 +981,21 @@ return SOAP_OK; } +int +processHeaders(struct soap *s, char *username, int usernamelen) +{ + int rc = SOAP_OK; + int sslauth = 0; + + rc = authenticate(s, username, usernamelen, &sslauth); + clear_header(s); + if (!sslauth) { + soap_wsse_add_Timestamp(s, NULL, 30); + } + + return rc; +} + /* * Don't know why these aren't being generated, but .... */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-05-19 15:33:41
|
Revision: 51 http://bespp.svn.sourceforge.net/bespp/?rev=51&view=rev Author: csmith Date: 2008-05-19 08:33:33 -0700 (Mon, 19 May 2008) Log Message: ----------- minor fix Modified Paths: -------------- trunk/besclient/libbes.c Modified: trunk/besclient/libbes.c =================================================================== --- trunk/besclient/libbes.c 2008-05-18 00:46:57 UTC (rev 50) +++ trunk/besclient/libbes.c 2008-05-19 15:33:33 UTC (rev 51) @@ -295,11 +295,9 @@ tmpdom = rsp.__any; cleanDom(tmpdom); - soap_set_namespaces(s, epr_namespaces); epr = (struct bes_epr *)malloc(sizeof(struct bes_epr)); if (!epr) { - soap_set_namespaces(s, default_namespaces); setErrorString(context, NULL, BESE_MEM_ALLOC); ret = BESE_MEM_ALLOC; goto end; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-05-18 00:46:49
|
Revision: 50 http://bespp.svn.sourceforge.net/bespp/?rev=50&view=rev Author: csmith Date: 2008-05-17 17:46:57 -0700 (Sat, 17 May 2008) Log Message: ----------- fixed problems with EPR handling Modified Paths: -------------- trunk/besclient/bes.h trunk/besclient/besclient.c trunk/besclient/libbes.c Modified: trunk/besclient/bes.h =================================================================== --- trunk/besclient/bes.h 2008-05-16 17:45:10 UTC (rev 49) +++ trunk/besclient/bes.h 2008-05-18 00:46:57 UTC (rev 50) @@ -85,6 +85,7 @@ void bes_freeEPR(epr_t *epr); int bes_writeEPRToFile(struct bes_context *, char *, epr_t); int bes_readEPRFromFile(struct bes_context *, char *, epr_t *); +char *bes_getEPRString(epr_t); #endif /* _BES_H */ Modified: trunk/besclient/besclient.c =================================================================== --- trunk/besclient/besclient.c 2008-05-16 17:45:10 UTC (rev 49) +++ trunk/besclient/besclient.c 2008-05-18 00:46:57 UTC (rev 50) @@ -29,7 +29,6 @@ #include "bes.h" - char *readPassword(char *); void zeroPassword(char *); void usage(); @@ -43,236 +42,243 @@ exit(1); } -char *bes_activity_state[BES_State_Num] = {"Pending", "Running", "Cancelled", "Failed", "Finished"}; +char *bes_activity_state[BES_State_Num] = + { + "Pending", + "Running", + "Cancelled", + "Failed", + "Finished" + }; int main(int argc, char *argv[]) { - struct bes_context *ctx; - char *endpoint, *command, *user, *pass; - char *capath, *x509cert, *x509pass; - int ch, ret_code = 0; - epr_t endpointepr = NULL, activityepr = NULL; - - endpoint = "endpoint.xml"; - capath = "./certs"; - x509cert = NULL; - x509pass = NULL; - user = NULL; - pass = NULL; + struct bes_context *ctx; + char *endpoint, *command, *user, *pass; + char *capath, *x509cert, *x509pass; + int ch, ret_code = 0; + epr_t endpointepr = NULL, activityepr = NULL; + + endpoint = "endpoint.xml"; + capath = "./certs"; + x509cert = NULL; + x509pass = NULL; + user = NULL; + pass = NULL; + + while ((ch = getopt(argc, argv, "Vc:e:u:p:x:k:")) != -1) { + switch (ch) { + case 'c': + capath = optarg; + break; + case 'e': + endpoint = optarg; + break; + case 'u': + user = optarg; + break; + case 'p': + pass = optarg; + break; + case 'x': + x509cert = optarg; + break; + case 'k': + x509pass = optarg; + break; + case 'V': + printf("besclient, %s\n%s\n", VERSION_STRING, COPYRIGHT); + exit(0); + break; + case '?': + default: + usage(); + } + } + + if ((user && x509cert) || (!user && !x509cert)) { + fprintf(stderr, "You must specify only one of username or certificate file.\n"); + usage(); + } + + argc -= optind; + argv += optind; + + if (argc < 1) { + usage(); + } - while ((ch = getopt(argc, argv, "Vc:e:u:p:x:k:")) != -1) { - switch (ch) { - case 'c': - capath = optarg; - break; - case 'e': - endpoint = optarg; - break; - case 'u': - user = optarg; - break; - case 'p': - pass = optarg; - break; - case 'x': - x509cert = optarg; - break; - case 'k': - x509pass = optarg; - break; - case 'V': - printf("besclient, %s\n%s\n", VERSION_STRING, COPYRIGHT); - exit(0); - break; - case '?': - default: - usage(); - } - } + command = argv[0]; - if ((user && x509cert) || (!user && !x509cert)) { - fprintf(stderr, "You must specify only one of username or certificate file.\n"); - usage(); - } - - argc -= optind; - argv += optind; - - if (argc < 1) { - usage(); - } - - command = argv[0]; + if (bes_init(&ctx)) { + ret_code = 1; + goto end; + } - if (bes_init(&ctx)) { - ret_code = 1; - goto end; - } - - if (user) { - if (pass == NULL ) { - pass = readPassword("WS-Security password:"); + if (user) { + if (pass == NULL ) { + pass = readPassword("WS-Security password:"); + } } - } - else { - if (x509pass == NULL) { - x509pass = readPassword("Key passphrase:"); + else { + if (x509pass == NULL) { + x509pass = readPassword("Key passphrase:"); + } } - } - if (bes_security(ctx, x509cert, x509pass, capath, user, pass)) { - fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); - ret_code = 1; - goto end; - } + if (bes_security(ctx, x509cert, x509pass, capath, user, pass)) { + fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); + ret_code = 1; + goto end; + } - if (bes_readEPRFromFile(ctx, endpoint, &endpointepr)) { - fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); - ret_code = 1; - goto end; - } + if (bes_readEPRFromFile(ctx, endpoint, &endpointepr)) { + fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); + ret_code = 1; + goto end; + } - if (!strcmp(command, "status") - || !strcmp(command, "terminate") - || !strcmp(command, "activity") - || !strcmp(command, "poll")) { - if (bes_readEPRFromFile(ctx, argv[1], &activityepr)) { - fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); - ret_code = 1; - goto end; + if (!strcmp(command, "status") + || !strcmp(command, "terminate") + || !strcmp(command, "activity") + || !strcmp(command, "poll")) { + if (bes_readEPRFromFile(ctx, argv[1], &activityepr)) { + fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); + ret_code = 1; + goto end; + } } - } - if (!strcmp(command, "create")) { - epr_t new_activityepr; + if (!strcmp(command, "create")) { + epr_t new_activityepr; - if (bes_createActivity(ctx, endpointepr, argv[1], &new_activityepr)) { - fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); - ret_code = 1; - } - else { - printf("Successfully submitted activity. Wrote EPR to %s\n", argv[2]); - if (bes_writeEPRToFile(ctx, argv[2], new_activityepr)) { - fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); - ret_code = 1; - } + if (bes_createActivity(ctx, endpointepr, argv[1], &new_activityepr)) { + fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); + ret_code = 1; + } + else { + if (bes_writeEPRToFile(ctx, argv[2], new_activityepr)) { + fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); + ret_code = 1; + } + printf("Successfully submitted activity. Wrote EPR to %s\n", argv[2]); - bes_freeEPR(&new_activityepr); + bes_freeEPR(&new_activityepr); + } } - } - else if (!strcmp(command, "status")) { - struct bes_activity_status status; + else if (!strcmp(command, "status")) { + struct bes_activity_status status; - if (bes_getActivityStatuses(ctx, endpointepr, activityepr, &status)) { - fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); - ret_code = 1; - } - else { - printf("The state of the activity is: %s\n", bes_activity_state[status.state]); - if (status.substate) { - printf("The substate is %s\n", status.substate); - free(status.substate); - } - } + if (bes_getActivityStatuses(ctx, endpointepr, activityepr, &status)) { + fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); + ret_code = 1; + } + else { + printf("The state of the activity is: %s\n", bes_activity_state[status.state]); + if (status.substate) { + printf("The substate is %s\n", status.substate); + free(status.substate); + } + } - } - else if (!strcmp(command, "terminate")) { - if (bes_terminateActivities(ctx, endpointepr, activityepr)) { - printf("The activity was canceled\n"); } - else { - printf("The activity was not canceled\n"); - fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); - ret_code = 1; + else if (!strcmp(command, "terminate")) { + if (bes_terminateActivities(ctx, endpointepr, activityepr)) { + printf("The activity was canceled\n"); + } + else { + printf("The activity was not canceled\n"); + fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); + ret_code = 1; + } } - } - else if (!strcmp(command, "activity")) { - char *strDoc; + else if (!strcmp(command, "activity")) { + char *strDoc; - if (bes_getActivityDocuments(ctx, endpointepr, activityepr, &strDoc)) { - fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); - ret_code = 1; + if (bes_getActivityDocuments(ctx, endpointepr, activityepr, &strDoc)) { + fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); + ret_code = 1; + } + else { + printf("Got result from server:\n"); + printf("%s\n", strDoc); + free(strDoc); + } } - else { - printf("Got result from server:\n"); - printf("%s\n", strDoc); - free(strDoc); - } - } - else if (!strcmp(command, "factory")) { - char *strDoc; + else if (!strcmp(command, "factory")) { + char *strDoc; - if (bes_getFactoryAttributesDocument(ctx, endpointepr, &strDoc)) { - fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); - ret_code = 1; + if (bes_getFactoryAttributesDocument(ctx, endpointepr, &strDoc)) { + fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); + ret_code = 1; + } + else { + printf("Got result from server:\n"); + printf("%s\n", strDoc); + free(strDoc); + } } - else { - printf("Got result from server:\n"); - printf("%s\n", strDoc); - free(strDoc); - } - } - else if (!strcmp(command, "poll")) { - struct bes_activity_status status; - int poll_interval, ret = 0; + else if (!strcmp(command, "poll")) { + struct bes_activity_status status; + int poll_interval, ret = 0; - if (argc != 3) { - fprintf(stderr, "Wrong arguments for poll command.\n", command); - goto end; - } + if (argc != 3) { + fprintf(stderr, "Wrong arguments for poll command.\n", command); + goto end; + } - poll_interval = atoi(argv[2]); - while (!(ret = bes_getActivityStatuses(ctx, endpointepr, activityepr, &status))) { - if ((status.state == BES_Cancelled) - || (status.state == BES_Failed) - || (status.state == BES_Finished)) { - break; - } - else { - printf("."); - fflush(stdout); - sleep(poll_interval); + poll_interval = atoi(argv[2]); + while (!(ret = bes_getActivityStatuses(ctx, endpointepr, activityepr, &status))) { + if ((status.state == BES_Cancelled) + || (status.state == BES_Failed) + || (status.state == BES_Finished)) { + break; + } + else { + printf("."); + fflush(stdout); + sleep(poll_interval); - if (user) { - if (bes_add_usertoken(ctx, user, pass)) { + if (user) { + if (bes_add_usertoken(ctx, user, pass)) { + fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); + ret_code = 1; + break; + } + } + } + } + + if (ret) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; - break; - } } - } + else { + printf("Activity has finished. Final status is: %s\n", bes_activity_state[status.state]); + if (status.substate) { + printf("The substate is %s\n", status.substate); + free(status.substate); + } + } } - - if (ret) { - fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); - ret_code = 1; - } else { - printf("Activity has finished. Final status is: %s\n", bes_activity_state[status.state]); - if (status.substate) { - printf("The substate is %s\n", status.substate); - free(status.substate); - } + fprintf(stderr, "Command %s is unknown.\n", command); + exit(1); } - } - else { - fprintf(stderr, "Command %s is unknown.\n", command); - exit(1); - } - if (endpointepr) { - bes_freeEPR(&endpointepr); - } + if (endpointepr) { + bes_freeEPR(&endpointepr); + } - if (activityepr) { - bes_freeEPR(&activityepr); - } + if (activityepr) { + bes_freeEPR(&activityepr); + } -end: - bes_finalize(&ctx); + end: + bes_finalize(&ctx); - return ret_code; + return ret_code; } void Modified: trunk/besclient/libbes.c =================================================================== --- trunk/besclient/libbes.c 2008-05-16 17:45:10 UTC (rev 49) +++ trunk/besclient/libbes.c 2008-05-18 00:46:57 UTC (rev 50) @@ -46,1203 +46,1117 @@ struct Namespace default_namespaces[] = { - {"SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org/*/soap-envelope", NULL}, - {"wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", NULL, NULL}, - {"wsa", "http://www.w3.org/2005/08/addressing", NULL, NULL}, - {"bes", "http://schemas.ggf.org/bes/2006/08/bes-factory", NULL, NULL}, - {"jsdl", "http://schemas.ggf.org/jsdl/2005/11/jsdl", NULL, NULL}, - {"app", "http://schemas.ggf.org/jsdl/2006/07/jsdl-hpcpa", NULL, NULL}, - {NULL, NULL, NULL, NULL} + {"SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org/*/soap-envelope", NULL}, + {"wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", NULL, NULL}, + {"wsa", "http://www.w3.org/2005/08/addressing", NULL, NULL}, + {"bes", "http://schemas.ggf.org/bes/2006/08/bes-factory", NULL, NULL}, + {"jsdl", "http://schemas.ggf.org/jsdl/2005/11/jsdl", NULL, NULL}, + {"app", "http://schemas.ggf.org/jsdl/2006/07/jsdl-hpcpa", NULL, NULL}, + {NULL, NULL, NULL, NULL} }; struct Namespace epr_namespaces[] = { - {"wsa", WSA_NS, NULL, NULL }, - {"bes", BESE_NS, NULL, NULL }, - {"xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance", NULL}, - {NULL, NULL, NULL, NULL} + {"wsa", WSA_NS, NULL, NULL }, + {"bes", BESE_NS, NULL, NULL }, + {"xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance", NULL}, + {NULL, NULL, NULL, NULL} }; struct bes_epr { - char *str; - struct soap_dom_element *dom; - int domCreateFlag; + char *str; + struct soap_dom_element *dom; + int domCreateFlag; }; #define FromMalloc 1 int isElement(struct soap_dom_element *, char *, char *); int isAttribute(struct soap_dom_attribute *, char *, char *); -int generateAddressHeader(struct bes_context *, epr_t, char *, char **); -int generateAddressingHeaders(struct bes_context *, char *, char *, char **); -void calcDomSize(struct soap_dom_element *, int *); -void calcDomSize2(struct soap *, struct soap_dom_element *, int *); -void sprintDom(struct soap_dom_element *, char *); -void sprintDom2(struct soap *, struct soap_dom_element *, char *); -void printDom(struct soap*, struct soap_dom_element*, int); +int generateAddressingHeaders(struct bes_context *, epr_t, char *, char **); +void printDom(struct soap_dom_element*, char *, int); void cleanDom(struct soap_dom_element*); void setErrorString(struct bes_context *, struct soap *, int); +char *generateEPRString(struct soap_dom_element *, char *); +int calcDomSize(struct soap_dom_element *, char *); +void sprintDom(struct soap_dom_element *, char *, char *); int bes_init(struct bes_context **context) { - struct bes_context *ctx; - struct soap *soap; - - if (context == NULL) { - return BESE_BAD_ARG; - } - - *context = NULL; - - ctx = (struct bes_context *)malloc(sizeof(struct bes_context)); - if (ctx == NULL) { - return BESE_SYS_ERR; - } - - soap = (struct soap *)malloc(sizeof(struct soap)); - if (soap == NULL) { - free(ctx); - return BESE_SYS_ERR; - } - - memset(ctx, 0, sizeof(struct bes_context)); - - soap_ssl_init(); - soap_init(soap); - soap_set_mode(soap, SOAP_C_UTFSTRING); - soap_register_plugin(soap, soap_wsse); - soap_set_namespaces(soap, default_namespaces); - soap_header(soap); + struct bes_context *ctx; + struct soap *soap; + + if (context == NULL) { + return BESE_BAD_ARG; + } + + *context = NULL; + + ctx = (struct bes_context *)malloc(sizeof(struct bes_context)); + if (ctx == NULL) { + return BESE_SYS_ERR; + } + + soap = (struct soap *)malloc(sizeof(struct soap)); + if (soap == NULL) { + free(ctx); + return BESE_SYS_ERR; + } + + memset(ctx, 0, sizeof(struct bes_context)); + + soap_ssl_init(); + soap_init(soap); + soap_set_mode(soap, SOAP_C_UTFSTRING); + soap_register_plugin(soap, soap_wsse); + soap_set_namespaces(soap, default_namespaces); + soap_header(soap); - ctx->soap = soap; - *context = ctx; + ctx->soap = soap; + *context = ctx; - return BESE_OK; + return BESE_OK; } int -bes_security(struct bes_context *context, char *x509cert, char *x509pass, char *capath, char *user, char *pass) +bes_security(struct bes_context *context, + char *x509cert, + char *x509pass, + char *capath, + char *user, + char *pass) { - struct soap *soap; - - if (context == NULL) { - return BESE_BAD_ARG; - } - - soap = context->soap; - - if (soap_ssl_client_context(soap, SOAP_SSL_DEFAULT|SOAP_SSL_SKIP_HOST_CHECK, - x509cert, x509pass, NULL, capath, NULL)) { - setErrorString(context, context->soap, BESE_SOAP_ERR); - return BESE_SOAP_ERR; - } - - if (user) { - if (soap_wsse_add_UsernameTokenText(soap, NULL, user, pass)) { - setErrorString(context, context->soap, BESE_SOAP_ERR); - return BESE_SOAP_ERR; + struct soap *soap; + + if (context == NULL) { + return BESE_BAD_ARG; } - } - - if (x509cert) { - context->x509cert = strdup(x509cert); - } + + soap = context->soap; + + if (soap_ssl_client_context(soap, SOAP_SSL_DEFAULT|SOAP_SSL_SKIP_HOST_CHECK, + x509cert, x509pass, NULL, capath, NULL)) { + setErrorString(context, context->soap, BESE_SOAP_ERR); + return BESE_SOAP_ERR; + } + + if (user) { + if (soap_wsse_add_UsernameTokenText(soap, NULL, user, pass)) { + setErrorString(context, context->soap, BESE_SOAP_ERR); + return BESE_SOAP_ERR; + } + } + + if (x509cert) { + context->x509cert = strdup(x509cert); + } + + if (x509pass) { + context->x509pass = strdup(x509pass); + } + + if (capath) { + context->capath = strdup(capath); + } - if (x509pass) { - context->x509pass = strdup(x509pass); - } - - if (capath) { - context->capath = strdup(capath); - } - - if (user) { - context->user = strdup(user); - } - - if (pass) { - context->pass = strdup(pass); - } - - return BESE_OK; + if (user) { + context->user = strdup(user); + } + + if (pass) { + context->pass = strdup(pass); + } + + return BESE_OK; } int -bes_add_usertoken(struct bes_context *context, char *user, char *pass) +bes_add_usertoken(struct bes_context *context, + char *user, + char *pass) { - if (context == NULL) { - return BESE_BAD_ARG; - } + if (context == NULL) { + return BESE_BAD_ARG; + } - if (soap_wsse_add_UsernameTokenText(context->soap, NULL, user, pass)) { - setErrorString(context, context->soap, BESE_SOAP_ERR); - return BESE_SOAP_ERR; - } - - return BESE_OK; + if (soap_wsse_add_UsernameTokenText(context->soap, NULL, user, pass)) { + setErrorString(context, context->soap, BESE_SOAP_ERR); + return BESE_SOAP_ERR; + } + + return BESE_OK; } int bes_finalize(struct bes_context **context) { - struct bes_context *ctx; + struct bes_context *ctx; + + if (context == NULL || *context == NULL) { + return BESE_BAD_ARG; + } + + ctx = *context; + + soap_end(ctx->soap); + soap_done(ctx->soap); + + free(ctx->soap); + + if (ctx->x509cert) { + free(ctx->x509cert); + } + + if (ctx->x509pass) { + free(ctx->x509pass); + } + + if (ctx->capath) { + free(ctx->capath); + } + + if (ctx->user) { + free(ctx->user); + } + + free(ctx); + *context = NULL; - if (context == NULL || *context == NULL) { - return BESE_BAD_ARG; - } - - ctx = *context; - - soap_end(ctx->soap); - soap_done(ctx->soap); - - free(ctx->soap); - - if (ctx->x509cert) { - free(ctx->x509cert); - } - - if (ctx->x509pass) { - free(ctx->x509pass); - } - - if (ctx->capath) { - free(ctx->capath); - } - - if (ctx->user) { - free(ctx->user); - } - - free(ctx); - *context = NULL; - - return BESE_OK; + return BESE_OK; } -const char* bes_get_lasterror(struct bes_context *context) +const char* +bes_get_lasterror(struct bes_context *context) { - if (context) { - return context->error_string; - } - - return "No valid BES Context."; + if (context) { + return context->error_string; + } + return "No valid BES Context."; } int -bes_createActivity(struct bes_context *context, epr_t endpointepr, char *jsdlfile, epr_t *activityepr) +bes_createActivity(struct bes_context *context, + epr_t endpointepr, + char *jsdlfile, + epr_t *activityepr) { - struct soap *s; - struct bes__CreateActivityType req; - struct bes__CreateActivityResponseType rsp; - struct soap_dom_element dom, *tmpdom; - struct soap_dom_attribute *attr; - struct bes_epr *epr; - int jsdl, size = 0, ret = BESE_OK; - char *endpoint; - - if (context == NULL - || endpointepr == NULL - || jsdlfile == NULL - || activityepr == NULL) { - return BESE_BAD_ARG; - } - - s = context->soap; - - if (ret = generateAddressHeader(context, endpointepr, CREATE_ACT, &endpoint)) { - return ret; - } - - jsdl = open(jsdlfile, O_RDONLY, 0); - if (jsdl == -1) { - setErrorString(context, NULL, BESE_SYS_ERR); - return BESE_SYS_ERR; - } - - memset(&dom, 0, sizeof(struct soap_dom_element)); - dom.soap = soap_new1(SOAP_DOM_TREE|SOAP_C_UTFSTRING); - dom.soap->recvfd = jsdl; - if (soap_begin_recv(dom.soap) - || soap_in_xsd__anyType(dom.soap, NULL, &dom, NULL) == NULL - || soap_end_recv(dom.soap)) { - setErrorString(context, dom.soap, BESE_SOAP_ERR); - close(jsdl); - ret = BESE_SOAP_ERR; - goto end; - } - close(jsdl); - - memset(&req, 0, sizeof(struct bes__CreateActivityType)); - memset(&rsp, 0, sizeof(struct bes__CreateActivityResponseType)); - - req.bes__ActivityDocument.__any = &dom; - - if (soap_call___bes__CreateActivity(s, endpoint, CREATE_ACT, &req, &rsp) != SOAP_OK) { - setErrorString(context, s, BESE_SOAP_ERR); - ret = BESE_SOAP_ERR; - goto end; - } - else { - tmpdom = rsp.__any; + struct soap *s; + struct bes__CreateActivityType req; + struct bes__CreateActivityResponseType rsp; + struct soap_dom_element dom, *tmpdom; + struct soap_dom_attribute *attr; + struct bes_epr *epr; + int jsdl, size = 0, ret = BESE_OK; + char *endpoint; - cleanDom(tmpdom); - soap_set_namespaces(s, epr_namespaces); + if (context == NULL + || endpointepr == NULL + || jsdlfile == NULL + || activityepr == NULL) { + return BESE_BAD_ARG; + } - epr = (struct bes_epr *)malloc(sizeof(struct bes_epr)); - if (!epr) { - soap_set_namespaces(s, default_namespaces); - setErrorString(context, NULL, BESE_MEM_ALLOC); - ret = BESE_MEM_ALLOC; - goto end; + s = context->soap; + + if (ret = generateAddressingHeaders(context, endpointepr, CREATE_ACT, &endpoint)) { + return ret; } - memset(epr, 0, sizeof(struct bes_epr)); - - s->ns = 0; - calcDomSize2(s, tmpdom, &size); - epr->str = (char *)malloc(size + 1); - if (!epr->str) { - free(epr); - soap_set_namespaces(s, default_namespaces); - setErrorString(context, NULL, BESE_MEM_ALLOC); - ret = BESE_MEM_ALLOC; - goto end; + + jsdl = open(jsdlfile, O_RDONLY, 0); + if (jsdl == -1) { + setErrorString(context, NULL, BESE_SYS_ERR); + return BESE_SYS_ERR; } - memset(epr->str, 0, size + 1); - - s->ns = 0; - sprintDom2(s, tmpdom, epr->str); - epr->dom = tmpdom; - *activityepr = (epr_t)epr; + memset(&dom, 0, sizeof(struct soap_dom_element)); + dom.soap = soap_new1(SOAP_DOM_TREE|SOAP_C_UTFSTRING); + dom.soap->recvfd = jsdl; + if (soap_begin_recv(dom.soap) + || soap_in_xsd__anyType(dom.soap, NULL, &dom, NULL) == NULL + || soap_end_recv(dom.soap)) { + setErrorString(context, dom.soap, BESE_SOAP_ERR); + close(jsdl); + ret = BESE_SOAP_ERR; + goto end; + } + close(jsdl); + + memset(&req, 0, sizeof(struct bes__CreateActivityType)); + memset(&rsp, 0, sizeof(struct bes__CreateActivityResponseType)); + + req.bes__ActivityDocument.__any = &dom; - soap_set_namespaces(s, default_namespaces); - } - -end: - soap_end(dom.soap); - soap_done(dom.soap); - free(dom.soap); - - return ret; + if (soap_call___bes__CreateActivity(s, endpoint, CREATE_ACT, &req, &rsp) != SOAP_OK) { + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; + goto end; + } + else { + tmpdom = rsp.__any; + + cleanDom(tmpdom); + soap_set_namespaces(s, epr_namespaces); + + epr = (struct bes_epr *)malloc(sizeof(struct bes_epr)); + if (!epr) { + soap_set_namespaces(s, default_namespaces); + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; + goto end; + } + memset(epr, 0, sizeof(struct bes_epr)); + + epr->str = generateEPRString(tmpdom, NULL); + if (!epr->str) { + free(epr); + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; + goto end; + } + epr->dom = tmpdom; + *activityepr = (epr_t)epr; + } + + end: + soap_end(dom.soap); + soap_done(dom.soap); + free(dom.soap); + + return ret; } int -bes_terminateActivities(struct bes_context *context, epr_t endpointepr, epr_t activityepr) +bes_terminateActivities(struct bes_context *context, + epr_t endpointepr, + epr_t activityepr) { - struct soap *s; - struct bes__TerminateActivitiesType req; - struct bes__TerminateActivitiesResponseType rsp; - struct bes_epr *epr; - int i, ret = BESE_OK; - char *endpoint; - - if (context == NULL || activityepr == NULL || endpointepr == NULL) { - return BESE_BAD_ARG; - } - - s = context->soap; - epr = (struct bes_epr *)activityepr; - - if (ret = generateAddressHeader(context, endpointepr, TERMINATE_ACT, &endpoint)) { - return BES_FALSE; - } - - memset(&req, 0, sizeof(struct bes__TerminateActivitiesType)); - memset(&rsp, 0, sizeof(struct bes__TerminateActivitiesResponseType)); - - req.__any = epr->dom; - if (soap_call___bes__TerminateActivities(s, endpoint, TERMINATE_ACT, req, &rsp) != SOAP_OK) { - setErrorString(context, s, BESE_SOAP_ERR); - ret = BES_FALSE; - } - else { - for (i = 0; i < rsp.__sizeResponse; i++) { - if (rsp.Response[i].Cancelled == true_) { - ret = BES_TRUE; - } - else { + struct soap *s; + struct bes__TerminateActivitiesType req; + struct bes__TerminateActivitiesResponseType rsp; + struct bes_epr *epr; + int i, ret = BESE_OK; + char *endpoint; + + if (context == NULL || activityepr == NULL || endpointepr == NULL) { + return BESE_BAD_ARG; + } + + s = context->soap; + epr = (struct bes_epr *)activityepr; + + if (ret = generateAddressingHeaders(context, endpointepr, TERMINATE_ACT, &endpoint)) { + return BES_FALSE; + } + + memset(&req, 0, sizeof(struct bes__TerminateActivitiesType)); + memset(&rsp, 0, sizeof(struct bes__TerminateActivitiesResponseType)); + + req.__any = epr->dom; + if (soap_call___bes__TerminateActivities(s, endpoint, TERMINATE_ACT, req, &rsp) != SOAP_OK) { + setErrorString(context, s, BESE_SOAP_ERR); ret = BES_FALSE; - } } - } - - return ret; + else { + for (i = 0; i < rsp.__sizeResponse; i++) { + if (rsp.Response[i].Cancelled == true_) { + ret = BES_TRUE; + } + else { + ret = BES_FALSE; + } + } + } + + return ret; } int -bes_getActivityStatuses(struct bes_context *context, epr_t endpointepr, epr_t activityepr, struct bes_activity_status *status) +bes_getActivityStatuses(struct bes_context *context, + epr_t endpointepr, + epr_t activityepr, + struct bes_activity_status *status) { - struct soap *s; - struct bes__GetActivityStatusesType req; - struct bes__GetActivityStatusesResponseType rsp; - struct bes_epr *epr; - int ret = BESE_OK; - char *endpoint; - - if (context == NULL - || activityepr == NULL - || status == NULL - || endpointepr == NULL) { - return BESE_BAD_ARG; - } - - s = context->soap; - epr = (struct bes_epr *)activityepr; - - memset(status, 0, sizeof(struct bes_activity_status)); - - if (ret = generateAddressHeader(context, endpointepr, STATUS_ACT, &endpoint)) { - return ret; - } - - memset(&req, 0, sizeof(struct bes__GetActivityStatusesType)); - memset(&rsp, 0, sizeof(struct bes__GetActivityStatusesResponseType)); - - req.__any = epr->dom; - if (soap_call___bes__GetActivityStatuses(s, endpoint, STATUS_ACT, req, &rsp) != SOAP_OK) { - setErrorString(context, s, BESE_SOAP_ERR); - ret = BESE_SOAP_ERR; - goto end; - } - else { - if ((rsp.__any!=NULL)&&(!strcmp(rsp.__any->name,"Response"))) { - struct soap_dom_element *element = rsp.__any->elts; - int size; - - while (element != NULL) { - if (!strcmp(element->name,"ActivityStatus")) { - if(element->atts!=NULL) { - struct soap_dom_attribute *attributes=element->atts; - - while (attributes != NULL) { - if((attributes->name!=NULL)&&(!strcmp(attributes->name,"state"))) { - if((attributes->data!=NULL)&&(!strcmp(attributes->data,"Pending"))) { - status->state = BES_Pending; + struct soap *s; + struct bes__GetActivityStatusesType req; + struct bes__GetActivityStatusesResponseType rsp; + struct bes_epr *epr; + int ret = BESE_OK; + char *endpoint; + + if (context == NULL + || activityepr == NULL + || status == NULL + || endpointepr == NULL) { + return BESE_BAD_ARG; + } + + s = context->soap; + epr = (struct bes_epr *)activityepr; + + memset(status, 0, sizeof(struct bes_activity_status)); + + if (ret = generateAddressingHeaders(context, endpointepr, STATUS_ACT, &endpoint)) { + return ret; + } + + memset(&req, 0, sizeof(struct bes__GetActivityStatusesType)); + memset(&rsp, 0, sizeof(struct bes__GetActivityStatusesResponseType)); + + req.__any = epr->dom; + if (soap_call___bes__GetActivityStatuses(s, endpoint, STATUS_ACT, req, &rsp) != SOAP_OK) { + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; + goto end; + } + else { + if ((rsp.__any!=NULL)&&(!strcmp(rsp.__any->name,"Response"))) { + struct soap_dom_element *element = rsp.__any->elts; + int size; + + while (element != NULL) { + if (!strcmp(element->name,"ActivityStatus")) { + if(element->atts!=NULL) { + struct soap_dom_attribute *attributes=element->atts; + + while (attributes != NULL) { + if((attributes->name!=NULL)&&(!strcmp(attributes->name,"state"))) { + if((attributes->data!=NULL)&&(!strcmp(attributes->data,"Pending"))) { + status->state = BES_Pending; + } + else if((attributes->data!=NULL)&&(!strcmp(attributes->data,"Running"))) { + status->state = BES_Running; + } + else if((attributes->data!=NULL)&&(!strcmp(attributes->data,"Cancelled"))) { + status->state = BES_Cancelled; + } + else if((attributes->data!=NULL)&&(!strcmp(attributes->data,"Failed"))) { + status->state = BES_Failed; + } + else if((attributes->data!=NULL)&&(!strcmp(attributes->data,"Finished"))) { + status->state = BES_Finished; + } + break; + } + attributes=attributes->next; + } + + if (element->elts) { + size = calcDomSize(element->elts, NULL); + + status->substate = (char *)malloc(size + 1); + if (!status->substate) { + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; + goto end; + } + + memset(status->substate, 0, size + 1); + sprintDom(element->elts, status->substate, NULL); + } + } + + break; } - else if((attributes->data!=NULL)&&(!strcmp(attributes->data,"Running"))) { - status->state = BES_Running; + else if(!strcmp(element->name,"Fault")) { + setErrorString(context, NULL, BESE_GETSTATUS_ERR); + ret = BESE_GETSTATUS_ERR; + goto end; } - else if((attributes->data!=NULL)&&(!strcmp(attributes->data,"Cancelled"))) { - status->state = BES_Cancelled; + else { + element=element->next; } - else if((attributes->data!=NULL)&&(!strcmp(attributes->data,"Failed"))) { - status->state = BES_Failed; - } - else if((attributes->data!=NULL)&&(!strcmp(attributes->data,"Finished"))) { - status->state = BES_Finished; - } - break; - } - attributes=attributes->next; } - - if (element->elts) { - calcDomSize(element->elts, &size); - - status->substate = (char *)malloc(size + 1); - if (!status->substate) { - setErrorString(context, NULL, BESE_MEM_ALLOC); - ret = BESE_MEM_ALLOC; - goto end; - } - - memset(status->substate, 0, size + 1); - sprintDom(element->elts, status->substate); - } - } - - break; } - else if(!strcmp(element->name,"Fault")) { - setErrorString(context, NULL, BESE_GETSTATUS_ERR); - ret = BESE_GETSTATUS_ERR; - goto end; - } - else { - element=element->next; - } - } } - } - -end: - return ret; + + end: + return ret; } int -bes_getActivityDocuments(struct bes_context *context, epr_t endpointepr, epr_t activityepr, char **strDoc) +bes_getActivityDocuments(struct bes_context *context, + epr_t endpointepr, + epr_t activityepr, + char **strDoc) { - struct soap *s; - struct bes__GetActivityDocumentsType req; - struct bes__GetActivityDocumentsResponseType rsp; - struct bes_epr *epr; - int size = 0, ret = BESE_OK; - char *endpoint, *str; - - if (context == NULL - || endpointepr == NULL - || activityepr == NULL - || strDoc == NULL) { - return BESE_BAD_ARG; - } - - s = context->soap; - epr = (struct bes_epr *)activityepr; - - if (ret = generateAddressHeader(context, endpointepr, ACTIVITIES_ACT, &endpoint)) { - return ret; - } - - memset(&req, 0, sizeof(struct bes__GetActivityDocumentsType)); - memset(&rsp, 0, sizeof(struct bes__GetActivityDocumentsResponseType)); - - req.__any = epr->dom; - if (soap_call___bes__GetActivityDocuments(s, endpoint, ACTIVITIES_ACT, req, &rsp) != SOAP_OK) { - setErrorString(context, s, BESE_SOAP_ERR); - ret = BESE_SOAP_ERR; - goto end; - } - else { - calcDomSize(rsp.__any, &size); + struct soap *s; + struct bes__GetActivityDocumentsType req; + struct bes__GetActivityDocumentsResponseType rsp; + struct bes_epr *epr; + int size = 0, ret = BESE_OK; + char *endpoint, *str; - str = (char *)malloc(size + 1); - if (!str) { - setErrorString(context, NULL, BESE_MEM_ALLOC); - ret = BESE_MEM_ALLOC; - goto end; + if (context == NULL + || endpointepr == NULL + || activityepr == NULL + || strDoc == NULL) { + return BESE_BAD_ARG; } - memset(str, 0, size + 1); - sprintDom(rsp.__any, str); + s = context->soap; + epr = (struct bes_epr *)activityepr; - *strDoc = str; - } - -end: - return ret; + if (ret = generateAddressingHeaders(context, endpointepr, ACTIVITIES_ACT, &endpoint)) { + return ret; + } + + memset(&req, 0, sizeof(struct bes__GetActivityDocumentsType)); + memset(&rsp, 0, sizeof(struct bes__GetActivityDocumentsResponseType)); + + req.__any = epr->dom; + if (soap_call___bes__GetActivityDocuments(s, endpoint, ACTIVITIES_ACT, req, &rsp) != SOAP_OK) { + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; + goto end; + } + else { + size = calcDomSize(rsp.__any, NULL); + + str = (char *)malloc(size + 1); + if (!str) { + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; + goto end; + } + memset(str, 0, size + 1); + + sprintDom(rsp.__any, str, NULL); + + *strDoc = str; + } + + end: + return ret; } int -bes_getFactoryAttributesDocument(struct bes_context *context, epr_t endpointepr, char **strDoc) +bes_getFactoryAttributesDocument(struct bes_context *context, + epr_t endpointepr, + char **strDoc) { - struct soap *s; - struct bes__GetFactoryAttributesDocumentType req; - struct bes__GetFactoryAttributesDocumentResponseType rsp; - char *endpoint, *str; - int size = 0, ret = BESE_OK; - - if (context == NULL || endpointepr == NULL || strDoc == NULL) { - return BESE_BAD_ARG; - } - - s = context->soap; - - if (ret = generateAddressHeader(context, endpointepr, FACTORY_ACT, &endpoint)) { - return ret; - } - - memset(&req, 0, sizeof(struct bes__GetFactoryAttributesDocumentType)); - memset(&rsp, 0, sizeof(struct bes__GetFactoryAttributesDocumentResponseType)); - - if (soap_call___bes__GetFactoryAttributesDocument(s, endpoint, FACTORY_ACT, &req, &rsp) != SOAP_OK) { - setErrorString(context, s, BESE_SOAP_ERR); - ret = BESE_SOAP_ERR; - } - else { - calcDomSize(rsp.__any, &size); + struct soap *s; + struct bes__GetFactoryAttributesDocumentType req; + struct bes__GetFactoryAttributesDocumentResponseType rsp; + char *endpoint, *str; + int size = 0, ret = BESE_OK; - str = (char *)malloc(size + 1); - if (!str) { - setErrorString(context, NULL, BESE_MEM_ALLOC); - return BESE_MEM_ALLOC; + if (context == NULL || endpointepr == NULL || strDoc == NULL) { + return BESE_BAD_ARG; } - - memset(str, 0, size + 1); - sprintDom(rsp.__any, str); - *strDoc = str; - } - - return ret; + s = context->soap; + + if (ret = generateAddressingHeaders(context, endpointepr, FACTORY_ACT, &endpoint)) { + return ret; + } + + memset(&req, 0, sizeof(struct bes__GetFactoryAttributesDocumentType)); + memset(&rsp, 0, sizeof(struct bes__GetFactoryAttributesDocumentResponseType)); + + if (soap_call___bes__GetFactoryAttributesDocument(s, endpoint, FACTORY_ACT, &req, &rsp) != SOAP_OK) { + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; + } + else { + size = calcDomSize(rsp.__any, NULL); + str = (char *)malloc(size + 1); + if (!str) { + setErrorString(context, NULL, BESE_MEM_ALLOC); + return BESE_MEM_ALLOC; + } + memset(str, 0, size + 1); + + sprintDom(rsp.__any, str, NULL); + *strDoc = str; + } + + return ret; } -void bes_freeEPR(epr_t *epr) +void +bes_freeEPR(epr_t *epr) { - struct bes_epr *tmpEPR; - - if (!epr || !(*epr)) { - return; - } - - tmpEPR = (struct bes_epr *)(*epr); - - if (tmpEPR->domCreateFlag == FromMalloc) { - soap_end(tmpEPR->dom->soap); - soap_done(tmpEPR->dom->soap); - free(tmpEPR->dom->soap); - } - - free(tmpEPR->str); - free(tmpEPR); - - *epr = NULL; + struct bes_epr *tmpEPR; + + if (!epr || !(*epr)) { + return; + } + + tmpEPR = (struct bes_epr *)(*epr); + + if (tmpEPR->domCreateFlag == FromMalloc) { + soap_end(tmpEPR->dom->soap); + soap_done(tmpEPR->dom->soap); + free(tmpEPR->dom->soap); + } + + free(tmpEPR->str); + free(tmpEPR); + + *epr = NULL; } -int bes_writeEPRToFile(struct bes_context *context, char *filename, epr_t epr) +int +bes_writeEPRToFile(struct bes_context *context, char *filename, epr_t epr) { - struct bes_epr *tmpEPR; - int fd; - - if (context == NULL || epr == NULL || filename == NULL) { - return BESE_BAD_ARG; - } - - tmpEPR = (struct bes_epr *)(epr); - - fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); - if (fd == -1) { - setErrorString(context, NULL, BESE_SYS_ERR); - return BESE_SYS_ERR; - } - - if (write(fd, tmpEPR->str, strlen(tmpEPR->str)) == -1) { - setErrorString(context, NULL, BESE_SYS_ERR); - return BESE_SYS_ERR; - } - - close(fd); - return BESE_OK; + struct bes_epr *tmpEPR; + int fd; + + if (context == NULL || epr == NULL || filename == NULL) { + return BESE_BAD_ARG; + } + + tmpEPR = (struct bes_epr *)(epr); + + fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); + if (fd == -1) { + setErrorString(context, NULL, BESE_SYS_ERR); + return BESE_SYS_ERR; + } + + if (write(fd, tmpEPR->str, strlen(tmpEPR->str)) == -1) { + setErrorString(context, NULL, BESE_SYS_ERR); + return BESE_SYS_ERR; + } + + close(fd); + return BESE_OK; } -int bes_readEPRFromFile(struct bes_context *context, char *filename, epr_t *epr) +int +bes_readEPRFromFile(struct bes_context *context, char *filename, epr_t *epr) { - int fd, size = 0, ret = BESE_OK; - struct soap_dom_element *dom; - struct bes_epr *tmpEPR; - struct stat fileStat; - - if (context == NULL || epr == NULL || filename == NULL) { - return BESE_BAD_ARG; - } - - fd = open(filename, O_RDONLY, 0); - if (fd == -1) { - setErrorString(context, NULL, BESE_SYS_ERR); - return BESE_SYS_ERR; - } - - dom = (struct soap_dom_element *)soap_malloc(context->soap, sizeof(struct soap_dom_element)); - if (!dom) { + int fd, size = 0, ret = BESE_OK; + struct soap_dom_element *dom; + struct bes_epr *tmpEPR; + struct stat fileStat; + + if (context == NULL || epr == NULL || filename == NULL) { + return BESE_BAD_ARG; + } + + fd = open(filename, O_RDONLY, 0); + if (fd == -1) { + setErrorString(context, NULL, BESE_SYS_ERR); + return BESE_SYS_ERR; + } + + dom = (struct soap_dom_element *)soap_malloc(context->soap, sizeof(struct soap_dom_element)); + if (!dom) { + close(fd); + setErrorString(context, NULL, BESE_MEM_ALLOC); + return BESE_MEM_ALLOC; + } + + dom->soap = soap_new1(SOAP_DOM_TREE|SOAP_C_UTFSTRING); + dom->soap->recvfd = fd; + if (soap_begin_recv(dom->soap) + || soap_in_xsd__anyType(dom->soap, NULL, dom, NULL) == NULL + || soap_end_recv(dom->soap)) { + setErrorString(context, dom->soap, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; + goto error_end; + } + + tmpEPR = (struct bes_epr *)malloc(sizeof(struct bes_epr)); + if (!tmpEPR) { + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; + goto error_end; + } + memset(tmpEPR, 0, sizeof(struct bes_epr)); + + if (lseek(fd, 0, SEEK_SET) == -1) { + free(tmpEPR); + setErrorString(context, NULL, BESE_SYS_ERR); + ret = BESE_SYS_ERR; + goto error_end; + } + + if (fstat(fd, &fileStat)) { + free(tmpEPR); + setErrorString(context, NULL, BESE_SYS_ERR); + ret = BESE_SYS_ERR; + goto error_end; + } + + size = fileStat.st_size; + tmpEPR->str = (char *)malloc(size + 1); + if (!tmpEPR->str) { + free(tmpEPR); + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; + goto error_end; + } + memset(tmpEPR->str, 0, size + 1); + + if (read(fd, tmpEPR->str, size) == -1) { + free(tmpEPR); + setErrorString(context, NULL, BESE_SYS_ERR); + ret = BESE_SYS_ERR; + goto error_end; + } + close(fd); - setErrorString(context, NULL, BESE_MEM_ALLOC); - return BESE_MEM_ALLOC; - } - - dom->soap = soap_new1(SOAP_DOM_TREE|SOAP_C_UTFSTRING); - dom->soap->recvfd = fd; - if (soap_begin_recv(dom->soap) - || soap_in_xsd__anyType(dom->soap, NULL, dom, NULL) == NULL - || soap_end_recv(dom->soap)) { - setErrorString(context, dom->soap, BESE_SOAP_ERR); - ret = BESE_SOAP_ERR; - goto error_end; - } - - tmpEPR = (struct bes_epr *)malloc(sizeof(struct bes_epr)); - if (!tmpEPR) { - setErrorString(context, NULL, BESE_MEM_ALLOC); - ret = BESE_MEM_ALLOC; - goto error_end; - } - memset(tmpEPR, 0, sizeof(struct bes_epr)); - - if (lseek(fd, 0, SEEK_SET) == -1) { - free(tmpEPR); - setErrorString(context, NULL, BESE_SYS_ERR); - ret = BESE_SYS_ERR; - goto error_end; - } - - if (fstat(fd, &fileStat)) { - free(tmpEPR); - setErrorString(context, NULL, BESE_SYS_ERR); - ret = BESE_SYS_ERR; - goto error_end; - } - - size = fileStat.st_size; - tmpEPR->str = (char *)malloc(size + 1); - if (!tmpEPR->str) { - free(tmpEPR); - setErrorString(context, NULL, BESE_MEM_ALLOC); - ret = BESE_MEM_ALLOC; - goto error_end; - } - memset(tmpEPR->str, 0, size + 1); - - if (read(fd, tmpEPR->str, size) == -1) { - free(tmpEPR); - setErrorString(context, NULL, BESE_SYS_ERR); - ret = BESE_SYS_ERR; - goto error_end; - } - - close(fd); - - tmpEPR->dom = dom; - tmpEPR->domCreateFlag = FromMalloc; - *epr = (epr_t)tmpEPR; - - return BESE_OK; - -error_end: - close(fd); - soap_end(dom->soap); - soap_done(dom->soap); - free(dom->soap); - - return ret; - + + tmpEPR->dom = dom; + tmpEPR->domCreateFlag = FromMalloc; + *epr = (epr_t)tmpEPR; + + return BESE_OK; + + error_end: + close(fd); + soap_end(dom->soap); + soap_done(dom->soap); + free(dom->soap); + + return ret; } -const char *getEPRString(epr_t epr) +char * +bes_getEPRString(epr_t epr) { - struct bes_epr *tmpEPR; - - if (!epr) { - return NULL; - } - - tmpEPR = (struct bes_epr *)(epr); - - return tmpEPR->str; -} - -void -calcDomSize(struct soap_dom_element *node, int *size) -{ - struct soap_dom_attribute *attr; - - if (node == NULL) { - return; - } - - *size += strlen(node->name) + 1; - attr = node->atts; - while (attr) { - *size += strlen(attr->name) + strlen(attr->data) + 4; - attr = attr->next; - } - (*size)++; - - if (node->data && strlen(node->data)) { - *size += strlen(node->data); - } - - if (node->elts) - calcDomSize(node->elts, size); - - *size += strlen(node->name) + 3; - - if (node->next) - calcDomSize(node->next, size); - -} - - -void calcElementSize(struct soap *soap, struct soap_dom_element *node, const char *prefix, int *size) -{ - struct Namespace *ns; - - if (!soap->ns) { - *size += strlen("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); - } - - *size += strlen(prefix) + strlen(node->name) + 2; - - if (!soap->ns) { - for (ns = soap->local_namespaces; ns && ns->id; ns++) { - if (*ns->id && (ns->out || ns->ns)) { - *size += strlen(ns->id) + strlen(ns->out ? ns->out : ns->ns) + 10; - } + if (!epr) { + return NULL; } - } - - if (!soap->ns) { - soap->ns = 1; - } - + return ((struct bes_epr*)epr)->str; } void -calcDomSize2(struct soap *soap, struct soap_dom_element *node, int *size) +printDom(struct soap_dom_element *node, + char *current_nstr, + int depth) { - struct Namespace *ns; - struct soap_dom_attribute *attr; - struct soap_dom_element *elt; - - for (ns = soap->local_namespaces; ns && ns->id; ns++) { - if (ns->ns == node->nstr || !strcmp(ns->ns, node->nstr)) { - calcElementSize(soap, node, ns->id, size); - break; + struct soap_dom_attribute *attr; + int i; + + if (node == NULL) { + return; } - } - - attr = node->atts; - while (attr) { - *size += strlen(attr->name) + strlen(attr->data) + 4; - attr = attr->next; - } - - (*size)++; - - if (node->data && strlen(node->data)) { - *size += strlen(node->data); - } - - for (elt = node->elts; elt; elt = elt->next) { - calcDomSize2(soap, elt, size); - } - - if (ns && ns->id) { - *size += strlen(ns->id) + strlen(node->name) + 4; - } - + + for (i = 0; i < depth; i++) + fprintf(stdout, " "); + fprintf(stdout, "<%s", node->name); + /* if we don't have a current namespace, or if the current */ + /* namespace is different from this node, emit an xmlns attribute */ + if (!current_nstr || strcmp(current_nstr, node->nstr)) { + fprintf(stdout, " xmlns=\"%s\"", node->nstr); + } + attr = node->atts; + while (attr) { + /* xmlns was handled earlier */ + if (strcmp(attr->name, "xmlns")) { + fprintf(stdout, " %s=\"%s\"", attr->name, attr->data); + } + attr = attr->next; + } + fprintf(stdout, ">\n"); + + if (node->data && strlen(node->data)) { + for (i = 0; i < depth; i++) + fprintf(stdout, " "); + fprintf(stdout, " %s\n", node->data); + } + + if (node->elts) + printDom(node->elts, (char*)node->nstr, depth+1); + + for (i = 0; i < depth; i++) + fprintf(stdout, " "); + fprintf(stdout, "</%s>\n", node->name); + + if (node->next) + printDom(node->next, current_nstr, depth); + } -void sprintElement(struct soap *soap, struct soap_dom_element *node, const char *prefix, char *str) +int +calcDomSize(struct soap_dom_element *node, + char *current_nstr) { - char buf[256]; - struct Namespace *ns; + struct soap_dom_attribute *attr; + int i, size = 0; - if (!soap->ns) { - sprintf(buf, "%s", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); - strcat(str, buf); - } - - sprintf(buf, "<%s:%s", prefix, node->name); - strcat(str, buf); - - if (!soap->ns) { - for (ns = soap->local_namespaces; ns && ns->id; ns++) { - if (*ns->id && (ns->out || ns->ns)) { - sprintf(buf, " xmlns:%s=\"%s\"", ns->id, ns->out ? ns->out : ns->ns); - strcat(str, buf); - } + if (node == NULL) { + return 0; } - } - - if (!soap->ns) { - soap->ns = 1; - } - -} - -void sprintDom2(struct soap *soap, struct soap_dom_element *node, char *str) -{ - struct Namespace *ns; - struct soap_dom_element *elt; - struct soap_dom_attribute *attr; - char buf[256]; - - for (ns = soap->local_namespaces; ns && ns->id; ns++) { - if (ns->ns == node->nstr || !strcmp(ns->ns, node->nstr)) { - sprintElement(soap, node, ns->id, str); - break; + + if (node->elts) { + size += calcDomSize(node->elts, (char*)node->nstr); } - } + + if (node->next) { + size += calcDomSize(node->next, current_nstr); + } + + /* element name, data and closing element) */ + size += 2*strlen(node->name) + strlen("<></>"); + if (node->data) { + size += strlen(node->data); + } + + /* if we don't have a current namespace, or if the current */ + /* namespace is different from this node, emit an xmlns attribute */ + if (!current_nstr || strcmp(current_nstr, node->nstr)) { + size += strlen(" xmlns=\"\"") + strlen(node->nstr); + } + + /* attributes */ + attr = node->atts; + while (attr) { + /* xmlns was handled earlier */ + if (strcmp(attr->name, "xmlns")) { + size += strlen("=\"\"") + strlen(attr->name) + strlen(attr->data); + } + attr = attr->next; + } - attr = node->atts; - while (attr) { - sprintf(buf, " %s=\"%s\"", attr->name, attr->data); - strcat(str, buf); - attr = attr->next; - } - - strcat(str, ">"); - - if (node->data) { - strcat(str, node->data); - } - - for (elt = node->elts; elt; elt = elt->next) { - sprintDom2(soap, elt, str); - } - - if (ns && ns->id) { - sprintf(buf, "</%s:%s>", ns->id, node->name); - strcat(str, buf); - } - + return size; } void -sprintDom(struct soap_dom_element *node, char *str) +sprintDom(struct soap_dom_element *node, + char *str, + char *current_nstr) { - struct soap_dom_attribute *attr; - char buf[256]; + struct soap_dom_attribute *attr; + int i; - if (node == NULL) { - return; - } - - sprintf(buf, "<%s", node->name); - strcat(str, buf); - attr = node->atts; - while (attr) { - sprintf(buf, " %s=\"%s\"", attr->name, attr->data); - strcat(str, buf); - attr = attr->next; - } - strcat(str, ">"); - - if (node->data && strlen(node->data)) { - sprintf(buf, "%s", node->data); - strcat(str, buf); - } - - if (node->elts) - sprintDom(node->elts, str); - - sprintf(buf, "</%s>", node->name); - strcat(str, buf); - - if (node->next) - sprintDom(node->next, str); - + if (node == NULL) { + return; + } + + sprintf(str, "%s<%s", str, node->name); + /* if we don't have a current namespace, or if the current */ + /* namespace is different from this node, emit an xmlns attribute */ + if (!current_nstr || strcmp(current_nstr, node->nstr)) { + sprintf(str, "%s xmlns=\"%s\"", str, node->nstr); + } + attr = node->atts; + while (attr) { + /* xmlns was handled earlier */ + if (strcmp(attr->name, "xmlns")) { + sprintf(str, "%s %s=\"%s\"", str, attr->name, attr->data); + } + attr = attr->next; + } + sprintf(str, "%s>", str); + + if (node->data && strlen(node->data)) { + sprintf(str, "%s%s", str, node->data); + } + + if (node->elts) + sprintDom(node->elts, str, (char*)node->nstr); + + sprintf(str, "%s</%s>", str, node->name); + + if (node->next) + sprintDom(node->next, str, current_nstr); + } -void -printDom(struct soap *s, struct soap_dom_element *node, int depth) +char * +generateEPRString(struct soap_dom_element *node, + char *current_nstr) { - struct soap_dom_attribute *attr; - int i; + struct soap_dom_attribute *attr; + char *epr_buf; + int i, epr_len; - if (node == NULL) { - return; - } - - for (i = 0; i < depth; i++) - fprintf(stdout, " "); - fprintf(stdout, "<%s", node->name); - attr = node->atts; - while (attr) { - fprintf(stdout, " %s=\"%s\"", attr->name, attr->data); - attr = attr->next; - } - fprintf(stdout, ">\n"); - - if (node->data && strlen(node->data)) { - for (i = 0; i < depth; i++) - fprintf(stdout, " "); - fprintf(stdout, "%s\n", node->data); - } + if (node == NULL) { + return NULL; + } - if (node->elts) - printDom(s, node->elts, depth+1); - - for (i = 0; i < depth; i++) - fprintf(stdout, " "); - fprintf(stdout, "</%s>\n", node->name); - - if (node->next) - printDom(s, node->next, depth); - + epr_len = calcDomSize(node, current_nstr); + epr_buf = (char*)malloc(epr_len+1); + if (epr_buf == NULL) { + perror("generateEPRSTring: malloc"); + return NULL; + } + memset(epr_buf, 0, epr_len+1); + + sprintDom(node, epr_buf, current_nstr); + + return epr_buf; } void cleanDom(struct soap_dom_element *node) { - struct soap_dom_attribute *attr; - char *cp; - - if (node == NULL) { - return; - } - cp = strchr(node->name, ':'); - if (cp) { - cp++; - node->name = cp; - } - if (node->nstr && strlen(node->nstr) == 0) - node->nstr = NULL; - attr = node->atts; - while (attr) { - cp = strchr(attr->name, ':'); + struct soap_dom_attribute *attr; + char *cp; + + if (node == NULL) { + return; + } + cp = strchr(node->name, ':'); if (cp) { - cp++; - attr->name = cp; + cp++; + node->name = cp; } - if (attr->nstr && strlen(attr->nstr) == 0) - attr->nstr = NULL; - attr = attr->next; - } - if (node->elts) - cleanDom(node->elts); - if (node->next) - cleanDom(node->next); + if (node->nstr && strlen(node->nstr) == 0) + node->nstr = NULL; + attr = node->atts; + while (attr) { + cp = strchr(attr->name, ':'); + if (cp) { + cp++; + attr->name = cp; + } + if (attr->nstr && strlen(attr->nstr) == 0) + attr->nstr = NULL; + attr = attr->next; + } + if (node->elts) + cleanDom(node->elts); + if (node->next) + cleanDom(node->next); } int generateAddressHeader(struct bes_context *context, - epr_t endpointepr, - char *action, - char **endpoint_ret) + epr_t endpointepr, + char *action, + char **endpoint_ret) { - struct soap *s; - struct soap_dom_element *dom, *iter; - struct bes_epr *epr; - char *endpoint; - - s = context->soap; - epr = (struct bes_epr *)endpointepr; - dom = epr->dom; - - iter = dom->elts; - if (!iter || !isElement(iter, WSA_NS, "Address")) { - setErrorString(context, NULL, BESE_ENDPOINT_ERR); - return BESE_ENDPOINT_ERR; - } - endpoint = soap_strdup(s, iter->data); - if (endpoint == NULL) { - setErrorString(context, s, BESE_SOAP_ERR); - return BESE_SOAP_ERR; - } - - s->header->wsa__To.__item = endpoint; - *endpoint_ret = endpoint; - - s->header->wsa__Action.__item = soap_strdup(s, action); - if (s->header->wsa__... [truncated message content] |
From: <cs...@us...> - 2008-05-16 17:45:15
|
Revision: 49 http://bespp.svn.sourceforge.net/bespp/?rev=49&view=rev Author: csmith Date: 2008-05-16 10:45:10 -0700 (Fri, 16 May 2008) Log Message: ----------- correct ls_sharedresourceinfo. not even used Modified Paths: -------------- trunk/besserver/besserver.c Modified: trunk/besserver/besserver.c =================================================================== --- trunk/besserver/besserver.c 2008-05-16 17:11:36 UTC (rev 48) +++ trunk/besserver/besserver.c 2008-05-16 17:45:10 UTC (rev 49) @@ -823,7 +823,6 @@ struct bes__BasicResourceAttributesDocumentType *resource; int num_contained_resources = 0; struct hostInfo *hinfo; - struct lsSharedResourceInfo *resinfo; char *cpuarch, *osname, *osver; int numhosts = 0, numres = 0; int i, j; @@ -837,11 +836,6 @@ fprintf(stderr, "%s: ls_gethostinfo error: %s\n", fname, ls_sysmsg()); return BESE_BACKEND; } - resinfo = ls_sharedresourceinfo(NULL, &numres, NULL, 0); - if (resinfo == NULL) { - fprintf(stderr, "%s: ls_sharedresourceinfo error: %s", fname, ls_sysmsg()); - return BESE_BACKEND; - } for (i = 0; i < numhosts; i++) { if (hinfo[i].maxCpus == 0) { /* host is unavailable at this time */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-05-16 17:11:29
|
Revision: 48 http://bespp.svn.sourceforge.net/bespp/?rev=48&view=rev Author: csmith Date: 2008-05-16 10:11:36 -0700 (Fri, 16 May 2008) Log Message: ----------- reverse previous change Modified Paths: -------------- trunk/besserver/job.c Modified: trunk/besserver/job.c =================================================================== --- trunk/besserver/job.c 2008-05-16 08:58:32 UTC (rev 47) +++ trunk/besserver/job.c 2008-05-16 17:11:36 UTC (rev 48) @@ -1067,23 +1067,18 @@ } close(pfd[1]); } - if (geteuid() != pw->pw_uid) { - /* if we're not already running as the user */ - /* making the request, make the change now */ - /* might happen when besserver is not run as root */ - if (seteuid(0)) { - perror("runBsubScriptAsUser (child): seteuid 0"); - _exit(1); - } - if (setgid(pw->pw_gid)) { - perror("runBsubScriptAsUser (child): setgid"); - _exit(1); - } - if (setuid(pw->pw_uid)) { - perror("runBsubScriptAsUser (child): setuid"); - _exit(1); - } + if (seteuid(0)) { + perror("runBsubScriptAsUser (child): seteuid 0"); + _exit(1); } + if (setgid(pw->pw_gid)) { + perror("runBsubScriptAsUser (child): setgid"); + _exit(1); + } + if (setuid(pw->pw_uid)) { + perror("runBsubScriptAsUser (child): setuid"); + _exit(1); + } arg0 = strrchr(scriptname, '/'); if (arg0) arg0++; execl(scriptname, arg0, NULL); @@ -1133,21 +1128,14 @@ service_uid = geteuid(); - if (pw->pw_uid != service_uid) { - /* if I'm already running as the osuser, I don't need */ - /* to change to root. Might be because besserver isn't */ - /* able to run as root */ + if (seteuid(0)) { + perror("createJobWrapperScript: seteuid 0 (1)"); + return BESE_SYS_ERR; + } - if (seteuid(0)) { - perror("createJobWrapperScript: seteuid 0 (1)"); - return BESE_SYS_ERR; - } - - if (seteuid(pw->pw_uid)) { - perror("createJobWrapperScript: seteuid user"); - return BESE_SYS_ERR; - } - + if (seteuid(pw->pw_uid)) { + perror("createJobWrapperScript: seteuid user"); + return BESE_SYS_ERR; } if (strlen(pw->pw_dir) + strlen("/jobscript.XXXXXX") + 1 > MAXPATHLEN) { @@ -1235,18 +1223,16 @@ fclose(wrapper); - if (pw->pw_uid != service_uid) { - if (seteuid(0)) { - perror("createJobWrapperScript: seteuid 0 (2)"); - unlink(wrappername); - return BESE_SYS_ERR; - } + if (seteuid(0)) { + perror("createJobWrapperScript: seteuid 0 (2)"); + unlink(wrappername); + return BESE_SYS_ERR; + } - if (seteuid(service_uid)) { - perror("createJobWrapperScript: seteuid service_uid"); - unlink(wrappername); - return BESE_SYS_ERR; - } + if (seteuid(service_uid)) { + perror("createJobWrapperScript: seteuid service_uid"); + unlink(wrappername); + return BESE_SYS_ERR; } strncpy(scriptname, wrappername, namelen-1); @@ -1414,23 +1400,18 @@ /* child process */ close(pfd[0]); - if (geteuid() != pw->pw_uid) { - /* if we're not already running as the user */ - /* making the request, make the change now */ - /* might happen when besserver is not run as root */ - if (seteuid(0)) { - perror("terminateLSFJob (child): seteuid 0"); - _exit(1); - } - if (setgid(pw->pw_gid)) { - perror("terminateLSFJob (child): setgid"); - _exit(1); - } - if (setuid(pw->pw_uid)) { - perror("terminateLSFJob (child): setuid"); - _exit(1); - } + if (seteuid(0)) { + perror("terminateLSFJob (child): seteuid 0"); + _exit(1); } + if (setgid(pw->pw_gid)) { + perror("terminateLSFJob (child): setgid"); + _exit(1); + } + if (setuid(pw->pw_uid)) { + perror("terminateLSFJob (child): setuid"); + _exit(1); + } if (lsb_signaljob(jobid, SIGKILL)) { lsb_perror("terminateLSFJob (child)"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zhq...@us...> - 2008-05-16 08:58:32
|
Revision: 47 http://bespp.svn.sourceforge.net/bespp/?rev=47&view=rev Author: zhq527725 Date: 2008-05-16 01:58:32 -0700 (Fri, 16 May 2008) Log Message: ----------- Add arguments checking for each bes_ functions. Modified Paths: -------------- trunk/besclient/bes.h trunk/besclient/besclient.c trunk/besclient/libbes.c Modified: trunk/besclient/bes.h =================================================================== --- trunk/besclient/bes.h 2008-05-15 21:54:16 UTC (rev 46) +++ trunk/besclient/bes.h 2008-05-16 08:58:32 UTC (rev 47) @@ -83,7 +83,7 @@ int bes_getActivityDocuments(struct bes_context *, epr_t, epr_t, char **); int bes_getFactoryAttributesDocument(struct bes_context *, epr_t, char **); void bes_freeEPR(epr_t *epr); -int bes_writeEPRToFile(struct bes_context *, epr_t, char *); +int bes_writeEPRToFile(struct bes_context *, char *, epr_t); int bes_readEPRFromFile(struct bes_context *, char *, epr_t *); #endif /* _BES_H */ Modified: trunk/besclient/besclient.c =================================================================== --- trunk/besclient/besclient.c 2008-05-15 21:54:16 UTC (rev 46) +++ trunk/besclient/besclient.c 2008-05-16 08:58:32 UTC (rev 47) @@ -153,7 +153,7 @@ } else { printf("Successfully submitted activity. Wrote EPR to %s\n", argv[2]); - if (bes_writeEPRToFile(ctx, new_activityepr, argv[2])) { + if (bes_writeEPRToFile(ctx, argv[2], new_activityepr)) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; } Modified: trunk/besclient/libbes.c =================================================================== --- trunk/besclient/libbes.c 2008-05-15 21:54:16 UTC (rev 46) +++ trunk/besclient/libbes.c 2008-05-16 08:58:32 UTC (rev 47) @@ -88,6 +88,10 @@ struct bes_context *ctx; struct soap *soap; + if (context == NULL) { + return BESE_BAD_ARG; + } + *context = NULL; ctx = (struct bes_context *)malloc(sizeof(struct bes_context)); @@ -120,6 +124,10 @@ bes_security(struct bes_context *context, char *x509cert, char *x509pass, char *capath, char *user, char *pass) { struct soap *soap; + + if (context == NULL) { + return BESE_BAD_ARG; + } soap = context->soap; @@ -162,6 +170,10 @@ int bes_add_usertoken(struct bes_context *context, char *user, char *pass) { + if (context == NULL) { + return BESE_BAD_ARG; + } + if (soap_wsse_add_UsernameTokenText(context->soap, NULL, user, pass)) { setErrorString(context, context->soap, BESE_SOAP_ERR); return BESE_SOAP_ERR; @@ -176,7 +188,7 @@ struct bes_context *ctx; if (context == NULL || *context == NULL) { - return -1; + return BESE_BAD_ARG; } ctx = *context; @@ -210,7 +222,11 @@ const char* bes_get_lasterror(struct bes_context *context) { - return context->error_string; + if (context) { + return context->error_string; + } + + return "No valid BES Context."; } int @@ -225,6 +241,13 @@ int jsdl, size = 0, ret = BESE_OK; char *endpoint; + if (context == NULL + || endpointepr == NULL + || jsdlfile == NULL + || activityepr == NULL) { + return BESE_BAD_ARG; + } + s = context->soap; if (ret = generateAddressHeader(context, endpointepr, CREATE_ACT, &endpoint)) { @@ -314,6 +337,10 @@ int i, ret = BESE_OK; char *endpoint; + if (context == NULL || activityepr == NULL || endpointepr == NULL) { + return BESE_BAD_ARG; + } + s = context->soap; epr = (struct bes_epr *)activityepr; @@ -353,6 +380,13 @@ int ret = BESE_OK; char *endpoint; + if (context == NULL + || activityepr == NULL + || status == NULL + || endpointepr == NULL) { + return BESE_BAD_ARG; + } + s = context->soap; epr = (struct bes_epr *)activityepr; @@ -446,6 +480,13 @@ int size = 0, ret = BESE_OK; char *endpoint, *str; + if (context == NULL + || endpointepr == NULL + || activityepr == NULL + || strDoc == NULL) { + return BESE_BAD_ARG; + } + s = context->soap; epr = (struct bes_epr *)activityepr; @@ -491,6 +532,10 @@ char *endpoint, *str; int size = 0, ret = BESE_OK; + if (context == NULL || endpointepr == NULL || strDoc == NULL) { + return BESE_BAD_ARG; + } + s = context->soap; if (ret = generateAddressHeader(context, endpointepr, FACTORY_ACT, &endpoint)) { @@ -544,13 +589,12 @@ *epr = NULL; } -int bes_writeEPRToFile(struct bes_context *context, epr_t epr, char *filename) +int bes_writeEPRToFile(struct bes_context *context, char *filename, epr_t epr) { struct bes_epr *tmpEPR; int fd; - if (!epr) { - setErrorString(context, NULL, BESE_BAD_ARG); + if (context == NULL || epr == NULL || filename == NULL) { return BESE_BAD_ARG; } @@ -577,9 +621,8 @@ struct soap_dom_element *dom; struct bes_epr *tmpEPR; struct stat fileStat; - - if (!epr) { - setErrorString(context, NULL, BESE_BAD_ARG); + + if (context == NULL || epr == NULL || filename == NULL) { return BESE_BAD_ARG; } @@ -951,7 +994,7 @@ struct soap_dom_element *dom, *iter; struct bes_epr *epr; char *endpoint; - + s = context->soap; epr = (struct bes_epr *)endpointepr; dom = epr->dom; @@ -968,9 +1011,7 @@ } s->header->wsa__To.__item = endpoint; - if (endpoint_ret) { - *endpoint_ret = endpoint; - } + *endpoint_ret = endpoint; s->header->wsa__Action.__item = soap_strdup(s, action); if (s->header->wsa__Action.__item == NULL) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-05-15 21:54:09
|
Revision: 46 http://bespp.svn.sourceforge.net/bespp/?rev=46&view=rev Author: csmith Date: 2008-05-15 14:54:16 -0700 (Thu, 15 May 2008) Log Message: ----------- allow besserver to run as regular user Modified Paths: -------------- trunk/besserver/job.c Modified: trunk/besserver/job.c =================================================================== --- trunk/besserver/job.c 2008-05-15 00:47:10 UTC (rev 45) +++ trunk/besserver/job.c 2008-05-15 21:54:16 UTC (rev 46) @@ -1067,18 +1067,23 @@ } close(pfd[1]); } - if (seteuid(0)) { - perror("runBsubScriptAsUser (child): setuid 0"); - _exit(1); + if (geteuid() != pw->pw_uid) { + /* if we're not already running as the user */ + /* making the request, make the change now */ + /* might happen when besserver is not run as root */ + if (seteuid(0)) { + perror("runBsubScriptAsUser (child): seteuid 0"); + _exit(1); + } + if (setgid(pw->pw_gid)) { + perror("runBsubScriptAsUser (child): setgid"); + _exit(1); + } + if (setuid(pw->pw_uid)) { + perror("runBsubScriptAsUser (child): setuid"); + _exit(1); + } } - if (setgid(pw->pw_gid)) { - perror("runBsubScriptAsUser (child): setgid"); - _exit(1); - } - if (setuid(pw->pw_uid)) { - perror("runBsubScriptAsUser (child): setuid"); - _exit(1); - } arg0 = strrchr(scriptname, '/'); if (arg0) arg0++; execl(scriptname, arg0, NULL); @@ -1128,14 +1133,21 @@ service_uid = geteuid(); - if (seteuid(0)) { - perror("createJobWrapperScript: seteuid 0 (1)"); - return BESE_SYS_ERR; - } + if (pw->pw_uid != service_uid) { + /* if I'm already running as the osuser, I don't need */ + /* to change to root. Might be because besserver isn't */ + /* able to run as root */ - if (seteuid(pw->pw_uid)) { - perror("createJobWrapperScript: seteuid user"); - return BESE_SYS_ERR; + if (seteuid(0)) { + perror("createJobWrapperScript: seteuid 0 (1)"); + return BESE_SYS_ERR; + } + + if (seteuid(pw->pw_uid)) { + perror("createJobWrapperScript: seteuid user"); + return BESE_SYS_ERR; + } + } if (strlen(pw->pw_dir) + strlen("/jobscript.XXXXXX") + 1 > MAXPATHLEN) { @@ -1223,16 +1235,18 @@ fclose(wrapper); - if (seteuid(0)) { - perror("createJobWrapperScript: seteuid 0 (2)"); - unlink(wrappername); - return BESE_SYS_ERR; - } + if (pw->pw_uid != service_uid) { + if (seteuid(0)) { + perror("createJobWrapperScript: seteuid 0 (2)"); + unlink(wrappername); + return BESE_SYS_ERR; + } - if (seteuid(service_uid)) { - perror("createJobWrapperScript: seteuid service_uid"); - unlink(wrappername); - return BESE_SYS_ERR; + if (seteuid(service_uid)) { + perror("createJobWrapperScript: seteuid service_uid"); + unlink(wrappername); + return BESE_SYS_ERR; + } } strncpy(scriptname, wrappername, namelen-1); @@ -1400,18 +1414,23 @@ /* child process */ close(pfd[0]); - if (seteuid(0)) { - perror("terminateLSFJob (child): setuid 0"); - _exit(1); + if (geteuid() != pw->pw_uid) { + /* if we're not already running as the user */ + /* making the request, make the change now */ + /* might happen when besserver is not run as root */ + if (seteuid(0)) { + perror("terminateLSFJob (child): seteuid 0"); + _exit(1); + } + if (setgid(pw->pw_gid)) { + perror("terminateLSFJob (child): setgid"); + _exit(1); + } + if (setuid(pw->pw_uid)) { + perror("terminateLSFJob (child): setuid"); + _exit(1); + } } - if (setgid(pw->pw_gid)) { - perror("terminateLSFJob (child): setgid"); - _exit(1); - } - if (setuid(pw->pw_uid)) { - perror("terminateLSFJob (child): setuid"); - _exit(1); - } if (lsb_signaljob(jobid, SIGKILL)) { lsb_perror("terminateLSFJob (child)"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-05-15 00:47:19
|
Revision: 45 http://bespp.svn.sourceforge.net/bespp/?rev=45&view=rev Author: csmith Date: 2008-05-14 17:47:10 -0700 (Wed, 14 May 2008) Log Message: ----------- refactored some macro and function names Modified Paths: -------------- trunk/besclient/bes.h trunk/besclient/besclient.c trunk/besclient/libbes.c Modified: trunk/besclient/bes.h =================================================================== --- trunk/besclient/bes.h 2008-05-09 18:09:38 UTC (rev 44) +++ trunk/besclient/bes.h 2008-05-15 00:47:10 UTC (rev 45) @@ -54,19 +54,19 @@ typedef void* epr_t; /* Error code */ -#define BES_OK 0 -#define BES_SOAP_ERR 1 -#define BES_SYS_ERR 2 -#define BES_ENDPOINT_ERR 3 -#define BES_MEM_ALLOC 4 -#define BES_GETSTATUS_ERR 5 -#define BES_BAD_ARG 6 +#define BESE_OK 0 +#define BESE_SOAP_ERR 1 +#define BESE_SYS_ERR 2 +#define BESE_ENDPOINT_ERR 3 +#define BESE_MEM_ALLOC 4 +#define BESE_GETSTATUS_ERR 5 +#define BESE_BAD_ARG 6 /*Error strings*/ -#define BES_ENDPOINT_STRING "The endpoint.xml does not contain a valid EPR" -#define BES_MEM_STRRING "Memory allocation error" -#define BES_GETSTATUS_STRING "Failed to get the status of activity" -#define BES_BAD_ARG_STRING "Bad arguments for the function" +#define BESE_ENDPOINT_STRING "The endpoint.xml does not contain a valid EPR" +#define BESE_MEM_STRING "Memory allocation error" +#define BESE_GETSTATUS_STRING "Failed to get the status of activity" +#define BESE_BAD_ARG_STRING "Bad arguments for the function" #define BES_FALSE 0 #define BES_TRUE 1 @@ -77,14 +77,14 @@ int bes_finalize(struct bes_context **); const char* bes_get_lasterror(struct bes_context *context); -int createActivity(struct bes_context *, epr_t, char *, epr_t *); -int terminateActivities(struct bes_context *, epr_t, epr_t); -int getActivityStatuses(struct bes_context *, epr_t, epr_t, struct bes_activity_status *); -int getActivityDocuments(struct bes_context *, epr_t, epr_t, char **); -int getFactoryAttributesDocument(struct bes_context *, epr_t, char **); -void freeEPR(epr_t *epr); -int writeEPRToFile(struct bes_context *, epr_t, char *); -int readEPRFromFile(struct bes_context *, char *, epr_t *); +int bes_createActivity(struct bes_context *, epr_t, char *, epr_t *); +int bes_terminateActivities(struct bes_context *, epr_t, epr_t); +int bes_getActivityStatuses(struct bes_context *, epr_t, epr_t, struct bes_activity_status *); +int bes_getActivityDocuments(struct bes_context *, epr_t, epr_t, char **); +int bes_getFactoryAttributesDocument(struct bes_context *, epr_t, char **); +void bes_freeEPR(epr_t *epr); +int bes_writeEPRToFile(struct bes_context *, epr_t, char *); +int bes_readEPRFromFile(struct bes_context *, char *, epr_t *); #endif /* _BES_H */ Modified: trunk/besclient/besclient.c =================================================================== --- trunk/besclient/besclient.c 2008-05-09 18:09:38 UTC (rev 44) +++ trunk/besclient/besclient.c 2008-05-15 00:47:10 UTC (rev 45) @@ -127,7 +127,7 @@ goto end; } - if (readEPRFromFile(ctx, endpoint, &endpointepr)) { + if (bes_readEPRFromFile(ctx, endpoint, &endpointepr)) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; goto end; @@ -137,7 +137,7 @@ || !strcmp(command, "terminate") || !strcmp(command, "activity") || !strcmp(command, "poll")) { - if (readEPRFromFile(ctx, argv[1], &activityepr)) { + if (bes_readEPRFromFile(ctx, argv[1], &activityepr)) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; goto end; @@ -147,24 +147,24 @@ if (!strcmp(command, "create")) { epr_t new_activityepr; - if (createActivity(ctx, endpointepr, argv[1], &new_activityepr)) { + if (bes_createActivity(ctx, endpointepr, argv[1], &new_activityepr)) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; } else { printf("Successfully submitted activity. Wrote EPR to %s\n", argv[2]); - if (writeEPRToFile(ctx, new_activityepr, argv[2])) { + if (bes_writeEPRToFile(ctx, new_activityepr, argv[2])) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; } - freeEPR(&new_activityepr); + bes_freeEPR(&new_activityepr); } } else if (!strcmp(command, "status")) { struct bes_activity_status status; - if (getActivityStatuses(ctx, endpointepr, activityepr, &status)) { + if (bes_getActivityStatuses(ctx, endpointepr, activityepr, &status)) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; } @@ -178,7 +178,7 @@ } else if (!strcmp(command, "terminate")) { - if (terminateActivities(ctx, endpointepr, activityepr)) { + if (bes_terminateActivities(ctx, endpointepr, activityepr)) { printf("The activity was canceled\n"); } else { @@ -190,7 +190,7 @@ else if (!strcmp(command, "activity")) { char *strDoc; - if (getActivityDocuments(ctx, endpointepr, activityepr, &strDoc)) { + if (bes_getActivityDocuments(ctx, endpointepr, activityepr, &strDoc)) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; } @@ -203,7 +203,7 @@ else if (!strcmp(command, "factory")) { char *strDoc; - if (getFactoryAttributesDocument(ctx, endpointepr, &strDoc)) { + if (bes_getFactoryAttributesDocument(ctx, endpointepr, &strDoc)) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; } @@ -223,7 +223,7 @@ } poll_interval = atoi(argv[2]); - while (!(ret = getActivityStatuses(ctx, endpointepr, activityepr, &status))) { + while (!(ret = bes_getActivityStatuses(ctx, endpointepr, activityepr, &status))) { if ((status.state == BES_Cancelled) || (status.state == BES_Failed) || (status.state == BES_Finished)) { @@ -262,11 +262,11 @@ } if (endpointepr) { - freeEPR(&endpointepr); + bes_freeEPR(&endpointepr); } if (activityepr) { - freeEPR(&activityepr); + bes_freeEPR(&activityepr); } end: Modified: trunk/besclient/libbes.c =================================================================== --- trunk/besclient/libbes.c 2008-05-09 18:09:38 UTC (rev 44) +++ trunk/besclient/libbes.c 2008-05-15 00:47:10 UTC (rev 45) @@ -40,7 +40,7 @@ #define FACTORY_ACT "http://schemas.ggf.org/bes/2006/08/bes-factory/BESFactoryPortType/GetFactoryAttributesDocument" #define WSA_NS "http://www.w3.org/2005/08/addressing" -#define BES_NS "http://schemas.ggf.org/bes/2006/08/bes-factory" +#define BESE_NS "http://schemas.ggf.org/bes/2006/08/bes-factory" #define NL "\n" @@ -57,7 +57,7 @@ struct Namespace epr_namespaces[] = { {"wsa", WSA_NS, NULL, NULL }, - {"bes", BES_NS, NULL, NULL }, + {"bes", BESE_NS, NULL, NULL }, {"xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance", NULL}, {NULL, NULL, NULL, NULL} }; @@ -92,13 +92,13 @@ ctx = (struct bes_context *)malloc(sizeof(struct bes_context)); if (ctx == NULL) { - return BES_SYS_ERR; + return BESE_SYS_ERR; } soap = (struct soap *)malloc(sizeof(struct soap)); if (soap == NULL) { free(ctx); - return BES_SYS_ERR; + return BESE_SYS_ERR; } memset(ctx, 0, sizeof(struct bes_context)); @@ -113,7 +113,7 @@ ctx->soap = soap; *context = ctx; - return BES_OK; + return BESE_OK; } int @@ -125,14 +125,14 @@ if (soap_ssl_client_context(soap, SOAP_SSL_DEFAULT|SOAP_SSL_SKIP_HOST_CHECK, x509cert, x509pass, NULL, capath, NULL)) { - setErrorString(context, context->soap, BES_SOAP_ERR); - return BES_SOAP_ERR; + setErrorString(context, context->soap, BESE_SOAP_ERR); + return BESE_SOAP_ERR; } if (user) { if (soap_wsse_add_UsernameTokenText(soap, NULL, user, pass)) { - setErrorString(context, context->soap, BES_SOAP_ERR); - return BES_SOAP_ERR; + setErrorString(context, context->soap, BESE_SOAP_ERR); + return BESE_SOAP_ERR; } } @@ -156,18 +156,18 @@ context->pass = strdup(pass); } - return BES_OK; + return BESE_OK; } int bes_add_usertoken(struct bes_context *context, char *user, char *pass) { if (soap_wsse_add_UsernameTokenText(context->soap, NULL, user, pass)) { - setErrorString(context, context->soap, BES_SOAP_ERR); - return BES_SOAP_ERR; + setErrorString(context, context->soap, BESE_SOAP_ERR); + return BESE_SOAP_ERR; } - return BES_OK; + return BESE_OK; } int @@ -205,7 +205,7 @@ free(ctx); *context = NULL; - return BES_OK; + return BESE_OK; } const char* bes_get_lasterror(struct bes_context *context) @@ -214,7 +214,7 @@ } int -createActivity(struct bes_context *context, epr_t endpointepr, char *jsdlfile, epr_t *activityepr) +bes_createActivity(struct bes_context *context, epr_t endpointepr, char *jsdlfile, epr_t *activityepr) { struct soap *s; struct bes__CreateActivityType req; @@ -222,7 +222,7 @@ struct soap_dom_element dom, *tmpdom; struct soap_dom_attribute *attr; struct bes_epr *epr; - int jsdl, size = 0, ret = BES_OK; + int jsdl, size = 0, ret = BESE_OK; char *endpoint; s = context->soap; @@ -233,8 +233,8 @@ jsdl = open(jsdlfile, O_RDONLY, 0); if (jsdl == -1) { - setErrorString(context, NULL, BES_SYS_ERR); - return BES_SYS_ERR; + setErrorString(context, NULL, BESE_SYS_ERR); + return BESE_SYS_ERR; } memset(&dom, 0, sizeof(struct soap_dom_element)); @@ -243,9 +243,9 @@ if (soap_begin_recv(dom.soap) || soap_in_xsd__anyType(dom.soap, NULL, &dom, NULL) == NULL || soap_end_recv(dom.soap)) { - setErrorString(context, dom.soap, BES_SOAP_ERR); + setErrorString(context, dom.soap, BESE_SOAP_ERR); close(jsdl); - ret = BES_SOAP_ERR; + ret = BESE_SOAP_ERR; goto end; } close(jsdl); @@ -256,8 +256,8 @@ req.bes__ActivityDocument.__any = &dom; if (soap_call___bes__CreateActivity(s, endpoint, CREATE_ACT, &req, &rsp) != SOAP_OK) { - setErrorString(context, s, BES_SOAP_ERR); - ret = BES_SOAP_ERR; + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; goto end; } else { @@ -269,8 +269,8 @@ epr = (struct bes_epr *)malloc(sizeof(struct bes_epr)); if (!epr) { soap_set_namespaces(s, default_namespaces); - setErrorString(context, NULL, BES_MEM_ALLOC); - ret = BES_MEM_ALLOC; + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; goto end; } memset(epr, 0, sizeof(struct bes_epr)); @@ -281,8 +281,8 @@ if (!epr->str) { free(epr); soap_set_namespaces(s, default_namespaces); - setErrorString(context, NULL, BES_MEM_ALLOC); - ret = BES_MEM_ALLOC; + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; goto end; } memset(epr->str, 0, size + 1); @@ -305,13 +305,13 @@ } int -terminateActivities(struct bes_context *context, epr_t endpointepr, epr_t activityepr) +bes_terminateActivities(struct bes_context *context, epr_t endpointepr, epr_t activityepr) { struct soap *s; struct bes__TerminateActivitiesType req; struct bes__TerminateActivitiesResponseType rsp; struct bes_epr *epr; - int i, ret = BES_OK; + int i, ret = BESE_OK; char *endpoint; s = context->soap; @@ -326,7 +326,7 @@ req.__any = epr->dom; if (soap_call___bes__TerminateActivities(s, endpoint, TERMINATE_ACT, req, &rsp) != SOAP_OK) { - setErrorString(context, s, BES_SOAP_ERR); + setErrorString(context, s, BESE_SOAP_ERR); ret = BES_FALSE; } else { @@ -344,13 +344,13 @@ } int -getActivityStatuses(struct bes_context *context, epr_t endpointepr, epr_t activityepr, struct bes_activity_status *status) +bes_getActivityStatuses(struct bes_context *context, epr_t endpointepr, epr_t activityepr, struct bes_activity_status *status) { struct soap *s; struct bes__GetActivityStatusesType req; struct bes__GetActivityStatusesResponseType rsp; struct bes_epr *epr; - int ret = BES_OK; + int ret = BESE_OK; char *endpoint; s = context->soap; @@ -367,8 +367,8 @@ req.__any = epr->dom; if (soap_call___bes__GetActivityStatuses(s, endpoint, STATUS_ACT, req, &rsp) != SOAP_OK) { - setErrorString(context, s, BES_SOAP_ERR); - ret = BES_SOAP_ERR; + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; goto end; } else { @@ -408,8 +408,8 @@ status->substate = (char *)malloc(size + 1); if (!status->substate) { - setErrorString(context, NULL, BES_MEM_ALLOC); - ret = BES_MEM_ALLOC; + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; goto end; } @@ -421,8 +421,8 @@ break; } else if(!strcmp(element->name,"Fault")) { - setErrorString(context, NULL, BES_GETSTATUS_ERR); - ret = BES_GETSTATUS_ERR; + setErrorString(context, NULL, BESE_GETSTATUS_ERR); + ret = BESE_GETSTATUS_ERR; goto end; } else { @@ -437,13 +437,13 @@ } int -getActivityDocuments(struct bes_context *context, epr_t endpointepr, epr_t activityepr, char **strDoc) +bes_getActivityDocuments(struct bes_context *context, epr_t endpointepr, epr_t activityepr, char **strDoc) { struct soap *s; struct bes__GetActivityDocumentsType req; struct bes__GetActivityDocumentsResponseType rsp; struct bes_epr *epr; - int size = 0, ret = BES_OK; + int size = 0, ret = BESE_OK; char *endpoint, *str; s = context->soap; @@ -458,8 +458,8 @@ req.__any = epr->dom; if (soap_call___bes__GetActivityDocuments(s, endpoint, ACTIVITIES_ACT, req, &rsp) != SOAP_OK) { - setErrorString(context, s, BES_SOAP_ERR); - ret = BES_SOAP_ERR; + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; goto end; } else { @@ -467,8 +467,8 @@ str = (char *)malloc(size + 1); if (!str) { - setErrorString(context, NULL, BES_MEM_ALLOC); - ret = BES_MEM_ALLOC; + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; goto end; } memset(str, 0, size + 1); @@ -483,13 +483,13 @@ } int -getFactoryAttributesDocument(struct bes_context *context, epr_t endpointepr, char **strDoc) +bes_getFactoryAttributesDocument(struct bes_context *context, epr_t endpointepr, char **strDoc) { struct soap *s; struct bes__GetFactoryAttributesDocumentType req; struct bes__GetFactoryAttributesDocumentResponseType rsp; char *endpoint, *str; - int size = 0, ret = BES_OK; + int size = 0, ret = BESE_OK; s = context->soap; @@ -501,16 +501,16 @@ memset(&rsp, 0, sizeof(struct bes__GetFactoryAttributesDocumentResponseType)); if (soap_call___bes__GetFactoryAttributesDocument(s, endpoint, FACTORY_ACT, &req, &rsp) != SOAP_OK) { - setErrorString(context, s, BES_SOAP_ERR); - ret = BES_SOAP_ERR; + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; } else { calcDomSize(rsp.__any, &size); str = (char *)malloc(size + 1); if (!str) { - setErrorString(context, NULL, BES_MEM_ALLOC); - return BES_MEM_ALLOC; + setErrorString(context, NULL, BESE_MEM_ALLOC); + return BESE_MEM_ALLOC; } memset(str, 0, size + 1); @@ -522,7 +522,7 @@ return ret; } -void freeEPR(epr_t *epr) +void bes_freeEPR(epr_t *epr) { struct bes_epr *tmpEPR; @@ -544,56 +544,56 @@ *epr = NULL; } -int writeEPRToFile(struct bes_context *context, epr_t epr, char *filename) +int bes_writeEPRToFile(struct bes_context *context, epr_t epr, char *filename) { struct bes_epr *tmpEPR; int fd; if (!epr) { - setErrorString(context, NULL, BES_BAD_ARG); - return BES_BAD_ARG; + setErrorString(context, NULL, BESE_BAD_ARG); + return BESE_BAD_ARG; } tmpEPR = (struct bes_epr *)(epr); fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); if (fd == -1) { - setErrorString(context, NULL, BES_SYS_ERR); - return BES_SYS_ERR; + setErrorString(context, NULL, BESE_SYS_ERR); + return BESE_SYS_ERR; } if (write(fd, tmpEPR->str, strlen(tmpEPR->str)) == -1) { - setErrorString(context, NULL, BES_SYS_ERR); - return BES_SYS_ERR; + setErrorString(context, NULL, BESE_SYS_ERR); + return BESE_SYS_ERR; } close(fd); - return BES_OK; + return BESE_OK; } -int readEPRFromFile(struct bes_context *context, char *filename, epr_t *epr) +int bes_readEPRFromFile(struct bes_context *context, char *filename, epr_t *epr) { - int fd, size = 0, ret = BES_OK; + int fd, size = 0, ret = BESE_OK; struct soap_dom_element *dom; struct bes_epr *tmpEPR; struct stat fileStat; if (!epr) { - setErrorString(context, NULL, BES_BAD_ARG); - return BES_BAD_ARG; + setErrorString(context, NULL, BESE_BAD_ARG); + return BESE_BAD_ARG; } fd = open(filename, O_RDONLY, 0); if (fd == -1) { - setErrorString(context, NULL, BES_SYS_ERR); - return BES_SYS_ERR; + setErrorString(context, NULL, BESE_SYS_ERR); + return BESE_SYS_ERR; } dom = (struct soap_dom_element *)soap_malloc(context->soap, sizeof(struct soap_dom_element)); if (!dom) { close(fd); - setErrorString(context, NULL, BES_MEM_ALLOC); - return BES_MEM_ALLOC; + setErrorString(context, NULL, BESE_MEM_ALLOC); + return BESE_MEM_ALLOC; } dom->soap = soap_new1(SOAP_DOM_TREE|SOAP_C_UTFSTRING); @@ -601,30 +601,30 @@ if (soap_begin_recv(dom->soap) || soap_in_xsd__anyType(dom->soap, NULL, dom, NULL) == NULL || soap_end_recv(dom->soap)) { - setErrorString(context, dom->soap, BES_SOAP_ERR); - ret = BES_SOAP_ERR; + setErrorString(context, dom->soap, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; goto error_end; } tmpEPR = (struct bes_epr *)malloc(sizeof(struct bes_epr)); if (!tmpEPR) { - setErrorString(context, NULL, BES_MEM_ALLOC); - ret = BES_MEM_ALLOC; + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; goto error_end; } memset(tmpEPR, 0, sizeof(struct bes_epr)); if (lseek(fd, 0, SEEK_SET) == -1) { free(tmpEPR); - setErrorString(context, NULL, BES_SYS_ERR); - ret = BES_SYS_ERR; + setErrorString(context, NULL, BESE_SYS_ERR); + ret = BESE_SYS_ERR; goto error_end; } if (fstat(fd, &fileStat)) { free(tmpEPR); - setErrorString(context, NULL, BES_SYS_ERR); - ret = BES_SYS_ERR; + setErrorString(context, NULL, BESE_SYS_ERR); + ret = BESE_SYS_ERR; goto error_end; } @@ -632,16 +632,16 @@ tmpEPR->str = (char *)malloc(size + 1); if (!tmpEPR->str) { free(tmpEPR); - setErrorString(context, NULL, BES_MEM_ALLOC); - ret = BES_MEM_ALLOC; + setErrorString(context, NULL, BESE_MEM_ALLOC); + ret = BESE_MEM_ALLOC; goto error_end; } memset(tmpEPR->str, 0, size + 1); if (read(fd, tmpEPR->str, size) == -1) { free(tmpEPR); - setErrorString(context, NULL, BES_SYS_ERR); - ret = BES_SYS_ERR; + setErrorString(context, NULL, BESE_SYS_ERR); + ret = BESE_SYS_ERR; goto error_end; } @@ -651,7 +651,7 @@ tmpEPR->domCreateFlag = FromMalloc; *epr = (epr_t)tmpEPR; - return BES_OK; + return BESE_OK; error_end: close(fd); @@ -958,13 +958,13 @@ iter = dom->elts; if (!iter || !isElement(iter, WSA_NS, "Address")) { - setErrorString(context, NULL, BES_ENDPOINT_ERR); - return BES_ENDPOINT_ERR; + setErrorString(context, NULL, BESE_ENDPOINT_ERR); + return BESE_ENDPOINT_ERR; } endpoint = soap_strdup(s, iter->data); if (endpoint == NULL) { - setErrorString(context, s, BES_SOAP_ERR); - return BES_SOAP_ERR; + setErrorString(context, s, BESE_SOAP_ERR); + return BESE_SOAP_ERR; } s->header->wsa__To.__item = endpoint; @@ -974,11 +974,11 @@ s->header->wsa__Action.__item = soap_strdup(s, action); if (s->header->wsa__Action.__item == NULL) { - setErrorString(context, s, BES_SOAP_ERR); - return BES_SOAP_ERR; + setErrorString(context, s, BESE_SOAP_ERR); + return BESE_SOAP_ERR; } - return BES_OK; + return BESE_OK; } @@ -993,14 +993,14 @@ struct soap_dom_element *refparams, *refparam; struct soap_dom_attribute *isrefparam; char *endpoint; - int epr, i, numrefparams, ret = BES_OK; + int epr, i, numrefparams, ret = BESE_OK; s = context->soap; epr = open(eprfile, O_RDONLY, 0); if (epr == -1) { - setErrorString(context, NULL, BES_SYS_ERR); - return BES_SYS_ERR; + setErrorString(context, NULL, BESE_SYS_ERR); + return BESE_SYS_ERR; } soap_set_namespaces(s, epr_namespaces); @@ -1011,10 +1011,10 @@ if (soap_begin_recv(dom.soap) || soap_in_xsd__anyType(dom.soap, NULL, &dom, NULL) == NULL || soap_end_recv(dom.soap)) { - setErrorString(context, dom.soap, BES_SOAP_ERR); + setErrorString(context, dom.soap, BESE_SOAP_ERR); soap_set_namespaces(s, namespaces); close(epr); - ret = BES_SOAP_ERR; + ret = BESE_SOAP_ERR; goto end; } close(epr); @@ -1023,14 +1023,14 @@ iter = dom.elts; if (!iter || !isElement(iter, WSA_NS, "Address")) { - setErrorString(context, NULL, BES_ENDPOINT_ERR); - ret = BES_ENDPOINT_ERR; + setErrorString(context, NULL, BESE_ENDPOINT_ERR); + ret = BESE_ENDPOINT_ERR; goto end; } endpoint = soap_strdup(s, iter->data); if (endpoint == NULL) { - setErrorString(context, s, BES_SOAP_ERR); - ret = BES_SOAP_ERR; + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; goto end; } s->header->wsa__To.__item = endpoint; @@ -1038,8 +1038,8 @@ s->header->wsa__Action.__item = soap_strdup(s, action); if (s->header->wsa__Action.__item == NULL) { - setErrorString(context, s, BES_SOAP_ERR); - ret = BES_SOAP_ERR; + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; goto end; } @@ -1048,8 +1048,8 @@ if (isElement(iter, WSA_NS, "ReferenceParameters")) { isrefparam = (struct soap_dom_attribute*)soap_malloc(s, sizeof(struct soap_dom_attribute)); if (isrefparam == NULL) { - setErrorString(context, s, BES_SOAP_ERR); - ret = BES_SOAP_ERR; + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; goto end; } memset(isrefparam, 0, sizeof(struct soap_dom_attribute)); @@ -1058,8 +1058,8 @@ isrefparam->name = soap_strdup(s, "wsa:IsReferenceParameter"); isrefparam->data = soap_strdup(s, "true"); if (!isrefparam->name || !isrefparam->data) { - setErrorString(context, s, BES_SOAP_ERR); - ret = BES_SOAP_ERR; + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; goto end; } @@ -1091,8 +1091,8 @@ refparams = (struct soap_dom_element*)soap_malloc(s, sizeof(struct soap_dom_element)*numrefparams); if (refparams == NULL) { - setErrorString(context, s, BES_SOAP_ERR); - ret = BES_SOAP_ERR; + setErrorString(context, s, BESE_SOAP_ERR); + ret = BESE_SOAP_ERR; goto end; } memset(refparams, 0, sizeof(struct soap_dom_element)*numrefparams); @@ -1175,28 +1175,28 @@ void setErrorString(struct bes_context *context, struct soap *s, int error_code) { switch (error_code) { - case BES_SOAP_ERR: + case BESE_SOAP_ERR: soap_sprint_fault(s, context->error_string, MAX_ERRSTR_LEN); break; - case BES_SYS_ERR: + case BESE_SYS_ERR: snprintf(context->error_string, MAX_ERRSTR_LEN, "System error: %s", strerror(errno)); break; - case BES_ENDPOINT_ERR: - snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BES_ENDPOINT_STRING); + case BESE_ENDPOINT_ERR: + snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BESE_ENDPOINT_STRING); break; - case BES_MEM_ALLOC: - snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BES_MEM_STRRING); + case BESE_MEM_ALLOC: + snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BESE_MEM_STRING); break; - case BES_GETSTATUS_ERR: - snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BES_GETSTATUS_STRING); + case BESE_GETSTATUS_ERR: + snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BESE_GETSTATUS_STRING); break; - case BES_BAD_ARG: - snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BES_BAD_ARG_STRING); + case BESE_BAD_ARG: + snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BESE_BAD_ARG_STRING); break; default: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-05-09 18:09:34
|
Revision: 44 http://bespp.svn.sourceforge.net/bespp/?rev=44&view=rev Author: csmith Date: 2008-05-09 11:09:38 -0700 (Fri, 09 May 2008) Log Message: ----------- fixed SEG fault when no generic_user specified and X.509 client auth used Modified Paths: -------------- trunk/besserver/auth.c Modified: trunk/besserver/auth.c =================================================================== --- trunk/besserver/auth.c 2008-05-09 17:50:19 UTC (rev 43) +++ trunk/besserver/auth.c 2008-05-09 18:09:38 UTC (rev 44) @@ -123,6 +123,11 @@ /* currently will just map to a generic user */ X509_free(clientcert); + if (!generic_user) { + /* no generic_user specified. Have no user to use for operations */ + return soap_receiver_fault(s, SYS_ERROR, NULL); + } + if (username && namelen) { strncpy(username, generic_user, namelen-1); username[namelen-1] = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-05-09 17:50:20
|
Revision: 43 http://bespp.svn.sourceforge.net/bespp/?rev=43&view=rev Author: csmith Date: 2008-05-09 10:50:19 -0700 (Fri, 09 May 2008) Log Message: ----------- - fixed namespace on sleep.jsdl - fixed wrapper not available on compute nodes Modified Paths: -------------- tags/release-1.0.1/besclient/sleep.jsdl tags/release-1.0.1/besserver/job.c Modified: tags/release-1.0.1/besclient/sleep.jsdl =================================================================== --- tags/release-1.0.1/besclient/sleep.jsdl 2008-05-08 23:30:24 UTC (rev 42) +++ tags/release-1.0.1/besclient/sleep.jsdl 2008-05-09 17:50:19 UTC (rev 43) @@ -5,7 +5,7 @@ <JobName>Sleep</JobName> </JobIdentification> <Application> - <HPCProfileApplication xmlns="http://schemas.ggf.org/jsdl/2006/07/jsdl-hpcp"> + <HPCProfileApplication xmlns="http://schemas.ggf.org/jsdl/2006/07/jsdl-hpcpa"> <Executable>sleep</Executable> <Argument>60</Argument> <Output>/dev/null</Output> Modified: tags/release-1.0.1/besserver/job.c =================================================================== --- tags/release-1.0.1/besserver/job.c 2008-05-08 23:30:24 UTC (rev 42) +++ tags/release-1.0.1/besserver/job.c 2008-05-09 17:50:19 UTC (rev 43) @@ -1109,7 +1109,7 @@ createJobWrapperScript(struct jobcard *jc, char *osuser, char *scriptname, int namelen) { static char fname[] = "createJobWrapperScript"; - char wrappername[64]; + char wrappername[MAXPATHLEN]; FILE *wrapper; int fd, i; struct passwd *pw; @@ -1129,34 +1129,37 @@ service_uid = geteuid(); if (seteuid(0)) { - perror("createJobWrapperScript: seteuid 0"); - unlink(fname); + perror("createJobWrapperScript: seteuid 0 (1)"); return BESE_SYS_ERR; } - strcpy(wrappername, "/tmp/jobscript.XXXXXX"); + if (seteuid(pw->pw_uid)) { + perror("createJobWrapperScript: seteuid user"); + return BESE_SYS_ERR; + } + + if (strlen(pw->pw_dir) + strlen("/jobscript.XXXXXX") + 1 > MAXPATHLEN) { + fprintf(stderr, "%s: cannot generate wrapper script: path too long\n", fname); + return BESE_SYS_ERR; + } + + sprintf(wrappername, "%s/jobscript.XXXXXX", pw->pw_dir); fd = mkstemp(wrappername); if (fd == -1) { perror("createJobWrapperScript: mkstemp"); return BESE_SYS_ERR; } - if (fchown(fd, pw->pw_uid, pw->pw_gid)) { - perror("createJobWrapperScript: fchown"); - unlink(fname); - return BESE_SYS_ERR; - } - if (fchmod(fd, S_IRWXU)) { perror("createJobWrapperScript: fchmod"); - unlink(fname); + unlink(wrappername); return BESE_SYS_ERR; } wrapper = fdopen(fd, "w"); if (wrapper == NULL) { perror("createJobWrapperScript: fdopen"); - unlink(fname); + unlink(wrappername); return BESE_SYS_ERR; } @@ -1169,7 +1172,7 @@ if (!cp) { fprintf(stderr, "%s: malformed source URI for file transfer %s\n", fname, file->source); fprintf(stderr, "%s: only support ftp URIs at this time\n", fname); - unlink(fname); + unlink(wrappername); return BESE_OTHER; } cp = cp + strlen("ftp://"); @@ -1200,7 +1203,7 @@ if (!cp) { fprintf(stderr, "%s: malformed target URI for file transfer %s\n", fname, file->target); fprintf(stderr, "%s: only support ftp URIs at this time\n", fname); - unlink(fname); + unlink(wrappername); return BESE_OTHER; } cp = cp + strlen("ftp://"); @@ -1215,14 +1218,20 @@ } fprintf(wrapper, "rm $0\n"); - + fprintf(wrapper, "exit $rc\n"); fclose(wrapper); + if (seteuid(0)) { + perror("createJobWrapperScript: seteuid 0 (2)"); + unlink(wrappername); + return BESE_SYS_ERR; + } + if (seteuid(service_uid)) { perror("createJobWrapperScript: seteuid service_uid"); - unlink(fname); + unlink(wrappername); return BESE_SYS_ERR; } @@ -1235,7 +1244,7 @@ submitLSFJob(struct jobcard *jc, int *return_jobid, char *osuser) { static char fname[] = "submitLSFJob"; - char scriptname[64], wrappername[64]; + char scriptname[MAXPATHLEN], wrappername[MAXPATHLEN]; char buf[512]; int fd, i, rc, jobid = 0, rr = 0; FILE *script; @@ -1329,7 +1338,7 @@ fprintf(script, "\" "); } - if ((rc = createJobWrapperScript(jc, osuser, wrappername, 64)) != BESE_OK) { + if ((rc = createJobWrapperScript(jc, osuser, wrappername, MAXPATHLEN)) != BESE_OK) { fclose(script); unlink(scriptname); return rc; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |