ran ecrustify on eet. this seems to do a good job of eet. comments?

SVN revision: 64237
This commit is contained in:
Carsten Haitzler 2011-10-21 05:40:01 +00:00
parent a331fe3bca
commit 8893a9ff35
21 changed files with 3908 additions and 3748 deletions

View File

@ -44,11 +44,11 @@ static int _eet_main_log_dom = -1;
#define CRIT(...) EINA_LOG_DOM_CRIT(_eet_main_log_dom, __VA_ARGS__) #define CRIT(...) EINA_LOG_DOM_CRIT(_eet_main_log_dom, __VA_ARGS__)
static void static void
do_eet_list(const char * file) do_eet_list(const char *file)
{ {
int i, num; int i, num;
char ** list; char **list;
Eet_File * ef; Eet_File *ef;
ef = eet_open(file, EET_FILE_MODE_READ); ef = eet_open(file, EET_FILE_MODE_READ);
if (!ef) if (!ef)
@ -61,7 +61,7 @@ do_eet_list(const char * file)
if (list) if (list)
{ {
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
printf("%s\n",list[i]); printf("%s\n", list[i]);
free(list); free(list);
} }
@ -69,15 +69,15 @@ do_eet_list(const char * file)
} /* do_eet_list */ } /* do_eet_list */
static void static void
do_eet_extract(const char * file, do_eet_extract(const char *file,
const char * key, const char *key,
const char * out, const char *out,
const char * crypto_key) const char *crypto_key)
{ {
Eet_File * ef; Eet_File *ef;
void * data; void *data;
int size = 0; int size = 0;
FILE * f; FILE *f;
ef = eet_open(file, EET_FILE_MODE_READ); ef = eet_open(file, EET_FILE_MODE_READ);
if (!ef) if (!ef)
@ -112,19 +112,20 @@ do_eet_extract(const char * file,
} /* do_eet_extract */ } /* do_eet_extract */
static void static void
do_eet_decode_dump(void * data, const char * str) do_eet_decode_dump(void *data,
const char *str)
{ {
fputs(str, (FILE *)data); fputs(str, (FILE *)data);
} /* do_eet_decode_dump */ } /* do_eet_decode_dump */
static void static void
do_eet_decode(const char * file, do_eet_decode(const char *file,
const char * key, const char *key,
const char * out, const char *out,
const char * crypto_key) const char *crypto_key)
{ {
Eet_File * ef; Eet_File *ef;
FILE * f; FILE *f;
ef = eet_open(file, EET_FILE_MODE_READ); ef = eet_open(file, EET_FILE_MODE_READ);
if (!ef) if (!ef)
@ -151,20 +152,20 @@ do_eet_decode(const char * file,
} /* do_eet_decode */ } /* do_eet_decode */
static void static void
do_eet_insert(const char * file, do_eet_insert(const char *file,
const char * key, const char *key,
const char * out, const char *out,
int compress, int compress,
const char * crypto_key) const char *crypto_key)
{ {
Eet_File * ef; Eet_File *ef;
void * data; void *data;
int size = 0; int size = 0;
FILE * f; FILE *f;
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)
{ {
@ -202,21 +203,21 @@ do_eet_insert(const char * file,
} /* do_eet_insert */ } /* do_eet_insert */
static void static void
do_eet_encode(const char * file, do_eet_encode(const char *file,
const char * key, const char *key,
const char * out, const char *out,
int compress, int compress,
const char * crypto_key) const char *crypto_key)
{ {
Eet_File * ef; Eet_File *ef;
char * text; char *text;
int textlen = 0; int textlen = 0;
int size = 0; int size = 0;
FILE * f; FILE *f;
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)
{ {
@ -259,9 +260,10 @@ do_eet_encode(const char * file,
} /* do_eet_encode */ } /* do_eet_encode */
static void static void
do_eet_remove(const char * file, const char * key) do_eet_remove(const char *file,
const char *key)
{ {
Eet_File * ef; Eet_File *ef;
ef = eet_open(file, EET_FILE_MODE_READ_WRITE); ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
if (!ef) if (!ef)
@ -275,10 +277,10 @@ do_eet_remove(const char * file, const char * key)
} /* do_eet_remove */ } /* do_eet_remove */
static void static void
do_eet_check(const char * file) do_eet_check(const char *file)
{ {
Eet_File * ef; Eet_File *ef;
const void * der; const void *der;
int der_length; int der_length;
int sign_length; int sign_length;
@ -301,10 +303,12 @@ do_eet_check(const char * file)
} /* do_eet_check */ } /* do_eet_check */
static void static void
do_eet_sign(const char * file, const char * private_key, const char * public_key) do_eet_sign(const char *file,
const char *private_key,
const char *public_key)
{ {
Eet_File * ef; Eet_File *ef;
Eet_Key * key; Eet_Key *key;
ef = eet_open(file, EET_FILE_MODE_READ_WRITE); ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
if (!ef) if (!ef)
@ -329,77 +333,78 @@ do_eet_sign(const char * file, const char * private_key, const char * public_key
} /* do_eet_sign */ } /* do_eet_sign */
int int
main(int argc, char ** argv) main(int argc,
char **argv)
{ {
if (!eet_init()) if (!eet_init())
return -1; return -1;
_eet_main_log_dom = eina_log_domain_register("eet_main", EINA_COLOR_CYAN); _eet_main_log_dom = eina_log_domain_register("eet_main", EINA_COLOR_CYAN);
if(_eet_main_log_dom < -1) if(_eet_main_log_dom < -1)
{ {
EINA_LOG_ERR("Impossible to create a log domain for eet_main."); EINA_LOG_ERR("Impossible to create a log domain for eet_main.");
eet_shutdown(); eet_shutdown();
return(-1); return -1;
} }
if (argc < 2) if (argc < 2)
{ {
help: help:
printf( printf(
"Usage:\n" "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"
" eet -i FILE.EET KEY IN-FILE COMPRESS [CRYPTO_KEY] insert data to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n" " eet -i FILE.EET KEY IN-FILE COMPRESS [CRYPTO_KEY] insert data to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n"
" eet -e FILE.EET KEY IN-FILE COMPRESS [CRYPTO_KEY] insert and encode to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n" " eet -e FILE.EET KEY IN-FILE COMPRESS [CRYPTO_KEY] insert and encode to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n"
" eet -r FILE.EET KEY remove KEY in FILE.EET\n" " eet -r FILE.EET KEY remove KEY in FILE.EET\n"
" eet -c FILE.EET report and check the signature information of an eet file\n" " eet -c FILE.EET report and check the signature information of an eet file\n"
" eet -s FILE.EET PRIVATE_KEY PUBLIC_KEY sign FILE.EET with PRIVATE_KEY and attach PUBLIC_KEY as it's certificate\n" " eet -s FILE.EET PRIVATE_KEY PUBLIC_KEY sign FILE.EET with PRIVATE_KEY and attach PUBLIC_KEY as it's certificate\n"
); );
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)
do_eet_extract(argv[2], argv[3], argv[4], argv[5]); do_eet_extract(argv[2], argv[3], argv[4], argv[5]);
else else
do_eet_extract(argv[2], argv[3], argv[4], NULL); do_eet_extract(argv[2], argv[3], argv[4], NULL);
} }
else if ((!strcmp(argv[1], "-d")) && (argc > 4)) else if ((!strcmp(argv[1], "-d")) && (argc > 4))
{ {
if (argc > 5) if (argc > 5)
do_eet_decode(argv[2], argv[3], argv[4], argv[5]); do_eet_decode(argv[2], argv[3], argv[4], argv[5]);
else else
do_eet_decode(argv[2], argv[3], argv[4], NULL); do_eet_decode(argv[2], argv[3], argv[4], NULL);
} }
else if ((!strcmp(argv[1], "-i")) && (argc > 5)) else if ((!strcmp(argv[1], "-i")) && (argc > 5))
{ {
if (argc > 6) if (argc > 6)
do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]); do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]);
else else
do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), NULL); do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), NULL);
} }
else if ((!strcmp(argv[1], "-e")) && (argc > 5)) else if ((!strcmp(argv[1], "-e")) && (argc > 5))
{ {
if (argc > 6) if (argc > 6)
do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]); do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]);
else else
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();

View File

@ -3,37 +3,38 @@
int int
main(void) main(void)
{ {
Eet_File *ef; Eet_File *ef;
char *ret; char *ret;
int size; int size;
char *entries[] = char *entries[] =
{ {
"Entry 1", "Entry 1",
"Big text string here compared to others", "Big text string here compared to others",
"Eet is cool" "Eet is cool"
}; };
eet_init(); eet_init();
// blindly open an file for output and write strings with their NUL char // blindly open an file for output and write strings with their NUL char
ef = eet_open("test.eet", EET_FILE_MODE_WRITE); ef = eet_open("test.eet", EET_FILE_MODE_WRITE);
eet_write(ef, "Entry 1", entries[0], strlen(entries[0]) + 1, 0); eet_write(ef, "Entry 1", entries[0], strlen(entries[0]) + 1, 0);
eet_write(ef, "Entry 2", entries[1], strlen(entries[1]) + 1, 1); eet_write(ef, "Entry 2", entries[1], strlen(entries[1]) + 1, 1);
eet_write(ef, "Entry 3", entries[2], strlen(entries[2]) + 1, 0); eet_write(ef, "Entry 3", entries[2], strlen(entries[2]) + 1, 0);
eet_close(ef); eet_close(ef);
// open the file again and blindly get the entries we wrote // open the file again and blindly get the entries we wrote
ef = eet_open("test.eet", EET_FILE_MODE_READ); ef = eet_open("test.eet", EET_FILE_MODE_READ);
ret = eet_read(ef, "Entry 1", &size); ret = eet_read(ef, "Entry 1", &size);
printf("%s\n", ret); printf("%s\n", ret);
free(ret); free(ret);
ret = eet_read(ef, "Entry 2", &size); ret = eet_read(ef, "Entry 2", &size);
printf("%s\n", ret); printf("%s\n", ret);
free(ret); free(ret);
ret = eet_read(ef, "Entry 3", &size); ret = eet_read(ef, "Entry 3", &size);
printf("%s\n", ret); printf("%s\n", ret);
free(ret); free(ret);
eet_close(ef); eet_close(ef);
eet_shutdown(); eet_shutdown();
} }

View File

@ -27,7 +27,7 @@ main(void)
if (!(file = tmpnam(file))) if (!(file = tmpnam(file)))
{ {
fprintf( fprintf(
stderr, "ERROR: could not create temporary file (%s).\n", file); stderr, "ERROR: could not create temporary file (%s).\n", file);
goto panic; goto panic;
} }
@ -36,14 +36,14 @@ main(void)
if (!ef) if (!ef)
{ {
fprintf( fprintf(
stderr, "ERROR: could not access file (%s).\n", file); stderr, "ERROR: could not access file (%s).\n", file);
goto error; goto error;
} }
if (!eet_write_cipher(ef, "keys/tests", buffer, strlen(buffer) + 1, 0, key)) if (!eet_write_cipher(ef, "keys/tests", buffer, strlen(buffer) + 1, 0, key))
{ {
fprintf( fprintf(
stderr, "ERROR: could not access file (%s).\n", file); stderr, "ERROR: could not access file (%s).\n", file);
goto error; goto error;
} }
@ -54,7 +54,7 @@ main(void)
if (!ef) if (!ef)
{ {
fprintf( fprintf(
stderr, "ERROR: could not access file (%s).\n", file); stderr, "ERROR: could not access file (%s).\n", file);
goto error; goto error;
} }
@ -62,22 +62,22 @@ main(void)
if (!test) if (!test)
{ {
fprintf( fprintf(
stderr, "ERROR: could decript contents on file %s, with key %s.\n", stderr, "ERROR: could decript contents on file %s, with key %s.\n",
file, key); file, key);
goto error; goto error;
} }
if (size != (int)strlen(buffer) + 1) if (size != (int)strlen(buffer) + 1)
{ {
fprintf( fprintf(
stderr, "ERROR: something is wrong with the decripted data\n"); stderr, "ERROR: something is wrong with the decripted data\n");
goto error; goto error;
} }
if (memcmp(test, buffer, strlen(buffer) + 1) != 0) if (memcmp(test, buffer, strlen(buffer) + 1) != 0)
{ {
fprintf( fprintf(
stderr, "ERROR: something is wrong with the decripted data\n"); stderr, "ERROR: something is wrong with the decripted data\n");
goto error; goto error;
} }
@ -88,7 +88,7 @@ main(void)
if (!ef) if (!ef)
{ {
fprintf( fprintf(
stderr, "ERROR: could not access file (%s).\n", file); stderr, "ERROR: could not access file (%s).\n", file);
goto error; goto error;
} }
@ -96,24 +96,24 @@ main(void)
if (size == (int)strlen(buffer) + 1) if (size == (int)strlen(buffer) + 1)
if (memcmp(test, buffer, strlen(buffer) + 1) == 0) if (memcmp(test, buffer, strlen(buffer) + 1) == 0)
{ {
fprintf( fprintf(
stderr, "ERROR: something is wrong with the contents of %s, as" stderr, "ERROR: something is wrong with the contents of %s, as"
" we accessed it with a different key and it decripted our" " we accessed it with a different key and it decripted our"
" information right.\n", file); " information right.\n", file);
goto error; goto error;
} }
eet_close(ef); eet_close(ef);
error: error:
if (unlink(file) != 0) if (unlink(file) != 0)
{ {
fprintf( fprintf(
stderr, "ERROR: could not unlink file (%s).\n", file); stderr, "ERROR: could not unlink file (%s).\n", file);
} }
panic: panic:
eet_shutdown(); eet_shutdown();
} }

View File

