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