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