2008-03-07 23:28:12 -08:00
|
|
|
/*
|
|
|
|
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
|
|
|
*/
|
|
|
|
|
2008-03-28 10:17:43 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2008-04-03 12:47:07 -07:00
|
|
|
#if HAVE___ATTRIBUTE__
|
2009-11-02 00:41:43 -08:00
|
|
|
# define __UNUSED__ __attribute__((unused))
|
2008-04-03 12:47:07 -07:00
|
|
|
#else
|
2009-11-02 00:41:43 -08:00
|
|
|
# define __UNUSED__
|
2008-04-03 12:47:07 -07:00
|
|
|
#endif
|
|
|
|
|
2008-03-28 10:17:43 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2007-09-25 11:26:49 -07:00
|
|
|
#include <math.h>
|
2008-03-28 10:17:43 -07:00
|
|
|
#include <ctype.h>
|
2008-07-17 13:28:59 -07:00
|
|
|
#include <limits.h>
|
2007-09-25 11:26:49 -07:00
|
|
|
|
2008-03-28 10:17:43 -07:00
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
# include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
|
2008-04-09 01:27:17 -07:00
|
|
|
#if defined(_WIN32) && ! defined(__CEGCC__)
|
2008-03-28 10:17:43 -07:00
|
|
|
# include <winsock2.h>
|
2008-03-07 23:28:12 -08:00
|
|
|
#endif
|
|
|
|
|
2008-10-20 02:44:34 -07:00
|
|
|
#include <Eina.h>
|
|
|
|
|
2008-01-27 05:17:22 -08:00
|
|
|
#include "Eet.h"
|
2008-02-29 22:38:09 -08:00
|
|
|
#include "Eet_private.h"
|
2002-12-02 15:39:26 -08:00
|
|
|
|
|
|
|
/*
|
2006-12-15 12:16:29 -08:00
|
|
|
* routines for doing data -> struct and struct -> data conversion
|
2005-05-22 21:32:04 -07:00
|
|
|
*
|
2002-12-02 15:39:26 -08:00
|
|
|
* types:
|
2005-05-22 21:32:04 -07:00
|
|
|
*
|
2002-12-02 15:39:26 -08:00
|
|
|
* basic types:
|
|
|
|
* a sequence of...
|
2005-05-22 21:32:04 -07:00
|
|
|
*
|
2002-12-02 15:39:26 -08:00
|
|
|
* char
|
|
|
|
* short
|
|
|
|
* int
|
|
|
|
* long long
|
|
|
|
* float
|
|
|
|
* double
|
|
|
|
* unsigned char
|
|
|
|
* unsigned short
|
|
|
|
* unsigned int
|
|
|
|
* unsgined long long
|
|
|
|
* string
|
2005-05-22 21:32:04 -07:00
|
|
|
*
|
2002-12-02 15:39:26 -08:00
|
|
|
* groupings:
|
|
|
|
* multiple entries ordered as...
|
2005-05-22 21:32:04 -07:00
|
|
|
*
|
2002-12-02 15:39:26 -08:00
|
|
|
* fixed size array [ of basic types ]
|
|
|
|
* variable size array [ of basic types ]
|
|
|
|
* linked list [ of basic types ]
|
|
|
|
* hash table [ of basic types ]
|
2005-05-22 21:32:04 -07:00
|
|
|
*
|
2002-12-02 15:39:26 -08:00
|
|
|
* need to provide builder/accessor funcs for:
|
2005-05-22 21:32:04 -07:00
|
|
|
*
|
2002-12-02 15:39:26 -08:00
|
|
|
* list_next
|
|
|
|
* list_append
|
2005-05-22 21:32:04 -07:00
|
|
|
*
|
2002-12-02 15:39:26 -08:00
|
|
|
* hash_foreach
|
|
|
|
* hash_add
|
2005-05-22 21:32:04 -07:00
|
|
|
*
|
2002-12-02 15:39:26 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*---*/
|
|
|
|
|
|
|
|
typedef struct _Eet_Data_Element Eet_Data_Element;
|
2008-06-26 08:47:25 -07:00
|
|
|
typedef struct _Eet_Data_Basic_Type_Codec Eet_Data_Basic_Type_Codec;
|
|
|
|
typedef struct _Eet_Data_Group_Type_Codec Eet_Data_Group_Type_Codec;
|
2002-12-02 15:39:26 -08:00
|
|
|
typedef struct _Eet_Data_Chunk Eet_Data_Chunk;
|
|
|
|
typedef struct _Eet_Data_Stream Eet_Data_Stream;
|
2005-05-25 20:57:57 -07:00
|
|
|
typedef struct _Eet_Data_Descriptor_Hash Eet_Data_Descriptor_Hash;
|
2006-12-17 03:00:45 -08:00
|
|
|
typedef struct _Eet_Data_Encode_Hash_Info Eet_Data_Encode_Hash_Info;
|
2009-03-19 12:00:46 -07:00
|
|
|
typedef struct _Eet_Free Eet_Free;
|
|
|
|
typedef struct _Eet_Free_Context Eet_Free_Context;
|
2002-12-02 15:39:26 -08:00
|
|
|
|
|
|
|
/*---*/
|
|
|
|
|
2008-06-26 08:47:25 -07:00
|
|
|
/* TODO:
|
|
|
|
* Eet_Data_Basic_Type_Codec (Coder, Decoder)
|
|
|
|
* Eet_Data_Group_Type_Codec (Coder, Decoder)
|
|
|
|
*/
|
|
|
|
struct _Eet_Data_Basic_Type_Codec
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2008-05-15 07:14:35 -07:00
|
|
|
int size;
|
|
|
|
const char *name;
|
|
|
|
int (*get) (const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
|
|
|
|
void *(*put) (Eet_Dictionary *ed, const void *src, int *size_ret);
|
2002-12-02 15:39:26 -08:00
|
|
|
};
|
|
|
|
|
2008-06-26 08:47:25 -07:00
|
|
|
struct _Eet_Data_Group_Type_Codec
|
|
|
|
{
|
2009-03-19 12:00:46 -07:00
|
|
|
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, int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata, char **p, int *size);
|
2008-06-26 08:47:25 -07:00
|
|
|
void (*put) (Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in);
|
|
|
|
};
|
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
struct _Eet_Data_Chunk
|
|
|
|
{
|
2007-09-08 00:44:03 -07:00
|
|
|
char *name;
|
2008-02-29 22:38:09 -08:00
|
|
|
int len;
|
2007-09-08 00:44:03 -07:00
|
|
|
int size;
|
2008-07-17 08:33:40 -07:00
|
|
|
int hash;
|
2007-09-08 00:44:03 -07:00
|
|
|
void *data;
|
|
|
|
unsigned char type;
|
|
|
|
unsigned char group_type;
|
2002-12-02 15:39:26 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _Eet_Data_Stream
|
|
|
|
{
|
|
|
|
void *data;
|
|
|
|
int size;
|
|
|
|
int pos;
|
|
|
|
};
|
|
|
|
|
2005-05-25 20:57:57 -07:00
|
|
|
struct _Eet_Data_Descriptor_Hash
|
|
|
|
{
|
|
|
|
Eet_Data_Element *element;
|
|
|
|
Eet_Data_Descriptor_Hash *next;
|
|
|
|
};
|
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
struct _Eet_Data_Descriptor
|
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
const char *name;
|
2008-07-18 04:39:38 -07:00
|
|
|
const Eet_Dictionary *ed;
|
2008-02-29 22:38:09 -08:00
|
|
|
int size;
|
2002-12-02 15:39:26 -08:00
|
|
|
struct {
|
2005-11-30 07:36:19 -08:00
|
|
|
void *(*mem_alloc) (size_t size);
|
|
|
|
void (*mem_free) (void *mem);
|
|
|
|
char *(*str_alloc) (const char *str);
|
2008-02-29 22:38:09 -08:00
|
|
|
char *(*str_direct_alloc) (const char *str);
|
2005-11-30 07:36:19 -08:00
|
|
|
void (*str_free) (const char *str);
|
2008-02-29 22:38:09 -08:00
|
|
|
void (*str_direct_free) (const char *str);
|
2002-12-02 15:39:26 -08:00
|
|
|
void *(*list_next) (void *l);
|
|
|
|
void *(*list_append) (void *l, void *d);
|
|
|
|
void *(*list_data) (void *l);
|
2003-07-07 00:52:20 -07:00
|
|
|
void *(*list_free) (void *l);
|
2002-12-02 15:39:26 -08:00
|
|
|
void (*hash_foreach) (void *h, int (*func) (void *h, const char *k, void *dt, void *fdt), void *fdt);
|
|
|
|
void *(*hash_add) (void *h, const char *k, void *d);
|
2003-07-07 00:52:20 -07:00
|
|
|
void (*hash_free) (void *h);
|
2002-12-02 15:39:26 -08:00
|
|
|
} func;
|
|
|
|
struct {
|
2008-02-29 22:38:09 -08:00
|
|
|
int num;
|
|
|
|
Eet_Data_Element *set;
|
2005-05-25 20:57:57 -07:00
|
|
|
struct {
|
2008-02-29 22:38:09 -08:00
|
|
|
int size;
|
|
|
|
Eet_Data_Descriptor_Hash *buckets;
|
2005-05-25 20:57:57 -07:00
|
|
|
} hash;
|
2002-12-02 15:39:26 -08:00
|
|
|
} elements;
|
2005-11-27 08:06:55 -08:00
|
|
|
// char *strings;
|
|
|
|
// int strings_len;
|
2002-12-02 15:39:26 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _Eet_Data_Element
|
|
|
|
{
|
2005-11-29 03:32:10 -08:00
|
|
|
const char *name;
|
|
|
|
const char *counter_name;
|
2008-07-18 04:39:38 -07:00
|
|
|
const char *directory_name_ptr;
|
2002-12-02 15:39:26 -08:00
|
|
|
Eet_Data_Descriptor *subtype;
|
2008-06-26 08:47:25 -07:00
|
|
|
int offset; /* offset in bytes from the base element */
|
|
|
|
int count; /* number of elements for a fixed array */
|
|
|
|
int counter_offset; /* for a variable array we need the offset of the count variable */
|
|
|
|
unsigned char type; /* EET_T_XXX */
|
|
|
|
unsigned char group_type; /* EET_G_XXX */
|
2002-12-02 15:39:26 -08:00
|
|
|
};
|
|
|
|
|
2006-12-17 03:00:45 -08:00
|
|
|
struct _Eet_Data_Encode_Hash_Info
|
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
Eet_Data_Stream *ds;
|
|
|
|
Eet_Data_Element *ede;
|
|
|
|
Eet_Dictionary *ed;
|
2006-12-17 03:00:45 -08:00
|
|
|
};
|
|
|
|
|
2009-03-19 12:00:46 -07:00
|
|
|
struct _Eet_Free
|
|
|
|
{
|
|
|
|
int ref;
|
|
|
|
int len[256];
|
|
|
|
int num[256];
|
|
|
|
void **list[256];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _Eet_Free_Context
|
|
|
|
{
|
|
|
|
Eet_Free freelist;
|
|
|
|
Eet_Free freelist_list;
|
|
|
|
Eet_Free freelist_hash;
|
|
|
|
Eet_Free freelist_str;
|
|
|
|
Eet_Free freelist_direct_str;
|
|
|
|
};
|
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
/*---*/
|
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
static int eet_data_get_char(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
|
|
|
|
static void *eet_data_put_char(Eet_Dictionary *ed, const void *src, int *size_ret);
|
|
|
|
static int eet_data_get_short(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
|
|
|
|
static void *eet_data_put_short(Eet_Dictionary *ed, const void *src, int *size_ret);
|
2008-09-11 04:26:09 -07:00
|
|
|
static inline int eet_data_get_int(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
|
2008-02-29 22:38:09 -08:00
|
|
|
static void *eet_data_put_int(Eet_Dictionary *ed, const void *src, int *size_ret);
|
|
|
|
static int eet_data_get_long_long(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
|
|
|
|
static void *eet_data_put_long_long(Eet_Dictionary *ed, const void *src, int *size_ret);
|
|
|
|
static int eet_data_get_float(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
|
|
|
|
static void *eet_data_put_float(Eet_Dictionary *ed, const void *src, int *size_ret);
|
|
|
|
static int eet_data_get_double(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
|
|
|
|
static void *eet_data_put_double(Eet_Dictionary *ed, const void *src, int *size_ret);
|
2009-09-29 06:24:45 -07:00
|
|
|
static int eet_data_get_f32p32(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
|
|
|
|
static void *eet_data_put_f32p32(Eet_Dictionary *ed, const void *src, int *size_ret);
|
|
|
|
static int eet_data_get_f16p16(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
|
|
|
|
static void *eet_data_put_f16p16(Eet_Dictionary *ed, const void *src, int *size_ret);
|
|
|
|
static int eet_data_get_f8p24(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
|
|
|
|
static void *eet_data_put_f8p24(Eet_Dictionary *ed, const void *src, int *size_ret);
|
2008-09-11 04:26:09 -07:00
|
|
|
static inline int eet_data_get_string(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
|
2008-02-29 22:38:09 -08:00
|
|
|
static void *eet_data_put_string(Eet_Dictionary *ed, const void *src, int *size_ret);
|
|
|
|
static int eet_data_get_istring(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
|
|
|
|
static void *eet_data_put_istring(Eet_Dictionary *ed, const void *src, int *size_ret);
|
2008-10-24 07:06:40 -07:00
|
|
|
static int eet_data_get_null(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
|
|
|
|
static void *eet_data_put_null(Eet_Dictionary *ed, const void *src, int *size_ret);
|
2008-02-29 22:38:09 -08:00
|
|
|
|
|
|
|
static int eet_data_get_type(const Eet_Dictionary *ed, int type, const void *src, const void *src_end, void *dest);
|
|
|
|
static void *eet_data_put_type(Eet_Dictionary *ed, int type, const void *src, int *size_ret);
|
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
static void eet_data_dump_group_start(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata, int group_type, const char *name);
|
|
|
|
static void eet_data_dump_group_end(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata);
|
|
|
|
static void eet_data_dump_level(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata);
|
|
|
|
static void eet_data_dump_simple_type(int type, const char *name, void *dd,
|
|
|
|
int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata);
|
|
|
|
|
|
|
|
|
2009-03-19 12:00:46 -07:00
|
|
|
static int eet_data_get_unknown(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, int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata, char **p, int *size);
|
2008-06-26 08:47:25 -07:00
|
|
|
static void eet_data_put_unknown(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in);
|
|
|
|
static void eet_data_put_array(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in);
|
2009-03-19 12:00:46 -07:00
|
|
|
static int eet_data_get_array(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, int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata, char **p, int *size);
|
|
|
|
static int eet_data_get_list(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, int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata, char **p, int *size);
|
2008-06-26 08:47:25 -07:00
|
|
|
static void eet_data_put_list(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in);
|
|
|
|
static void eet_data_put_hash(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in);
|
2009-03-19 12:00:46 -07:00
|
|
|
static int eet_data_get_hash(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, int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata, char **p, int *size);
|
2008-06-26 08:47:25 -07:00
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
static void eet_data_chunk_get(const Eet_Dictionary *ed, Eet_Data_Chunk *chnk, const void *src, int size);
|
2007-09-08 00:44:03 -07:00
|
|
|
static Eet_Data_Chunk *eet_data_chunk_new(void *data, int size, const char *name, int type, int group_type);
|
2002-12-02 15:39:26 -08:00
|
|
|
static void eet_data_chunk_free(Eet_Data_Chunk *chnk);
|
|
|
|
|
|
|
|
static Eet_Data_Stream *eet_data_stream_new(void);
|
2006-11-05 04:14:08 -08:00
|
|
|
static void eet_data_stream_write(Eet_Data_Stream *ds, const void *data, int size);
|
2002-12-02 15:39:26 -08:00
|
|
|
static void eet_data_stream_free(Eet_Data_Stream *ds);
|
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
static void eet_data_chunk_put(Eet_Dictionary *ed, Eet_Data_Chunk *chnk, Eet_Data_Stream *ds);
|
2002-12-02 15:39:26 -08:00
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
static int eet_data_descriptor_encode_hash_cb(void *hash, const char *key, void *hdata, void *fdata);
|
|
|
|
static void *_eet_data_descriptor_encode(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, const void *data_in, int *size_ret);
|
2009-03-19 12:00:46 -07:00
|
|
|
static void *_eet_data_descriptor_decode(Eet_Free_Context *context,
|
|
|
|
const Eet_Dictionary *ed,
|
2008-02-29 22:38:09 -08:00
|
|
|
Eet_Data_Descriptor *edd,
|
|
|
|
const void *data_in,
|
|
|
|
int size_in,
|
|
|
|
int level,
|
|
|
|
void (*dumpfunc) (void *data, const char *str),
|
|
|
|
void *dumpdata);
|
2006-12-17 03:00:45 -08:00
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
/*---*/
|
|
|
|
|
2008-06-26 08:47:25 -07:00
|
|
|
static const Eet_Data_Basic_Type_Codec eet_basic_codec[] =
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2008-05-15 07:16:46 -07:00
|
|
|
{sizeof(char), "char", eet_data_get_char, eet_data_put_char },
|
|
|
|
{sizeof(short), "short", eet_data_get_short, eet_data_put_short },
|
|
|
|
{sizeof(int), "int", eet_data_get_int, eet_data_put_int },
|
|
|
|
{sizeof(long long), "long_long", eet_data_get_long_long, eet_data_put_long_long},
|
|
|
|
{sizeof(float), "float", eet_data_get_float, eet_data_put_float },
|
|
|
|
{sizeof(double), "double", eet_data_get_double, eet_data_put_double },
|
2008-05-15 07:14:35 -07:00
|
|
|
{sizeof(char), "uchar", eet_data_get_char, eet_data_put_char },
|
|
|
|
{sizeof(short), "ushort", eet_data_get_short, eet_data_put_short },
|
|
|
|
{sizeof(int), "uint", eet_data_get_int, eet_data_put_int },
|
|
|
|
{sizeof(long long), "ulong_long", eet_data_get_long_long, eet_data_put_long_long},
|
2008-05-15 07:16:46 -07:00
|
|
|
{sizeof(char *), "string", eet_data_get_string, eet_data_put_string },
|
2008-10-24 07:06:40 -07:00
|
|
|
{sizeof(char *), "inlined", eet_data_get_istring, eet_data_put_istring },
|
2009-09-29 06:24:45 -07:00
|
|
|
{sizeof(void *), "NULL", eet_data_get_null, eet_data_put_null },
|
|
|
|
{sizeof(Eina_F32p32),"f32p32", eet_data_get_f32p32, eet_data_put_f32p32 },
|
|
|
|
{sizeof(Eina_F16p16),"f16p16", eet_data_get_f16p16, eet_data_put_f16p16 },
|
|
|
|
{sizeof(Eina_F8p24),"f8p24", eet_data_get_f8p24, eet_data_put_f8p24 }
|
2002-12-02 15:39:26 -08:00
|
|
|
};
|
|
|
|
|
2008-06-26 08:47:25 -07:00
|
|
|
static const Eet_Data_Group_Type_Codec eet_group_codec[] =
|
|
|
|
{
|
|
|
|
{ eet_data_get_unknown, eet_data_put_unknown },
|
|
|
|
{ eet_data_get_array, eet_data_put_array },
|
|
|
|
{ eet_data_get_array, eet_data_put_array },
|
|
|
|
{ eet_data_get_list, eet_data_put_list },
|
|
|
|
{ eet_data_get_hash, eet_data_put_hash }
|
|
|
|
};
|
|
|
|
|
2009-11-02 00:41:43 -08:00
|
|
|
static int _eet_data_words_bigendian = -1;
|
2002-12-02 15:39:26 -08:00
|
|
|
|
|
|
|
/*---*/
|
|
|
|
|
2004-04-28 18:32:35 -07:00
|
|
|
#define SWAP64(x) (x) = \
|
2004-07-13 11:23:16 -07:00
|
|
|
((((unsigned long long)(x) & 0x00000000000000ffULL ) << 56) |\
|
|
|
|
(((unsigned long long)(x) & 0x000000000000ff00ULL ) << 40) |\
|
|
|
|
(((unsigned long long)(x) & 0x0000000000ff0000ULL ) << 24) |\
|
|
|
|
(((unsigned long long)(x) & 0x00000000ff000000ULL ) << 8) |\
|
|
|
|
(((unsigned long long)(x) & 0x000000ff00000000ULL ) >> 8) |\
|
|
|
|
(((unsigned long long)(x) & 0x0000ff0000000000ULL ) >> 24) |\
|
|
|
|
(((unsigned long long)(x) & 0x00ff000000000000ULL ) >> 40) |\
|
|
|
|
(((unsigned long long)(x) & 0xff00000000000000ULL ) >> 56))
|
2004-04-28 18:32:35 -07:00
|
|
|
#define SWAP32(x) (x) = \
|
2004-04-20 23:38:37 -07:00
|
|
|
((((int)(x) & 0x000000ff ) << 24) |\
|
|
|
|
(((int)(x) & 0x0000ff00 ) << 8) |\
|
|
|
|
(((int)(x) & 0x00ff0000 ) >> 8) |\
|
|
|
|
(((int)(x) & 0xff000000 ) >> 24))
|
2004-04-28 18:32:35 -07:00
|
|
|
#define SWAP16(x) (x) = \
|
2004-04-20 23:38:37 -07:00
|
|
|
((((short)(x) & 0x00ff ) << 8) |\
|
|
|
|
(((short)(x) & 0xff00 ) >> 8))
|
2002-12-02 15:39:26 -08:00
|
|
|
|
2009-11-02 00:41:43 -08:00
|
|
|
#ifdef CONV8
|
|
|
|
# undef CONV8
|
|
|
|
#endif
|
|
|
|
#ifdef CONV16
|
|
|
|
# undef CONV16
|
|
|
|
#endif
|
|
|
|
#ifdef CONV32
|
|
|
|
# undef CONV32
|
|
|
|
#endif
|
|
|
|
#ifdef CONV64
|
|
|
|
# undef CONV64
|
|
|
|
#endif
|
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
#define CONV8(x)
|
2009-11-02 00:41:43 -08:00
|
|
|
#define CONV16(x) {if (_eet_data_words_bigendian) SWAP16(x);}
|
|
|
|
#define CONV32(x) {if (_eet_data_words_bigendian) SWAP32(x);}
|
|
|
|
#define CONV64(x) {if (_eet_data_words_bigendian) SWAP64(x);}
|
2002-12-02 15:39:26 -08:00
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
#define IS_SIMPLE_TYPE(Type) (Type > EET_T_UNKNOW && Type < EET_T_LAST)
|
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
/*---*/
|
|
|
|
|
|
|
|
/* CHAR TYPE */
|
|
|
|
static int
|
2008-04-03 12:47:07 -07:00
|
|
|
eet_data_get_char(const Eet_Dictionary *ed __UNUSED__, const void *src, const void *src_end, void *dst)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
|
|
|
char *s, *d;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2004-04-28 18:32:35 -07:00
|
|
|
if (((char *)src + sizeof(char)) > (char *)src_end) return -1;
|
2002-12-02 15:39:26 -08:00
|
|
|
s = (char *)src;
|
|
|
|
d = (char *)dst;
|
2002-12-20 14:00:44 -08:00
|
|
|
*d = *s;
|
|
|
|
CONV8(*d);
|
2002-12-02 15:39:26 -08:00
|
|
|
return sizeof(char);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
2008-04-03 12:47:07 -07:00
|
|
|
eet_data_put_char(Eet_Dictionary *ed __UNUSED__, const void *src, int *size_ret)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
|
|
|
char *s, *d;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
d = (char *)malloc(sizeof(char));
|
|
|
|
if (!d) return NULL;
|
|
|
|
s = (char *)src;
|
|
|
|
*d = *s;
|
|
|
|
CONV8(*d);
|
|
|
|
*size_ret = sizeof(char);
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SHORT TYPE */
|
|
|
|
static int
|
2008-04-03 12:47:07 -07:00
|
|
|
eet_data_get_short(const Eet_Dictionary *ed __UNUSED__, const void *src, const void *src_end, void *dst)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2003-07-10 16:18:42 -07:00
|
|
|
short *d;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2004-04-28 18:32:35 -07:00
|
|
|
if (((char *)src + sizeof(short)) > (char *)src_end) return -1;
|
2003-07-10 16:18:42 -07:00
|
|
|
memcpy(dst, src, sizeof(short));
|
2002-12-02 15:39:26 -08:00
|
|
|
d = (short *)dst;
|
|
|
|
CONV16(*d);
|
|
|
|
return sizeof(short);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
2008-04-03 12:47:07 -07:00
|
|
|
eet_data_put_short(Eet_Dictionary *ed __UNUSED__, const void *src, int *size_ret)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
|
|
|
short *s, *d;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
d = (short *)malloc(sizeof(short));
|
|
|
|
if (!d) return NULL;
|
|
|
|
s = (short *)src;
|
|
|
|
*d = *s;
|
|
|
|
CONV16(*d);
|
|
|
|
*size_ret = sizeof(short);
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* INT TYPE */
|
2008-09-11 04:26:09 -07:00
|
|
|
static inline int
|
2008-04-03 12:47:07 -07:00
|
|
|
eet_data_get_int(const Eet_Dictionary *ed __UNUSED__, const void *src, const void *src_end, void *dst)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2003-07-10 16:18:42 -07:00
|
|
|
int *d;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2004-04-28 18:32:35 -07:00
|
|
|
if (((char *)src + sizeof(int)) > (char *)src_end) return -1;
|
2003-07-10 16:18:42 -07:00
|
|
|
memcpy(dst, src, sizeof(int));
|
2002-12-02 15:39:26 -08:00
|
|
|
d = (int *)dst;
|
|
|
|
CONV32(*d);
|
|
|
|
return sizeof(int);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
2008-04-03 12:47:07 -07:00
|
|
|
eet_data_put_int(Eet_Dictionary *ed __UNUSED__, const void *src, int *size_ret)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
|
|
|
int *s, *d;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
d = (int *)malloc(sizeof(int));
|
|
|
|
if (!d) return NULL;
|
|
|
|
s = (int *)src;
|
|
|
|
*d = *s;
|
|
|
|
CONV32(*d);
|
|
|
|
*size_ret = sizeof(int);
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* LONG LONG TYPE */
|
|
|
|
static int
|
2008-04-03 12:47:07 -07:00
|
|
|
eet_data_get_long_long(const Eet_Dictionary *ed __UNUSED__, const void *src, const void *src_end, void *dst)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2004-04-20 23:38:37 -07:00
|
|
|
unsigned long long *d;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2004-04-28 18:32:35 -07:00
|
|
|
if (((char *)src + sizeof(unsigned long long)) > (char *)src_end) return -1;
|
2004-04-20 23:38:37 -07:00
|
|
|
memcpy(dst, src, sizeof(unsigned long long));
|
|
|
|
d = (unsigned long long *)dst;
|
2002-12-02 15:39:26 -08:00
|
|
|
CONV64(*d);
|
2004-04-20 23:38:37 -07:00
|
|
|
return sizeof(unsigned long long);
|
2002-12-02 15:39:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
2008-04-03 12:47:07 -07:00
|
|
|
eet_data_put_long_long(Eet_Dictionary *ed __UNUSED__, const void *src, int *size_ret)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2004-04-20 23:38:37 -07:00
|
|
|
unsigned long long *s, *d;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2004-04-20 23:38:37 -07:00
|
|
|
d = (unsigned long long *)malloc(sizeof(unsigned long long));
|
2002-12-02 15:39:26 -08:00
|
|
|
if (!d) return NULL;
|
2004-04-20 23:38:37 -07:00
|
|
|
s = (unsigned long long *)src;
|
2002-12-02 15:39:26 -08:00
|
|
|
*d = *s;
|
|
|
|
CONV64(*d);
|
2004-04-20 23:38:37 -07:00
|
|
|
*size_ret = sizeof(unsigned long long);
|
2002-12-02 15:39:26 -08:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* STRING TYPE */
|
2008-09-11 04:26:09 -07:00
|
|
|
static inline int
|
2008-07-17 08:33:40 -07:00
|
|
|
eet_data_get_string_hash(const Eet_Dictionary *ed, const void *src, const void *src_end)
|
|
|
|
{
|
|
|
|
if (ed)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
if (eet_data_get_int(ed, src, src_end, &index) < 0) return -1;
|
|
|
|
|
|
|
|
return eet_dictionary_string_get_hash(ed, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-09-11 04:26:09 -07:00
|
|
|
static inline int
|
2008-02-29 22:38:09 -08:00
|
|
|
eet_data_get_string(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dst)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
char *s, **d;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
d = (char **)dst;
|
2008-02-29 22:38:09 -08:00
|
|
|
|
|
|
|
if (ed)
|
|
|
|
{
|
|
|
|
const char *str;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
if (eet_data_get_int(ed, src, src_end, &index) < 0) return -1;
|
|
|
|
|
|
|
|
str = eet_dictionary_string_get_char(ed, index);
|
|
|
|
if (str == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*d = (char *) str;
|
|
|
|
return eet_dictionary_string_get_size(ed, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
s = (char *)src;
|
|
|
|
if (s == NULL)
|
2005-11-23 04:55:43 -08:00
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
*d = NULL;
|
|
|
|
return 0;
|
2005-11-23 04:55:43 -08:00
|
|
|
}
|
2008-02-29 22:38:09 -08:00
|
|
|
|
|
|
|
*d = s;
|
|
|
|
return strlen(s) + 1;
|
2002-12-02 15:39:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
2008-02-29 22:38:09 -08:00
|
|
|
eet_data_put_string(Eet_Dictionary *ed, const void *src, int *size_ret)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
|
|
|
char *s, *d;
|
|
|
|
int len;
|
2008-02-29 22:38:09 -08:00
|
|
|
|
|
|
|
if (ed)
|
|
|
|
{
|
|
|
|
const char *str;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
str = *((const char **) src);
|
|
|
|
if (!str) return NULL;
|
|
|
|
|
|
|
|
index = eet_dictionary_string_add(ed, str);
|
|
|
|
if (index == -1) return NULL;
|
|
|
|
|
|
|
|
return eet_data_put_int(ed, &index, size_ret);
|
|
|
|
}
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
s = (char *)(*((char **)src));
|
2005-11-23 04:55:43 -08:00
|
|
|
if (!s) return NULL;
|
2002-12-02 15:39:26 -08:00
|
|
|
len = strlen(s);
|
|
|
|
d = malloc(len + 1);
|
|
|
|
if (!d) return NULL;
|
2008-05-19 08:25:46 -07:00
|
|
|
memcpy(d, s, len + 1);
|
2002-12-02 15:39:26 -08:00
|
|
|
*size_ret = len + 1;
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
/* ALWAYS INLINED STRING TYPE */
|
|
|
|
static int
|
2008-04-03 12:47:07 -07:00
|
|
|
eet_data_get_istring(const Eet_Dictionary *ed __UNUSED__, const void *src, const void *src_end, void *dst)
|
2008-02-29 22:38:09 -08:00
|
|
|
{
|
|
|
|
return eet_data_get_string(NULL, src, src_end, dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
2008-04-03 12:47:07 -07:00
|
|
|
eet_data_put_istring(Eet_Dictionary *ed __UNUSED__, const void *src, int *size_ret)
|
2008-02-29 22:38:09 -08:00
|
|
|
{
|
|
|
|
return eet_data_put_string(NULL, src, size_ret);
|
|
|
|
}
|
|
|
|
|
2008-10-24 07:06:40 -07:00
|
|
|
/* ALWAYS NULL TYPE */
|
|
|
|
static int
|
|
|
|
eet_data_get_null(const Eet_Dictionary *ed __UNUSED__, const void *src __UNUSED__, const void *src_end __UNUSED__, void *dst)
|
|
|
|
{
|
|
|
|
char **d;
|
|
|
|
|
|
|
|
d = (char**) dst;
|
|
|
|
|
|
|
|
*d = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
eet_data_put_null(Eet_Dictionary *ed __UNUSED__, const void *src __UNUSED__, int *size_ret)
|
|
|
|
{
|
|
|
|
*size_ret = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-10-03 07:28:07 -07:00
|
|
|
/**
|
|
|
|
* Fast lookups of simple doubles/floats.
|
|
|
|
*
|
|
|
|
* These aren't properly a cache because they don't store pre-calculated
|
|
|
|
* values, but have a so simple math that is almost as fast.
|
|
|
|
*/
|
|
|
|
static inline int
|
2008-02-29 22:38:09 -08:00
|
|
|
_eet_data_float_cache_get(const char *s, int len, float *d)
|
2007-10-03 07:28:07 -07:00
|
|
|
{
|
|
|
|
/* fast handle of simple case 0xMp+E*/
|
|
|
|
if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
|
|
|
|
{
|
|
|
|
int mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
|
|
|
|
int exponent = (s[5] - '0');
|
|
|
|
|
|
|
|
if (s[4] == '+') *d = (float)(mantisse << exponent);
|
|
|
|
else *d = (float)mantisse / (float)(1 << exponent);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
2008-02-29 22:38:09 -08:00
|
|
|
_eet_data_double_cache_get(const char *s, int len, double *d)
|
2007-10-03 07:28:07 -07:00
|
|
|
{
|
|
|
|
/* fast handle of simple case 0xMp+E*/
|
|
|
|
if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
|
|
|
|
{
|
|
|
|
int mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
|
|
|
|
int exponent = (s[5] - '0');
|
|
|
|
|
|
|
|
if (s[4] == '+') *d = (double)(mantisse << exponent);
|
|
|
|
else *d = (double)mantisse / (double)(1 << exponent);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
/* FLOAT TYPE */
|
|
|
|
static int
|
2008-02-29 22:38:09 -08:00
|
|
|
eet_data_get_float(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dst)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
float *d;
|
|
|
|
int index;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
d = (float *) dst;
|
|
|
|
if (!ed)
|
|
|
|
{
|
|
|
|
const char *s, *p;
|
|
|
|
long long mantisse;
|
|
|
|
long exponent;
|
|
|
|
int len;
|
2007-10-02 17:08:41 -07:00
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
s = (const char *)src;
|
|
|
|
p = s;
|
|
|
|
len = 0;
|
|
|
|
while ((p < (const char *)src_end) && (*p != 0)) {len++; p++;}
|
2007-10-02 17:08:41 -07:00
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
if (_eet_data_float_cache_get(s, len, d) != 0) return len + 1;
|
2007-09-25 11:26:49 -07:00
|
|
|
|
2008-10-20 02:44:34 -07:00
|
|
|
if (eina_convert_atod(s, len, &mantisse, &exponent) == EINA_FALSE) return -1;
|
2008-02-29 22:38:09 -08:00
|
|
|
*d = (float)ldexp((double)mantisse, exponent);
|
|
|
|
|
|
|
|
return len + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eet_data_get_int(ed, src, src_end, &index) < 0) return -1;
|
|
|
|
|
|
|
|
if (!eet_dictionary_string_get_float(ed, index, d))
|
|
|
|
return -1;
|
|
|
|
return 1;
|
2002-12-02 15:39:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
2008-02-29 22:38:09 -08:00
|
|
|
eet_data_put_float(Eet_Dictionary *ed, const void *src, int *size_ret)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2008-05-19 08:27:04 -07:00
|
|
|
char buf[128];
|
2008-02-29 22:38:09 -08:00
|
|
|
int index;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2008-10-20 02:44:34 -07:00
|
|
|
eina_convert_dtoa((double)(*(float *)src), buf);
|
2007-09-25 11:26:49 -07:00
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
if (!ed)
|
|
|
|
{
|
|
|
|
char *d;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = strlen(buf);
|
|
|
|
d = malloc(len + 1);
|
|
|
|
if (!d) return NULL;
|
2008-05-19 08:25:46 -07:00
|
|
|
memcpy(d, buf, len + 1);
|
2008-02-29 22:38:09 -08:00
|
|
|
*size_ret = len + 1;
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
index = eet_dictionary_string_add(ed, buf);
|
|
|
|
if (index == -1) return NULL;
|
|
|
|
|
|
|
|
return eet_data_put_int(ed, &index, size_ret);
|
2002-12-02 15:39:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DOUBLE TYPE */
|
|
|
|
static int
|
2008-02-29 22:38:09 -08:00
|
|
|
eet_data_get_double(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dst)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
double *d;
|
|
|
|
int index;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
d = (double *) dst;
|
2007-10-03 07:28:07 -07:00
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
if (!ed)
|
|
|
|
{
|
|
|
|
const char *s, *p;
|
|
|
|
long long mantisse = 0;
|
|
|
|
long exponent = 0;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
s = (const char *) src;
|
|
|
|
p = s;
|
|
|
|
len = 0;
|
|
|
|
while ((p < (const char *)src_end) && (*p != 0)) {len++; p++;}
|
|
|
|
|
|
|
|
if (_eet_data_double_cache_get(s, len, d) != 0) return len + 1;
|
2007-10-03 07:28:07 -07:00
|
|
|
|
2008-10-20 02:44:34 -07:00
|
|
|
if (eina_convert_atod(s, len, &mantisse, &exponent) == EINA_FALSE) return -1;
|
2008-02-29 22:38:09 -08:00
|
|
|
*d = ldexp((double) mantisse, exponent);
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
return len + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eet_data_get_int(ed, src, src_end, &index) < 0) return -1;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
if (!eet_dictionary_string_get_double(ed, index, d))
|
|
|
|
return -1;
|
|
|
|
return 1;
|
2002-12-02 15:39:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
2008-02-29 22:38:09 -08:00
|
|
|
eet_data_put_double(Eet_Dictionary *ed, const void *src, int *size_ret)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
char buf[128];
|
|
|
|
int index;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2008-10-20 02:44:34 -07:00
|
|
|
eina_convert_dtoa((double)(*(double *)src), buf);
|
2007-09-25 11:26:49 -07:00
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
if (!ed)
|
|
|
|
{
|
|
|
|
char *d;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = strlen(buf);
|
|
|
|
d = malloc(len + 1);
|
|
|
|
if (!d) return NULL;
|
2008-05-19 08:25:46 -07:00
|
|
|
memcpy(d, buf, len + 1);
|
2008-02-29 22:38:09 -08:00
|
|
|
*size_ret = len + 1;
|
|
|
|
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
index = eet_dictionary_string_add(ed, buf);
|
|
|
|
if (index == -1) return NULL;
|
|
|
|
|
|
|
|
return eet_data_put_int(ed, &index, size_ret);
|
2002-12-02 15:39:26 -08:00
|
|
|
}
|
|
|
|
|
2009-09-29 06:24:45 -07:00
|
|
|
static int
|
|
|
|
eet_data_get_f32p32(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dst)
|
|
|
|
{
|
|
|
|
Eina_F32p32 *fp;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
fp = (Eina_F32p32*) dst;
|
|
|
|
|
|
|
|
if (!ed) return -1;
|
|
|
|
|
|
|
|
if (eet_data_get_int(ed, src, src_end, &index) < 0) return -1;
|
|
|
|
|
|
|
|
if (!eet_dictionary_string_get_fp(ed, index, fp))
|
|
|
|
return -1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
eet_data_put_f32p32(Eet_Dictionary *ed, const void *src, int *size_ret)
|
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
int index;
|
|
|
|
|
|
|
|
if (!ed) return NULL;
|
|
|
|
|
|
|
|
eina_convert_fptoa((Eina_F32p32)(*(Eina_F32p32 *)src), buf);
|
|
|
|
|
|
|
|
index = eet_dictionary_string_add(ed, buf);
|
|
|
|
if (index == -1) return NULL;
|
|
|
|
|
|
|
|
return eet_data_put_int(ed, &index, size_ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
eet_data_get_f16p16(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dst)
|
|
|
|
{
|
|
|
|
Eina_F32p32 tmp;
|
|
|
|
Eina_F16p16 *fp;
|
|
|
|
|
|
|
|
fp = (Eina_F16p16*) dst;
|
|
|
|
|
|
|
|
if (eet_data_get_f32p32(ed, src, src_end, &tmp) < 0) return -1;
|
|
|
|
|
|
|
|
*fp = eina_f32p32_to_f16p16(tmp);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
eet_data_put_f16p16(Eet_Dictionary *ed, const void *src, int *size_ret)
|
|
|
|
{
|
|
|
|
Eina_F32p32 tmp;
|
|
|
|
|
|
|
|
tmp = eina_f16p16_to_f32p32((Eina_F16p16)(*(Eina_F16p16 *)src));
|
|
|
|
return eet_data_put_f32p32(ed, &tmp, size_ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
eet_data_get_f8p24(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dst)
|
|
|
|
{
|
|
|
|
Eina_F32p32 tmp;
|
|
|
|
Eina_F8p24 *fp;
|
|
|
|
|
|
|
|
fp = (Eina_F8p24*) dst;
|
|
|
|
|
|
|
|
if (eet_data_get_f32p32(ed, src, src_end, &tmp) < 0) return -1;
|
|
|
|
|
|
|
|
*fp = eina_f32p32_to_f8p24(tmp);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
eet_data_put_f8p24(Eet_Dictionary *ed, const void *src, int *size_ret)
|
|
|
|
{
|
|
|
|
Eina_F32p32 tmp;
|
|
|
|
|
|
|
|
tmp = eina_f8p24_to_f32p32((Eina_F8p24)(*(Eina_F8p24 *)src));
|
|
|
|
return eet_data_put_f32p32(ed, &tmp, size_ret);
|
|
|
|
}
|
|
|
|
|
2008-09-11 04:26:09 -07:00
|
|
|
static inline int
|
2008-02-29 22:38:09 -08:00
|
|
|
eet_data_get_type(const Eet_Dictionary *ed, int type, const void *src, const void *src_end, void *dest)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
|
|
|
int ret;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2008-06-26 08:47:25 -07:00
|
|
|
ret = eet_basic_codec[type - 1].get(ed, src, src_end, dest);
|
2002-12-02 15:39:26 -08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-09-11 04:26:09 -07:00
|
|
|
static inline void *
|
2008-02-29 22:38:09 -08:00
|
|
|
eet_data_put_type(Eet_Dictionary *ed, int type, const void *src, int *size_ret)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
|
|
|
void *ret;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2008-06-26 08:47:25 -07:00
|
|
|
ret = eet_basic_codec[type - 1].put(ed, src, size_ret);
|
2002-12-02 15:39:26 -08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-09-29 06:24:45 -07:00
|
|
|
static inline Eina_Bool
|
|
|
|
eet_data_type_match(int type1, int type2)
|
|
|
|
{
|
|
|
|
if (type1 == type2) return EINA_TRUE;
|
|
|
|
|
|
|
|
/* Note: All floating point type are equivalent and could be read
|
|
|
|
without problem by any other floating point getter. */
|
|
|
|
switch (type1)
|
|
|
|
{
|
|
|
|
case EET_T_FLOAT:
|
|
|
|
case EET_T_DOUBLE:
|
|
|
|
case EET_T_F32P32:
|
|
|
|
case EET_T_F16P16:
|
|
|
|
case EET_T_F8P24:
|
|
|
|
switch (type2)
|
|
|
|
{
|
|
|
|
case EET_T_FLOAT:
|
|
|
|
case EET_T_DOUBLE:
|
|
|
|
case EET_T_F32P32:
|
|
|
|
case EET_T_F16P16:
|
|
|
|
case EET_T_F8P24:
|
|
|
|
return EINA_TRUE;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
/* chunk format...
|
2005-05-22 21:32:04 -07:00
|
|
|
*
|
2007-09-08 00:44:03 -07:00
|
|
|
* char[4] = "CHnK"; // untyped data ... or
|
|
|
|
* char[4] = "CHKx"; // typed data - x == type
|
2008-03-07 01:59:37 -08:00
|
|
|
*
|
2002-12-02 15:39:26 -08:00
|
|
|
* int = chunk size (including magic string);
|
2008-06-26 08:47:25 -07:00
|
|
|
* char[] = chunk magic/name string (0 byte terminated);
|
2002-12-02 15:39:26 -08:00
|
|
|
* ... sub-chunks (a chunk can contain chuncks recusrively) ...
|
|
|
|
* or
|
|
|
|
* ... payload data ...
|
2005-05-22 21:32:04 -07:00
|
|
|
*
|
2002-12-02 15:39:26 -08:00
|
|
|
*/
|
|
|
|
|
2008-09-11 04:26:09 -07:00
|
|
|
static inline void
|
2008-06-26 08:47:25 -07:00
|
|
|
eet_data_chunk_get(const Eet_Dictionary *ed, Eet_Data_Chunk *chnk,
|
|
|
|
const void *src, int size)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2006-03-03 18:46:24 -08:00
|
|
|
const char *s;
|
2002-12-02 15:39:26 -08:00
|
|
|
int ret1, ret2;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
if (!src) return;
|
|
|
|
if (size <= 8) return;
|
2008-10-24 14:47:10 -07:00
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
if (!chnk) return;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
s = src;
|
2007-09-08 00:44:03 -07:00
|
|
|
if (s[2] == 'K')
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2007-09-08 00:44:03 -07:00
|
|
|
if ((s[0] != 'C') || (s[1] != 'H') || (s[2] != 'K'))
|
2009-05-14 08:58:10 -07:00
|
|
|
return;
|
|
|
|
|
2007-09-08 00:44:03 -07:00
|
|
|
chnk->type = (unsigned char)(s[3]);
|
|
|
|
if (chnk->type > EET_T_LAST)
|
|
|
|
{
|
|
|
|
chnk->group_type = chnk->type;
|
|
|
|
chnk->type = EET_T_UNKNOW;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
chnk->group_type = EET_G_UNKNOWN;
|
2007-11-21 14:20:16 -08:00
|
|
|
if ((chnk->type >= EET_T_LAST) ||
|
|
|
|
(chnk->group_type >= EET_G_LAST))
|
2007-09-08 00:44:03 -07:00
|
|
|
{
|
|
|
|
chnk->type = 0;
|
|
|
|
chnk->group_type = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((s[0] != 'C') || (s[1] != 'H') || (s[2] != 'n') || (s[3] != 'K'))
|
2009-05-14 08:58:10 -07:00
|
|
|
return;
|
2002-12-02 15:39:26 -08:00
|
|
|
}
|
2008-02-29 22:38:09 -08:00
|
|
|
ret1 = eet_data_get_type(ed, EET_T_INT, (s + 4), (s + size), &(chnk->size));
|
2009-05-14 08:58:10 -07:00
|
|
|
if (ret1 <= 0) return;
|
|
|
|
if ((chnk->size < 0) || ((chnk->size + 8) > size)) return;
|
2008-02-29 22:38:09 -08:00
|
|
|
ret2 = eet_data_get_type(ed, EET_T_STRING, (s + 8), (s + size), &(chnk->name));
|
2009-05-14 08:58:10 -07:00
|
|
|
if (ret2 <= 0) return;
|
2008-02-29 22:38:09 -08:00
|
|
|
|
|
|
|
chnk->len = ret2;
|
2008-07-17 08:33:40 -07:00
|
|
|
|
|
|
|
/* Precalc hash */
|
|
|
|
chnk->hash = eet_data_get_string_hash(ed, (s + 8), (s + size));
|
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
if (ed)
|
|
|
|
{
|
|
|
|
chnk->data = (char *)src + 4 + ret1 + sizeof(int);
|
|
|
|
chnk->size -= sizeof(int);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
chnk->data = (char *)src + 4 + ret1 + chnk->len;
|
|
|
|
chnk->size -= chnk->len;
|
|
|
|
}
|
|
|
|
|
2005-11-27 10:54:02 -08:00
|
|
|
return;
|
2002-12-02 15:39:26 -08:00
|
|
|
}
|
|
|
|
|
2008-09-11 04:26:09 -07:00
|
|
|
static inline Eet_Data_Chunk *
|
2007-09-08 00:44:03 -07:00
|
|
|
eet_data_chunk_new(void *data, int size, const char *name, int type, int group_type)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
|
|
|
Eet_Data_Chunk *chnk;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
if (!name) return NULL;
|
2005-11-03 23:16:50 -08:00
|
|
|
chnk = calloc(1, sizeof(Eet_Data_Chunk));
|
2002-12-02 15:39:26 -08:00
|
|
|
if (!chnk) return NULL;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2009-09-29 06:24:45 -07:00
|
|
|
/* Note: Another security, so older eet library could read file
|
|
|
|
saved with fixed point value. */
|
|
|
|
if (type == EET_T_F32P32
|
|
|
|
|| type == EET_T_F16P16
|
|
|
|
|| type == EET_T_F8P24)
|
|
|
|
type = EET_T_DOUBLE;
|
|
|
|
|
2005-11-03 23:16:50 -08:00
|
|
|
chnk->name = strdup(name);
|
2008-02-29 22:38:09 -08:00
|
|
|
chnk->len = strlen(name) + 1;
|
2002-12-02 15:39:26 -08:00
|
|
|
chnk->size = size;
|
|
|
|
chnk->data = data;
|
2007-09-08 00:44:03 -07:00
|
|
|
chnk->type = type;
|
|
|
|
chnk->group_type = group_type;
|
2002-12-02 15:39:26 -08:00
|
|
|
return chnk;
|
|
|
|
}
|
|
|
|
|
2008-09-11 04:26:09 -07:00
|
|
|
static inline void
|
2002-12-02 15:39:26 -08:00
|
|
|
eet_data_chunk_free(Eet_Data_Chunk *chnk)
|
|
|
|
{
|
2005-11-03 23:16:50 -08:00
|
|
|
if (chnk->name) free(chnk->name);
|
2002-12-02 15:39:26 -08:00
|
|
|
free(chnk);
|
|
|
|
}
|
|
|
|
|
2008-09-11 04:26:09 -07:00
|
|
|
static inline Eet_Data_Stream *
|
2002-12-02 15:39:26 -08:00
|
|
|
eet_data_stream_new(void)
|
|
|
|
{
|
|
|
|
Eet_Data_Stream *ds;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
ds = calloc(1, sizeof(Eet_Data_Stream));
|
|
|
|
if (!ds) return NULL;
|
|
|
|
return ds;
|
|
|
|
}
|
|
|
|
|
2008-09-11 04:26:09 -07:00
|
|
|
static inline void
|
2002-12-02 15:39:26 -08:00
|
|
|
eet_data_stream_free(Eet_Data_Stream *ds)
|
|
|
|
{
|
|
|
|
if (ds->data) free(ds->data);
|
|
|
|
free(ds);
|
|
|
|
}
|
|
|
|
|
2008-09-11 04:26:09 -07:00
|
|
|
static inline void
|
2006-11-05 04:14:08 -08:00
|
|
|
eet_data_stream_write(Eet_Data_Stream *ds, const void *data, int size)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
|
|
|
char *p;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
if ((ds->pos + size) > ds->size)
|
|
|
|
{
|
2007-09-08 00:44:03 -07:00
|
|
|
ds->data = realloc(ds->data, ds->size + size + 512);
|
2002-12-02 15:39:26 -08:00
|
|
|
if (!ds->data)
|
|
|
|
{
|
|
|
|
ds->pos = 0;
|
|
|
|
ds->size = 0;
|
|
|
|
return;
|
|
|
|
}
|
2007-09-08 00:44:03 -07:00
|
|
|
ds->size = ds->size + size + 512;
|
2002-12-02 15:39:26 -08:00
|
|
|
}
|
|
|
|
p = ds->data;
|
|
|
|
memcpy(p + ds->pos, data, size);
|
|
|
|
ds->pos += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-02-29 22:38:09 -08:00
|
|
|
eet_data_chunk_put(Eet_Dictionary *ed, Eet_Data_Chunk *chnk, Eet_Data_Stream *ds)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
int *size;
|
|
|
|
void *string;
|
|
|
|
int s;
|
|
|
|
int size_ret = 0;
|
|
|
|
int string_ret = 0;
|
2007-09-08 00:44:03 -07:00
|
|
|
unsigned char buf[4] = "CHK";
|
2008-02-29 22:38:09 -08:00
|
|
|
|
2009-08-16 00:06:22 -07:00
|
|
|
/* disable this check - it will allow empty chunks to be written. this is
|
|
|
|
* right for corner-cases when y have a struct with empty fields (empty
|
|
|
|
* strings or empty list ptrs etc.) */
|
|
|
|
/* if (!chnk->data && chnk->type != EET_T_NULL) return; */
|
2002-12-02 15:39:26 -08:00
|
|
|
/* chunk head */
|
2008-02-29 22:38:09 -08:00
|
|
|
|
2007-09-08 00:44:03 -07:00
|
|
|
/* eet_data_stream_write(ds, "CHnK", 4);*/
|
|
|
|
if (chnk->type != EET_T_UNKNOW) buf[3] = chnk->type;
|
|
|
|
else buf[3] = chnk->group_type;
|
2008-02-29 22:38:09 -08:00
|
|
|
|
|
|
|
string = eet_data_put_string(ed, &chnk->name, &string_ret);
|
|
|
|
if (!string)
|
|
|
|
return ;
|
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
/* size of chunk payload data + name */
|
2008-02-29 22:38:09 -08:00
|
|
|
s = chnk->size + string_ret;
|
|
|
|
size = eet_data_put_int(ed, &s, &size_ret);
|
|
|
|
|
|
|
|
/* FIXME: If something goes wrong the resulting file will be corrupted. */
|
|
|
|
if (!size)
|
|
|
|
goto on_error;
|
|
|
|
|
|
|
|
eet_data_stream_write(ds, buf, 4);
|
|
|
|
|
|
|
|
/* write chunk length */
|
|
|
|
eet_data_stream_write(ds, size, size_ret);
|
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
/* write chunk name */
|
2008-02-29 22:38:09 -08:00
|
|
|
eet_data_stream_write(ds, string, string_ret);
|
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
/* write payload */
|
2009-08-16 00:06:22 -07:00
|
|
|
if (chnk->data)
|
|
|
|
eet_data_stream_write(ds, chnk->data, chnk->size);
|
2008-02-29 22:38:09 -08:00
|
|
|
|
|
|
|
free(string);
|
|
|
|
on_error:
|
|
|
|
free(size);
|
2002-12-02 15:39:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---*/
|
|
|
|
|
2005-05-25 20:57:57 -07:00
|
|
|
static void
|
|
|
|
_eet_descriptor_hash_new(Eet_Data_Descriptor *edd)
|
|
|
|
{
|
|
|
|
int i;
|
2008-03-07 01:59:37 -08:00
|
|
|
|
2005-05-25 20:57:57 -07:00
|
|
|
edd->elements.hash.size = 1 << 6;
|
|
|
|
edd->elements.hash.buckets = calloc(1, sizeof(Eet_Data_Descriptor_Hash) * edd->elements.hash.size);
|
|
|
|
for (i = 0; i < edd->elements.num; i++)
|
|
|
|
{
|
|
|
|
Eet_Data_Element *ede;
|
|
|
|
int hash;
|
2008-03-07 01:59:37 -08:00
|
|
|
|
2005-05-25 20:57:57 -07:00
|
|
|
ede = &(edd->elements.set[i]);
|
2006-12-28 07:23:47 -08:00
|
|
|
hash = _eet_hash_gen((char *) ede->name, 6);
|
2005-05-25 20:57:57 -07:00
|
|
|
if (!edd->elements.hash.buckets[hash].element)
|
|
|
|
edd->elements.hash.buckets[hash].element = ede;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Eet_Data_Descriptor_Hash *bucket;
|
2008-03-07 01:59:37 -08:00
|
|
|
|
2005-05-25 20:57:57 -07:00
|
|
|
bucket = calloc(1, sizeof(Eet_Data_Descriptor_Hash));
|
|
|
|
bucket->element = ede;
|
|
|
|
bucket->next = edd->elements.hash.buckets[hash].next;
|
|
|
|
edd->elements.hash.buckets[hash].next = bucket;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_eet_descriptor_hash_free(Eet_Data_Descriptor *edd)
|
|
|
|
{
|
|
|
|
int i;
|
2008-03-07 01:59:37 -08:00
|
|
|
|
2005-05-25 20:57:57 -07:00
|
|
|
for (i = 0; i < edd->elements.hash.size; i++)
|
|
|
|
{
|
|
|
|
Eet_Data_Descriptor_Hash *bucket, *pbucket;
|
2008-03-07 01:59:37 -08:00
|
|
|
|
2005-05-25 20:57:57 -07:00
|
|
|
bucket = edd->elements.hash.buckets[i].next;
|
|
|
|
while (bucket)
|
|
|
|
{
|
|
|
|
pbucket = bucket;
|
|
|
|
bucket = bucket->next;
|
|
|
|
free(pbucket);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (edd->elements.hash.buckets) free(edd->elements.hash.buckets);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eet_Data_Element *
|
2008-07-17 08:33:40 -07:00
|
|
|
_eet_descriptor_hash_find(Eet_Data_Descriptor *edd, char *name, int hash)
|
2005-05-25 20:57:57 -07:00
|
|
|
{
|
|
|
|
Eet_Data_Descriptor_Hash *bucket;
|
2008-03-07 01:59:37 -08:00
|
|
|
|
2008-07-17 08:33:40 -07:00
|
|
|
if (hash < 0) hash = _eet_hash_gen(name, 6);
|
|
|
|
else hash &= 0x3f;
|
2005-05-25 20:57:57 -07:00
|
|
|
if (!edd->elements.hash.buckets[hash].element) return NULL;
|
2008-07-18 04:39:38 -07:00
|
|
|
/*
|
|
|
|
When we use the dictionnary as a source for chunk name, we will always
|
|
|
|
have the same pointer in name. It's a good idea to just compare pointer
|
|
|
|
instead of running strcmp on both string.
|
|
|
|
*/
|
|
|
|
if (edd->elements.hash.buckets[hash].element->directory_name_ptr == name)
|
2005-05-25 20:57:57 -07:00
|
|
|
return edd->elements.hash.buckets[hash].element;
|
2008-07-18 04:39:38 -07:00
|
|
|
if (!strcmp(edd->elements.hash.buckets[hash].element->name, name))
|
|
|
|
{
|
|
|
|
edd->elements.hash.buckets[hash].element->directory_name_ptr = name;
|
|
|
|
return edd->elements.hash.buckets[hash].element;
|
|
|
|
}
|
2005-05-25 20:57:57 -07:00
|
|
|
bucket = edd->elements.hash.buckets[hash].next;
|
|
|
|
while (bucket)
|
|
|
|
{
|
2008-07-18 04:39:38 -07:00
|
|
|
if (bucket->element->directory_name_ptr == name) return bucket->element;
|
|
|
|
if (!strcmp(bucket->element->name, name))
|
|
|
|
{
|
|
|
|
bucket->element->directory_name_ptr = name;
|
|
|
|
return bucket->element;
|
|
|
|
}
|
2005-05-25 20:57:57 -07:00
|
|
|
bucket = bucket->next;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-11-30 07:36:19 -08:00
|
|
|
static void *
|
|
|
|
_eet_mem_alloc(size_t size)
|
|
|
|
{
|
|
|
|
return calloc(1, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_eet_mem_free(void *mem)
|
|
|
|
{
|
|
|
|
free(mem);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
_eet_str_alloc(const char *str)
|
|
|
|
{
|
|
|
|
return strdup(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_eet_str_free(const char *str)
|
|
|
|
{
|
|
|
|
free((char *)str);
|
|
|
|
}
|
|
|
|
|
2009-08-13 05:52:41 -07:00
|
|
|
static Eina_Hash *
|
|
|
|
_eet_eina_hash_add_alloc(Eina_Hash *hash, const char *key, void *data)
|
|
|
|
{
|
|
|
|
if (!hash) hash = eina_hash_string_small_new(NULL);
|
|
|
|
if (!hash) return NULL;
|
|
|
|
|
|
|
|
eina_hash_add(hash, key, data);
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2009-08-13 06:26:43 -07:00
|
|
|
_eet_str_direct_alloc(const char *str)
|
2009-08-13 05:52:41 -07:00
|
|
|
{
|
|
|
|
return (char *)str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-08-13 06:26:43 -07:00
|
|
|
_eet_str_direct_free(const char *str)
|
2009-08-13 05:52:41 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-05-25 20:57:57 -07:00
|
|
|
/*---*/
|
2009-08-13 05:52:41 -07:00
|
|
|
EAPI Eina_Bool
|
2009-08-13 07:47:10 -07:00
|
|
|
eet_eina_stream_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc, const char *name, int size)
|
2009-08-13 05:52:41 -07:00
|
|
|
{
|
2009-08-13 07:47:10 -07:00
|
|
|
if (!eddc || !name) return EINA_FALSE;
|
|
|
|
|
|
|
|
eddc->name = name;
|
|
|
|
eddc->size = size;
|
|
|
|
eddc->version = 1;
|
|
|
|
|
|
|
|
eddc->func.mem_alloc = _eet_mem_alloc;
|
|
|
|
eddc->func.mem_free = _eet_mem_free;
|
|
|
|
eddc->func.str_alloc = (char *(*)(const char *))eina_stringshare_add;
|
|
|
|
eddc->func.str_free = eina_stringshare_del;
|
|
|
|
eddc->func.list_next = (void *(*)(void *))eina_list_next;
|
|
|
|
eddc->func.list_append = (void *(*)(void *, void *))eina_list_append;
|
|
|
|
eddc->func.list_data = (void *(*)(void *))eina_list_data_get;
|
|
|
|
eddc->func.list_free = (void *(*)(void *))eina_list_free;
|
|
|
|
eddc->func.hash_foreach = (void (*)(void *, int (*)(void *, const char *, void *, void *), void *))eina_hash_foreach;
|
|
|
|
eddc->func.hash_add = (void* (*)(void *, const char *, void *)) _eet_eina_hash_add_alloc;
|
|
|
|
eddc->func.hash_free = (void (*)(void *))eina_hash_free;
|
2009-08-13 05:52:41 -07:00
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
2005-05-25 20:57:57 -07:00
|
|
|
|
2009-08-13 05:52:41 -07:00
|
|
|
EAPI Eina_Bool
|
2009-08-13 07:47:10 -07:00
|
|
|
eet_eina_file_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc, const char *name, int size)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2009-08-13 07:47:10 -07:00
|
|
|
if (!eet_eina_stream_data_descriptor_class_set(eddc, name, size))
|
2009-08-13 05:52:41 -07:00
|
|
|
return EINA_FALSE;
|
2003-01-12 22:40:49 -08:00
|
|
|
|
2009-08-13 07:47:10 -07:00
|
|
|
eddc->version = 2;
|
2008-02-29 22:38:09 -08:00
|
|
|
|
2009-08-13 07:47:10 -07:00
|
|
|
eddc->func.str_direct_alloc = _eet_str_direct_alloc;
|
|
|
|
eddc->func.str_direct_free = _eet_str_direct_free;
|
2009-08-13 05:52:41 -07:00
|
|
|
|
|
|
|
return EINA_TRUE;
|
2002-12-02 15:39:26 -08:00
|
|
|
}
|
|
|
|
|
2009-08-13 05:52:41 -07:00
|
|
|
static Eet_Data_Descriptor *
|
|
|
|
_eet_data_descriptor_new(const Eet_Data_Descriptor_Class *eddc, int version)
|
2005-11-30 07:36:19 -08:00
|
|
|
{
|
|
|
|
Eet_Data_Descriptor *edd;
|
|
|
|
|
|
|
|
if (!eddc) return NULL;
|
2009-08-13 05:52:41 -07:00
|
|
|
if (eddc->version < version) return NULL;
|
|
|
|
|
|
|
|
edd = calloc(1, sizeof (Eet_Data_Descriptor));
|
2008-02-29 22:38:09 -08:00
|
|
|
if (!edd) return NULL;
|
|
|
|
|
|
|
|
edd->name = eddc->name;
|
2008-07-18 04:39:38 -07:00
|
|
|
edd->ed = NULL;
|
2008-02-29 22:38:09 -08:00
|
|
|
edd->size = eddc->size;
|
|
|
|
edd->func.mem_alloc = _eet_mem_alloc;
|
|
|
|
edd->func.mem_free = _eet_mem_free;
|
|
|
|
edd->func.str_alloc = _eet_str_alloc;
|
|
|
|
edd->func.str_free = _eet_str_free;
|
|
|
|
if (eddc->func.mem_alloc)
|
|
|
|
edd->func.mem_alloc = eddc->func.mem_alloc;
|
|
|
|
if (eddc->func.mem_free)
|
|
|
|
edd->func.mem_free = eddc->func.mem_free;
|
|
|
|
if (eddc->func.str_alloc)
|
|
|
|
edd->func.str_alloc = eddc->func.str_alloc;
|
|
|
|
if (eddc->func.str_free)
|
|
|
|
edd->func.str_free = eddc->func.str_free;
|
|
|
|
edd->func.list_next = eddc->func.list_next;
|
|
|
|
edd->func.list_append = eddc->func.list_append;
|
|
|
|
edd->func.list_data = eddc->func.list_data;
|
|
|
|
edd->func.list_free = eddc->func.list_free;
|
|
|
|
edd->func.hash_foreach = eddc->func.hash_foreach;
|
|
|
|
edd->func.hash_add = eddc->func.hash_add;
|
|
|
|
edd->func.hash_free = eddc->func.hash_free;
|
|
|
|
|
2009-08-13 05:52:41 -07:00
|
|
|
if (version > 1)
|
|
|
|
{
|
|
|
|
edd->func.str_direct_alloc = eddc->func.str_direct_alloc;
|
|
|
|
edd->func.str_direct_free = eddc->func.str_direct_free;
|
|
|
|
}
|
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
return edd;
|
|
|
|
}
|
|
|
|
|
2008-03-07 01:59:37 -08:00
|
|
|
EAPI Eet_Data_Descriptor *
|
2009-08-13 05:52:41 -07:00
|
|
|
eet_data_descriptor_new(const char *name,
|
|
|
|
int size,
|
|
|
|
void *(*func_list_next) (void *l),
|
|
|
|
void *(*func_list_append) (void *l, void *d),
|
|
|
|
void *(*func_list_data) (void *l),
|
|
|
|
void *(*func_list_free) (void *l),
|
|
|
|
void (*func_hash_foreach) (void *h, int (*func) (void *h, const char *k, void *dt, void *fdt), void *fdt),
|
|
|
|
void *(*func_hash_add) (void *h, const char *k, void *d),
|
|
|
|
void (*func_hash_free) (void *h))
|
2008-02-29 22:38:09 -08:00
|
|
|
{
|
2009-08-13 05:52:41 -07:00
|
|
|
Eet_Data_Descriptor_Class eddc;
|
2008-02-29 22:38:09 -08:00
|
|
|
|
2009-08-13 05:52:41 -07:00
|
|
|
if (!name) return NULL;
|
2008-02-29 22:38:09 -08:00
|
|
|
|
2009-08-13 06:57:22 -07:00
|
|
|
memset(&eddc, 0, sizeof (Eet_Data_Descriptor_Class));
|
|
|
|
|
2009-08-13 05:52:41 -07:00
|
|
|
eddc.name = name;
|
|
|
|
eddc.size = size;
|
|
|
|
eddc.version = 0;
|
2008-02-29 22:38:09 -08:00
|
|
|
|
2009-08-13 05:52:41 -07:00
|
|
|
eddc.func.list_next = func_list_next;
|
|
|
|
eddc.func.list_append = func_list_append;
|
|
|
|
eddc.func.list_data = func_list_data;
|
|
|
|
eddc.func.list_free = func_list_free;
|
|
|
|
eddc.func.hash_foreach = func_hash_foreach;
|
|
|
|
eddc.func.hash_add = func_hash_add;
|
|
|
|
eddc.func.hash_free = func_hash_free;
|
|
|
|
|
|
|
|
return _eet_data_descriptor_new(&eddc, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eet_Data_Descriptor *
|
|
|
|
eet_data_descriptor2_new(const Eet_Data_Descriptor_Class *eddc)
|
|
|
|
{
|
|
|
|
return _eet_data_descriptor_new(eddc, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eet_Data_Descriptor *
|
|
|
|
eet_data_descriptor3_new(const Eet_Data_Descriptor_Class *eddc)
|
|
|
|
{
|
|
|
|
return _eet_data_descriptor_new(eddc, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eet_Data_Descriptor *
|
|
|
|
eet_data_descriptor_stream_new(const Eet_Data_Descriptor_Class *eddc)
|
|
|
|
{
|
|
|
|
return _eet_data_descriptor_new(eddc, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eet_Data_Descriptor *
|
|
|
|
eet_data_descriptor_file_new(const Eet_Data_Descriptor_Class *eddc)
|
|
|
|
{
|
|
|
|
return _eet_data_descriptor_new(eddc, 2);
|
2005-11-30 07:36:19 -08:00
|
|
|
}
|
|
|
|
|
2008-03-07 01:59:37 -08:00
|
|
|
EAPI void
|
2002-12-02 15:39:26 -08:00
|
|
|
eet_data_descriptor_free(Eet_Data_Descriptor *edd)
|
|
|
|
{
|
2005-05-25 20:57:57 -07:00
|
|
|
_eet_descriptor_hash_free(edd);
|
2002-12-02 15:39:26 -08:00
|
|
|
if (edd->elements.set) free(edd->elements.set);
|
|
|
|
free(edd);
|
|
|
|
}
|
|
|
|
|
2008-03-07 01:59:37 -08:00
|
|
|
EAPI void
|
|
|
|
eet_data_descriptor_element_add(Eet_Data_Descriptor *edd,
|
2008-06-26 08:47:25 -07:00
|
|
|
const char *name,
|
|
|
|
int type,
|
2005-05-22 21:32:04 -07:00
|
|
|
int group_type,
|
|
|
|
int offset,
|
2008-06-26 08:47:25 -07:00
|
|
|
int count,
|
|
|
|
/* int counter_offset, */
|
|
|
|
const char *counter_name /* Useless should go on a major release */,
|
2002-12-02 15:39:26 -08:00
|
|
|
Eet_Data_Descriptor *subtype)
|
|
|
|
{
|
|
|
|
Eet_Data_Element *ede;
|
2005-11-29 03:32:10 -08:00
|
|
|
/* int l1, l2, p1, p2, i;
|
|
|
|
char *ps;*/
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2008-05-15 07:14:35 -07:00
|
|
|
/* FIXME: Fail safely when realloc fail. */
|
2002-12-02 15:39:26 -08:00
|
|
|
edd->elements.num++;
|
|
|
|
edd->elements.set = realloc(edd->elements.set, edd->elements.num * sizeof(Eet_Data_Element));
|
|
|
|
if (!edd->elements.set) return;
|
|
|
|
ede = &(edd->elements.set[edd->elements.num - 1]);
|
2005-11-27 08:06:55 -08:00
|
|
|
ede->name = name;
|
2008-07-18 04:39:38 -07:00
|
|
|
ede->directory_name_ptr = NULL;
|
2008-02-29 22:38:09 -08:00
|
|
|
|
2008-05-15 07:14:35 -07:00
|
|
|
/*
|
|
|
|
* We do a special case when we do list,hash or whatever group of simple type.
|
|
|
|
* Instead of handling it in encode/decode/dump/undump, we create an
|
|
|
|
* implicit structure with only the simple type.
|
|
|
|
*/
|
|
|
|
if (group_type > EET_G_UNKNOWN
|
|
|
|
&& group_type < EET_G_LAST
|
2008-10-23 06:12:33 -07:00
|
|
|
&& type > EET_T_UNKNOW && type < EET_T_STRING
|
2008-05-15 07:14:35 -07:00
|
|
|
&& subtype == NULL)
|
|
|
|
{
|
|
|
|
subtype = calloc(1, sizeof (Eet_Data_Descriptor));
|
|
|
|
if (!subtype) return ;
|
|
|
|
subtype->name = "implicit";
|
2008-06-26 08:47:25 -07:00
|
|
|
subtype->size = eet_basic_codec[type - 1].size;
|
2008-05-15 07:14:35 -07:00
|
|
|
memcpy(&subtype->func, &edd->func, sizeof(subtype->func));
|
|
|
|
|
2008-06-26 08:47:25 -07:00
|
|
|
eet_data_descriptor_element_add(subtype, eet_basic_codec[type - 1].name, type,
|
|
|
|
EET_G_UNKNOWN, 0, 0, /* 0, */NULL, NULL);
|
2008-05-15 07:14:35 -07:00
|
|
|
type = EET_T_UNKNOW;
|
|
|
|
}
|
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
ede->type = type;
|
|
|
|
ede->group_type = group_type;
|
|
|
|
ede->offset = offset;
|
|
|
|
ede->count = count;
|
2008-06-26 08:47:25 -07:00
|
|
|
/* FIXME: For the time being, EET_G_VAR_ARRAY will put the counter_offset in count. */
|
|
|
|
ede->counter_offset = count;
|
|
|
|
/* ede->counter_offset = counter_offset; */
|
2005-11-27 08:06:55 -08:00
|
|
|
ede->counter_name = counter_name;
|
2008-02-29 22:38:09 -08:00
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
ede->subtype = subtype;
|
|
|
|
}
|
|
|
|
|
2008-03-07 01:59:37 -08:00
|
|
|
EAPI void *
|
2008-11-13 08:31:13 -08:00
|
|
|
eet_data_read_cipher(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const char *key)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
const Eet_Dictionary *ed = NULL;
|
2008-11-13 08:31:13 -08:00
|
|
|
const void *data = NULL;
|
2008-02-29 22:38:09 -08:00
|
|
|
void *data_dec;
|
2009-03-19 12:00:46 -07:00
|
|
|
Eet_Free_Context context;
|
2008-02-29 22:38:09 -08:00
|
|
|
int required_free = 0;
|
2008-11-13 08:31:13 -08:00
|
|
|
int size;
|
2008-02-29 22:38:09 -08:00
|
|
|
|
|
|
|
ed = eet_dictionary_get(ef);
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2008-11-13 08:31:13 -08:00
|
|
|
if (!key)
|
|
|
|
data = eet_read_direct(ef, name, &size);
|
2006-06-13 03:20:22 -07:00
|
|
|
if (!data)
|
|
|
|
{
|
|
|
|
required_free = 1;
|
2008-11-13 08:31:13 -08:00
|
|
|
data = eet_read_cipher(ef, name, &size, key);
|
2006-06-13 03:20:22 -07:00
|
|
|
if (!data) return NULL;
|
|
|
|
}
|
2008-02-29 22:38:09 -08:00
|
|
|
|
2009-03-19 12:00:46 -07:00
|
|
|
memset(&context, 0, sizeof (context));
|
|
|
|
data_dec = _eet_data_descriptor_decode(&context, ed, edd, data, size, 0, NULL, NULL);
|
2006-06-13 03:20:22 -07:00
|
|
|
if (required_free)
|
2008-02-29 22:38:09 -08:00
|
|
|
free((void*)data);
|
2006-06-13 03:20:22 -07:00
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
return data_dec;
|
|
|
|
}
|
|
|
|
|
2008-11-13 08:31:13 -08:00
|
|
|
EAPI void *
|
|
|
|
eet_data_read(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name)
|
|
|
|
{
|
|
|
|
return eet_data_read_cipher(ef, edd, name, NULL);
|
|
|
|
}
|
|
|
|
|
2008-03-07 01:59:37 -08:00
|
|
|
EAPI int
|
2008-11-13 08:31:13 -08:00
|
|
|
eet_data_write_cipher(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const char *key, const void *data, int compress)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
Eet_Dictionary *ed;
|
|
|
|
void *data_enc;
|
|
|
|
int size;
|
|
|
|
int val;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
ed = eet_dictionary_get(ef);
|
|
|
|
|
|
|
|
data_enc = _eet_data_descriptor_encode(ed, edd, data, &size);
|
2002-12-02 15:39:26 -08:00
|
|
|
if (!data_enc) return 0;
|
2008-11-13 08:31:13 -08:00
|
|
|
val = eet_write_cipher(ef, name, data_enc, size, compress, key);
|
2002-12-02 15:39:26 -08:00
|
|
|
free(data_enc);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2008-11-13 08:31:13 -08:00
|
|
|
EAPI int
|
|
|
|
eet_data_write(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const void *data, int compress)
|
|
|
|
{
|
|
|
|
return eet_data_write_cipher(ef, edd, name, NULL, data, compress);
|
|
|
|
}
|
|
|
|
|
2008-07-17 09:39:28 -07:00
|
|
|
static int
|
|
|
|
_eet_free_hash(void *data)
|
|
|
|
{
|
2008-07-26 05:54:39 -07:00
|
|
|
unsigned long ptr = (unsigned long)(data);
|
2008-07-17 09:39:28 -07:00
|
|
|
int hash;
|
|
|
|
|
|
|
|
hash = ptr;
|
|
|
|
hash ^= ptr >> 8;
|
|
|
|
hash ^= ptr >> 16;
|
|
|
|
hash ^= ptr >> 24;
|
|
|
|
|
2008-07-17 13:28:59 -07:00
|
|
|
#if LONG_BIT != 32
|
2008-07-17 09:39:28 -07:00
|
|
|
hash ^= ptr >> 32;
|
|
|
|
hash ^= ptr >> 40;
|
|
|
|
hash ^= ptr >> 48;
|
|
|
|
hash ^= ptr >> 56;
|
2008-07-17 13:28:59 -07:00
|
|
|
#endif
|
2008-07-17 09:39:28 -07:00
|
|
|
|
|
|
|
return hash & 0xFF;
|
|
|
|
}
|
|
|
|
|
2003-07-07 00:52:20 -07:00
|
|
|
static void
|
2008-02-29 22:38:09 -08:00
|
|
|
_eet_free_add(Eet_Free *ef, void *data)
|
2003-07-07 00:52:20 -07:00
|
|
|
{
|
2008-07-17 09:39:28 -07:00
|
|
|
int hash;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
hash = _eet_free_hash(data);
|
2008-02-29 22:38:09 -08:00
|
|
|
|
2008-07-17 09:39:28 -07:00
|
|
|
for (i = 0; i < ef->num[hash]; ++i)
|
|
|
|
if (ef->list[hash][i] == data) return;
|
2008-02-29 22:38:09 -08:00
|
|
|
|
2008-07-17 09:39:28 -07:00
|
|
|
ef->num[hash]++;
|
|
|
|
if (ef->num[hash] > ef->len[hash])
|
2003-07-07 00:52:20 -07:00
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
void **tmp;
|
|
|
|
|
2008-07-17 09:39:28 -07:00
|
|
|
tmp = realloc(ef->list[hash], (ef->len[hash] + 16) * sizeof(void*));
|
2008-02-29 22:38:09 -08:00
|
|
|
if (!tmp) return ;
|
|
|
|
|
2008-07-17 09:39:28 -07:00
|
|
|
ef->len[hash] += 16;
|
|
|
|
ef->list[hash] = tmp;
|
2003-07-07 00:52:20 -07:00
|
|
|
}
|
2008-07-17 09:39:28 -07:00
|
|
|
ef->list[hash][ef->num[hash] - 1] = data;
|
2003-07-07 00:52:20 -07:00
|
|
|
}
|
|
|
|
static void
|
2008-02-29 22:38:09 -08:00
|
|
|
_eet_free_reset(Eet_Free *ef)
|
2003-07-07 00:52:20 -07:00
|
|
|
{
|
2008-07-17 09:39:28 -07:00
|
|
|
int i;
|
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
if (ef->ref > 0) return ;
|
2008-07-17 09:39:28 -07:00
|
|
|
for (i = 0; i < 256; ++i)
|
|
|
|
{
|
|
|
|
ef->len[i] = 0;
|
|
|
|
ef->num[i] = 0;
|
|
|
|
if (ef->list[i]) free(ef->list[i]);
|
|
|
|
ef->list[i] = NULL;
|
|
|
|
}
|
2003-07-07 00:52:20 -07:00
|
|
|
}
|
|
|
|
static void
|
2008-02-29 22:38:09 -08:00
|
|
|
_eet_free_ref(Eet_Free *ef)
|
2003-07-07 00:52:20 -07:00
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
ef->ref++;
|
2003-07-07 00:52:20 -07:00
|
|
|
}
|
2003-07-07 15:36:37 -07:00
|
|
|
static void
|
2008-02-29 22:38:09 -08:00
|
|
|
_eet_free_unref(Eet_Free *ef)
|
2003-07-07 15:36:37 -07:00
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
ef->ref--;
|
2003-07-07 15:36:37 -07:00
|
|
|
}
|
|
|
|
|
2009-03-19 12:00:46 -07:00
|
|
|
#define _eet_freelist_add(Ctx, Data) _eet_free_add(&Ctx->freelist, Data);
|
|
|
|
#define _eet_freelist_reset(Ctx) _eet_free_reset(&Ctx->freelist);
|
|
|
|
#define _eet_freelist_ref(Ctx) _eet_free_ref(&Ctx->freelist);
|
|
|
|
#define _eet_freelist_unref(Ctx) _eet_free_unref(&Ctx->freelist);
|
2003-07-07 00:52:20 -07:00
|
|
|
|
|
|
|
static void
|
2009-03-19 12:00:46 -07:00
|
|
|
_eet_freelist_free(Eet_Free_Context *context, Eet_Data_Descriptor *edd)
|
2003-07-07 00:52:20 -07:00
|
|
|
{
|
2008-07-17 09:39:28 -07:00
|
|
|
int j;
|
2003-07-07 00:52:20 -07:00
|
|
|
int i;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2009-03-19 12:00:46 -07:00
|
|
|
if (context->freelist.ref > 0) return;
|
2008-07-17 09:39:28 -07:00
|
|
|
for (j = 0; j < 256; ++j)
|
2009-03-19 12:00:46 -07:00
|
|
|
for (i = 0; i < context->freelist.num[j]; ++i)
|
2008-07-17 09:39:28 -07:00
|
|
|
{
|
|
|
|
if (edd)
|
2009-03-19 12:00:46 -07:00
|
|
|
edd->func.mem_free(context->freelist.list[j][i]);
|
2008-07-17 09:39:28 -07:00
|
|
|
else
|
2009-03-19 12:00:46 -07:00
|
|
|
free(context->freelist.list[j][i]);
|
2008-07-17 09:39:28 -07:00
|
|
|
}
|
2009-03-19 12:00:46 -07:00
|
|
|
_eet_free_reset(&context->freelist);
|
2003-07-07 00:52:20 -07:00
|
|
|
}
|
|
|
|
|
2009-03-19 12:00:46 -07:00
|
|
|
#define _eet_freelist_list_add(Ctx, Data) _eet_free_add(&Ctx->freelist_list, Data);
|
|
|
|
#define _eet_freelist_list_reset(Ctx) _eet_free_reset(&Ctx->freelist_list);
|
|
|
|
#define _eet_freelist_list_ref(Ctx) _eet_free_ref(&Ctx->freelist_list);
|
|
|
|
#define _eet_freelist_list_unref(Ctx) _eet_free_unref(&Ctx->freelist_list);
|
2003-07-07 00:52:20 -07:00
|
|
|
|
|
|
|
static void
|
2009-03-19 12:00:46 -07:00
|
|
|
_eet_freelist_list_free(Eet_Free_Context *context, Eet_Data_Descriptor *edd)
|
2003-07-07 00:52:20 -07:00
|
|
|
{
|
2008-07-17 09:39:28 -07:00
|
|
|
int j;
|
2003-07-07 00:52:20 -07:00
|
|
|
int i;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2009-03-19 12:00:46 -07:00
|
|
|
if (context->freelist_list.ref > 0) return;
|
2008-07-17 09:39:28 -07:00
|
|
|
for (j = 0; j < 256; ++j)
|
2009-03-19 12:00:46 -07:00
|
|
|
for (i = 0; i < context->freelist_list.num[j]; ++i)
|
2008-07-17 09:39:28 -07:00
|
|
|
{
|
|
|
|
if (edd)
|
2009-03-19 12:00:46 -07:00
|
|
|
edd->func.list_free(*((void**)(context->freelist_list.list[j][i])));
|
2008-07-17 09:39:28 -07:00
|
|
|
}
|
2009-03-19 12:00:46 -07:00
|
|
|
_eet_free_reset(&context->freelist_list);
|
2003-07-07 00:52:20 -07:00
|
|
|
}
|
|
|
|
|
2009-03-19 12:00:46 -07:00
|
|
|
#define _eet_freelist_str_add(Ctx, Data) _eet_free_add(&Ctx->freelist_str, Data);
|
|
|
|
#define _eet_freelist_str_reset(Ctx) _eet_free_reset(&Ctx->freelist_str);
|
|
|
|
#define _eet_freelist_str_ref(Ctx) _eet_free_ref(&Ctx->freelist_str);
|
|
|
|
#define _eet_freelist_str_unref(Ctx) _eet_free_unref(&Ctx->freelist_str);
|
2005-11-30 07:36:19 -08:00
|
|
|
|
|
|
|
static void
|
2009-03-19 12:00:46 -07:00
|
|
|
_eet_freelist_str_free(Eet_Free_Context *context, Eet_Data_Descriptor *edd)
|
2005-11-30 07:36:19 -08:00
|
|
|
{
|
2008-07-17 09:39:28 -07:00
|
|
|
int j;
|
2008-02-29 22:38:09 -08:00
|
|
|
int i;
|
|
|
|
|
2009-03-19 12:00:46 -07:00
|
|
|
if (context->freelist_str.ref > 0) return;
|
2008-07-17 09:39:28 -07:00
|
|
|
for (j = 0; j < 256; ++j)
|
2009-03-19 12:00:46 -07:00
|
|
|
for (i = 0; i < context->freelist_str.num[j]; ++i)
|
2008-07-17 09:39:28 -07:00
|
|
|
{
|
|
|
|
if (edd)
|
2009-03-19 12:00:46 -07:00
|
|
|
edd->func.str_free(context->freelist_str.list[j][i]);
|
2008-07-17 09:39:28 -07:00
|
|
|
else
|
2009-03-19 12:00:46 -07:00
|
|
|
free(context->freelist_str.list[j][i]);
|
2008-07-17 09:39:28 -07:00
|
|
|
}
|
2009-03-19 12:00:46 -07:00
|
|
|
_eet_free_reset(&context->freelist_str);
|
2005-11-30 07:36:19 -08:00
|
|
|
}
|
|
|
|
|
2009-03-19 12:00:46 -07:00
|
|
|
#define _eet_freelist_direct_str_add(Ctx, Data) _eet_free_add(&Ctx->freelist_direct_str, Data);
|
|
|
|
#define _eet_freelist_direct_str_reset(Ctx) _eet_free_reset(&Ctx->freelist_direct_str);
|
|
|
|
#define _eet_freelist_direct_str_ref(Ctx) _eet_free_ref(&Ctx->freelist_direct_str);
|
|
|
|
#define _eet_freelist_direct_str_unref(Ctx) _eet_free_unref(&Ctx->freelist_direct_str);
|
|
|
|
|
|
|
|
static void
|
|
|
|
_eet_freelist_direct_str_free(Eet_Free_Context *context, Eet_Data_Descriptor *edd)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (context->freelist_direct_str.ref > 0) return;
|
|
|
|
for (j = 0; j < 256; ++j)
|
|
|
|
for (i = 0; i < context->freelist_direct_str.num[j]; ++i)
|
|
|
|
{
|
|
|
|
if (edd)
|
|
|
|
edd->func.str_direct_free(context->freelist_direct_str.list[j][i]);
|
|
|
|
else
|
|
|
|
free(context->freelist_direct_str.list[j][i]);
|
|
|
|
}
|
|
|
|
_eet_free_reset(&context->freelist_direct_str);
|
|
|
|
}
|
2008-02-29 22:38:09 -08:00
|
|
|
|
2009-03-19 12:00:46 -07:00
|
|
|
#define _eet_freelist_hash_add(Ctx, Data) _eet_free_add(&Ctx->freelist_hash, Data);
|
|
|
|
#define _eet_freelist_hash_reset(Ctx) _eet_free_reset(&Ctx->freelist_hash);
|
|
|
|
#define _eet_freelist_hash_ref(Ctx) _eet_free_ref(&Ctx->freelist_hash);
|
|
|
|
#define _eet_freelist_hash_unref(Ctx) _eet_free_unref(&Ctx->freelist_hash);
|
2005-11-30 07:36:19 -08:00
|
|
|
|
|
|
|
static void
|
2009-03-19 12:00:46 -07:00
|
|
|
_eet_freelist_hash_free(Eet_Free_Context *context, Eet_Data_Descriptor *edd)
|
2005-11-30 07:36:19 -08:00
|
|
|
{
|
2008-07-17 09:39:28 -07:00
|
|
|
int j;
|
2005-11-30 07:36:19 -08:00
|
|
|
int i;
|
|
|
|
|
2009-03-19 12:00:46 -07:00
|
|
|
if (context->freelist_hash.ref > 0) return;
|
2008-07-17 09:39:28 -07:00
|
|
|
for (j = 0; j < 256; ++j)
|
2009-03-19 12:00:46 -07:00
|
|
|
for (i = 0; i < context->freelist_hash.num[j]; ++i)
|
2008-07-17 09:39:28 -07:00
|
|
|
{
|
|
|
|
if (edd)
|
2009-03-19 12:00:46 -07:00
|
|
|
edd->func.hash_free(context->freelist_hash.list[j][i]);
|
2008-07-17 09:39:28 -07:00
|
|
|
else
|
2009-03-19 12:00:46 -07:00
|
|
|
free(context->freelist_hash.list[j][i]);
|
2008-07-17 09:39:28 -07:00
|
|
|
}
|
2009-03-19 12:00:46 -07:00
|
|
|
_eet_free_reset(&context->freelist_hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_eet_freelist_all_ref(Eet_Free_Context *freelist_context)
|
|
|
|
{
|
|
|
|
_eet_freelist_ref(freelist_context);
|
|
|
|
_eet_freelist_str_ref(freelist_context);
|
|
|
|
_eet_freelist_list_ref(freelist_context);
|
|
|
|
_eet_freelist_hash_ref(freelist_context);
|
|
|
|
_eet_freelist_direct_str_ref(freelist_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_eet_freelist_all_unref(Eet_Free_Context *freelist_context)
|
|
|
|
{
|
|
|
|
_eet_freelist_unref(freelist_context);
|
|
|
|
_eet_freelist_str_unref(freelist_context);
|
|
|
|
_eet_freelist_list_unref(freelist_context);
|
|
|
|
_eet_freelist_hash_unref(freelist_context);
|
|
|
|
_eet_freelist_direct_str_unref(freelist_context);
|
2005-11-30 07:36:19 -08:00
|
|
|
}
|
|
|
|
|
2006-12-17 03:00:45 -08:00
|
|
|
static int
|
2008-04-03 12:47:07 -07:00
|
|
|
eet_data_descriptor_encode_hash_cb(void *hash __UNUSED__, const char *key, void *hdata, void *fdata)
|
2006-12-17 03:00:45 -08:00
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
Eet_Dictionary *ed;
|
|
|
|
Eet_Data_Encode_Hash_Info *edehi;
|
|
|
|
Eet_Data_Stream *ds;
|
|
|
|
Eet_Data_Element *ede;
|
|
|
|
Eet_Data_Chunk *echnk;
|
|
|
|
void *data = NULL;
|
|
|
|
int size;
|
2006-12-17 03:00:45 -08:00
|
|
|
|
|
|
|
edehi = fdata;
|
|
|
|
ede = edehi->ede;
|
|
|
|
ds = edehi->ds;
|
2008-02-29 22:38:09 -08:00
|
|
|
ed = edehi->ed;
|
2006-12-17 03:00:45 -08:00
|
|
|
|
|
|
|
/* Store key */
|
2008-02-29 22:38:09 -08:00
|
|
|
data = eet_data_put_type(ed,
|
|
|
|
EET_T_STRING,
|
2006-12-17 03:00:45 -08:00
|
|
|
&key,
|
|
|
|
&size);
|
|
|
|
if (data)
|
|
|
|
{
|
2007-09-08 00:44:03 -07:00
|
|
|
echnk = eet_data_chunk_new(data, size, ede->name, ede->type, ede->group_type);
|
2008-02-29 22:38:09 -08:00
|
|
|
eet_data_chunk_put(ed, echnk, ds);
|
2006-12-17 03:00:45 -08:00
|
|
|
eet_data_chunk_free(echnk);
|
|
|
|
free(data);
|
|
|
|
data = NULL;
|
|
|
|
}
|
|
|
|
|
2008-10-23 07:41:04 -07:00
|
|
|
EET_ASSERT(!((ede->type > EET_T_UNKNOW) && (ede->type < EET_T_STRING)), return );
|
2008-05-15 07:16:46 -07:00
|
|
|
|
2006-12-17 03:00:45 -08:00
|
|
|
/* Store data */
|
2008-10-23 07:41:04 -07:00
|
|
|
if (ede->type >= EET_T_STRING)
|
|
|
|
eet_data_put_unknown(ed, NULL, ede, ds, &hdata);
|
|
|
|
else
|
2006-12-17 03:00:45 -08:00
|
|
|
{
|
2008-10-23 07:41:04 -07:00
|
|
|
if (ede->subtype)
|
|
|
|
data = _eet_data_descriptor_encode(ed,
|
|
|
|
ede->subtype,
|
|
|
|
hdata,
|
|
|
|
&size);
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
echnk = eet_data_chunk_new(data, size, ede->name, ede->type, ede->group_type);
|
|
|
|
eet_data_chunk_put(ed, echnk, ds);
|
|
|
|
eet_data_chunk_free(echnk);
|
|
|
|
free(data);
|
|
|
|
data = NULL;
|
|
|
|
}
|
2006-12-17 03:00:45 -08:00
|
|
|
}
|
2008-10-23 07:41:04 -07:00
|
|
|
|
2006-12-17 03:00:45 -08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-09-08 00:44:03 -07:00
|
|
|
static char *
|
|
|
|
_eet_data_string_escape(const char *str)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2007-09-08 00:44:03 -07:00
|
|
|
char *s, *sp;
|
|
|
|
const char *strp;
|
|
|
|
int sz = 0;
|
|
|
|
|
|
|
|
for (strp = str; *strp; strp++)
|
|
|
|
{
|
2008-03-07 01:59:37 -08:00
|
|
|
if (*strp == '\"') sz += 2;
|
|
|
|
else if (*strp == '\\') sz += 2;
|
2007-09-08 00:44:03 -07:00
|
|
|
else sz += 1;
|
|
|
|
}
|
|
|
|
s = malloc(sz + 1);
|
2007-09-14 16:38:17 -07:00
|
|
|
if (!s) return NULL;
|
2007-09-08 00:44:03 -07:00
|
|
|
for (strp = str, sp = s; *strp; strp++, sp++)
|
|
|
|
{
|
|
|
|
if (*strp == '\"')
|
|
|
|
{
|
|
|
|
*sp = '\\';
|
|
|
|
sp++;
|
|
|
|
}
|
2007-09-08 08:32:33 -07:00
|
|
|
else if (*strp == '\\')
|
|
|
|
{
|
|
|
|
*sp = '\\';
|
|
|
|
sp++;
|
|
|
|
}
|
2007-09-08 00:44:03 -07:00
|
|
|
*sp = *strp;
|
|
|
|
}
|
|
|
|
*sp = 0;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-09-14 16:38:17 -07:00
|
|
|
_eet_data_dump_string_escape(void *dumpdata, void dumpfunc(void *data, const char *str), const char *str)
|
2007-09-08 00:44:03 -07:00
|
|
|
{
|
|
|
|
char *s;
|
2008-03-07 01:59:37 -08:00
|
|
|
|
2007-09-08 00:44:03 -07:00
|
|
|
s = _eet_data_string_escape(str);
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
dumpfunc(dumpdata, s);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2007-09-14 16:38:17 -07:00
|
|
|
_eet_data_dump_token_get(const char *src, int *len)
|
2007-09-08 00:44:03 -07:00
|
|
|
{
|
2007-09-14 16:38:17 -07:00
|
|
|
const char *p;
|
|
|
|
char *tok = NULL;
|
2007-09-08 00:44:03 -07:00
|
|
|
int in_token = 0;
|
|
|
|
int in_quote = 0;
|
|
|
|
int tlen = 0, tsize = 0;
|
2008-03-07 01:59:37 -08:00
|
|
|
|
2007-09-08 00:44:03 -07:00
|
|
|
#define TOK_ADD(x) \
|
|
|
|
{ \
|
|
|
|
tlen++; \
|
|
|
|
if (tlen >= tsize) \
|
|
|
|
{ \
|
|
|
|
tsize += 32; \
|
|
|
|
tok = realloc(tok, tsize); \
|
|
|
|
} \
|
|
|
|
tok[tlen - 1] = x; \
|
|
|
|
}
|
2008-03-07 01:59:37 -08:00
|
|
|
|
2007-09-08 00:44:03 -07:00
|
|
|
for (p = src; *len > 0; p++, (*len)--)
|
|
|
|
{
|
|
|
|
if (in_token)
|
|
|
|
{
|
|
|
|
if (in_quote)
|
|
|
|
{
|
|
|
|
if ((p[0] == '\"') && (p > src) && (p[-1] != '\\'))
|
|
|
|
{
|
|
|
|
in_quote = 0;
|
|
|
|
}
|
|
|
|
else if ((p[0] == '\\') && (*len > 1) && (p[1] == '\"'))
|
|
|
|
{
|
|
|
|
/* skip */
|
|
|
|
}
|
2007-09-08 08:32:33 -07:00
|
|
|
else if ((p[0] == '\\') && (p > src) && (p[-1] == '\\'))
|
|
|
|
{
|
|
|
|
/* skip */
|
|
|
|
}
|
2007-09-08 00:44:03 -07:00
|
|
|
else
|
|
|
|
TOK_ADD(p[0]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (p[0] == '\"') in_quote = 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((isspace(p[0])) || (p[0] == ';')) /* token ends here */
|
|
|
|
{
|
|
|
|
TOK_ADD(0);
|
|
|
|
(*len)--;
|
|
|
|
return tok;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
TOK_ADD(p[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!((isspace(p[0])) || (p[0] == ';')))
|
|
|
|
{
|
|
|
|
in_token = 1;
|
|
|
|
(*len)++;
|
|
|
|
p--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (in_token)
|
|
|
|
{
|
|
|
|
TOK_ADD(0);
|
|
|
|
return tok;
|
|
|
|
}
|
|
|
|
if (tok) free(tok);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
2008-02-29 22:38:09 -08:00
|
|
|
_eet_data_dump_encode(Eet_Dictionary *ed,
|
2009-04-16 05:18:18 -07:00
|
|
|
Eet_Node *node,
|
2007-09-08 00:44:03 -07:00
|
|
|
int *size_ret)
|
|
|
|
{
|
|
|
|
Eet_Data_Chunk *chnk = NULL, *echnk = NULL;
|
|
|
|
Eet_Data_Stream *ds;
|
|
|
|
void *cdata, *data;
|
|
|
|
int csize, size;
|
2009-04-16 05:18:18 -07:00
|
|
|
Eet_Node *n;
|
2008-03-07 01:59:37 -08:00
|
|
|
|
2009-11-02 00:41:43 -08:00
|
|
|
if (_eet_data_words_bigendian == -1)
|
2007-09-08 00:44:03 -07:00
|
|
|
{
|
|
|
|
unsigned long int v;
|
2008-03-07 01:59:37 -08:00
|
|
|
|
2007-09-08 00:44:03 -07:00
|
|
|
v = htonl(0x12345678);
|
2009-11-02 00:41:43 -08:00
|
|
|
if (v == 0x12345678) _eet_data_words_bigendian = 1;
|
|
|
|
else _eet_data_words_bigendian = 0;
|
2007-09-08 00:44:03 -07:00
|
|
|
}
|
2008-02-29 22:38:09 -08:00
|
|
|
|
2009-06-04 02:29:56 -07:00
|
|
|
if (node == NULL) return NULL;
|
|
|
|
|
2007-09-08 00:44:03 -07:00
|
|
|
ds = eet_data_stream_new();
|
|
|
|
if (!ds) return NULL;
|
2008-03-07 01:59:37 -08:00
|
|
|
|
2007-09-08 00:44:03 -07:00
|
|
|
switch (node->type)
|
|
|
|
{
|
|
|
|
case EET_G_UNKNOWN:
|
|
|
|
for (n = node->values; n; n = n->next)
|
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
data = _eet_data_dump_encode(ed, n, &size);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
eet_data_stream_write(ds, data, size);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EET_G_ARRAY:
|
2008-06-26 08:47:25 -07:00
|
|
|
case EET_G_VAR_ARRAY:
|
|
|
|
data = eet_data_put_type(ed,
|
|
|
|
EET_T_INT,
|
|
|
|
&node->count,
|
|
|
|
&size);
|
|
|
|
if (data)
|
2007-09-08 00:44:03 -07:00
|
|
|
{
|
2008-06-26 08:47:25 -07:00
|
|
|
echnk = eet_data_chunk_new(data, size, node->name, node->type, node->type);
|
|
|
|
eet_data_chunk_put(ed, echnk, ds);
|
|
|
|
eet_data_chunk_free(echnk);
|
|
|
|
free(data);
|
2007-09-08 00:44:03 -07:00
|
|
|
}
|
|
|
|
for (n = node->values; n; n = n->next)
|
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
data = _eet_data_dump_encode(ed, n, &size);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (data)
|
|
|
|
{
|
2008-06-26 08:47:25 -07:00
|
|
|
echnk = eet_data_chunk_new(data, size, node->name, node->type, node->type);
|
|
|
|
eet_data_chunk_put(ed, echnk, ds);
|
|
|
|
eet_data_chunk_free(echnk);
|
2007-09-08 00:44:03 -07:00
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
}
|
2008-06-26 08:47:25 -07:00
|
|
|
|
|
|
|
/* Array is somekind of special case, so we should embed it inside another chunk. */
|
|
|
|
*size_ret = ds->pos;
|
|
|
|
cdata = ds->data;
|
|
|
|
|
|
|
|
ds->data = NULL;
|
|
|
|
ds->size = 0;
|
|
|
|
eet_data_stream_free(ds);
|
|
|
|
|
|
|
|
return cdata;
|
2007-09-08 00:44:03 -07:00
|
|
|
case EET_G_LIST:
|
|
|
|
for (n = node->values; n; n = n->next)
|
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
data = _eet_data_dump_encode(ed, n, &size);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
eet_data_stream_write(ds, data, size);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EET_G_HASH:
|
|
|
|
if (node->key)
|
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
data = eet_data_put_type(ed,
|
|
|
|
EET_T_STRING,
|
2007-09-08 00:44:03 -07:00
|
|
|
&node->key,
|
|
|
|
&size);
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
echnk = eet_data_chunk_new(data, size, node->name, node->type, node->type);
|
2008-02-29 22:38:09 -08:00
|
|
|
eet_data_chunk_put(ed, echnk, ds);
|
2007-09-08 00:44:03 -07:00
|
|
|
eet_data_chunk_free(echnk);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (n = node->values; n; n = n->next)
|
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
data = _eet_data_dump_encode(ed, n, &size);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (data)
|
|
|
|
{
|
2008-05-14 13:53:07 -07:00
|
|
|
echnk = eet_data_chunk_new(data, size, node->name, node->type, node->type);
|
|
|
|
eet_data_chunk_put(ed, echnk, ds);
|
|
|
|
eet_data_chunk_free(echnk);
|
2007-09-08 00:44:03 -07:00
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
}
|
2008-05-14 13:53:07 -07:00
|
|
|
|
|
|
|
/* Hash is somekind of special case, so we should embed it inside another chunk. */
|
|
|
|
*size_ret = ds->pos;
|
|
|
|
cdata = ds->data;
|
|
|
|
|
|
|
|
ds->data = NULL;
|
|
|
|
ds->size = 0;
|
|
|
|
eet_data_stream_free(ds);
|
|
|
|
|
|
|
|
return cdata;
|
2008-10-24 07:06:40 -07:00
|
|
|
case EET_T_NULL:
|
|
|
|
break;
|
2007-09-08 00:44:03 -07:00
|
|
|
case EET_T_CHAR:
|
2008-02-29 22:38:09 -08:00
|
|
|
data = eet_data_put_type(ed, node->type, &(node->data.c), &size);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
eet_data_stream_write(ds, data, size);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EET_T_SHORT:
|
2008-02-29 22:38:09 -08:00
|
|
|
data = eet_data_put_type(ed, node->type, &(node->data.s), &size);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
eet_data_stream_write(ds, data, size);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EET_T_INT:
|
2008-02-29 22:38:09 -08:00
|
|
|
data = eet_data_put_type(ed, node->type, &(node->data.i), &size);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
eet_data_stream_write(ds, data, size);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EET_T_LONG_LONG:
|
2008-02-29 22:38:09 -08:00
|
|
|
data = eet_data_put_type(ed, node->type, &(node->data.l), &size);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
eet_data_stream_write(ds, data, size);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EET_T_FLOAT:
|
2008-02-29 22:38:09 -08:00
|
|
|
data = eet_data_put_type(ed, node->type, &(node->data.f), &size);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
eet_data_stream_write(ds, data, size);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EET_T_DOUBLE:
|
2008-02-29 22:38:09 -08:00
|
|
|
data = eet_data_put_type(ed, node->type, &(node->data.d), &size);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
eet_data_stream_write(ds, data, size);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EET_T_UCHAR:
|
2008-02-29 22:38:09 -08:00
|
|
|
data = eet_data_put_type(ed, node->type, &(node->data.uc), &size);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
eet_data_stream_write(ds, data, size);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EET_T_USHORT:
|
2008-02-29 22:38:09 -08:00
|
|
|
data = eet_data_put_type(ed, node->type, &(node->data.us), &size);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
eet_data_stream_write(ds, data, size);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EET_T_UINT:
|
2008-02-29 22:38:09 -08:00
|
|
|
data = eet_data_put_type(ed, node->type, &(node->data.ui), &size);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
eet_data_stream_write(ds, data, size);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EET_T_ULONG_LONG:
|
2008-02-29 22:38:09 -08:00
|
|
|
data = eet_data_put_type(ed, node->type, &(node->data.ul), &size);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
eet_data_stream_write(ds, data, size);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
break;
|
2008-03-06 09:52:59 -08:00
|
|
|
case EET_T_INLINED_STRING:
|
2008-05-14 13:54:15 -07:00
|
|
|
data = eet_data_put_type(ed, node->type, &(node->data.str), &size);
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
eet_data_stream_write(ds, data, size);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
break;
|
2007-09-08 00:44:03 -07:00
|
|
|
case EET_T_STRING:
|
2008-02-29 22:38:09 -08:00
|
|
|
data = eet_data_put_type(ed, node->type, &(node->data.str), &size);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
eet_data_stream_write(ds, data, size);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-03-07 01:59:37 -08:00
|
|
|
|
2008-06-27 08:26:53 -07:00
|
|
|
if ((node->type >= EET_G_UNKNOWN) && (node->type < EET_G_LAST))
|
2007-09-08 00:44:03 -07:00
|
|
|
chnk = eet_data_chunk_new(ds->data, ds->pos, node->name, EET_T_UNKNOW, node->type);
|
|
|
|
else
|
|
|
|
chnk = eet_data_chunk_new(ds->data, ds->pos, node->name, node->type, EET_G_UNKNOWN);
|
|
|
|
ds->data = NULL;
|
|
|
|
ds->size = 0;
|
|
|
|
eet_data_stream_free(ds);
|
2008-03-07 01:59:37 -08:00
|
|
|
|
2007-09-08 00:44:03 -07:00
|
|
|
ds = eet_data_stream_new();
|
2008-02-29 22:38:09 -08:00
|
|
|
eet_data_chunk_put(ed, chnk, ds);
|
2007-09-08 00:44:03 -07:00
|
|
|
cdata = ds->data;
|
|
|
|
csize = ds->pos;
|
2008-03-07 01:59:37 -08:00
|
|
|
|
2007-09-08 00:44:03 -07:00
|
|
|
ds->data = NULL;
|
|
|
|
ds->size = 0;
|
|
|
|
eet_data_stream_free(ds);
|
|
|
|
*size_ret = csize;
|
2008-03-07 01:59:37 -08:00
|
|
|
|
2007-09-08 00:44:03 -07:00
|
|
|
free(chnk->data);
|
|
|
|
eet_data_chunk_free(chnk);
|
2008-03-07 01:59:37 -08:00
|
|
|
|
2007-09-08 00:44:03 -07:00
|
|
|
return cdata;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
2008-02-29 22:38:09 -08:00
|
|
|
_eet_data_dump_parse(Eet_Dictionary *ed,
|
|
|
|
int *size_ret,
|
2007-09-14 16:38:17 -07:00
|
|
|
const char *src,
|
2007-09-08 00:44:03 -07:00
|
|
|
int size)
|
|
|
|
{
|
|
|
|
void *cdata = NULL;
|
2007-09-14 16:38:17 -07:00
|
|
|
const char *p;
|
2007-09-08 00:44:03 -07:00
|
|
|
#define M_NONE 0
|
|
|
|
#define M_STRUCT 1
|
|
|
|
#define M_ 2
|
|
|
|
int left, jump;
|
2009-04-16 05:18:18 -07:00
|
|
|
Eet_Node *node_base = NULL;
|
|
|
|
Eet_Node *node = NULL;
|
|
|
|
Eet_Node *n, *nn;
|
2007-09-08 00:44:03 -07:00
|
|
|
|
|
|
|
/* FIXME; handle parse errors */
|
|
|
|
#define TOK_GET(t) \
|
|
|
|
jump = left; t = _eet_data_dump_token_get(p, &left); p += jump - left;
|
|
|
|
left = size;
|
|
|
|
for (p = src; p < (src + size);)
|
|
|
|
{
|
|
|
|
char *tok1, *tok2, *tok3, *tok4;
|
2008-03-07 01:59:37 -08:00
|
|
|
|
2007-09-08 00:44:03 -07:00
|
|
|
TOK_GET(tok1);
|
|
|
|
if (tok1)
|
|
|
|
{
|
|
|
|
if (!strcmp(tok1, "group"))
|
|
|
|
{
|
|
|
|
TOK_GET(tok2);
|
|
|
|
if (tok2)
|
|
|
|
{
|
|
|
|
TOK_GET(tok3);
|
|
|
|
if (tok3)
|
|
|
|
{
|
|
|
|
TOK_GET(tok4);
|
|
|
|
if (tok4)
|
|
|
|
{
|
|
|
|
if (!strcmp(tok4, "{"))
|
|
|
|
{
|
|
|
|
/* we have 'group NAM TYP {' */
|
2009-04-16 05:18:18 -07:00
|
|
|
n = calloc(1, sizeof(Eet_Node));
|
2007-09-08 00:44:03 -07:00
|
|
|
if (n)
|
|
|
|
{
|
|
|
|
n->parent = node;
|
|
|
|
if (!node_base)
|
|
|
|
{
|
|
|
|
node_base = n;
|
|
|
|
}
|
2009-03-13 09:12:24 -07:00
|
|
|
if (node)
|
2007-09-08 00:44:03 -07:00
|
|
|
{
|
|
|
|
/* append node */
|
|
|
|
if (!node->values)
|
|
|
|
node->values = n;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (nn = node->values; nn; nn = nn->next)
|
|
|
|
{
|
|
|
|
if (!nn->next)
|
|
|
|
{
|
|
|
|
nn->next = n;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-04-16 05:18:18 -07:00
|
|
|
n->name = eina_stringshare_add(tok2);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (!strcmp(tok3, "struct")) n->type = EET_G_UNKNOWN;
|
|
|
|
else if (!strcmp(tok3, "array")) n->type = EET_G_ARRAY;
|
|
|
|
else if (!strcmp(tok3, "var_array")) n->type = EET_G_VAR_ARRAY;
|
|
|
|
else if (!strcmp(tok3, "list")) n->type = EET_G_LIST;
|
|
|
|
else if (!strcmp(tok3, "hash")) n->type = EET_G_HASH;
|
|
|
|
else
|
|
|
|
{
|
2009-09-17 07:33:06 -07:00
|
|
|
ERR("ERROR: group type '%s' invalid.", tok3);
|
2007-09-08 00:44:03 -07:00
|
|
|
}
|
|
|
|
node = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(tok4);
|
|
|
|
}
|
|
|
|
free(tok3);
|
|
|
|
}
|
|
|
|
free(tok2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!strcmp(tok1, "value"))
|
|
|
|
{
|
|
|
|
TOK_GET(tok2);
|
|
|
|
if (tok2)
|
|
|
|
{
|
|
|
|
TOK_GET(tok3);
|
|
|
|
if (tok3)
|
|
|
|
{
|
|
|
|
TOK_GET(tok4);
|
|
|
|
if (tok4)
|
|
|
|
{
|
|
|
|
/* we have 'value NAME TYP XXX' */
|
|
|
|
if (node_base)
|
|
|
|
{
|
2009-04-16 05:18:18 -07:00
|
|
|
n = calloc(1, sizeof(Eet_Node));
|
2007-09-08 00:44:03 -07:00
|
|
|
if (n)
|
|
|
|
{
|
|
|
|
n->parent = node;
|
|
|
|
/* append node */
|
|
|
|
if (!node->values)
|
|
|
|
node->values = n;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (nn = node->values; nn; nn = nn->next)
|
|
|
|
{
|
|
|
|
if (!nn->next)
|
|
|
|
{
|
|
|
|
nn->next = n;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-04-16 05:18:18 -07:00
|
|
|
n->name = eina_stringshare_add(tok2);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (!strcmp(tok3, "char:"))
|
|
|
|
{
|
|
|
|
n->type = EET_T_CHAR;
|
|
|
|
sscanf(tok4, "%hhi", &(n->data.c));
|
|
|
|
}
|
|
|
|
else if (!strcmp(tok3, "short:"))
|
|
|
|
{
|
|
|
|
n->type = EET_T_SHORT;
|
|
|
|
sscanf(tok4, "%hi", &(n->data.s));
|
|
|
|
}
|
|
|
|
else if (!strcmp(tok3, "int:"))
|
|
|
|
{
|
|
|
|
n->type = EET_T_INT;
|
|
|
|
sscanf(tok4, "%i", &(n->data.i));
|
|
|
|
}
|
|
|
|
else if (!strcmp(tok3, "long_long:"))
|
|
|
|
{
|
|
|
|
n->type = EET_T_LONG_LONG;
|
|
|
|
sscanf(tok4, "%lli", &(n->data.l));
|
|
|
|
}
|
|
|
|
else if (!strcmp(tok3, "float:"))
|
|
|
|
{
|
|
|
|
n->type = EET_T_FLOAT;
|
|
|
|
sscanf(tok4, "%f", &(n->data.f));
|
|
|
|
}
|
|
|
|
else if (!strcmp(tok3, "double:"))
|
|
|
|
{
|
|
|
|
n->type = EET_T_DOUBLE;
|
|
|
|
sscanf(tok4, "%lf", &(n->data.d));
|
|
|
|
}
|
|
|
|
else if (!strcmp(tok3, "uchar:"))
|
|
|
|
{
|
|
|
|
n->type = EET_T_UCHAR;
|
|
|
|
sscanf(tok4, "%hhu", &(n->data.uc));
|
|
|
|
}
|
|
|
|
else if (!strcmp(tok3, "ushort:"))
|
|
|
|
{
|
|
|
|
n->type = EET_T_USHORT;
|
|
|
|
sscanf(tok4, "%hu", &(n->data.us));
|
|
|
|
}
|
2008-05-15 07:03:09 -07:00
|
|
|
else if (!strcmp(tok3, "uint:"))
|
2007-09-08 00:44:03 -07:00
|
|
|
{
|
|
|
|
n->type = EET_T_UINT;
|
|
|
|
sscanf(tok4, "%u", &(n->data.ui));
|
|
|
|
}
|
|
|
|
else if (!strcmp(tok3, "ulong_long:"))
|
|
|
|
{
|
|
|
|
n->type = EET_T_ULONG_LONG;
|
|
|
|
sscanf(tok4, "%llu", &(n->data.ul));
|
|
|
|
}
|
|
|
|
else if (!strcmp(tok3, "string:"))
|
|
|
|
{
|
|
|
|
n->type = EET_T_STRING;
|
2009-04-16 05:18:18 -07:00
|
|
|
n->data.str = eina_stringshare_add(tok4);
|
2007-09-08 00:44:03 -07:00
|
|
|
}
|
2008-05-14 13:54:15 -07:00
|
|
|
else if (!strcmp(tok3, "inlined:"))
|
|
|
|
{
|
|
|
|
n->type = EET_T_INLINED_STRING;
|
2009-04-16 05:18:18 -07:00
|
|
|
n->data.str = eina_stringshare_add(tok4);
|
2008-05-14 13:54:15 -07:00
|
|
|
}
|
2008-10-24 07:06:40 -07:00
|
|
|
else if (!strcmp(tok3, "null"))
|
|
|
|
{
|
|
|
|
n->type = EET_T_NULL;
|
|
|
|
n->data.str = NULL;
|
|
|
|
}
|
2007-09-08 00:44:03 -07:00
|
|
|
else
|
|
|
|
{
|
2009-09-17 07:33:06 -07:00
|
|
|
ERR("ERROR: value type '%s' invalid.", tok4);
|
2007-09-08 00:44:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(tok4);
|
|
|
|
}
|
|
|
|
free(tok3);
|
|
|
|
}
|
|
|
|
free(tok2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!strcmp(tok1, "key"))
|
|
|
|
{
|
|
|
|
TOK_GET(tok2);
|
|
|
|
if (tok2)
|
|
|
|
{
|
|
|
|
/* we have 'key NAME' */
|
|
|
|
if (node)
|
|
|
|
{
|
2009-04-16 05:18:18 -07:00
|
|
|
node->key = eina_stringshare_add(tok2);
|
2007-09-08 00:44:03 -07:00
|
|
|
}
|
|
|
|
free(tok2);
|
|
|
|
}
|
|
|
|
}
|
2008-06-26 08:47:25 -07:00
|
|
|
else if (!strcmp(tok1, "count"))
|
|
|
|
{
|
|
|
|
TOK_GET(tok2);
|
|
|
|
if (tok2)
|
|
|
|
{
|
|
|
|
/* we have a 'count COUNT' */
|
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
sscanf(tok2, "%i", &(node->count));
|
|
|
|
}
|
|
|
|
free(tok2);
|
|
|
|
}
|
|
|
|
}
|
2007-09-08 00:44:03 -07:00
|
|
|
else if (!strcmp(tok1, "}"))
|
|
|
|
{
|
|
|
|
/* we have an end of the group */
|
|
|
|
if (node) node = node->parent;
|
|
|
|
}
|
|
|
|
free(tok1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node_base)
|
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
cdata = _eet_data_dump_encode(ed, node_base, size_ret);
|
2009-04-16 05:18:18 -07:00
|
|
|
eet_node_del(node_base);
|
2007-09-08 00:44:03 -07:00
|
|
|
}
|
|
|
|
return cdata;
|
|
|
|
}
|
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
#define NEXT_CHUNK(P, Size, Echnk, Ed) \
|
|
|
|
{ \
|
|
|
|
int tmp; \
|
2008-07-17 13:28:59 -07:00
|
|
|
tmp = Ed ? (int) (sizeof(int) * 2) : Echnk.len + 4;\
|
2008-02-29 22:38:09 -08:00
|
|
|
P += (4 + Echnk.size + tmp); \
|
|
|
|
Size -= (4 + Echnk.size + tmp); \
|
|
|
|
}
|
|
|
|
|
2009-04-16 08:19:14 -07:00
|
|
|
static const char *_dump_g_name[6] = {
|
|
|
|
"struct",
|
|
|
|
"array",
|
|
|
|
"var_array",
|
|
|
|
"list",
|
|
|
|
"hash",
|
|
|
|
"???"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *_dump_t_name[14][2] = {
|
|
|
|
{ "???: ", "???" },
|
|
|
|
{ "char: ", "%hhi" },
|
|
|
|
{ "short: ", "%hi" },
|
|
|
|
{ "int: ", "%i" },
|
|
|
|
{ "long_long: ", "%lli" },
|
|
|
|
{ "float: ", "%1.25f" },
|
|
|
|
{ "double: ", "%1.25f" },
|
|
|
|
{ "uchar: ", "%hhu" },
|
|
|
|
{ "ushort: ", "%i" },
|
|
|
|
{ "uint: ", "%u" },
|
|
|
|
{ "ulong_long: ", "%llu" },
|
|
|
|
{ "null", "" }
|
|
|
|
};
|
|
|
|
|
2007-09-08 00:44:03 -07:00
|
|
|
static void *
|
2009-03-19 12:00:46 -07:00
|
|
|
_eet_data_descriptor_decode(Eet_Free_Context *context,
|
|
|
|
const Eet_Dictionary *ed,
|
2008-02-29 22:38:09 -08:00
|
|
|
Eet_Data_Descriptor *edd,
|
2007-09-08 00:44:03 -07:00
|
|
|
const void *data_in,
|
|
|
|
int size_in,
|
|
|
|
int level,
|
|
|
|
void (*dumpfunc) (void *data, const char *str),
|
|
|
|
void *dumpdata)
|
|
|
|
{
|
|
|
|
void *data = NULL;
|
2009-05-14 08:58:10 -07:00
|
|
|
char *p;
|
2007-09-14 16:38:17 -07:00
|
|
|
int size, i, dump;
|
2005-11-27 10:54:02 -08:00
|
|
|
Eet_Data_Chunk chnk;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2009-11-02 00:41:43 -08:00
|
|
|
if (_eet_data_words_bigendian == -1)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
|
|
|
unsigned long int v;
|
|
|
|
|
|
|
|
v = htonl(0x12345678);
|
2009-11-02 00:41:43 -08:00
|
|
|
if (v == 0x12345678) _eet_data_words_bigendian = 1;
|
|
|
|
else _eet_data_words_bigendian = 0;
|
2002-12-02 15:39:26 -08:00
|
|
|
}
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2007-09-08 00:44:03 -07:00
|
|
|
if (edd)
|
|
|
|
{
|
|
|
|
data = edd->func.mem_alloc(edd->size);
|
|
|
|
if (!data) return NULL;
|
2008-07-18 04:39:38 -07:00
|
|
|
if (edd->ed != ed)
|
|
|
|
{
|
|
|
|
for (i = 0; i < edd->elements.num; i++)
|
|
|
|
edd->elements.set[i].directory_name_ptr = NULL;
|
|
|
|
edd->ed = ed;
|
|
|
|
}
|
2007-09-08 00:44:03 -07:00
|
|
|
}
|
2009-03-19 12:00:46 -07:00
|
|
|
_eet_freelist_all_ref(context);
|
|
|
|
if (data) _eet_freelist_add(context, data);
|
2007-09-08 00:44:03 -07:00
|
|
|
dump = 0;
|
2005-11-27 10:54:02 -08:00
|
|
|
memset(&chnk, 0, sizeof(Eet_Data_Chunk));
|
2008-02-29 22:38:09 -08:00
|
|
|
eet_data_chunk_get(ed, &chnk, data_in, size_in);
|
2006-12-16 14:27:18 -08:00
|
|
|
if (!chnk.name) goto error;
|
2007-09-08 00:44:03 -07:00
|
|
|
if (edd)
|
|
|
|
{
|
|
|
|
if (strcmp(chnk.name, edd->name)) goto error;
|
|
|
|
}
|
2005-11-27 10:54:02 -08:00
|
|
|
p = chnk.data;
|
2008-02-29 22:38:09 -08:00
|
|
|
if (ed)
|
|
|
|
size = size_in - (4 + sizeof(int) * 2);
|
|
|
|
else
|
|
|
|
size = size_in - (4 + 4 + chnk.len);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (edd)
|
|
|
|
{
|
|
|
|
if (!edd->elements.hash.buckets) _eet_descriptor_hash_new(edd);
|
|
|
|
}
|
2009-04-16 08:19:14 -07:00
|
|
|
else if (dumpfunc)
|
2007-09-08 00:44:03 -07:00
|
|
|
{
|
|
|
|
dump = 1;
|
|
|
|
if (chnk.type == EET_T_UNKNOW)
|
2009-05-14 08:58:10 -07:00
|
|
|
eet_data_dump_group_start(level, dumpfunc, dumpdata, chnk.group_type, chnk.name);
|
2007-09-08 00:44:03 -07:00
|
|
|
}
|
2002-12-02 15:39:26 -08:00
|
|
|
while (size > 0)
|
|
|
|
{
|
2005-11-27 10:54:02 -08:00
|
|
|
Eet_Data_Chunk echnk;
|
2009-05-14 08:58:10 -07:00
|
|
|
Eet_Data_Element *ede = NULL;
|
|
|
|
unsigned char dd[128];
|
|
|
|
int group_type = EET_G_UNKNOWN, type = EET_T_UNKNOW;
|
|
|
|
int ret = 0;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
/* get next data chunk */
|
2005-11-27 10:54:02 -08:00
|
|
|
memset(&echnk, 0, sizeof(Eet_Data_Chunk));
|
2008-02-29 22:38:09 -08:00
|
|
|
eet_data_chunk_get(ed, &echnk, p, size);
|
2006-12-16 14:27:18 -08:00
|
|
|
if (!echnk.name) goto error;
|
2007-09-08 00:44:03 -07:00
|
|
|
/* FIXME: don't REPLY on edd - work without */
|
|
|
|
if ((edd) && (!dumpfunc))
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2008-07-17 08:33:40 -07:00
|
|
|
ede = _eet_descriptor_hash_find(edd, echnk.name, echnk.hash);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (ede)
|
|
|
|
{
|
2007-09-08 18:46:47 -07:00
|
|
|
group_type = ede->group_type;
|
|
|
|
type = ede->type;
|
2007-09-08 00:44:03 -07:00
|
|
|
if ((echnk.type == 0) && (echnk.group_type == 0))
|
|
|
|
{
|
|
|
|
type = ede->type;
|
|
|
|
group_type = ede->group_type;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-26 08:47:25 -07:00
|
|
|
if (IS_SIMPLE_TYPE(echnk.type) &&
|
2009-09-29 06:24:45 -07:00
|
|
|
eet_data_type_match(echnk.type, ede->type))
|
2007-09-08 00:44:03 -07:00
|
|
|
type = echnk.type;
|
|
|
|
else if ((echnk.group_type > EET_G_UNKNOWN) &&
|
|
|
|
(echnk.group_type < EET_G_LAST) &&
|
|
|
|
(echnk.group_type == ede->group_type))
|
|
|
|
group_type = echnk.group_type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*...... dump func */
|
|
|
|
else if (dumpfunc)
|
|
|
|
{
|
|
|
|
if ((echnk.type > EET_T_UNKNOW) &&
|
|
|
|
(echnk.type < EET_T_LAST))
|
2007-09-08 18:46:47 -07:00
|
|
|
type = echnk.type;
|
2007-09-08 00:44:03 -07:00
|
|
|
else if ((echnk.group_type > EET_G_UNKNOWN) &&
|
|
|
|
(echnk.group_type < EET_G_LAST))
|
|
|
|
group_type = echnk.group_type;
|
2009-05-14 08:58:10 -07:00
|
|
|
}
|
2009-04-16 08:19:14 -07:00
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
if (dumpfunc && group_type == EET_G_UNKNOWN && IS_SIMPLE_TYPE(type))
|
|
|
|
{
|
|
|
|
ret = eet_data_get_type(ed,
|
|
|
|
type,
|
|
|
|
echnk.data,
|
|
|
|
((char *)echnk.data) + echnk.size,
|
|
|
|
dd);
|
|
|
|
if (ret <= 0) goto error;
|
|
|
|
|
|
|
|
eet_data_dump_simple_type(type, echnk.name, dd, level, dumpfunc, dumpdata);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = eet_group_codec[group_type - 100].get(context,
|
|
|
|
ed, edd, ede, &echnk,
|
2009-05-18 07:46:32 -07:00
|
|
|
type, group_type, ede ? (void*) (((char *)data) + ede->offset) : dd,
|
2009-05-14 08:58:10 -07:00
|
|
|
level, dumpfunc, dumpdata,
|
|
|
|
&p, &size);
|
|
|
|
if (ret <= 0) goto error;
|
2002-12-02 15:39:26 -08:00
|
|
|
}
|
|
|
|
/* advance to next chunk */
|
2008-02-29 22:38:09 -08:00
|
|
|
NEXT_CHUNK(p, size, echnk, ed);
|
2002-12-02 15:39:26 -08:00
|
|
|
}
|
2009-06-02 09:24:28 -07:00
|
|
|
|
2009-03-19 12:00:46 -07:00
|
|
|
_eet_freelist_all_unref(context);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (dumpfunc)
|
|
|
|
{
|
2009-03-19 12:00:46 -07:00
|
|
|
_eet_freelist_str_free(context, edd);
|
|
|
|
_eet_freelist_direct_str_free(context, edd);
|
|
|
|
_eet_freelist_list_free(context, edd);
|
|
|
|
_eet_freelist_hash_free(context, edd);
|
|
|
|
_eet_freelist_free(context, edd);
|
2007-09-08 00:44:03 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-19 12:00:46 -07:00
|
|
|
_eet_freelist_reset(context);
|
|
|
|
_eet_freelist_str_reset(context);
|
|
|
|
_eet_freelist_list_reset(context);
|
|
|
|
_eet_freelist_hash_reset(context);
|
|
|
|
_eet_freelist_direct_str_reset(context);
|
2007-09-08 00:44:03 -07:00
|
|
|
}
|
|
|
|
if (dumpfunc)
|
|
|
|
{
|
|
|
|
if (dump)
|
|
|
|
{
|
|
|
|
if (chnk.type == EET_T_UNKNOW)
|
|
|
|
{
|
|
|
|
for (i = 0; i < level; i++) dumpfunc(dumpdata, " ");
|
|
|
|
dumpfunc(dumpdata, "}\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (void *)1;
|
|
|
|
}
|
2002-12-02 15:39:26 -08:00
|
|
|
return data;
|
2006-12-16 14:27:18 -08:00
|
|
|
|
|
|
|
error:
|
2009-03-19 12:00:46 -07:00
|
|
|
_eet_freelist_all_unref(context);
|
|
|
|
_eet_freelist_str_free(context, edd);
|
|
|
|
_eet_freelist_direct_str_free(context, edd);
|
|
|
|
_eet_freelist_list_free(context, edd);
|
|
|
|
_eet_freelist_hash_free(context, edd);
|
|
|
|
_eet_freelist_free(context, edd);
|
2007-09-08 00:44:03 -07:00
|
|
|
if (dumpfunc)
|
|
|
|
{
|
|
|
|
if (dump)
|
|
|
|
{
|
|
|
|
if (chnk.type == EET_T_UNKNOW)
|
|
|
|
{
|
|
|
|
for (i = 0; i < level; i++) dumpfunc(dumpdata, " ");
|
|
|
|
dumpfunc(dumpdata, "}\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-12-16 14:27:18 -08:00
|
|
|
return NULL;
|
2002-12-02 15:39:26 -08:00
|
|
|
}
|
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
static void
|
|
|
|
eet_data_dump_level(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < level; i++) dumpfunc(dumpdata, " ");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
eet_data_dump_group_start(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata,
|
|
|
|
int group_type, const char *name)
|
|
|
|
{
|
|
|
|
int chnk_type;
|
|
|
|
|
|
|
|
chnk_type = (group_type >= EET_G_UNKNOWN && group_type <= EET_G_HASH) ?
|
|
|
|
group_type : EET_G_LAST;
|
|
|
|
|
|
|
|
eet_data_dump_level(level, dumpfunc, dumpdata);
|
|
|
|
dumpfunc(dumpdata, "group \"");
|
|
|
|
_eet_data_dump_string_escape(dumpdata, dumpfunc, name);
|
|
|
|
dumpfunc(dumpdata, "\" ");
|
|
|
|
|
|
|
|
dumpfunc(dumpdata, _dump_g_name[chnk_type - EET_G_UNKNOWN]);
|
|
|
|
dumpfunc(dumpdata, " {\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
eet_data_dump_group_end(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata)
|
|
|
|
{
|
|
|
|
eet_data_dump_level(level, dumpfunc, dumpdata);
|
|
|
|
dumpfunc(dumpdata, " }\n");
|
|
|
|
}
|
|
|
|
|
2008-06-26 08:47:25 -07:00
|
|
|
static int
|
2009-03-19 12:00:46 -07:00
|
|
|
eet_data_get_list(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Chunk *echnk,
|
2009-05-14 08:58:10 -07:00
|
|
|
int type, int group_type __UNUSED__, void *data,
|
2008-06-26 08:47:25 -07:00
|
|
|
int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata,
|
2009-05-14 08:58:10 -07:00
|
|
|
char **p, int *size)
|
2008-06-26 08:47:25 -07:00
|
|
|
{
|
2009-05-14 08:58:10 -07:00
|
|
|
Eet_Data_Descriptor *subtype = NULL;
|
2008-06-26 08:47:25 -07:00
|
|
|
void *list = NULL;
|
|
|
|
void **ptr;
|
|
|
|
void *data_ret;
|
2009-05-14 08:58:10 -07:00
|
|
|
int et = EET_T_UNKNOW;
|
2008-06-26 08:47:25 -07:00
|
|
|
|
2008-10-23 06:12:33 -07:00
|
|
|
EET_ASSERT(!((type > EET_T_UNKNOW) && (type < EET_T_STRING)), return 0);
|
2008-06-26 08:47:25 -07:00
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
if (edd)
|
|
|
|
{
|
|
|
|
subtype = ede->subtype;
|
|
|
|
et = ede->type;
|
|
|
|
}
|
|
|
|
else if (dumpfunc)
|
|
|
|
{
|
|
|
|
eet_data_dump_group_start(level + 1, dumpfunc, dumpdata, echnk->group_type, echnk->name);
|
|
|
|
}
|
|
|
|
|
2008-06-26 08:47:25 -07:00
|
|
|
ptr = (void **)data;
|
|
|
|
list = *ptr;
|
|
|
|
data_ret = NULL;
|
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
if (et >= EET_T_STRING)
|
2008-10-23 06:12:33 -07:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
ret = eet_data_get_unknown(context, ed, edd, ede, echnk, et, EET_G_UNKNOWN,
|
2008-10-23 06:12:33 -07:00
|
|
|
&data_ret, level, dumpfunc, dumpdata, p, size);
|
|
|
|
if (!ret) return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-05-14 08:58:10 -07:00
|
|
|
data_ret = _eet_data_descriptor_decode(context, ed, subtype,
|
|
|
|
echnk->data, echnk->size,
|
|
|
|
level + 2, dumpfunc, dumpdata);
|
2008-10-23 06:12:33 -07:00
|
|
|
if (!data_ret) return 0;
|
|
|
|
}
|
2008-06-26 08:47:25 -07:00
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
if (edd)
|
|
|
|
{
|
|
|
|
list = edd->func.list_append(list, data_ret);
|
|
|
|
*ptr = list;
|
|
|
|
_eet_freelist_list_add(context, ptr);
|
|
|
|
}
|
|
|
|
else if (dumpfunc)
|
|
|
|
eet_data_dump_group_end(level, dumpfunc, dumpdata);
|
2008-06-26 08:47:25 -07:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-03-19 12:00:46 -07:00
|
|
|
eet_data_get_hash(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Chunk *echnk,
|
2008-07-17 13:28:59 -07:00
|
|
|
int type, int group_type __UNUSED__, void *data,
|
2008-06-26 08:47:25 -07:00
|
|
|
int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata,
|
|
|
|
char **p, int *size)
|
|
|
|
{
|
|
|
|
void **ptr;
|
|
|
|
void *hash = NULL;
|
|
|
|
char *key = NULL;
|
|
|
|
void *data_ret = NULL;
|
|
|
|
int ret = 0;
|
|
|
|
|
2008-10-23 07:41:04 -07:00
|
|
|
EET_ASSERT(!((type > EET_T_UNKNOW) && (type < EET_T_STRING)), return 0);
|
2008-06-26 08:47:25 -07:00
|
|
|
|
|
|
|
ptr = (void **)data;
|
|
|
|
hash = *ptr;
|
|
|
|
|
|
|
|
/* Read key */
|
|
|
|
ret = eet_data_get_type(ed,
|
|
|
|
EET_T_STRING,
|
|
|
|
echnk->data,
|
|
|
|
((char *)echnk->data) + echnk->size,
|
|
|
|
&key);
|
|
|
|
if (ret <= 0) goto on_error;
|
|
|
|
|
|
|
|
/* Advance to next chunk */
|
|
|
|
NEXT_CHUNK((*p), (*size), (*echnk), ed);
|
|
|
|
memset(echnk, 0, sizeof(Eet_Data_Chunk));
|
|
|
|
|
|
|
|
/* Read value */
|
|
|
|
eet_data_chunk_get(ed, echnk, *p, *size);
|
|
|
|
if (!echnk->name) goto on_error;
|
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
if (dumpfunc && key)
|
|
|
|
{
|
|
|
|
eet_data_dump_group_start(level + 1, dumpfunc, dumpdata, echnk->group_type, echnk->name);
|
|
|
|
|
|
|
|
eet_data_dump_level(level, dumpfunc, dumpdata);
|
|
|
|
dumpfunc(dumpdata, " key \"");
|
|
|
|
_eet_data_dump_string_escape(dumpdata, dumpfunc, key);
|
|
|
|
dumpfunc(dumpdata, "\";\n");
|
|
|
|
}
|
|
|
|
|
2008-10-23 07:41:04 -07:00
|
|
|
if (type >= EET_T_STRING)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
ret = eet_data_get_unknown(context, ed, edd, ede, echnk, ede ? ede->type : type, EET_G_UNKNOWN,
|
2008-10-23 07:41:04 -07:00
|
|
|
&data_ret, level, dumpfunc, dumpdata, p, size);
|
|
|
|
if (!ret) return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-19 12:00:46 -07:00
|
|
|
data_ret = _eet_data_descriptor_decode(context,
|
|
|
|
ed,
|
2009-05-14 08:58:10 -07:00
|
|
|
ede ? ede->subtype : NULL,
|
2008-10-23 07:41:04 -07:00
|
|
|
echnk->data,
|
|
|
|
echnk->size,
|
|
|
|
level + 2,
|
|
|
|
dumpfunc,
|
|
|
|
dumpdata);
|
|
|
|
if (!data_ret) goto on_error;
|
|
|
|
}
|
2008-06-26 08:47:25 -07:00
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
if (edd)
|
|
|
|
{
|
|
|
|
hash = edd->func.hash_add(hash, key, data_ret);
|
|
|
|
*ptr = hash;
|
|
|
|
_eet_freelist_hash_add(context, ptr);
|
|
|
|
}
|
|
|
|
else if (dumpfunc)
|
|
|
|
eet_data_dump_group_end(level, dumpfunc, dumpdata);
|
|
|
|
|
2008-06-26 08:47:25 -07:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
on_error:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* var arrays and fixed arrays have to
|
|
|
|
* get all chunks at once. for fixed arrays
|
|
|
|
* we can get each chunk and increment a
|
|
|
|
* counter stored on the element itself but
|
|
|
|
* it wont be thread safe. for var arrays
|
|
|
|
* we still need a way to get the number of
|
|
|
|
* elements from the data, so storing the
|
|
|
|
* number of elements and the element data on
|
|
|
|
* each chunk is pointless.
|
|
|
|
*/
|
|
|
|
static int
|
2009-03-19 12:00:46 -07:00
|
|
|
eet_data_get_array(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd __UNUSED__,
|
2008-07-17 13:28:59 -07:00
|
|
|
Eet_Data_Element *ede, Eet_Data_Chunk *echnk,
|
2008-06-26 08:47:25 -07:00
|
|
|
int type, int group_type, void *data,
|
|
|
|
int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata,
|
|
|
|
char **p, int *size)
|
|
|
|
{
|
2008-10-24 07:06:40 -07:00
|
|
|
const char *name;
|
2008-06-26 08:47:25 -07:00
|
|
|
void *ptr;
|
|
|
|
int count;
|
|
|
|
int ret;
|
2009-05-14 08:58:10 -07:00
|
|
|
int subsize = 0;
|
2008-06-26 08:47:25 -07:00
|
|
|
int i;
|
|
|
|
|
2008-10-24 07:06:40 -07:00
|
|
|
EET_ASSERT(!((type > EET_T_UNKNOW) && (type < EET_T_STRING)), return 0);
|
2008-06-26 08:47:25 -07:00
|
|
|
|
|
|
|
ptr = data;
|
|
|
|
/* read the number of elements */
|
|
|
|
ret = eet_data_get_type(ed,
|
|
|
|
EET_T_INT,
|
|
|
|
echnk->data,
|
|
|
|
((char *)echnk->data) + echnk->size,
|
|
|
|
&count);
|
|
|
|
if (ret <= 0) return ret;
|
2008-10-24 07:06:40 -07:00
|
|
|
|
|
|
|
name = echnk->name;
|
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
if (ede)
|
2008-06-26 08:47:25 -07:00
|
|
|
{
|
2009-05-14 08:58:10 -07:00
|
|
|
if (type >= EET_T_STRING)
|
|
|
|
subsize = eet_basic_codec[ede->type].size;
|
|
|
|
else
|
|
|
|
subsize = ede->subtype->size;
|
|
|
|
|
|
|
|
if (group_type == EET_G_VAR_ARRAY)
|
|
|
|
{
|
|
|
|
/* store the number of elements
|
|
|
|
* on the counter offset */
|
|
|
|
*(int *)(((char *)data) + ede->count - ede->offset) = count;
|
|
|
|
/* allocate space for the array of elements */
|
|
|
|
*(void **)ptr = edd->func.mem_alloc(count * subsize);
|
2008-06-26 08:47:25 -07:00
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
if (!*(void **)ptr) return 0;
|
2008-06-26 08:47:25 -07:00
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
memset(*(void **)ptr, 0, count * subsize);
|
2009-03-19 12:00:46 -07:00
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
_eet_freelist_add(context, *(void **)ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char tbuf[256];
|
|
|
|
|
|
|
|
eet_data_dump_group_start(level + 1, dumpfunc, dumpdata, echnk->group_type, echnk->name);
|
|
|
|
|
|
|
|
eet_data_dump_level(level, dumpfunc, dumpdata);
|
|
|
|
dumpfunc(dumpdata, " count ");
|
|
|
|
eina_convert_itoa(count, tbuf);
|
|
|
|
dumpfunc(dumpdata, tbuf);
|
|
|
|
dumpfunc(dumpdata, ";\n");
|
2008-06-26 08:47:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get all array elements */
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2009-05-14 08:58:10 -07:00
|
|
|
void *dst = NULL;
|
2008-06-26 08:47:25 -07:00
|
|
|
void *data_ret = NULL;
|
|
|
|
|
|
|
|
/* Advance to next chunk */
|
|
|
|
NEXT_CHUNK((*p), (*size), (*echnk), ed);
|
|
|
|
memset(echnk, 0, sizeof(Eet_Data_Chunk));
|
|
|
|
|
|
|
|
eet_data_chunk_get(ed, echnk, *p, *size);
|
2008-10-24 07:06:40 -07:00
|
|
|
if (!echnk->name || strcmp(echnk->name, name) != 0) return 0;
|
2008-06-26 08:47:25 -07:00
|
|
|
/* get the data */
|
|
|
|
|
|
|
|
/* get the destination pointer */
|
2009-05-14 08:58:10 -07:00
|
|
|
if (ede)
|
|
|
|
{
|
|
|
|
if (group_type == EET_G_ARRAY)
|
|
|
|
dst = (char *)ptr + (subsize * i);
|
|
|
|
else
|
|
|
|
dst = *(char **)ptr + (subsize * i);
|
|
|
|
}
|
2008-10-24 07:06:40 -07:00
|
|
|
|
|
|
|
if (type >= EET_T_STRING)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
ret = eet_data_get_unknown(context, ed, edd, ede, echnk, ede ? ede->type : type, EET_G_UNKNOWN,
|
|
|
|
&data_ret, level, dumpfunc, dumpdata, p, size);
|
2008-10-24 07:06:40 -07:00
|
|
|
if (!ret) return 0;
|
2009-05-14 08:58:10 -07:00
|
|
|
if (dst) memcpy(dst, &data_ret, subsize);
|
2008-10-24 07:06:40 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-05-14 08:58:10 -07:00
|
|
|
data_ret = _eet_data_descriptor_decode(context, ed, ede ? ede->subtype : NULL,
|
|
|
|
echnk->data, echnk->size,
|
|
|
|
level + 2, dumpfunc, dumpdata);
|
2008-10-24 07:06:40 -07:00
|
|
|
if (!data_ret) return 0;
|
2009-05-14 08:58:10 -07:00
|
|
|
if (dst)
|
|
|
|
{
|
|
|
|
memcpy(dst, data_ret, subsize);
|
|
|
|
_eet_freelist_add(context, data_ret);
|
|
|
|
}
|
2008-10-24 07:06:40 -07:00
|
|
|
}
|
2008-06-26 08:47:25 -07:00
|
|
|
}
|
2009-05-14 08:58:10 -07:00
|
|
|
|
|
|
|
if (dumpfunc)
|
|
|
|
eet_data_dump_group_end(level, dumpfunc, dumpdata);
|
|
|
|
|
2008-06-26 08:47:25 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
static void
|
|
|
|
eet_data_dump_simple_type(int type, const char *name, void *dd,
|
|
|
|
int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata)
|
|
|
|
{
|
|
|
|
const char *type_name = NULL;
|
|
|
|
char tbuf[256];
|
|
|
|
|
|
|
|
eet_data_dump_level(level, dumpfunc, dumpdata);
|
|
|
|
dumpfunc(dumpdata, " value \"");
|
|
|
|
_eet_data_dump_string_escape(dumpdata, dumpfunc, name);
|
|
|
|
dumpfunc(dumpdata, "\" ");
|
|
|
|
|
2009-11-02 00:41:43 -08:00
|
|
|
#ifdef EET_T_TYPE
|
|
|
|
# undef EET_T_TYPE
|
|
|
|
#endif
|
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
#define EET_T_TYPE(Eet_Type, Type) \
|
|
|
|
case Eet_Type: \
|
|
|
|
{ \
|
|
|
|
dumpfunc(dumpdata, _dump_t_name[Eet_Type][0]); \
|
|
|
|
snprintf(tbuf, sizeof (tbuf), _dump_t_name[Eet_Type][1], *((Type *)dd)); \
|
|
|
|
dumpfunc(dumpdata, tbuf); \
|
|
|
|
break; \
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
EET_T_TYPE(EET_T_CHAR, char);
|
|
|
|
EET_T_TYPE(EET_T_SHORT, short);
|
|
|
|
EET_T_TYPE(EET_T_INT, int);
|
|
|
|
EET_T_TYPE(EET_T_LONG_LONG, long long);
|
|
|
|
EET_T_TYPE(EET_T_FLOAT, float);
|
|
|
|
EET_T_TYPE(EET_T_DOUBLE, double);
|
|
|
|
EET_T_TYPE(EET_T_UCHAR, unsigned char);
|
|
|
|
EET_T_TYPE(EET_T_USHORT, unsigned short);
|
|
|
|
EET_T_TYPE(EET_T_UINT, unsigned int);
|
|
|
|
EET_T_TYPE(EET_T_ULONG_LONG, unsigned long long);
|
|
|
|
case EET_T_INLINED_STRING:
|
|
|
|
type_name = "inlined: \"";
|
|
|
|
case EET_T_STRING:
|
|
|
|
if (!type_name) type_name = "string: \"";
|
|
|
|
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
s = *((char **)dd);
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
dumpfunc(dumpdata, type_name);
|
|
|
|
_eet_data_dump_string_escape(dumpdata, dumpfunc, s);
|
|
|
|
dumpfunc(dumpdata, "\"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EET_T_NULL:
|
|
|
|
dumpfunc(dumpdata, "null");
|
|
|
|
break;
|
|
|
|
default:
|
2009-05-18 07:46:32 -07:00
|
|
|
dumpfunc(dumpdata, "???: ???");
|
2009-05-14 08:58:10 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
dumpfunc(dumpdata, ";\n");
|
|
|
|
}
|
|
|
|
|
2008-06-26 08:47:25 -07:00
|
|
|
static int
|
2009-03-19 12:00:46 -07:00
|
|
|
eet_data_get_unknown(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Chunk *echnk,
|
2008-07-17 13:28:59 -07:00
|
|
|
int type, int group_type __UNUSED__, void *data,
|
2008-06-26 08:47:25 -07:00
|
|
|
int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata,
|
2008-07-17 13:28:59 -07:00
|
|
|
char **p __UNUSED__, int *size __UNUSED__)
|
2008-06-26 08:47:25 -07:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
void *data_ret;
|
|
|
|
|
|
|
|
if (IS_SIMPLE_TYPE(type))
|
|
|
|
{
|
|
|
|
ret = eet_data_get_type(ed, type, echnk->data, ((char *)echnk->data) + echnk->size, ((char *)data));
|
|
|
|
if (ret <= 0) return ret;
|
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
if (!edd && dumpfunc)
|
|
|
|
{
|
|
|
|
eet_data_dump_simple_type(type, echnk->name, data, level, dumpfunc, dumpdata);
|
|
|
|
}
|
2009-09-30 03:05:15 -07:00
|
|
|
else if (edd && type == EET_T_STRING)
|
2008-06-26 08:47:25 -07:00
|
|
|
{
|
2008-07-02 05:10:12 -07:00
|
|
|
char **str;
|
2008-06-26 08:47:25 -07:00
|
|
|
|
|
|
|
str = (char **)(((char *)data));
|
|
|
|
if (*str)
|
|
|
|
{
|
2008-08-10 02:33:55 -07:00
|
|
|
if ((ed == NULL) || (edd->func.str_direct_alloc == NULL))
|
2008-06-26 08:47:25 -07:00
|
|
|
{
|
|
|
|
*str = edd->func.str_alloc(*str);
|
2009-03-19 12:00:46 -07:00
|
|
|
_eet_freelist_str_add(context, *str);
|
2008-06-26 08:47:25 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*str = edd->func.str_direct_alloc(*str);
|
2009-03-19 12:00:46 -07:00
|
|
|
_eet_freelist_direct_str_add(context, *str);
|
2008-06-26 08:47:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-30 03:05:15 -07:00
|
|
|
else if (edd && type == EET_T_INLINED_STRING)
|
2008-07-02 05:10:12 -07:00
|
|
|
{
|
|
|
|
char **str;
|
|
|
|
|
|
|
|
str = (char **)(((char *)data));
|
|
|
|
if (*str)
|
|
|
|
{
|
|
|
|
*str = edd->func.str_alloc(*str);
|
2009-03-19 12:00:46 -07:00
|
|
|
_eet_freelist_str_add(context, *str);
|
2008-07-02 05:10:12 -07:00
|
|
|
}
|
|
|
|
}
|
2008-06-26 08:47:25 -07:00
|
|
|
}
|
2009-05-14 08:58:10 -07:00
|
|
|
else
|
2008-06-26 08:47:25 -07:00
|
|
|
{
|
2009-05-14 08:58:10 -07:00
|
|
|
Eet_Data_Descriptor *subtype;
|
2008-06-26 08:47:25 -07:00
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
subtype = ede ? ede->subtype : NULL;
|
2008-06-26 08:47:25 -07:00
|
|
|
|
2009-05-14 08:58:10 -07:00
|
|
|
if (subtype || dumpfunc)
|
|
|
|
{
|
|
|
|
void **ptr;
|
|
|
|
|
|
|
|
data_ret = _eet_data_descriptor_decode(context, ed, subtype, echnk->data, echnk->size, level + 1, dumpfunc, dumpdata);
|
|
|
|
if (!data_ret) return 0;
|
|
|
|
|
|
|
|
ptr = (void **)(((char *)data));
|
|
|
|
*ptr = (void *)data_ret;
|
|
|
|
}
|
2008-06-26 08:47:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
eet_data_encode(Eet_Dictionary *ed, Eet_Data_Stream *ds, void *data, const char *name, int size, int type, int group_type)
|
|
|
|
{
|
|
|
|
Eet_Data_Chunk *echnk;
|
|
|
|
|
|
|
|
echnk = eet_data_chunk_new(data, size, name, type, group_type);
|
|
|
|
eet_data_chunk_put(ed, echnk, ds);
|
|
|
|
eet_data_chunk_free(echnk);
|
2008-10-24 07:06:40 -07:00
|
|
|
if (data) free(data);
|
2008-06-26 08:47:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-07-17 13:28:59 -07:00
|
|
|
eet_data_put_array(Eet_Dictionary *ed, Eet_Data_Descriptor *edd __UNUSED__, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in)
|
2008-06-26 08:47:25 -07:00
|
|
|
{
|
|
|
|
void *data;
|
|
|
|
int offset = 0;
|
2008-10-24 07:06:40 -07:00
|
|
|
int subsize;
|
2008-06-26 08:47:25 -07:00
|
|
|
int count;
|
2008-10-24 07:06:40 -07:00
|
|
|
int size;
|
|
|
|
int j;
|
2008-06-26 08:47:25 -07:00
|
|
|
|
2008-10-24 07:06:40 -07:00
|
|
|
EET_ASSERT(!((ede->type > EET_T_UNKNOW) && (ede->type < EET_T_STRING)), return );
|
2008-06-26 08:47:25 -07:00
|
|
|
|
|
|
|
if (ede->group_type == EET_G_ARRAY)
|
|
|
|
count = ede->counter_offset;
|
|
|
|
else
|
|
|
|
count = *(int *)(((char *)data_in) + ede->count - ede->offset);
|
|
|
|
|
|
|
|
if (count <= 0) return;
|
|
|
|
/* Store number of elements */
|
|
|
|
data = eet_data_put_type(ed, EET_T_INT, &count, &size);
|
|
|
|
if (data) eet_data_encode(ed, ds, data, ede->name, size, ede->type, ede->group_type);
|
|
|
|
|
2008-10-24 07:06:40 -07:00
|
|
|
if (ede->type >= EET_T_STRING)
|
|
|
|
subsize = eet_basic_codec[ede->type].size;
|
|
|
|
else
|
|
|
|
subsize = ede->subtype->size;
|
|
|
|
|
2008-06-26 08:47:25 -07:00
|
|
|
for (j = 0; j < count; j++)
|
|
|
|
{
|
|
|
|
void *d;
|
2008-10-24 07:06:40 -07:00
|
|
|
int pos = ds->pos;
|
2008-06-26 08:47:25 -07:00
|
|
|
|
|
|
|
if (ede->group_type == EET_G_ARRAY)
|
|
|
|
d = (void *)(((char *)data_in) + offset);
|
|
|
|
else
|
|
|
|
d = *(((char **)data_in)) + offset;
|
|
|
|
|
2008-10-24 07:06:40 -07:00
|
|
|
if (ede->type >= EET_T_STRING)
|
|
|
|
eet_data_put_unknown(ed, NULL, ede, ds, d);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data = _eet_data_descriptor_encode(ed, ede->subtype, d, &size);
|
|
|
|
if (data) eet_data_encode(ed, ds, data, ede->name, size, ede->type, ede->group_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos == ds->pos)
|
|
|
|
{
|
|
|
|
/* Add a NULL element just to have the correct array layout. */
|
|
|
|
eet_data_encode(ed, ds, NULL, ede->name, 0, EET_T_NULL, ede->group_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += subsize;
|
2008-06-26 08:47:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-07-17 13:28:59 -07:00
|
|
|
eet_data_put_unknown(Eet_Dictionary *ed, Eet_Data_Descriptor *edd __UNUSED__, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in)
|
2008-06-26 08:47:25 -07:00
|
|
|
{
|
2008-06-27 08:26:53 -07:00
|
|
|
void *data = NULL;
|
2008-06-26 08:47:25 -07:00
|
|
|
int size;
|
|
|
|
|
|
|
|
if (IS_SIMPLE_TYPE(ede->type))
|
|
|
|
data = eet_data_put_type(ed, ede->type, data_in, &size);
|
|
|
|
else if (ede->subtype)
|
|
|
|
{
|
2008-06-27 08:26:53 -07:00
|
|
|
if (*((char **)data_in))
|
2008-06-26 08:47:25 -07:00
|
|
|
data = _eet_data_descriptor_encode(ed,
|
|
|
|
ede->subtype,
|
|
|
|
*((char **)((char *)(data_in))),
|
|
|
|
&size);
|
|
|
|
}
|
|
|
|
if (data) eet_data_encode(ed, ds, data, ede->name, size, ede->type, ede->group_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
eet_data_put_list(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in)
|
|
|
|
{
|
|
|
|
void *data;
|
|
|
|
void *l;
|
|
|
|
int size;
|
|
|
|
|
2008-10-23 06:12:33 -07:00
|
|
|
EET_ASSERT(!((ede->type > EET_T_UNKNOW) && (ede->type < EET_T_STRING)), return );
|
2008-06-26 08:47:25 -07:00
|
|
|
|
|
|
|
l = *((void **)(((char *)data_in)));
|
|
|
|
for (; l; l = edd->func.list_next(l))
|
|
|
|
{
|
2008-10-23 06:12:33 -07:00
|
|
|
if (ede->type >= EET_T_STRING)
|
|
|
|
{
|
|
|
|
const char *str = edd->func.list_data(l);
|
|
|
|
eet_data_put_unknown(ed, NULL, ede, ds, &str);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data = _eet_data_descriptor_encode(ed,
|
|
|
|
ede->subtype,
|
|
|
|
edd->func.list_data(l),
|
|
|
|
&size);
|
|
|
|
if (data) eet_data_encode(ed, ds, data, ede->name, size, ede->type, ede->group_type);
|
|
|
|
}
|
2008-06-26 08:47:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
eet_data_put_hash(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in)
|
|
|
|
{
|
|
|
|
Eet_Data_Encode_Hash_Info fdata;
|
|
|
|
void *l;
|
|
|
|
|
|
|
|
l = *((void **)(((char *)data_in)));
|
|
|
|
fdata.ds = ds;
|
|
|
|
fdata.ede = ede;
|
|
|
|
fdata.ed = ed;
|
|
|
|
edd->func.hash_foreach(l, eet_data_descriptor_encode_hash_cb, &fdata);
|
|
|
|
}
|
|
|
|
|
2008-04-10 01:57:03 -07:00
|
|
|
EAPI int
|
2008-11-13 08:31:13 -08:00
|
|
|
eet_data_dump_cipher(Eet_File *ef,
|
|
|
|
const char *name, const char *key,
|
|
|
|
void (*dumpfunc) (void *data, const char *str),
|
|
|
|
void *dumpdata)
|
2008-04-10 01:57:03 -07:00
|
|
|
{
|
|
|
|
const Eet_Dictionary *ed = NULL;
|
2008-11-13 08:31:13 -08:00
|
|
|
const void *data = NULL;
|
2009-03-19 12:00:46 -07:00
|
|
|
Eet_Free_Context context;
|
2008-04-10 01:57:03 -07:00
|
|
|
int ret = 0;
|
|
|
|
int required_free = 0;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
ed = eet_dictionary_get(ef);
|
|
|
|
|
2008-11-13 08:31:13 -08:00
|
|
|
if (!key)
|
|
|
|
data = eet_read_direct(ef, name, &size);
|
2008-04-10 01:57:03 -07:00
|
|
|
if (!data)
|
|
|
|
{
|
|
|
|
required_free = 1;
|
2008-11-13 08:31:13 -08:00
|
|
|
data = eet_read_cipher(ef, name, &size, key);
|
2008-04-10 01:57:03 -07:00
|
|
|
if (!data) return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-19 12:00:46 -07:00
|
|
|
memset(&context, 0, sizeof (context));
|
|
|
|
if (_eet_data_descriptor_decode(&context, ed, NULL, data, size, 0,
|
2008-04-10 01:57:03 -07:00
|
|
|
dumpfunc, dumpdata))
|
|
|
|
ret = 1;
|
|
|
|
|
|
|
|
if (required_free)
|
|
|
|
free((void*)data);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-13 08:31:13 -08:00
|
|
|
EAPI int
|
|
|
|
eet_data_dump(Eet_File *ef,
|
|
|
|
const char *name,
|
|
|
|
void (*dumpfunc) (void *data, const char *str),
|
|
|
|
void *dumpdata)
|
|
|
|
{
|
|
|
|
return eet_data_dump_cipher(ef, name, NULL, dumpfunc, dumpdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
eet_data_text_dump_cipher(const void *data_in,
|
|
|
|
const char *key, int size_in,
|
|
|
|
void (*dumpfunc) (void *data, const char *str),
|
|
|
|
void *dumpdata)
|
|
|
|
{
|
|
|
|
void *ret = NULL;
|
2009-03-19 12:00:46 -07:00
|
|
|
Eet_Free_Context context;
|
2008-11-13 08:31:13 -08:00
|
|
|
unsigned int ret_len = 0;
|
|
|
|
|
|
|
|
if (data_in && key)
|
|
|
|
{
|
|
|
|
if (eet_decipher(data_in, size_in, key, strlen(key), &ret, &ret_len))
|
|
|
|
{
|
|
|
|
if (ret) free(ret);
|
|
|
|
return 1;
|
|
|
|
}
|
2009-03-19 12:00:46 -07:00
|
|
|
memset(&context, 0, sizeof (context));
|
|
|
|
if (_eet_data_descriptor_decode(&context, NULL, NULL, ret, ret_len, 0,
|
2008-11-13 08:31:13 -08:00
|
|
|
dumpfunc, dumpdata))
|
|
|
|
{
|
|
|
|
free(ret);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
free(ret);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-03-19 12:00:46 -07:00
|
|
|
memset(&context, 0, sizeof (context));
|
|
|
|
if (_eet_data_descriptor_decode(&context, NULL, NULL, data_in, size_in, 0,
|
2008-11-13 08:31:13 -08:00
|
|
|
dumpfunc, dumpdata))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-04-10 01:57:03 -07:00
|
|
|
|
2008-03-07 01:59:37 -08:00
|
|
|
EAPI int
|
2007-09-08 00:44:03 -07:00
|
|
|
eet_data_text_dump(const void *data_in,
|
|
|
|
int size_in,
|
|
|
|
void (*dumpfunc) (void *data, const char *str),
|
|
|
|
void *dumpdata)
|
|
|
|
{
|
2008-11-13 08:31:13 -08:00
|
|
|
return eet_data_text_dump_cipher(data_in, NULL, size_in, dumpfunc, dumpdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void *
|
|
|
|
eet_data_text_undump_cipher(const char *text,
|
|
|
|
const char *key,
|
|
|
|
int textlen,
|
|
|
|
int *size_ret)
|
|
|
|
{
|
|
|
|
void *ret = NULL;
|
|
|
|
|
|
|
|
ret = _eet_data_dump_parse(NULL, size_ret, text, textlen);
|
|
|
|
if (ret && key)
|
|
|
|
{
|
2008-11-13 12:49:18 -08:00
|
|
|
void *ciphered = NULL;
|
|
|
|
unsigned int ciphered_len;
|
|
|
|
|
2009-03-19 12:00:46 -07:00
|
|
|
if (eet_cipher(ret, *size_ret, key, strlen(key), &ciphered, &ciphered_len))
|
|
|
|
{
|
|
|
|
if (ciphered) free(ciphered);
|
|
|
|
size_ret = 0;
|
|
|
|
free(ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
free(ret);
|
|
|
|
*size_ret = ciphered_len;
|
|
|
|
ret = ciphered;
|
2008-11-13 08:31:13 -08:00
|
|
|
}
|
|
|
|
return ret;
|
2007-09-08 00:44:03 -07:00
|
|
|
}
|
|
|
|
|
2008-03-07 01:59:37 -08:00
|
|
|
EAPI void *
|
2007-09-08 00:44:03 -07:00
|
|
|
eet_data_text_undump(const char *text,
|
|
|
|
int textlen,
|
|
|
|
int *size_ret)
|
|
|
|
{
|
2008-11-13 08:31:13 -08:00
|
|
|
return eet_data_text_undump_cipher(text, NULL, textlen, size_ret);
|
2007-09-08 00:44:03 -07:00
|
|
|
}
|
|
|
|
|
2008-04-10 01:57:03 -07:00
|
|
|
EAPI int
|
2008-11-13 08:31:13 -08:00
|
|
|
eet_data_undump_cipher(Eet_File *ef,
|
|
|
|
const char *name,
|
|
|
|
const char *key,
|
|
|
|
const char *text,
|
|
|
|
int textlen,
|
|
|
|
int compress)
|
2008-04-10 01:57:03 -07:00
|
|
|
{
|
|
|
|
Eet_Dictionary *ed;
|
|
|
|
void *data_enc;
|
|
|
|
int size;
|
|
|
|
int val;
|
|
|
|
|
|
|
|
ed = eet_dictionary_get(ef);
|
|
|
|
|
|
|
|
data_enc = _eet_data_dump_parse(ed, &size, text, textlen);
|
|
|
|
if (!data_enc) return 0;
|
2008-11-13 08:31:13 -08:00
|
|
|
val = eet_write_cipher(ef, name, data_enc, size, compress, key);
|
2008-04-10 01:57:03 -07:00
|
|
|
free(data_enc);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2008-11-13 08:31:13 -08:00
|
|
|
EAPI int
|
|
|
|
eet_data_undump(Eet_File *ef,
|
|
|
|
const char *name,
|
|
|
|
const char *text,
|
|
|
|
int textlen,
|
|
|
|
int compress)
|
|
|
|
{
|
|
|
|
return eet_data_undump_cipher(ef, name, NULL, text, textlen, compress);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void *
|
|
|
|
eet_data_descriptor_decode_cipher(Eet_Data_Descriptor *edd,
|
|
|
|
const void *data_in,
|
|
|
|
const char *key,
|
|
|
|
int size_in)
|
|
|
|
{
|
|
|
|
void *deciphered = NULL;
|
|
|
|
void *ret;
|
2009-03-19 12:00:46 -07:00
|
|
|
Eet_Free_Context context;
|
|
|
|
unsigned int deciphered_len = 0;
|
2008-11-13 08:31:13 -08:00
|
|
|
|
|
|
|
if (key && data_in)
|
|
|
|
{
|
|
|
|
if (eet_decipher(data_in, size_in, key, strlen(key), &deciphered, &deciphered_len))
|
|
|
|
{
|
|
|
|
if (deciphered) free(deciphered);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-03-19 12:00:46 -07:00
|
|
|
memset(&context, 0, sizeof (context));
|
|
|
|
ret = _eet_data_descriptor_decode(&context, NULL, edd, deciphered, deciphered_len, 0,
|
2008-11-13 08:31:13 -08:00
|
|
|
NULL, NULL);
|
|
|
|
free(deciphered);
|
|
|
|
return ret;
|
|
|
|
}
|
2009-03-19 12:00:46 -07:00
|
|
|
memset(&context, 0, sizeof (context));
|
|
|
|
return _eet_data_descriptor_decode(&context, NULL, edd, data_in, size_in, 0,
|
2008-11-13 08:31:13 -08:00
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2008-03-07 01:59:37 -08:00
|
|
|
EAPI void *
|
2007-09-08 00:44:03 -07:00
|
|
|
eet_data_descriptor_decode(Eet_Data_Descriptor *edd,
|
|
|
|
const void *data_in,
|
|
|
|
int size_in)
|
|
|
|
{
|
2008-11-13 08:31:13 -08:00
|
|
|
return eet_data_descriptor_decode_cipher(edd, data_in, NULL, size_in);
|
2007-09-08 00:44:03 -07:00
|
|
|
}
|
|
|
|
|
2008-02-29 22:38:09 -08:00
|
|
|
static void *
|
|
|
|
_eet_data_descriptor_encode(Eet_Dictionary *ed,
|
|
|
|
Eet_Data_Descriptor *edd,
|
|
|
|
const void *data_in,
|
|
|
|
int *size_ret)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
2008-02-29 22:38:09 -08:00
|
|
|
Eet_Data_Stream *ds;
|
|
|
|
Eet_Data_Chunk *chnk;
|
|
|
|
void *cdata;
|
|
|
|
int csize;
|
|
|
|
int i;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2009-11-02 00:41:43 -08:00
|
|
|
if (_eet_data_words_bigendian == -1)
|
2002-12-02 15:39:26 -08:00
|
|
|
{
|
|
|
|
unsigned long int v;
|
|
|
|
|
|
|
|
v = htonl(0x12345678);
|
2009-11-02 00:41:43 -08:00
|
|
|
if (v == 0x12345678) _eet_data_words_bigendian = 1;
|
|
|
|
else _eet_data_words_bigendian = 0;
|
2002-12-02 15:39:26 -08:00
|
|
|
}
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
ds = eet_data_stream_new();
|
|
|
|
for (i = 0; i < edd->elements.num; i++)
|
|
|
|
{
|
|
|
|
Eet_Data_Element *ede;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
ede = &(edd->elements.set[i]);
|
2008-06-26 08:47:25 -07:00
|
|
|
eet_group_codec[ede->group_type - 100].put(ed, edd, ede, ds, ((char *)data_in) + ede->offset);
|
2002-12-02 15:39:26 -08:00
|
|
|
}
|
2007-09-08 00:44:03 -07:00
|
|
|
chnk = eet_data_chunk_new(ds->data, ds->pos, edd->name, EET_T_UNKNOW, EET_G_UNKNOWN);
|
2002-12-02 15:39:26 -08:00
|
|
|
ds->data = NULL;
|
|
|
|
ds->size = 0;
|
|
|
|
eet_data_stream_free(ds);
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
ds = eet_data_stream_new();
|
2008-02-29 22:38:09 -08:00
|
|
|
eet_data_chunk_put(ed, chnk, ds);
|
2002-12-02 15:39:26 -08:00
|
|
|
cdata = ds->data;
|
|
|
|
csize = ds->pos;
|
|
|
|
|
|
|
|
ds->data = NULL;
|
|
|
|
ds->size = 0;
|
|
|
|
eet_data_stream_free(ds);
|
|
|
|
*size_ret = csize;
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2004-01-19 18:02:33 -08:00
|
|
|
free(chnk->data);
|
2002-12-02 15:39:26 -08:00
|
|
|
eet_data_chunk_free(chnk);
|
2005-05-22 21:32:04 -07:00
|
|
|
|
2002-12-02 15:39:26 -08:00
|
|
|
return cdata;
|
|
|
|
}
|
2008-02-29 22:38:09 -08:00
|
|
|
|
2009-04-16 05:43:34 -07:00
|
|
|
EAPI int
|
|
|
|
eet_data_node_write_cipher(Eet_File *ef, const char *name, const char *key, Eet_Node *node, int compress)
|
|
|
|
{
|
|
|
|
Eet_Dictionary *ed;
|
|
|
|
void *data_enc;
|
|
|
|
int size;
|
|
|
|
int val;
|
|
|
|
|
|
|
|
ed = eet_dictionary_get(ef);
|
|
|
|
|
|
|
|
data_enc = _eet_data_dump_encode(ed, node, &size);
|
|
|
|
if (!data_enc) return 0;
|
|
|
|
val = eet_write_cipher(ef, name, data_enc, size, compress, key);
|
|
|
|
free(data_enc);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2009-04-16 05:18:18 -07:00
|
|
|
EAPI void *
|
|
|
|
eet_data_node_encode_cipher(Eet_Node *node,
|
|
|
|
const char *key,
|
|
|
|
int *size_ret)
|
|
|
|
{
|
|
|
|
void *ret = NULL;
|
|
|
|
void *ciphered = NULL;
|
|
|
|
unsigned int ciphered_len = 0;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
ret = _eet_data_dump_encode(NULL, node, &size);
|
|
|
|
if (key && ret)
|
|
|
|
{
|
|
|
|
if (eet_cipher(ret, size, key, strlen(key), &ciphered, &ciphered_len))
|
|
|
|
{
|
|
|
|
if (ciphered) free(ciphered);
|
|
|
|
if (size_ret) *size_ret = 0;
|
|
|
|
free(ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
free(ret);
|
|
|
|
size = (int) ciphered_len;
|
|
|
|
ret = ciphered;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size_ret) *size_ret = size;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-13 08:31:13 -08:00
|
|
|
EAPI void *
|
|
|
|
eet_data_descriptor_encode_cipher(Eet_Data_Descriptor *edd,
|
|
|
|
const void *data_in,
|
|
|
|
const char *key,
|
|
|
|
int *size_ret)
|
|
|
|
{
|
|
|
|
void *ret = NULL;
|
|
|
|
void *ciphered = NULL;
|
|
|
|
unsigned int ciphered_len = 0;
|
2009-04-16 05:18:18 -07:00
|
|
|
int size;
|
2008-11-13 08:31:13 -08:00
|
|
|
|
2009-04-16 05:18:18 -07:00
|
|
|
ret = _eet_data_descriptor_encode(NULL, edd, data_in, &size);
|
2008-11-13 08:31:13 -08:00
|
|
|
if (key && ret)
|
|
|
|
{
|
2009-04-16 05:18:18 -07:00
|
|
|
if (eet_cipher(ret, size, key, strlen(key), &ciphered, &ciphered_len))
|
2008-11-13 08:31:13 -08:00
|
|
|
{
|
|
|
|
if (ciphered) free(ciphered);
|
2009-04-16 05:18:18 -07:00
|
|
|
if (size_ret) *size_ret = 0;
|
2008-11-13 08:31:13 -08:00
|
|
|
free(ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
free(ret);
|
2009-04-16 05:18:18 -07:00
|
|
|
size = ciphered_len;
|
2008-11-13 08:31:13 -08:00
|
|
|
ret = ciphered;
|
|
|
|
}
|
2009-04-16 05:18:18 -07:00
|
|
|
|
|
|
|
if (size_ret) *size_ret = size;
|
2008-11-13 08:31:13 -08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-03-07 01:59:37 -08:00
|
|
|
EAPI void *
|
2008-02-29 22:38:09 -08:00
|
|
|
eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
|
|
|
|
const void *data_in,
|
|
|
|
int *size_ret)
|
|
|
|
{
|
2008-11-13 08:31:13 -08:00
|
|
|
return eet_data_descriptor_encode_cipher(edd, data_in, NULL, size_ret);
|
2008-02-29 22:38:09 -08:00
|
|
|
}
|