[1] | 1 | /** |
---|
| 2 | * Author : Gérald FENOY |
---|
| 3 | * |
---|
[392] | 4 | * Copyright 2008-2013 GeoLabs SARL. All rights reserved. |
---|
[1] | 5 | * |
---|
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 7 | * of this software and associated documentation files (the "Software"), to deal |
---|
| 8 | * in the Software without restriction, including without limitation the rights |
---|
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 10 | * copies of the Software, and to permit persons to whom the Software is |
---|
| 11 | * furnished to do so, subject to the following conditions: |
---|
| 12 | * |
---|
| 13 | * The above copyright notice and this permission notice shall be included in |
---|
| 14 | * all copies or substantial portions of the Software. |
---|
| 15 | * |
---|
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 22 | * THE SOFTWARE. |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #define length(x) (sizeof(x) / sizeof(x[0])) |
---|
| 26 | |
---|
| 27 | extern "C" int yylex(); |
---|
| 28 | extern "C" int crlex(); |
---|
[9] | 29 | |
---|
[376] | 30 | #include "cgic.h" |
---|
| 31 | |
---|
[1] | 32 | extern "C" { |
---|
| 33 | #include <libxml/tree.h> |
---|
| 34 | #include <libxml/xmlmemory.h> |
---|
| 35 | #include <libxml/parser.h> |
---|
| 36 | #include <libxml/xpath.h> |
---|
| 37 | #include <libxml/xpathInternals.h> |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | #include "ulinet.h" |
---|
| 41 | |
---|
[34] | 42 | #include <libintl.h> |
---|
| 43 | #include <locale.h> |
---|
[1] | 44 | #include <string.h> |
---|
| 45 | |
---|
| 46 | #include "service.h" |
---|
[34] | 47 | |
---|
[1] | 48 | #include "service_internal.h" |
---|
[33] | 49 | |
---|
| 50 | #ifdef USE_PYTHON |
---|
[1] | 51 | #include "service_internal_python.h" |
---|
[33] | 52 | #endif |
---|
[1] | 53 | |
---|
| 54 | #ifdef USE_JAVA |
---|
| 55 | #include "service_internal_java.h" |
---|
| 56 | #endif |
---|
| 57 | |
---|
| 58 | #ifdef USE_PHP |
---|
| 59 | #include "service_internal_php.h" |
---|
| 60 | #endif |
---|
| 61 | |
---|
| 62 | #ifdef USE_JS |
---|
| 63 | #include "service_internal_js.h" |
---|
| 64 | #endif |
---|
| 65 | |
---|
[25] | 66 | #ifdef USE_PERL |
---|
| 67 | #include "service_internal_perl.h" |
---|
| 68 | #endif |
---|
[1] | 69 | |
---|
| 70 | #include <dirent.h> |
---|
| 71 | #include <signal.h> |
---|
| 72 | #include <unistd.h> |
---|
| 73 | #ifndef WIN32 |
---|
| 74 | #include <dlfcn.h> |
---|
| 75 | #include <libgen.h> |
---|
| 76 | #else |
---|
| 77 | #include <windows.h> |
---|
| 78 | #include <direct.h> |
---|
[364] | 79 | #include <sys/types.h> |
---|
| 80 | #include <sys/stat.h> |
---|
| 81 | #include <unistd.h> |
---|
| 82 | #define pid_t int; |
---|
[1] | 83 | #endif |
---|
| 84 | #include <fcntl.h> |
---|
| 85 | #include <time.h> |
---|
| 86 | #include <stdarg.h> |
---|
| 87 | |
---|
[364] | 88 | #ifdef WIN32 |
---|
| 89 | extern "C" { |
---|
[370] | 90 | __declspec(dllexport) char *strcasestr(char const *a, char const *b) |
---|
| 91 | #ifndef USE_MS |
---|
| 92 | { |
---|
| 93 | char *x=_strdup(a); |
---|
| 94 | char *y=_strdup(b); |
---|
| 95 | |
---|
| 96 | x=_strlwr(x); |
---|
| 97 | y=_strlwr(y); |
---|
| 98 | char *pos = strstr(x, y); |
---|
| 99 | char *ret = pos == NULL ? NULL : (char *)(a + (pos-x)); |
---|
| 100 | free(x); |
---|
| 101 | free(y); |
---|
| 102 | return ret; |
---|
| 103 | }; |
---|
| 104 | #else |
---|
| 105 | ; |
---|
| 106 | #endif |
---|
[364] | 107 | } |
---|
| 108 | #endif |
---|
| 109 | |
---|
[34] | 110 | #define _(String) dgettext ("zoo-kernel",String) |
---|
[376] | 111 | #define __(String) dgettext ("zoo-service",String) |
---|
[34] | 112 | |
---|
| 113 | |
---|
[109] | 114 | void translateChar(char* str,char toReplace,char toReplaceBy){ |
---|
[34] | 115 | int i=0,len=strlen(str); |
---|
| 116 | for(i=0;i<len;i++){ |
---|
| 117 | if(str[i]==toReplace) |
---|
| 118 | str[i]=toReplaceBy; |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | |
---|
[360] | 122 | /** |
---|
| 123 | * Create (or append to) an array valued maps |
---|
| 124 | * value = "["",""]" |
---|
| 125 | */ |
---|
| 126 | int appendMapsToMaps(maps* m,maps* mo,maps* mi,elements* elem){ |
---|
[362] | 127 | maps* tmpMaps=getMaps(mo,mi->name); |
---|
| 128 | map* tmap=getMapType(tmpMaps->content); |
---|
| 129 | elements* el=getElements(elem,mi->name); |
---|
| 130 | int hasEl=1; |
---|
| 131 | if(el==NULL) |
---|
| 132 | hasEl=-1; |
---|
[360] | 133 | if(tmap==NULL){ |
---|
[362] | 134 | if(hasEl>0) |
---|
| 135 | tmap=getMapType(el->defaults->content); |
---|
[360] | 136 | } |
---|
| 137 | |
---|
[362] | 138 | map* testMap=NULL; |
---|
| 139 | if(hasEl>0){ |
---|
| 140 | testMap=getMap(el->content,"maxOccurs"); |
---|
| 141 | }else{ |
---|
| 142 | testMap=createMap("maxOccurs","unbounded"); |
---|
| 143 | } |
---|
| 144 | |
---|
[360] | 145 | if(testMap!=NULL){ |
---|
| 146 | if(strncasecmp(testMap->value,"unbounded",9)!=0 && atoi(testMap->value)>1){ |
---|
| 147 | if(addMapsArrayToMaps(&mo,mi,tmap->name)<0){ |
---|
| 148 | char emsg[1024]; |
---|
| 149 | 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)); |
---|
| 150 | errorException(m,emsg,"InternalError"); |
---|
| 151 | return -1; |
---|
| 152 | } |
---|
| 153 | }else{ |
---|
| 154 | if(strncasecmp(testMap->value,"unbounded",9)==0){ |
---|
[362] | 155 | if(hasEl<0){ |
---|
| 156 | freeMap(&testMap); |
---|
| 157 | free(testMap); |
---|
| 158 | } |
---|
[360] | 159 | if(addMapsArrayToMaps(&mo,mi,tmap->name)<0){ |
---|
| 160 | char emsg[1024]; |
---|
| 161 | map* tmpMap=getMap(mi->content,"length"); |
---|
| 162 | sprintf(emsg,_("ZOO-Kernel was unable to load your data for %s position %s."),mi->name,tmpMap->value); |
---|
| 163 | errorException(m,emsg,"InternalError"); |
---|
| 164 | return -1; |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | else{ |
---|
| 168 | char emsg[1024]; |
---|
| 169 | 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); |
---|
| 170 | errorException(m,emsg,"InternalError"); |
---|
| 171 | return -1; |
---|
| 172 | } |
---|
| 173 | } |
---|
| 174 | } |
---|
| 175 | return 0; |
---|
| 176 | } |
---|
| 177 | |
---|
[114] | 178 | xmlXPathObjectPtr extractFromDoc(xmlDocPtr doc,const char* search){ |
---|
[1] | 179 | xmlXPathContextPtr xpathCtx; |
---|
| 180 | xmlXPathObjectPtr xpathObj; |
---|
| 181 | xpathCtx = xmlXPathNewContext(doc); |
---|
| 182 | xpathObj = xmlXPathEvalExpression(BAD_CAST search,xpathCtx); |
---|
[9] | 183 | xmlXPathFreeContext(xpathCtx); |
---|
| 184 | return xpathObj; |
---|
[1] | 185 | } |
---|
| 186 | |
---|
[105] | 187 | void donothing(int sig){ |
---|
| 188 | fprintf(stderr,"Signal %d after the ZOO-Kernel returned result !\n",sig); |
---|
| 189 | exit(0); |
---|
| 190 | } |
---|
| 191 | |
---|
[9] | 192 | void sig_handler(int sig){ |
---|
| 193 | char tmp[100]; |
---|
[114] | 194 | const char *ssig; |
---|
[9] | 195 | switch(sig){ |
---|
| 196 | case SIGSEGV: |
---|
| 197 | ssig="SIGSEGV"; |
---|
| 198 | break; |
---|
| 199 | case SIGTERM: |
---|
| 200 | ssig="SIGTERM"; |
---|
| 201 | break; |
---|
| 202 | case SIGINT: |
---|
| 203 | ssig="SIGINT"; |
---|
| 204 | break; |
---|
| 205 | case SIGILL: |
---|
| 206 | ssig="SIGILL"; |
---|
| 207 | break; |
---|
| 208 | case SIGFPE: |
---|
| 209 | ssig="SIGFPE"; |
---|
| 210 | break; |
---|
| 211 | case SIGABRT: |
---|
| 212 | ssig="SIGABRT"; |
---|
| 213 | break; |
---|
| 214 | default: |
---|
| 215 | ssig="UNKNOWN"; |
---|
| 216 | break; |
---|
| 217 | } |
---|
[34] | 218 | sprintf(tmp,_("ZOO Kernel failed to process your request receiving signal %d = %s"),sig,ssig); |
---|
[9] | 219 | errorException(NULL, tmp, "InternalError"); |
---|
[10] | 220 | #ifdef DEBUG |
---|
[1] | 221 | fprintf(stderr,"Not this time!\n"); |
---|
[10] | 222 | #endif |
---|
[9] | 223 | exit(0); |
---|
[1] | 224 | } |
---|
| 225 | |
---|
[109] | 226 | void loadServiceAndRun(maps **myMap,service* s1,map* request_inputs,maps **inputs,maps** ioutputs,int* eres){ |
---|
[34] | 227 | char tmps1[1024]; |
---|
| 228 | char ntmp[1024]; |
---|
| 229 | maps *m=*myMap; |
---|
| 230 | maps *request_output_real_format=*ioutputs; |
---|
| 231 | maps *request_input_real_format=*inputs; |
---|
| 232 | /** |
---|
| 233 | * Extract serviceType to know what kind of service should be loaded |
---|
| 234 | */ |
---|
| 235 | map* r_inputs=NULL; |
---|
| 236 | #ifndef WIN32 |
---|
[114] | 237 | char* pntmp=getcwd(ntmp,1024); |
---|
[34] | 238 | #else |
---|
| 239 | _getcwd(ntmp,1024); |
---|
| 240 | #endif |
---|
| 241 | r_inputs=getMap(s1->content,"serviceType"); |
---|
| 242 | #ifdef DEBUG |
---|
| 243 | fprintf(stderr,"LOAD A %s SERVICE PROVIDER \n",r_inputs->value); |
---|
| 244 | fflush(stderr); |
---|
| 245 | #endif |
---|
[364] | 246 | if(strlen(r_inputs->value)==1 && strncasecmp(r_inputs->value,"C",1)==0){ |
---|
[34] | 247 | r_inputs=getMap(request_inputs,"metapath"); |
---|
| 248 | if(r_inputs!=NULL) |
---|
| 249 | sprintf(tmps1,"%s/%s",ntmp,r_inputs->value); |
---|
| 250 | else |
---|
| 251 | sprintf(tmps1,"%s/",ntmp); |
---|
| 252 | char *altPath=strdup(tmps1); |
---|
| 253 | r_inputs=getMap(s1->content,"ServiceProvider"); |
---|
| 254 | sprintf(tmps1,"%s/%s",altPath,r_inputs->value); |
---|
| 255 | free(altPath); |
---|
| 256 | #ifdef DEBUG |
---|
| 257 | fprintf(stderr,"Trying to load %s\n",tmps1); |
---|
| 258 | #endif |
---|
| 259 | #ifdef WIN32 |
---|
| 260 | HINSTANCE so = LoadLibraryEx(tmps1,NULL,LOAD_WITH_ALTERED_SEARCH_PATH); |
---|
| 261 | #else |
---|
| 262 | void* so = dlopen(tmps1, RTLD_LAZY); |
---|
| 263 | #endif |
---|
| 264 | #ifdef DEBUG |
---|
[57] | 265 | #ifdef WIN32 |
---|
[34] | 266 | DWORD errstr; |
---|
| 267 | errstr = GetLastError(); |
---|
| 268 | fprintf(stderr,"%s loaded (%d) \n",tmps1,errstr); |
---|
| 269 | #else |
---|
| 270 | char *errstr; |
---|
| 271 | errstr = dlerror(); |
---|
| 272 | #endif |
---|
| 273 | #endif |
---|
| 274 | if( so != NULL ) { |
---|
| 275 | #ifdef DEBUG |
---|
| 276 | fprintf(stderr,"Library loaded %s \n",errstr); |
---|
| 277 | fprintf(stderr,"Service Shared Object = %s\n",r_inputs->value); |
---|
| 278 | #endif |
---|
| 279 | r_inputs=getMap(s1->content,"serviceType"); |
---|
| 280 | #ifdef DEBUG |
---|
| 281 | dumpMap(r_inputs); |
---|
| 282 | fprintf(stderr,"%s\n",r_inputs->value); |
---|
| 283 | fflush(stderr); |
---|
| 284 | #endif |
---|
| 285 | if(strncasecmp(r_inputs->value,"C-FORTRAN",9)==0){ |
---|
| 286 | r_inputs=getMap(request_inputs,"Identifier"); |
---|
| 287 | char fname[1024]; |
---|
| 288 | sprintf(fname,"%s_",r_inputs->value); |
---|
| 289 | #ifdef DEBUG |
---|
| 290 | fprintf(stderr,"Try to load function %s\n",fname); |
---|
| 291 | #endif |
---|
| 292 | #ifdef WIN32 |
---|
| 293 | typedef int (CALLBACK* execute_t)(char***,char***,char***); |
---|
| 294 | execute_t execute=(execute_t)GetProcAddress(so,fname); |
---|
| 295 | #else |
---|
| 296 | typedef int (*execute_t)(char***,char***,char***); |
---|
| 297 | execute_t execute=(execute_t)dlsym(so,fname); |
---|
| 298 | #endif |
---|
| 299 | #ifdef DEBUG |
---|
| 300 | #ifdef WIN32 |
---|
| 301 | errstr = GetLastError(); |
---|
| 302 | #else |
---|
| 303 | errstr = dlerror(); |
---|
| 304 | #endif |
---|
| 305 | fprintf(stderr,"Function loaded %s\n",errstr); |
---|
| 306 | #endif |
---|
| 307 | |
---|
| 308 | char main_conf[10][30][1024]; |
---|
| 309 | char inputs[10][30][1024]; |
---|
| 310 | char outputs[10][30][1024]; |
---|
| 311 | for(int i=0;i<10;i++){ |
---|
| 312 | for(int j=0;j<30;j++){ |
---|
| 313 | memset(main_conf[i][j],0,1024); |
---|
| 314 | memset(inputs[i][j],0,1024); |
---|
| 315 | memset(outputs[i][j],0,1024); |
---|
| 316 | } |
---|
| 317 | } |
---|
| 318 | mapsToCharXXX(m,(char***)main_conf); |
---|
| 319 | mapsToCharXXX(request_input_real_format,(char***)inputs); |
---|
| 320 | mapsToCharXXX(request_output_real_format,(char***)outputs); |
---|
| 321 | *eres=execute((char***)&main_conf[0],(char***)&inputs[0],(char***)&outputs[0]); |
---|
| 322 | #ifdef DEBUG |
---|
| 323 | fprintf(stderr,"Function run successfully \n"); |
---|
| 324 | #endif |
---|
| 325 | charxxxToMaps((char***)&outputs[0],&request_output_real_format); |
---|
| 326 | }else{ |
---|
| 327 | #ifdef DEBUG |
---|
| 328 | #ifdef WIN32 |
---|
| 329 | errstr = GetLastError(); |
---|
| 330 | fprintf(stderr,"Function %s failed to load because of %d\n",r_inputs->value,errstr); |
---|
| 331 | #endif |
---|
| 332 | #endif |
---|
| 333 | r_inputs=getMap(request_inputs,"Identifier"); |
---|
| 334 | #ifdef DEBUG |
---|
| 335 | fprintf(stderr,"Try to load function %s\n",r_inputs->value); |
---|
| 336 | #endif |
---|
| 337 | typedef int (*execute_t)(maps**,maps**,maps**); |
---|
| 338 | #ifdef WIN32 |
---|
| 339 | execute_t execute=(execute_t)GetProcAddress(so,r_inputs->value); |
---|
| 340 | #else |
---|
| 341 | execute_t execute=(execute_t)dlsym(so,r_inputs->value); |
---|
| 342 | #endif |
---|
| 343 | |
---|
| 344 | #ifdef DEBUG |
---|
| 345 | #ifdef WIN32 |
---|
| 346 | errstr = GetLastError(); |
---|
| 347 | #else |
---|
| 348 | errstr = dlerror(); |
---|
| 349 | #endif |
---|
| 350 | fprintf(stderr,"Function loaded %s\n",errstr); |
---|
| 351 | #endif |
---|
| 352 | |
---|
| 353 | #ifdef DEBUG |
---|
| 354 | fprintf(stderr,"Now run the function \n"); |
---|
| 355 | fflush(stderr); |
---|
| 356 | #endif |
---|
| 357 | *eres=execute(&m,&request_input_real_format,&request_output_real_format); |
---|
| 358 | #ifdef DEBUG |
---|
| 359 | fprintf(stderr,"Function loaded and returned %d\n",eres); |
---|
| 360 | fflush(stderr); |
---|
| 361 | #endif |
---|
| 362 | } |
---|
[216] | 363 | #ifdef WIN32 |
---|
| 364 | *ioutputs=dupMaps(&request_output_real_format); |
---|
| 365 | FreeLibrary(so); |
---|
| 366 | #else |
---|
[34] | 367 | dlclose(so); |
---|
[216] | 368 | #endif |
---|
[34] | 369 | } else { |
---|
| 370 | /** |
---|
| 371 | * Unable to load the specified shared library |
---|
| 372 | */ |
---|
| 373 | char tmps[1024]; |
---|
| 374 | #ifdef WIN32 |
---|
| 375 | DWORD errstr = GetLastError(); |
---|
| 376 | #else |
---|
| 377 | char* errstr = dlerror(); |
---|
| 378 | #endif |
---|
[392] | 379 | sprintf(tmps,_("C Library can't be loaded %s"),errstr); |
---|
[34] | 380 | map* tmps1=createMap("text",tmps); |
---|
| 381 | printExceptionReportResponse(m,tmps1); |
---|
| 382 | *eres=-1; |
---|
| 383 | } |
---|
| 384 | } |
---|
| 385 | else |
---|
| 386 | #ifdef USE_PYTHON |
---|
| 387 | if(strncasecmp(r_inputs->value,"PYTHON",6)==0){ |
---|
| 388 | *eres=zoo_python_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); |
---|
| 389 | } |
---|
| 390 | else |
---|
| 391 | #endif |
---|
| 392 | |
---|
| 393 | #ifdef USE_JAVA |
---|
| 394 | if(strncasecmp(r_inputs->value,"JAVA",4)==0){ |
---|
| 395 | *eres=zoo_java_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); |
---|
| 396 | } |
---|
| 397 | else |
---|
| 398 | #endif |
---|
| 399 | |
---|
| 400 | #ifdef USE_PHP |
---|
| 401 | if(strncasecmp(r_inputs->value,"PHP",3)==0){ |
---|
| 402 | *eres=zoo_php_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); |
---|
| 403 | } |
---|
| 404 | else |
---|
| 405 | #endif |
---|
| 406 | |
---|
| 407 | |
---|
| 408 | #ifdef USE_PERL |
---|
| 409 | if(strncasecmp(r_inputs->value,"PERL",4)==0){ |
---|
| 410 | *eres=zoo_perl_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); |
---|
| 411 | } |
---|
| 412 | else |
---|
| 413 | #endif |
---|
| 414 | |
---|
| 415 | #ifdef USE_JS |
---|
| 416 | if(strncasecmp(r_inputs->value,"JS",2)==0){ |
---|
| 417 | *eres=zoo_js_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); |
---|
| 418 | } |
---|
| 419 | else |
---|
| 420 | #endif |
---|
| 421 | { |
---|
| 422 | char tmpv[1024]; |
---|
| 423 | sprintf(tmpv,_("Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n"),r_inputs->value); |
---|
| 424 | map* tmps=createMap("text",tmpv); |
---|
| 425 | printExceptionReportResponse(m,tmps); |
---|
| 426 | *eres=-1; |
---|
| 427 | } |
---|
[57] | 428 | *myMap=m; |
---|
[34] | 429 | *ioutputs=request_output_real_format; |
---|
| 430 | } |
---|
| 431 | |
---|
[384] | 432 | |
---|
[216] | 433 | #ifdef WIN32 |
---|
| 434 | /** |
---|
| 435 | * createProcess function: create a new process after setting some env variables |
---|
| 436 | */ |
---|
| 437 | void createProcess(maps* m,map* request_inputs,service* s1,char* opts,int cpid, maps* inputs,maps* outputs){ |
---|
| 438 | STARTUPINFO si; |
---|
| 439 | PROCESS_INFORMATION pi; |
---|
| 440 | ZeroMemory( &si, sizeof(si) ); |
---|
| 441 | si.cb = sizeof(si); |
---|
| 442 | ZeroMemory( &pi, sizeof(pi) ); |
---|
| 443 | char *tmp=(char *)malloc((1024+cgiContentLength)*sizeof(char)); |
---|
| 444 | char *tmpq=(char *)malloc((1024+cgiContentLength)*sizeof(char)); |
---|
| 445 | map *req=getMap(request_inputs,"request"); |
---|
| 446 | map *id=getMap(request_inputs,"identifier"); |
---|
| 447 | map *di=getMap(request_inputs,"DataInputs"); |
---|
| 448 | |
---|
| 449 | char *dataInputsKVP=getMapsAsKVP(inputs,cgiContentLength,0); |
---|
| 450 | char *dataOutputsKVP=getMapsAsKVP(outputs,cgiContentLength,1); |
---|
[384] | 451 | #ifdef DEBUG |
---|
[216] | 452 | fprintf(stderr,"DATAINPUTSKVP %s\n",dataInputsKVP); |
---|
| 453 | fprintf(stderr,"DATAOUTPUTSKVP %s\n",dataOutputsKVP); |
---|
[384] | 454 | #endif |
---|
[216] | 455 | map *sid=getMapFromMaps(m,"lenv","sid"); |
---|
| 456 | map* r_inputs=getMapFromMaps(m,"main","tmpPath"); |
---|
[384] | 457 | map* r_inputs1=getMap(request_inputs,"metapath"); |
---|
| 458 | int hasIn=-1; |
---|
| 459 | if(r_inputs1==NULL){ |
---|
| 460 | r_inputs1=createMap("metapath",""); |
---|
| 461 | hasIn=1; |
---|
| 462 | } |
---|
[216] | 463 | map* r_inputs2=getMap(s1->content,"ResponseDocument"); |
---|
| 464 | if(r_inputs2==NULL) |
---|
| 465 | r_inputs2=getMap(s1->content,"RawDataOutput"); |
---|
| 466 | map *tmpPath=getMapFromMaps(m,"lenv","cwd"); |
---|
| 467 | |
---|
| 468 | if(r_inputs2!=NULL){ |
---|
[384] | 469 | 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,r_inputs2->value,sid->value); |
---|
| 470 | 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); |
---|
[216] | 471 | } |
---|
| 472 | else{ |
---|
[384] | 473 | 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); |
---|
| 474 | 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); |
---|
[216] | 475 | } |
---|
[384] | 476 | |
---|
| 477 | if(hasIn>0){ |
---|
| 478 | freeMap(&r_inputs1); |
---|
| 479 | free(r_inputs1); |
---|
| 480 | } |
---|
[216] | 481 | char *tmp1=strdup(tmp); |
---|
| 482 | sprintf(tmp,"zoo_loader.cgi %s \"%s\"",tmp1,sid->value); |
---|
[384] | 483 | |
---|
[216] | 484 | free(dataInputsKVP); |
---|
| 485 | free(dataOutputsKVP); |
---|
[384] | 486 | //printf("REQUEST IS : %s \n",tmp); |
---|
| 487 | #ifdef DEBUG |
---|
[216] | 488 | fprintf(stderr,"REQUEST IS : %s \n",tmp); |
---|
[384] | 489 | #endif |
---|
[216] | 490 | SetEnvironmentVariable("CGISID",TEXT(sid->value)); |
---|
| 491 | SetEnvironmentVariable("QUERY_STRING",TEXT(tmpq)); |
---|
| 492 | char clen[1000]; |
---|
| 493 | sprintf(clen,"%d",strlen(tmpq)); |
---|
| 494 | SetEnvironmentVariable("CONTENT_LENGTH",TEXT(clen)); |
---|
| 495 | |
---|
| 496 | if( !CreateProcess( NULL, // No module name (use command line) |
---|
| 497 | TEXT(tmp), // Command line |
---|
| 498 | NULL, // Process handle not inheritable |
---|
| 499 | NULL, // Thread handle not inheritable |
---|
| 500 | FALSE, // Set handle inheritance to FALSE |
---|
| 501 | CREATE_NO_WINDOW, // Apache won't wait until the end |
---|
| 502 | NULL, // Use parent's environment block |
---|
| 503 | NULL, // Use parent's starting directory |
---|
| 504 | &si, // Pointer to STARTUPINFO struct |
---|
| 505 | &pi ) // Pointer to PROCESS_INFORMATION struct |
---|
| 506 | ) |
---|
| 507 | { |
---|
[384] | 508 | //printf("CreateProcess failed (%d).\n",GetLastError() ); |
---|
| 509 | #ifdef DEBUG |
---|
[216] | 510 | fprintf( stderr, "CreateProcess failed (%d).\n", GetLastError() ); |
---|
[384] | 511 | #endif |
---|
[216] | 512 | return ; |
---|
| 513 | }else{ |
---|
[384] | 514 | //printf("CreateProcess successfull (%d).\n",GetLastError() ); |
---|
| 515 | #ifdef DEBUG |
---|
[216] | 516 | fprintf( stderr, "CreateProcess successfull (%d).\n\n\n\n", GetLastError() ); |
---|
[384] | 517 | #endif |
---|
[216] | 518 | } |
---|
| 519 | CloseHandle( pi.hProcess ); |
---|
| 520 | CloseHandle( pi.hThread ); |
---|
[384] | 521 | //printf("CreateProcess finished !\n"); |
---|
| 522 | #ifdef DEBUG |
---|
[216] | 523 | fprintf(stderr,"CreateProcess finished !\n"); |
---|
[384] | 524 | #endif |
---|
[216] | 525 | } |
---|
| 526 | #endif |
---|
| 527 | |
---|
[1] | 528 | int runRequest(map* request_inputs) |
---|
| 529 | { |
---|
| 530 | |
---|
[53] | 531 | #ifndef USE_GDB |
---|
[9] | 532 | (void) signal(SIGSEGV,sig_handler); |
---|
| 533 | (void) signal(SIGTERM,sig_handler); |
---|
| 534 | (void) signal(SIGINT,sig_handler); |
---|
| 535 | (void) signal(SIGILL,sig_handler); |
---|
| 536 | (void) signal(SIGFPE,sig_handler); |
---|
| 537 | (void) signal(SIGABRT,sig_handler); |
---|
[53] | 538 | #endif |
---|
[9] | 539 | |
---|
[114] | 540 | map* r_inputs=NULL; |
---|
[1] | 541 | maps* m=NULL; |
---|
| 542 | |
---|
| 543 | char* REQUEST=NULL; |
---|
| 544 | /** |
---|
| 545 | * Parsing service specfic configuration file |
---|
| 546 | */ |
---|
[381] | 547 | m=(maps*)malloc(MAPS_SIZE); |
---|
[9] | 548 | if(m == NULL){ |
---|
[34] | 549 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 550 | } |
---|
[1] | 551 | char ntmp[1024]; |
---|
| 552 | #ifndef WIN32 |
---|
[114] | 553 | char *pntmp=getcwd(ntmp,1024); |
---|
[1] | 554 | #else |
---|
| 555 | _getcwd(ntmp,1024); |
---|
| 556 | #endif |
---|
[282] | 557 | r_inputs=getMapOrFill(request_inputs,"metapath",""); |
---|
| 558 | |
---|
[381] | 559 | |
---|
[9] | 560 | char conf_file[10240]; |
---|
| 561 | snprintf(conf_file,10240,"%s/%s/main.cfg",ntmp,r_inputs->value); |
---|
[385] | 562 | if(conf_read(conf_file,m)==2){ |
---|
| 563 | errorException(NULL, _("Unable to load the main.cfg file."),"InternalError"); |
---|
| 564 | free(m); |
---|
| 565 | return 1; |
---|
| 566 | } |
---|
[9] | 567 | #ifdef DEBUG |
---|
| 568 | fprintf(stderr, "***** BEGIN MAPS\n"); |
---|
| 569 | dumpMaps(m); |
---|
| 570 | fprintf(stderr, "***** END MAPS\n"); |
---|
| 571 | #endif |
---|
| 572 | |
---|
[376] | 573 | map *getPath=getMapFromMaps(m,"main","gettextPath"); |
---|
| 574 | if(getPath!=NULL){ |
---|
| 575 | bindtextdomain ("zoo-kernel",getPath->value); |
---|
| 576 | bindtextdomain ("zoo-services",getPath->value); |
---|
| 577 | }else{ |
---|
| 578 | bindtextdomain ("zoo-kernel","/usr/share/locale/"); |
---|
| 579 | bindtextdomain ("zoo-services","/usr/share/locale/"); |
---|
| 580 | } |
---|
[364] | 581 | |
---|
[381] | 582 | |
---|
[364] | 583 | /** |
---|
| 584 | * Manage our own error log file (usefull to separate standard apache debug |
---|
| 585 | * messages from the ZOO-Kernel ones but also for IIS users to avoid wrong |
---|
| 586 | * headers messages returned by the CGI due to wrong redirection of stderr) |
---|
| 587 | */ |
---|
| 588 | FILE * fstde=NULL; |
---|
| 589 | map* fstdem=getMapFromMaps(m,"main","logPath"); |
---|
| 590 | if(fstdem!=NULL) |
---|
| 591 | fstde = freopen(fstdem->value, "a+", stderr) ; |
---|
| 592 | |
---|
[376] | 593 | r_inputs=getMap(request_inputs,"language"); |
---|
| 594 | if(r_inputs==NULL) |
---|
| 595 | r_inputs=getMapFromMaps(m,"main","language"); |
---|
| 596 | if(r_inputs!=NULL){ |
---|
[34] | 597 | char *tmp=strdup(r_inputs->value); |
---|
[376] | 598 | setMapInMaps(m,"main","language",tmp); |
---|
[34] | 599 | translateChar(tmp,'-','_'); |
---|
| 600 | setlocale (LC_ALL, tmp); |
---|
[376] | 601 | #ifdef WIN32 |
---|
| 602 | char tmp1[12]; |
---|
| 603 | sprintf(tmp1,"LC_ALL=%s",tmp); |
---|
| 604 | putenv(tmp1); |
---|
| 605 | #endif |
---|
[34] | 606 | free(tmp); |
---|
| 607 | } |
---|
| 608 | else{ |
---|
| 609 | setlocale (LC_ALL, "en_US"); |
---|
[376] | 610 | #ifdef WIN32 |
---|
| 611 | char tmp1[12]; |
---|
| 612 | sprintf(tmp1,"LC_ALL=en_US"); |
---|
| 613 | putenv(tmp1); |
---|
| 614 | #endif |
---|
[34] | 615 | setMapInMaps(m,"main","language","en-US"); |
---|
| 616 | } |
---|
| 617 | setlocale (LC_NUMERIC, "en_US"); |
---|
| 618 | bind_textdomain_codeset("zoo-kernel","UTF-8"); |
---|
| 619 | textdomain("zoo-kernel"); |
---|
| 620 | bind_textdomain_codeset("zoo-services","UTF-8"); |
---|
| 621 | textdomain("zoo-services"); |
---|
| 622 | |
---|
[280] | 623 | map* lsoap=getMap(request_inputs,"soap"); |
---|
| 624 | if(lsoap!=NULL && strcasecmp(lsoap->value,"true")==0) |
---|
| 625 | setMapInMaps(m,"main","isSoap","true"); |
---|
| 626 | else |
---|
| 627 | setMapInMaps(m,"main","isSoap","false"); |
---|
[34] | 628 | |
---|
[381] | 629 | |
---|
[1] | 630 | /** |
---|
| 631 | * Check for minimum inputs |
---|
| 632 | */ |
---|
| 633 | r_inputs=getMap(request_inputs,"Request"); |
---|
[9] | 634 | if(request_inputs==NULL || r_inputs==NULL){ |
---|
[34] | 635 | errorException(m, _("Parameter <request> was not specified"),"MissingParameterValue"); |
---|
[9] | 636 | freeMaps(&m); |
---|
| 637 | free(m); |
---|
[1] | 638 | return 1; |
---|
| 639 | } |
---|
[9] | 640 | else{ |
---|
[1] | 641 | REQUEST=strdup(r_inputs->value); |
---|
[9] | 642 | if(strncasecmp(r_inputs->value,"GetCapabilities",15)!=0 |
---|
| 643 | && strncasecmp(r_inputs->value,"DescribeProcess",15)!=0 |
---|
| 644 | && strncasecmp(r_inputs->value,"Execute",7)!=0){ |
---|
[34] | 645 | errorException(m, _("Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."), "InvalidParameterValue"); |
---|
[9] | 646 | freeMaps(&m); |
---|
| 647 | free(m); |
---|
| 648 | free(REQUEST); |
---|
| 649 | return 1; |
---|
| 650 | } |
---|
| 651 | } |
---|
[1] | 652 | r_inputs=NULL; |
---|
| 653 | r_inputs=getMap(request_inputs,"Service"); |
---|
[9] | 654 | if(r_inputs==NULLMAP){ |
---|
[34] | 655 | errorException(m, _("Parameter <service> was not specified"),"MissingParameterValue"); |
---|
[9] | 656 | freeMaps(&m); |
---|
| 657 | free(m); |
---|
| 658 | free(REQUEST); |
---|
[1] | 659 | return 1; |
---|
| 660 | } |
---|
[9] | 661 | if(strncasecmp(REQUEST,"GetCapabilities",15)!=0){ |
---|
[1] | 662 | r_inputs=getMap(request_inputs,"Version"); |
---|
| 663 | if(r_inputs==NULL){ |
---|
[34] | 664 | errorException(m, _("Parameter <version> was not specified"),"MissingParameterValue"); |
---|
[9] | 665 | freeMaps(&m); |
---|
| 666 | free(m); |
---|
| 667 | free(REQUEST); |
---|
[1] | 668 | return 1; |
---|
| 669 | } |
---|
| 670 | } |
---|
| 671 | |
---|
[9] | 672 | r_inputs=getMap(request_inputs,"serviceprovider"); |
---|
| 673 | if(r_inputs==NULL){ |
---|
| 674 | addToMap(request_inputs,"serviceprovider",""); |
---|
[1] | 675 | } |
---|
| 676 | |
---|
| 677 | maps* request_output_real_format=NULL; |
---|
| 678 | map* tmpm=getMapFromMaps(m,"main","serverAddress"); |
---|
| 679 | if(tmpm!=NULL) |
---|
| 680 | SERVICE_URL=strdup(tmpm->value); |
---|
| 681 | else |
---|
[63] | 682 | SERVICE_URL=strdup(DEFAULT_SERVICE_URL); |
---|
[1] | 683 | |
---|
| 684 | service* s1; |
---|
| 685 | int scount=0; |
---|
| 686 | #ifdef DEBUG |
---|
| 687 | dumpMap(r_inputs); |
---|
| 688 | #endif |
---|
| 689 | char conf_dir[1024]; |
---|
| 690 | int t; |
---|
| 691 | char tmps1[1024]; |
---|
| 692 | |
---|
[9] | 693 | r_inputs=NULL; |
---|
| 694 | r_inputs=getMap(request_inputs,"metapath"); |
---|
| 695 | if(r_inputs!=NULL) |
---|
| 696 | snprintf(conf_dir,1024,"%s/%s",ntmp,r_inputs->value); |
---|
| 697 | else |
---|
| 698 | snprintf(conf_dir,1024,"%s",ntmp); |
---|
| 699 | |
---|
| 700 | if(strncasecmp(REQUEST,"GetCapabilities",15)==0){ |
---|
[1] | 701 | struct dirent *dp; |
---|
| 702 | #ifdef DEBUG |
---|
| 703 | dumpMap(r_inputs); |
---|
| 704 | #endif |
---|
[9] | 705 | DIR *dirp = opendir(conf_dir); |
---|
[1] | 706 | if(dirp==NULL){ |
---|
[34] | 707 | return errorException(m, _("The specified path doesn't exist."),"InvalidParameterValue"); |
---|
[1] | 708 | } |
---|
| 709 | xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); |
---|
| 710 | r_inputs=NULL; |
---|
| 711 | r_inputs=getMap(request_inputs,"ServiceProvider"); |
---|
[9] | 712 | xmlNodePtr n; |
---|
| 713 | if(r_inputs!=NULL) |
---|
| 714 | n = printGetCapabilitiesHeader(doc,r_inputs->value,m); |
---|
| 715 | else |
---|
| 716 | n = printGetCapabilitiesHeader(doc,"",m); |
---|
[1] | 717 | /** |
---|
[214] | 718 | * Here we need to close stdout to ensure that not supported chars |
---|
| 719 | * has been found in the zcfg and then printed on stdout |
---|
[1] | 720 | */ |
---|
| 721 | int saved_stdout = dup(fileno(stdout)); |
---|
| 722 | dup2(fileno(stderr),fileno(stdout)); |
---|
| 723 | while ((dp = readdir(dirp)) != NULL) |
---|
| 724 | if(strstr(dp->d_name,".zcfg")!=0){ |
---|
[9] | 725 | memset(tmps1,0,1024); |
---|
| 726 | snprintf(tmps1,1024,"%s/%s",conf_dir,dp->d_name); |
---|
[381] | 727 | s1=(service*)malloc(SERVICE_SIZE); |
---|
[9] | 728 | if(s1 == NULL){ |
---|
[34] | 729 | return errorException(m, _("Unable to allocate memory."),"InternalError"); |
---|
[9] | 730 | } |
---|
[1] | 731 | #ifdef DEBUG |
---|
| 732 | fprintf(stderr,"#################\n%s\n#################\n",tmps1); |
---|
| 733 | #endif |
---|
| 734 | t=getServiceFromFile(tmps1,&s1); |
---|
| 735 | #ifdef DEBUG |
---|
| 736 | dumpService(s1); |
---|
| 737 | fflush(stdout); |
---|
| 738 | fflush(stderr); |
---|
| 739 | #endif |
---|
| 740 | printGetCapabilitiesForProcess(m,n,s1); |
---|
[9] | 741 | freeService(&s1); |
---|
| 742 | free(s1); |
---|
[1] | 743 | scount++; |
---|
| 744 | } |
---|
| 745 | (void)closedir(dirp); |
---|
| 746 | fflush(stdout); |
---|
| 747 | dup2(saved_stdout,fileno(stdout)); |
---|
[9] | 748 | printDocument(m,doc,getpid()); |
---|
| 749 | freeMaps(&m); |
---|
| 750 | free(m); |
---|
| 751 | free(REQUEST); |
---|
| 752 | free(SERVICE_URL); |
---|
[1] | 753 | fflush(stdout); |
---|
| 754 | return 0; |
---|
| 755 | } |
---|
| 756 | else{ |
---|
| 757 | r_inputs=getMap(request_inputs,"Identifier"); |
---|
| 758 | if(r_inputs==NULL |
---|
| 759 | || strlen(r_inputs->name)==0 || strlen(r_inputs->value)==0){ |
---|
[34] | 760 | errorException(m, _("Mandatory <identifier> was not specified"),"MissingParameterValue"); |
---|
[9] | 761 | freeMaps(&m); |
---|
| 762 | free(m); |
---|
| 763 | free(REQUEST); |
---|
| 764 | free(SERVICE_URL); |
---|
| 765 | return 0; |
---|
[1] | 766 | } |
---|
| 767 | |
---|
| 768 | struct dirent *dp; |
---|
| 769 | DIR *dirp = opendir(conf_dir); |
---|
| 770 | if(dirp==NULL){ |
---|
[34] | 771 | errorException(m, _("The specified path path doesn't exist."),"InvalidParameterValue"); |
---|
[9] | 772 | freeMaps(&m); |
---|
| 773 | free(m); |
---|
| 774 | free(REQUEST); |
---|
| 775 | free(SERVICE_URL); |
---|
| 776 | return 0; |
---|
[1] | 777 | } |
---|
[9] | 778 | if(strncasecmp(REQUEST,"DescribeProcess",15)==0){ |
---|
[1] | 779 | /** |
---|
| 780 | * Loop over Identifier list |
---|
| 781 | */ |
---|
| 782 | xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); |
---|
| 783 | r_inputs=NULL; |
---|
| 784 | r_inputs=getMap(request_inputs,"ServiceProvider"); |
---|
[9] | 785 | |
---|
[1] | 786 | xmlNodePtr n; |
---|
| 787 | if(r_inputs!=NULL) |
---|
| 788 | n = printDescribeProcessHeader(doc,r_inputs->value,m); |
---|
[9] | 789 | else |
---|
| 790 | n = printDescribeProcessHeader(doc,"",m); |
---|
[1] | 791 | |
---|
| 792 | r_inputs=getMap(request_inputs,"Identifier"); |
---|
| 793 | char *tmps=strtok(r_inputs->value,","); |
---|
| 794 | |
---|
| 795 | char buff[256]; |
---|
| 796 | char buff1[1024]; |
---|
| 797 | int saved_stdout = dup(fileno(stdout)); |
---|
| 798 | dup2(fileno(stderr),fileno(stdout)); |
---|
| 799 | while(tmps){ |
---|
| 800 | memset(buff,0,256); |
---|
[9] | 801 | snprintf(buff,256,"%s.zcfg",tmps); |
---|
[1] | 802 | memset(buff1,0,1024); |
---|
| 803 | #ifdef DEBUG |
---|
[379] | 804 | printf("\n#######%s\n########\n",buff1); |
---|
[1] | 805 | #endif |
---|
| 806 | while ((dp = readdir(dirp)) != NULL) |
---|
[260] | 807 | if((strcasecmp("all.zcfg",buff)==0 && strstr(dp->d_name,".zcfg")>0) |
---|
| 808 | || strcasecmp(dp->d_name,buff)==0){ |
---|
[1] | 809 | memset(buff1,0,1024); |
---|
[9] | 810 | snprintf(buff1,1024,"%s/%s",conf_dir,dp->d_name); |
---|
[381] | 811 | s1=(service*)malloc(SERVICE_SIZE); |
---|
[9] | 812 | if(s1 == NULL){ |
---|
[379] | 813 | dup2(saved_stdout,fileno(stdout)); |
---|
[34] | 814 | return errorException(m, _("Unable to allocate memory."),"InternalError"); |
---|
[9] | 815 | } |
---|
[1] | 816 | #ifdef DEBUG |
---|
[379] | 817 | printf("#################\n%s\n#################\n",buff1); |
---|
[1] | 818 | #endif |
---|
| 819 | t=getServiceFromFile(buff1,&s1); |
---|
[9] | 820 | #ifdef DEBUG |
---|
| 821 | dumpService(s1); |
---|
| 822 | #endif |
---|
| 823 | printDescribeProcessForProcess(m,n,s1,1); |
---|
| 824 | freeService(&s1); |
---|
| 825 | free(s1); |
---|
[1] | 826 | scount++; |
---|
| 827 | } |
---|
| 828 | rewinddir(dirp); |
---|
| 829 | tmps=strtok(NULL,","); |
---|
| 830 | } |
---|
[9] | 831 | closedir(dirp); |
---|
[1] | 832 | fflush(stdout); |
---|
| 833 | dup2(saved_stdout,fileno(stdout)); |
---|
[9] | 834 | printDocument(m,doc,getpid()); |
---|
| 835 | freeMaps(&m); |
---|
| 836 | free(m); |
---|
| 837 | free(REQUEST); |
---|
| 838 | free(SERVICE_URL); |
---|
[1] | 839 | fflush(stdout); |
---|
| 840 | return 0; |
---|
| 841 | } |
---|
| 842 | else |
---|
[9] | 843 | if(strncasecmp(REQUEST,"Execute",strlen(REQUEST))!=0){ |
---|
[34] | 844 | errorException(m, _("Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."), "InvalidParameterValue"); |
---|
[1] | 845 | #ifdef DEBUG |
---|
| 846 | fprintf(stderr,"No request found %s",REQUEST); |
---|
| 847 | #endif |
---|
[9] | 848 | closedir(dirp); |
---|
[385] | 849 | freeMaps(&m); |
---|
| 850 | free(m); |
---|
| 851 | free(REQUEST); |
---|
| 852 | free(SERVICE_URL); |
---|
| 853 | fflush(stdout); |
---|
[1] | 854 | return 0; |
---|
| 855 | } |
---|
[9] | 856 | closedir(dirp); |
---|
[1] | 857 | } |
---|
| 858 | |
---|
| 859 | s1=NULL; |
---|
[381] | 860 | s1=(service*)malloc(SERVICE_SIZE); |
---|
[9] | 861 | if(s1 == NULL){ |
---|
[32] | 862 | freeMaps(&m); |
---|
| 863 | free(m); |
---|
| 864 | free(REQUEST); |
---|
| 865 | free(SERVICE_URL); |
---|
[34] | 866 | return errorException(m, _("Unable to allocate memory."),"InternalError"); |
---|
[9] | 867 | } |
---|
[1] | 868 | r_inputs=getMap(request_inputs,"MetaPath"); |
---|
[9] | 869 | if(r_inputs!=NULL) |
---|
| 870 | snprintf(tmps1,1024,"%s/%s",ntmp,r_inputs->value); |
---|
| 871 | else |
---|
| 872 | snprintf(tmps1,1024,"%s/",ntmp); |
---|
[1] | 873 | r_inputs=getMap(request_inputs,"Identifier"); |
---|
[9] | 874 | char *ttmp=strdup(tmps1); |
---|
| 875 | snprintf(tmps1,1024,"%s/%s.zcfg",ttmp,r_inputs->value); |
---|
| 876 | free(ttmp); |
---|
[1] | 877 | #ifdef DEBUG |
---|
| 878 | fprintf(stderr,"Trying to load %s\n", tmps1); |
---|
| 879 | #endif |
---|
| 880 | int saved_stdout = dup(fileno(stdout)); |
---|
[331] | 881 | dup2(fileno(stderr),fileno(stdout)); |
---|
[1] | 882 | t=getServiceFromFile(tmps1,&s1); |
---|
| 883 | fflush(stdout); |
---|
| 884 | dup2(saved_stdout,fileno(stdout)); |
---|
[32] | 885 | if(t<0){ |
---|
[216] | 886 | char *tmpMsg=(char*)malloc(2048+strlen(r_inputs->value)); |
---|
| 887 | |
---|
[34] | 888 | sprintf(tmpMsg,_("The value for <indetifier> seems to be wrong (%s). Please, ensure that the process exist using the GetCapabilities request."),r_inputs->value); |
---|
[32] | 889 | errorException(m, tmpMsg, "InvalidParameterValue"); |
---|
[216] | 890 | free(tmpMsg); |
---|
[32] | 891 | free(s1); |
---|
| 892 | freeMaps(&m); |
---|
| 893 | free(m); |
---|
| 894 | free(REQUEST); |
---|
| 895 | free(SERVICE_URL); |
---|
| 896 | return 0; |
---|
[1] | 897 | } |
---|
[258] | 898 | close(saved_stdout); |
---|
[1] | 899 | |
---|
| 900 | #ifdef DEBUG |
---|
| 901 | dumpService(s1); |
---|
| 902 | #endif |
---|
| 903 | int j; |
---|
| 904 | |
---|
[381] | 905 | |
---|
[1] | 906 | /** |
---|
[344] | 907 | * Create the input and output maps data structure |
---|
[1] | 908 | */ |
---|
| 909 | int i=0; |
---|
| 910 | HINTERNET hInternet; |
---|
| 911 | HINTERNET res; |
---|
| 912 | hInternet=InternetOpen( |
---|
| 913 | #ifndef WIN32 |
---|
| 914 | (LPCTSTR) |
---|
| 915 | #endif |
---|
| 916 | "ZooWPSClient\0", |
---|
| 917 | INTERNET_OPEN_TYPE_PRECONFIG, |
---|
| 918 | NULL,NULL, 0); |
---|
| 919 | |
---|
| 920 | #ifndef WIN32 |
---|
| 921 | if(!CHECK_INET_HANDLE(hInternet)) |
---|
| 922 | fprintf(stderr,"WARNING : hInternet handle failed to initialize"); |
---|
| 923 | #endif |
---|
| 924 | maps* request_input_real_format=NULL; |
---|
| 925 | maps* tmpmaps = request_input_real_format; |
---|
| 926 | map* postRequest=NULL; |
---|
| 927 | postRequest=getMap(request_inputs,"xrequest"); |
---|
| 928 | if(postRequest==NULLMAP){ |
---|
| 929 | /** |
---|
| 930 | * Parsing outputs provided as KVP |
---|
| 931 | */ |
---|
| 932 | r_inputs=NULL; |
---|
| 933 | #ifdef DEBUG |
---|
| 934 | fprintf(stderr,"OUTPUT Parsing ... \n"); |
---|
| 935 | #endif |
---|
| 936 | r_inputs=getMap(request_inputs,"ResponseDocument"); |
---|
[9] | 937 | if(r_inputs==NULL) r_inputs=getMap(request_inputs,"RawDataOutput"); |
---|
| 938 | |
---|
[32] | 939 | #ifdef DEBUG |
---|
[1] | 940 | fprintf(stderr,"OUTPUT Parsing ... \n"); |
---|
[32] | 941 | #endif |
---|
[9] | 942 | if(r_inputs!=NULL){ |
---|
[32] | 943 | #ifdef DEBUG |
---|
[1] | 944 | fprintf(stderr,"OUTPUT Parsing start now ... \n"); |
---|
[32] | 945 | #endif |
---|
[1] | 946 | char cursor_output[10240]; |
---|
[9] | 947 | char *cotmp=strdup(r_inputs->value); |
---|
| 948 | snprintf(cursor_output,10240,"%s",cotmp); |
---|
| 949 | free(cotmp); |
---|
[1] | 950 | j=0; |
---|
| 951 | |
---|
| 952 | /** |
---|
| 953 | * Put each Output into the outputs_as_text array |
---|
| 954 | */ |
---|
| 955 | char * pToken; |
---|
| 956 | maps* tmp_output=NULL; |
---|
| 957 | #ifdef DEBUG |
---|
| 958 | fprintf(stderr,"OUTPUT [%s]\n",cursor_output); |
---|
| 959 | #endif |
---|
| 960 | pToken=strtok(cursor_output,";"); |
---|
[381] | 961 | char** outputs_as_text=(char**)malloc(128*sizeof(char*)); |
---|
[9] | 962 | if(outputs_as_text == NULL) { |
---|
[34] | 963 | return errorException(m, _("Unable to allocate memory"), "InternalError"); |
---|
[9] | 964 | } |
---|
[1] | 965 | i=0; |
---|
| 966 | while(pToken!=NULL){ |
---|
| 967 | #ifdef DEBUG |
---|
| 968 | fprintf(stderr,"***%s***\n",pToken); |
---|
| 969 | fflush(stderr); |
---|
| 970 | fprintf(stderr,"***%s***\n",pToken); |
---|
| 971 | #endif |
---|
[381] | 972 | outputs_as_text[i]=(char*)malloc((strlen(pToken)+1)*sizeof(char)); |
---|
[9] | 973 | if(outputs_as_text[i] == NULL) { |
---|
[34] | 974 | return errorException(m, _("Unable to allocate memory"), "InternalError"); |
---|
[9] | 975 | } |
---|
| 976 | snprintf(outputs_as_text[i],strlen(pToken)+1,"%s",pToken); |
---|
[1] | 977 | pToken = strtok(NULL,";"); |
---|
| 978 | i++; |
---|
| 979 | } |
---|
| 980 | for(j=0;j<i;j++){ |
---|
| 981 | char *tmp=strdup(outputs_as_text[j]); |
---|
[9] | 982 | free(outputs_as_text[j]); |
---|
[1] | 983 | char *tmpc; |
---|
| 984 | tmpc=strtok(tmp,"@"); |
---|
| 985 | int k=0; |
---|
| 986 | while(tmpc!=NULL){ |
---|
| 987 | if(k==0){ |
---|
| 988 | if(tmp_output==NULL){ |
---|
[381] | 989 | tmp_output=(maps*)malloc(MAPS_SIZE); |
---|
[9] | 990 | if(tmp_output == NULL){ |
---|
[34] | 991 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 992 | } |
---|
[1] | 993 | tmp_output->name=strdup(tmpc); |
---|
| 994 | tmp_output->content=NULL; |
---|
| 995 | tmp_output->next=NULL; |
---|
| 996 | } |
---|
| 997 | } |
---|
| 998 | else{ |
---|
| 999 | char *tmpv=strstr(tmpc,"="); |
---|
| 1000 | char tmpn[256]; |
---|
| 1001 | memset(tmpn,0,256); |
---|
| 1002 | strncpy(tmpn,tmpc,(strlen(tmpc)-strlen(tmpv))*sizeof(char)); |
---|
| 1003 | tmpn[strlen(tmpc)-strlen(tmpv)]=0; |
---|
| 1004 | #ifdef DEBUG |
---|
| 1005 | fprintf(stderr,"OUTPUT DEF [%s]=[%s]\n",tmpn,tmpv+1); |
---|
| 1006 | #endif |
---|
| 1007 | if(tmp_output->content==NULL){ |
---|
| 1008 | tmp_output->content=createMap(tmpn,tmpv+1); |
---|
| 1009 | tmp_output->content->next=NULL; |
---|
| 1010 | } |
---|
| 1011 | else |
---|
| 1012 | addToMap(tmp_output->content,tmpn,tmpv+1); |
---|
| 1013 | } |
---|
| 1014 | k++; |
---|
| 1015 | #ifdef DEBUG |
---|
| 1016 | fprintf(stderr,"***%s***\n",tmpc); |
---|
| 1017 | #endif |
---|
| 1018 | tmpc=strtok(NULL,"@"); |
---|
| 1019 | } |
---|
| 1020 | if(request_output_real_format==NULL) |
---|
[9] | 1021 | request_output_real_format=dupMaps(&tmp_output); |
---|
[1] | 1022 | else |
---|
| 1023 | addMapsToMaps(&request_output_real_format,tmp_output); |
---|
[9] | 1024 | freeMaps(&tmp_output); |
---|
| 1025 | free(tmp_output); |
---|
| 1026 | tmp_output=NULL; |
---|
[1] | 1027 | #ifdef DEBUG |
---|
| 1028 | dumpMaps(tmp_output); |
---|
| 1029 | fflush(stderr); |
---|
| 1030 | #endif |
---|
[9] | 1031 | free(tmp); |
---|
[1] | 1032 | } |
---|
[9] | 1033 | free(outputs_as_text); |
---|
[1] | 1034 | } |
---|
| 1035 | |
---|
| 1036 | |
---|
| 1037 | /** |
---|
| 1038 | * Parsing inputs provided as KVP |
---|
| 1039 | */ |
---|
| 1040 | r_inputs=getMap(request_inputs,"DataInputs"); |
---|
| 1041 | #ifdef DEBUG |
---|
| 1042 | fprintf(stderr,"DATA INPUTS [%s]\n",r_inputs->value); |
---|
| 1043 | #endif |
---|
| 1044 | char cursor_input[40960]; |
---|
[9] | 1045 | if(r_inputs!=NULL) |
---|
| 1046 | snprintf(cursor_input,40960,"%s",r_inputs->value); |
---|
| 1047 | else{ |
---|
[34] | 1048 | errorException(m, _("Parameter <DataInputs> was not specified"),"MissingParameterValue"); |
---|
[9] | 1049 | freeMaps(&m); |
---|
| 1050 | free(m); |
---|
| 1051 | free(REQUEST); |
---|
| 1052 | free(SERVICE_URL); |
---|
[57] | 1053 | InternetCloseHandle(hInternet); |
---|
| 1054 | freeService(&s1); |
---|
| 1055 | free(s1); |
---|
[9] | 1056 | return 0; |
---|
| 1057 | } |
---|
[1] | 1058 | j=0; |
---|
| 1059 | |
---|
| 1060 | /** |
---|
| 1061 | * Put each DataInputs into the inputs_as_text array |
---|
| 1062 | */ |
---|
[328] | 1063 | char *tmp1=strdup(cursor_input); |
---|
[1] | 1064 | char * pToken; |
---|
| 1065 | pToken=strtok(cursor_input,";"); |
---|
[328] | 1066 | if(pToken!=NULL && strncasecmp(pToken,tmp1,strlen(tmp1))==0){ |
---|
| 1067 | char* tmp2=url_decode(tmp1); |
---|
| 1068 | snprintf(cursor_input,(strlen(tmp2)+1)*sizeof(char),"%s",tmp2); |
---|
| 1069 | free(tmp2); |
---|
| 1070 | pToken=strtok(cursor_input,";"); |
---|
| 1071 | } |
---|
| 1072 | free(tmp1); |
---|
| 1073 | |
---|
[381] | 1074 | char** inputs_as_text=(char**)malloc(100*sizeof(char*)); |
---|
[9] | 1075 | if(inputs_as_text == NULL){ |
---|
[34] | 1076 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 1077 | } |
---|
[1] | 1078 | i=0; |
---|
| 1079 | while(pToken!=NULL){ |
---|
| 1080 | #ifdef DEBUG |
---|
| 1081 | fprintf(stderr,"***%s***\n",pToken); |
---|
| 1082 | #endif |
---|
| 1083 | fflush(stderr); |
---|
| 1084 | #ifdef DEBUG |
---|
| 1085 | fprintf(stderr,"***%s***\n",pToken); |
---|
| 1086 | #endif |
---|
[381] | 1087 | inputs_as_text[i]=(char*)malloc((strlen(pToken)+1)*sizeof(char)); |
---|
[9] | 1088 | snprintf(inputs_as_text[i],strlen(pToken)+1,"%s",pToken); |
---|
| 1089 | if(inputs_as_text[i] == NULL){ |
---|
[34] | 1090 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 1091 | } |
---|
[1] | 1092 | pToken = strtok(NULL,";"); |
---|
| 1093 | i++; |
---|
| 1094 | } |
---|
| 1095 | |
---|
| 1096 | for(j=0;j<i;j++){ |
---|
| 1097 | char *tmp=strdup(inputs_as_text[j]); |
---|
[9] | 1098 | free(inputs_as_text[j]); |
---|
[1] | 1099 | char *tmpc; |
---|
| 1100 | tmpc=strtok(tmp,"@"); |
---|
| 1101 | while(tmpc!=NULL){ |
---|
| 1102 | #ifdef DEBUG |
---|
| 1103 | fprintf(stderr,"***\n***%s***\n",tmpc); |
---|
| 1104 | #endif |
---|
| 1105 | char *tmpv=strstr(tmpc,"="); |
---|
| 1106 | char tmpn[256]; |
---|
| 1107 | memset(tmpn,0,256); |
---|
[216] | 1108 | if(tmpv!=NULL){ |
---|
| 1109 | strncpy(tmpn,tmpc,(strlen(tmpc)-strlen(tmpv))*sizeof(char)); |
---|
| 1110 | tmpn[strlen(tmpc)-strlen(tmpv)]=0; |
---|
| 1111 | } |
---|
| 1112 | else{ |
---|
| 1113 | strncpy(tmpn,tmpc,strlen(tmpc)*sizeof(char)); |
---|
| 1114 | tmpn[strlen(tmpc)]=0; |
---|
| 1115 | } |
---|
[1] | 1116 | #ifdef DEBUG |
---|
| 1117 | fprintf(stderr,"***\n*** %s = %s ***\n",tmpn,tmpv+1); |
---|
| 1118 | #endif |
---|
| 1119 | if(tmpmaps==NULL){ |
---|
[381] | 1120 | tmpmaps=(maps*)malloc(MAPS_SIZE); |
---|
[9] | 1121 | if(tmpmaps == NULL){ |
---|
[34] | 1122 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 1123 | } |
---|
[1] | 1124 | tmpmaps->name=strdup(tmpn); |
---|
[344] | 1125 | if(tmpv!=NULL){ |
---|
| 1126 | char *tmpvf=url_decode(tmpv+1); |
---|
| 1127 | tmpmaps->content=createMap("value",tmpvf); |
---|
| 1128 | free(tmpvf); |
---|
| 1129 | } |
---|
[216] | 1130 | else |
---|
| 1131 | tmpmaps->content=createMap("value","Reference"); |
---|
[1] | 1132 | tmpmaps->next=NULL; |
---|
| 1133 | } |
---|
| 1134 | tmpc=strtok(NULL,"@"); |
---|
| 1135 | while(tmpc!=NULL){ |
---|
| 1136 | #ifdef DEBUG |
---|
| 1137 | fprintf(stderr,"*** KVP NON URL-ENCODED \n***%s***\n",tmpc); |
---|
| 1138 | #endif |
---|
| 1139 | char *tmpv1=strstr(tmpc,"="); |
---|
| 1140 | #ifdef DEBUG |
---|
| 1141 | fprintf(stderr,"*** VALUE NON URL-ENCODED \n***%s***\n",tmpv1+1); |
---|
| 1142 | #endif |
---|
| 1143 | char tmpn1[1024]; |
---|
| 1144 | memset(tmpn1,0,1024); |
---|
[216] | 1145 | if(tmpv1!=NULL){ |
---|
| 1146 | strncpy(tmpn1,tmpc,strlen(tmpc)-strlen(tmpv1)); |
---|
| 1147 | tmpn1[strlen(tmpc)-strlen(tmpv1)]=0; |
---|
| 1148 | addToMap(tmpmaps->content,tmpn1,tmpv1+1); |
---|
| 1149 | } |
---|
| 1150 | else{ |
---|
| 1151 | strncpy(tmpn1,tmpc,strlen(tmpc)); |
---|
| 1152 | tmpn1[strlen(tmpc)]=0; |
---|
| 1153 | map* lmap=getLastMap(tmpmaps->content); |
---|
[381] | 1154 | char *tmpValue=(char*)malloc((strlen(tmpv)+strlen(tmpc)+1)*sizeof(char)); |
---|
[365] | 1155 | sprintf(tmpValue,"%s@%s",tmpv+1,tmpc); |
---|
[216] | 1156 | free(lmap->value); |
---|
| 1157 | lmap->value=strdup(tmpValue); |
---|
| 1158 | free(tmpValue); |
---|
| 1159 | tmpc=strtok(NULL,"@"); |
---|
| 1160 | continue; |
---|
| 1161 | } |
---|
[1] | 1162 | #ifdef DEBUG |
---|
| 1163 | fprintf(stderr,"*** NAME NON URL-ENCODED \n***%s***\n",tmpn1); |
---|
| 1164 | fprintf(stderr,"*** VALUE NON URL-ENCODED \n***%s***\n",tmpv1+1); |
---|
| 1165 | #endif |
---|
| 1166 | if(strcmp(tmpn1,"xlink:href")!=0) |
---|
| 1167 | addToMap(tmpmaps->content,tmpn1,tmpv1+1); |
---|
[216] | 1168 | else |
---|
| 1169 | if(tmpv1!=NULL){ |
---|
[328] | 1170 | char *tmpx2=url_decode(tmpv1+1); |
---|
| 1171 | if(strncasecmp(tmpx2,"http://",7)!=0 && |
---|
| 1172 | strncasecmp(tmpx2,"ftp://",6)!=0){ |
---|
[216] | 1173 | char emsg[1024]; |
---|
| 1174 | sprintf(emsg,_("Unable to find a valid protocol to download the remote file %s"),tmpv1+1); |
---|
| 1175 | errorException(m,emsg,"InternalError"); |
---|
| 1176 | freeMaps(&m); |
---|
| 1177 | free(m); |
---|
| 1178 | free(REQUEST); |
---|
| 1179 | free(SERVICE_URL); |
---|
| 1180 | InternetCloseHandle(hInternet); |
---|
| 1181 | freeService(&s1); |
---|
| 1182 | free(s1); |
---|
| 1183 | return 0; |
---|
| 1184 | } |
---|
[1] | 1185 | #ifdef DEBUG |
---|
[216] | 1186 | fprintf(stderr,"REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n",tmpv1+1); |
---|
[1] | 1187 | #endif |
---|
[328] | 1188 | addToMap(tmpmaps->content,tmpn1,tmpx2); |
---|
[280] | 1189 | |
---|
[1] | 1190 | #ifndef WIN32 |
---|
[216] | 1191 | if(CHECK_INET_HANDLE(hInternet)) |
---|
[1] | 1192 | #endif |
---|
[216] | 1193 | { |
---|
[368] | 1194 | if(loadRemoteFile(m,tmpmaps->content,hInternet,tmpx2)<0){ |
---|
| 1195 | freeMaps(&m); |
---|
| 1196 | free(m); |
---|
| 1197 | free(REQUEST); |
---|
| 1198 | free(SERVICE_URL); |
---|
| 1199 | InternetCloseHandle(hInternet); |
---|
| 1200 | freeService(&s1); |
---|
| 1201 | free(s1); |
---|
| 1202 | return 0; |
---|
| 1203 | } |
---|
[58] | 1204 | } |
---|
[328] | 1205 | free(tmpx2); |
---|
[216] | 1206 | addToMap(tmpmaps->content,"Reference",tmpv1+1); |
---|
| 1207 | } |
---|
[1] | 1208 | tmpc=strtok(NULL,"@"); |
---|
| 1209 | } |
---|
| 1210 | #ifdef DEBUG |
---|
| 1211 | dumpMaps(tmpmaps); |
---|
| 1212 | fflush(stderr); |
---|
| 1213 | #endif |
---|
[9] | 1214 | if(request_input_real_format==NULL) |
---|
| 1215 | request_input_real_format=dupMaps(&tmpmaps); |
---|
[360] | 1216 | else{ |
---|
| 1217 | maps* testPresence=getMaps(request_input_real_format,tmpmaps->name); |
---|
| 1218 | if(testPresence!=NULL){ |
---|
| 1219 | elements* elem=getElements(s1->inputs,tmpmaps->name); |
---|
| 1220 | if(elem!=NULL){ |
---|
| 1221 | if(appendMapsToMaps(m,request_input_real_format,tmpmaps,elem)<0){ |
---|
| 1222 | freeMaps(&m); |
---|
| 1223 | free(m); |
---|
| 1224 | free(REQUEST); |
---|
| 1225 | free(SERVICE_URL); |
---|
| 1226 | InternetCloseHandle(hInternet); |
---|
| 1227 | freeService(&s1); |
---|
| 1228 | free(s1); |
---|
| 1229 | return 0; |
---|
| 1230 | } |
---|
| 1231 | } |
---|
| 1232 | } |
---|
| 1233 | else |
---|
| 1234 | addMapsToMaps(&request_input_real_format,tmpmaps); |
---|
| 1235 | } |
---|
[9] | 1236 | freeMaps(&tmpmaps); |
---|
| 1237 | free(tmpmaps); |
---|
| 1238 | tmpmaps=NULL; |
---|
| 1239 | free(tmp); |
---|
[1] | 1240 | } |
---|
| 1241 | } |
---|
[9] | 1242 | free(inputs_as_text); |
---|
| 1243 | } |
---|
[1] | 1244 | else { |
---|
[9] | 1245 | /** |
---|
| 1246 | * Parse XML request |
---|
| 1247 | */ |
---|
[1] | 1248 | xmlInitParser(); |
---|
| 1249 | #ifdef DEBUG |
---|
| 1250 | fflush(stderr); |
---|
| 1251 | fprintf(stderr,"BEFORE %s\n",postRequest->value); |
---|
| 1252 | fflush(stderr); |
---|
| 1253 | #endif |
---|
| 1254 | xmlDocPtr doc = |
---|
[5] | 1255 | xmlParseMemory(postRequest->value,cgiContentLength); |
---|
[1] | 1256 | #ifdef DEBUG |
---|
| 1257 | fprintf(stderr,"AFTER\n"); |
---|
| 1258 | fflush(stderr); |
---|
| 1259 | #endif |
---|
| 1260 | /** |
---|
| 1261 | * Parse every Input in DataInputs node. |
---|
| 1262 | */ |
---|
[9] | 1263 | xmlXPathObjectPtr tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='Input']"); |
---|
| 1264 | xmlNodeSet* tmps=tmpsptr->nodesetval; |
---|
[1] | 1265 | #ifdef DEBUG |
---|
| 1266 | fprintf(stderr,"*****%d*****\n",tmps->nodeNr); |
---|
| 1267 | #endif |
---|
| 1268 | for(int k=0;k<tmps->nodeNr;k++){ |
---|
| 1269 | maps *tmpmaps=NULL; |
---|
| 1270 | xmlNodePtr cur=tmps->nodeTab[k]; |
---|
| 1271 | if(tmps->nodeTab[k]->type == XML_ELEMENT_NODE) { |
---|
| 1272 | /** |
---|
| 1273 | * A specific Input node. |
---|
| 1274 | */ |
---|
| 1275 | #ifdef DEBUG |
---|
| 1276 | fprintf(stderr, "= element 0 node \"%s\"\n", cur->name); |
---|
| 1277 | #endif |
---|
[9] | 1278 | xmlNodePtr cur2=cur->children; |
---|
[32] | 1279 | while(cur2!=NULL){ |
---|
| 1280 | while(cur2!=NULL && cur2->type!=XML_ELEMENT_NODE) |
---|
[9] | 1281 | cur2=cur2->next; |
---|
[32] | 1282 | if(cur2==NULL) |
---|
| 1283 | break; |
---|
[9] | 1284 | /** |
---|
| 1285 | * Indentifier |
---|
| 1286 | */ |
---|
| 1287 | if(xmlStrncasecmp(cur2->name,BAD_CAST "Identifier",xmlStrlen(cur2->name))==0){ |
---|
| 1288 | xmlChar *val= xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); |
---|
| 1289 | if(tmpmaps==NULL){ |
---|
[381] | 1290 | tmpmaps=(maps*)malloc(MAPS_SIZE); |
---|
[9] | 1291 | if(tmpmaps == NULL){ |
---|
[34] | 1292 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[1] | 1293 | } |
---|
[9] | 1294 | tmpmaps->name=strdup((char*)val); |
---|
| 1295 | tmpmaps->content=NULL; |
---|
| 1296 | tmpmaps->next=NULL; |
---|
[1] | 1297 | } |
---|
[9] | 1298 | xmlFree(val); |
---|
| 1299 | } |
---|
| 1300 | /** |
---|
| 1301 | * Title, Asbtract |
---|
| 1302 | */ |
---|
| 1303 | if(xmlStrncasecmp(cur2->name,BAD_CAST "Title",xmlStrlen(cur2->name))==0 || |
---|
| 1304 | xmlStrncasecmp(cur2->name,BAD_CAST "Abstract",xmlStrlen(cur2->name))==0){ |
---|
| 1305 | xmlChar *val= |
---|
| 1306 | xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); |
---|
| 1307 | if(tmpmaps==NULL){ |
---|
[381] | 1308 | tmpmaps=(maps*)malloc(MAPS_SIZE); |
---|
[9] | 1309 | if(tmpmaps == NULL){ |
---|
[34] | 1310 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[1] | 1311 | } |
---|
[114] | 1312 | tmpmaps->name=strdup("missingIndetifier"); |
---|
[9] | 1313 | tmpmaps->content=createMap((char*)cur2->name,(char*)val); |
---|
| 1314 | tmpmaps->next=NULL; |
---|
| 1315 | } |
---|
| 1316 | else{ |
---|
| 1317 | if(tmpmaps->content!=NULL) |
---|
| 1318 | addToMap(tmpmaps->content, |
---|
| 1319 | (char*)cur2->name,(char*)val); |
---|
| 1320 | else |
---|
| 1321 | tmpmaps->content= |
---|
| 1322 | createMap((char*)cur2->name,(char*)val); |
---|
| 1323 | } |
---|
[1] | 1324 | #ifdef DEBUG |
---|
[9] | 1325 | dumpMaps(tmpmaps); |
---|
[1] | 1326 | #endif |
---|
[9] | 1327 | xmlFree(val); |
---|
| 1328 | } |
---|
| 1329 | /** |
---|
| 1330 | * InputDataFormChoice (Reference or Data ?) |
---|
| 1331 | */ |
---|
| 1332 | if(xmlStrcasecmp(cur2->name,BAD_CAST "Reference")==0){ |
---|
[1] | 1333 | /** |
---|
[9] | 1334 | * Get every attribute from a Reference node |
---|
| 1335 | * mimeType, encoding, schema, href, method |
---|
| 1336 | * Header and Body gesture should be added here |
---|
[1] | 1337 | */ |
---|
| 1338 | #ifdef DEBUG |
---|
[9] | 1339 | fprintf(stderr,"REFERENCE\n"); |
---|
[1] | 1340 | #endif |
---|
[283] | 1341 | const char *refs[5]={"mimeType","encoding","schema","method","href"}; |
---|
[9] | 1342 | for(int l=0;l<5;l++){ |
---|
[1] | 1343 | #ifdef DEBUG |
---|
[9] | 1344 | fprintf(stderr,"*** %s ***",refs[l]); |
---|
[1] | 1345 | #endif |
---|
[9] | 1346 | xmlChar *val=xmlGetProp(cur2,BAD_CAST refs[l]); |
---|
| 1347 | if(val!=NULL && xmlStrlen(val)>0){ |
---|
| 1348 | if(tmpmaps->content!=NULL) |
---|
| 1349 | addToMap(tmpmaps->content,refs[l],(char*)val); |
---|
| 1350 | else |
---|
| 1351 | tmpmaps->content=createMap(refs[l],(char*)val); |
---|
| 1352 | map* ltmp=getMap(tmpmaps->content,"method"); |
---|
| 1353 | if(l==4){ |
---|
| 1354 | if(!(ltmp!=NULL && strcmp(ltmp->value,"POST")==0) |
---|
| 1355 | && CHECK_INET_HANDLE(hInternet)){ |
---|
[379] | 1356 | if(loadRemoteFile(m,tmpmaps->content,hInternet,(char*)val)!=0){ |
---|
[368] | 1357 | freeMaps(&m); |
---|
| 1358 | free(m); |
---|
| 1359 | free(REQUEST); |
---|
| 1360 | free(SERVICE_URL); |
---|
| 1361 | InternetCloseHandle(hInternet); |
---|
| 1362 | freeService(&s1); |
---|
| 1363 | free(s1); |
---|
| 1364 | return 0; |
---|
| 1365 | } |
---|
[1] | 1366 | } |
---|
| 1367 | } |
---|
[9] | 1368 | } |
---|
[1] | 1369 | #ifdef DEBUG |
---|
[9] | 1370 | fprintf(stderr,"%s\n",val); |
---|
[1] | 1371 | #endif |
---|
[9] | 1372 | xmlFree(val); |
---|
| 1373 | } |
---|
[1] | 1374 | #ifdef POST_DEBUG |
---|
[9] | 1375 | fprintf(stderr,"Parse Header and Body from Reference \n"); |
---|
[1] | 1376 | #endif |
---|
[9] | 1377 | xmlNodePtr cur3=cur2->children; |
---|
| 1378 | hInternet.header=NULL; |
---|
| 1379 | while(cur3){ |
---|
[216] | 1380 | while(cur3!=NULL && cur3->type!=XML_ELEMENT_NODE) |
---|
| 1381 | cur2=cur3->next; |
---|
[9] | 1382 | if(xmlStrcasecmp(cur3->name,BAD_CAST "Header")==0 ){ |
---|
[114] | 1383 | const char *ha[2]; |
---|
[9] | 1384 | ha[0]="key"; |
---|
| 1385 | ha[1]="value"; |
---|
| 1386 | int hai; |
---|
| 1387 | char *has; |
---|
| 1388 | char *key; |
---|
| 1389 | for(hai=0;hai<2;hai++){ |
---|
| 1390 | xmlChar *val=xmlGetProp(cur3,BAD_CAST ha[hai]); |
---|
[1] | 1391 | #ifdef POST_DEBUG |
---|
[9] | 1392 | fprintf(stderr,"%s = %s\n",ha[hai],(char*)val); |
---|
[1] | 1393 | #endif |
---|
[9] | 1394 | if(hai==0){ |
---|
[381] | 1395 | key=(char*)malloc((1+strlen((char*)val))*sizeof(char)); |
---|
[9] | 1396 | snprintf(key,1+strlen((char*)val),"%s",(char*)val); |
---|
| 1397 | }else{ |
---|
[381] | 1398 | has=(char*)malloc((3+strlen((char*)val)+strlen(key))*sizeof(char)); |
---|
[9] | 1399 | if(has == NULL){ |
---|
[34] | 1400 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 1401 | } |
---|
| 1402 | snprintf(has,(3+strlen((char*)val)+strlen(key)),"%s: %s",key,(char*)val); |
---|
[1] | 1403 | #ifdef POST_DEBUG |
---|
[9] | 1404 | fprintf(stderr,"%s\n",has); |
---|
[1] | 1405 | #endif |
---|
| 1406 | } |
---|
| 1407 | } |
---|
[9] | 1408 | hInternet.header=curl_slist_append(hInternet.header, has); |
---|
[114] | 1409 | free(has); |
---|
[9] | 1410 | } |
---|
| 1411 | else{ |
---|
[1] | 1412 | #ifdef POST_DEBUG |
---|
[9] | 1413 | fprintf(stderr,"Try to fetch the body part of the request ...\n"); |
---|
[1] | 1414 | #endif |
---|
[9] | 1415 | if(xmlStrcasecmp(cur3->name,BAD_CAST "Body")==0 ){ |
---|
[1] | 1416 | #ifdef POST_DEBUG |
---|
[9] | 1417 | fprintf(stderr,"Body part found !!!\n",(char*)cur3->content); |
---|
[1] | 1418 | #endif |
---|
[9] | 1419 | char *tmp=new char[cgiContentLength]; |
---|
| 1420 | memset(tmp,0,cgiContentLength); |
---|
| 1421 | xmlNodePtr cur4=cur3->children; |
---|
| 1422 | while(cur4!=NULL){ |
---|
[127] | 1423 | while(cur4->type!=XML_ELEMENT_NODE) |
---|
| 1424 | cur4=cur4->next; |
---|
[9] | 1425 | xmlDocPtr bdoc = xmlNewDoc(BAD_CAST "1.0"); |
---|
| 1426 | bdoc->encoding = xmlCharStrdup ("UTF-8"); |
---|
| 1427 | xmlDocSetRootElement(bdoc,cur4); |
---|
| 1428 | xmlChar* btmps; |
---|
| 1429 | int bsize; |
---|
| 1430 | xmlDocDumpMemory(bdoc,&btmps,&bsize); |
---|
[1] | 1431 | #ifdef POST_DEBUG |
---|
[9] | 1432 | fprintf(stderr,"Body part found !!! %s %s\n",tmp,(char*)btmps); |
---|
[1] | 1433 | #endif |
---|
[9] | 1434 | if(btmps!=NULL) |
---|
| 1435 | sprintf(tmp,"%s",(char*)btmps); |
---|
| 1436 | xmlFreeDoc(bdoc); |
---|
| 1437 | cur4=cur4->next; |
---|
| 1438 | } |
---|
| 1439 | map *btmp=getMap(tmpmaps->content,"href"); |
---|
| 1440 | if(btmp!=NULL){ |
---|
| 1441 | #ifdef POST_DEBUG |
---|
| 1442 | fprintf(stderr,"%s %s\n",btmp->value,tmp); |
---|
| 1443 | curl_easy_setopt(hInternet.handle, CURLOPT_VERBOSE, 1); |
---|
| 1444 | #endif |
---|
| 1445 | res=InternetOpenUrl(hInternet,btmp->value,tmp,strlen(tmp), |
---|
| 1446 | INTERNET_FLAG_NO_CACHE_WRITE,0); |
---|
[381] | 1447 | char* tmpContent = (char*)malloc((res.nDataLen+1)*sizeof(char)); |
---|
[9] | 1448 | if(tmpContent == NULL){ |
---|
[34] | 1449 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[1] | 1450 | } |
---|
[9] | 1451 | size_t dwRead; |
---|
| 1452 | InternetReadFile(res, (LPVOID)tmpContent, |
---|
| 1453 | res.nDataLen, &dwRead); |
---|
| 1454 | tmpContent[res.nDataLen]=0; |
---|
| 1455 | if(hInternet.header!=NULL) |
---|
| 1456 | curl_slist_free_all(hInternet.header); |
---|
| 1457 | addToMap(tmpmaps->content,"value",tmpContent); |
---|
| 1458 | #ifdef POST_DEBUG |
---|
| 1459 | fprintf(stderr,"DL CONTENT : (%s)\n",tmpContent); |
---|
| 1460 | #endif |
---|
| 1461 | } |
---|
| 1462 | } |
---|
| 1463 | else |
---|
| 1464 | if(xmlStrcasecmp(cur3->name,BAD_CAST "BodyReference")==0 ){ |
---|
| 1465 | xmlChar *val=xmlGetProp(cur3,BAD_CAST "href"); |
---|
| 1466 | HINTERNET bInternet,res1; |
---|
| 1467 | bInternet=InternetOpen( |
---|
| 1468 | #ifndef WIN32 |
---|
| 1469 | (LPCTSTR) |
---|
| 1470 | #endif |
---|
| 1471 | "ZooWPSClient\0", |
---|
| 1472 | INTERNET_OPEN_TYPE_PRECONFIG, |
---|
| 1473 | NULL,NULL, 0); |
---|
| 1474 | if(!CHECK_INET_HANDLE(bInternet)) |
---|
| 1475 | fprintf(stderr,"WARNING : hInternet handle failed to initialize"); |
---|
| 1476 | #ifdef POST_DEBUG |
---|
| 1477 | curl_easy_setopt(bInternet.handle, CURLOPT_VERBOSE, 1); |
---|
| 1478 | #endif |
---|
| 1479 | res1=InternetOpenUrl(bInternet,(char*)val,NULL,0, |
---|
| 1480 | INTERNET_FLAG_NO_CACHE_WRITE,0); |
---|
| 1481 | char* tmp= |
---|
[381] | 1482 | (char*)malloc((res1.nDataLen+1)*sizeof(char)); |
---|
[9] | 1483 | if(tmp == NULL){ |
---|
[34] | 1484 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 1485 | } |
---|
| 1486 | size_t bRead; |
---|
| 1487 | InternetReadFile(res1, (LPVOID)tmp, |
---|
| 1488 | res1.nDataLen, &bRead); |
---|
| 1489 | tmp[res1.nDataLen]=0; |
---|
| 1490 | InternetCloseHandle(bInternet); |
---|
[1] | 1491 | map *btmp=getMap(tmpmaps->content,"href"); |
---|
| 1492 | if(btmp!=NULL){ |
---|
| 1493 | #ifdef POST_DEBUG |
---|
| 1494 | fprintf(stderr,"%s %s\n",btmp->value,tmp); |
---|
| 1495 | curl_easy_setopt(hInternet.handle, CURLOPT_VERBOSE, 1); |
---|
| 1496 | #endif |
---|
[9] | 1497 | res=InternetOpenUrl(hInternet,btmp->value,tmp, |
---|
| 1498 | strlen(tmp), |
---|
[1] | 1499 | INTERNET_FLAG_NO_CACHE_WRITE,0); |
---|
[381] | 1500 | char* tmpContent = (char*)malloc((res.nDataLen+1)*sizeof(char)); |
---|
[9] | 1501 | if(tmpContent == NULL){ |
---|
[34] | 1502 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 1503 | } |
---|
[1] | 1504 | size_t dwRead; |
---|
| 1505 | InternetReadFile(res, (LPVOID)tmpContent, |
---|
| 1506 | res.nDataLen, &dwRead); |
---|
| 1507 | tmpContent[res.nDataLen]=0; |
---|
| 1508 | if(hInternet.header!=NULL) |
---|
| 1509 | curl_slist_free_all(hInternet.header); |
---|
| 1510 | addToMap(tmpmaps->content,"value",tmpContent); |
---|
| 1511 | #ifdef POST_DEBUG |
---|
| 1512 | fprintf(stderr,"DL CONTENT : (%s)\n",tmpContent); |
---|
| 1513 | #endif |
---|
| 1514 | } |
---|
| 1515 | } |
---|
| 1516 | } |
---|
[9] | 1517 | cur3=cur3->next; |
---|
| 1518 | } |
---|
[1] | 1519 | #ifdef POST_DEBUG |
---|
[9] | 1520 | fprintf(stderr,"Header and Body was parsed from Reference \n"); |
---|
[1] | 1521 | #endif |
---|
| 1522 | #ifdef DEBUG |
---|
[9] | 1523 | dumpMap(tmpmaps->content); |
---|
| 1524 | fprintf(stderr, "= element 2 node \"%s\" = (%s)\n", |
---|
| 1525 | cur2->name,cur2->content); |
---|
[1] | 1526 | #endif |
---|
[9] | 1527 | } |
---|
| 1528 | else if(xmlStrcasecmp(cur2->name,BAD_CAST "Data")==0){ |
---|
[1] | 1529 | #ifdef DEBUG |
---|
[9] | 1530 | fprintf(stderr,"DATA\n"); |
---|
[1] | 1531 | #endif |
---|
[9] | 1532 | xmlNodePtr cur4=cur2->children; |
---|
[32] | 1533 | while(cur4!=NULL){ |
---|
| 1534 | while(cur4!=NULL &&cur4->type!=XML_ELEMENT_NODE) |
---|
[9] | 1535 | cur4=cur4->next; |
---|
[32] | 1536 | if(cur4==NULL) |
---|
| 1537 | break; |
---|
[9] | 1538 | if(xmlStrcasecmp(cur4->name, BAD_CAST "LiteralData")==0){ |
---|
| 1539 | /** |
---|
| 1540 | * Get every attribute from a LiteralData node |
---|
| 1541 | * dataType , uom |
---|
| 1542 | */ |
---|
[114] | 1543 | char *list[2]; |
---|
| 1544 | list[0]=strdup("dataType"); |
---|
| 1545 | list[1]=strdup("uom"); |
---|
[9] | 1546 | for(int l=0;l<2;l++){ |
---|
[1] | 1547 | #ifdef DEBUG |
---|
[114] | 1548 | fprintf(stderr,"*** LiteralData %s ***",list[l]); |
---|
[1] | 1549 | #endif |
---|
[114] | 1550 | xmlChar *val=xmlGetProp(cur4,BAD_CAST list[l]); |
---|
[9] | 1551 | if(val!=NULL && strlen((char*)val)>0){ |
---|
| 1552 | if(tmpmaps->content!=NULL) |
---|
[114] | 1553 | addToMap(tmpmaps->content,list[l],(char*)val); |
---|
[9] | 1554 | else |
---|
[114] | 1555 | tmpmaps->content=createMap(list[l],(char*)val); |
---|
[1] | 1556 | #ifdef DEBUG |
---|
[280] | 1557 | fprintf(stderr,"%s\n",val); |
---|
[1] | 1558 | #endif |
---|
[280] | 1559 | } |
---|
[9] | 1560 | xmlFree(val); |
---|
[280] | 1561 | free(list[l]); |
---|
[1] | 1562 | } |
---|
[9] | 1563 | } |
---|
| 1564 | else if(xmlStrcasecmp(cur4->name, BAD_CAST "ComplexData")==0){ |
---|
| 1565 | /** |
---|
| 1566 | * Get every attribute from a Reference node |
---|
| 1567 | * mimeType, encoding, schema |
---|
| 1568 | */ |
---|
[282] | 1569 | const char *coms[3]={"mimeType","encoding","schema"}; |
---|
[9] | 1570 | for(int l=0;l<3;l++){ |
---|
[1] | 1571 | #ifdef DEBUG |
---|
[280] | 1572 | fprintf(stderr,"*** ComplexData %s ***\n",coms[l]); |
---|
[1] | 1573 | #endif |
---|
[9] | 1574 | xmlChar *val=xmlGetProp(cur4,BAD_CAST coms[l]); |
---|
| 1575 | if(val!=NULL && strlen((char*)val)>0){ |
---|
| 1576 | if(tmpmaps->content!=NULL) |
---|
| 1577 | addToMap(tmpmaps->content,coms[l],(char*)val); |
---|
| 1578 | else |
---|
| 1579 | tmpmaps->content=createMap(coms[l],(char*)val); |
---|
[1] | 1580 | #ifdef DEBUG |
---|
[280] | 1581 | fprintf(stderr,"%s\n",val); |
---|
[1] | 1582 | #endif |
---|
[280] | 1583 | } |
---|
[9] | 1584 | xmlFree(val); |
---|
[1] | 1585 | } |
---|
| 1586 | } |
---|
[280] | 1587 | |
---|
[94] | 1588 | map* test=getMap(tmpmaps->content,"encoding"); |
---|
[280] | 1589 | if(test==NULL){ |
---|
| 1590 | if(tmpmaps->content!=NULL) |
---|
| 1591 | addToMap(tmpmaps->content,"encoding","utf-8"); |
---|
| 1592 | else |
---|
| 1593 | tmpmaps->content=createMap("encoding","utf-8"); |
---|
| 1594 | test=getMap(tmpmaps->content,"encoding"); |
---|
| 1595 | } |
---|
| 1596 | |
---|
| 1597 | if(strcasecmp(test->value,"base64")!=0){ |
---|
[94] | 1598 | xmlChar* mv=xmlNodeListGetString(doc,cur4->xmlChildrenNode,1); |
---|
[280] | 1599 | map* ltmp=getMap(tmpmaps->content,"mimeType"); |
---|
| 1600 | if(mv==NULL || |
---|
| 1601 | (xmlStrcasecmp(cur4->name, BAD_CAST "ComplexData")==0 && |
---|
| 1602 | (ltmp==NULL || strncasecmp(ltmp->value,"text/xml",8)==0) )){ |
---|
[94] | 1603 | xmlDocPtr doc1=xmlNewDoc(BAD_CAST "1.0"); |
---|
| 1604 | int buffersize; |
---|
[280] | 1605 | xmlNodePtr cur5=cur4->children; |
---|
| 1606 | while(cur5!=NULL &&cur5->type!=XML_ELEMENT_NODE) |
---|
| 1607 | cur5=cur5->next; |
---|
| 1608 | xmlDocSetRootElement(doc1,cur5); |
---|
[94] | 1609 | xmlDocDumpFormatMemoryEnc(doc1, &mv, &buffersize, "utf-8", 1); |
---|
| 1610 | char size[1024]; |
---|
| 1611 | sprintf(size,"%d",buffersize); |
---|
| 1612 | addToMap(tmpmaps->content,"size",size); |
---|
| 1613 | } |
---|
| 1614 | addToMap(tmpmaps->content,"value",(char*)mv); |
---|
| 1615 | xmlFree(mv); |
---|
| 1616 | }else{ |
---|
[95] | 1617 | xmlChar* tmp=xmlNodeListGetRawString(doc,cur4->xmlChildrenNode,0); |
---|
[94] | 1618 | addToMap(tmpmaps->content,"value",(char*)tmp); |
---|
| 1619 | map* tmpv=getMap(tmpmaps->content,"value"); |
---|
| 1620 | char *res=NULL; |
---|
| 1621 | char *curs=tmpv->value; |
---|
| 1622 | for(int i=0;i<=strlen(tmpv->value)/64;i++) { |
---|
| 1623 | if(res==NULL) |
---|
| 1624 | res=(char*)malloc(67*sizeof(char)); |
---|
| 1625 | else |
---|
| 1626 | res=(char*)realloc(res,(((i+1)*65)+i)*sizeof(char)); |
---|
| 1627 | int csize=i*65; |
---|
| 1628 | strncpy(res + csize,curs,64); |
---|
| 1629 | if(i==xmlStrlen(tmp)/64) |
---|
| 1630 | strcat(res,"\n\0"); |
---|
| 1631 | else{ |
---|
| 1632 | strncpy(res + (((i+1)*64)+i),"\n\0",2); |
---|
| 1633 | curs+=64; |
---|
| 1634 | } |
---|
| 1635 | } |
---|
| 1636 | free(tmpv->value); |
---|
| 1637 | tmpv->value=strdup(res); |
---|
| 1638 | free(res); |
---|
| 1639 | xmlFree(tmp); |
---|
[69] | 1640 | } |
---|
[9] | 1641 | cur4=cur4->next; |
---|
[1] | 1642 | } |
---|
[9] | 1643 | } |
---|
[1] | 1644 | #ifdef DEBUG |
---|
[9] | 1645 | fprintf(stderr,"cur2 next \n"); |
---|
| 1646 | fflush(stderr); |
---|
[1] | 1647 | #endif |
---|
[9] | 1648 | cur2=cur2->next; |
---|
| 1649 | } |
---|
[1] | 1650 | #ifdef DEBUG |
---|
[9] | 1651 | fprintf(stderr,"ADD MAPS TO REQUEST MAPS !\n"); |
---|
| 1652 | fflush(stderr); |
---|
[1] | 1653 | #endif |
---|
[360] | 1654 | |
---|
| 1655 | { |
---|
| 1656 | maps* testPresence=getMaps(request_input_real_format,tmpmaps->name); |
---|
| 1657 | if(testPresence!=NULL){ |
---|
| 1658 | elements* elem=getElements(s1->inputs,tmpmaps->name); |
---|
| 1659 | if(elem!=NULL){ |
---|
| 1660 | if(appendMapsToMaps(m,request_input_real_format,tmpmaps,elem)<0){ |
---|
| 1661 | freeMaps(&m); |
---|
| 1662 | free(m); |
---|
| 1663 | free(REQUEST); |
---|
| 1664 | free(SERVICE_URL); |
---|
| 1665 | InternetCloseHandle(hInternet); |
---|
| 1666 | freeService(&s1); |
---|
| 1667 | free(s1); |
---|
| 1668 | return 0; |
---|
| 1669 | } |
---|
| 1670 | } |
---|
| 1671 | } |
---|
| 1672 | else |
---|
| 1673 | addMapsToMaps(&request_input_real_format,tmpmaps); |
---|
| 1674 | } |
---|
[418] | 1675 | |
---|
[1] | 1676 | #ifdef DEBUG |
---|
[9] | 1677 | fprintf(stderr,"******TMPMAPS*****\n"); |
---|
[1] | 1678 | dumpMaps(tmpmaps); |
---|
[9] | 1679 | fprintf(stderr,"******REQUESTMAPS*****\n"); |
---|
| 1680 | dumpMaps(request_input_real_format); |
---|
[1] | 1681 | #endif |
---|
[32] | 1682 | freeMaps(&tmpmaps); |
---|
| 1683 | free(tmpmaps); |
---|
| 1684 | tmpmaps=NULL; |
---|
[1] | 1685 | } |
---|
[25] | 1686 | #ifdef DEBUG |
---|
| 1687 | dumpMaps(tmpmaps); |
---|
| 1688 | #endif |
---|
[1] | 1689 | } |
---|
| 1690 | #ifdef DEBUG |
---|
[9] | 1691 | fprintf(stderr,"Search for response document node\n"); |
---|
| 1692 | #endif |
---|
| 1693 | xmlXPathFreeObject(tmpsptr); |
---|
[105] | 1694 | |
---|
[9] | 1695 | tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='ResponseDocument']"); |
---|
[105] | 1696 | bool asRaw=false; |
---|
[9] | 1697 | tmps=tmpsptr->nodesetval; |
---|
[105] | 1698 | if(tmps->nodeNr==0){ |
---|
| 1699 | tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='RawDataOutput']"); |
---|
| 1700 | tmps=tmpsptr->nodesetval; |
---|
| 1701 | asRaw=true; |
---|
| 1702 | } |
---|
[9] | 1703 | #ifdef DEBUG |
---|
[1] | 1704 | fprintf(stderr,"*****%d*****\n",tmps->nodeNr); |
---|
| 1705 | #endif |
---|
| 1706 | for(int k=0;k<tmps->nodeNr;k++){ |
---|
[105] | 1707 | if(asRaw==true) |
---|
| 1708 | addToMap(request_inputs,"RawDataOutput",""); |
---|
| 1709 | else |
---|
| 1710 | addToMap(request_inputs,"ResponseDocument",""); |
---|
[1] | 1711 | maps *tmpmaps=NULL; |
---|
| 1712 | xmlNodePtr cur=tmps->nodeTab[k]; |
---|
| 1713 | if(cur->type == XML_ELEMENT_NODE) { |
---|
| 1714 | /** |
---|
| 1715 | * A specific responseDocument node. |
---|
| 1716 | */ |
---|
| 1717 | if(tmpmaps==NULL){ |
---|
[381] | 1718 | tmpmaps=(maps*)malloc(MAPS_SIZE); |
---|
[9] | 1719 | if(tmpmaps == NULL){ |
---|
[34] | 1720 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 1721 | } |
---|
[114] | 1722 | tmpmaps->name=strdup("unknownIdentifier"); |
---|
[381] | 1723 | tmpmaps->content=NULL; |
---|
[1] | 1724 | tmpmaps->next=NULL; |
---|
| 1725 | } |
---|
| 1726 | /** |
---|
[384] | 1727 | * Get every attribute: storeExecuteResponse, lineage, status |
---|
[1] | 1728 | */ |
---|
[283] | 1729 | const char *ress[3]={"storeExecuteResponse","lineage","status"}; |
---|
[1] | 1730 | xmlChar *val; |
---|
| 1731 | for(int l=0;l<3;l++){ |
---|
| 1732 | #ifdef DEBUG |
---|
| 1733 | fprintf(stderr,"*** %s ***\t",ress[l]); |
---|
| 1734 | #endif |
---|
| 1735 | val=xmlGetProp(cur,BAD_CAST ress[l]); |
---|
| 1736 | if(val!=NULL && strlen((char*)val)>0){ |
---|
| 1737 | if(tmpmaps->content!=NULL) |
---|
| 1738 | addToMap(tmpmaps->content,ress[l],(char*)val); |
---|
| 1739 | else |
---|
| 1740 | tmpmaps->content=createMap(ress[l],(char*)val); |
---|
| 1741 | addToMap(request_inputs,ress[l],(char*)val); |
---|
| 1742 | } |
---|
| 1743 | #ifdef DEBUG |
---|
| 1744 | fprintf(stderr,"%s\n",val); |
---|
| 1745 | #endif |
---|
| 1746 | xmlFree(val); |
---|
| 1747 | } |
---|
| 1748 | xmlNodePtr cur1=cur->children; |
---|
[381] | 1749 | while(cur1!=NULL && cur1->type != XML_ELEMENT_NODE) |
---|
| 1750 | cur1=cur1->next; |
---|
[418] | 1751 | int cur1cnt=0; |
---|
[1] | 1752 | while(cur1){ |
---|
[280] | 1753 | /** |
---|
| 1754 | * Indentifier |
---|
| 1755 | */ |
---|
| 1756 | if(xmlStrncasecmp(cur1->name,BAD_CAST "Identifier",xmlStrlen(cur1->name))==0){ |
---|
| 1757 | xmlChar *val= |
---|
| 1758 | xmlNodeListGetString(doc,cur1->xmlChildrenNode,1); |
---|
| 1759 | if(tmpmaps==NULL){ |
---|
[381] | 1760 | tmpmaps=(maps*)malloc(MAPS_SIZE); |
---|
[280] | 1761 | if(tmpmaps == NULL){ |
---|
| 1762 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
| 1763 | } |
---|
| 1764 | tmpmaps->name=strdup((char*)val); |
---|
| 1765 | tmpmaps->content=NULL; |
---|
| 1766 | tmpmaps->next=NULL; |
---|
| 1767 | } |
---|
[384] | 1768 | else{ |
---|
| 1769 | //free(tmpmaps->name); |
---|
| 1770 | tmpmaps->name=strdup((char*)val); |
---|
| 1771 | } |
---|
[418] | 1772 | if(asRaw==true) |
---|
| 1773 | addToMap(request_inputs,"RawDataOutput",(char*)val); |
---|
| 1774 | else{ |
---|
| 1775 | if(cur1cnt==0) |
---|
| 1776 | addToMap(request_inputs,"ResponseDocument",(char*)val); |
---|
| 1777 | else{ |
---|
| 1778 | map* tt=getMap(request_inputs,"ResponseDocument"); |
---|
| 1779 | char* tmp=strdup(tt->value); |
---|
| 1780 | free(tt->value); |
---|
| 1781 | tt->value=(char*)malloc((strlen(tmp)+strlen((char*)val)+1)*sizeof(char)); |
---|
| 1782 | sprintf(tt->value,"%s;%s",tmp,(char*)val); |
---|
| 1783 | free(tmp); |
---|
| 1784 | } |
---|
| 1785 | } |
---|
| 1786 | cur1cnt+=1; |
---|
[280] | 1787 | xmlFree(val); |
---|
| 1788 | } |
---|
| 1789 | /** |
---|
| 1790 | * Title, Asbtract |
---|
| 1791 | */ |
---|
| 1792 | else if(xmlStrncasecmp(cur1->name,BAD_CAST "Title",xmlStrlen(cur1->name))==0 || |
---|
| 1793 | xmlStrncasecmp(cur1->name,BAD_CAST "Abstract",xmlStrlen(cur1->name))==0){ |
---|
| 1794 | xmlChar *val= |
---|
| 1795 | xmlNodeListGetString(doc,cur1->xmlChildrenNode,1); |
---|
| 1796 | if(tmpmaps==NULL){ |
---|
[381] | 1797 | tmpmaps=(maps*)malloc(MAPS_SIZE); |
---|
[280] | 1798 | if(tmpmaps == NULL){ |
---|
| 1799 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
| 1800 | } |
---|
| 1801 | tmpmaps->name=strdup("missingIndetifier"); |
---|
| 1802 | tmpmaps->content=createMap((char*)cur1->name,(char*)val); |
---|
| 1803 | tmpmaps->next=NULL; |
---|
| 1804 | } |
---|
| 1805 | else{ |
---|
| 1806 | if(tmpmaps->content!=NULL) |
---|
[384] | 1807 | addToMap(tmpmaps->content,(char*)cur1->name,(char*)val); |
---|
[280] | 1808 | else |
---|
[384] | 1809 | tmpmaps->content=createMap((char*)cur1->name,(char*)val); |
---|
[280] | 1810 | } |
---|
| 1811 | xmlFree(val); |
---|
| 1812 | } |
---|
| 1813 | else if(xmlStrncasecmp(cur1->name,BAD_CAST "Output",xmlStrlen(cur1->name))==0){ |
---|
[1] | 1814 | /** |
---|
| 1815 | * Get every attribute from a Output node |
---|
| 1816 | * mimeType, encoding, schema, uom, asReference |
---|
| 1817 | */ |
---|
[283] | 1818 | const char *outs[5]={"mimeType","encoding","schema","uom","asReference"}; |
---|
[1] | 1819 | for(int l=0;l<5;l++){ |
---|
| 1820 | #ifdef DEBUG |
---|
| 1821 | fprintf(stderr,"*** %s ***\t",outs[l]); |
---|
| 1822 | #endif |
---|
| 1823 | val=xmlGetProp(cur1,BAD_CAST outs[l]); |
---|
| 1824 | if(val!=NULL && strlen((char*)val)>0){ |
---|
| 1825 | if(tmpmaps->content!=NULL) |
---|
| 1826 | addToMap(tmpmaps->content,outs[l],(char*)val); |
---|
| 1827 | else |
---|
| 1828 | tmpmaps->content=createMap(outs[l],(char*)val); |
---|
| 1829 | } |
---|
| 1830 | #ifdef DEBUG |
---|
| 1831 | fprintf(stderr,"%s\n",val); |
---|
| 1832 | #endif |
---|
| 1833 | xmlFree(val); |
---|
| 1834 | } |
---|
| 1835 | xmlNodePtr cur2=cur1->children; |
---|
[384] | 1836 | while(cur2!=NULL && cur2->type != XML_ELEMENT_NODE) |
---|
| 1837 | cur2=cur2->next; |
---|
[1] | 1838 | while(cur2){ |
---|
| 1839 | /** |
---|
| 1840 | * Indentifier |
---|
| 1841 | */ |
---|
[9] | 1842 | if(xmlStrncasecmp(cur2->name,BAD_CAST "Identifier",xmlStrlen(cur2->name))==0){ |
---|
[1] | 1843 | xmlChar *val= |
---|
| 1844 | xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); |
---|
| 1845 | if(tmpmaps==NULL){ |
---|
[381] | 1846 | tmpmaps=(maps*)malloc(MAPS_SIZE); |
---|
[9] | 1847 | if(tmpmaps == NULL){ |
---|
[34] | 1848 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 1849 | } |
---|
[1] | 1850 | tmpmaps->name=strdup((char*)val); |
---|
| 1851 | tmpmaps->content=NULL; |
---|
| 1852 | tmpmaps->next=NULL; |
---|
| 1853 | } |
---|
[380] | 1854 | else{ |
---|
| 1855 | if(tmpmaps->name!=NULL) |
---|
| 1856 | free(tmpmaps->name); |
---|
[1] | 1857 | tmpmaps->name=strdup((char*)val);; |
---|
[380] | 1858 | } |
---|
[1] | 1859 | xmlFree(val); |
---|
| 1860 | } |
---|
| 1861 | /** |
---|
| 1862 | * Title, Asbtract |
---|
| 1863 | */ |
---|
[274] | 1864 | else if(xmlStrncasecmp(cur2->name,BAD_CAST "Title",xmlStrlen(cur2->name))==0 || |
---|
[331] | 1865 | xmlStrncasecmp(cur2->name,BAD_CAST "Abstract",xmlStrlen(cur2->name))==0){ |
---|
[1] | 1866 | xmlChar *val= |
---|
| 1867 | xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); |
---|
| 1868 | if(tmpmaps==NULL){ |
---|
[381] | 1869 | tmpmaps=(maps*)malloc(MAPS_SIZE); |
---|
[9] | 1870 | if(tmpmaps == NULL){ |
---|
[34] | 1871 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 1872 | } |
---|
[114] | 1873 | tmpmaps->name=strdup("missingIndetifier"); |
---|
[1] | 1874 | tmpmaps->content=createMap((char*)cur2->name,(char*)val); |
---|
| 1875 | tmpmaps->next=NULL; |
---|
| 1876 | } |
---|
| 1877 | else{ |
---|
| 1878 | if(tmpmaps->content!=NULL) |
---|
| 1879 | addToMap(tmpmaps->content, |
---|
| 1880 | (char*)cur2->name,(char*)val); |
---|
| 1881 | else |
---|
| 1882 | tmpmaps->content= |
---|
| 1883 | createMap((char*)cur2->name,(char*)val); |
---|
| 1884 | } |
---|
| 1885 | xmlFree(val); |
---|
| 1886 | } |
---|
| 1887 | cur2=cur2->next; |
---|
[380] | 1888 | while(cur2!=NULL && cur2->type != XML_ELEMENT_NODE) |
---|
| 1889 | cur2=cur2->next; |
---|
[1] | 1890 | } |
---|
| 1891 | } |
---|
| 1892 | cur1=cur1->next; |
---|
[380] | 1893 | while(cur1!=NULL && cur1->type != XML_ELEMENT_NODE) |
---|
| 1894 | cur1=cur1->next; |
---|
[1] | 1895 | } |
---|
| 1896 | } |
---|
[418] | 1897 | if(request_output_real_format==NULL) |
---|
| 1898 | request_output_real_format=dupMaps(&tmpmaps); |
---|
| 1899 | else |
---|
| 1900 | addMapsToMaps(&request_output_real_format,tmpmaps); |
---|
[380] | 1901 | if(tmpmaps!=NULL){ |
---|
| 1902 | freeMaps(&tmpmaps); |
---|
| 1903 | free(tmpmaps); |
---|
| 1904 | tmpmaps=NULL; |
---|
| 1905 | } |
---|
[1] | 1906 | } |
---|
[9] | 1907 | xmlXPathFreeObject(tmpsptr); |
---|
[1] | 1908 | xmlCleanupParser(); |
---|
| 1909 | } |
---|
[105] | 1910 | |
---|
[392] | 1911 | |
---|
| 1912 | // if(CHECK_INET_HANDLE(hInternet)) |
---|
[9] | 1913 | InternetCloseHandle(hInternet); |
---|
[1] | 1914 | |
---|
| 1915 | #ifdef DEBUG |
---|
[375] | 1916 | fprintf(stderr,"\n%d\n",__LINE__); |
---|
| 1917 | fflush(stderr); |
---|
[1] | 1918 | dumpMaps(request_input_real_format); |
---|
| 1919 | dumpMaps(request_output_real_format); |
---|
[9] | 1920 | dumpMap(request_inputs); |
---|
[375] | 1921 | fprintf(stderr,"\n%d\n",__LINE__); |
---|
| 1922 | fflush(stderr); |
---|
[1] | 1923 | #endif |
---|
| 1924 | |
---|
| 1925 | /** |
---|
| 1926 | * Ensure that each requested arguments are present in the request |
---|
| 1927 | * DataInputs and ResponseDocument / RawDataOutput |
---|
[92] | 1928 | */ |
---|
[63] | 1929 | char *dfv=addDefaultValues(&request_input_real_format,s1->inputs,m,0); |
---|
[280] | 1930 | char *dfv1=addDefaultValues(&request_output_real_format,s1->outputs,m,1); |
---|
| 1931 | if(strcmp(dfv1,"")!=0 || strcmp(dfv,"")!=0){ |
---|
[9] | 1932 | char tmps[1024]; |
---|
[280] | 1933 | if(strcmp(dfv,"")!=0){ |
---|
| 1934 | 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); |
---|
| 1935 | } |
---|
| 1936 | else if(strcmp(dfv1,"")!=0){ |
---|
| 1937 | 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); |
---|
| 1938 | } |
---|
[9] | 1939 | map* tmpe=createMap("text",tmps); |
---|
| 1940 | addToMap(tmpe,"code","MissingParameterValue"); |
---|
| 1941 | printExceptionReportResponse(m,tmpe); |
---|
[63] | 1942 | freeService(&s1); |
---|
| 1943 | free(s1); |
---|
[9] | 1944 | freeMap(&tmpe); |
---|
| 1945 | free(tmpe); |
---|
| 1946 | freeMaps(&m); |
---|
| 1947 | free(m); |
---|
| 1948 | free(REQUEST); |
---|
[63] | 1949 | free(SERVICE_URL); |
---|
[9] | 1950 | freeMaps(&request_input_real_format); |
---|
| 1951 | free(request_input_real_format); |
---|
| 1952 | freeMaps(&request_output_real_format); |
---|
| 1953 | free(request_output_real_format); |
---|
| 1954 | freeMaps(&tmpmaps); |
---|
| 1955 | free(tmpmaps); |
---|
| 1956 | return 1; |
---|
| 1957 | } |
---|
[331] | 1958 | maps* tmpReqI=request_input_real_format; |
---|
| 1959 | while(tmpReqI!=NULL){ |
---|
| 1960 | char name[1024]; |
---|
| 1961 | if(getMap(tmpReqI->content,"isFile")!=NULL){ |
---|
| 1962 | if (cgiFormFileName(tmpReqI->name, name, sizeof(name)) == cgiFormSuccess) { |
---|
| 1963 | int BufferLen=1024; |
---|
| 1964 | cgiFilePtr file; |
---|
| 1965 | int targetFile; |
---|
| 1966 | mode_t mode; |
---|
| 1967 | char storageNameOnServer[2048]; |
---|
| 1968 | char fileNameOnServer[64]; |
---|
| 1969 | char contentType[1024]; |
---|
[364] | 1970 | char buffer[1024]; |
---|
[331] | 1971 | char *tmpStr=NULL; |
---|
| 1972 | int size; |
---|
| 1973 | int got,t; |
---|
| 1974 | map *path=getMapFromMaps(m,"main","tmpPath"); |
---|
| 1975 | cgiFormFileSize(tmpReqI->name, &size); |
---|
| 1976 | cgiFormFileContentType(tmpReqI->name, contentType, sizeof(contentType)); |
---|
| 1977 | if (cgiFormFileOpen(tmpReqI->name, &file) == cgiFormSuccess) { |
---|
| 1978 | t=-1; |
---|
| 1979 | while(1){ |
---|
| 1980 | tmpStr=strstr(name+t+1,"\\"); |
---|
| 1981 | if(NULL==tmpStr) |
---|
| 1982 | tmpStr=strstr(name+t+1,"/"); |
---|
| 1983 | if(NULL!=tmpStr) |
---|
| 1984 | t=(int)(tmpStr-name); |
---|
| 1985 | else |
---|
| 1986 | break; |
---|
| 1987 | } |
---|
| 1988 | strcpy(fileNameOnServer,name+t+1); |
---|
| 1989 | |
---|
| 1990 | sprintf(storageNameOnServer,"%s/%s",path->value,fileNameOnServer); |
---|
[375] | 1991 | #ifdef DEBUG |
---|
[331] | 1992 | fprintf(stderr,"Name on server %s\n",storageNameOnServer); |
---|
| 1993 | fprintf(stderr,"fileNameOnServer: %s\n",fileNameOnServer); |
---|
[375] | 1994 | #endif |
---|
[331] | 1995 | mode=S_IRWXU|S_IRGRP|S_IROTH; |
---|
[364] | 1996 | targetFile = open (storageNameOnServer,O_RDWR|O_CREAT|O_TRUNC,S_IRWXU|S_IRGRP|S_IROTH); |
---|
[331] | 1997 | if(targetFile<0){ |
---|
[375] | 1998 | #ifdef DEBUG |
---|
[331] | 1999 | fprintf(stderr,"could not create the new file,%s\n",fileNameOnServer); |
---|
[375] | 2000 | #endif |
---|
[331] | 2001 | }else{ |
---|
| 2002 | while (cgiFormFileRead(file, buffer, BufferLen, &got) ==cgiFormSuccess){ |
---|
| 2003 | if(got>0) |
---|
| 2004 | write(targetFile,buffer,got); |
---|
| 2005 | } |
---|
| 2006 | } |
---|
| 2007 | addToMap(tmpReqI->content,"lref",storageNameOnServer); |
---|
| 2008 | cgiFormFileClose(file); |
---|
| 2009 | close(targetFile); |
---|
[375] | 2010 | #ifdef DEBUG |
---|
[331] | 2011 | fprintf(stderr,"File \"%s\" has been uploaded",fileNameOnServer); |
---|
[375] | 2012 | #endif |
---|
[331] | 2013 | } |
---|
| 2014 | } |
---|
| 2015 | } |
---|
| 2016 | tmpReqI=tmpReqI->next; |
---|
| 2017 | } |
---|
| 2018 | |
---|
[88] | 2019 | ensureDecodedBase64(&request_input_real_format); |
---|
| 2020 | |
---|
[9] | 2021 | #ifdef DEBUG |
---|
| 2022 | fprintf(stderr,"REQUEST_INPUTS\n"); |
---|
| 2023 | dumpMaps(request_input_real_format); |
---|
| 2024 | fprintf(stderr,"REQUEST_OUTPUTS\n"); |
---|
| 2025 | dumpMaps(request_output_real_format); |
---|
| 2026 | #endif |
---|
[1] | 2027 | |
---|
| 2028 | maps* curs=getMaps(m,"env"); |
---|
| 2029 | if(curs!=NULL){ |
---|
| 2030 | map* mapcs=curs->content; |
---|
| 2031 | while(mapcs!=NULLMAP){ |
---|
| 2032 | #ifndef WIN32 |
---|
| 2033 | setenv(mapcs->name,mapcs->value,1); |
---|
| 2034 | #else |
---|
| 2035 | #ifdef DEBUG |
---|
| 2036 | fprintf(stderr,"[ZOO: setenv (%s=%s)]\n",mapcs->name,mapcs->value); |
---|
| 2037 | #endif |
---|
| 2038 | if(mapcs->value[strlen(mapcs->value)-2]=='\r'){ |
---|
| 2039 | #ifdef DEBUG |
---|
| 2040 | fprintf(stderr,"[ZOO: Env var finish with \r]\n"); |
---|
| 2041 | #endif |
---|
| 2042 | mapcs->value[strlen(mapcs->value)-1]=0; |
---|
| 2043 | } |
---|
| 2044 | #ifdef DEBUG |
---|
| 2045 | fflush(stderr); |
---|
[364] | 2046 | fprintf(stderr,"setting variable... %s\n",( |
---|
[1] | 2047 | #endif |
---|
| 2048 | SetEnvironmentVariable(mapcs->name,mapcs->value) |
---|
| 2049 | #ifdef DEBUG |
---|
[364] | 2050 | ==0)? "OK" : "FAILED"); |
---|
[1] | 2051 | #else |
---|
| 2052 | ; |
---|
| 2053 | #endif |
---|
[392] | 2054 | char* toto=(char*)malloc((strlen(mapcs->name)+strlen(mapcs->value)+2)*sizeof(char)); |
---|
[364] | 2055 | sprintf(toto,"%s=%s",mapcs->name,mapcs->value); |
---|
[392] | 2056 | putenv(toto); |
---|
[1] | 2057 | #ifdef DEBUG |
---|
| 2058 | fflush(stderr); |
---|
| 2059 | #endif |
---|
| 2060 | #endif |
---|
| 2061 | #ifdef DEBUG |
---|
| 2062 | fprintf(stderr,"[ZOO: setenv (%s=%s)]\n",mapcs->name,mapcs->value); |
---|
| 2063 | fflush(stderr); |
---|
| 2064 | #endif |
---|
| 2065 | mapcs=mapcs->next; |
---|
| 2066 | } |
---|
| 2067 | } |
---|
| 2068 | |
---|
| 2069 | #ifdef DEBUG |
---|
| 2070 | dumpMap(request_inputs); |
---|
| 2071 | #endif |
---|
| 2072 | |
---|
| 2073 | /** |
---|
| 2074 | * Need to check if we need to fork to load a status enabled |
---|
| 2075 | */ |
---|
| 2076 | r_inputs=NULL; |
---|
[72] | 2077 | map* store=getMap(request_inputs,"storeExecuteResponse"); |
---|
| 2078 | map* status=getMap(request_inputs,"status"); |
---|
| 2079 | /** |
---|
| 2080 | * 05-007r7 WPS 1.0.0 page 57 : |
---|
| 2081 | * 'If status="true" and storeExecuteResponse is "false" then the service |
---|
| 2082 | * shall raise an exception.' |
---|
| 2083 | */ |
---|
| 2084 | if(status!=NULL && strcmp(status->value,"true")==0 && |
---|
| 2085 | store!=NULL && strcmp(store->value,"false")==0){ |
---|
| 2086 | errorException(m, _("Status cannot be set to true with storeExecuteResponse to false. Please, modify your request parameters."), "InvalidParameterValue"); |
---|
| 2087 | freeService(&s1); |
---|
| 2088 | free(s1); |
---|
| 2089 | freeMaps(&m); |
---|
| 2090 | free(m); |
---|
| 2091 | |
---|
| 2092 | freeMaps(&request_input_real_format); |
---|
| 2093 | free(request_input_real_format); |
---|
| 2094 | |
---|
| 2095 | freeMaps(&request_output_real_format); |
---|
| 2096 | free(request_output_real_format); |
---|
| 2097 | |
---|
| 2098 | free(REQUEST); |
---|
| 2099 | free(SERVICE_URL); |
---|
| 2100 | return 1; |
---|
| 2101 | } |
---|
[1] | 2102 | r_inputs=getMap(request_inputs,"storeExecuteResponse"); |
---|
| 2103 | int eres=SERVICE_STARTED; |
---|
| 2104 | int cpid=getpid(); |
---|
[94] | 2105 | |
---|
[32] | 2106 | maps *_tmpMaps=(maps*)malloc(MAPS_SIZE); |
---|
| 2107 | _tmpMaps->name=strdup("lenv"); |
---|
| 2108 | char tmpBuff[100]; |
---|
| 2109 | sprintf(tmpBuff,"%i",cpid); |
---|
| 2110 | _tmpMaps->content=createMap("sid",tmpBuff); |
---|
| 2111 | _tmpMaps->next=NULL; |
---|
| 2112 | addToMap(_tmpMaps->content,"status","0"); |
---|
[216] | 2113 | addToMap(_tmpMaps->content,"cwd",ntmp); |
---|
[280] | 2114 | map* ltmp=getMap(request_inputs,"soap"); |
---|
| 2115 | if(ltmp!=NULL) |
---|
| 2116 | addToMap(_tmpMaps->content,"soap",ltmp->value); |
---|
| 2117 | else |
---|
| 2118 | addToMap(_tmpMaps->content,"soap","false"); |
---|
[92] | 2119 | if(cgiCookie!=NULL && strlen(cgiCookie)>0){ |
---|
[390] | 2120 | int hasValidCookie=-1; |
---|
[342] | 2121 | char *tcook=strdup(cgiCookie); |
---|
[391] | 2122 | if(strstr(cgiCookie,";")!=NULL){ |
---|
[342] | 2123 | char *token,*saveptr; |
---|
| 2124 | token=strtok_r(cgiCookie,";",&saveptr); |
---|
| 2125 | while(token!=NULL){ |
---|
[392] | 2126 | if(strcasestr(token,"ID=")!=NULL){ |
---|
[342] | 2127 | if(tcook!=NULL) |
---|
| 2128 | free(tcook); |
---|
| 2129 | tcook=strdup(token); |
---|
[390] | 2130 | hasValidCookie=1; |
---|
[342] | 2131 | } |
---|
| 2132 | token=strtok_r(NULL,";",&saveptr); |
---|
| 2133 | } |
---|
[391] | 2134 | }else{ |
---|
[392] | 2135 | if(strstr(cgiCookie,"=")!=NULL && strcasestr(cgiCookie,"ID=")!=NULL){ |
---|
[391] | 2136 | tcook=strdup(cgiCookie); |
---|
| 2137 | hasValidCookie=1; |
---|
| 2138 | } |
---|
[342] | 2139 | } |
---|
[390] | 2140 | if(hasValidCookie>0){ |
---|
| 2141 | addToMap(_tmpMaps->content,"sessid",strstr(tcook,"=")+1); |
---|
| 2142 | char session_file_path[1024]; |
---|
| 2143 | map *tmpPath=getMapFromMaps(m,"main","sessPath"); |
---|
| 2144 | if(tmpPath==NULL) |
---|
| 2145 | tmpPath=getMapFromMaps(m,"main","tmpPath"); |
---|
| 2146 | char *tmp1=strtok(tcook,";"); |
---|
| 2147 | if(tmp1!=NULL) |
---|
| 2148 | sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,strstr(tmp1,"=")+1); |
---|
| 2149 | else |
---|
| 2150 | sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,strstr(cgiCookie,"=")+1); |
---|
| 2151 | free(tcook); |
---|
| 2152 | maps *tmpSess=(maps*)malloc(MAPS_SIZE); |
---|
| 2153 | struct stat file_status; |
---|
| 2154 | int istat = stat(session_file_path, &file_status); |
---|
| 2155 | if(istat==0 && file_status.st_size>0){ |
---|
| 2156 | conf_read(session_file_path,tmpSess); |
---|
| 2157 | addMapsToMaps(&m,tmpSess); |
---|
| 2158 | freeMaps(&tmpSess); |
---|
| 2159 | }else{ |
---|
| 2160 | errorException(m, _("Unable to read your session file."), "InternalError"); |
---|
| 2161 | free(tmpSess); |
---|
| 2162 | freeService(&s1); |
---|
| 2163 | free(s1); |
---|
| 2164 | freeMaps(&m); |
---|
| 2165 | free(m); |
---|
| 2166 | freeMaps(&request_input_real_format); |
---|
| 2167 | free(request_input_real_format); |
---|
| 2168 | freeMaps(&request_output_real_format); |
---|
| 2169 | free(request_output_real_format); |
---|
| 2170 | free(REQUEST); |
---|
| 2171 | free(SERVICE_URL); |
---|
| 2172 | return 1; |
---|
| 2173 | } |
---|
| 2174 | free(tmpSess); |
---|
[92] | 2175 | } |
---|
| 2176 | } |
---|
[32] | 2177 | addMapsToMaps(&m,_tmpMaps); |
---|
| 2178 | freeMaps(&_tmpMaps); |
---|
| 2179 | free(_tmpMaps); |
---|
| 2180 | |
---|
[1] | 2181 | #ifdef DEBUG |
---|
| 2182 | dumpMap(request_inputs); |
---|
| 2183 | #endif |
---|
[216] | 2184 | #ifdef WIN32 |
---|
| 2185 | char *cgiSidL=NULL; |
---|
| 2186 | if(getenv("CGISID")!=NULL) |
---|
[331] | 2187 | addToMap(request_inputs,"cgiSid",getenv("CGISID")); |
---|
[216] | 2188 | map* test1=getMap(request_inputs,"cgiSid"); |
---|
| 2189 | if(test1!=NULL){ |
---|
| 2190 | cgiSid=test1->value; |
---|
| 2191 | addToMap(request_inputs,"storeExecuteResponse","true"); |
---|
| 2192 | addToMap(request_inputs,"status","true"); |
---|
[384] | 2193 | setMapInMaps(m,"lenv","sid",test1->value); |
---|
[216] | 2194 | status=getMap(request_inputs,"status"); |
---|
[384] | 2195 | printf("cgiSid %s\n",cgiSid); |
---|
[216] | 2196 | } |
---|
| 2197 | #endif |
---|
[384] | 2198 | int hrstd=-1; |
---|
| 2199 | char *fbkp,*fbkp1; |
---|
| 2200 | FILE *f0,*f1; |
---|
[72] | 2201 | if(status!=NULL) |
---|
| 2202 | if(strcasecmp(status->value,"false")==0) |
---|
[364] | 2203 | status=NULLMAP; |
---|
[72] | 2204 | if(status==NULLMAP){ |
---|
[34] | 2205 | loadServiceAndRun(&m,s1,request_inputs,&request_input_real_format,&request_output_real_format,&eres); |
---|
| 2206 | } |
---|
[1] | 2207 | else{ |
---|
[364] | 2208 | int pid; |
---|
[1] | 2209 | #ifdef DEBUG |
---|
| 2210 | fprintf(stderr,"\nPID : %d\n",cpid); |
---|
| 2211 | #endif |
---|
[9] | 2212 | |
---|
[1] | 2213 | #ifndef WIN32 |
---|
[9] | 2214 | pid = fork (); |
---|
[1] | 2215 | #else |
---|
[216] | 2216 | if(cgiSid==NULL){ |
---|
| 2217 | createProcess(m,request_inputs,s1,NULL,cpid,request_input_real_format,request_output_real_format); |
---|
| 2218 | pid = cpid; |
---|
| 2219 | }else{ |
---|
| 2220 | pid=0; |
---|
| 2221 | cpid=atoi(cgiSid); |
---|
[384] | 2222 | printf("cgiSid %s\n",cgiSid); |
---|
[216] | 2223 | } |
---|
[384] | 2224 | //printf("pid cpid %d %d\n",pid,cpid); |
---|
| 2225 | //fflush(stderr); |
---|
[1] | 2226 | #endif |
---|
| 2227 | if (pid > 0) { |
---|
| 2228 | /** |
---|
| 2229 | * dady : |
---|
| 2230 | * set status to SERVICE_ACCEPTED |
---|
| 2231 | */ |
---|
| 2232 | #ifdef DEBUG |
---|
| 2233 | fprintf(stderr,"father pid continue (origin %d) %d ...\n",cpid,getpid()); |
---|
| 2234 | #endif |
---|
| 2235 | eres=SERVICE_ACCEPTED; |
---|
| 2236 | }else if (pid == 0) { |
---|
| 2237 | /** |
---|
| 2238 | * son : have to close the stdout, stdin and stderr to let the parent |
---|
| 2239 | * process answer to http client. |
---|
| 2240 | */ |
---|
| 2241 | r_inputs=getMapFromMaps(m,"main","tmpPath"); |
---|
[9] | 2242 | map* r_inputs1=getMap(s1->content,"ServiceProvider"); |
---|
[384] | 2243 | fbkp=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+1024)*sizeof(char)); |
---|
[9] | 2244 | sprintf(fbkp,"%s/%s_%d.xml",r_inputs->value,r_inputs1->value,cpid); |
---|
[384] | 2245 | char* flog=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+1024)*sizeof(char)); |
---|
[9] | 2246 | sprintf(flog,"%s/%s_%d_error.log",r_inputs->value,r_inputs1->value,cpid); |
---|
[1] | 2247 | #ifdef DEBUG |
---|
| 2248 | fprintf(stderr,"RUN IN BACKGROUND MODE \n"); |
---|
| 2249 | fprintf(stderr,"son pid continue (origin %d) %d ...\n",cpid,getpid()); |
---|
[9] | 2250 | fprintf(stderr,"\nFILE TO STORE DATA %s\n",r_inputs->value); |
---|
[1] | 2251 | #endif |
---|
[216] | 2252 | freopen(flog,"w+",stderr); |
---|
[384] | 2253 | f0=freopen(fbkp , "w+", stdout); |
---|
[1] | 2254 | fclose(stdin); |
---|
[9] | 2255 | free(flog); |
---|
[1] | 2256 | /** |
---|
| 2257 | * set status to SERVICE_STARTED and flush stdout to ensure full |
---|
| 2258 | * content was outputed (the file used to store the ResponseDocument). |
---|
| 2259 | * The rewind stdout to restart writing from the bgining of the file, |
---|
| 2260 | * this way the data will be updated at the end of the process run. |
---|
| 2261 | */ |
---|
[9] | 2262 | printProcessResponse(m,request_inputs,cpid, |
---|
[216] | 2263 | s1,r_inputs1->value,SERVICE_STARTED, |
---|
| 2264 | request_input_real_format, |
---|
| 2265 | request_output_real_format); |
---|
| 2266 | #ifndef WIN32 |
---|
[1] | 2267 | fflush(stdout); |
---|
| 2268 | rewind(stdout); |
---|
[384] | 2269 | #else |
---|
[216] | 2270 | #endif |
---|
[384] | 2271 | fbkp1=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+1024)*sizeof(char)); |
---|
| 2272 | sprintf(fbkp1,"%s/%s_final_%d.xml",r_inputs->value,r_inputs1->value,cpid); |
---|
| 2273 | f1=freopen(fbkp1 , "w+", stdout); |
---|
[34] | 2274 | loadServiceAndRun(&m,s1,request_inputs,&request_input_real_format,&request_output_real_format,&eres); |
---|
[1] | 2275 | } else { |
---|
| 2276 | /** |
---|
| 2277 | * error server don't accept the process need to output a valid |
---|
| 2278 | * error response here !!! |
---|
| 2279 | */ |
---|
[34] | 2280 | eres=-1; |
---|
| 2281 | errorException(m, _("Unable to run the child process properly"), "InternalError"); |
---|
[1] | 2282 | } |
---|
| 2283 | } |
---|
| 2284 | |
---|
| 2285 | #ifdef DEBUG |
---|
| 2286 | dumpMaps(request_output_real_format); |
---|
| 2287 | #endif |
---|
[9] | 2288 | if(eres!=-1) |
---|
| 2289 | outputResponse(s1,request_input_real_format, |
---|
| 2290 | request_output_real_format,request_inputs, |
---|
| 2291 | cpid,m,eres); |
---|
[216] | 2292 | fflush(stdout); |
---|
[105] | 2293 | /** |
---|
| 2294 | * Ensure that if error occurs when freeing memory, no signal will return |
---|
| 2295 | * an ExceptionReport document as the result was already returned to the |
---|
| 2296 | * client. |
---|
| 2297 | */ |
---|
| 2298 | #ifndef USE_GDB |
---|
| 2299 | (void) signal(SIGSEGV,donothing); |
---|
| 2300 | (void) signal(SIGTERM,donothing); |
---|
| 2301 | (void) signal(SIGINT,donothing); |
---|
| 2302 | (void) signal(SIGILL,donothing); |
---|
| 2303 | (void) signal(SIGFPE,donothing); |
---|
| 2304 | (void) signal(SIGABRT,donothing); |
---|
| 2305 | #endif |
---|
[1] | 2306 | |
---|
[32] | 2307 | if(((int)getpid())!=cpid){ |
---|
| 2308 | fclose(stdout); |
---|
| 2309 | fclose(stderr); |
---|
| 2310 | unhandleStatus(m); |
---|
[384] | 2311 | /** |
---|
| 2312 | * Dump back the final file fbkp1 to fbkp |
---|
| 2313 | */ |
---|
| 2314 | fclose(f0); |
---|
| 2315 | fclose(f1); |
---|
| 2316 | FILE* f2=fopen(fbkp1,"rb"); |
---|
| 2317 | FILE* f3=fopen(fbkp,"wb+"); |
---|
| 2318 | free(fbkp); |
---|
| 2319 | fseek(f2,0,SEEK_END); |
---|
| 2320 | long flen=ftell(f2); |
---|
| 2321 | fseek(f2,0,SEEK_SET); |
---|
| 2322 | char *tmps1=(char*)malloc((flen+1)*sizeof(char)); |
---|
| 2323 | fread(tmps1,flen,1,f2); |
---|
| 2324 | fwrite(tmps1,1,flen,f3); |
---|
| 2325 | fclose(f2); |
---|
| 2326 | fclose(f3); |
---|
[393] | 2327 | unlink(fbkp1); |
---|
| 2328 | free(fbkp1); |
---|
[32] | 2329 | } |
---|
| 2330 | |
---|
[9] | 2331 | freeService(&s1); |
---|
| 2332 | free(s1); |
---|
[59] | 2333 | freeMaps(&m); |
---|
[9] | 2334 | free(m); |
---|
| 2335 | |
---|
| 2336 | freeMaps(&request_input_real_format); |
---|
| 2337 | free(request_input_real_format); |
---|
[25] | 2338 | |
---|
[59] | 2339 | freeMaps(&request_output_real_format); |
---|
| 2340 | free(request_output_real_format); |
---|
[9] | 2341 | |
---|
| 2342 | free(REQUEST); |
---|
| 2343 | free(SERVICE_URL); |
---|
[1] | 2344 | #ifdef DEBUG |
---|
| 2345 | fprintf(stderr,"Processed response \n"); |
---|
| 2346 | fflush(stdout); |
---|
| 2347 | fflush(stderr); |
---|
| 2348 | #endif |
---|
| 2349 | |
---|
| 2350 | return 0; |
---|
| 2351 | } |
---|
[364] | 2352 | |
---|