@ -82,48 +82,48 @@ _my_cache_descriptor_init(void)
// Describe the members to be saved: // Describe the members to be saved:
// 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 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);
ADD_BASIC(id, EET_T_UINT); ADD_BASIC(id, EET_T_UINT);
ADD_BASIC(status_id, EET_T_UINT); ADD_BASIC(status_id, EET_T_UINT);
ADD_BASIC(date, EET_T_UINT); ADD_BASIC(date, EET_T_UINT);
ADD_BASIC(timeline, EET_T_UINT); ADD_BASIC(timeline, EET_T_UINT);
#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_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
EET_DATA_DESCRIPTOR_ADD_LIST EET_DATA_DESCRIPTOR_ADD_LIST
(_my_account_descriptor, My_Account, "messages", messages, (_my_account_descriptor, My_Account, "messages", messages,
_my_message_descriptor); _my_message_descriptor);
EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY
(_my_account_descriptor, My_Account, "posts", posts, (_my_account_descriptor, My_Account, "posts", posts,
_my_post_descriptor); _my_post_descriptor);
#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
EET_DATA_DESCRIPTOR_ADD_HASH EET_DATA_DESCRIPTOR_ADD_HASH
(_my_cache_descriptor, My_Cache, "accounts", accounts, (_my_cache_descriptor, My_Cache, "accounts", accounts,
_my_account_descriptor); _my_account_descriptor);
} /* _my_cache_descriptor_init */ } /* _my_cache_descriptor_init */
static void static void
@ -138,21 +138,21 @@ _my_cache_descriptor_shutdown(void)
// need to check if the pointer came from mmaped area in eet_dictionary // need to check if the pointer came from mmaped area in eet_dictionary
// or it was allocated with eina_stringshare_add() // or it was allocated with eina_stringshare_add()
static void static void
_eet_string_free(const char * str) _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);
} /* _eet_string_free */ } /* _eet_string_free */
static My_Message * static My_Message *
_my_message_new(const char * message) _my_message_new(const char *message)
{ {
My_Message * msg = calloc(1, sizeof(My_Message)); My_Message *msg = calloc(1, sizeof(My_Message));
if (!msg) if (!msg)
{ {
fprintf(stderr, "ERROR: could not calloc My_Message\n"); fprintf(stderr, "ERROR: could not calloc My_Message\n");
@ -164,7 +164,7 @@ _my_message_new(const char * message)
} /* _my_message_new */ } /* _my_message_new */
static void static void
_my_message_free(My_Message * msg) _my_message_free(My_Message *msg)
{ {
_eet_string_free(msg->screen_name); _eet_string_free(msg->screen_name);
_eet_string_free(msg->name); _eet_string_free(msg->name);
@ -173,7 +173,8 @@ _my_message_free(My_Message * msg)
} /* _my_message_free */ } /* _my_message_free */
static Eina_Bool static Eina_Bool
_my_post_add(My_Account *acc, const char * message) _my_post_add(My_Account *acc,
const char *message)
{ {
int new_count = acc->posts_count + 1; int new_count = acc->posts_count + 1;
My_Post *post = realloc(acc->posts, new_count * sizeof(My_Post)); My_Post *post = realloc(acc->posts, new_count * sizeof(My_Post));
@ -187,20 +188,20 @@ _my_post_add(My_Account *acc, const char * message)
post[acc->posts_count].dm_to = NULL; post[acc->posts_count].dm_to = NULL;
acc->posts_count = new_count; acc->posts_count = new_count;
acc->posts = post; acc->posts = post;
return EINA_TRUE;; return EINA_TRUE;
} /* _my_post_new */ } /* _my_post_new */
static void static void
_my_post_free(My_Post * post) _my_post_free(My_Post *post)
{ {
_eet_string_free(post->dm_to); _eet_string_free(post->dm_to);
_eet_string_free(post->message); _eet_string_free(post->message);
} /* _my_post_free */ } /* _my_post_free */
static My_Account * static My_Account *
_my_account_new(const char * name) _my_account_new(const char *name)
{ {
My_Account * acc = calloc(1, sizeof(My_Account)); My_Account *acc = calloc(1, sizeof(My_Account));
if (!acc) if (!acc)
{ {
fprintf(stderr, "ERROR: could not calloc My_Account\n"); fprintf(stderr, "ERROR: could not calloc My_Account\n");
@ -212,15 +213,15 @@ _my_account_new(const char * name)
} /* _my_account_new */ } /* _my_account_new */
static void static void
_my_account_free(My_Account * acc) _my_account_free(My_Account *acc)
{ {
My_Message * m; My_Message *m;
int i; int i;
_eet_string_free(acc->name); _eet_string_free(acc->name);
EINA_LIST_FREE(acc->messages, m) EINA_LIST_FREE(acc->messages, m)
_my_message_free(m); _my_message_free(m);
for (i = 0; i < acc->posts_count; i++) for (i = 0; i < acc->posts_count; i++)
_my_post_free(&acc->posts[i]); _my_post_free(&acc->posts[i]);
@ -232,7 +233,7 @@ _my_account_free(My_Account * acc)
static My_Cache * static My_Cache *
_my_cache_new(void) _my_cache_new(void)
{ {
My_Cache * my_cache = calloc(1, sizeof(My_Cache)); My_Cache *my_cache = calloc(1, sizeof(My_Cache));
if (!my_cache) if (!my_cache)
{ {
fprintf(stderr, "ERROR: could not calloc My_Cache\n"); fprintf(stderr, "ERROR: could not calloc My_Cache\n");
@ -246,32 +247,36 @@ _my_cache_new(void)
} /* _my_cache_new */ } /* _my_cache_new */
static Eina_Bool static Eina_Bool
_my_cache_account_free_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata) _my_cache_account_free_cb(const Eina_Hash *hash,
const void *key,
void *data,
void *fdata)
{ {
_my_account_free(data); _my_account_free(data);
return EINA_TRUE; return EINA_TRUE;
} }
static void static void
_my_cache_free(My_Cache * my_cache) _my_cache_free(My_Cache *my_cache)
{ {
My_Account * acc; My_Account *acc;
eina_hash_foreach(my_cache->accounts, _my_cache_account_free_cb, NULL); eina_hash_foreach(my_cache->accounts, _my_cache_account_free_cb, NULL);
eina_hash_free(my_cache->accounts); eina_hash_free(my_cache->accounts);
free(my_cache); free(my_cache);
} /* _my_cache_free */ } /* _my_cache_free */
static My_Account * static My_Account *
_my_cache_account_find(My_Cache * my_cache, const char * name) _my_cache_account_find(My_Cache *my_cache,
const char *name)
{ {
return eina_hash_find(my_cache->accounts, name); return eina_hash_find(my_cache->accounts, name);
} /* _my_cache_account_find */ } /* _my_cache_account_find */
static My_Cache * static My_Cache *
_my_cache_load(const char * filename) _my_cache_load(const char *filename)
{ {
My_Cache * my_cache; My_Cache *my_cache;
Eet_File * ef = eet_open(filename, EET_FILE_MODE_READ); Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ);
if (!ef) if (!ef)
{ {
fprintf(stderr, "ERROR: could not open '%s' for read\n", filename); fprintf(stderr, "ERROR: could not open '%s' for read\n", filename);
@ -295,7 +300,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);
@ -304,10 +309,11 @@ _my_cache_load(const char * filename)
} /* _my_cache_load */ } /* _my_cache_load */
static Eina_Bool static Eina_Bool
_my_cache_save(const My_Cache * my_cache, const char * filename) _my_cache_save(const My_Cache *my_cache,
const char *filename)
{ {
char tmp[PATH_MAX]; char tmp[PATH_MAX];
Eet_File * ef; Eet_File *ef;
Eina_Bool ret; Eina_Bool ret;
unsigned int i, len; unsigned int i, len;
struct stat st; struct stat st;
@ -335,7 +341,7 @@ _my_cache_save(const My_Cache * my_cache, const char * filename)
} }
ret = eet_data_write ret = eet_data_write
(ef, _my_cache_descriptor, MY_CACHE_FILE_ENTRY, my_cache, EINA_TRUE); (ef, _my_cache_descriptor, MY_CACHE_FILE_ENTRY, my_cache, EINA_TRUE);
// VERY IMPORTANT NOTE: // VERY IMPORTANT NOTE:
// after eet_close(), all strings mmaped from file will be GONE, invalid! // after eet_close(), all strings mmaped from file will be GONE, invalid!
@ -356,12 +362,14 @@ _my_cache_save(const My_Cache * my_cache, const char * filename)
return ret; return ret;
} /* _my_cache_save */ } /* _my_cache_save */
int main(int argc, char * argv[]) int
main(int argc,
char *argv[])
{ {
My_Cache * my_cache; My_Cache *my_cache;
const Eina_List * l_acc; const Eina_List *l_acc;
Eina_Iterator *it; Eina_Iterator *it;
My_Account * acc; My_Account *acc;
int ret = 0; int ret = 0;
if (argc < 3) if (argc < 3)
@ -399,58 +407,58 @@ int main(int argc, char * argv[])
{ {
if (argc == 5) if (argc == 5)
{ {
My_Account * acc = _my_cache_account_find(my_cache, argv[4]); My_Account *acc = _my_cache_account_find(my_cache, argv[4]);
if (!acc) if (!acc)
{ {
acc = _my_account_new(argv[4]); acc = _my_account_new(argv[4]);
eina_hash_direct_add(my_cache->accounts, acc->name, acc); eina_hash_direct_add(my_cache->accounts, acc->name, acc);
} }
else else
fprintf(stderr, "ERROR: account '%s' already exists.\n", fprintf(stderr, "ERROR: account '%s' already exists.\n",
argv[4]); argv[4]);
} }
else else
fprintf(stderr, fprintf(stderr,
"ERROR: wrong number of parameters (%d).\n", "ERROR: wrong number of parameters (%d).\n",
argc); argc);
} }
else if (strcmp(argv[3], "post") == 0) else if (strcmp(argv[3], "post") == 0)
{ {
if (argc == 6) if (argc == 6)
{ {
My_Account * acc = _my_cache_account_find(my_cache, argv[4]); My_Account *acc = _my_cache_account_find(my_cache, argv[4]);
if (acc) if (acc)
{ {
_my_post_add(acc, argv[5]); _my_post_add(acc, argv[5]);
} }
else else
fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]); fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]);
} }
else else
fprintf(stderr, fprintf(stderr,
"ERROR: wrong number of parameters (%d).\n", "ERROR: wrong number of parameters (%d).\n",
argc); argc);
} }
else if (strcmp(argv[3], "message") == 0) else if (strcmp(argv[3], "message") == 0)
{ {
if (argc == 6) if (argc == 6)
{ {
My_Account * acc = _my_cache_account_find(my_cache, argv[4]); My_Account *acc = _my_cache_account_find(my_cache, argv[4]);
if (acc) if (acc)
{ {
My_Message * msg = _my_message_new(argv[5]); My_Message *msg = _my_message_new(argv[5]);
acc->messages = eina_list_append(acc->messages, msg); acc->messages = eina_list_append(acc->messages, msg);
} }
else else
fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]); fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]);
} }
else else
fprintf(stderr, fprintf(stderr,
"ERROR: wrong number of parameters (%d).\n", "ERROR: wrong number of parameters (%d).\n",
argc); argc);
} }
else else
fprintf(stderr, "ERROR: unknown action '%s'\n", argv[2]); fprintf(stderr, "ERROR: unknown action '%s'\n", argv[2]);
} }
printf("My_Cache:\n" printf("My_Cache:\n"
@ -460,52 +468,52 @@ int main(int argc, char * argv[])
eina_hash_population(my_cache->accounts)); eina_hash_population(my_cache->accounts));
it = eina_hash_iterator_data_new(my_cache->accounts); it = eina_hash_iterator_data_new(my_cache->accounts);
EINA_ITERATOR_FOREACH(it, acc) EINA_ITERATOR_FOREACH(it, acc)
{ {
const My_Post * post; const My_Post *post;
printf("\t > %-#8x '%.20s' stats: m=%u, p=%u\n", printf("\t > %-#8x '%.20s' stats: m=%u, p=%u\n",
acc->id, acc->name ? acc->name : "", acc->id, acc->name ? acc->name : "",
eina_list_count(acc->messages), eina_list_count(acc->messages),
acc->posts_count); acc->posts_count);
if (eina_list_count(acc->messages)) if (eina_list_count(acc->messages))
{ {
const Eina_List * l; const Eina_List *l;
const My_Message * msg; const My_Message *msg;
printf("\t |messages:\n"); printf("\t |messages:\n");
EINA_LIST_FOREACH(acc->messages, l, msg) EINA_LIST_FOREACH(acc->messages, l, msg)
{ {
printf("\t | %-8x '%s' [%s]: '%.20s'\n", printf("\t | %-8x '%s' [%s]: '%.20s'\n",
msg->id, msg->id,
msg->name ? msg->name : "", msg->name ? msg->name : "",
msg->screen_name ? msg->screen_name : "", msg->screen_name ? msg->screen_name : "",
msg->message ? msg->message : ""); msg->message ? msg->message : "");
} }
} }
if (acc->posts_count) if (acc->posts_count)
{ {
const My_Post * post; const My_Post *post;
int i; int i;
printf("\t |posts:\n"); printf("\t |posts:\n");
for (i = 0; i < acc->posts_count; i++) for (i = 0; i < acc->posts_count; i++)
{ {
post = &acc->posts[i]; post = &acc->posts[i];
if (post->dm_to) if (post->dm_to)
printf("\t | @%s: '%.20s'\n", post->dm_to, post->message); printf("\t | @%s: '%.20s'\n", post->dm_to, post->message);
else else
printf("\t | '%.20s'\n", post->message); printf("\t | '%.20s'\n", post->message);
} }
} }
printf("\n"); printf("\n");
} }
eina_iterator_free(it); eina_iterator_free(it);
if (!_my_cache_save(my_cache, argv[2])) if (!_my_cache_save(my_cache, argv[2]))
ret = -3; ret = -3;
_my_cache_free(my_cache); _my_cache_free(my_cache);

View File

