- Timestamp:
- Oct 22, 2014, 7:46:23 PM (10 years ago)
- Location:
- branches/PublicaMundi_David-devel/zoo-project/zoo-kernel
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/Makefile.in
r490 r512 12 12 JAVA_FILE=@JAVA_FILE@ 13 13 14 CFLAGS=@DEB_DEF@ -fpic ${ YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF15 LDFLAGS=-lcurl -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${ PYTHONLDFLAGS} ${PERLLDFLAGS} ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} -lfcgi -lcrypto ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${YAML_LDFLAGS}14 CFLAGS=@DEB_DEF@ -fpic ${GLIB_CPPFLAGS} ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF 15 LDFLAGS=-lcurl -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${GLIB_LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS} ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} -lfcgi -lcrypto ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${YAML_LDFLAGS} 16 16 17 17 PHPCFLAGS=@PHP_CPPFLAGS@ … … 59 59 gcc -fPIC ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c ulinet.c 60 60 61 service_zcfg.o: service_zcfg.c 62 gcc -fPIC ${GLIB_CPPFLAGS} ${XML2CFLAGS} -c service_zcfg.c 63 61 64 service_internal.o: service_internal.c service.h 62 65 g++ ${GDAL_CFLAGS} ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service_internal.c … … 92 95 g++ -g -O2 ${XML2CFLAGS} ${CFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PERLCFLAGS} ${PHPCFLAGS} ${PYTHON_ENABLED} ${JS_ENABLED} ${PHP_ENABLED} ${PERL_ENABLED} ${JAVA_ENABLED} -c zoo_service_loader.c -fno-common -DPIC -o zoo_service_loader.o 93 96 94 zoo_loader.cgi: version.h zoo_loader.c zoo_service_loader.o ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o service_internal.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE}97 zoo_loader.cgi: version.h zoo_loader.c service_zcfg.o zoo_service_loader.o ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o service_internal.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} 95 98 g++ -g -O2 ${JSCFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${RUBYCFLAGS} ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} -c zoo_loader.c -fno-common -DPIC -o zoo_loader.o 96 g++ ${JSCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o service_internal.o ${MS_FILE} ${PYTHON_FILE} ${PERL_FILE} ${PHP_FILE} ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi ${LDFLAGS}99 g++ ${JSCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o service_zcfg.o zoo_service_loader.o service_internal.o ${MS_FILE} ${PYTHON_FILE} ${PERL_FILE} ${PHP_FILE} ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi ${LDFLAGS} 97 100 98 101 zcfg2yaml: zcfg2yaml.c ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o service_internal.o ${MS_FILE} ${JS_FILE} ${RUBY_FILE} ${YAML_FILE} -
branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/ZOOMakefile.opts.in
r465 r512 16 16 XML2CFLAGS=@XML2_CPPFLAGS@ 17 17 XML2LDFLAGS=@XML2_LDFLAGS@ 18 19 GLIB_LDFLAGS=@GLIB_LDFLAGS@ 20 GLIB_CPPFLAGS=@GLIB_CPPFLAGS@ 18 21 19 22 PYTHONCFLAGS=@PYTHON_CPPFLAGS@ -
branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/configure.ac
r466 r512 190 190 XML2_CPPFLAGS=`$XML2CONFIG --cflags` 191 191 192 193 192 194 # Check headers file 193 195 CPPFLAGS_SAVE="$CPPFLAGS" … … 203 205 AC_SUBST([XML2_CPPFLAGS]) 204 206 AC_SUBST([XML2_LDFLAGS]) 207 208 209 210 GLIB_LDFLAGS=`pkg-config --libs glib-2.0` 211 GLIB_CPPFLAGS=`pkg-config --cflags glib-2.0` 212 213 AC_SUBST([GLIB_CPPFLAGS]) 214 AC_SUBST([GLIB_LDFLAGS]) 215 216 205 217 206 218 #============================================================================ -
branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/service.h
r490 r512 82 82 #define IOTYPE_SIZE MAP_SIZE+sizeof(NULL) 83 83 #define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE 84 #define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*) 84 #define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*)+sizeof(char*)+sizeof(char*) 85 //#define SERVICE_SIZE sizeof(struct service) 85 86 86 87 #define SHMSZ 27 … … 333 334 typedef struct service{ 334 335 char* name; 336 char* identifier; 337 char * zcfg; 335 338 struct map* content; 336 339 struct map* metadata; … … 407 410 if(tmp!=NULL){ 408 411 if(tmp->name!=NULL) 409 free(tmp->name); 412 free(tmp->name); 413 if (tmp->identifier!=NULL) 414 free(tmp->identifier); 415 if (tmp->zcfg!=NULL) 416 free(tmp->zcfg); 410 417 freeMap(&tmp->content); 411 418 if(tmp->content!=NULL) … … 873 880 static void dumpService(service* s){ 874 881 fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",s->name); 882 if (s->identifier !=NULL) 883 fprintf(stderr,"IDENTIFIER : %s \n",s->identifier); 884 if (s->zcfg !=NULL) 885 fprintf(stderr,"ZCFG PATH : %s \n",s->zcfg); 875 886 if(s->content!=NULL){ 876 887 fprintf(stderr,"CONTENT MAP\n"); -
branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/service_internal.h
r501 r512 26 26 #define ZOO_SERVICE_INTERNAL_H 1 27 27 28 #pragma once 28 #pragma once 29 29 30 30 #define DEFAULT_SERVICE_URL "http://www.zoo-project.org/" … … 38 38 #include <sys/stat.h> 39 39 #include <sys/types.h> 40 #include "cgic.h"40 //#include "cgic.h" 41 41 #ifndef WIN32 42 42 #include <sys/ipc.h> … … 67 67 #include <openssl/buffer.h> 68 68 69 extern int conf_read(const char*,maps*);69 extern int conf_read (const char *, maps *); 70 70 71 71 #ifdef USE_JS … … 80 80 81 81 #ifdef __cplusplus 82 extern "C" { 82 extern "C" 83 { 83 84 #endif 84 85 #include <libxml/parser.h> 85 86 #include <libxml/xpath.h> 86 87 87 static char *SERVICE_URL;88 static char *SERVICE_URL; 88 89 static xmlNsPtr usedNs[10]; 89 static char *nsName[10];90 static char *nsName[10]; 90 91 static xmlDocPtr iDocs[10]; 91 static int nbNs =0;92 static int nbDocs =0;92 static int nbNs = 0; 93 static int nbDocs = 0; 93 94 94 int getServiceFromYAML (maps*,char*,service**,char *name);95 int readServiceFile (maps*, char*,service**,char *);96 int isValidLang (maps*,const char*);95 int getServiceFromYAML (maps *, char *, service **, char *name); 96 int readServiceFile (maps *, char *, service **, char *); 97 int isValidLang (maps *, const char *); 97 98 98 void printHeaders (maps*);99 void unhandleStatus (maps*);100 int _updateStatus (maps*);101 char * getStatus(int);99 void printHeaders (maps *); 100 void unhandleStatus (maps *); 101 int _updateStatus (maps *); 102 char *getStatus (int); 102 103 103 104 #ifdef USE_JS 104 char * JSValToChar(JSContext*,jsval*);105 JSBool JSUpdateStatus (JSContext*,uintN,jsval *);105 char *JSValToChar (JSContext *, jsval *); 106 JSBool JSUpdateStatus (JSContext *, uintN, jsval *); 106 107 #endif 107 108 void URLDecode(char *);109 char *url_encode(char *);110 char *url_decode(char *);111 char* getEncoding(maps*);112 108 113 int zooXmlSearchForNs(const char*); 114 int zooXmlAddNs(xmlNodePtr,const char*,const char*); 115 void zooXmlCleanupNs(); 109 void URLDecode (char *); 110 char *url_encode (char *); 111 char *url_decode (char *); 112 char *getEncoding (maps *); 116 113 117 int zooXmlAddDoc(xmlNodePtr,const char*,const char*); 118 void zooXmlCleanupDocs(); 119 120 void printExceptionReportResponse(maps*,map*); 121 xmlNodePtr createExceptionReportNode(maps*,map*,int); 122 void printProcessResponse(maps*,map*,int,service*,const char*,int,maps*,maps*); 123 xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr,const char*,maps*); 124 void printGetCapabilitiesForProcess(maps*,xmlNodePtr,service*); 125 xmlNodePtr printDescribeProcessHeader(xmlDocPtr,const char*,maps*); 126 void printDescribeProcessForProcess(maps*,xmlNodePtr,service*); 127 void printFullDescription(int,elements*,const char*,xmlNsPtr,xmlNodePtr); 128 void printDocument(maps*,xmlDocPtr,int); 129 void printDescription(xmlNodePtr,xmlNsPtr,const char*,map*); 130 void printIOType(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*); 131 map* parseBoundingBox(const char*); 132 void printBoundingBox(xmlNsPtr,xmlNodePtr,map*); 133 void printBoundingBoxDocument(maps*,maps*,FILE*); 134 void printOutputDefinitions1(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*); 135 136 void outputResponse(service*,maps*,maps*,map*,int,maps*,int); 114 int zooXmlSearchForNs (const char *); 115 int zooXmlAddNs (xmlNodePtr, const char *, const char *); 116 void zooXmlCleanupNs (); 137 117 138 char *base64(const char*,int); 139 char *base64d(const char*,int,int*); 140 void ensureDecodedBase64(maps**); 118 int zooXmlAddDoc (xmlNodePtr, const char *, const char *); 119 void zooXmlCleanupDocs (); 120 void addPrefix (maps * conf, map * level, service * serv); 121 void printExceptionReportResponse (maps *, map *); 122 xmlNodePtr createExceptionReportNode (maps *, map *, int); 123 void printProcessResponse (maps *, map *, int, service *, const char *, int, 124 maps *, maps *); 125 xmlNodePtr printGetCapabilitiesHeader (xmlDocPtr, const char *, maps *); 126 void printGetCapabilitiesForProcess (maps *, xmlNodePtr, service *); 127 xmlNodePtr printDescribeProcessHeader (xmlDocPtr, const char *, maps *); 128 void printDescribeProcessForProcess (maps *, xmlNodePtr, service *); 129 void printFullDescription (int, elements *, const char *, xmlNsPtr, 130 xmlNodePtr); 131 void printDocument (maps *, xmlDocPtr, int); 132 void printDescription (xmlNodePtr, xmlNsPtr, const char *, map *); 133 void printIOType (xmlDocPtr, xmlNodePtr, xmlNsPtr, xmlNsPtr, xmlNsPtr, 134 elements *, maps *, const char *); 135 map *parseBoundingBox (const char *); 136 void printBoundingBox (xmlNsPtr, xmlNodePtr, map *); 137 void printBoundingBoxDocument (maps *, maps *, FILE *); 138 void printOutputDefinitions1 (xmlDocPtr, xmlNodePtr, xmlNsPtr, xmlNsPtr, 139 elements *, maps *, const char *); 141 140 142 char* addDefaultValues(maps**,elements*,maps*,int);141 void outputResponse (service *, maps *, maps *, map *, int, maps *, int); 143 142 144 int errorException(maps *, const char *, const char *, const char*); 143 char *base64 (const char *, int); 144 char *base64d (const char *, int, int *); 145 void ensureDecodedBase64 (maps **); 145 146 146 int checkForSoapEnvelope(xmlDocPtr);147 char *addDefaultValues (maps **, elements *, maps *, int); 147 148 148 void addToCache(maps*,char*,char*,char*,int); 149 char* isInCache(maps*,char*); 150 int runHttpRequests(maps**,maps**,HINTERNET*); 151 int loadRemoteFile(maps**,map**,HINTERNET*,char*); 149 int errorException (maps *, const char *, const char *, const char *); 152 150 153 char *readVSIFile(maps*,const char*); 154 void parseIdentifier(maps*,char*,char*,char*); 155 int updateStatus( maps*,const int,const char*); 156 char* getInputValue( maps*,const char*,size_t*); 157 int setOutputValue( maps*, const char*, char*, size_t); 151 int checkForSoapEnvelope (xmlDocPtr); 152 153 void addToCache (maps *, char *, char *, char *, int); 154 char *isInCache (maps *, char *); 155 int runHttpRequests (maps **, maps **, HINTERNET *); 156 int loadRemoteFile (maps **, map **, HINTERNET *, char *); 157 158 char *readVSIFile (maps *, const char *); 159 void parseIdentifier (maps *, char *, char *, char *); 160 int updateStatus (maps *, const int, const char *); 161 char *getInputValue (maps *, const char *, size_t *); 162 int setOutputValue (maps *, const char *, char *, size_t); 158 163 159 164 #ifdef __cplusplus -
branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_loader.c
r490 r512 31 31 #ifndef WIN32 32 32 #include "fcgio.h" 33 #include "fcgi_config.h" 33 #include "fcgi_config.h" 34 34 #include "fcgi_stdio.h" 35 35 #endif … … 42 42 #endif 43 43 44 extern "C" { 44 extern "C" 45 { 45 46 #include "cgic.h" 46 47 #include <libxml/tree.h> … … 49 50 #include <libxml/xpath.h> 50 51 #include <libxml/xpathInternals.h> 52 53 #include <string.h> 54 #include <stdio.h> 55 #include <stdlib.h> 56 #include <glib.h> 57 #include <sys/stat.h> 58 #include "service_zcfg.h" 51 59 } 52 60 53 61 #include "service_internal.h" 54 62 55 xmlXPathObjectPtr extractFromDoc (xmlDocPtr,const char*);56 int runRequest (map**);63 xmlXPathObjectPtr extractFromDoc (xmlDocPtr, const char *); 64 int runRequest (map **); 57 65 58 66 using namespace std; … … 65 73 #endif 66 74 67 int cgiMain(){ 68 /** 75 76 int 77 main (int argc, char *argv[]) 78 { 79 maps *m; 80 m = (maps *) malloc (MAP_SIZE); 81 conf_read ("main.cfg", m); 82 char ntmp[1024]; 83 #ifndef WIN32 84 getcwd (ntmp, 1024); 85 #else 86 _getcwd (ntmp, 1024); 87 #endif 88 char *rootDir = "/var/www/zoo-wps/cgi-bin"; 89 init_services_conf (rootDir); 90 91 92 while (FCGI_Accept () >= 0) 93 { 94 cgiMain_init (argc, argv); 95 /** 69 96 * We'll use cgiOut as the default output (stdout) to produce plain text 70 97 * response. 71 98 */ 72 dup2(fileno(cgiOut),fileno(stdout)); 99 dup2 (fileno (cgiOut), fileno (stdout)); 100 73 101 #ifdef DEBUG 74 fprintf(cgiOut,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); 75 fprintf(cgiOut,"Welcome on ZOO verbose debuging mode \r\n\r\n"); 76 fflush(cgiOut); 77 fprintf (stderr, "Addr:%s\n", cgiRemoteAddr); 78 fprintf (stderr, "RequestMethod: (%s) %d %d\n", cgiRequestMethod,strncasecmp(cgiRequestMethod,"post",4),strncmp(cgiContentType,"text/xml",8)==0 || strncasecmp(cgiRequestMethod,"post",4)==0); 79 fprintf (stderr, "Request: %s\n", cgiQueryString); 80 fprintf (stderr, "ContentType: %s\n", cgiContentType); 81 fprintf (stderr, "ContentLength: %d\n", cgiContentLength); 82 fflush(stderr); 83 #endif 84 85 86 char *strQuery=NULL; 87 if(cgiQueryString!=NULL) 88 strQuery=zStrdup(cgiQueryString); 89 map* tmpMap=NULL; 90 91 if(strncmp(cgiContentType,"text/xml",8)==0 || 92 strncasecmp(cgiRequestMethod,"post",4)==0){ 93 if(cgiContentLength==0){ 94 char *buffer=new char[2]; 95 char *res=NULL; 96 int r=0; 97 while((r=fread(buffer,sizeof(char),1,cgiIn))){ 98 buffer[1]=0; 99 cgiContentLength+=r; 100 if(res==NULL){ 101 res=(char*)malloc(2*sizeof(char)); 102 sprintf(res,"%s",buffer); 103 } 104 else{ 105 char *tmp=zStrdup(res); 106 res=(char*)realloc(res,(strlen(tmp)+2)*sizeof(char)); 107 sprintf(res,"%s%s",tmp,buffer); 108 free(tmp); 109 } 110 } 111 delete[] buffer; 112 if(res==NULL && (strQuery==NULL || strlen(strQuery)==0)){ 113 return errorException(NULL,"ZOO-Kernel failed to process your request cause the request was emtpty.","InternalError",NULL); 114 }else{ 115 if(strQuery==NULL || strlen(strQuery)==0) 116 tmpMap=createMap("request",res); 117 } 118 if(res!=NULL) 119 free(res); 120 }else{ 121 char *buffer=new char[cgiContentLength+1]; 122 if(fread(buffer,sizeof(char),cgiContentLength,cgiIn)>0){ 123 buffer[cgiContentLength]=0; 124 tmpMap=createMap("request",buffer); 125 }else{ 126 buffer[0]=0; 127 char **array, **arrayStep; 128 if (cgiFormEntries(&array) != cgiFormSuccess) { 129 return 1; 130 } 131 arrayStep = array; 132 while (*arrayStep) { 133 char *ivalue=new char[cgiContentLength]; 134 cgiFormStringNoNewlines(*arrayStep, ivalue, cgiContentLength); 135 char* tmpValueFinal=(char*) malloc((strlen(*arrayStep)+strlen(ivalue)+1)*sizeof(char)); 136 sprintf(tmpValueFinal,"%s=%s",*arrayStep,ivalue); 137 if(strlen(buffer)==0){ 138 sprintf(buffer,"%s",tmpValueFinal); 139 }else{ 140 char *tmp=zStrdup(buffer); 141 sprintf(buffer,"%s&%s",tmp,tmpValueFinal); 142 free(tmp); 143 } 144 free(tmpValueFinal); 102 fprintf (cgiOut, 103 "Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); 104 fprintf (cgiOut, "Welcome on ZOO verbose debuging mode \r\n\r\n"); 105 fflush (cgiOut); 106 fprintf (stderr, "Addr:%s\n", cgiRemoteAddr); 107 fprintf (stderr, "RequestMethod: (%s) %d %d\n", cgiRequestMethod, 108 strncasecmp (cgiRequestMethod, "post", 4), 109 strncmp (cgiContentType, "text/xml", 8) == 0 110 || strncasecmp (cgiRequestMethod, "post", 4) == 0); 111 fprintf (stderr, "Request: %s\n", cgiQueryString); 112 fprintf (stderr, "ContentType: %s\n", cgiContentType); 113 fprintf (stderr, "ContentLength: %d\n", cgiContentLength); 114 fflush (stderr); 115 #endif 116 117 118 char *strQuery = NULL; 119 if (cgiQueryString != NULL) 120 strQuery = zStrdup (cgiQueryString); 121 map *tmpMap = NULL; 122 123 if (strncmp (cgiContentType, "text/xml", 8) == 0 || 124 strncasecmp (cgiRequestMethod, "post", 4) == 0) 125 { 126 if (cgiContentLength == 0) 127 { 128 char *buffer = new char[2]; 129 char *res = NULL; 130 int r = 0; 131 while ((r = fread (buffer, sizeof (char), 1, cgiIn))) 132 { 133 buffer[1] = 0; 134 cgiContentLength += r; 135 if (res == NULL) 136 { 137 res = (char *) malloc (2 * sizeof (char)); 138 sprintf (res, "%s", buffer); 139 } 140 else 141 { 142 char *tmp = zStrdup (res); 143 res = 144 (char *) realloc (res, 145 (strlen (tmp) + 2) * sizeof (char)); 146 sprintf (res, "%s%s", tmp, buffer); 147 free (tmp); 148 } 149 } 150 delete[]buffer; 151 if (res == NULL && (strQuery == NULL || strlen (strQuery) == 0)) 152 { 153 return errorException (NULL, 154 "ZOO-Kernel failed to process your request cause the request was emtpty.", 155 "InternalError", NULL); 156 } 157 else 158 { 159 if (strQuery == NULL || strlen (strQuery) == 0) 160 tmpMap = createMap ("request", res); 161 } 162 if (res != NULL) 163 free (res); 164 } 165 else 166 { 167 char *buffer = new char[cgiContentLength + 1]; 168 if (fread (buffer, sizeof (char), cgiContentLength, cgiIn) > 0) 169 { 170 buffer[cgiContentLength] = 0; 171 tmpMap = createMap ("request", buffer); 172 } 173 else 174 { 175 buffer[0] = 0; 176 char **array, **arrayStep; 177 if (cgiFormEntries (&array) != cgiFormSuccess) 178 { 179 return 1; 180 } 181 arrayStep = array; 182 while (*arrayStep) 183 { 184 char *ivalue = new char[cgiContentLength]; 185 cgiFormStringNoNewlines (*arrayStep, ivalue, 186 cgiContentLength); 187 char *tmpValueFinal = 188 (char *) 189 malloc ((strlen (*arrayStep) + strlen (ivalue) + 190 1) * sizeof (char)); 191 sprintf (tmpValueFinal, "%s=%s", *arrayStep, ivalue); 192 if (strlen (buffer) == 0) 193 { 194 sprintf (buffer, "%s", tmpValueFinal); 195 } 196 else 197 { 198 char *tmp = zStrdup (buffer); 199 sprintf (buffer, "%s&%s", tmp, tmpValueFinal); 200 free (tmp); 201 } 202 free (tmpValueFinal); 145 203 #ifdef DEBUG 146 fprintf(stderr,"(( \n %s \n %s \n ))",*arrayStep,ivalue); 147 #endif 148 delete[]ivalue; 149 arrayStep++; 150 } 151 if(tmpMap!=NULL) 152 addToMap(tmpMap,"request",buffer); 153 else 154 tmpMap=createMap("request",buffer); 155 } 156 delete[]buffer; 157 } 158 } 159 else{ 204 fprintf (stderr, "(( \n %s \n %s \n ))", *arrayStep, 205 ivalue); 206 #endif 207 delete[]ivalue; 208 arrayStep++; 209 } 210 if (tmpMap != NULL) 211 addToMap (tmpMap, "request", buffer); 212 else 213 tmpMap = createMap ("request", buffer); 214 } 215 delete[]buffer; 216 } 217 } 218 else 219 { 160 220 #ifdef DEBUG 161 dumpMap(tmpMap); 162 #endif 163 char **array, **arrayStep; 164 if (cgiFormEntries(&array) != cgiFormSuccess) { 165 return 1; 166 } 167 arrayStep = array; 168 while (*arrayStep) { 169 char *value=new char[cgiContentLength]; 170 cgiFormStringNoNewlines(*arrayStep, value, cgiContentLength); 221 dumpMap (tmpMap); 222 #endif 223 char **array, **arrayStep; 224 if (cgiFormEntries (&array) != cgiFormSuccess) 225 { 226 return 1; 227 } 228 arrayStep = array; 229 while (*arrayStep) 230 { 231 char *value = new char[cgiContentLength]; 232 cgiFormStringNoNewlines (*arrayStep, value, cgiContentLength); 171 233 #ifdef DEBUG 172 fprintf(stderr,"(( \n %s \n %s \n ))",*arrayStep,value);173 #endif 174 if(tmpMap!=NULL)175 addToMap(tmpMap,*arrayStep,value);176 else177 tmpMap=createMap(*arrayStep,value);178 arrayStep++;179 delete[]value;180 }181 cgiStringArrayFree(array);182 }234 fprintf (stderr, "(( \n %s \n %s \n ))", *arrayStep, value); 235 #endif 236 if (tmpMap != NULL) 237 addToMap (tmpMap, *arrayStep, value); 238 else 239 tmpMap = createMap (*arrayStep, value); 240 arrayStep++; 241 delete[]value; 242 } 243 cgiStringArrayFree (array); 244 } 183 245 184 246 #ifdef WIN32 185 map *tmpReq=getMap(tmpMap,"rfile"); 186 if(tmpReq!=NULL){ 187 FILE *lf=fopen(tmpReq->value,"r"); 188 fseek(lf,0,SEEK_END); 189 long flen=ftell(lf); 190 fseek(lf,0,SEEK_SET); 191 char *buffer=(char*)malloc((flen+1)*sizeof(char)); 192 fread(buffer,flen,1,lf); 193 fclose(lf); 194 addToMap(tmpMap,"request",buffer); 195 free(buffer); 196 cgiContentLength=flen+9; 197 } 247 map *tmpReq = getMap (tmpMap, "rfile"); 248 if (tmpReq != NULL) 249 { 250 FILE *lf = fopen (tmpReq->value, "r"); 251 fseek (lf, 0, SEEK_END); 252 long flen = ftell (lf); 253 fseek (lf, 0, SEEK_SET); 254 char *buffer = (char *) malloc ((flen + 1) * sizeof (char)); 255 fread (buffer, flen, 1, lf); 256 fclose (lf); 257 addToMap (tmpMap, "request", buffer); 258 free (buffer); 259 cgiContentLength = flen + 9; 260 } 198 261 #endif 199 262 /** … … 202 265 * one. 203 266 */ 204 if(strncasecmp(cgiRequestMethod,"post",4)==0 ||205 (count(tmpMap)==1 && strncmp(tmpMap->value,"<",1)==0)267 if (strncasecmp (cgiRequestMethod, "post", 4) == 0 || 268 (count (tmpMap) == 1 && strncmp (tmpMap->value, "<", 1) == 0) 206 269 #ifdef WIN32 207 ||tmpReq!=NULL 208 #endif 209 ){ 270 || tmpReq != NULL 271 #endif 272 ) 273 { 210 274 /** 211 275 * Store the original XML request in xrequest map 212 276 */ 213 map* t1=getMap(tmpMap,"request"); 214 if(t1!=NULL && strncasecmp(t1->value,"<",1)==0){ 215 addToMap(tmpMap,"xrequest",t1->value); 216 xmlInitParser(); 217 xmlDocPtr doc = xmlParseMemory(t1->value,cgiContentLength); 218 { 219 xmlXPathObjectPtr reqptr=extractFromDoc(doc,"/*[local-name()='Envelope']/*[local-name()='Body']/*"); 220 if(reqptr!=NULL){ 221 xmlNodeSet* req=reqptr->nodesetval; 222 if(req!=NULL && req->nodeNr==1){ 223 addToMap(tmpMap,"soap","true"); 224 for(int k=0;k < req->nodeNr;k++){ 225 //xmlNsPtr ns=xmlNewNs(req->nodeTab[k],BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi"); 226 xmlDocSetRootElement(doc, req->nodeTab[k]); 227 xmlChar *xmlbuff; 228 int buffersize; 229 xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, "utf-8", 1); 230 addToMap(tmpMap,"xrequest",(char*)xmlbuff); 231 xmlFree(xmlbuff); 232 } 233 } 234 xmlXPathFreeObject(reqptr); 235 } 236 } 237 238 xmlNodePtr cur = xmlDocGetRootElement(doc); 239 char *tval; 240 tval=NULL; 241 tval = (char*) xmlGetProp(cur,BAD_CAST "service"); 242 if(tval!=NULL){ 243 addToMap(tmpMap,"service",tval); 244 xmlFree(tval); 245 } 246 tval=NULL; 247 tval = (char*) xmlGetProp(cur,BAD_CAST "language"); 248 if(tval!=NULL){ 249 addToMap(tmpMap,"language",tval); 250 xmlFree(tval); 251 } 252 const char* requests[3]={"GetCapabilities","DescribeProcess","Execute"}; 253 for(int j=0;j<3;j++){ 254 char tt[128]; 255 sprintf(tt,"/*[local-name()='%s']",requests[j]); 256 xmlXPathObjectPtr reqptr=extractFromDoc(doc,tt); 257 if(reqptr!=NULL){ 258 xmlNodeSet* req=reqptr->nodesetval; 277 map *t1 = getMap (tmpMap, "request"); 278 if (t1 != NULL && strncasecmp (t1->value, "<", 1) == 0) 279 { 280 addToMap (tmpMap, "xrequest", t1->value); 281 xmlInitParser (); 282 xmlDocPtr doc = xmlParseMemory (t1->value, cgiContentLength); 283 { 284 xmlXPathObjectPtr reqptr = extractFromDoc (doc, 285 "/*[local-name()='Envelope']/*[local-name()='Body']/*"); 286 if (reqptr != NULL) 287 { 288 xmlNodeSet *req = reqptr->nodesetval; 289 if (req != NULL && req->nodeNr == 1) 290 { 291 addToMap (tmpMap, "soap", "true"); 292 for (int k = 0; k < req->nodeNr; k++) 293 { 294 //xmlNsPtr ns=xmlNewNs(req->nodeTab[k],BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi"); 295 xmlDocSetRootElement (doc, req->nodeTab[k]); 296 xmlChar *xmlbuff; 297 int buffersize; 298 xmlDocDumpFormatMemoryEnc (doc, &xmlbuff, 299 &buffersize, "utf-8", 300 1); 301 addToMap (tmpMap, "xrequest", (char *) xmlbuff); 302 xmlFree (xmlbuff); 303 } 304 } 305 xmlXPathFreeObject (reqptr); 306 } 307 } 308 309 xmlNodePtr cur = xmlDocGetRootElement (doc); 310 char *tval; 311 tval = NULL; 312 tval = (char *) xmlGetProp (cur, BAD_CAST "service"); 313 if (tval != NULL) 314 { 315 addToMap (tmpMap, "service", tval); 316 xmlFree (tval); 317 } 318 tval = NULL; 319 tval = (char *) xmlGetProp (cur, BAD_CAST "language"); 320 if (tval != NULL) 321 { 322 addToMap (tmpMap, "language", tval); 323 xmlFree (tval); 324 } 325 const char *requests[3] = 326 { "GetCapabilities", "DescribeProcess", "Execute" }; 327 for (int j = 0; j < 3; j++) 328 { 329 char tt[128]; 330 sprintf (tt, "/*[local-name()='%s']", requests[j]); 331 xmlXPathObjectPtr reqptr = extractFromDoc (doc, tt); 332 if (reqptr != NULL) 333 { 334 xmlNodeSet *req = reqptr->nodesetval; 259 335 #ifdef DEBUG 260 fprintf(stderr,"%i",req->nodeNr); 261 #endif 262 if(req!=NULL && req->nodeNr==1){ 263 if(t1->value!=NULL) 264 free(t1->value); 265 t1->value=zStrdup(requests[j]); 266 j=2; 267 } 268 xmlXPathFreeObject(reqptr); 269 } 270 } 271 if(strncasecmp(t1->value,"GetCapabilities",15)==0){ 272 xmlXPathObjectPtr versptr=extractFromDoc(doc,"/*/*/*[local-name()='Version']"); 273 xmlNodeSet* vers=versptr->nodesetval; 274 xmlChar* content=xmlNodeListGetString(doc, vers->nodeTab[0]->xmlChildrenNode,1); 275 addToMap(tmpMap,"version",(char*)content); 276 xmlXPathFreeObject(versptr); 277 xmlFree(content); 278 }else{ 279 tval=NULL; 280 tval = (char*) xmlGetProp(cur,BAD_CAST "version"); 281 if(tval!=NULL){ 282 addToMap(tmpMap,"version",tval); 283 xmlFree(tval); 284 } 285 tval = (char*) xmlGetProp(cur,BAD_CAST "language"); 286 if(tval!=NULL){ 287 addToMap(tmpMap,"language",tval); 288 xmlFree(tval); 289 } 290 xmlXPathObjectPtr idptr=extractFromDoc(doc,"/*/*[local-name()='Identifier']"); 291 if(idptr!=NULL){ 292 xmlNodeSet* id=idptr->nodesetval; 293 if(id!=NULL){ 294 char* identifiers=NULL; 295 identifiers=(char*)calloc(cgiContentLength,sizeof(char)); 296 identifiers[0]=0; 297 for(int k=0;k<id->nodeNr;k++){ 298 xmlChar* content=xmlNodeListGetString(doc, id->nodeTab[k]->xmlChildrenNode,1); 299 if(strlen(identifiers)>0){ 300 char *tmp=zStrdup(identifiers); 301 snprintf(identifiers,strlen(tmp)+xmlStrlen(content)+2,"%s,%s",tmp,content); 302 free(tmp); 303 } 304 else{ 305 snprintf(identifiers,xmlStrlen(content)+1,"%s",content); 306 } 307 xmlFree(content); 308 } 309 xmlXPathFreeObject(idptr); 310 addToMap(tmpMap,"Identifier",identifiers); 311 free(identifiers); 312 } 313 } 314 } 315 xmlFreeDoc(doc); 316 xmlCleanupParser(); 317 }else{ 318 freeMap(&tmpMap); 319 free(tmpMap); 320 tmpMap=createMap("not_valid","true"); 321 } 322 323 char *token,*saveptr; 324 token=strtok_r(cgiQueryString,"&",&saveptr); 325 while(token!=NULL){ 326 char *token1,*saveptr1; 327 char *name=NULL; 328 char *value=NULL; 329 token1=strtok_r(token,"=",&saveptr1); 330 while(token1!=NULL){ 331 if(name==NULL) 332 name=zStrdup(token1); 333 else 334 value=zStrdup(token1); 335 token1=strtok_r(NULL,"=",&saveptr1); 336 } 337 addToMap(tmpMap,name,value); 338 free(name); 339 free(value); 340 name=NULL; 341 value=NULL; 342 token=strtok_r(NULL,"&",&saveptr); 343 } 344 345 } 346 347 if(strncasecmp(cgiContentType,"multipart/form-data",19)==0){ 348 map* tmp=getMap(tmpMap,"dataInputs"); 349 if(tmp!=NULL){ 350 addToMap(tmpMap,"dataInputs",strstr(strQuery,"dataInputs=")+11); 351 } 352 } 353 354 if(strQuery!=NULL) 355 free(strQuery); 356 357 runRequest(&tmpMap); 336 fprintf (stderr, "%i", req->nodeNr); 337 #endif 338 if (req != NULL && req->nodeNr == 1) 339 { 340 if (t1->value != NULL) 341 free (t1->value); 342 t1->value = zStrdup (requests[j]); 343 j = 2; 344 } 345 xmlXPathFreeObject (reqptr); 346 } 347 } 348 if (strncasecmp (t1->value, "GetCapabilities", 15) == 0) 349 { 350 xmlXPathObjectPtr versptr = 351 extractFromDoc (doc, "/*/*/*[local-name()='Version']"); 352 xmlNodeSet *vers = versptr->nodesetval; 353 xmlChar *content = xmlNodeListGetString (doc, 354 vers-> 355 nodeTab 356 [0]->xmlChildrenNode, 357 1); 358 addToMap (tmpMap, "version", (char *) content); 359 xmlXPathFreeObject (versptr); 360 xmlFree (content); 361 } 362 else 363 { 364 tval = NULL; 365 tval = (char *) xmlGetProp (cur, BAD_CAST "version"); 366 if (tval != NULL) 367 { 368 addToMap (tmpMap, "version", tval); 369 xmlFree (tval); 370 } 371 tval = (char *) xmlGetProp (cur, BAD_CAST "language"); 372 if (tval != NULL) 373 { 374 addToMap (tmpMap, "language", tval); 375 xmlFree (tval); 376 } 377 xmlXPathObjectPtr idptr = 378 extractFromDoc (doc, "/*/*[local-name()='Identifier']"); 379 if (idptr != NULL) 380 { 381 xmlNodeSet *id = idptr->nodesetval; 382 if (id != NULL) 383 { 384 char *identifiers = NULL; 385 identifiers = 386 (char *) calloc (cgiContentLength, sizeof (char)); 387 identifiers[0] = 0; 388 for (int k = 0; k < id->nodeNr; k++) 389 { 390 xmlChar *content = xmlNodeListGetString (doc, 391 id->nodeTab 392 [k]-> 393 xmlChildrenNode, 394 1); 395 if (strlen (identifiers) > 0) 396 { 397 char *tmp = zStrdup (identifiers); 398 snprintf (identifiers, 399 strlen (tmp) + 400 xmlStrlen (content) + 2, "%s,%s", 401 tmp, content); 402 free (tmp); 403 } 404 else 405 { 406 snprintf (identifiers, 407 xmlStrlen (content) + 1, "%s", 408 content); 409 } 410 xmlFree (content); 411 } 412 xmlXPathFreeObject (idptr); 413 addToMap (tmpMap, "Identifier", identifiers); 414 free (identifiers); 415 } 416 } 417 } 418 xmlFreeDoc (doc); 419 xmlCleanupParser (); 420 } 421 else 422 { 423 freeMap (&tmpMap); 424 free (tmpMap); 425 tmpMap = createMap ("not_valid", "true"); 426 } 427 428 char *token, *saveptr; 429 token = strtok_r (cgiQueryString, "&", &saveptr); 430 while (token != NULL) 431 { 432 char *token1, *saveptr1; 433 char *name = NULL; 434 char *value = NULL; 435 token1 = strtok_r (token, "=", &saveptr1); 436 while (token1 != NULL) 437 { 438 if (name == NULL) 439 name = zStrdup (token1); 440 else 441 value = zStrdup (token1); 442 token1 = strtok_r (NULL, "=", &saveptr1); 443 } 444 addToMap (tmpMap, name, value); 445 free (name); 446 free (value); 447 name = NULL; 448 value = NULL; 449 token = strtok_r (NULL, "&", &saveptr); 450 } 451 452 } 453 454 if (strncasecmp (cgiContentType, "multipart/form-data", 19) == 0) 455 { 456 map *tmp = getMap (tmpMap, "dataInputs"); 457 if (tmp != NULL) 458 { 459 addToMap (tmpMap, "dataInputs", 460 strstr (strQuery, "dataInputs=") + 11); 461 } 462 } 463 464 if (strQuery != NULL) 465 free (strQuery); 466 467 runRequest (&tmpMap); 358 468 359 469 /** 360 470 * Required but can't be made after executing a process using POST requests. 361 471 */ 362 if(/*strncasecmp(cgiRequestMethod,"post",4)!=0 && count(tmpMap)!=1 && */tmpMap!=NULL){ 363 freeMap(&tmpMap); 364 free(tmpMap); 365 } 472 if ( /*strncasecmp(cgiRequestMethod,"post",4)!=0 && count(tmpMap)!=1 && */ tmpMap != NULL) 473 { 474 freeMap (&tmpMap); 475 free (tmpMap); 476 } 477 cgiFreeResources (); 478 } 479 FCGI_Finish (); 366 480 return 0; 367 481 -
branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_service_loader.c
r504 r512 25 25 #define length(x) (sizeof(x) / sizeof(x[0])) 26 26 27 extern "C" int yylex ();28 extern "C" int crlex ();27 extern "C" int yylex (); 28 extern "C" int crlex (); 29 29 30 30 #include "cgic.h" 31 31 32 extern "C" { 32 extern "C" 33 { 33 34 #include <libxml/tree.h> 34 35 #include <libxml/xmlmemory.h> … … 36 37 #include <libxml/xpath.h> 37 38 #include <libxml/xpathInternals.h> 39 #include "service_zcfg.h" 38 40 } 39 41 … … 45 47 46 48 #include "service.h" 49 47 50 48 51 #include "service_internal.h" … … 91 94 92 95 #ifdef WIN32 93 extern "C" { 94 __declspec(dllexport) char *strcasestr(char const *a, char const *b) 96 extern "C" 97 { 98 __declspec (dllexport) char *strcasestr (char const *a, char const *b) 95 99 #ifndef USE_MS 96 {97 char *x=zStrdup(a);98 char *y=zStrdup(b);99 100 x=_strlwr(x);101 y=_strlwr(y);102 char *pos = strstr(x, y);103 char *ret = pos == NULL ? NULL : (char *)(a + (pos-x));104 free(x);105 free(y);106 return ret;107 };100 { 101 char *x = zStrdup (a); 102 char *y = zStrdup (b); 103 104 x = _strlwr (x); 105 y = _strlwr (y); 106 char *pos = strstr (x, y); 107 char *ret = pos == NULL ? NULL : (char *) (a + (pos - x)); 108 free (x); 109 free (y); 110 return ret; 111 }; 108 112 #else 109 ;113 ; 110 114 #endif 111 115 } … … 115 119 #define __(String) dgettext ("zoo-service",String) 116 120 117 extern int getServiceFromFile(maps*,const char*,service**); 118 119 int readServiceFile(maps* conf, char* file,service** service,char *name){ 120 int t=getServiceFromFile(conf,file,service); 121 extern int getServiceFromFile (maps *, const char *, service **); 122 123 int 124 readServiceFile (maps * conf, char *file, service ** service, char *name) 125 { 126 int t = getServiceFromFile (conf, file, service); 121 127 #ifdef YAML 122 if(t<0){ 123 t=getServiceFromYAML(conf,file,service,name); 124 } 128 if (t < 0) 129 { 130 t = getServiceFromYAML (conf, file, service, name); 131 } 125 132 #endif 126 133 return t; 127 134 } 128 135 129 void translateChar(char* str,char toReplace,char toReplaceBy){ 130 int i=0,len=strlen(str); 131 for(i=0;i<len;i++){ 132 if(str[i]==toReplace) 133 str[i]=toReplaceBy; 134 } 136 void 137 translateChar (char *str, char toReplace, char toReplaceBy) 138 { 139 int i = 0, len = strlen (str); 140 for (i = 0; i < len; i++) 141 { 142 if (str[i] == toReplace) 143 str[i] = toReplaceBy; 144 } 135 145 } 136 146 … … 139 149 * value = "["",""]" 140 150 */ 141 int appendMapsToMaps(maps* m,maps* mo,maps* mi,elements* elem){ 142 maps* tmpMaps=getMaps(mo,mi->name); 143 map* tmap=getMapType(tmpMaps->content); 144 elements* el=getElements(elem,mi->name); 145 int hasEl=1; 146 if(el==NULL) 147 hasEl=-1; 148 if(tmap==NULL){ 149 if(hasEl>0) 150 tmap=getMapType(el->defaults->content); 151 } 152 153 map* testMap=NULL; 154 if(hasEl>0){ 155 testMap=getMap(el->content,"maxOccurs"); 156 }else{ 157 testMap=createMap("maxOccurs","unbounded"); 158 } 159 160 if(testMap!=NULL){ 161 if(strncasecmp(testMap->value,"unbounded",9)!=0 && atoi(testMap->value)>1){ 162 if(addMapsArrayToMaps(&mo,mi,tmap->name)<0){ 163 char emsg[1024]; 164 sprintf(emsg,_("You set maximum occurences for <%s> as %i but you tried to use it more than the limit you set. Please correct your ZCFG file or your request."),mi->name,atoi(testMap->value)); 165 errorException(m,emsg,"InternalError",NULL); 166 return -1; 167 } 168 }else{ 169 if(strncasecmp(testMap->value,"unbounded",9)==0){ 170 if(hasEl<0){ 171 freeMap(&testMap); 172 free(testMap); 173 } 174 if(addMapsArrayToMaps(&mo,mi,tmap->name)<0){ 175 char emsg[1024]; 176 map* tmpMap=getMap(mi->content,"length"); 177 sprintf(emsg,_("ZOO-Kernel was unable to load your data for %s position %s."),mi->name,tmpMap->value); 178 errorException(m,emsg,"InternalError",NULL); 179 return -1; 180 } 181 } 182 else{ 183 char emsg[1024]; 184 sprintf(emsg,_("You set maximum occurences for <%s> to one but you tried to use it more than once. Please correct your ZCFG file or your request."),mi->name); 185 errorException(m,emsg,"InternalError",NULL); 186 return -1; 187 } 188 } 189 } 151 int 152 appendMapsToMaps (maps * m, maps * mo, maps * mi, elements * elem) 153 { 154 maps *tmpMaps = getMaps (mo, mi->name); 155 map *tmap = getMapType (tmpMaps->content); 156 elements *el = getElements (elem, mi->name); 157 int hasEl = 1; 158 if (el == NULL) 159 hasEl = -1; 160 if (tmap == NULL) 161 { 162 if (hasEl > 0) 163 tmap = getMapType (el->defaults->content); 164 } 165 166 map *testMap = NULL; 167 if (hasEl > 0) 168 { 169 testMap = getMap (el->content, "maxOccurs"); 170 } 171 else 172 { 173 testMap = createMap ("maxOccurs", "unbounded"); 174 } 175 176 if (testMap != NULL) 177 { 178 if (strncasecmp (testMap->value, "unbounded", 9) != 0 179 && atoi (testMap->value) > 1) 180 { 181 if (addMapsArrayToMaps (&mo, mi, tmap->name) < 0) 182 { 183 char emsg[1024]; 184 sprintf (emsg, 185 _ 186 ("You set maximum occurences for <%s> as %i but you tried to use it more than the limit you set. Please correct your ZCFG file or your request."), 187 mi->name, atoi (testMap->value)); 188 errorException (m, emsg, "InternalError", NULL); 189 return -1; 190 } 191 } 192 else 193 { 194 if (strncasecmp (testMap->value, "unbounded", 9) == 0) 195 { 196 if (hasEl < 0) 197 { 198 freeMap (&testMap); 199 free (testMap); 200 } 201 if (addMapsArrayToMaps (&mo, mi, tmap->name) < 0) 202 { 203 char emsg[1024]; 204 map *tmpMap = getMap (mi->content, "length"); 205 sprintf (emsg, 206 _ 207 ("ZOO-Kernel was unable to load your data for %s position %s."), 208 mi->name, tmpMap->value); 209 errorException (m, emsg, "InternalError", NULL); 210 return -1; 211 } 212 } 213 else 214 { 215 char emsg[1024]; 216 sprintf (emsg, 217 _ 218 ("You set maximum occurences for <%s> to one but you tried to use it more than once. Please correct your ZCFG file or your request."), 219 mi->name); 220 errorException (m, emsg, "InternalError", NULL); 221 return -1; 222 } 223 } 224 } 190 225 return 0; 191 226 } 192 227 193 int recursReaddirF(maps* m,xmlNodePtr n,char *conf_dir,char *prefix,int saved_stdout,int level,void (func) (maps*,xmlNodePtr,service*)){ 228 int 229 recursReaddirF (maps * m, xmlNodePtr n, char *conf_dir, char *prefix, 230 int saved_stdout, int level, void (func) (maps *, xmlNodePtr, 231 service *)) 232 { 194 233 struct dirent *dp; 195 int scount =0;196 197 if (conf_dir==NULL)234 int scount = 0; 235 236 if (conf_dir == NULL) 198 237 return 1; 199 DIR *dirp = opendir(conf_dir); 200 if(dirp==NULL){ 201 if(level>0) 202 return 1; 238 DIR *dirp = opendir (conf_dir); 239 if (dirp == NULL) 240 { 241 if (level > 0) 242 return 1; 243 else 244 return -1; 245 } 246 char tmp1[25]; 247 sprintf (tmp1, "sprefix_%d", level); 248 char levels[17]; 249 sprintf (levels, "%d", level); 250 setMapInMaps (m, "lenv", "level", levels); 251 while ((dp = readdir (dirp)) != NULL) 252 if ((dp->d_type == DT_DIR || dp->d_type == DT_LNK) && dp->d_name[0] != '.' 253 && strstr (dp->d_name, ".") == NULL) 254 { 255 256 char *tmp = 257 (char *) malloc ((strlen (conf_dir) + strlen (dp->d_name) + 2) * 258 sizeof (char)); 259 sprintf (tmp, "%s/%s", conf_dir, dp->d_name); 260 261 if (prefix != NULL) 262 { 263 prefix = NULL; 264 } 265 prefix = (char *) malloc ((strlen (dp->d_name) + 2) * sizeof (char)); 266 sprintf (prefix, "%s.", dp->d_name); 267 268 //map* tmpMap=getMapFromMaps(m,"lenv",tmp1); 269 270 int res; 271 if (prefix != NULL) 272 { 273 setMapInMaps (m, "lenv", tmp1, prefix); 274 char levels1[17]; 275 sprintf (levels1, "%d", level + 1); 276 setMapInMaps (m, "lenv", "level", levels1); 277 res = 278 recursReaddirF (m, n, tmp, prefix, saved_stdout, level + 1, 279 func); 280 sprintf (levels1, "%d", level); 281 setMapInMaps (m, "lenv", "level", levels1); 282 free (prefix); 283 prefix = NULL; 284 } 285 else 286 res = -1; 287 free (tmp); 288 if (res < 0) 289 { 290 return res; 291 } 292 } 203 293 else 204 return -1; 205 } 206 char tmp1[25]; 207 sprintf(tmp1,"sprefix_%d",level); 208 char levels[17]; 209 sprintf(levels,"%d",level); 210 setMapInMaps(m,"lenv","level",levels); 211 while ((dp = readdir(dirp)) != NULL) 212 if((dp->d_type==DT_DIR || dp->d_type==DT_LNK) && dp->d_name[0]!='.' && strstr(dp->d_name,".")==NULL){ 213 214 char *tmp=(char*)malloc((strlen(conf_dir)+strlen(dp->d_name)+2)*sizeof(char)); 215 sprintf(tmp,"%s/%s",conf_dir,dp->d_name); 216 217 if(prefix!=NULL){ 218 prefix=NULL; 294 { 295 if (dp->d_name[0] != '.' && strstr (dp->d_name, ".zcfg") != 0) 296 { 297 int t; 298 char tmps1[1024]; 299 memset (tmps1, 0, 1024); 300 snprintf (tmps1, 1024, "%s/%s", conf_dir, dp->d_name); 301 service *s1 = (service *) malloc (SERVICE_SIZE); 302 if (s1 == NULL) 303 { 304 dup2 (saved_stdout, fileno (stdout)); 305 errorException (m, _("Unable to allocate memory."), 306 "InternalError", NULL); 307 return -1; 308 } 309 #ifdef DEBUG 310 fprintf (stderr, "#################\n%s\n#################\n", 311 tmps1); 312 #endif 313 t = readServiceFile (m, tmps1, &s1, dp->d_name); 314 315 if (t < 0) 316 { 317 map *tmp00 = getMapFromMaps (m, "lenv", "message"); 318 char tmp01[1024]; 319 if (tmp00 != NULL) 320 sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"), 321 dp->d_name, tmp00->value); 322 else 323 sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), 324 dp->d_name); 325 dup2 (saved_stdout, fileno (stdout)); 326 errorException (m, tmp01, "InternalError", NULL); 327 freeMaps (&m); 328 free (m); 329 return -1; 330 } 331 #ifdef DEBUG 332 dumpService (s1); 333 fflush (stdout); 334 fflush (stderr); 335 #endif 336 func (m, n, s1); 337 freeService (&s1); 338 free (s1); 339 scount++; 340 } 219 341 } 220 prefix=(char*)malloc((strlen(dp->d_name)+2)*sizeof(char)); 221 sprintf(prefix,"%s.",dp->d_name); 222 223 //map* tmpMap=getMapFromMaps(m,"lenv",tmp1); 224 225 int res; 226 if(prefix!=NULL){ 227 setMapInMaps(m,"lenv",tmp1,prefix); 228 char levels1[17]; 229 sprintf(levels1,"%d",level+1); 230 setMapInMaps(m,"lenv","level",levels1); 231 res=recursReaddirF(m,n,tmp,prefix,saved_stdout,level+1,func); 232 sprintf(levels1,"%d",level); 233 setMapInMaps(m,"lenv","level",levels1); 234 free(prefix); 235 prefix=NULL; 236 }else 237 res=-1; 238 free(tmp); 239 if(res<0){ 240 return res; 241 } 242 } 243 else{ 244 if(dp->d_name[0]!='.' && strstr(dp->d_name,".zcfg")!=0){ 245 int t; 246 char tmps1[1024]; 247 memset(tmps1,0,1024); 248 snprintf(tmps1,1024,"%s/%s",conf_dir,dp->d_name); 249 service* s1=(service*)malloc(SERVICE_SIZE); 250 if(s1 == NULL){ 251 dup2(saved_stdout,fileno(stdout)); 252 errorException(m, _("Unable to allocate memory."),"InternalError",NULL); 253 return -1; 254 } 255 #ifdef DEBUG 256 fprintf(stderr,"#################\n%s\n#################\n",tmps1); 257 #endif 258 t=readServiceFile(m,tmps1,&s1,dp->d_name); 259 260 if(t<0){ 261 map* tmp00=getMapFromMaps(m,"lenv","message"); 262 char tmp01[1024]; 263 if(tmp00!=NULL) 264 sprintf(tmp01,_("Unable to parse the ZCFG file: %s (%s)"),dp->d_name,tmp00->value); 265 else 266 sprintf(tmp01,_("Unable to parse the ZCFG file: %s."),dp->d_name); 267 dup2(saved_stdout,fileno(stdout)); 268 errorException(m, tmp01,"InternalError",NULL); 269 freeMaps(&m); 270 free(m); 271 return -1; 272 } 273 #ifdef DEBUG 274 dumpService(s1); 275 fflush(stdout); 276 fflush(stderr); 277 #endif 278 func(m,n,s1); 279 freeService(&s1); 280 free(s1); 281 scount++; 282 } 283 } 284 (void)closedir(dirp); 342 (void) closedir (dirp); 285 343 return 1; 286 344 } 287 345 288 xmlXPathObjectPtr extractFromDoc(xmlDocPtr doc,const char* search){ 346 xmlXPathObjectPtr 347 extractFromDoc (xmlDocPtr doc, const char *search) 348 { 289 349 xmlXPathContextPtr xpathCtx; 290 350 xmlXPathObjectPtr xpathObj; 291 xpathCtx = xmlXPathNewContext (doc);292 xpathObj = xmlXPathEvalExpression (BAD_CAST search,xpathCtx);293 xmlXPathFreeContext (xpathCtx);351 xpathCtx = xmlXPathNewContext (doc); 352 xpathObj = xmlXPathEvalExpression (BAD_CAST search, xpathCtx); 353 xmlXPathFreeContext (xpathCtx); 294 354 return xpathObj; 295 355 } 296 356 297 void donothing(int sig){ 298 #ifdef DEBUG 299 fprintf(stderr,"Signal %d after the ZOO-Kernel returned result !\n",sig); 300 #endif 301 exit(0); 357 void 358 donothing (int sig) 359 { 360 #ifdef DEBUG 361 fprintf (stderr, "Signal %d after the ZOO-Kernel returned result !\n", sig); 362 #endif 363 exit (0); 302 364 } 303 365 304 void sig_handler(int sig){ 366 void 367 sig_handler (int sig) 368 { 305 369 char tmp[100]; 306 370 const char *ssig; 307 switch(sig){ 308 case SIGSEGV: 309 ssig="SIGSEGV"; 310 break; 311 case SIGTERM: 312 ssig="SIGTERM"; 313 break; 314 case SIGINT: 315 ssig="SIGINT"; 316 break; 317 case SIGILL: 318 ssig="SIGILL"; 319 break; 320 case SIGFPE: 321 ssig="SIGFPE"; 322 break; 323 case SIGABRT: 324 ssig="SIGABRT"; 325 break; 326 default: 327 ssig="UNKNOWN"; 328 break; 329 } 330 sprintf(tmp,_("ZOO Kernel failed to process your request receiving signal %d = %s"),sig,ssig); 331 errorException(NULL, tmp, "InternalError",NULL); 332 #ifdef DEBUG 333 fprintf(stderr,"Not this time!\n"); 334 #endif 335 exit(0); 371 switch (sig) 372 { 373 case SIGSEGV: 374 ssig = "SIGSEGV"; 375 break; 376 case SIGTERM: 377 ssig = "SIGTERM"; 378 break; 379 case SIGINT: 380 ssig = "SIGINT"; 381 break; 382 case SIGILL: 383 ssig = "SIGILL"; 384 break; 385 case SIGFPE: 386 ssig = "SIGFPE"; 387 break; 388 case SIGABRT: 389 ssig = "SIGABRT"; 390 break; 391 default: 392 ssig = "UNKNOWN"; 393 break; 394 } 395 sprintf (tmp, 396 _ 397 ("ZOO Kernel failed to process your request receiving signal %d = %s"), 398 sig, ssig); 399 errorException (NULL, tmp, "InternalError", NULL); 400 #ifdef DEBUG 401 fprintf (stderr, "Not this time!\n"); 402 #endif 403 exit (0); 336 404 } 337 405 338 void loadServiceAndRun(maps **myMap,service* s1,map* request_inputs,maps **inputs,maps** ioutputs,int* eres){ 406 void 407 loadServiceAndRun (maps ** myMap, service * s1, map * request_inputs, 408 maps ** inputs, maps ** ioutputs, int *eres) 409 { 339 410 char tmps1[1024]; 340 411 char ntmp[1024]; 341 maps *m =*myMap;342 maps *request_output_real_format =*ioutputs;343 maps *request_input_real_format =*inputs;412 maps *m = *myMap; 413 maps *request_output_real_format = *ioutputs; 414 maps *request_input_real_format = *inputs; 344 415 /** 345 416 * Extract serviceType to know what kind of service should be loaded 346 417 */ 347 map * r_inputs=NULL;418 map *r_inputs = NULL; 348 419 #ifndef WIN32 349 getcwd (ntmp,1024);420 getcwd (ntmp, 1024); 350 421 #else 351 _getcwd(ntmp,1024); 352 #endif 353 r_inputs=getMap(s1->content,"serviceType"); 354 #ifdef DEBUG 355 fprintf(stderr,"LOAD A %s SERVICE PROVIDER \n",r_inputs->value); 356 fflush(stderr); 357 #endif 358 if(strlen(r_inputs->value)==1 && strncasecmp(r_inputs->value,"C",1)==0){ 359 r_inputs=getMap(request_inputs,"metapath"); 360 if(r_inputs!=NULL) 361 sprintf(tmps1,"%s/%s",ntmp,r_inputs->value); 362 else 363 sprintf(tmps1,"%s/",ntmp); 364 char *altPath=zStrdup(tmps1); 365 r_inputs=getMap(s1->content,"ServiceProvider"); 366 sprintf(tmps1,"%s/%s",altPath,r_inputs->value); 367 free(altPath); 368 #ifdef DEBUG 369 fprintf(stderr,"Trying to load %s\n",tmps1); 422 _getcwd (ntmp, 1024); 423 #endif 424 r_inputs = getMap (s1->content, "serviceType"); 425 #ifdef DEBUG 426 fprintf (stderr, "LOAD A %s SERVICE PROVIDER \n", r_inputs->value); 427 fflush (stderr); 428 #endif 429 if (strlen (r_inputs->value) == 1 430 && strncasecmp (r_inputs->value, "C", 1) == 0) 431 { 432 r_inputs = getMap (request_inputs, "metapath"); 433 if (r_inputs != NULL) 434 sprintf (tmps1, "%s/%s", ntmp, r_inputs->value); 435 else 436 sprintf (tmps1, "%s/", ntmp); 437 char *altPath = zStrdup (tmps1); 438 r_inputs = getMap (s1->content, "ServiceProvider"); 439 sprintf (tmps1, "%s/%s", altPath, r_inputs->value); 440 free (altPath); 441 #ifdef DEBUG 442 fprintf (stderr, "Trying to load %s\n", tmps1); 370 443 #endif 371 444 #ifdef WIN32 372 HINSTANCE so = LoadLibraryEx(tmps1,NULL,LOAD_WITH_ALTERED_SEARCH_PATH); 445 HINSTANCE so = 446 LoadLibraryEx (tmps1, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); 373 447 #else 374 void* so = dlopen(tmps1, RTLD_LAZY);448 void *so = dlopen (tmps1, RTLD_LAZY); 375 449 #endif 376 450 #ifdef WIN32 377 DWORD errstr;378 errstr = GetLastError();451 DWORD errstr; 452 errstr = GetLastError (); 379 453 #else 380 char *errstr; 381 errstr = dlerror(); 382 #endif 383 #ifdef DEBUG 384 fprintf(stderr,"%s loaded (%d) \n",tmps1,errstr); 385 #endif 386 if( so != NULL ) { 387 #ifdef DEBUG 388 fprintf(stderr,"Library loaded %s \n",errstr); 389 fprintf(stderr,"Service Shared Object = %s\n",r_inputs->value); 390 #endif 391 r_inputs=getMap(s1->content,"serviceType"); 392 #ifdef DEBUG 393 dumpMap(r_inputs); 394 fprintf(stderr,"%s\n",r_inputs->value); 395 fflush(stderr); 396 #endif 397 if(strncasecmp(r_inputs->value,"C-FORTRAN",9)==0){ 398 r_inputs=getMap(request_inputs,"Identifier"); 399 char fname[1024]; 400 sprintf(fname,"%s_",r_inputs->value); 401 #ifdef DEBUG 402 fprintf(stderr,"Try to load function %s\n",fname); 454 char *errstr; 455 errstr = dlerror (); 456 #endif 457 #ifdef DEBUG 458 fprintf (stderr, "%s loaded (%d) \n", tmps1, errstr); 459 #endif 460 if (so != NULL) 461 { 462 #ifdef DEBUG 463 fprintf (stderr, "Library loaded %s \n", errstr); 464 fprintf (stderr, "Service Shared Object = %s\n", r_inputs->value); 465 #endif 466 r_inputs = getMap (s1->content, "serviceType"); 467 #ifdef DEBUG 468 dumpMap (r_inputs); 469 fprintf (stderr, "%s\n", r_inputs->value); 470 fflush (stderr); 471 #endif 472 if (strncasecmp (r_inputs->value, "C-FORTRAN", 9) == 0) 473 { 474 r_inputs = getMap (request_inputs, "Identifier"); 475 char fname[1024]; 476 sprintf (fname, "%s_", r_inputs->value); 477 #ifdef DEBUG 478 fprintf (stderr, "Try to load function %s\n", fname); 403 479 #endif 404 480 #ifdef WIN32 405 typedef int (CALLBACK* execute_t)(char***,char***,char***); 406 execute_t execute=(execute_t)GetProcAddress(so,fname); 481 typedef int (CALLBACK * execute_t) (char ***, char ***, 482 char ***); 483 execute_t execute = (execute_t) GetProcAddress (so, fname); 407 484 #else 408 typedef int (*execute_t)(char***,char***,char***);409 execute_t execute=(execute_t)dlsym(so,fname);485 typedef int (*execute_t) (char ***, char ***, char ***); 486 execute_t execute = (execute_t) dlsym (so, fname); 410 487 #endif 411 488 #ifdef DEBUG 412 489 #ifdef WIN32 413 errstr = GetLastError();490 errstr = GetLastError (); 414 491 #else 415 errstr = dlerror(); 416 #endif 417 fprintf(stderr,"Function loaded %s\n",errstr); 418 #endif 419 420 char main_conf[10][30][1024]; 421 char inputs[10][30][1024]; 422 char outputs[10][30][1024]; 423 for(int i=0;i<10;i++){ 424 for(int j=0;j<30;j++){ 425 memset(main_conf[i][j],0,1024); 426 memset(inputs[i][j],0,1024); 427 memset(outputs[i][j],0,1024); 428 } 429 } 430 mapsToCharXXX(m,(char***)main_conf); 431 mapsToCharXXX(request_input_real_format,(char***)inputs); 432 mapsToCharXXX(request_output_real_format,(char***)outputs); 433 *eres=execute((char***)&main_conf[0],(char***)&inputs[0],(char***)&outputs[0]); 434 #ifdef DEBUG 435 fprintf(stderr,"Function run successfully \n"); 436 #endif 437 charxxxToMaps((char***)&outputs[0],&request_output_real_format); 438 }else{ 492 errstr = dlerror (); 493 #endif 494 fprintf (stderr, "Function loaded %s\n", errstr); 495 #endif 496 497 char main_conf[10][30][1024]; 498 char inputs[10][30][1024]; 499 char outputs[10][30][1024]; 500 for (int i = 0; i < 10; i++) 501 { 502 for (int j = 0; j < 30; j++) 503 { 504 memset (main_conf[i][j], 0, 1024); 505 memset (inputs[i][j], 0, 1024); 506 memset (outputs[i][j], 0, 1024); 507 } 508 } 509 mapsToCharXXX (m, (char ***) main_conf); 510 mapsToCharXXX (request_input_real_format, (char ***) inputs); 511 mapsToCharXXX (request_output_real_format, (char ***) outputs); 512 *eres = 513 execute ((char ***) &main_conf[0], (char ***) &inputs[0], 514 (char ***) &outputs[0]); 515 #ifdef DEBUG 516 fprintf (stderr, "Function run successfully \n"); 517 #endif 518 charxxxToMaps ((char ***) &outputs[0], 519 &request_output_real_format); 520 } 521 else 522 { 439 523 #ifdef DEBUG 440 524 #ifdef WIN32 441 errstr = GetLastError(); 442 fprintf(stderr,"Function %s failed to load because of %d\n",r_inputs->value,errstr); 443 #endif 444 #endif 445 r_inputs=getMapFromMaps(m,"lenv","Identifier"); 446 #ifdef DEBUG 447 fprintf(stderr,"Try to load function %s\n",r_inputs->value); 448 #endif 449 typedef int (*execute_t)(maps**,maps**,maps**); 525 errstr = GetLastError (); 526 fprintf (stderr, "Function %s failed to load because of %d\n", 527 r_inputs->value, errstr); 528 #endif 529 #endif 530 r_inputs = getMapFromMaps (m, "lenv", "Identifier"); 531 #ifdef DEBUG 532 fprintf (stderr, "Try to load function %s\n", r_inputs->value); 533 #endif 534 typedef int (*execute_t) (maps **, maps **, maps **); 450 535 #ifdef WIN32 451 execute_t execute=(execute_t)GetProcAddress(so,r_inputs->value); 536 execute_t execute = 537 (execute_t) GetProcAddress (so, r_inputs->value); 452 538 #else 453 execute_t execute=(execute_t)dlsym(so,r_inputs->value); 454 #endif 455 456 if(execute==NULL){ 539 execute_t execute = (execute_t) dlsym (so, r_inputs->value); 540 #endif 541 542 if (execute == NULL) 543 { 457 544 #ifdef WIN32 458 errstr = GetLastError();545 errstr = GetLastError (); 459 546 #else 460 errstr = dlerror(); 461 #endif 462 char *tmpMsg=(char*)malloc(2048+strlen(r_inputs->value)); 463 sprintf(tmpMsg,_("Error occured while running the %s function: %s"),r_inputs->value,errstr); 464 errorException(m, tmpMsg, "InternalError",NULL); 465 free(tmpMsg); 466 #ifdef DEBUG 467 fprintf(stderr,"Function %s error %s\n",r_inputs->value,errstr); 468 #endif 469 *eres=-1; 470 return; 471 } 547 errstr = dlerror (); 548 #endif 549 char *tmpMsg = 550 (char *) malloc (2048 + strlen (r_inputs->value)); 551 sprintf (tmpMsg, 552 _ 553 ("Error occured while running the %s function: %s"), 554 r_inputs->value, errstr); 555 errorException (m, tmpMsg, "InternalError", NULL); 556 free (tmpMsg); 557 #ifdef DEBUG 558 fprintf (stderr, "Function %s error %s\n", r_inputs->value, 559 errstr); 560 #endif 561 *eres = -1; 562 return; 563 } 472 564 473 565 #ifdef DEBUG 474 566 #ifdef WIN32 475 errstr = GetLastError();567 errstr = GetLastError (); 476 568 #else 477 errstr = dlerror(); 478 #endif 479 fprintf(stderr,"Function loaded %s\n",errstr); 480 #endif 481 482 #ifdef DEBUG 483 fprintf(stderr,"Now run the function \n"); 484 fflush(stderr); 485 #endif 486 *eres=execute(&m,&request_input_real_format,&request_output_real_format); 487 #ifdef DEBUG 488 fprintf(stderr,"Function loaded and returned %d\n",eres); 489 fflush(stderr); 490 #endif 491 } 569 errstr = dlerror (); 570 #endif 571 fprintf (stderr, "Function loaded %s\n", errstr); 572 #endif 573 574 #ifdef DEBUG 575 fprintf (stderr, "Now run the function \n"); 576 fflush (stderr); 577 #endif 578 *eres = 579 execute (&m, &request_input_real_format, 580 &request_output_real_format); 581 #ifdef DEBUG 582 fprintf (stderr, "Function loaded and returned %d\n", eres); 583 fflush (stderr); 584 #endif 585 } 492 586 #ifdef WIN32 493 *ioutputs=dupMaps(&request_output_real_format);494 FreeLibrary(so);587 *ioutputs = dupMaps (&request_output_real_format); 588 FreeLibrary (so); 495 589 #else 496 dlclose(so); 497 #endif 498 } else { 590 dlclose (so); 591 #endif 592 } 593 else 594 { 499 595 /** 500 596 * Unable to load the specified shared library 501 597 */ 502 char tmps[1024];598 char tmps[1024]; 503 599 #ifdef WIN32 504 DWORD errstr = GetLastError();600 DWORD errstr = GetLastError (); 505 601 #else 506 char* errstr = dlerror();507 #endif 508 sprintf(tmps,_("C Library can't be loaded %s"),errstr);509 map* tmps1=createMap("text",tmps);510 printExceptionReportResponse(m,tmps1);511 *eres=-1;512 freeMap(&tmps1);513 free(tmps1);514 }515 }602 char *errstr = dlerror (); 603 #endif 604 sprintf (tmps, _("C Library can't be loaded %s"), errstr); 605 map *tmps1 = createMap ("text", tmps); 606 printExceptionReportResponse (m, tmps1); 607 *eres = -1; 608 freeMap (&tmps1); 609 free (tmps1); 610 } 611 } 516 612 else 517 613 #ifdef USE_PYTHON 518 if(strncasecmp(r_inputs->value,"PYTHON",6)==0){ 519 *eres=zoo_python_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); 520 } 521 else 522 #endif 523 614 if (strncasecmp (r_inputs->value, "PYTHON", 6) == 0) 615 { 616 *eres = 617 zoo_python_support (&m, request_inputs, s1, 618 &request_input_real_format, 619 &request_output_real_format); 620 } 621 else 622 #endif 623 524 624 #ifdef USE_JAVA 525 if(strncasecmp(r_inputs->value,"JAVA",4)==0){ 526 *eres=zoo_java_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); 527 } 528 else 625 if (strncasecmp (r_inputs->value, "JAVA", 4) == 0) 626 { 627 *eres = 628 zoo_java_support (&m, request_inputs, s1, &request_input_real_format, 629 &request_output_real_format); 630 } 631 else 529 632 #endif 530 633 531 634 #ifdef USE_PHP 532 if(strncasecmp(r_inputs->value,"PHP",3)==0){ 533 *eres=zoo_php_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); 534 } 535 else 536 #endif 537 538 635 if (strncasecmp (r_inputs->value, "PHP", 3) == 0) 636 { 637 *eres = 638 zoo_php_support (&m, request_inputs, s1, &request_input_real_format, 639 &request_output_real_format); 640 } 641 else 642 #endif 643 644 539 645 #ifdef USE_PERL 540 if(strncasecmp(r_inputs->value,"PERL",4)==0){ 541 *eres=zoo_perl_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); 542 } 543 else 646 if (strncasecmp (r_inputs->value, "PERL", 4) == 0) 647 { 648 *eres = 649 zoo_perl_support (&m, request_inputs, s1, &request_input_real_format, 650 &request_output_real_format); 651 } 652 else 544 653 #endif 545 654 546 655 #ifdef USE_JS 547 if(strncasecmp(r_inputs->value,"JS",2)==0){ 548 *eres=zoo_js_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); 549 } 550 else 656 if (strncasecmp (r_inputs->value, "JS", 2) == 0) 657 { 658 *eres = 659 zoo_js_support (&m, request_inputs, s1, &request_input_real_format, 660 &request_output_real_format); 661 } 662 else 551 663 #endif 552 664 553 665 #ifdef USE_RUBY 554 if(strncasecmp(r_inputs->value,"Ruby",4)==0){ 555 *eres=zoo_ruby_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); 556 } 557 else 558 #endif 559 560 { 561 char tmpv[1024]; 562 sprintf(tmpv,_("Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n"),r_inputs->value); 563 map* tmps=createMap("text",tmpv); 564 printExceptionReportResponse(m,tmps); 565 *eres=-1; 566 } 567 *myMap=m; 568 *ioutputs=request_output_real_format; 666 if (strncasecmp (r_inputs->value, "Ruby", 4) == 0) 667 { 668 *eres = 669 zoo_ruby_support (&m, request_inputs, s1, &request_input_real_format, 670 &request_output_real_format); 671 } 672 else 673 #endif 674 675 { 676 char tmpv[1024]; 677 sprintf (tmpv, 678 _ 679 ("Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n"), 680 r_inputs->value); 681 map *tmps = createMap ("text", tmpv); 682 printExceptionReportResponse (m, tmps); 683 *eres = -1; 684 } 685 *myMap = m; 686 *ioutputs = request_output_real_format; 569 687 } 570 688 … … 574 692 * createProcess function: create a new process after setting some env variables 575 693 */ 576 void createProcess(maps* m,map* request_inputs,service* s1,char* opts,int cpid, maps* inputs,maps* outputs){ 694 void 695 createProcess (maps * m, map * request_inputs, service * s1, char *opts, 696 int cpid, maps * inputs, maps * outputs) 697 { 577 698 STARTUPINFO si; 578 699 PROCESS_INFORMATION pi; 579 ZeroMemory( &si, sizeof(si) ); 580 si.cb = sizeof(si); 581 ZeroMemory( &pi, sizeof(pi) ); 582 char *tmp=(char *)malloc((1024+cgiContentLength)*sizeof(char)); 583 char *tmpq=(char *)malloc((1024+cgiContentLength)*sizeof(char)); 584 map *req=getMap(request_inputs,"request"); 585 map *id=getMap(request_inputs,"identifier"); 586 map *di=getMap(request_inputs,"DataInputs"); 587 588 char *dataInputsKVP=getMapsAsKVP(inputs,cgiContentLength,0); 589 char *dataOutputsKVP=getMapsAsKVP(outputs,cgiContentLength,1); 590 #ifdef DEBUG 591 fprintf(stderr,"DATAINPUTSKVP %s\n",dataInputsKVP); 592 fprintf(stderr,"DATAOUTPUTSKVP %s\n",dataOutputsKVP); 593 #endif 594 map *sid=getMapFromMaps(m,"lenv","sid"); 595 map* r_inputs=getMapFromMaps(m,"main","tmpPath"); 596 map* r_inputs1=getMap(request_inputs,"metapath"); 597 int hasIn=-1; 598 if(r_inputs1==NULL){ 599 r_inputs1=createMap("metapath",""); 600 hasIn=1; 601 } 602 map* r_inputs2=getMap(request_inputs,"ResponseDocument"); 603 if(r_inputs2==NULL) 604 r_inputs2=getMap(request_inputs,"RawDataOutput"); 605 map *tmpPath=getMapFromMaps(m,"lenv","cwd"); 606 607 map *tmpReq=getMap(request_inputs,"xrequest"); 608 if(r_inputs2!=NULL){ 609 sprintf(tmp,"\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s&cgiSid=%s\"",r_inputs1->value,req->value,id->value,dataInputsKVP,r_inputs2->name,dataOutputsKVP,sid->value); 610 sprintf(tmpq,"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s",r_inputs1->value,req->value,id->value,dataInputsKVP,r_inputs2->name,dataOutputsKVP); 611 } 612 else{ 613 sprintf(tmp,"\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&cgiSid=%s\"",r_inputs1->value,req->value,id->value,dataInputsKVP,sid->value); 614 sprintf(tmpq,"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s",r_inputs1->value,req->value,id->value,dataInputsKVP,sid->value); 615 } 616 617 if(hasIn>0){ 618 freeMap(&r_inputs1); 619 free(r_inputs1); 620 } 621 char *tmp1=zStrdup(tmp); 622 sprintf(tmp,"\"zoo_loader.cgi\" %s \"%s\"",tmp1,sid->value); 623 624 free(dataInputsKVP); 625 free(dataOutputsKVP); 626 #ifdef DEBUG 627 fprintf(stderr,"REQUEST IS : %s \n",tmp); 628 #endif 629 SetEnvironmentVariable("CGISID",TEXT(sid->value)); 630 SetEnvironmentVariable("QUERY_STRING",TEXT(tmpq)); 700 ZeroMemory (&si, sizeof (si)); 701 si.cb = sizeof (si); 702 ZeroMemory (&pi, sizeof (pi)); 703 char *tmp = (char *) malloc ((1024 + cgiContentLength) * sizeof (char)); 704 char *tmpq = (char *) malloc ((1024 + cgiContentLength) * sizeof (char)); 705 map *req = getMap (request_inputs, "request"); 706 map *id = getMap (request_inputs, "identifier"); 707 map *di = getMap (request_inputs, "DataInputs"); 708 709 char *dataInputsKVP = getMapsAsKVP (inputs, cgiContentLength, 0); 710 char *dataOutputsKVP = getMapsAsKVP (outputs, cgiContentLength, 1); 711 #ifdef DEBUG 712 fprintf (stderr, "DATAINPUTSKVP %s\n", dataInputsKVP); 713 fprintf (stderr, "DATAOUTPUTSKVP %s\n", dataOutputsKVP); 714 #endif 715 map *sid = getMapFromMaps (m, "lenv", "sid"); 716 map *r_inputs = getMapFromMaps (m, "main", "tmpPath"); 717 map *r_inputs1 = getMap (request_inputs, "metapath"); 718 int hasIn = -1; 719 if (r_inputs1 == NULL) 720 { 721 r_inputs1 = createMap ("metapath", ""); 722 hasIn = 1; 723 } 724 map *r_inputs2 = getMap (request_inputs, "ResponseDocument"); 725 if (r_inputs2 == NULL) 726 r_inputs2 = getMap (request_inputs, "RawDataOutput"); 727 map *tmpPath = getMapFromMaps (m, "lenv", "cwd"); 728 729 map *tmpReq = getMap (request_inputs, "xrequest"); 730 if (r_inputs2 != NULL) 731 { 732 sprintf (tmp, 733 "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s&cgiSid=%s\"", 734 r_inputs1->value, req->value, id->value, dataInputsKVP, 735 r_inputs2->name, dataOutputsKVP, sid->value); 736 sprintf (tmpq, 737 "metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s", 738 r_inputs1->value, req->value, id->value, dataInputsKVP, 739 r_inputs2->name, dataOutputsKVP); 740 } 741 else 742 { 743 sprintf (tmp, 744 "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&cgiSid=%s\"", 745 r_inputs1->value, req->value, id->value, dataInputsKVP, 746 sid->value); 747 sprintf (tmpq, 748 "metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s", 749 r_inputs1->value, req->value, id->value, dataInputsKVP, 750 sid->value); 751 } 752 753 if (hasIn > 0) 754 { 755 freeMap (&r_inputs1); 756 free (r_inputs1); 757 } 758 char *tmp1 = zStrdup (tmp); 759 sprintf (tmp, "\"zoo_loader.cgi\" %s \"%s\"", tmp1, sid->value); 760 761 free (dataInputsKVP); 762 free (dataOutputsKVP); 763 #ifdef DEBUG 764 fprintf (stderr, "REQUEST IS : %s \n", tmp); 765 #endif 766 SetEnvironmentVariable ("CGISID", TEXT (sid->value)); 767 SetEnvironmentVariable ("QUERY_STRING", TEXT (tmpq)); 631 768 char clen[1000]; 632 sprintf(clen,"%d",strlen(tmpq)); 633 SetEnvironmentVariable("CONTENT_LENGTH",TEXT(clen)); 634 635 if( !CreateProcess( NULL, // No module name (use command line) 636 TEXT(tmp), // Command line 637 NULL, // Process handle not inheritable 638 NULL, // Thread handle not inheritable 639 FALSE, // Set handle inheritance to FALSE 640 CREATE_NO_WINDOW, // Apache won't wait until the end 641 NULL, // Use parent's environment block 642 NULL, // Use parent's starting directory 643 &si, // Pointer to STARTUPINFO struct 644 &pi ) // Pointer to PROCESS_INFORMATION struct 645 ) 646 { 647 #ifdef DEBUG 648 fprintf( stderr, "CreateProcess failed (%d).\n", GetLastError() ); 649 #endif 650 return ; 651 }else{ 652 #ifdef DEBUG 653 fprintf( stderr, "CreateProcess successfull (%d).\n\n\n\n", GetLastError() ); 654 #endif 655 } 656 CloseHandle( pi.hProcess ); 657 CloseHandle( pi.hThread ); 658 #ifdef DEBUG 659 fprintf(stderr,"CreateProcess finished !\n"); 769 sprintf (clen, "%d", strlen (tmpq)); 770 SetEnvironmentVariable ("CONTENT_LENGTH", TEXT (clen)); 771 772 if (!CreateProcess (NULL, // No module name (use command line) 773 TEXT (tmp), // Command line 774 NULL, // Process handle not inheritable 775 NULL, // Thread handle not inheritable 776 FALSE, // Set handle inheritance to FALSE 777 CREATE_NO_WINDOW, // Apache won't wait until the end 778 NULL, // Use parent's environment block 779 NULL, // Use parent's starting directory 780 &si, // Pointer to STARTUPINFO struct 781 &pi) // Pointer to PROCESS_INFORMATION struct 782 ) 783 { 784 #ifdef DEBUG 785 fprintf (stderr, "CreateProcess failed (%d).\n", GetLastError ()); 786 #endif 787 return; 788 } 789 else 790 { 791 #ifdef DEBUG 792 fprintf (stderr, "CreateProcess successfull (%d).\n\n\n\n", 793 GetLastError ()); 794 #endif 795 } 796 CloseHandle (pi.hProcess); 797 CloseHandle (pi.hThread); 798 #ifdef DEBUG 799 fprintf (stderr, "CreateProcess finished !\n"); 660 800 #endif 661 801 } 662 802 #endif 663 803 664 int runRequest(map** inputs) 804 int 805 runRequest (map ** inputs) 665 806 { 666 807 667 808 #ifndef USE_GDB 668 (void) signal (SIGSEGV,sig_handler);669 (void) signal (SIGTERM,sig_handler);670 (void) signal (SIGINT,sig_handler);671 (void) signal (SIGILL,sig_handler);672 (void) signal (SIGFPE,sig_handler);673 (void) signal (SIGABRT,sig_handler);674 #endif 675 676 map * r_inputs=NULL;677 map * request_inputs=*inputs;678 maps * m=NULL;679 char * REQUEST=NULL;809 (void) signal (SIGSEGV, sig_handler); 810 (void) signal (SIGTERM, sig_handler); 811 (void) signal (SIGINT, sig_handler); 812 (void) signal (SIGILL, sig_handler); 813 (void) signal (SIGFPE, sig_handler); 814 (void) signal (SIGABRT, sig_handler); 815 #endif 816 817 map *r_inputs = NULL; 818 map *request_inputs = *inputs; 819 maps *m = NULL; 820 char *REQUEST = NULL; 680 821 /** 681 822 * Parsing service specfic configuration file 682 823 */ 683 m=(maps*)malloc(MAPS_SIZE); 684 if(m == NULL){ 685 return errorException(m, _("Unable to allocate memory."), "InternalError",NULL); 686 } 824 m = (maps *) malloc (MAPS_SIZE); 825 if (m == NULL) 826 { 827 return errorException (m, _("Unable to allocate memory."), 828 "InternalError", NULL); 829 } 687 830 char ntmp[1024]; 688 831 #ifndef WIN32 689 getcwd (ntmp,1024);832 getcwd (ntmp, 1024); 690 833 #else 691 _getcwd (ntmp,1024);692 #endif 693 r_inputs =getMapOrFill(&request_inputs,"metapath","");834 _getcwd (ntmp, 1024); 835 #endif 836 r_inputs = getMapOrFill (&request_inputs, "metapath", ""); 694 837 695 838 696 839 char conf_file[10240]; 697 snprintf(conf_file,10240,"%s/%s/main.cfg",ntmp,r_inputs->value); 698 if(conf_read(conf_file,m)==2){ 699 errorException(NULL, _("Unable to load the main.cfg file."),"InternalError",NULL); 700 free(m); 701 return 1; 702 } 703 #ifdef DEBUG 704 fprintf(stderr, "***** BEGIN MAPS\n"); 705 dumpMaps(m); 706 fprintf(stderr, "***** END MAPS\n"); 707 #endif 708 709 map *getPath=getMapFromMaps(m,"main","gettextPath"); 710 if(getPath!=NULL){ 711 bindtextdomain ("zoo-kernel",getPath->value); 712 bindtextdomain ("zoo-services",getPath->value); 713 }else{ 714 bindtextdomain ("zoo-kernel","/usr/share/locale/"); 715 bindtextdomain ("zoo-services","/usr/share/locale/"); 716 } 840 snprintf (conf_file, 10240, "%s/%s/main.cfg", ntmp, r_inputs->value); 841 if (conf_read (conf_file, m) == 2) 842 { 843 errorException (NULL, _("Unable to load the main.cfg file."), 844 "InternalError", NULL); 845 free (m); 846 return 1; 847 } 848 #ifdef DEBUG 849 fprintf (stderr, "***** BEGIN MAPS\n"); 850 dumpMaps (m); 851 fprintf (stderr, "***** END MAPS\n"); 852 #endif 853 854 map *getPath = getMapFromMaps (m, "main", "gettextPath"); 855 if (getPath != NULL) 856 { 857 bindtextdomain ("zoo-kernel", getPath->value); 858 bindtextdomain ("zoo-services", getPath->value); 859 } 860 else 861 { 862 bindtextdomain ("zoo-kernel", "/usr/share/locale/"); 863 bindtextdomain ("zoo-services", "/usr/share/locale/"); 864 } 717 865 718 866 … … 722 870 * headers messages returned by the CGI due to wrong redirection of stderr) 723 871 */ 724 FILE * fstde=NULL; 725 map* fstdem=getMapFromMaps(m,"main","logPath"); 726 if(fstdem!=NULL) 727 fstde = freopen(fstdem->value, "a+", stderr) ; 728 729 r_inputs=getMap(request_inputs,"language"); 730 if(r_inputs==NULL) 731 r_inputs=getMapFromMaps(m,"main","language"); 732 if(r_inputs!=NULL){ 733 if(isValidLang(m,r_inputs->value)<0){ 734 char tmp[1024]; 735 sprintf(tmp,_("The value %s is not supported for the <language> parameter"), 736 r_inputs->value); 737 errorException(m, tmp,"InvalidParameterValue","language"); 738 freeMaps(&m); 739 free(m); 740 free(REQUEST); 741 return 1; 742 743 } 744 char *tmp=zStrdup(r_inputs->value); 745 setMapInMaps(m,"main","language",tmp); 872 FILE *fstde = NULL; 873 map *fstdem = getMapFromMaps (m, "main", "logPath"); 874 if (fstdem != NULL) 875 fstde = freopen (fstdem->value, "a+", stderr); 876 877 r_inputs = getMap (request_inputs, "language"); 878 if (r_inputs == NULL) 879 r_inputs = getMapFromMaps (m, "main", "language"); 880 if (r_inputs != NULL) 881 { 882 if (isValidLang (m, r_inputs->value) < 0) 883 { 884 char tmp[1024]; 885 sprintf (tmp, 886 _ 887 ("The value %s is not supported for the <language> parameter"), 888 r_inputs->value); 889 errorException (m, tmp, "InvalidParameterValue", "language"); 890 freeMaps (&m); 891 free (m); 892 free (REQUEST); 893 return 1; 894 895 } 896 char *tmp = zStrdup (r_inputs->value); 897 setMapInMaps (m, "main", "language", tmp); 746 898 #ifdef DEB 747 char tmp2[12];748 sprintf(tmp2,"%s.utf-8",tmp);749 translateChar(tmp2,'-','_');750 setlocale (LC_ALL, tmp2);899 char tmp2[12]; 900 sprintf (tmp2, "%s.utf-8", tmp); 901 translateChar (tmp2, '-', '_'); 902 setlocale (LC_ALL, tmp2); 751 903 #else 752 translateChar(tmp,'-','_');753 setlocale (LC_ALL, tmp);904 translateChar (tmp, '-', '_'); 905 setlocale (LC_ALL, tmp); 754 906 #endif 755 907 #ifndef WIN32 756 setenv("LC_ALL",tmp,1);908 setenv ("LC_ALL", tmp, 1); 757 909 #else 758 char tmp1[12]; 759 sprintf(tmp1,"LC_ALL=%s",tmp); 760 putenv(tmp1); 761 #endif 762 free(tmp); 763 } 764 else{ 765 setlocale (LC_ALL, "en_US"); 910 char tmp1[12]; 911 sprintf (tmp1, "LC_ALL=%s", tmp); 912 putenv (tmp1); 913 #endif 914 free (tmp); 915 } 916 else 917 { 918 setlocale (LC_ALL, "en_US"); 766 919 #ifndef WIN32 767 setenv("LC_ALL","en_US",1);920 setenv ("LC_ALL", "en_US", 1); 768 921 #else 769 char tmp1[12];770 sprintf(tmp1,"LC_ALL=en_US");771 putenv(tmp1);772 #endif 773 setMapInMaps(m,"main","language","en-US");774 }922 char tmp1[12]; 923 sprintf (tmp1, "LC_ALL=en_US"); 924 putenv (tmp1); 925 #endif 926 setMapInMaps (m, "main", "language", "en-US"); 927 } 775 928 setlocale (LC_NUMERIC, "en_US"); 776 bind_textdomain_codeset ("zoo-kernel","UTF-8");777 textdomain ("zoo-kernel");778 bind_textdomain_codeset ("zoo-services","UTF-8");779 textdomain ("zoo-services");780 781 map * lsoap=getMap(request_inputs,"soap");782 if (lsoap!=NULL && strcasecmp(lsoap->value,"true")==0)783 setMapInMaps (m,"main","isSoap","true");929 bind_textdomain_codeset ("zoo-kernel", "UTF-8"); 930 textdomain ("zoo-kernel"); 931 bind_textdomain_codeset ("zoo-services", "UTF-8"); 932 textdomain ("zoo-services"); 933 934 map *lsoap = getMap (request_inputs, "soap"); 935 if (lsoap != NULL && strcasecmp (lsoap->value, "true") == 0) 936 setMapInMaps (m, "main", "isSoap", "true"); 784 937 else 785 setMapInMaps(m,"main","isSoap","false"); 786 787 if(strlen(cgiServerName)>0){ 788 char tmpUrl[1024]; 789 if(strncmp(cgiServerPort,"80",2)==0){ 790 sprintf(tmpUrl,"http://%s%s",cgiServerName,cgiScriptName); 791 }else{ 792 sprintf(tmpUrl,"http://%s:%s%s",cgiServerName,cgiServerPort,cgiScriptName); 793 } 794 #ifdef DEBUG 795 fprintf(stderr,"*** %s ***\n",tmpUrl); 796 #endif 797 setMapInMaps(m,"main","serverAddress",tmpUrl); 798 } 938 setMapInMaps (m, "main", "isSoap", "false"); 939 940 if (strlen (cgiServerName) > 0) 941 { 942 char tmpUrl[1024]; 943 if (strncmp (cgiServerPort, "80", 2) == 0) 944 { 945 sprintf (tmpUrl, "http://%s%s", cgiServerName, cgiScriptName); 946 } 947 else 948 { 949 sprintf (tmpUrl, "http://%s:%s%s", cgiServerName, cgiServerPort, 950 cgiScriptName); 951 } 952 #ifdef DEBUG 953 fprintf (stderr, "*** %s ***\n", tmpUrl); 954 #endif 955 setMapInMaps (m, "main", "serverAddress", tmpUrl); 956 } 799 957 800 958 /** 801 959 * Check for minimum inputs 802 960 */ 803 r_inputs=getMap(request_inputs,"Request"); 804 if(request_inputs==NULL || r_inputs==NULL){ 805 errorException(m, _("Parameter <request> was not specified"),"MissingParameterValue","request"); 806 if(count(request_inputs)==1){ 807 freeMap(&request_inputs); 808 free(request_inputs); 809 } 810 freeMaps(&m); 811 free(m); 812 return 1; 813 } 814 else{ 815 REQUEST=zStrdup(r_inputs->value); 816 if(strncasecmp(r_inputs->value,"GetCapabilities",15)!=0 817 && strncasecmp(r_inputs->value,"DescribeProcess",15)!=0 818 && strncasecmp(r_inputs->value,"Execute",7)!=0){ 819 errorException(m, _("Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."), "OperationNotSupported",r_inputs->value); 820 freeMaps(&m); 821 free(m); 822 free(REQUEST); 961 r_inputs = getMap (request_inputs, "Request"); 962 if (request_inputs == NULL || r_inputs == NULL) 963 { 964 errorException (m, _("Parameter <request> was not specified"), 965 "MissingParameterValue", "request"); 966 if (count (request_inputs) == 1) 967 { 968 freeMap (&request_inputs); 969 free (request_inputs); 970 } 971 freeMaps (&m); 972 free (m); 823 973 return 1; 824 974 } 825 } 826 r_inputs=NULL; 827 r_inputs=getMap(request_inputs,"Service"); 828 if(r_inputs==NULLMAP){ 829 errorException(m, _("Parameter <service> was not specified"),"MissingParameterValue","service"); 830 freeMaps(&m); 831 free(m); 832 free(REQUEST); 833 return 1; 834 }else{ 835 if(strcasecmp(r_inputs->value,"WPS")!=0){ 836 errorException(m, _("Unenderstood <service> value, WPS is the only acceptable value."), "InvalidParameterValue","service"); 837 freeMaps(&m); 838 free(m); 839 free(REQUEST); 975 else 976 { 977 REQUEST = zStrdup (r_inputs->value); 978 if (strncasecmp (r_inputs->value, "GetCapabilities", 15) != 0 979 && strncasecmp (r_inputs->value, "DescribeProcess", 15) != 0 980 && strncasecmp (r_inputs->value, "Execute", 7) != 0) 981 { 982 errorException (m, 983 _ 984 ("Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."), 985 "OperationNotSupported", r_inputs->value); 986 freeMaps (&m); 987 free (m); 988 free (REQUEST); 989 return 1; 990 } 991 } 992 r_inputs = NULL; 993 r_inputs = getMap (request_inputs, "Service"); 994 if (r_inputs == NULLMAP) 995 { 996 errorException (m, _("Parameter <service> was not specified"), 997 "MissingParameterValue", "service"); 998 freeMaps (&m); 999 free (m); 1000 free (REQUEST); 840 1001 return 1; 841 1002 } 842 }843 if(strncasecmp(REQUEST,"GetCapabilities",15)!=0){844 r_inputs=getMap(request_inputs,"Version");845 if(r_inputs==NULL){846 errorException(m, _("Parameter <version> was not specified"),"MissingParameterValue","version");847 freeMaps(&m);848 free(m);849 free(REQUEST);850 return 1;851 }else{852 if(strcasecmp(r_inputs->value,"1.0.0")!=0){853 errorException(m, _("Unenderstood <version> value, 1.0.0 is the only acceptable value."), "InvalidParameterValue","service");854 freeMaps(&m);855 free(m);856 free(REQUEST);857 return 1;858 }859 }860 }else{861 r_inputs=getMap(request_inputs,"AcceptVersions");862 if(r_inputs!=NULL){863 if(strncmp(r_inputs->value,"1.0.0",5)!=0){864 errorException(m, _("Unenderstood <AcceptVersions> value, 1.0.0 is the only acceptable value."), "VersionNegotiationFailed",NULL);865 freeMaps(&m);866 free(m);867 free(REQUEST);868 return 1;869 }870 }871 }872 873 r_inputs=getMap(request_inputs,"serviceprovider");874 if(r_inputs==NULL){875 addToMap(request_inputs,"serviceprovider","");876 }877 878 maps* request_output_real_format=NULL;879 map* tmpm=getMapFromMaps(m,"main","serverAddress");880 if(tmpm!=NULL)881 SERVICE_URL=zStrdup(tmpm->value);882 1003 else 883 SERVICE_URL=zStrdup(DEFAULT_SERVICE_URL); 884 885 service* s1; 886 int scount=0; 887 #ifdef DEBUG 888 dumpMap(r_inputs); 1004 { 1005 if (strcasecmp (r_inputs->value, "WPS") != 0) 1006 { 1007 errorException (m, 1008 _ 1009 ("Unenderstood <service> value, WPS is the only acceptable value."), 1010 "InvalidParameterValue", "service"); 1011 freeMaps (&m); 1012 free (m); 1013 free (REQUEST); 1014 return 1; 1015 } 1016 } 1017 if (strncasecmp (REQUEST, "GetCapabilities", 15) != 0) 1018 { 1019 r_inputs = getMap (request_inputs, "Version"); 1020 if (r_inputs == NULL) 1021 { 1022 errorException (m, _("Parameter <version> was not specified"), 1023 "MissingParameterValue", "version"); 1024 freeMaps (&m); 1025 free (m); 1026 free (REQUEST); 1027 return 1; 1028 } 1029 else 1030 { 1031 if (strcasecmp (r_inputs->value, "1.0.0") != 0) 1032 { 1033 errorException (m, 1034 _ 1035 ("Unenderstood <version> value, 1.0.0 is the only acceptable value."), 1036 "InvalidParameterValue", "service"); 1037 freeMaps (&m); 1038 free (m); 1039 free (REQUEST); 1040 return 1; 1041 } 1042 } 1043 } 1044 else 1045 { 1046 r_inputs = getMap (request_inputs, "AcceptVersions"); 1047 if (r_inputs != NULL) 1048 { 1049 if (strncmp (r_inputs->value, "1.0.0", 5) != 0) 1050 { 1051 errorException (m, 1052 _ 1053 ("Unenderstood <AcceptVersions> value, 1.0.0 is the only acceptable value."), 1054 "VersionNegotiationFailed", NULL); 1055 freeMaps (&m); 1056 free (m); 1057 free (REQUEST); 1058 return 1; 1059 } 1060 } 1061 } 1062 1063 r_inputs = getMap (request_inputs, "serviceprovider"); 1064 if (r_inputs == NULL) 1065 { 1066 addToMap (request_inputs, "serviceprovider", ""); 1067 } 1068 1069 maps *request_output_real_format = NULL; 1070 map *tmpm = getMapFromMaps (m, "main", "serverAddress"); 1071 if (tmpm != NULL) 1072 SERVICE_URL = zStrdup (tmpm->value); 1073 else 1074 SERVICE_URL = zStrdup (DEFAULT_SERVICE_URL); 1075 1076 service *s1; 1077 int scount = 0; 1078 #ifdef DEBUG 1079 dumpMap (r_inputs); 889 1080 #endif 890 1081 char conf_dir[1024]; … … 892 1083 char tmps1[1024]; 893 1084 894 r_inputs =NULL;895 r_inputs =getMap(request_inputs,"metapath");896 if (r_inputs!=NULL)897 snprintf (conf_dir,1024,"%s/%s",ntmp,r_inputs->value);1085 r_inputs = NULL; 1086 r_inputs = getMap (request_inputs, "metapath"); 1087 if (r_inputs != NULL) 1088 snprintf (conf_dir, 1024, "%s/%s", ntmp, r_inputs->value); 898 1089 else 899 snprintf(conf_dir,1024,"%s",ntmp); 900 901 if(strncasecmp(REQUEST,"GetCapabilities",15)==0){ 902 #ifdef DEBUG 903 dumpMap(r_inputs); 904 #endif 905 xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); 906 r_inputs=NULL; 907 r_inputs=getMap(request_inputs,"ServiceProvider"); 908 xmlNodePtr n; 909 if(r_inputs!=NULL) 910 n = printGetCapabilitiesHeader(doc,r_inputs->value,m); 911 else 912 n = printGetCapabilitiesHeader(doc,"",m); 1090 snprintf (conf_dir, 1024, "%s", ntmp); 1091 1092 if (strncasecmp (REQUEST, "GetCapabilities", 15) == 0) 1093 { 1094 #ifdef DEBUG 1095 dumpMap (r_inputs); 1096 #endif 1097 xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0"); 1098 r_inputs = NULL; 1099 r_inputs = getMap (request_inputs, "ServiceProvider"); 1100 xmlNodePtr n; 1101 if (r_inputs != NULL) 1102 n = printGetCapabilitiesHeader (doc, r_inputs->value, m); 1103 else 1104 n = printGetCapabilitiesHeader (doc, "", m); 913 1105 /** 914 1106 * Here we need to close stdout to ensure that not supported chars 915 1107 * has been found in the zcfg and then printed on stdout 916 1108 */ 917 int saved_stdout = dup(fileno(stdout)); 918 dup2(fileno(stderr),fileno(stdout)); 919 if(int res=recursReaddirF(m,n,conf_dir,NULL,saved_stdout,0,printGetCapabilitiesForProcess)<0){ 920 freeMaps(&m); 921 free(m); 922 free(REQUEST); 923 free(SERVICE_URL); 924 fflush(stdout); 925 return res; 926 } 927 dup2(saved_stdout,fileno(stdout)); 928 printDocument(m,doc,getpid()); 929 freeMaps(&m); 930 free(m); 931 free(REQUEST); 932 free(SERVICE_URL); 933 fflush(stdout); 934 return 0; 935 } 936 else{ 937 r_inputs=getMap(request_inputs,"Identifier"); 938 if(r_inputs==NULL 939 || strlen(r_inputs->name)==0 || strlen(r_inputs->value)==0){ 940 errorException(m, _("Mandatory <identifier> was not specified"),"MissingParameterValue","identifier"); 941 freeMaps(&m); 942 free(m); 943 free(REQUEST); 944 free(SERVICE_URL); 1109 int saved_stdout = dup (fileno (stdout)); 1110 dup2 (fileno (stderr), fileno (stdout)); 1111 1112 /** 1113 if (int res = 1114 recursReaddirF (m, n, conf_dir, NULL, saved_stdout, 0, 1115 printGetCapabilitiesForProcess) < 0) 1116 { 1117 freeMaps (&m); 1118 free (m); 1119 free (REQUEST); 1120 free (SERVICE_URL); 1121 fflush (stdout); 1122 return res; 1123 } 1124 **/ 1125 XML_CapabilitiesAllProcess (m, n); 1126 dup2 (saved_stdout, fileno (stdout)); 1127 printDocument (m, doc, getpid ()); 1128 freeMaps (&m); 1129 free (m); 1130 free (REQUEST); 1131 free (SERVICE_URL); 1132 fflush (stdout); 945 1133 return 0; 946 1134 } 947 948 struct dirent *dp; 949 DIR *dirp = opendir(conf_dir); 950 if(dirp==NULL){ 951 errorException(m, _("The specified path path doesn't exist."),"InvalidParameterValue",conf_dir); 952 freeMaps(&m); 953 free(m); 954 free(REQUEST); 955 free(SERVICE_URL); 956 return 0; 957 } 958 if(strncasecmp(REQUEST,"DescribeProcess",15)==0){ 1135 else 1136 { 1137 r_inputs = getMap (request_inputs, "Identifier"); 1138 if (r_inputs == NULL 1139 || strlen (r_inputs->name) == 0 || strlen (r_inputs->value) == 0) 1140 { 1141 errorException (m, _("Mandatory <identifier> was not specified"), 1142 "MissingParameterValue", "identifier"); 1143 freeMaps (&m); 1144 free (m); 1145 free (REQUEST); 1146 free (SERVICE_URL); 1147 return 0; 1148 } 1149 1150 struct dirent *dp; 1151 DIR *dirp = opendir (conf_dir); 1152 if (dirp == NULL) 1153 { 1154 errorException (m, _("The specified path path doesn't exist."), 1155 "InvalidParameterValue", conf_dir); 1156 freeMaps (&m); 1157 free (m); 1158 free (REQUEST); 1159 free (SERVICE_URL); 1160 return 0; 1161 } 1162 if (strncasecmp (REQUEST, "DescribeProcess", 15) == 0) 1163 { 959 1164 /** 960 1165 * Loop over Identifier list 961 1166 */ 962 xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); 963 r_inputs=NULL; 964 r_inputs=getMap(request_inputs,"ServiceProvider"); 965 966 xmlNodePtr n; 967 if(r_inputs!=NULL) 968 n = printDescribeProcessHeader(doc,r_inputs->value,m); 969 else 970 n = printDescribeProcessHeader(doc,"",m); 971 972 r_inputs=getMap(request_inputs,"Identifier"); 973 974 char *orig=zStrdup(r_inputs->value); 975 976 int saved_stdout = dup(fileno(stdout)); 977 dup2(fileno(stderr),fileno(stdout)); 978 if(strcasecmp("all",orig)==0){ 979 if(int res=recursReaddirF(m,n,conf_dir,NULL,saved_stdout,0,printDescribeProcessForProcess)<0) 980 return res; 981 } 982 else{ 983 char *saveptr; 984 char *tmps=strtok_r(orig,",",&saveptr); 985 986 char buff[256]; 987 char buff1[1024]; 988 while(tmps!=NULL){ 989 int hasVal=-1; 990 char *corig=zStrdup(tmps); 991 if(strstr(corig,".")!=NULL){ 992 993 parseIdentifier(m,conf_dir,corig,buff1); 994 map* tmpMap=getMapFromMaps(m,"lenv","metapath"); 995 if(tmpMap!=NULL) 996 addToMap(request_inputs,"metapath",tmpMap->value); 997 998 s1=(service*)malloc(SERVICE_SIZE); 999 t=readServiceFile(m,buff1,&s1,corig); 1000 if(t<0){ 1001 map* tmp00=getMapFromMaps(m,"lenv","message"); 1002 char tmp01[1024]; 1003 if(tmp00!=NULL) 1004 sprintf(tmp01,_("Unable to parse the ZCFG file for the following ZOO-Service: %s. Message: %s"),tmps,tmp00->value); 1005 else 1006 sprintf(tmp01,_("Unable to parse the ZCFG file for the following ZOO-Service: %s."),tmps); 1007 dup2(saved_stdout,fileno(stdout)); 1008 errorException(m, tmp01,"InvalidParameterValue","identifier"); 1009 freeMaps(&m); 1010 free(m); 1011 free(REQUEST); 1012 free(corig); 1013 free(orig); 1014 free(SERVICE_URL); 1015 free(s1); 1016 closedir(dirp); 1017 xmlFreeDoc(doc); 1018 xmlCleanupParser(); 1019 zooXmlCleanupNs(); 1020 return 1; 1021 } 1022 #ifdef DEBUG 1023 dumpService(s1); 1024 #endif 1025 printDescribeProcessForProcess(m,n,s1); 1026 freeService(&s1); 1027 free(s1); 1028 s1=NULL; 1029 scount++; 1030 hasVal=1; 1031 setMapInMaps(m,"lenv","level","0"); 1032 }else{ 1033 memset(buff,0,256); 1034 snprintf(buff,256,"%s.zcfg",corig); 1035 memset(buff1,0,1024); 1036 #ifdef DEBUG 1037 printf("\n#######%s\n########\n",buff); 1038 #endif 1039 while ((dp = readdir(dirp)) != NULL){ 1040 if( strcasecmp(dp->d_name,buff)==0 ){ 1041 memset(buff1,0,1024); 1042 snprintf(buff1,1024,"%s/%s",conf_dir,dp->d_name); 1043 s1=(service*)malloc(SERVICE_SIZE); 1044 if(s1 == NULL){ 1045 dup2(saved_stdout,fileno(stdout)); 1046 return errorException(m, _("Unable to allocate memory."),"InternalError",NULL); 1047 } 1048 #ifdef DEBUG 1049 printf("#################\n(%s) %s\n#################\n",r_inputs->value,buff1); 1050 #endif 1051 char *tmp0=zStrdup(dp->d_name); 1052 tmp0[strlen(tmp0)-5]=0; 1053 t=readServiceFile(m,buff1,&s1,tmp0); 1054 free(tmp0); 1055 if(t<0){ 1056 map* tmp00=getMapFromMaps(m,"lenv","message"); 1057 char tmp01[1024]; 1058 if(tmp00!=NULL) 1059 sprintf(tmp01,_("Unable to parse the ZCFG file: %s (%s)"),dp->d_name,tmp00->value); 1060 else 1061 sprintf(tmp01,_("Unable to parse the ZCFG file: %s."),dp->d_name); 1062 dup2(saved_stdout,fileno(stdout)); 1063 errorException(m, tmp01,"InternalError",NULL); 1064 freeMaps(&m); 1065 free(m); 1066 free(orig); 1067 free(REQUEST); 1068 closedir(dirp); 1069 xmlFreeDoc(doc); 1070 xmlCleanupParser(); 1071 zooXmlCleanupNs(); 1072 return 1; 1073 } 1074 #ifdef DEBUG 1075 dumpService(s1); 1076 #endif 1077 printDescribeProcessForProcess(m,n,s1); 1078 freeService(&s1); 1079 free(s1); 1080 s1=NULL; 1081 scount++; 1082 hasVal=1; 1083 } 1084 } 1085 } 1086 if(hasVal<0){ 1087 map* tmp00=getMapFromMaps(m,"lenv","message"); 1088 char tmp01[1024]; 1089 if(tmp00!=NULL) 1090 sprintf(tmp01,_("Unable to parse the ZCFG file: %s (%s)"),buff,tmp00->value); 1091 else 1092 sprintf(tmp01,_("Unable to parse the ZCFG file: %s."),buff); 1093 dup2(saved_stdout,fileno(stdout)); 1094 errorException(m, tmp01,"InvalidParameterValue","Identifier"); 1095 freeMaps(&m); 1096 free(m); 1097 free(orig); 1098 free(REQUEST); 1099 closedir(dirp); 1100 xmlFreeDoc(doc); 1101 xmlCleanupParser(); 1102 zooXmlCleanupNs(); 1103 return 1; 1104 } 1105 rewinddir(dirp); 1106 tmps=strtok_r(NULL,",",&saveptr); 1107 if(corig!=NULL) 1108 free(corig); 1109 } 1110 } 1111 closedir(dirp); 1112 fflush(stdout); 1113 dup2(saved_stdout,fileno(stdout)); 1114 free(orig); 1115 printDocument(m,doc,getpid()); 1116 freeMaps(&m); 1117 free(m); 1118 free(REQUEST); 1119 free(SERVICE_URL); 1120 fflush(stdout); 1167 xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0"); 1168 r_inputs = NULL; 1169 r_inputs = getMap (request_inputs, "ServiceProvider"); 1170 1171 xmlNodePtr n; 1172 if (r_inputs != NULL) 1173 n = printDescribeProcessHeader (doc, r_inputs->value, m); 1174 else 1175 n = printDescribeProcessHeader (doc, "", m); 1176 1177 r_inputs = getMap (request_inputs, "Identifier"); 1178 1179 char *orig = zStrdup (r_inputs->value); 1180 1181 1182 int saved_stdout = dup (fileno (stdout)); 1183 dup2 (fileno (stderr), fileno (stdout)); 1184 XML_Describe_Process (m, n, orig); 1185 closedir (dirp); 1186 fflush (stdout); 1187 dup2 (saved_stdout, fileno (stdout)); 1188 free (orig); 1189 printDocument (m, doc, getpid ()); 1190 freeMaps (&m); 1191 free (m); 1192 free (REQUEST); 1193 free (SERVICE_URL); 1194 fflush (stdout); 1195 return 0; 1196 1197 } 1198 else if (strncasecmp (REQUEST, "Execute", strlen (REQUEST)) != 0) 1199 { 1200 errorException (m, 1201 _ 1202 ("Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."), 1203 "InvalidParameterValue", "request"); 1204 #ifdef DEBUG 1205 fprintf (stderr, "No request found %s", REQUEST); 1206 #endif 1207 closedir (dirp); 1208 freeMaps (&m); 1209 free (m); 1210 free (REQUEST); 1211 free (SERVICE_URL); 1212 fflush (stdout); 1213 return 0; 1214 } 1215 closedir (dirp); 1216 } 1217 1218 s1 = NULL; 1219 s1 = (service *) malloc (SERVICE_SIZE); 1220 if (s1 == NULL) 1221 { 1222 freeMaps (&m); 1223 free (m); 1224 free (REQUEST); 1225 free (SERVICE_URL); 1226 return errorException (m, _("Unable to allocate memory."), 1227 "InternalError", NULL); 1228 } 1229 r_inputs = getMap (request_inputs, "MetaPath"); 1230 if (r_inputs != NULL) 1231 snprintf (tmps1, 1024, "%s/%s", ntmp, r_inputs->value); 1232 else 1233 snprintf (tmps1, 1024, "%s/", ntmp); 1234 r_inputs = getMap (request_inputs, "Identifier"); 1235 char *ttmp = zStrdup (tmps1); 1236 snprintf (tmps1, 1024, "%s/%s.zcfg", ttmp, r_inputs->value); 1237 free (ttmp); 1238 #ifdef DEBUG 1239 fprintf (stderr, "Trying to load %s\n", tmps1); 1240 #endif 1241 if (strstr (r_inputs->value, ".") != NULL) 1242 { 1243 char *identifier = zStrdup (r_inputs->value); 1244 parseIdentifier (m, conf_dir, identifier, tmps1); 1245 map *tmpMap = getMapFromMaps (m, "lenv", "metapath"); 1246 if (tmpMap != NULL) 1247 addToMap (request_inputs, "metapath", tmpMap->value); 1248 free (identifier); 1249 } 1250 else 1251 setMapInMaps (m, "lenv", "Identifier", r_inputs->value); 1252 int saved_stdout = dup (fileno (stdout)); 1253 dup2 (fileno (stderr), fileno (stdout)); 1254 t = readServiceFile (m, tmps1, &s1, r_inputs->value); 1255 fflush (stdout); 1256 dup2 (saved_stdout, fileno (stdout)); 1257 if (t < 0) 1258 { 1259 char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value)); 1260 sprintf (tmpMsg, 1261 _ 1262 ("The value for <indetifier> seems to be wrong (%s). Please, ensure that the process exist using the GetCapabilities request."), 1263 r_inputs->value); 1264 errorException (m, tmpMsg, "InvalidParameterValue", "identifier"); 1265 free (tmpMsg); 1266 free (s1); 1267 freeMaps (&m); 1268 free (m); 1269 free (REQUEST); 1270 free (SERVICE_URL); 1121 1271 return 0; 1122 1272 } 1123 else 1124 if(strncasecmp(REQUEST,"Execute",strlen(REQUEST))!=0){ 1125 errorException(m, _("Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."), "InvalidParameterValue","request"); 1126 #ifdef DEBUG 1127 fprintf(stderr,"No request found %s",REQUEST); 1128 #endif 1129 closedir(dirp); 1130 freeMaps(&m); 1131 free(m); 1132 free(REQUEST); 1133 free(SERVICE_URL); 1134 fflush(stdout); 1135 return 0; 1136 } 1137 closedir(dirp); 1138 } 1139 1140 s1=NULL; 1141 s1=(service*)malloc(SERVICE_SIZE); 1142 if(s1 == NULL){ 1143 freeMaps(&m); 1144 free(m); 1145 free(REQUEST); 1146 free(SERVICE_URL); 1147 return errorException(m, _("Unable to allocate memory."),"InternalError",NULL); 1148 } 1149 r_inputs=getMap(request_inputs,"MetaPath"); 1150 if(r_inputs!=NULL) 1151 snprintf(tmps1,1024,"%s/%s",ntmp,r_inputs->value); 1152 else 1153 snprintf(tmps1,1024,"%s/",ntmp); 1154 r_inputs=getMap(request_inputs,"Identifier"); 1155 char *ttmp=zStrdup(tmps1); 1156 snprintf(tmps1,1024,"%s/%s.zcfg",ttmp,r_inputs->value); 1157 free(ttmp); 1158 #ifdef DEBUG 1159 fprintf(stderr,"Trying to load %s\n", tmps1); 1160 #endif 1161 if(strstr(r_inputs->value,".")!=NULL){ 1162 char *identifier=zStrdup(r_inputs->value); 1163 parseIdentifier(m,conf_dir,identifier,tmps1); 1164 map* tmpMap=getMapFromMaps(m,"lenv","metapath"); 1165 if(tmpMap!=NULL) 1166 addToMap(request_inputs,"metapath",tmpMap->value); 1167 free(identifier); 1168 }else 1169 setMapInMaps(m,"lenv","Identifier",r_inputs->value); 1170 int saved_stdout = dup(fileno(stdout)); 1171 dup2(fileno(stderr),fileno(stdout)); 1172 t=readServiceFile(m,tmps1,&s1,r_inputs->value); 1173 fflush(stdout); 1174 dup2(saved_stdout,fileno(stdout)); 1175 if(t<0){ 1176 char *tmpMsg=(char*)malloc(2048+strlen(r_inputs->value)); 1177 sprintf(tmpMsg,_("The value for <indetifier> seems to be wrong (%s). Please, ensure that the process exist using the GetCapabilities request."),r_inputs->value); 1178 errorException(m, tmpMsg, "InvalidParameterValue","identifier"); 1179 free(tmpMsg); 1180 free(s1); 1181 freeMaps(&m); 1182 free(m); 1183 free(REQUEST); 1184 free(SERVICE_URL); 1185 return 0; 1186 } 1187 close(saved_stdout); 1188 1189 #ifdef DEBUG 1190 dumpService(s1); 1273 close (saved_stdout); 1274 1275 #ifdef DEBUG 1276 dumpService (s1); 1191 1277 #endif 1192 1278 int j; 1193 1279 1194 1280 1195 1281 /** 1196 1282 * Create the input and output maps data structure 1197 1283 */ 1198 int i =0;1284 int i = 0; 1199 1285 HINTERNET hInternet; 1200 1286 HINTERNET res; 1201 hInternet =InternetOpen(1287 hInternet = InternetOpen ( 1202 1288 #ifndef WIN32 1203 (LPCTSTR) 1204 #endif 1205 "ZooWPSClient\0", 1206 INTERNET_OPEN_TYPE_PRECONFIG, 1207 NULL,NULL, 0); 1289 (LPCTSTR) 1290 #endif 1291 "ZooWPSClient\0", 1292 INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); 1208 1293 1209 1294 #ifndef WIN32 1210 if(!CHECK_INET_HANDLE(hInternet)) 1211 fprintf(stderr,"WARNING : hInternet handle failed to initialize"); 1212 #endif 1213 maps* request_input_real_format=NULL; 1214 maps* tmpmaps = request_input_real_format; 1215 map* postRequest=NULL; 1216 postRequest=getMap(request_inputs,"xrequest"); 1217 if(postRequest==NULLMAP){ 1295 if (!CHECK_INET_HANDLE (hInternet)) 1296 fprintf (stderr, "WARNING : hInternet handle failed to initialize"); 1297 #endif 1298 maps *request_input_real_format = NULL; 1299 maps *tmpmaps = request_input_real_format; 1300 map *postRequest = NULL; 1301 postRequest = getMap (request_inputs, "xrequest"); 1302 if (postRequest == NULLMAP) 1303 { 1218 1304 /** 1219 1305 * Parsing outputs provided as KVP 1220 1306 */ 1221 r_inputs=NULL; 1222 #ifdef DEBUG 1223 fprintf(stderr,"OUTPUT Parsing ... \n"); 1224 #endif 1225 r_inputs=getMap(request_inputs,"ResponseDocument"); 1226 if(r_inputs==NULL) r_inputs=getMap(request_inputs,"RawDataOutput"); 1227 1228 #ifdef DEBUG 1229 fprintf(stderr,"OUTPUT Parsing ... \n"); 1230 #endif 1231 if(r_inputs!=NULL){ 1232 #ifdef DEBUG 1233 fprintf(stderr,"OUTPUT Parsing start now ... \n"); 1234 #endif 1235 char cursor_output[10240]; 1236 char *cotmp=zStrdup(r_inputs->value); 1237 snprintf(cursor_output,10240,"%s",cotmp); 1238 free(cotmp); 1239 j=0; 1240 1307 r_inputs = NULL; 1308 #ifdef DEBUG 1309 fprintf (stderr, "OUTPUT Parsing ... \n"); 1310 #endif 1311 r_inputs = getMap (request_inputs, "ResponseDocument"); 1312 if (r_inputs == NULL) 1313 r_inputs = getMap (request_inputs, "RawDataOutput"); 1314 1315 #ifdef DEBUG 1316 fprintf (stderr, "OUTPUT Parsing ... \n"); 1317 #endif 1318 if (r_inputs != NULL) 1319 { 1320 #ifdef DEBUG 1321 fprintf (stderr, "OUTPUT Parsing start now ... \n"); 1322 #endif 1323 char cursor_output[10240]; 1324 char *cotmp = zStrdup (r_inputs->value); 1325 snprintf (cursor_output, 10240, "%s", cotmp); 1326 free (cotmp); 1327 j = 0; 1328 1241 1329 /** 1242 1330 * Put each Output into the outputs_as_text array 1243 1331 */ 1244 char * pToken; 1245 maps* tmp_output=NULL; 1246 #ifdef DEBUG 1247 fprintf(stderr,"OUTPUT [%s]\n",cursor_output); 1248 #endif 1249 pToken=strtok(cursor_output,";"); 1250 char** outputs_as_text=(char**)malloc(128*sizeof(char*)); 1251 if(outputs_as_text == NULL) { 1252 return errorException(m, _("Unable to allocate memory"), "InternalError",NULL); 1253 } 1254 i=0; 1255 while(pToken!=NULL){ 1256 #ifdef DEBUG 1257 fprintf(stderr,"***%s***\n",pToken); 1258 fflush(stderr); 1259 fprintf(stderr,"***%s***\n",pToken); 1260 #endif 1261 outputs_as_text[i]=(char*)malloc((strlen(pToken)+1)*sizeof(char)); 1262 if(outputs_as_text[i] == NULL) { 1263 return errorException(m, _("Unable to allocate memory"), "InternalError",NULL); 1264 } 1265 snprintf(outputs_as_text[i],strlen(pToken)+1,"%s",pToken); 1266 pToken = strtok(NULL,";"); 1267 i++; 1268 } 1269 for(j=0;j<i;j++){ 1270 char *tmp=zStrdup(outputs_as_text[j]); 1271 free(outputs_as_text[j]); 1272 char *tmpc; 1273 tmpc=strtok(tmp,"@"); 1274 int k=0; 1275 while(tmpc!=NULL){ 1276 if(k==0){ 1277 if(tmp_output==NULL){ 1278 tmp_output=(maps*)malloc(MAPS_SIZE); 1279 if(tmp_output == NULL){ 1280 return errorException(m, _("Unable to allocate memory."), "InternalError",NULL); 1281 } 1282 tmp_output->name=zStrdup(tmpc); 1283 tmp_output->content=NULL; 1284 tmp_output->next=NULL; 1285 } 1286 } 1287 else{ 1288 char *tmpv=strstr(tmpc,"="); 1289 char tmpn[256]; 1290 memset(tmpn,0,256); 1291 strncpy(tmpn,tmpc,(strlen(tmpc)-strlen(tmpv))*sizeof(char)); 1292 tmpn[strlen(tmpc)-strlen(tmpv)]=0; 1293 #ifdef DEBUG 1294 fprintf(stderr,"OUTPUT DEF [%s]=[%s]\n",tmpn,tmpv+1); 1295 #endif 1296 if(tmp_output->content==NULL){ 1297 tmp_output->content=createMap(tmpn,tmpv+1); 1298 tmp_output->content->next=NULL; 1299 } 1300 else 1301 addToMap(tmp_output->content,tmpn,tmpv+1); 1302 } 1303 k++; 1304 #ifdef DEBUG 1305 fprintf(stderr,"***%s***\n",tmpc); 1306 #endif 1307 tmpc=strtok(NULL,"@"); 1308 } 1309 if(request_output_real_format==NULL) 1310 request_output_real_format=dupMaps(&tmp_output); 1311 else 1312 addMapsToMaps(&request_output_real_format,tmp_output); 1313 freeMaps(&tmp_output); 1314 free(tmp_output); 1315 tmp_output=NULL; 1316 #ifdef DEBUG 1317 dumpMaps(tmp_output); 1318 fflush(stderr); 1319 #endif 1320 free(tmp); 1321 } 1322 free(outputs_as_text); 1323 } 1332 char *pToken; 1333 maps *tmp_output = NULL; 1334 #ifdef DEBUG 1335 fprintf (stderr, "OUTPUT [%s]\n", cursor_output); 1336 #endif 1337 pToken = strtok (cursor_output, ";"); 1338 char **outputs_as_text = (char **) malloc (128 * sizeof (char *)); 1339 if (outputs_as_text == NULL) 1340 { 1341 return errorException (m, _("Unable to allocate memory"), 1342 "InternalError", NULL); 1343 } 1344 i = 0; 1345 while (pToken != NULL) 1346 { 1347 #ifdef DEBUG 1348 fprintf (stderr, "***%s***\n", pToken); 1349 fflush (stderr); 1350 fprintf (stderr, "***%s***\n", pToken); 1351 #endif 1352 outputs_as_text[i] = 1353 (char *) malloc ((strlen (pToken) + 1) * sizeof (char)); 1354 if (outputs_as_text[i] == NULL) 1355 { 1356 return errorException (m, _("Unable to allocate memory"), 1357 "InternalError", NULL); 1358 } 1359 snprintf (outputs_as_text[i], strlen (pToken) + 1, "%s", 1360 pToken); 1361 pToken = strtok (NULL, ";"); 1362 i++; 1363 } 1364 for (j = 0; j < i; j++) 1365 { 1366 char *tmp = zStrdup (outputs_as_text[j]); 1367 free (outputs_as_text[j]); 1368 char *tmpc; 1369 tmpc = strtok (tmp, "@"); 1370 int k = 0; 1371 while (tmpc != NULL) 1372 { 1373 if (k == 0) 1374 { 1375 if (tmp_output == NULL) 1376 { 1377 tmp_output = (maps *) malloc (MAPS_SIZE); 1378 if (tmp_output == NULL) 1379 { 1380 return errorException (m, 1381 _ 1382 ("Unable to allocate memory."), 1383 "InternalError", NULL); 1384 } 1385 tmp_output->name = zStrdup (tmpc); 1386 tmp_output->content = NULL; 1387 tmp_output->next = NULL; 1388 } 1389 } 1390 else 1391 { 1392 char *tmpv = strstr (tmpc, "="); 1393 char tmpn[256]; 1394 memset (tmpn, 0, 256); 1395 strncpy (tmpn, tmpc, 1396 (strlen (tmpc) - 1397 strlen (tmpv)) * sizeof (char)); 1398 tmpn[strlen (tmpc) - strlen (tmpv)] = 0; 1399 #ifdef DEBUG 1400 fprintf (stderr, "OUTPUT DEF [%s]=[%s]\n", tmpn, 1401 tmpv + 1); 1402 #endif 1403 if (tmp_output->content == NULL) 1404 { 1405 tmp_output->content = createMap (tmpn, tmpv + 1); 1406 tmp_output->content->next = NULL; 1407 } 1408 else 1409 addToMap (tmp_output->content, tmpn, tmpv + 1); 1410 } 1411 k++; 1412 #ifdef DEBUG 1413 fprintf (stderr, "***%s***\n", tmpc); 1414 #endif 1415 tmpc = strtok (NULL, "@"); 1416 } 1417 if (request_output_real_format == NULL) 1418 request_output_real_format = dupMaps (&tmp_output); 1419 else 1420 addMapsToMaps (&request_output_real_format, tmp_output); 1421 freeMaps (&tmp_output); 1422 free (tmp_output); 1423 tmp_output = NULL; 1424 #ifdef DEBUG 1425 dumpMaps (tmp_output); 1426 fflush (stderr); 1427 #endif 1428 free (tmp); 1429 } 1430 free (outputs_as_text); 1431 } 1324 1432 1325 1433 … … 1327 1435 * Parsing inputs provided as KVP 1328 1436 */ 1329 r_inputs=getMap(request_inputs,"DataInputs"); 1330 #ifdef DEBUG 1331 fprintf(stderr,"DATA INPUTS [%s]\n",r_inputs->value); 1332 #endif 1333 char cursor_input[40960]; 1334 if(r_inputs!=NULL) 1335 snprintf(cursor_input,40960,"%s",r_inputs->value); 1336 else{ 1337 errorException(m, _("Parameter <DataInputs> was not specified"),"MissingParameterValue","DataInputs"); 1338 freeMaps(&m); 1339 free(m); 1340 free(REQUEST); 1341 free(SERVICE_URL); 1342 InternetCloseHandle(&hInternet); 1343 freeService(&s1); 1344 free(s1); 1345 return 0; 1346 } 1347 j=0; 1348 1437 r_inputs = getMap (request_inputs, "DataInputs"); 1438 #ifdef DEBUG 1439 fprintf (stderr, "DATA INPUTS [%s]\n", r_inputs->value); 1440 #endif 1441 char cursor_input[40960]; 1442 if (r_inputs != NULL) 1443 snprintf (cursor_input, 40960, "%s", r_inputs->value); 1444 else 1445 { 1446 errorException (m, _("Parameter <DataInputs> was not specified"), 1447 "MissingParameterValue", "DataInputs"); 1448 freeMaps (&m); 1449 free (m); 1450 free (REQUEST); 1451 free (SERVICE_URL); 1452 InternetCloseHandle (&hInternet); 1453 freeService (&s1); 1454 free (s1); 1455 return 0; 1456 } 1457 j = 0; 1458 1349 1459 /** 1350 1460 * Put each DataInputs into the inputs_as_text array 1351 1461 */ 1352 char *tmp1=zStrdup(cursor_input); 1353 char * pToken; 1354 pToken=strtok(cursor_input,";"); 1355 if(pToken!=NULL && strncasecmp(pToken,tmp1,strlen(tmp1))==0){ 1356 char* tmp2=url_decode(tmp1); 1357 snprintf(cursor_input,(strlen(tmp2)+1)*sizeof(char),"%s",tmp2); 1358 free(tmp2); 1359 pToken=strtok(cursor_input,";"); 1360 } 1361 free(tmp1); 1362 1363 char** inputs_as_text=(char**)malloc(100*sizeof(char*)); 1364 if(inputs_as_text == NULL){ 1365 return errorException(m, _("Unable to allocate memory."), "InternalError",NULL); 1366 } 1367 i=0; 1368 while(pToken!=NULL){ 1369 #ifdef DEBUG 1370 fprintf(stderr,"***%s***\n",pToken); 1371 #endif 1372 fflush(stderr); 1373 #ifdef DEBUG 1374 fprintf(stderr,"***%s***\n",pToken); 1375 #endif 1376 inputs_as_text[i]=(char*)malloc((strlen(pToken)+1)*sizeof(char)); 1377 snprintf(inputs_as_text[i],strlen(pToken)+1,"%s",pToken); 1378 if(inputs_as_text[i] == NULL){ 1379 return errorException(m, _("Unable to allocate memory."), "InternalError",NULL); 1380 } 1381 pToken = strtok(NULL,";"); 1382 i++; 1383 } 1384 1385 for(j=0;j<i;j++){ 1386 char *tmp=zStrdup(inputs_as_text[j]); 1387 free(inputs_as_text[j]); 1388 char *tmpc; 1389 tmpc=strtok(tmp,"@"); 1390 while(tmpc!=NULL){ 1391 #ifdef DEBUG 1392 fprintf(stderr,"***\n***%s***\n",tmpc); 1393 #endif 1394 char *tmpv=strstr(tmpc,"="); 1395 char tmpn[256]; 1396 memset(tmpn,0,256); 1397 if(tmpv!=NULL){ 1398 strncpy(tmpn,tmpc,(strlen(tmpc)-strlen(tmpv))*sizeof(char)); 1399 tmpn[strlen(tmpc)-strlen(tmpv)]=0; 1400 } 1401 else{ 1402 strncpy(tmpn,tmpc,strlen(tmpc)*sizeof(char)); 1403 tmpn[strlen(tmpc)]=0; 1404 } 1405 #ifdef DEBUG 1406 fprintf(stderr,"***\n*** %s = %s ***\n",tmpn,tmpv+1); 1407 #endif 1408 if(tmpmaps==NULL){ 1409 tmpmaps=(maps*)malloc(MAPS_SIZE); 1410 if(tmpmaps == NULL){ 1411 return errorException(m, _("Unable to allocate memory."), "InternalError",NULL); 1412 } 1413 tmpmaps->name=zStrdup(tmpn); 1414 if(tmpv!=NULL){ 1415 char *tmpvf=url_decode(tmpv+1); 1416 tmpmaps->content=createMap("value",tmpvf); 1417 free(tmpvf); 1418 } 1419 else 1420 tmpmaps->content=createMap("value","Reference"); 1421 tmpmaps->next=NULL; 1422 } 1423 tmpc=strtok(NULL,"@"); 1424 while(tmpc!=NULL){ 1425 #ifdef DEBUG 1426 fprintf(stderr,"*** KVP NON URL-ENCODED \n***%s***\n",tmpc); 1427 #endif 1428 char *tmpv1=strstr(tmpc,"="); 1429 #ifdef DEBUG 1430 fprintf(stderr,"*** VALUE NON URL-ENCODED \n***%s***\n",tmpv1+1); 1431 #endif 1432 char tmpn1[1024]; 1433 memset(tmpn1,0,1024); 1434 if(tmpv1!=NULL){ 1435 strncpy(tmpn1,tmpc,strlen(tmpc)-strlen(tmpv1)); 1436 tmpn1[strlen(tmpc)-strlen(tmpv1)]=0; 1437 addToMap(tmpmaps->content,tmpn1,tmpv1+1); 1438 } 1439 else{ 1440 strncpy(tmpn1,tmpc,strlen(tmpc)); 1441 tmpn1[strlen(tmpc)]=0; 1442 map* lmap=getLastMap(tmpmaps->content); 1443 char *tmpValue=(char*)malloc((strlen(tmpv)+strlen(tmpc)+1)*sizeof(char)); 1444 sprintf(tmpValue,"%s@%s",tmpv+1,tmpc); 1445 free(lmap->value); 1446 lmap->value=zStrdup(tmpValue); 1447 free(tmpValue); 1448 tmpc=strtok(NULL,"@"); 1449 continue; 1450 } 1451 #ifdef DEBUG 1452 fprintf(stderr,"*** NAME NON URL-ENCODED \n***%s***\n",tmpn1); 1453 fprintf(stderr,"*** VALUE NON URL-ENCODED \n***%s***\n",tmpv1+1); 1454 #endif 1455 if(strcmp(tmpn1,"xlink:href")!=0) 1456 addToMap(tmpmaps->content,tmpn1,tmpv1+1); 1457 else 1458 if(tmpv1!=NULL){ 1459 char *tmpx2=url_decode(tmpv1+1); 1460 if(strncasecmp(tmpx2,"http://",7)!=0 && 1461 strncasecmp(tmpx2,"ftp://",6)!=0 && 1462 strncasecmp(tmpx2,"https://",8)!=0){ 1463 char emsg[1024]; 1464 sprintf(emsg,_("Unable to find a valid protocol to download the remote file %s"),tmpv1+1); 1465 errorException(m,emsg,"InternalError",NULL); 1466 freeMaps(&m); 1467 free(m); 1468 free(REQUEST); 1469 free(SERVICE_URL); 1470 InternetCloseHandle(&hInternet); 1471 freeService(&s1); 1472 free(s1); 1473 return 0; 1474 } 1475 #ifdef DEBUG 1476 fprintf(stderr,"REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n",tmpv1+1); 1477 #endif 1478 addToMap(tmpmaps->content,tmpn1,tmpx2); 1462 char *tmp1 = zStrdup (cursor_input); 1463 char *pToken; 1464 pToken = strtok (cursor_input, ";"); 1465 if (pToken != NULL && strncasecmp (pToken, tmp1, strlen (tmp1)) == 0) 1466 { 1467 char *tmp2 = url_decode (tmp1); 1468 snprintf (cursor_input, (strlen (tmp2) + 1) * sizeof (char), "%s", 1469 tmp2); 1470 free (tmp2); 1471 pToken = strtok (cursor_input, ";"); 1472 } 1473 free (tmp1); 1474 1475 char **inputs_as_text = (char **) malloc (100 * sizeof (char *)); 1476 if (inputs_as_text == NULL) 1477 { 1478 return errorException (m, _("Unable to allocate memory."), 1479 "InternalError", NULL); 1480 } 1481 i = 0; 1482 while (pToken != NULL) 1483 { 1484 #ifdef DEBUG 1485 fprintf (stderr, "***%s***\n", pToken); 1486 #endif 1487 fflush (stderr); 1488 #ifdef DEBUG 1489 fprintf (stderr, "***%s***\n", pToken); 1490 #endif 1491 inputs_as_text[i] = 1492 (char *) malloc ((strlen (pToken) + 1) * sizeof (char)); 1493 snprintf (inputs_as_text[i], strlen (pToken) + 1, "%s", pToken); 1494 if (inputs_as_text[i] == NULL) 1495 { 1496 return errorException (m, _("Unable to allocate memory."), 1497 "InternalError", NULL); 1498 } 1499 pToken = strtok (NULL, ";"); 1500 i++; 1501 } 1502 1503 for (j = 0; j < i; j++) 1504 { 1505 char *tmp = zStrdup (inputs_as_text[j]); 1506 free (inputs_as_text[j]); 1507 char *tmpc; 1508 tmpc = strtok (tmp, "@"); 1509 while (tmpc != NULL) 1510 { 1511 #ifdef DEBUG 1512 fprintf (stderr, "***\n***%s***\n", tmpc); 1513 #endif 1514 char *tmpv = strstr (tmpc, "="); 1515 char tmpn[256]; 1516 memset (tmpn, 0, 256); 1517 if (tmpv != NULL) 1518 { 1519 strncpy (tmpn, tmpc, 1520 (strlen (tmpc) - strlen (tmpv)) * sizeof (char)); 1521 tmpn[strlen (tmpc) - strlen (tmpv)] = 0; 1522 } 1523 else 1524 { 1525 strncpy (tmpn, tmpc, strlen (tmpc) * sizeof (char)); 1526 tmpn[strlen (tmpc)] = 0; 1527 } 1528 #ifdef DEBUG 1529 fprintf (stderr, "***\n*** %s = %s ***\n", tmpn, tmpv + 1); 1530 #endif 1531 if (tmpmaps == NULL) 1532 { 1533 tmpmaps = (maps *) malloc (MAPS_SIZE); 1534 if (tmpmaps == NULL) 1535 { 1536 return errorException (m, 1537 _("Unable to allocate memory."), 1538 "InternalError", NULL); 1539 } 1540 tmpmaps->name = zStrdup (tmpn); 1541 if (tmpv != NULL) 1542 { 1543 char *tmpvf = url_decode (tmpv + 1); 1544 tmpmaps->content = createMap ("value", tmpvf); 1545 free (tmpvf); 1546 } 1547 else 1548 tmpmaps->content = createMap ("value", "Reference"); 1549 tmpmaps->next = NULL; 1550 } 1551 tmpc = strtok (NULL, "@"); 1552 while (tmpc != NULL) 1553 { 1554 #ifdef DEBUG 1555 fprintf (stderr, "*** KVP NON URL-ENCODED \n***%s***\n", 1556 tmpc); 1557 #endif 1558 char *tmpv1 = strstr (tmpc, "="); 1559 #ifdef DEBUG 1560 fprintf (stderr, "*** VALUE NON URL-ENCODED \n***%s***\n", 1561 tmpv1 + 1); 1562 #endif 1563 char tmpn1[1024]; 1564 memset (tmpn1, 0, 1024); 1565 if (tmpv1 != NULL) 1566 { 1567 strncpy (tmpn1, tmpc, strlen (tmpc) - strlen (tmpv1)); 1568 tmpn1[strlen (tmpc) - strlen (tmpv1)] = 0; 1569 addToMap (tmpmaps->content, tmpn1, tmpv1 + 1); 1570 } 1571 else 1572 { 1573 strncpy (tmpn1, tmpc, strlen (tmpc)); 1574 tmpn1[strlen (tmpc)] = 0; 1575 map *lmap = getLastMap (tmpmaps->content); 1576 char *tmpValue = 1577 (char *) malloc ((strlen (tmpv) + strlen (tmpc) + 1) * 1578 sizeof (char)); 1579 sprintf (tmpValue, "%s@%s", tmpv + 1, tmpc); 1580 free (lmap->value); 1581 lmap->value = zStrdup (tmpValue); 1582 free (tmpValue); 1583 tmpc = strtok (NULL, "@"); 1584 continue; 1585 } 1586 #ifdef DEBUG 1587 fprintf (stderr, "*** NAME NON URL-ENCODED \n***%s***\n", 1588 tmpn1); 1589 fprintf (stderr, "*** VALUE NON URL-ENCODED \n***%s***\n", 1590 tmpv1 + 1); 1591 #endif 1592 if (strcmp (tmpn1, "xlink:href") != 0) 1593 addToMap (tmpmaps->content, tmpn1, tmpv1 + 1); 1594 else if (tmpv1 != NULL) 1595 { 1596 char *tmpx2 = url_decode (tmpv1 + 1); 1597 if (strncasecmp (tmpx2, "http://", 7) != 0 && 1598 strncasecmp (tmpx2, "ftp://", 6) != 0 && 1599 strncasecmp (tmpx2, "https://", 8) != 0) 1600 { 1601 char emsg[1024]; 1602 sprintf (emsg, 1603 _ 1604 ("Unable to find a valid protocol to download the remote file %s"), 1605 tmpv1 + 1); 1606 errorException (m, emsg, "InternalError", NULL); 1607 freeMaps (&m); 1608 free (m); 1609 free (REQUEST); 1610 free (SERVICE_URL); 1611 InternetCloseHandle (&hInternet); 1612 freeService (&s1); 1613 free (s1); 1614 return 0; 1615 } 1616 #ifdef DEBUG 1617 fprintf (stderr, 1618 "REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n", 1619 tmpv1 + 1); 1620 #endif 1621 addToMap (tmpmaps->content, tmpn1, tmpx2); 1479 1622 #ifndef WIN32 1480 if(CHECK_INET_HANDLE(hInternet)) 1481 #endif 1482 { 1483 if(loadRemoteFile(&m,&tmpmaps->content,&hInternet,tmpx2)<0){ 1484 freeMaps(&m); 1485 free(m); 1486 free(REQUEST); 1487 free(SERVICE_URL); 1488 InternetCloseHandle(&hInternet); 1489 freeService(&s1); 1490 free(s1); 1491 return 0; 1492 } 1493 } 1494 free(tmpx2); 1495 addToMap(tmpmaps->content,"Reference",tmpv1+1); 1496 } 1497 tmpc=strtok(NULL,"@"); 1498 } 1499 #ifdef DEBUG 1500 dumpMaps(tmpmaps); 1501 fflush(stderr); 1502 #endif 1503 if(request_input_real_format==NULL) 1504 request_input_real_format=dupMaps(&tmpmaps); 1505 else{ 1506 maps* testPresence=getMaps(request_input_real_format,tmpmaps->name); 1507 if(testPresence!=NULL){ 1508 elements* elem=getElements(s1->inputs,tmpmaps->name); 1509 if(elem!=NULL){ 1510 if(appendMapsToMaps(m,request_input_real_format,tmpmaps,elem)<0){ 1511 freeMaps(&m); 1512 free(m); 1513 free(REQUEST); 1514 free(SERVICE_URL); 1515 InternetCloseHandle(&hInternet); 1516 freeService(&s1); 1517 free(s1); 1518 return 0; 1519 } 1520 } 1521 } 1522 else 1523 addMapsToMaps(&request_input_real_format,tmpmaps); 1524 } 1525 freeMaps(&tmpmaps); 1526 free(tmpmaps); 1527 tmpmaps=NULL; 1528 free(tmp); 1529 } 1530 } 1531 free(inputs_as_text); 1532 } 1533 else { 1623 if (CHECK_INET_HANDLE (hInternet)) 1624 #endif 1625 { 1626 if (loadRemoteFile 1627 (&m, &tmpmaps->content, &hInternet, tmpx2) < 0) 1628 { 1629 freeMaps (&m); 1630 free (m); 1631 free (REQUEST); 1632 free (SERVICE_URL); 1633 InternetCloseHandle (&hInternet); 1634 freeService (&s1); 1635 free (s1); 1636 return 0; 1637 } 1638 } 1639 free (tmpx2); 1640 addToMap (tmpmaps->content, "Reference", tmpv1 + 1); 1641 } 1642 tmpc = strtok (NULL, "@"); 1643 } 1644 #ifdef DEBUG 1645 dumpMaps (tmpmaps); 1646 fflush (stderr); 1647 #endif 1648 if (request_input_real_format == NULL) 1649 request_input_real_format = dupMaps (&tmpmaps); 1650 else 1651 { 1652 maps *testPresence = 1653 getMaps (request_input_real_format, tmpmaps->name); 1654 if (testPresence != NULL) 1655 { 1656 elements *elem = 1657 getElements (s1->inputs, tmpmaps->name); 1658 if (elem != NULL) 1659 { 1660 if (appendMapsToMaps 1661 (m, request_input_real_format, tmpmaps, 1662 elem) < 0) 1663 { 1664 freeMaps (&m); 1665 free (m); 1666 free (REQUEST); 1667 free (SERVICE_URL); 1668 InternetCloseHandle (&hInternet); 1669 freeService (&s1); 1670 free (s1); 1671 return 0; 1672 } 1673 } 1674 } 1675 else 1676 addMapsToMaps (&request_input_real_format, tmpmaps); 1677 } 1678 freeMaps (&tmpmaps); 1679 free (tmpmaps); 1680 tmpmaps = NULL; 1681 free (tmp); 1682 } 1683 } 1684 free (inputs_as_text); 1685 } 1686 else 1687 { 1534 1688 /** 1535 1689 * Parse XML request 1536 */ 1537 xmlInitParser(); 1538 #ifdef DEBUG 1539 fflush(stderr); 1540 fprintf(stderr,"BEFORE %s\n",postRequest->value); 1541 fflush(stderr); 1542 #endif 1543 xmlDocPtr doc = 1544 xmlParseMemory(postRequest->value,cgiContentLength); 1545 #ifdef DEBUG 1546 fprintf(stderr,"AFTER\n"); 1547 fflush(stderr); 1690 */ 1691 xmlInitParser (); 1692 #ifdef DEBUG 1693 fflush (stderr); 1694 fprintf (stderr, "BEFORE %s\n", postRequest->value); 1695 fflush (stderr); 1696 #endif 1697 xmlDocPtr doc = xmlParseMemory (postRequest->value, cgiContentLength); 1698 #ifdef DEBUG 1699 fprintf (stderr, "AFTER\n"); 1700 fflush (stderr); 1548 1701 #endif 1549 1702 /** 1550 1703 * Parse every Input in DataInputs node. 1551 1704 */ 1552 xmlXPathObjectPtr tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='Input']"); 1553 xmlNodeSet* tmps=tmpsptr->nodesetval; 1554 #ifdef DEBUG 1555 fprintf(stderr,"*****%d*****\n",tmps->nodeNr); 1556 #endif 1557 for(int k=0;k<tmps->nodeNr;k++){ 1558 maps *tmpmaps=NULL; 1559 xmlNodePtr cur=tmps->nodeTab[k]; 1560 if(tmps->nodeTab[k]->type == XML_ELEMENT_NODE) { 1561 /** 1705 xmlXPathObjectPtr tmpsptr = 1706 extractFromDoc (doc, "/*/*/*[local-name()='Input']"); 1707 xmlNodeSet *tmps = tmpsptr->nodesetval; 1708 #ifdef DEBUG 1709 fprintf (stderr, "*****%d*****\n", tmps->nodeNr); 1710 #endif 1711 for (int k = 0; k < tmps->nodeNr; k++) 1712 { 1713 maps *tmpmaps = NULL; 1714 xmlNodePtr cur = tmps->nodeTab[k]; 1715 if (tmps->nodeTab[k]->type == XML_ELEMENT_NODE) 1716 { 1717 /** 1562 1718 * A specific Input node. 1563 1719 */ 1564 1720 #ifdef DEBUG 1565 fprintf(stderr, "= element 0 node \"%s\"\n", cur->name); 1566 #endif 1567 xmlNodePtr cur2=cur->children; 1568 while(cur2!=NULL){ 1569 while(cur2!=NULL && cur2->type!=XML_ELEMENT_NODE) 1570 cur2=cur2->next; 1571 if(cur2==NULL) 1572 break; 1573 /** 1721 fprintf (stderr, "= element 0 node \"%s\"\n", cur->name); 1722 #endif 1723 xmlNodePtr cur2 = cur->children; 1724 while (cur2 != NULL) 1725 { 1726 while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE) 1727 cur2 = cur2->next; 1728 if (cur2 == NULL) 1729 break; 1730 /** 1574 1731 * Indentifier 1575 1732 */ 1576 if(xmlStrncasecmp(cur2->name,BAD_CAST "Identifier",xmlStrlen(cur2->name))==0){ 1577 xmlChar *val= xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); 1578 if(tmpmaps==NULL){ 1579 tmpmaps=(maps*)malloc(MAPS_SIZE); 1580 if(tmpmaps == NULL){ 1581 return errorException(m, _("Unable to allocate memory."), "InternalError",NULL); 1582 } 1583 tmpmaps->name=zStrdup((char*)val); 1584 tmpmaps->content=NULL; 1585 tmpmaps->next=NULL; 1586 } 1587 xmlFree(val); 1588 } 1589 /** 1733 if (xmlStrncasecmp 1734 (cur2->name, BAD_CAST "Identifier", 1735 xmlStrlen (cur2->name)) == 0) 1736 { 1737 xmlChar *val = 1738 xmlNodeListGetString (doc, cur2->xmlChildrenNode, 1); 1739 if (tmpmaps == NULL) 1740 { 1741 tmpmaps = (maps *) malloc (MAPS_SIZE); 1742 if (tmpmaps == NULL) 1743 { 1744 return errorException (m, 1745 _ 1746 ("Unable to allocate memory."), 1747 "InternalError", NULL); 1748 } 1749 tmpmaps->name = zStrdup ((char *) val); 1750 tmpmaps->content = NULL; 1751 tmpmaps->next = NULL; 1752 } 1753 xmlFree (val); 1754 } 1755 /** 1590 1756 * Title, Asbtract 1591 1757 */ 1592 if(xmlStrncasecmp(cur2->name,BAD_CAST "Title",xmlStrlen(cur2->name))==0 || 1593 xmlStrncasecmp(cur2->name,BAD_CAST "Abstract",xmlStrlen(cur2->name))==0){ 1594 xmlChar *val= 1595 xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); 1596 if(tmpmaps==NULL){ 1597 tmpmaps=(maps*)malloc(MAPS_SIZE); 1598 if(tmpmaps == NULL){ 1599 return errorException(m, _("Unable to allocate memory."), "InternalError",NULL); 1600 } 1601 tmpmaps->name=zStrdup("missingIndetifier"); 1602 tmpmaps->content=createMap((char*)cur2->name,(char*)val); 1603 tmpmaps->next=NULL; 1604 } 1605 else{ 1606 if(tmpmaps->content!=NULL) 1607 addToMap(tmpmaps->content, 1608 (char*)cur2->name,(char*)val); 1609 else 1610 tmpmaps->content= 1611 createMap((char*)cur2->name,(char*)val); 1612 } 1613 #ifdef DEBUG 1614 dumpMaps(tmpmaps); 1615 #endif 1616 xmlFree(val); 1617 } 1618 /** 1758 if (xmlStrncasecmp 1759 (cur2->name, BAD_CAST "Title", 1760 xmlStrlen (cur2->name)) == 0 1761 || xmlStrncasecmp (cur2->name, BAD_CAST "Abstract", 1762 xmlStrlen (cur2->name)) == 0) 1763 { 1764 xmlChar *val = 1765 xmlNodeListGetString (doc, cur2->xmlChildrenNode, 1); 1766 if (tmpmaps == NULL) 1767 { 1768 tmpmaps = (maps *) malloc (MAPS_SIZE); 1769 if (tmpmaps == NULL) 1770 { 1771 return errorException (m, 1772 _ 1773 ("Unable to allocate memory."), 1774 "InternalError", NULL); 1775 } 1776 tmpmaps->name = zStrdup ("missingIndetifier"); 1777 tmpmaps->content = 1778 createMap ((char *) cur2->name, (char *) val); 1779 tmpmaps->next = NULL; 1780 } 1781 else 1782 { 1783 if (tmpmaps->content != NULL) 1784 addToMap (tmpmaps->content, 1785 (char *) cur2->name, (char *) val); 1786 else 1787 tmpmaps->content = 1788 createMap ((char *) cur2->name, (char *) val); 1789 } 1790 #ifdef DEBUG 1791 dumpMaps (tmpmaps); 1792 #endif 1793 xmlFree (val); 1794 } 1795 /** 1619 1796 * InputDataFormChoice (Reference or Data ?) 1620 1797 */ 1621 if(xmlStrcasecmp(cur2->name,BAD_CAST "Reference")==0){ 1622 /** 1798 if (xmlStrcasecmp (cur2->name, BAD_CAST "Reference") == 0) 1799 { 1800 /** 1623 1801 * Get every attribute from a Reference node 1624 1802 * mimeType, encoding, schema, href, method … … 1626 1804 */ 1627 1805 #ifdef DEBUG 1628 fprintf(stderr,"REFERENCE\n"); 1629 #endif 1630 const char *refs[5]={"mimeType","encoding","schema","method","href"}; 1631 for(int l=0;l<5;l++){ 1632 #ifdef DEBUG 1633 fprintf(stderr,"*** %s ***",refs[l]); 1634 #endif 1635 xmlChar *val=xmlGetProp(cur2,BAD_CAST refs[l]); 1636 if(val!=NULL && xmlStrlen(val)>0){ 1637 if(tmpmaps->content!=NULL) 1638 addToMap(tmpmaps->content,refs[l],(char*)val); 1639 else 1640 tmpmaps->content=createMap(refs[l],(char*)val); 1641 map* ltmp=getMap(tmpmaps->content,"method"); 1642 if(l==4){ 1643 if(!(ltmp!=NULL && strncmp(ltmp->value,"POST",4)==0) 1644 && CHECK_INET_HANDLE(hInternet)){ 1645 if(loadRemoteFile(&m,&tmpmaps->content,&hInternet,(char*)val)!=0){ 1646 freeMaps(&m); 1647 free(m); 1648 free(REQUEST); 1649 free(SERVICE_URL); 1650 InternetCloseHandle(&hInternet); 1651 freeService(&s1); 1652 free(s1); 1653 return 0; 1654 } 1655 } 1656 } 1657 } 1658 #ifdef DEBUG 1659 fprintf(stderr,"%s\n",val); 1660 #endif 1661 xmlFree(val); 1662 } 1806 fprintf (stderr, "REFERENCE\n"); 1807 #endif 1808 const char *refs[5] = 1809 { "mimeType", "encoding", "schema", "method", 1810 "href" 1811 }; 1812 for (int l = 0; l < 5; l++) 1813 { 1814 #ifdef DEBUG 1815 fprintf (stderr, "*** %s ***", refs[l]); 1816 #endif 1817 xmlChar *val = xmlGetProp (cur2, BAD_CAST refs[l]); 1818 if (val != NULL && xmlStrlen (val) > 0) 1819 { 1820 if (tmpmaps->content != NULL) 1821 addToMap (tmpmaps->content, refs[l], 1822 (char *) val); 1823 else 1824 tmpmaps->content = 1825 createMap (refs[l], (char *) val); 1826 map *ltmp = getMap (tmpmaps->content, "method"); 1827 if (l == 4) 1828 { 1829 if (! 1830 (ltmp != NULL 1831 && strncmp (ltmp->value, "POST", 1832 4) == 0) 1833 && CHECK_INET_HANDLE (hInternet)) 1834 { 1835 if (loadRemoteFile 1836 (&m, &tmpmaps->content, &hInternet, 1837 (char *) val) != 0) 1838 { 1839 freeMaps (&m); 1840 free (m); 1841 free (REQUEST); 1842 free (SERVICE_URL); 1843 InternetCloseHandle (&hInternet); 1844 freeService (&s1); 1845 free (s1); 1846 return 0; 1847 } 1848 } 1849 } 1850 } 1851 #ifdef DEBUG 1852 fprintf (stderr, "%s\n", val); 1853 #endif 1854 xmlFree (val); 1855 } 1663 1856 #ifdef POST_DEBUG 1664 fprintf(stderr,"Parse Header and Body from Reference \n"); 1665 #endif 1666 xmlNodePtr cur3=cur2->children; 1667 /* HINTERNET hInternetP; 1668 hInternetP=InternetOpen( 1669 #ifndef WIN32 1670 (LPCTSTR) 1671 #endif 1672 "ZooWPSClient\0", 1673 INTERNET_OPEN_TYPE_PRECONFIG, 1674 NULL,NULL, 0);*/ 1675 //hInternet.ihandle[hInternet.nb].header=NULL; 1676 while(cur3!=NULL){ 1677 while(cur3!=NULL && cur3->type!=XML_ELEMENT_NODE) 1678 cur3=cur3->next; 1679 if(cur3==NULL) 1680 break; 1681 if(xmlStrcasecmp(cur3->name,BAD_CAST "Header")==0 ){ 1682 const char *ha[2]; 1683 ha[0]="key"; 1684 ha[1]="value"; 1685 int hai; 1686 char *has; 1687 char *key; 1688 for(hai=0;hai<2;hai++){ 1689 xmlChar *val=xmlGetProp(cur3,BAD_CAST ha[hai]); 1857 fprintf (stderr, 1858 "Parse Header and Body from Reference \n"); 1859 #endif 1860 xmlNodePtr cur3 = cur2->children; 1861 /* HINTERNET hInternetP; 1862 hInternetP=InternetOpen( 1863 #ifndef WIN32 1864 (LPCTSTR) 1865 #endif 1866 "ZooWPSClient\0", 1867 INTERNET_OPEN_TYPE_PRECONFIG, 1868 NULL,NULL, 0); */ 1869 //hInternet.ihandle[hInternet.nb].header=NULL; 1870 while (cur3 != NULL) 1871 { 1872 while (cur3 != NULL 1873 && cur3->type != XML_ELEMENT_NODE) 1874 cur3 = cur3->next; 1875 if (cur3 == NULL) 1876 break; 1877 if (xmlStrcasecmp (cur3->name, BAD_CAST "Header") == 1878 0) 1879 { 1880 const char *ha[2]; 1881 ha[0] = "key"; 1882 ha[1] = "value"; 1883 int hai; 1884 char *has; 1885 char *key; 1886 for (hai = 0; hai < 2; hai++) 1887 { 1888 xmlChar *val = 1889 xmlGetProp (cur3, BAD_CAST ha[hai]); 1690 1890 #ifdef POST_DEBUG 1691 fprintf(stderr,"%s = %s\n",ha[hai],(char*)val); 1692 #endif 1693 if(hai==0){ 1694 key=zStrdup((char*)val); 1695 }else{ 1696 has=(char*)malloc((4+xmlStrlen(val)+strlen(key))*sizeof(char)); 1697 if(has == NULL){ 1698 return errorException(m, _("Unable to allocate memory."), "InternalError",NULL); 1699 } 1700 snprintf(has,(3+xmlStrlen(val)+strlen(key)),"%s: %s",key,(char*)val); 1701 free(key); 1891 fprintf (stderr, "%s = %s\n", ha[hai], 1892 (char *) val); 1893 #endif 1894 if (hai == 0) 1895 { 1896 key = zStrdup ((char *) val); 1897 } 1898 else 1899 { 1900 has = 1901 (char *) 1902 malloc ((4 + xmlStrlen (val) + 1903 strlen (key)) * 1904 sizeof (char)); 1905 if (has == NULL) 1906 { 1907 return errorException (m, 1908 _ 1909 ("Unable to allocate memory."), 1910 "InternalError", 1911 NULL); 1912 } 1913 snprintf (has, 1914 (3 + xmlStrlen (val) + 1915 strlen (key)), "%s: %s", key, 1916 (char *) val); 1917 free (key); 1702 1918 #ifdef POST_DEBUG 1703 fprintf(stderr,"%s\n",has); 1704 #endif 1705 } 1706 xmlFree(val); 1707 } 1708 hInternet.ihandle[hInternet.nb].header=curl_slist_append(hInternet.ihandle[hInternet.nb].header, has); 1709 if(has!=NULL) 1710 free(has); 1711 } 1712 else{ 1919 fprintf (stderr, "%s\n", has); 1920 #endif 1921 } 1922 xmlFree (val); 1923 } 1924 hInternet.ihandle[hInternet.nb].header = 1925 curl_slist_append (hInternet.ihandle 1926 [hInternet.nb].header, 1927 has); 1928 if (has != NULL) 1929 free (has); 1930 } 1931 else 1932 { 1713 1933 #ifdef POST_DEBUG 1714 fprintf(stderr,"Try to fetch the body part of the request ...\n"); 1715 #endif 1716 if(xmlStrcasecmp(cur3->name,BAD_CAST "Body")==0 ){ 1934 fprintf (stderr, 1935 "Try to fetch the body part of the request ...\n"); 1936 #endif 1937 if (xmlStrcasecmp (cur3->name, BAD_CAST "Body") 1938 == 0) 1939 { 1717 1940 #ifdef POST_DEBUG 1718 fprintf(stderr,"Body part found !!!\n",(char*)cur3->content); 1719 #endif 1720 char *tmp=(char*)malloc(cgiContentLength+1*sizeof(char)); 1721 memset(tmp,0,cgiContentLength); 1722 xmlNodePtr cur4=cur3->children; 1723 while(cur4!=NULL){ 1724 while(cur4->type!=XML_ELEMENT_NODE) 1725 cur4=cur4->next; 1726 xmlDocPtr bdoc = xmlNewDoc(BAD_CAST "1.0"); 1727 bdoc->encoding = xmlCharStrdup ("UTF-8"); 1728 xmlDocSetRootElement(bdoc,cur4); 1729 xmlChar* btmps; 1730 int bsize; 1731 xmlDocDumpMemory(bdoc,&btmps,&bsize); 1941 fprintf (stderr, "Body part found !!!\n", 1942 (char *) cur3->content); 1943 #endif 1944 char *tmp = 1945 (char *) malloc (cgiContentLength + 1946 1 * sizeof (char)); 1947 memset (tmp, 0, cgiContentLength); 1948 xmlNodePtr cur4 = cur3->children; 1949 while (cur4 != NULL) 1950 { 1951 while (cur4->type != XML_ELEMENT_NODE) 1952 cur4 = cur4->next; 1953 xmlDocPtr bdoc = 1954 xmlNewDoc (BAD_CAST "1.0"); 1955 bdoc->encoding = 1956 xmlCharStrdup ("UTF-8"); 1957 xmlDocSetRootElement (bdoc, cur4); 1958 xmlChar *btmps; 1959 int bsize; 1960 xmlDocDumpMemory (bdoc, &btmps, &bsize); 1732 1961 #ifdef POST_DEBUG 1733 fprintf(stderr,"Body part found !!! %s %s\n",tmp,(char*)btmps); 1734 #endif 1735 if(btmps!=NULL) 1736 sprintf(tmp,"%s",(char*)btmps); 1737 xmlFree(btmps); 1738 cur4=cur4->next; 1739 xmlFreeDoc(bdoc); 1740 } 1741 map *btmp=getMap(tmpmaps->content,"href"); 1742 if(btmp!=NULL){ 1962 fprintf (stderr, 1963 "Body part found !!! %s %s\n", 1964 tmp, (char *) btmps); 1965 #endif 1966 if (btmps != NULL) 1967 sprintf (tmp, "%s", (char *) btmps); 1968 xmlFree (btmps); 1969 cur4 = cur4->next; 1970 xmlFreeDoc (bdoc); 1971 } 1972 map *btmp = 1973 getMap (tmpmaps->content, "href"); 1974 if (btmp != NULL) 1975 { 1743 1976 #ifdef POST_DEBUG 1744 fprintf(stderr,"%s %s\n",btmp->value,tmp); 1745 curl_easy_setopt(hInternet.handle, CURLOPT_VERBOSE, 1); 1746 #endif 1747 hInternet.waitingRequests[hInternet.nb]=strdup(tmp); 1748 InternetOpenUrl(&hInternet,btmp->value,hInternet.waitingRequests[hInternet.nb],strlen(hInternet.waitingRequests[hInternet.nb]), 1749 INTERNET_FLAG_NO_CACHE_WRITE,0); 1750 } 1751 free(tmp); 1752 } 1753 else 1754 if(xmlStrcasecmp(cur3->name,BAD_CAST "BodyReference")==0 ){ 1755 xmlChar *val=xmlGetProp(cur3,BAD_CAST "href"); 1756 HINTERNET bInternet,res1; 1757 bInternet=InternetOpen( 1977 fprintf (stderr, "%s %s\n", btmp->value, 1978 tmp); 1979 curl_easy_setopt (hInternet.handle, 1980 CURLOPT_VERBOSE, 1); 1981 #endif 1982 hInternet.waitingRequests[hInternet. 1983 nb] = 1984 strdup (tmp); 1985 InternetOpenUrl (&hInternet, 1986 btmp->value, 1987 hInternet. 1988 waitingRequests 1989 [hInternet.nb], 1990 strlen (hInternet. 1991 waitingRequests 1992 [hInternet. 1993 nb]), 1994 INTERNET_FLAG_NO_CACHE_WRITE, 1995 0); 1996 } 1997 free (tmp); 1998 } 1999 else 2000 if (xmlStrcasecmp 2001 (cur3->name, 2002 BAD_CAST "BodyReference") == 0) 2003 { 2004 xmlChar *val = 2005 xmlGetProp (cur3, BAD_CAST "href"); 2006 HINTERNET bInternet, res1; 2007 bInternet = InternetOpen ( 1758 2008 #ifndef WIN32 1759 (LPCTSTR) 1760 #endif 1761 "ZooWPSClient\0", 1762 INTERNET_OPEN_TYPE_PRECONFIG, 1763 NULL,NULL, 0); 1764 if(!CHECK_INET_HANDLE(hInternet)) 1765 fprintf(stderr,"WARNING : hInternet handle failed to initialize"); 2009 (LPCTSTR) 2010 #endif 2011 "ZooWPSClient\0", 2012 INTERNET_OPEN_TYPE_PRECONFIG, 2013 NULL, NULL, 0); 2014 if (!CHECK_INET_HANDLE (hInternet)) 2015 fprintf (stderr, 2016 "WARNING : hInternet handle failed to initialize"); 1766 2017 #ifdef POST_DEBUG 1767 curl_easy_setopt(bInternet.handle, CURLOPT_VERBOSE, 1); 1768 #endif 1769 bInternet.waitingRequests[0]=strdup((char*)val); 1770 res1=InternetOpenUrl(&bInternet,bInternet.waitingRequests[0],NULL,0, 1771 INTERNET_FLAG_NO_CACHE_WRITE,0); 1772 processDownloads(&bInternet); 1773 char* tmp= 1774 (char*)malloc((bInternet.ihandle[0].nDataLen+1)*sizeof(char)); 1775 if(tmp == NULL){ 1776 return errorException(m, _("Unable to allocate memory."), "InternalError",NULL); 1777 } 1778 size_t bRead; 1779 InternetReadFile(bInternet.ihandle[0], (LPVOID)tmp, 1780 bInternet.ihandle[0].nDataLen, &bRead); 1781 tmp[bInternet.ihandle[0].nDataLen]=0; 1782 InternetCloseHandle(&bInternet); 1783 map *btmp=getMap(tmpmaps->content,"href"); 1784 if(btmp!=NULL){ 2018 curl_easy_setopt (bInternet.handle, 2019 CURLOPT_VERBOSE, 1); 2020 #endif 2021 bInternet.waitingRequests[0] = 2022 strdup ((char *) val); 2023 res1 = 2024 InternetOpenUrl (&bInternet, 2025 bInternet.waitingRequests 2026 [0], NULL, 0, 2027 INTERNET_FLAG_NO_CACHE_WRITE, 2028 0); 2029 processDownloads (&bInternet); 2030 char *tmp = 2031 (char *) 2032 malloc ((bInternet.ihandle[0].nDataLen + 2033 1) * sizeof (char)); 2034 if (tmp == NULL) 2035 { 2036 return errorException (m, 2037 _ 2038 ("Unable to allocate memory."), 2039 "InternalError", 2040 NULL); 2041 } 2042 size_t bRead; 2043 InternetReadFile (bInternet.ihandle[0], 2044 (LPVOID) tmp, 2045 bInternet.ihandle[0]. 2046 nDataLen, &bRead); 2047 tmp[bInternet.ihandle[0].nDataLen] = 0; 2048 InternetCloseHandle (&bInternet); 2049 map *btmp = 2050 getMap (tmpmaps->content, "href"); 2051 if (btmp != NULL) 2052 { 1785 2053 #ifdef POST_DEBUG 1786 fprintf(stderr,"%s %s\n",btmp->value,tmp); 1787 #endif 1788 hInternet.waitingRequests[hInternet.nb]=strdup(tmp); 1789 res=InternetOpenUrl(&hInternet,btmp->value,hInternet.waitingRequests[hInternet.nb], 1790 strlen(hInternet.waitingRequests[hInternet.nb]), 1791 INTERNET_FLAG_NO_CACHE_WRITE,0); 1792 } 1793 free(tmp); 1794 } 1795 } 1796 cur3=cur3->next; 1797 } 2054 fprintf (stderr, "%s %s\n", btmp->value, 2055 tmp); 2056 #endif 2057 hInternet.waitingRequests[hInternet. 2058 nb] = 2059 strdup (tmp); 2060 res = 2061 InternetOpenUrl (&hInternet, 2062 btmp->value, 2063 hInternet. 2064 waitingRequests 2065 [hInternet.nb], 2066 strlen (hInternet. 2067 waitingRequests 2068 [hInternet. 2069 nb]), 2070 INTERNET_FLAG_NO_CACHE_WRITE, 2071 0); 2072 } 2073 free (tmp); 2074 } 2075 } 2076 cur3 = cur3->next; 2077 } 1798 2078 #ifdef POST_DEBUG 1799 fprintf(stderr,"Header and Body was parsed from Reference \n"); 1800 #endif 1801 #ifdef DEBUG 1802 dumpMap(tmpmaps->content); 1803 fprintf(stderr, "= element 2 node \"%s\" = (%s)\n", 1804 cur2->name,cur2->content); 1805 #endif 1806 } 1807 else if(xmlStrcasecmp(cur2->name,BAD_CAST "Data")==0){ 1808 #ifdef DEBUG 1809 fprintf(stderr,"DATA\n"); 1810 #endif 1811 xmlNodePtr cur4=cur2->children; 1812 while(cur4!=NULL){ 1813 while(cur4!=NULL &&cur4->type!=XML_ELEMENT_NODE) 1814 cur4=cur4->next; 1815 if(cur4==NULL) 1816 break; 1817 if(xmlStrcasecmp(cur4->name, BAD_CAST "LiteralData")==0){ 1818 /** 2079 fprintf (stderr, 2080 "Header and Body was parsed from Reference \n"); 2081 #endif 2082 #ifdef DEBUG 2083 dumpMap (tmpmaps->content); 2084 fprintf (stderr, "= element 2 node \"%s\" = (%s)\n", 2085 cur2->name, cur2->content); 2086 #endif 2087 } 2088 else if (xmlStrcasecmp (cur2->name, BAD_CAST "Data") == 0) 2089 { 2090 #ifdef DEBUG 2091 fprintf (stderr, "DATA\n"); 2092 #endif 2093 xmlNodePtr cur4 = cur2->children; 2094 while (cur4 != NULL) 2095 { 2096 while (cur4 != NULL 2097 && cur4->type != XML_ELEMENT_NODE) 2098 cur4 = cur4->next; 2099 if (cur4 == NULL) 2100 break; 2101 if (xmlStrcasecmp 2102 (cur4->name, BAD_CAST "LiteralData") == 0) 2103 { 2104 /** 1819 2105 * Get every attribute from a LiteralData node 1820 2106 * dataType , uom 1821 2107 */ 1822 char *list[2]; 1823 list[0]=zStrdup("dataType"); 1824 list[1]=zStrdup("uom"); 1825 for(int l=0;l<2;l++){ 1826 #ifdef DEBUG 1827 fprintf(stderr,"*** LiteralData %s ***",list[l]); 1828 #endif 1829 xmlChar *val=xmlGetProp(cur4,BAD_CAST list[l]); 1830 if(val!=NULL && strlen((char*)val)>0){ 1831 if(tmpmaps->content!=NULL) 1832 addToMap(tmpmaps->content,list[l],(char*)val); 1833 else 1834 tmpmaps->content=createMap(list[l],(char*)val); 1835 #ifdef DEBUG 1836 fprintf(stderr,"%s\n",val); 1837 #endif 1838 } 1839 xmlFree(val); 1840 free(list[l]); 1841 } 1842 } 1843 else if(xmlStrcasecmp(cur4->name, BAD_CAST "ComplexData")==0){ 1844 /** 2108 char *list[2]; 2109 list[0] = zStrdup ("dataType"); 2110 list[1] = zStrdup ("uom"); 2111 for (int l = 0; l < 2; l++) 2112 { 2113 #ifdef DEBUG 2114 fprintf (stderr, "*** LiteralData %s ***", 2115 list[l]); 2116 #endif 2117 xmlChar *val = 2118 xmlGetProp (cur4, BAD_CAST list[l]); 2119 if (val != NULL 2120 && strlen ((char *) val) > 0) 2121 { 2122 if (tmpmaps->content != NULL) 2123 addToMap (tmpmaps->content, list[l], 2124 (char *) val); 2125 else 2126 tmpmaps->content = 2127 createMap (list[l], (char *) val); 2128 #ifdef DEBUG 2129 fprintf (stderr, "%s\n", val); 2130 #endif 2131 } 2132 xmlFree (val); 2133 free (list[l]); 2134 } 2135 } 2136 else 2137 if (xmlStrcasecmp 2138 (cur4->name, BAD_CAST "ComplexData") == 0) 2139 { 2140 /** 1845 2141 * Get every attribute from a Reference node 1846 2142 * mimeType, encoding, schema 1847 2143 */ 1848 const char *coms[3]={"mimeType","encoding","schema"}; 1849 for(int l=0;l<3;l++){ 1850 #ifdef DEBUG 1851 fprintf(stderr,"*** ComplexData %s ***\n",coms[l]); 1852 #endif 1853 xmlChar *val=xmlGetProp(cur4,BAD_CAST coms[l]); 1854 if(val!=NULL && strlen((char*)val)>0){ 1855 if(tmpmaps->content!=NULL) 1856 addToMap(tmpmaps->content,coms[l],(char*)val); 1857 else 1858 tmpmaps->content=createMap(coms[l],(char*)val); 1859 #ifdef DEBUG 1860 fprintf(stderr,"%s\n",val); 1861 #endif 1862 } 1863 xmlFree(val); 1864 } 1865 } 1866 1867 map* test=getMap(tmpmaps->content,"encoding"); 1868 if(test==NULL){ 1869 if(tmpmaps->content!=NULL) 1870 addToMap(tmpmaps->content,"encoding","utf-8"); 1871 else 1872 tmpmaps->content=createMap("encoding","utf-8"); 1873 test=getMap(tmpmaps->content,"encoding"); 1874 } 1875 1876 if(strcasecmp(test->value,"base64")!=0){ 1877 xmlChar* mv=xmlNodeListGetString(doc,cur4->xmlChildrenNode,1); 1878 map* ltmp=getMap(tmpmaps->content,"mimeType"); 1879 if(mv==NULL || 1880 (xmlStrcasecmp(cur4->name, BAD_CAST "ComplexData")==0 && 1881 (ltmp==NULL || strncasecmp(ltmp->value,"text/xml",8)==0) )){ 1882 xmlDocPtr doc1=xmlNewDoc(BAD_CAST "1.0"); 1883 int buffersize; 1884 xmlNodePtr cur5=cur4->children; 1885 while(cur5!=NULL && cur5->type!=XML_ELEMENT_NODE && cur5->type!=XML_CDATA_SECTION_NODE) 1886 cur5=cur5->next; 1887 if(cur5!=NULL && cur5->type!=XML_CDATA_SECTION_NODE){ 1888 xmlDocSetRootElement(doc1,cur5); 1889 xmlDocDumpFormatMemoryEnc(doc1, &mv, &buffersize, "utf-8", 1); 1890 char size[1024]; 1891 sprintf(size,"%d",buffersize); 1892 addToMap(tmpmaps->content,"size",size); 1893 xmlFreeDoc(doc1); 1894 } 1895 } 1896 if(mv!=NULL){ 1897 addToMap(tmpmaps->content,"value",(char*)mv); 1898 xmlFree(mv); 1899 } 1900 }else{ 1901 xmlChar* tmp=xmlNodeListGetRawString(doc,cur4->xmlChildrenNode,0); 1902 addToMap(tmpmaps->content,"value",(char*)tmp); 1903 map* tmpv=getMap(tmpmaps->content,"value"); 1904 char *res=NULL; 1905 char *curs=tmpv->value; 1906 for(int i=0;i<=strlen(tmpv->value)/64;i++) { 1907 if(res==NULL) 1908 res=(char*)malloc(67*sizeof(char)); 1909 else 1910 res=(char*)realloc(res,(((i+1)*65)+i)*sizeof(char)); 1911 int csize=i*65; 1912 strncpy(res + csize,curs,64); 1913 if(i==xmlStrlen(tmp)/64) 1914 strcat(res,"\n\0"); 1915 else{ 1916 strncpy(res + (((i+1)*64)+i),"\n\0",2); 1917 curs+=64; 1918 } 1919 } 1920 free(tmpv->value); 1921 tmpv->value=zStrdup(res); 1922 free(res); 1923 xmlFree(tmp); 1924 } 1925 cur4=cur4->next; 1926 } 1927 } 1928 #ifdef DEBUG 1929 fprintf(stderr,"cur2 next \n"); 1930 fflush(stderr); 1931 #endif 1932 cur2=cur2->next; 1933 } 1934 #ifdef DEBUG 1935 fprintf(stderr,"ADD MAPS TO REQUEST MAPS !\n"); 1936 fflush(stderr); 1937 #endif 1938 1939 { 1940 maps* testPresence=getMaps(request_input_real_format,tmpmaps->name); 1941 if(testPresence!=NULL){ 1942 elements* elem=getElements(s1->inputs,tmpmaps->name); 1943 if(elem!=NULL){ 1944 if(appendMapsToMaps(m,request_input_real_format,tmpmaps,elem)<0){ 1945 freeMaps(&m); 1946 free(m); 1947 free(REQUEST); 1948 free(SERVICE_URL); 1949 InternetCloseHandle(&hInternet); 1950 freeService(&s1); 1951 free(s1); 1952 return 0; 1953 } 1954 } 1955 } 1956 else 1957 addMapsToMaps(&request_input_real_format,tmpmaps); 1958 } 1959 1960 #ifdef DEBUG 1961 fprintf(stderr,"******TMPMAPS*****\n"); 1962 dumpMaps(tmpmaps); 1963 fprintf(stderr,"******REQUESTMAPS*****\n"); 1964 dumpMaps(request_input_real_format); 1965 #endif 1966 freeMaps(&tmpmaps); 1967 free(tmpmaps); 1968 tmpmaps=NULL; 1969 } 1970 #ifdef DEBUG 1971 dumpMaps(tmpmaps); 1972 #endif 1973 } 1974 #ifdef DEBUG 1975 fprintf(stderr,"Search for response document node\n"); 1976 #endif 1977 xmlXPathFreeObject(tmpsptr); 1978 1979 tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='ResponseDocument']"); 1980 bool asRaw=false; 1981 tmps=tmpsptr->nodesetval; 1982 if(tmps->nodeNr==0){ 1983 tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='RawDataOutput']"); 1984 tmps=tmpsptr->nodesetval; 1985 asRaw=true; 1986 } 1987 #ifdef DEBUG 1988 fprintf(stderr,"*****%d*****\n",tmps->nodeNr); 1989 #endif 1990 if(asRaw==true){ 1991 addToMap(request_inputs,"RawDataOutput",""); 1992 xmlNodePtr cur0=tmps->nodeTab[0]; 1993 if(cur0->type == XML_ELEMENT_NODE) { 1994 1995 maps* tmpmaps=(maps*)malloc(MAPS_SIZE); 1996 if(tmpmaps == NULL){ 1997 return errorException(m, _("Unable to allocate memory."), "InternalError",NULL); 1998 } 1999 tmpmaps->name=zStrdup("unknownIdentifier"); 2000 tmpmaps->content=NULL; 2001 tmpmaps->next=NULL; 2002 2003 /** 2144 const char *coms[3] = 2145 { "mimeType", "encoding", "schema" }; 2146 for (int l = 0; l < 3; l++) 2147 { 2148 #ifdef DEBUG 2149 fprintf (stderr, "*** ComplexData %s ***\n", 2150 coms[l]); 2151 #endif 2152 xmlChar *val = 2153 xmlGetProp (cur4, BAD_CAST coms[l]); 2154 if (val != NULL 2155 && strlen ((char *) val) > 0) 2156 { 2157 if (tmpmaps->content != NULL) 2158 addToMap (tmpmaps->content, coms[l], 2159 (char *) val); 2160 else 2161 tmpmaps->content = 2162 createMap (coms[l], (char *) val); 2163 #ifdef DEBUG 2164 fprintf (stderr, "%s\n", val); 2165 #endif 2166 } 2167 xmlFree (val); 2168 } 2169 } 2170 2171 map *test = getMap (tmpmaps->content, "encoding"); 2172 if (test == NULL) 2173 { 2174 if (tmpmaps->content != NULL) 2175 addToMap (tmpmaps->content, "encoding", 2176 "utf-8"); 2177 else 2178 tmpmaps->content = 2179 createMap ("encoding", "utf-8"); 2180 test = getMap (tmpmaps->content, "encoding"); 2181 } 2182 2183 if (strcasecmp (test->value, "base64") != 0) 2184 { 2185 xmlChar *mv = xmlNodeListGetString (doc, 2186 cur4->xmlChildrenNode, 2187 1); 2188 map *ltmp = 2189 getMap (tmpmaps->content, "mimeType"); 2190 if (mv == NULL 2191 || 2192 (xmlStrcasecmp 2193 (cur4->name, BAD_CAST "ComplexData") == 0 2194 && (ltmp == NULL 2195 || strncasecmp (ltmp->value, 2196 "text/xml", 8) == 0))) 2197 { 2198 xmlDocPtr doc1 = xmlNewDoc (BAD_CAST "1.0"); 2199 int buffersize; 2200 xmlNodePtr cur5 = cur4->children; 2201 while (cur5 != NULL 2202 && cur5->type != XML_ELEMENT_NODE 2203 && cur5->type != 2204 XML_CDATA_SECTION_NODE) 2205 cur5 = cur5->next; 2206 if (cur5 != NULL 2207 && cur5->type != XML_CDATA_SECTION_NODE) 2208 { 2209 xmlDocSetRootElement (doc1, cur5); 2210 xmlDocDumpFormatMemoryEnc (doc1, &mv, 2211 &buffersize, 2212 "utf-8", 1); 2213 char size[1024]; 2214 sprintf (size, "%d", buffersize); 2215 addToMap (tmpmaps->content, "size", 2216 size); 2217 xmlFreeDoc (doc1); 2218 } 2219 } 2220 if (mv != NULL) 2221 { 2222 addToMap (tmpmaps->content, "value", 2223 (char *) mv); 2224 xmlFree (mv); 2225 } 2226 } 2227 else 2228 { 2229 xmlChar *tmp = xmlNodeListGetRawString (doc, 2230 cur4-> 2231 xmlChildrenNode, 2232 0); 2233 addToMap (tmpmaps->content, "value", 2234 (char *) tmp); 2235 map *tmpv = getMap (tmpmaps->content, "value"); 2236 char *res = NULL; 2237 char *curs = tmpv->value; 2238 for (int i = 0; i <= strlen (tmpv->value) / 64; 2239 i++) 2240 { 2241 if (res == NULL) 2242 res = 2243 (char *) malloc (67 * sizeof (char)); 2244 else 2245 res = 2246 (char *) realloc (res, 2247 (((i + 1) * 65) + 2248 i) * sizeof (char)); 2249 int csize = i * 65; 2250 strncpy (res + csize, curs, 64); 2251 if (i == xmlStrlen (tmp) / 64) 2252 strcat (res, "\n\0"); 2253 else 2254 { 2255 strncpy (res + (((i + 1) * 64) + i), 2256 "\n\0", 2); 2257 curs += 64; 2258 } 2259 } 2260 free (tmpv->value); 2261 tmpv->value = zStrdup (res); 2262 free (res); 2263 xmlFree (tmp); 2264 } 2265 cur4 = cur4->next; 2266 } 2267 } 2268 #ifdef DEBUG 2269 fprintf (stderr, "cur2 next \n"); 2270 fflush (stderr); 2271 #endif 2272 cur2 = cur2->next; 2273 } 2274 #ifdef DEBUG 2275 fprintf (stderr, "ADD MAPS TO REQUEST MAPS !\n"); 2276 fflush (stderr); 2277 #endif 2278 2279 { 2280 maps *testPresence = 2281 getMaps (request_input_real_format, tmpmaps->name); 2282 if (testPresence != NULL) 2283 { 2284 elements *elem = getElements (s1->inputs, tmpmaps->name); 2285 if (elem != NULL) 2286 { 2287 if (appendMapsToMaps 2288 (m, request_input_real_format, tmpmaps, elem) < 0) 2289 { 2290 freeMaps (&m); 2291 free (m); 2292 free (REQUEST); 2293 free (SERVICE_URL); 2294 InternetCloseHandle (&hInternet); 2295 freeService (&s1); 2296 free (s1); 2297 return 0; 2298 } 2299 } 2300 } 2301 else 2302 addMapsToMaps (&request_input_real_format, tmpmaps); 2303 } 2304 2305 #ifdef DEBUG 2306 fprintf (stderr, "******TMPMAPS*****\n"); 2307 dumpMaps (tmpmaps); 2308 fprintf (stderr, "******REQUESTMAPS*****\n"); 2309 dumpMaps (request_input_real_format); 2310 #endif 2311 freeMaps (&tmpmaps); 2312 free (tmpmaps); 2313 tmpmaps = NULL; 2314 } 2315 #ifdef DEBUG 2316 dumpMaps (tmpmaps); 2317 #endif 2318 } 2319 #ifdef DEBUG 2320 fprintf (stderr, "Search for response document node\n"); 2321 #endif 2322 xmlXPathFreeObject (tmpsptr); 2323 2324 tmpsptr = 2325 extractFromDoc (doc, "/*/*/*[local-name()='ResponseDocument']"); 2326 bool asRaw = false; 2327 tmps = tmpsptr->nodesetval; 2328 if (tmps->nodeNr == 0) 2329 { 2330 tmpsptr = 2331 extractFromDoc (doc, "/*/*/*[local-name()='RawDataOutput']"); 2332 tmps = tmpsptr->nodesetval; 2333 asRaw = true; 2334 } 2335 #ifdef DEBUG 2336 fprintf (stderr, "*****%d*****\n", tmps->nodeNr); 2337 #endif 2338 if (asRaw == true) 2339 { 2340 addToMap (request_inputs, "RawDataOutput", ""); 2341 xmlNodePtr cur0 = tmps->nodeTab[0]; 2342 if (cur0->type == XML_ELEMENT_NODE) 2343 { 2344 2345 maps *tmpmaps = (maps *) malloc (MAPS_SIZE); 2346 if (tmpmaps == NULL) 2347 { 2348 return errorException (m, _("Unable to allocate memory."), 2349 "InternalError", NULL); 2350 } 2351 tmpmaps->name = zStrdup ("unknownIdentifier"); 2352 tmpmaps->content = NULL; 2353 tmpmaps->next = NULL; 2354 2355 /** 2004 2356 * Get every attribute from a RawDataOutput node 2005 2357 * mimeType, encoding, schema, uom 2006 2358 */ 2007 const char *outs[4]={"mimeType","encoding","schema","uom"}; 2008 for(int l=0;l<4;l++){ 2009 #ifdef DEBUG 2010 fprintf(stderr,"*** %s ***\t",outs[l]); 2011 #endif 2012 xmlChar *val=xmlGetProp(cur0,BAD_CAST outs[l]); 2013 if(val!=NULL){ 2014 if(strlen((char*)val)>0){ 2015 if(tmpmaps->content!=NULL) 2016 addToMap(tmpmaps->content,outs[l],(char*)val); 2017 else 2018 tmpmaps->content=createMap(outs[l],(char*)val); 2019 } 2020 xmlFree(val); 2021 } 2022 } 2023 xmlNodePtr cur2=cur0->children; 2024 while(cur2!=NULL && cur2->type != XML_ELEMENT_NODE) 2025 cur2=cur2->next; 2026 int cur1cnt=0; 2027 while(cur2!=NULL){ 2028 if(xmlStrncasecmp(cur2->name,BAD_CAST "Identifier",xmlStrlen(cur2->name))==0){ 2029 xmlChar *val= 2030 xmlNodeListGetString(NULL,cur2->xmlChildrenNode,1); 2031 free(tmpmaps->name); 2032 tmpmaps->name=zStrdup((char*)val); 2033 } 2034 cur2=cur2->next; 2035 while(cur2!=NULL && cur2->type != XML_ELEMENT_NODE) 2036 cur2=cur2->next; 2037 } 2038 if(request_output_real_format==NULL) 2039 request_output_real_format=dupMaps(&tmpmaps); 2040 else 2041 addMapsToMaps(&request_output_real_format,tmpmaps); 2042 if(tmpmaps!=NULL){ 2043 freeMaps(&tmpmaps); 2044 free(tmpmaps); 2045 tmpmaps=NULL; 2046 } 2047 } 2048 } 2049 else 2050 for(int k=0;k<tmps->nodeNr;k++){ 2051 //else 2052 addToMap(request_inputs,"ResponseDocument",""); 2053 maps *tmpmaps=NULL; 2054 xmlNodePtr cur=tmps->nodeTab[k]; 2055 if(cur->type == XML_ELEMENT_NODE) { 2056 /** 2359 const char *outs[4] = 2360 { "mimeType", "encoding", "schema", "uom" }; 2361 for (int l = 0; l < 4; l++) 2362 { 2363 #ifdef DEBUG 2364 fprintf (stderr, "*** %s ***\t", outs[l]); 2365 #endif 2366 xmlChar *val = xmlGetProp (cur0, BAD_CAST outs[l]); 2367 if (val != NULL) 2368 { 2369 if (strlen ((char *) val) > 0) 2370 { 2371 if (tmpmaps->content != NULL) 2372 addToMap (tmpmaps->content, outs[l], 2373 (char *) val); 2374 else 2375 tmpmaps->content = 2376 createMap (outs[l], (char *) val); 2377 } 2378 xmlFree (val); 2379 } 2380 } 2381 xmlNodePtr cur2 = cur0->children; 2382 while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE) 2383 cur2 = cur2->next; 2384 int cur1cnt = 0; 2385 while (cur2 != NULL) 2386 { 2387 if (xmlStrncasecmp 2388 (cur2->name, BAD_CAST "Identifier", 2389 xmlStrlen (cur2->name)) == 0) 2390 { 2391 xmlChar *val = 2392 xmlNodeListGetString (NULL, cur2->xmlChildrenNode, 1); 2393 free (tmpmaps->name); 2394 tmpmaps->name = zStrdup ((char *) val); 2395 } 2396 cur2 = cur2->next; 2397 while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE) 2398 cur2 = cur2->next; 2399 } 2400 if (request_output_real_format == NULL) 2401 request_output_real_format = dupMaps (&tmpmaps); 2402 else 2403 addMapsToMaps (&request_output_real_format, tmpmaps); 2404 if (tmpmaps != NULL) 2405 { 2406 freeMaps (&tmpmaps); 2407 free (tmpmaps); 2408 tmpmaps = NULL; 2409 } 2410 } 2411 } 2412 else 2413 for (int k = 0; k < tmps->nodeNr; k++) 2414 { 2415 //else 2416 addToMap (request_inputs, "ResponseDocument", ""); 2417 maps *tmpmaps = NULL; 2418 xmlNodePtr cur = tmps->nodeTab[k]; 2419 if (cur->type == XML_ELEMENT_NODE) 2420 { 2421 /** 2057 2422 * A specific responseDocument node. 2058 2423 */ 2059 if(tmpmaps==NULL){ 2060 tmpmaps=(maps*)malloc(MAPS_SIZE); 2061 if(tmpmaps == NULL){ 2062 return errorException(m, _("Unable to allocate memory."), "InternalError",NULL); 2063 } 2064 tmpmaps->name=zStrdup("unknownIdentifier"); 2065 tmpmaps->content=NULL; 2066 tmpmaps->next=NULL; 2067 } 2068 /** 2424 if (tmpmaps == NULL) 2425 { 2426 tmpmaps = (maps *) malloc (MAPS_SIZE); 2427 if (tmpmaps == NULL) 2428 { 2429 return errorException (m, 2430 _ 2431 ("Unable to allocate memory."), 2432 "InternalError", NULL); 2433 } 2434 tmpmaps->name = zStrdup ("unknownIdentifier"); 2435 tmpmaps->content = NULL; 2436 tmpmaps->next = NULL; 2437 } 2438 /** 2069 2439 * Get every attribute: storeExecuteResponse, lineage, status 2070 2440 */ 2071 const char *ress[3]={"storeExecuteResponse","lineage","status"}; 2072 xmlChar *val; 2073 for(int l=0;l<3;l++){ 2074 #ifdef DEBUG 2075 fprintf(stderr,"*** %s ***\t",ress[l]); 2076 #endif 2077 val=xmlGetProp(cur,BAD_CAST ress[l]); 2078 if(val!=NULL && strlen((char*)val)>0){ 2079 if(tmpmaps->content!=NULL) 2080 addToMap(tmpmaps->content,ress[l],(char*)val); 2081 else 2082 tmpmaps->content=createMap(ress[l],(char*)val); 2083 addToMap(request_inputs,ress[l],(char*)val); 2084 } 2085 #ifdef DEBUG 2086 fprintf(stderr,"%s\n",val); 2087 #endif 2088 xmlFree(val); 2089 } 2090 xmlNodePtr cur1=cur->children; 2091 while(cur1!=NULL && cur1->type != XML_ELEMENT_NODE) 2092 cur1=cur1->next; 2093 int cur1cnt=0; 2094 while(cur1){ 2095 /** 2441 const char *ress[3] = 2442 { "storeExecuteResponse", "lineage", "status" }; 2443 xmlChar *val; 2444 for (int l = 0; l < 3; l++) 2445 { 2446 #ifdef DEBUG 2447 fprintf (stderr, "*** %s ***\t", ress[l]); 2448 #endif 2449 val = xmlGetProp (cur, BAD_CAST ress[l]); 2450 if (val != NULL && strlen ((char *) val) > 0) 2451 { 2452 if (tmpmaps->content != NULL) 2453 addToMap (tmpmaps->content, ress[l], (char *) val); 2454 else 2455 tmpmaps->content = 2456 createMap (ress[l], (char *) val); 2457 addToMap (request_inputs, ress[l], (char *) val); 2458 } 2459 #ifdef DEBUG 2460 fprintf (stderr, "%s\n", val); 2461 #endif 2462 xmlFree (val); 2463 } 2464 xmlNodePtr cur1 = cur->children; 2465 while (cur1 != NULL && cur1->type != XML_ELEMENT_NODE) 2466 cur1 = cur1->next; 2467 int cur1cnt = 0; 2468 while (cur1) 2469 { 2470 /** 2096 2471 * Indentifier 2097 2472 */ 2098 if(xmlStrncasecmp(cur1->name,BAD_CAST "Identifier",xmlStrlen(cur1->name))==0){ 2099 xmlChar *val= 2100 xmlNodeListGetString(doc,cur1->xmlChildrenNode,1); 2101 if(tmpmaps==NULL){ 2102 tmpmaps=(maps*)malloc(MAPS_SIZE); 2103 if(tmpmaps == NULL){ 2104 return errorException(m, _("Unable to allocate memory."), "InternalError",NULL); 2105 } 2106 tmpmaps->name=zStrdup((char*)val); 2107 tmpmaps->content=NULL; 2108 tmpmaps->next=NULL; 2109 } 2110 else{ 2111 free(tmpmaps->name); 2112 tmpmaps->name=zStrdup((char*)val); 2113 } 2114 if(asRaw==true) 2115 addToMap(request_inputs,"RawDataOutput",(char*)val); 2116 else{ 2117 if(cur1cnt==0) 2118 addToMap(request_inputs,"ResponseDocument",(char*)val); 2119 else{ 2120 map* tt=getMap(request_inputs,"ResponseDocument"); 2121 char* tmp=zStrdup(tt->value); 2122 free(tt->value); 2123 tt->value=(char*)malloc((strlen(tmp)+strlen((char*)val)+1)*sizeof(char)); 2124 sprintf(tt->value,"%s;%s",tmp,(char*)val); 2125 free(tmp); 2126 } 2127 } 2128 cur1cnt+=1; 2129 xmlFree(val); 2130 } 2131 /** 2473 if (xmlStrncasecmp 2474 (cur1->name, BAD_CAST "Identifier", 2475 xmlStrlen (cur1->name)) == 0) 2476 { 2477 xmlChar *val = 2478 xmlNodeListGetString (doc, cur1->xmlChildrenNode, 2479 1); 2480 if (tmpmaps == NULL) 2481 { 2482 tmpmaps = (maps *) malloc (MAPS_SIZE); 2483 if (tmpmaps == NULL) 2484 { 2485 return errorException (m, 2486 _ 2487 ("Unable to allocate memory."), 2488 "InternalError", NULL); 2489 } 2490 tmpmaps->name = zStrdup ((char *) val); 2491 tmpmaps->content = NULL; 2492 tmpmaps->next = NULL; 2493 } 2494 else 2495 { 2496 free (tmpmaps->name); 2497 tmpmaps->name = zStrdup ((char *) val); 2498 } 2499 if (asRaw == true) 2500 addToMap (request_inputs, "RawDataOutput", 2501 (char *) val); 2502 else 2503 { 2504 if (cur1cnt == 0) 2505 addToMap (request_inputs, "ResponseDocument", 2506 (char *) val); 2507 else 2508 { 2509 map *tt = 2510 getMap (request_inputs, "ResponseDocument"); 2511 char *tmp = zStrdup (tt->value); 2512 free (tt->value); 2513 tt->value = 2514 (char *) 2515 malloc ((strlen (tmp) + 2516 strlen ((char *) val) + 2517 1) * sizeof (char)); 2518 sprintf (tt->value, "%s;%s", tmp, 2519 (char *) val); 2520 free (tmp); 2521 } 2522 } 2523 cur1cnt += 1; 2524 xmlFree (val); 2525 } 2526 /** 2132 2527 * Title, Asbtract 2133 2528 */ 2134 else if(xmlStrncasecmp(cur1->name,BAD_CAST "Title",xmlStrlen(cur1->name))==0 || 2135 xmlStrncasecmp(cur1->name,BAD_CAST "Abstract",xmlStrlen(cur1->name))==0){ 2136 xmlChar *val= 2137 xmlNodeListGetString(doc,cur1->xmlChildrenNode,1); 2138 if(tmpmaps==NULL){ 2139 tmpmaps=(maps*)malloc(MAPS_SIZE); 2140 if(tmpmaps == NULL){ 2141 return errorException(m, _("Unable to allocate memory."), "InternalError",NULL); 2142 } 2143 tmpmaps->name=zStrdup("missingIndetifier"); 2144 tmpmaps->content=createMap((char*)cur1->name,(char*)val); 2145 tmpmaps->next=NULL; 2146 } 2147 else{ 2148 if(tmpmaps->content!=NULL) 2149 addToMap(tmpmaps->content,(char*)cur1->name,(char*)val); 2150 else 2151 tmpmaps->content=createMap((char*)cur1->name,(char*)val); 2152 } 2153 xmlFree(val); 2154 } 2155 else if(xmlStrncasecmp(cur1->name,BAD_CAST "Output",xmlStrlen(cur1->name))==0){ 2156 /** 2529 else 2530 if (xmlStrncasecmp 2531 (cur1->name, BAD_CAST "Title", 2532 xmlStrlen (cur1->name)) == 0 2533 || xmlStrncasecmp (cur1->name, BAD_CAST "Abstract", 2534 xmlStrlen (cur1->name)) == 0) 2535 { 2536 xmlChar *val = 2537 xmlNodeListGetString (doc, cur1->xmlChildrenNode, 2538 1); 2539 if (tmpmaps == NULL) 2540 { 2541 tmpmaps = (maps *) malloc (MAPS_SIZE); 2542 if (tmpmaps == NULL) 2543 { 2544 return errorException (m, 2545 _ 2546 ("Unable to allocate memory."), 2547 "InternalError", NULL); 2548 } 2549 tmpmaps->name = zStrdup ("missingIndetifier"); 2550 tmpmaps->content = 2551 createMap ((char *) cur1->name, (char *) val); 2552 tmpmaps->next = NULL; 2553 } 2554 else 2555 { 2556 if (tmpmaps->content != NULL) 2557 addToMap (tmpmaps->content, (char *) cur1->name, 2558 (char *) val); 2559 else 2560 tmpmaps->content = 2561 createMap ((char *) cur1->name, (char *) val); 2562 } 2563 xmlFree (val); 2564 } 2565 else 2566 if (xmlStrncasecmp 2567 (cur1->name, BAD_CAST "Output", 2568 xmlStrlen (cur1->name)) == 0) 2569 { 2570 /** 2157 2571 * Get every attribute from a Output node 2158 2572 * mimeType, encoding, schema, uom, asReference 2159 2573 */ 2160 const char *outs[5]={"mimeType","encoding","schema","uom","asReference"}; 2161 for(int l=0;l<5;l++){ 2162 #ifdef DEBUG 2163 fprintf(stderr,"*** %s ***\t",outs[l]); 2164 #endif 2165 xmlChar *val=xmlGetProp(cur1,BAD_CAST outs[l]); 2166 if(val!=NULL && strlen((char*)val)>0){ 2167 if(tmpmaps->content!=NULL) 2168 addToMap(tmpmaps->content,outs[l],(char*)val); 2169 else 2170 tmpmaps->content=createMap(outs[l],(char*)val); 2171 } 2172 #ifdef DEBUG 2173 fprintf(stderr,"%s\n",val); 2174 #endif 2175 xmlFree(val); 2176 } 2177 xmlNodePtr cur2=cur1->children; 2178 while(cur2!=NULL && cur2->type != XML_ELEMENT_NODE) 2179 cur2=cur2->next; 2180 while(cur2){ 2181 /** 2574 const char *outs[5] = 2575 { "mimeType", "encoding", "schema", "uom", 2576 "asReference" 2577 }; 2578 for (int l = 0; l < 5; l++) 2579 { 2580 #ifdef DEBUG 2581 fprintf (stderr, "*** %s ***\t", outs[l]); 2582 #endif 2583 xmlChar *val = 2584 xmlGetProp (cur1, BAD_CAST outs[l]); 2585 if (val != NULL && strlen ((char *) val) > 0) 2586 { 2587 if (tmpmaps->content != NULL) 2588 addToMap (tmpmaps->content, outs[l], 2589 (char *) val); 2590 else 2591 tmpmaps->content = 2592 createMap (outs[l], (char *) val); 2593 } 2594 #ifdef DEBUG 2595 fprintf (stderr, "%s\n", val); 2596 #endif 2597 xmlFree (val); 2598 } 2599 xmlNodePtr cur2 = cur1->children; 2600 while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE) 2601 cur2 = cur2->next; 2602 while (cur2) 2603 { 2604 /** 2182 2605 * Indentifier 2183 2606 */ 2184 if(xmlStrncasecmp(cur2->name,BAD_CAST "Identifier",xmlStrlen(cur2->name))==0){ 2185 xmlChar *val= 2186 xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); 2187 if(tmpmaps==NULL){ 2188 tmpmaps=(maps*)malloc(MAPS_SIZE); 2189 if(tmpmaps == NULL){ 2190 return errorException(m, _("Unable to allocate memory."), "InternalError",NULL); 2191 } 2192 tmpmaps->name=zStrdup((char*)val); 2193 tmpmaps->content=NULL; 2194 tmpmaps->next=NULL; 2195 } 2196 else{ 2197 if(tmpmaps->name!=NULL) 2198 free(tmpmaps->name); 2199 tmpmaps->name=zStrdup((char*)val);; 2200 } 2201 xmlFree(val); 2202 } 2203 /** 2607 if (xmlStrncasecmp 2608 (cur2->name, BAD_CAST "Identifier", 2609 xmlStrlen (cur2->name)) == 0) 2610 { 2611 xmlChar *val = xmlNodeListGetString (doc, 2612 cur2->xmlChildrenNode, 2613 1); 2614 if (tmpmaps == NULL) 2615 { 2616 tmpmaps = (maps *) malloc (MAPS_SIZE); 2617 if (tmpmaps == NULL) 2618 { 2619 return errorException (m, 2620 _ 2621 ("Unable to allocate memory."), 2622 "InternalError", 2623 NULL); 2624 } 2625 tmpmaps->name = zStrdup ((char *) val); 2626 tmpmaps->content = NULL; 2627 tmpmaps->next = NULL; 2628 } 2629 else 2630 { 2631 if (tmpmaps->name != NULL) 2632 free (tmpmaps->name); 2633 tmpmaps->name = zStrdup ((char *) val);; 2634 } 2635 xmlFree (val); 2636 } 2637 /** 2204 2638 * Title, Asbtract 2205 2639 */ 2206 else if(xmlStrncasecmp(cur2->name,BAD_CAST "Title",xmlStrlen(cur2->name))==0 || 2207 xmlStrncasecmp(cur2->name,BAD_CAST "Abstract",xmlStrlen(cur2->name))==0){ 2208 xmlChar *val= 2209 xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); 2210 if(tmpmaps==NULL){ 2211 tmpmaps=(maps*)malloc(MAPS_SIZE); 2212 if(tmpmaps == NULL){ 2213 return errorException(m, _("Unable to allocate memory."), "InternalError",NULL); 2214 } 2215 tmpmaps->name=zStrdup("missingIndetifier"); 2216 tmpmaps->content=createMap((char*)cur2->name,(char*)val); 2217 tmpmaps->next=NULL; 2218 } 2219 else{ 2220 if(tmpmaps->content!=NULL) 2221 addToMap(tmpmaps->content, 2222 (char*)cur2->name,(char*)val); 2223 else 2224 tmpmaps->content= 2225 createMap((char*)cur2->name,(char*)val); 2226 } 2227 xmlFree(val); 2228 } 2229 cur2=cur2->next; 2230 while(cur2!=NULL && cur2->type != XML_ELEMENT_NODE) 2231 cur2=cur2->next; 2232 } 2233 } 2234 cur1=cur1->next; 2235 while(cur1!=NULL && cur1->type != XML_ELEMENT_NODE) 2236 cur1=cur1->next; 2237 } 2238 } 2239 if(request_output_real_format==NULL) 2240 request_output_real_format=dupMaps(&tmpmaps); 2241 else 2242 addMapsToMaps(&request_output_real_format,tmpmaps); 2243 if(tmpmaps!=NULL){ 2244 freeMaps(&tmpmaps); 2245 free(tmpmaps); 2246 tmpmaps=NULL; 2247 } 2248 } 2249 xmlXPathFreeObject(tmpsptr); 2250 xmlFreeDoc(doc); 2251 xmlCleanupParser(); 2252 } 2253 2254 runHttpRequests(&m,&request_input_real_format,&hInternet); 2640 else 2641 if (xmlStrncasecmp 2642 (cur2->name, BAD_CAST "Title", 2643 xmlStrlen (cur2->name)) == 0 2644 || xmlStrncasecmp (cur2->name, 2645 BAD_CAST "Abstract", 2646 xmlStrlen (cur2->name)) 2647 == 0) 2648 { 2649 xmlChar *val = xmlNodeListGetString (doc, 2650 cur2->xmlChildrenNode, 2651 1); 2652 if (tmpmaps == NULL) 2653 { 2654 tmpmaps = (maps *) malloc (MAPS_SIZE); 2655 if (tmpmaps == NULL) 2656 { 2657 return errorException (m, 2658 _ 2659 ("Unable to allocate memory."), 2660 "InternalError", 2661 NULL); 2662 } 2663 tmpmaps->name = 2664 zStrdup ("missingIndetifier"); 2665 tmpmaps->content = 2666 createMap ((char *) cur2->name, 2667 (char *) val); 2668 tmpmaps->next = NULL; 2669 } 2670 else 2671 { 2672 if (tmpmaps->content != NULL) 2673 addToMap (tmpmaps->content, 2674 (char *) cur2->name, 2675 (char *) val); 2676 else 2677 tmpmaps->content = 2678 createMap ((char *) cur2->name, 2679 (char *) val); 2680 } 2681 xmlFree (val); 2682 } 2683 cur2 = cur2->next; 2684 while (cur2 != NULL 2685 && cur2->type != XML_ELEMENT_NODE) 2686 cur2 = cur2->next; 2687 } 2688 } 2689 cur1 = cur1->next; 2690 while (cur1 != NULL && cur1->type != XML_ELEMENT_NODE) 2691 cur1 = cur1->next; 2692 } 2693 } 2694 if (request_output_real_format == NULL) 2695 request_output_real_format = dupMaps (&tmpmaps); 2696 else 2697 addMapsToMaps (&request_output_real_format, tmpmaps); 2698 if (tmpmaps != NULL) 2699 { 2700 freeMaps (&tmpmaps); 2701 free (tmpmaps); 2702 tmpmaps = NULL; 2703 } 2704 } 2705 xmlXPathFreeObject (tmpsptr); 2706 xmlFreeDoc (doc); 2707 xmlCleanupParser (); 2708 } 2709 2710 runHttpRequests (&m, &request_input_real_format, &hInternet); 2255 2711 2256 2712 // if(CHECK_INET_HANDLE(hInternet)) 2257 InternetCloseHandle (&hInternet);2258 2259 #ifdef DEBUG 2260 fprintf (stderr,"\n%d\n",__LINE__);2261 fflush (stderr);2262 dumpMaps (request_input_real_format);2263 dumpMaps (request_output_real_format);2264 dumpMap (request_inputs);2265 fprintf (stderr,"\n%d\n",__LINE__);2266 fflush (stderr);2713 InternetCloseHandle (&hInternet); 2714 2715 #ifdef DEBUG 2716 fprintf (stderr, "\n%d\n", __LINE__); 2717 fflush (stderr); 2718 dumpMaps (request_input_real_format); 2719 dumpMaps (request_output_real_format); 2720 dumpMap (request_inputs); 2721 fprintf (stderr, "\n%d\n", __LINE__); 2722 fflush (stderr); 2267 2723 #endif 2268 2724 … … 2271 2727 * DataInputs and ResponseDocument / RawDataOutput 2272 2728 */ 2273 char *dfv=addDefaultValues(&request_input_real_format,s1->inputs,m,0); 2274 maps *ptr=request_input_real_format; 2275 while(ptr!=NULL){ 2276 map *tmp0=getMap(ptr->content,"size"); 2277 map *tmp1=getMap(ptr->content,"maximumMegabytes"); 2278 if(tmp1!=NULL && tmp0!=NULL){ 2279 float i=atof(tmp0->value)/1048576.0; 2280 if(i>=atoi(tmp1->value)){ 2281 char tmps[1024]; 2282 map* tmpe=createMap("code","FileSizeExceeded"); 2283 snprintf(tmps,1024,_("The <%s> parameter has a limited size (%sMB) defined in ZOO ServicesProvider configuration file but the reference you provided exceed this limitation (%fMB), please correct your query or the ZOO Configuration file."),ptr->name,tmp1->value,i); 2284 addToMap(tmpe,"locator",ptr->name); 2285 addToMap(tmpe,"text",tmps); 2286 printExceptionReportResponse(m,tmpe); 2287 freeService(&s1); 2288 free(s1); 2289 freeMap(&tmpe); 2290 free(tmpe); 2291 freeMaps(&m); 2292 free(m); 2293 free(REQUEST); 2294 free(SERVICE_URL); 2295 freeMaps(&request_input_real_format); 2296 free(request_input_real_format); 2297 freeMaps(&request_output_real_format); 2298 free(request_output_real_format); 2299 freeMaps(&tmpmaps); 2300 free(tmpmaps); 2301 return 1; 2302 } 2303 } 2304 ptr=ptr->next; 2305 } 2306 2307 char *dfv1=addDefaultValues(&request_output_real_format,s1->outputs,m,1); 2308 if(strcmp(dfv1,"")!=0 || strcmp(dfv,"")!=0){ 2309 char tmps[1024]; 2310 map* tmpe=createMap("code","MissingParameterValue"); 2311 if(strcmp(dfv,"")!=0){ 2312 snprintf(tmps,1024,_("The <%s> argument was not specified in DataInputs but defined as requested in ZOO ServicesProvider configuration file, please correct your query or the ZOO Configuration file."),dfv); 2313 addToMap(tmpe,"locator",dfv); 2314 } 2315 else if(strcmp(dfv1,"")!=0){ 2316 snprintf(tmps,1024,_("The <%s> argument was specified as Output identifier but not defined in the ZOO Configuration File. Please, correct your query or the ZOO Configuration File."),dfv1); 2317 addToMap(tmpe,"locator",dfv1); 2318 } 2319 addToMap(tmpe,"text",tmps); 2320 printExceptionReportResponse(m,tmpe); 2321 freeService(&s1); 2322 free(s1); 2323 freeMap(&tmpe); 2324 free(tmpe); 2325 freeMaps(&m); 2326 free(m); 2327 free(REQUEST); 2328 free(SERVICE_URL); 2329 freeMaps(&request_input_real_format); 2330 free(request_input_real_format); 2331 freeMaps(&request_output_real_format); 2332 free(request_output_real_format); 2333 freeMaps(&tmpmaps); 2334 free(tmpmaps); 2335 return 1; 2336 } 2337 maps* tmpReqI=request_input_real_format; 2338 while(tmpReqI!=NULL){ 2339 char name[1024]; 2340 if(getMap(tmpReqI->content,"isFile")!=NULL){ 2341 if (cgiFormFileName(tmpReqI->name, name, sizeof(name)) == cgiFormSuccess) { 2342 int BufferLen=1024; 2343 cgiFilePtr file; 2344 int targetFile; 2345 char storageNameOnServer[2048]; 2346 char fileNameOnServer[64]; 2347 char contentType[1024]; 2348 char buffer[1024]; 2349 char *tmpStr=NULL; 2350 int size; 2351 int got,t; 2352 map *path=getMapFromMaps(m,"main","tmpPath"); 2353 cgiFormFileSize(tmpReqI->name, &size); 2354 cgiFormFileContentType(tmpReqI->name, contentType, sizeof(contentType)); 2355 if (cgiFormFileOpen(tmpReqI->name, &file) == cgiFormSuccess) { 2356 t=-1; 2357 while(1){ 2358 tmpStr=strstr(name+t+1,"\\"); 2359 if(NULL==tmpStr) 2360 tmpStr=strstr(name+t+1,"/"); 2361 if(NULL!=tmpStr) 2362 t=(int)(tmpStr-name); 2363 else 2364 break; 2365 } 2366 strcpy(fileNameOnServer,name+t+1); 2367 2368 sprintf(storageNameOnServer,"%s/%s",path->value,fileNameOnServer); 2369 #ifdef DEBUG 2370 fprintf(stderr,"Name on server %s\n",storageNameOnServer); 2371 fprintf(stderr,"fileNameOnServer: %s\n",fileNameOnServer); 2372 #endif 2373 targetFile = open (storageNameOnServer,O_RDWR|O_CREAT|O_TRUNC,S_IRWXU|S_IRGRP|S_IROTH); 2374 if(targetFile<0){ 2375 #ifdef DEBUG 2376 fprintf(stderr,"could not create the new file,%s\n",fileNameOnServer); 2377 #endif 2378 }else{ 2379 while (cgiFormFileRead(file, buffer, BufferLen, &got) ==cgiFormSuccess){ 2380 if(got>0) 2381 write(targetFile,buffer,got); 2382 } 2383 } 2384 addToMap(tmpReqI->content,"lref",storageNameOnServer); 2385 cgiFormFileClose(file); 2386 close(targetFile); 2387 #ifdef DEBUG 2388 fprintf(stderr,"File \"%s\" has been uploaded",fileNameOnServer); 2389 #endif 2390 } 2391 } 2392 } 2393 tmpReqI=tmpReqI->next; 2394 } 2395 2396 ensureDecodedBase64(&request_input_real_format); 2397 2398 #ifdef DEBUG 2399 fprintf(stderr,"REQUEST_INPUTS\n"); 2400 dumpMaps(request_input_real_format); 2401 fprintf(stderr,"REQUEST_OUTPUTS\n"); 2402 dumpMaps(request_output_real_format); 2403 #endif 2404 2405 maps* curs=getMaps(m,"env"); 2406 if(curs!=NULL){ 2407 map* mapcs=curs->content; 2408 while(mapcs!=NULLMAP){ 2729 char *dfv = addDefaultValues (&request_input_real_format, s1->inputs, m, 0); 2730 maps *ptr = request_input_real_format; 2731 while (ptr != NULL) 2732 { 2733 map *tmp0 = getMap (ptr->content, "size"); 2734 map *tmp1 = getMap (ptr->content, "maximumMegabytes"); 2735 if (tmp1 != NULL && tmp0 != NULL) 2736 { 2737 float i = atof (tmp0->value) / 1048576.0; 2738 if (i >= atoi (tmp1->value)) 2739 { 2740 char tmps[1024]; 2741 map *tmpe = createMap ("code", "FileSizeExceeded"); 2742 snprintf (tmps, 1024, 2743 _ 2744 ("The <%s> parameter has a limited size (%sMB) defined in ZOO ServicesProvider configuration file but the reference you provided exceed this limitation (%fMB), please correct your query or the ZOO Configuration file."), 2745 ptr->name, tmp1->value, i); 2746 addToMap (tmpe, "locator", ptr->name); 2747 addToMap (tmpe, "text", tmps); 2748 printExceptionReportResponse (m, tmpe); 2749 freeService (&s1); 2750 free (s1); 2751 freeMap (&tmpe); 2752 free (tmpe); 2753 freeMaps (&m); 2754 free (m); 2755 free (REQUEST); 2756 free (SERVICE_URL); 2757 freeMaps (&request_input_real_format); 2758 free (request_input_real_format); 2759 freeMaps (&request_output_real_format); 2760 free (request_output_real_format); 2761 freeMaps (&tmpmaps); 2762 free (tmpmaps); 2763 return 1; 2764 } 2765 } 2766 ptr = ptr->next; 2767 } 2768 2769 char *dfv1 = 2770 addDefaultValues (&request_output_real_format, s1->outputs, m, 1); 2771 if (strcmp (dfv1, "") != 0 || strcmp (dfv, "") != 0) 2772 { 2773 char tmps[1024]; 2774 map *tmpe = createMap ("code", "MissingParameterValue"); 2775 if (strcmp (dfv, "") != 0) 2776 { 2777 snprintf (tmps, 1024, 2778 _ 2779 ("The <%s> argument was not specified in DataInputs but defined as requested in ZOO ServicesProvider configuration file, please correct your query or the ZOO Configuration file."), 2780 dfv); 2781 addToMap (tmpe, "locator", dfv); 2782 } 2783 else if (strcmp (dfv1, "") != 0) 2784 { 2785 snprintf (tmps, 1024, 2786 _ 2787 ("The <%s> argument was specified as Output identifier but not defined in the ZOO Configuration File. Please, correct your query or the ZOO Configuration File."), 2788 dfv1); 2789 addToMap (tmpe, "locator", dfv1); 2790 } 2791 addToMap (tmpe, "text", tmps); 2792 printExceptionReportResponse (m, tmpe); 2793 freeService (&s1); 2794 free (s1); 2795 freeMap (&tmpe); 2796 free (tmpe); 2797 freeMaps (&m); 2798 free (m); 2799 free (REQUEST); 2800 free (SERVICE_URL); 2801 freeMaps (&request_input_real_format); 2802 free (request_input_real_format); 2803 freeMaps (&request_output_real_format); 2804 free (request_output_real_format); 2805 freeMaps (&tmpmaps); 2806 free (tmpmaps); 2807 return 1; 2808 } 2809 maps *tmpReqI = request_input_real_format; 2810 while (tmpReqI != NULL) 2811 { 2812 char name[1024]; 2813 if (getMap (tmpReqI->content, "isFile") != NULL) 2814 { 2815 if (cgiFormFileName (tmpReqI->name, name, sizeof (name)) == 2816 cgiFormSuccess) 2817 { 2818 int BufferLen = 1024; 2819 cgiFilePtr file; 2820 int targetFile; 2821 char storageNameOnServer[2048]; 2822 char fileNameOnServer[64]; 2823 char contentType[1024]; 2824 char buffer[1024]; 2825 char *tmpStr = NULL; 2826 int size; 2827 int got, t; 2828 map *path = getMapFromMaps (m, "main", "tmpPath"); 2829 cgiFormFileSize (tmpReqI->name, &size); 2830 cgiFormFileContentType (tmpReqI->name, contentType, 2831 sizeof (contentType)); 2832 if (cgiFormFileOpen (tmpReqI->name, &file) == cgiFormSuccess) 2833 { 2834 t = -1; 2835 while (1) 2836 { 2837 tmpStr = strstr (name + t + 1, "\\"); 2838 if (NULL == tmpStr) 2839 tmpStr = strstr (name + t + 1, "/"); 2840 if (NULL != tmpStr) 2841 t = (int) (tmpStr - name); 2842 else 2843 break; 2844 } 2845 strcpy (fileNameOnServer, name + t + 1); 2846 2847 sprintf (storageNameOnServer, "%s/%s", path->value, 2848 fileNameOnServer); 2849 #ifdef DEBUG 2850 fprintf (stderr, "Name on server %s\n", 2851 storageNameOnServer); 2852 fprintf (stderr, "fileNameOnServer: %s\n", 2853 fileNameOnServer); 2854 #endif 2855 targetFile = 2856 open (storageNameOnServer, O_RDWR | O_CREAT | O_TRUNC, 2857 S_IRWXU | S_IRGRP | S_IROTH); 2858 if (targetFile < 0) 2859 { 2860 #ifdef DEBUG 2861 fprintf (stderr, "could not create the new file,%s\n", 2862 fileNameOnServer); 2863 #endif 2864 } 2865 else 2866 { 2867 while (cgiFormFileRead (file, buffer, BufferLen, &got) 2868 == cgiFormSuccess) 2869 { 2870 if (got > 0) 2871 write (targetFile, buffer, got); 2872 } 2873 } 2874 addToMap (tmpReqI->content, "lref", storageNameOnServer); 2875 cgiFormFileClose (file); 2876 close (targetFile); 2877 #ifdef DEBUG 2878 fprintf (stderr, "File \"%s\" has been uploaded", 2879 fileNameOnServer); 2880 #endif 2881 } 2882 } 2883 } 2884 tmpReqI = tmpReqI->next; 2885 } 2886 2887 ensureDecodedBase64 (&request_input_real_format); 2888 2889 #ifdef DEBUG 2890 fprintf (stderr, "REQUEST_INPUTS\n"); 2891 dumpMaps (request_input_real_format); 2892 fprintf (stderr, "REQUEST_OUTPUTS\n"); 2893 dumpMaps (request_output_real_format); 2894 #endif 2895 2896 maps *curs = getMaps (m, "env"); 2897 if (curs != NULL) 2898 { 2899 map *mapcs = curs->content; 2900 while (mapcs != NULLMAP) 2901 { 2409 2902 #ifndef WIN32 2410 setenv(mapcs->name,mapcs->value,1);2903 setenv (mapcs->name, mapcs->value, 1); 2411 2904 #else 2412 2905 #ifdef DEBUG 2413 fprintf(stderr,"[ZOO: setenv (%s=%s)]\n",mapcs->name,mapcs->value); 2414 #endif 2415 if(mapcs->value[strlen(mapcs->value)-2]=='\r'){ 2416 #ifdef DEBUG 2417 fprintf(stderr,"[ZOO: Env var finish with \r]\n"); 2418 #endif 2419 mapcs->value[strlen(mapcs->value)-1]=0; 2420 } 2421 #ifdef DEBUG 2422 fflush(stderr); 2423 fprintf(stderr,"setting variable... %s\n",( 2424 #endif 2425 SetEnvironmentVariable(mapcs->name,mapcs->value) 2426 #ifdef DEBUG 2427 ==0)? "OK" : "FAILED"); 2906 fprintf (stderr, "[ZOO: setenv (%s=%s)]\n", mapcs->name, 2907 mapcs->value); 2908 #endif 2909 if (mapcs->value[strlen (mapcs->value) - 2] == '\r') 2910 { 2911 #ifdef DEBUG 2912 fprintf (stderr, "[ZOO: Env var finish with \r]\n"); 2913 #endif 2914 mapcs->value[strlen (mapcs->value) - 1] = 0; 2915 } 2916 #ifdef DEBUG 2917 fflush (stderr); 2918 fprintf (stderr, "setting variable... %s\n", ( 2919 #endif 2920 SetEnvironmentVariable 2921 (mapcs->name, 2922 mapcs->value) 2923 #ifdef DEBUG 2924 == 0) ? "OK" : 2925 "FAILED"); 2428 2926 #else 2429 ; 2430 #endif 2431 char* toto=(char*)malloc((strlen(mapcs->name)+strlen(mapcs->value)+2)*sizeof(char)); 2432 sprintf(toto,"%s=%s",mapcs->name,mapcs->value); 2433 putenv(toto); 2434 #ifdef DEBUG 2435 fflush(stderr); 2436 #endif 2437 #endif 2438 #ifdef DEBUG 2439 fprintf(stderr,"[ZOO: setenv (%s=%s)]\n",mapcs->name,mapcs->value); 2440 fflush(stderr); 2441 #endif 2442 mapcs=mapcs->next; 2443 } 2444 } 2445 2446 #ifdef DEBUG 2447 dumpMap(request_inputs); 2448 #endif 2449 2927 ; 2928 #endif 2929 char *toto = 2930 (char 2931 *)malloc ((strlen 2932 (mapcs-> 2933 name) + 2934 strlen 2935 (mapcs-> 2936 value) + 2937 2) * 2938 sizeof 2939 (char)); 2940 sprintf (toto, 2941 "%s=%s", 2942 mapcs->name, 2943 mapcs-> 2944 value); 2945 putenv (toto); 2946 #ifdef DEBUG 2947 fflush (stderr); 2948 #endif 2949 #endif 2950 #ifdef DEBUG 2951 fprintf (stderr, 2952 "[ZOO: setenv (%s=%s)]\n", 2953 mapcs->name, 2954 mapcs-> 2955 value); 2956 fflush (stderr); 2957 #endif 2958 mapcs = mapcs->next;} 2959 } 2960 2961 #ifdef DEBUG 2962 dumpMap 2963 (request_inputs); 2964 #endif 2450 2965 /** 2451 2966 * Need to check if we need to fork to load a status enabled 2452 2967 */ 2453 r_inputs=NULL; 2454 map* store=getMap(request_inputs,"storeExecuteResponse"); 2455 map* status=getMap(request_inputs,"status"); 2968 r_inputs = NULL; 2969 map * store = 2970 getMap 2971 (request_inputs, 2972 "storeExecuteResponse"); 2973 map * status = 2974 getMap 2975 (request_inputs, 2976 "status"); 2456 2977 /** 2457 2978 * 05-007r7 WPS 1.0.0 page 57 : … … 2459 2980 * shall raise an exception.' 2460 2981 */ 2461 if(status!=NULL && strcmp(status->value,"true")==0 && 2462 store!=NULL && strcmp(store->value,"false")==0){ 2463 errorException(m, _("Status cannot be set to true with storeExecuteResponse to false. Please, modify your request parameters."), "InvalidParameterValue","storeExecuteResponse"); 2464 freeService(&s1); 2465 free(s1); 2466 freeMaps(&m); 2467 free(m); 2468 2469 freeMaps(&request_input_real_format); 2470 free(request_input_real_format); 2471 2472 freeMaps(&request_output_real_format); 2473 free(request_output_real_format); 2474 2475 free(REQUEST); 2476 free(SERVICE_URL); 2477 return 1; 2478 } 2479 r_inputs=getMap(request_inputs,"storeExecuteResponse"); 2480 int eres=SERVICE_STARTED; 2481 int cpid=getpid(); 2482 2982 if (status != NULL 2983 && 2984 strcmp 2985 (status->value, 2986 "true") == 0 2987 && store != NULL 2988 && 2989 strcmp 2990 (store->value, 2991 "false") == 0) 2992 { 2993 errorException (m, 2994 _ 2995 ("Status cannot be set to true with storeExecuteResponse to false. Please, modify your request parameters."), 2996 "InvalidParameterValue", 2997 "storeExecuteResponse"); 2998 freeService (&s1); 2999 free (s1); 3000 freeMaps (&m); 3001 free (m); 3002 freeMaps 3003 (&request_input_real_format); 3004 free 3005 (request_input_real_format); 3006 freeMaps 3007 (&request_output_real_format); 3008 free 3009 (request_output_real_format); 3010 free (REQUEST); 3011 free (SERVICE_URL); 3012 return 1;} 3013 r_inputs = 3014 getMap 3015 (request_inputs, 3016 "storeExecuteResponse"); 3017 int eres = 3018 SERVICE_STARTED; 3019 int cpid = getpid (); 2483 3020 /** 2484 3021 * Initialize the specific [lenv] section which contains runtime variables: … … 2499 3036 * 2500 3037 */ 2501 maps *_tmpMaps=(maps*)malloc(MAPS_SIZE); 2502 _tmpMaps->name=zStrdup("lenv"); 2503 char tmpBuff[100]; 2504 sprintf(tmpBuff,"%i",(cpid+(int)time(NULL))); 2505 _tmpMaps->content=createMap("usid",tmpBuff); 2506 _tmpMaps->next=NULL; 2507 sprintf(tmpBuff,"%i",cpid); 2508 addToMap(_tmpMaps->content,"sid",tmpBuff); 2509 addToMap(_tmpMaps->content,"status","0"); 2510 addToMap(_tmpMaps->content,"cwd",ntmp); 2511 addToMap(_tmpMaps->content,"message",_("No message provided")); 2512 map* ltmp=getMap(request_inputs,"soap"); 2513 if(ltmp!=NULL) 2514 addToMap(_tmpMaps->content,"soap",ltmp->value); 2515 else 2516 addToMap(_tmpMaps->content,"soap","false"); 2517 if(cgiCookie!=NULL && strlen(cgiCookie)>0){ 2518 int hasValidCookie=-1; 2519 char *tcook=zStrdup(cgiCookie); 2520 char *tmp=NULL; 2521 map* testing=getMapFromMaps(m,"main","cookiePrefix"); 2522 if(testing==NULL){ 2523 tmp=zStrdup("ID="); 2524 }else{ 2525 tmp=(char*)malloc((strlen(testing->value)+2)*sizeof(char)); 2526 sprintf(tmp,"%s=",testing->value); 2527 } 2528 if(strstr(cgiCookie,";")!=NULL){ 2529 char *token,*saveptr; 2530 token=strtok_r(cgiCookie,";",&saveptr); 2531 while(token!=NULL){ 2532 if(strcasestr(token,tmp)!=NULL){ 2533 if(tcook!=NULL) 2534 free(tcook); 2535 tcook=zStrdup(token); 2536 hasValidCookie=1; 2537 } 2538 token=strtok_r(NULL,";",&saveptr); 2539 } 2540 }else{ 2541 if(strstr(cgiCookie,"=")!=NULL && strcasestr(cgiCookie,tmp)!=NULL){ 2542 tcook=zStrdup(cgiCookie); 2543 hasValidCookie=1; 2544 } 2545 if(tmp!=NULL){ 2546 free(tmp); 2547 } 2548 } 2549 if(hasValidCookie>0){ 2550 addToMap(_tmpMaps->content,"sessid",strstr(tcook,"=")+1); 2551 char session_file_path[1024]; 2552 map *tmpPath=getMapFromMaps(m,"main","sessPath"); 2553 if(tmpPath==NULL) 2554 tmpPath=getMapFromMaps(m,"main","tmpPath"); 2555 char *tmp1=strtok(tcook,";"); 2556 if(tmp1!=NULL) 2557 sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,strstr(tmp1,"=")+1); 2558 else 2559 sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,strstr(cgiCookie,"=")+1); 2560 free(tcook); 2561 maps *tmpSess=(maps*)malloc(MAPS_SIZE); 2562 struct stat file_status; 2563 int istat = stat(session_file_path, &file_status); 2564 if(istat==0 && file_status.st_size>0){ 2565 conf_read(session_file_path,tmpSess); 2566 addMapsToMaps(&m,tmpSess); 2567 freeMaps(&tmpSess); 2568 free(tmpSess); 2569 } 2570 } 2571 } 2572 addMapsToMaps(&m,_tmpMaps); 2573 freeMaps(&_tmpMaps); 2574 free(_tmpMaps); 2575 2576 #ifdef DEBUG 2577 dumpMap(request_inputs); 3038 maps * _tmpMaps = 3039 (maps *) 3040 malloc (MAPS_SIZE); 3041 _tmpMaps->name = 3042 zStrdup ("lenv"); 3043 char tmpBuff[100]; 3044 sprintf (tmpBuff, 3045 "%i", 3046 (cpid + 3047 (int) 3048 time 3049 (NULL))); 3050 _tmpMaps->content = 3051 createMap ("usid", 3052 tmpBuff); 3053 _tmpMaps->next = 3054 NULL; 3055 sprintf (tmpBuff, 3056 "%i", cpid); 3057 addToMap 3058 (_tmpMaps->content, 3059 "sid", tmpBuff); 3060 addToMap 3061 (_tmpMaps->content, 3062 "status", "0"); 3063 addToMap 3064 (_tmpMaps->content, 3065 "cwd", ntmp); 3066 addToMap 3067 (_tmpMaps->content, 3068 "message", 3069 _ 3070 ("No message provided")); 3071 map * ltmp = 3072 getMap 3073 (request_inputs, 3074 "soap"); 3075 if (ltmp != 3076 NULL) 3077 addToMap 3078 (_tmpMaps->content, 3079 "soap", 3080 ltmp->value); 3081 else 3082 addToMap 3083 (_tmpMaps->content, 3084 "soap", "false"); 3085 if (cgiCookie != NULL 3086 && 3087 strlen 3088 (cgiCookie) > 0) 3089 { 3090 int hasValidCookie = 3091 -1; 3092 char *tcook = 3093 zStrdup (cgiCookie); 3094 char *tmp = NULL; 3095 map * testing = 3096 getMapFromMaps (m, 3097 "main", 3098 "cookiePrefix"); 3099 if (testing == NULL) 3100 { 3101 tmp = 3102 zStrdup ("ID=");} 3103 else 3104 { 3105 tmp = 3106 (char *) 3107 malloc ((strlen 3108 (testing-> 3109 value) + 3110 2) * 3111 sizeof 3112 (char)); 3113 sprintf (tmp, "%s=", 3114 testing-> 3115 value);} 3116 if (strstr 3117 (cgiCookie, 3118 ";") != NULL) 3119 { 3120 char *token, 3121 *saveptr; 3122 token = 3123 strtok_r (cgiCookie, 3124 ";", 3125 &saveptr); 3126 while (token != NULL) 3127 { 3128 if (strcasestr 3129 (token, 3130 tmp) != NULL) 3131 { 3132 if (tcook != NULL) 3133 free (tcook); 3134 tcook = 3135 zStrdup (token); 3136 hasValidCookie = 1;} 3137 token = 3138 strtok_r (NULL, ";", 3139 &saveptr);} 3140 } 3141 else 3142 { 3143 if (strstr 3144 (cgiCookie, 3145 "=") != NULL 3146 && 3147 strcasestr 3148 (cgiCookie, 3149 tmp) != NULL) 3150 { 3151 tcook = 3152 zStrdup (cgiCookie); 3153 hasValidCookie = 1;} 3154 if (tmp != NULL) 3155 { 3156 free (tmp);} 3157 } 3158 if (hasValidCookie > 3159 0) 3160 { 3161 addToMap 3162 (_tmpMaps->content, 3163 "sessid", 3164 strstr (tcook, 3165 "=") + 1); 3166 char 3167 session_file_path 3168 [1024]; 3169 map * tmpPath = 3170 getMapFromMaps (m, 3171 "main", 3172 "sessPath"); 3173 if (tmpPath == 3174 NULL) tmpPath = 3175 getMapFromMaps (m, 3176 "main", 3177 "tmpPath"); 3178 char *tmp1 = 3179 strtok (tcook, ";"); 3180 if (tmp1 != 3181 NULL) 3182 sprintf 3183 (session_file_path, 3184 "%s/sess_%s.cfg", 3185 tmpPath->value, 3186 strstr (tmp1, 3187 "=") + 1); 3188 else 3189 sprintf 3190 (session_file_path, 3191 "%s/sess_%s.cfg", 3192 tmpPath->value, 3193 strstr (cgiCookie, 3194 "=") + 1); 3195 free (tcook); 3196 maps * tmpSess = 3197 (maps *) 3198 malloc (MAPS_SIZE); 3199 struct stat 3200 file_status; 3201 int istat = 3202 stat 3203 (session_file_path, 3204 &file_status); 3205 if (istat == 0 3206 && 3207 file_status. 3208 st_size > 0) 3209 { 3210 conf_read 3211 (session_file_path, 3212 tmpSess); 3213 addMapsToMaps (&m, 3214 tmpSess); 3215 freeMaps (&tmpSess); 3216 free (tmpSess);} 3217 } 3218 } 3219 addMapsToMaps (&m, 3220 _tmpMaps); 3221 freeMaps (&_tmpMaps); 3222 free (_tmpMaps); 3223 #ifdef DEBUG 3224 dumpMap 3225 (request_inputs); 2578 3226 #endif 2579 3227 #ifdef WIN32 2580 char *cgiSidL=NULL; 2581 if(getenv("CGISID")!=NULL) 2582 addToMap(request_inputs,"cgiSid",getenv("CGISID")); 2583 map* test1=getMap(request_inputs,"cgiSid"); 2584 if(test1!=NULL){ 2585 cgiSid=test1->value; 2586 addToMap(request_inputs,"storeExecuteResponse","true"); 2587 addToMap(request_inputs,"status","true"); 2588 setMapInMaps(m,"lenv","sid",test1->value); 2589 status=getMap(request_inputs,"status"); 2590 } 2591 #endif 2592 char *fbkp,*fbkp1; 2593 FILE *f0,*f1; 2594 if(status!=NULL) 2595 if(strcasecmp(status->value,"false")==0) 2596 status=NULLMAP; 2597 if(status==NULLMAP){ 2598 loadServiceAndRun(&m,s1,request_inputs,&request_input_real_format,&request_output_real_format,&eres); 2599 } 2600 else{ 2601 int pid; 2602 #ifdef DEBUG 2603 fprintf(stderr,"\nPID : %d\n",cpid); 2604 #endif 2605 3228 char *cgiSidL = NULL; 3229 if (getenv ("CGISID") 3230 != 3231 NULL) 3232 addToMap 3233 (request_inputs, 3234 "cgiSid", 3235 getenv ("CGISID")); 3236 map * test1 = 3237 getMap 3238 (request_inputs, 3239 "cgiSid"); 3240 if (test1 != NULL) 3241 { 3242 cgiSid = 3243 test1->value; 3244 addToMap 3245 (request_inputs, 3246 "storeExecuteResponse", 3247 "true"); 3248 addToMap 3249 (request_inputs, 3250 "status", "true"); 3251 setMapInMaps (m, 3252 "lenv", 3253 "sid", 3254 test1-> 3255 value); 3256 status = 3257 getMap 3258 (request_inputs, 3259 "status");} 3260 #endif 3261 char *fbkp, *fbkp1; 3262 FILE * f0, *f1; 3263 if (status != NULL) 3264 if (strcasecmp 3265 (status->value, 3266 "false") == 3267 0) status = 3268 NULLMAP; 3269 if (status == 3270 NULLMAP) 3271 { 3272 loadServiceAndRun 3273 (&m, s1, 3274 request_inputs, 3275 &request_input_real_format, 3276 &request_output_real_format, 3277 &eres);} 3278 else 3279 { 3280 int pid; 3281 #ifdef DEBUG 3282 fprintf (stderr, 3283 "\nPID : %d\n", 3284 cpid); 3285 #endif 2606 3286 #ifndef WIN32 2607 pid = fork ();3287 pid = fork (); 2608 3288 #else 2609 if(cgiSid==NULL){ 2610 createProcess(m,request_inputs,s1,NULL,cpid,request_input_real_format,request_output_real_format); 2611 pid = cpid; 2612 }else{ 2613 pid=0; 2614 cpid=atoi(cgiSid); 2615 } 2616 #endif 2617 if (pid > 0) { 3289 if (cgiSid == NULL) 3290 { 3291 createProcess (m, 3292 request_inputs, 3293 s1, 3294 NULL, 3295 cpid, 3296 request_input_real_format, 3297 request_output_real_format); 3298 pid = cpid;} 3299 else 3300 { 3301 pid = 0; 3302 cpid = 3303 atoi (cgiSid);} 3304 #endif 3305 if (pid > 0) 3306 { 2618 3307 /** 2619 3308 * dady : … … 2621 3310 */ 2622 3311 #ifdef DEBUG 2623 fprintf(stderr,"father pid continue (origin %d) %d ...\n",cpid,getpid()); 2624 #endif 2625 eres=SERVICE_ACCEPTED; 2626 }else if (pid == 0) { 3312 fprintf (stderr, 3313 "father pid continue (origin %d) %d ...\n", 3314 cpid, 3315 getpid ()); 3316 #endif 3317 eres = 3318 SERVICE_ACCEPTED;} 3319 else 3320 if (pid == 0) 3321 { 2627 3322 /** 2628 3323 * son : have to close the stdout, stdin and stderr to let the parent 2629 3324 * process answer to http client. 2630 3325 */ 2631 r_inputs=getMapFromMaps(m,"main","tmpPath"); 2632 map* r_inputs1=getMap(s1->content,"ServiceProvider"); 2633 fbkp=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+1024)*sizeof(char)); 2634 sprintf(fbkp,"%s/%s_%d.xml",r_inputs->value,r_inputs1->value,cpid); 2635 char* flog=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+1024)*sizeof(char)); 2636 sprintf(flog,"%s/%s_%d_error.log",r_inputs->value,r_inputs1->value,cpid); 2637 #ifdef DEBUG 2638 fprintf(stderr,"RUN IN BACKGROUND MODE \n"); 2639 fprintf(stderr,"son pid continue (origin %d) %d ...\n",cpid,getpid()); 2640 fprintf(stderr,"\nFILE TO STORE DATA %s\n",r_inputs->value); 2641 #endif 2642 freopen(flog, "w+", stderr); 2643 f0=freopen(fbkp , "w+", stdout); 3326 r_inputs = 3327 getMapFromMaps (m, 3328 "main", 3329 "tmpPath"); 3330 map * r_inputs1 = 3331 getMap (s1->content, 3332 "ServiceProvider"); 3333 fbkp = 3334 (char *) 3335 malloc ((strlen 3336 (r_inputs-> 3337 value) + 3338 strlen 3339 (r_inputs1-> 3340 value) + 3341 1024) * 3342 sizeof 3343 (char)); 3344 sprintf (fbkp, 3345 "%s/%s_%d.xml", 3346 r_inputs-> 3347 value, 3348 r_inputs1-> 3349 value, 3350 cpid); 3351 char *flog = 3352 (char *) 3353 malloc ((strlen 3354 (r_inputs-> 3355 value) + 3356 strlen 3357 (r_inputs1-> 3358 value) + 3359 1024) * 3360 sizeof 3361 (char)); 3362 sprintf (flog, 3363 "%s/%s_%d_error.log", 3364 r_inputs-> 3365 value, 3366 r_inputs1-> 3367 value, 3368 cpid); 3369 #ifdef DEBUG 3370 fprintf (stderr, 3371 "RUN IN BACKGROUND MODE \n"); 3372 fprintf (stderr, 3373 "son pid continue (origin %d) %d ...\n", 3374 cpid, 3375 getpid ()); 3376 fprintf (stderr, 3377 "\nFILE TO STORE DATA %s\n", 3378 r_inputs-> 3379 value); 3380 #endif 3381 freopen (flog, "w+", 3382 stderr); 3383 f0 = 3384 freopen (fbkp, "w+", 3385 stdout); 2644 3386 #ifndef WIN32 2645 fclose(stdin);2646 #endif 2647 free(flog);3387 fclose (stdin); 3388 #endif 3389 free (flog); 2648 3390 /** 2649 3391 * set status to SERVICE_STARTED and flush stdout to ensure full … … 2652 3394 * this way the data will be updated at the end of the process run. 2653 3395 */ 2654 printProcessResponse(m,request_inputs,cpid,s1,r_inputs1->value,SERVICE_STARTED, 2655 request_input_real_format,request_output_real_format); 3396 printProcessResponse 3397 (m, request_inputs, 3398 cpid, s1, 3399 r_inputs1->value, 3400 SERVICE_STARTED, 3401 request_input_real_format, 3402 request_output_real_format); 2656 3403 #ifndef WIN32 2657 fflush(stdout);2658 rewind(stdout);3404 fflush (stdout); 3405 rewind (stdout); 2659 3406 #else 2660 3407 #endif 2661 fbkp1=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+1024)*sizeof(char)); 2662 sprintf(fbkp1,"%s/%s_final_%d.xml",r_inputs->value,r_inputs1->value,cpid); 2663 f1=freopen(fbkp1 , "w+", stdout); 2664 loadServiceAndRun(&m,s1,request_inputs,&request_input_real_format,&request_output_real_format,&eres); 2665 } else { 3408 fbkp1 = 3409 (char *) 3410 malloc ((strlen 3411 (r_inputs-> 3412 value) + 3413 strlen 3414 (r_inputs1-> 3415 value) + 3416 1024) * 3417 sizeof 3418 (char)); 3419 sprintf (fbkp1, 3420 "%s/%s_final_%d.xml", 3421 r_inputs-> 3422 value, 3423 r_inputs1-> 3424 value, 3425 cpid); 3426 f1 = 3427 freopen (fbkp1, "w+", 3428 stdout); 3429 loadServiceAndRun 3430 (&m, s1, 3431 request_inputs, 3432 &request_input_real_format, 3433 &request_output_real_format, 3434 &eres);} 3435 else 3436 { 2666 3437 /** 2667 3438 * error server don't accept the process need to output a valid 2668 3439 * error response here !!! 2669 3440 */ 2670 eres=-1; 2671 errorException(m, _("Unable to run the child process properly"), "InternalError",NULL); 2672 } 2673 } 2674 2675 #ifdef DEBUG 2676 dumpMaps(request_output_real_format); 2677 #endif 2678 if(eres!=-1) 2679 outputResponse(s1,request_input_real_format, 2680 request_output_real_format,request_inputs, 2681 cpid,m,eres); 2682 fflush(stdout); 3441 eres = -1; 3442 errorException (m, 3443 _ 3444 ("Unable to run the child process properly"), 3445 "InternalError", 3446 NULL);} 3447 } 3448 3449 #ifdef DEBUG 3450 dumpMaps 3451 (request_output_real_format); 3452 #endif 3453 if (eres != -1) 3454 outputResponse (s1, 3455 request_input_real_format, 3456 request_output_real_format, 3457 request_inputs, 3458 cpid, 3459 m, 3460 eres); 3461 fflush (stdout); 2683 3462 /** 2684 3463 * Ensure that if error occurs when freeing memory, no signal will return … … 2687 3466 */ 2688 3467 #ifndef USE_GDB 2689 (void) signal(SIGSEGV,donothing); 2690 (void) signal(SIGTERM,donothing); 2691 (void) signal(SIGINT,donothing); 2692 (void) signal(SIGILL,donothing); 2693 (void) signal(SIGFPE,donothing); 2694 (void) signal(SIGABRT,donothing); 2695 #endif 2696 if(((int)getpid())!=cpid || cgiSid!=NULL){ 2697 fclose(stdout); 2698 fclose(stderr); 2699 unhandleStatus(m); 3468 (void) 3469 signal (SIGSEGV, 3470 donothing); 3471 (void) 3472 signal (SIGTERM, 3473 donothing); 3474 (void) 3475 signal (SIGINT, 3476 donothing); 3477 (void) 3478 signal (SIGILL, 3479 donothing); 3480 (void) 3481 signal (SIGFPE, 3482 donothing); 3483 (void) 3484 signal (SIGABRT, 3485 donothing); 3486 #endif 3487 if (((int) getpid ()) 3488 != cpid 3489 || cgiSid != 3490 NULL) 3491 { 3492 fclose (stdout); 3493 fclose (stderr); 3494 unhandleStatus (m); 2700 3495 /** 2701 3496 * Dump back the final file fbkp1 to fbkp 2702 3497 */ 2703 fclose(f0); 2704 fclose(f1); 2705 FILE* f2=fopen(fbkp1,"rb"); 2706 FILE* f3=fopen(fbkp,"wb+"); 2707 free(fbkp); 2708 fseek(f2,0,SEEK_END); 2709 long flen=ftell(f2); 2710 fseek(f2,0,SEEK_SET); 2711 char *tmps1=(char*)malloc((flen+1)*sizeof(char)); 2712 fread(tmps1,flen,1,f2); 2713 fwrite(tmps1,1,flen,f3); 2714 fclose(f2); 2715 fclose(f3); 2716 unlink(fbkp1); 2717 free(fbkp1); 2718 free(tmps1); 2719 } 2720 2721 freeService(&s1); 2722 free(s1); 2723 freeMaps(&m); 2724 free(m); 2725 2726 freeMaps(&request_input_real_format); 2727 free(request_input_real_format); 2728 2729 freeMaps(&request_output_real_format); 2730 free(request_output_real_format); 2731 2732 free(REQUEST); 2733 free(SERVICE_URL); 2734 #ifdef DEBUG 2735 fprintf(stderr,"Processed response \n"); 2736 fflush(stdout); 2737 fflush(stderr); 2738 #endif 2739 2740 return 0; 2741 } 2742 3498 fclose (f0); 3499 fclose (f1); 3500 FILE * f2 = 3501 fopen (fbkp1, "rb"); 3502 FILE * f3 = 3503 fopen (fbkp, "wb+"); 3504 free (fbkp); 3505 fseek (f2, 0, 3506 SEEK_END); 3507 long flen = 3508 ftell (f2); 3509 fseek (f2, 0, 3510 SEEK_SET); 3511 char *tmps1 = 3512 (char 3513 *)malloc ((flen + 3514 1) * 3515 sizeof 3516 (char)); 3517 fread (tmps1, flen, 3518 1, f2); 3519 fwrite (tmps1, 1, 3520 flen, f3); 3521 fclose (f2); 3522 fclose (f3); 3523 unlink (fbkp1); 3524 free (fbkp1); 3525 free (tmps1);} 3526 3527 freeService (&s1); 3528 free (s1); 3529 freeMaps (&m); 3530 free (m); 3531 freeMaps 3532 (&request_input_real_format); 3533 free 3534 (request_input_real_format); 3535 freeMaps 3536 (&request_output_real_format); 3537 free 3538 (request_output_real_format); 3539 free (REQUEST); 3540 free (SERVICE_URL); 3541 #ifdef DEBUG 3542 fprintf (stderr, 3543 "Processed response \n"); 3544 fflush (stdout); 3545 fflush (stderr); 3546 #endif 3547 return 0;}
Note: See TracChangeset
for help on using the changeset viewer.