Changeset 917 for trunk/zoo-project/zoo-kernel/server_internal.c
- Timestamp:
- May 7, 2019, 2:17:08 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property
svn:mergeinfo
set to
False
/branches/prototype-v0 merged eligible
-
Property
svn:mergeinfo
set to
False
-
trunk/zoo-project/zoo-kernel/server_internal.c
r889 r917 26 26 #include "service_internal.h" 27 27 #include "response_print.h" 28 //#include "service_callback.h" 28 29 #include "mimetypes.h" 29 30 #ifndef WIN32 … … 366 367 */ 367 368 void readGeneratedFile(maps* m,map* content,char* filename){ 369 char rsize[1024]; 368 370 FILE * file=fopen(filename,"rb"); 369 371 if(file==NULL){ 370 fprintf(stderr,"Failed to open file %s for reading purpose.\n",filename);371 372 setMapInMaps(m,"lenv","message","Unable to read produced file. Please try again later"); 372 373 return ; 373 374 } 374 375 fseek(file, 0, SEEK_END); 375 long count = ftell(file); 376 zStatStruct f_status; 377 int s=zStat(filename, &f_status); 378 sprintf(rsize,"%lld",f_status.st_size); 376 379 rewind(file); 377 struct stat file_status; 378 stat(filename, &file_status); 379 map* tmpMap1=getMap(content,"value"); 380 if(tmpMap1==NULL){ 381 addToMap(content,"value",""); 382 tmpMap1=getMap(content,"value"); 383 } 384 free(tmpMap1->value); 385 tmpMap1->value=(char*) malloc((count+1)*sizeof(char)); 386 fread(tmpMap1->value,1,count,file); 387 tmpMap1->value[count]=0; 388 fclose(file); 389 char rsize[1000]; 390 sprintf(rsize,"%ld",count); 380 if(getMap(content,"storage")==NULL){ 381 map* memUse=getMapFromMaps(m,"main","memory"); 382 if(memUse==NULL || strncmp(memUse->value,"load",4)==0){ 383 map* tmpMap1=getMap(content,"value"); 384 if(tmpMap1==NULL){ 385 addToMap(content,"value",""); 386 tmpMap1=getMap(content,"value"); 387 } 388 free(tmpMap1->value); 389 tmpMap1->value=(char*) malloc((f_status.st_size+1)*sizeof(char)); 390 if(tmpMap1->value==NULL){ 391 setMapInMaps(m,"lenv","message","Unable to allocate the memory required to read the produced file."); 392 } 393 fread(&tmpMap1->value,1,f_status.st_size,file); 394 tmpMap1->value[f_status.st_size]=0; 395 } 396 } 397 fclose(file); 391 398 addToMap(content,"size",rsize); 392 399 } … … 423 430 void dumpMapsValuesToFiles(maps** main_conf,maps** in){ 424 431 map* tmpPath=getMapFromMaps(*main_conf,"main","tmpPath"); 432 map* tmpUrl=getMapFromMaps(*main_conf,"main","tmpUrl"); 425 433 map* tmpSid=getMapFromMaps(*main_conf,"lenv","usid"); 426 434 maps* inputs=*in; … … 445 453 if(cSize!=NULL){ 446 454 length=atoi(cSize->value); 447 } 455 }else 456 length=strlen(cValue->value); 448 457 writeFile(val,cValue->value,length); 449 458 setMapArray(cMap,"cache_file",k,val); 459 free(val); 460 val=(char*)malloc((strlen(tmpUrl->value)+strlen(inputs->name)+strlen(tmpSid->value)+strlen(file_ext)+16)*sizeof(char)); 461 sprintf(val,"%s/Input_%s_%s_%d.%s",tmpUrl->value,inputs->name,tmpSid->value,k,file_ext); 462 setMapArray(cMap,"cache_url",k,val); 463 setMapArray(cMap,"byValue",k,"true"); 450 464 free(val); 451 465 } … … 461 475 if(cSize!=NULL){ 462 476 length=atoi(cSize->value); 463 } 477 }else 478 length=strlen(cValue->value); 464 479 writeFile(val,cValue->value,length); 465 480 addToMap(cMap,"cache_file",val); 481 free(val); 482 val=(char*)malloc((strlen(tmpUrl->value)+strlen(inputs->name)+strlen(tmpSid->value)+strlen(file_ext)+16)*sizeof(char)); 483 sprintf(val,"%s/Input_%s_%s_%d.%s",tmpUrl->value,inputs->name,tmpSid->value,0,file_ext); 484 addToMap(cMap,"cache_url",val); 485 addToMap(cMap,"byValue",val); 466 486 free(val); 467 487 } … … 638 658 } 639 659 if(res==NULL){ 660 map* tmpMaxO0=getMap(tmpInputs->content,"useMapserver"); 661 if(tmpMaxO0!=NULL){ 662 if(tmpMaps2->content==NULL) 663 tmpMaps2->content=createMap("useMapserver",tmpMaxO0->value); 664 else 665 addToMap(tmpMaps2->content,"useMapserver",tmpMaxO0->value); 666 } 640 667 map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs"); 641 668 if(tmpMaxO!=NULL){ … … 701 728 } 702 729 } 703 else {730 else /*toto*/{ 704 731 iotype* tmpIoType=NULL; 705 732 if(tmpMaps->content!=NULL){ … … 711 738 * content map. 712 739 */ 713 map* tmpMap1=getMap(tmpInputs->content,"minOccurs"); 714 if(tmpMap1!=NULL){ 715 if(tmpMaps->content==NULL) 716 tmpMaps->content=createMap("minOccurs",tmpMap1->value); 717 else 718 addToMap(tmpMaps->content,"minOccurs",tmpMap1->value); 719 } 720 map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs"); 721 if(tmpMaxO!=NULL){ 722 if(tmpMaps->content==NULL) 723 tmpMaps->content=createMap("maxOccurs",tmpMaxO->value); 724 else 725 addToMap(tmpMaps->content,"maxOccurs",tmpMaxO->value); 726 } 727 map* tmpMaxMB=getMap(tmpInputs->content,"maximumMegabytes"); 728 if(tmpMaxMB!=NULL){ 729 if(tmpMaps->content==NULL) 730 tmpMaps->content=createMap("maximumMegabytes",tmpMaxMB->value); 731 else 732 addToMap(tmpMaps->content,"maximumMegabytes",tmpMaxMB->value); 740 char* keys[4]={ 741 "minOccurs", 742 "maxOccurs", 743 "maximumMegabytes", 744 "useMapserver" 745 }; 746 int i=0; 747 for(i=0;i<4;i++){ 748 map* tmpMap1=getMap(tmpInputs->content,keys[i]); 749 if(tmpMap1!=NULL){ 750 addToMap(tmpMaps->content,keys[i],tmpMap1->value); 751 } 733 752 } 734 753 /** … … 743 762 map* tmpV=getMap(tmpI->content,"value"); 744 763 if(tmpV!=NULL){ 745 char *tmpVS= strdup(tmpV->value);764 char *tmpVS=zStrdup(tmpV->value); 746 765 map* tmp=parseBoundingBox(tmpVS); 747 766 free(tmpVS); … … 780 799 map* length=getMap(tmpMaps->content,"length"); 781 800 int i; 782 char *tcn= strdup(tmpContent->name);801 char *tcn=zStrdup(tmpContent->name); 783 802 for(i=1;i<atoi(length->value);i++){ 784 803 #ifdef DEBUG … … 806 825 */ 807 826 if(tmpIoType!=NULL){ 808 map* tmpCheck=getMap(tmpIoType->content,"useMap Server");809 if(tmpCheck!=NULL ){827 map* tmpCheck=getMap(tmpIoType->content,"useMapserver"); 828 if(tmpCheck!=NULL && strncasecmp(tmpCheck->value,"true",4)==0){ 810 829 // Get the default value 830 addToMap(tmpMaps->content,"useMapserver","true"); 811 831 tmpIoType=getIoTypeFromElement(tmpInputs,tmpInputs->name,NULL); 812 832 tmpCheck=getMap(tmpMaps->content,"mimeType"); … … 834 854 addToMap(tmpMaps->content,"inRequest","true"); 835 855 elements* tmpElements=getElements(in,tmpMaps->name); 836 if( tmpElements!=NULL && tmpElements->child!=NULL){856 if(/*tmpMaps->child!=NULL && */tmpElements!=NULL && tmpElements->child!=NULL){ 837 857 char *res=addDefaultValues(&tmpMaps->child,tmpElements->child,m,type,err); 838 858 if(strlen(res)>0){ 839 859 return res; 840 860 } 861 } 862 } 863 if(tmpInputs->child!=NULL){ 864 tmpInputss=tmpInputs->next; 865 tmpInputs=tmpInputs->child; 866 if(tmpMaps!=NULL){ 867 out1=tmpMaps->child; 868 out1s=tmpMaps; 841 869 } 842 870 } … … 972 1000 if(isRunning(conf,pid)>0){ 973 1001 if(strncasecmp(req,"GetResult",strlen(req))==0){ 974 errorException (conf, _("The result for the requested JobID has not yet been generated. "),1002 errorException (conf, _("The result for the requested JobID has not yet been generated. The service is currently running."), 975 1003 "ResultNotReady", pid); 976 1004 return; … … 981 1009 char* tmpStr=_getStatus(conf,pid); 982 1010 if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){ 983 char *tmpStr1= strdup(tmpStr);984 char *tmpStr0= strdup(strstr(tmpStr,"|")+1);1011 char *tmpStr1=zStrdup(tmpStr); 1012 char *tmpStr0=zStrdup(strstr(tmpStr,"|")+1); 985 1013 free(tmpStr); 986 1014 tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0'; … … 1000 1028 printf("%s",result); 1001 1029 fflush(stdout); 1030 free(sid); 1002 1031 freeMap(&statusInfo); 1003 1032 free(statusInfo); 1033 free(result); 1004 1034 return; 1005 1035 }else{ 1006 errorException (conf, _("The result for the requested JobID has not yet been generated. "),1036 errorException (conf, _("The result for the requested JobID has not yet been generated. The service ends but it still needs to produce the outputs."), 1007 1037 "ResultNotReady", pid); 1008 1038 freeMap(&statusInfo); … … 1015 1045 char* tmpStr=_getStatus(conf,pid); 1016 1046 if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){ 1017 char *tmpStr1= strdup(tmpStr);1018 char *tmpStr0= strdup(strstr(tmpStr,"|")+1);1047 char *tmpStr1=zStrdup(tmpStr); 1048 char *tmpStr0=zStrdup(strstr(tmpStr,"|")+1); 1019 1049 free(tmpStr); 1020 1050 tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0'; … … 1026 1056 } 1027 1057 } 1058 free(sid); 1028 1059 printStatusInfo(conf,statusInfo,req); 1029 1060 freeMap(&statusInfo); … … 1083 1114 if(strstr(dp->d_name,pid)!=0){ 1084 1115 sprintf(fileName,"%s/%s",r_inputs->value,dp->d_name); 1085 if( unlink(fileName)!=0){1116 if(zUnlink(fileName)!=0){ 1086 1117 errorException (conf, 1087 1118 _("The job cannot be removed, a file cannot be removed"), … … 1095 1126 removeService(conf,pid); 1096 1127 #endif 1128 /* No need to call 7_1 when an execution is dismissed. 1129 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 1130 invokeCallback(conf,NULL,NULL,7,1); 1131 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 1132 */ 1097 1133 map* statusInfo=createMap("JobID",pid); 1098 1134 addToMap(statusInfo,"Status","Dismissed");
Note: See TracChangeset
for help on using the changeset viewer.