3 #endif /* ifdef HAVE_CONFIG_H */
11 #ifdef HAVE_NETINET_IN_H
12 # include <netinet/in.h>
13 #endif /* ifdef HAVE_NETINET_IN_H */
16 # include <winsock2.h>
17 #endif /* ifdef _WIN32 */
22 #include "Eet_private.h"
25 * routines for doing data -> struct and struct -> data conversion
45 * multiple entries ordered as...
47 * fixed size array [ of basic types ]
48 * variable size array [ of basic types ]
49 * linked list [ of basic types ]
50 * hash table [ of basic types ]
52 * need to provide builder/accessor funcs for:
64 typedef struct _Eet_Data_Element Eet_Data_Element;
65 typedef struct _Eet_Data_Basic_Type_Codec Eet_Data_Basic_Type_Codec;
66 typedef struct _Eet_Data_Group_Type_Codec Eet_Data_Group_Type_Codec;
67 typedef struct _Eet_Data_Chunk Eet_Data_Chunk;
68 typedef struct _Eet_Data_Stream Eet_Data_Stream;
69 typedef struct _Eet_Data_Descriptor_Hash Eet_Data_Descriptor_Hash;
70 typedef struct _Eet_Data_Encode_Hash_Info Eet_Data_Encode_Hash_Info;
71 typedef struct _Eet_Free Eet_Free;
72 typedef struct _Eet_Free_Context Eet_Free_Context;
73 typedef struct _Eet_Variant_Unknow Eet_Variant_Unknow;
78 * Eet_Data_Basic_Type_Codec (Coder, Decoder)
79 * Eet_Data_Group_Type_Codec (Coder, Decoder)
81 struct _Eet_Data_Basic_Type_Codec
85 int (*get)(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
86 void * (*put)(Eet_Dictionary *ed, const void *src, int *size_ret);
89 struct _Eet_Data_Group_Type_Codec
91 int (*get)(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Chunk *echnk, int type, int group_type, void *data_in, char **p, int *size);
92 void (*put)(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in);
95 struct _Eet_Data_Chunk
103 unsigned char group_type;
106 struct _Eet_Data_Stream
113 struct _Eet_Data_Descriptor_Hash
115 Eet_Data_Element *element;
116 Eet_Data_Descriptor_Hash *next;
119 struct _Eet_Data_Descriptor
122 const Eet_Dictionary *ed;
126 void * (*mem_alloc)(size_t size);
127 void (*mem_free)(void *mem);
128 char * (*str_alloc)(const char *str);
129 char * (*str_direct_alloc)(const char *str);
130 void (*str_free)(const char *str);
131 void (*str_direct_free)(const char *str);
132 void * (*list_next)(void *l);
133 void * (*list_append)(void *l, void *d);
134 void * (*list_data)(void *l);
135 void * (*list_free)(void *l);
136 void (*hash_foreach)(void *h, int (*func)(void *h, const char *k, void *dt, void *fdt), void *fdt);
137 void * (*hash_add)(void *h, const char *k, void *d);
138 void (*hash_free)(void *h);
139 const char *(*type_get)(const void *data, Eina_Bool *unknow);
140 Eina_Bool (*type_set)(const char *type, void *data, Eina_Bool unknow);
141 void * (*array_alloc)(size_t size);
142 void (*array_free)(void *mem);
147 Eet_Data_Element *set;
151 Eet_Data_Descriptor_Hash *buckets;
155 Eina_Bool unified_type : 1;
160 struct _Eet_Data_Element
163 const char *counter_name;
164 const char *directory_name_ptr;
165 Eet_Data_Descriptor *subtype;
166 int offset; /* offset in bytes from the base element */
167 int count; /* number of elements for a fixed array */
168 int counter_offset; /* for a variable array we need the offset of the count variable */
169 unsigned char type; /* EET_T_XXX */
170 unsigned char group_type; /* EET_G_XXX */
173 struct _Eet_Data_Encode_Hash_Info
176 Eet_Data_Element *ede;
180 #define EET_FREE_COUNT 256
184 Eina_Array list[EET_FREE_COUNT];
187 struct _Eet_Free_Context
190 Eet_Free freelist_array;
191 Eet_Free freelist_list;
192 Eet_Free freelist_hash;
193 Eet_Free freelist_str;
194 Eet_Free freelist_direct_str;
197 struct _Eet_Variant_Unknow
207 static void eet_free_context_init(Eet_Free_Context *context);
208 static void eet_free_context_shutdown(Eet_Free_Context *context);
210 static int eet_data_get_char(const Eet_Dictionary *ed,
214 static void * eet_data_put_char(Eet_Dictionary *ed,
217 static int eet_data_get_short(const Eet_Dictionary *ed,
221 static void * eet_data_put_short(Eet_Dictionary *ed,
224 static inline int eet_data_get_int(const Eet_Dictionary *ed,
228 static void * eet_data_put_int(Eet_Dictionary *ed,
231 static int eet_data_get_long_long(const Eet_Dictionary *ed,
235 static void * eet_data_put_long_long(Eet_Dictionary *ed,
238 static int eet_data_get_float(const Eet_Dictionary *ed,
242 static void * eet_data_put_float(Eet_Dictionary *ed,
245 static int eet_data_get_double(const Eet_Dictionary *ed,
249 static void * eet_data_put_double(Eet_Dictionary *ed,
252 static int eet_data_get_f32p32(const Eet_Dictionary *ed,
256 static void * eet_data_put_f32p32(Eet_Dictionary *ed,
259 static int eet_data_get_f16p16(const Eet_Dictionary *ed,
263 static void * eet_data_put_f16p16(Eet_Dictionary *ed,
266 static int eet_data_get_f8p24(const Eet_Dictionary *ed,
270 static void * eet_data_put_f8p24(Eet_Dictionary *ed,
273 static inline int eet_data_get_string(const Eet_Dictionary *ed,
277 static void * eet_data_put_string(Eet_Dictionary *ed,
280 static int eet_data_get_istring(const Eet_Dictionary *ed,
284 static void * eet_data_put_istring(Eet_Dictionary *ed,
287 static int eet_data_get_null(const Eet_Dictionary *ed,
291 static void * eet_data_put_null(Eet_Dictionary *ed,
295 static int eet_data_get_type(const Eet_Dictionary *ed,
300 static void * eet_data_put_type(Eet_Dictionary *ed,
305 static Eet_Node * eet_data_node_simple_type(int type,
309 static int eet_data_get_unknown(Eet_Free_Context *context,
310 const Eet_Dictionary *ed,
311 Eet_Data_Descriptor *edd,
312 Eet_Data_Element *ede,
313 Eet_Data_Chunk *echnk,
319 static void eet_data_put_unknown(Eet_Dictionary *ed,
320 Eet_Data_Descriptor *edd,
321 Eet_Data_Element *ede,
324 static void eet_data_put_array(Eet_Dictionary *ed,
325 Eet_Data_Descriptor *edd,
326 Eet_Data_Element *ede,
329 static int eet_data_get_array(Eet_Free_Context *context,
330 const Eet_Dictionary *ed,
331 Eet_Data_Descriptor *edd,
332 Eet_Data_Element *ede,
333 Eet_Data_Chunk *echnk,
339 static int eet_data_get_list(Eet_Free_Context *context,
340 const Eet_Dictionary *ed,
341 Eet_Data_Descriptor *edd,
342 Eet_Data_Element *ede,
343 Eet_Data_Chunk *echnk,
349 static void eet_data_put_list(Eet_Dictionary *ed,
350 Eet_Data_Descriptor *edd,
351 Eet_Data_Element *ede,
354 static void eet_data_put_hash(Eet_Dictionary *ed,
355 Eet_Data_Descriptor *edd,
356 Eet_Data_Element *ede,
359 static int eet_data_get_hash(Eet_Free_Context *context,
360 const Eet_Dictionary *ed,
361 Eet_Data_Descriptor *edd,
362 Eet_Data_Element *ede,
363 Eet_Data_Chunk *echnk,
369 static void eet_data_put_union(Eet_Dictionary *ed,
370 Eet_Data_Descriptor *edd,
371 Eet_Data_Element *ede,
374 static int eet_data_get_union(Eet_Free_Context *context,
375 const Eet_Dictionary *ed,
376 Eet_Data_Descriptor *edd,
377 Eet_Data_Element *ede,
378 Eet_Data_Chunk *echnk,
384 static void eet_data_put_variant(Eet_Dictionary *ed,
385 Eet_Data_Descriptor *edd,
386 Eet_Data_Element *ede,
389 static int eet_data_get_variant(Eet_Free_Context *context,
390 const Eet_Dictionary *ed,
391 Eet_Data_Descriptor *edd,
392 Eet_Data_Element *ede,
393 Eet_Data_Chunk *echnk,
400 static void eet_data_chunk_get(const Eet_Dictionary *ed,
401 Eet_Data_Chunk *chnk,
404 static Eet_Data_Chunk * eet_data_chunk_new(void *data,
409 static void eet_data_chunk_free(Eet_Data_Chunk *chnk);
411 static Eet_Data_Stream * eet_data_stream_new(void);
412 static void eet_data_stream_write(Eet_Data_Stream *ds,
415 static void eet_data_stream_free(Eet_Data_Stream *ds);
417 static void eet_data_chunk_put(Eet_Dictionary *ed,
418 Eet_Data_Chunk *chnk,
419 Eet_Data_Stream *ds);
421 static int eet_data_descriptor_encode_hash_cb(void *hash,
425 static void * _eet_data_descriptor_encode(Eet_Dictionary *ed,
426 Eet_Data_Descriptor *edd,
429 static void * _eet_data_descriptor_decode(Eet_Free_Context *context,
430 const Eet_Dictionary *ed,
431 Eet_Data_Descriptor *edd,
437 static const Eet_Data_Basic_Type_Codec eet_basic_codec[] =
439 {sizeof(char), "char", eet_data_get_char, eet_data_put_char },
440 {sizeof(short), "short", eet_data_get_short, eet_data_put_short },
441 {sizeof(int), "int", eet_data_get_int, eet_data_put_int },
442 {sizeof(long long), "long_long", eet_data_get_long_long, eet_data_put_long_long},
443 {sizeof(float), "float", eet_data_get_float, eet_data_put_float },
444 {sizeof(double), "double", eet_data_get_double, eet_data_put_double },
445 {sizeof(char), "uchar", eet_data_get_char, eet_data_put_char },
446 {sizeof(short), "ushort", eet_data_get_short, eet_data_put_short },
447 {sizeof(int), "uint", eet_data_get_int, eet_data_put_int },
448 {sizeof(long long), "ulong_long", eet_data_get_long_long, eet_data_put_long_long},
449 {sizeof(char *), "string", eet_data_get_string, eet_data_put_string },
450 {sizeof(char *), "inlined", eet_data_get_istring, eet_data_put_istring },
451 {sizeof(void *), "NULL", eet_data_get_null, eet_data_put_null },
452 {sizeof(Eina_F32p32),"f32p32", eet_data_get_f32p32, eet_data_put_f32p32 },
453 {sizeof(Eina_F16p16),"f16p16", eet_data_get_f16p16, eet_data_put_f16p16 },
454 {sizeof(Eina_F8p24),"f8p24", eet_data_get_f8p24, eet_data_put_f8p24 }
457 static const Eet_Data_Group_Type_Codec eet_group_codec[] =
459 { eet_data_get_unknown, eet_data_put_unknown },
460 { eet_data_get_array, eet_data_put_array },
461 { eet_data_get_array, eet_data_put_array },
462 { eet_data_get_list, eet_data_put_list },
463 { eet_data_get_hash, eet_data_put_hash },
464 { eet_data_get_union, eet_data_put_union },
465 { eet_data_get_variant, eet_data_put_variant }
468 static int _eet_data_words_bigendian = -1;
472 #define SWAP64(x) (x) =\
473 ((((unsigned long long)(x) & 0x00000000000000ffULL) << 56) |\
474 (((unsigned long long)(x) & 0x000000000000ff00ULL) << 40) |\
475 (((unsigned long long)(x) & 0x0000000000ff0000ULL) << 24) |\
476 (((unsigned long long)(x) & 0x00000000ff000000ULL) << 8) |\
477 (((unsigned long long)(x) & 0x000000ff00000000ULL) >> 8) |\
478 (((unsigned long long)(x) & 0x0000ff0000000000ULL) >> 24) |\
479 (((unsigned long long)(x) & 0x00ff000000000000ULL) >> 40) |\
480 (((unsigned long long)(x) & 0xff00000000000000ULL) >> 56))
481 #define SWAP32(x) (x) =\
482 ((((int)(x) & 0x000000ff) << 24) |\
483 (((int)(x) & 0x0000ff00) << 8) |\
484 (((int)(x) & 0x00ff0000) >> 8) |\
485 (((int)(x) & 0xff000000) >> 24))
486 #define SWAP16(x) (x) =\
487 ((((short)(x) & 0x00ff) << 8) |\
488 (((short)(x) & 0xff00) >> 8))
492 #endif /* ifdef CONV8 */
495 #endif /* ifdef CONV16 */
498 #endif /* ifdef CONV32 */
501 #endif /* ifdef CONV64 */
504 #define CONV16(x) {if (_eet_data_words_bigendian) {SWAP16(x); }}
505 #define CONV32(x) {if (_eet_data_words_bigendian) {SWAP32(x); }}
506 #define CONV64(x) {if (_eet_data_words_bigendian) {SWAP64(x); }}
508 #define IS_SIMPLE_TYPE(Type) (Type > EET_T_UNKNOW && Type < EET_T_LAST)
509 #define IS_POINTER_TYPE(Type) (Type >= EET_T_STRING && Type <= EET_T_NULL)
511 #define POINTER_TYPE_DECODE(Context,\
523 ___r = eet_data_get_unknown(Context,\
527 Type, EET_G_UNKNOWN,\
529 if (!___r) { goto Label; }\
532 #define STRUCT_TYPE_DECODE(Data_Ret, Context, Ed, Ede, Data, Size, Label)\
534 Data_Ret = _eet_data_descriptor_decode(Context,\
539 if (!Data_Ret) { goto Label; }\
542 #define EET_I_STRING 1 << 4
543 #define EET_I_INLINED_STRING 2 << 4
544 #define EET_I_NULL 3 << 4
546 #define EET_MAGIC_VARIANT 0xF1234BC
551 eet_data_get_char(const Eet_Dictionary *ed __UNUSED__,
558 if (((char *)src + sizeof(char)) > (char *)src_end)
566 } /* eet_data_get_char */
569 eet_data_put_char(Eet_Dictionary *ed __UNUSED__,
575 d = (char *)malloc(sizeof(char));
582 *size_ret = sizeof(char);
584 } /* eet_data_put_char */
588 eet_data_get_short(const Eet_Dictionary *ed __UNUSED__,
595 if (((char *)src + sizeof(short)) > (char *)src_end)
598 memcpy(dst, src, sizeof(short));
601 return sizeof(short);
602 } /* eet_data_get_short */
605 eet_data_put_short(Eet_Dictionary *ed __UNUSED__,
611 d = (short *)malloc(sizeof(short));
618 *size_ret = sizeof(short);
620 } /* eet_data_put_short */
624 eet_data_get_int(const Eet_Dictionary *ed __UNUSED__,
631 if (((char *)src + sizeof(int)) > (char *)src_end)
634 memcpy(dst, src, sizeof(int));
638 } /* eet_data_get_int */
641 eet_data_put_int(Eet_Dictionary *ed __UNUSED__,
647 d = (int *)malloc(sizeof(int));
654 *size_ret = sizeof(int);
656 } /* eet_data_put_int */
660 eet_data_get_long_long(const Eet_Dictionary *ed __UNUSED__,
665 unsigned long long *d;
667 if (((char *)src + sizeof(unsigned long long)) > (char *)src_end)
670 memcpy(dst, src, sizeof(unsigned long long));
671 d = (unsigned long long *)dst;
673 return sizeof(unsigned long long);
674 } /* eet_data_get_long_long */
677 eet_data_put_long_long(Eet_Dictionary *ed __UNUSED__,
681 unsigned long long *s, *d;
683 d = (unsigned long long *)malloc(sizeof(unsigned long long));
687 s = (unsigned long long *)src;
690 *size_ret = sizeof(unsigned long long);
692 } /* eet_data_put_long_long */
696 eet_data_get_string_hash(const Eet_Dictionary *ed,
704 if (eet_data_get_int(ed, src, src_end, &idx) < 0)
707 return eet_dictionary_string_get_hash(ed, idx);
711 } /* eet_data_get_string_hash */
714 eet_data_get_string(const Eet_Dictionary *ed,
728 if (eet_data_get_int(ed, src, src_end, &idx) < 0)
731 str = eet_dictionary_string_get_char(ed, idx);
736 return eet_dictionary_string_get_size(ed, idx);
747 return strlen(s) + 1;
748 } /* eet_data_get_string */
751 eet_data_put_string(Eet_Dictionary *ed,
763 str = *((const char **)src);
767 idx = eet_dictionary_string_add(ed, str);
771 return eet_data_put_int(ed, &idx, size_ret);
774 s = (char *)(*((char **)src));
783 memcpy(d, s, len + 1);
786 } /* eet_data_put_string */
788 /* ALWAYS INLINED STRING TYPE */
790 eet_data_get_istring(const Eet_Dictionary *ed __UNUSED__,
795 return eet_data_get_string(NULL, src, src_end, dst);
796 } /* eet_data_get_istring */
799 eet_data_put_istring(Eet_Dictionary *ed __UNUSED__,
803 return eet_data_put_string(NULL, src, size_ret);
804 } /* eet_data_put_istring */
806 /* ALWAYS NULL TYPE */
808 eet_data_get_null(const Eet_Dictionary *ed __UNUSED__,
809 const void *src __UNUSED__,
810 const void *src_end __UNUSED__,
819 } /* eet_data_get_null */
822 eet_data_put_null(Eet_Dictionary *ed __UNUSED__,
823 const void *src __UNUSED__,
828 } /* eet_data_put_null */
831 * Fast lookups of simple doubles/floats.
833 * These aren't properly a cache because they don't store pre-calculated
834 * values, but have a so simple math that is almost as fast.
837 _eet_data_float_cache_get(const char *s,
841 /* fast handle of simple case 0xMp+E*/
842 if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
844 int mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
845 int exponent = (s[5] - '0');
848 *d = (float)(mantisse << exponent);
850 *d = (float)mantisse / (float)(1 << exponent);
856 } /* _eet_data_float_cache_get */
859 _eet_data_double_cache_get(const char *s,
863 /* fast handle of simple case 0xMp+E*/
864 if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
866 int mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
867 int exponent = (s[5] - '0');
870 *d = (double)(mantisse << exponent);
872 *d = (double)mantisse / (double)(1 << exponent);
878 } /* _eet_data_double_cache_get */
882 eet_data_get_float(const Eet_Dictionary *ed,
898 s = (const char *)src;
901 while ((p < (const char *)src_end) && (*p != 0)) {len++; p++; }
903 if (_eet_data_float_cache_get(s, len, d) != 0)
906 if (eina_convert_atod(s, len, &mantisse, &exponent) == EINA_FALSE)
909 *d = (float)ldexp((double)mantisse, exponent);
914 if (eet_data_get_int(ed, src, src_end, &idx) < 0)
917 if (!eet_dictionary_string_get_float(ed, idx, d))
921 } /* eet_data_get_float */
924 eet_data_put_float(Eet_Dictionary *ed,
931 eina_convert_dtoa((double)(*(float *)src), buf);
943 memcpy(d, buf, len + 1);
948 idx = eet_dictionary_string_add(ed, buf);
952 return eet_data_put_int(ed, &idx, size_ret);
953 } /* eet_data_put_float */
957 eet_data_get_double(const Eet_Dictionary *ed,
970 long long mantisse = 0;
974 s = (const char *)src;
977 while ((p < (const char *)src_end) && (*p != 0)) {len++; p++; }
979 if (_eet_data_double_cache_get(s, len, d) != 0)
982 if (eina_convert_atod(s, len, &mantisse, &exponent) == EINA_FALSE)
985 *d = ldexp((double)mantisse, exponent);
990 if (eet_data_get_int(ed, src, src_end, &idx) < 0)
993 if (!eet_dictionary_string_get_double(ed, idx, d))
997 } /* eet_data_get_double */
1000 eet_data_put_double(Eet_Dictionary *ed,
1007 eina_convert_dtoa((double)(*(double *)src), buf);
1015 d = malloc(len + 1);
1019 memcpy(d, buf, len + 1);
1020 *size_ret = len + 1;
1025 idx = eet_dictionary_string_add(ed, buf);
1029 return eet_data_put_int(ed, &idx, size_ret);
1030 } /* eet_data_put_double */
1033 eet_data_get_f32p32(const Eet_Dictionary *ed,
1035 const void *src_end,
1041 fp = (Eina_F32p32 *)dst;
1048 s = (const char *)src;
1051 while ((p < (const char *)src_end) && (*p != 0)) { len++; p++; }
1053 if (!(eina_convert_atofp(s, len, fp)))
1059 if (eet_data_get_int(ed, src, src_end, &idx) < 0)
1062 if (!eet_dictionary_string_get_fp(ed, idx, fp))
1066 } /* eet_data_get_f32p32 */
1069 eet_data_put_f32p32(Eet_Dictionary *ed,
1076 eina_convert_fptoa((Eina_F32p32)(*(Eina_F32p32 *)src), buf);
1084 d = malloc(len + 1);
1088 memcpy(d, buf, len + 1);
1089 *size_ret = len + 1;
1094 idx = eet_dictionary_string_add(ed, buf);
1098 return eet_data_put_int(ed, &idx, size_ret);
1099 } /* eet_data_put_f32p32 */
1102 eet_data_get_f16p16(const Eet_Dictionary *ed,
1104 const void *src_end,
1110 fp = (Eina_F16p16 *)dst;
1112 if (eet_data_get_f32p32(ed, src, src_end, &tmp) < 0)
1115 *fp = eina_f32p32_to_f16p16(tmp);
1117 } /* eet_data_get_f16p16 */
1120 eet_data_put_f16p16(Eet_Dictionary *ed,
1126 tmp = eina_f16p16_to_f32p32((Eina_F16p16)(*(Eina_F16p16 *)src));
1127 return eet_data_put_f32p32(ed, &tmp, size_ret);
1128 } /* eet_data_put_f16p16 */
1131 eet_data_get_f8p24(const Eet_Dictionary *ed,
1133 const void *src_end,
1139 fp = (Eina_F8p24 *)dst;
1141 if (eet_data_get_f32p32(ed, src, src_end, &tmp) < 0)
1144 *fp = eina_f32p32_to_f8p24(tmp);
1146 } /* eet_data_get_f8p24 */
1149 eet_data_put_f8p24(Eet_Dictionary *ed,
1155 tmp = eina_f8p24_to_f32p32((Eina_F8p24)(*(Eina_F8p24 *)src));
1156 return eet_data_put_f32p32(ed, &tmp, size_ret);
1157 } /* eet_data_put_f8p24 */
1160 eet_data_get_type(const Eet_Dictionary *ed,
1163 const void *src_end,
1168 ret = eet_basic_codec[type - 1].get(ed, src, src_end, dest);
1170 } /* eet_data_get_type */
1172 static inline void *
1173 eet_data_put_type(Eet_Dictionary *ed,
1180 ret = eet_basic_codec[type - 1].put(ed, src, size_ret);
1182 } /* eet_data_put_type */
1184 static inline Eina_Bool
1185 eet_data_type_match(int type1,
1191 /* Note: All floating point type are equivalent and could be read
1192 without problem by any other floating point getter. */
1219 } /* eet_data_type_match */
1223 * char[4] = "CHnK"; // untyped data ... or
1224 * char[4] = "CHKx"; // typed data - x == type
1226 * int = chunk size (including magic string);
1227 * char[] = chunk magic/name string (0 byte terminated);
1228 * ... sub-chunks (a chunk can contain chuncks recusrively) ...
1230 * ... payload data ...
1235 eet_data_chunk_get(const Eet_Dictionary *ed,
1236 Eet_Data_Chunk *chnk,
1255 if ((s[0] != 'C') || (s[1] != 'H') || (s[2] != 'K'))
1258 chnk->type = (unsigned char)(s[3]);
1259 if (chnk->type >= EET_I_LIMIT)
1262 ((chnk->type - EET_I_LIMIT) & 0xF) + EET_G_UNKNOWN;
1263 switch ((chnk->type - EET_I_LIMIT) & 0xF0)
1265 #define EET_UNMATCH_TYPE(Type)\
1266 case EET_I_ ## Type: chnk->type = EET_T_ ## Type; break;
1268 EET_UNMATCH_TYPE(STRING);
1269 EET_UNMATCH_TYPE(INLINED_STRING);
1270 EET_UNMATCH_TYPE(NULL);
1276 else if (chnk->type > EET_T_LAST)
1278 chnk->group_type = chnk->type;
1279 chnk->type = EET_T_UNKNOW;
1282 chnk->group_type = EET_G_UNKNOWN;
1283 if ((chnk->type >= EET_T_LAST) ||
1284 (chnk->group_type >=
1288 chnk->group_type = 0;
1291 else if ((s[0] != 'C') || (s[1] != 'H') || (s[2] != 'n') || (s[3] != 'K'))
1294 ret1 = eet_data_get_type(ed, EET_T_INT, (s + 4), (s + size), &(chnk->size));
1299 if ((chnk->size < 0) || ((chnk->size + 8) > size))
1302 ret2 = eet_data_get_type(ed, EET_T_STRING, (s + 8), (s + size), &(chnk->name));
1310 chnk->hash = eet_data_get_string_hash(ed, (s + 8), (s + size));
1314 chnk->data = (char *)src + 4 + ret1 + sizeof(int);
1315 chnk->size -= sizeof(int);
1319 chnk->data = (char *)src + 4 + ret1 + chnk->len;
1320 chnk->size -= chnk->len;
1324 } /* eet_data_chunk_get */
1326 static inline Eet_Data_Chunk *
1327 eet_data_chunk_new(void *data,
1333 Eet_Data_Chunk *chnk;
1338 chnk = calloc(1, sizeof(Eet_Data_Chunk));
1342 /* Note: Another security, so older eet library could read file
1343 saved with fixed point value. */
1344 if (type == EET_T_F32P32
1345 || type == EET_T_F16P16
1346 || type == EET_T_F8P24)
1347 type = EET_T_DOUBLE;
1349 chnk->name = strdup(name);
1350 chnk->len = strlen(name) + 1;
1354 chnk->group_type = group_type;
1356 } /* eet_data_chunk_new */
1359 eet_data_chunk_free(Eet_Data_Chunk *chnk)
1365 } /* eet_data_chunk_free */
1367 static inline Eet_Data_Stream *
1368 eet_data_stream_new(void)
1370 Eet_Data_Stream *ds;
1372 ds = calloc(1, sizeof(Eet_Data_Stream));
1377 } /* eet_data_stream_new */
1380 eet_data_stream_free(Eet_Data_Stream *ds)
1386 } /* eet_data_stream_free */
1389 eet_data_stream_flush(Eet_Data_Stream *ds)
1392 } /* eet_data_stream_flush */
1395 eet_data_stream_write(Eet_Data_Stream *ds,
1401 if ((ds->pos + size) > ds->size)
1403 ds->data = realloc(ds->data, ds->size + size + 512);
1411 ds->size = ds->size + size + 512;
1415 memcpy(p + ds->pos, data, size);
1417 } /* eet_data_stream_write */
1420 eet_data_chunk_put(Eet_Dictionary *ed,
1421 Eet_Data_Chunk *chnk,
1422 Eet_Data_Stream *ds)
1429 unsigned char buf[4] = "CHK";
1431 /* disable this check - it will allow empty chunks to be written. this is
1432 * right for corner-cases when y have a struct with empty fields (empty
1433 * strings or empty list ptrs etc.) */
1434 /* if (!chnk->data && chnk->type != EET_T_NULL) return; */
1437 /* eet_data_stream_write(ds, "CHnK", 4);*/
1438 if (chnk->type != EET_T_UNKNOW)
1440 if (chnk->group_type != EET_G_UNKNOWN)
1442 int type = EET_I_LIMIT + chnk->group_type - EET_G_UNKNOWN;
1446 /* Only make sense with pointer type. */
1447 #define EET_MATCH_TYPE(Type)\
1448 case EET_T_ ## Type: type += EET_I_ ## Type; break;
1450 EET_MATCH_TYPE(STRING);
1451 EET_MATCH_TYPE(INLINED_STRING);
1452 EET_MATCH_TYPE(NULL);
1461 buf[3] = chnk->type;
1464 buf[3] = chnk->group_type;
1466 string = eet_data_put_string(ed, &chnk->name, &string_ret);
1470 /* size of chunk payload data + name */
1471 s = chnk->size + string_ret;
1472 size = eet_data_put_int(ed, &s, &size_ret);
1474 /* FIXME: If something goes wrong the resulting file will be corrupted. */
1478 eet_data_stream_write(ds, buf, 4);
1480 /* write chunk length */
1481 eet_data_stream_write(ds, size, size_ret);
1483 /* write chunk name */
1484 eet_data_stream_write(ds, string, string_ret);
1488 eet_data_stream_write(ds, chnk->data, chnk->size);
1493 } /* eet_data_chunk_put */
1498 _eet_descriptor_hash_new(Eet_Data_Descriptor *edd)
1502 edd->elements.hash.size = 1 << 6;
1503 edd->elements.hash.buckets = calloc(
1505 sizeof(Eet_Data_Descriptor_Hash) *
1506 edd->elements.hash.size);
1507 for (i = 0; i < edd->elements.num; i++)
1509 Eet_Data_Element *ede;
1512 ede = &(edd->elements.set[i]);
1513 hash = _eet_hash_gen((char *)ede->name, 6);
1514 if (!edd->elements.hash.buckets[hash].element)
1515 edd->elements.hash.buckets[hash].element = ede;
1518 Eet_Data_Descriptor_Hash *bucket;
1520 bucket = calloc(1, sizeof(Eet_Data_Descriptor_Hash));
1521 bucket->element = ede;
1522 bucket->next = edd->elements.hash.buckets[hash].next;
1523 edd->elements.hash.buckets[hash].next = bucket;
1526 } /* _eet_descriptor_hash_new */
1529 _eet_descriptor_hash_free(Eet_Data_Descriptor *edd)
1533 for (i = 0; i < edd->elements.hash.size; i++)
1535 Eet_Data_Descriptor_Hash *bucket, *pbucket;
1537 bucket = edd->elements.hash.buckets[i].next;
1541 bucket = bucket->next;
1545 if (edd->elements.hash.buckets)
1546 free(edd->elements.hash.buckets);
1547 } /* _eet_descriptor_hash_free */
1549 static Eet_Data_Element *
1550 _eet_descriptor_hash_find(Eet_Data_Descriptor *edd,
1554 Eet_Data_Descriptor_Hash *bucket;
1557 hash = _eet_hash_gen(name, 6);
1561 if (!edd->elements.hash.buckets[hash].element)
1563 When we use the dictionnary as a source for chunk name, we will always
1564 have the same pointer in name. It's a good idea to just compare pointer
1565 instead of running strcmp on both string.
1568 if (edd->elements.hash.buckets[hash].element->directory_name_ptr == name)
1569 return edd->elements.hash.buckets[hash].element;
1571 if (!strcmp(edd->elements.hash.buckets[hash].element->name, name))
1573 edd->elements.hash.buckets[hash].element->directory_name_ptr = name;
1574 return edd->elements.hash.buckets[hash].element;
1577 bucket = edd->elements.hash.buckets[hash].next;
1580 if (bucket->element->directory_name_ptr == name)
1581 return bucket->element;
1583 if (!strcmp(bucket->element->name, name))
1585 bucket->element->directory_name_ptr = name;
1586 return bucket->element;
1589 bucket = bucket->next;
1592 } /* _eet_descriptor_hash_find */
1595 _eet_mem_alloc(size_t size)
1597 return calloc(1, size);
1598 } /* _eet_mem_alloc */
1601 _eet_mem_free(void *mem)
1604 } /* _eet_mem_free */
1607 _eet_str_alloc(const char *str)
1610 } /* _eet_str_alloc */
1613 _eet_str_free(const char *str)
1616 } /* _eet_str_free */
1619 _eet_eina_hash_add_alloc(Eina_Hash *hash,
1624 hash = eina_hash_string_small_new(NULL);
1629 eina_hash_add(hash, key, data);
1631 } /* _eet_eina_hash_add_alloc */
1634 _eet_eina_hash_direct_add_alloc(Eina_Hash *hash,
1639 hash = eina_hash_string_small_new(NULL);
1644 eina_hash_direct_add(hash, key, data);
1646 } /* _eet_eina_hash_direct_add_alloc */
1649 _eet_str_direct_alloc(const char *str)
1652 } /* _eet_str_direct_alloc */
1655 _eet_str_direct_free(const char *str __UNUSED__)
1657 } /* _eet_str_direct_free */
1660 _eet_eina_hash_foreach(void *hash,
1661 Eina_Hash_Foreach cb,
1665 eina_hash_foreach(hash, cb, fdata);
1666 } /* _eet_eina_hash_foreach */
1669 _eet_eina_hash_free(void *hash)
1672 eina_hash_free(hash);
1673 } /* _eet_eina_hash_free */
1677 eet_eina_stream_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc,
1678 /* When we change the structure content in the future, we need to handle old structure type too */
1679 unsigned int eddc_size,
1683 if (!eddc || !name || eddc_size != sizeof (Eet_Data_Descriptor_Class))
1688 eddc->version = EET_DATA_DESCRIPTOR_CLASS_VERSION;
1690 eddc->func.mem_alloc = _eet_mem_alloc;
1691 eddc->func.mem_free = _eet_mem_free;
1692 eddc->func.str_alloc = (char *(*)(const char *))eina_stringshare_add;
1693 eddc->func.str_free = eina_stringshare_del;
1694 eddc->func.list_next = (void *(*)(void *))eina_list_next;
1695 eddc->func.list_append = (void *(*)(void *, void *))eina_list_append;
1696 eddc->func.list_data = (void *(*)(void *))eina_list_data_get;
1697 eddc->func.list_free = (void *(*)(void *))eina_list_free;
1698 eddc->func.hash_foreach = (void (*)(void *, int (*)(void *, const char *, void *, void *), void *))_eet_eina_hash_foreach;
1699 eddc->func.hash_add = (void * (*)(void *, const char *, void *))_eet_eina_hash_add_alloc;
1700 eddc->func.hash_free = (void (*)(void *))_eet_eina_hash_free;
1702 /* This will cause an ABI incompatibility */
1703 eddc->func.array_alloc = _eet_mem_alloc;
1704 eddc->func.array_free = _eet_mem_free;
1707 } /* eet_eina_stream_data_descriptor_class_set */
1710 eet_eina_file_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc,
1711 /* When we change the structure content in the future, we need to handle old structure type too */
1712 unsigned int eddc_size,
1716 if (!eet_eina_stream_data_descriptor_class_set(eddc, eddc_size, name, size))
1719 eddc->version = EET_DATA_DESCRIPTOR_CLASS_VERSION;
1721 eddc->func.hash_add = (void * (*)(void *, const char *, void *))_eet_eina_hash_direct_add_alloc;
1722 eddc->func.str_direct_alloc = _eet_str_direct_alloc;
1723 eddc->func.str_direct_free = _eet_str_direct_free;
1726 } /* eet_eina_file_data_descriptor_class_set */
1728 static Eet_Data_Descriptor *
1729 _eet_data_descriptor_new(const Eet_Data_Descriptor_Class *eddc,
1732 Eet_Data_Descriptor *edd;
1737 edd = calloc(1, sizeof (Eet_Data_Descriptor));
1741 edd->name = eddc->name;
1743 edd->size = eddc->size;
1744 edd->func.mem_alloc = _eet_mem_alloc;
1745 edd->func.mem_free = _eet_mem_free;
1746 edd->func.str_alloc = _eet_str_alloc;
1747 edd->func.str_free = _eet_str_free;
1748 if (eddc->func.mem_alloc)
1749 edd->func.mem_alloc = eddc->func.mem_alloc;
1751 if (eddc->func.mem_free)
1752 edd->func.mem_free = eddc->func.mem_free;
1754 if (eddc->func.str_alloc)
1755 edd->func.str_alloc = eddc->func.str_alloc;
1757 if (eddc->func.str_free)
1758 edd->func.str_free = eddc->func.str_free;
1760 edd->func.list_next = eddc->func.list_next;
1761 edd->func.list_append = eddc->func.list_append;
1762 edd->func.list_data = eddc->func.list_data;
1763 edd->func.list_free = eddc->func.list_free;
1764 edd->func.hash_foreach = eddc->func.hash_foreach;
1765 edd->func.hash_add = eddc->func.hash_add;
1766 edd->func.hash_free = eddc->func.hash_free;
1768 if (eddc->version > 1 && version > 1)
1770 edd->func.str_direct_alloc = eddc->func.str_direct_alloc;
1771 edd->func.str_direct_free = eddc->func.str_direct_free;
1774 if (eddc->version > 2)
1776 edd->func.type_get = eddc->func.type_get;
1777 edd->func.type_set = eddc->func.type_set;
1780 if (eddc->version > 3)
1782 edd->func.array_alloc = eddc->func.array_alloc;
1783 edd->func.array_free = eddc->func.array_free;
1787 } /* _eet_data_descriptor_new */
1789 EAPI Eet_Data_Descriptor *
1790 eet_data_descriptor_new(const char *name,
1792 Eet_Descriptor_List_Next_Callback func_list_next,
1793 Eet_Descriptor_List_Append_Callback func_list_append,
1794 Eet_Descriptor_List_Data_Callback func_list_data,
1795 Eet_Descriptor_List_Free_Callback func_list_free,
1796 Eet_Descriptor_Hash_Foreach_Callback func_hash_foreach,
1797 Eet_Descriptor_Hash_Add_Callback func_hash_add,
1798 Eet_Descriptor_Hash_Free_Callback func_hash_free)
1800 Eet_Data_Descriptor_Class eddc;
1805 memset(&eddc, 0, sizeof (Eet_Data_Descriptor_Class));
1811 eddc.func.list_next = func_list_next;
1812 eddc.func.list_append = func_list_append;
1813 eddc.func.list_data = func_list_data;
1814 eddc.func.list_free = func_list_free;
1815 eddc.func.hash_foreach = func_hash_foreach;
1816 eddc.func.hash_add = func_hash_add;
1817 eddc.func.hash_free = func_hash_free;
1819 return _eet_data_descriptor_new(&eddc, 0);
1820 } /* eet_data_descriptor_new */
1822 EAPI Eet_Data_Descriptor *
1823 eet_data_descriptor2_new(const Eet_Data_Descriptor_Class *eddc)
1825 return _eet_data_descriptor_new(eddc, 1);
1826 } /* eet_data_descriptor2_new */
1828 EAPI Eet_Data_Descriptor *
1829 eet_data_descriptor3_new(const Eet_Data_Descriptor_Class *eddc)
1831 return _eet_data_descriptor_new(eddc, 2);
1832 } /* eet_data_descriptor3_new */
1834 EAPI Eet_Data_Descriptor *
1835 eet_data_descriptor_stream_new(const Eet_Data_Descriptor_Class *eddc)
1837 return _eet_data_descriptor_new(eddc, 1);
1838 } /* eet_data_descriptor_stream_new */
1840 EAPI Eet_Data_Descriptor *
1841 eet_data_descriptor_file_new(const Eet_Data_Descriptor_Class *eddc)
1843 return _eet_data_descriptor_new(eddc, 2);
1844 } /* eet_data_descriptor_file_new */
1847 eet_data_descriptor_free(Eet_Data_Descriptor *edd)
1852 _eet_descriptor_hash_free(edd);
1853 if (edd->elements.set)
1854 free(edd->elements.set);
1857 } /* eet_data_descriptor_free */
1860 eet_data_descriptor_element_add(Eet_Data_Descriptor *edd,
1866 /* int counter_offset, */
1867 const char *counter_name /* FIXME: Useless should go on a major release */,
1868 Eet_Data_Descriptor *subtype)
1870 Eet_Data_Element *ede;
1871 Eet_Data_Element *tmp;
1873 /* UNION, VARIANT type would not work with simple type, we need a way to map the type. */
1874 if ((group_type == EET_G_UNION
1875 || group_type == EET_G_VARIANT)
1877 (type != EET_T_UNKNOW
1879 || !subtype->func.type_get
1880 || !subtype->func.type_set))
1883 /* VARIANT type will only work if the map only contains EET_G_*, but not UNION, VARIANT and ARRAY. */
1884 if (group_type == EET_G_VARIANT)
1888 for (i = 0; i < subtype->elements.num; ++i)
1889 if (subtype->elements.set[i].type != EET_T_UNKNOW
1890 && subtype->elements.set[i].group_type > EET_G_VAR_ARRAY
1891 && subtype->elements.set[i].group_type < EET_G_UNION)
1894 subtype->unified_type = EINA_TRUE;
1898 && subtype->unified_type
1899 && (type != EET_T_UNKNOW
1900 || group_type < EET_G_UNION))
1903 /* Sanity check done, let allocate ! */
1904 edd->elements.num++;
1905 tmp = realloc(edd->elements.set, edd->elements.num * sizeof(Eet_Data_Element));
1909 edd->elements.set = tmp;
1910 ede = &(edd->elements.set[edd->elements.num - 1]);
1912 ede->directory_name_ptr = NULL;
1915 * We do a special case when we do list,hash or whatever group of simple type.
1916 * Instead of handling it in encode/decode/dump/undump, we create an
1917 * implicit structure with only the simple type.
1919 if ((group_type > EET_G_UNKNOWN)
1920 && (group_type < EET_G_LAST)
1921 && (((type > EET_T_UNKNOW) && (type < EET_T_STRING))
1922 || ((type > EET_T_NULL) && (type < EET_T_LAST)))
1925 subtype = calloc(1, sizeof (Eet_Data_Descriptor));
1929 subtype->name = "implicit";
1930 subtype->size = eet_basic_codec[type - 1].size;
1931 memcpy(&subtype->func, &edd->func, sizeof(subtype->func));
1933 eet_data_descriptor_element_add(subtype,
1934 eet_basic_codec[type - 1].name,
1941 type = EET_T_UNKNOW;
1945 ede->group_type = group_type;
1946 ede->offset = offset;
1948 /* FIXME: For the time being, VAR_ARRAY, UNION and VARIANT will put the counter_offset in count. */
1949 ede->counter_offset = count;
1950 /* ede->counter_offset = counter_offset; */
1951 ede->counter_name = counter_name;
1953 ede->subtype = subtype;
1954 } /* eet_data_descriptor_element_add */
1957 eet_data_read_cipher(Eet_File *ef,
1958 Eet_Data_Descriptor *edd,
1960 const char *cipher_key)
1962 const Eet_Dictionary *ed = NULL;
1963 const void *data = NULL;
1965 Eet_Free_Context context;
1966 int required_free = 0;
1969 ed = eet_dictionary_get(ef);
1972 data = eet_read_direct(ef, name, &size);
1977 data = eet_read_cipher(ef, name, &size, cipher_key);
1982 eet_free_context_init(&context);
1983 data_dec = _eet_data_descriptor_decode(&context, ed, edd, data, size);
1984 eet_free_context_shutdown(&context);
1990 } /* eet_data_read_cipher */
1993 eet_data_node_read_cipher(Eet_File *ef,
1995 const char *cipher_key)
1997 const Eet_Dictionary *ed = NULL;
1998 const void *data = NULL;
2000 Eet_Free_Context context;
2001 int required_free = 0;
2004 ed = eet_dictionary_get(ef);
2007 data = eet_read_direct(ef, name, &size);
2012 data = eet_read_cipher(ef, name, &size, cipher_key);
2017 eet_free_context_init(&context);
2018 result = _eet_data_descriptor_decode(&context, ed, NULL, data, size);
2019 eet_free_context_shutdown(&context);
2025 } /* eet_data_node_read_cipher */
2028 eet_data_read(Eet_File *ef,
2029 Eet_Data_Descriptor *edd,
2032 return eet_data_read_cipher(ef, edd, name, NULL);
2033 } /* eet_data_read */
2036 eet_data_write_cipher(Eet_File *ef,
2037 Eet_Data_Descriptor *edd,
2039 const char *cipher_key,
2048 ed = eet_dictionary_get(ef);
2050 data_enc = _eet_data_descriptor_encode(ed, edd, data, &size);
2054 val = eet_write_cipher(ef, name, data_enc, size, compress, cipher_key);
2057 } /* eet_data_write_cipher */
2060 eet_data_write(Eet_File *ef,
2061 Eet_Data_Descriptor *edd,
2066 return eet_data_write_cipher(ef, edd, name, NULL, data, compress);
2067 } /* eet_data_write */
2070 eet_free_context_init(Eet_Free_Context *context)
2074 memset(context, 0, sizeof (Eet_Free_Context));
2075 for (i = 0; i < EET_FREE_COUNT; ++i)
2077 eina_array_step_set(&context->freelist.list[i],
2078 sizeof (context->freelist.list[i]),
2080 eina_array_step_set(&context->freelist_array.list[i],
2081 sizeof (context->freelist.list[i]),
2083 eina_array_step_set(&context->freelist_list.list[i],
2084 sizeof (context->freelist.list[i]),
2086 eina_array_step_set(&context->freelist_hash.list[i],
2087 sizeof (context->freelist.list[i]),
2089 eina_array_step_set(&context->freelist_str.list[i],
2090 sizeof (context->freelist.list[i]),
2092 eina_array_step_set(&context->freelist_direct_str.list[i],
2093 sizeof (context->freelist.list[i]),
2099 eet_free_context_shutdown(Eet_Free_Context *context)
2103 for (i = 0; i < EET_FREE_COUNT; ++i)
2105 eina_array_flush(&context->freelist.list[i]);
2106 eina_array_flush(&context->freelist_array.list[i]);
2107 eina_array_flush(&context->freelist_list.list[i]);
2108 eina_array_flush(&context->freelist_hash.list[i]);
2109 eina_array_flush(&context->freelist_str.list[i]);
2110 eina_array_flush(&context->freelist_direct_str.list[i]);
2115 _eet_free_hash(void *data)
2118 __int64 ptr = (UINT_PTR)data;
2119 #else /* ifdef _WIN64 */
2120 unsigned long ptr = (unsigned long)(data);
2121 #endif /* ifdef _WIN64 */
2129 #if defined (_WIN64) || ((!defined (_WIN32)) && (LONG_BIT != 32))
2134 #endif /* if defined (_WIN64) || ((!defined (_WIN32)) && (LONG_BIT != 32)) */
2137 } /* _eet_free_hash */
2140 _eet_free_add(Eet_Free *ef,
2144 Eina_Array_Iterator it;
2148 hash = _eet_free_hash(data);
2150 EINA_ARRAY_ITER_NEXT(&ef->list[hash], i, track, it)
2154 eina_array_push(&ef->list[hash], data);
2155 } /* _eet_free_add */
2158 _eet_free_del(Eet_Free *ef,
2162 Eina_Array_Iterator it;
2166 hash = _eet_free_hash(data);
2168 EINA_ARRAY_ITER_NEXT(&ef->list[hash], i, track, it)
2171 eina_array_data_set(&ef->list[hash], i, NULL);
2177 _eet_free_reset(Eet_Free *ef)
2184 for (i = 0; i < EET_FREE_COUNT; ++i)
2185 eina_array_clean(&ef->list[i]);
2186 } /* _eet_free_reset */
2189 _eet_free_ref(Eet_Free *ef)
2192 } /* _eet_free_ref */
2195 _eet_free_unref(Eet_Free *ef)
2198 } /* _eet_free_unref */
2200 #define _eet_freelist_add(Ctx, Data) _eet_free_add(&Ctx->freelist, Data);
2201 #define _eet_freelist_del(Ctx, Data) _eet_free_del(&Ctx->freelist, Data);
2202 #define _eet_freelist_reset(Ctx) _eet_free_reset(&Ctx->freelist);
2203 #define _eet_freelist_ref(Ctx) _eet_free_ref(&Ctx->freelist);
2204 #define _eet_freelist_unref(Ctx) _eet_free_unref(&Ctx->freelist);
2207 _eet_freelist_free(Eet_Free_Context *context,
2208 Eet_Data_Descriptor *edd)
2211 Eina_Array_Iterator it;
2215 if (context->freelist.ref > 0)
2218 for (j = 0; j < EET_FREE_COUNT; ++j)
2219 EINA_ARRAY_ITER_NEXT(&context->freelist.list[j], i, track, it)
2223 edd->func.mem_free(track);
2227 _eet_free_reset(&context->freelist);
2228 } /* _eet_freelist_free */
2230 #define _eet_freelist_array_add(Ctx, Data) _eet_free_add(&Ctx->freelist_array, Data);
2231 #define _eet_freelist_array_del(Ctx, Data) _eet_free_del(&Ctx->freelist_array, Data);
2232 #define _eet_freelist_array_reset(Ctx) _eet_free_reset(&Ctx->freelist_array);
2233 #define _eet_freelist_array_ref(Ctx) _eet_free_ref(&Ctx->freelist_array);
2234 #define _eet_freelist_array_unref(Ctx) _eet_free_unref(&Ctx->freelist_array);
2237 _eet_freelist_array_free(Eet_Free_Context *context,
2238 Eet_Data_Descriptor *edd)
2241 Eina_Array_Iterator it;
2245 if (context->freelist_array.ref > 0)
2248 for (j = 0; j < EET_FREE_COUNT; ++j)
2249 EINA_ARRAY_ITER_NEXT(&context->freelist_array.list[j], i, track, it)
2254 if (edd->func.array_free)
2255 edd->func.array_free(track);
2257 edd->func.mem_free(track);
2262 _eet_free_reset(&context->freelist_array);
2263 } /* _eet_freelist_array_free */
2265 #define _eet_freelist_list_add(Ctx, Data) _eet_free_add(&Ctx->freelist_list, Data);
2266 #define _eet_freelist_list_del(Ctx, Data) _eet_free_del(&Ctx->freelist_list, Data);
2267 #define _eet_freelist_list_reset(Ctx) _eet_free_reset(&Ctx->freelist_list);
2268 #define _eet_freelist_list_ref(Ctx) _eet_free_ref(&Ctx->freelist_list);
2269 #define _eet_freelist_list_unref(Ctx) _eet_free_unref(&Ctx->freelist_list);
2272 _eet_freelist_list_free(Eet_Free_Context *context,
2273 Eet_Data_Descriptor *edd)
2276 Eina_Array_Iterator it;
2280 if (context->freelist_list.ref > 0)
2283 for (j = 0; j < EET_FREE_COUNT; ++j)
2284 EINA_ARRAY_ITER_NEXT(&context->freelist_list.list[j], i, track, it)
2288 edd->func.list_free(*((void **)(track)));
2290 _eet_free_reset(&context->freelist_list);
2291 } /* _eet_freelist_list_free */
2293 #define _eet_freelist_str_add(Ctx, Data) _eet_free_add(&Ctx->freelist_str, Data);
2294 #define _eet_freelist_str_del(Ctx, Data) _eet_free_del(&Ctx->freelist_str, Data);
2295 #define _eet_freelist_str_reset(Ctx) _eet_free_reset(&Ctx->freelist_str);
2296 #define _eet_freelist_str_ref(Ctx) _eet_free_ref(&Ctx->freelist_str);
2297 #define _eet_freelist_str_unref(Ctx) _eet_free_unref(&Ctx->freelist_str);
2300 _eet_freelist_str_free(Eet_Free_Context *context, Eet_Data_Descriptor *edd)
2303 Eina_Array_Iterator it;
2307 if (context->freelist_str.ref > 0)
2310 for (j = 0; j < EET_FREE_COUNT; ++j)
2311 EINA_ARRAY_ITER_NEXT(&context->freelist_str.list[j], i, track, it)
2315 edd->func.str_free(track);
2319 _eet_free_reset(&context->freelist_str);
2320 } /* _eet_freelist_str_free */
2322 #define _eet_freelist_direct_str_add(Ctx, Data) _eet_free_add(&Ctx->freelist_direct_str, Data);
2323 #define _eet_freelist_direct_str_del(Ctx, Data) _eet_free_del(&Ctx->freelist_direct_str, Data);
2324 #define _eet_freelist_direct_str_reset(Ctx) _eet_free_reset(&Ctx->freelist_direct_str);
2325 #define _eet_freelist_direct_str_ref(Ctx) _eet_free_ref(&Ctx->freelist_direct_str);
2326 #define _eet_freelist_direct_str_unref(Ctx) _eet_free_unref(&Ctx->freelist_direct_str);
2329 _eet_freelist_direct_str_free(Eet_Free_Context *context,
2330 Eet_Data_Descriptor *edd)
2333 Eina_Array_Iterator it;
2337 if (context->freelist_direct_str.ref > 0)
2340 for (j = 0; j < EET_FREE_COUNT; ++j)
2341 EINA_ARRAY_ITER_NEXT(&context->freelist_str.list[j], i, track, it)
2345 edd->func.str_direct_free(track);
2349 _eet_free_reset(&context->freelist_direct_str);
2350 } /* _eet_freelist_direct_str_free */
2352 #define _eet_freelist_hash_add(Ctx, Data) _eet_free_add(&Ctx->freelist_hash, Data);
2353 #define _eet_freelist_hash_del(Ctx, Data) _eet_free_del(&Ctx->freelist_hash, Data);
2354 #define _eet_freelist_hash_reset(Ctx) _eet_free_reset(&Ctx->freelist_hash);
2355 #define _eet_freelist_hash_ref(Ctx) _eet_free_ref(&Ctx->freelist_hash);
2356 #define _eet_freelist_hash_unref(Ctx) _eet_free_unref(&Ctx->freelist_hash);
2359 _eet_freelist_hash_free(Eet_Free_Context *context,
2360 Eet_Data_Descriptor *edd)
2363 Eina_Array_Iterator it;
2367 if (context->freelist_hash.ref > 0)
2370 for (j = 0; j < EET_FREE_COUNT; ++j)
2371 EINA_ARRAY_ITER_NEXT(&context->freelist_hash.list[j], i, track, it)
2375 edd->func.hash_free(track);
2379 _eet_free_reset(&context->freelist_hash);
2380 } /* _eet_freelist_hash_free */
2383 _eet_freelist_all_ref(Eet_Free_Context *freelist_context)
2385 _eet_freelist_ref(freelist_context);
2386 _eet_freelist_str_ref(freelist_context);
2387 _eet_freelist_list_ref(freelist_context);
2388 _eet_freelist_hash_ref(freelist_context);
2389 _eet_freelist_direct_str_ref(freelist_context);
2390 } /* _eet_freelist_all_ref */
2393 _eet_freelist_all_unref(Eet_Free_Context *freelist_context)
2395 _eet_freelist_unref(freelist_context);
2396 _eet_freelist_str_unref(freelist_context);
2397 _eet_freelist_list_unref(freelist_context);
2398 _eet_freelist_hash_unref(freelist_context);
2399 _eet_freelist_direct_str_unref(freelist_context);
2400 } /* _eet_freelist_all_unref */
2403 eet_data_descriptor_encode_hash_cb(void *hash __UNUSED__,
2404 const char *cipher_key,
2409 Eet_Data_Encode_Hash_Info *edehi;
2410 Eet_Data_Stream *ds;
2411 Eet_Data_Element *ede;
2412 Eet_Data_Chunk *echnk;
2422 data = eet_data_put_type(ed,
2428 echnk = eet_data_chunk_new(data,
2433 eet_data_chunk_put(ed, echnk, ds);
2434 eet_data_chunk_free(echnk);
2439 EET_ASSERT(!((ede->type > EET_T_UNKNOW) && (ede->type < EET_T_STRING)), return );
2442 if (ede->type >= EET_T_STRING)
2443 eet_data_put_unknown(ed, NULL, ede, ds, &hdata);
2447 data = _eet_data_descriptor_encode(ed,
2454 echnk = eet_data_chunk_new(data,
2459 eet_data_chunk_put(ed, echnk, ds);
2460 eet_data_chunk_free(echnk);
2467 } /* eet_data_descriptor_encode_hash_cb */
2470 _eet_data_dump_token_get(const char *src,
2477 int tlen = 0, tsize = 0;
2485 tok = realloc(tok, tsize);\
2490 for (p = src; *len > 0; p++, (*len)--)
2496 if ((p[0] == '\"') && (p > src) && (p[-1] != '\\'))
2498 else if ((p[0] == '\\') && (*len > 1) &&
2503 else if ((p[0] == '\\') && (p > src) && (p[-1] == '\\'))
2507 else if ((p[0] == '\\') && (*len > 1) && (p[1] == 'n'))
2511 else if ((p[0] == 'n') && (p > src) && (p[-1] == '\\'))
2522 if ((isspace(p[0])) || (p[0] == ';')) /* token ends here */
2533 else if (!((isspace(p[0])) || (p[0] == ';')))
2550 } /* _eet_data_dump_token_get */
2553 eet_data_encode(Eet_Dictionary *ed,
2554 Eet_Data_Stream *ds,
2561 Eet_Data_Chunk *echnk;
2566 if (group_type != EET_G_UNKNOWN)
2567 if (type >= EET_T_LAST)
2568 type = EET_T_UNKNOW;
2570 echnk = eet_data_chunk_new(data, size, name, type, group_type);
2571 eet_data_chunk_put(ed, echnk, ds);
2572 eet_data_chunk_free(echnk);
2574 } /* eet_data_encode */
2577 _eet_data_dump_encode(int parent_type,
2582 Eet_Data_Chunk *chnk = NULL;
2583 Eet_Data_Stream *ds;
2590 if (_eet_data_words_bigendian == -1)
2592 unsigned long int v;
2594 v = htonl(0x12345678);
2595 if (v == 0x12345678)
2596 _eet_data_words_bigendian = 1;
2598 _eet_data_words_bigendian = 0;
2604 ds = eet_data_stream_new();
2611 for (n = node->values; n; n = n->next)
2613 data = _eet_data_dump_encode(node->type, ed, n, &size);
2616 eet_data_stream_write(ds, data, size);
2623 case EET_G_VAR_ARRAY:
2624 for (child_type = EET_T_NULL, n = node->values; n; n = n->next)
2626 if (n->type != EET_T_NULL)
2628 child_type = n->type;
2633 data = eet_data_put_type(ed,
2645 count = node->count;
2647 for (n = node->values; n; n = n->next)
2654 case EET_T_INLINED_STRING:
2655 data = eet_data_put_type(ed,
2657 &(n->data.value.str),
2674 data = _eet_data_dump_encode(n->type, ed, n, &size);
2688 for (; count; count--)
2699 /* Array is somekind of special case, so we should embed it inside another chunk. */
2700 *size_ret = ds->pos;
2705 eet_data_stream_free(ds);
2711 for (n = node->values; n; n = n->next)
2716 case EET_T_INLINED_STRING:
2717 data = eet_data_put_type(ed,
2719 &(n->data.value.str),
2736 data = _eet_data_dump_encode(node->type, ed, n, &size);
2747 /* List is another somekind of special case, every chunk is embed inside a list chunk. */
2748 *size_ret = ds->pos;
2753 eet_data_stream_free(ds);
2761 data = eet_data_put_type(ed,
2774 /* A Hash without key will not decode correctly. */
2777 for (n = node->values; n; n = n->next)
2782 case EET_T_INLINED_STRING:
2783 data = eet_data_put_type(ed,
2785 &(n->data.value.str),
2802 data = _eet_data_dump_encode(node->type, ed, n, &size);
2813 /* Hash is somekind of special case, so we should embed it inside another chunk. */
2814 *size_ret = ds->pos;
2817 eet_data_stream_flush(ds);
2824 #define EET_DATA_NODE_ENCODE(Eet_Type, Type)\
2826 data = eet_data_put_type(ed, node->type, &(node->data.value.Type), &size);\
2829 eet_data_encode(ed,\
2837 *size_ret = ds->pos;\
2838 eet_data_stream_flush(ds);\
2843 EET_DATA_NODE_ENCODE(EET_T_CHAR, c);
2844 EET_DATA_NODE_ENCODE(EET_T_SHORT, s);
2845 EET_DATA_NODE_ENCODE(EET_T_INT, i);
2846 EET_DATA_NODE_ENCODE(EET_T_LONG_LONG, l);
2847 EET_DATA_NODE_ENCODE(EET_T_FLOAT, f);
2848 EET_DATA_NODE_ENCODE(EET_T_DOUBLE, d);
2849 EET_DATA_NODE_ENCODE(EET_T_UCHAR, uc);
2850 EET_DATA_NODE_ENCODE(EET_T_USHORT, us);
2851 EET_DATA_NODE_ENCODE(EET_T_UINT, ui);
2852 EET_DATA_NODE_ENCODE(EET_T_ULONG_LONG, ul);
2853 EET_DATA_NODE_ENCODE(EET_T_INLINED_STRING, str);
2854 EET_DATA_NODE_ENCODE(EET_T_STRING, str);
2860 if ((node->type >= EET_G_UNKNOWN) && (node->type < EET_G_LAST))
2861 chnk = eet_data_chunk_new(ds->data,
2867 chnk = eet_data_chunk_new(ds->data,
2873 eet_data_stream_flush(ds);
2875 ds = eet_data_stream_new();
2876 eet_data_chunk_put(ed, chnk, ds);
2880 eet_data_stream_flush(ds);
2884 eet_data_chunk_free(chnk);
2887 } /* _eet_data_dump_encode */
2890 _eet_data_dump_parse(Eet_Dictionary *ed,
2896 const char *p = NULL;
2901 Eet_Node *node_base = NULL;
2902 Eet_Node *node = NULL;
2903 Eet_Node *n = NULL, *nn = NULL;
2905 /* FIXME; handle parse errors */
2907 jump = left; t = _eet_data_dump_token_get(p, &left); p += jump - left;
2909 for (p = src; p < (src + size); )
2911 char *tok1, *tok2, *tok3, *tok4;
2916 if (!strcmp(tok1, "group"))
2927 if (!strcmp(tok4, "{"))
2929 /* we have 'group NAM TYP {' */
2943 for (nn = node->values; nn;
2954 n->name = eina_stringshare_add(tok2);
2955 if (!strcmp(tok3, "struct"))
2956 n->type = EET_G_UNKNOWN;
2957 else if (!strcmp(tok3, "array"))
2958 n->type = EET_G_ARRAY;
2959 else if (!strcmp(tok3, "var_array"))
2960 n->type = EET_G_VAR_ARRAY;
2961 else if (!strcmp(tok3, "list"))
2962 n->type = EET_G_LIST;
2963 else if (!strcmp(tok3, "hash"))
2964 n->type = EET_G_HASH;
2967 "ERROR: group type '%s' invalid.",
2983 else if (!strcmp(tok1, "value"))
2994 /* we have 'value NAME TYP XXX' */
3005 for (nn = node->values; nn;
3015 n->name = eina_stringshare_add(tok2);
3016 if (!strcmp(tok3, "char:"))
3018 n->type = EET_T_CHAR;
3019 sscanf(tok4, "%hhi",
3020 &(n->data.value.c));
3022 else if (!strcmp(tok3, "short:"))
3024 n->type = EET_T_SHORT;
3026 &(n->data.value.s));
3028 else if (!strcmp(tok3, "int:"))
3030 n->type = EET_T_INT;
3032 &(n->data.value.i));
3034 else if (!strcmp(tok3, "long_long:"))
3036 n->type = EET_T_LONG_LONG;
3037 sscanf(tok4, "%lli",
3038 &(n->data.value.l));
3040 else if (!strcmp(tok3, "float:"))
3042 n->type = EET_T_FLOAT;
3044 &(n->data.value.f));
3046 else if (!strcmp(tok3, "double:"))
3048 n->type = EET_T_DOUBLE;
3050 &(n->data.value.d));
3052 else if (!strcmp(tok3, "uchar:"))
3054 n->type = EET_T_UCHAR;
3055 sscanf(tok4, "%hhu",
3056 &(n->data.value.uc));
3058 else if (!strcmp(tok3, "ushort:"))
3060 n->type = EET_T_USHORT;
3062 &(n->data.value.us));
3064 else if (!strcmp(tok3, "uint:"))
3066 n->type = EET_T_UINT;
3068 &(n->data.value.ui));
3070 else if (!strcmp(tok3, "ulong_long:"))
3072 n->type = EET_T_ULONG_LONG;
3073 sscanf(tok4, "%llu",
3074 &(n->data.value.ul));
3076 else if (!strcmp(tok3, "string:"))
3078 n->type = EET_T_STRING;
3080 eina_stringshare_add(tok4);
3082 else if (!strcmp(tok3, "inlined:"))
3084 n->type = EET_T_INLINED_STRING;
3086 eina_stringshare_add(tok4);
3088 else if (!strcmp(tok3, "null"))
3090 n->type = EET_T_NULL;
3091 n->data.value.str = NULL;
3095 "ERROR: value type '%s' invalid.",
3109 else if (!strcmp(tok1, "key"))
3114 /* we have 'key NAME' */
3116 node->key = eina_stringshare_add(tok2);
3121 else if (!strcmp(tok1, "count"))
3126 /* we have a 'count COUNT' */
3128 sscanf(tok2, "%i", &(node->count));
3133 else if (!strcmp(tok1, "}"))
3134 /* we have an end of the group */
3136 node = node->parent;
3144 cdata = _eet_data_dump_encode(EET_G_UNKNOWN, ed, node_base, size_ret);
3145 eet_node_del(node_base);
3149 } /* _eet_data_dump_parse */
3151 #define NEXT_CHUNK(P, Size, Echnk, Ed)\
3154 tmp = Ed ? (int)(sizeof(int) * 2) : Echnk.len + 4;\
3155 P += (4 + Echnk.size + tmp);\
3156 Size -= (4 + Echnk.size + tmp);\
3160 _eet_data_descriptor_decode(Eet_Free_Context *context,
3161 const Eet_Dictionary *ed,
3162 Eet_Data_Descriptor *edd,
3163 const void *data_in,
3166 Eet_Node *result = NULL;
3170 Eet_Data_Chunk chnk;
3172 if (_eet_data_words_bigendian == -1)
3174 unsigned long int v;
3176 v = htonl(0x12345678);
3177 if (v == 0x12345678)
3178 _eet_data_words_bigendian = 1;
3180 _eet_data_words_bigendian = 0;
3185 data = edd->func.mem_alloc(edd->size);
3191 for (i = 0; i < edd->elements.num; i++)
3192 edd->elements.set[i].directory_name_ptr = NULL;
3197 _eet_freelist_all_ref(context);
3199 _eet_freelist_add(context, data);
3201 memset(&chnk, 0, sizeof(Eet_Data_Chunk));
3202 eet_data_chunk_get(ed, &chnk, data_in, size_in);
3207 if (strcmp(chnk.name, edd->name))
3212 size = size_in - (4 + sizeof(int) * 2);
3214 size = size_in - (4 + 4 + chnk.len);
3218 if (!edd->elements.hash.buckets)
3219 _eet_descriptor_hash_new(edd);
3223 switch (chnk.group_type)
3229 return eet_node_string_new(chnk.name, chnk.data);
3231 case EET_T_INLINED_STRING:
3232 return eet_node_inlined_string_new(chnk.name, chnk.data);
3235 return eet_node_null_new(chnk.name);
3238 result = eet_node_struct_new(chnk.name, NULL);
3242 case EET_G_VAR_ARRAY:
3243 return eet_node_var_array_new(chnk.name, NULL);
3257 Eet_Data_Chunk echnk;
3258 Eet_Data_Element *ede = NULL;
3259 Eet_Node *child = NULL;
3260 int group_type = EET_G_UNKNOWN, type = EET_T_UNKNOW;
3263 /* get next data chunk */
3264 memset(&echnk, 0, sizeof(Eet_Data_Chunk));
3265 eet_data_chunk_get(ed, &echnk, p, size);
3267 goto error; /* FIXME: don't REPLY on edd - work without */
3271 ede = _eet_descriptor_hash_find(edd, echnk.name, echnk.hash);
3274 group_type = ede->group_type;
3276 if ((echnk.type == 0) && (echnk.group_type == 0))
3279 group_type = ede->group_type;
3283 if (IS_SIMPLE_TYPE(echnk.type) &&
3284 eet_data_type_match(echnk.type, ede->type))
3285 /* Needed when converting on the fly from FP to Float */
3287 else if ((echnk.group_type > EET_G_UNKNOWN) &&
3288 (echnk.group_type < EET_G_LAST) &&
3289 (echnk.group_type == ede->group_type))
3290 group_type = echnk.group_type;
3294 /*...... dump to node */
3298 group_type = echnk.group_type;
3301 if (!edd && group_type == EET_G_UNKNOWN && IS_SIMPLE_TYPE(type))
3303 unsigned char dd[128];
3305 ret = eet_data_get_type(ed,
3308 ((char *)echnk.data) + echnk.size,
3313 child = eet_data_node_simple_type(type, echnk.name, dd);
3315 eet_node_struct_append(result, echnk.name, child);
3319 ret = eet_group_codec[group_type - 100].get(
3327 ede ? (void *)(((char*) data) + ede->offset) : (void **)&result,
3335 /* advance to next chunk */
3336 NEXT_CHUNK(p, size, echnk, ed);
3339 _eet_freelist_all_unref(context);
3342 _eet_freelist_str_free(context, edd);
3343 _eet_freelist_direct_str_free(context, edd);
3344 _eet_freelist_list_free(context, edd);
3345 _eet_freelist_hash_free(context, edd);
3346 _eet_freelist_array_free(context, edd);
3347 _eet_freelist_free(context, edd);
3351 _eet_freelist_reset(context);
3352 _eet_freelist_str_reset(context);
3353 _eet_freelist_list_reset(context);
3354 _eet_freelist_hash_reset(context);
3355 _eet_freelist_direct_str_reset(context);
3356 _eet_freelist_array_reset(context);
3365 eet_node_del(result);
3367 _eet_freelist_all_unref(context);
3368 _eet_freelist_str_free(context, edd);
3369 _eet_freelist_direct_str_free(context, edd);
3370 _eet_freelist_list_free(context, edd);
3371 _eet_freelist_hash_free(context, edd);
3372 _eet_freelist_array_free(context, edd);
3373 _eet_freelist_free(context, edd);
3375 /* FIXME: Warn that something goes wrong here. */
3377 } /* _eet_data_descriptor_decode */
3380 eet_data_get_list(Eet_Free_Context *context,
3381 const Eet_Dictionary *ed,
3382 Eet_Data_Descriptor *edd,
3383 Eet_Data_Element *ede,
3384 Eet_Data_Chunk *echnk,
3386 int group_type __UNUSED__,
3391 Eet_Data_Descriptor *subtype = NULL;
3396 EET_ASSERT(!((type > EET_T_UNKNOW) && (type < EET_T_STRING)), return 0);
3400 subtype = ede->subtype;
3402 if (type != ede->type)
3406 ptr = (void **)data;
3410 if (IS_POINTER_TYPE(type))
3411 POINTER_TYPE_DECODE(context,
3422 STRUCT_TYPE_DECODE(data_ret,
3432 list = edd->func.list_append(list, data_ret);
3434 _eet_freelist_list_add(context, ptr);
3437 eet_node_list_append(*((Eet_Node **)data), echnk->name, data_ret);
3443 } /* eet_data_get_list */
3446 eet_data_get_hash(Eet_Free_Context *context,
3447 const Eet_Dictionary *ed,
3448 Eet_Data_Descriptor *edd,
3449 Eet_Data_Element *ede,
3450 Eet_Data_Chunk *echnk,
3452 int group_type __UNUSED__,
3460 void *data_ret = NULL;
3463 EET_ASSERT(!((type > EET_T_UNKNOW) && (type < EET_T_STRING)), return 0);
3465 ptr = (void **)data;
3469 ret = eet_data_get_type(ed,
3472 ((char *)echnk->data) + echnk->size,
3480 /* Advance to next chunk */
3481 NEXT_CHUNK((*p), (*size), (*echnk), ed);
3482 memset(echnk, 0, sizeof(Eet_Data_Chunk));
3485 eet_data_chunk_get(ed, echnk, *p, *size);
3490 if ((ede->group_type != echnk->group_type)
3491 || (ede->type != echnk->type))
3494 if (IS_POINTER_TYPE(echnk->type))
3495 POINTER_TYPE_DECODE(context,
3506 STRUCT_TYPE_DECODE(data_ret,
3509 ede ? ede->subtype : NULL,
3516 hash = edd->func.hash_add(hash, key, data_ret);
3518 _eet_freelist_hash_add(context, hash);
3521 eet_node_hash_add(*((Eet_Node **)data), echnk->name, key, data_ret);
3527 } /* eet_data_get_hash */
3529 /* var arrays and fixed arrays have to
3530 * get all chunks at once. for fixed arrays
3531 * we can get each chunk and increment a
3532 * counter stored on the element itself but
3533 * it wont be thread safe. for var arrays
3534 * we still need a way to get the number of
3535 * elements from the data, so storing the
3536 * number of elements and the element data on
3537 * each chunk is pointless.
3540 eet_data_get_array(Eet_Free_Context *context,
3541 const Eet_Dictionary *ed,
3542 Eet_Data_Descriptor *edd,
3543 Eet_Data_Element *ede,
3544 Eet_Data_Chunk *echnk,
3551 Eina_List *childs = NULL;
3560 EET_ASSERT(!((type > EET_T_UNKNOW) && (type < EET_T_STRING)), return 0);
3563 /* read the number of elements */
3564 ret = eet_data_get_type(ed,
3567 ((char *)echnk->data) + echnk->size,
3576 if (IS_POINTER_TYPE(type))
3577 subsize = eet_basic_codec[ede->type].size;
3579 subsize = ede->subtype->size;
3581 if (group_type == EET_G_VAR_ARRAY)
3583 /* store the number of elements
3584 * on the counter offset */
3585 *(int *)(((char *)data) + ede->count - ede->offset) = count;
3586 /* allocate space for the array of elements */
3587 if (edd->func.array_alloc)
3588 *(void **) ptr = edd->func.array_alloc(count * subsize);
3590 *(void **) ptr = edd->func.mem_alloc(count * subsize);
3595 memset(*(void **)ptr, 0, count * subsize);
3597 _eet_freelist_array_add(context, *(void **)ptr);
3601 /* get all array elements */
3602 for (i = 0; i < count; i++)
3605 void *data_ret = NULL;
3607 /* Advance to next chunk */
3608 NEXT_CHUNK((*p), (*size), (*echnk), ed);
3609 memset(echnk, 0, sizeof(Eet_Data_Chunk));
3611 eet_data_chunk_get(ed, echnk, *p, *size);
3612 if (!echnk->name || strcmp(echnk->name, name) != 0)
3613 goto on_error; /* get the data */
3615 if ((echnk->group_type != group_type)
3616 || ((echnk->type != type) && (echnk->type != EET_T_NULL)))
3620 if ((ede->group_type != echnk->group_type)
3621 || ((echnk->type != ede->type) && (echnk->type != EET_T_NULL)))
3624 /* get the destination pointer */
3627 if (group_type == EET_G_ARRAY)
3628 dst = (char *)ptr + (subsize * i);
3630 dst = *(char **)ptr + (subsize * i);
3633 if (IS_POINTER_TYPE(echnk->type))
3635 POINTER_TYPE_DECODE(context,
3646 memcpy(dst, &data_ret, subsize);
3649 childs = eina_list_append(childs, data_ret);
3653 STRUCT_TYPE_DECODE(data_ret,
3656 ede ? ede->subtype : NULL,
3662 memcpy(dst, data_ret, subsize);
3663 if ((ede) && (ede->subtype))
3664 ede->subtype->func.mem_free(data_ret);
3666 edd->func.mem_free(data_ret);
3667 else free(data_ret);
3668 _eet_freelist_del(context, data_ret);
3672 childs = eina_list_append(childs, data_ret);
3678 Eet_Node *parent = *((Eet_Node **)data);
3681 if (group_type == EET_G_ARRAY)
3682 array = eet_node_array_new(name, count, childs);
3684 array = eet_node_var_array_new(name, childs);
3689 eet_node_struct_append(parent, name, array);
3695 EINA_LIST_FREE(childs, tmp)
3699 } /* eet_data_get_array */
3702 eet_data_put_union(Eet_Dictionary *ed,
3703 Eet_Data_Descriptor *edd __UNUSED__,
3704 Eet_Data_Element *ede,
3705 Eet_Data_Stream *ds,
3708 const char *union_type;
3711 EET_ASSERT(!((ede->type != EET_T_UNKNOW) || (!ede->subtype)), return );
3713 union_type = ede->subtype->func.type_get(
3714 ((char *)data_in) + ede->count - ede->offset,
3720 /* Search the structure of the union to encode. */
3721 for (i = 0; i < ede->subtype->elements.num; ++i)
3722 if (strcmp(ede->subtype->elements.set[i].name, union_type) == 0)
3724 Eet_Data_Element *sede;
3728 /* Yeah we found it ! */
3729 data = eet_data_put_type(ed, EET_T_STRING, &union_type, &size);
3739 sede = &(ede->subtype->elements.set[i]);
3740 data = _eet_data_descriptor_encode(ed,
3756 } /* eet_data_put_union */
3759 eet_data_get_union(Eet_Free_Context *context,
3760 const Eet_Dictionary *ed,
3761 Eet_Data_Descriptor *edd __UNUSED__,
3762 Eet_Data_Element *ede,
3763 Eet_Data_Chunk *echnk,
3770 const char *union_type;
3771 void *data_ret = NULL;
3776 ret = eet_data_get_type(ed,
3779 ((char *)echnk->data) + echnk->size,
3784 /* Advance to next chunk */
3785 NEXT_CHUNK((*p), (*size), (*echnk), ed);
3786 memset(echnk, 0, sizeof(Eet_Data_Chunk));
3789 eet_data_chunk_get(ed, echnk, *p, *size);
3795 EET_ASSERT(!(ede->group_type != group_type || ede->type != type),
3798 /* Search the structure of the union to decode */
3799 for (i = 0; i < ede->subtype->elements.num; ++i)
3800 if (strcmp(ede->subtype->elements.set[i].name, union_type) == 0)
3802 Eet_Data_Element *sede;
3805 /* Yeah we found it ! */
3806 sede = &(ede->subtype->elements.set[i]);
3807 EET_ASSERT(sede->subtype, goto on_error);
3809 data_ret = _eet_data_descriptor_decode(context,
3817 /* Memcopy the structure content to remove pointer indirection. */
3818 memcpy(data, data_ret, sede->subtype->size);
3820 /* data_ret is now useless. */
3821 sede->subtype->func.mem_free(data_ret);
3823 /* Set union type. */
3824 if ((!ed) || (!ede->subtype->func.str_direct_alloc))
3826 ut = ede->subtype->func.str_alloc(union_type);
3827 _eet_freelist_str_add(context, ut);
3831 ut = ede->subtype->func.str_direct_alloc(union_type);
3832 _eet_freelist_direct_str_add(context, ut);
3835 ede->subtype->func.type_set(
3837 ((char *)data) + ede->count -
3847 /* FIXME: generate node structure. */
3848 data_ret = _eet_data_descriptor_decode(context,
3850 echnk->data, echnk->size);
3858 } /* eet_data_get_union */
3861 eet_data_put_variant(Eet_Dictionary *ed,
3862 Eet_Data_Descriptor *edd __UNUSED__,
3863 Eet_Data_Element *ede,
3864 Eet_Data_Stream *ds,
3867 const char *union_type;
3869 Eina_Bool unknow = EINA_FALSE;
3873 EET_ASSERT(!((ede->type != EET_T_UNKNOW) || (!ede->subtype)), return );
3875 union_type = ede->subtype->func.type_get(
3876 ((char *)data_in) + ede->count - ede->offset,
3879 if (!union_type && unknow == EINA_FALSE)
3884 /* Handle opaque internal representation */
3885 Eet_Variant_Unknow *evu;
3887 data = eet_data_put_type(ed, EET_T_STRING, &union_type, &size);
3897 evu = (Eet_Variant_Unknow *)data_in;
3898 if (evu && EINA_MAGIC_CHECK(evu, EET_MAGIC_VARIANT))
3908 /* Search the structure of the union to encode. */
3909 for (i = 0; i < ede->subtype->elements.num; ++i)
3910 if (strcmp(ede->subtype->elements.set[i].name, union_type) == 0)
3912 Eet_Data_Element *sede;
3914 /* Yeah we found it ! */
3915 data = eet_data_put_type(ed, EET_T_STRING, &union_type, &size);
3925 sede = &(ede->subtype->elements.set[i]);
3927 if (sede->group_type != EET_G_UNKNOWN)
3929 Eet_Data_Stream *lds;
3931 lds = eet_data_stream_new();
3932 eet_group_codec[sede->group_type - 100].put(ed,
3939 eet_data_encode(ed, ds, lds->data, ede->name, lds->pos,
3940 ede->type, ede->group_type);
3946 eet_data_encode(ed, ds, NULL, ede->name, 0,
3947 EET_T_NULL, ede->group_type);
3949 eet_data_stream_free(lds);
3953 data = _eet_data_descriptor_encode(ed,
3970 } /* eet_data_put_variant */
3973 eet_data_get_variant(Eet_Free_Context *context,
3974 const Eet_Dictionary *ed,
3975 Eet_Data_Descriptor *edd __UNUSED__,
3976 Eet_Data_Element *ede,
3977 Eet_Data_Chunk *echnk,
3978 int type __UNUSED__,
3979 int group_type __UNUSED__,
3984 const char *union_type;
3985 void *data_ret = NULL;
3990 ret = eet_data_get_type(ed,
3993 ((char *)echnk->data) + echnk->size,
3998 /* Advance to next chunk */
3999 NEXT_CHUNK((*p), (*size), (*echnk), ed);
4000 memset(echnk, 0, sizeof(Eet_Data_Chunk));
4003 eet_data_chunk_get(ed, echnk, *p, *size);
4011 EET_ASSERT(ede->subtype, goto on_error);
4013 if ((!ed) || (!ede->subtype->func.str_direct_alloc))
4015 ut = ede->subtype->func.str_alloc(union_type);
4016 _eet_freelist_str_add(context, ut);
4020 ut = ede->subtype->func.str_direct_alloc(union_type);
4021 _eet_freelist_direct_str_add(context, ut);
4024 /* Search the structure of the union to decode */
4025 for (i = 0; i < ede->subtype->elements.num; ++i)
4026 if (strcmp(ede->subtype->elements.set[i].name, union_type) == 0)
4028 Eet_Data_Element *sede;
4030 /* Yeah we found it ! */
4031 sede = &(ede->subtype->elements.set[i]);
4033 if (sede->group_type != EET_G_UNKNOWN)
4035 Eet_Data_Chunk chnk;
4041 size2 = echnk->size;
4043 /* Didn't find a proper way to provide this
4044 without duplicating code */
4047 memset(&chnk, 0, sizeof(Eet_Data_Chunk));
4048 eet_data_chunk_get(ed, &chnk, p2, size2);
4053 ret = eet_group_codec[sede->group_type - 100].get
4054 (context, ed, sede->subtype, sede, &chnk, sede->type,
4055 sede->group_type, data, &p2, &size2);
4060 /* advance to next chunk */
4061 NEXT_CHUNK(p2, size2, chnk, ed);
4064 /* Put garbage so that we will not put eet_variant_unknow in it */
4065 data_ret = (void *)data;
4067 /* Set variant type. */
4068 ede->subtype->func.type_set
4069 (ut, ((char *)data) + ede->count - ede->offset,
4074 data_ret = _eet_data_descriptor_decode(context,
4082 /* And point to the variant data. */
4083 *(void **)data = data_ret;
4085 /* Set variant type. */
4086 ede->subtype->func.type_set
4087 (ut, ((char *)data) + ede->count - ede->offset, EINA_FALSE);
4093 Eet_Variant_Unknow *evu;
4095 evu = calloc(1, sizeof (Eet_Variant_Unknow) + echnk->size - 1);
4099 evu->size = echnk->size;
4100 memcpy(evu->data, echnk->data, evu->size);
4101 EINA_MAGIC_SET(evu, EET_MAGIC_VARIANT);
4103 /* And point to the opaque internal data scructure */
4104 *(void **)data = evu;
4106 /* Set variant type. */
4107 ede->subtype->func.type_set
4108 (ut, ((char *)data) + ede->count - ede->offset, EINA_TRUE);
4113 /* FIXME: dump node structure. */
4114 data_ret = _eet_data_descriptor_decode(context,
4116 echnk->data, echnk->size);
4124 } /* eet_data_get_variant */
4127 eet_data_node_simple_type(int type, const char *name, void *dd)
4131 #endif /* ifdef EET_T_TYPE */
4133 #define EET_T_TYPE(Eet_Type, Eet_Node_Type, Type)\
4135 return eet_node_ ## Eet_Node_Type ## _new(name, *((Type *)dd));\
4139 EET_T_TYPE(EET_T_CHAR, char, char);
4140 EET_T_TYPE(EET_T_SHORT, short, short);
4141 EET_T_TYPE(EET_T_INT, int, int);
4142 EET_T_TYPE(EET_T_LONG_LONG, long_long, long long);
4143 EET_T_TYPE(EET_T_FLOAT, float, float);
4144 EET_T_TYPE(EET_T_DOUBLE, double, double);
4145 EET_T_TYPE(EET_T_UCHAR, unsigned_char, unsigned char);
4146 EET_T_TYPE(EET_T_USHORT, unsigned_short, unsigned short);
4147 EET_T_TYPE(EET_T_UINT, unsigned_int, unsigned int);
4148 EET_T_TYPE(EET_T_ULONG_LONG, unsigned_long_long, unsigned long long);
4149 EET_T_TYPE(EET_T_STRING, string, char *);
4150 EET_T_TYPE(EET_T_INLINED_STRING, inlined_string, char *);
4153 return eet_node_null_new(name);
4156 ERR("Unknow type passed to eet_data_node_simple_type");
4159 } /* eet_data_node_simple_type */
4162 eet_data_get_unknown(Eet_Free_Context *context,
4163 const Eet_Dictionary *ed,
4164 Eet_Data_Descriptor *edd,
4165 Eet_Data_Element *ede,
4166 Eet_Data_Chunk *echnk,
4168 int group_type __UNUSED__,
4170 char **p __UNUSED__,
4171 int *size __UNUSED__)
4176 if (IS_SIMPLE_TYPE(type))
4178 unsigned char dd[128];
4180 ret = eet_data_get_type(ed,
4183 ((char *)echnk->data) + echnk->size,
4184 edd ? (char *)data : (char *)dd);
4190 Eet_Node **parent = data;
4193 node = eet_data_node_simple_type(type, echnk->name, dd);
4196 eet_node_struct_append(*parent, echnk->name, node);
4202 if (type == EET_T_STRING)
4206 str = (char **)(((char *)data));
4209 if ((!ed) || (!edd->func.str_direct_alloc))
4211 *str = edd->func.str_alloc(*str);
4212 _eet_freelist_str_add(context, *str);
4216 *str = edd->func.str_direct_alloc(*str);
4217 _eet_freelist_direct_str_add(context, *str);
4221 else if (edd && type == EET_T_INLINED_STRING)
4225 str = (char **)(((char *)data));
4228 *str = edd->func.str_alloc(*str);
4229 _eet_freelist_str_add(context, *str);
4236 Eet_Data_Descriptor *subtype;
4238 subtype = ede ? ede->subtype : NULL;
4240 if (subtype || !edd)
4242 Eet_Node **parent = data;
4245 data_ret = _eet_data_descriptor_decode(context,
4255 ptr = (void **)(((char *)data));
4256 *ptr = (void *)data_ret;
4260 Eet_Node *node = data_ret;
4264 node = eet_node_struct_child_new(echnk->name, node);
4265 eet_node_struct_append(*parent, echnk->name, node);
4274 } /* eet_data_get_unknown */
4277 eet_data_put_array(Eet_Dictionary *ed,
4278 Eet_Data_Descriptor *edd __UNUSED__,
4279 Eet_Data_Element *ede,
4280 Eet_Data_Stream *ds,
4290 EET_ASSERT(!((ede->type > EET_T_UNKNOW) && (ede->type < EET_T_STRING)),
4293 if (ede->group_type == EET_G_ARRAY)
4294 count = ede->counter_offset;
4296 count = *(int *)(((char *)data_in) + ede->count - ede->offset);
4299 return; /* Store number of elements */
4301 data = eet_data_put_type(ed, EET_T_INT, &count, &size);
4303 eet_data_encode(ed, ds, data, ede->name, size, ede->type, ede->group_type);
4305 if (IS_POINTER_TYPE(ede->type))
4306 subsize = eet_basic_codec[ede->type].size;
4308 subsize = ede->subtype->size;
4310 for (j = 0; j < count; j++)
4315 if (ede->group_type == EET_G_ARRAY)
4316 d = (void *)(((char *)data_in) + offset);
4318 d = *(((char **)data_in)) + offset;
4320 if (IS_POINTER_TYPE(ede->type))
4323 eet_data_put_unknown(ed, NULL, ede, ds, d);
4327 data = _eet_data_descriptor_encode(ed, ede->subtype, d, &size);
4339 /* Add a NULL element just to have the correct array layout. */
4350 } /* eet_data_put_array */
4353 eet_data_put_unknown(Eet_Dictionary *ed,
4354 Eet_Data_Descriptor *edd __UNUSED__,
4355 Eet_Data_Element *ede,
4356 Eet_Data_Stream *ds,
4362 if (IS_SIMPLE_TYPE(ede->type))
4363 data = eet_data_put_type(ed, ede->type, data_in, &size);
4364 else if (ede->subtype)
4365 if (*((char **)data_in))
4366 data = _eet_data_descriptor_encode(ed,
4368 *((char **)((char *)(data_in))),
4379 } /* eet_data_put_unknown */
4382 eet_data_put_list(Eet_Dictionary *ed,
4383 Eet_Data_Descriptor *edd,
4384 Eet_Data_Element *ede,
4385 Eet_Data_Stream *ds,
4392 EET_ASSERT(!(((ede->type > EET_T_UNKNOW) && (ede->type < EET_T_STRING))
4393 || ((ede->type > EET_T_NULL) && (ede->type < EET_T_LAST))),
4396 l = *((void **)(((char *)data_in)));
4397 for (; l; l = edd->func.list_next(l))
4399 if (IS_POINTER_TYPE(ede->type))
4401 const void *str = edd->func.list_data(l);
4402 eet_data_put_unknown(ed, NULL, ede, ds, &str);
4406 data = _eet_data_descriptor_encode(ed,
4408 edd->func.list_data(l),
4420 } /* eet_data_put_list */
4423 eet_data_put_hash(Eet_Dictionary *ed,
4424 Eet_Data_Descriptor *edd,
4425 Eet_Data_Element *ede,
4426 Eet_Data_Stream *ds,
4429 Eet_Data_Encode_Hash_Info fdata;
4432 l = *((void **)(((char *)data_in)));
4436 edd->func.hash_foreach(l, eet_data_descriptor_encode_hash_cb, &fdata);
4437 } /* eet_data_put_hash */
4440 eet_data_dump_cipher(Eet_File *ef,
4442 const char *cipher_key,
4443 Eet_Dump_Callback dumpfunc,
4446 const Eet_Dictionary *ed = NULL;
4447 const void *data = NULL;
4449 Eet_Free_Context context;
4450 int required_free = 0;
4453 ed = eet_dictionary_get(ef);
4456 data = eet_read_direct(ef, name, &size);
4461 data = eet_read_cipher(ef, name, &size, cipher_key);
4466 eet_free_context_init(&context);
4467 result = _eet_data_descriptor_decode(&context, ed, NULL, data, size);
4468 eet_free_context_shutdown(&context);
4470 eet_node_dump(result, 0, dumpfunc, dumpdata);
4472 eet_node_del(result);
4477 return result ? 1 : 0;
4478 } /* eet_data_dump_cipher */
4481 eet_data_dump(Eet_File *ef,
4483 Eet_Dump_Callback dumpfunc,
4486 return eet_data_dump_cipher(ef, name, NULL, dumpfunc, dumpdata);
4487 } /* eet_data_dump */
4490 eet_data_text_dump_cipher(const void *data_in,
4491 const char *cipher_key,
4493 Eet_Dump_Callback dumpfunc,
4498 Eet_Free_Context context;
4499 unsigned int ret_len = 0;
4506 if (eet_decipher(data_in, size_in, cipher_key,
4507 strlen(cipher_key), &ret, &ret_len))
4517 ret = (void *)data_in;
4521 eet_free_context_init(&context);
4522 result = _eet_data_descriptor_decode(&context, NULL, NULL, ret, ret_len);
4523 eet_free_context_shutdown(&context);
4525 eet_node_dump(result, 0, dumpfunc, dumpdata);
4527 eet_node_del(result);
4531 return result ? 1 : 0;
4532 } /* eet_data_text_dump_cipher */
4535 eet_data_text_dump(const void *data_in,
4537 Eet_Dump_Callback dumpfunc,
4540 return eet_data_text_dump_cipher(data_in, NULL, size_in, dumpfunc, dumpdata);
4541 } /* eet_data_text_dump */
4544 eet_data_text_undump_cipher(const char *text,
4545 const char *cipher_key,
4551 ret = _eet_data_dump_parse(NULL, size_ret, text, textlen);
4552 if (ret && cipher_key)
4554 void *ciphered = NULL;
4555 unsigned int ciphered_len;
4557 if (eet_cipher(ret, *size_ret, cipher_key,
4558 strlen(cipher_key), &ciphered, &ciphered_len))
4569 *size_ret = ciphered_len;
4574 } /* eet_data_text_undump_cipher */
4577 eet_data_text_undump(const char *text,
4581 return eet_data_text_undump_cipher(text, NULL, textlen, size_ret);
4582 } /* eet_data_text_undump */
4585 eet_data_undump_cipher(Eet_File *ef,
4587 const char *cipher_key,
4597 ed = eet_dictionary_get(ef);
4599 data_enc = _eet_data_dump_parse(ed, &size, text, textlen);
4603 val = eet_write_cipher(ef, name, data_enc, size, compress, cipher_key);
4606 } /* eet_data_undump_cipher */
4609 eet_data_undump(Eet_File *ef,
4615 return eet_data_undump_cipher(ef, name, NULL, text, textlen, compress);
4616 } /* eet_data_undump */
4619 eet_data_descriptor_decode_cipher(Eet_Data_Descriptor *edd,
4620 const void *data_in,
4621 const char *cipher_key,
4624 void *deciphered = (void *)data_in;
4626 Eet_Free_Context context;
4627 unsigned int deciphered_len = size_in;
4629 if (cipher_key && data_in)
4630 if (eet_decipher(data_in, size_in, cipher_key,
4631 strlen(cipher_key), &deciphered, &deciphered_len))
4639 eet_free_context_init(&context);
4640 ret = _eet_data_descriptor_decode(&context,
4645 eet_free_context_shutdown(&context);
4647 if (data_in != deciphered)
4651 } /* eet_data_descriptor_decode_cipher */
4654 eet_data_descriptor_decode(Eet_Data_Descriptor *edd,
4655 const void *data_in,
4658 return eet_data_descriptor_decode_cipher(edd, data_in, NULL, size_in);
4659 } /* eet_data_descriptor_decode */
4662 eet_data_node_decode_cipher(const void *data_in,
4663 const char *cipher_key,
4666 void *deciphered = (void *)data_in;
4668 Eet_Free_Context context;
4669 unsigned int deciphered_len = size_in;
4671 if (cipher_key && data_in)
4672 if (eet_decipher(data_in, size_in, cipher_key,
4673 strlen(cipher_key), &deciphered, &deciphered_len))
4681 eet_free_context_init(&context);
4682 ret = _eet_data_descriptor_decode(&context,
4687 eet_free_context_shutdown(&context);
4689 if (data_in != deciphered)
4693 } /* eet_data_node_decode_cipher */
4696 _eet_data_descriptor_encode(Eet_Dictionary *ed,
4697 Eet_Data_Descriptor *edd,
4698 const void *data_in,
4701 Eet_Data_Stream *ds;
4702 Eet_Data_Chunk *chnk;
4707 if (_eet_data_words_bigendian == -1)
4709 unsigned long int v;
4711 v = htonl(0x12345678);
4712 if (v == 0x12345678)
4713 _eet_data_words_bigendian = 1;
4715 _eet_data_words_bigendian = 0;
4718 ds = eet_data_stream_new();
4719 for (i = 0; i < edd->elements.num; i++)
4721 Eet_Data_Element *ede;
4723 ede = &(edd->elements.set[i]);
4724 eet_group_codec[ede->group_type - 100].put(
4732 chnk = eet_data_chunk_new(ds->data,
4739 eet_data_stream_free(ds);
4741 ds = eet_data_stream_new();
4742 eet_data_chunk_put(ed, chnk, ds);
4748 eet_data_stream_free(ds);
4752 eet_data_chunk_free(chnk);
4755 } /* _eet_data_descriptor_encode */
4758 eet_data_node_write_cipher(Eet_File *ef,
4760 const char *cipher_key,
4769 ed = eet_dictionary_get(ef);
4771 data_enc = _eet_data_dump_encode(EET_G_UNKNOWN, ed, node, &size);
4775 val = eet_write_cipher(ef, name, data_enc, size, compress, cipher_key);
4778 } /* eet_data_node_write_cipher */
4781 eet_data_node_encode_cipher(Eet_Node *node,
4782 const char *cipher_key,
4786 void *ciphered = NULL;
4787 unsigned int ciphered_len = 0;
4790 ret = _eet_data_dump_encode(EET_G_UNKNOWN, NULL, node, &size);
4791 if (cipher_key && ret)
4793 if (eet_cipher(ret, size, cipher_key,
4794 strlen(cipher_key), &ciphered, &ciphered_len))
4807 size = (int)ciphered_len;
4815 } /* eet_data_node_encode_cipher */
4818 eet_data_descriptor_encode_cipher(Eet_Data_Descriptor *edd,
4819 const void *data_in,
4820 const char *cipher_key,
4824 void *ciphered = NULL;
4825 unsigned int ciphered_len = 0;
4828 ret = _eet_data_descriptor_encode(NULL, edd, data_in, &size);
4829 if (cipher_key && ret)
4831 if (eet_cipher(ret, size, cipher_key,
4832 strlen(cipher_key), &ciphered, &ciphered_len))
4845 size = ciphered_len;
4853 } /* eet_data_descriptor_encode_cipher */
4856 eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
4857 const void *data_in,
4860 return eet_data_descriptor_encode_cipher(edd, data_in, NULL, size_ret);
4861 } /* eet_data_descriptor_encode */