Ignore:
Timestamp:
Apr 13, 2015, 8:17:18 PM (9 years ago)
Author:
djay
Message:

Add readBase64 function, avoid calling it prior to fork . Add dumpMapsValuesToFiles function used to simplify OTB support.

File:
1 edited

Legend:

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

    r630 r631  
    29482948}
    29492949
     2950/**
     2951 * Write a file from value and length
     2952 *
     2953 * @param fname the file name
     2954 * @param val the value
     2955 * @param length the value length
     2956 */
     2957int writeFile(char* fname,char* val,int length){
     2958  FILE* of=fopen(fname,"wb");
     2959  if(of==NULL){
     2960    return -1;
     2961  }
     2962  size_t ret=fwrite(val,sizeof(char),length,of);
     2963  if(ret<length){
     2964    fprintf(stderr,"Write error occured!\n");
     2965    fclose(of);
     2966    return -1;
     2967  }
     2968  fclose(of);
     2969  return 1;
     2970}
     2971
     2972/**
     2973 * Dump all values in a maps as files
     2974 *
     2975 * @param main_conf the maps containing the settings of the main.cfg file
     2976 * @param in the maps containing values to dump as files
     2977 */
     2978void dumpMapsValuesToFiles(maps** main_conf,maps** in){
     2979  map* tmpPath=getMapFromMaps(*main_conf,"main","tmpPath");
     2980  map* tmpSid=getMapFromMaps(*main_conf,"lenv","sid");
     2981  maps* inputs=*in;
     2982  int length=0;
     2983  while(inputs!=NULL){
     2984    if(getMap(inputs->content,"mimeType")!=NULL &&
     2985       getMap(inputs->content,"cache_file")==NULL){
     2986      map* cMap=inputs->content;
     2987      if(getMap(cMap,"length")!=NULL){
     2988        map* tmpLength=getMap(cMap,"length");
     2989        int len=atoi(tmpLength->value);
     2990        int k=0;
     2991        for(k=0;k<len;k++){
     2992          map* cMimeType=getMapArray(cMap,"mimeType",k);
     2993          map* cValue=getMapArray(cMap,"value",k);
     2994          map* cSize=getMapArray(cMap,"size",k);
     2995          char file_ext[32];
     2996          getFileExtension(cMimeType != NULL ? cMimeType->value : NULL, file_ext, 32);
     2997          char* val=(char*)malloc((strlen(tmpPath->value)+strlen(inputs->name)+strlen(tmpSid->value)+strlen(file_ext)+16)*sizeof(char));
     2998          sprintf(val,"%s/Input_%s_%s_%d.%s",tmpPath->value,inputs->name,tmpSid->value,k,file_ext);
     2999          length=0;
     3000          if(cSize!=NULL){
     3001            length=atoi(cSize->value);
     3002          }
     3003          writeFile(val,cValue->value,length);
     3004          setMapArray(cMap,"cache_file",k,val);
     3005          free(val);
     3006        }
     3007      }else{
     3008        int length=0;
     3009        map* cMimeType=getMap(cMap,"mimeType");
     3010        map* cValue=getMap(cMap,"value");
     3011        map* cSize=getMap(cMap,"size");
     3012        char file_ext[32];
     3013        getFileExtension(cMimeType != NULL ? cMimeType->value : NULL, file_ext, 32);
     3014        char *val=(char*)malloc((strlen(tmpPath->value)+strlen(inputs->name)+strlen(tmpSid->value)+strlen(file_ext)+16)*sizeof(char));
     3015        sprintf(val,"%s/Input_%s_%s_%d.%s",tmpPath->value,inputs->name,tmpSid->value,0,file_ext);
     3016        if(cSize!=NULL){
     3017          length=atoi(cSize->value);
     3018        }
     3019        writeFile(val,cValue->value,length);
     3020        addToMap(cMap,"cache_file",val);
     3021        free(val);
     3022      }
     3023    }
     3024    inputs=inputs->next;
     3025  }
     3026}
    29503027
    29513028/**
     
    30083085
    30093086/**
     3087 * Read Base64 value and split it value by lines of 64 char.
     3088 *
     3089 * @param in the map containing the value to split
     3090 */
     3091void readBase64(map **in){
     3092  char *res = NULL;
     3093  char *curs = (*in)->value;
     3094  int i = 0;
     3095  for (i = 0; i <= strlen ((*in)->value) / 64;
     3096       i++)
     3097    {
     3098      if (res == NULL)
     3099        res =
     3100          (char *) malloc (65 * sizeof (char));
     3101      else
     3102        res =
     3103          (char *) realloc (res,
     3104                            (((i + 1) * 65) +
     3105                             i) * sizeof (char));
     3106      int csize = i * 65;
     3107      strncpy (res + csize, curs, 64);
     3108      if (i == strlen ((*in)->value) / 64)
     3109        strcat (res, "\n\0");
     3110      else
     3111        {
     3112          strncpy (res + (((i + 1) * 64) + i),
     3113                   "\n\0", 2);
     3114          curs += 64;
     3115        }
     3116    }
     3117  free ((*in)->value);
     3118  (*in)->value = zStrdup (res);
     3119  free (res);
     3120}
     3121
     3122/**
    30103123 * Make sure that each value encoded in base64 in a maps is decoded.
    30113124 *
    30123125 * @param in the maps containing the values
     3126 * @see readBase64
    30133127 */
    30143128void ensureDecodedBase64(maps **in){
     
    30183132    if(tmp!=NULL && strncasecmp(tmp->value,"base64",6)==0){
    30193133      tmp=getMap(cursor->content,"value");
     3134      readBase64(&tmp);
    30203135      addToMap(cursor->content,"base64_value",tmp->value);
    30213136      int size=0;
     
    30373152          sprintf(key,"base64_value_%d",i);
    30383153          tmp=getMapArray(cursor->content,"value",i);
     3154          readBase64(&tmp);
    30393155          addToMap(cursor->content,key,tmp->value);
    30403156          int size=0;
     
    41224238#endif
    41234239}
     4240
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