testing uncrustify on eet. this shall be standard efl formatting from

now on. you may run indent on code and convert to your own formatting
if you want.. but all code MUST be "uncrustified" before being
cxommitted to svn or before generating patches. time to get the
formatting monster under control.



SVN revision: 50563
This commit is contained in:
Carsten Haitzler 2010-07-28 01:45:57 +00:00
parent ba10bce434
commit 926db95c54
16 changed files with 10555 additions and 7874 deletions

View File

@ -60,6 +60,7 @@ do_eet_list(const char *file)
ERR("cannot open for reading: %s\n", file); ERR("cannot open for reading: %s\n", file);
exit(-1); exit(-1);
} }
list = eet_list(ef, "*", &num); list = eet_list(ef, "*", &num);
if (list) if (list)
{ {
@ -67,11 +68,15 @@ do_eet_list(const char *file)
printf("%s\n",list[i]); printf("%s\n",list[i]);
free(list); free(list);
} }
eet_close(ef); eet_close(ef);
} }
static void static void
do_eet_extract(const char *file, const char *key, const char *out, const char *crypto_key) do_eet_extract(const char *file,
const char *key,
const char *out,
const char *crypto_key)
{ {
Eet_File *ef; Eet_File *ef;
void *data; void *data;
@ -84,23 +89,27 @@ do_eet_extract(const char *file, const char *key, const char *out, const char *c
ERR("cannot open for reading: %s\n", file); ERR("cannot open for reading: %s\n", file);
exit(-1); exit(-1);
} }
data = eet_read_cipher(ef, key, &size, crypto_key); data = eet_read_cipher(ef, key, &size, crypto_key);
if (!data) if (!data)
{ {
ERR("cannot read key %s\n", key); ERR("cannot read key %s\n", key);
exit(-1); exit(-1);
} }
f = fopen(out, "wb"); f = fopen(out, "wb");
if (!f) if (!f)
{ {
ERR("cannot open %s\n", out); ERR("cannot open %s\n", out);
exit(-1); exit(-1);
} }
if (fwrite(data, size, 1, f) != 1) if (fwrite(data, size, 1, f) != 1)
{ {
ERR("cannot write to %s\n", out); ERR("cannot write to %s\n", out);
exit(-1); exit(-1);
} }
fclose(f); fclose(f);
free(data); free(data);
eet_close(ef); eet_close(ef);
@ -113,7 +122,10 @@ do_eet_decode_dump(void *data, const char *str)
} }
static void static void
do_eet_decode(const char *file, const char *key, const char *out, const char *crypto_key) do_eet_decode(const char *file,
const char *key,
const char *out,
const char *crypto_key)
{ {
Eet_File *ef; Eet_File *ef;
FILE *f; FILE *f;
@ -124,23 +136,30 @@ do_eet_decode(const char *file, const char *key, const char *out, const char *cr
ERR("cannot open for reading: %s\n", file); ERR("cannot open for reading: %s\n", file);
exit(-1); exit(-1);
} }
f = fopen(out, "wb"); f = fopen(out, "wb");
if (!f) if (!f)
{ {
ERR("cannot open %s\n", out); ERR("cannot open %s\n", out);
exit(-1); exit(-1);
} }
if (!eet_data_dump_cipher(ef, key, crypto_key, do_eet_decode_dump, f)) if (!eet_data_dump_cipher(ef, key, crypto_key, do_eet_decode_dump, f))
{ {
ERR("cannot write to %s\n", out); ERR("cannot write to %s\n", out);
exit(-1); exit(-1);
} }
fclose(f); fclose(f);
eet_close(ef); eet_close(ef);
} }
static void static void
do_eet_insert(const char *file, const char *key, const char *out, int compress, const char *crypto_key) do_eet_insert(const char *file,
const char *key,
const char *out,
int compress,
const char *crypto_key)
{ {
Eet_File *ef; Eet_File *ef;
void *data; void *data;
@ -150,17 +169,20 @@ do_eet_insert(const char *file, const char *key, const char *out, int compress,
ef = eet_open(file, EET_FILE_MODE_READ_WRITE); ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
if (!ef) if (!ef)
ef = eet_open(file, EET_FILE_MODE_WRITE); ef = eet_open(file, EET_FILE_MODE_WRITE);
if (!ef) if (!ef)
{ {
ERR("cannot open for read+write: %s\n", file); ERR("cannot open for read+write: %s\n", file);
exit(-1); exit(-1);
} }
f = fopen(out, "rb"); f = fopen(out, "rb");
if (!f) if (!f)
{ {
ERR("cannot open %s\n", out); ERR("cannot open %s\n", out);
exit(-1); exit(-1);
} }
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
size = ftell(f); size = ftell(f);
rewind(f); rewind(f);
@ -170,11 +192,13 @@ do_eet_insert(const char *file, const char *key, const char *out, int compress,
ERR("cannot allocate %i bytes\n", size); ERR("cannot allocate %i bytes\n", size);
exit(-1); exit(-1);
} }
if (fread(data, size, 1, f) != 1) if (fread(data, size, 1, f) != 1)
{ {
ERR("cannot read file %s\n", out); ERR("cannot read file %s\n", out);
exit(-1); exit(-1);
} }
fclose(f); fclose(f);
eet_write_cipher(ef, key, data, size, compress, crypto_key); eet_write_cipher(ef, key, data, size, compress, crypto_key);
free(data); free(data);
@ -182,7 +206,11 @@ do_eet_insert(const char *file, const char *key, const char *out, int compress,
} }
static void static void
do_eet_encode(const char *file, const char *key, const char *out, int compress, const char *crypto_key) do_eet_encode(const char *file,
const char *key,
const char *out,
int compress,
const char *crypto_key)
{ {
Eet_File *ef; Eet_File *ef;
char *text; char *text;
@ -193,17 +221,20 @@ do_eet_encode(const char *file, const char *key, const char *out, int compress,
ef = eet_open(file, EET_FILE_MODE_READ_WRITE); ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
if (!ef) if (!ef)
ef = eet_open(file, EET_FILE_MODE_WRITE); ef = eet_open(file, EET_FILE_MODE_WRITE);
if (!ef) if (!ef)
{ {
ERR("cannot open for read+write: %s\n", file); ERR("cannot open for read+write: %s\n", file);
exit(-1); exit(-1);
} }
f = fopen(out, "rb"); f = fopen(out, "rb");
if (!f) if (!f)
{ {
ERR("cannot open %s\n", out); ERR("cannot open %s\n", out);
exit(-1); exit(-1);
} }
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
textlen = ftell(f); textlen = ftell(f);
rewind(f); rewind(f);
@ -213,17 +244,20 @@ do_eet_encode(const char *file, const char *key, const char *out, int compress,
ERR("cannot allocate %i bytes\n", size); ERR("cannot allocate %i bytes\n", size);
exit(-1); exit(-1);
} }
if (fread(text, textlen, 1, f) != 1) if (fread(text, textlen, 1, f) != 1)
{ {
ERR("cannot read file %s\n", out); ERR("cannot read file %s\n", out);
exit(-1); exit(-1);
} }
fclose(f); fclose(f);
if (!eet_data_undump_cipher(ef, key, crypto_key, text, textlen, compress)) if (!eet_data_undump_cipher(ef, key, crypto_key, text, textlen, compress))
{ {
ERR("cannot parse %s\n", out); ERR("cannot parse %s\n", out);
exit(-1); exit(-1);
} }
free(text); free(text);
eet_close(ef); eet_close(ef);
} }
@ -239,6 +273,7 @@ do_eet_remove(const char *file, const char *key)
ERR("cannot open for read+write: %s\n", file); ERR("cannot open for read+write: %s\n", file);
exit(-1); exit(-1);
} }
eet_delete(ef, key); eet_delete(ef, key);
eet_close(ef); eet_close(ef);
} }
@ -310,10 +345,12 @@ main(int argc, char **argv)
eet_shutdown(); eet_shutdown();
return(-1); return(-1);
} }
if (argc < 2) if (argc < 2)
{ {
help: help:
printf("Usage:\n" printf(
"Usage:\n"
" eet -l FILE.EET list all keys in FILE.EET\n" " eet -l FILE.EET list all keys in FILE.EET\n"
" eet -x FILE.EET KEY OUT-FILE [CRYPTO_KEY] extract data stored in KEY in FILE.EET and write to OUT-FILE\n" " eet -x FILE.EET KEY OUT-FILE [CRYPTO_KEY] extract data stored in KEY in FILE.EET and write to OUT-FILE\n"
" eet -d FILE.EET KEY OUT-FILE [CRYPTO_KEY] extract and decode data stored in KEY in FILE.EET and write to OUT-FILE\n" " eet -d FILE.EET KEY OUT-FILE [CRYPTO_KEY] extract and decode data stored in KEY in FILE.EET and write to OUT-FILE\n"
@ -326,14 +363,11 @@ main(int argc, char **argv)
eet_shutdown(); eet_shutdown();
return -1; return -1;
} }
if ((!strncmp(argv[1], "-h", 2))) if ((!strncmp(argv[1], "-h", 2)))
{
goto help; goto help;
}
else if ((!strcmp(argv[1], "-l")) && (argc > 2)) else if ((!strcmp(argv[1], "-l")) && (argc > 2))
{
do_eet_list(argv[2]); do_eet_list(argv[2]);
}
else if ((!strcmp(argv[1], "-x")) && (argc > 4)) else if ((!strcmp(argv[1], "-x")) && (argc > 4))
{ {
if (argc > 5) if (argc > 5)
@ -363,21 +397,14 @@ main(int argc, char **argv)
do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), NULL); do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), NULL);
} }
else if ((!strcmp(argv[1], "-r")) && (argc > 3)) else if ((!strcmp(argv[1], "-r")) && (argc > 3))
{
do_eet_remove(argv[2], argv[3]); do_eet_remove(argv[2], argv[3]);
}
else if ((!strcmp(argv[1], "-c")) && (argc > 2)) else if ((!strcmp(argv[1], "-c")) && (argc > 2))
{
do_eet_check(argv[2]); do_eet_check(argv[2]);
}
else if ((!strcmp(argv[1], "-s")) && (argc > 4)) else if ((!strcmp(argv[1], "-s")) && (argc > 4))
{
do_eet_sign(argv[2], argv[3], argv[4]); do_eet_sign(argv[2], argv[3], argv[4]);
}
else else
{
goto help; goto help;
}
eina_log_domain_unregister(_eet_main_log_dom); eina_log_domain_unregister(_eet_main_log_dom);
eet_shutdown(); eet_shutdown();
return 0; return 0;

View File

