[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 |
---|
[9] | 454 | r_inputs=getMap(request_inputs,"metapath"); |
---|
| 455 | if(r_inputs==NULL){ |
---|
| 456 | if(request_inputs==NULL) |
---|
| 457 | request_inputs=createMap("metapath",""); |
---|
| 458 | else |
---|
| 459 | addToMap(request_inputs,"metapath",""); |
---|
| 460 | #ifdef DEBUG |
---|
| 461 | fprintf(stderr,"ADD METAPATH\n"); |
---|
| 462 | dumpMap(request_inputs); |
---|
| 463 | #endif |
---|
| 464 | r_inputs=getMap(request_inputs,"metapath"); |
---|
| 465 | } |
---|
| 466 | char conf_file[10240]; |
---|
| 467 | snprintf(conf_file,10240,"%s/%s/main.cfg",ntmp,r_inputs->value); |
---|
[1] | 468 | conf_read(conf_file,m); |
---|
[9] | 469 | #ifdef DEBUG |
---|
| 470 | fprintf(stderr, "***** BEGIN MAPS\n"); |
---|
| 471 | dumpMaps(m); |
---|
| 472 | fprintf(stderr, "***** END MAPS\n"); |
---|
| 473 | #endif |
---|
| 474 | |
---|
[34] | 475 | bindtextdomain ("zoo-kernel","/usr/share/locale/"); |
---|
| 476 | bindtextdomain ("zoo-services","/usr/share/locale/"); |
---|
| 477 | |
---|
| 478 | if((r_inputs=getMap(request_inputs,"language"))!=NULL){ |
---|
| 479 | char *tmp=strdup(r_inputs->value); |
---|
| 480 | translateChar(tmp,'-','_'); |
---|
| 481 | setlocale (LC_ALL, tmp); |
---|
| 482 | free(tmp); |
---|
| 483 | setMapInMaps(m,"main","language",r_inputs->value); |
---|
| 484 | } |
---|
| 485 | else{ |
---|
| 486 | setlocale (LC_ALL, "en_US"); |
---|
| 487 | setMapInMaps(m,"main","language","en-US"); |
---|
| 488 | } |
---|
| 489 | setlocale (LC_NUMERIC, "en_US"); |
---|
| 490 | bind_textdomain_codeset("zoo-kernel","UTF-8"); |
---|
| 491 | textdomain("zoo-kernel"); |
---|
| 492 | bind_textdomain_codeset("zoo-services","UTF-8"); |
---|
| 493 | textdomain("zoo-services"); |
---|
| 494 | |
---|
[280] | 495 | map* lsoap=getMap(request_inputs,"soap"); |
---|
| 496 | if(lsoap!=NULL && strcasecmp(lsoap->value,"true")==0) |
---|
| 497 | setMapInMaps(m,"main","isSoap","true"); |
---|
| 498 | else |
---|
| 499 | setMapInMaps(m,"main","isSoap","false"); |
---|
[34] | 500 | |
---|
[1] | 501 | /** |
---|
| 502 | * Check for minimum inputs |
---|
| 503 | */ |
---|
| 504 | r_inputs=getMap(request_inputs,"Request"); |
---|
[9] | 505 | if(request_inputs==NULL || r_inputs==NULL){ |
---|
[34] | 506 | errorException(m, _("Parameter <request> was not specified"),"MissingParameterValue"); |
---|
[9] | 507 | freeMaps(&m); |
---|
| 508 | free(m); |
---|
[60] | 509 | freeMap(&request_inputs); |
---|
| 510 | free(request_inputs); |
---|
| 511 | free(REQUEST); |
---|
[1] | 512 | return 1; |
---|
| 513 | } |
---|
[9] | 514 | else{ |
---|
[1] | 515 | REQUEST=strdup(r_inputs->value); |
---|
[9] | 516 | if(strncasecmp(r_inputs->value,"GetCapabilities",15)!=0 |
---|
| 517 | && strncasecmp(r_inputs->value,"DescribeProcess",15)!=0 |
---|
| 518 | && strncasecmp(r_inputs->value,"Execute",7)!=0){ |
---|
[34] | 519 | errorException(m, _("Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."), "InvalidParameterValue"); |
---|
[9] | 520 | freeMaps(&m); |
---|
| 521 | free(m); |
---|
| 522 | free(REQUEST); |
---|
| 523 | return 1; |
---|
| 524 | } |
---|
| 525 | } |
---|
[1] | 526 | r_inputs=NULL; |
---|
| 527 | r_inputs=getMap(request_inputs,"Service"); |
---|
[9] | 528 | if(r_inputs==NULLMAP){ |
---|
[34] | 529 | errorException(m, _("Parameter <service> was not specified"),"MissingParameterValue"); |
---|
[9] | 530 | freeMaps(&m); |
---|
| 531 | free(m); |
---|
| 532 | free(REQUEST); |
---|
[1] | 533 | return 1; |
---|
| 534 | } |
---|
[9] | 535 | if(strncasecmp(REQUEST,"GetCapabilities",15)!=0){ |
---|
[1] | 536 | r_inputs=getMap(request_inputs,"Version"); |
---|
| 537 | if(r_inputs==NULL){ |
---|
[34] | 538 | errorException(m, _("Parameter <version> was not specified"),"MissingParameterValue"); |
---|
[9] | 539 | freeMaps(&m); |
---|
| 540 | free(m); |
---|
| 541 | free(REQUEST); |
---|
[1] | 542 | return 1; |
---|
| 543 | } |
---|
| 544 | } |
---|
| 545 | |
---|
[9] | 546 | r_inputs=getMap(request_inputs,"serviceprovider"); |
---|
| 547 | if(r_inputs==NULL){ |
---|
| 548 | addToMap(request_inputs,"serviceprovider",""); |
---|
[1] | 549 | } |
---|
| 550 | |
---|
| 551 | maps* request_output_real_format=NULL; |
---|
| 552 | map* tmpm=getMapFromMaps(m,"main","serverAddress"); |
---|
| 553 | if(tmpm!=NULL) |
---|
| 554 | SERVICE_URL=strdup(tmpm->value); |
---|
| 555 | else |
---|
[63] | 556 | SERVICE_URL=strdup(DEFAULT_SERVICE_URL); |
---|
[1] | 557 | |
---|
| 558 | service* s1; |
---|
| 559 | int scount=0; |
---|
| 560 | |
---|
| 561 | #ifdef DEBUG |
---|
| 562 | dumpMap(r_inputs); |
---|
| 563 | #endif |
---|
| 564 | char conf_dir[1024]; |
---|
| 565 | int t; |
---|
| 566 | char tmps1[1024]; |
---|
| 567 | |
---|
[9] | 568 | r_inputs=NULL; |
---|
| 569 | r_inputs=getMap(request_inputs,"metapath"); |
---|
| 570 | if(r_inputs!=NULL) |
---|
| 571 | snprintf(conf_dir,1024,"%s/%s",ntmp,r_inputs->value); |
---|
| 572 | else |
---|
| 573 | snprintf(conf_dir,1024,"%s",ntmp); |
---|
| 574 | |
---|
| 575 | if(strncasecmp(REQUEST,"GetCapabilities",15)==0){ |
---|
[1] | 576 | struct dirent *dp; |
---|
| 577 | #ifdef DEBUG |
---|
| 578 | dumpMap(r_inputs); |
---|
| 579 | #endif |
---|
[9] | 580 | DIR *dirp = opendir(conf_dir); |
---|
[1] | 581 | if(dirp==NULL){ |
---|
[34] | 582 | return errorException(m, _("The specified path doesn't exist."),"InvalidParameterValue"); |
---|
[1] | 583 | } |
---|
| 584 | xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); |
---|
| 585 | r_inputs=NULL; |
---|
| 586 | r_inputs=getMap(request_inputs,"ServiceProvider"); |
---|
[9] | 587 | xmlNodePtr n; |
---|
| 588 | if(r_inputs!=NULL) |
---|
| 589 | n = printGetCapabilitiesHeader(doc,r_inputs->value,m); |
---|
| 590 | else |
---|
| 591 | n = printGetCapabilitiesHeader(doc,"",m); |
---|
[1] | 592 | /** |
---|
[214] | 593 | * Here we need to close stdout to ensure that not supported chars |
---|
| 594 | * has been found in the zcfg and then printed on stdout |
---|
[1] | 595 | */ |
---|
| 596 | int saved_stdout = dup(fileno(stdout)); |
---|
| 597 | dup2(fileno(stderr),fileno(stdout)); |
---|
| 598 | while ((dp = readdir(dirp)) != NULL) |
---|
| 599 | if(strstr(dp->d_name,".zcfg")!=0){ |
---|
[9] | 600 | memset(tmps1,0,1024); |
---|
| 601 | snprintf(tmps1,1024,"%s/%s",conf_dir,dp->d_name); |
---|
| 602 | s1=(service*)calloc(1,SERVICE_SIZE); |
---|
| 603 | if(s1 == NULL){ |
---|
[34] | 604 | return errorException(m, _("Unable to allocate memory."),"InternalError"); |
---|
[9] | 605 | } |
---|
[1] | 606 | #ifdef DEBUG |
---|
| 607 | fprintf(stderr,"#################\n%s\n#################\n",tmps1); |
---|
| 608 | #endif |
---|
| 609 | t=getServiceFromFile(tmps1,&s1); |
---|
| 610 | #ifdef DEBUG |
---|
| 611 | dumpService(s1); |
---|
| 612 | fflush(stdout); |
---|
| 613 | fflush(stderr); |
---|
| 614 | #endif |
---|
| 615 | printGetCapabilitiesForProcess(m,n,s1); |
---|
[9] | 616 | freeService(&s1); |
---|
| 617 | free(s1); |
---|
[1] | 618 | scount++; |
---|
| 619 | } |
---|
| 620 | (void)closedir(dirp); |
---|
| 621 | fflush(stdout); |
---|
| 622 | dup2(saved_stdout,fileno(stdout)); |
---|
[9] | 623 | printDocument(m,doc,getpid()); |
---|
| 624 | freeMaps(&m); |
---|
| 625 | free(m); |
---|
| 626 | free(REQUEST); |
---|
| 627 | free(SERVICE_URL); |
---|
[1] | 628 | fflush(stdout); |
---|
| 629 | return 0; |
---|
| 630 | } |
---|
| 631 | else{ |
---|
| 632 | r_inputs=getMap(request_inputs,"Identifier"); |
---|
| 633 | if(r_inputs==NULL |
---|
| 634 | || strlen(r_inputs->name)==0 || strlen(r_inputs->value)==0){ |
---|
[34] | 635 | errorException(m, _("Mandatory <identifier> was not specified"),"MissingParameterValue"); |
---|
[9] | 636 | freeMaps(&m); |
---|
| 637 | free(m); |
---|
| 638 | free(REQUEST); |
---|
| 639 | free(SERVICE_URL); |
---|
| 640 | return 0; |
---|
[1] | 641 | } |
---|
| 642 | |
---|
| 643 | struct dirent *dp; |
---|
| 644 | DIR *dirp = opendir(conf_dir); |
---|
| 645 | if(dirp==NULL){ |
---|
[34] | 646 | errorException(m, _("The specified path path doesn't exist."),"InvalidParameterValue"); |
---|
[9] | 647 | freeMaps(&m); |
---|
| 648 | free(m); |
---|
| 649 | free(REQUEST); |
---|
| 650 | free(SERVICE_URL); |
---|
| 651 | return 0; |
---|
[1] | 652 | } |
---|
[9] | 653 | if(strncasecmp(REQUEST,"DescribeProcess",15)==0){ |
---|
[1] | 654 | /** |
---|
| 655 | * Loop over Identifier list |
---|
| 656 | */ |
---|
| 657 | xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); |
---|
| 658 | r_inputs=NULL; |
---|
| 659 | r_inputs=getMap(request_inputs,"ServiceProvider"); |
---|
[9] | 660 | |
---|
[1] | 661 | xmlNodePtr n; |
---|
| 662 | if(r_inputs!=NULL) |
---|
| 663 | n = printDescribeProcessHeader(doc,r_inputs->value,m); |
---|
[9] | 664 | else |
---|
| 665 | n = printDescribeProcessHeader(doc,"",m); |
---|
[1] | 666 | |
---|
| 667 | r_inputs=getMap(request_inputs,"Identifier"); |
---|
| 668 | char *tmps=strtok(r_inputs->value,","); |
---|
| 669 | |
---|
| 670 | char buff[256]; |
---|
| 671 | char buff1[1024]; |
---|
| 672 | int saved_stdout = dup(fileno(stdout)); |
---|
| 673 | dup2(fileno(stderr),fileno(stdout)); |
---|
| 674 | while(tmps){ |
---|
| 675 | memset(buff,0,256); |
---|
[9] | 676 | snprintf(buff,256,"%s.zcfg",tmps); |
---|
[1] | 677 | memset(buff1,0,1024); |
---|
| 678 | #ifdef DEBUG |
---|
| 679 | fprintf(stderr,"\n#######%s\n########\n",buff1); |
---|
| 680 | #endif |
---|
| 681 | while ((dp = readdir(dirp)) != NULL) |
---|
[260] | 682 | if((strcasecmp("all.zcfg",buff)==0 && strstr(dp->d_name,".zcfg")>0) |
---|
| 683 | || strcasecmp(dp->d_name,buff)==0){ |
---|
[1] | 684 | memset(buff1,0,1024); |
---|
[9] | 685 | snprintf(buff1,1024,"%s/%s",conf_dir,dp->d_name); |
---|
| 686 | s1=(service*)calloc(1,SERVICE_SIZE); |
---|
| 687 | if(s1 == NULL){ |
---|
[34] | 688 | return errorException(m, _("Unable to allocate memory."),"InternalError"); |
---|
[9] | 689 | } |
---|
[1] | 690 | #ifdef DEBUG |
---|
[9] | 691 | fprintf(stderr,"#################\n%s\n#################\n",buff1); |
---|
[1] | 692 | #endif |
---|
| 693 | t=getServiceFromFile(buff1,&s1); |
---|
[9] | 694 | #ifdef DEBUG |
---|
| 695 | dumpService(s1); |
---|
| 696 | #endif |
---|
| 697 | printDescribeProcessForProcess(m,n,s1,1); |
---|
| 698 | freeService(&s1); |
---|
| 699 | free(s1); |
---|
[1] | 700 | scount++; |
---|
| 701 | } |
---|
| 702 | rewinddir(dirp); |
---|
| 703 | tmps=strtok(NULL,","); |
---|
| 704 | } |
---|
[9] | 705 | closedir(dirp); |
---|
[1] | 706 | fflush(stdout); |
---|
| 707 | dup2(saved_stdout,fileno(stdout)); |
---|
[9] | 708 | printDocument(m,doc,getpid()); |
---|
| 709 | freeMaps(&m); |
---|
| 710 | free(m); |
---|
| 711 | free(REQUEST); |
---|
| 712 | free(SERVICE_URL); |
---|
[1] | 713 | fflush(stdout); |
---|
| 714 | #ifndef LINUX_FREE_ISSUE |
---|
[9] | 715 | if(s1) |
---|
| 716 | free(s1); |
---|
[1] | 717 | #endif |
---|
| 718 | return 0; |
---|
| 719 | } |
---|
| 720 | else |
---|
[9] | 721 | if(strncasecmp(REQUEST,"Execute",strlen(REQUEST))!=0){ |
---|
[34] | 722 | errorException(m, _("Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."), "InvalidParameterValue"); |
---|
[1] | 723 | #ifdef DEBUG |
---|
| 724 | fprintf(stderr,"No request found %s",REQUEST); |
---|
| 725 | #endif |
---|
[9] | 726 | closedir(dirp); |
---|
[1] | 727 | return 0; |
---|
| 728 | } |
---|
[9] | 729 | closedir(dirp); |
---|
[1] | 730 | } |
---|
| 731 | |
---|
| 732 | s1=NULL; |
---|
[9] | 733 | s1=(service*)calloc(1,SERVICE_SIZE); |
---|
| 734 | if(s1 == NULL){ |
---|
[32] | 735 | freeMaps(&m); |
---|
| 736 | free(m); |
---|
| 737 | free(REQUEST); |
---|
| 738 | free(SERVICE_URL); |
---|
[34] | 739 | return errorException(m, _("Unable to allocate memory."),"InternalError"); |
---|
[9] | 740 | } |
---|
[1] | 741 | r_inputs=getMap(request_inputs,"MetaPath"); |
---|
[9] | 742 | if(r_inputs!=NULL) |
---|
| 743 | snprintf(tmps1,1024,"%s/%s",ntmp,r_inputs->value); |
---|
| 744 | else |
---|
| 745 | snprintf(tmps1,1024,"%s/",ntmp); |
---|
[1] | 746 | r_inputs=getMap(request_inputs,"Identifier"); |
---|
[9] | 747 | char *ttmp=strdup(tmps1); |
---|
| 748 | snprintf(tmps1,1024,"%s/%s.zcfg",ttmp,r_inputs->value); |
---|
| 749 | free(ttmp); |
---|
[1] | 750 | #ifdef DEBUG |
---|
| 751 | fprintf(stderr,"Trying to load %s\n", tmps1); |
---|
| 752 | #endif |
---|
| 753 | int saved_stdout = dup(fileno(stdout)); |
---|
[216] | 754 | dup2(fileno(stderr),fileno(stdout)); |
---|
[1] | 755 | t=getServiceFromFile(tmps1,&s1); |
---|
| 756 | fflush(stdout); |
---|
| 757 | dup2(saved_stdout,fileno(stdout)); |
---|
[32] | 758 | if(t<0){ |
---|
[216] | 759 | char *tmpMsg=(char*)malloc(2048+strlen(r_inputs->value)); |
---|
| 760 | |
---|
[34] | 761 | 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] | 762 | errorException(m, tmpMsg, "InvalidParameterValue"); |
---|
[216] | 763 | free(tmpMsg); |
---|
[32] | 764 | freeService(&s1); |
---|
| 765 | free(s1); |
---|
| 766 | freeMaps(&m); |
---|
| 767 | free(m); |
---|
| 768 | free(REQUEST); |
---|
| 769 | free(SERVICE_URL); |
---|
| 770 | return 0; |
---|
[1] | 771 | } |
---|
[258] | 772 | close(saved_stdout); |
---|
[1] | 773 | |
---|
| 774 | #ifdef DEBUG |
---|
| 775 | dumpService(s1); |
---|
| 776 | #endif |
---|
| 777 | int j; |
---|
| 778 | |
---|
| 779 | /** |
---|
| 780 | * Create the input maps data structure |
---|
| 781 | */ |
---|
| 782 | int i=0; |
---|
| 783 | HINTERNET hInternet; |
---|
| 784 | HINTERNET res; |
---|
| 785 | hInternet=InternetOpen( |
---|
| 786 | #ifndef WIN32 |
---|
| 787 | (LPCTSTR) |
---|
| 788 | #endif |
---|
| 789 | "ZooWPSClient\0", |
---|
| 790 | INTERNET_OPEN_TYPE_PRECONFIG, |
---|
| 791 | NULL,NULL, 0); |
---|
| 792 | |
---|
| 793 | #ifndef WIN32 |
---|
| 794 | if(!CHECK_INET_HANDLE(hInternet)) |
---|
| 795 | fprintf(stderr,"WARNING : hInternet handle failed to initialize"); |
---|
| 796 | #endif |
---|
| 797 | maps* request_input_real_format=NULL; |
---|
| 798 | maps* tmpmaps = request_input_real_format; |
---|
| 799 | map* postRequest=NULL; |
---|
| 800 | postRequest=getMap(request_inputs,"xrequest"); |
---|
| 801 | if(postRequest==NULLMAP){ |
---|
| 802 | /** |
---|
| 803 | * Parsing outputs provided as KVP |
---|
| 804 | */ |
---|
| 805 | r_inputs=NULL; |
---|
| 806 | #ifdef DEBUG |
---|
| 807 | fprintf(stderr,"OUTPUT Parsing ... \n"); |
---|
| 808 | #endif |
---|
| 809 | r_inputs=getMap(request_inputs,"ResponseDocument"); |
---|
[9] | 810 | if(r_inputs==NULL) r_inputs=getMap(request_inputs,"RawDataOutput"); |
---|
| 811 | |
---|
[32] | 812 | #ifdef DEBUG |
---|
[1] | 813 | fprintf(stderr,"OUTPUT Parsing ... \n"); |
---|
[32] | 814 | #endif |
---|
[9] | 815 | if(r_inputs!=NULL){ |
---|
[32] | 816 | #ifdef DEBUG |
---|
[1] | 817 | fprintf(stderr,"OUTPUT Parsing start now ... \n"); |
---|
[32] | 818 | #endif |
---|
[1] | 819 | char cursor_output[10240]; |
---|
[9] | 820 | char *cotmp=strdup(r_inputs->value); |
---|
| 821 | snprintf(cursor_output,10240,"%s",cotmp); |
---|
| 822 | free(cotmp); |
---|
[1] | 823 | j=0; |
---|
| 824 | |
---|
| 825 | /** |
---|
| 826 | * Put each Output into the outputs_as_text array |
---|
| 827 | */ |
---|
| 828 | char * pToken; |
---|
| 829 | maps* tmp_output=NULL; |
---|
| 830 | #ifdef DEBUG |
---|
| 831 | fprintf(stderr,"OUTPUT [%s]\n",cursor_output); |
---|
| 832 | #endif |
---|
| 833 | pToken=strtok(cursor_output,";"); |
---|
[9] | 834 | char** outputs_as_text=(char**)calloc(128,sizeof(char*)); |
---|
| 835 | if(outputs_as_text == NULL) { |
---|
[34] | 836 | return errorException(m, _("Unable to allocate memory"), "InternalError"); |
---|
[9] | 837 | } |
---|
[1] | 838 | i=0; |
---|
| 839 | while(pToken!=NULL){ |
---|
| 840 | #ifdef DEBUG |
---|
| 841 | fprintf(stderr,"***%s***\n",pToken); |
---|
| 842 | fflush(stderr); |
---|
| 843 | fprintf(stderr,"***%s***\n",pToken); |
---|
| 844 | #endif |
---|
[9] | 845 | outputs_as_text[i]=(char*)calloc(strlen(pToken)+1,sizeof(char)); |
---|
| 846 | if(outputs_as_text[i] == NULL) { |
---|
[34] | 847 | return errorException(m, _("Unable to allocate memory"), "InternalError"); |
---|
[9] | 848 | } |
---|
| 849 | snprintf(outputs_as_text[i],strlen(pToken)+1,"%s",pToken); |
---|
[1] | 850 | pToken = strtok(NULL,";"); |
---|
| 851 | i++; |
---|
| 852 | } |
---|
| 853 | for(j=0;j<i;j++){ |
---|
| 854 | char *tmp=strdup(outputs_as_text[j]); |
---|
[9] | 855 | free(outputs_as_text[j]); |
---|
[1] | 856 | char *tmpc; |
---|
| 857 | tmpc=strtok(tmp,"@"); |
---|
| 858 | int k=0; |
---|
| 859 | while(tmpc!=NULL){ |
---|
| 860 | if(k==0){ |
---|
| 861 | if(tmp_output==NULL){ |
---|
[9] | 862 | tmp_output=(maps*)calloc(1,MAPS_SIZE); |
---|
| 863 | if(tmp_output == NULL){ |
---|
[34] | 864 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 865 | } |
---|
[1] | 866 | tmp_output->name=strdup(tmpc); |
---|
| 867 | tmp_output->content=NULL; |
---|
| 868 | tmp_output->next=NULL; |
---|
| 869 | } |
---|
| 870 | } |
---|
| 871 | else{ |
---|
| 872 | char *tmpv=strstr(tmpc,"="); |
---|
| 873 | char tmpn[256]; |
---|
| 874 | memset(tmpn,0,256); |
---|
| 875 | strncpy(tmpn,tmpc,(strlen(tmpc)-strlen(tmpv))*sizeof(char)); |
---|
| 876 | tmpn[strlen(tmpc)-strlen(tmpv)]=0; |
---|
| 877 | #ifdef DEBUG |
---|
| 878 | fprintf(stderr,"OUTPUT DEF [%s]=[%s]\n",tmpn,tmpv+1); |
---|
| 879 | #endif |
---|
| 880 | if(tmp_output->content==NULL){ |
---|
| 881 | tmp_output->content=createMap(tmpn,tmpv+1); |
---|
| 882 | tmp_output->content->next=NULL; |
---|
| 883 | } |
---|
| 884 | else |
---|
| 885 | addToMap(tmp_output->content,tmpn,tmpv+1); |
---|
| 886 | } |
---|
| 887 | k++; |
---|
| 888 | #ifdef DEBUG |
---|
| 889 | fprintf(stderr,"***%s***\n",tmpc); |
---|
| 890 | #endif |
---|
| 891 | tmpc=strtok(NULL,"@"); |
---|
| 892 | } |
---|
| 893 | if(request_output_real_format==NULL) |
---|
[9] | 894 | request_output_real_format=dupMaps(&tmp_output); |
---|
[1] | 895 | else |
---|
| 896 | addMapsToMaps(&request_output_real_format,tmp_output); |
---|
[9] | 897 | freeMaps(&tmp_output); |
---|
| 898 | free(tmp_output); |
---|
| 899 | tmp_output=NULL; |
---|
[1] | 900 | #ifdef DEBUG |
---|
| 901 | dumpMaps(tmp_output); |
---|
| 902 | fflush(stderr); |
---|
| 903 | #endif |
---|
[9] | 904 | free(tmp); |
---|
[1] | 905 | } |
---|
[9] | 906 | free(outputs_as_text); |
---|
[1] | 907 | } |
---|
| 908 | |
---|
| 909 | |
---|
| 910 | /** |
---|
| 911 | * Parsing inputs provided as KVP |
---|
| 912 | */ |
---|
| 913 | r_inputs=getMap(request_inputs,"DataInputs"); |
---|
| 914 | #ifdef DEBUG |
---|
| 915 | fprintf(stderr,"DATA INPUTS [%s]\n",r_inputs->value); |
---|
| 916 | #endif |
---|
| 917 | char cursor_input[40960]; |
---|
[9] | 918 | if(r_inputs!=NULL) |
---|
| 919 | snprintf(cursor_input,40960,"%s",r_inputs->value); |
---|
| 920 | else{ |
---|
[34] | 921 | errorException(m, _("Parameter <DataInputs> was not specified"),"MissingParameterValue"); |
---|
[9] | 922 | freeMaps(&m); |
---|
| 923 | free(m); |
---|
| 924 | free(REQUEST); |
---|
| 925 | free(SERVICE_URL); |
---|
[57] | 926 | InternetCloseHandle(hInternet); |
---|
| 927 | freeService(&s1); |
---|
| 928 | free(s1); |
---|
[9] | 929 | return 0; |
---|
| 930 | } |
---|
[1] | 931 | j=0; |
---|
| 932 | |
---|
| 933 | /** |
---|
| 934 | * Put each DataInputs into the inputs_as_text array |
---|
| 935 | */ |
---|
| 936 | char * pToken; |
---|
| 937 | pToken=strtok(cursor_input,";"); |
---|
[9] | 938 | char** inputs_as_text=(char**)calloc(100,sizeof(char*)); |
---|
| 939 | if(inputs_as_text == NULL){ |
---|
[34] | 940 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 941 | } |
---|
[1] | 942 | i=0; |
---|
| 943 | while(pToken!=NULL){ |
---|
| 944 | #ifdef DEBUG |
---|
| 945 | fprintf(stderr,"***%s***\n",pToken); |
---|
| 946 | #endif |
---|
| 947 | fflush(stderr); |
---|
| 948 | #ifdef DEBUG |
---|
| 949 | fprintf(stderr,"***%s***\n",pToken); |
---|
| 950 | #endif |
---|
[9] | 951 | inputs_as_text[i]=(char*)calloc(strlen(pToken)+1,sizeof(char)); |
---|
| 952 | snprintf(inputs_as_text[i],strlen(pToken)+1,"%s",pToken); |
---|
| 953 | if(inputs_as_text[i] == NULL){ |
---|
[34] | 954 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 955 | } |
---|
[1] | 956 | pToken = strtok(NULL,";"); |
---|
| 957 | i++; |
---|
| 958 | } |
---|
| 959 | |
---|
| 960 | for(j=0;j<i;j++){ |
---|
| 961 | char *tmp=strdup(inputs_as_text[j]); |
---|
[9] | 962 | free(inputs_as_text[j]); |
---|
[1] | 963 | char *tmpc; |
---|
| 964 | tmpc=strtok(tmp,"@"); |
---|
| 965 | while(tmpc!=NULL){ |
---|
| 966 | #ifdef DEBUG |
---|
| 967 | fprintf(stderr,"***\n***%s***\n",tmpc); |
---|
| 968 | #endif |
---|
| 969 | char *tmpv=strstr(tmpc,"="); |
---|
| 970 | char tmpn[256]; |
---|
| 971 | memset(tmpn,0,256); |
---|
[216] | 972 | if(tmpv!=NULL){ |
---|
| 973 | strncpy(tmpn,tmpc,(strlen(tmpc)-strlen(tmpv))*sizeof(char)); |
---|
| 974 | tmpn[strlen(tmpc)-strlen(tmpv)]=0; |
---|
| 975 | } |
---|
| 976 | else{ |
---|
| 977 | strncpy(tmpn,tmpc,strlen(tmpc)*sizeof(char)); |
---|
| 978 | tmpn[strlen(tmpc)]=0; |
---|
| 979 | } |
---|
[1] | 980 | #ifdef DEBUG |
---|
| 981 | fprintf(stderr,"***\n*** %s = %s ***\n",tmpn,tmpv+1); |
---|
| 982 | #endif |
---|
| 983 | if(tmpmaps==NULL){ |
---|
[9] | 984 | tmpmaps=(maps*)calloc(1,MAPS_SIZE); |
---|
| 985 | if(tmpmaps == NULL){ |
---|
[34] | 986 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 987 | } |
---|
[1] | 988 | tmpmaps->name=strdup(tmpn); |
---|
[216] | 989 | if(tmpv!=NULL) |
---|
| 990 | tmpmaps->content=createMap("value",tmpv+1); |
---|
| 991 | else |
---|
| 992 | tmpmaps->content=createMap("value","Reference"); |
---|
[1] | 993 | tmpmaps->next=NULL; |
---|
| 994 | } |
---|
| 995 | tmpc=strtok(NULL,"@"); |
---|
| 996 | while(tmpc!=NULL){ |
---|
| 997 | #ifdef DEBUG |
---|
| 998 | fprintf(stderr,"*** KVP NON URL-ENCODED \n***%s***\n",tmpc); |
---|
| 999 | #endif |
---|
| 1000 | char *tmpv1=strstr(tmpc,"="); |
---|
| 1001 | #ifdef DEBUG |
---|
| 1002 | fprintf(stderr,"*** VALUE NON URL-ENCODED \n***%s***\n",tmpv1+1); |
---|
| 1003 | #endif |
---|
| 1004 | char tmpn1[1024]; |
---|
| 1005 | memset(tmpn1,0,1024); |
---|
[216] | 1006 | if(tmpv1!=NULL){ |
---|
| 1007 | strncpy(tmpn1,tmpc,strlen(tmpc)-strlen(tmpv1)); |
---|
| 1008 | tmpn1[strlen(tmpc)-strlen(tmpv1)]=0; |
---|
| 1009 | addToMap(tmpmaps->content,tmpn1,tmpv1+1); |
---|
| 1010 | } |
---|
| 1011 | else{ |
---|
| 1012 | strncpy(tmpn1,tmpc,strlen(tmpc)); |
---|
| 1013 | tmpn1[strlen(tmpc)]=0; |
---|
| 1014 | map* lmap=getLastMap(tmpmaps->content); |
---|
| 1015 | char *tmpValue=(char*)calloc((strlen(lmap->value)+strlen(tmpc)+1),sizeof(char)); |
---|
| 1016 | sprintf(tmpValue,"%s@%s",lmap->value,tmpc); |
---|
| 1017 | free(lmap->value); |
---|
| 1018 | lmap->value=strdup(tmpValue); |
---|
| 1019 | free(tmpValue); |
---|
| 1020 | tmpc=strtok(NULL,"@"); |
---|
| 1021 | continue; |
---|
| 1022 | } |
---|
[1] | 1023 | #ifdef DEBUG |
---|
| 1024 | fprintf(stderr,"*** NAME NON URL-ENCODED \n***%s***\n",tmpn1); |
---|
| 1025 | fprintf(stderr,"*** VALUE NON URL-ENCODED \n***%s***\n",tmpv1+1); |
---|
| 1026 | #endif |
---|
| 1027 | if(strcmp(tmpn1,"xlink:href")!=0) |
---|
| 1028 | addToMap(tmpmaps->content,tmpn1,tmpv1+1); |
---|
[216] | 1029 | else |
---|
| 1030 | if(tmpv1!=NULL){ |
---|
| 1031 | if(strncasecmp(tmpv1+1,"http://",7)!=0 && |
---|
| 1032 | strncasecmp(tmpv1+1,"ftp://",6)!=0){ |
---|
| 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 |
---|
[280] | 1048 | char *tmpx=url_encode(tmpv1+1); |
---|
| 1049 | addToMap(tmpmaps->content,tmpn1,tmpx); |
---|
| 1050 | |
---|
[1] | 1051 | #ifndef WIN32 |
---|
[216] | 1052 | if(CHECK_INET_HANDLE(hInternet)) |
---|
[1] | 1053 | #endif |
---|
[216] | 1054 | { |
---|
[281] | 1055 | loadRemoteFile(m,tmpmaps->content,hInternet,tmpv1+1); |
---|
[58] | 1056 | } |
---|
[280] | 1057 | char *tmpx1=url_encode(tmpv1+1); |
---|
| 1058 | addToMap(tmpmaps->content,tmpn1,tmpx1); |
---|
| 1059 | free(tmpx1); |
---|
[216] | 1060 | addToMap(tmpmaps->content,"Reference",tmpv1+1); |
---|
| 1061 | } |
---|
[1] | 1062 | tmpc=strtok(NULL,"@"); |
---|
| 1063 | } |
---|
| 1064 | #ifdef DEBUG |
---|
| 1065 | dumpMaps(tmpmaps); |
---|
| 1066 | fflush(stderr); |
---|
| 1067 | #endif |
---|
[9] | 1068 | if(request_input_real_format==NULL) |
---|
| 1069 | request_input_real_format=dupMaps(&tmpmaps); |
---|
| 1070 | else |
---|
| 1071 | addMapsToMaps(&request_input_real_format,tmpmaps); |
---|
| 1072 | freeMaps(&tmpmaps); |
---|
| 1073 | free(tmpmaps); |
---|
| 1074 | tmpmaps=NULL; |
---|
| 1075 | free(tmp); |
---|
[1] | 1076 | } |
---|
| 1077 | } |
---|
[9] | 1078 | free(inputs_as_text); |
---|
| 1079 | } |
---|
[1] | 1080 | else { |
---|
[9] | 1081 | /** |
---|
| 1082 | * Parse XML request |
---|
| 1083 | */ |
---|
[1] | 1084 | xmlInitParser(); |
---|
| 1085 | #ifdef DEBUG |
---|
| 1086 | fflush(stderr); |
---|
| 1087 | fprintf(stderr,"BEFORE %s\n",postRequest->value); |
---|
| 1088 | fflush(stderr); |
---|
| 1089 | #endif |
---|
| 1090 | xmlDocPtr doc = |
---|
[5] | 1091 | xmlParseMemory(postRequest->value,cgiContentLength); |
---|
[1] | 1092 | #ifdef DEBUG |
---|
| 1093 | fprintf(stderr,"AFTER\n"); |
---|
| 1094 | fflush(stderr); |
---|
| 1095 | #endif |
---|
| 1096 | /** |
---|
| 1097 | * Parse every Input in DataInputs node. |
---|
| 1098 | */ |
---|
[9] | 1099 | xmlXPathObjectPtr tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='Input']"); |
---|
| 1100 | xmlNodeSet* tmps=tmpsptr->nodesetval; |
---|
[1] | 1101 | #ifdef DEBUG |
---|
| 1102 | fprintf(stderr,"*****%d*****\n",tmps->nodeNr); |
---|
| 1103 | #endif |
---|
| 1104 | for(int k=0;k<tmps->nodeNr;k++){ |
---|
| 1105 | maps *tmpmaps=NULL; |
---|
| 1106 | xmlNodePtr cur=tmps->nodeTab[k]; |
---|
| 1107 | if(tmps->nodeTab[k]->type == XML_ELEMENT_NODE) { |
---|
| 1108 | /** |
---|
| 1109 | * A specific Input node. |
---|
| 1110 | */ |
---|
| 1111 | #ifdef DEBUG |
---|
| 1112 | fprintf(stderr, "= element 0 node \"%s\"\n", cur->name); |
---|
| 1113 | #endif |
---|
[9] | 1114 | xmlNodePtr cur2=cur->children; |
---|
[32] | 1115 | while(cur2!=NULL){ |
---|
| 1116 | while(cur2!=NULL && cur2->type!=XML_ELEMENT_NODE) |
---|
[9] | 1117 | cur2=cur2->next; |
---|
[32] | 1118 | if(cur2==NULL) |
---|
| 1119 | break; |
---|
[9] | 1120 | /** |
---|
| 1121 | * Indentifier |
---|
| 1122 | */ |
---|
| 1123 | if(xmlStrncasecmp(cur2->name,BAD_CAST "Identifier",xmlStrlen(cur2->name))==0){ |
---|
| 1124 | xmlChar *val= xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); |
---|
| 1125 | if(tmpmaps==NULL){ |
---|
| 1126 | tmpmaps=(maps*)calloc(1,MAPS_SIZE); |
---|
| 1127 | if(tmpmaps == NULL){ |
---|
[34] | 1128 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[1] | 1129 | } |
---|
[9] | 1130 | tmpmaps->name=strdup((char*)val); |
---|
| 1131 | tmpmaps->content=NULL; |
---|
| 1132 | tmpmaps->next=NULL; |
---|
[1] | 1133 | } |
---|
[9] | 1134 | xmlFree(val); |
---|
| 1135 | } |
---|
| 1136 | /** |
---|
| 1137 | * Title, Asbtract |
---|
| 1138 | */ |
---|
| 1139 | if(xmlStrncasecmp(cur2->name,BAD_CAST "Title",xmlStrlen(cur2->name))==0 || |
---|
| 1140 | xmlStrncasecmp(cur2->name,BAD_CAST "Abstract",xmlStrlen(cur2->name))==0){ |
---|
| 1141 | xmlChar *val= |
---|
| 1142 | xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); |
---|
| 1143 | if(tmpmaps==NULL){ |
---|
| 1144 | tmpmaps=(maps*)calloc(1,MAPS_SIZE); |
---|
| 1145 | if(tmpmaps == NULL){ |
---|
[34] | 1146 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[1] | 1147 | } |
---|
[114] | 1148 | tmpmaps->name=strdup("missingIndetifier"); |
---|
[9] | 1149 | tmpmaps->content=createMap((char*)cur2->name,(char*)val); |
---|
| 1150 | tmpmaps->next=NULL; |
---|
| 1151 | } |
---|
| 1152 | else{ |
---|
| 1153 | if(tmpmaps->content!=NULL) |
---|
| 1154 | addToMap(tmpmaps->content, |
---|
| 1155 | (char*)cur2->name,(char*)val); |
---|
| 1156 | else |
---|
| 1157 | tmpmaps->content= |
---|
| 1158 | createMap((char*)cur2->name,(char*)val); |
---|
| 1159 | } |
---|
[1] | 1160 | #ifdef DEBUG |
---|
[9] | 1161 | dumpMaps(tmpmaps); |
---|
[1] | 1162 | #endif |
---|
[9] | 1163 | xmlFree(val); |
---|
| 1164 | } |
---|
| 1165 | /** |
---|
| 1166 | * InputDataFormChoice (Reference or Data ?) |
---|
| 1167 | */ |
---|
| 1168 | if(xmlStrcasecmp(cur2->name,BAD_CAST "Reference")==0){ |
---|
[1] | 1169 | /** |
---|
[9] | 1170 | * Get every attribute from a Reference node |
---|
| 1171 | * mimeType, encoding, schema, href, method |
---|
| 1172 | * Header and Body gesture should be added here |
---|
[1] | 1173 | */ |
---|
| 1174 | #ifdef DEBUG |
---|
[9] | 1175 | fprintf(stderr,"REFERENCE\n"); |
---|
[1] | 1176 | #endif |
---|
[114] | 1177 | const char *refs[5]; |
---|
[9] | 1178 | refs[0]="mimeType"; |
---|
| 1179 | refs[1]="encoding"; |
---|
| 1180 | refs[2]="schema"; |
---|
| 1181 | refs[3]="method"; |
---|
| 1182 | refs[4]="href"; |
---|
| 1183 | for(int l=0;l<5;l++){ |
---|
[1] | 1184 | #ifdef DEBUG |
---|
[9] | 1185 | fprintf(stderr,"*** %s ***",refs[l]); |
---|
[1] | 1186 | #endif |
---|
[9] | 1187 | xmlChar *val=xmlGetProp(cur2,BAD_CAST refs[l]); |
---|
| 1188 | if(val!=NULL && xmlStrlen(val)>0){ |
---|
| 1189 | if(tmpmaps->content!=NULL) |
---|
| 1190 | addToMap(tmpmaps->content,refs[l],(char*)val); |
---|
| 1191 | else |
---|
| 1192 | tmpmaps->content=createMap(refs[l],(char*)val); |
---|
| 1193 | map* ltmp=getMap(tmpmaps->content,"method"); |
---|
| 1194 | if(l==4){ |
---|
| 1195 | if(!(ltmp!=NULL && strcmp(ltmp->value,"POST")==0) |
---|
| 1196 | && CHECK_INET_HANDLE(hInternet)){ |
---|
[281] | 1197 | loadRemoteFile(m,tmpmaps->content,hInternet,(char*)val); |
---|
[1] | 1198 | } |
---|
| 1199 | } |
---|
[9] | 1200 | } |
---|
[1] | 1201 | #ifdef DEBUG |
---|
[9] | 1202 | fprintf(stderr,"%s\n",val); |
---|
[1] | 1203 | #endif |
---|
[9] | 1204 | xmlFree(val); |
---|
| 1205 | } |
---|
[1] | 1206 | #ifdef POST_DEBUG |
---|
[9] | 1207 | fprintf(stderr,"Parse Header and Body from Reference \n"); |
---|
[1] | 1208 | #endif |
---|
[9] | 1209 | xmlNodePtr cur3=cur2->children; |
---|
| 1210 | hInternet.header=NULL; |
---|
| 1211 | while(cur3){ |
---|
[216] | 1212 | while(cur3!=NULL && cur3->type!=XML_ELEMENT_NODE) |
---|
| 1213 | cur2=cur3->next; |
---|
[9] | 1214 | if(xmlStrcasecmp(cur3->name,BAD_CAST "Header")==0 ){ |
---|
[114] | 1215 | const char *ha[2]; |
---|
[9] | 1216 | ha[0]="key"; |
---|
| 1217 | ha[1]="value"; |
---|
| 1218 | int hai; |
---|
| 1219 | char *has; |
---|
| 1220 | char *key; |
---|
| 1221 | for(hai=0;hai<2;hai++){ |
---|
| 1222 | xmlChar *val=xmlGetProp(cur3,BAD_CAST ha[hai]); |
---|
[1] | 1223 | #ifdef POST_DEBUG |
---|
[9] | 1224 | fprintf(stderr,"%s = %s\n",ha[hai],(char*)val); |
---|
[1] | 1225 | #endif |
---|
[9] | 1226 | if(hai==0){ |
---|
| 1227 | key=(char*)calloc((1+strlen((char*)val)),sizeof(char)); |
---|
| 1228 | snprintf(key,1+strlen((char*)val),"%s",(char*)val); |
---|
| 1229 | }else{ |
---|
| 1230 | has=(char*)calloc((3+strlen((char*)val)+strlen(key)),sizeof(char)); |
---|
| 1231 | if(has == NULL){ |
---|
[34] | 1232 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 1233 | } |
---|
| 1234 | snprintf(has,(3+strlen((char*)val)+strlen(key)),"%s: %s",key,(char*)val); |
---|
[1] | 1235 | #ifdef POST_DEBUG |
---|
[9] | 1236 | fprintf(stderr,"%s\n",has); |
---|
[1] | 1237 | #endif |
---|
| 1238 | } |
---|
| 1239 | } |
---|
[9] | 1240 | hInternet.header=curl_slist_append(hInternet.header, has); |
---|
[114] | 1241 | free(has); |
---|
[9] | 1242 | } |
---|
| 1243 | else{ |
---|
[1] | 1244 | #ifdef POST_DEBUG |
---|
[9] | 1245 | fprintf(stderr,"Try to fetch the body part of the request ...\n"); |
---|
[1] | 1246 | #endif |
---|
[9] | 1247 | if(xmlStrcasecmp(cur3->name,BAD_CAST "Body")==0 ){ |
---|
[1] | 1248 | #ifdef POST_DEBUG |
---|
[9] | 1249 | fprintf(stderr,"Body part found !!!\n",(char*)cur3->content); |
---|
[1] | 1250 | #endif |
---|
[9] | 1251 | char *tmp=new char[cgiContentLength]; |
---|
| 1252 | memset(tmp,0,cgiContentLength); |
---|
| 1253 | xmlNodePtr cur4=cur3->children; |
---|
| 1254 | while(cur4!=NULL){ |
---|
[127] | 1255 | while(cur4->type!=XML_ELEMENT_NODE) |
---|
| 1256 | cur4=cur4->next; |
---|
[9] | 1257 | xmlDocPtr bdoc = xmlNewDoc(BAD_CAST "1.0"); |
---|
| 1258 | bdoc->encoding = xmlCharStrdup ("UTF-8"); |
---|
| 1259 | xmlDocSetRootElement(bdoc,cur4); |
---|
| 1260 | xmlChar* btmps; |
---|
| 1261 | int bsize; |
---|
| 1262 | xmlDocDumpMemory(bdoc,&btmps,&bsize); |
---|
[1] | 1263 | #ifdef POST_DEBUG |
---|
[9] | 1264 | fprintf(stderr,"Body part found !!! %s %s\n",tmp,(char*)btmps); |
---|
[1] | 1265 | #endif |
---|
[9] | 1266 | if(btmps!=NULL) |
---|
| 1267 | sprintf(tmp,"%s",(char*)btmps); |
---|
| 1268 | xmlFreeDoc(bdoc); |
---|
| 1269 | cur4=cur4->next; |
---|
| 1270 | } |
---|
| 1271 | map *btmp=getMap(tmpmaps->content,"href"); |
---|
| 1272 | if(btmp!=NULL){ |
---|
| 1273 | #ifdef POST_DEBUG |
---|
| 1274 | fprintf(stderr,"%s %s\n",btmp->value,tmp); |
---|
| 1275 | curl_easy_setopt(hInternet.handle, CURLOPT_VERBOSE, 1); |
---|
| 1276 | #endif |
---|
| 1277 | res=InternetOpenUrl(hInternet,btmp->value,tmp,strlen(tmp), |
---|
| 1278 | INTERNET_FLAG_NO_CACHE_WRITE,0); |
---|
| 1279 | char* tmpContent = (char*)calloc((res.nDataLen+1),sizeof(char)); |
---|
| 1280 | if(tmpContent == NULL){ |
---|
[34] | 1281 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[1] | 1282 | } |
---|
[9] | 1283 | size_t dwRead; |
---|
| 1284 | InternetReadFile(res, (LPVOID)tmpContent, |
---|
| 1285 | res.nDataLen, &dwRead); |
---|
| 1286 | tmpContent[res.nDataLen]=0; |
---|
| 1287 | if(hInternet.header!=NULL) |
---|
| 1288 | curl_slist_free_all(hInternet.header); |
---|
| 1289 | addToMap(tmpmaps->content,"value",tmpContent); |
---|
| 1290 | #ifdef POST_DEBUG |
---|
| 1291 | fprintf(stderr,"DL CONTENT : (%s)\n",tmpContent); |
---|
| 1292 | #endif |
---|
| 1293 | } |
---|
| 1294 | } |
---|
| 1295 | else |
---|
| 1296 | if(xmlStrcasecmp(cur3->name,BAD_CAST "BodyReference")==0 ){ |
---|
| 1297 | xmlChar *val=xmlGetProp(cur3,BAD_CAST "href"); |
---|
| 1298 | HINTERNET bInternet,res1; |
---|
| 1299 | bInternet=InternetOpen( |
---|
| 1300 | #ifndef WIN32 |
---|
| 1301 | (LPCTSTR) |
---|
| 1302 | #endif |
---|
| 1303 | "ZooWPSClient\0", |
---|
| 1304 | INTERNET_OPEN_TYPE_PRECONFIG, |
---|
| 1305 | NULL,NULL, 0); |
---|
| 1306 | if(!CHECK_INET_HANDLE(bInternet)) |
---|
| 1307 | fprintf(stderr,"WARNING : hInternet handle failed to initialize"); |
---|
| 1308 | #ifdef POST_DEBUG |
---|
| 1309 | curl_easy_setopt(bInternet.handle, CURLOPT_VERBOSE, 1); |
---|
| 1310 | #endif |
---|
| 1311 | res1=InternetOpenUrl(bInternet,(char*)val,NULL,0, |
---|
| 1312 | INTERNET_FLAG_NO_CACHE_WRITE,0); |
---|
| 1313 | char* tmp= |
---|
| 1314 | (char*)calloc((res1.nDataLen+1),sizeof(char)); |
---|
| 1315 | if(tmp == NULL){ |
---|
[34] | 1316 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 1317 | } |
---|
| 1318 | size_t bRead; |
---|
| 1319 | InternetReadFile(res1, (LPVOID)tmp, |
---|
| 1320 | res1.nDataLen, &bRead); |
---|
| 1321 | tmp[res1.nDataLen]=0; |
---|
| 1322 | InternetCloseHandle(bInternet); |
---|
[1] | 1323 | map *btmp=getMap(tmpmaps->content,"href"); |
---|
| 1324 | if(btmp!=NULL){ |
---|
| 1325 | #ifdef POST_DEBUG |
---|
| 1326 | fprintf(stderr,"%s %s\n",btmp->value,tmp); |
---|
| 1327 | curl_easy_setopt(hInternet.handle, CURLOPT_VERBOSE, 1); |
---|
| 1328 | #endif |
---|
[9] | 1329 | res=InternetOpenUrl(hInternet,btmp->value,tmp, |
---|
| 1330 | strlen(tmp), |
---|
[1] | 1331 | INTERNET_FLAG_NO_CACHE_WRITE,0); |
---|
[9] | 1332 | char* tmpContent = (char*)calloc((res.nDataLen+1),sizeof(char)); |
---|
| 1333 | if(tmpContent == NULL){ |
---|
[34] | 1334 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 1335 | } |
---|
[1] | 1336 | size_t dwRead; |
---|
| 1337 | InternetReadFile(res, (LPVOID)tmpContent, |
---|
| 1338 | res.nDataLen, &dwRead); |
---|
| 1339 | tmpContent[res.nDataLen]=0; |
---|
| 1340 | if(hInternet.header!=NULL) |
---|
| 1341 | curl_slist_free_all(hInternet.header); |
---|
| 1342 | addToMap(tmpmaps->content,"value",tmpContent); |
---|
| 1343 | #ifdef POST_DEBUG |
---|
| 1344 | fprintf(stderr,"DL CONTENT : (%s)\n",tmpContent); |
---|
| 1345 | #endif |
---|
| 1346 | } |
---|
| 1347 | } |
---|
| 1348 | } |
---|
[9] | 1349 | cur3=cur3->next; |
---|
| 1350 | } |
---|
[1] | 1351 | #ifdef POST_DEBUG |
---|
[9] | 1352 | fprintf(stderr,"Header and Body was parsed from Reference \n"); |
---|
[1] | 1353 | #endif |
---|
| 1354 | #ifdef DEBUG |
---|
[9] | 1355 | dumpMap(tmpmaps->content); |
---|
| 1356 | fprintf(stderr, "= element 2 node \"%s\" = (%s)\n", |
---|
| 1357 | cur2->name,cur2->content); |
---|
[1] | 1358 | #endif |
---|
[9] | 1359 | } |
---|
| 1360 | else if(xmlStrcasecmp(cur2->name,BAD_CAST "Data")==0){ |
---|
[1] | 1361 | #ifdef DEBUG |
---|
[9] | 1362 | fprintf(stderr,"DATA\n"); |
---|
[1] | 1363 | #endif |
---|
[9] | 1364 | xmlNodePtr cur4=cur2->children; |
---|
[32] | 1365 | while(cur4!=NULL){ |
---|
| 1366 | while(cur4!=NULL &&cur4->type!=XML_ELEMENT_NODE) |
---|
[9] | 1367 | cur4=cur4->next; |
---|
[32] | 1368 | if(cur4==NULL) |
---|
| 1369 | break; |
---|
[9] | 1370 | if(xmlStrcasecmp(cur4->name, BAD_CAST "LiteralData")==0){ |
---|
| 1371 | /** |
---|
| 1372 | * Get every attribute from a LiteralData node |
---|
| 1373 | * dataType , uom |
---|
| 1374 | */ |
---|
[114] | 1375 | char *list[2]; |
---|
| 1376 | list[0]=strdup("dataType"); |
---|
| 1377 | list[1]=strdup("uom"); |
---|
[9] | 1378 | for(int l=0;l<2;l++){ |
---|
[1] | 1379 | #ifdef DEBUG |
---|
[114] | 1380 | fprintf(stderr,"*** LiteralData %s ***",list[l]); |
---|
[1] | 1381 | #endif |
---|
[114] | 1382 | xmlChar *val=xmlGetProp(cur4,BAD_CAST list[l]); |
---|
[9] | 1383 | if(val!=NULL && strlen((char*)val)>0){ |
---|
| 1384 | if(tmpmaps->content!=NULL) |
---|
[114] | 1385 | addToMap(tmpmaps->content,list[l],(char*)val); |
---|
[9] | 1386 | else |
---|
[114] | 1387 | tmpmaps->content=createMap(list[l],(char*)val); |
---|
[1] | 1388 | #ifdef DEBUG |
---|
[280] | 1389 | fprintf(stderr,"%s\n",val); |
---|
[1] | 1390 | #endif |
---|
[280] | 1391 | } |
---|
[9] | 1392 | xmlFree(val); |
---|
[280] | 1393 | free(list[l]); |
---|
[1] | 1394 | } |
---|
[9] | 1395 | } |
---|
| 1396 | else if(xmlStrcasecmp(cur4->name, BAD_CAST "ComplexData")==0){ |
---|
| 1397 | /** |
---|
| 1398 | * Get every attribute from a Reference node |
---|
| 1399 | * mimeType, encoding, schema |
---|
| 1400 | */ |
---|
[114] | 1401 | const char *coms[3]; |
---|
[9] | 1402 | coms[0]="mimeType"; |
---|
| 1403 | coms[1]="encoding"; |
---|
| 1404 | coms[2]="schema"; |
---|
| 1405 | for(int l=0;l<3;l++){ |
---|
[1] | 1406 | #ifdef DEBUG |
---|
[280] | 1407 | fprintf(stderr,"*** ComplexData %s ***\n",coms[l]); |
---|
[1] | 1408 | #endif |
---|
[9] | 1409 | xmlChar *val=xmlGetProp(cur4,BAD_CAST coms[l]); |
---|
| 1410 | if(val!=NULL && strlen((char*)val)>0){ |
---|
| 1411 | if(tmpmaps->content!=NULL) |
---|
| 1412 | addToMap(tmpmaps->content,coms[l],(char*)val); |
---|
| 1413 | else |
---|
| 1414 | tmpmaps->content=createMap(coms[l],(char*)val); |
---|
[1] | 1415 | #ifdef DEBUG |
---|
[280] | 1416 | fprintf(stderr,"%s\n",val); |
---|
[1] | 1417 | #endif |
---|
[280] | 1418 | } |
---|
[9] | 1419 | xmlFree(val); |
---|
[1] | 1420 | } |
---|
| 1421 | } |
---|
[280] | 1422 | |
---|
[94] | 1423 | map* test=getMap(tmpmaps->content,"encoding"); |
---|
[280] | 1424 | if(test==NULL){ |
---|
| 1425 | if(tmpmaps->content!=NULL) |
---|
| 1426 | addToMap(tmpmaps->content,"encoding","utf-8"); |
---|
| 1427 | else |
---|
| 1428 | tmpmaps->content=createMap("encoding","utf-8"); |
---|
| 1429 | test=getMap(tmpmaps->content,"encoding"); |
---|
| 1430 | } |
---|
| 1431 | |
---|
| 1432 | if(strcasecmp(test->value,"base64")!=0){ |
---|
[94] | 1433 | xmlChar* mv=xmlNodeListGetString(doc,cur4->xmlChildrenNode,1); |
---|
[280] | 1434 | map* ltmp=getMap(tmpmaps->content,"mimeType"); |
---|
| 1435 | if(mv==NULL || |
---|
| 1436 | (xmlStrcasecmp(cur4->name, BAD_CAST "ComplexData")==0 && |
---|
| 1437 | (ltmp==NULL || strncasecmp(ltmp->value,"text/xml",8)==0) )){ |
---|
[94] | 1438 | xmlDocPtr doc1=xmlNewDoc(BAD_CAST "1.0"); |
---|
| 1439 | int buffersize; |
---|
[280] | 1440 | xmlNodePtr cur5=cur4->children; |
---|
| 1441 | while(cur5!=NULL &&cur5->type!=XML_ELEMENT_NODE) |
---|
| 1442 | cur5=cur5->next; |
---|
| 1443 | xmlDocSetRootElement(doc1,cur5); |
---|
[94] | 1444 | xmlDocDumpFormatMemoryEnc(doc1, &mv, &buffersize, "utf-8", 1); |
---|
| 1445 | char size[1024]; |
---|
| 1446 | sprintf(size,"%d",buffersize); |
---|
| 1447 | addToMap(tmpmaps->content,"size",size); |
---|
| 1448 | } |
---|
| 1449 | addToMap(tmpmaps->content,"value",(char*)mv); |
---|
| 1450 | xmlFree(mv); |
---|
| 1451 | }else{ |
---|
[95] | 1452 | xmlChar* tmp=xmlNodeListGetRawString(doc,cur4->xmlChildrenNode,0); |
---|
[94] | 1453 | addToMap(tmpmaps->content,"value",(char*)tmp); |
---|
| 1454 | map* tmpv=getMap(tmpmaps->content,"value"); |
---|
| 1455 | char *res=NULL; |
---|
| 1456 | char *curs=tmpv->value; |
---|
| 1457 | for(int i=0;i<=strlen(tmpv->value)/64;i++) { |
---|
| 1458 | if(res==NULL) |
---|
| 1459 | res=(char*)malloc(67*sizeof(char)); |
---|
| 1460 | else |
---|
| 1461 | res=(char*)realloc(res,(((i+1)*65)+i)*sizeof(char)); |
---|
| 1462 | int csize=i*65; |
---|
| 1463 | strncpy(res + csize,curs,64); |
---|
| 1464 | if(i==xmlStrlen(tmp)/64) |
---|
| 1465 | strcat(res,"\n\0"); |
---|
| 1466 | else{ |
---|
| 1467 | strncpy(res + (((i+1)*64)+i),"\n\0",2); |
---|
| 1468 | curs+=64; |
---|
| 1469 | } |
---|
| 1470 | } |
---|
| 1471 | free(tmpv->value); |
---|
| 1472 | tmpv->value=strdup(res); |
---|
| 1473 | free(res); |
---|
| 1474 | xmlFree(tmp); |
---|
[69] | 1475 | } |
---|
[9] | 1476 | cur4=cur4->next; |
---|
[1] | 1477 | } |
---|
[9] | 1478 | } |
---|
[1] | 1479 | #ifdef DEBUG |
---|
[9] | 1480 | fprintf(stderr,"cur2 next \n"); |
---|
| 1481 | fflush(stderr); |
---|
[1] | 1482 | #endif |
---|
[9] | 1483 | cur2=cur2->next; |
---|
| 1484 | } |
---|
[1] | 1485 | #ifdef DEBUG |
---|
[9] | 1486 | fprintf(stderr,"ADD MAPS TO REQUEST MAPS !\n"); |
---|
| 1487 | fflush(stderr); |
---|
[1] | 1488 | #endif |
---|
[9] | 1489 | addMapsToMaps(&request_input_real_format,tmpmaps); |
---|
| 1490 | |
---|
[1] | 1491 | #ifdef DEBUG |
---|
[9] | 1492 | fprintf(stderr,"******TMPMAPS*****\n"); |
---|
[1] | 1493 | dumpMaps(tmpmaps); |
---|
[9] | 1494 | fprintf(stderr,"******REQUESTMAPS*****\n"); |
---|
| 1495 | dumpMaps(request_input_real_format); |
---|
[1] | 1496 | #endif |
---|
[32] | 1497 | freeMaps(&tmpmaps); |
---|
| 1498 | free(tmpmaps); |
---|
| 1499 | tmpmaps=NULL; |
---|
[1] | 1500 | } |
---|
[25] | 1501 | #ifdef DEBUG |
---|
| 1502 | dumpMaps(tmpmaps); |
---|
| 1503 | #endif |
---|
[1] | 1504 | } |
---|
| 1505 | #ifdef DEBUG |
---|
[9] | 1506 | fprintf(stderr,"Search for response document node\n"); |
---|
| 1507 | #endif |
---|
| 1508 | xmlXPathFreeObject(tmpsptr); |
---|
[105] | 1509 | |
---|
[9] | 1510 | tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='ResponseDocument']"); |
---|
[105] | 1511 | bool asRaw=false; |
---|
[9] | 1512 | tmps=tmpsptr->nodesetval; |
---|
[105] | 1513 | if(tmps->nodeNr==0){ |
---|
| 1514 | tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='RawDataOutput']"); |
---|
| 1515 | tmps=tmpsptr->nodesetval; |
---|
| 1516 | asRaw=true; |
---|
| 1517 | } |
---|
[9] | 1518 | #ifdef DEBUG |
---|
[1] | 1519 | fprintf(stderr,"*****%d*****\n",tmps->nodeNr); |
---|
| 1520 | #endif |
---|
| 1521 | for(int k=0;k<tmps->nodeNr;k++){ |
---|
[105] | 1522 | if(asRaw==true) |
---|
| 1523 | addToMap(request_inputs,"RawDataOutput",""); |
---|
| 1524 | else |
---|
| 1525 | addToMap(request_inputs,"ResponseDocument",""); |
---|
[1] | 1526 | maps *tmpmaps=NULL; |
---|
| 1527 | xmlNodePtr cur=tmps->nodeTab[k]; |
---|
| 1528 | if(cur->type == XML_ELEMENT_NODE) { |
---|
| 1529 | /** |
---|
| 1530 | * A specific responseDocument node. |
---|
| 1531 | */ |
---|
| 1532 | if(tmpmaps==NULL){ |
---|
[9] | 1533 | tmpmaps=(maps*)calloc(1,MAPS_SIZE); |
---|
| 1534 | if(tmpmaps == NULL){ |
---|
[34] | 1535 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 1536 | } |
---|
[114] | 1537 | tmpmaps->name=strdup("unknownIdentifier"); |
---|
[1] | 1538 | tmpmaps->next=NULL; |
---|
| 1539 | } |
---|
| 1540 | /** |
---|
| 1541 | * Get every attribute from a LiteralData node |
---|
| 1542 | * storeExecuteResponse, lineage, status |
---|
| 1543 | */ |
---|
[114] | 1544 | const char *ress[3]; |
---|
[1] | 1545 | ress[0]="storeExecuteResponse"; |
---|
| 1546 | ress[1]="lineage"; |
---|
| 1547 | ress[2]="status"; |
---|
| 1548 | xmlChar *val; |
---|
| 1549 | for(int l=0;l<3;l++){ |
---|
| 1550 | #ifdef DEBUG |
---|
| 1551 | fprintf(stderr,"*** %s ***\t",ress[l]); |
---|
| 1552 | #endif |
---|
| 1553 | val=xmlGetProp(cur,BAD_CAST ress[l]); |
---|
| 1554 | if(val!=NULL && strlen((char*)val)>0){ |
---|
| 1555 | if(tmpmaps->content!=NULL) |
---|
| 1556 | addToMap(tmpmaps->content,ress[l],(char*)val); |
---|
| 1557 | else |
---|
| 1558 | tmpmaps->content=createMap(ress[l],(char*)val); |
---|
| 1559 | addToMap(request_inputs,ress[l],(char*)val); |
---|
| 1560 | } |
---|
| 1561 | #ifdef DEBUG |
---|
| 1562 | fprintf(stderr,"%s\n",val); |
---|
| 1563 | #endif |
---|
| 1564 | xmlFree(val); |
---|
| 1565 | } |
---|
| 1566 | xmlNodePtr cur1=cur->children; |
---|
| 1567 | while(cur1){ |
---|
[280] | 1568 | /** |
---|
| 1569 | * Indentifier |
---|
| 1570 | */ |
---|
| 1571 | if(xmlStrncasecmp(cur1->name,BAD_CAST "Identifier",xmlStrlen(cur1->name))==0){ |
---|
| 1572 | xmlChar *val= |
---|
| 1573 | xmlNodeListGetString(doc,cur1->xmlChildrenNode,1); |
---|
| 1574 | if(tmpmaps==NULL){ |
---|
| 1575 | tmpmaps=(maps*)calloc(1,MAPS_SIZE); |
---|
| 1576 | if(tmpmaps == NULL){ |
---|
| 1577 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
| 1578 | } |
---|
| 1579 | tmpmaps->name=strdup((char*)val); |
---|
| 1580 | tmpmaps->content=NULL; |
---|
| 1581 | tmpmaps->next=NULL; |
---|
| 1582 | } |
---|
| 1583 | else |
---|
| 1584 | tmpmaps->name=strdup((char*)val);; |
---|
| 1585 | xmlFree(val); |
---|
| 1586 | } |
---|
| 1587 | /** |
---|
| 1588 | * Title, Asbtract |
---|
| 1589 | */ |
---|
| 1590 | else if(xmlStrncasecmp(cur1->name,BAD_CAST "Title",xmlStrlen(cur1->name))==0 || |
---|
| 1591 | xmlStrncasecmp(cur1->name,BAD_CAST "Abstract",xmlStrlen(cur1->name))==0){ |
---|
| 1592 | xmlChar *val= |
---|
| 1593 | xmlNodeListGetString(doc,cur1->xmlChildrenNode,1); |
---|
| 1594 | if(tmpmaps==NULL){ |
---|
| 1595 | tmpmaps=(maps*)calloc(1,MAPS_SIZE); |
---|
| 1596 | if(tmpmaps == NULL){ |
---|
| 1597 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
| 1598 | } |
---|
| 1599 | tmpmaps->name=strdup("missingIndetifier"); |
---|
| 1600 | tmpmaps->content=createMap((char*)cur1->name,(char*)val); |
---|
| 1601 | tmpmaps->next=NULL; |
---|
| 1602 | } |
---|
| 1603 | else{ |
---|
| 1604 | if(tmpmaps->content!=NULL) |
---|
| 1605 | addToMap(tmpmaps->content, |
---|
| 1606 | (char*)cur1->name,(char*)val); |
---|
| 1607 | else |
---|
| 1608 | tmpmaps->content= |
---|
| 1609 | createMap((char*)cur1->name,(char*)val); |
---|
| 1610 | } |
---|
| 1611 | xmlFree(val); |
---|
| 1612 | } |
---|
| 1613 | else if(xmlStrncasecmp(cur1->name,BAD_CAST "Output",xmlStrlen(cur1->name))==0){ |
---|
[1] | 1614 | /** |
---|
| 1615 | * Get every attribute from a Output node |
---|
| 1616 | * mimeType, encoding, schema, uom, asReference |
---|
| 1617 | */ |
---|
[114] | 1618 | const char *outs[5]; |
---|
[1] | 1619 | outs[0]="mimeType"; |
---|
| 1620 | outs[1]="encoding"; |
---|
| 1621 | outs[2]="schema"; |
---|
| 1622 | outs[3]="uom"; |
---|
| 1623 | outs[4]="asReference"; |
---|
| 1624 | for(int l=0;l<5;l++){ |
---|
| 1625 | #ifdef DEBUG |
---|
| 1626 | fprintf(stderr,"*** %s ***\t",outs[l]); |
---|
| 1627 | #endif |
---|
| 1628 | val=xmlGetProp(cur1,BAD_CAST outs[l]); |
---|
| 1629 | if(val!=NULL && strlen((char*)val)>0){ |
---|
| 1630 | if(tmpmaps->content!=NULL) |
---|
| 1631 | addToMap(tmpmaps->content,outs[l],(char*)val); |
---|
| 1632 | else |
---|
| 1633 | tmpmaps->content=createMap(outs[l],(char*)val); |
---|
| 1634 | } |
---|
| 1635 | #ifdef DEBUG |
---|
| 1636 | fprintf(stderr,"%s\n",val); |
---|
| 1637 | #endif |
---|
| 1638 | xmlFree(val); |
---|
| 1639 | } |
---|
| 1640 | |
---|
| 1641 | xmlNodePtr cur2=cur1->children; |
---|
| 1642 | while(cur2){ |
---|
| 1643 | /** |
---|
| 1644 | * Indentifier |
---|
| 1645 | */ |
---|
[9] | 1646 | if(xmlStrncasecmp(cur2->name,BAD_CAST "Identifier",xmlStrlen(cur2->name))==0){ |
---|
[1] | 1647 | xmlChar *val= |
---|
| 1648 | xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); |
---|
| 1649 | if(tmpmaps==NULL){ |
---|
[9] | 1650 | tmpmaps=(maps*)calloc(1,MAPS_SIZE); |
---|
| 1651 | if(tmpmaps == NULL){ |
---|
[34] | 1652 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 1653 | } |
---|
[1] | 1654 | tmpmaps->name=strdup((char*)val); |
---|
| 1655 | tmpmaps->content=NULL; |
---|
| 1656 | tmpmaps->next=NULL; |
---|
| 1657 | } |
---|
| 1658 | else |
---|
| 1659 | tmpmaps->name=strdup((char*)val);; |
---|
| 1660 | xmlFree(val); |
---|
| 1661 | } |
---|
| 1662 | /** |
---|
| 1663 | * Title, Asbtract |
---|
| 1664 | */ |
---|
[274] | 1665 | else if(xmlStrncasecmp(cur2->name,BAD_CAST "Title",xmlStrlen(cur2->name))==0 || |
---|
[9] | 1666 | xmlStrncasecmp(cur2->name,BAD_CAST "Abstract",xmlStrlen(cur2->name))==0){ |
---|
[1] | 1667 | xmlChar *val= |
---|
| 1668 | xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); |
---|
| 1669 | if(tmpmaps==NULL){ |
---|
[9] | 1670 | tmpmaps=(maps*)calloc(1,MAPS_SIZE); |
---|
| 1671 | if(tmpmaps == NULL){ |
---|
[34] | 1672 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
[9] | 1673 | } |
---|
[114] | 1674 | tmpmaps->name=strdup("missingIndetifier"); |
---|
[1] | 1675 | tmpmaps->content=createMap((char*)cur2->name,(char*)val); |
---|
| 1676 | tmpmaps->next=NULL; |
---|
| 1677 | } |
---|
| 1678 | else{ |
---|
| 1679 | if(tmpmaps->content!=NULL) |
---|
| 1680 | addToMap(tmpmaps->content, |
---|
| 1681 | (char*)cur2->name,(char*)val); |
---|
| 1682 | else |
---|
| 1683 | tmpmaps->content= |
---|
| 1684 | createMap((char*)cur2->name,(char*)val); |
---|
| 1685 | } |
---|
| 1686 | xmlFree(val); |
---|
| 1687 | } |
---|
| 1688 | cur2=cur2->next; |
---|
| 1689 | } |
---|
| 1690 | } |
---|
| 1691 | cur1=cur1->next; |
---|
| 1692 | } |
---|
| 1693 | } |
---|
| 1694 | if(request_output_real_format==NULL) |
---|
[105] | 1695 | request_output_real_format=dupMaps(&tmpmaps); |
---|
[1] | 1696 | else |
---|
| 1697 | addMapsToMaps(&request_output_real_format,tmpmaps); |
---|
| 1698 | #ifdef DEBUG |
---|
| 1699 | dumpMaps(tmpmaps); |
---|
| 1700 | #endif |
---|
[105] | 1701 | freeMaps(&tmpmaps); |
---|
| 1702 | free(tmpmaps); |
---|
[1] | 1703 | } |
---|
[105] | 1704 | |
---|
[9] | 1705 | xmlXPathFreeObject(tmpsptr); |
---|
[1] | 1706 | xmlCleanupParser(); |
---|
| 1707 | } |
---|
[105] | 1708 | |
---|
[9] | 1709 | //if(CHECK_INET_HANDLE(hInternet)) |
---|
| 1710 | InternetCloseHandle(hInternet); |
---|
[1] | 1711 | |
---|
| 1712 | #ifdef DEBUG |
---|
| 1713 | fprintf(stderr,"\n%i\n",i); |
---|
| 1714 | dumpMaps(request_input_real_format); |
---|
| 1715 | dumpMaps(request_output_real_format); |
---|
[9] | 1716 | dumpMap(request_inputs); |
---|
[280] | 1717 | fprintf(stderr,"\n%i\n",i); |
---|
[1] | 1718 | #endif |
---|
| 1719 | |
---|
| 1720 | /** |
---|
| 1721 | * Ensure that each requested arguments are present in the request |
---|
| 1722 | * DataInputs and ResponseDocument / RawDataOutput |
---|
[92] | 1723 | */ |
---|
[63] | 1724 | char *dfv=addDefaultValues(&request_input_real_format,s1->inputs,m,0); |
---|
[280] | 1725 | char *dfv1=addDefaultValues(&request_output_real_format,s1->outputs,m,1); |
---|
| 1726 | if(strcmp(dfv1,"")!=0 || strcmp(dfv,"")!=0){ |
---|
[9] | 1727 | char tmps[1024]; |
---|
[280] | 1728 | if(strcmp(dfv,"")!=0){ |
---|
| 1729 | 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); |
---|
| 1730 | } |
---|
| 1731 | else if(strcmp(dfv1,"")!=0){ |
---|
| 1732 | 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); |
---|
| 1733 | } |
---|
[9] | 1734 | map* tmpe=createMap("text",tmps); |
---|
| 1735 | addToMap(tmpe,"code","MissingParameterValue"); |
---|
| 1736 | printExceptionReportResponse(m,tmpe); |
---|
[63] | 1737 | freeService(&s1); |
---|
| 1738 | free(s1); |
---|
[9] | 1739 | freeMap(&tmpe); |
---|
| 1740 | free(tmpe); |
---|
| 1741 | freeMaps(&m); |
---|
| 1742 | free(m); |
---|
| 1743 | free(REQUEST); |
---|
[63] | 1744 | free(SERVICE_URL); |
---|
[9] | 1745 | freeMaps(&request_input_real_format); |
---|
| 1746 | free(request_input_real_format); |
---|
| 1747 | freeMaps(&request_output_real_format); |
---|
| 1748 | free(request_output_real_format); |
---|
| 1749 | freeMaps(&tmpmaps); |
---|
| 1750 | free(tmpmaps); |
---|
| 1751 | return 1; |
---|
| 1752 | } |
---|
[1] | 1753 | |
---|
[88] | 1754 | ensureDecodedBase64(&request_input_real_format); |
---|
| 1755 | |
---|
[9] | 1756 | #ifdef DEBUG |
---|
| 1757 | fprintf(stderr,"REQUEST_INPUTS\n"); |
---|
| 1758 | dumpMaps(request_input_real_format); |
---|
| 1759 | fprintf(stderr,"REQUEST_OUTPUTS\n"); |
---|
| 1760 | dumpMaps(request_output_real_format); |
---|
| 1761 | #endif |
---|
[1] | 1762 | |
---|
| 1763 | maps* curs=getMaps(m,"env"); |
---|
| 1764 | if(curs!=NULL){ |
---|
| 1765 | map* mapcs=curs->content; |
---|
| 1766 | while(mapcs!=NULLMAP){ |
---|
| 1767 | #ifndef WIN32 |
---|
| 1768 | setenv(mapcs->name,mapcs->value,1); |
---|
| 1769 | #else |
---|
| 1770 | #ifdef DEBUG |
---|
| 1771 | fprintf(stderr,"[ZOO: setenv (%s=%s)]\n",mapcs->name,mapcs->value); |
---|
| 1772 | #endif |
---|
| 1773 | if(mapcs->value[strlen(mapcs->value)-2]=='\r'){ |
---|
| 1774 | #ifdef DEBUG |
---|
| 1775 | fprintf(stderr,"[ZOO: Env var finish with \r]\n"); |
---|
| 1776 | #endif |
---|
| 1777 | mapcs->value[strlen(mapcs->value)-1]=0; |
---|
| 1778 | } |
---|
| 1779 | #ifdef DEBUG |
---|
| 1780 | fflush(stderr); |
---|
| 1781 | fprintf(stderr,"setting variable... %s\n", |
---|
| 1782 | #endif |
---|
| 1783 | SetEnvironmentVariable(mapcs->name,mapcs->value) |
---|
| 1784 | #ifdef DEBUG |
---|
| 1785 | ? "OK" : "FAILED"); |
---|
| 1786 | #else |
---|
| 1787 | ; |
---|
| 1788 | #endif |
---|
| 1789 | #ifdef DEBUG |
---|
| 1790 | fflush(stderr); |
---|
| 1791 | #endif |
---|
| 1792 | #endif |
---|
| 1793 | #ifdef DEBUG |
---|
| 1794 | fprintf(stderr,"[ZOO: setenv (%s=%s)]\n",mapcs->name,mapcs->value); |
---|
| 1795 | fflush(stderr); |
---|
| 1796 | #endif |
---|
| 1797 | mapcs=mapcs->next; |
---|
| 1798 | } |
---|
| 1799 | } |
---|
| 1800 | |
---|
| 1801 | #ifdef DEBUG |
---|
| 1802 | dumpMap(request_inputs); |
---|
| 1803 | #endif |
---|
| 1804 | |
---|
| 1805 | /** |
---|
| 1806 | * Need to check if we need to fork to load a status enabled |
---|
| 1807 | */ |
---|
| 1808 | r_inputs=NULL; |
---|
[72] | 1809 | map* store=getMap(request_inputs,"storeExecuteResponse"); |
---|
| 1810 | map* status=getMap(request_inputs,"status"); |
---|
| 1811 | /** |
---|
| 1812 | * 05-007r7 WPS 1.0.0 page 57 : |
---|
| 1813 | * 'If status="true" and storeExecuteResponse is "false" then the service |
---|
| 1814 | * shall raise an exception.' |
---|
| 1815 | */ |
---|
| 1816 | if(status!=NULL && strcmp(status->value,"true")==0 && |
---|
| 1817 | store!=NULL && strcmp(store->value,"false")==0){ |
---|
| 1818 | errorException(m, _("Status cannot be set to true with storeExecuteResponse to false. Please, modify your request parameters."), "InvalidParameterValue"); |
---|
| 1819 | freeService(&s1); |
---|
| 1820 | free(s1); |
---|
| 1821 | freeMaps(&m); |
---|
| 1822 | free(m); |
---|
| 1823 | |
---|
| 1824 | freeMaps(&request_input_real_format); |
---|
| 1825 | free(request_input_real_format); |
---|
| 1826 | |
---|
| 1827 | freeMaps(&request_output_real_format); |
---|
| 1828 | free(request_output_real_format); |
---|
| 1829 | |
---|
| 1830 | free(REQUEST); |
---|
| 1831 | free(SERVICE_URL); |
---|
| 1832 | return 1; |
---|
| 1833 | } |
---|
[1] | 1834 | r_inputs=getMap(request_inputs,"storeExecuteResponse"); |
---|
| 1835 | int eres=SERVICE_STARTED; |
---|
| 1836 | int cpid=getpid(); |
---|
[94] | 1837 | |
---|
[32] | 1838 | maps *_tmpMaps=(maps*)malloc(MAPS_SIZE); |
---|
| 1839 | _tmpMaps->name=strdup("lenv"); |
---|
| 1840 | char tmpBuff[100]; |
---|
| 1841 | sprintf(tmpBuff,"%i",cpid); |
---|
| 1842 | _tmpMaps->content=createMap("sid",tmpBuff); |
---|
| 1843 | _tmpMaps->next=NULL; |
---|
| 1844 | addToMap(_tmpMaps->content,"status","0"); |
---|
[216] | 1845 | addToMap(_tmpMaps->content,"cwd",ntmp); |
---|
[280] | 1846 | map* ltmp=getMap(request_inputs,"soap"); |
---|
| 1847 | if(ltmp!=NULL) |
---|
| 1848 | addToMap(_tmpMaps->content,"soap",ltmp->value); |
---|
| 1849 | else |
---|
| 1850 | addToMap(_tmpMaps->content,"soap","false"); |
---|
[92] | 1851 | if(cgiCookie!=NULL && strlen(cgiCookie)>0){ |
---|
| 1852 | addToMap(_tmpMaps->content,"sessid",strstr(cgiCookie,"=")+1); |
---|
| 1853 | char session_file_path[1024]; |
---|
| 1854 | map *tmpPath=getMapFromMaps(m,"main","sessPath"); |
---|
| 1855 | if(tmpPath==NULL) |
---|
| 1856 | tmpPath=getMapFromMaps(m,"main","tmpPath"); |
---|
[253] | 1857 | char *tmp1=strtok(cgiCookie,";"); |
---|
| 1858 | if(tmp1!=NULL) |
---|
| 1859 | sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,strstr(tmp1,"=")+1); |
---|
| 1860 | else |
---|
| 1861 | sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,strstr(cgiCookie,"=")+1); |
---|
| 1862 | |
---|
[92] | 1863 | maps *tmpSess=(maps*)calloc(1,MAPS_SIZE); |
---|
| 1864 | struct stat file_status; |
---|
| 1865 | int istat = stat(session_file_path, &file_status); |
---|
[254] | 1866 | if(istat==0 && file_status.st_size>0){ |
---|
[92] | 1867 | conf_read(session_file_path,tmpSess); |
---|
| 1868 | addMapsToMaps(&m,tmpSess); |
---|
| 1869 | freeMaps(&tmpSess); |
---|
| 1870 | } |
---|
| 1871 | free(tmpSess); |
---|
| 1872 | } |
---|
[32] | 1873 | addMapsToMaps(&m,_tmpMaps); |
---|
| 1874 | freeMaps(&_tmpMaps); |
---|
| 1875 | free(_tmpMaps); |
---|
| 1876 | |
---|
[1] | 1877 | #ifdef DEBUG |
---|
| 1878 | dumpMap(request_inputs); |
---|
| 1879 | #endif |
---|
[216] | 1880 | #ifdef WIN32 |
---|
| 1881 | char *cgiSidL=NULL; |
---|
| 1882 | if(getenv("CGISID")!=NULL) |
---|
| 1883 | addToMap(request_inputs,"cgiSid",getenv("CGISID")); |
---|
| 1884 | map* test1=getMap(request_inputs,"cgiSid"); |
---|
| 1885 | if(test1!=NULL){ |
---|
| 1886 | cgiSid=test1->value; |
---|
| 1887 | } |
---|
| 1888 | if(cgiSid!=NULL){ |
---|
| 1889 | addToMap(request_inputs,"storeExecuteResponse","true"); |
---|
| 1890 | addToMap(request_inputs,"status","true"); |
---|
| 1891 | status=getMap(request_inputs,"status"); |
---|
| 1892 | fprintf(stderr,"cgiSID : %s",cgiSid); |
---|
| 1893 | } |
---|
| 1894 | #endif |
---|
[72] | 1895 | if(status!=NULL) |
---|
| 1896 | if(strcasecmp(status->value,"false")==0) |
---|
| 1897 | status=NULL; |
---|
| 1898 | if(status==NULLMAP){ |
---|
[34] | 1899 | loadServiceAndRun(&m,s1,request_inputs,&request_input_real_format,&request_output_real_format,&eres); |
---|
| 1900 | } |
---|
[1] | 1901 | else{ |
---|
| 1902 | pid_t pid; |
---|
| 1903 | #ifdef DEBUG |
---|
| 1904 | fprintf(stderr,"\nPID : %d\n",cpid); |
---|
| 1905 | #endif |
---|
[9] | 1906 | |
---|
[1] | 1907 | #ifndef WIN32 |
---|
[9] | 1908 | pid = fork (); |
---|
[1] | 1909 | #else |
---|
[216] | 1910 | if(cgiSid==NULL){ |
---|
| 1911 | addToMap(request_inputs,"cgSid",cgiSid); |
---|
| 1912 | createProcess(m,request_inputs,s1,NULL,cpid,request_input_real_format,request_output_real_format); |
---|
| 1913 | pid = cpid; |
---|
| 1914 | }else{ |
---|
| 1915 | pid=0; |
---|
| 1916 | cpid=atoi(cgiSid); |
---|
| 1917 | } |
---|
| 1918 | fflush(stderr); |
---|
[1] | 1919 | #endif |
---|
| 1920 | if (pid > 0) { |
---|
| 1921 | /** |
---|
| 1922 | * dady : |
---|
| 1923 | * set status to SERVICE_ACCEPTED |
---|
| 1924 | */ |
---|
| 1925 | #ifdef DEBUG |
---|
| 1926 | fprintf(stderr,"father pid continue (origin %d) %d ...\n",cpid,getpid()); |
---|
| 1927 | #endif |
---|
| 1928 | eres=SERVICE_ACCEPTED; |
---|
| 1929 | }else if (pid == 0) { |
---|
| 1930 | /** |
---|
| 1931 | * son : have to close the stdout, stdin and stderr to let the parent |
---|
| 1932 | * process answer to http client. |
---|
| 1933 | */ |
---|
| 1934 | r_inputs=getMapFromMaps(m,"main","tmpPath"); |
---|
[9] | 1935 | map* r_inputs1=getMap(s1->content,"ServiceProvider"); |
---|
[32] | 1936 | char* fbkp=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+100)*sizeof(char)); |
---|
[9] | 1937 | sprintf(fbkp,"%s/%s_%d.xml",r_inputs->value,r_inputs1->value,cpid); |
---|
[32] | 1938 | char* flog=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+100)*sizeof(char)); |
---|
[9] | 1939 | sprintf(flog,"%s/%s_%d_error.log",r_inputs->value,r_inputs1->value,cpid); |
---|
[1] | 1940 | #ifdef DEBUG |
---|
| 1941 | fprintf(stderr,"RUN IN BACKGROUND MODE \n"); |
---|
| 1942 | fprintf(stderr,"son pid continue (origin %d) %d ...\n",cpid,getpid()); |
---|
[9] | 1943 | fprintf(stderr,"\nFILE TO STORE DATA %s\n",r_inputs->value); |
---|
[1] | 1944 | #endif |
---|
[216] | 1945 | freopen(flog,"w+",stderr); |
---|
[9] | 1946 | freopen(fbkp , "w+", stdout); |
---|
[1] | 1947 | fclose(stdin); |
---|
[9] | 1948 | free(fbkp); |
---|
| 1949 | free(flog); |
---|
[1] | 1950 | /** |
---|
| 1951 | * set status to SERVICE_STARTED and flush stdout to ensure full |
---|
| 1952 | * content was outputed (the file used to store the ResponseDocument). |
---|
| 1953 | * The rewind stdout to restart writing from the bgining of the file, |
---|
| 1954 | * this way the data will be updated at the end of the process run. |
---|
| 1955 | */ |
---|
[32] | 1956 | updateStatus(m); |
---|
[9] | 1957 | printProcessResponse(m,request_inputs,cpid, |
---|
[216] | 1958 | s1,r_inputs1->value,SERVICE_STARTED, |
---|
| 1959 | request_input_real_format, |
---|
| 1960 | request_output_real_format); |
---|
| 1961 | #ifndef WIN32 |
---|
[1] | 1962 | fflush(stdout); |
---|
| 1963 | rewind(stdout); |
---|
[216] | 1964 | #endif |
---|
[1] | 1965 | |
---|
[34] | 1966 | loadServiceAndRun(&m,s1,request_inputs,&request_input_real_format,&request_output_real_format,&eres); |
---|
[9] | 1967 | |
---|
[1] | 1968 | } else { |
---|
| 1969 | /** |
---|
| 1970 | * error server don't accept the process need to output a valid |
---|
| 1971 | * error response here !!! |
---|
| 1972 | */ |
---|
[34] | 1973 | eres=-1; |
---|
| 1974 | errorException(m, _("Unable to run the child process properly"), "InternalError"); |
---|
[1] | 1975 | } |
---|
| 1976 | } |
---|
| 1977 | |
---|
| 1978 | #ifdef DEBUG |
---|
| 1979 | dumpMaps(request_output_real_format); |
---|
[216] | 1980 | fprintf(stderr,"Function loaded and returned %d\n",*eres); |
---|
[9] | 1981 | fflush(stderr); |
---|
[1] | 1982 | #endif |
---|
[9] | 1983 | if(eres!=-1) |
---|
| 1984 | outputResponse(s1,request_input_real_format, |
---|
| 1985 | request_output_real_format,request_inputs, |
---|
| 1986 | cpid,m,eres); |
---|
[216] | 1987 | fflush(stdout); |
---|
[105] | 1988 | /** |
---|
| 1989 | * Ensure that if error occurs when freeing memory, no signal will return |
---|
| 1990 | * an ExceptionReport document as the result was already returned to the |
---|
| 1991 | * client. |
---|
| 1992 | */ |
---|
| 1993 | #ifndef USE_GDB |
---|
| 1994 | (void) signal(SIGSEGV,donothing); |
---|
| 1995 | (void) signal(SIGTERM,donothing); |
---|
| 1996 | (void) signal(SIGINT,donothing); |
---|
| 1997 | (void) signal(SIGILL,donothing); |
---|
| 1998 | (void) signal(SIGFPE,donothing); |
---|
| 1999 | (void) signal(SIGABRT,donothing); |
---|
| 2000 | #endif |
---|
[1] | 2001 | |
---|
[32] | 2002 | if(((int)getpid())!=cpid){ |
---|
| 2003 | fclose(stdout); |
---|
| 2004 | fclose(stderr); |
---|
| 2005 | unhandleStatus(m); |
---|
| 2006 | } |
---|
| 2007 | |
---|
[9] | 2008 | freeService(&s1); |
---|
| 2009 | free(s1); |
---|
[59] | 2010 | freeMaps(&m); |
---|
[9] | 2011 | free(m); |
---|
| 2012 | |
---|
| 2013 | freeMaps(&request_input_real_format); |
---|
| 2014 | free(request_input_real_format); |
---|
[25] | 2015 | |
---|
[59] | 2016 | freeMaps(&request_output_real_format); |
---|
| 2017 | free(request_output_real_format); |
---|
[9] | 2018 | |
---|
| 2019 | free(REQUEST); |
---|
| 2020 | free(SERVICE_URL); |
---|
[1] | 2021 | #ifdef DEBUG |
---|
| 2022 | fprintf(stderr,"Processed response \n"); |
---|
| 2023 | fflush(stdout); |
---|
| 2024 | fflush(stderr); |
---|
| 2025 | #endif |
---|
| 2026 | |
---|
| 2027 | return 0; |
---|
| 2028 | } |
---|