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 # define FMT_CHAR "%c"
26 # define FMT_UCHAR "%c"
27 # define FMT_LONG_LONG "%I64i"
28 # define FMT_ULONG_LONG "%I64u"
30 # define FMT_CHAR "%hhi"
31 # define FMT_UCHAR "%hhu"
32 # define FMT_LONG_LONG "%lli"
33 # define FMT_ULONG_LONG "%llu"
37 * routines for doing data -> struct and struct -> data conversion
57 * multiple entries ordered as...
59 * fixed size array [ of basic types ]
60 * variable size array [ of basic types ]
61 * linked list [ of basic types ]
62 * hash table [ of basic types ]
64 * need to provide builder/accessor funcs for:
76 typedef struct _Eet_Data_Element Eet_Data_Element;
77 typedef struct _Eet_Data_Basic_Type_Codec Eet_Data_Basic_Type_Codec;
78 typedef struct _Eet_Data_Group_Type_Codec Eet_Data_Group_Type_Codec;
79 typedef struct _Eet_Data_Chunk Eet_Data_Chunk;
80 typedef struct _Eet_Data_Stream Eet_Data_Stream;
81 typedef struct _Eet_Data_Descriptor_Hash Eet_Data_Descriptor_Hash;
82 typedef struct _Eet_Data_Encode_Hash_Info Eet_Data_Encode_Hash_Info;
83 typedef struct _Eet_Free Eet_Free;
84 typedef struct _Eet_Free_Context Eet_Free_Context;
85 typedef struct _Eet_Variant_Unknow Eet_Variant_Unknow;
90 * Eet_Data_Basic_Type_Codec (Coder, Decoder)
91 * Eet_Data_Group_Type_Codec (Coder, Decoder)
93 struct _Eet_Data_Basic_Type_Codec
97 int (*get)(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
98 void * (*put)(Eet_Dictionary *ed, const void *src, int *size_ret);
101 struct _Eet_Data_Group_Type_Codec
103 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);
104 void (*put)(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in);
107 struct _Eet_Data_Chunk
115 unsigned char group_type;
118 struct _Eet_Data_Stream
125 struct _Eet_Data_Descriptor_Hash
127 Eet_Data_Element *element;
128 Eet_Data_Descriptor_Hash *next;
131 struct _Eet_Data_Descriptor
134 const Eet_Dictionary *ed;
138 void * (*mem_alloc)(size_t size);
139 void (*mem_free)(void *mem);
140 char * (*str_alloc)(const char *str);
141 char * (*str_direct_alloc)(const char *str);
142 void (*str_free)(const char *str);
143 void (*str_direct_free)(const char *str);
144 void * (*list_next)(void *l);
145 void * (*list_append)(void *l, void *d);
146 void * (*list_data)(void *l);
147 void * (*list_free)(void *l);
148 void (*hash_foreach)(void *h, int (*func)(void *h, const char *k, void *dt, void *fdt), void *fdt);
149 void * (*hash_add)(void *h, const char *k, void *d);
150 void (*hash_free)(void *h);
151 const char *(*type_get)(const void *data, Eina_Bool *unknow);
152 Eina_Bool (*type_set)(const char *type, void *data, Eina_Bool unknow);
153 void * (*array_alloc)(size_t size);
154 void (*array_free)(void *mem);
159 Eet_Data_Element *set;
163 Eet_Data_Descriptor_Hash *buckets;
167 Eina_Bool unified_type : 1;
172 struct _Eet_Data_Element
175 const char *counter_name;
176 const char *directory_name_ptr;
177 Eet_Data_Descriptor *subtype;
178 int offset; /* offset in bytes from the base element */
179 int count; /* number of elements for a fixed array */
180 int counter_offset; /* for a variable array we need the offset of the count variable */
181 unsigned char type; /* EET_T_XXX */
182 unsigned char group_type; /* EET_G_XXX */
185 struct _Eet_Data_Encode_Hash_Info
188 Eet_Data_Element *ede;
192 #define EET_FREE_COUNT 256
196 Eina_Array list[EET_FREE_COUNT];
199 struct _Eet_Free_Context
202 Eet_Free freelist_array;
203 Eet_Free freelist_list;
204 Eet_Free freelist_hash;
205 Eet_Free freelist_str;
206 Eet_Free freelist_direct_str;
209 struct _Eet_Variant_Unknow
219 static void eet_free_context_init(Eet_Free_Context *context);
220 static void eet_free_context_shutdown(Eet_Free_Context *context);
222 static int eet_data_get_char(const Eet_Dictionary *ed,
226 static void * eet_data_put_char(Eet_Dictionary *ed,
229 static int eet_data_get_short(const Eet_Dictionary *ed,
233 static void * eet_data_put_short(Eet_Dictionary *ed,
236 static inline int eet_data_get_int(const Eet_Dictionary *ed,
240 static void * eet_data_put_int(Eet_Dictionary *ed,
243 static int eet_data_get_long_long(const Eet_Dictionary *ed,
247 static void * eet_data_put_long_long(Eet_Dictionary *ed,
250 static int eet_data_get_float(const Eet_Dictionary *ed,
254 static void * eet_data_put_float(Eet_Dictionary *ed,
257 static int eet_data_get_double(const Eet_Dictionary *ed,
261 static void * eet_data_put_double(Eet_Dictionary *ed,
264 static int eet_data_get_f32p32(const Eet_Dictionary *ed,
268 static void * eet_data_put_f32p32(Eet_Dictionary *ed,
271 static int eet_data_get_f16p16(const Eet_Dictionary *ed,
275 static void * eet_data_put_f16p16(Eet_Dictionary *ed,
278 static int eet_data_get_f8p24(const Eet_Dictionary *ed,
282 static void * eet_data_put_f8p24(Eet_Dictionary *ed,
285 static inline int eet_data_get_string(const Eet_Dictionary *ed,
289 static void * eet_data_put_string(Eet_Dictionary *ed,
292 static int eet_data_get_istring(const Eet_Dictionary *ed,
296 static void * eet_data_put_istring(Eet_Dictionary *ed,
299 static int eet_data_get_null(const Eet_Dictionary *ed,
303 static void * eet_data_put_null(Eet_Dictionary *ed,
307 static int eet_data_get_type(const Eet_Dictionary *ed,
312 static void * eet_data_put_type(Eet_Dictionary *ed,
317 static Eet_Node * eet_data_node_simple_type(int type,
321 static int eet_data_get_unknown(Eet_Free_Context *context,
322 const Eet_Dictionary *ed,
323 Eet_Data_Descriptor *edd,
324 Eet_Data_Element *ede,
325 Eet_Data_Chunk *echnk,
331 static void eet_data_put_unknown(Eet_Dictionary *ed,
332 Eet_Data_Descriptor *edd,
333 Eet_Data_Element *ede,
336 static void eet_data_put_array(Eet_Dictionary *ed,
337 Eet_Data_Descriptor *edd,
338 Eet_Data_Element *ede,
341 static int eet_data_get_array(Eet_Free_Context *context,
342 const Eet_Dictionary *ed,
343 Eet_Data_Descriptor *edd,
344 Eet_Data_Element *ede,
345 Eet_Data_Chunk *echnk,
351 static int eet_data_get_list(Eet_Free_Context *context,
352 const Eet_Dictionary *ed,
353 Eet_Data_Descriptor *edd,
354 Eet_Data_Element *ede,
355 Eet_Data_Chunk *echnk,
361 static void eet_data_put_list(Eet_Dictionary *ed,
362 Eet_Data_Descriptor *edd,
363 Eet_Data_Element *ede,
366 static void eet_data_put_hash(Eet_Dictionary *ed,
367 Eet_Data_Descriptor *edd,
368 Eet_Data_Element *ede,
371 static int eet_data_get_hash(Eet_Free_Context *context,
372 const Eet_Dictionary *ed,
373 Eet_Data_Descriptor *edd,
374 Eet_Data_Element *ede,
375 Eet_Data_Chunk *echnk,
381 static void eet_data_put_union(Eet_Dictionary *ed,
382 Eet_Data_Descriptor *edd,
383 Eet_Data_Element *ede,
386 static int eet_data_get_union(Eet_Free_Context *context,
387 const Eet_Dictionary *ed,
388 Eet_Data_Descriptor *edd,
389 Eet_Data_Element *ede,
390 Eet_Data_Chunk *echnk,
396 static void eet_data_put_variant(Eet_Dictionary *ed,
397 Eet_Data_Descriptor *edd,
398 Eet_Data_Element *ede,
401 static int eet_data_get_variant(Eet_Free_Context *context,
402 const Eet_Dictionary *ed,
403 Eet_Data_Descriptor *edd,
404 Eet_Data_Element *ede,
405 Eet_Data_Chunk *echnk,
412 static void eet_data_chunk_get(const Eet_Dictionary *ed,
413 Eet_Data_Chunk *chnk,
416 static Eet_Data_Chunk * eet_data_chunk_new(void *data,
421 static void eet_data_chunk_free(Eet_Data_Chunk *chnk);
423 static Eet_Data_Stream * eet_data_stream_new(void);
424 static void eet_data_stream_write(Eet_Data_Stream *ds,
427 static void eet_data_stream_free(Eet_Data_Stream *ds);
429 static void eet_data_chunk_put(Eet_Dictionary *ed,
430 Eet_Data_Chunk *chnk,
431 Eet_Data_Stream *ds);
433 static int eet_data_descriptor_encode_hash_cb(void *hash,
437 static void * _eet_data_descriptor_encode(Eet_Dictionary *ed,
438 Eet_Data_Descriptor *edd,
441 static void * _eet_data_descriptor_decode(Eet_Free_Context *context,
442 const Eet_Dictionary *ed,
443 Eet_Data_Descriptor *edd,
451 static const Eet_Data_Basic_Type_Codec eet_basic_codec[] =
453 {sizeof(char), "char", eet_data_get_char, eet_data_put_char },
454 {sizeof(short), "short", eet_data_get_short, eet_data_put_short },
455 {sizeof(int), "int", eet_data_get_int, eet_data_put_int },
456 {sizeof(long long), "long_long", eet_data_get_long_long, eet_data_put_long_long},
457 {sizeof(float), "float", eet_data_get_float, eet_data_put_float },
458 {sizeof(double), "double", eet_data_get_double, eet_data_put_double },
459 {sizeof(char), "uchar", eet_data_get_char, eet_data_put_char },
460 {sizeof(short), "ushort", eet_data_get_short, eet_data_put_short },
461 {sizeof(int), "uint", eet_data_get_int, eet_data_put_int },
462 {sizeof(long long), "ulong_long", eet_data_get_long_long, eet_data_put_long_long},
463 {sizeof(char *), "string", eet_data_get_string, eet_data_put_string },
464 {sizeof(char *), "inlined", eet_data_get_istring, eet_data_put_istring },
465 {sizeof(void *), "NULL", eet_data_get_null, eet_data_put_null },
466 {sizeof(Eina_F32p32),"f32p32", eet_data_get_f32p32, eet_data_put_f32p32 },
467 {sizeof(Eina_F16p16),"f16p16", eet_data_get_f16p16, eet_data_put_f16p16 },
468 {sizeof(Eina_F8p24),"f8p24", eet_data_get_f8p24, eet_data_put_f8p24 }
471 static const Eet_Data_Group_Type_Codec eet_group_codec[] =
473 { eet_data_get_unknown, eet_data_put_unknown },
474 { eet_data_get_array, eet_data_put_array },
475 { eet_data_get_array, eet_data_put_array },
476 { eet_data_get_list, eet_data_put_list },
477 { eet_data_get_hash, eet_data_put_hash },
478 { eet_data_get_union, eet_data_put_union },
479 { eet_data_get_variant, eet_data_put_variant }
482 static int _eet_data_words_bigendian = -1;
486 #define SWAP64(x) (x) =\
487 ((((unsigned long long)(x) & 0x00000000000000ffULL) << 56) |\
488 (((unsigned long long)(x) & 0x000000000000ff00ULL) << 40) |\
489 (((unsigned long long)(x) & 0x0000000000ff0000ULL) << 24) |\
490 (((unsigned long long)(x) & 0x00000000ff000000ULL) << 8) |\
491 (((unsigned long long)(x) & 0x000000ff00000000ULL) >> 8) |\
492 (((unsigned long long)(x) & 0x0000ff0000000000ULL) >> 24) |\
493 (((unsigned long long)(x) & 0x00ff000000000000ULL) >> 40) |\
494 (((unsigned long long)(x) & 0xff00000000000000ULL) >> 56))
495 #define SWAP32(x) (x) =\
496 ((((int)(x) & 0x000000ff) << 24) |\
497 (((int)(x) & 0x0000ff00) << 8) |\
498 (((int)(x) & 0x00ff0000) >> 8) |\
499 (((int)(x) & 0xff000000) >> 24))
500 #define SWAP16(x) (x) =\
501 ((((short)(x) & 0x00ff) << 8) |\
502 (((short)(x) & 0xff00) >> 8))
506 #endif /* ifdef CONV8 */
509 #endif /* ifdef CONV16 */
512 #endif /* ifdef CONV32 */
515 #endif /* ifdef CONV64 */
518 #define CONV16(x) {if (_eet_data_words_bigendian) {SWAP16(x); }}
519 #define CONV32(x) {if (_eet_data_words_bigendian) {SWAP32(x); }}
520 #define CONV64(x) {if (_eet_data_words_bigendian) {SWAP64(x); }}
522 #define IS_SIMPLE_TYPE(Type) (Type > EET_T_UNKNOW && Type < EET_T_LAST)
523 #define IS_POINTER_TYPE(Type) (Type >= EET_T_STRING && Type <= EET_T_NULL)
525 #define POINTER_TYPE_DECODE(Context,\
537 ___r = eet_data_get_unknown(Context,\
541 Type, EET_G_UNKNOWN,\
543 if (!___r) { goto Label; }\
546 #define STRUCT_TYPE_DECODE(Data_Ret, Context, Ed, Ede, Data, Size, SubSize, Label) \
548 Data_Ret = _eet_data_descriptor_decode(Context,\
553 SubSize > 0 ? Data_Ret : NULL,\
555 if (!Data_Ret) { goto Label; }\
558 #define EET_I_STRING 1 << 4
559 #define EET_I_INLINED_STRING 2 << 4
560 #define EET_I_NULL 3 << 4
562 #define EET_MAGIC_VARIANT 0xF1234BC
567 eet_data_get_char(const Eet_Dictionary *ed __UNUSED__,
574 if (((char *)src + sizeof(char)) > (char *)src_end)
582 } /* eet_data_get_char */
585 eet_data_put_char(Eet_Dictionary *ed __UNUSED__,
591 d = (char *)malloc(sizeof(char));
598 *size_ret = sizeof(char);
600 } /* eet_data_put_char */
604 eet_data_get_short(const Eet_Dictionary *ed __UNUSED__,
611 if (((char *)src + sizeof(short)) > (char *)src_end)
614 memcpy(dst, src, sizeof(short));
617 return sizeof(short);
618 } /* eet_data_get_short */
621 eet_data_put_short(Eet_Dictionary *ed __UNUSED__,
627 d = (short *)malloc(sizeof(short));
634 *size_ret = sizeof(short);
636 } /* eet_data_put_short */
640 eet_data_get_int(const Eet_Dictionary *ed __UNUSED__,
647 if (((char *)src + sizeof(int)) > (char *)src_end)
650 memcpy(dst, src, sizeof(int));
654 } /* eet_data_get_int */
657 eet_data_put_int(Eet_Dictionary *ed __UNUSED__,
663 d = (int *)malloc(sizeof(int));
670 *size_ret = sizeof(int);
672 } /* eet_data_put_int */
676 eet_data_get_long_long(const Eet_Dictionary *ed __UNUSED__,
681 unsigned long long *d;
683 if (((char *)src + sizeof(unsigned long long)) > (char *)src_end)
686 memcpy(dst, src, sizeof(unsigned long long));
687 d = (unsigned long long *)dst;
689 return sizeof(unsigned long long);
690 } /* eet_data_get_long_long */
693 eet_data_put_long_long(Eet_Dictionary *ed __UNUSED__,
697 unsigned long long *s, *d;
699 d = (unsigned long long *)malloc(sizeof(unsigned long long));
703 s = (unsigned long long *)src;
706 *size_ret = sizeof(unsigned long long);
708 } /* eet_data_put_long_long */
712 eet_data_get_string_hash(const Eet_Dictionary *ed,
720 if (eet_data_get_int(ed, src, src_end, &idx) < 0)
723 return eet_dictionary_string_get_hash(ed, idx);
727 } /* eet_data_get_string_hash */
730 eet_data_get_string(const Eet_Dictionary *ed,
744 if (eet_data_get_int(ed, src, src_end, &idx) < 0)
747 str = eet_dictionary_string_get_char(ed, idx);
752 return eet_dictionary_string_get_size(ed, idx);
763 return strlen(s) + 1;
764 } /* eet_data_get_string */
767 eet_data_put_string(Eet_Dictionary *ed,
779 str = *((const char **)src);
783 idx = eet_dictionary_string_add(ed, str);
787 return eet_data_put_int(ed, &idx, size_ret);
790 s = (char *)(*((char **)src));
799 memcpy(d, s, len + 1);
802 } /* eet_data_put_string */
804 /* ALWAYS INLINED STRING TYPE */
806 eet_data_get_istring(const Eet_Dictionary *ed __UNUSED__,
811 return eet_data_get_string(NULL, src, src_end, dst);
812 } /* eet_data_get_istring */
815 eet_data_put_istring(Eet_Dictionary *ed __UNUSED__,
819 return eet_data_put_string(NULL, src, size_ret);
820 } /* eet_data_put_istring */
822 /* ALWAYS NULL TYPE */
824 eet_data_get_null(const Eet_Dictionary *ed __UNUSED__,
825 const void *src __UNUSED__,
826 const void *src_end __UNUSED__,
835 } /* eet_data_get_null */
838 eet_data_put_null(Eet_Dictionary *ed __UNUSED__,
839 const void *src __UNUSED__,
844 } /* eet_data_put_null */
847 * Fast lookups of simple doubles/floats.
849 * These aren't properly a cache because they don't store pre-calculated
850 * values, but have a so simple math that is almost as fast.
853 _eet_data_float_cache_get(const char *s,
857 /* fast handle of simple case 0xMp+E*/
858 if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
860 int mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
861 int exponent = (s[5] - '0');
864 *d = (float)(mantisse << exponent);
866 *d = (float)mantisse / (float)(1 << exponent);
872 } /* _eet_data_float_cache_get */
875 _eet_data_double_cache_get(const char *s,
879 /* fast handle of simple case 0xMp+E*/
880 if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
882 int mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
883 int exponent = (s[5] - '0');
886 *d = (double)(mantisse << exponent);
888 *d = (double)mantisse / (double)(1 << exponent);
894 } /* _eet_data_double_cache_get */
898 eet_data_get_float(const Eet_Dictionary *ed,
914 s = (const char *)src;
917 while ((p < (const char *)src_end) && (*p != 0)) {len++; p++; }
919 if (_eet_data_float_cache_get(s, len, d) != 0)
922 if (eina_convert_atod(s, len, &mantisse, &exponent) == EINA_FALSE)
925 *d = (float)ldexp((double)mantisse, exponent);
930 if (eet_data_get_int(ed, src, src_end, &idx) < 0)
933 if (!eet_dictionary_string_get_float(ed, idx, d))
937 } /* eet_data_get_float */
940 eet_data_put_float(Eet_Dictionary *ed,
947 eina_convert_dtoa((double)(*(float *)src), buf);
959 memcpy(d, buf, len + 1);
964 idx = eet_dictionary_string_add(ed, buf);
968 return eet_data_put_int(ed, &idx, size_ret);
969 } /* eet_data_put_float */
973 eet_data_get_double(const Eet_Dictionary *ed,
986 long long mantisse = 0;
990 s = (const char *)src;
993 while ((p < (const char *)src_end) && (*p != 0)) {len++; p++; }
995 if (_eet_data_double_cache_get(s, len, d) != 0)
998 if (eina_convert_atod(s, len, &mantisse, &exponent) == EINA_FALSE)
1001 *d = ldexp((double)mantisse, exponent);
1006 if (eet_data_get_int(ed, src, src_end, &idx) < 0)
1009 if (!eet_dictionary_string_get_double(ed, idx, d))
1013 } /* eet_data_get_double */
1016 eet_data_put_double(Eet_Dictionary *ed,
1023 eina_convert_dtoa((double)(*(double *)src), buf);
1031 d = malloc(len + 1);
1035 memcpy(d, buf, len + 1);
1036 *size_ret = len + 1;
1041 idx = eet_dictionary_string_add(ed, buf);
1045 return eet_data_put_int(ed, &idx, size_ret);
1046 } /* eet_data_put_double */
1049 eet_data_get_f32p32(const Eet_Dictionary *ed,
1051 const void *src_end,
1057 fp = (Eina_F32p32 *)dst;
1064 s = (const char *)src;
1067 while ((p < (const char *)src_end) && (*p != 0)) { len++; p++; }
1069 if (!(eina_convert_atofp(s, len, fp)))
1075 if (eet_data_get_int(ed, src, src_end, &idx) < 0)
1078 if (!eet_dictionary_string_get_fp(ed, idx, fp))
1082 } /* eet_data_get_f32p32 */
1085 eet_data_put_f32p32(Eet_Dictionary *ed,
1092 eina_convert_fptoa((Eina_F32p32)(*(Eina_F32p32 *)src), buf);
1100 d = malloc(len + 1);
1104 memcpy(d, buf, len + 1);
1105 *size_ret = len + 1;
1110 idx = eet_dictionary_string_add(ed, buf);
1114 return eet_data_put_int(ed, &idx, size_ret);
1115 } /* eet_data_put_f32p32 */
1118 eet_data_get_f16p16(const Eet_Dictionary *ed,
1120 const void *src_end,
1126 fp = (Eina_F16p16 *)dst;
1128 if (eet_data_get_f32p32(ed, src, src_end, &tmp) < 0)
1131 *fp = eina_f32p32_to_f16p16(tmp);
1133 } /* eet_data_get_f16p16 */
1136 eet_data_put_f16p16(Eet_Dictionary *ed,
1142 tmp = eina_f16p16_to_f32p32((Eina_F16p16)(*(Eina_F16p16 *)src));
1143 return eet_data_put_f32p32(ed, &tmp, size_ret);
1144 } /* eet_data_put_f16p16 */
1147 eet_data_get_f8p24(const Eet_Dictionary *ed,
1149 const void *src_end,
1155 fp = (Eina_F8p24 *)dst;
1157 if (eet_data_get_f32p32(ed, src, src_end, &tmp) < 0)
1160 *fp = eina_f32p32_to_f8p24(tmp);
1162 } /* eet_data_get_f8p24 */
1165 eet_data_put_f8p24(Eet_Dictionary *ed,
1171 tmp = eina_f8p24_to_f32p32((Eina_F8p24)(*(Eina_F8p24 *)src));
1172 return eet_data_put_f32p32(ed, &tmp, size_ret);
1173 } /* eet_data_put_f8p24 */
1176 eet_data_get_type(const Eet_Dictionary *ed,
1179 const void *src_end,
1184 ret = eet_basic_codec[type - 1].get(ed, src, src_end, dest);
1186 } /* eet_data_get_type */
1188 static inline void *
1189 eet_data_put_type(Eet_Dictionary *ed,
1196 ret = eet_basic_codec[type - 1].put(ed, src, size_ret);
1198 } /* eet_data_put_type */
1200 static inline Eina_Bool
1201 eet_data_type_match(int type1,
1207 /* Note: All floating point type are equivalent and could be read
1208 without problem by any other floating point getter. */
1235 } /* eet_data_type_match */
1239 * char[4] = "CHnK"; // untyped data ... or
1240 * char[4] = "CHKx"; // typed data - x == type
1242 * int = chunk size (including magic string);
1243 * char[] = chunk magic/name string (0 byte terminated);
1244 * ... sub-chunks (a chunk can contain chuncks recusrively) ...
1246 * ... payload data ...
1251 eet_data_chunk_get(const Eet_Dictionary *ed,
1252 Eet_Data_Chunk *chnk,
1271 if ((s[0] != 'C') || (s[1] != 'H') || (s[2] != 'K'))
1274 chnk->type = (unsigned char)(s[3]);
1275 if (chnk->type >= EET_I_LIMIT)
1278 ((chnk->type - EET_I_LIMIT) & 0xF) + EET_G_UNKNOWN;
1279 switch ((chnk->type - EET_I_LIMIT) & 0xF0)
1281 #define EET_UNMATCH_TYPE(Type)\
1282 case EET_I_ ## Type: chnk->type = EET_T_ ## Type; break;
1284 EET_UNMATCH_TYPE(STRING);
1285 EET_UNMATCH_TYPE(INLINED_STRING);
1286 EET_UNMATCH_TYPE(NULL);
1292 else if (chnk->type > EET_T_LAST)
1294 chnk->group_type = chnk->type;
1295 chnk->type = EET_T_UNKNOW;
1298 chnk->group_type = EET_G_UNKNOWN;
1299 if ((chnk->type >= EET_T_LAST) ||
1300 (chnk->group_type >=
1304 chnk->group_type = 0;
1307 else if ((s[0] != 'C') || (s[1] != 'H') || (s[2] != 'n') || (s[3] != 'K'))
1310 ret1 = eet_data_get_type(ed, EET_T_INT, (s + 4), (s + size), &(chnk->size));
1315 if ((chnk->size < 0) || ((chnk->size + 8) > size))
1318 ret2 = eet_data_get_type(ed, EET_T_STRING, (s + 8), (s + size), &(chnk->name));
1326 chnk->hash = eet_data_get_string_hash(ed, (s + 8), (s + size));
1330 chnk->data = (char *)src + 4 + ret1 + sizeof(int);
1331 chnk->size -= sizeof(int);
1335 chnk->data = (char *)src + 4 + ret1 + chnk->len;
1336 chnk->size -= chnk->len;
1340 } /* eet_data_chunk_get */
1342 static inline Eet_Data_Chunk *
1343 eet_data_chunk_new(void *data,
1349 Eet_Data_Chunk *chnk;
1354 chnk = calloc(1, sizeof(Eet_Data_Chunk));
1358 /* Note: Another security, so older eet library could read file
1359 saved with fixed point value. */
1360 if (type == EET_T_F32P32
1361 || type == EET_T_F16P16
1362 || type == EET_T_F8P24)
1363 type = EET_T_DOUBLE;
1365 chnk->name = strdup(name);
1366 chnk->len = strlen(name) + 1;
1370 chnk->group_type = group_type;
1372 } /* eet_data_chunk_new */
1375 eet_data_chunk_free(Eet_Data_Chunk *chnk)
1381 } /* eet_data_chunk_free */
1383 static inline Eet_Data_Stream *
1384 eet_data_stream_new(void)
1386 Eet_Data_Stream *ds;
1388 ds = calloc(1, sizeof(Eet_Data_Stream));
1393 } /* eet_data_stream_new */
1396 eet_data_stream_free(Eet_Data_Stream *ds)
1402 } /* eet_data_stream_free */
1405 eet_data_stream_flush(Eet_Data_Stream *ds)
1408 } /* eet_data_stream_flush */
1411 eet_data_stream_write(Eet_Data_Stream *ds,
1417 if ((ds->pos + size) > ds->size)
1419 ds->data = realloc(ds->data, ds->size + size + 512);
1427 ds->size = ds->size + size + 512;
1431 memcpy(p + ds->pos, data, size);
1433 } /* eet_data_stream_write */
1436 eet_data_chunk_put(Eet_Dictionary *ed,
1437 Eet_Data_Chunk *chnk,
1438 Eet_Data_Stream *ds)
1445 unsigned char buf[4] = "CHK";
1447 /* disable this check - it will allow empty chunks to be written. this is
1448 * right for corner-cases when y have a struct with empty fields (empty
1449 * strings or empty list ptrs etc.) */
1450 /* if (!chnk->data && chnk->type != EET_T_NULL) return; */
1453 /* eet_data_stream_write(ds, "CHnK", 4);*/
1454 if (chnk->type != EET_T_UNKNOW)
1456 if (chnk->group_type != EET_G_UNKNOWN)
1458 int type = EET_I_LIMIT + chnk->group_type - EET_G_UNKNOWN;
1462 /* Only make sense with pointer type. */
1463 #define EET_MATCH_TYPE(Type)\
1464 case EET_T_ ## Type: type += EET_I_ ## Type; break;
1466 EET_MATCH_TYPE(STRING);
1467 EET_MATCH_TYPE(INLINED_STRING);
1468 EET_MATCH_TYPE(NULL);
1477 buf[3] = chnk->type;
1480 buf[3] = chnk->group_type;
1482 string = eet_data_put_string(ed, &chnk->name, &string_ret);
1486 /* size of chunk payload data + name */
1487 s = chnk->size + string_ret;
1488 size = eet_data_put_int(ed, &s, &size_ret);
1490 /* FIXME: If something goes wrong the resulting file will be corrupted. */
1494 eet_data_stream_write(ds, buf, 4);
1496 /* write chunk length */
1497 eet_data_stream_write(ds, size, size_ret);
1499 /* write chunk name */
1500 eet_data_stream_write(ds, string, string_ret);
1504 eet_data_stream_write(ds, chnk->data, chnk->size);
1509 } /* eet_data_chunk_put */
1514 _eet_descriptor_hash_new(Eet_Data_Descriptor *edd)
1518 edd->elements.hash.size = 1 << 6;
1519 edd->elements.hash.buckets = calloc(
1521 sizeof(Eet_Data_Descriptor_Hash) *
1522 edd->elements.hash.size);
1523 for (i = 0; i < edd->elements.num; i++)
1525 Eet_Data_Element *ede;
1528 ede = &(edd->elements.set[i]);
1529 hash = _eet_hash_gen((char *)ede->name, 6);
1530 if (!edd->elements.hash.buckets[hash].element)
1531 edd->elements.hash.buckets[hash].element = ede;
1534 Eet_Data_Descriptor_Hash *bucket;
1536 bucket = calloc(1, sizeof(Eet_Data_Descriptor_Hash));
1537 bucket->element = ede;
1538 bucket->next = edd->elements.hash.buckets[hash].next;
1539 edd->elements.hash.buckets[hash].next = bucket;
1542 } /* _eet_descriptor_hash_new */
1545 _eet_descriptor_hash_free(Eet_Data_Descriptor *edd)
1549 for (i = 0; i < edd->elements.hash.size; i++)
1551 Eet_Data_Descriptor_Hash *bucket, *pbucket;
1553 bucket = edd->elements.hash.buckets[i].next;
1557 bucket = bucket->next;
1561 if (edd->elements.hash.buckets)
1562 free(edd->elements.hash.buckets);
1563 } /* _eet_descriptor_hash_free */
1565 static Eet_Data_Element *
1566 _eet_descriptor_hash_find(Eet_Data_Descriptor *edd,
1570 Eet_Data_Descriptor_Hash *bucket;
1573 hash = _eet_hash_gen(name, 6);
1577 if (!edd->elements.hash.buckets[hash].element)
1579 When we use the dictionary as a source for chunk name, we will always
1580 have the same pointer in name. It's a good idea to just compare pointer
1581 instead of running strcmp on both string.
1584 if (edd->elements.hash.buckets[hash].element->directory_name_ptr == name)
1585 return edd->elements.hash.buckets[hash].element;
1587 if (!strcmp(edd->elements.hash.buckets[hash].element->name, name))
1589 edd->elements.hash.buckets[hash].element->directory_name_ptr = name;
1590 return edd->elements.hash.buckets[hash].element;
1593 bucket = edd->elements.hash.buckets[hash].next;
1596 if (bucket->element->directory_name_ptr == name)
1597 return bucket->element;
1599 if (!strcmp(bucket->element->name, name))
1601 bucket->element->directory_name_ptr = name;
1602 return bucket->element;
1605 bucket = bucket->next;
1608 } /* _eet_descriptor_hash_find */
1611 _eet_mem_alloc(size_t size)
1613 return calloc(1, size);
1614 } /* _eet_mem_alloc */
1617 _eet_mem_free(void *mem)
1620 } /* _eet_mem_free */
1623 _eet_str_alloc(const char *str)
1626 } /* _eet_str_alloc */
1629 _eet_str_free(const char *str)
1632 } /* _eet_str_free */
1635 _eet_eina_hash_add_alloc(Eina_Hash *hash,
1640 hash = eina_hash_string_small_new(NULL);
1645 eina_hash_add(hash, key, data);
1647 } /* _eet_eina_hash_add_alloc */
1650 _eet_eina_hash_direct_add_alloc(Eina_Hash *hash,
1655 hash = eina_hash_string_small_new(NULL);
1660 eina_hash_direct_add(hash, key, data);
1662 } /* _eet_eina_hash_direct_add_alloc */
1665 _eet_str_direct_alloc(const char *str)
1668 } /* _eet_str_direct_alloc */
1671 _eet_str_direct_free(const char *str __UNUSED__)
1673 } /* _eet_str_direct_free */
1676 _eet_eina_hash_foreach(void *hash,
1677 Eina_Hash_Foreach cb,
1681 eina_hash_foreach(hash, cb, fdata);
1682 } /* _eet_eina_hash_foreach */
1685 _eet_eina_hash_free(void *hash)
1688 eina_hash_free(hash);
1689 } /* _eet_eina_hash_free */
1693 eet_eina_stream_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc,
1694 /* When we change the structure content in the future, we need to handle old structure type too */
1695 unsigned int eddc_size,
1699 if (!eddc || !name || eddc_size != sizeof (Eet_Data_Descriptor_Class))
1704 eddc->version = EET_DATA_DESCRIPTOR_CLASS_VERSION;
1706 eddc->func.mem_alloc = _eet_mem_alloc;
1707 eddc->func.mem_free = _eet_mem_free;
1708 eddc->func.str_alloc = (char *(*)(const char *))eina_stringshare_add;
1709 eddc->func.str_free = eina_stringshare_del;
1710 eddc->func.list_next = (void *(*)(void *))eina_list_next;
1711 eddc->func.list_append = (void *(*)(void *, void *))eina_list_append;
1712 eddc->func.list_data = (void *(*)(void *))eina_list_data_get;
1713 eddc->func.list_free = (void *(*)(void *))eina_list_free;
1714 eddc->func.hash_foreach = (void (*)(void *, int (*)(void *, const char *, void *, void *), void *))_eet_eina_hash_foreach;
1715 eddc->func.hash_add = (void * (*)(void *, const char *, void *))_eet_eina_hash_add_alloc;
1716 eddc->func.hash_free = (void (*)(void *))_eet_eina_hash_free;
1718 /* This will cause an ABI incompatibility */
1719 eddc->func.array_alloc = _eet_mem_alloc;
1720 eddc->func.array_free = _eet_mem_free;
1723 } /* eet_eina_stream_data_descriptor_class_set */
1726 eet_eina_file_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc,
1727 /* When we change the structure content in the future, we need to handle old structure type too */
1728 unsigned int eddc_size,
1732 if (!eet_eina_stream_data_descriptor_class_set(eddc, eddc_size, name, size))
1735 eddc->version = EET_DATA_DESCRIPTOR_CLASS_VERSION;
1737 eddc->func.hash_add = (void * (*)(void *, const char *, void *))_eet_eina_hash_direct_add_alloc;
1738 eddc->func.str_direct_alloc = _eet_str_direct_alloc;
1739 eddc->func.str_direct_free = _eet_str_direct_free;
1742 } /* eet_eina_file_data_descriptor_class_set */
1744 static Eet_Data_Descriptor *
1745 _eet_data_descriptor_new(const Eet_Data_Descriptor_Class *eddc,
1748 Eet_Data_Descriptor *edd;
1753 edd = calloc(1, sizeof (Eet_Data_Descriptor));
1757 edd->name = eddc->name;
1759 edd->size = eddc->size;
1760 edd->func.mem_alloc = _eet_mem_alloc;
1761 edd->func.mem_free = _eet_mem_free;
1762 edd->func.str_alloc = _eet_str_alloc;
1763 edd->func.str_free = _eet_str_free;
1764 if (eddc->func.mem_alloc)
1765 edd->func.mem_alloc = eddc->func.mem_alloc;
1767 if (eddc->func.mem_free)
1768 edd->func.mem_free = eddc->func.mem_free;
1770 if (eddc->func.str_alloc)
1771 edd->func.str_alloc = eddc->func.str_alloc;
1773 if (eddc->func.str_free)
1774 edd->func.str_free = eddc->func.str_free;
1776 edd->func.list_next = eddc->func.list_next;
1777 edd->func.list_append = eddc->func.list_append;
1778 edd->func.list_data = eddc->func.list_data;
1779 edd->func.list_free = eddc->func.list_free;
1780 edd->func.hash_foreach = eddc->func.hash_foreach;
1781 edd->func.hash_add = eddc->func.hash_add;
1782 edd->func.hash_free = eddc->func.hash_free;
1784 if (eddc->version > 1 && version > 1)
1786 edd->func.str_direct_alloc = eddc->func.str_direct_alloc;
1787 edd->func.str_direct_free = eddc->func.str_direct_free;
1790 if (eddc->version > 2)
1792 edd->func.type_get = eddc->func.type_get;
1793 edd->func.type_set = eddc->func.type_set;
1796 if (eddc->version > 3)
1798 edd->func.array_alloc = eddc->func.array_alloc;
1799 edd->func.array_free = eddc->func.array_free;
1803 } /* _eet_data_descriptor_new */
1805 EAPI Eet_Data_Descriptor *
1806 eet_data_descriptor_new(const char *name,
1808 Eet_Descriptor_List_Next_Callback func_list_next,
1809 Eet_Descriptor_List_Append_Callback func_list_append,
1810 Eet_Descriptor_List_Data_Callback func_list_data,
1811 Eet_Descriptor_List_Free_Callback func_list_free,
1812 Eet_Descriptor_Hash_Foreach_Callback func_hash_foreach,
1813 Eet_Descriptor_Hash_Add_Callback func_hash_add,
1814 Eet_Descriptor_Hash_Free_Callback func_hash_free)
1816 Eet_Data_Descriptor_Class eddc;
1821 memset(&eddc, 0, sizeof (Eet_Data_Descriptor_Class));
1827 eddc.func.list_next = func_list_next;
1828 eddc.func.list_append = func_list_append;
1829 eddc.func.list_data = func_list_data;
1830 eddc.func.list_free = func_list_free;
1831 eddc.func.hash_foreach = func_hash_foreach;
1832 eddc.func.hash_add = func_hash_add;
1833 eddc.func.hash_free = func_hash_free;
1835 return _eet_data_descriptor_new(&eddc, 0);
1836 } /* eet_data_descriptor_new */
1838 EAPI Eet_Data_Descriptor *
1839 eet_data_descriptor2_new(const Eet_Data_Descriptor_Class *eddc)
1841 return _eet_data_descriptor_new(eddc, 1);
1842 } /* eet_data_descriptor2_new */
1844 EAPI Eet_Data_Descriptor *
1845 eet_data_descriptor3_new(const Eet_Data_Descriptor_Class *eddc)
1847 return _eet_data_descriptor_new(eddc, 2);
1848 } /* eet_data_descriptor3_new */
1850 EAPI Eet_Data_Descriptor *
1851 eet_data_descriptor_stream_new(const Eet_Data_Descriptor_Class *eddc)
1853 return _eet_data_descriptor_new(eddc, 1);
1854 } /* eet_data_descriptor_stream_new */
1856 EAPI Eet_Data_Descriptor *
1857 eet_data_descriptor_file_new(const Eet_Data_Descriptor_Class *eddc)
1859 return _eet_data_descriptor_new(eddc, 2);
1860 } /* eet_data_descriptor_file_new */
1863 eet_data_descriptor_free(Eet_Data_Descriptor *edd)
1868 _eet_descriptor_hash_free(edd);
1869 if (edd->elements.set)
1870 free(edd->elements.set);
1873 } /* eet_data_descriptor_free */
1876 eet_data_descriptor_element_add(Eet_Data_Descriptor *edd,
1882 /* int counter_offset, */
1883 const char *counter_name /* FIXME: Useless should go on a major release */,
1884 Eet_Data_Descriptor *subtype)
1886 Eet_Data_Element *ede;
1887 Eet_Data_Element *tmp;
1889 /* UNION, VARIANT type would not work with simple type, we need a way to map the type. */
1890 if ((group_type == EET_G_UNION
1891 || group_type == EET_G_VARIANT)
1893 (type != EET_T_UNKNOW
1895 || !subtype->func.type_get
1896 || !subtype->func.type_set))
1899 /* VARIANT type will only work if the map only contains EET_G_*, but not UNION, VARIANT and ARRAY. */
1900 if (group_type == EET_G_VARIANT)
1904 for (i = 0; i < subtype->elements.num; ++i)
1905 if (subtype->elements.set[i].type != EET_T_UNKNOW
1906 && subtype->elements.set[i].group_type > EET_G_VAR_ARRAY
1907 && subtype->elements.set[i].group_type < EET_G_UNION)
1910 subtype->unified_type = EINA_TRUE;
1914 && subtype->unified_type
1915 && (type != EET_T_UNKNOW
1916 || group_type < EET_G_UNION))
1919 /* Sanity check done, let allocate ! */
1920 edd->elements.num++;
1921 tmp = realloc(edd->elements.set, edd->elements.num * sizeof(Eet_Data_Element));
1925 edd->elements.set = tmp;
1926 ede = &(edd->elements.set[edd->elements.num - 1]);
1928 ede->directory_name_ptr = NULL;
1931 * We do a special case when we do list,hash or whatever group of simple type.
1932 * Instead of handling it in encode/decode/dump/undump, we create an
1933 * implicit structure with only the simple type.
1935 if ((group_type > EET_G_UNKNOWN)
1936 && (group_type < EET_G_LAST)
1937 && (((type > EET_T_UNKNOW) && (type < EET_T_STRING))
1938 || ((type > EET_T_NULL) && (type < EET_T_LAST)))
1941 subtype = calloc(1, sizeof (Eet_Data_Descriptor));
1945 subtype->name = "implicit";
1946 subtype->size = eet_basic_codec[type - 1].size;
1947 memcpy(&subtype->func, &edd->func, sizeof(subtype->func));
1949 eet_data_descriptor_element_add(subtype,
1950 eet_basic_codec[type - 1].name,
1957 type = EET_T_UNKNOW;
1961 ede->group_type = group_type;
1962 ede->offset = offset;
1964 /* FIXME: For the time being, VAR_ARRAY, UNION and VARIANT will put the counter_offset in count. */
1965 ede->counter_offset = count;
1966 /* ede->counter_offset = counter_offset; */
1967 ede->counter_name = counter_name;
1969 ede->subtype = subtype;
1970 } /* eet_data_descriptor_element_add */
1973 eet_data_read_cipher(Eet_File *ef,
1974 Eet_Data_Descriptor *edd,
1976 const char *cipher_key)
1978 const Eet_Dictionary *ed = NULL;
1979 const void *data = NULL;
1981 Eet_Free_Context context;
1982 int required_free = 0;
1985 ed = eet_dictionary_get(ef);
1988 data = eet_read_direct(ef, name, &size);
1993 data = eet_read_cipher(ef, name, &size, cipher_key);
1998 eet_free_context_init(&context);
1999 data_dec = _eet_data_descriptor_decode(&context, ed, edd, data, size, NULL, 0);
2000 eet_free_context_shutdown(&context);
2006 } /* eet_data_read_cipher */
2009 eet_data_node_read_cipher(Eet_File *ef,
2011 const char *cipher_key)
2013 const Eet_Dictionary *ed = NULL;
2014 const void *data = NULL;
2016 Eet_Free_Context context;
2017 int required_free = 0;
2020 ed = eet_dictionary_get(ef);
2023 data = eet_read_direct(ef, name, &size);
2028 data = eet_read_cipher(ef, name, &size, cipher_key);
2033 eet_free_context_init(&context);
2034 result = _eet_data_descriptor_decode(&context, ed, NULL, data, size, NULL, 0);
2035 eet_free_context_shutdown(&context);
2041 } /* eet_data_node_read_cipher */
2044 eet_data_read(Eet_File *ef,
2045 Eet_Data_Descriptor *edd,
2048 return eet_data_read_cipher(ef, edd, name, NULL);
2049 } /* eet_data_read */
2052 eet_data_write_cipher(Eet_File *ef,
2053 Eet_Data_Descriptor *edd,
2055 const char *cipher_key,
2064 ed = eet_dictionary_get(ef);
2066 data_enc = _eet_data_descriptor_encode(ed, edd, data, &size);
2070 val = eet_write_cipher(ef, name, data_enc, size, compress, cipher_key);
2073 } /* eet_data_write_cipher */
2076 eet_data_write(Eet_File *ef,
2077 Eet_Data_Descriptor *edd,
2082 return eet_data_write_cipher(ef, edd, name, NULL, data, compress);
2083 } /* eet_data_write */
2086 eet_free_context_init(Eet_Free_Context *context)
2090 memset(context, 0, sizeof (Eet_Free_Context));
2091 for (i = 0; i < EET_FREE_COUNT; ++i)
2093 eina_array_step_set(&context->freelist.list[i],
2094 sizeof (context->freelist.list[i]),
2096 eina_array_step_set(&context->freelist_array.list[i],
2097 sizeof (context->freelist.list[i]),
2099 eina_array_step_set(&context->freelist_list.list[i],
2100 sizeof (context->freelist.list[i]),
2102 eina_array_step_set(&context->freelist_hash.list[i],
2103 sizeof (context->freelist.list[i]),
2105 eina_array_step_set(&context->freelist_str.list[i],
2106 sizeof (context->freelist.list[i]),
2108 eina_array_step_set(&context->freelist_direct_str.list[i],
2109 sizeof (context->freelist.list[i]),
2115 eet_free_context_shutdown(Eet_Free_Context *context)
2119 for (i = 0; i < EET_FREE_COUNT; ++i)
2121 eina_array_flush(&context->freelist.list[i]);
2122 eina_array_flush(&context->freelist_array.list[i]);
2123 eina_array_flush(&context->freelist_list.list[i]);
2124 eina_array_flush(&context->freelist_hash.list[i]);
2125 eina_array_flush(&context->freelist_str.list[i]);
2126 eina_array_flush(&context->freelist_direct_str.list[i]);
2131 _eet_free_hash(void *data)
2134 __int64 ptr = (UINT_PTR)data;
2135 #else /* ifdef _WIN64 */
2136 unsigned long ptr = (unsigned long)(data);
2137 #endif /* ifdef _WIN64 */
2145 #if defined (_WIN64) || ((!defined (_WIN32)) && (LONG_BIT != 32))
2150 #endif /* if defined (_WIN64) || ((!defined (_WIN32)) && (LONG_BIT != 32)) */
2153 } /* _eet_free_hash */
2156 _eet_free_add(Eet_Free *ef,
2160 Eina_Array_Iterator it;
2164 hash = _eet_free_hash(data);
2166 EINA_ARRAY_ITER_NEXT(&ef->list[hash], i, track, it)
2170 eina_array_push(&ef->list[hash], data);
2171 } /* _eet_free_add */
2175 _eet_free_del(Eet_Free *ef,
2179 Eina_Array_Iterator it;
2183 hash = _eet_free_hash(data);
2185 EINA_ARRAY_ITER_NEXT(&ef->list[hash], i, track, it)
2188 eina_array_data_set(&ef->list[hash], i, NULL);
2195 _eet_free_reset(Eet_Free *ef)
2202 for (i = 0; i < EET_FREE_COUNT; ++i)
2203 eina_array_clean(&ef->list[i]);
2204 } /* _eet_free_reset */
2207 _eet_free_ref(Eet_Free *ef)
2210 } /* _eet_free_ref */
2213 _eet_free_unref(Eet_Free *ef)
2216 } /* _eet_free_unref */
2218 #define _eet_freelist_add(Ctx, Data) _eet_free_add(&Ctx->freelist, Data);
2219 #define _eet_freelist_del(Ctx, Data) _eet_free_del(&Ctx->freelist, Data);
2220 #define _eet_freelist_reset(Ctx) _eet_free_reset(&Ctx->freelist);
2221 #define _eet_freelist_ref(Ctx) _eet_free_ref(&Ctx->freelist);
2222 #define _eet_freelist_unref(Ctx) _eet_free_unref(&Ctx->freelist);
2225 _eet_freelist_free(Eet_Free_Context *context,
2226 Eet_Data_Descriptor *edd)
2229 Eina_Array_Iterator it;
2233 if (context->freelist.ref > 0)
2236 for (j = 0; j < EET_FREE_COUNT; ++j)
2237 EINA_ARRAY_ITER_NEXT(&context->freelist.list[j], i, track, it)
2241 edd->func.mem_free(track);
2245 _eet_free_reset(&context->freelist);
2246 } /* _eet_freelist_free */
2248 #define _eet_freelist_array_add(Ctx, Data) _eet_free_add(&Ctx->freelist_array, Data);
2249 #define _eet_freelist_array_del(Ctx, Data) _eet_free_del(&Ctx->freelist_array, Data);
2250 #define _eet_freelist_array_reset(Ctx) _eet_free_reset(&Ctx->freelist_array);
2251 #define _eet_freelist_array_ref(Ctx) _eet_free_ref(&Ctx->freelist_array);
2252 #define _eet_freelist_array_unref(Ctx) _eet_free_unref(&Ctx->freelist_array);
2255 _eet_freelist_array_free(Eet_Free_Context *context,
2256 Eet_Data_Descriptor *edd)
2259 Eina_Array_Iterator it;
2263 if (context->freelist_array.ref > 0)
2266 for (j = 0; j < EET_FREE_COUNT; ++j)
2267 EINA_ARRAY_ITER_NEXT(&context->freelist_array.list[j], i, track, it)
2272 if (edd->func.array_free)
2273 edd->func.array_free(track);
2275 edd->func.mem_free(track);
2280 _eet_free_reset(&context->freelist_array);
2281 } /* _eet_freelist_array_free */
2283 #define _eet_freelist_list_add(Ctx, Data) _eet_free_add(&Ctx->freelist_list, Data);
2284 #define _eet_freelist_list_del(Ctx, Data) _eet_free_del(&Ctx->freelist_list, Data);
2285 #define _eet_freelist_list_reset(Ctx) _eet_free_reset(&Ctx->freelist_list);
2286 #define _eet_freelist_list_ref(Ctx) _eet_free_ref(&Ctx->freelist_list);
2287 #define _eet_freelist_list_unref(Ctx) _eet_free_unref(&Ctx->freelist_list);
2290 _eet_freelist_list_free(Eet_Free_Context *context,
2291 Eet_Data_Descriptor *edd)
2294 Eina_Array_Iterator it;
2298 if (context->freelist_list.ref > 0)
2301 for (j = 0; j < EET_FREE_COUNT; ++j)
2302 EINA_ARRAY_ITER_NEXT(&context->freelist_list.list[j], i, track, it)
2306 edd->func.list_free(*((void **)(track)));
2308 _eet_free_reset(&context->freelist_list);
2309 } /* _eet_freelist_list_free */
2311 #define _eet_freelist_str_add(Ctx, Data) _eet_free_add(&Ctx->freelist_str, Data);
2312 #define _eet_freelist_str_del(Ctx, Data) _eet_free_del(&Ctx->freelist_str, Data);
2313 #define _eet_freelist_str_reset(Ctx) _eet_free_reset(&Ctx->freelist_str);
2314 #define _eet_freelist_str_ref(Ctx) _eet_free_ref(&Ctx->freelist_str);
2315 #define _eet_freelist_str_unref(Ctx) _eet_free_unref(&Ctx->freelist_str);
2318 _eet_freelist_str_free(Eet_Free_Context *context, Eet_Data_Descriptor *edd)
2321 Eina_Array_Iterator it;
2325 if (context->freelist_str.ref > 0)
2328 for (j = 0; j < EET_FREE_COUNT; ++j)
2329 EINA_ARRAY_ITER_NEXT(&context->freelist_str.list[j], i, track, it)
2333 edd->func.str_free(track);
2337 _eet_free_reset(&context->freelist_str);
2338 } /* _eet_freelist_str_free */
2340 #define _eet_freelist_direct_str_add(Ctx, Data) _eet_free_add(&Ctx->freelist_direct_str, Data);
2341 #define _eet_freelist_direct_str_del(Ctx, Data) _eet_free_del(&Ctx->freelist_direct_str, Data);
2342 #define _eet_freelist_direct_str_reset(Ctx) _eet_free_reset(&Ctx->freelist_direct_str);
2343 #define _eet_freelist_direct_str_ref(Ctx) _eet_free_ref(&Ctx->freelist_direct_str);
2344 #define _eet_freelist_direct_str_unref(Ctx) _eet_free_unref(&Ctx->freelist_direct_str);
2347 _eet_freelist_direct_str_free(Eet_Free_Context *context,
2348 Eet_Data_Descriptor *edd)
2351 Eina_Array_Iterator it;
2355 if (context->freelist_direct_str.ref > 0)
2358 for (j = 0; j < EET_FREE_COUNT; ++j)
2359 EINA_ARRAY_ITER_NEXT(&context->freelist_str.list[j], i, track, it)
2363 edd->func.str_direct_free(track);
2367 _eet_free_reset(&context->freelist_direct_str);
2368 } /* _eet_freelist_direct_str_free */
2370 #define _eet_freelist_hash_add(Ctx, Data) _eet_free_add(&Ctx->freelist_hash, Data);
2371 #define _eet_freelist_hash_del(Ctx, Data) _eet_free_del(&Ctx->freelist_hash, Data);
2372 #define _eet_freelist_hash_reset(Ctx) _eet_free_reset(&Ctx->freelist_hash);
2373 #define _eet_freelist_hash_ref(Ctx) _eet_free_ref(&Ctx->freelist_hash);
2374 #define _eet_freelist_hash_unref(Ctx) _eet_free_unref(&Ctx->freelist_hash);
2377 _eet_freelist_hash_free(Eet_Free_Context *context,
2378 Eet_Data_Descriptor *edd)
2381 Eina_Array_Iterator it;
2385 if (context->freelist_hash.ref > 0)
2388 for (j = 0; j < EET_FREE_COUNT; ++j)
2389 EINA_ARRAY_ITER_NEXT(&context->freelist_hash.list[j], i, track, it)
2393 edd->func.hash_free(track);
2397 _eet_free_reset(&context->freelist_hash);
2398 } /* _eet_freelist_hash_free */
2401 _eet_freelist_all_ref(Eet_Free_Context *freelist_context)
2403 _eet_freelist_ref(freelist_context);
2404 _eet_freelist_str_ref(freelist_context);
2405 _eet_freelist_list_ref(freelist_context);
2406 _eet_freelist_hash_ref(freelist_context);
2407 _eet_freelist_direct_str_ref(freelist_context);
2408 } /* _eet_freelist_all_ref */
2411 _eet_freelist_all_unref(Eet_Free_Context *freelist_context)
2413 _eet_freelist_unref(freelist_context);
2414 _eet_freelist_str_unref(freelist_context);
2415 _eet_freelist_list_unref(freelist_context);
2416 _eet_freelist_hash_unref(freelist_context);
2417 _eet_freelist_direct_str_unref(freelist_context);
2418 } /* _eet_freelist_all_unref */
2421 eet_data_descriptor_encode_hash_cb(void *hash __UNUSED__,
2422 const char *cipher_key,
2427 Eet_Data_Encode_Hash_Info *edehi;
2428 Eet_Data_Stream *ds;
2429 Eet_Data_Element *ede;
2430 Eet_Data_Chunk *echnk;
2440 data = eet_data_put_type(ed,
2446 echnk = eet_data_chunk_new(data,
2451 eet_data_chunk_put(ed, echnk, ds);
2452 eet_data_chunk_free(echnk);
2457 EET_ASSERT(!((ede->type > EET_T_UNKNOW) && (ede->type < EET_T_STRING)), return );
2460 if (ede->type >= EET_T_STRING)
2461 eet_data_put_unknown(ed, NULL, ede, ds, &hdata);
2465 data = _eet_data_descriptor_encode(ed,
2472 echnk = eet_data_chunk_new(data,
2477 eet_data_chunk_put(ed, echnk, ds);
2478 eet_data_chunk_free(echnk);
2485 } /* eet_data_descriptor_encode_hash_cb */
2488 _eet_data_dump_token_get(const char *src,
2495 int tlen = 0, tsize = 0;
2503 tok = realloc(tok, tsize);\
2508 for (p = src; *len > 0; p++, (*len)--)
2514 if ((p[0] == '\"') && (p > src) && (p[-1] != '\\'))
2516 else if ((p[0] == '\\') && (*len > 1) &&
2521 else if ((p[0] == '\\') && (p > src) && (p[-1] == '\\'))
2525 else if ((p[0] == '\\') && (*len > 1) && (p[1] == 'n'))
2529 else if ((p[0] == 'n') && (p > src) && (p[-1] == '\\'))
2540 if ((isspace(p[0])) || (p[0] == ';')) /* token ends here */
2551 else if (!((isspace(p[0])) || (p[0] == ';')))
2568 } /* _eet_data_dump_token_get */
2571 eet_data_encode(Eet_Dictionary *ed,
2572 Eet_Data_Stream *ds,
2579 Eet_Data_Chunk *echnk;
2584 if (group_type != EET_G_UNKNOWN)
2585 if (type >= EET_T_LAST)
2586 type = EET_T_UNKNOW;
2588 echnk = eet_data_chunk_new(data, size, name, type, group_type);
2589 eet_data_chunk_put(ed, echnk, ds);
2590 eet_data_chunk_free(echnk);
2592 } /* eet_data_encode */
2595 _eet_data_dump_encode(int parent_type,
2600 Eet_Data_Chunk *chnk = NULL;
2601 Eet_Data_Stream *ds;
2608 if (_eet_data_words_bigendian == -1)
2610 unsigned long int v;
2612 v = htonl(0x12345678);
2613 if (v == 0x12345678)
2614 _eet_data_words_bigendian = 1;
2616 _eet_data_words_bigendian = 0;
2622 ds = eet_data_stream_new();
2629 for (n = node->values; n; n = n->next)
2631 data = _eet_data_dump_encode(node->type, ed, n, &size);
2634 eet_data_stream_write(ds, data, size);
2641 case EET_G_VAR_ARRAY:
2642 for (child_type = EET_T_NULL, n = node->values; n; n = n->next)
2644 if (n->type != EET_T_NULL)
2646 child_type = n->type;
2651 data = eet_data_put_type(ed,
2663 count = node->count;
2665 for (n = node->values; n; n = n->next)
2672 case EET_T_INLINED_STRING:
2673 data = eet_data_put_type(ed,
2675 &(n->data.value.str),
2692 data = _eet_data_dump_encode(n->type, ed, n, &size);
2706 for (; count; count--)
2717 /* Array is somekind of special case, so we should embed it inside another chunk. */
2718 *size_ret = ds->pos;
2723 eet_data_stream_free(ds);
2729 for (n = node->values; n; n = n->next)
2734 case EET_T_INLINED_STRING:
2735 data = eet_data_put_type(ed,
2737 &(n->data.value.str),
2754 data = _eet_data_dump_encode(node->type, ed, n, &size);
2765 /* List is another somekind of special case, every chunk is embed inside a list chunk. */
2766 *size_ret = ds->pos;
2771 eet_data_stream_free(ds);
2779 data = eet_data_put_type(ed,
2792 /* A Hash without key will not decode correctly. */
2795 for (n = node->values; n; n = n->next)
2800 case EET_T_INLINED_STRING:
2801 data = eet_data_put_type(ed,
2803 &(n->data.value.str),
2820 data = _eet_data_dump_encode(node->type, ed, n, &size);
2831 /* Hash is somekind of special case, so we should embed it inside another chunk. */
2832 *size_ret = ds->pos;
2835 eet_data_stream_flush(ds);
2842 #define EET_DATA_NODE_ENCODE(Eet_Type, Type)\
2844 data = eet_data_put_type(ed, node->type, &(node->data.value.Type), &size);\
2847 eet_data_encode(ed,\
2855 *size_ret = ds->pos;\
2856 eet_data_stream_flush(ds);\
2861 EET_DATA_NODE_ENCODE(EET_T_CHAR, c);
2862 EET_DATA_NODE_ENCODE(EET_T_SHORT, s);
2863 EET_DATA_NODE_ENCODE(EET_T_INT, i);
2864 EET_DATA_NODE_ENCODE(EET_T_LONG_LONG, l);
2865 EET_DATA_NODE_ENCODE(EET_T_FLOAT, f);
2866 EET_DATA_NODE_ENCODE(EET_T_DOUBLE, d);
2867 EET_DATA_NODE_ENCODE(EET_T_UCHAR, uc);
2868 EET_DATA_NODE_ENCODE(EET_T_USHORT, us);
2869 EET_DATA_NODE_ENCODE(EET_T_UINT, ui);
2870 EET_DATA_NODE_ENCODE(EET_T_ULONG_LONG, ul);
2871 EET_DATA_NODE_ENCODE(EET_T_INLINED_STRING, str);
2872 EET_DATA_NODE_ENCODE(EET_T_STRING, str);
2878 if ((node->type >= EET_G_UNKNOWN) && (node->type < EET_G_LAST))
2879 chnk = eet_data_chunk_new(ds->data,
2885 chnk = eet_data_chunk_new(ds->data,
2891 eet_data_stream_flush(ds);
2893 ds = eet_data_stream_new();
2894 eet_data_chunk_put(ed, chnk, ds);
2898 eet_data_stream_flush(ds);
2902 eet_data_chunk_free(chnk);
2905 } /* _eet_data_dump_encode */
2908 _eet_data_dump_parse(Eet_Dictionary *ed,
2914 const char *p = NULL;
2919 Eet_Node *node_base = NULL;
2920 Eet_Node *node = NULL;
2921 Eet_Node *n = NULL, *nn = NULL;
2923 /* FIXME; handle parse errors */
2925 jump = left; t = _eet_data_dump_token_get(p, &left); p += jump - left;
2927 for (p = src; p < (src + size); )
2929 char *tok1, *tok2, *tok3, *tok4;
2934 if (!strcmp(tok1, "group"))
2945 if (!strcmp(tok4, "{"))
2947 /* we have 'group NAM TYP {' */
2961 for (nn = node->values; nn;
2972 n->name = eina_stringshare_add(tok2);
2973 if (!strcmp(tok3, "struct"))
2974 n->type = EET_G_UNKNOWN;
2975 else if (!strcmp(tok3, "array"))
2976 n->type = EET_G_ARRAY;
2977 else if (!strcmp(tok3, "var_array"))
2978 n->type = EET_G_VAR_ARRAY;
2979 else if (!strcmp(tok3, "list"))
2980 n->type = EET_G_LIST;
2981 else if (!strcmp(tok3, "hash"))
2982 n->type = EET_G_HASH;
2985 "ERROR: group type '%s' invalid.",
3001 else if (!strcmp(tok1, "value"))
3012 /* we have 'value NAME TYP XXX' */
3023 for (nn = node->values; nn;
3033 n->name = eina_stringshare_add(tok2);
3034 if (!strcmp(tok3, "char:"))
3036 n->type = EET_T_CHAR;
3037 sscanf(tok4, FMT_CHAR,
3038 &(n->data.value.c));
3040 else if (!strcmp(tok3, "short:"))
3042 n->type = EET_T_SHORT;
3044 &(n->data.value.s));
3046 else if (!strcmp(tok3, "int:"))
3048 n->type = EET_T_INT;
3050 &(n->data.value.i));
3052 else if (!strcmp(tok3, "long_long:"))
3054 n->type = EET_T_LONG_LONG;
3055 sscanf(tok4, FMT_LONG_LONG,
3056 &(n->data.value.l));
3058 else if (!strcmp(tok3, "float:"))
3060 n->type = EET_T_FLOAT;
3062 &(n->data.value.f));
3064 else if (!strcmp(tok3, "double:"))
3066 n->type = EET_T_DOUBLE;
3068 &(n->data.value.d));
3070 else if (!strcmp(tok3, "uchar:"))
3072 n->type = EET_T_UCHAR;
3073 sscanf(tok4, FMT_UCHAR,
3074 &(n->data.value.uc));
3076 else if (!strcmp(tok3, "ushort:"))
3078 n->type = EET_T_USHORT;
3080 &(n->data.value.us));
3082 else if (!strcmp(tok3, "uint:"))
3084 n->type = EET_T_UINT;
3086 &(n->data.value.ui));
3088 else if (!strcmp(tok3, "ulong_long:"))
3090 n->type = EET_T_ULONG_LONG;
3091 sscanf(tok4, FMT_ULONG_LONG,
3092 &(n->data.value.ul));
3094 else if (!strcmp(tok3, "string:"))
3096 n->type = EET_T_STRING;
3098 eina_stringshare_add(tok4);
3100 else if (!strcmp(tok3, "inlined:"))
3102 n->type = EET_T_INLINED_STRING;
3104 eina_stringshare_add(tok4);
3106 else if (!strcmp(tok3, "null"))
3108 n->type = EET_T_NULL;
3109 n->data.value.str = NULL;
3113 "ERROR: value type '%s' invalid.",
3127 else if (!strcmp(tok1, "key"))
3132 /* we have 'key NAME' */
3134 node->key = eina_stringshare_add(tok2);
3139 else if (!strcmp(tok1, "count"))
3144 /* we have a 'count COUNT' */
3146 sscanf(tok2, "%i", &(node->count));
3151 else if (!strcmp(tok1, "}"))
3152 /* we have an end of the group */
3154 node = node->parent;
3162 cdata = _eet_data_dump_encode(EET_G_UNKNOWN, ed, node_base, size_ret);
3163 eet_node_del(node_base);
3167 } /* _eet_data_dump_parse */
3169 #define NEXT_CHUNK(P, Size, Echnk, Ed)\
3172 __tmp = Ed ? (int)(sizeof(int) * 2) : Echnk.len + 4;\
3173 P += (4 + Echnk.size + __tmp);\
3174 Size -= (4 + Echnk.size + __tmp);\
3178 _eet_data_descriptor_decode(Eet_Free_Context *context,
3179 const Eet_Dictionary *ed,
3180 Eet_Data_Descriptor *edd,
3181 const void *data_in,
3186 Eet_Node *result = NULL;
3190 Eet_Data_Chunk chnk;
3192 if (_eet_data_words_bigendian == -1)
3194 unsigned long int v;
3196 v = htonl(0x12345678);
3197 if (v == 0x12345678)
3198 _eet_data_words_bigendian = 1;
3200 _eet_data_words_bigendian = 0;
3207 if (size_out <= edd->size)
3212 data = edd->func.mem_alloc(edd->size);
3220 for (i = 0; i < edd->elements.num; i++)
3221 edd->elements.set[i].directory_name_ptr = NULL;
3226 _eet_freelist_all_ref(context);
3227 if (data && !data_out)
3228 _eet_freelist_add(context, data);
3230 memset(&chnk, 0, sizeof(Eet_Data_Chunk));
3231 eet_data_chunk_get(ed, &chnk, data_in, size_in);
3236 if (strcmp(chnk.name, edd->name))
3241 size = size_in - (4 + sizeof(int) * 2);
3243 size = size_in - (4 + 4 + chnk.len);
3247 if (!edd->elements.hash.buckets)
3248 _eet_descriptor_hash_new(edd);
3252 switch (chnk.group_type)
3258 return eet_node_string_new(chnk.name, chnk.data);
3260 case EET_T_INLINED_STRING:
3261 return eet_node_inlined_string_new(chnk.name, chnk.data);
3264 return eet_node_null_new(chnk.name);
3267 result = eet_node_struct_new(chnk.name, NULL);
3271 case EET_G_VAR_ARRAY:
3272 return eet_node_var_array_new(chnk.name, NULL);
3286 Eet_Data_Chunk echnk;
3287 Eet_Data_Element *ede = NULL;
3288 Eet_Node *child = NULL;
3289 int group_type = EET_G_UNKNOWN, type = EET_T_UNKNOW;
3292 /* get next data chunk */
3293 memset(&echnk, 0, sizeof(Eet_Data_Chunk));
3294 eet_data_chunk_get(ed, &echnk, p, size);
3296 goto error; /* FIXME: don't REPLY on edd - work without */
3300 ede = _eet_descriptor_hash_find(edd, echnk.name, echnk.hash);
3303 group_type = ede->group_type;
3305 if ((echnk.type == 0) && (echnk.group_type == 0))
3308 group_type = ede->group_type;
3312 if (IS_SIMPLE_TYPE(echnk.type) &&
3313 eet_data_type_match(echnk.type, ede->type))
3314 /* Needed when converting on the fly from FP to Float */
3316 else if ((echnk.group_type > EET_G_UNKNOWN) &&
3317 (echnk.group_type < EET_G_LAST) &&
3318 (echnk.group_type == ede->group_type))
3319 group_type = echnk.group_type;
3323 /*...... dump to node */
3327 group_type = echnk.group_type;
3330 if (!edd && group_type == EET_G_UNKNOWN && IS_SIMPLE_TYPE(type))
3332 unsigned char dd[128];
3334 ret = eet_data_get_type(ed,
3337 ((char *)echnk.data) + echnk.size,
3342 child = eet_data_node_simple_type(type, echnk.name, dd);
3344 eet_node_struct_append(result, echnk.name, child);
3348 ret = eet_group_codec[group_type - 100].get(
3356 ede ? (void *)(((char*) data) + ede->offset) : (void **)&result,
3364 /* advance to next chunk */
3365 NEXT_CHUNK(p, size, echnk, ed);
3368 _eet_freelist_all_unref(context);
3371 _eet_freelist_str_free(context, edd);
3372 _eet_freelist_direct_str_free(context, edd);
3373 _eet_freelist_list_free(context, edd);
3374 _eet_freelist_hash_free(context, edd);
3375 _eet_freelist_array_free(context, edd);
3376 _eet_freelist_free(context, edd);
3380 _eet_freelist_reset(context);
3381 _eet_freelist_str_reset(context);
3382 _eet_freelist_list_reset(context);
3383 _eet_freelist_hash_reset(context);
3384 _eet_freelist_direct_str_reset(context);
3385 _eet_freelist_array_reset(context);
3394 eet_node_del(result);
3396 _eet_freelist_all_unref(context);
3397 _eet_freelist_str_free(context, edd);
3398 _eet_freelist_direct_str_free(context, edd);
3399 _eet_freelist_list_free(context, edd);
3400 _eet_freelist_hash_free(context, edd);
3401 _eet_freelist_array_free(context, edd);
3402 _eet_freelist_free(context, edd);
3404 /* FIXME: Warn that something goes wrong here. */
3406 } /* _eet_data_descriptor_decode */
3409 eet_data_get_list(Eet_Free_Context *context,
3410 const Eet_Dictionary *ed,
3411 Eet_Data_Descriptor *edd,
3412 Eet_Data_Element *ede,
3413 Eet_Data_Chunk *echnk,
3415 int group_type __UNUSED__,
3420 Eet_Data_Descriptor *subtype = NULL;
3425 EET_ASSERT(!((type > EET_T_UNKNOW) && (type < EET_T_STRING)), return 0);
3429 subtype = ede->subtype;
3431 if (type != ede->type)
3435 ptr = (void **)data;
3439 if (IS_POINTER_TYPE(type))
3440 POINTER_TYPE_DECODE(context,
3451 STRUCT_TYPE_DECODE(data_ret,
3462 list = edd->func.list_append(list, data_ret);
3464 _eet_freelist_list_add(context, ptr);
3467 eet_node_list_append(*((Eet_Node **)data), echnk->name, data_ret);
3473 } /* eet_data_get_list */
3476 eet_data_get_hash(Eet_Free_Context *context,
3477 const Eet_Dictionary *ed,
3478 Eet_Data_Descriptor *edd,
3479 Eet_Data_Element *ede,
3480 Eet_Data_Chunk *echnk,
3482 int group_type __UNUSED__,
3490 void *data_ret = NULL;
3493 EET_ASSERT(!((type > EET_T_UNKNOW) && (type < EET_T_STRING)), return 0);
3495 ptr = (void **)data;
3499 ret = eet_data_get_type(ed,
3502 ((char *)echnk->data) + echnk->size,
3510 /* Advance to next chunk */
3511 NEXT_CHUNK((*p), (*size), (*echnk), ed);
3512 memset(echnk, 0, sizeof(Eet_Data_Chunk));
3515 eet_data_chunk_get(ed, echnk, *p, *size);
3520 if ((ede->group_type != echnk->group_type)
3521 || (ede->type != echnk->type))
3524 if (IS_POINTER_TYPE(echnk->type))
3525 POINTER_TYPE_DECODE(context,
3536 STRUCT_TYPE_DECODE(data_ret,
3539 ede ? ede->subtype : NULL,
3547 hash = edd->func.hash_add(hash, key, data_ret);
3549 _eet_freelist_hash_add(context, hash);
3552 eet_node_hash_add(*((Eet_Node **)data), echnk->name, key, data_ret);
3558 } /* eet_data_get_hash */
3560 /* var arrays and fixed arrays have to
3561 * get all chunks at once. for fixed arrays
3562 * we can get each chunk and increment a
3563 * counter stored on the element itself but
3564 * it wont be thread safe. for var arrays
3565 * we still need a way to get the number of
3566 * elements from the data, so storing the
3567 * number of elements and the element data on
3568 * each chunk is pointless.
3571 eet_data_get_array(Eet_Free_Context *context,
3572 const Eet_Dictionary *ed,
3573 Eet_Data_Descriptor *edd,
3574 Eet_Data_Element *ede,
3575 Eet_Data_Chunk *echnk,
3582 Eina_List *childs = NULL;
3591 EET_ASSERT(!((type > EET_T_UNKNOW) && (type < EET_T_STRING)), return 0);
3594 /* read the number of elements */
3595 ret = eet_data_get_type(ed,
3598 ((char *)echnk->data) + echnk->size,
3607 if (IS_POINTER_TYPE(type))
3608 subsize = eet_basic_codec[ede->type].size;
3610 subsize = ede->subtype->size;
3612 if (group_type == EET_G_VAR_ARRAY)
3614 /* store the number of elements
3615 * on the counter offset */
3616 *(int *)(((char *)data) + ede->count - ede->offset) = count;
3617 /* allocate space for the array of elements */
3618 if (edd->func.array_alloc)
3619 *(void **) ptr = edd->func.array_alloc(count * subsize);
3621 *(void **) ptr = edd->func.mem_alloc(count * subsize);
3626 memset(*(void **)ptr, 0, count * subsize);
3628 _eet_freelist_array_add(context, *(void **)ptr);
3632 /* get all array elements */
3633 for (i = 0; i < count; i++)
3637 /* Advance to next chunk */
3638 NEXT_CHUNK((*p), (*size), (*echnk), ed);
3639 memset(echnk, 0, sizeof(Eet_Data_Chunk));
3641 eet_data_chunk_get(ed, echnk, *p, *size);
3642 if (!echnk->name || strcmp(echnk->name, name) != 0)
3643 goto on_error; /* get the data */
3645 if ((echnk->group_type != group_type)
3646 || ((echnk->type != type) && (echnk->type != EET_T_NULL)))
3650 if ((ede->group_type != echnk->group_type)
3651 || ((echnk->type != ede->type) && (echnk->type != EET_T_NULL)))
3654 /* get the destination pointer */
3657 if (group_type == EET_G_ARRAY)
3658 dst = (char *)ptr + (subsize * i);
3660 dst = *(char **)ptr + (subsize * i);
3663 if (IS_POINTER_TYPE(echnk->type))
3665 void *data_ret = NULL;
3667 POINTER_TYPE_DECODE(context,
3678 memcpy(dst, &data_ret, subsize);
3681 childs = eina_list_append(childs, data_ret);
3685 STRUCT_TYPE_DECODE(dst,
3688 ede ? ede->subtype : NULL,
3695 childs = eina_list_append(childs, dst);
3701 Eet_Node *parent = *((Eet_Node **)data);
3704 if (group_type == EET_G_ARRAY)
3705 array = eet_node_array_new(name, count, childs);
3707 array = eet_node_var_array_new(name, childs);
3712 eet_node_struct_append(parent, name, array);
3718 EINA_LIST_FREE(childs, tmp)
3722 } /* eet_data_get_array */
3725 eet_data_put_union(Eet_Dictionary *ed,
3726 Eet_Data_Descriptor *edd __UNUSED__,
3727 Eet_Data_Element *ede,
3728 Eet_Data_Stream *ds,
3731 const char *union_type;
3734 EET_ASSERT(!((ede->type != EET_T_UNKNOW) || (!ede->subtype)), return );
3736 union_type = ede->subtype->func.type_get(
3737 ((char *)data_in) + ede->count - ede->offset,
3743 /* Search the structure of the union to encode. */
3744 for (i = 0; i < ede->subtype->elements.num; ++i)
3745 if (strcmp(ede->subtype->elements.set[i].name, union_type) == 0)
3747 Eet_Data_Element *sede;
3751 /* Yeah we found it ! */
3752 data = eet_data_put_type(ed, EET_T_STRING, &union_type, &size);
3762 sede = &(ede->subtype->elements.set[i]);
3763 data = _eet_data_descriptor_encode(ed,
3779 } /* eet_data_put_union */
3782 eet_data_get_union(Eet_Free_Context *context,
3783 const Eet_Dictionary *ed,
3784 Eet_Data_Descriptor *edd __UNUSED__,
3785 Eet_Data_Element *ede,
3786 Eet_Data_Chunk *echnk,
3793 const char *union_type;
3794 void *data_ret = NULL;
3799 ret = eet_data_get_type(ed,
3802 ((char *)echnk->data) + echnk->size,
3807 /* Advance to next chunk */
3808 NEXT_CHUNK((*p), (*size), (*echnk), ed);
3809 memset(echnk, 0, sizeof(Eet_Data_Chunk));
3812 eet_data_chunk_get(ed, echnk, *p, *size);
3818 EET_ASSERT(!(ede->group_type != group_type || ede->type != type),
3821 /* Search the structure of the union to decode */
3822 for (i = 0; i < ede->subtype->elements.num; ++i)
3823 if (strcmp(ede->subtype->elements.set[i].name, union_type) == 0)
3825 Eet_Data_Element *sede;
3828 /* Yeah we found it ! */
3829 sede = &(ede->subtype->elements.set[i]);
3830 EET_ASSERT(sede->subtype, goto on_error);
3832 data_ret = _eet_data_descriptor_decode(context,
3838 sede->subtype->size);
3842 /* Set union type. */
3843 if ((!ed) || (!ede->subtype->func.str_direct_alloc))
3845 ut = ede->subtype->func.str_alloc(union_type);
3846 _eet_freelist_str_add(context, ut);
3850 ut = ede->subtype->func.str_direct_alloc(union_type);
3851 _eet_freelist_direct_str_add(context, ut);
3854 ede->subtype->func.type_set(
3856 ((char *)data) + ede->count -
3866 /* FIXME: generate node structure. */
3867 data_ret = _eet_data_descriptor_decode(context,
3869 echnk->data, echnk->size,
3878 } /* eet_data_get_union */
3881 eet_data_put_variant(Eet_Dictionary *ed,
3882 Eet_Data_Descriptor *edd __UNUSED__,
3883 Eet_Data_Element *ede,
3884 Eet_Data_Stream *ds,
3887 const char *union_type;
3889 Eina_Bool unknow = EINA_FALSE;
3893 EET_ASSERT(!((ede->type != EET_T_UNKNOW) || (!ede->subtype)), return );
3895 union_type = ede->subtype->func.type_get(
3896 ((char *)data_in) + ede->count - ede->offset,
3899 if (!union_type && unknow == EINA_FALSE)
3904 /* Handle opaque internal representation */
3905 Eet_Variant_Unknow *evu;
3907 data = eet_data_put_type(ed, EET_T_STRING, &union_type, &size);
3917 evu = (Eet_Variant_Unknow *)data_in;
3918 if (evu && EINA_MAGIC_CHECK(evu, EET_MAGIC_VARIANT))
3928 /* Search the structure of the union to encode. */
3929 for (i = 0; i < ede->subtype->elements.num; ++i)
3930 if (strcmp(ede->subtype->elements.set[i].name, union_type) == 0)
3932 Eet_Data_Element *sede;
3934 /* Yeah we found it ! */
3935 data = eet_data_put_type(ed, EET_T_STRING, &union_type, &size);
3945 sede = &(ede->subtype->elements.set[i]);
3947 if (sede->group_type != EET_G_UNKNOWN)
3949 Eet_Data_Stream *lds;
3951 lds = eet_data_stream_new();
3952 eet_group_codec[sede->group_type - 100].put(ed,
3959 eet_data_encode(ed, ds, lds->data, ede->name, lds->pos,
3960 ede->type, ede->group_type);
3966 eet_data_encode(ed, ds, NULL, ede->name, 0,
3967 EET_T_NULL, ede->group_type);
3969 eet_data_stream_free(lds);
3973 data = _eet_data_descriptor_encode(ed,
3990 } /* eet_data_put_variant */
3993 eet_data_get_variant(Eet_Free_Context *context,
3994 const Eet_Dictionary *ed,
3995 Eet_Data_Descriptor *edd __UNUSED__,
3996 Eet_Data_Element *ede,
3997 Eet_Data_Chunk *echnk,
3998 int type __UNUSED__,
3999 int group_type __UNUSED__,
4004 const char *union_type;
4005 void *data_ret = NULL;
4010 ret = eet_data_get_type(ed,
4013 ((char *)echnk->data) + echnk->size,
4018 /* Advance to next chunk */
4019 NEXT_CHUNK((*p), (*size), (*echnk), ed);
4020 memset(echnk, 0, sizeof(Eet_Data_Chunk));
4023 eet_data_chunk_get(ed, echnk, *p, *size);
4031 EET_ASSERT(ede->subtype, goto on_error);
4033 if ((!ed) || (!ede->subtype->func.str_direct_alloc))
4035 ut = ede->subtype->func.str_alloc(union_type);
4036 _eet_freelist_str_add(context, ut);
4040 ut = ede->subtype->func.str_direct_alloc(union_type);
4041 _eet_freelist_direct_str_add(context, ut);
4044 /* Search the structure of the union to decode */
4045 for (i = 0; i < ede->subtype->elements.num; ++i)
4046 if (strcmp(ede->subtype->elements.set[i].name, union_type) == 0)
4048 Eet_Data_Element *sede;
4050 /* Yeah we found it ! */
4051 sede = &(ede->subtype->elements.set[i]);
4053 if (sede->group_type != EET_G_UNKNOWN)
4055 Eet_Data_Chunk chnk;
4060 size2 = echnk->size;
4062 /* Didn't find a proper way to provide this
4063 without duplicating code */
4066 memset(&chnk, 0, sizeof(Eet_Data_Chunk));
4067 eet_data_chunk_get(ed, &chnk, p2, size2);
4072 ret = eet_group_codec[sede->group_type - 100].get
4073 (context, ed, sede->subtype, sede, &chnk, sede->type,
4074 sede->group_type, data, &p2, &size2);
4079 /* advance to next chunk */
4080 NEXT_CHUNK(p2, size2, chnk, ed);
4083 /* Put garbage so that we will not put eet_variant_unknow in it */
4084 data_ret = (void *)data;
4086 /* Set variant type. */
4087 ede->subtype->func.type_set
4088 (ut, ((char *)data) + ede->count - ede->offset,
4093 data_ret = _eet_data_descriptor_decode(context,
4102 /* And point to the variant data. */
4103 *(void **)data = data_ret;
4105 /* Set variant type. */
4106 ede->subtype->func.type_set
4107 (ut, ((char *)data) + ede->count - ede->offset, EINA_FALSE);
4113 Eet_Variant_Unknow *evu;
4115 evu = calloc(1, sizeof (Eet_Variant_Unknow) + echnk->size - 1);
4119 evu->size = echnk->size;
4120 memcpy(evu->data, echnk->data, evu->size);
4121 EINA_MAGIC_SET(evu, EET_MAGIC_VARIANT);
4123 /* And point to the opaque internal data scructure */
4124 *(void **)data = evu;
4126 /* Set variant type. */
4127 ede->subtype->func.type_set
4128 (ut, ((char *)data) + ede->count - ede->offset, EINA_TRUE);
4133 /* FIXME: dump node structure. */
4134 data_ret = _eet_data_descriptor_decode(context,
4136 echnk->data, echnk->size,
4145 } /* eet_data_get_variant */
4148 eet_data_node_simple_type(int type, const char *name, void *dd)
4152 #endif /* ifdef EET_T_TYPE */
4154 #define EET_T_TYPE(Eet_Type, Eet_Node_Type, Type)\
4156 return eet_node_ ## Eet_Node_Type ## _new(name, *((Type *)dd));\
4160 EET_T_TYPE(EET_T_CHAR, char, char);
4161 EET_T_TYPE(EET_T_SHORT, short, short);
4162 EET_T_TYPE(EET_T_INT, int, int);
4163 EET_T_TYPE(EET_T_LONG_LONG, long_long, long long);
4164 EET_T_TYPE(EET_T_FLOAT, float, float);
4165 EET_T_TYPE(EET_T_DOUBLE, double, double);
4166 EET_T_TYPE(EET_T_UCHAR, unsigned_char, unsigned char);
4167 EET_T_TYPE(EET_T_USHORT, unsigned_short, unsigned short);
4168 EET_T_TYPE(EET_T_UINT, unsigned_int, unsigned int);
4169 EET_T_TYPE(EET_T_ULONG_LONG, unsigned_long_long, unsigned long long);
4170 EET_T_TYPE(EET_T_STRING, string, char *);
4171 EET_T_TYPE(EET_T_INLINED_STRING, inlined_string, char *);
4174 return eet_node_null_new(name);
4177 ERR("Unknow type passed to eet_data_node_simple_type");
4180 } /* eet_data_node_simple_type */
4183 eet_data_get_unknown(Eet_Free_Context *context,
4184 const Eet_Dictionary *ed,
4185 Eet_Data_Descriptor *edd,
4186 Eet_Data_Element *ede,
4187 Eet_Data_Chunk *echnk,
4189 int group_type __UNUSED__,
4191 char **p __UNUSED__,
4192 int *size __UNUSED__)
4197 if (IS_SIMPLE_TYPE(type))
4199 unsigned char dd[128];
4201 ret = eet_data_get_type(ed,
4204 ((char *)echnk->data) + echnk->size,
4205 edd ? (char *)data : (char *)dd);
4211 Eet_Node **parent = data;
4214 node = eet_data_node_simple_type(type, echnk->name, dd);
4217 eet_node_struct_append(*parent, echnk->name, node);
4223 if (type == EET_T_STRING)
4227 str = (char **)(((char *)data));
4230 if ((!ed) || (!edd->func.str_direct_alloc))
4232 *str = edd->func.str_alloc(*str);
4233 _eet_freelist_str_add(context, *str);
4237 *str = edd->func.str_direct_alloc(*str);
4238 _eet_freelist_direct_str_add(context, *str);
4242 else if (edd && type == EET_T_INLINED_STRING)
4246 str = (char **)(((char *)data));
4249 *str = edd->func.str_alloc(*str);
4250 _eet_freelist_str_add(context, *str);
4257 Eet_Data_Descriptor *subtype;
4259 subtype = ede ? ede->subtype : NULL;
4261 if (subtype || !edd)
4263 Eet_Node **parent = data;
4266 data_ret = _eet_data_descriptor_decode(context,
4277 ptr = (void **)(((char *)data));
4278 *ptr = (void *)data_ret;
4282 Eet_Node *node = data_ret;
4286 node = eet_node_struct_child_new(echnk->name, node);
4287 eet_node_struct_append(*parent, echnk->name, node);
4296 } /* eet_data_get_unknown */
4299 eet_data_put_array(Eet_Dictionary *ed,
4300 Eet_Data_Descriptor *edd __UNUSED__,
4301 Eet_Data_Element *ede,
4302 Eet_Data_Stream *ds,
4312 EET_ASSERT(!((ede->type > EET_T_UNKNOW) && (ede->type < EET_T_STRING)),
4315 if (ede->group_type == EET_G_ARRAY)
4316 count = ede->counter_offset;
4318 count = *(int *)(((char *)data_in) + ede->count - ede->offset);
4321 return; /* Store number of elements */
4323 data = eet_data_put_type(ed, EET_T_INT, &count, &size);
4325 eet_data_encode(ed, ds, data, ede->name, size, ede->type, ede->group_type);
4327 if (IS_POINTER_TYPE(ede->type))
4328 subsize = eet_basic_codec[ede->type].size;
4330 subsize = ede->subtype->size;
4332 for (j = 0; j < count; j++)
4337 if (ede->group_type == EET_G_ARRAY)
4338 d = (void *)(((char *)data_in) + offset);
4340 d = *(((char **)data_in)) + offset;
4342 if (IS_POINTER_TYPE(ede->type))
4345 eet_data_put_unknown(ed, NULL, ede, ds, d);
4349 data = _eet_data_descriptor_encode(ed, ede->subtype, d, &size);
4361 /* Add a NULL element just to have the correct array layout. */
4372 } /* eet_data_put_array */
4375 eet_data_put_unknown(Eet_Dictionary *ed,
4376 Eet_Data_Descriptor *edd __UNUSED__,
4377 Eet_Data_Element *ede,
4378 Eet_Data_Stream *ds,
4384 if (IS_SIMPLE_TYPE(ede->type))
4385 data = eet_data_put_type(ed, ede->type, data_in, &size);
4386 else if (ede->subtype)
4387 if (*((char **)data_in))
4388 data = _eet_data_descriptor_encode(ed,
4390 *((char **)((char *)(data_in))),
4401 } /* eet_data_put_unknown */
4404 eet_data_put_list(Eet_Dictionary *ed,
4405 Eet_Data_Descriptor *edd,
4406 Eet_Data_Element *ede,
4407 Eet_Data_Stream *ds,
4414 EET_ASSERT(!(((ede->type > EET_T_UNKNOW) && (ede->type < EET_T_STRING))
4415 || ((ede->type > EET_T_NULL) && (ede->type < EET_T_LAST))),
4418 l = *((void **)(((char *)data_in)));
4419 for (; l; l = edd->func.list_next(l))
4421 if (IS_POINTER_TYPE(ede->type))
4423 const void *str = edd->func.list_data(l);
4424 eet_data_put_unknown(ed, NULL, ede, ds, &str);
4428 data = _eet_data_descriptor_encode(ed,
4430 edd->func.list_data(l),
4442 } /* eet_data_put_list */
4445 eet_data_put_hash(Eet_Dictionary *ed,
4446 Eet_Data_Descriptor *edd,
4447 Eet_Data_Element *ede,
4448 Eet_Data_Stream *ds,
4451 Eet_Data_Encode_Hash_Info fdata;
4454 l = *((void **)(((char *)data_in)));
4458 edd->func.hash_foreach(l, eet_data_descriptor_encode_hash_cb, &fdata);
4459 } /* eet_data_put_hash */
4462 eet_data_dump_cipher(Eet_File *ef,
4464 const char *cipher_key,
4465 Eet_Dump_Callback dumpfunc,
4468 const Eet_Dictionary *ed = NULL;
4469 const void *data = NULL;
4471 Eet_Free_Context context;
4472 int required_free = 0;
4475 ed = eet_dictionary_get(ef);
4478 data = eet_read_direct(ef, name, &size);
4483 data = eet_read_cipher(ef, name, &size, cipher_key);
4488 eet_free_context_init(&context);
4489 result = _eet_data_descriptor_decode(&context, ed, NULL, data, size, NULL, 0);
4490 eet_free_context_shutdown(&context);
4492 eet_node_dump(result, 0, dumpfunc, dumpdata);
4494 eet_node_del(result);
4499 return result ? 1 : 0;
4500 } /* eet_data_dump_cipher */
4503 eet_data_dump(Eet_File *ef,
4505 Eet_Dump_Callback dumpfunc,
4508 return eet_data_dump_cipher(ef, name, NULL, dumpfunc, dumpdata);
4509 } /* eet_data_dump */
4512 eet_data_text_dump_cipher(const void *data_in,
4513 const char *cipher_key,
4515 Eet_Dump_Callback dumpfunc,
4520 Eet_Free_Context context;
4521 unsigned int ret_len = 0;
4528 if (eet_decipher(data_in, size_in, cipher_key,
4529 strlen(cipher_key), &ret, &ret_len))
4539 ret = (void *)data_in;
4543 eet_free_context_init(&context);
4544 result = _eet_data_descriptor_decode(&context, NULL, NULL, ret, ret_len, NULL, 0);
4545 eet_free_context_shutdown(&context);
4547 eet_node_dump(result, 0, dumpfunc, dumpdata);
4549 eet_node_del(result);
4553 return result ? 1 : 0;
4554 } /* eet_data_text_dump_cipher */
4557 eet_data_text_dump(const void *data_in,
4559 Eet_Dump_Callback dumpfunc,
4562 return eet_data_text_dump_cipher(data_in, NULL, size_in, dumpfunc, dumpdata);
4563 } /* eet_data_text_dump */
4566 eet_data_text_undump_cipher(const char *text,
4567 const char *cipher_key,
4573 ret = _eet_data_dump_parse(NULL, size_ret, text, textlen);
4574 if (ret && cipher_key)
4576 void *ciphered = NULL;
4577 unsigned int ciphered_len;
4579 if (eet_cipher(ret, *size_ret, cipher_key,
4580 strlen(cipher_key), &ciphered, &ciphered_len))
4591 *size_ret = ciphered_len;
4596 } /* eet_data_text_undump_cipher */
4599 eet_data_text_undump(const char *text,
4603 return eet_data_text_undump_cipher(text, NULL, textlen, size_ret);
4604 } /* eet_data_text_undump */
4607 eet_data_undump_cipher(Eet_File *ef,
4609 const char *cipher_key,
4619 ed = eet_dictionary_get(ef);
4621 data_enc = _eet_data_dump_parse(ed, &size, text, textlen);
4625 val = eet_write_cipher(ef, name, data_enc, size, compress, cipher_key);
4628 } /* eet_data_undump_cipher */
4631 eet_data_undump(Eet_File *ef,
4637 return eet_data_undump_cipher(ef, name, NULL, text, textlen, compress);
4638 } /* eet_data_undump */
4641 eet_data_descriptor_decode_cipher(Eet_Data_Descriptor *edd,
4642 const void *data_in,
4643 const char *cipher_key,
4646 void *deciphered = (void *)data_in;
4648 Eet_Free_Context context;
4649 unsigned int deciphered_len = size_in;
4651 if (cipher_key && data_in)
4652 if (eet_decipher(data_in, size_in, cipher_key,
4653 strlen(cipher_key), &deciphered, &deciphered_len))
4661 eet_free_context_init(&context);
4662 ret = _eet_data_descriptor_decode(&context,
4668 eet_free_context_shutdown(&context);
4670 if (data_in != deciphered)
4674 } /* eet_data_descriptor_decode_cipher */
4677 eet_data_descriptor_decode(Eet_Data_Descriptor *edd,
4678 const void *data_in,
4681 return eet_data_descriptor_decode_cipher(edd, data_in, NULL, size_in);
4682 } /* eet_data_descriptor_decode */
4685 eet_data_node_decode_cipher(const void *data_in,
4686 const char *cipher_key,
4689 void *deciphered = (void *)data_in;
4691 Eet_Free_Context context;
4692 unsigned int deciphered_len = size_in;
4694 if (cipher_key && data_in)
4695 if (eet_decipher(data_in, size_in, cipher_key,
4696 strlen(cipher_key), &deciphered, &deciphered_len))
4704 eet_free_context_init(&context);
4705 ret = _eet_data_descriptor_decode(&context,
4711 eet_free_context_shutdown(&context);
4713 if (data_in != deciphered)
4717 } /* eet_data_node_decode_cipher */
4720 _eet_data_descriptor_encode(Eet_Dictionary *ed,
4721 Eet_Data_Descriptor *edd,
4722 const void *data_in,
4725 Eet_Data_Stream *ds;
4726 Eet_Data_Chunk *chnk;
4731 if (_eet_data_words_bigendian == -1)
4733 unsigned long int v;
4735 v = htonl(0x12345678);
4736 if (v == 0x12345678)
4737 _eet_data_words_bigendian = 1;
4739 _eet_data_words_bigendian = 0;
4742 ds = eet_data_stream_new();
4743 for (i = 0; i < edd->elements.num; i++)
4745 Eet_Data_Element *ede;
4747 ede = &(edd->elements.set[i]);
4748 eet_group_codec[ede->group_type - 100].put(
4756 chnk = eet_data_chunk_new(ds->data,
4763 eet_data_stream_free(ds);
4765 ds = eet_data_stream_new();
4766 eet_data_chunk_put(ed, chnk, ds);
4772 eet_data_stream_free(ds);
4776 eet_data_chunk_free(chnk);
4779 } /* _eet_data_descriptor_encode */
4782 eet_data_node_write_cipher(Eet_File *ef,
4784 const char *cipher_key,
4793 ed = eet_dictionary_get(ef);
4795 data_enc = _eet_data_dump_encode(EET_G_UNKNOWN, ed, node, &size);
4799 val = eet_write_cipher(ef, name, data_enc, size, compress, cipher_key);
4802 } /* eet_data_node_write_cipher */
4805 eet_data_node_encode_cipher(Eet_Node *node,
4806 const char *cipher_key,
4810 void *ciphered = NULL;
4811 unsigned int ciphered_len = 0;
4814 ret = _eet_data_dump_encode(EET_G_UNKNOWN, NULL, node, &size);
4815 if (cipher_key && ret)
4817 if (eet_cipher(ret, size, cipher_key,
4818 strlen(cipher_key), &ciphered, &ciphered_len))
4831 size = (int)ciphered_len;
4839 } /* eet_data_node_encode_cipher */
4842 eet_data_descriptor_encode_cipher(Eet_Data_Descriptor *edd,
4843 const void *data_in,
4844 const char *cipher_key,
4848 void *ciphered = NULL;
4849 unsigned int ciphered_len = 0;
4852 ret = _eet_data_descriptor_encode(NULL, edd, data_in, &size);
4853 if (cipher_key && ret)
4855 if (eet_cipher(ret, size, cipher_key,
4856 strlen(cipher_key), &ciphered, &ciphered_len))
4869 size = ciphered_len;
4877 } /* eet_data_descriptor_encode_cipher */
4880 eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
4881 const void *data_in,
4884 return eet_data_descriptor_encode_cipher(edd, data_in, NULL, size_ret);
4885 } /* eet_data_descriptor_encode */