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