Ignore:
Timestamp:
May 7, 2019, 2:17:08 PM (5 years ago)
Author:
djay
Message:

Merge prototype-v0 branch in trunk

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/zoo-project/zoo-kernel/server_internal.c

    r889 r917  
    2626#include "service_internal.h"
    2727#include "response_print.h"
     28//#include "service_callback.h"
    2829#include "mimetypes.h"
    2930#ifndef WIN32
     
    366367 */
    367368void readGeneratedFile(maps* m,map* content,char* filename){
     369  char rsize[1024];
    368370  FILE * file=fopen(filename,"rb");
    369371  if(file==NULL){
    370     fprintf(stderr,"Failed to open file %s for reading purpose.\n",filename);
    371372    setMapInMaps(m,"lenv","message","Unable to read produced file. Please try again later");
    372373    return ;
    373374  }
    374375  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);
    376379  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); 
    391398  addToMap(content,"size",rsize);
    392399}
     
    423430void dumpMapsValuesToFiles(maps** main_conf,maps** in){
    424431  map* tmpPath=getMapFromMaps(*main_conf,"main","tmpPath");
     432  map* tmpUrl=getMapFromMaps(*main_conf,"main","tmpUrl");
    425433  map* tmpSid=getMapFromMaps(*main_conf,"lenv","usid");
    426434  maps* inputs=*in;
     
    445453          if(cSize!=NULL){
    446454            length=atoi(cSize->value);
    447           }
     455          }else
     456            length=strlen(cValue->value);
    448457          writeFile(val,cValue->value,length);
    449458          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");
    450464          free(val);
    451465        }
     
    461475        if(cSize!=NULL){
    462476          length=atoi(cSize->value);
    463         }
     477        }else
     478          length=strlen(cValue->value);
    464479        writeFile(val,cValue->value,length);
    465480        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);
    466486        free(val);
    467487      }
     
    638658        }
    639659        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          }
    640667          map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs");
    641668          if(tmpMaxO!=NULL){
     
    701728      }
    702729    }
    703     else {
     730    else /*toto*/{
    704731      iotype* tmpIoType=NULL;
    705732      if(tmpMaps->content!=NULL){
     
    711738           * content map.
    712739           */
    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            }
    733752          }
    734753          /**
     
    743762              map* tmpV=getMap(tmpI->content,"value");
    744763              if(tmpV!=NULL){
    745                 char *tmpVS=strdup(tmpV->value);
     764                char *tmpVS=zStrdup(tmpV->value);
    746765                map* tmp=parseBoundingBox(tmpVS);
    747766                free(tmpVS);
     
    780799              map* length=getMap(tmpMaps->content,"length");
    781800              int i;
    782               char *tcn=strdup(tmpContent->name);
     801              char *tcn=zStrdup(tmpContent->name);
    783802              for(i=1;i<atoi(length->value);i++){
    784803#ifdef DEBUG
     
    806825         */
    807826        if(tmpIoType!=NULL){
    808           map* tmpCheck=getMap(tmpIoType->content,"useMapServer");
    809           if(tmpCheck!=NULL){
     827          map* tmpCheck=getMap(tmpIoType->content,"useMapserver");
     828          if(tmpCheck!=NULL && strncasecmp(tmpCheck->value,"true",4)==0){
    810829            // Get the default value
     830            addToMap(tmpMaps->content,"useMapserver","true");
    811831            tmpIoType=getIoTypeFromElement(tmpInputs,tmpInputs->name,NULL);
    812832            tmpCheck=getMap(tmpMaps->content,"mimeType");
     
    834854        addToMap(tmpMaps->content,"inRequest","true");
    835855      elements* tmpElements=getElements(in,tmpMaps->name);
    836       if(tmpElements!=NULL && tmpElements->child!=NULL){
     856      if(/*tmpMaps->child!=NULL && */tmpElements!=NULL && tmpElements->child!=NULL){
    837857        char *res=addDefaultValues(&tmpMaps->child,tmpElements->child,m,type,err);
    838858        if(strlen(res)>0){
    839859          return res;
    840860        }
     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;
    841869      }
    842870    }
     
    9721000    if(isRunning(conf,pid)>0){         
    9731001      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."),
    9751003                        "ResultNotReady", pid);
    9761004        return;
     
    9811009          char* tmpStr=_getStatus(conf,pid);
    9821010          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);
    9851013            free(tmpStr);
    9861014            tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0';
     
    10001028          printf("%s",result);
    10011029          fflush(stdout);
     1030          free(sid);
    10021031          freeMap(&statusInfo);
    10031032          free(statusInfo);
     1033          free(result);
    10041034          return;
    10051035        }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."),
    10071037                          "ResultNotReady", pid);
    10081038          freeMap(&statusInfo);
     
    10151045          char* tmpStr=_getStatus(conf,pid);
    10161046          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);
    10191049            free(tmpStr);
    10201050            tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0';
     
    10261056        }
    10271057    }
     1058    free(sid);
    10281059    printStatusInfo(conf,statusInfo,req);
    10291060    freeMap(&statusInfo);
     
    10831114        if(strstr(dp->d_name,pid)!=0){
    10841115          sprintf(fileName,"%s/%s",r_inputs->value,dp->d_name);
    1085           if(unlink(fileName)!=0){
     1116          if(zUnlink(fileName)!=0){
    10861117            errorException (conf,
    10871118                            _("The job cannot be removed, a file cannot be removed"),
     
    10951126    removeService(conf,pid);
    10961127#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    */
    10971133    map* statusInfo=createMap("JobID",pid);
    10981134    addToMap(statusInfo,"Status","Dismissed");
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png