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