@ -7,7 +7,8 @@
#include <unistd.h> #include <unistd.h>
// complex real-world structures based on elmdentica database // complex real-world structures based on elmdentica database
typedef struct { typedef struct
{
const char *screen_name; const char *screen_name;
const char *name; const char *name;
const char *message; const char *message;
@ -17,19 +18,22 @@ typedef struct {
unsigned int timeline; unsigned int timeline;
} My_Message; } My_Message;
typedef struct { typedef struct
{
const char *dm_to; const char *dm_to;
const char *message; const char *message;
} My_Post; } My_Post;
typedef struct { typedef struct
{
unsigned int id; unsigned int id;
const char *name; const char *name;
Eina_List *messages; Eina_List *messages;
Eina_List *posts; Eina_List *posts;
} My_Account; } My_Account;
typedef struct { typedef struct
{
unsigned int version; // it is recommended to use versioned configuration! unsigned int version; // it is recommended to use versioned configuration!
Eina_List *accounts; Eina_List *accounts;
} My_Cache; } My_Cache;
@ -76,7 +80,7 @@ _my_cache_descriptor_init(void)
#define ADD_BASIC(member, eet_type) \ #define ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \ EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_message_descriptor, My_Message, #member, member, eet_type) (_my_message_descriptor, My_Message, # member, member, eet_type)
ADD_BASIC(screen_name, EET_T_STRING); ADD_BASIC(screen_name, EET_T_STRING);
ADD_BASIC(name, EET_T_STRING); ADD_BASIC(name, EET_T_STRING);
ADD_BASIC(message, EET_T_STRING); ADD_BASIC(message, EET_T_STRING);
@ -88,14 +92,14 @@ _my_cache_descriptor_init(void)
#define ADD_BASIC(member, eet_type) \ #define ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \ EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_post_descriptor, My_Post, #member, member, eet_type) (_my_post_descriptor, My_Post, # member, member, eet_type)
ADD_BASIC(dm_to, EET_T_STRING); ADD_BASIC(dm_to, EET_T_STRING);
ADD_BASIC(message, EET_T_STRING); ADD_BASIC(message, EET_T_STRING);
#undef ADD_BASIC #undef ADD_BASIC
#define ADD_BASIC(member, eet_type) \ #define ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \ EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_account_descriptor, My_Account, #member, member, eet_type) (_my_account_descriptor, My_Account, # member, member, eet_type)
ADD_BASIC(name, EET_T_STRING); ADD_BASIC(name, EET_T_STRING);
ADD_BASIC(id, EET_T_UINT); ADD_BASIC(id, EET_T_UINT);
#undef ADD_BASIC #undef ADD_BASIC
@ -109,7 +113,7 @@ _my_cache_descriptor_init(void)
#define ADD_BASIC(member, eet_type) \ #define ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \ EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_cache_descriptor, My_Cache, #member, member, eet_type) (_my_cache_descriptor, My_Cache, # member, member, eet_type)
ADD_BASIC(version, EET_T_UINT); ADD_BASIC(version, EET_T_UINT);
#undef ADD_BASIC #undef ADD_BASIC
@ -134,8 +138,10 @@ _eet_string_free(const char *str)
{ {
if (!str) if (!str)
return; return;
if ((_my_cache_dict) && (eet_dictionary_string_check(_my_cache_dict, str))) if ((_my_cache_dict) && (eet_dictionary_string_check(_my_cache_dict, str)))
return; return;
eina_stringshare_del(str); eina_stringshare_del(str);
} }
@ -148,6 +154,7 @@ _my_message_new(const char *message)
fprintf(stderr, "ERROR: could not calloc My_Message\n"); fprintf(stderr, "ERROR: could not calloc My_Message\n");
return NULL; return NULL;
} }
msg->message = eina_stringshare_add(message); msg->message = eina_stringshare_add(message);
return msg; return msg;
} }
@ -170,6 +177,7 @@ _my_post_new(const char *message)
fprintf(stderr, "ERROR: could not calloc My_Post\n"); fprintf(stderr, "ERROR: could not calloc My_Post\n");
return NULL; return NULL;
} }
post->message = eina_stringshare_add(message); post->message = eina_stringshare_add(message);
return post; return post;
} }
@ -191,6 +199,7 @@ _my_account_new(const char *name)
fprintf(stderr, "ERROR: could not calloc My_Account\n"); fprintf(stderr, "ERROR: could not calloc My_Account\n");
return NULL; return NULL;
} }
acc->name = eina_stringshare_add(name); acc->name = eina_stringshare_add(name);
return acc; return acc;
} }
@ -243,6 +252,7 @@ _my_cache_account_find(My_Cache *my_cache, const char *name)
EINA_LIST_FOREACH(my_cache->accounts, l, acc) EINA_LIST_FOREACH(my_cache->accounts, l, acc)
if (strcmp(acc->name, name) == 0) if (strcmp(acc->name, name) == 0)
return acc; return acc;
return NULL; return NULL;
} }
@ -275,6 +285,7 @@ _my_cache_load(const char *filename)
if (_my_cache_file) if (_my_cache_file)
eet_close(_my_cache_file); eet_close(_my_cache_file);
_my_cache_file = ef; _my_cache_file = ef;
_my_cache_dict = eet_dictionary_get(ef); _my_cache_dict = eet_dictionary_get(ef);
@ -388,7 +399,8 @@ int main(int argc, char *argv[])
argv[4]); argv[4]);
} }
else else
fprintf(stderr, "ERROR: wrong number of parameters (%d).\n", fprintf(stderr,
"ERROR: wrong number of parameters (%d).\n",
argc); argc);
} }
else if (strcmp(argv[3], "post") == 0) else if (strcmp(argv[3], "post") == 0)
@ -405,7 +417,8 @@ int main(int argc, char *argv[])
fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]); fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]);
} }
else else
fprintf(stderr, "ERROR: wrong number of parameters (%d).\n", fprintf(stderr,
"ERROR: wrong number of parameters (%d).\n",
argc); argc);
} }
else if (strcmp(argv[3], "message") == 0) else if (strcmp(argv[3], "message") == 0)
@ -422,7 +435,8 @@ int main(int argc, char *argv[])
fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]); fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]);
} }
else else
fprintf(stderr, "ERROR: wrong number of parameters (%d).\n", fprintf(stderr,
"ERROR: wrong number of parameters (%d).\n",
argc); argc);
} }
else else
@ -473,6 +487,7 @@ int main(int argc, char *argv[])
printf("\t | '%.20s'\n", post->message); printf("\t | '%.20s'\n", post->message);
} }
} }
printf("\n"); printf("\n");
} }
@ -481,7 +496,7 @@ int main(int argc, char *argv[])
_my_cache_free(my_cache); _my_cache_free(my_cache);
end: end:
_my_cache_descriptor_shutdown(); _my_cache_descriptor_shutdown();
eet_shutdown(); eet_shutdown();
eina_shutdown(); eina_shutdown();

View File

@ -11,7 +11,8 @@
// will be automatically handled. The other members will have their // will be automatically handled. The other members will have their
// space reserved and zeroed (as it uses calloc()), but not // space reserved and zeroed (as it uses calloc()), but not
// saved or loaded from eet files. // saved or loaded from eet files.
typedef struct { typedef struct
{
unsigned int version; // it is recommended to use versioned configuration! unsigned int version; // it is recommended to use versioned configuration!
const char *name; const char *name;
int id; int id;
@ -20,7 +21,8 @@ typedef struct {
Eina_List *subs; Eina_List *subs;
} My_Conf_Type; } My_Conf_Type;
typedef struct { typedef struct
{
const char *server; const char *server;
int port; int port;
} My_Conf_Subtype; } My_Conf_Subtype;
@ -64,10 +66,10 @@ _my_conf_descriptor_init(void)
// Use a temporary macro so we don't type a lot, also avoid errors: // Use a temporary macro so we don't type a lot, also avoid errors:
#define MY_CONF_ADD_BASIC(member, eet_type) \ #define MY_CONF_ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \ EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_conf_descriptor, My_Conf_Type, #member, member, eet_type) (_my_conf_descriptor, My_Conf_Type, # member, member, eet_type)
#define MY_CONF_SUB_ADD_BASIC(member, eet_type) \ #define MY_CONF_SUB_ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \ EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_conf_sub_descriptor, My_Conf_Subtype, #member, member, eet_type) (_my_conf_sub_descriptor, My_Conf_Subtype, # member, member, eet_type)
MY_CONF_SUB_ADD_BASIC(server, EET_T_STRING); MY_CONF_SUB_ADD_BASIC(server, EET_T_STRING);
MY_CONF_SUB_ADD_BASIC(port, EET_T_INT); MY_CONF_SUB_ADD_BASIC(port, EET_T_INT);
@ -156,7 +158,7 @@ _my_conf_load(const char *filename)
my_conf->enabled = EINA_TRUE; my_conf->enabled = EINA_TRUE;
} }
end: end:
eet_close(ef); eet_close(ef);
return my_conf; return my_conf;
} }
@ -255,7 +257,7 @@ int main(int argc, char *argv[])
_my_conf_free(my_conf); _my_conf_free(my_conf);
end: end:
_my_conf_descriptor_shutdown(); _my_conf_descriptor_shutdown();
eet_shutdown(); eet_shutdown();
eina_shutdown(); eina_shutdown();

View File

@ -11,7 +11,8 @@
// will be automatically handled. The other members will have their // will be automatically handled. The other members will have their
// space reserved and zeroed (as it uses calloc()), but not // space reserved and zeroed (as it uses calloc()), but not
// saved or loaded from eet files. // saved or loaded from eet files.
typedef struct { typedef struct
{
unsigned int version; // it is recommended to use versioned configuration! unsigned int version; // it is recommended to use versioned configuration!
const char *name; const char *name;
int id; int id;
@ -54,7 +55,7 @@ _my_conf_descriptor_init(void)
// Use a temporary macro so we don't type a lot, also avoid errors: // Use a temporary macro so we don't type a lot, also avoid errors:
#define MY_CONF_ADD_BASIC(member, eet_type) \ #define MY_CONF_ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \ EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_conf_descriptor, My_Conf_Type, #member, member, eet_type) (_my_conf_descriptor, My_Conf_Type, # member, member, eet_type)
MY_CONF_ADD_BASIC(version, EET_T_UINT); MY_CONF_ADD_BASIC(version, EET_T_UINT);
MY_CONF_ADD_BASIC(name, EET_T_STRING); MY_CONF_ADD_BASIC(name, EET_T_STRING);
@ -117,7 +118,7 @@ _my_conf_load(const char *filename)
my_conf->enabled = EINA_TRUE; my_conf->enabled = EINA_TRUE;
} }
end: end:
eet_close(ef); eet_close(ef);
return my_conf; return my_conf;
} }
@ -208,7 +209,7 @@ int main(int argc, char *argv[])
_my_conf_free(my_conf); _my_conf_free(my_conf);
end: end:
_my_conf_descriptor_shutdown(); _my_conf_descriptor_shutdown();
eet_shutdown(); eet_shutdown();
eina_shutdown(); eina_shutdown();

File diff suppressed because it is too large Load Diff

View File

@ -101,25 +101,50 @@ extern int _eet_log_dom_global;
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,
int eet_dictionary_string_get_size(const Eet_Dictionary *ed, int index); const char *string);
const char *eet_dictionary_string_get_char(const Eet_Dictionary *ed, int index); int eet_dictionary_string_get_size(const Eet_Dictionary *ed,
Eina_Bool eet_dictionary_string_get_float(const Eet_Dictionary *ed, int index, float *result); int index);
Eina_Bool eet_dictionary_string_get_double(const Eet_Dictionary *ed, int index, double *result); const char * eet_dictionary_string_get_char(const Eet_Dictionary *ed,
Eina_Bool eet_dictionary_string_get_fp(const Eet_Dictionary *ed, int index, Eina_F32p32 *result); int index);
int eet_dictionary_string_get_hash(const Eet_Dictionary *ed, int index); Eina_Bool eet_dictionary_string_get_float(const Eet_Dictionary *ed,
int index,
float *result);
Eina_Bool eet_dictionary_string_get_double(const Eet_Dictionary *ed,
int index,
double *result);
Eina_Bool eet_dictionary_string_get_fp(const Eet_Dictionary *ed,
int index,
Eina_F32p32 *result);
int eet_dictionary_string_get_hash(const Eet_Dictionary *ed,
int index);
int _eet_hash_gen(const char *key, int hash_size); int _eet_hash_gen(const char *key, int hash_size);
const void* eet_identity_check(const void *data_base, unsigned int data_length, const void * eet_identity_check(const void *data_base,
void **sha1, int *sha1_length, unsigned int data_length,
const void *signature_base, unsigned int signature_length, void **sha1,
const void **raw_signature_base, unsigned int *raw_signature_length, int *sha1_length,
const void *signature_base,
unsigned int signature_length,
const void **raw_signature_base,
unsigned int *raw_signature_length,
int *x509_length); int *x509_length);
void *eet_identity_compute_sha1(const void *data_base, unsigned int data_length, void * eet_identity_compute_sha1(const void *data_base,
unsigned int data_length,
int *sha1_length); int *sha1_length);
Eet_Error eet_cipher(const void *data, unsigned int size, const char *key, unsigned int length, void **result, unsigned int *result_length); Eet_Error eet_cipher(const void *data,
Eet_Error eet_decipher(const void *data, unsigned int size, const char *key, unsigned int length, void **result, unsigned int *result_length); unsigned int size,
const char *key,
unsigned int length,
void **result,
unsigned int *result_length);
Eet_Error eet_decipher(const void *data,
unsigned int size,
const char *key,
unsigned int length,
void **result,
unsigned int *result_length);
Eet_Error eet_identity_sign(FILE *fp, Eet_Key *key); Eet_Error eet_identity_sign(FILE *fp, Eet_Key *key);
void eet_identity_unref(Eet_Key *key); void eet_identity_unref(Eet_Key *key);
void eet_identity_ref(Eet_Key *key); void eet_identity_ref(Eet_Key *key);
@ -134,9 +159,9 @@ void eet_node_free(Eet_Node *node);
#endif #endif
#ifdef DNDEBUG #ifdef DNDEBUG
# define EET_ASSERT(Test, Do) if (Test == 0) Do; # define EET_ASSERT(Test, Do) if (Test == 0) {Do; }
#else #else
# define EET_ASSERT(Test, Do) if (Test == 0) abort(); # define EET_ASSERT(Test, Do) if (Test == 0) {abort(); }
#endif #endif
#endif #endif

View File

