Changeset 619 for trunk/zoo-project


Ignore:
Timestamp:
Mar 30, 2015, 2:42:31 PM (9 years ago)
Author:
djay
Message:

Fix issue with OTB multiple inputs potentially encoded in base64.

Location:
trunk/zoo-project/zoo-kernel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/service_internal.c

    r618 r619  
    30173017      addToMap(cursor->content,"size",sizes);
    30183018    }
     3019    map* length=getMap(cursor->content,"length");
     3020    if(length!=NULL){
     3021      int len=atoi(length->value);
     3022      for(int i=1;i<len;i++){
     3023        tmp=getMapArray(cursor->content,"encoding",i);
     3024        if(tmp!=NULL && strncasecmp(tmp->value,"base64",6)==0){
     3025          char key[17];
     3026          sprintf(key,"base64_value_%d",i);
     3027          tmp=getMapArray(cursor->content,"value",i);
     3028          addToMap(cursor->content,key,tmp->value);
     3029          int size=0;
     3030          char *s=strdup(tmp->value);
     3031          free(tmp->value);
     3032          tmp->value=base64d(s,strlen(s),&size);
     3033          free(s);
     3034          char sizes[1024];
     3035          sprintf(sizes,"%d",size);
     3036          sprintf(key,"size_%d",i);
     3037          addToMap(cursor->content,key,sizes);
     3038        }
     3039      }
     3040    }
    30193041    cursor=cursor->next;
    30203042  }
  • trunk/zoo-project/zoo-kernel/service_internal_otb.c

    r618 r619  
    9595    }
    9696    return str;
     97}
     98
     99/**
     100 * Write a file from value and length
     101 *
     102 * @param fname the file name
     103 * @param val the value
     104 * @param length the value length
     105 */
     106int writeFile(char* fname,char* val,int length){
     107  FILE* of=fopen(fname,"wb");
     108  if(of==NULL){
     109    return -1;
     110  }
     111  size_t ret=fwrite(val,sizeof(char),length,of);
     112  if(ret<length){
     113    fprintf(stderr,"Write error occured!\n");
     114    fclose(of);
     115    return -1;
     116  }
     117  fclose(of);
     118  return 1;
    97119}
    98120
     
    191213                    dynamic_cast<OutputImageParameter *> (param.GetPointer())->SetPixelType(outPixType);
    192214                  }else{
     215                    map* tmpPath=getMapFromMaps(m,"main","tmpPath");
     216                    map* tmpSid=getMapFromMaps(m,"lenv","sid");
    193217                    map* tmpVal=getMapFromMaps(inputs,paramKey.c_str(),"mimeType");
    194218                    char file_ext[32];
    195219                    getFileExtension(tmpVal != NULL ? tmpVal->value : NULL, file_ext, 32);
    196220                    if(type == ParameterType_InputImageList){
    197                       values.push_back(test->value);
     221                      char *val=(char*)malloc((strlen(tmpPath->value)+strlen(s->name)+strlen(tmpSid->value)+strlen(file_ext)+13)*sizeof(char));
     222                      sprintf(val,"%s/Input_%s_%s_%d.%s",tmpPath->value,s->name,tmpSid->value,0,file_ext);
     223                      int length=0;
     224                      map* tmpSize=getMap(test,"size");
     225                      if(tmpSize!=NULL){
     226                        length=atoi(tmpSize->value);
     227                      }
     228                      writeFile(val,test->value,length);
     229                      values.push_back(val);
     230                      free(val);
    198231                      map* tmpLength=getMapFromMaps(inputs,paramKey.c_str(),"length");
    199232                      if(tmpLength!=NULL){
    200233                        int len=atoi(tmpLength->value);
     234                        maps* tmpI=getMaps(inputs,paramKey.c_str());
    201235                        for(int k=1;k<len;k++){
    202                           char *val=(char*)malloc((strlen(tmpPath->value)+strlen(s->name)+strlen(tmpSid->value)+strlen(file_ext)+13)*sizeof(char));
     236                          val=(char*)malloc((strlen(tmpPath->value)+strlen(s->name)+strlen(tmpSid->value)+strlen(file_ext)+13)*sizeof(char));
    203237                          sprintf(val,"%s/Input_%s_%s_%d.%s",tmpPath->value,s->name,tmpSid->value,k,file_ext);
    204                           FILE* of=fopen(val,"wb");
    205                           int length=0;
    206                           map* tmpSize=getMap(test,"size");
     238                          length=0;
     239                          map* tmpV=getMapArray(tmpI->content,"value",k);
     240                          tmpSize=getMapArray(tmpI->content,"size",k);
    207241                          if(tmpSize!=NULL){
    208242                            length=atoi(tmpSize->value);
    209243                          }
    210                           fwrite(test->value,sizeof(char),length,of);
    211                           fclose(of);
     244                          writeFile(val,tmpV->value,length);
    212245                          values.push_back(val);
    213246                          free(val);
     
    220253                           || type == ParameterType_ComplexInputImage || type == ParameterType_InputVectorData
    221254                           || type == ParameterType_InputFilename){
    222                         map* tmpPath=getMapFromMaps(m,"main","tmpPath");
    223                         map* tmpSid=getMapFromMaps(m,"lenv","sid");
    224255                        char tmp[1024];
    225256                        char* ext="json";
     
    227258                          char *val=(char*)malloc((strlen(tmpPath->value)+strlen(s->name)+strlen(tmpSid->value)+strlen(file_ext)+10)*sizeof(char));
    228259                          sprintf(val,"%s/Input_%s_%s.%s",tmpPath->value,s->name,tmpSid->value,file_ext);
    229                           FILE* of=fopen(val,"wb");
    230260                          int length=0;
    231261                          map* tmpSize=getMap(test,"size");
     
    233263                            length=atoi(tmpSize->value);
    234264                          }
    235                           fwrite(test->value,sizeof(char),length,of);
    236                           fclose(of);
     265                          writeFile(val,test->value,length);
    237266
    238267                          if(strncasecmp(tmpVal->value,"application/zip",14)==0){
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