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