forked from enlightenment/efl
* eet: Expose Eet_Node so we can now write external parser for eet_data. Still need
a way to retrieve an Eet_Node from an eet_data, perhaps some documentation and tests also. SVN revision: 40105
This commit is contained in:
parent
52c7896045
commit
b954d4dd49
|
@ -9,6 +9,7 @@ AM_CPPFLAGS = \
|
||||||
-DPACKAGE_LIB_DIR=\"$(libdir)\" \
|
-DPACKAGE_LIB_DIR=\"$(libdir)\" \
|
||||||
-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
|
-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
|
||||||
@EET_CPPFLAGS@ \
|
@EET_CPPFLAGS@ \
|
||||||
|
@EINA_CFLAGS@ \
|
||||||
@EVIL_CFLAGS@
|
@EVIL_CFLAGS@
|
||||||
|
|
||||||
bin_PROGRAMS = eet
|
bin_PROGRAMS = eet
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <Eina.h>
|
||||||
|
|
||||||
#ifdef EAPI
|
#ifdef EAPI
|
||||||
# undef EAPI
|
# undef EAPI
|
||||||
|
@ -104,6 +105,7 @@ extern "C" {
|
||||||
typedef struct _Eet_Dictionary Eet_Dictionary;
|
typedef struct _Eet_Dictionary Eet_Dictionary;
|
||||||
typedef struct _Eet_Data_Descriptor Eet_Data_Descriptor;
|
typedef struct _Eet_Data_Descriptor Eet_Data_Descriptor;
|
||||||
typedef struct _Eet_Key Eet_Key;
|
typedef struct _Eet_Key Eet_Key;
|
||||||
|
typedef struct _Eet_Node Eet_Node;
|
||||||
|
|
||||||
typedef struct _Eet_Data_Descriptor_Class Eet_Data_Descriptor_Class;
|
typedef struct _Eet_Data_Descriptor_Class Eet_Data_Descriptor_Class;
|
||||||
|
|
||||||
|
@ -1355,6 +1357,30 @@ eet_dictionary_string_check * example: values), and @p type is the basic data
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
|
||||||
|
EAPI Eet_Node *eet_node_char_new(const char *name, char c);
|
||||||
|
EAPI Eet_Node *eet_node_short_new(const char *name, short s);
|
||||||
|
EAPI Eet_Node *eet_node_int_new(const char *name, int i);
|
||||||
|
EAPI Eet_Node *eet_node_long_long_new(const char *name, long long l);
|
||||||
|
EAPI Eet_Node *eet_node_float_new(const char *name, float f);
|
||||||
|
EAPI Eet_Node *eet_node_double_new(const char *name, double d);
|
||||||
|
EAPI Eet_Node *eet_node_unsigned_char_new(const char *name, unsigned char uc);
|
||||||
|
EAPI Eet_Node *eet_node_unsigned_short_new(const char *name, unsigned short us);
|
||||||
|
EAPI Eet_Node *eet_node_unsigned_int_new(const char *name, unsigned int ui);
|
||||||
|
EAPI Eet_Node *eet_node_string_new(const char *name, const char *str);
|
||||||
|
EAPI Eet_Node *eet_node_inlined_string_new(const char *name, const char *str);
|
||||||
|
EAPI Eet_Node *eet_node_null_new(const char *name);
|
||||||
|
EAPI Eet_Node *eet_node_list_new(const char *name, Eina_List *nodes);
|
||||||
|
EAPI Eet_Node *eet_node_array_new(const char *name, int count, Eina_List *nodes);
|
||||||
|
EAPI Eet_Node *eet_node_var_array_new(const char *name, int count, Eina_List *nodes);
|
||||||
|
EAPI Eet_Node *eet_node_hash_new(const char *name, const char *key, Eina_List *nodes);
|
||||||
|
EAPI Eet_Node *eet_node_struct_new(const char *name, Eina_List *nodes);
|
||||||
|
EAPI void eet_node_del(Eet_Node *n);
|
||||||
|
|
||||||
|
EAPI void *eet_data_node_encode_cipher(Eet_Node *node, const char *key, int *size_ret);
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,13 +5,6 @@
|
||||||
#ifndef _EET_PRIVATE_H
|
#ifndef _EET_PRIVATE_H
|
||||||
#define _EET_PRIVATE_H
|
#define _EET_PRIVATE_H
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
# if __GNUC__ >= 4
|
|
||||||
// BROKEN in gcc 4 on amd64
|
|
||||||
//# pragma GCC visibility push(hidden)
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -57,6 +50,30 @@ struct _Eet_Dictionary
|
||||||
const char *end;
|
const char *end;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct _Eet_Node
|
||||||
|
{
|
||||||
|
int type;
|
||||||
|
int count;
|
||||||
|
const char *name;
|
||||||
|
const char *key;
|
||||||
|
Eet_Node *values;
|
||||||
|
Eet_Node *next;
|
||||||
|
Eet_Node *parent;
|
||||||
|
union {
|
||||||
|
char c;
|
||||||
|
short s;
|
||||||
|
int i;
|
||||||
|
long long l;
|
||||||
|
float f;
|
||||||
|
double d;
|
||||||
|
unsigned char uc;
|
||||||
|
unsigned short us;
|
||||||
|
unsigned int ui;
|
||||||
|
unsigned long long ul;
|
||||||
|
const char *str;
|
||||||
|
} data;
|
||||||
|
};
|
||||||
|
|
||||||
Eet_Dictionary *eet_dictionary_add(void);
|
Eet_Dictionary *eet_dictionary_add(void);
|
||||||
void eet_dictionary_free(Eet_Dictionary *ed);
|
void eet_dictionary_free(Eet_Dictionary *ed);
|
||||||
int eet_dictionary_string_add(Eet_Dictionary *ed, const char *string);
|
int eet_dictionary_string_add(Eet_Dictionary *ed, const char *string);
|
||||||
|
|
|
@ -26,6 +26,7 @@ eet_data.c \
|
||||||
eet_image.c \
|
eet_image.c \
|
||||||
eet_cipher.c \
|
eet_cipher.c \
|
||||||
eet_dictionary.c \
|
eet_dictionary.c \
|
||||||
|
eet_node.c \
|
||||||
eet_utils.c
|
eet_utils.c
|
||||||
|
|
||||||
libeet_la_CFLAGS = @EET_CFLAGS@ @DEBUG_CFLAGS@
|
libeet_la_CFLAGS = @EET_CFLAGS@ @DEBUG_CFLAGS@
|
||||||
|
|
|
@ -1673,84 +1673,16 @@ _eet_data_dump_token_get(const char *src, int *len)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct _Node Node;
|
|
||||||
|
|
||||||
struct _Node
|
|
||||||
{
|
|
||||||
int type;
|
|
||||||
int count;
|
|
||||||
char *name;
|
|
||||||
char *key;
|
|
||||||
Node *values;
|
|
||||||
Node *next;
|
|
||||||
Node *parent;
|
|
||||||
union {
|
|
||||||
char c;
|
|
||||||
short s;
|
|
||||||
int i;
|
|
||||||
long long l;
|
|
||||||
float f;
|
|
||||||
double d;
|
|
||||||
unsigned char uc;
|
|
||||||
unsigned short us;
|
|
||||||
unsigned int ui;
|
|
||||||
unsigned long long ul;
|
|
||||||
char *str;
|
|
||||||
} data;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
|
||||||
_eet_data_dump_free(Node *node)
|
|
||||||
{
|
|
||||||
Node *n, *n2;
|
|
||||||
|
|
||||||
switch (node->type)
|
|
||||||
{
|
|
||||||
case EET_G_UNKNOWN:
|
|
||||||
case EET_G_ARRAY:
|
|
||||||
case EET_G_VAR_ARRAY:
|
|
||||||
case EET_G_LIST:
|
|
||||||
case EET_G_HASH:
|
|
||||||
if (node->key) free(node->key);
|
|
||||||
for (n = node->values; n;)
|
|
||||||
{
|
|
||||||
n2 = n;
|
|
||||||
n = n->next;
|
|
||||||
_eet_data_dump_free(n2);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case EET_T_CHAR:
|
|
||||||
case EET_T_SHORT:
|
|
||||||
case EET_T_INT:
|
|
||||||
case EET_T_LONG_LONG:
|
|
||||||
case EET_T_FLOAT:
|
|
||||||
case EET_T_DOUBLE:
|
|
||||||
case EET_T_UCHAR:
|
|
||||||
case EET_T_USHORT:
|
|
||||||
case EET_T_UINT:
|
|
||||||
case EET_T_ULONG_LONG:
|
|
||||||
case EET_T_NULL:
|
|
||||||
break;
|
|
||||||
case EET_T_INLINED_STRING:
|
|
||||||
case EET_T_STRING:
|
|
||||||
if (node->data.str) free(node->data.str);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
free(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
_eet_data_dump_encode(Eet_Dictionary *ed,
|
_eet_data_dump_encode(Eet_Dictionary *ed,
|
||||||
Node *node,
|
Eet_Node *node,
|
||||||
int *size_ret)
|
int *size_ret)
|
||||||
{
|
{
|
||||||
Eet_Data_Chunk *chnk = NULL, *echnk = NULL;
|
Eet_Data_Chunk *chnk = NULL, *echnk = NULL;
|
||||||
Eet_Data_Stream *ds;
|
Eet_Data_Stream *ds;
|
||||||
void *cdata, *data;
|
void *cdata, *data;
|
||||||
int csize, size;
|
int csize, size;
|
||||||
Node *n;
|
Eet_Node *n;
|
||||||
|
|
||||||
if (words_bigendian == -1)
|
if (words_bigendian == -1)
|
||||||
{
|
{
|
||||||
|
@ -1996,9 +1928,9 @@ _eet_data_dump_parse(Eet_Dictionary *ed,
|
||||||
#define M_STRUCT 1
|
#define M_STRUCT 1
|
||||||
#define M_ 2
|
#define M_ 2
|
||||||
int left, jump;
|
int left, jump;
|
||||||
Node *node_base = NULL;
|
Eet_Node *node_base = NULL;
|
||||||
Node *node = NULL;
|
Eet_Node *node = NULL;
|
||||||
Node *n, *nn;
|
Eet_Node *n, *nn;
|
||||||
|
|
||||||
/* FIXME; handle parse errors */
|
/* FIXME; handle parse errors */
|
||||||
#define TOK_GET(t) \
|
#define TOK_GET(t) \
|
||||||
|
@ -2025,7 +1957,7 @@ _eet_data_dump_parse(Eet_Dictionary *ed,
|
||||||
if (!strcmp(tok4, "{"))
|
if (!strcmp(tok4, "{"))
|
||||||
{
|
{
|
||||||
/* we have 'group NAM TYP {' */
|
/* we have 'group NAM TYP {' */
|
||||||
n = calloc(1, sizeof(Node));
|
n = calloc(1, sizeof(Eet_Node));
|
||||||
if (n)
|
if (n)
|
||||||
{
|
{
|
||||||
n->parent = node;
|
n->parent = node;
|
||||||
|
@ -2050,7 +1982,7 @@ _eet_data_dump_parse(Eet_Dictionary *ed,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n->name = strdup(tok2);
|
n->name = eina_stringshare_add(tok2);
|
||||||
if (!strcmp(tok3, "struct")) n->type = EET_G_UNKNOWN;
|
if (!strcmp(tok3, "struct")) n->type = EET_G_UNKNOWN;
|
||||||
else if (!strcmp(tok3, "array")) n->type = EET_G_ARRAY;
|
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, "var_array")) n->type = EET_G_VAR_ARRAY;
|
||||||
|
@ -2084,7 +2016,7 @@ _eet_data_dump_parse(Eet_Dictionary *ed,
|
||||||
/* we have 'value NAME TYP XXX' */
|
/* we have 'value NAME TYP XXX' */
|
||||||
if (node_base)
|
if (node_base)
|
||||||
{
|
{
|
||||||
n = calloc(1, sizeof(Node));
|
n = calloc(1, sizeof(Eet_Node));
|
||||||
if (n)
|
if (n)
|
||||||
{
|
{
|
||||||
n->parent = node;
|
n->parent = node;
|
||||||
|
@ -2102,7 +2034,7 @@ _eet_data_dump_parse(Eet_Dictionary *ed,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n->name = strdup(tok2);
|
n->name = eina_stringshare_add(tok2);
|
||||||
if (!strcmp(tok3, "char:"))
|
if (!strcmp(tok3, "char:"))
|
||||||
{
|
{
|
||||||
n->type = EET_T_CHAR;
|
n->type = EET_T_CHAR;
|
||||||
|
@ -2156,12 +2088,12 @@ _eet_data_dump_parse(Eet_Dictionary *ed,
|
||||||
else if (!strcmp(tok3, "string:"))
|
else if (!strcmp(tok3, "string:"))
|
||||||
{
|
{
|
||||||
n->type = EET_T_STRING;
|
n->type = EET_T_STRING;
|
||||||
n->data.str = strdup(tok4);
|
n->data.str = eina_stringshare_add(tok4);
|
||||||
}
|
}
|
||||||
else if (!strcmp(tok3, "inlined:"))
|
else if (!strcmp(tok3, "inlined:"))
|
||||||
{
|
{
|
||||||
n->type = EET_T_INLINED_STRING;
|
n->type = EET_T_INLINED_STRING;
|
||||||
n->data.str = strdup(tok4);
|
n->data.str = eina_stringshare_add(tok4);
|
||||||
}
|
}
|
||||||
else if (!strcmp(tok3, "null"))
|
else if (!strcmp(tok3, "null"))
|
||||||
{
|
{
|
||||||
|
@ -2189,7 +2121,7 @@ _eet_data_dump_parse(Eet_Dictionary *ed,
|
||||||
/* we have 'key NAME' */
|
/* we have 'key NAME' */
|
||||||
if (node)
|
if (node)
|
||||||
{
|
{
|
||||||
node->key = strdup(tok2);
|
node->key = eina_stringshare_add(tok2);
|
||||||
}
|
}
|
||||||
free(tok2);
|
free(tok2);
|
||||||
}
|
}
|
||||||
|
@ -2219,7 +2151,7 @@ _eet_data_dump_parse(Eet_Dictionary *ed,
|
||||||
if (node_base)
|
if (node_base)
|
||||||
{
|
{
|
||||||
cdata = _eet_data_dump_encode(ed, node_base, size_ret);
|
cdata = _eet_data_dump_encode(ed, node_base, size_ret);
|
||||||
_eet_data_dump_free(node_base);
|
eet_node_del(node_base);
|
||||||
}
|
}
|
||||||
return cdata;
|
return cdata;
|
||||||
}
|
}
|
||||||
|
@ -3328,6 +3260,35 @@ _eet_data_descriptor_encode(Eet_Dictionary *ed,
|
||||||
return cdata;
|
return cdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
EAPI void *
|
EAPI void *
|
||||||
eet_data_descriptor_encode_cipher(Eet_Data_Descriptor *edd,
|
eet_data_descriptor_encode_cipher(Eet_Data_Descriptor *edd,
|
||||||
const void *data_in,
|
const void *data_in,
|
||||||
|
@ -3337,21 +3298,24 @@ eet_data_descriptor_encode_cipher(Eet_Data_Descriptor *edd,
|
||||||
void *ret = NULL;
|
void *ret = NULL;
|
||||||
void *ciphered = NULL;
|
void *ciphered = NULL;
|
||||||
unsigned int ciphered_len = 0;
|
unsigned int ciphered_len = 0;
|
||||||
|
int size;
|
||||||
|
|
||||||
ret = _eet_data_descriptor_encode(NULL, edd, data_in, size_ret);
|
ret = _eet_data_descriptor_encode(NULL, edd, data_in, &size);
|
||||||
if (key && ret)
|
if (key && ret)
|
||||||
{
|
{
|
||||||
if (eet_cipher(ret, *size_ret, key, strlen(key), &ciphered, &ciphered_len))
|
if (eet_cipher(ret, size, key, strlen(key), &ciphered, &ciphered_len))
|
||||||
{
|
{
|
||||||
if (ciphered) free(ciphered);
|
if (ciphered) free(ciphered);
|
||||||
size_ret = 0;
|
if (size_ret) *size_ret = 0;
|
||||||
free(ret);
|
free(ret);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
free(ret);
|
free(ret);
|
||||||
*size_ret = ciphered_len;
|
size = ciphered_len;
|
||||||
ret = ciphered;
|
ret = ciphered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (size_ret) *size_ret = size;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue