Changeset 9 for trunk/zoo-kernel/zoo_service_loader.c
- Timestamp:
- Sep 14, 2010, 2:04:55 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-kernel/zoo_service_loader.c
r5 r9 27 27 extern "C" int yylex(); 28 28 extern "C" int crlex(); 29 30 29 31 extern "C" { 30 32 #include <libxml/tree.h> … … 71 73 #include <stdarg.h> 72 74 73 xml NodeSet*extractFromDoc(xmlDocPtr doc,char* search){75 xmlXPathObjectPtr extractFromDoc(xmlDocPtr doc,char* search){ 74 76 xmlXPathContextPtr xpathCtx; 75 77 xmlXPathObjectPtr xpathObj; 76 78 xpathCtx = xmlXPathNewContext(doc); 77 79 xpathObj = xmlXPathEvalExpression(BAD_CAST search,xpathCtx); 78 xmlXPathFreeContext(xpathCtx); 79 return xpathObj ->nodesetval;80 xmlXPathFreeContext(xpathCtx); 81 return xpathObj; 80 82 } 81 83 82 void sigint_handler(int sig){ 84 void sig_handler(int sig){ 85 char tmp[100]; 86 char *ssig; 87 switch(sig){ 88 case SIGSEGV: 89 ssig="SIGSEGV"; 90 break; 91 case SIGTERM: 92 ssig="SIGTERM"; 93 break; 94 case SIGINT: 95 ssig="SIGINT"; 96 break; 97 case SIGILL: 98 ssig="SIGILL"; 99 break; 100 case SIGFPE: 101 ssig="SIGFPE"; 102 break; 103 case SIGABRT: 104 ssig="SIGABRT"; 105 break; 106 default: 107 ssig="UNKNOWN"; 108 break; 109 } 110 sprintf(tmp,"ZOO Kernel failed to process your request receiving signal %d = %s",sig,ssig); 111 errorException(NULL, tmp, "InternalError"); 83 112 fprintf(stderr,"Not this time!\n"); 113 exit(0); 84 114 } 85 115 86 116 int runRequest(map* request_inputs) 87 117 { 118 119 (void) signal(SIGSEGV,sig_handler); 120 (void) signal(SIGTERM,sig_handler); 121 (void) signal(SIGINT,sig_handler); 122 (void) signal(SIGILL,sig_handler); 123 (void) signal(SIGFPE,sig_handler); 124 (void) signal(SIGABRT,sig_handler); 88 125 89 126 map* r_inputs=NULL,*tmps=NULL; … … 95 132 * Parsing service specfic configuration file 96 133 */ 97 m=(maps*)malloc(MAPS_SIZE); 134 m=(maps*)calloc(1,MAPS_SIZE); 135 if(m == NULL){ 136 return errorException(m, "Unable to allocate memory.", "InternalError"); 137 } 98 138 char ntmp[1024]; 99 139 #ifndef WIN32 … … 102 142 _getcwd(ntmp,1024); 103 143 #endif 104 char conf_file[1024]; 105 sprintf(conf_file,"%s/main.cfg",ntmp); 144 r_inputs=getMap(request_inputs,"metapath"); 145 if(r_inputs==NULL){ 146 if(request_inputs==NULL) 147 request_inputs=createMap("metapath",""); 148 else 149 addToMap(request_inputs,"metapath",""); 150 #ifdef DEBUG 151 fprintf(stderr,"ADD METAPATH\n"); 152 dumpMap(request_inputs); 153 #endif 154 r_inputs=getMap(request_inputs,"metapath"); 155 } 156 char conf_file[10240]; 157 snprintf(conf_file,10240,"%s/%s/main.cfg",ntmp,r_inputs->value); 106 158 conf_read(conf_file,m); 107 159 #ifdef DEBUG 160 fprintf(stderr, "***** BEGIN MAPS\n"); 161 dumpMaps(m); 162 fprintf(stderr, "***** END MAPS\n"); 163 #endif 164 108 165 /** 109 166 * Check for minimum inputs 110 167 */ 111 168 r_inputs=getMap(request_inputs,"Request"); 112 if(r_inputs==NULLMAP){ 113 tmps=createMap("text","Parameter <request> was not specified"); 114 addToMap(tmps,"code","MissingParameterValue"); 115 printExceptionReportResponse(m,tmps); 169 if(request_inputs==NULL || r_inputs==NULL){ 170 errorException(m, "Parameter <request> was not specified","MissingParameterValue"); 171 freeMaps(&m); 172 free(m); 173 freeMap(&request_inputs); 174 free(request_inputs); 116 175 return 1; 117 176 } 118 else 177 else{ 119 178 REQUEST=strdup(r_inputs->value); 120 r_inputs=NULL; 121 r_inputs=getMap(request_inputs,"Service"); 122 if(r_inputs==NULLMAP){ 123 tmps=createMap("text","Parameter <service> was not specified"); 124 addToMap(tmps,"code","MissingParameterValue"); 125 printExceptionReportResponse(m,tmps); 126 return 1; 127 } 128 if(strcmp(mtoupper(REQUEST),"GETCAPABILITIES")!=0){ 129 r_inputs=getMap(request_inputs,"Version"); 130 if(r_inputs==NULL){ 131 tmps=createMap("text","Parameter <version> was not specified"); 132 addToMap(tmps,"code","MissingParameterValue"); 133 printExceptionReportResponse(m,tmps); 179 if(strncasecmp(r_inputs->value,"GetCapabilities",15)!=0 180 && strncasecmp(r_inputs->value,"DescribeProcess",15)!=0 181 && strncasecmp(r_inputs->value,"Execute",7)!=0){ 182 errorException(m, "Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute.", "InvalidParameterValue"); 183 freeMaps(&m); 184 free(m); 185 freeMap(&request_inputs); 186 free(request_inputs); 187 free(REQUEST); 134 188 return 1; 135 189 } 136 190 } 137 138 /** 139 * Need to print std exception message here 140 */ 141 char SP[1024]; 142 if ((argc < 5 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")!=0) || (argc < 4 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")==0)){ 143 r_inputs=getMap(request_inputs,"ServiceProvider"); 144 if(r_inputs==NULLMAP){ 145 tmps=createMap("text","Parameter <serviceprovider> was not specified"); 146 addToMap(tmps,"code","MissingParameterValue"); 147 printExceptionReportResponse(m,tmps); 191 r_inputs=NULL; 192 r_inputs=getMap(request_inputs,"Service"); 193 if(r_inputs==NULLMAP){ 194 errorException(m, "Parameter <service> was not specified","MissingParameterValue"); 195 freeMaps(&m); 196 free(m); 197 free(REQUEST); 198 return 1; 199 } 200 if(strncasecmp(REQUEST,"GetCapabilities",15)!=0){ 201 r_inputs=getMap(request_inputs,"Version"); 202 if(r_inputs==NULL){ 203 errorException(m, "Parameter <version> was not specified","MissingParameterValue"); 204 freeMaps(&m); 205 free(m); 206 free(REQUEST); 148 207 return 1; 149 208 } 150 else 151 sprintf(SP,"%s",r_inputs->value); 152 r_inputs=getMap(request_inputs,"MetaPath"); 153 if(r_inputs==NULLMAP){ 154 tmps=createMap("text","Parameter <metapath> was not specified"); 155 addToMap(tmps,"code","MissingParameterValue"); 156 printExceptionReportResponse(m,tmps); 157 return 1; 158 } 159 tmps=createMap("text","Parameter <unknown> was not specified"); 160 addToMap(tmps,"code","MissingParameterValue"); 161 printExceptionReportResponse(m,tmps); 162 return 1; 209 } 210 211 r_inputs=getMap(request_inputs,"serviceprovider"); 212 if(r_inputs==NULL){ 213 addToMap(request_inputs,"serviceprovider",""); 163 214 } 164 215 … … 182 233 char tmps1[1024]; 183 234 184 if(strcmp(mtoupper(REQUEST),mtoupper("GetCapabilities"))==0){ 235 r_inputs=NULL; 236 r_inputs=getMap(request_inputs,"metapath"); 237 if(r_inputs!=NULL) 238 snprintf(conf_dir,1024,"%s/%s",ntmp,r_inputs->value); 239 else 240 snprintf(conf_dir,1024,"%s",ntmp); 241 242 if(strncasecmp(REQUEST,"GetCapabilities",15)==0){ 185 243 int i=0; 186 244 struct dirent *dp; 187 r_inputs=NULL;188 r_inputs=getMap(request_inputs,"metapath");189 245 #ifdef DEBUG 190 246 dumpMap(r_inputs); 191 247 #endif 192 sprintf(conf_dir,"%s/%s",ntmp,r_inputs->value); 193 DIR *dirp = opendir(conf_dir); 248 DIR *dirp = opendir(conf_dir); 194 249 if(dirp==NULL){ 195 tmps=createMap("text","The specified path doesn't exist."); 196 addToMap(tmps,"code","InvalidParameterValue"); 197 printExceptionReportResponse(m,tmps); 198 return -1; 250 return errorException(m, "The specified path doesn't exist.","InvalidParameterValue"); 199 251 } 200 252 xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); 201 doc->encoding = xmlCharStrdup ("UTF-8");202 253 r_inputs=NULL; 203 254 r_inputs=getMap(request_inputs,"ServiceProvider"); 204 xmlNodePtr n = printGetCapabilitiesHeader(doc,r_inputs->value,m); 255 xmlNodePtr n; 256 //dumpMap(request_inputs); 257 if(r_inputs!=NULL) 258 n = printGetCapabilitiesHeader(doc,r_inputs->value,m); 259 else 260 n = printGetCapabilitiesHeader(doc,"",m); 205 261 /** 206 262 * Strange, here we need to close stdout to ensure that no uneeded … … 211 267 while ((dp = readdir(dirp)) != NULL) 212 268 if(strstr(dp->d_name,".zcfg")!=0){ 213 sprintf(tmps1,"%s/%s",conf_dir,dp->d_name); 214 char *tmps=tmps1; 215 s1=(service*)malloc(sizeof(service*)); 216 s[0]=(service*)malloc(sizeof(service*)); 269 memset(tmps1,0,1024); 270 snprintf(tmps1,1024,"%s/%s",conf_dir,dp->d_name); 271 s1=(service*)calloc(1,SERVICE_SIZE); 272 if(s1 == NULL){ 273 return errorException(m, "Unable to allocate memory.","InternalError"); 274 } 217 275 #ifdef DEBUG 218 276 fprintf(stderr,"#################\n%s\n#################\n",tmps1); … … 224 282 fflush(stderr); 225 283 #endif 226 s[0]=s1;227 284 printGetCapabilitiesForProcess(m,n,s1); 228 //freeService(&s1);229 //s1=NULL;285 freeService(&s1); 286 free(s1); 230 287 scount++; 231 288 } … … 233 290 fflush(stdout); 234 291 dup2(saved_stdout,fileno(stdout)); 235 236 printDocument(doc); 292 printDocument(m,doc,getpid()); 293 freeMaps(&m); 294 free(m); 295 free(REQUEST); 296 free(SERVICE_URL); 237 297 fflush(stdout); 238 xmlFree(n);239 298 return 0; 240 299 } … … 243 302 if(r_inputs==NULL 244 303 || strlen(r_inputs->name)==0 || strlen(r_inputs->value)==0){ 245 if(r_inputs!=NULL && strlen(r_inputs->value)==0) 246 tmps=createMap("text","Mandatory value for <identifier> was not specified"); 247 else 248 tmps=createMap("text","Mandatory <identifier> was not specified"); 249 addToMap(tmps,"code","MissingParameterValue"); 250 printExceptionReportResponse(m,tmps); 251 return 1; 304 errorException(m, "Mandatory <identifier> was not specified","MissingParameterValue"); 305 freeMaps(&m); 306 free(m); 307 free(REQUEST); 308 free(SERVICE_URL); 309 return 0; 252 310 } 253 311 254 r_inputs=getMap(request_inputs,"metapath");255 sprintf(conf_dir,"%s/%s",ntmp,r_inputs->value);256 312 struct dirent *dp; 257 313 DIR *dirp = opendir(conf_dir); 258 314 if(dirp==NULL){ 259 tmps=createMap("text","The specified metapath path doesn't exist."); 260 addToMap(tmps,"code","InvalidParameterValue"); 261 printExceptionReportResponse(m,tmps); 262 return -1; 315 errorException(m, "The specified path path doesn't exist.","InvalidParameterValue"); 316 freeMaps(&m); 317 free(m); 318 free(REQUEST); 319 free(SERVICE_URL); 320 return 0; 263 321 } 264 if(str cmp(mtoupper(REQUEST),"DESCRIBEPROCESS")==0){322 if(strncasecmp(REQUEST,"DescribeProcess",15)==0){ 265 323 /** 266 324 * Loop over Identifier list 267 325 */ 268 326 xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); 269 doc->encoding = xmlCharStrdup ("UTF-8");270 327 r_inputs=NULL; 271 328 r_inputs=getMap(request_inputs,"ServiceProvider"); 329 272 330 xmlNodePtr n; 273 331 if(r_inputs!=NULL) 274 332 n = printDescribeProcessHeader(doc,r_inputs->value,m); 333 else 334 n = printDescribeProcessHeader(doc,"",m); 275 335 276 336 r_inputs=getMap(request_inputs,"Identifier"); … … 286 346 while(tmps){ 287 347 memset(buff,0,256); 288 s printf(buff,"%s.zcfg",tmps);348 snprintf(buff,256,"%s.zcfg",tmps); 289 349 memset(buff1,0,1024); 290 350 #ifdef DEBUG … … 294 354 if(strcmp(dp->d_name,buff)==0){ 295 355 memset(buff1,0,1024); 296 sprintf(buff1,"%s/%s",conf_dir,dp->d_name); 297 s1=(service*)malloc(sizeof(service*)); 298 s[scount]=(service*)malloc(sizeof(service*)); 299 #ifdef DEBUG 300 fprintf(stderr,"#################\n%s\n#################\n",tmps1); 356 snprintf(buff1,1024,"%s/%s",conf_dir,dp->d_name); 357 //s1=(service*)malloc(sizeof(service*)); 358 s1=(service*)calloc(1,SERVICE_SIZE); 359 if(s1 == NULL){ 360 return errorException(m, "Unable to allocate memory.","InternalError"); 361 } 362 #ifdef DEBUG 363 fprintf(stderr,"#################\n%s\n#################\n",buff1); 301 364 #endif 302 365 t=getServiceFromFile(buff1,&s1); 303 /*dumpService(s1); 304 fflush(stdout); 305 fflush(stderr);*/ 306 s[0]=s1; 307 printDescribeProcessForProcess(m,n,s,1); 366 #ifdef DEBUG 367 dumpService(s1); 368 #endif 369 printDescribeProcessForProcess(m,n,s1,1); 370 freeService(&s1); 371 free(s1); 308 372 scount++; 309 373 } … … 311 375 tmps=strtok(NULL,","); 312 376 } 313 (void)closedir(dirp);377 closedir(dirp); 314 378 fflush(stdout); 315 379 dup2(saved_stdout,fileno(stdout)); 316 317 printDocument(doc); 380 printDocument(m,doc,getpid()); 381 freeMaps(&m); 382 free(m); 383 free(REQUEST); 384 free(SERVICE_URL); 318 385 fflush(stdout); 319 386 //xmlFree(n); 320 387 #ifndef LINUX_FREE_ISSUE 321 free(s1); 388 if(s1) 389 free(s1); 322 390 #endif 323 391 return 0; 324 392 } 325 393 else 326 if(strcmp(mtoupper(REQUEST),"EXECUTE")!=0){ 327 tmps=createMap("text","Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."); 328 addToMap(tmps,"code","InvalidParameterValue"); 329 printExceptionReportResponse(m,tmps); 394 if(strncasecmp(REQUEST,"Execute",strlen(REQUEST))!=0){ 395 errorException(m, "Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute.", "InvalidParameterValue"); 330 396 #ifdef DEBUG 331 397 fprintf(stderr,"No request found %s",REQUEST); 332 398 #endif 399 closedir(dirp); 333 400 free(s); 334 401 return 0; 335 402 } 403 closedir(dirp); 336 404 } 337 405 338 406 s1=NULL; 339 s1=(service*)malloc(sizeof(service*)); 340 s[0]=(service*)malloc(sizeof(service*)); 407 s1=(service*)calloc(1,SERVICE_SIZE); 408 if(s1 == NULL){ 409 return errorException(m, "Unable to allocate memory.","InternalError"); 410 } 341 411 r_inputs=getMap(request_inputs,"MetaPath"); 342 sprintf(tmps1,"%s/%s",ntmp,r_inputs->value); 412 if(r_inputs!=NULL) 413 snprintf(tmps1,1024,"%s/%s",ntmp,r_inputs->value); 414 else 415 snprintf(tmps1,1024,"%s/",ntmp); 343 416 r_inputs=getMap(request_inputs,"Identifier"); 344 345 s printf(tmps1,"%s/%s.zcfg",strdup(tmps1),r_inputs->value);346 417 char *ttmp=strdup(tmps1); 418 snprintf(tmps1,1024,"%s/%s.zcfg",ttmp,r_inputs->value); 419 free(ttmp); 347 420 #ifdef DEBUG 348 421 fprintf(stderr,"Trying to load %s\n", tmps1); … … 354 427 dup2(saved_stdout,fileno(stdout)); 355 428 if(t==22){ 356 tmps=createMap("text","The value for <indetifier> seems to be wrong. Please, ensure that the process exsits using the GetCapabilities request."); 357 addToMap(tmps,"code","InvalidParameterValue"); 358 printExceptionReportResponse(m,tmps); 429 errorException(m, "The value for <indetifier> seems to be wrong. Please, ensure that the process exsits using the GetCapabilities request.", "InvalidParameterValue"); 359 430 exit(0); 360 431 } 361 s[0]=s1;432 //s[0]=s1; 362 433 363 434 #ifdef DEBUG … … 399 470 #endif 400 471 r_inputs=getMap(request_inputs,"ResponseDocument"); 401 if(r_inputs==NULL MAP)402 r_inputs=getMap(request_inputs,"RawDataOutput");403 #ifdef DEBUG472 if(r_inputs==NULL) r_inputs=getMap(request_inputs,"RawDataOutput"); 473 474 //#ifdef DEBUG 404 475 fprintf(stderr,"OUTPUT Parsing ... \n"); 405 #endif406 if(r_inputs!=NULL MAP){407 #ifdef DEBUG476 //#endif 477 if(r_inputs!=NULL){ 478 //#ifdef DEBUG 408 479 fprintf(stderr,"OUTPUT Parsing start now ... \n"); 409 #endif480 //#endif 410 481 char current_output_as_string[10240]; 411 482 char cursor_output[10240]; 412 sprintf(cursor_output,"%s",strdup(r_inputs->value)); 483 char *cotmp=strdup(r_inputs->value); 484 snprintf(cursor_output,10240,"%s",cotmp); 485 free(cotmp); 413 486 j=0; 414 487 map* request_kvp_outputs=NULL; … … 423 496 #endif 424 497 pToken=strtok(cursor_output,";"); 425 char** outputs_as_text=(char**)malloc(128*sizeof(char*)); 498 char** outputs_as_text=(char**)calloc(128,sizeof(char*)); 499 if(outputs_as_text == NULL) { 500 return errorException(m, "Unable to allocate memory", "InternalError"); 501 } 426 502 i=0; 427 503 while(pToken!=NULL){ … … 431 507 fprintf(stderr,"***%s***\n",pToken); 432 508 #endif 433 outputs_as_text[i]=(char*)malloc(strlen(pToken)*sizeof(char)); 434 sprintf(outputs_as_text[i],"%s",pToken); 509 outputs_as_text[i]=(char*)calloc(strlen(pToken)+1,sizeof(char)); 510 if(outputs_as_text[i] == NULL) { 511 return errorException(m, "Unable to allocate memory", "InternalError"); 512 } 513 snprintf(outputs_as_text[i],strlen(pToken)+1,"%s",pToken); 435 514 pToken = strtok(NULL,";"); 436 515 i++; … … 438 517 for(j=0;j<i;j++){ 439 518 char *tmp=strdup(outputs_as_text[j]); 519 free(outputs_as_text[j]); 440 520 char *tmpc; 441 521 tmpc=strtok(tmp,"@"); … … 444 524 if(k==0){ 445 525 if(tmp_output==NULL){ 446 tmp_output=(maps*)malloc(MAPS_SIZE); 526 tmp_output=(maps*)calloc(1,MAPS_SIZE); 527 if(tmp_output == NULL){ 528 return errorException(m, "Unable to allocate memory.", "InternalError"); 529 } 447 530 tmp_output->name=strdup(tmpc); 448 531 tmp_output->content=NULL; … … 473 556 } 474 557 if(request_output_real_format==NULL) 475 request_output_real_format= tmp_output;558 request_output_real_format=dupMaps(&tmp_output); 476 559 else 477 560 addMapsToMaps(&request_output_real_format,tmp_output); 561 freeMaps(&tmp_output); 562 free(tmp_output); 563 tmp_output=NULL; 478 564 #ifdef DEBUG 479 565 dumpMaps(tmp_output); 480 566 fflush(stderr); 481 567 #endif 482 tmp_output=tmp_output->next; 568 //tmp_output=tmp_output->next; 569 free(tmp); 483 570 } 571 free(outputs_as_text); 484 572 } 485 573 … … 494 582 char current_input_as_string[40960]; 495 583 char cursor_input[40960]; 496 sprintf(cursor_input,"%s",strdup(r_inputs->value)); 584 if(r_inputs!=NULL) 585 snprintf(cursor_input,40960,"%s",r_inputs->value); 586 else{ 587 errorException(m, "Parameter <DataInputs> was not specified","MissingParameterValue"); 588 freeMaps(&m); 589 free(m); 590 free(REQUEST); 591 free(SERVICE_URL); 592 return 0; 593 } 497 594 j=0; 498 595 map* request_kvp_inputs=NULL; … … 503 600 char * pToken; 504 601 pToken=strtok(cursor_input,";"); 505 char** inputs_as_text=(char**)malloc(100*sizeof(char*)); 602 char** inputs_as_text=(char**)calloc(100,sizeof(char*)); 603 if(inputs_as_text == NULL){ 604 return errorException(m, "Unable to allocate memory.", "InternalError"); 605 } 506 606 i=0; 507 607 while(pToken!=NULL){ … … 513 613 fprintf(stderr,"***%s***\n",pToken); 514 614 #endif 515 inputs_as_text[i]=(char*)malloc(strlen(pToken)*sizeof(char)); 516 sprintf(inputs_as_text[i],"%s",pToken); 615 inputs_as_text[i]=(char*)calloc(strlen(pToken)+1,sizeof(char)); 616 snprintf(inputs_as_text[i],strlen(pToken)+1,"%s",pToken); 617 if(inputs_as_text[i] == NULL){ 618 return errorException(m, "Unable to allocate memory.", "InternalError"); 619 } 517 620 pToken = strtok(NULL,";"); 518 621 i++; … … 521 624 for(j=0;j<i;j++){ 522 625 char *tmp=strdup(inputs_as_text[j]); 626 free(inputs_as_text[j]); 523 627 char *tmpc; 524 628 tmpc=strtok(tmp,"@"); … … 537 641 #endif 538 642 if(tmpmaps==NULL){ 539 tmpmaps=(maps*)malloc(MAPS_SIZE); 643 tmpmaps=(maps*)calloc(1,MAPS_SIZE); 644 if(tmpmaps == NULL){ 645 return errorException(m, "Unable to allocate memory.", "InternalError"); 646 } 540 647 tmpmaps->name=strdup(tmpn); 541 648 tmpmaps->content=createMap("value",tmpv+1); … … 566 673 #endif 567 674 #ifndef WIN32 568 if(CHECK_INET_HANDLE(hInternet)) 569 #endif 570 { 571 res=InternetOpenUrl(hInternet,tmpv1+1,NULL,0, 572 INTERNET_FLAG_NO_CACHE_WRITE,0); 573 #ifdef DEBUG 574 fprintf(stderr,"(%s) content-length : %d,,res.nDataAlloc %d \n", 575 tmpv1+1,res.nDataAlloc,res.nDataLen); 576 #endif 577 char* tmpContent=(char*)malloc((res.nDataLen+1)*sizeof(char)); 578 size_t dwRead; 579 InternetReadFile(res, (LPVOID)tmpContent,res.nDataLen, &dwRead); 580 map* tmpMap=getMap(tmpmaps->content,"value"); 581 if(tmpMap!=NULL) 582 tmpMap->value=tmpContent; 583 } 675 if(CHECK_INET_HANDLE(hInternet)) 676 #endif 677 { 678 res=InternetOpenUrl(hInternet,tmpv1+1,NULL,0, 679 INTERNET_FLAG_NO_CACHE_WRITE,0); 680 #ifdef DEBUG 681 fprintf(stderr,"(%s) content-length : %d,,res.nDataAlloc %d \n", 682 tmpv1+1,res.nDataAlloc,res.nDataLen); 683 #endif 684 char* tmpContent=(char*)calloc((res.nDataLen+1),sizeof(char)); 685 if(tmpContent == NULL){ 686 return errorException(m, "Unable to allocate memory.", "InternalError"); 687 } 688 size_t dwRead; 689 InternetReadFile(res, (LPVOID)tmpContent,res.nDataLen, &dwRead); 690 map* tmpMap=getMap(tmpmaps->content,"value"); 691 if(tmpMap!=NULL) 692 tmpMap->value=strdup(tmpContent); 693 free(tmpContent); 694 } 584 695 addToMap(tmpmaps->content,tmpn1,tmpv1+1); 585 696 } 586 697 tmpc=strtok(NULL,"@"); 587 698 } 699 #ifdef DEBUG 700 dumpMaps(tmpmaps); 701 fflush(stderr); 702 #endif 588 703 if(request_input_real_format==NULL) 589 request_input_real_format= tmpmaps;704 request_input_real_format=dupMaps(&tmpmaps); 590 705 else 591 706 addMapsToMaps(&request_input_real_format,tmpmaps); 592 #ifdef DEBUG 593 dumpMaps(tmpmaps); 594 fflush(stderr); 595 #endif 596 tmpmaps=tmpmaps->next; 707 /*freeMap(&tmpmaps->content); 708 free(tmpmaps->content); 709 tmpmaps->content=NULL;*/ 710 freeMaps(&tmpmaps); 711 free(tmpmaps); 712 //} 713 tmpmaps=NULL; 714 free(tmp); 597 715 } 598 716 } 599 } 717 free(inputs_as_text); 718 } 600 719 else { 720 /** 721 * Parse XML request 722 */ 601 723 xmlInitParser(); 602 724 #ifdef DEBUG … … 616 738 */ 617 739 maps* tempMaps=NULL; 618 xml NodeSet* tmps=extractFromDoc(doc,619 "/*/*/*[local-name()='Input']");740 xmlXPathObjectPtr tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='Input']"); 741 xmlNodeSet* tmps=tmpsptr->nodesetval; 620 742 #ifdef DEBUG 621 743 fprintf(stderr,"*****%d*****\n",tmps->nodeNr); … … 631 753 fprintf(stderr, "= element 0 node \"%s\"\n", cur->name); 632 754 #endif 633 xmlNodePtr cur1=cur->children; 634 while(cur1){ 635 #ifdef DEBUG 636 fprintf(stderr, "= element 1 node \"%s\" = (%s)\n", 637 cur1->name,xmlNodeListGetString(doc,cur1,1)); 638 #endif 639 xmlNodePtr cur2=cur1/*->next*/; 640 while(cur2){ 755 xmlNodePtr cur2=cur->children; 756 while(cur2){ 757 while(cur2->type!=XML_ELEMENT_NODE) 758 cur2=cur2->next; 759 /** 760 * Indentifier 761 */ 762 if(xmlStrncasecmp(cur2->name,BAD_CAST "Identifier",xmlStrlen(cur2->name))==0){ 763 xmlChar *val= xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); 764 if(tmpmaps==NULL){ 765 tmpmaps=(maps*)calloc(1,MAPS_SIZE); 766 if(tmpmaps == NULL){ 767 return errorException(m, "Unable to allocate memory.", "InternalError"); 768 } 769 tmpmaps->name=strdup((char*)val); 770 tmpmaps->content=NULL; 771 tmpmaps->next=NULL; 772 } 773 xmlFree(val); 774 } 775 /** 776 * Title, Asbtract 777 */ 778 if(xmlStrncasecmp(cur2->name,BAD_CAST "Title",xmlStrlen(cur2->name))==0 || 779 xmlStrncasecmp(cur2->name,BAD_CAST "Abstract",xmlStrlen(cur2->name))==0){ 780 xmlChar *val= 781 xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); 782 if(tmpmaps==NULL){ 783 tmpmaps=(maps*)calloc(1,MAPS_SIZE); 784 if(tmpmaps == NULL){ 785 return errorException(m, "Unable to allocate memory.", "InternalError"); 786 } 787 tmpmaps->name="missingIndetifier"; 788 tmpmaps->content=createMap((char*)cur2->name,(char*)val); 789 tmpmaps->next=NULL; 790 } 791 else{ 792 if(tmpmaps->content!=NULL) 793 addToMap(tmpmaps->content, 794 (char*)cur2->name,(char*)val); 795 else 796 tmpmaps->content= 797 createMap((char*)cur2->name,(char*)val); 798 } 799 #ifdef DEBUG 800 dumpMaps(tmpmaps); 801 #endif 802 xmlFree(val); 803 } 804 /** 805 * InputDataFormChoice (Reference or Data ?) 806 */ 807 if(xmlStrcasecmp(cur2->name,BAD_CAST "Reference")==0){ 641 808 /** 642 * Indentifier 809 * Get every attribute from a Reference node 810 * mimeType, encoding, schema, href, method 811 * Header and Body gesture should be added here 643 812 */ 644 if(strcmp(mtoupper((char*)cur2->name), 645 mtoupper("Identifier"))==0){ 646 xmlChar *val= 647 xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); 648 if(tmpmaps==NULL){ 649 tmpmaps=(maps*)malloc(MAPS_SIZE); 650 tmpmaps->name=strdup((char*)val); 651 tmpmaps->content=NULL; 652 tmpmaps->next=NULL; 813 #ifdef DEBUG 814 fprintf(stderr,"REFERENCE\n"); 815 #endif 816 map* referenceMap=NULL; 817 char *refs[5]; 818 refs[0]="mimeType"; 819 refs[1]="encoding"; 820 refs[2]="schema"; 821 refs[3]="method"; 822 refs[4]="href"; 823 char*url; 824 for(int l=0;l<5;l++){ 825 #ifdef DEBUG 826 fprintf(stderr,"*** %s ***",refs[l]); 827 #endif 828 xmlChar *val=xmlGetProp(cur2,BAD_CAST refs[l]); 829 if(val!=NULL && xmlStrlen(val)>0){ 830 if(tmpmaps->content!=NULL) 831 addToMap(tmpmaps->content,refs[l],(char*)val); 832 else 833 tmpmaps->content=createMap(refs[l],(char*)val); 834 map* ltmp=getMap(tmpmaps->content,"method"); 835 if(l==4){ 836 if(!(ltmp!=NULL && strcmp(ltmp->value,"POST")==0) 837 && CHECK_INET_HANDLE(hInternet)){ 838 res=InternetOpenUrl(hInternet,(char*)val,NULL,0, 839 INTERNET_FLAG_NO_CACHE_WRITE,0); 840 char* tmpContent= 841 (char*)calloc((res.nDataLen+1),sizeof(char)); 842 if(tmpContent == NULL){ 843 return errorException(m, "Unable to allocate memory.", "InternalError"); 844 } 845 size_t dwRead; 846 InternetReadFile(res, (LPVOID)tmpContent, 847 res.nDataLen, &dwRead); 848 tmpContent[res.nDataLen]=0; 849 addToMap(tmpmaps->content,"value",tmpContent); 850 } 851 } 653 852 } 853 #ifdef DEBUG 854 fprintf(stderr,"%s\n",val); 855 #endif 654 856 xmlFree(val); 655 857 } 656 /** 657 * Title, Asbtract 658 */ 659 if(strcmp(mtoupper((char*)cur2->name), 660 mtoupper("Title"))==0 || 661 strcmp(mtoupper((char*)cur2->name), 662 mtoupper("Abstract"))==0){ 663 xmlChar *val= 664 xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); 665 if(tmpmaps==NULL){ 666 tmpmaps=(maps*)malloc(MAPS_SIZE); 667 tmpmaps->name="missingIndetifier"; 668 tmpmaps->content=createMap((char*)cur2->name,(char*)val); 669 tmpmaps->next=NULL; 858 #ifdef POST_DEBUG 859 fprintf(stderr,"Parse Header and Body from Reference \n"); 860 #endif 861 xmlNodePtr cur3=cur2->children; 862 hInternet.header=NULL; 863 while(cur3){ 864 if(xmlStrcasecmp(cur3->name,BAD_CAST "Header")==0 ){ 865 xmlNodePtr cur4=cur3; 866 char *tmp=new char[cgiContentLength]; 867 char *ha[2]; 868 ha[0]="key"; 869 ha[1]="value"; 870 int hai; 871 char *has; 872 char *key; 873 for(hai=0;hai<2;hai++){ 874 xmlChar *val=xmlGetProp(cur3,BAD_CAST ha[hai]); 875 #ifdef POST_DEBUG 876 fprintf(stderr,"%s = %s\n",ha[hai],(char*)val); 877 #endif 878 if(hai==0){ 879 key=(char*)calloc((1+strlen((char*)val)),sizeof(char)); 880 snprintf(key,1+strlen((char*)val),"%s",(char*)val); 881 }else{ 882 has=(char*)calloc((3+strlen((char*)val)+strlen(key)),sizeof(char)); 883 if(has == NULL){ 884 return errorException(m, "Unable to allocate memory.", "InternalError"); 885 } 886 snprintf(has,(3+strlen((char*)val)+strlen(key)),"%s: %s",key,(char*)val); 887 #ifdef POST_DEBUG 888 fprintf(stderr,"%s\n",has); 889 #endif 890 } 891 } 892 hInternet.header=curl_slist_append(hInternet.header, has); 893 //free(has); 670 894 } 671 895 else{ 672 if(tmpmaps->content!=NULL) 673 addToMap(tmpmaps->content, 674 (char*)cur2->name,(char*)val); 896 #ifdef POST_DEBUG 897 fprintf(stderr,"Try to fetch the body part of the request ...\n"); 898 #endif 899 if(xmlStrcasecmp(cur3->name,BAD_CAST "Body")==0 ){ 900 #ifdef POST_DEBUG 901 fprintf(stderr,"Body part found !!!\n",(char*)cur3->content); 902 #endif 903 char *tmp=new char[cgiContentLength]; 904 memset(tmp,0,cgiContentLength); 905 xmlNodePtr cur4=cur3->children; 906 while(cur4!=NULL){ 907 xmlDocPtr bdoc = xmlNewDoc(BAD_CAST "1.0"); 908 bdoc->encoding = xmlCharStrdup ("UTF-8"); 909 xmlDocSetRootElement(bdoc,cur4); 910 xmlChar* btmps; 911 int bsize; 912 xmlDocDumpMemory(bdoc,&btmps,&bsize); 913 #ifdef POST_DEBUG 914 fprintf(stderr,"Body part found !!! %s %s\n",tmp,(char*)btmps); 915 #endif 916 if(btmps!=NULL) 917 sprintf(tmp,"%s",(char*)btmps); 918 xmlFreeDoc(bdoc); 919 cur4=cur4->next; 920 } 921 map *btmp=getMap(tmpmaps->content,"href"); 922 if(btmp!=NULL){ 923 #ifdef POST_DEBUG 924 fprintf(stderr,"%s %s\n",btmp->value,tmp); 925 curl_easy_setopt(hInternet.handle, CURLOPT_VERBOSE, 1); 926 #endif 927 res=InternetOpenUrl(hInternet,btmp->value,tmp,strlen(tmp), 928 INTERNET_FLAG_NO_CACHE_WRITE,0); 929 char* tmpContent = (char*)calloc((res.nDataLen+1),sizeof(char)); 930 if(tmpContent == NULL){ 931 return errorException(m, "Unable to allocate memory.", "InternalError"); 932 } 933 size_t dwRead; 934 InternetReadFile(res, (LPVOID)tmpContent, 935 res.nDataLen, &dwRead); 936 tmpContent[res.nDataLen]=0; 937 if(hInternet.header!=NULL) 938 curl_slist_free_all(hInternet.header); 939 addToMap(tmpmaps->content,"value",tmpContent); 940 #ifdef POST_DEBUG 941 fprintf(stderr,"DL CONTENT : (%s)\n",tmpContent); 942 #endif 943 } 944 } 675 945 else 676 tmpmaps->content= 677 createMap((char*)cur2->name,(char*)val); 678 } 679 #ifdef DEBUG 680 dumpMaps(tmpmaps); 681 #endif 682 xmlFree(val); 683 } 684 /** 685 * InputDataFormChoice (Reference or Data ?) 686 */ 687 if(strcmp(mtoupper((char*)cur2->name), 688 mtoupper("Reference"))==0){ 689 /** 690 * Get every attribute from a Reference node 691 * mimeType, encoding, schema, href, method 692 * Header and Body gesture should be added here 693 */ 694 #ifdef DEBUG 695 fprintf(stderr,"REFERENCE\n"); 696 #endif 697 map* referenceMap=NULL; 698 char *refs[5]; 699 refs[0]="mimeType"; 700 refs[1]="encoding"; 701 refs[2]="schema"; 702 refs[3]="method"; 703 refs[4]="href"; 704 char*url; 705 for(int l=0;l<5;l++){ 706 #ifdef DEBUG 707 fprintf(stderr,"*** %s ***\t",refs[l]); 708 #endif 709 xmlChar *val=xmlGetProp(cur2,BAD_CAST refs[l]); 710 if(val!=NULL && strlen((char*)val)>0){ 711 if(tmpmaps->content!=NULL) 712 addToMap(tmpmaps->content,refs[l],(char*)val); 713 else 714 tmpmaps->content=createMap(refs[l],(char*)val); 715 map* ltmp=getMap(tmpmaps->content,"method"); 716 if(l==4){ 717 if(!(ltmp!=NULL && strcmp(ltmp->value,"POST")==0) 718 && CHECK_INET_HANDLE(hInternet)){ 719 res=InternetOpenUrl(hInternet,(char*)val,NULL,0, 720 INTERNET_FLAG_NO_CACHE_WRITE,0); 721 char* tmpContent= 722 (char*)malloc((res.nDataLen+1)*sizeof(char)); 723 size_t dwRead; 724 InternetReadFile(res, (LPVOID)tmpContent, 725 res.nDataLen, &dwRead); 726 tmpContent[res.nDataLen]=0; 727 addToMap(tmpmaps->content,"value",tmpContent); 946 if(xmlStrcasecmp(cur3->name,BAD_CAST "BodyReference")==0 ){ 947 xmlChar *val=xmlGetProp(cur3,BAD_CAST "href"); 948 HINTERNET bInternet,res1; 949 bInternet=InternetOpen( 950 #ifndef WIN32 951 (LPCTSTR) 952 #endif 953 "ZooWPSClient\0", 954 INTERNET_OPEN_TYPE_PRECONFIG, 955 NULL,NULL, 0); 956 if(!CHECK_INET_HANDLE(bInternet)) 957 fprintf(stderr,"WARNING : hInternet handle failed to initialize"); 958 #ifdef POST_DEBUG 959 curl_easy_setopt(bInternet.handle, CURLOPT_VERBOSE, 1); 960 #endif 961 res1=InternetOpenUrl(bInternet,(char*)val,NULL,0, 962 INTERNET_FLAG_NO_CACHE_WRITE,0); 963 char* tmp= 964 (char*)calloc((res1.nDataLen+1),sizeof(char)); 965 if(tmp == NULL){ 966 return errorException(m, "Unable to allocate memory.", "InternalError"); 728 967 } 729 } 730 731 } 732 #ifdef DEBUG 733 fprintf(stderr,"%s\n",val); 734 #endif 735 xmlFree(val); 736 } 737 #ifdef POST_DEBUG 738 fprintf(stderr,"Parse Header and Body from Reference \n"); 739 #endif 740 xmlNodePtr cur3=cur2->children; 741 hInternet.header=NULL; 742 while(cur3){ 743 if(strcmp(mtoupper((char*)cur3->name), mtoupper("Header"))==0 ){ 744 xmlNodePtr cur4=cur3; 745 char *tmp=new char[cgiContentLength]; 746 char *ha[2]; 747 ha[0]="key"; 748 ha[1]="value"; 749 int hai; 750 char *has; 751 char *key; 752 for(hai=0;hai<2;hai++){ 753 xmlChar *val=xmlGetProp(cur3,BAD_CAST ha[hai]); 754 #ifdef POST_DEBUG 755 fprintf(stderr,"%s = %s\n",ha[hai],(char*)val); 756 #endif 757 if(hai==0){ 758 key=(char*)malloc((1+strlen((char*)val))*sizeof(char)); 759 sprintf(key,"%s",(char*)val); 760 }else{ 761 has=(char*)malloc((3+strlen((char*)val)+strlen(key))*sizeof(char)); 762 sprintf(has,"%s: %s",key,(char*)val); 763 #ifdef POST_DEBUG 764 fprintf(stderr,"%s\n",has); 765 #endif 766 } 767 } 768 hInternet.header=curl_slist_append(hInternet.header, has); 769 //free(has); 770 } 771 else{ 772 #ifdef POST_DEBUG 773 fprintf(stderr,"Try to fetch the body part of the request ...\n"); 774 #endif 775 if(strcmp(mtoupper((char*)cur3->name),mtoupper("Body"))==0 ){ 776 #ifdef POST_DEBUG 777 fprintf(stderr,"Body part found !!!\n",(char*)cur3->content); 778 #endif 779 char *tmp=new char[cgiContentLength]; 780 memset(tmp,cgiContentLength,0); 781 xmlNodePtr cur4=cur3->children; 782 while(cur4!=NULL){ 783 xmlDocPtr bdoc = xmlNewDoc(BAD_CAST "1.0"); 784 bdoc->encoding = xmlCharStrdup ("UTF-8"); 785 xmlDocSetRootElement(bdoc,cur4); 786 xmlChar* btmps; 787 int bsize; 788 xmlDocDumpMemory(bdoc,&btmps,&bsize); 789 #ifdef POST_DEBUG 790 fprintf(stderr,"Body part found !!! %s %s\n",tmp,(char*)btmps); 791 #endif 792 if(btmps!=NULL) 793 sprintf(tmp,"%s",(char*)btmps); 794 xmlFreeDoc(bdoc); 795 cur4=cur4->next; 796 } 968 size_t bRead; 969 InternetReadFile(res1, (LPVOID)tmp, 970 res1.nDataLen, &bRead); 971 tmp[res1.nDataLen]=0; 972 InternetCloseHandle(bInternet); 797 973 map *btmp=getMap(tmpmaps->content,"href"); 798 974 if(btmp!=NULL){ … … 801 977 curl_easy_setopt(hInternet.handle, CURLOPT_VERBOSE, 1); 802 978 #endif 803 res=InternetOpenUrl(hInternet,btmp->value,tmp,strlen(tmp), 979 res=InternetOpenUrl(hInternet,btmp->value,tmp, 980 strlen(tmp), 804 981 INTERNET_FLAG_NO_CACHE_WRITE,0); 805 char* tmpContent= 806 (char*)malloc((res.nDataLen+1)*sizeof(char)); 982 char* tmpContent = (char*)calloc((res.nDataLen+1),sizeof(char)); 983 if(tmpContent == NULL){ 984 return errorException(m, "Unable to allocate memory.", "InternalError"); 985 } 807 986 size_t dwRead; 808 987 InternetReadFile(res, (LPVOID)tmpContent, … … 817 996 } 818 997 } 819 else 820 if(strcmp(mtoupper((char*)cur3->name),mtoupper("BodyReference"))==0 ){ 821 xmlChar *val=xmlGetProp(cur3,BAD_CAST "href"); 822 HINTERNET bInternet,res1; 823 bInternet=InternetOpen( 824 #ifndef WIN32 825 (LPCTSTR) 826 #endif 827 "ZooWPSClient\0", 828 INTERNET_OPEN_TYPE_PRECONFIG, 829 NULL,NULL, 0); 830 if(!CHECK_INET_HANDLE(bInternet)) 831 fprintf(stderr,"WARNING : hInternet handle failed to initialize"); 998 } 999 cur3=cur3->next; 1000 } 832 1001 #ifdef POST_DEBUG 833 curl_easy_setopt(bInternet.handle, CURLOPT_VERBOSE, 1); 834 #endif 835 res1=InternetOpenUrl(bInternet,(char*)val,NULL,0, 836 INTERNET_FLAG_NO_CACHE_WRITE,0); 837 char* tmp= 838 (char*)malloc((res1.nDataLen+1)*sizeof(char)); 839 size_t bRead; 840 InternetReadFile(res1, (LPVOID)tmp, 841 res1.nDataLen, &bRead); 842 tmp[res1.nDataLen]=0; 843 InternetCloseHandle(bInternet); 844 map *btmp=getMap(tmpmaps->content,"href"); 845 if(btmp!=NULL){ 846 #ifdef POST_DEBUG 847 fprintf(stderr,"%s %s\n",btmp->value,tmp); 848 curl_easy_setopt(hInternet.handle, CURLOPT_VERBOSE, 1); 849 #endif 850 res=InternetOpenUrl(hInternet,btmp->value,tmp, 851 strlen(tmp), 852 INTERNET_FLAG_NO_CACHE_WRITE,0); 853 char* tmpContent= 854 (char*)malloc((res.nDataLen+1)*sizeof(char)); 855 size_t dwRead; 856 InternetReadFile(res, (LPVOID)tmpContent, 857 res.nDataLen, &dwRead); 858 tmpContent[res.nDataLen]=0; 859 if(hInternet.header!=NULL) 860 curl_slist_free_all(hInternet.header); 861 addToMap(tmpmaps->content,"value",tmpContent); 862 #ifdef POST_DEBUG 863 fprintf(stderr,"DL CONTENT : (%s)\n",tmpContent); 864 #endif 865 } 866 } 867 } 868 cur3=cur3->next; 869 } 870 #ifdef POST_DEBUG 871 fprintf(stderr,"Header and Body was parsed from Reference \n"); 872 #endif 873 #ifdef DEBUG 874 dumpMap(tmpmaps->content); 875 fprintf(stderr, "= element 2 node \"%s\" = (%s)\n", 876 cur2->name,cur2->content); 877 #endif 878 } 879 else if(strcmp(mtoupper((char*)cur2->name), 880 mtoupper("Data"))==0){ 881 #ifdef DEBUG 882 fprintf(stderr,"DATA\n"); 883 #endif 884 xmlNodePtr cur4=cur2->children; 885 while(cur4){ 886 if(strcmp(mtoupper((char*)cur4->name), 887 mtoupper("LiteralData"))==0){ 888 /** 889 * Get every attribute from a LiteralData node 890 * dataType , uom 891 */ 892 char *lits[2]; 893 lits[0]="dataType"; 894 lits[1]="uom"; 895 for(int l=0;l<2;l++){ 896 #ifdef DEBUG 897 fprintf(stderr,"*** %s ***\t",lits[l]); 898 #endif 899 xmlChar *val=xmlGetProp(cur4,BAD_CAST lits[l]); 900 if(val!=NULL && strlen((char*)val)>0){ 901 if(tmpmaps->content!=NULL) 902 addToMap(tmpmaps->content,lits[l],(char*)val); 903 else 904 tmpmaps->content=createMap(lits[l],(char*)val); 905 } 906 #ifdef DEBUG 907 fprintf(stderr,"%s\n",val); 908 #endif 909 xmlFree(val); 910 } 911 xmlChar* mv=xmlNodeListGetString(doc, 912 cur4->xmlChildrenNode,1); 913 if(tmpmaps->content!=NULL) 914 addToMap(tmpmaps->content, 915 "value", 916 (char*)mv); 917 else 918 tmpmaps->content= 919 createMap("value", 920 (char*)mv); 921 xmlFree(mv); 922 } 923 else if(strcmp(mtoupper((char*)cur4->name), 924 mtoupper("ComplexData"))==0){ 925 /** 926 * Get every attribute from a Reference node 927 * mimeType, encoding, schema 928 */ 929 char *coms[2]; 930 coms[0]="mimeType"; 931 coms[1]="encoding"; 932 coms[2]="schema"; 933 for(int l=0;l<2;l++){ 934 #ifdef DEBUG 935 fprintf(stderr,"*** %s ***\t",coms[l]); 936 #endif 937 xmlChar *val=xmlGetProp(cur4,BAD_CAST coms[l]); 938 if(val!=NULL && strlen((char*)val)>0){ 939 if(tmpmaps->content!=NULL) 940 addToMap(tmpmaps->content,coms[l],(char*)val); 941 else 942 tmpmaps->content=createMap(coms[l],(char*)val); 943 } 944 #ifdef DEBUG 945 fprintf(stderr,"%s\n",val); 946 #endif 947 xmlFree(val); 948 } 949 xmlChar* mv=xmlNodeListGetString(doc, 950 cur4->xmlChildrenNode,1); 951 if(tmpmaps->content!=NULL) 952 addToMap(tmpmaps->content, 953 "value", 954 (char*)mv); 955 else 956 tmpmaps->content= 957 createMap("value", 958 (char*)mv); 959 xmlFree(mv); 960 } 961 cur4=cur4->next; 962 } 963 } 1002 fprintf(stderr,"Header and Body was parsed from Reference \n"); 1003 #endif 964 1004 #ifdef DEBUG 965 1005 dumpMap(tmpmaps->content); 966 1006 fprintf(stderr, "= element 2 node \"%s\" = (%s)\n", 967 cur2->name,cur2->content); 968 #endif 969 xmlNodePtr cur3=cur->children; 970 while(cur3){ 971 #ifdef DEBUG 972 fprintf(stderr, "= element 3 node \"%s\" = (%s)\n",cur3->name, 973 xmlNodeListGetString(doc,cur3->xmlChildrenNode,1)); 974 #endif 975 if(strcmp(mtoupper((char*)cur3->name), 976 mtoupper("Title"))==0){ 977 #ifdef DEBUG 978 fprintf(stderr, "= element 3 node \"%s\" = (%s)\n", 979 cur3->name,xmlNodeListGetString(doc,cur3,1)); 980 #endif 1007 cur2->name,cur2->content); 1008 #endif 1009 } 1010 else if(xmlStrcasecmp(cur2->name,BAD_CAST "Data")==0){ 1011 #ifdef DEBUG 1012 fprintf(stderr,"DATA\n"); 1013 #endif 1014 xmlNodePtr cur4=cur2->children; 1015 while(cur4){ 1016 while(cur4->type!=XML_ELEMENT_NODE) 1017 cur4=cur4->next; 1018 1019 if(xmlStrcasecmp(cur4->name, BAD_CAST "LiteralData")==0){ 1020 /** 1021 * Get every attribute from a LiteralData node 1022 * dataType , uom 1023 */ 1024 char *lits[2]; 1025 lits[0]="dataType"; 1026 lits[1]="uom"; 1027 for(int l=0;l<2;l++){ 1028 #ifdef DEBUG 1029 fprintf(stderr,"*** LiteralData %s ***",lits[l]); 1030 #endif 1031 xmlChar *val=xmlGetProp(cur4,BAD_CAST lits[l]); 1032 if(val!=NULL && strlen((char*)val)>0){ 1033 if(tmpmaps->content!=NULL) 1034 addToMap(tmpmaps->content,lits[l],(char*)val); 1035 else 1036 tmpmaps->content=createMap(lits[l],(char*)val); 1037 } 1038 #ifdef DEBUG 1039 fprintf(stderr,"%s\n",val); 1040 #endif 1041 xmlFree(val); 1042 } 981 1043 } 982 cur3=cur3->children; 1044 else if(xmlStrcasecmp(cur4->name, BAD_CAST "ComplexData")==0){ 1045 /** 1046 * Get every attribute from a Reference node 1047 * mimeType, encoding, schema 1048 */ 1049 char *coms[3]; 1050 coms[0]="mimeType"; 1051 coms[1]="encoding"; 1052 coms[2]="schema"; 1053 for(int l=0;l<3;l++){ 1054 #ifdef DEBUG 1055 fprintf(stderr,"*** ComplexData %s ***",coms[l]); 1056 #endif 1057 xmlChar *val=xmlGetProp(cur4,BAD_CAST coms[l]); 1058 if(val!=NULL && strlen((char*)val)>0){ 1059 if(tmpmaps->content!=NULL) 1060 addToMap(tmpmaps->content,coms[l],(char*)val); 1061 else 1062 tmpmaps->content=createMap(coms[l],(char*)val); 1063 } 1064 #ifdef DEBUG 1065 fprintf(stderr,"%s\n",val); 1066 #endif 1067 xmlFree(val); 1068 } 1069 } 1070 xmlChar* mv=xmlNodeListGetString(doc,cur4->xmlChildrenNode,1); 1071 addToMap(tmpmaps->content,"value",(char*)mv); 1072 xmlFree(mv); 1073 cur4=cur4->next; 983 1074 } 984 cur2=cur2->next;985 1075 } 986 cur1=cur1->children; 1076 #ifdef DEBUG 1077 fprintf(stderr,"cur2 next \n"); 1078 fflush(stderr); 1079 #endif 1080 cur2=cur2->next; 987 1081 } 988 if(request_input_real_format==NULL) 989 request_input_real_format=tmpmaps; 990 else 991 addMapsToMaps(&request_input_real_format,tmpmaps); 992 #ifdef DEBUG 1082 #ifdef DEBUG 1083 fprintf(stderr,"ADD MAPS TO REQUEST MAPS !\n"); 1084 fflush(stderr); 1085 #endif 1086 addMapsToMaps(&request_input_real_format,tmpmaps); 1087 1088 #ifdef DEBUG 1089 fprintf(stderr,"******TMPMAPS*****\n"); 993 1090 dumpMaps(tmpmaps); 994 #endif 995 fflush(stderr); 1091 fprintf(stderr,"******REQUESTMAPS*****\n"); 1092 dumpMaps(request_input_real_format); 1093 #endif 996 1094 tmpmaps=tmpmaps->next; 997 1095 998 } else {999 #ifdef DEBUG1000 fprintf(stderr, "= node \"%s\": type %d\n", cur->name, cur->type);1001 #endif1002 1096 } 1003 1097 #ifdef DEBUG … … 1005 1099 #endif 1006 1100 } 1007 1008 xmlFree(tmps); 1009 tmps=extractFromDoc(doc,"/*/*/*[local-name()='ResponseDocument']"); 1101 #ifdef DEBUG 1102 fprintf(stderr,"Search for response document node\n"); 1103 #endif 1104 xmlXPathFreeObject(tmpsptr); 1105 //xmlFree(tmps); 1106 tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='ResponseDocument']"); 1107 tmps=tmpsptr->nodesetval; 1010 1108 #ifdef DEBUG 1011 1109 fprintf(stderr,"*****%d*****\n",tmps->nodeNr); … … 1021 1119 */ 1022 1120 if(tmpmaps==NULL){ 1023 tmpmaps=(maps*)malloc(MAPS_SIZE); 1121 tmpmaps=(maps*)calloc(1,MAPS_SIZE); 1122 if(tmpmaps == NULL){ 1123 return errorException(m, "Unable to allocate memory.", "InternalError"); 1124 } 1024 1125 tmpmaps->name="unknownIdentifier"; 1025 1126 tmpmaps->next=NULL; … … 1053 1154 xmlNodePtr cur1=cur->children; 1054 1155 while(cur1){ 1055 if(strcmp(mtoupper((char*)cur1->name), 1056 mtoupper("Output"))==0){ 1156 if(xmlStrncasecmp(cur1->name,BAD_CAST "Output",xmlStrlen(cur1->name))==0){ 1057 1157 /** 1058 1158 * Get every attribute from a Output node … … 1087 1187 * Indentifier 1088 1188 */ 1089 if(strcmp(mtoupper((char*)cur2->name), 1090 mtoupper("Identifier"))==0){ 1189 if(xmlStrncasecmp(cur2->name,BAD_CAST "Identifier",xmlStrlen(cur2->name))==0){ 1091 1190 xmlChar *val= 1092 1191 xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); 1093 1192 if(tmpmaps==NULL){ 1094 tmpmaps=(maps*)malloc(MAPS_SIZE); 1193 tmpmaps=(maps*)calloc(1,MAPS_SIZE); 1194 if(tmpmaps == NULL){ 1195 return errorException(m, "Unable to allocate memory.", "InternalError"); 1196 } 1095 1197 tmpmaps->name=strdup((char*)val); 1096 1198 tmpmaps->content=NULL; … … 1104 1206 * Title, Asbtract 1105 1207 */ 1106 if(strcmp(mtoupper((char*)cur2->name), 1107 mtoupper("Title"))==0 || 1108 strcmp(mtoupper((char*)cur2->name), 1109 mtoupper("Abstract"))==0){ 1208 if(xmlStrncasecmp(cur2->name,BAD_CAST "Title",xmlStrlen(cur2->name))==0 || 1209 xmlStrncasecmp(cur2->name,BAD_CAST "Abstract",xmlStrlen(cur2->name))==0){ 1110 1210 xmlChar *val= 1111 1211 xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); 1112 1212 if(tmpmaps==NULL){ 1113 tmpmaps=(maps*)malloc(MAPS_SIZE); 1213 tmpmaps=(maps*)calloc(1,MAPS_SIZE); 1214 if(tmpmaps == NULL){ 1215 return errorException(m, "Unable to allocate memory.", "InternalError"); 1216 } 1114 1217 tmpmaps->name="missingIndetifier"; 1115 1218 tmpmaps->content=createMap((char*)cur2->name,(char*)val); … … 1141 1244 #endif 1142 1245 } 1143 1144 xmlFree(tmps); 1145 tmps=extractFromDoc(doc,"/*/*/*[local-name()='RawDataOutput']"); 1246 xmlXPathFreeObject(tmpsptr); 1247 //xmlFree(tmps); 1248 tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='RawDataOutput']"); 1249 tmps=tmpsptr->nodesetval; 1146 1250 #ifdef DEBUG 1147 1251 fprintf(stderr,"*****%d*****\n",tmps->nodeNr); … … 1167 1271 if(val!=NULL && strlen((char*)val)>0){ 1168 1272 if(tmpmaps==NULL){ 1169 tmpmaps=(maps*)malloc(MAPS_SIZE); 1273 tmpmaps=(maps*)calloc(1,MAPS_SIZE); 1274 if(tmpmaps == NULL){ 1275 return errorException(m, "Unable to allocate memory.", "InternalError"); 1276 } 1170 1277 tmpmaps->name="unknownIdentifier"; 1171 1278 tmpmaps->content=createMap(outs[l],(char*)val); … … 1186 1293 * Indentifier 1187 1294 */ 1188 if(strcmp(mtoupper((char*)cur2->name), 1189 mtoupper("Identifier"))==0){ 1295 if(xmlStrncasecmp(cur2->name,BAD_CAST "Identifier",xmlStrlen(cur2->name))==0){ 1190 1296 val= 1191 1297 xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); 1192 1298 if(tmpmaps==NULL){ 1193 tmpmaps=(maps*)malloc(MAPS_SIZE); 1299 tmpmaps=(maps*)calloc(1,MAPS_SIZE); 1300 if(tmpmaps == NULL){ 1301 return errorException(m, "Unable to allocate memory.", "InternalError"); 1302 } 1194 1303 tmpmaps->name=strdup((char*)val); 1195 1304 tmpmaps->content=NULL; … … 1210 1319 #endif 1211 1320 } 1212 1213 xmlFree(tmps);1321 xmlXPathFreeObject(tmpsptr); 1322 //xmlFree(tmps); 1214 1323 xmlCleanupParser(); 1215 1324 } 1216 1325 1217 if(CHECK_INET_HANDLE(hInternet))1218 1326 //if(CHECK_INET_HANDLE(hInternet)) 1327 InternetCloseHandle(hInternet); 1219 1328 1220 1329 #ifdef DEBUG … … 1222 1331 dumpMaps(request_input_real_format); 1223 1332 dumpMaps(request_output_real_format); 1224 dump Elements();1333 dumpMap(request_inputs); 1225 1334 #endif 1226 1335 … … 1228 1337 * Ensure that each requested arguments are present in the request 1229 1338 * DataInputs and ResponseDocument / RawDataOutput 1230 */ 1231 addDefaultValues(&request_input_real_format,s1->inputs,m,"inputs"); 1339 */ 1340 char *dfv=addDefaultValues(&request_input_real_format,s1->inputs,m,"inputs"); 1341 if(strcmp(dfv,"")!=0){ 1342 char tmps[1024]; 1343 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); 1344 map* tmpe=createMap("text",tmps); 1345 addToMap(tmpe,"code","MissingParameterValue"); 1346 printExceptionReportResponse(m,tmpe); 1347 freeMap(&tmpe); 1348 free(tmpe); 1349 freeMaps(&m); 1350 free(m); 1351 free(REQUEST); 1352 freeMaps(&request_input_real_format); 1353 free(request_input_real_format); 1354 freeMaps(&request_output_real_format); 1355 free(request_output_real_format); 1356 freeMaps(&tmpmaps); 1357 free(tmpmaps); 1358 return 1; 1359 } 1232 1360 addDefaultValues(&request_output_real_format,s1->outputs,m,"outputs"); 1233 1361 1234 const struct tm *tm; 1235 size_t len; 1236 time_t now; 1237 char *sDate; 1238 1239 now = time ( NULL ); 1240 tm = localtime ( &now ); 1241 1242 sDate = new char[TIME_SIZE]; 1362 #ifdef DEBUG 1363 fprintf(stderr,"REQUEST_INPUTS\n"); 1364 dumpMaps(request_input_real_format); 1365 fprintf(stderr,"REQUEST_OUTPUTS\n"); 1366 dumpMaps(request_output_real_format); 1367 #endif 1243 1368 1244 1369 maps* curs=getMaps(m,"env"); … … 1280 1405 } 1281 1406 1282 len = strftime ( sDate, TIME_SIZE, "%d-%B-%YT%I:%M:%SZ", tm );1283 1284 1407 #ifdef DEBUG 1285 1408 dumpMap(request_inputs); … … 1297 1420 #endif 1298 1421 1422 if(r_inputs!=NULL) 1423 if(strcasecmp(r_inputs->value,"false")==0) 1424 r_inputs=NULL; 1299 1425 if(r_inputs==NULLMAP){ 1300 1426 /** … … 1307 1433 fflush(stderr); 1308 1434 #endif 1309 1310 if(strncmp(mtoupper(r_inputs->value),"C",1)==0){ 1435 if(strncasecmp(r_inputs->value,"C",1)==0){ 1311 1436 r_inputs=getMap(request_inputs,"metapath"); 1312 sprintf(tmps1,"%s/%s",ntmp,r_inputs->value); 1313 char *altPath=strdup(tmps1); 1437 if(r_inputs!=NULL) 1438 sprintf(tmps1,"%s/%s",ntmp,r_inputs->value); 1439 else 1440 sprintf(tmps1,"%s/",ntmp); 1441 char *altPath=strdup(tmps1); 1314 1442 r_inputs=getMap(s1->content,"ServiceProvider"); 1315 1443 sprintf(tmps1,"%s/%s",altPath,r_inputs->value); 1316 1444 free(altPath); 1317 1445 #ifdef DEBUG 1318 1446 fprintf(stderr,"Trying to load %s\n",tmps1); 1319 1447 #endif 1320 1448 #ifdef WIN32 1321 1449 HINSTANCE so = LoadLibraryEx(tmps1,NULL,LOAD_WITH_ALTERED_SEARCH_PATH); 1322 1450 #else 1323 1451 void* so = dlopen(tmps1, RTLD_LAZY); 1324 1452 #endif 1453 #ifdef DEBUG 1325 1454 #ifdef WIN32 1326 1455 DWORD errstr; 1327 errstr = GetLastError(); 1328 #ifdef DEBUG 1329 fprintf(stderr,"%s loaded (%d) \n",tmps1,errstr); 1330 #endif 1456 errstr = GetLastError(); 1457 fprintf(stderr,"%s loaded (%d) \n",tmps1,errstr); 1331 1458 #else 1332 1459 char *errstr; 1333 errstr = dlerror(); 1460 errstr = dlerror(); 1461 #endif 1334 1462 #endif 1335 1463 … … 1342 1470 #ifdef DEBUG 1343 1471 dumpMap(r_inputs); 1344 fprintf(stderr,"%s %s",r_inputs->value,mtoupper(r_inputs->value));1472 fprintf(stderr,"%s\n",r_inputs->value); 1345 1473 fflush(stderr); 1346 1474 #endif 1347 if(str cmp(mtoupper(r_inputs->value),"C-FORTRAN")==0){1475 if(strncasecmp(r_inputs->value,"C-FORTRAN",9)==0){ 1348 1476 #ifdef WIN32 1349 1477 //Strange return value needed here ! … … 1352 1480 r_inputs=getMap(request_inputs,"Identifier"); 1353 1481 char fname[1024]; 1354 sprintf(fname,"%s ",r_inputs->value);1482 sprintf(fname,"%s_",r_inputs->value); 1355 1483 #ifdef DEBUG 1356 1484 fprintf(stderr,"Try to load function %s\n",fname); … … 1371 1499 fprintf(stderr,"Function loaded %s\n",errstr); 1372 1500 #endif 1501 1373 1502 char main_conf[10][30][1024]; 1374 1503 char inputs[10][30][1024]; … … 1390 1519 charxxxToMaps((char***)&outputs[0],&request_output_real_format); 1391 1520 }else{ 1521 #ifdef DEBUG 1392 1522 #ifdef WIN32 1393 1523 errstr = GetLastError(); 1394 #ifdef DEBUG1395 1524 fprintf(stderr,"Function %s failed to load because of %d\n",r_inputs->value,errstr); 1396 1525 #endif … … 1404 1533 execute_t execute=(execute_t)GetProcAddress(so,r_inputs->value); 1405 1534 #ifdef DEBUG 1406 /*if(!execute)*/1407 1535 errstr = GetLastError(); 1408 1536 fprintf(stderr,"Function %s failed to load because of %d\n",r_inputs->value,errstr); 1409 /*else1410 fprintf(stderr,"Function %s loaded\n",r_inputs->value);*/1411 1537 #endif 1412 1538 #else … … 1433 1559 #endif 1434 1560 } 1435 1436 1561 dlclose(so); 1437 1562 } else { … … 1440 1565 */ 1441 1566 char tmps[1024]; 1567 #ifdef WIN32 1568 DWORD errstr = GetLastError(); 1569 #else 1570 char* errstr = dlerror(); 1571 #endif 1442 1572 sprintf(tmps,"C Library can't be loaded %s \n",errstr); 1443 1573 map* tmps1=createMap("text",tmps); … … 1447 1577 } 1448 1578 else{ 1449 if(strcmp(mtoupper(r_inputs->value),"PYTHON")==0){1450 1451 1452 1453 1454 1455 if(str cmp(mtoupper(r_inputs->value),"JAVA")==0){1579 if(strncasecmp(r_inputs->value,"PYTHON",6)==0){ 1580 eres=zoo_python_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); 1581 } 1582 else 1583 1584 #ifdef USE_JAVA 1585 if(strncasecmp(r_inputs->value,"JAVA",4)==0){ 1456 1586 eres=zoo_java_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); 1457 1587 } 1458 1588 else 1459 1460 1461 1462 if(str cmp(mtoupper(r_inputs->value),"PHP")==0){1589 #endif 1590 1591 #ifdef USE_PHP 1592 if(strncasecmp(r_inputs->value,"PHP",3)==0){ 1463 1593 eres=zoo_php_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); 1464 1594 } 1465 else1466 1467 1468 1469 if(str cmp(mtoupper(r_inputs->value),"JS")==0){1595 else 1596 #endif 1597 1598 #ifdef USE_JS 1599 if(strncasecmp(r_inputs->value,"JS",2)==0){ 1470 1600 eres=zoo_js_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); 1471 1601 } 1472 1602 else 1473 1474 1475 1476 1477 1478 1479 1480 }1603 #endif 1604 { 1605 char tmpv[1024]; 1606 sprintf(tmpv,"Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n",r_inputs->value); 1607 map* tmps=createMap("text",tmpv); 1608 printExceptionReportResponse(m,tmps); 1609 return(-1); 1610 } 1481 1611 } 1482 1612 } … … 1487 1617 fprintf(stderr,"\nPID : %d\n",cpid); 1488 1618 #endif 1619 1489 1620 #ifndef WIN32 1490 1621 pid = fork (); 1491 1622 #else 1492 1623 pid = 0; 1493 1624 #endif 1494 1625 if (pid > 0) { … … 1506 1637 * process answer to http client. 1507 1638 */ 1508 char tmp1[256];1509 1639 r_inputs=getMapFromMaps(m,"main","tmpPath"); 1510 sprintf(tmp1,"%s",r_inputs->value); 1511 r_inputs=getMap(s1->content,"ServiceProvider"); 1512 sprintf(tmp1,"%s/%s",strdup(tmp1),r_inputs->value); 1513 sprintf(tmp1,"%s_%d.xml",strdup(tmp1),cpid); 1640 map* r_inputs1=getMap(s1->content,"ServiceProvider"); 1641 char* fbkp=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+16)*sizeof(char)); 1642 sprintf(fbkp,"%s/%s_%d.xml",r_inputs->value,r_inputs1->value,cpid); 1643 char* flog=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+22)*sizeof(char)); 1644 sprintf(flog,"%s/%s_%d_error.log",r_inputs->value,r_inputs1->value,cpid); 1645 fprintf(stderr,"File to use as backup %s\n",fbkp); 1514 1646 #ifdef DEBUG 1515 1647 fprintf(stderr,"RUN IN BACKGROUND MODE \n"); 1516 1648 fprintf(stderr,"son pid continue (origin %d) %d ...\n",cpid,getpid()); 1517 fprintf(stderr,"\nFILE TO STORE DATA %s\n", tmp1);1518 #endif 1519 freopen( tmp1, "w+", stdout);1649 fprintf(stderr,"\nFILE TO STORE DATA %s\n",r_inputs->value); 1650 #endif 1651 freopen(fbkp , "w+", stdout); 1520 1652 fclose(stdin); 1521 r_inputs=getMapFromMaps(m,"main","tmpPath"); 1522 sprintf(tmp1,"%s",r_inputs->value); 1523 r_inputs=getMap(s1->content,"ServiceProvider"); 1524 sprintf(tmp1,"%s/%s",strdup(tmp1),r_inputs->value); 1525 sprintf(tmp1,"%s_%d_error.log",strdup(tmp1),cpid); 1526 freopen(tmp1,"w+",stderr); 1653 freopen(flog,"w+",stderr); 1654 free(fbkp); 1655 free(flog); 1527 1656 /** 1528 1657 * set status to SERVICE_STARTED and flush stdout to ensure full … … 1531 1660 * this way the data will be updated at the end of the process run. 1532 1661 */ 1533 printProcessResponse 1(m,request_inputs,cpid,1534 s [0],r_inputs->value,SERVICE_STARTED,1662 printProcessResponse(m,request_inputs,cpid, 1663 s1,r_inputs->value,SERVICE_STARTED, 1535 1664 request_input_real_format, 1536 1665 request_output_real_format); … … 1546 1675 #endif 1547 1676 1548 if(strncmp(mtoupper(r_inputs->value),"C",1)==0){ 1677 if(strncasecmp(r_inputs->value,"C",1)==0){ 1678 1549 1679 r_inputs=getMap(request_inputs,"metapath"); 1550 sprintf(tmps1,"%s/%s",ntmp,r_inputs->value); 1551 r_inputs=getMap(s1->content,"ServiceProvider"); 1552 sprintf(tmps1,"%s/%s",strdup(tmps1),r_inputs->value); 1680 if(r_inputs!=NULL){ 1681 sprintf(tmps1,"%s/%s",ntmp,r_inputs->value); 1682 r_inputs=getMap(s1->content,"ServiceProvider"); 1683 if(r_inputs!=NULL) 1684 sprintf(tmps1,"%s/%s",strdup(tmps1),r_inputs->value); 1685 }else{ 1686 sprintf(tmps1,"%s/",ntmp); 1687 } 1688 1553 1689 1554 1690 #ifdef DEBUG … … 1556 1692 #endif 1557 1693 #ifdef WIN32 1558 1694 HINSTANCE so = LoadLibraryEx(tmps1,NULL,LOAD_WITH_ALTERED_SEARCH_PATH); 1559 1695 #else 1560 1696 void* so = dlopen(tmps1, RTLD_LAZY); 1561 1697 #endif 1562 1698 #ifdef WIN32 1563 1564 1699 DWORD errstr; 1700 errstr = GetLastError(); 1565 1701 #else 1566 1567 1702 char *errstr; 1703 errstr = dlerror(); 1568 1704 #endif 1569 1705 if( so != NULL ) { … … 1572 1708 fprintf(stderr,"r_inputs->value = %s\n",r_inputs->value); 1573 1709 #endif 1574 if(str cmp(mtoupper(r_inputs->value),"C-FORTRAN")==0){1710 if(strncasecmp(r_inputs->value,"C-FORTRAN",9)==0){ 1575 1711 r_inputs=getMap(request_inputs,"Identifier"); 1576 1712 #ifdef DEBUG … … 1584 1720 #endif 1585 1721 #ifdef WIN32 1586 execute_t execute=(execute_t)GetProcAddress(so,fname);1722 execute_t execute=(execute_t)GetProcAddress(so,fname); 1587 1723 #else 1588 execute_t execute=(execute_t)dlsym(so,fname);1724 execute_t execute=(execute_t)dlsym(so,fname); 1589 1725 #endif 1590 1726 #ifdef DEBUG 1591 1727 #ifdef WIN32 1592 errstr = GetLastError();1728 errstr = GetLastError(); 1593 1729 #else 1594 errstr = dlerror();1730 errstr = dlerror(); 1595 1731 #endif 1596 1732 #endif … … 1622 1758 #endif 1623 1759 #ifdef WIN32 1624 execute_t execute=(execute_t)GetProcAddress(so,r_inputs->value);1760 execute_t execute=(execute_t)GetProcAddress(so,r_inputs->value); 1625 1761 #else 1626 execute_t execute=(execute_t)dlsym(so,r_inputs->value);1762 execute_t execute=(execute_t)dlsym(so,r_inputs->value); 1627 1763 #endif 1628 1764 #ifdef DEBUG 1629 1765 #ifdef WIN32 1630 errstr = GetLastError();1766 errstr = GetLastError(); 1631 1767 #else 1632 errstr = dlerror();1768 errstr = dlerror(); 1633 1769 #endif 1634 1770 fprintf(stderr,"Function loaded %s\n",errstr); … … 1638 1774 */ 1639 1775 eres=execute(&m,&request_input_real_format,&request_output_real_format); 1640 dlclose(so);1641 1776 } 1777 dlclose(so); 1642 1778 } else { 1643 1779 /** … … 1648 1784 map* tmps=createMap("text",tmps1); 1649 1785 printExceptionReportResponse(m,tmps); 1786 freeMap(&tmps); 1787 free(tmps); 1650 1788 exit(1); 1651 1789 } 1652 1790 } else{ 1653 if(str cmp(mtoupper(r_inputs->value),"PYTHON")==0){1791 if(strncasecmp(r_inputs->value,"PYTHON",6)==0){ 1654 1792 eres=zoo_python_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); 1655 1793 } 1656 1794 else 1657 1795 1658 1659 if(str cmp(mtoupper(r_inputs->value),"JAVA")==0){1796 #ifdef USE_JAVA 1797 if(strncasecmp(r_inputs->value,"JAVA",4)==0){ 1660 1798 eres=zoo_java_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); 1661 1799 } 1662 1800 else 1663 1664 1665 1666 if(str cmp(mtoupper(r_inputs->value),"PHP")==0){1801 #endif 1802 1803 #ifdef USE_PHP 1804 if(strncasecmp(r_inputs->value,"PHP",3)==0){ 1667 1805 eres=zoo_php_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); 1668 1806 } 1669 1807 else 1670 1671 1672 1673 if(strcmp(mtoupper(r_inputs->value),"JS")==0){1808 #endif 1809 1810 #ifdef USE_JS 1811 if(strncasecmp(r_inputs->value,"JS",2)==0){ 1674 1812 eres=zoo_js_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format); 1675 1813 } 1676 else1677 1678 {1679 1680 1681 1682 1683 1684 1814 else 1815 #endif 1816 { 1817 char tmpv[1024]; 1818 sprintf(tmpv,"Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n",r_inputs->value); 1819 map* tmps=createMap("text",tmpv); 1820 printExceptionReportResponse(m,tmps); 1821 return -1; 1822 } 1685 1823 } 1686 1824 … … 1697 1835 #ifdef DEBUG 1698 1836 dumpMaps(request_output_real_format); 1699 #endif 1700 outputResponse(s1,request_input_real_format, 1701 request_output_real_format,request_inputs, 1702 cpid,m,eres); 1703 1837 fprintf(stderr,"Function loaded and returned %d\n",eres); 1838 fflush(stderr); 1839 #endif 1840 if(eres!=-1) 1841 outputResponse(s1,request_input_real_format, 1842 request_output_real_format,request_inputs, 1843 cpid,m,eres); 1844 1845 //if(getpid()==cpid){ 1846 freeService(&s1); 1847 free(s1); 1848 freeMaps(&m); 1849 free(m); 1850 freeMaps(&tmpmaps); 1851 free(tmpmaps); 1852 1853 freeMaps(&request_input_real_format); 1854 free(request_input_real_format); 1855 1856 //freeMap(&request_inputs); 1857 //free(request_inputs); 1858 1859 /* The following is requested but get issue using with Python support :/ */ 1860 freeMaps(&request_output_real_format); 1861 free(request_output_real_format); 1862 1863 free(REQUEST); 1864 free(SERVICE_URL); 1704 1865 #ifdef DEBUG 1705 1866 fprintf(stderr,"Processed response \n"); … … 1707 1868 fflush(stderr); 1708 1869 #endif 1870 //} 1709 1871 1710 1872 return 0;
Note: See TracChangeset
for help on using the changeset viewer.