@ -80,9 +80,19 @@ void *alloca (size_t);
#ifdef HAVE_CIPHER #ifdef HAVE_CIPHER
# ifdef HAVE_GNUTLS # ifdef HAVE_GNUTLS
static Eet_Error eet_hmac_sha1(const void *key, size_t key_len, const void *data, size_t data_len, unsigned char *res); static Eet_Error eet_hmac_sha1(const void *key,
size_t key_len,
const void *data,
size_t data_len,
unsigned char *res);
# endif # endif
static Eet_Error eet_pbkdf2_sha1(const char *key, int key_len, const unsigned char *salt, unsigned int salt_len, int iter, unsigned char *res, int res_len); static Eet_Error eet_pbkdf2_sha1(const char *key,
int key_len,
const unsigned char *salt,
unsigned int salt_len,
int iter,
unsigned char *res,
int res_len);
#endif #endif
struct _Eet_Key struct _Eet_Key
@ -99,8 +109,10 @@ struct _Eet_Key
#endif #endif
}; };
EAPI Eet_Key* EAPI Eet_Key *
eet_identity_open(const char *certificate_file, const char *private_key_file, Eet_Key_Password_Callback cb) eet_identity_open(const char *certificate_file,
const char *private_key_file,
Eet_Key_Password_Callback cb)
{ {
#ifdef HAVE_SIGNATURE #ifdef HAVE_SIGNATURE
/* Signature declarations */ /* Signature declarations */
@ -115,24 +127,40 @@ eet_identity_open(const char *certificate_file, const char *private_key_file, Ee
char pass[1024]; char pass[1024];
/* Init */ /* Init */
if (!(key = malloc(sizeof(Eet_Key)))) goto on_error; if (!(key = malloc(sizeof(Eet_Key))))
goto on_error;
key->references = 1; key->references = 1;
if (gnutls_x509_crt_init(&(key->certificate))) goto on_error; if (gnutls_x509_crt_init(&(key->certificate)))
if (gnutls_x509_privkey_init(&(key->private_key))) goto on_error; goto on_error;
if (gnutls_x509_privkey_init(&(key->private_key)))
goto on_error;
/* Mmap certificate_file */ /* Mmap certificate_file */
if (!(fp = fopen(certificate_file, "r"))) goto on_error; if (!(fp = fopen(certificate_file, "r")))
if ((fd = fileno(fp)) == -1) goto on_error; goto on_error;
if (fstat(fd, &st)) goto on_error;
if ((data = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED) goto on_error; if ((fd = fileno(fp)) == -1)
goto on_error;
if (fstat(fd, &st))
goto on_error;
if ((data =
mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED)
goto on_error;
/* Import the certificate in Eet_Key structure */ /* Import the certificate in Eet_Key structure */
load_file.data = data; load_file.data = data;
load_file.size = st.st_size; load_file.size = st.st_size;
if (gnutls_x509_crt_import(key->certificate, &load_file, GNUTLS_X509_FMT_PEM) < 0) if (gnutls_x509_crt_import(key->certificate, &load_file,
GNUTLS_X509_FMT_PEM) < 0)
goto on_error;
if (munmap(data, st.st_size))
goto on_error; goto on_error;
if (munmap(data, st.st_size)) goto on_error;
/* Reset values */ /* Reset values */
fclose(fp); fclose(fp);
@ -142,45 +170,66 @@ eet_identity_open(const char *certificate_file, const char *private_key_file, Ee
load_file.size = 0; load_file.size = 0;
/* Mmap private_key_file */ /* Mmap private_key_file */
if (!(fp = fopen(private_key_file, "r"))) goto on_error; if (!(fp = fopen(private_key_file, "r")))
if ((fd = fileno(fp)) == -1) goto on_error; goto on_error;
if (fstat(fd, &st)) goto on_error;
if ((data = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED) goto on_error; if ((fd = fileno(fp)) == -1)
goto on_error;
if (fstat(fd, &st))
goto on_error;
if ((data =
mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED)
goto on_error;
/* Import the private key in Eet_Key structure */ /* Import the private key in Eet_Key structure */
load_file.data = data; load_file.data = data;
load_file.size = st.st_size; load_file.size = st.st_size;
/* Try to directly import the PEM encoded private key */ /* Try to directly import the PEM encoded private key */
if (gnutls_x509_privkey_import(key->private_key, &load_file, GNUTLS_X509_FMT_PEM) < 0) if (gnutls_x509_privkey_import(key->private_key, &load_file,
GNUTLS_X509_FMT_PEM) < 0)
{ {
/* Else ask for the private key pass */ /* Else ask for the private key pass */
if (cb && cb(pass, 1024, 0, NULL)) if (cb && cb(pass, 1024, 0, NULL))
{ {
/* If pass then try to decode the pkcs 8 private key */ /* If pass then try to decode the pkcs 8 private key */
if (gnutls_x509_privkey_import_pkcs8(key->private_key, &load_file, GNUTLS_X509_FMT_PEM, pass, 0)) if (gnutls_x509_privkey_import_pkcs8(key->private_key, &load_file,
GNUTLS_X509_FMT_PEM, pass, 0))
goto on_error; goto on_error;
} }
else else
{
/* Else try to import the pkcs 8 private key without pass */ /* Else try to import the pkcs 8 private key without pass */
if (gnutls_x509_privkey_import_pkcs8(key->private_key, &load_file, GNUTLS_X509_FMT_PEM, NULL, 1)) if (gnutls_x509_privkey_import_pkcs8(key->private_key, &load_file,
GNUTLS_X509_FMT_PEM, NULL, 1))
goto on_error; goto on_error;
} }
}
if (munmap(data, st.st_size)) goto on_error; if (munmap(data, st.st_size))
goto on_error;
fclose(fp); fclose(fp);
return key; return key;
on_error: on_error:
if (fp) fclose(fp); if (fp)
fclose(fp);
if (key) if (key)
{ {
if (key->certificate) gnutls_x509_crt_deinit(key->certificate); if (key->certificate)
if (key->private_key) gnutls_x509_privkey_deinit(key->private_key); gnutls_x509_crt_deinit(key->certificate);
if (key->private_key)
gnutls_x509_privkey_deinit(key->private_key);
free(key); free(key);
} }
if (data) munmap(data, st.st_size);
if (data)
munmap(data, st.st_size);
# else # else
/* Openssl private declarations */ /* Openssl private declarations */
EVP_PKEY *pkey = NULL; EVP_PKEY *pkey = NULL;
@ -188,34 +237,47 @@ eet_identity_open(const char *certificate_file, const char *private_key_file, Ee
/* Load the X509 certificate in memory. */ /* Load the X509 certificate in memory. */
fp = fopen(certificate_file, "r"); fp = fopen(certificate_file, "r");
if (!fp) return NULL; if (!fp)
return NULL;
cert = PEM_read_X509(fp, NULL, NULL, NULL); cert = PEM_read_X509(fp, NULL, NULL, NULL);
fclose(fp); fclose(fp);
if (!cert) goto on_error; if (!cert)
goto on_error;
/* Check the presence of the public key. Just in case. */ /* Check the presence of the public key. Just in case. */
pkey = X509_get_pubkey(cert); pkey = X509_get_pubkey(cert);
if (!pkey) goto on_error; if (!pkey)
goto on_error;
/* Load the private key in memory. */ /* Load the private key in memory. */
fp = fopen(private_key_file, "r"); fp = fopen(private_key_file, "r");
if (!fp) goto on_error; if (!fp)
goto on_error;
pkey = PEM_read_PrivateKey(fp, NULL, cb, NULL); pkey = PEM_read_PrivateKey(fp, NULL, cb, NULL);
fclose(fp); fclose(fp);
if (!pkey) goto on_error; if (!pkey)
goto on_error;
/* Load the certificate and the private key in Eet_Key structure */ /* Load the certificate and the private key in Eet_Key structure */
key = malloc(sizeof(Eet_Key)); key = malloc(sizeof(Eet_Key));
if (!key) goto on_error; if (!key)
goto on_error;
key->references = 1; key->references = 1;
key->certificate = cert; key->certificate = cert;
key->private_key = pkey; key->private_key = pkey;
return key; return key;
on_error: on_error:
if (cert) X509_free(cert); if (cert)
if (pkey) EVP_PKEY_free(pkey); X509_free(cert);
if (pkey)
EVP_PKEY_free(pkey);
# endif # endif
#endif #endif
return NULL; return NULL;
@ -225,7 +287,9 @@ EAPI void
eet_identity_close(Eet_Key *key) eet_identity_close(Eet_Key *key)
{ {
#ifdef HAVE_SIGNATURE #ifdef HAVE_SIGNATURE
if (!key || (key->references > 0)) return ; if (!key || (key->references > 0))
return;
# ifdef HAVE_GNUTLS # ifdef HAVE_GNUTLS
gnutls_x509_crt_deinit(key->certificate); gnutls_x509_crt_deinit(key->certificate);
gnutls_x509_privkey_deinit(key->private_key); gnutls_x509_privkey_deinit(key->private_key);
@ -258,7 +322,8 @@ eet_identity_print(Eet_Key *key, FILE *out)
char buf[33]; char buf[33];
unsigned int i, j; unsigned int i, j;
if (!key) return ; if (!key)
return;
if (key->private_key) if (key->private_key)
{ {
@ -270,19 +335,26 @@ eet_identity_print(Eet_Key *key, FILE *out)
rsa_raw + 4, /* Second prime */ rsa_raw + 4, /* Second prime */
rsa_raw + 5)) /* Coefficient */ rsa_raw + 5)) /* Coefficient */
goto on_error; goto on_error;
if (!(res = malloc(size))) goto on_error;
if (!(res = malloc(size)))
goto on_error;
fprintf(out, "Private Key:\n"); fprintf(out, "Private Key:\n");
buf[32] = '\0'; buf[32] = '\0';
for (i = 0; i < 6; i++) for (i = 0; i < 6; i++)
{ {
while ((err = gnutls_hex_encode(rsa_raw + i, res, &size)) == GNUTLS_E_SHORT_MEMORY_BUFFER) while ((err =
gnutls_hex_encode(rsa_raw + i, res,
&size)) ==
GNUTLS_E_SHORT_MEMORY_BUFFER)
{ {
size += 128; size += 128;
if (!(res = realloc(res, size))) goto on_error; if (!(res = realloc(res, size)))
goto on_error;
} }
if (err) goto on_error; if (err)
goto on_error;
fprintf(out, "\t%s:\n", names[i]); fprintf(out, "\t%s:\n", names[i]);
for (j = 0; strlen(res) > j; j += 32) for (j = 0; strlen(res) > j; j += 32)
@ -298,22 +370,29 @@ eet_identity_print(Eet_Key *key, FILE *out)
if (key->certificate) if (key->certificate)
{ {
fprintf(out, "Public certificate:\n"); fprintf(out, "Public certificate:\n");
if (gnutls_x509_crt_print(key->certificate, GNUTLS_X509_CRT_FULL, &data)) goto on_error; if (gnutls_x509_crt_print(key->certificate, GNUTLS_X509_CRT_FULL, &data))
goto on_error;
fprintf(out, "%s\n", data.data); fprintf(out, "%s\n", data.data);
gnutls_free(data.data); gnutls_free(data.data);
data.data = NULL; data.data = NULL;
} }
on_error: on_error:
if (res) free(res); if (res)
if (data.data) gnutls_free(data.data); free(res);
return ;
if (data.data)
gnutls_free(data.data);
return;
# else # else
RSA *rsa; RSA *rsa;
DSA *dsa; DSA *dsa;
DH *dh; DH *dh;
if (!key) return ; if (!key)
return;
rsa = EVP_PKEY_get1_RSA(key->private_key); rsa = EVP_PKEY_get1_RSA(key->private_key);
if (rsa) if (rsa)
@ -347,14 +426,18 @@ eet_identity_print(Eet_Key *key, FILE *out)
void void
eet_identity_ref(Eet_Key *key) eet_identity_ref(Eet_Key *key)
{ {
if (key == NULL) return ; if (key == NULL)
return;
key->references++; key->references++;
} }
void void
eet_identity_unref(Eet_Key *key) eet_identity_unref(Eet_Key *key)
{ {
if (key == NULL) return ; if (key == NULL)
return;
key->references--; key->references--;
eet_identity_close(key); eet_identity_close(key);
} }
@ -368,17 +451,23 @@ eet_identity_compute_sha1(const void *data_base, unsigned int data_length,
#ifdef HAVE_SIGNATURE #ifdef HAVE_SIGNATURE
# ifdef HAVE_GNUTLS # ifdef HAVE_GNUTLS
result = malloc(gcry_md_get_algo_dlen(GCRY_MD_SHA1)); result = malloc(gcry_md_get_algo_dlen(GCRY_MD_SHA1));
if (!result) return NULL; if (!result)
return NULL;
gcry_md_hash_buffer(GCRY_MD_SHA1, result, data_base, data_length); gcry_md_hash_buffer(GCRY_MD_SHA1, result, data_base, data_length);
if (sha1_length) *sha1_length = gcry_md_get_algo_dlen(GCRY_MD_SHA1); if (sha1_length)
*sha1_length = gcry_md_get_algo_dlen(GCRY_MD_SHA1);
# else # else
# ifdef HAVE_OPENSSL # ifdef HAVE_OPENSSL
result = malloc(SHA_DIGEST_LENGTH); result = malloc(SHA_DIGEST_LENGTH);
if (!result) return NULL; if (!result)
return NULL;
SHA1(data_base, data_length, result); SHA1(data_base, data_length, result);
if (sha1_length) *sha1_length = SHA_DIGEST_LENGTH; if (sha1_length)
*sha1_length = SHA_DIGEST_LENGTH;
# else # else
result = NULL; result = NULL;
# endif # endif
@ -417,19 +506,24 @@ eet_identity_sign(FILE *fp, Eet_Key *key)
/* Get the file size. */ /* Get the file size. */
fd = fileno(fp); fd = fileno(fp);
if (fd < 0) return EET_ERROR_BAD_OBJECT; if (fd < 0)
if (fstat(fd, &st_buf) < 0) return EET_ERROR_MMAP_FAILED; return EET_ERROR_BAD_OBJECT;
if (fstat(fd, &st_buf) < 0)
return EET_ERROR_MMAP_FAILED;
/* Map the file in memory. */ /* Map the file in memory. */
data = mmap(NULL, st_buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); data = mmap(NULL, st_buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (data == MAP_FAILED) return EET_ERROR_MMAP_FAILED; if (data == MAP_FAILED)
return EET_ERROR_MMAP_FAILED;
# ifdef HAVE_GNUTLS # ifdef HAVE_GNUTLS
datum.data = data; datum.data = data;
datum.size = st_buf.st_size; datum.size = st_buf.st_size;
/* Get the signature length */ /* Get the signature length */
if (gnutls_x509_privkey_sign_data(key->private_key, GNUTLS_DIG_SHA1, 0, &datum, sign, &sign_len) && if (gnutls_x509_privkey_sign_data(key->private_key, GNUTLS_DIG_SHA1, 0,
&datum, sign, &sign_len) &&
!sign_len) !sign_len)
{ {
err = EET_ERROR_SIGNATURE_FAILED; err = EET_ERROR_SIGNATURE_FAILED;
@ -438,15 +532,22 @@ eet_identity_sign(FILE *fp, Eet_Key *key)
/* Get the signature */ /* Get the signature */
sign = malloc(sign_len); sign = malloc(sign_len);
if (!sign || gnutls_x509_privkey_sign_data(key->private_key, GNUTLS_DIG_SHA1, 0, &datum, sign, &sign_len)) if (!sign ||
gnutls_x509_privkey_sign_data(key->private_key, GNUTLS_DIG_SHA1, 0,
&datum,
sign, &sign_len))
{ {
if (!sign) err = EET_ERROR_OUT_OF_MEMORY; if (!sign)
else err = EET_ERROR_SIGNATURE_FAILED; err = EET_ERROR_OUT_OF_MEMORY;
else
err = EET_ERROR_SIGNATURE_FAILED;
goto on_error; goto on_error;
} }
/* Get the certificate length */ /* Get the certificate length */
if (gnutls_x509_crt_export(key->certificate, GNUTLS_X509_FMT_DER, cert, &cert_len) && if (gnutls_x509_crt_export(key->certificate, GNUTLS_X509_FMT_DER, cert,
&cert_len) &&
!cert_len) !cert_len)
{ {
err = EET_ERROR_SIGNATURE_FAILED; err = EET_ERROR_SIGNATURE_FAILED;
@ -455,12 +556,18 @@ eet_identity_sign(FILE *fp, Eet_Key *key)
/* Get the certificate */ /* Get the certificate */
cert = malloc(cert_len); cert = malloc(cert_len);
if (!cert || gnutls_x509_crt_export(key->certificate, GNUTLS_X509_FMT_DER, cert, &cert_len)) if (!cert ||
gnutls_x509_crt_export(key->certificate, GNUTLS_X509_FMT_DER, cert,
&cert_len))
{ {
if (!cert) err = EET_ERROR_OUT_OF_MEMORY; if (!cert)
else err = EET_ERROR_SIGNATURE_FAILED; err = EET_ERROR_OUT_OF_MEMORY;
else
err = EET_ERROR_SIGNATURE_FAILED;
goto on_error; goto on_error;
} }
# else # else
sign_len = EVP_PKEY_size(key->private_key); sign_len = EVP_PKEY_size(key->private_key);
sign = malloc(sign_len); sign = malloc(sign_len);
@ -473,7 +580,10 @@ eet_identity_sign(FILE *fp, Eet_Key *key)
/* Do the signature. */ /* Do the signature. */
EVP_SignInit(&md_ctx, EVP_sha1()); EVP_SignInit(&md_ctx, EVP_sha1());
EVP_SignUpdate(&md_ctx, data, st_buf.st_size); EVP_SignUpdate(&md_ctx, data, st_buf.st_size);
err = EVP_SignFinal(&md_ctx, sign, (unsigned int *)&sign_len, key->private_key); err = EVP_SignFinal(&md_ctx,
sign,
(unsigned int *)&sign_len,
key->private_key);
if (err != 1) if (err != 1)
{ {
ERR_print_errors_fp(stdout); ERR_print_errors_fp(stdout);
@ -489,35 +599,44 @@ eet_identity_sign(FILE *fp, Eet_Key *key)
err = EET_ERROR_X509_ENCODING_FAILED; err = EET_ERROR_X509_ENCODING_FAILED;
goto on_error; goto on_error;
} }
# endif # endif
/* Append the signature at the end of the file. */ /* Append the signature at the end of the file. */
head[0] = (int) htonl ((unsigned int) EET_MAGIC_SIGN); head[0] = (int)htonl ((unsigned int)EET_MAGIC_SIGN);
head[1] = (int) htonl ((unsigned int) sign_len); head[1] = (int)htonl ((unsigned int)sign_len);
head[2] = (int) htonl ((unsigned int) cert_len); head[2] = (int)htonl ((unsigned int)cert_len);
if (fwrite(head, sizeof(head), 1, fp) != 1) if (fwrite(head, sizeof(head), 1, fp) != 1)
{ {
err = EET_ERROR_WRITE_ERROR; err = EET_ERROR_WRITE_ERROR;
goto on_error; goto on_error;
} }
if (fwrite(sign, sign_len, 1, fp) != 1) if (fwrite(sign, sign_len, 1, fp) != 1)
{ {
err = EET_ERROR_WRITE_ERROR; err = EET_ERROR_WRITE_ERROR;
goto on_error; goto on_error;
} }
if (fwrite(cert, cert_len, 1, fp) != 1) if (fwrite(cert, cert_len, 1, fp) != 1)
{ {
err = EET_ERROR_WRITE_ERROR; err = EET_ERROR_WRITE_ERROR;
goto on_error; goto on_error;
} }
on_error: on_error:
# ifdef HAVE_GNUTLS # ifdef HAVE_GNUTLS
if (cert) free(cert); if (cert)
free(cert);
# else # else
if (cert) OPENSSL_free(cert); if (cert)
OPENSSL_free(cert);
# endif # endif
if (sign) free(sign); if (sign)
free(sign);
munmap(data, st_buf.st_size); munmap(data, st_buf.st_size);
return err; return err;
#else #else
@ -525,11 +644,15 @@ eet_identity_sign(FILE *fp, Eet_Key *key)
#endif #endif
} }
const void* const void *
eet_identity_check(const void *data_base, unsigned int data_length, eet_identity_check(const void *data_base,
void **sha1, int *sha1_length, unsigned int data_length,
const void *signature_base, unsigned int signature_length, void **sha1,
const void **raw_signature_base, unsigned int *raw_signature_length, int *sha1_length,
const void *signature_base,
unsigned int signature_length,
const void **raw_signature_base,
unsigned int *raw_signature_length,
int *x509_length) int *x509_length)
{ {
#ifdef HAVE_SIGNATURE #ifdef HAVE_SIGNATURE
@ -541,7 +664,8 @@ eet_identity_check(const void *data_base, unsigned int data_length,
int magic; int magic;
/* At least the header size */ /* At least the header size */
if (signature_length < sizeof(int) * 3) return NULL; if (signature_length < sizeof(int) * 3)
return NULL;
/* Get the header */ /* Get the header */
magic = ntohl(header[0]); magic = ntohl(header[0]);
@ -549,8 +673,11 @@ eet_identity_check(const void *data_base, unsigned int data_length,
cert_len = ntohl(header[2]); cert_len = ntohl(header[2]);
/* Verify the header */ /* Verify the header */
if (magic != EET_MAGIC_SIGN) return NULL; if (magic != EET_MAGIC_SIGN)
if (sign_len + cert_len + sizeof(int) * 3 > signature_length) return NULL; return NULL;
if (sign_len + cert_len + sizeof(int) * 3 > signature_length)
return NULL;
/* Update the signature and certificate pointer */ /* Update the signature and certificate pointer */
sign = (unsigned char *)signature_base + sizeof(int) * 3; sign = (unsigned char *)signature_base + sizeof(int) * 3;
@ -582,7 +709,8 @@ eet_identity_check(const void *data_base, unsigned int data_length,
But we now have a way to prevent double computation of SHA1. But we now have a way to prevent double computation of SHA1.
*/ */
err = gcry_md_open (&md, GCRY_MD_SHA1, 0); err = gcry_md_open (&md, GCRY_MD_SHA1, 0);
if (err < 0) return NULL; if (err < 0)
return NULL;
gcry_md_write(md, data_base, data_length); gcry_md_write(md, data_base, data_length);
@ -628,6 +756,7 @@ eet_identity_check(const void *data_base, unsigned int data_length,
*sha1 = NULL; *sha1 = NULL;
*sha1_length = -1; *sha1_length = -1;
} }
# endif # endif
gnutls_x509_crt_deinit(cert); gnutls_x509_crt_deinit(cert);
@ -640,12 +769,13 @@ eet_identity_check(const void *data_base, unsigned int data_length,
/* Strange but d2i_X509 seems to put 0 all over the place. */ /* Strange but d2i_X509 seems to put 0 all over the place. */
tmp = alloca(cert_len); tmp = alloca(cert_len);
memcpy((char*) tmp, cert_der, cert_len); memcpy((char *)tmp, cert_der, cert_len);
x509 = d2i_X509(NULL, &tmp, cert_len); x509 = d2i_X509(NULL, &tmp, cert_len);
if (x509 == NULL) return NULL; if (x509 == NULL)
return NULL;
/* Get public key - eay */ /* Get public key - eay */
pkey=X509_get_pubkey(x509); pkey = X509_get_pubkey(x509);
if (pkey == NULL) if (pkey == NULL)
{ {
X509_free(x509); X509_free(x509);
@ -668,10 +798,17 @@ eet_identity_check(const void *data_base, unsigned int data_length,
if (err != 1) if (err != 1)
return NULL; return NULL;
# endif # endif
if (x509_length) *x509_length = cert_len; if (x509_length)
if (raw_signature_base) *raw_signature_base = sign; *x509_length = cert_len;
if (raw_signature_length) *raw_signature_length = sign_len;
if (raw_signature_base)
*raw_signature_base = sign;
if (raw_signature_length)
*raw_signature_length = sign_len;
return cert_der; return cert_der;
#else #else
return NULL; return NULL;
@ -679,14 +816,17 @@ eet_identity_check(const void *data_base, unsigned int data_length,
} }
EAPI void EAPI void
eet_identity_certificate_print(const unsigned char *certificate, int der_length, FILE *out) eet_identity_certificate_print(const unsigned char *certificate,
int der_length,
FILE *out)
{ {
#ifdef HAVE_SIGNATURE #ifdef HAVE_SIGNATURE
if (!certificate || !out || der_length <= 0) if (!certificate || !out || der_length <= 0)
{ {
ERR("No certificate provided."); ERR("No certificate provided.");
return ; return;
} }
# ifdef HAVE_GNUTLS # ifdef HAVE_GNUTLS
gnutls_datum_t datum; gnutls_datum_t datum;
gnutls_x509_crt_t cert; gnutls_x509_crt_t cert;
@ -694,18 +834,25 @@ eet_identity_certificate_print(const unsigned char *certificate, int der_length,
/* Create an understanding certificate structure for gnutls */ /* Create an understanding certificate structure for gnutls */
datum.data = (void *)certificate; datum.data = (void *)certificate;
datum.size = der_length; datum.size = der_length;
if (gnutls_x509_crt_init(&cert)) goto on_error; if (gnutls_x509_crt_init(&cert))
if (gnutls_x509_crt_import(cert, &datum, GNUTLS_X509_FMT_DER)) goto on_error; goto on_error;
if (gnutls_x509_crt_import(cert, &datum, GNUTLS_X509_FMT_DER))
goto on_error;
/* Pretty print the certificate */ /* Pretty print the certificate */
datum.data = NULL; datum.data = NULL;
datum.size = 0; datum.size = 0;
if (gnutls_x509_crt_print(cert, GNUTLS_X509_CRT_FULL, &datum)) goto on_error; if (gnutls_x509_crt_print(cert, GNUTLS_X509_CRT_FULL, &datum))
goto on_error;
INF("Public certificate :"); INF("Public certificate :");
INF("%s", datum.data); INF("%s", datum.data);
on_error: on_error:
if (datum.data) gnutls_free(datum.data); if (datum.data)
gnutls_free(datum.data);
gnutls_x509_crt_deinit(cert); gnutls_x509_crt_deinit(cert);
# else # else
const unsigned char *tmp; const unsigned char *tmp;
@ -713,12 +860,12 @@ eet_identity_certificate_print(const unsigned char *certificate, int der_length,
/* Strange but d2i_X509 seems to put 0 all over the place. */ /* Strange but d2i_X509 seems to put 0 all over the place. */
tmp = alloca(der_length); tmp = alloca(der_length);
memcpy((char*) tmp, certificate, der_length); memcpy((char *)tmp, certificate, der_length);
x509 = d2i_X509(NULL, &tmp, der_length); x509 = d2i_X509(NULL, &tmp, der_length);
if (x509 == NULL) if (x509 == NULL)
{ {
INF("Not a valid certificate."); INF("Not a valid certificate.");
return ; return;
} }
INF("Public certificate :"); INF("Public certificate :");
@ -732,7 +879,12 @@ eet_identity_certificate_print(const unsigned char *certificate, int der_length,
} }
Eet_Error Eet_Error
eet_cipher(const void *data, unsigned int size, const char *key, unsigned int length, void **result, unsigned int *result_length) eet_cipher(const void *data,
unsigned int size,
const char *key,
unsigned int length,
void **result,
unsigned int *result_length)
{ {
#ifdef HAVE_CIPHER #ifdef HAVE_CIPHER
/* Cipher declarations */ /* Cipher declarations */
@ -760,11 +912,18 @@ eet_cipher(const void *data, unsigned int size, const char *key, unsigned int le
gcry_create_nonce((unsigned char *)&salt, sizeof(salt)); gcry_create_nonce((unsigned char *)&salt, sizeof(salt));
# else # else
/* Openssl salt generation */ /* Openssl salt generation */
if (!RAND_bytes((unsigned char*)&salt, sizeof (unsigned int))) if (!RAND_bytes((unsigned char *)&salt, sizeof (unsigned int)))
return EET_ERROR_PRNG_NOT_SEEDED; return EET_ERROR_PRNG_NOT_SEEDED;
#endif #endif
eet_pbkdf2_sha1(key, length, (unsigned char *)&salt, sizeof(unsigned int), 2048, key_material, MAX_KEY_LEN + MAX_IV_LEN); eet_pbkdf2_sha1(key,
length,
(unsigned char *)&salt,
sizeof(unsigned int),
2048,
key_material,
MAX_KEY_LEN + MAX_IV_LEN);
memcpy(iv, key_material, MAX_IV_LEN); memcpy(iv, key_material, MAX_IV_LEN);
memcpy(ik, key_material + MAX_IV_LEN, MAX_KEY_LEN); memcpy(ik, key_material + MAX_IV_LEN, MAX_KEY_LEN);
@ -773,7 +932,8 @@ eet_cipher(const void *data, unsigned int size, const char *key, unsigned int le
crypted_length = ((((size + sizeof (unsigned int)) >> 5) + 1) << 5); crypted_length = ((((size + sizeof (unsigned int)) >> 5) + 1) << 5);
ret = malloc(crypted_length + sizeof(unsigned int)); ret = malloc(crypted_length + sizeof(unsigned int));
if (!ret) { if (!ret)
{
memset(iv, 0, sizeof (iv)); memset(iv, 0, sizeof (iv));
memset(ik, 0, sizeof (ik)); memset(ik, 0, sizeof (ik));
memset(&salt, 0, sizeof (salt)); memset(&salt, 0, sizeof (salt));
@ -791,19 +951,29 @@ eet_cipher(const void *data, unsigned int size, const char *key, unsigned int le
/* Gcrypt create the corresponding cipher /* Gcrypt create the corresponding cipher
AES with a 256 bit key, Cipher Block Chaining mode */ AES with a 256 bit key, Cipher Block Chaining mode */
err = gcry_cipher_open(&cipher, GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CBC, 0); err = gcry_cipher_open(&cipher, GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CBC, 0);
if (err) goto on_error; if (err)
goto on_error;
opened = 1; opened = 1;
err = gcry_cipher_setiv(cipher, iv, MAX_IV_LEN); err = gcry_cipher_setiv(cipher, iv, MAX_IV_LEN);
if (err) goto on_error; if (err)
goto on_error;
err = gcry_cipher_setkey(cipher, ik, MAX_KEY_LEN); err = gcry_cipher_setkey(cipher, ik, MAX_KEY_LEN);
if (err) goto on_error; if (err)
goto on_error;
memset(iv, 0, sizeof (iv)); memset(iv, 0, sizeof (iv));
memset(ik, 0, sizeof (ik)); memset(ik, 0, sizeof (ik));
/* Gcrypt encrypt */ /* Gcrypt encrypt */
err = gcry_cipher_encrypt(cipher, (unsigned char *)(ret + 1), crypted_length, NULL, 0); err = gcry_cipher_encrypt(cipher,
if (err) goto on_error; (unsigned char *)(ret + 1),
crypted_length,
NULL,
0);
if (err)
goto on_error;
/* Gcrypt close the cipher */ /* Gcrypt close the cipher */
gcry_cipher_close(cipher); gcry_cipher_close(cipher);
@ -816,60 +986,81 @@ eet_cipher(const void *data, unsigned int size, const char *key, unsigned int le
/* Openssl create the corresponding cipher /* Openssl create the corresponding cipher
AES with a 256 bit key, Cipher Block Chaining mode */ AES with a 256 bit key, Cipher Block Chaining mode */
EVP_CIPHER_CTX_init(&ctx); EVP_CIPHER_CTX_init(&ctx);
if (!EVP_EncryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, ik, iv)) goto on_error; if (!EVP_EncryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, ik, iv))
goto on_error;
opened = 1; opened = 1;
memset(iv, 0, sizeof (iv)); memset(iv, 0, sizeof (iv));
memset(ik, 0, sizeof (ik)); memset(ik, 0, sizeof (ik));
/* Openssl encrypt */ /* Openssl encrypt */
if (!EVP_EncryptUpdate(&ctx, (unsigned char*)(ret + 1), &tmp_len, (unsigned char*) buffer, size + sizeof (unsigned int))) if (!EVP_EncryptUpdate(&ctx, (unsigned char *)(ret + 1), &tmp_len,
(unsigned char *)buffer, size + sizeof (unsigned int)))
goto on_error; goto on_error;
/* Openssl close the cipher */ /* Openssl close the cipher */
if (!EVP_EncryptFinal_ex(&ctx, ((unsigned char*)(ret + 1)) + tmp_len, &tmp_len)) if (!EVP_EncryptFinal_ex(&ctx, ((unsigned char *)(ret + 1)) + tmp_len,
&tmp_len))
goto on_error; goto on_error;
EVP_CIPHER_CTX_cleanup(&ctx); EVP_CIPHER_CTX_cleanup(&ctx);
# endif # endif
/* Set return values */ /* Set return values */
if (result_length) *result_length = crypted_length + sizeof(unsigned int); if (result_length)
if (result) *result = ret; *result_length = crypted_length + sizeof(unsigned int);
else free(ret);
if (result)
*result = ret;
else
free(ret);
return EET_ERROR_NONE; return EET_ERROR_NONE;
on_error: on_error:
memset(iv, 0, sizeof (iv)); memset(iv, 0, sizeof (iv));
memset(ik, 0, sizeof (ik)); memset(ik, 0, sizeof (ik));
# ifdef HAVE_GNUTLS # ifdef HAVE_GNUTLS
/* Gcrypt error */ /* Gcrypt error */
if (opened) gcry_cipher_close(cipher); if (opened)
gcry_cipher_close(cipher);
# else # else
/* Openssl error */ /* Openssl error */
if (opened) EVP_CIPHER_CTX_cleanup(&ctx); if (opened)
EVP_CIPHER_CTX_cleanup(&ctx);
# endif # endif
/* General error */ /* General error */
free(ret); free(ret);
if (result) *result = NULL; if (result)
if (result_length) *result_length = 0; *result = NULL;
if (result_length)
*result_length = 0;
return EET_ERROR_ENCRYPT_FAILED; return EET_ERROR_ENCRYPT_FAILED;
#else #else
/* Cipher not supported */ /* Cipher not supported */
(void) data; (void)data;
(void) size; (void)size;
(void) key; (void)key;
(void) length; (void)length;
(void) result; (void)result;
(void) result_length; (void)result_length;
return EET_ERROR_NOT_IMPLEMENTED; return EET_ERROR_NOT_IMPLEMENTED;
#endif #endif
} }
Eet_Error Eet_Error
eet_decipher(const void *data, unsigned int size, const char *key, unsigned int length, void **result, unsigned int *result_length) eet_decipher(const void *data,
unsigned int size,
const char *key,
unsigned int length,
void **result,
unsigned int *result_length)
{ {
#ifdef HAVE_CIPHER #ifdef HAVE_CIPHER
const unsigned int *over = data; const unsigned int *over = data;
@ -882,13 +1073,20 @@ eet_decipher(const void *data, unsigned int size, const char *key, unsigned int
int tmp = 0; int tmp = 0;
/* At least the salt and an AES block */ /* At least the salt and an AES block */
if (size < sizeof(unsigned int) + 16) return EET_ERROR_BAD_OBJECT; if (size < sizeof(unsigned int) + 16)
return EET_ERROR_BAD_OBJECT;
/* Get the salt */ /* Get the salt */
salt = *over; salt = *over;
/* Generate the iv and the key with the salt */ /* Generate the iv and the key with the salt */
eet_pbkdf2_sha1(key, length, (unsigned char *)&salt, sizeof(unsigned int), 2048, key_material, MAX_KEY_LEN + MAX_IV_LEN); eet_pbkdf2_sha1(key,
length,
(unsigned char *)&salt,
sizeof(unsigned int),
2048,
key_material,
MAX_KEY_LEN + MAX_IV_LEN);
memcpy(iv, key_material, MAX_IV_LEN); memcpy(iv, key_material, MAX_IV_LEN);
memcpy(ik, key_material + MAX_IV_LEN, MAX_KEY_LEN); memcpy(ik, key_material + MAX_IV_LEN, MAX_KEY_LEN);
@ -898,10 +1096,12 @@ eet_decipher(const void *data, unsigned int size, const char *key, unsigned int
/* Align to AES block size if size is not align */ /* Align to AES block size if size is not align */
tmp_len = size - sizeof (unsigned int); tmp_len = size - sizeof (unsigned int);
if ((tmp_len & 0x1F) != 0) goto on_error; if ((tmp_len & 0x1F) != 0)
goto on_error;
ret = malloc(tmp_len); ret = malloc(tmp_len);
if (!ret) goto on_error; if (!ret)
goto on_error;
# ifdef HAVE_GNUTLS # ifdef HAVE_GNUTLS
gcry_error_t err = 0; gcry_error_t err = 0;
@ -909,18 +1109,28 @@ eet_decipher(const void *data, unsigned int size, const char *key, unsigned int
/* Gcrypt create the corresponding cipher */ /* Gcrypt create the corresponding cipher */
err = gcry_cipher_open(&cipher, GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CBC, 0); err = gcry_cipher_open(&cipher, GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CBC, 0);
if (err) return EET_ERROR_DECRYPT_FAILED; if (err)
return EET_ERROR_DECRYPT_FAILED;
err = gcry_cipher_setiv(cipher, iv, MAX_IV_LEN); err = gcry_cipher_setiv(cipher, iv, MAX_IV_LEN);
if (err) goto on_error; if (err)
goto on_error;
err = gcry_cipher_setkey(cipher, ik, MAX_KEY_LEN); err = gcry_cipher_setkey(cipher, ik, MAX_KEY_LEN);
if (err) goto on_error; if (err)
goto on_error;
memset(iv, 0, sizeof (iv)); memset(iv, 0, sizeof (iv));
memset(ik, 0, sizeof (ik)); memset(ik, 0, sizeof (ik));
/* Gcrypt decrypt */ /* Gcrypt decrypt */
err = gcry_cipher_decrypt(cipher, ret, tmp_len, ((unsigned int *)data) + 1, tmp_len); err = gcry_cipher_decrypt(cipher,
if (err) goto on_error; ret,
tmp_len,
((unsigned int *)data) + 1,
tmp_len);
if (err)
goto on_error;
/* Gcrypt close the cipher */ /* Gcrypt close the cipher */
gcry_cipher_close(cipher); gcry_cipher_close(cipher);
@ -940,8 +1150,8 @@ eet_decipher(const void *data, unsigned int size, const char *key, unsigned int
memset(ik, 0, sizeof (ik)); memset(ik, 0, sizeof (ik));
/* Openssl decrypt */ /* Openssl decrypt */
if (!EVP_DecryptUpdate(&ctx, (unsigned char *) ret, &tmp, if (!EVP_DecryptUpdate(&ctx, (unsigned char *)ret, &tmp,
(unsigned char *) (over + 1), tmp_len)) (unsigned char *)(over + 1), tmp_len))
goto on_error; goto on_error;
/* Openssl close the cipher*/ /* Openssl close the cipher*/
@ -950,42 +1160,54 @@ eet_decipher(const void *data, unsigned int size, const char *key, unsigned int
/* Get the decrypted data size */ /* Get the decrypted data size */
tmp = *ret; tmp = *ret;
tmp = ntohl(tmp); tmp = ntohl(tmp);
if (tmp > tmp_len) goto on_error; if (tmp > tmp_len)
goto on_error;
/* Update the return values */ /* Update the return values */
if (result_length) *result_length = tmp; if (result_length)
*result_length = tmp;
if (result) if (result)
{ {
*result = NULL; *result = NULL;
*result = malloc(tmp); *result = malloc(tmp);
if (!*result) if (!*result)
goto on_error; goto on_error;
memcpy(*result, ret + 1, tmp); memcpy(*result, ret + 1, tmp);
} }
free(ret); free(ret);
return EET_ERROR_NONE; return EET_ERROR_NONE;
on_error: on_error:
memset(iv, 0, sizeof (iv)); memset(iv, 0, sizeof (iv));
memset(ik, 0, sizeof (ik)); memset(ik, 0, sizeof (ik));
# ifdef HAVE_GNUTLS # ifdef HAVE_GNUTLS
# else # else
if (opened) EVP_CIPHER_CTX_cleanup(&ctx); if (opened)
EVP_CIPHER_CTX_cleanup(&ctx);
# endif # endif
if (result) *result = NULL; if (result)
if (result_length) *result_length = 0; *result = NULL;
if (ret) free(ret);
if (result_length)
*result_length = 0;
if (ret)
free(ret);
return EET_ERROR_DECRYPT_FAILED; return EET_ERROR_DECRYPT_FAILED;
#else #else
(void) data; (void)data;
(void) size; (void)size;
(void) key; (void)key;
(void) length; (void)length;
(void) result; (void)result;
(void) result_length; (void)result_length;
return EET_ERROR_NOT_IMPLEMENTED; return EET_ERROR_NOT_IMPLEMENTED;
#endif #endif
} }
@ -1053,12 +1275,15 @@ eet_pbkdf2_sha1(const char *key,
# endif # endif
buf = alloca(salt_len + 4); buf = alloca(salt_len + 4);
if (!buf) return 1; if (!buf)
return 1;
for (i = 1; len; len -= tmp_len, p += tmp_len, i++) for (i = 1; len; len -= tmp_len, p += tmp_len, i++)
{ {
if (len > digest_len) tmp_len = digest_len; if (len > digest_len)
else tmp_len = len; tmp_len = digest_len;
else
tmp_len = len;
tab[0] = (unsigned char)(i & 0xff000000) >> 24; tab[0] = (unsigned char)(i & 0xff000000) >> 24;
tab[1] = (unsigned char)(i & 0x00ff0000) >> 16; tab[1] = (unsigned char)(i & 0x00ff0000) >> 16;

View File

@ -42,7 +42,8 @@ void *alloca (size_t);
#define MAGIC_EET_DATA_PACKET 0x4270ACE1 #define MAGIC_EET_DATA_PACKET 0x4270ACE1
typedef struct _Eet_Message Eet_Message; typedef struct _Eet_Message Eet_Message;
struct _Eet_Message { struct _Eet_Message
{
int magic; int magic;
int size; int size;
}; };
@ -76,7 +77,7 @@ eet_connection_new(Eet_Read_Cb *eet_read_cb,
conn->eet_read_cb = eet_read_cb; conn->eet_read_cb = eet_read_cb;
conn->eet_write_cb = eet_write_cb; conn->eet_write_cb = eet_write_cb;
conn->user_data = (void*) user_data; conn->user_data = (void *)user_data;
return conn; return conn;
} }
@ -108,15 +109,15 @@ eet_connection_received(Eet_Connection *conn, const void *data, size_t size)
if (packet_size > 64 * 1024) if (packet_size > 64 * 1024)
break; break;
data = (void*) (msg + 1); data = (void *)(msg + 1);
size -= sizeof (msg); size -= sizeof (msg);
if ((size_t) packet_size <= size) if ((size_t)packet_size <= size)
{ {
/* Not a partial receive, go the quick way. */ /* Not a partial receive, go the quick way. */
if (!conn->eet_read_cb(data, packet_size, conn->user_data)) if (!conn->eet_read_cb(data, packet_size, conn->user_data))
break; break;
data = (void*) ((char *) data + packet_size); data = (void *)((char *)data + packet_size);
size -= packet_size; size -= packet_size;
conn->received = 0; conn->received = 0;
@ -138,11 +139,13 @@ eet_connection_received(Eet_Connection *conn, const void *data, size_t size)
} }
/* Partial receive */ /* Partial receive */
copy_size = (conn->size - conn->received >= size) ? size : conn->size - conn->received; copy_size =
memcpy((char*) conn->buffer + conn->received, data, copy_size); (conn->size - conn->received >=
size) ? size : conn->size - conn->received;
memcpy((char *)conn->buffer + conn->received, data, copy_size);
conn->received += copy_size; conn->received += copy_size;
data = (void*)((char *) data + copy_size); data = (void *)((char *)data + copy_size);
size -= copy_size; size -= copy_size;
if (conn->received == conn->size) if (conn->received == conn->size)
@ -181,18 +184,26 @@ _eet_connection_raw_send(Eet_Connection *conn, void *data, int data_size)
memcpy(message + 1, data, data_size); memcpy(message + 1, data, data_size);
conn->eet_write_cb(message, data_size + sizeof (Eet_Message), conn->user_data); conn->eet_write_cb(message,
data_size + sizeof (Eet_Message),
conn->user_data);
return EINA_TRUE; return EINA_TRUE;
} }
EAPI Eina_Bool EAPI Eina_Bool
eet_connection_send(Eet_Connection *conn, Eet_Data_Descriptor *edd, const void *data_in, const char *cipher_key) eet_connection_send(Eet_Connection *conn,
Eet_Data_Descriptor *edd,
const void *data_in,
const char *cipher_key)
{ {
void *flat_data; void *flat_data;
int data_size; int data_size;
Eina_Bool ret = EINA_FALSE; Eina_Bool ret = EINA_FALSE;
flat_data = eet_data_descriptor_encode_cipher(edd, data_in, cipher_key, &data_size); flat_data = eet_data_descriptor_encode_cipher(edd,
data_in,
cipher_key,
&data_size);
if (!flat_data) if (!flat_data)
return EINA_FALSE; return EINA_FALSE;
@ -204,7 +215,9 @@ eet_connection_send(Eet_Connection *conn, Eet_Data_Descriptor *edd, const void *
} }
EAPI Eina_Bool EAPI Eina_Bool
eet_connection_node_send(Eet_Connection *conn, Eet_Node *node, const char *cipher_key) eet_connection_node_send(Eet_Connection *conn,
Eet_Node *node,
const char *cipher_key)
{ {
void *data; void *data;
int data_size; int data_size;

File diff suppressed because it is too large Load Diff

View File

@ -39,7 +39,10 @@ eet_dictionary_free(Eet_Dictionary *ed)
for (i = 0; i < ed->count; ++i) for (i = 0; i < ed->count; ++i)
if (ed->all[i].str) if (ed->all[i].str)
free(ed->all[i].str); free(ed->all[i].str);
if (ed->all) free(ed->all);
if (ed->all)
free(ed->all);
free(ed); free(ed);
} }
} }
@ -55,15 +58,12 @@ _eet_dictionary_lookup(Eet_Dictionary *ed, const char *string, int hash)
while (current != -1) while (current != -1)
{ {
if (ed->all[current].str) if (ed->all[current].str)
{
if (strcmp(ed->all[current].str, string) >= 0) if (strcmp(ed->all[current].str, string) >= 0)
break ; break;
}
if (ed->all[current].mmap) if (ed->all[current].mmap)
{
if (strcmp(ed->all[current].mmap, string) >= 0) if (strcmp(ed->all[current].mmap, string) >= 0)
break ; break;
}
prev = current; prev = current;
current = ed->all[current].next; current = ed->all[current].next;
@ -94,15 +94,13 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
if (idx != -1) if (idx != -1)
{ {
if (ed->all[idx].str) if (ed->all[idx].str)
{
if (strcmp(ed->all[idx].str, string) == 0) if (strcmp(ed->all[idx].str, string) == 0)
return idx; return idx;
}
if (ed->all[idx].mmap) if (ed->all[idx].mmap)
{
if (strcmp(ed->all[idx].mmap, string) == 0) if (strcmp(ed->all[idx].mmap, string) == 0)
return idx; return idx;
}
} }
if (ed->total == ed->count) if (ed->total == ed->count)
@ -148,6 +146,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
if (current->next != -1) if (current->next != -1)
ed->all[current->next].prev = ed->count; ed->all[current->next].prev = ed->count;
if (current->prev != -1) if (current->prev != -1)
ed->all[current->prev].next = ed->count; ed->all[current->prev].next = ed->count;
else else
@ -160,28 +159,42 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
int int
eet_dictionary_string_get_size(const Eet_Dictionary *ed, int idx) eet_dictionary_string_get_size(const Eet_Dictionary *ed, int idx)
{ {
if (!ed) return 0; if (!ed)
if (idx < 0) return 0; return 0;
if (idx < 0)
return 0;
if (idx < ed->count) if (idx < ed->count)
return ed->all[idx].len; return ed->all[idx].len;
return 0; return 0;
} }
int int
eet_dictionary_string_get_hash(const Eet_Dictionary *ed, int idx) eet_dictionary_string_get_hash(const Eet_Dictionary *ed, int idx)
{ {
if (!ed) return -1; if (!ed)
if (idx < 0) return -1; return -1;
if (idx < 0)
return -1;
if (idx < ed->count) if (idx < ed->count)
return ed->all[idx].hash; return ed->all[idx].hash;
return -1; return -1;
} }
const char * const char *
eet_dictionary_string_get_char(const Eet_Dictionary *ed, int idx) eet_dictionary_string_get_char(const Eet_Dictionary *ed, int idx)
{ {
if (!ed) return NULL; if (!ed)
if (idx < 0) return NULL; return NULL;
if (idx < 0)
return NULL;
if (idx < ed->count) if (idx < ed->count)
{ {
#ifdef _WIN32 #ifdef _WIN32
@ -191,17 +204,23 @@ eet_dictionary_string_get_char(const Eet_Dictionary *ed, int idx)
ed->all[idx].str = strdup(ed->all[idx].mmap); ed->all[idx].str = strdup(ed->all[idx].mmap);
ed->all[idx].mmap = NULL; ed->all[idx].mmap = NULL;
} }
#else #else
if (ed->all[idx].mmap) if (ed->all[idx].mmap)
return ed->all[idx].mmap; return ed->all[idx].mmap;
#endif #endif
return ed->all[idx].str; return ed->all[idx].str;
} }
return NULL; return NULL;
} }
static inline Eina_Bool static inline Eina_Bool
_eet_dictionary_string_get_me_cache(const char *s, int len, int *mantisse, int *exponent) _eet_dictionary_string_get_me_cache(const char *s,
int len,
int *mantisse,
int *exponent)
{ {
if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p')) if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
{ {
@ -210,6 +229,7 @@ _eet_dictionary_string_get_me_cache(const char *s, int len, int *mantisse, int *
return EINA_TRUE; return EINA_TRUE;
} }
return EINA_FALSE; return EINA_FALSE;
} }
@ -221,11 +241,14 @@ _eet_dictionary_string_get_float_cache(const char *s, int len, float *result)
if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent)) if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
{ {
if (s[4] == '+') *result = (float) (mantisse << exponent); if (s[4] == '+')
else *result = (float) mantisse / (float) (1 << exponent); *result = (float)(mantisse << exponent);
else
*result = (float)mantisse / (float)(1 << exponent);
return EINA_TRUE; return EINA_TRUE;
} }
return EINA_FALSE; return EINA_FALSE;
} }
@ -237,28 +260,42 @@ _eet_dictionary_string_get_double_cache(const char *s, int len, double *result)
if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent)) if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
{ {
if (s[4] == '+') *result = (double) (mantisse << exponent); if (s[4] == '+')
else *result = (double) mantisse / (float) (1 << exponent); *result = (double)(mantisse << exponent);
else
*result = (double)mantisse / (float)(1 << exponent);
return EINA_TRUE; return EINA_TRUE;
} }
return EINA_FALSE; return EINA_FALSE;
} }
static inline Eina_Bool static inline Eina_Bool
_eet_dictionary_test(const Eet_Dictionary *ed, int idx, void *result) _eet_dictionary_test(const Eet_Dictionary *ed, int idx, void *result)
{ {
if (!result) return EINA_FALSE; if (!result)
if (!ed) return EINA_FALSE; return EINA_FALSE;
if (idx < 0) return EINA_FALSE;
if (!(idx < ed->count)) return EINA_FALSE; if (!ed)
return EINA_FALSE;
if (idx < 0)
return EINA_FALSE;
if (!(idx < ed->count))
return EINA_FALSE;
return EINA_TRUE; return EINA_TRUE;
} }
Eina_Bool Eina_Bool
eet_dictionary_string_get_float(const Eet_Dictionary *ed, int idx, float *result) eet_dictionary_string_get_float(const Eet_Dictionary *ed,
int idx,
float *result)
{ {
if (!_eet_dictionary_test(ed, idx, result)) return EINA_FALSE; if (!_eet_dictionary_test(ed, idx, result))
return EINA_FALSE;
if (!(ed->all[idx].type & EET_D_FLOAT)) if (!(ed->all[idx].type & EET_D_FLOAT))
{ {
@ -266,15 +303,17 @@ eet_dictionary_string_get_float(const Eet_Dictionary *ed, int idx, float *result
str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap; str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len, &ed->all[idx].f)) if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len,
&ed->all[idx].f))
{ {
long long mantisse = 0; long long mantisse = 0;
long exponent = 0; long exponent = 0;
if (eina_convert_atod(str, ed->all[idx].len, &mantisse, &exponent) == EINA_FALSE) if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
&exponent) == EINA_FALSE)
return EINA_FALSE; return EINA_FALSE;
ed->all[idx].f = ldexpf((float) mantisse, exponent); ed->all[idx].f = ldexpf((float)mantisse, exponent);
} }
ed->all[idx].type |= EET_D_FLOAT; ed->all[idx].type |= EET_D_FLOAT;
@ -285,9 +324,12 @@ eet_dictionary_string_get_float(const Eet_Dictionary *ed, int idx, float *result
} }
Eina_Bool Eina_Bool
eet_dictionary_string_get_double(const Eet_Dictionary *ed, int idx, double *result) eet_dictionary_string_get_double(const Eet_Dictionary *ed,
int idx,
double *result)
{ {
if (!_eet_dictionary_test(ed, idx, result)) return EINA_FALSE; if (!_eet_dictionary_test(ed, idx, result))
return EINA_FALSE;
if (!(ed->all[idx].type & EET_D_DOUBLE)) if (!(ed->all[idx].type & EET_D_DOUBLE))
{ {
@ -295,15 +337,17 @@ eet_dictionary_string_get_double(const Eet_Dictionary *ed, int idx, double *resu
str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap; str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len, &ed->all[idx].d)) if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len,
&ed->all[idx].d))
{ {
long long mantisse = 0; long long mantisse = 0;
long exponent = 0; long exponent = 0;
if (eina_convert_atod(str, ed->all[idx].len, &mantisse, &exponent) == EINA_FALSE) if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
&exponent) == EINA_FALSE)
return EINA_FALSE; return EINA_FALSE;
ed->all[idx].d = ldexp((double) mantisse, exponent); ed->all[idx].d = ldexp((double)mantisse, exponent);
} }
ed->all[idx].type |= EET_D_DOUBLE; ed->all[idx].type |= EET_D_DOUBLE;
@ -314,9 +358,12 @@ eet_dictionary_string_get_double(const Eet_Dictionary *ed, int idx, double *resu
} }
Eina_Bool Eina_Bool
eet_dictionary_string_get_fp(const Eet_Dictionary *ed, int idx, Eina_F32p32 *result) eet_dictionary_string_get_fp(const Eet_Dictionary *ed,
int idx,
Eina_F32p32 *result)
{ {
if (!_eet_dictionary_test(ed, idx, result)) return EINA_FALSE; if (!_eet_dictionary_test(ed, idx, result))
return EINA_FALSE;
if (!(ed->all[idx].type & EET_D_FIXED_POINT)) if (!(ed->all[idx].type & EET_D_FIXED_POINT))
{ {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -45,7 +45,8 @@ _eet_node_new(const char *name, int type)
Eet_Node *n; Eet_Node *n;
n = eet_node_new(); n = eet_node_new();
if (!n) return NULL; if (!n)
return NULL;
n->type = type; n->type = type;
n->name = eina_stringshare_add(name); n->name = eina_stringshare_add(name);
@ -68,12 +69,12 @@ _eet_node_append(Eet_Node *n, Eina_List *nodes)
#define EET_NODE_NEW(Eet_type, Name, Value, Type) \ #define EET_NODE_NEW(Eet_type, Name, Value, Type) \
EAPI Eet_Node * \ EAPI Eet_Node * \
eet_node_##Name##_new(const char *name, Type Value) \ eet_node_ ## Name ## _new(const char *name, Type Value) \
{ \ { \
Eet_Node *n; \ Eet_Node *n; \
\ \
n = _eet_node_new(name, Eet_type); \ n = _eet_node_new(name, Eet_type); \
if (!n) return NULL; \ if (!n) { return NULL; } \
\ \
n->data.value.Value = Value; \ n->data.value.Value = Value; \
\ \
@ -82,12 +83,12 @@ _eet_node_append(Eet_Node *n, Eina_List *nodes)
#define EET_NODE_STR_NEW(Eet_type, Name, Value, Type) \ #define EET_NODE_STR_NEW(Eet_type, Name, Value, Type) \
EAPI Eet_Node * \ EAPI Eet_Node * \
eet_node_##Name##_new(const char *name, Type Value) \ eet_node_ ## Name ## _new(const char *name, Type Value) \
{ \ { \
Eet_Node *n; \ Eet_Node *n; \
\ \
n = _eet_node_new(name, Eet_type); \ n = _eet_node_new(name, Eet_type); \
if (!n) return NULL; \ if (!n) { return NULL; } \
\ \
n->data.value.Value = eina_stringshare_add(Value); \ n->data.value.Value = eina_stringshare_add(Value); \
\ \
@ -113,7 +114,8 @@ eet_node_null_new(const char *name)
Eet_Node *n; Eet_Node *n;
n = _eet_node_new(name, EET_T_NULL); n = _eet_node_new(name, EET_T_NULL);
if (!n) return NULL; if (!n)
return NULL;
n->data.value.str = NULL; n->data.value.str = NULL;
@ -126,7 +128,8 @@ eet_node_list_new(const char *name, Eina_List *nodes)
Eet_Node *n; Eet_Node *n;
n = _eet_node_new(name, EET_G_LIST); n = _eet_node_new(name, EET_G_LIST);
if (!n) return NULL; if (!n)
return NULL;
_eet_node_append(n, nodes); _eet_node_append(n, nodes);
@ -139,7 +142,8 @@ eet_node_array_new(const char *name, int count, Eina_List *nodes)
Eet_Node *n; Eet_Node *n;
n = _eet_node_new(name, EET_G_ARRAY); n = _eet_node_new(name, EET_G_ARRAY);
if (!n) return NULL; if (!n)
return NULL;
n->count = count; n->count = count;
@ -154,7 +158,8 @@ eet_node_var_array_new(const char *name, Eina_List *nodes)
Eet_Node *n; Eet_Node *n;
n = _eet_node_new(name, EET_G_VAR_ARRAY); n = _eet_node_new(name, EET_G_VAR_ARRAY);
if (!n) return NULL; if (!n)
return NULL;
n->count = eina_list_count(nodes); n->count = eina_list_count(nodes);
@ -169,10 +174,12 @@ eet_node_hash_new(const char *name, const char *key, Eet_Node *node)
Eina_List *nodes; Eina_List *nodes;
Eet_Node *n; Eet_Node *n;
if (!node) return NULL; if (!node)
return NULL;
n = _eet_node_new(name, EET_G_HASH); n = _eet_node_new(name, EET_G_HASH);
if (!n) return NULL; if (!n)
return NULL;
n->key = eina_stringshare_add(key); n->key = eina_stringshare_add(key);
nodes = eina_list_append(NULL, node); nodes = eina_list_append(NULL, node);
@ -188,7 +195,8 @@ eet_node_struct_new(const char *name, Eina_List *nodes)
Eet_Node *n; Eet_Node *n;
n = _eet_node_new(name, EET_G_UNKNOWN); n = _eet_node_new(name, EET_G_UNKNOWN);
if (!n) return NULL; if (!n)
return NULL;
_eet_node_append(n, nodes); _eet_node_append(n, nodes);
@ -204,7 +212,8 @@ eet_node_struct_child_new(const char *parent, Eet_Node *child)
return child; return child;
n = _eet_node_new(parent, EET_G_UNKNOWN); n = _eet_node_new(parent, EET_G_UNKNOWN);
if (!n) return NULL; if (!n)
return NULL;
_eet_node_append(n, eina_list_prepend(NULL, child)); _eet_node_append(n, eina_list_prepend(NULL, child));
@ -224,18 +233,20 @@ eet_node_list_append(Eet_Node *parent, const char *name, Eet_Node *child)
{ {
Eet_Node *n; Eet_Node *n;
if (!nn->values) nn->values = child; if (!nn->values)
nn->values = child;
else else
{ {
for (n = nn->values; n->next; n = n->next) for (n = nn->values; n->next; n = n->next)
; ;
n->next = child; n->next = child;
} }
child->next = NULL; child->next = NULL;
eina_stringshare_del(tmp); eina_stringshare_del(tmp);
return ; return;
} }
/* No list found, so create it. */ /* No list found, so create it. */
@ -257,9 +268,11 @@ eet_node_struct_append(Eet_Node *parent, const char *name, Eet_Node *child)
if (parent->type != EET_G_UNKNOWN) if (parent->type != EET_G_UNKNOWN)
{ {
ERR("[%s] is not a structure. Will not insert [%s] in it", parent->name, name); ERR("[%s] is not a structure. Will not insert [%s] in it",
parent->name,
name);
eet_node_del(child); eet_node_del(child);
return ; return;
} }
tmp = eina_stringshare_add(name); tmp = eina_stringshare_add(name);
@ -267,8 +280,10 @@ eet_node_struct_append(Eet_Node *parent, const char *name, Eet_Node *child)
for (prev = NULL, nn = parent->values; nn; prev = nn, nn = nn->next) for (prev = NULL, nn = parent->values; nn; prev = nn, nn = nn->next)
if (nn->name == tmp && nn->type == child->type) if (nn->name == tmp && nn->type == child->type)
{ {
if (prev) prev->next = nn->next; if (prev)
else parent->values = nn->next; prev->next = nn->next;
else
parent->values = nn->next;
nn->next = NULL; nn->next = NULL;
eet_node_del(nn); eet_node_del(nn);
@ -291,7 +306,10 @@ eet_node_struct_append(Eet_Node *parent, const char *name, Eet_Node *child)
} }
void void
eet_node_hash_add(Eet_Node *parent, const char *name, const char *key, Eet_Node *child) eet_node_hash_add(Eet_Node *parent,
const char *name,
const char *key,
Eet_Node *child)
{ {
Eet_Node *nn; Eet_Node *nn;
@ -309,12 +327,14 @@ eet_node_del(Eet_Node *n)
Eet_Node *nn; Eet_Node *nn;
Eet_Node *tmp; Eet_Node *tmp;
if (!n) return ; if (!n)
return;
switch (n->type) switch (n->type)
{ {
case EET_G_HASH: case EET_G_HASH:
eina_stringshare_del(n->key); eina_stringshare_del(n->key);
case EET_G_UNKNOWN: case EET_G_UNKNOWN:
case EET_G_VAR_ARRAY: case EET_G_VAR_ARRAY:
case EET_G_ARRAY: case EET_G_ARRAY:
@ -326,10 +346,12 @@ eet_node_del(Eet_Node *n)
eet_node_del(tmp); eet_node_del(tmp);
} }
break; break;
case EET_T_STRING: case EET_T_STRING:
case EET_T_INLINED_STRING: case EET_T_INLINED_STRING:
eina_stringshare_del(n->data.value.str); eina_stringshare_del(n->data.value.str);
break; break;
case EET_T_CHAR: case EET_T_CHAR:
case EET_T_SHORT: case EET_T_SHORT:
case EET_T_INT: case EET_T_INT:
@ -371,7 +393,9 @@ static const char *eet_node_dump_t_name[14][2] = {
}; };
static void static void
eet_node_dump_level(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata) eet_node_dump_level(int level, void (*dumpfunc)(void *data,
const char *str),
void *dumpdata)
{ {
int i; int i;
@ -387,13 +411,19 @@ eet_node_string_escape(const char *str)
for (strp = str; *strp; strp++) for (strp = str; *strp; strp++)
{ {
if (*strp == '\"') sz += 2; if (*strp == '\"')
else if (*strp == '\\') sz += 2; sz += 2;
else if (*strp == '\n') sz += 2; else if (*strp == '\\')
else sz += 1; sz += 2;
else if (*strp == '\n')
sz += 2;
else
sz += 1;
} }
s = malloc(sz + 1); s = malloc(sz + 1);
if (!s) return NULL; if (!s)
return NULL;
for (strp = str, sp = s; *strp; strp++, sp++) for (strp = str, sp = s; *strp; strp++, sp++)
{ {
if (*strp == '\"' if (*strp == '\"'
@ -403,20 +433,26 @@ eet_node_string_escape(const char *str)
*sp = '\\'; *sp = '\\';
sp++; sp++;
} }
if (*strp == '\n') *sp = 'n';
else *sp = *strp; if (*strp == '\n')
*sp = 'n';
else
*sp = *strp;
} }
*sp = 0; *sp = 0;
return s; return s;
} }
static void static void
eet_node_dump_string_escape(void *dumpdata, void dumpfunc(void *data, const char *str), const char *str) eet_node_dump_string_escape(void *dumpdata, void dumpfunc(void *data,
const char *str),
const char *str)
{ {
char *s; char *s;
s = eet_node_string_escape(str); s = eet_node_string_escape(str);
if (!s) return ; if (!s)
return;
dumpfunc(dumpdata, s); dumpfunc(dumpdata, s);
free(s); free(s);
@ -424,7 +460,8 @@ eet_node_dump_string_escape(void *dumpdata, void dumpfunc(void *data, const char
static void static void
eet_node_dump_simple_type(Eet_Node *n, int level, eet_node_dump_simple_type(Eet_Node *n, int level,
void (*dumpfunc) (void *data, const char *str), void *dumpdata) void (*dumpfunc)(void *data,
const char *str), void *dumpdata)
{ {
const char *type_name = NULL; const char *type_name = NULL;
char tbuf[256]; char tbuf[256];
@ -442,7 +479,10 @@ eet_node_dump_simple_type(Eet_Node *n, int level,
case Eet_Type: \ case Eet_Type: \
{ \ { \
dumpfunc(dumpdata, eet_node_dump_t_name[Eet_Type][0]); \ dumpfunc(dumpdata, eet_node_dump_t_name[Eet_Type][0]); \
snprintf(tbuf, sizeof (tbuf), eet_node_dump_t_name[Eet_Type][1], n->data.value.Type); \ snprintf(tbuf, \
sizeof (tbuf), \
eet_node_dump_t_name[Eet_Type][1], \
n->data.value.Type); \
dumpfunc(dumpdata, tbuf); \ dumpfunc(dumpdata, tbuf); \
break; \ break; \
} }
@ -459,18 +499,23 @@ eet_node_dump_simple_type(Eet_Node *n, int level,
EET_T_TYPE(EET_T_USHORT, us); EET_T_TYPE(EET_T_USHORT, us);
EET_T_TYPE(EET_T_UINT, ui); EET_T_TYPE(EET_T_UINT, ui);
EET_T_TYPE(EET_T_ULONG_LONG, ul); EET_T_TYPE(EET_T_ULONG_LONG, ul);
case EET_T_INLINED_STRING: case EET_T_INLINED_STRING:
type_name = "inlined: \""; type_name = "inlined: \"";
case EET_T_STRING: case EET_T_STRING:
if (!type_name) type_name = "string: \""; if (!type_name)
type_name = "string: \"";
dumpfunc(dumpdata, type_name); dumpfunc(dumpdata, type_name);
eet_node_dump_string_escape(dumpdata, dumpfunc, n->data.value.str); eet_node_dump_string_escape(dumpdata, dumpfunc, n->data.value.str);
dumpfunc(dumpdata, "\""); dumpfunc(dumpdata, "\"");
break; break;
case EET_T_NULL: case EET_T_NULL:
dumpfunc(dumpdata, "null"); dumpfunc(dumpdata, "null");
break; break;
default: default:
dumpfunc(dumpdata, "???: ???"); dumpfunc(dumpdata, "???: ???");
break; break;
@ -480,7 +525,9 @@ eet_node_dump_simple_type(Eet_Node *n, int level,
} }
static void static void
eet_node_dump_group_start(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata, eet_node_dump_group_start(int level, void (*dumpfunc)(void *data,
const char *str),
void *dumpdata,
int group_type, const char *name) int group_type, const char *name)
{ {
int chnk_type; int chnk_type;
@ -498,18 +545,23 @@ eet_node_dump_group_start(int level, void (*dumpfunc) (void *data, const char *s
} }
static void static void
eet_node_dump_group_end(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata) eet_node_dump_group_end(int level, void (*dumpfunc)(void *data,
const char *str),
void *dumpdata)
{ {
eet_node_dump_level(level, dumpfunc, dumpdata); eet_node_dump_level(level, dumpfunc, dumpdata);
dumpfunc(dumpdata, "}\n"); dumpfunc(dumpdata, "}\n");
} }
void void
eet_node_dump(Eet_Node *n, int dumplevel, void (*dumpfunc) (void *data, const char *str), void *dumpdata) eet_node_dump(Eet_Node *n, int dumplevel, void (*dumpfunc)(void *data,
const char *str),
void *dumpdata)
{ {
Eet_Node *it; Eet_Node *it;
if (!n) return ; if (!n)
return;
switch (n->type) switch (n->type)
{ {
@ -518,7 +570,11 @@ eet_node_dump(Eet_Node *n, int dumplevel, void (*dumpfunc) (void *data, const ch
case EET_G_UNKNOWN: case EET_G_UNKNOWN:
case EET_G_HASH: case EET_G_HASH:
case EET_G_LIST: case EET_G_LIST:
eet_node_dump_group_start(dumplevel, dumpfunc, dumpdata, n->type, n->name); eet_node_dump_group_start(dumplevel,
dumpfunc,
dumpdata,
n->type,
n->name);
if (n->type == EET_G_VAR_ARRAY if (n->type == EET_G_VAR_ARRAY
|| n->type == EET_G_ARRAY) || n->type == EET_G_ARRAY)
@ -544,6 +600,7 @@ eet_node_dump(Eet_Node *n, int dumplevel, void (*dumpfunc) (void *data, const ch
eet_node_dump_group_end(dumplevel, dumpfunc, dumpdata); eet_node_dump_group_end(dumplevel, dumpfunc, dumpdata);
break; break;
case EET_T_STRING: case EET_T_STRING:
case EET_T_INLINED_STRING: case EET_T_INLINED_STRING:
case EET_T_CHAR: case EET_T_CHAR:
@ -561,8 +618,12 @@ eet_node_dump(Eet_Node *n, int dumplevel, void (*dumpfunc) (void *data, const ch
} }
} }
void* void *
eet_node_walk(void *parent, const char *name, Eet_Node *root, Eet_Node_Walk *cb, void *user_data) eet_node_walk(void *parent,
const char *name,
Eet_Node *root,
Eet_Node_Walk *cb,
void *user_data)
{ {
Eet_Node *it; Eet_Node *it;
void *me = NULL; void *me = NULL;
@ -570,7 +631,9 @@ eet_node_walk(void *parent, const char *name, Eet_Node *root, Eet_Node_Walk *cb,
if (!root) if (!root)
{ {
if (parent) cb->struct_add(parent, name, NULL, user_data); if (parent)
cb->struct_add(parent, name, NULL, user_data);
return NULL; return NULL;
} }
@ -583,26 +646,44 @@ eet_node_walk(void *parent, const char *name, Eet_Node *root, Eet_Node_Walk *cb,
eet_node_walk(me, it->name, it, cb, user_data); eet_node_walk(me, it->name, it, cb, user_data);
break; break;
case EET_G_VAR_ARRAY: case EET_G_VAR_ARRAY:
case EET_G_ARRAY: case EET_G_ARRAY:
me = cb->array(root->type == EET_G_VAR_ARRAY ? EINA_TRUE : EINA_FALSE, me = cb->array(root->type == EET_G_VAR_ARRAY ? EINA_TRUE : EINA_FALSE,
root->name, root->count, user_data); root->name, root->count, user_data);
for (i = 0, it = root->values; it != NULL; it = it->next) for (i = 0, it = root->values; it != NULL; it = it->next)
cb->insert(me, i++, eet_node_walk(NULL, NULL, it, cb, user_data), user_data); cb->insert(me, i++, eet_node_walk(NULL,
NULL,
it,
cb,
user_data), user_data);
break; break;
case EET_G_LIST: case EET_G_LIST:
me = cb->list(root->name, user_data); me = cb->list(root->name, user_data);
for (it = root->values; it != NULL; it = it->next) for (it = root->values; it != NULL; it = it->next)
cb->append(me, eet_node_walk(NULL, NULL, it, cb, user_data), user_data); cb->append(me, eet_node_walk(NULL,
NULL,
it,
cb,
user_data), user_data);
break; break;
case EET_G_HASH:
if (!parent) return NULL;
return cb->hash(parent, root->name, root->key, eet_node_walk(NULL, NULL, root->values, cb, user_data), user_data); case EET_G_HASH:
if (!parent)
return NULL;
return cb->hash(parent, root->name, root->key,
eet_node_walk(NULL,
NULL,
root->values,
cb,
user_data), user_data);
case EET_T_STRING: case EET_T_STRING:
case EET_T_INLINED_STRING: case EET_T_INLINED_STRING:
case EET_T_CHAR: case EET_T_CHAR:
@ -619,7 +700,9 @@ eet_node_walk(void *parent, const char *name, Eet_Node *root, Eet_Node_Walk *cb,
break; break;
} }
if (parent) cb->struct_add(parent, name, me, user_data); if (parent)
cb->struct_add(parent, name, me, user_data);
return me; return me;
} }
@ -634,7 +717,8 @@ eet_node_init(void)
if (tmp && tmp[0]) if (tmp && tmp[0])
choice = tmp; choice = tmp;
_eet_node_mp = eina_mempool_add(choice, "eet-node-alloc", NULL, sizeof(Eet_Node), 1024); _eet_node_mp =
eina_mempool_add(choice, "eet-node-alloc", NULL, sizeof(Eet_Node), 1024);
return _eet_node_mp ? 1 : 0; return _eet_node_mp ? 1 : 0;
} }

View File

@ -21,7 +21,8 @@ _eet_hash_gen(const char *key, int hash_size)
unsigned char *ptr; unsigned char *ptr;
/* no string - index 0 */ /* no string - index 0 */
if (!key) return 0; if (!key)
return 0;
/* calc hash num */ /* calc hash num */
for (i = 0, ptr = (unsigned char *)key, value = (int)(*ptr); for (i = 0, ptr = (unsigned char *)key, value = (int)(*ptr);

View File

@ -5,31 +5,35 @@
#include "eet_suite.h" #include "eet_suite.h"
static char* static char *
_eet_str_direct_alloc(const char *str) _eet_str_direct_alloc(const char *str)
{ {
return (char*) str; return (char *)str;
} }
static void static void
_eet_str_direct_free(const char *str) _eet_str_direct_free(const char *str)
{ {
/* FIXME: Use attribute unused */ /* FIXME: Use attribute unused */
(void) str; (void)str;
} }
static void static void
_eet_eina_hash_foreach(void *hash, Eina_Hash_Foreach cb, void *fdata) _eet_eina_hash_foreach(void *hash, Eina_Hash_Foreach cb, void *fdata)
{ {
if (hash) eina_hash_foreach(hash, cb, fdata); if (hash)
eina_hash_foreach(hash, cb, fdata);
} }
/* Internal wrapper for eina_hash */ /* Internal wrapper for eina_hash */
static Eina_Hash* static Eina_Hash *
_eet_eina_hash_add(Eina_Hash *hash, const char *key, const void *data) _eet_eina_hash_add(Eina_Hash *hash, const char *key, const void *data)
{ {
if (!hash) hash = eina_hash_string_superfast_new(NULL); if (!hash)
if (!hash) return NULL; hash = eina_hash_string_superfast_new(NULL);
if (!hash)
return NULL;
eina_hash_add(hash, key, data); eina_hash_add(hash, key, data);
return hash; return hash;
@ -38,7 +42,8 @@ _eet_eina_hash_add(Eina_Hash *hash, const char *key, const void *data)
static void static void
_eet_eina_hash_free(Eina_Hash *hash) _eet_eina_hash_free(Eina_Hash *hash)
{ {
if (hash) eina_hash_free(hash); if (hash)
eina_hash_free(hash);
} }
void void
@ -49,14 +54,14 @@ eet_test_setup_eddc(Eet_Data_Descriptor_Class *eddc)
eddc->func.mem_free = NULL; eddc->func.mem_free = NULL;
eddc->func.str_alloc = NULL; eddc->func.str_alloc = NULL;
eddc->func.str_free = NULL; eddc->func.str_free = NULL;
eddc->func.list_next = (void*) eina_list_next; eddc->func.list_next = (void *)eina_list_next;
eddc->func.list_append = (void*) eina_list_append; eddc->func.list_append = (void *)eina_list_append;
eddc->func.list_data = (void*) eina_list_data_get; eddc->func.list_data = (void *)eina_list_data_get;
eddc->func.list_free = (void*) eina_list_free; eddc->func.list_free = (void *)eina_list_free;
eddc->func.hash_foreach = (void*) _eet_eina_hash_foreach; eddc->func.hash_foreach = (void *)_eet_eina_hash_foreach;
eddc->func.hash_add = (void*) _eet_eina_hash_add; eddc->func.hash_add = (void *)_eet_eina_hash_add;
eddc->func.hash_free = (void*) _eet_eina_hash_free; eddc->func.hash_free = (void *)_eet_eina_hash_free;
eddc->func.str_direct_alloc = (void*) _eet_str_direct_alloc; eddc->func.str_direct_alloc = (void *)_eet_str_direct_alloc;
eddc->func.str_direct_free = (void*) _eet_str_direct_free; eddc->func.str_direct_free = (void *)_eet_str_direct_free;
} }

File diff suppressed because it is too large Load Diff