@ -115,7 +115,9 @@ _st3_set(Example_Struct3 *st3,
st3->body = v1; st3->body = v1;
} /* _st3_set */ } /* _st3_set */
static const char * /* union type_get() */ static const char *
/* union
type_get() */
_union_type_get(const void *data, _union_type_get(const void *data,
Eina_Bool *unknow) Eina_Bool *unknow)
{ {
@ -259,7 +261,8 @@ static Eet_Data_Descriptor *_variant_unified_descriptor;
static Eet_File *_cache_file = NULL; static Eet_File *_cache_file = NULL;
static Eet_Dictionary *_cache_dict = NULL; static Eet_Dictionary *_cache_dict = NULL;
static void /* declaring types */ static void
/* declaring types */
_data_descriptors_init(void) _data_descriptors_init(void)
{ {
Eet_Data_Descriptor_Class eddc; Eet_Data_Descriptor_Class eddc;

View File

@ -17,17 +17,17 @@
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;
int not_saved_value; // example of not saved data inside! int not_saved_value; // example of not saved data inside!
Eina_Bool enabled; Eina_Bool enabled;
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;
// string that represents the entry in eet file, you might like to have // string that represents the entry in eet file, you might like to have
@ -38,8 +38,8 @@ static const char MY_CONF_FILE_ENTRY[] = "config";
// keep the descriptor static global, so it can be // keep the descriptor static global, so it can be
// shared by different functions (load/save) of this and only this // shared by different functions (load/save) of this and only this
// file. // file.
static Eet_Data_Descriptor * _my_conf_descriptor; static Eet_Data_Descriptor *_my_conf_descriptor;
static Eet_Data_Descriptor * _my_conf_sub_descriptor; static Eet_Data_Descriptor *_my_conf_sub_descriptor;
static void static void
_my_conf_descriptor_init(void) _my_conf_descriptor_init(void)
@ -66,24 +66,24 @@ _my_conf_descriptor_init(void)
// Describe the members to be saved: // Describe the members to be saved:
// 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);
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);
MY_CONF_ADD_BASIC(id, EET_T_INT); MY_CONF_ADD_BASIC(id, EET_T_INT);
MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR); MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR);
// And add the sub descriptor as a linked list at 'subs' in the main struct // And add the sub descriptor as a linked list at 'subs' in the main struct
EET_DATA_DESCRIPTOR_ADD_LIST EET_DATA_DESCRIPTOR_ADD_LIST
(_my_conf_descriptor, My_Conf_Type, "subs", subs, _my_conf_sub_descriptor); (_my_conf_descriptor, My_Conf_Type, "subs", subs, _my_conf_sub_descriptor);
#undef MY_CONF_ADD_BASIC #undef MY_CONF_ADD_BASIC
#undef MY_CONF_SUB_ADD_BASIC #undef MY_CONF_SUB_ADD_BASIC
@ -99,8 +99,8 @@ _my_conf_descriptor_shutdown(void)
static My_Conf_Type * static My_Conf_Type *
_my_conf_new(void) _my_conf_new(void)
{ {
My_Conf_Type * my_conf = calloc(1, sizeof(My_Conf_Type)); My_Conf_Type *my_conf = calloc(1, sizeof(My_Conf_Type));
My_Conf_Subtype * sub; My_Conf_Subtype *sub;
if (!my_conf) if (!my_conf)
{ {
fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n"); fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n");
@ -122,24 +122,24 @@ _my_conf_new(void)
} /* _my_conf_new */ } /* _my_conf_new */
static void static void
_my_conf_free(My_Conf_Type * my_conf) _my_conf_free(My_Conf_Type *my_conf)
{ {
My_Conf_Subtype * sub; My_Conf_Subtype *sub;
EINA_LIST_FREE(my_conf->subs, sub) EINA_LIST_FREE(my_conf->subs, sub)
{ {
eina_stringshare_del(sub->server); eina_stringshare_del(sub->server);
free(sub); free(sub);
} }
eina_stringshare_del(my_conf->name); eina_stringshare_del(my_conf->name);
free(my_conf); free(my_conf);
} /* _my_conf_free */ } /* _my_conf_free */
static My_Conf_Type * static My_Conf_Type *
_my_conf_load(const char * filename) _my_conf_load(const char *filename)
{ {
My_Conf_Type * my_conf; My_Conf_Type *my_conf;
Eet_File * ef = eet_open(filename, EET_FILE_MODE_READ); Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ);
if (!ef) if (!ef)
{ {
fprintf(stderr, "ERROR: could not open '%s' for read\n", filename); fprintf(stderr, "ERROR: could not open '%s' for read\n", filename);
@ -148,7 +148,7 @@ _my_conf_load(const char * filename)
my_conf = eet_data_read(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY); my_conf = eet_data_read(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY);
if (!my_conf) if (!my_conf)
goto end; goto end;
if (my_conf->version < 0x112233) if (my_conf->version < 0x112233)
{ {
@ -166,10 +166,11 @@ end:
} /* _my_conf_load */ } /* _my_conf_load */
static Eina_Bool static Eina_Bool
_my_conf_save(const My_Conf_Type * my_conf, const char * filename) _my_conf_save(const My_Conf_Type *my_conf,
const char *filename)
{ {
char tmp[PATH_MAX]; char tmp[PATH_MAX];
Eet_File * ef; Eet_File *ef;
Eina_Bool ret; Eina_Bool ret;
unsigned int i, len; unsigned int i, len;
struct stat st; struct stat st;
@ -197,7 +198,7 @@ _my_conf_save(const My_Conf_Type * my_conf, const char * filename)
} }
ret = eet_data_write ret = eet_data_write
(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY, my_conf, EINA_TRUE); (ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY, my_conf, EINA_TRUE);
eet_close(ef); eet_close(ef);
if (ret) if (ret)
@ -209,11 +210,13 @@ _my_conf_save(const My_Conf_Type * my_conf, const char * filename)
return ret; return ret;
} /* _my_conf_save */ } /* _my_conf_save */
int main(int argc, char * argv[]) int
main(int argc,
char *argv[])
{ {
My_Conf_Type * my_conf; My_Conf_Type *my_conf;
const My_Conf_Subtype * sub; const My_Conf_Subtype *sub;
const Eina_List * l; const Eina_List *l;
int ret = 0; int ret = 0;
if (argc != 3) if (argc != 3)
@ -250,12 +253,12 @@ int main(int argc, char * argv[])
my_conf->enabled); my_conf->enabled);
EINA_LIST_FOREACH(my_conf->subs, l, sub) EINA_LIST_FOREACH(my_conf->subs, l, sub)
printf("\t\tserver: '%s', port: %d\n", printf("\t\tserver: '%s', port: %d\n",
sub->server ? sub->server : "", sub->server ? sub->server : "",
sub->port); sub->port);
if (!_my_conf_save(my_conf, argv[2])) if (!_my_conf_save(my_conf, argv[2]))
ret = -3; ret = -3;
_my_conf_free(my_conf); _my_conf_free(my_conf);

View File

@ -17,7 +17,7 @@
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;
int not_saved_value; // example of not saved data inside! int not_saved_value; // example of not saved data inside!
Eina_Bool enabled; Eina_Bool enabled;
@ -31,7 +31,7 @@ static const char MY_CONF_FILE_ENTRY[] = "config";
// keep the descriptor static global, so it can be // keep the descriptor static global, so it can be
// shared by different functions (load/save) of this and only this // shared by different functions (load/save) of this and only this
// file. // file.
static Eet_Data_Descriptor * _my_conf_descriptor; static Eet_Data_Descriptor *_my_conf_descriptor;
static void static void
_my_conf_descriptor_init(void) _my_conf_descriptor_init(void)
@ -55,13 +55,13 @@ _my_conf_descriptor_init(void)
// Describe the members to be saved: // Describe the members to be saved:
// 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);
MY_CONF_ADD_BASIC(id, EET_T_INT); MY_CONF_ADD_BASIC(id, EET_T_INT);
MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR); MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR);
#undef MY_CONF_ADD_BASIC #undef MY_CONF_ADD_BASIC
@ -76,7 +76,7 @@ _my_conf_descriptor_shutdown(void)
static My_Conf_Type * static My_Conf_Type *
_my_conf_new(void) _my_conf_new(void)
{ {
My_Conf_Type * my_conf = calloc(1, sizeof(My_Conf_Type)); My_Conf_Type *my_conf = calloc(1, sizeof(My_Conf_Type));
if (!my_conf) if (!my_conf)
{ {
fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n"); fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n");
@ -89,17 +89,17 @@ _my_conf_new(void)
} /* _my_conf_new */ } /* _my_conf_new */
static void static void
_my_conf_free(My_Conf_Type * my_conf) _my_conf_free(My_Conf_Type *my_conf)
{ {
eina_stringshare_del(my_conf->name); eina_stringshare_del(my_conf->name);
free(my_conf); free(my_conf);
} /* _my_conf_free */ } /* _my_conf_free */
static My_Conf_Type * static My_Conf_Type *
_my_conf_load(const char * filename) _my_conf_load(const char *filename)
{ {
My_Conf_Type * my_conf; My_Conf_Type *my_conf;
Eet_File * ef = eet_open(filename, EET_FILE_MODE_READ); Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ);
if (!ef) if (!ef)
{ {
fprintf(stderr, "ERROR: could not open '%s' for read\n", filename); fprintf(stderr, "ERROR: could not open '%s' for read\n", filename);
@ -108,7 +108,7 @@ _my_conf_load(const char * filename)
my_conf = eet_data_read(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY); my_conf = eet_data_read(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY);
if (!my_conf) if (!my_conf)
goto end; goto end;
if (my_conf->version < 0x112233) if (my_conf->version < 0x112233)
{ {
@ -126,10 +126,11 @@ end:
} /* _my_conf_load */ } /* _my_conf_load */
static Eina_Bool static Eina_Bool
_my_conf_save(const My_Conf_Type * my_conf, const char * filename) _my_conf_save(const My_Conf_Type *my_conf,
const char *filename)
{ {
char tmp[PATH_MAX]; char tmp[PATH_MAX];
Eet_File * ef; Eet_File *ef;
Eina_Bool ret; Eina_Bool ret;
unsigned int i, len; unsigned int i, len;
struct stat st; struct stat st;
@ -157,7 +158,7 @@ _my_conf_save(const My_Conf_Type * my_conf, const char * filename)
} }
ret = eet_data_write ret = eet_data_write
(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY, my_conf, EINA_TRUE); (ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY, my_conf, EINA_TRUE);
eet_close(ef); eet_close(ef);
if (ret) if (ret)
@ -169,9 +170,11 @@ _my_conf_save(const My_Conf_Type * my_conf, const char * filename)
return ret; return ret;
} /* _my_conf_save */ } /* _my_conf_save */
int main(int argc, char * argv[]) int
main(int argc,
char *argv[])
{ {
My_Conf_Type * my_conf; My_Conf_Type *my_conf;
int ret = 0; int ret = 0;
if (argc != 3) if (argc != 3)
@ -207,7 +210,7 @@ int main(int argc, char * argv[])
my_conf->enabled); my_conf->enabled);
if (!_my_conf_save(my_conf, argv[2])) if (!_my_conf_save(my_conf, argv[2]))
ret = -3; ret = -3;
_my_conf_free(my_conf); _my_conf_free(my_conf);

View File

@ -12,25 +12,25 @@ create_eet_file(void)
char buf[1024], *ptr; char buf[1024], *ptr;
int size, len, i; int size, len, i;
const char *some_strings[] = { const char *some_strings[] = {
"And some more strings", "And some more strings",
"spread across several", "spread across several",
"elements of an array!" "elements of an array!"
}; };
const char some_data[] = const char some_data[] =
"\x1e\xe7\x0f\x42\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x35" "\x1e\xe7\x0f\x42\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x35"
"\x00\x00\x00\xa0\x00\x00\x00\xa0\x00\x00\x00\x24\x00\x00\x00\x11" "\x00\x00\x00\xa0\x00\x00\x00\xa0\x00\x00\x00\x24\x00\x00\x00\x11"
"\x00\x00\x00\x00\x2f\x6d\x69\x73\x74\x65\x72\x69\x6f\x75\x73\x2f" "\x00\x00\x00\x00\x2f\x6d\x69\x73\x74\x65\x72\x69\x6f\x75\x73\x2f"
"\x64\x61\x74\x61\x00\x41\x6e\x20\x45\x45\x54\x20\x69\x6e\x73\x69" "\x64\x61\x74\x61\x00\x41\x6e\x20\x45\x45\x54\x20\x69\x6e\x73\x69"
"\x64\x65\x20\x6f\x66\x20\x61\x6e\x20\x45\x45\x54\x21\x0a\x54\x68" "\x64\x65\x20\x6f\x66\x20\x61\x6e\x20\x45\x45\x54\x21\x0a\x54\x68"
"\x69\x73\x20\x77\x61\x73\x6e\x27\x74\x20\x72\x65\x61\x6c\x6c\x79" "\x69\x73\x20\x77\x61\x73\x6e\x27\x74\x20\x72\x65\x61\x6c\x6c\x79"
"\x20\x75\x73\x65\x66\x75\x6c\x20\x62\x75\x74\x20\x69\x74\x20\x68" "\x20\x75\x73\x65\x66\x75\x6c\x20\x62\x75\x74\x20\x69\x74\x20\x68"
"\x65\x6c\x70\x65\x64\x20\x74\x6f\x20\x73\x68\x6f\x77\x20\x68\x6f" "\x65\x6c\x70\x65\x64\x20\x74\x6f\x20\x73\x68\x6f\x77\x20\x68\x6f"
"\x77\x0a\x74\x6f\x20\x75\x73\x65\x20\x65\x65\x74\x5f\x6d\x65\x6d" "\x77\x0a\x74\x6f\x20\x75\x73\x65\x20\x65\x65\x74\x5f\x6d\x65\x6d"
"\x6f\x70\x65\x6e\x5f\x72\x65\x61\x64\x28\x29\x20\x74\x6f\x20\x6f" "\x6f\x70\x65\x6e\x5f\x72\x65\x61\x64\x28\x29\x20\x74\x6f\x20\x6f"
"\x70\x65\x6e\x20\x61\x6e\x20\x65\x65\x74\x20\x66\x69\x6c\x65\x20" "\x70\x65\x6e\x20\x61\x6e\x20\x65\x65\x74\x20\x66\x69\x6c\x65\x20"
"\x66\x72\x6f\x6d\x0a\x64\x61\x74\x61\x20\x61\x6c\x72\x65\x61\x64" "\x66\x72\x6f\x6d\x0a\x64\x61\x74\x61\x20\x61\x6c\x72\x65\x61\x64"
"\x79\x20\x6c\x6f\x61\x64\x65\x64\x20\x69\x6e\x20\x6d\x65\x6d\x6f" "\x79\x20\x6c\x6f\x61\x64\x65\x64\x20\x69\x6e\x20\x6d\x65\x6d\x6f"
"\x72\x79\x2e\x0a\x00"; "\x72\x79\x2e\x0a\x00";
ef = eet_open("/tmp/my_file.eet", EET_FILE_MODE_WRITE); ef = eet_open("/tmp/my_file.eet", EET_FILE_MODE_WRITE);
if (!ef) return 0; if (!ef) return 0;
@ -60,67 +60,68 @@ create_eet_file(void)
eet_delete(ef, "/several/strings"); eet_delete(ef, "/several/strings");
return (eet_close(ef) == EET_ERROR_NONE); return eet_close(ef) == EET_ERROR_NONE;
} }
int int
main(void) main(void)
{ {
Eet_File *ef; Eet_File *ef;
char *ret, **list; char *ret, **list;
int size, num, i; int size, num, i;
eet_init(); eet_init();
if (!create_eet_file()) if (!create_eet_file())
return -1; return -1;
ef = eet_open("/tmp/my_file.eet", EET_FILE_MODE_READ); ef = eet_open("/tmp/my_file.eet", EET_FILE_MODE_READ);
if (!ef) return -1; if (!ef) return -1;
list = eet_list(ef, "*", &num); list = eet_list(ef, "*", &num);
if (list) if (list)
{ {
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
printf("Key stored: %s\n", list[i]); printf("Key stored: %s\n", list[i]);
free(list); free(list);
} }
ret = eet_read(ef, "/key/to_store/at", &size); ret = eet_read(ef, "/key/to_store/at", &size);
if (ret) if (ret)
{ {
printf("Data read (%i bytes):\n%s\n", size, ret); printf("Data read (%i bytes):\n%s\n", size, ret);
free(ret); free(ret);
} }
ret = eet_read(ef, "/several/strings", &size); ret = eet_read(ef, "/several/strings", &size);
if (ret) if (ret)
{ {
printf("More data read (%i bytes):\n%s\n", size, ret); printf("More data read (%i bytes):\n%s\n", size, ret);
free(ret); free(ret);
} }
ret = eet_read(ef, "/some/mysterious/data", &size); ret = eet_read(ef, "/some/mysterious/data", &size);
if (ret) if (ret)
{ {
Eet_File *ef2; Eet_File *ef2;
ef2 = eet_memopen_read(ret, size); ef2 = eet_memopen_read(ret, size);
num = eet_num_entries(ef2); num = eet_num_entries(ef2);
printf("Mysterious data has %d entries\n", num); printf("Mysterious data has %d entries\n", num);
printf("Mysterious data:\n%s\n", printf("Mysterious data:\n%s\n",
(char *)eet_read_direct(ef2, "/mysterious/data", NULL)); (char *)eet_read_direct(ef2, "/mysterious/data", NULL));
eet_close(ef2); eet_close(ef2);
free(ret); free(ret);
} }
eet_close(ef); eet_close(ef);
eet_shutdown(); eet_shutdown();
return 0; return 0;
} }

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
#include <Eina.h> #include <Eina.h>
typedef enum _Eet_Convert_Type Eet_Convert_Type; typedef enum _Eet_Convert_Type Eet_Convert_Type;
enum _Eet_Convert_Type enum _Eet_Convert_Type
{ {
@ -13,8 +13,8 @@ enum _Eet_Convert_Type
EET_D_FIXED_POINT = 1 << 4 EET_D_FIXED_POINT = 1 << 4
}; };
typedef struct _Eet_String Eet_String; typedef struct _Eet_String Eet_String;
typedef struct _Eet_Convert Eet_Convert; typedef struct _Eet_Convert Eet_Convert;
struct _Eet_Convert struct _Eet_Convert
{ {
@ -27,15 +27,15 @@ struct _Eet_Convert
struct _Eet_String struct _Eet_String
{ {
const char *str; const char *str;
int len; int len;
int next; int next;
int prev; int prev;
unsigned char hash; unsigned char hash;
unsigned char allocated : 1; unsigned char allocated : 1;
}; };
struct _Eet_Dictionary struct _Eet_Dictionary
{ {
@ -101,61 +101,82 @@ extern int _eet_log_dom_global;
#endif /* ifdef CRIT */ #endif /* ifdef CRIT */
#define CRIT(...) EINA_LOG_DOM_CRIT(_eet_log_dom_global, __VA_ARGS__) #define CRIT(...) EINA_LOG_DOM_CRIT(_eet_log_dom_global, __VA_ARGS__)
Eet_Dictionary * eet_dictionary_add(void); Eet_Dictionary *
void eet_dictionary_free(Eet_Dictionary *ed); eet_dictionary_add(void);
int eet_dictionary_string_add(Eet_Dictionary *ed, void
const char *string); eet_dictionary_free(Eet_Dictionary *ed);
int eet_dictionary_string_get_size(const Eet_Dictionary *ed, int
int index); eet_dictionary_string_add(Eet_Dictionary *ed,
const char * eet_dictionary_string_get_char(const Eet_Dictionary *ed, const char *string);
int index); int
Eina_Bool eet_dictionary_string_get_float(const Eet_Dictionary *ed, eet_dictionary_string_get_size(const Eet_Dictionary *ed,
int index, int index);
float *result); const char *
Eina_Bool eet_dictionary_string_get_double(const Eet_Dictionary *ed, eet_dictionary_string_get_char(const Eet_Dictionary *ed,
int index, int index);
double *result); Eina_Bool
Eina_Bool eet_dictionary_string_get_fp(const Eet_Dictionary *ed, eet_dictionary_string_get_float(const Eet_Dictionary *ed,
int index, int index,
Eina_F32p32 *result); float *result);
int eet_dictionary_string_get_hash(const Eet_Dictionary *ed, Eina_Bool
int index); 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, const void *
unsigned int data_length, eet_identity_check(const void *data_base,
void **sha1, unsigned int data_length,
int *sha1_length, void **sha1,
const void *signature_base, int *sha1_length,
unsigned int signature_length, const void *signature_base,
const void **raw_signature_base, unsigned int signature_length,
unsigned int *raw_signature_length, const void **raw_signature_base,
int *x509_length); unsigned int *raw_signature_length,
void * eet_identity_compute_sha1(const void *data_base, int *x509_length);
unsigned int data_length, void *
int *sha1_length); eet_identity_compute_sha1(const void *data_base,
Eet_Error eet_cipher(const void *data, unsigned int data_length,
unsigned int size, int *sha1_length);
const char *key, Eet_Error
unsigned int length, eet_cipher(const void *data,
void **result, unsigned int size,
unsigned int *result_length); const char *key,
Eet_Error eet_decipher(const void *data, unsigned int length,
unsigned int size, void **result,
const char *key, unsigned int *result_length);
unsigned int length, Eet_Error
void **result, eet_decipher(const void *data,
unsigned int *result_length); unsigned int size,
Eet_Error eet_identity_sign(FILE *fp, const char *key,
Eet_Key *key); unsigned int length,
void eet_identity_unref(Eet_Key *key); void **result,
void eet_identity_ref(Eet_Key *key); unsigned int *result_length);
Eet_Error
eet_identity_sign(FILE *fp,
Eet_Key *key);
void
eet_identity_unref(Eet_Key *key);
void
eet_identity_ref(Eet_Key *key);
void eet_node_shutdown(void); void
int eet_node_init(void); eet_node_shutdown(void);
Eet_Node * eet_node_new(void); int
void eet_node_free(Eet_Node *node); eet_node_init(void);
Eet_Node *
eet_node_new(void);
void
eet_node_free(Eet_Node *node);
#ifndef PATH_MAX #ifndef PATH_MAX
# define PATH_MAX 4096 # define PATH_MAX 4096

View File

@ -16,7 +16,7 @@
# ifdef __cplusplus # ifdef __cplusplus
extern "C" extern "C"
# endif /* ifdef __cplusplus */ # endif /* ifdef __cplusplus */
void * alloca (size_t); void *alloca(size_t);
#endif /* ifdef HAVE_ALLOCA_H */ #endif /* ifdef HAVE_ALLOCA_H */
#include <stdio.h> #include <stdio.h>
@ -80,19 +80,21 @@ 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, static Eet_Error
size_t key_len, eet_hmac_sha1(const void *key,
const void *data, size_t key_len,
size_t data_len, const void *data,
unsigned char *res); size_t data_len,
unsigned char *res);
# endif /* ifdef HAVE_GNUTLS */ # endif /* ifdef HAVE_GNUTLS */
static Eet_Error eet_pbkdf2_sha1(const char *key, static Eet_Error
int key_len, eet_pbkdf2_sha1(const char *key,
const unsigned char *salt, int key_len,
unsigned int salt_len, const unsigned char *salt,
int iter, unsigned int salt_len,
unsigned char *res, int iter,
int res_len); unsigned char *res,
int res_len);
#endif /* ifdef HAVE_CIPHER */ #endif /* ifdef HAVE_CIPHER */
struct _Eet_Key struct _Eet_Key
@ -126,20 +128,20 @@ eet_identity_open(const char *certificate_file,
/* Init */ /* Init */
if (!(key = malloc(sizeof(Eet_Key)))) if (!(key = malloc(sizeof(Eet_Key))))
goto on_error; goto on_error;
key->references = 1; key->references = 1;
if (gnutls_x509_crt_init(&(key->certificate))) if (gnutls_x509_crt_init(&(key->certificate)))
goto on_error; goto on_error;
if (gnutls_x509_privkey_init(&(key->private_key))) if (gnutls_x509_privkey_init(&(key->private_key)))
goto on_error; goto on_error;
/* Mmap certificate_file */ /* Mmap certificate_file */
f = eina_file_open(certificate_file, 0); f = eina_file_open(certificate_file, 0);
if (!f) if (!f)
goto on_error; goto on_error;
/* let's make mmap safe and just get 0 pages for IO erro */ /* let's make mmap safe and just get 0 pages for IO erro */
eina_mmap_safety_enabled_set(EINA_TRUE); eina_mmap_safety_enabled_set(EINA_TRUE);
@ -149,10 +151,10 @@ eet_identity_open(const char *certificate_file,
/* 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 = eina_file_size_get(f);; load_file.size = eina_file_size_get(f);
if (gnutls_x509_crt_import(key->certificate, &load_file, if (gnutls_x509_crt_import(key->certificate, &load_file,
GNUTLS_X509_FMT_PEM) < 0) GNUTLS_X509_FMT_PEM) < 0)
goto on_error; goto on_error;
eina_file_map_free(f, data); eina_file_map_free(f, data);
@ -166,34 +168,34 @@ eet_identity_open(const char *certificate_file,
/* Mmap private_key_file */ /* Mmap private_key_file */
f = eina_file_open(private_key_file, 0); f = eina_file_open(private_key_file, 0);
if (!f) if (!f)
goto on_error; goto on_error;
/* let's make mmap safe and just get 0 pages for IO erro */ /* let's make mmap safe and just get 0 pages for IO erro */
eina_mmap_safety_enabled_set(EINA_TRUE); eina_mmap_safety_enabled_set(EINA_TRUE);
data = eina_file_map_all(f, EINA_FILE_SEQUENTIAL); data = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
if (!data) if (!data)
goto on_error; 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 = eina_file_size_get(f);; load_file.size = eina_file_size_get(f);
/* 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, if (gnutls_x509_privkey_import(key->private_key, &load_file,
GNUTLS_X509_FMT_PEM) < 0) 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, if (gnutls_x509_privkey_import_pkcs8(key->private_key, &load_file,
GNUTLS_X509_FMT_PEM, pass, 0)) 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, if (gnutls_x509_privkey_import_pkcs8(key->private_key, &load_file,
GNUTLS_X509_FMT_PEM, NULL, 1)) GNUTLS_X509_FMT_PEM, NULL, 1))
goto on_error; goto on_error;
} }
@ -209,10 +211,10 @@ on_error:
if (key) if (key)
{ {
if (key->certificate) if (key->certificate)
gnutls_x509_crt_deinit(key->certificate); gnutls_x509_crt_deinit(key->certificate);
if (key->private_key) if (key->private_key)
gnutls_x509_privkey_deinit(key->private_key); gnutls_x509_privkey_deinit(key->private_key);
free(key); free(key);
} }
@ -226,32 +228,32 @@ on_error:
/* Load the X509 certificate in memory. */ /* Load the X509 certificate in memory. */
fp = fopen(certificate_file, "r"); fp = fopen(certificate_file, "r");
if (!fp) if (!fp)
return NULL; return NULL;
cert = PEM_read_X509(fp, NULL, NULL, NULL); cert = PEM_read_X509(fp, NULL, NULL, NULL);
fclose(fp); fclose(fp);
if (!cert) if (!cert)
goto on_error; 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) if (!pkey)
goto on_error; 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) if (!fp)
goto on_error; 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) if (!pkey)
goto on_error; 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) if (!key)
goto on_error; goto on_error;
key->references = 1; key->references = 1;
key->certificate = cert; key->certificate = cert;
@ -261,10 +263,10 @@ on_error:
on_error: on_error:
if (cert) if (cert)
X509_free(cert); X509_free(cert);
if (pkey) if (pkey)
EVP_PKEY_free(pkey); EVP_PKEY_free(pkey);
# endif /* ifdef HAVE_GNUTLS */ # endif /* ifdef HAVE_GNUTLS */
#else #else
@ -280,7 +282,7 @@ eet_identity_close(Eet_Key *key)
{ {
#ifdef HAVE_SIGNATURE #ifdef HAVE_SIGNATURE
if (!key || (key->references > 0)) if (!key || (key->references > 0))
return; return;
# ifdef HAVE_GNUTLS # ifdef HAVE_GNUTLS
gnutls_x509_crt_deinit(key->certificate); gnutls_x509_crt_deinit(key->certificate);
@ -318,7 +320,7 @@ eet_identity_print(Eet_Key *key,
unsigned int i, j; unsigned int i, j;
if (!key) if (!key)
return; return;
if (key->private_key) if (key->private_key)
{ {
@ -329,10 +331,10 @@ eet_identity_print(Eet_Key *key,
rsa_raw + 3, /* First prime */ rsa_raw + 3, /* First prime */
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))) if (!(res = malloc(size)))
goto on_error; goto on_error;
fprintf(out, "Private Key:\n"); fprintf(out, "Private Key:\n");
buf[32] = '\0'; buf[32] = '\0';
@ -344,10 +346,10 @@ eet_identity_print(Eet_Key *key,
{ {
size += 128; size += 128;
if (!(res = realloc(res, size))) if (!(res = realloc(res, size)))
goto on_error; goto on_error;
} }
if (err) if (err)
goto on_error; 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)
@ -365,7 +367,7 @@ eet_identity_print(Eet_Key *key,
fprintf(out, "Public certificate:\n"); fprintf(out, "Public certificate:\n");
if (gnutls_x509_crt_print(key->certificate, GNUTLS_X509_CRT_FULL, if (gnutls_x509_crt_print(key->certificate, GNUTLS_X509_CRT_FULL,
&data)) &data))
goto on_error; goto on_error;
fprintf(out, "%s\n", data.data); fprintf(out, "%s\n", data.data);
gnutls_free(data.data); gnutls_free(data.data);
@ -374,10 +376,10 @@ eet_identity_print(Eet_Key *key,
on_error: on_error:
if (res) if (res)
free(res); free(res);
if (data.data) if (data.data)
gnutls_free(data.data); gnutls_free(data.data);
return; return;
# else /* ifdef HAVE_GNUTLS */ # else /* ifdef HAVE_GNUTLS */
@ -386,7 +388,7 @@ on_error:
DH *dh; DH *dh;
if (!key) if (!key)
return; return;
rsa = EVP_PKEY_get1_RSA(key->private_key); rsa = EVP_PKEY_get1_RSA(key->private_key);
if (rsa) if (rsa)
@ -423,7 +425,7 @@ void
eet_identity_ref(Eet_Key *key) eet_identity_ref(Eet_Key *key)
{ {
if (!key) if (!key)
return; return;
key->references++; key->references++;
} /* eet_identity_ref */ } /* eet_identity_ref */
@ -432,7 +434,7 @@ void
eet_identity_unref(Eet_Key *key) eet_identity_unref(Eet_Key *key)
{ {
if (!key) if (!key)
return; return;
key->references--; key->references--;
eet_identity_close(key); eet_identity_close(key);
@ -449,21 +451,21 @@ eet_identity_compute_sha1(const void *data_base,
# 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) if (!result)
return NULL; 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) if (sha1_length)
*sha1_length = gcry_md_get_algo_dlen(GCRY_MD_SHA1); *sha1_length = gcry_md_get_algo_dlen(GCRY_MD_SHA1);
# else /* ifdef HAVE_GNUTLS */ # else /* ifdef HAVE_GNUTLS */
# ifdef HAVE_OPENSSL # ifdef HAVE_OPENSSL
result = malloc(SHA_DIGEST_LENGTH); result = malloc(SHA_DIGEST_LENGTH);
if (!result) if (!result)
return NULL; return NULL;
SHA1(data_base, data_length, result); SHA1(data_base, data_length, result);
if (sha1_length) if (sha1_length)
*sha1_length = SHA_DIGEST_LENGTH; *sha1_length = SHA_DIGEST_LENGTH;
# else /* ifdef HAVE_OPENSSL */ # else /* ifdef HAVE_OPENSSL */
result = NULL; result = NULL;
@ -503,15 +505,15 @@ eet_identity_sign(FILE *fp,
/* A few check and flush pending write. */ /* A few check and flush pending write. */
if (!fp || !key || !key->certificate || !key->private_key) if (!fp || !key || !key->certificate || !key->private_key)
return EET_ERROR_BAD_OBJECT; return EET_ERROR_BAD_OBJECT;
/* Get the file size. */ /* Get the file size. */
fd = fileno(fp); fd = fileno(fp);
if (fd < 0) if (fd < 0)
return EET_ERROR_BAD_OBJECT; return EET_ERROR_BAD_OBJECT;
if (fstat(fd, &st_buf) < 0) if (fstat(fd, &st_buf) < 0)
return EET_ERROR_MMAP_FAILED; return EET_ERROR_MMAP_FAILED;
/* let's make mmap safe and just get 0 pages for IO erro */ /* let's make mmap safe and just get 0 pages for IO erro */
eina_mmap_safety_enabled_set(EINA_TRUE); eina_mmap_safety_enabled_set(EINA_TRUE);
@ -519,7 +521,7 @@ eet_identity_sign(FILE *fp,
/* 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) if (data == MAP_FAILED)
return EET_ERROR_MMAP_FAILED; return EET_ERROR_MMAP_FAILED;
# ifdef HAVE_GNUTLS # ifdef HAVE_GNUTLS
datum.data = data; datum.data = data;
@ -542,9 +544,9 @@ eet_identity_sign(FILE *fp,
sign, &sign_len)) sign, &sign_len))
{ {
if (!sign) if (!sign)
err = EET_ERROR_OUT_OF_MEMORY; err = EET_ERROR_OUT_OF_MEMORY;
else else
err = EET_ERROR_SIGNATURE_FAILED; err = EET_ERROR_SIGNATURE_FAILED;
goto on_error; goto on_error;
} }
@ -565,9 +567,9 @@ eet_identity_sign(FILE *fp,
&cert_len)) &cert_len))
{ {
if (!cert) if (!cert)
err = EET_ERROR_OUT_OF_MEMORY; err = EET_ERROR_OUT_OF_MEMORY;
else else
err = EET_ERROR_SIGNATURE_FAILED; err = EET_ERROR_SIGNATURE_FAILED;
goto on_error; goto on_error;
} }
@ -631,15 +633,15 @@ eet_identity_sign(FILE *fp,
on_error: on_error:
# ifdef HAVE_GNUTLS # ifdef HAVE_GNUTLS
if (cert) if (cert)
free(cert); free(cert);
# else /* ifdef HAVE_GNUTLS */ # else /* ifdef HAVE_GNUTLS */
if (cert) if (cert)
OPENSSL_free(cert); OPENSSL_free(cert);
# endif /* ifdef HAVE_GNUTLS */ # endif /* ifdef HAVE_GNUTLS */
if (sign) if (sign)
free(sign); free(sign);
munmap(data, st_buf.st_size); munmap(data, st_buf.st_size);
return err; return err;
@ -671,7 +673,7 @@ eet_identity_check(const void *data_base,
/* At least the header size */ /* At least the header size */
if (signature_length < sizeof(int) * 3) if (signature_length < sizeof(int) * 3)
return NULL; return NULL;
/* Get the header */ /* Get the header */
magic = ntohl(header[0]); magic = ntohl(header[0]);
@ -680,10 +682,10 @@ eet_identity_check(const void *data_base,
/* Verify the header */ /* Verify the header */
if (magic != EET_MAGIC_SIGN) if (magic != EET_MAGIC_SIGN)
return NULL; return NULL;
if (sign_len + cert_len + sizeof(int) * 3 > signature_length) if (sign_len + cert_len + sizeof(int) * 3 > signature_length)
return NULL; 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;
@ -716,7 +718,7 @@ eet_identity_check(const void *data_base,
*/ */
err = gcry_md_open (&md, GCRY_MD_SHA1, 0); err = gcry_md_open (&md, GCRY_MD_SHA1, 0);
if (err < 0) if (err < 0)
return NULL; return NULL;
gcry_md_write(md, data_base, data_length); gcry_md_write(md, data_base, data_length);
@ -755,7 +757,7 @@ eet_identity_check(const void *data_base,
datum.size = data_length; datum.size = data_length;
if (!gnutls_x509_crt_verify_data(cert, 0, &datum, &signature)) if (!gnutls_x509_crt_verify_data(cert, 0, &datum, &signature))
return NULL; return NULL;
if (sha1) if (sha1)
{ {
@ -778,7 +780,7 @@ eet_identity_check(const void *data_base,
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) if (!x509)
return NULL; return NULL;
/* Get public key - eay */ /* Get public key - eay */
pkey = X509_get_pubkey(x509); pkey = X509_get_pubkey(x509);
@ -803,17 +805,17 @@ eet_identity_check(const void *data_base,
} }
if (err != 1) if (err != 1)
return NULL; return NULL;
# endif /* ifdef HAVE_GNUTLS */ # endif /* ifdef HAVE_GNUTLS */
if (x509_length) if (x509_length)
*x509_length = cert_len; *x509_length = cert_len;
if (raw_signature_base) if (raw_signature_base)
*raw_signature_base = sign; *raw_signature_base = sign;
if (raw_signature_length) if (raw_signature_length)
*raw_signature_length = sign_len; *raw_signature_length = sign_len;
return cert_der; return cert_der;
#else /* ifdef HAVE_SIGNATURE */ #else /* ifdef HAVE_SIGNATURE */
@ -850,23 +852,23 @@ eet_identity_certificate_print(const unsigned char *certificate,
datum.data = (void *)certificate; datum.data = (void *)certificate;
datum.size = der_length; datum.size = der_length;
if (gnutls_x509_crt_init(&cert)) if (gnutls_x509_crt_init(&cert))
goto on_error; goto on_error;
if (gnutls_x509_crt_import(cert, &datum, GNUTLS_X509_FMT_DER)) if (gnutls_x509_crt_import(cert, &datum, GNUTLS_X509_FMT_DER))
goto on_error; 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)) if (gnutls_x509_crt_print(cert, GNUTLS_X509_CRT_FULL, &datum))
goto on_error; goto on_error;
INF("Public certificate :"); INF("Public certificate :");
INF("%s", datum.data); INF("%s", datum.data);
on_error: on_error:
if (datum.data) if (datum.data)
gnutls_free(datum.data); gnutls_free(datum.data);
gnutls_x509_crt_deinit(cert); gnutls_x509_crt_deinit(cert);
# else /* ifdef HAVE_GNUTLS */ # else /* ifdef HAVE_GNUTLS */
@ -931,7 +933,7 @@ eet_cipher(const void *data,
# else /* ifdef HAVE_GNUTLS */ # else /* ifdef HAVE_GNUTLS */
/* 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 /* ifdef HAVE_GNUTLS */ # endif /* ifdef HAVE_GNUTLS */
@ -943,7 +945,7 @@ eet_cipher(const void *data,
key_material, key_material,
MAX_KEY_LEN + MAX_IV_LEN); 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);
memset(key_material, 0, sizeof (key_material)); memset(key_material, 0, sizeof (key_material));
@ -952,8 +954,8 @@ eet_cipher(const void *data,
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));
return EET_ERROR_OUT_OF_MEMORY; return EET_ERROR_OUT_OF_MEMORY;
} }
@ -970,16 +972,16 @@ eet_cipher(const void *data,
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) if (err)
goto on_error; 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) if (err)
goto on_error; goto on_error;
err = gcry_cipher_setkey(cipher, ik, MAX_KEY_LEN); err = gcry_cipher_setkey(cipher, ik, MAX_KEY_LEN);
if (err) if (err)
goto on_error; goto on_error;
memset(iv, 0, sizeof (iv)); memset(iv, 0, sizeof (iv));
memset(ik, 0, sizeof (ik)); memset(ik, 0, sizeof (ik));
@ -991,7 +993,7 @@ eet_cipher(const void *data,
NULL, NULL,
0); 0);
if (err) if (err)
goto on_error; goto on_error;
/* Gcrypt close the cipher */ /* Gcrypt close the cipher */
gcry_cipher_close(cipher); gcry_cipher_close(cipher);
@ -1005,7 +1007,7 @@ eet_cipher(const void *data,
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)) if (!EVP_EncryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, ik, iv))
goto on_error; goto on_error;
opened = 1; opened = 1;
@ -1016,24 +1018,24 @@ eet_cipher(const void *data,
if (!EVP_EncryptUpdate(&ctx, (unsigned char *)(ret + 1), &tmp_len, if (!EVP_EncryptUpdate(&ctx, (unsigned char *)(ret + 1), &tmp_len,
(unsigned char *)buffer, (unsigned char *)buffer,
size + sizeof(unsigned int))) 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, if (!EVP_EncryptFinal_ex(&ctx, ((unsigned char *)(ret + 1)) + tmp_len,
&tmp_len)) &tmp_len))
goto on_error; goto on_error;
EVP_CIPHER_CTX_cleanup(&ctx); EVP_CIPHER_CTX_cleanup(&ctx);
# endif /* ifdef HAVE_GNUTLS */ # endif /* ifdef HAVE_GNUTLS */
/* Set return values */ /* Set return values */
if (result_length) if (result_length)
*result_length = crypted_length + sizeof(unsigned int); *result_length = crypted_length + sizeof(unsigned int);
if (result) if (result)
*result = ret; *result = ret;
else else
free(ret); free(ret);
return EET_ERROR_NONE; return EET_ERROR_NONE;
@ -1044,21 +1046,21 @@ on_error:
# ifdef HAVE_GNUTLS # ifdef HAVE_GNUTLS
/* Gcrypt error */ /* Gcrypt error */
if (opened) if (opened)
gcry_cipher_close(cipher); gcry_cipher_close(cipher);
# else /* ifdef HAVE_GNUTLS */ # else /* ifdef HAVE_GNUTLS */
/* Openssl error */ /* Openssl error */
if (opened) if (opened)
EVP_CIPHER_CTX_cleanup(&ctx); EVP_CIPHER_CTX_cleanup(&ctx);
# endif /* ifdef HAVE_GNUTLS */ # endif /* ifdef HAVE_GNUTLS */
/* General error */ /* General error */
free(ret); free(ret);
if (result) if (result)
*result = NULL; *result = NULL;
if (result_length) if (result_length)
*result_length = 0; *result_length = 0;
return EET_ERROR_ENCRYPT_FAILED; return EET_ERROR_ENCRYPT_FAILED;
#else /* ifdef HAVE_CIPHER */ #else /* ifdef HAVE_CIPHER */
@ -1093,7 +1095,7 @@ eet_decipher(const void *data,
/* At least the salt and an AES block */ /* At least the salt and an AES block */
if (size < sizeof(unsigned int) + 16) if (size < sizeof(unsigned int) + 16)
return EET_ERROR_BAD_OBJECT; return EET_ERROR_BAD_OBJECT;
/* Get the salt */ /* Get the salt */
salt = *over; salt = *over;
@ -1103,20 +1105,20 @@ eet_decipher(const void *data,
sizeof(unsigned int), 2048, key_material, sizeof(unsigned int), 2048, key_material,
MAX_KEY_LEN + MAX_IV_LEN); 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);
memset(key_material, 0, sizeof (key_material)); memset(key_material, 0, sizeof (key_material));
memset(&salt, 0, sizeof (salt)); memset(&salt, 0, sizeof (salt));
/* 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) if ((tmp_len & 0x1F) != 0)
goto on_error; goto on_error;
ret = malloc(tmp_len); ret = malloc(tmp_len);
if (!ret) if (!ret)
goto on_error; goto on_error;
# ifdef HAVE_GNUTLS # ifdef HAVE_GNUTLS
gcry_error_t err = 0; gcry_error_t err = 0;
@ -1125,15 +1127,15 @@ eet_decipher(const void *data,
/* 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) if (err)
return EET_ERROR_DECRYPT_FAILED; 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) if (err)
goto on_error; goto on_error;
err = gcry_cipher_setkey(cipher, ik, MAX_KEY_LEN); err = gcry_cipher_setkey(cipher, ik, MAX_KEY_LEN);
if (err) if (err)
goto on_error; goto on_error;
memset(iv, 0, sizeof (iv)); memset(iv, 0, sizeof (iv));
memset(ik, 0, sizeof (ik)); memset(ik, 0, sizeof (ik));
@ -1142,7 +1144,7 @@ eet_decipher(const void *data,
err = gcry_cipher_decrypt(cipher, ret, tmp_len, err = gcry_cipher_decrypt(cipher, ret, tmp_len,
((unsigned int *)data) + 1, tmp_len); ((unsigned int *)data) + 1, tmp_len);
if (err) if (err)
goto on_error; goto on_error;
/* Gcrypt close the cipher */ /* Gcrypt close the cipher */
gcry_cipher_close(cipher); gcry_cipher_close(cipher);
@ -1156,7 +1158,7 @@ eet_decipher(const void *data,
opened = 1; opened = 1;
if (!EVP_DecryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, ik, iv)) if (!EVP_DecryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, ik, iv))
goto on_error; goto on_error;
memset(iv, 0, sizeof (iv)); memset(iv, 0, sizeof (iv));
memset(ik, 0, sizeof (ik)); memset(ik, 0, sizeof (ik));
@ -1164,7 +1166,7 @@ eet_decipher(const void *data,
/* 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*/
EVP_CIPHER_CTX_cleanup(&ctx); EVP_CIPHER_CTX_cleanup(&ctx);
@ -1173,18 +1175,18 @@ eet_decipher(const void *data,
tmp = *ret; tmp = *ret;
tmp = ntohl(tmp); tmp = ntohl(tmp);
if (tmp > tmp_len) if (tmp > tmp_len)
goto on_error; goto on_error;
/* Update the return values */ /* Update the return values */
if (result_length) if (result_length)
*result_length = tmp; *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);
} }
@ -1200,17 +1202,17 @@ on_error:
# ifdef HAVE_GNUTLS # ifdef HAVE_GNUTLS
# else # else
if (opened) if (opened)
EVP_CIPHER_CTX_cleanup(&ctx); EVP_CIPHER_CTX_cleanup(&ctx);
# endif /* ifdef HAVE_GNUTLS */ # endif /* ifdef HAVE_GNUTLS */
if (result) if (result)
*result = NULL; *result = NULL;
if (result_length) if (result_length)
*result_length = 0; *result_length = 0;
if (ret) if (ret)
free(ret); free(ret);
return EET_ERROR_DECRYPT_FAILED; return EET_ERROR_DECRYPT_FAILED;
#else /* ifdef HAVE_CIPHER */ #else /* ifdef HAVE_CIPHER */
@ -1240,7 +1242,7 @@ eet_hmac_sha1(const void *key,
err = gcry_md_open(&mdh, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC); err = gcry_md_open(&mdh, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC);
if (err != GPG_ERR_NO_ERROR) if (err != GPG_ERR_NO_ERROR)
return 1; return 1;
err = gcry_md_setkey(mdh, key, key_len); err = gcry_md_setkey(mdh, key, key_len);
if (err != GPG_ERR_NO_ERROR) if (err != GPG_ERR_NO_ERROR)
@ -1292,14 +1294,14 @@ eet_pbkdf2_sha1(const char *key,
buf = alloca(salt_len + 4); buf = alloca(salt_len + 4);
if (!buf) if (!buf)
return 1; 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) if (len > digest_len)
tmp_len = digest_len; tmp_len = digest_len;
else else
tmp_len = len; 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;
@ -1307,13 +1309,13 @@ eet_pbkdf2_sha1(const char *key,
tab[3] = (unsigned char)(i & 0x000000ff) >> 0; tab[3] = (unsigned char)(i & 0x000000ff) >> 0;
# ifdef HAVE_GNUTLS # ifdef HAVE_GNUTLS
memcpy(buf, salt, salt_len); memcpy(buf, salt, salt_len);
memcpy(buf + salt_len, tab, 4); memcpy(buf + salt_len, tab, 4);
eet_hmac_sha1(key, key_len, buf, salt_len + 4, digest); eet_hmac_sha1(key, key_len, buf, salt_len + 4, digest);
# else /* ifdef HAVE_GNUTLS */ # else /* ifdef HAVE_GNUTLS */
HMAC_Init(&hctx, key, key_len, EVP_sha1()); HMAC_Init(&hctx, key, key_len, EVP_sha1());
HMAC_Update(&hctx, salt, salt_len); HMAC_Update(&hctx, salt, salt_len);
HMAC_Update(&hctx, tab, 4); HMAC_Update(&hctx, tab, 4);
HMAC_Final(&hctx, digest, NULL); HMAC_Final(&hctx, digest, NULL);
# endif /* ifdef HAVE_GNUTLS */ # endif /* ifdef HAVE_GNUTLS */
memcpy(p, digest, tmp_len); memcpy(p, digest, tmp_len);
@ -1326,7 +1328,7 @@ eet_pbkdf2_sha1(const char *key,
HMAC(EVP_sha1(), key, key_len, digest, 20, digest, NULL); HMAC(EVP_sha1(), key, key_len, digest, 20, digest, NULL);
# endif /* ifdef HAVE_GNUTLS */ # endif /* ifdef HAVE_GNUTLS */
for (k = 0; k < tmp_len; k++) for (k = 0; k < tmp_len; k++)
p[k] ^= digest[k]; p[k] ^= digest[k];
} }
} }

View File

@ -16,7 +16,7 @@
# ifdef __cplusplus # ifdef __cplusplus
extern "C" extern "C"
# endif /* ifdef __cplusplus */ # endif /* ifdef __cplusplus */
void * alloca (size_t); void *alloca(size_t);
#endif /* ifdef HAVE_ALLOCA_H */ #endif /* ifdef HAVE_ALLOCA_H */
#include <string.h> #include <string.h>
@ -58,11 +58,11 @@ eet_connection_new(Eet_Read_Cb *eet_read_cb,
Eet_Connection *conn; Eet_Connection *conn;
if (!eet_read_cb || !eet_write_cb) if (!eet_read_cb || !eet_write_cb)
return NULL; return NULL;
conn = calloc(1, sizeof (Eet_Connection)); conn = calloc(1, sizeof (Eet_Connection));
if (!conn) if (!conn)
return NULL; return NULL;
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;
@ -77,7 +77,7 @@ eet_connection_received(Eet_Connection *conn,
size_t size) size_t size)
{ {
if ((!conn) || (!data) || (!size)) if ((!conn) || (!data) || (!size))
return size; return size;
do { do {
size_t copy_size; size_t copy_size;
@ -88,31 +88,31 @@ eet_connection_received(Eet_Connection *conn,
size_t packet_size; size_t packet_size;
if (size < sizeof (int) * 2) if (size < sizeof (int) * 2)
break; break;
msg = data; msg = data;
/* Check the magic */ /* Check the magic */
if (ntohl(msg[0]) != MAGIC_EET_DATA_PACKET) if (ntohl(msg[0]) != MAGIC_EET_DATA_PACKET)
break; break;
packet_size = ntohl(msg[1]); packet_size = ntohl(msg[1]);
/* Message should always be under 64K */ /* Message should always be under 64K */
if (packet_size > 64 * 1024) if (packet_size > 64 * 1024)
break; break;
data = (void *)(msg + 2); data = (void *)(msg + 2);
size -= sizeof (int) * 2; size -= sizeof (int) * 2;
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;
continue; continue;
} }
conn->size = packet_size; conn->size = packet_size;
@ -122,7 +122,7 @@ eet_connection_received(Eet_Connection *conn,
tmp = realloc(conn->buffer, conn->size); tmp = realloc(conn->buffer, conn->size);
if (!tmp) if (!tmp)
break; break;
conn->buffer = tmp; conn->buffer = tmp;
conn->allocated = conn->size; conn->allocated = conn->size;
@ -131,8 +131,8 @@ eet_connection_received(Eet_Connection *conn,
/* Partial receive */ /* Partial receive */
copy_size = copy_size =
(conn->size - conn->received >= (conn->size - conn->received >=
size) ? size : conn->size - conn->received; size) ? size : conn->size - conn->received;
memcpy((char *)conn->buffer + conn->received, data, copy_size); memcpy((char *)conn->buffer + conn->received, data, copy_size);
conn->received += copy_size; conn->received += copy_size;
@ -150,9 +150,9 @@ eet_connection_received(Eet_Connection *conn,
/* Completed a packet. */ /* Completed a packet. */
if (!conn->eet_read_cb(conn->buffer, data_size, conn->user_data)) if (!conn->eet_read_cb(conn->buffer, data_size, conn->user_data))
{ {
/* Something goes wrong. Stop now. */ /* Something goes wrong. Stop now. */
size += data_size; size += data_size;
break; break;
} }
} }
} while (size > 0); } while (size > 0);
@ -169,7 +169,7 @@ _eet_connection_raw_send(Eet_Connection *conn,
/* Message should never be above 64K */ /* Message should never be above 64K */
if (data_size > 64 * 1024) if (data_size > 64 * 1024)
return EINA_FALSE; return EINA_FALSE;
message = alloca(data_size + sizeof (int) * 2); message = alloca(data_size + sizeof (int) * 2);
message[0] = htonl(MAGIC_EET_DATA_PACKET); message[0] = htonl(MAGIC_EET_DATA_PACKET);
@ -198,10 +198,10 @@ eet_connection_send(Eet_Connection *conn,
cipher_key, cipher_key,
&data_size); &data_size);
if (!flat_data) if (!flat_data)
return EINA_FALSE; return EINA_FALSE;
if (_eet_connection_raw_send(conn, flat_data, data_size)) if (_eet_connection_raw_send(conn, flat_data, data_size))
ret = EINA_TRUE; ret = EINA_TRUE;
free(flat_data); free(flat_data);
return ret; return ret;
@ -218,10 +218,10 @@ eet_connection_node_send(Eet_Connection *conn,
data = eet_data_node_encode_cipher(node, cipher_key, &data_size); data = eet_data_node_encode_cipher(node, cipher_key, &data_size);
if (!data) if (!data)
return EINA_FALSE; return EINA_FALSE;
if (_eet_connection_raw_send(conn, data, data_size)) if (_eet_connection_raw_send(conn, data, data_size))
ret = EINA_TRUE; ret = EINA_TRUE;
free(data); free(data);
return ret; return ret;
@ -234,10 +234,10 @@ eet_connection_close(Eet_Connection *conn,
void *user_data; void *user_data;
if (!conn) if (!conn)
return NULL; return NULL;
if (on_going) if (on_going)
*on_going = conn->received == 0 ? EINA_FALSE : EINA_TRUE; *on_going = conn->received == 0 ? EINA_FALSE : EINA_TRUE;
user_data = conn->user_data; user_data = conn->user_data;

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,7 @@ eet_dictionary_add(void)
new = calloc(1, sizeof (Eet_Dictionary)); new = calloc(1, sizeof (Eet_Dictionary));
if (!new) if (!new)
return NULL; return NULL;
memset(new->hash, -1, sizeof (int) * 256); memset(new->hash, -1, sizeof (int) * 256);
@ -48,7 +48,7 @@ eet_dictionary_free(Eet_Dictionary *ed)
static int static int
_eet_dictionary_lookup(Eet_Dictionary *ed, _eet_dictionary_lookup(Eet_Dictionary *ed,
const char *string, const char *string,
int len, int len,
int hash) int hash)
{ {
Eina_Bool found = EINA_FALSE; Eina_Bool found = EINA_FALSE;
@ -59,22 +59,22 @@ _eet_dictionary_lookup(Eet_Dictionary *ed,
while (current != -1) while (current != -1)
{ {
if (ed->all[current].len == len) if (ed->all[current].len == len)
{ {
if (ed->all[current].str && if (ed->all[current].str &&
(ed->all[current].str == string || strcmp(ed->all[current].str, string) == 0)) (ed->all[current].str == string || strcmp(ed->all[current].str, string) == 0))
{ {
found = EINA_TRUE; found = EINA_TRUE;
break; break;
} }
} }
prev = current; prev = current;
current = ed->all[current].next; current = ed->all[current].next;
} }
if (current == -1 && found) if (current == -1 && found)
return prev; return prev;
return current; return current;
} /* _eet_dictionary_lookup */ } /* _eet_dictionary_lookup */
@ -90,7 +90,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed,
int len; int len;
if (!ed) if (!ed)
return -1; return -1;
hash = _eet_hash_gen(string, 8); hash = _eet_hash_gen(string, 8);
len = strlen(string) + 1; len = strlen(string) + 1;
@ -99,7 +99,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed,
if (idx != -1) if (idx != -1)
{ {
if (ed->all[idx].str && (ed->all[idx].str == string || strcmp(ed->all[idx].str, string) == 0)) if (ed->all[idx].str && (ed->all[idx].str == string || strcmp(ed->all[idx].str, string) == 0))
return idx; return idx;
} }
@ -112,7 +112,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed,
new = realloc(ed->all, sizeof (Eet_String) * total); new = realloc(ed->all, sizeof (Eet_String) * total);
if (!new) if (!new)
return -1; return -1;
ed->all = new; ed->all = new;
ed->total = total; ed->total = total;
@ -120,7 +120,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed,
str = eina_stringshare_add(string); str = eina_stringshare_add(string);
if (!str) if (!str)
return -1; return -1;
current = ed->all + ed->count; current = ed->all + ed->count;
@ -143,12 +143,12 @@ eet_dictionary_string_add(Eet_Dictionary *ed,
current->prev = ed->all[idx].prev; current->prev = ed->all[idx].prev;
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
ed->hash[hash] = ed->count; ed->hash[hash] = ed->count;
} }
return ed->count++; return ed->count++;
@ -159,13 +159,13 @@ eet_dictionary_string_get_size(const Eet_Dictionary *ed,
int idx) int idx)
{ {
if (!ed) if (!ed)
return 0; return 0;
if (idx < 0) if (idx < 0)
return 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;
} /* eet_dictionary_string_get_size */ } /* eet_dictionary_string_get_size */
@ -175,13 +175,13 @@ eet_dictionary_string_get_hash(const Eet_Dictionary *ed,
int idx) int idx)
{ {
if (!ed) if (!ed)
return -1; return -1;
if (idx < 0) if (idx < 0)
return -1; return -1;
if (idx < ed->count) if (idx < ed->count)
return ed->all[idx].hash; return ed->all[idx].hash;
return -1; return -1;
} /* eet_dictionary_string_get_hash */ } /* eet_dictionary_string_get_hash */
@ -191,10 +191,10 @@ eet_dictionary_string_get_char(const Eet_Dictionary *ed,
int idx) int idx)
{ {
if (!ed) if (!ed)
return NULL; return NULL;
if (idx < 0) if (idx < 0)
return NULL; return NULL;
if (idx < ed->count) if (idx < ed->count)
{ {
@ -240,9 +240,9 @@ _eet_dictionary_string_get_float_cache(const char *s,
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] == '+') if (s[4] == '+')
*result = (float)(mantisse << exponent); *result = (float)(mantisse << exponent);
else else
*result = (float)mantisse / (float)(1 << exponent); *result = (float)mantisse / (float)(1 << exponent);
return EINA_TRUE; return EINA_TRUE;
} }
@ -261,9 +261,9 @@ _eet_dictionary_string_get_double_cache(const char *s,
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] == '+') if (s[4] == '+')
*result = (double)(mantisse << exponent); *result = (double)(mantisse << exponent);
else else
*result = (double)mantisse / (float)(1 << exponent); *result = (double)mantisse / (float)(1 << exponent);
return EINA_TRUE; return EINA_TRUE;
} }
@ -277,24 +277,24 @@ _eet_dictionary_test(const Eet_Dictionary *ed,
void *result) void *result)
{ {
if (!result) if (!result)
return EINA_FALSE; return EINA_FALSE;
if (!ed) if (!ed)
return EINA_FALSE; return EINA_FALSE;
if (idx < 0) if (idx < 0)
return EINA_FALSE; return EINA_FALSE;
if (!(idx < ed->count)) if (!(idx < ed->count))
return EINA_FALSE; return EINA_FALSE;
return EINA_TRUE; return EINA_TRUE;
} /* _eet_dictionary_test */ } /* _eet_dictionary_test */
static Eet_Convert * static Eet_Convert *
eet_dictionary_convert_get(const Eet_Dictionary *ed, eet_dictionary_convert_get(const Eet_Dictionary *ed,
int idx, int idx,
const char **str) const char **str)
{ {
Eet_Convert *result; Eet_Convert *result;
@ -302,7 +302,7 @@ eet_dictionary_convert_get(const Eet_Dictionary *ed,
if (!ed->converts) if (!ed->converts)
{ {
((Eet_Dictionary*)ed)->converts = eina_hash_int32_new(free); ((Eet_Dictionary *)ed)->converts = eina_hash_int32_new(free);
goto add_convert; goto add_convert;
} }
@ -310,7 +310,7 @@ eet_dictionary_convert_get(const Eet_Dictionary *ed,
result = eina_hash_find(ed->converts, &idx); result = eina_hash_find(ed->converts, &idx);
if (result) return result; if (result) return result;
add_convert: add_convert:
result = calloc(1, sizeof (Eet_Convert)); result = calloc(1, sizeof (Eet_Convert));
eina_hash_add(ed->converts, &idx, result); eina_hash_add(ed->converts, &idx, result);
@ -326,7 +326,7 @@ eet_dictionary_string_get_float(const Eet_Dictionary *ed,
const char *str; const char *str;
if (!_eet_dictionary_test(ed, idx, result)) if (!_eet_dictionary_test(ed, idx, result))
return EINA_FALSE; return EINA_FALSE;
convert = eet_dictionary_convert_get(ed, idx, &str); convert = eet_dictionary_convert_get(ed, idx, &str);
if (!convert) return EINA_FALSE; if (!convert) return EINA_FALSE;
@ -341,7 +341,7 @@ eet_dictionary_string_get_float(const Eet_Dictionary *ed,
if (eina_convert_atod(str, ed->all[idx].len, &mantisse, if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
&exponent) == EINA_FALSE) &exponent) == EINA_FALSE)
return EINA_FALSE; return EINA_FALSE;
convert->f = ldexpf((float)mantisse, exponent); convert->f = ldexpf((float)mantisse, exponent);
} }
@ -362,7 +362,7 @@ eet_dictionary_string_get_double(const Eet_Dictionary *ed,
const char *str; const char *str;
if (!_eet_dictionary_test(ed, idx, result)) if (!_eet_dictionary_test(ed, idx, result))
return EINA_FALSE; return EINA_FALSE;
convert = eet_dictionary_convert_get(ed, idx, &str); convert = eet_dictionary_convert_get(ed, idx, &str);
if (!convert) return EINA_FALSE; if (!convert) return EINA_FALSE;
@ -377,7 +377,7 @@ eet_dictionary_string_get_double(const Eet_Dictionary *ed,
if (eina_convert_atod(str, ed->all[idx].len, &mantisse, if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
&exponent) == EINA_FALSE) &exponent) == EINA_FALSE)
return EINA_FALSE; return EINA_FALSE;
convert->d = ldexp((double)mantisse, exponent); convert->d = ldexp((double)mantisse, exponent);
} }
@ -398,7 +398,7 @@ eet_dictionary_string_get_fp(const Eet_Dictionary *ed,
const char *str; const char *str;
if (!_eet_dictionary_test(ed, idx, result)) if (!_eet_dictionary_test(ed, idx, result))
return EINA_FALSE; return EINA_FALSE;
convert = eet_dictionary_convert_get(ed, idx, &str); convert = eet_dictionary_convert_get(ed, idx, &str);
if (!convert) return EINA_FALSE; if (!convert) return EINA_FALSE;
@ -408,7 +408,7 @@ eet_dictionary_string_get_fp(const Eet_Dictionary *ed,
Eina_F32p32 fp; Eina_F32p32 fp;
if (!eina_convert_atofp(str, ed->all[idx].len, &fp)) if (!eina_convert_atofp(str, ed->all[idx].len, &fp))
return EINA_FALSE; return EINA_FALSE;
convert->fp = fp; convert->fp = fp;
convert->type |= EET_D_FIXED_POINT; convert->type |= EET_D_FIXED_POINT;
@ -425,10 +425,10 @@ eet_dictionary_string_check(Eet_Dictionary *ed,
int i; int i;
if ((!ed) || (!string)) if ((!ed) || (!string))
return 0; return 0;
if ((ed->start <= string) && (string < ed->end)) if ((ed->start <= string) && (string < ed->end))
return 1; return 1;
for (i = 0; i < ed->count; ++i) for (i = 0; i < ed->count; ++i)
if ((ed->all[i].allocated) && ed->all[i].str == string) if ((ed->all[i].allocated) && ed->all[i].str == string)

View File

@ -16,7 +16,7 @@
# ifdef __cplusplus # ifdef __cplusplus
extern "C" extern "C"
# endif /* ifdef __cplusplus */ # endif /* ifdef __cplusplus */
void * alloca (size_t); void *alloca(size_t);
#endif /* ifdef HAVE_ALLOCA_H */ #endif /* ifdef HAVE_ALLOCA_H */
#ifdef HAVE_NETINET_IN_H #ifdef HAVE_NETINET_IN_H
@ -42,7 +42,7 @@ void * alloca (size_t);
/*---*/ /*---*/
typedef struct _JPEG_error_mgr * emptr; typedef struct _JPEG_error_mgr *emptr;
/*---*/ /*---*/
@ -54,7 +54,7 @@ struct _JPEG_error_mgr
struct jpeg_membuf_src struct jpeg_membuf_src
{ {
struct jpeg_source_mgr pub; struct jpeg_source_mgr pub;
const unsigned char *buf; const unsigned char *buf;
size_t len; size_t len;
@ -65,7 +65,7 @@ static void
_eet_jpeg_membuf_src_init(j_decompress_ptr cinfo) _eet_jpeg_membuf_src_init(j_decompress_ptr cinfo)
{ {
/* FIXME: Use attribute unused */ /* FIXME: Use attribute unused */
(void)cinfo; (void)cinfo;
} /* _eet_jpeg_membuf_src_init */ } /* _eet_jpeg_membuf_src_init */
static boolean static boolean
@ -108,7 +108,7 @@ eet_jpeg_membuf_src(j_decompress_ptr cinfo,
src = calloc(1, sizeof(*src)); src = calloc(1, sizeof(*src));
if (!src) if (!src)
return -1; return -1;
src->self = src; src->self = src;
@ -143,7 +143,7 @@ static void
_eet_jpeg_membuf_dst_init(j_compress_ptr cinfo) _eet_jpeg_membuf_dst_init(j_compress_ptr cinfo)
{ {
/* FIXME: Use eina attribute */ /* FIXME: Use eina attribute */
(void)cinfo; (void)cinfo;
} /* _eet_jpeg_membuf_dst_init */ } /* _eet_jpeg_membuf_dst_init */
static boolean static boolean
@ -162,7 +162,7 @@ _eet_jpeg_membuf_dst_flush(j_compress_ptr cinfo)
} }
dst->pub.next_output_byte = dst->pub.next_output_byte =
buf + ((unsigned char *)dst->pub.next_output_byte - dst->buf); buf + ((unsigned char *)dst->pub.next_output_byte - dst->buf);
dst->buf = buf; dst->buf = buf;
dst->pub.free_in_buffer += dst->len; dst->pub.free_in_buffer += dst->len;
dst->len *= 2; dst->len *= 2;
@ -200,7 +200,7 @@ eet_jpeg_membuf_dst(j_compress_ptr cinfo,
dst = calloc(1, sizeof(*dst)); dst = calloc(1, sizeof(*dst));
if (!dst) if (!dst)
return -1; return -1;
dst->buf = malloc(32768); dst->buf = malloc(32768);
if (!dst->buf) if (!dst->buf)
@ -227,54 +227,61 @@ eet_jpeg_membuf_dst(j_compress_ptr cinfo,
/*---*/ /*---*/
static void _JPEGFatalErrorHandler(j_common_ptr cinfo); static void _JPEGFatalErrorHandler(j_common_ptr cinfo);
static void _JPEGErrorHandler(j_common_ptr cinfo); static void _JPEGErrorHandler(j_common_ptr cinfo);
static void _JPEGErrorHandler2(j_common_ptr cinfo, static void _JPEGErrorHandler2(j_common_ptr cinfo,
int msg_level); int msg_level);
static int eet_data_image_jpeg_header_decode(const void *data, static int
int size, eet_data_image_jpeg_header_decode(const void *data,
unsigned int *w, int size,
unsigned int *h); unsigned int *w,
static int eet_data_image_jpeg_rgb_decode(const void *data, unsigned int *h);
int size, static int
unsigned int src_x, eet_data_image_jpeg_rgb_decode(const void *data,
unsigned int src_y, int size,
unsigned int *d, unsigned int src_x,
unsigned int w, unsigned int src_y,
unsigned int h, unsigned int *d,
unsigned int row_stride); unsigned int w,
static void * eet_data_image_jpeg_alpha_decode(const void *data, unsigned int h,
int size, unsigned int row_stride);
unsigned int src_x, static void *
unsigned int src_y, eet_data_image_jpeg_alpha_decode(const void *data,
unsigned int *d, int size,
unsigned int w, unsigned int src_x,
unsigned int h, unsigned int src_y,
unsigned int row_stride); unsigned int *d,
static void * eet_data_image_lossless_convert(int *size, unsigned int w,
const void *data, unsigned int h,
unsigned int w, unsigned int row_stride);
unsigned int h, static void *
int alpha); eet_data_image_lossless_convert(int *size,
static void * eet_data_image_lossless_compressed_convert(int *size, const void *data,
const void *data, unsigned int w,
unsigned int w, unsigned int h,
unsigned int h, int alpha);
int alpha, static void *
int compression); eet_data_image_lossless_compressed_convert(int *size,
static void * eet_data_image_jpeg_convert(int *size, const void *data,
const void *data, unsigned int w,
unsigned int w, unsigned int h,
unsigned int h, int alpha,
int alpha, int compression);
int quality); static void *
static void * eet_data_image_jpeg_alpha_convert(int *size, eet_data_image_jpeg_convert(int *size,
const void *data, const void *data,
unsigned int w, unsigned int w,
unsigned int h, unsigned int h,
int alpha, int alpha,
int quality); int quality);
static void *
eet_data_image_jpeg_alpha_convert(int *size,
const void *data,
unsigned int w,
unsigned int h,
int alpha,
int quality);
/*---*/ /*---*/
@ -282,23 +289,23 @@ static int _eet_image_words_bigendian = -1;
/*---*/ /*---*/
#define SWAP64(x) (x) =\ #define SWAP64(x) (x) = \
((((unsigned long long)(x) & 0x00000000000000ffULL) << 56) |\ ((((unsigned long long)(x) & 0x00000000000000ffULL) << 56) | \
(((unsigned long long)(x) & 0x000000000000ff00ULL) << 40) |\ (((unsigned long long)(x) & 0x000000000000ff00ULL) << 40) | \
(((unsigned long long)(x) & 0x0000000000ff0000ULL) << 24) |\ (((unsigned long long)(x) & 0x0000000000ff0000ULL) << 24) | \
(((unsigned long long)(x) & 0x00000000ff000000ULL) << 8) |\ (((unsigned long long)(x) & 0x00000000ff000000ULL) << 8) | \
(((unsigned long long)(x) & 0x000000ff00000000ULL) >> 8) |\ (((unsigned long long)(x) & 0x000000ff00000000ULL) >> 8) | \
(((unsigned long long)(x) & 0x0000ff0000000000ULL) >> 24) |\ (((unsigned long long)(x) & 0x0000ff0000000000ULL) >> 24) | \
(((unsigned long long)(x) & 0x00ff000000000000ULL) >> 40) |\ (((unsigned long long)(x) & 0x00ff000000000000ULL) >> 40) | \
(((unsigned long long)(x) & 0xff00000000000000ULL) >> 56)) (((unsigned long long)(x) & 0xff00000000000000ULL) >> 56))
#define SWAP32(x) (x) =\ #define SWAP32(x) (x) = \
((((int)(x) & 0x000000ff) << 24) |\ ((((int)(x) & 0x000000ff) << 24) | \
(((int)(x) & 0x0000ff00) << 8) |\ (((int)(x) & 0x0000ff00) << 8) | \
(((int)(x) & 0x00ff0000) >> 8) |\ (((int)(x) & 0x00ff0000) >> 8) | \
(((int)(x) & 0xff000000) >> 24)) (((int)(x) & 0xff000000) >> 24))
#define SWAP16(x) (x) =\ #define SWAP16(x) (x) = \
((((short)(x) & 0x00ff) << 8) |\ ((((short)(x) & 0x00ff) << 8) | \
(((short)(x) & 0xff00) >> 8)) (((short)(x) & 0xff00) >> 8))
#ifdef CONV8 #ifdef CONV8
# undef CONV8 # undef CONV8
@ -336,22 +343,22 @@ _JPEGErrorHandler(j_common_ptr cinfo __UNUSED__)
{ {
/* emptr errmgr; */ /* emptr errmgr; */
/* errmgr = (emptr) cinfo->err; */ /* errmgr = (emptr) cinfo->err; */
/* cinfo->err->output_message(cinfo);*/ /* cinfo->err->output_message(cinfo);*/
/* longjmp(errmgr->setjmp_buffer, 1);*/ /* longjmp(errmgr->setjmp_buffer, 1);*/
return; return;
} /* _JPEGErrorHandler */ } /* _JPEGErrorHandler */
static void static void
_JPEGErrorHandler2(j_common_ptr cinfo __UNUSED__, _JPEGErrorHandler2(j_common_ptr cinfo __UNUSED__,
int msg_level __UNUSED__) int msg_level __UNUSED__)
{ {
/* emptr errmgr; */ /* emptr errmgr; */
/* errmgr = (emptr) cinfo->err; */ /* errmgr = (emptr) cinfo->err; */
/* cinfo->err->output_message(cinfo);*/ /* cinfo->err->output_message(cinfo);*/
/* longjmp(errmgr->setjmp_buffer, 1);*/ /* longjmp(errmgr->setjmp_buffer, 1);*/
return; return;
} /* _JPEGErrorHandler2 */ } /* _JPEGErrorHandler2 */
static int static int
@ -370,7 +377,7 @@ eet_data_image_jpeg_header_decode(const void *data,
jerr.pub.emit_message = _JPEGErrorHandler2; jerr.pub.emit_message = _JPEGErrorHandler2;
jerr.pub.output_message = _JPEGErrorHandler; jerr.pub.output_message = _JPEGErrorHandler;
if (setjmp(jerr.setjmp_buffer)) if (setjmp(jerr.setjmp_buffer))
return 0; return 0;
jpeg_create_decompress(&cinfo); jpeg_create_decompress(&cinfo);
@ -395,7 +402,7 @@ eet_data_image_jpeg_header_decode(const void *data,
jpeg_destroy_decompress(&cinfo); jpeg_destroy_decompress(&cinfo);
if ((*w < 1) || (*h < 1) || (*w > 8192) || (*h > 8192)) if ((*w < 1) || (*h < 1) || (*w > 8192) || (*h > 8192))
return 0; return 0;
return 1; return 1;
} /* eet_data_image_jpeg_header_decode */ } /* eet_data_image_jpeg_header_decode */
@ -420,7 +427,7 @@ eet_data_image_jpeg_rgb_decode(const void *data,
/* FIXME: handle src_x, src_y and row_stride correctly */ /* FIXME: handle src_x, src_y and row_stride correctly */
if (!d) if (!d)
return 0; return 0;
memset(&cinfo, 0, sizeof (struct jpeg_decompress_struct)); memset(&cinfo, 0, sizeof (struct jpeg_decompress_struct));
@ -429,7 +436,7 @@ eet_data_image_jpeg_rgb_decode(const void *data,
jerr.pub.emit_message = _JPEGErrorHandler2; jerr.pub.emit_message = _JPEGErrorHandler2;
jerr.pub.output_message = _JPEGErrorHandler; jerr.pub.output_message = _JPEGErrorHandler;
if (setjmp(jerr.setjmp_buffer)) if (setjmp(jerr.setjmp_buffer))
return 0; return 0;
jpeg_create_decompress(&cinfo); jpeg_create_decompress(&cinfo);
@ -474,13 +481,13 @@ eet_data_image_jpeg_rgb_decode(const void *data,
if (cinfo.output_components == 3) if (cinfo.output_components == 3)
{ {
for (i = 0; i < (unsigned int)cinfo.rec_outbuf_height; i++) for (i = 0; i < (unsigned int)cinfo.rec_outbuf_height; i++)
line[i] = tdata + (i * (iw) * 3); line[i] = tdata + (i * (iw) * 3);
for (l = 0; l < ih; l += cinfo.rec_outbuf_height) for (l = 0; l < ih; l += cinfo.rec_outbuf_height)
{ {
jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
scans = cinfo.rec_outbuf_height; scans = cinfo.rec_outbuf_height;
if ((ih - l) < scans) if ((ih - l) < scans)
scans = ih - l; scans = ih - l;
ptr = tdata; ptr = tdata;
@ -488,7 +495,7 @@ eet_data_image_jpeg_rgb_decode(const void *data,
{ {
y = src_y - l; y = src_y - l;
if (src_y < l) if (src_y < l)
y = 0; y = 0;
for (ptr += 3 * iw * y; y < scans && (y + l) < (src_y + h); for (ptr += 3 * iw * y; y < scans && (y + l) < (src_y + h);
y++) y++)
@ -498,8 +505,8 @@ eet_data_image_jpeg_rgb_decode(const void *data,
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
{ {
*ptr2 = *ptr2 =
(0xff000000) | (0xff000000) |
((ptr[0]) << 16) | ((ptr[1]) << 8) | (ptr[2]); ((ptr[0]) << 16) | ((ptr[1]) << 8) | (ptr[2]);
ptr += 3; ptr += 3;
ptr2++; ptr2++;
} }
@ -512,13 +519,13 @@ eet_data_image_jpeg_rgb_decode(const void *data,
else if (cinfo.output_components == 1) else if (cinfo.output_components == 1)
{ {
for (i = 0; i < (unsigned int)cinfo.rec_outbuf_height; i++) for (i = 0; i < (unsigned int)cinfo.rec_outbuf_height; i++)
line[i] = tdata + (i * (iw)); line[i] = tdata + (i * (iw));
for (l = 0; l < (ih); l += cinfo.rec_outbuf_height) for (l = 0; l < (ih); l += cinfo.rec_outbuf_height)
{ {
jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
scans = cinfo.rec_outbuf_height; scans = cinfo.rec_outbuf_height;
if (((ih) - l) < scans) if (((ih) - l) < scans)
scans = (ih) - l; scans = (ih) - l;
ptr = tdata; ptr = tdata;
@ -526,7 +533,7 @@ eet_data_image_jpeg_rgb_decode(const void *data,
{ {
y = src_y - l; y = src_y - l;
if (src_y < l) if (src_y < l)
y = 0; y = 0;
for (ptr += iw * y; y < scans && (y + l) < (src_y + h); y++) for (ptr += iw * y; y < scans && (y + l) < (src_y + h); y++)
{ {
@ -535,8 +542,8 @@ eet_data_image_jpeg_rgb_decode(const void *data,
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
{ {
*ptr2 = *ptr2 =
(0xff000000) | (0xff000000) |
((ptr[0]) << 16) | ((ptr[0]) << 8) | (ptr[0]); ((ptr[0]) << 16) | ((ptr[0]) << 8) | (ptr[0]);
ptr++; ptr++;
ptr2++; ptr2++;
} }
@ -577,7 +584,7 @@ eet_data_image_jpeg_alpha_decode(const void *data,
jerr.pub.emit_message = _JPEGErrorHandler2; jerr.pub.emit_message = _JPEGErrorHandler2;
jerr.pub.output_message = _JPEGErrorHandler; jerr.pub.output_message = _JPEGErrorHandler;
if (setjmp(jerr.setjmp_buffer)) if (setjmp(jerr.setjmp_buffer))
return NULL; return NULL;
jpeg_create_decompress(&cinfo); jpeg_create_decompress(&cinfo);
@ -621,13 +628,13 @@ eet_data_image_jpeg_alpha_decode(const void *data,
if (cinfo.output_components == 1) if (cinfo.output_components == 1)
{ {
for (i = 0; i < (unsigned int)cinfo.rec_outbuf_height; i++) for (i = 0; i < (unsigned int)cinfo.rec_outbuf_height; i++)
line[i] = tdata + (i * w); line[i] = tdata + (i * w);
for (l = 0; l < h; l += cinfo.rec_outbuf_height) for (l = 0; l < h; l += cinfo.rec_outbuf_height)
{ {
jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
scans = cinfo.rec_outbuf_height; scans = cinfo.rec_outbuf_height;
if ((h - l) < scans) if ((h - l) < scans)
scans = h - l; scans = h - l;
ptr = tdata; ptr = tdata;
@ -635,7 +642,7 @@ eet_data_image_jpeg_alpha_decode(const void *data,
{ {
y = src_y - l; y = src_y - l;
if (src_y < l) if (src_y < l)
y = 0; y = 0;
for (ptr += iw * y; y < scans && (y + l) < (src_y + h); y++) for (ptr += iw * y; y < scans && (y + l) < (src_y + h); y++)
{ {
@ -644,8 +651,8 @@ eet_data_image_jpeg_alpha_decode(const void *data,
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
{ {
*ptr2 = *ptr2 =
((*ptr2) & 0x00ffffff) | ((*ptr2) & 0x00ffffff) |
((ptr[0]) << 24); ((ptr[0]) << 24);
ptr++; ptr++;
ptr2++; ptr2++;
} }
@ -675,9 +682,9 @@ eet_data_image_lossless_convert(int *size,
v = htonl(0x12345678); v = htonl(0x12345678);
if (v == 0x12345678) if (v == 0x12345678)
_eet_image_words_bigendian = 1; _eet_image_words_bigendian = 1;
else else
_eet_image_words_bigendian = 0; _eet_image_words_bigendian = 0;
} }
{ {
@ -686,7 +693,7 @@ eet_data_image_lossless_convert(int *size,
d = malloc((w * h * 4) + (8 * 4)); d = malloc((w * h * 4) + (8 * 4));
if (!d) if (!d)
return NULL; return NULL;
header = (int *)d; header = (int *)d;
memset(d, 0, 32); memset(d, 0, 32);
@ -724,9 +731,9 @@ eet_data_image_lossless_compressed_convert(int *size,
v = htonl(0x12345678); v = htonl(0x12345678);
if (v == 0x12345678) if (v == 0x12345678)
_eet_image_words_bigendian = 1; _eet_image_words_bigendian = 1;
else else
_eet_image_words_bigendian = 0; _eet_image_words_bigendian = 0;
} }
{ {
@ -738,7 +745,7 @@ eet_data_image_lossless_compressed_convert(int *size,
d = malloc((w * h * 4) + (8 * 4)); d = malloc((w * h * 4) + (8 * 4));
if (!d) if (!d)
return NULL; return NULL;
buflen = (((w * h * 101) / 100) + 3) * 4; buflen = (((w * h * 101) / 100) + 3) * 4;
comp = malloc(buflen); comp = malloc(buflen);
@ -811,7 +818,7 @@ eet_data_image_jpeg_convert(int *size,
jerr.pub.emit_message = _JPEGErrorHandler2; jerr.pub.emit_message = _JPEGErrorHandler2;
jerr.pub.output_message = _JPEGErrorHandler; jerr.pub.output_message = _JPEGErrorHandler;
if (setjmp(jerr.setjmp_buffer)) if (setjmp(jerr.setjmp_buffer))
return NULL; return NULL;
jpeg_create_compress(&cinfo); jpeg_create_compress(&cinfo);
@ -884,9 +891,9 @@ eet_data_image_jpeg_alpha_convert(int *size,
v = htonl(0x12345678); v = htonl(0x12345678);
if (v == 0x12345678) if (v == 0x12345678)
_eet_image_words_bigendian = 1; _eet_image_words_bigendian = 1;
else else
_eet_image_words_bigendian = 0; _eet_image_words_bigendian = 0;
} }
{ {
@ -905,7 +912,7 @@ eet_data_image_jpeg_alpha_convert(int *size,
jerr.pub.emit_message = _JPEGErrorHandler2; jerr.pub.emit_message = _JPEGErrorHandler2;
jerr.pub.output_message = _JPEGErrorHandler; jerr.pub.output_message = _JPEGErrorHandler;
if (setjmp(jerr.setjmp_buffer)) if (setjmp(jerr.setjmp_buffer))
return NULL; return NULL;
jpeg_create_compress(&cinfo); jpeg_create_compress(&cinfo);
if (eet_jpeg_membuf_dst(&cinfo, &dst, &sz)) if (eet_jpeg_membuf_dst(&cinfo, &dst, &sz))
@ -1042,7 +1049,7 @@ eet_data_image_jpeg_alpha_convert(int *size,
for (i = 0; i < 3; i++) SWAP32(header[i]); for (i = 0; i < 3; i++) SWAP32(header[i]);
} }
memcpy(d + 12, d1, sz1); memcpy(d + 12, d1, sz1);
memcpy(d + 12 + sz1, d2, sz2); memcpy(d + 12 + sz1, d2, sz2);
free(d1); free(d1);
@ -1119,20 +1126,20 @@ eet_data_image_read_cipher(Eet_File *ef,
int size; int size;
if (!cipher_key) if (!cipher_key)
data = (void *)eet_read_direct(ef, name, &size); data = (void *)eet_read_direct(ef, name, &size);
if (!data) if (!data)
{ {
data = eet_read_cipher(ef, name, &size, cipher_key); data = eet_read_cipher(ef, name, &size, cipher_key);
free_data = 1; free_data = 1;
if (!data) if (!data)
return NULL; return NULL;
} }
d = eet_data_image_decode(data, size, w, h, alpha, comp, quality, lossy); d = eet_data_image_decode(data, size, w, h, alpha, comp, quality, lossy);
if (free_data) if (free_data)
free(data); free(data);
return d; return d;
} /* eet_data_image_read_cipher */ } /* eet_data_image_read_cipher */
@ -1172,14 +1179,14 @@ eet_data_image_read_to_surface_cipher(Eet_File *ef,
int size; int size;
if (!cipher_key) if (!cipher_key)
data = (void *)eet_read_direct(ef, name, &size); data = (void *)eet_read_direct(ef, name, &size);
if (!data) if (!data)
{ {
data = eet_read_cipher(ef, name, &size, cipher_key); data = eet_read_cipher(ef, name, &size, cipher_key);
free_data = 1; free_data = 1;
if (!data) if (!data)
return 0; return 0;
} }
res = eet_data_image_decode_to_surface(data, size, src_x, src_y, d, res = eet_data_image_decode_to_surface(data, size, src_x, src_y, d,
@ -1187,7 +1194,7 @@ eet_data_image_read_to_surface_cipher(Eet_File *ef,
comp, quality, lossy); comp, quality, lossy);
if (free_data) if (free_data)
free(data); free(data);
return res; return res;
} /* eet_data_image_read_to_surface_cipher */ } /* eet_data_image_read_to_surface_cipher */
@ -1230,20 +1237,20 @@ eet_data_image_header_read_cipher(Eet_File *ef,
int d; int d;
if (!cipher_key) if (!cipher_key)
data = (void *)eet_read_direct(ef, name, &size); data = (void *)eet_read_direct(ef, name, &size);
if (!data) if (!data)
{ {
data = eet_read_cipher(ef, name, &size, cipher_key); data = eet_read_cipher(ef, name, &size, cipher_key);
free_data = 1; free_data = 1;
if (!data) if (!data)
return 0; return 0;
} }
d = eet_data_image_header_decode(data, size, w, h, alpha, d = eet_data_image_header_decode(data, size, w, h, alpha,
comp, quality, lossy); comp, quality, lossy);
if (free_data) if (free_data)
free(data); free(data);
return d; return d;
} /* eet_data_image_header_read_cipher */ } /* eet_data_image_header_read_cipher */
@ -1282,21 +1289,21 @@ eet_data_image_encode_cipher(const void *data,
if (lossy == 0) if (lossy == 0)
{ {
if (comp > 0) if (comp > 0)
d = eet_data_image_lossless_compressed_convert(&size, data, d = eet_data_image_lossless_compressed_convert(&size, data,
w, h, alpha, comp); w, h, alpha, comp);
/* eet_data_image_lossless_compressed_convert will refuse to compress something /* eet_data_image_lossless_compressed_convert will refuse to compress something
if the result is bigger than the entry. */ if the result is bigger than the entry. */
if (comp <= 0 || !d) if (comp <= 0 || !d)
d = eet_data_image_lossless_convert(&size, data, w, h, alpha); d = eet_data_image_lossless_convert(&size, data, w, h, alpha);
} }
else else
{ {
if (!alpha) if (!alpha)
d = eet_data_image_jpeg_convert(&size, data, w, h, alpha, quality); d = eet_data_image_jpeg_convert(&size, data, w, h, alpha, quality);
else else
d = eet_data_image_jpeg_alpha_convert(&size, data, d = eet_data_image_jpeg_alpha_convert(&size, data,
w, h, alpha, quality); w, h, alpha, quality);
} }
if (cipher_key) if (cipher_key)
@ -1305,18 +1312,18 @@ eet_data_image_encode_cipher(const void *data,
&ciphered_sz)) &ciphered_sz))
{ {
if (d) if (d)
free(d); free(d);
d = ciphered_d; d = ciphered_d;
size = ciphered_sz; size = ciphered_sz;
} }
else else
if (ciphered_d) if (ciphered_d)
free(ciphered_d); free(ciphered_d);
} }
if (size_ret) if (size_ret)
*size_ret = size; *size_ret = size;
return d; return d;
} /* eet_data_image_encode_cipher */ } /* eet_data_image_encode_cipher */
@ -1360,7 +1367,7 @@ eet_data_image_header_decode_cipher(const void *data,
} }
else else
if (deciphered_d) if (deciphered_d)
free(deciphered_d); free(deciphered_d);
} }
if (_eet_image_words_bigendian == -1) if (_eet_image_words_bigendian == -1)
@ -1369,13 +1376,13 @@ eet_data_image_header_decode_cipher(const void *data,
v = htonl(0x12345678); v = htonl(0x12345678);
if (v == 0x12345678) if (v == 0x12345678)
_eet_image_words_bigendian = 1; _eet_image_words_bigendian = 1;
else else
_eet_image_words_bigendian = 0; _eet_image_words_bigendian = 0;
} }
if (size < 32) if (size < 32)
return 0; return 0;
memcpy(header, data, 32); memcpy(header, data, 32);
if (_eet_image_words_bigendian) if (_eet_image_words_bigendian)
@ -1394,28 +1401,28 @@ eet_data_image_header_decode_cipher(const void *data,
al = header[3]; al = header[3];
cp = header[4]; cp = header[4];
if ((iw < 1) || (ih < 1) || (iw > 8192) || (ih > 8192)) if ((iw < 1) || (ih < 1) || (iw > 8192) || (ih > 8192))
return 0; return 0;
if ((cp == 0) && (size < ((iw * ih * 4) + 32))) if ((cp == 0) && (size < ((iw * ih * 4) + 32)))
return 0; return 0;
if (w) if (w)
*w = iw; *w = iw;
if (h) if (h)
*h = ih; *h = ih;
if (alpha) if (alpha)
*alpha = al ? 1 : 0; *alpha = al ? 1 : 0;
if (comp) if (comp)
*comp = cp; *comp = cp;
if (lossy) if (lossy)
*lossy = 0; *lossy = 0;
if (quality) if (quality)
*quality = 100; *quality = 100;
return 1; return 1;
} }
@ -1434,22 +1441,22 @@ eet_data_image_header_decode_cipher(const void *data,
if (ok) if (ok)
{ {
if (w) if (w)
*w = iw; *w = iw;
if (h) if (h)
*h = ih; *h = ih;
if (alpha) if (alpha)
*alpha = 1; *alpha = 1;
if (comp) if (comp)
*comp = 0; *comp = 0;
if (lossy) if (lossy)
*lossy = 1; *lossy = 1;
if (quality) if (quality)
*quality = 75; *quality = 75;
return 1; return 1;
} }
@ -1463,22 +1470,22 @@ eet_data_image_header_decode_cipher(const void *data,
if (ok) if (ok)
{ {
if (w) if (w)
*w = iw; *w = iw;
if (h) if (h)
*h = ih; *h = ih;
if (alpha) if (alpha)
*alpha = 0; *alpha = 0;
if (comp) if (comp)
*comp = 0; *comp = 0;
if (lossy) if (lossy)
*lossy = 1; *lossy = 1;
if (quality) if (quality)
*quality = 75; *quality = 75;
return 1; return 1;
} }
@ -1521,14 +1528,14 @@ _eet_data_image_copy_buffer(const unsigned int *src,
src += src_x + src_y * src_w; src += src_x + src_y * src_w;
if (row_stride == src_w * 4 && w == src_w) if (row_stride == src_w * 4 && w == src_w)
memcpy(dst, src, row_stride * h); memcpy(dst, src, row_stride * h);
else else
{ {
unsigned int *over = dst; unsigned int *over = dst;
unsigned int y; unsigned int y;
for (y = 0; y < h; ++y, src += src_w, over += row_stride) for (y = 0; y < h; ++y, src += src_w, over += row_stride)
memcpy(over, src, w * 4); memcpy(over, src, w * 4);
} }
} /* _eet_data_image_copy_buffer */ } /* _eet_data_image_copy_buffer */
@ -1554,8 +1561,8 @@ _eet_data_image_decode_inside(const void *data,
body = ((unsigned int *)data) + 8; body = ((unsigned int *)data) + 8;
if (!comp) if (!comp)
_eet_data_image_copy_buffer(body, src_x, src_y, src_w, d, _eet_data_image_copy_buffer(body, src_x, src_y, src_w, d,
w, h, row_stride); w, h, row_stride);
else else
{ {
if (src_h == h && src_w == w && row_stride == src_w * 4) if (src_h == h && src_w == w && row_stride == src_w * 4)
@ -1571,11 +1578,11 @@ _eet_data_image_decode_inside(const void *data,
Bytef *dtmp; Bytef *dtmp;
uLongf dlen = src_w * src_h * 4; uLongf dlen = src_w * src_h * 4;
/* FIXME: This could create a huge alloc. So compressed /* FIXME: This could create a huge alloc. So compressed
data and tile could not always work. */ data and tile could not always work. */
dtmp = malloc(dlen); dtmp = malloc(dlen);
if (!dtmp) if (!dtmp)
return 0; return 0;
uncompress(dtmp, &dlen, (Bytef *)body, (uLongf)(size - 32)); uncompress(dtmp, &dlen, (Bytef *)body, (uLongf)(size - 32));
@ -1622,15 +1629,15 @@ _eet_data_image_decode_inside(const void *data,
dt += sz1; dt += sz1;
if (!eet_data_image_jpeg_alpha_decode(dt, sz2, src_x, src_y, if (!eet_data_image_jpeg_alpha_decode(dt, sz2, src_x, src_y,
d, w, h, row_stride)) d, w, h, row_stride))
return 0; return 0;
} }
} }
else if (!eet_data_image_jpeg_rgb_decode(data, size, src_x, src_y, d, w, else if (!eet_data_image_jpeg_rgb_decode(data, size, src_x, src_y, d, w,
h, row_stride)) h, row_stride))
return 0; return 0;
} }
else else
abort(); abort();
return 1; return 1;
} /* _eet_data_image_decode_inside */ } /* _eet_data_image_decode_inside */
@ -1662,17 +1669,17 @@ eet_data_image_decode_cipher(const void *data,
} }
else else
if (deciphered_d) if (deciphered_d)
free(deciphered_d); free(deciphered_d);
} }
/* All check are done during header decode, this simplify the code a lot. */ /* All check are done during header decode, this simplify the code a lot. */
if (!eet_data_image_header_decode(data, size, &iw, &ih, &ialpha, &icompress, if (!eet_data_image_header_decode(data, size, &iw, &ih, &ialpha, &icompress,
&iquality, &ilossy)) &iquality, &ilossy))
return NULL; return NULL;
d = malloc(iw * ih * 4); d = malloc(iw * ih * 4);
if (!d) if (!d)
return NULL; return NULL;
if (!_eet_data_image_decode_inside(data, size, 0, 0, iw, ih, d, iw, ih, iw * if (!_eet_data_image_decode_inside(data, size, 0, 0, iw, ih, d, iw, ih, iw *
4, ialpha, icompress, iquality, ilossy)) 4, ialpha, icompress, iquality, ilossy))
@ -1682,22 +1689,22 @@ eet_data_image_decode_cipher(const void *data,
} }
if (w) if (w)
*w = iw; *w = iw;
if (h) if (h)
*h = ih; *h = ih;
if (alpha) if (alpha)
*alpha = ialpha; *alpha = ialpha;
if (comp) if (comp)
*comp = icompress; *comp = icompress;
if (quality) if (quality)
*quality = iquality; *quality = iquality;
if (lossy) if (lossy)
*lossy = ilossy; *lossy = ilossy;
return d; return d;
} /* eet_data_image_decode_cipher */ } /* eet_data_image_decode_cipher */
@ -1746,39 +1753,39 @@ eet_data_image_decode_to_surface_cipher(const void *data,
} }
else else
if (deciphered_d) if (deciphered_d)
free(deciphered_d); free(deciphered_d);
} }
/* All check are done during header decode, this simplify the code a lot. */ /* All check are done during header decode, this simplify the code a lot. */
if (!eet_data_image_header_decode(data, size, &iw, &ih, &ialpha, &icompress, if (!eet_data_image_header_decode(data, size, &iw, &ih, &ialpha, &icompress,
&iquality, &ilossy)) &iquality, &ilossy))
return 0; return 0;
if (!d) if (!d)
return 0; return 0;
if (w * 4 > row_stride) if (w * 4 > row_stride)
return 0; return 0;
if (w > iw || h > ih) if (w > iw || h > ih)
return 0; return 0;
if (!_eet_data_image_decode_inside(data, size, src_x, src_y, iw, ih, d, w, h, if (!_eet_data_image_decode_inside(data, size, src_x, src_y, iw, ih, d, w, h,
row_stride, ialpha, icompress, iquality, row_stride, ialpha, icompress, iquality,
ilossy)) ilossy))
return 0; return 0;
if (alpha) if (alpha)
*alpha = ialpha; *alpha = ialpha;
if (comp) if (comp)
*comp = icompress; *comp = icompress;
if (quality) if (quality)
*quality = iquality; *quality = iquality;
if (lossy) if (lossy)
*lossy = ilossy; *lossy = ilossy;
return 1; return 1;
} /* eet_data_image_decode_to_surface_cipher */ } /* eet_data_image_decode_to_surface_cipher */
@ -1798,8 +1805,8 @@ eet_data_image_decode_to_surface(const void *data,
int *lossy) int *lossy)
{ {
return eet_data_image_decode_to_surface_cipher(data, NULL, size, return eet_data_image_decode_to_surface_cipher(data, NULL, size,
src_x, src_y, d, src_x, src_y, d,
w, h, row_stride, w, h, row_stride,
alpha, comp, quality, alpha, comp, quality,
lossy); lossy);
} /* eet_data_image_decode_to_surface */ } /* eet_data_image_decode_to_surface */

File diff suppressed because it is too large Load Diff

View File

@ -23,7 +23,7 @@ eet_node_new(void)
result = eina_mempool_malloc(_eet_node_mp, sizeof (Eet_Node)); result = eina_mempool_malloc(_eet_node_mp, sizeof (Eet_Node));
if (!result) if (!result)
return NULL; return NULL;
memset(result, 0, sizeof (Eet_Node)); memset(result, 0, sizeof (Eet_Node));
return result; return result;
@ -43,7 +43,7 @@ _eet_node_new(const char *name,
n = eet_node_new(); n = eet_node_new();
if (!n) if (!n)
return NULL; return NULL;
n->type = type; n->type = type;
n->name = eina_stringshare_add(name); n->name = eina_stringshare_add(name);
@ -52,57 +52,58 @@ _eet_node_new(const char *name,
} /* _eet_node_new */ } /* _eet_node_new */
static void static void
_eet_node_append(Eet_Node *n, Eina_List *nodes) _eet_node_append(Eet_Node *n,
Eina_List *nodes)
{ {
Eet_Node *value; Eet_Node *value;
Eina_List *l; Eina_List *l;
EINA_LIST_REVERSE_FOREACH(nodes, l, value) EINA_LIST_REVERSE_FOREACH(nodes, l, value)
{ {
value->next = n->values; value->next = n->values;
n->values = value; n->values = value;
} }
} /* _eet_node_append */ } /* _eet_node_append */
#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; \
\ \
return n;\ return n; \
} }
#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); \
\ \
return n;\ return n; \
} }
EET_NODE_NEW(EET_T_CHAR, char, c, char) EET_NODE_NEW(EET_T_CHAR, char, c, char)
EET_NODE_NEW(EET_T_SHORT, short, s, short) EET_NODE_NEW(EET_T_SHORT, short, s, short)
EET_NODE_NEW(EET_T_INT, int, i, int) EET_NODE_NEW(EET_T_INT, int, i, int)
EET_NODE_NEW(EET_T_LONG_LONG, long_long, l, long long) EET_NODE_NEW(EET_T_LONG_LONG, long_long, l, long long)
EET_NODE_NEW(EET_T_FLOAT, float, f, float) EET_NODE_NEW(EET_T_FLOAT, float, f, float)
EET_NODE_NEW(EET_T_DOUBLE, double, d, double) EET_NODE_NEW(EET_T_DOUBLE, double, d, double)
EET_NODE_NEW(EET_T_UCHAR, unsigned_char, uc, unsigned char) EET_NODE_NEW(EET_T_UCHAR, unsigned_char, uc, unsigned char)
EET_NODE_NEW(EET_T_USHORT, unsigned_short, us, unsigned short) EET_NODE_NEW(EET_T_USHORT, unsigned_short, us, unsigned short)
EET_NODE_NEW(EET_T_UINT, unsigned_int, ui, unsigned int) EET_NODE_NEW(EET_T_UINT, unsigned_int, ui, unsigned int)
EET_NODE_NEW(EET_T_ULONG_LONG, unsigned_long_long, ul, unsigned long long) EET_NODE_NEW(EET_T_ULONG_LONG, unsigned_long_long, ul, unsigned long long)
EET_NODE_STR_NEW(EET_T_STRING, string, str, const char *) EET_NODE_STR_NEW(EET_T_STRING, string, str, const char *)
EET_NODE_STR_NEW(EET_T_INLINED_STRING, inlined_string, str, const char *) EET_NODE_STR_NEW(EET_T_INLINED_STRING, inlined_string, str, const char *)
Eet_Node * Eet_Node *
@ -112,7 +113,7 @@ eet_node_null_new(const char *name)
n = _eet_node_new(name, EET_T_NULL); n = _eet_node_new(name, EET_T_NULL);
if (!n) if (!n)
return NULL; return NULL;
n->data.value.str = NULL; n->data.value.str = NULL;
@ -127,7 +128,7 @@ eet_node_list_new(const char *name,
n = _eet_node_new(name, EET_G_LIST); n = _eet_node_new(name, EET_G_LIST);
if (!n) if (!n)
return NULL; return NULL;
_eet_node_append(n, nodes); _eet_node_append(n, nodes);
@ -143,7 +144,7 @@ eet_node_array_new(const char *name,
n = _eet_node_new(name, EET_G_ARRAY); n = _eet_node_new(name, EET_G_ARRAY);
if (!n) if (!n)
return NULL; return NULL;
n->count = count; n->count = count;
@ -160,7 +161,7 @@ eet_node_var_array_new(const char *name,
n = _eet_node_new(name, EET_G_VAR_ARRAY); n = _eet_node_new(name, EET_G_VAR_ARRAY);
if (!n) if (!n)
return NULL; return NULL;
n->count = eina_list_count(nodes); n->count = eina_list_count(nodes);
@ -178,11 +179,11 @@ eet_node_hash_new(const char *name,
Eet_Node *n; Eet_Node *n;
if (!node) if (!node)
return NULL; return NULL;
n = _eet_node_new(name, EET_G_HASH); n = _eet_node_new(name, EET_G_HASH);
if (!n) if (!n)
return NULL; 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);
@ -200,7 +201,7 @@ eet_node_struct_new(const char *name,
n = _eet_node_new(name, EET_G_UNKNOWN); n = _eet_node_new(name, EET_G_UNKNOWN);
if (!n) if (!n)
return NULL; return NULL;
_eet_node_append(n, nodes); _eet_node_append(n, nodes);
@ -216,11 +217,11 @@ eet_node_struct_child_new(const char *parent,
if (!child) return NULL; if (!child) return NULL;
if (child->type != EET_G_UNKNOWN) if (child->type != EET_G_UNKNOWN)
return child; return child;
n = _eet_node_new(parent, EET_G_UNKNOWN); n = _eet_node_new(parent, EET_G_UNKNOWN);
if (!n) if (!n)
return NULL; return NULL;
_eet_node_append(n, eina_list_prepend(NULL, child)); _eet_node_append(n, eina_list_prepend(NULL, child));
@ -260,25 +261,25 @@ eet_node_list_append(Eet_Node *parent,
tmp = eina_stringshare_add(name); tmp = eina_stringshare_add(name);
for (nn = parent->values; nn; nn = nn->next) for (nn = parent->values; nn; nn = nn->next)
if (nn->name == tmp && nn->type == EET_G_LIST) if (nn->name == tmp && nn->type == EET_G_LIST)
{ {
Eet_Node *n; Eet_Node *n;
if (!nn->values) if (!nn->values)
nn->values = child; 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. */
nn = eet_node_list_new(tmp, eina_list_append(NULL, child)); nn = eet_node_list_new(tmp, eina_list_append(NULL, child));
@ -312,18 +313,18 @@ eet_node_struct_append(Eet_Node *parent,
tmp = eina_stringshare_add(name); tmp = eina_stringshare_add(name);
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) if (prev)
prev->next = nn->next; prev->next = nn->next;
else else
parent->values = nn->next; parent->values = nn->next;
nn->next = NULL; nn->next = NULL;
eet_node_del(nn); eet_node_del(nn);
break; break;
} }
if (prev) if (prev)
{ {
@ -357,7 +358,6 @@ eet_node_hash_add(Eet_Node *parent,
parent->values = nn; parent->values = nn;
} /* eet_node_hash_add */ } /* eet_node_hash_add */
int int
eet_node_type_get(Eet_Node *node) eet_node_type_get(Eet_Node *node)
{ {
@ -386,29 +386,29 @@ eet_node_del(Eet_Node *n)
Eet_Node *tmp; Eet_Node *tmp;
if (!n) if (!n)
return; 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:
case EET_G_LIST: case EET_G_LIST:
for (nn = n->values; nn; ) for (nn = n->values; nn; )
{ {
tmp = nn; tmp = nn;
nn = nn->next; nn = nn->next;
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:
@ -419,7 +419,7 @@ eet_node_del(Eet_Node *n)
case EET_T_UCHAR: case EET_T_UCHAR:
case EET_T_USHORT: case EET_T_USHORT:
case EET_T_UINT: case EET_T_UINT:
break; break;
} /* switch */ } /* switch */
eina_stringshare_del(n->name); eina_stringshare_del(n->name);
@ -451,9 +451,9 @@ static const char *eet_node_dump_t_name[14][2] = {
}; };
static void static void
eet_node_dump_level(int level, eet_node_dump_level(int level,
Eet_Dump_Callback dumpfunc, Eet_Dump_Callback dumpfunc,
void *dumpdata) void *dumpdata)
{ {
int i; int i;
@ -470,17 +470,17 @@ eet_node_string_escape(const char *str)
for (strp = str; *strp; strp++) for (strp = str; *strp; strp++)
{ {
if (*strp == '\"') if (*strp == '\"')
sz += 2; sz += 2;
else if (*strp == '\\') else if (*strp == '\\')
sz += 2; sz += 2;
else if (*strp == '\n') else if (*strp == '\n')
sz += 2; sz += 2;
else else
sz += 1; sz += 1;
} }
s = malloc(sz + 1); s = malloc(sz + 1);
if (!s) if (!s)
return NULL; return NULL;
for (strp = str, sp = s; *strp; strp++, sp++) for (strp = str, sp = s; *strp; strp++, sp++)
{ {
@ -493,33 +493,34 @@ eet_node_string_escape(const char *str)
} }
if (*strp == '\n') if (*strp == '\n')
*sp = 'n'; *sp = 'n';
else else
*sp = *strp; *sp = *strp;
} }
*sp = 0; *sp = 0;
return s; return s;
} /* eet_node_string_escape */ } /* eet_node_string_escape */
static void static void
eet_node_dump_string_escape(void *dumpdata, eet_node_dump_string_escape(void *dumpdata,
Eet_Dump_Callback dumpfunc, Eet_Dump_Callback dumpfunc,
const char *str) const char *str)
{ {
char *s; char *s;
s = eet_node_string_escape(str); s = eet_node_string_escape(str);
if (!s) if (!s)
return; return;
dumpfunc(dumpdata, s); dumpfunc(dumpdata, s);
free(s); free(s);
} /* eet_node_dump_string_escape */ } /* eet_node_dump_string_escape */
static void static void
eet_node_dump_simple_type(Eet_Node *n, int level, eet_node_dump_simple_type(Eet_Node *n,
int level,
Eet_Dump_Callback dumpfunc, Eet_Dump_Callback dumpfunc,
void *dumpdata) void *dumpdata)
{ {
const char *type_name = NULL; const char *type_name = NULL;
char tbuf[256]; char tbuf[256];
@ -533,95 +534,95 @@ eet_node_dump_simple_type(Eet_Node *n, int level,
# undef EET_T_TYPE # undef EET_T_TYPE
#endif /* ifdef EET_T_TYPE */ #endif /* ifdef EET_T_TYPE */
#define EET_T_TYPE(Eet_Type, Type)\ #define EET_T_TYPE(Eet_Type, Type) \
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,\ snprintf(tbuf, \
sizeof (tbuf),\ sizeof (tbuf), \
eet_node_dump_t_name[Eet_Type][1],\ eet_node_dump_t_name[Eet_Type][1], \
n->data.value.Type);\ n->data.value.Type); \
dumpfunc(dumpdata, tbuf);\ dumpfunc(dumpdata, tbuf); \
break;\ break; \
} }
switch (n->type) switch (n->type)
{ {
EET_T_TYPE(EET_T_CHAR, c); EET_T_TYPE(EET_T_CHAR, c);
EET_T_TYPE(EET_T_SHORT, s); EET_T_TYPE(EET_T_SHORT, s);
EET_T_TYPE(EET_T_INT, i); EET_T_TYPE(EET_T_INT, i);
EET_T_TYPE(EET_T_LONG_LONG, l); EET_T_TYPE(EET_T_LONG_LONG, l);
EET_T_TYPE(EET_T_FLOAT, f); EET_T_TYPE(EET_T_FLOAT, f);
EET_T_TYPE(EET_T_DOUBLE, d); EET_T_TYPE(EET_T_DOUBLE, d);
EET_T_TYPE(EET_T_UCHAR, uc); EET_T_TYPE(EET_T_UCHAR, uc);
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) if (!type_name)
type_name = "string: \""; 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;
} /* switch */ } /* switch */
dumpfunc(dumpdata, ";\n"); dumpfunc(dumpdata, ";\n");
} /* eet_node_dump_simple_type */ } /* eet_node_dump_simple_type */
static void static void
eet_node_dump_group_start(int level, eet_node_dump_group_start(int level,
Eet_Dump_Callback dumpfunc, Eet_Dump_Callback dumpfunc,
void *dumpdata, void *dumpdata,
int group_type, int group_type,
const char *name) const char *name)
{ {
int chnk_type; int chnk_type;
chnk_type = (group_type >= EET_G_UNKNOWN && group_type <= EET_G_HASH) ? chnk_type = (group_type >= EET_G_UNKNOWN && group_type <= EET_G_HASH) ?
group_type : EET_G_LAST; group_type : EET_G_LAST;
eet_node_dump_level(level, dumpfunc, dumpdata); eet_node_dump_level(level, dumpfunc, dumpdata);
dumpfunc(dumpdata, "group \""); dumpfunc(dumpdata, "group \"");
eet_node_dump_string_escape(dumpdata, dumpfunc, name); eet_node_dump_string_escape(dumpdata, dumpfunc, name);
dumpfunc(dumpdata, "\" "); dumpfunc(dumpdata, "\" ");
dumpfunc(dumpdata, eet_node_dump_g_name[chnk_type - EET_G_UNKNOWN]); dumpfunc(dumpdata, eet_node_dump_g_name[chnk_type - EET_G_UNKNOWN]);
dumpfunc(dumpdata, " {\n"); dumpfunc(dumpdata, " {\n");
} /* eet_node_dump_group_start */ } /* eet_node_dump_group_start */
static void static void
eet_node_dump_group_end(int level, eet_node_dump_group_end(int level,
Eet_Dump_Callback dumpfunc, Eet_Dump_Callback dumpfunc,
void *dumpdata) void *dumpdata)
{ {
eet_node_dump_level(level, dumpfunc, dumpdata); eet_node_dump_level(level, dumpfunc, dumpdata);
dumpfunc(dumpdata, "}\n"); dumpfunc(dumpdata, "}\n");
} /* eet_node_dump_group_end */ } /* eet_node_dump_group_end */
void void
eet_node_dump(Eet_Node *n, eet_node_dump(Eet_Node *n,
int dumplevel, int dumplevel,
Eet_Dump_Callback dumpfunc, Eet_Dump_Callback dumpfunc,
void *dumpdata) void *dumpdata)
{ {
Eet_Node *it; Eet_Node *it;
if (!n) if (!n)
return; return;
switch (n->type) switch (n->type)
{ {
@ -630,36 +631,36 @@ eet_node_dump(Eet_Node *n,
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, eet_node_dump_group_start(dumplevel,
dumpfunc, dumpfunc,
dumpdata, dumpdata,
n->type, n->type,
n->name); 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)
{ {
char tbuf[256]; char tbuf[256];
eet_node_dump_level(dumplevel, dumpfunc, dumpdata); eet_node_dump_level(dumplevel, dumpfunc, dumpdata);
dumpfunc(dumpdata, " count "); dumpfunc(dumpdata, " count ");
eina_convert_itoa(n->count, tbuf); eina_convert_itoa(n->count, tbuf);
dumpfunc(dumpdata, tbuf); dumpfunc(dumpdata, tbuf);
dumpfunc(dumpdata, ";\n"); dumpfunc(dumpdata, ";\n");
} }
else if (n->type == EET_G_HASH) else if (n->type == EET_G_HASH)
{ {
eet_node_dump_level(dumplevel, dumpfunc, dumpdata); eet_node_dump_level(dumplevel, dumpfunc, dumpdata);
dumpfunc(dumpdata, " key \""); dumpfunc(dumpdata, " key \"");
eet_node_dump_string_escape(dumpdata, dumpfunc, n->key); eet_node_dump_string_escape(dumpdata, dumpfunc, n->key);
dumpfunc(dumpdata, "\";\n"); dumpfunc(dumpdata, "\";\n");
} }
for (it = n->values; it; it = it->next) for (it = n->values; it; it = it->next)
eet_node_dump(it, dumplevel + 2, dumpfunc, dumpdata); eet_node_dump(it, dumplevel + 2, dumpfunc, dumpdata);
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:
@ -673,8 +674,8 @@ eet_node_dump(Eet_Node *n,
case EET_T_USHORT: case EET_T_USHORT:
case EET_T_UINT: case EET_T_UINT:
case EET_T_ULONG_LONG: case EET_T_ULONG_LONG:
eet_node_dump_simple_type(n, dumplevel, dumpfunc, dumpdata); eet_node_dump_simple_type(n, dumplevel, dumpfunc, dumpdata);
break; break;
} /* switch */ } /* switch */
} /* eet_node_dump */ } /* eet_node_dump */
@ -692,7 +693,7 @@ eet_node_walk(void *parent,
if (!root) if (!root)
{ {
if (parent) if (parent)
cb->struct_add(parent, name, NULL, user_data); cb->struct_add(parent, name, NULL, user_data);
return NULL; return NULL;
} }
@ -700,50 +701,50 @@ eet_node_walk(void *parent,
switch (root->type) switch (root->type)
{ {
case EET_G_UNKNOWN: case EET_G_UNKNOWN:
me = cb->struct_alloc(root->name, user_data); me = cb->struct_alloc(root->name, user_data);
for (it = root->values; it; it = it->next) for (it = root->values; it; it = it->next)
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; it = it->next) for (i = 0, it = root->values; it; it = it->next)
cb->insert(me, i++, eet_node_walk(NULL, cb->insert(me, i++, eet_node_walk(NULL,
NULL, NULL,
it, it,
cb, cb,
user_data), user_data); 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; it = it->next) for (it = root->values; it; it = it->next)
cb->append(me, eet_node_walk(NULL, cb->append(me, eet_node_walk(NULL,
NULL,
it,
cb,
user_data), user_data);
break;
case EET_G_HASH:
if (!parent)
return NULL;
return cb->hash(parent, root->name, root->key,
eet_node_walk(NULL,
NULL, NULL,
root->values, it,
cb, cb,
user_data), user_data); user_data), user_data);
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_T_STRING: case EET_T_STRING:
case EET_T_INLINED_STRING: case EET_T_INLINED_STRING:
case EET_T_CHAR: case EET_T_CHAR:
@ -756,12 +757,12 @@ eet_node_walk(void *parent,
case EET_T_USHORT: case EET_T_USHORT:
case EET_T_UINT: case EET_T_UINT:
case EET_T_ULONG_LONG: case EET_T_ULONG_LONG:
me = cb->simple(root->type, &root->data, user_data); me = cb->simple(root->type, &root->data, user_data);
break; break;
} /* switch */ } /* switch */
if (parent) if (parent)
cb->struct_add(parent, name, me, user_data); cb->struct_add(parent, name, me, user_data);
return me; return me;
} /* eet_node_walk */ } /* eet_node_walk */
@ -779,10 +780,10 @@ eet_node_init(void)
#endif #endif
tmp = getenv("EET_MEMPOOL"); tmp = getenv("EET_MEMPOOL");
if (tmp && tmp[0]) if (tmp && tmp[0])
choice = tmp; choice = tmp;
_eet_node_mp = _eet_node_mp =
eina_mempool_add(choice, "eet-node-alloc", NULL, sizeof(Eet_Node), 1024); eina_mempool_add(choice, "eet-node-alloc", NULL, sizeof(Eet_Node), 1024);
return _eet_node_mp ? 1 : 0; return _eet_node_mp ? 1 : 0;
} /* eet_node_init */ } /* eet_node_init */

View File

@ -19,13 +19,13 @@ _eet_hash_gen(const char *key,
/* no string - index 0 */ /* no string - index 0 */
if (!key) if (!key)
return 0; 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);
value; value;
ptr++, i++, value = (int)(*ptr)) ptr++, i++, value = (int)(*ptr))
hash_num ^= (value | (value << 8)) >> (i & 0x7); hash_num ^= (value | (value << 8)) >> (i & 0x7);
/* mask it */ /* mask it */
mask = (1 << hash_size) - 1; mask = (1 << hash_size) - 1;

View File

@ -6,48 +6,52 @@
#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;
} /* _eet_str_direct_alloc */ } /* _eet_str_direct_alloc */
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;
} /* _eet_str_direct_free */ } /* _eet_str_direct_free */
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) if (hash)
eina_hash_foreach(hash, cb, fdata); eina_hash_foreach(hash, cb, fdata);
} /* _eet_eina_hash_foreach */ } /* _eet_eina_hash_foreach */
/* 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) if (!hash)
hash = eina_hash_string_superfast_new(NULL); hash = eina_hash_string_superfast_new(NULL);
if (!hash) if (!hash)
return NULL; return NULL;
eina_hash_add(hash, key, data); eina_hash_add(hash, key, data);
return hash; return hash;
} /* _eet_eina_hash_add */ } /* _eet_eina_hash_add */
static void static void
_eet_eina_hash_free(Eina_Hash * hash) _eet_eina_hash_free(Eina_Hash *hash)
{ {
if (hash) if (hash)
eina_hash_free(hash); eina_hash_free(hash);
} /* _eet_eina_hash_free */ } /* _eet_eina_hash_free */
void void
eet_test_setup_eddc(Eet_Data_Descriptor_Class * eddc) eet_test_setup_eddc(Eet_Data_Descriptor_Class *eddc)
{ {
eddc->version = EET_DATA_DESCRIPTOR_CLASS_VERSION; eddc->version = EET_DATA_DESCRIPTOR_CLASS_VERSION;
eddc->func.mem_alloc = NULL; eddc->func.mem_alloc = NULL;

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,7 @@
#include "Eet.h" #include "Eet.h"
void eet_test_setup_eddc(Eet_Data_Descriptor_Class * eddc); void
eet_test_setup_eddc(Eet_Data_Descriptor_Class *eddc);
#endif /* _EET_SUITE_H */ #endif /* _EET_SUITE_H */