Changeset 631 for trunk/zoo-project/zoo-kernel/service_internal.c
- Timestamp:
- Apr 13, 2015, 8:17:18 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/service_internal.c
r630 r631 2948 2948 } 2949 2949 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 */ 2957 int 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 */ 2978 void 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 } 2950 3027 2951 3028 /** … … 3008 3085 3009 3086 /** 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 */ 3091 void 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 /** 3010 3123 * Make sure that each value encoded in base64 in a maps is decoded. 3011 3124 * 3012 3125 * @param in the maps containing the values 3126 * @see readBase64 3013 3127 */ 3014 3128 void ensureDecodedBase64(maps **in){ … … 3018 3132 if(tmp!=NULL && strncasecmp(tmp->value,"base64",6)==0){ 3019 3133 tmp=getMap(cursor->content,"value"); 3134 readBase64(&tmp); 3020 3135 addToMap(cursor->content,"base64_value",tmp->value); 3021 3136 int size=0; … … 3037 3152 sprintf(key,"base64_value_%d",i); 3038 3153 tmp=getMapArray(cursor->content,"value",i); 3154 readBase64(&tmp); 3039 3155 addToMap(cursor->content,key,tmp->value); 3040 3156 int size=0; … … 4122 4238 #endif 4123 4239 } 4240
Note: See TracChangeset
for help on using the changeset viewer.