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__)
static void
do_eet_list(const char * file)
do_eet_list(const char *file)
{
int i, num;
char ** list;
Eet_File * ef;
char **list;
Eet_File *ef;
ef = eet_open(file, EET_FILE_MODE_READ);
if (!ef)
@ -61,7 +61,7 @@ do_eet_list(const char * file)
if (list)
{
for (i = 0; i < num; i++)
printf("%s\n",list[i]);
printf("%s\n", list[i]);
free(list);
}
@ -69,15 +69,15 @@ do_eet_list(const char * file)
} /* do_eet_list */
static void
do_eet_extract(const char * file,
const char * key,
const char * out,
const char * crypto_key)
do_eet_extract(const char *file,
const char *key,
const char *out,
const char *crypto_key)
{
Eet_File * ef;
void * data;
Eet_File *ef;
void *data;
int size = 0;
FILE * f;
FILE *f;
ef = eet_open(file, EET_FILE_MODE_READ);
if (!ef)
@ -112,19 +112,20 @@ do_eet_extract(const char * file,
} /* do_eet_extract */
static void
do_eet_decode_dump(void * data, const char * str)
do_eet_decode_dump(void *data,
const char *str)
{
fputs(str, (FILE *)data);
} /* do_eet_decode_dump */
static void
do_eet_decode(const char * file,
const char * key,
const char * out,
const char * crypto_key)
do_eet_decode(const char *file,
const char *key,
const char *out,
const char *crypto_key)
{
Eet_File * ef;
FILE * f;
Eet_File *ef;
FILE *f;
ef = eet_open(file, EET_FILE_MODE_READ);
if (!ef)
@ -151,20 +152,20 @@ do_eet_decode(const char * file,
} /* do_eet_decode */
static void
do_eet_insert(const char * file,
const char * key,
const char * out,
int compress,
const char * crypto_key)
do_eet_insert(const char *file,
const char *key,
const char *out,
int compress,
const char *crypto_key)
{
Eet_File * ef;
void * data;
Eet_File *ef;
void *data;
int size = 0;
FILE * f;
FILE *f;
ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
if (!ef)
ef = eet_open(file, EET_FILE_MODE_WRITE);
ef = eet_open(file, EET_FILE_MODE_WRITE);
if (!ef)
{
@ -202,21 +203,21 @@ do_eet_insert(const char * file,
} /* do_eet_insert */
static void
do_eet_encode(const char * file,
const char * key,
const char * out,
int compress,
const char * crypto_key)
do_eet_encode(const char *file,
const char *key,
const char *out,
int compress,
const char *crypto_key)
{
Eet_File * ef;
char * text;
Eet_File *ef;
char *text;
int textlen = 0;
int size = 0;
FILE * f;
FILE *f;
ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
if (!ef)
ef = eet_open(file, EET_FILE_MODE_WRITE);
ef = eet_open(file, EET_FILE_MODE_WRITE);
if (!ef)
{
@ -259,9 +260,10 @@ do_eet_encode(const char * file,
} /* do_eet_encode */
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);
if (!ef)
@ -275,10 +277,10 @@ do_eet_remove(const char * file, const char * key)
} /* do_eet_remove */
static void
do_eet_check(const char * file)
do_eet_check(const char *file)
{
Eet_File * ef;
const void * der;
Eet_File *ef;
const void *der;
int der_length;
int sign_length;
@ -301,10 +303,12 @@ do_eet_check(const char * file)
} /* do_eet_check */
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_Key * key;
Eet_File *ef;
Eet_Key *key;
ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
if (!ef)
@ -329,77 +333,78 @@ do_eet_sign(const char * file, const char * private_key, const char * public_key
} /* do_eet_sign */
int
main(int argc, char ** argv)
main(int argc,
char **argv)
{
if (!eet_init())
return -1;
return -1;
_eet_main_log_dom = eina_log_domain_register("eet_main", EINA_COLOR_CYAN);
if(_eet_main_log_dom < -1)
{
EINA_LOG_ERR("Impossible to create a log domain for eet_main.");
eet_shutdown();
return(-1);
return -1;
}
if (argc < 2)
{
help:
printf(
"Usage:\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 -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 -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 -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"
);
"Usage:\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 -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 -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 -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_shutdown();
return -1;
}
if ((!strncmp(argv[1], "-h", 2)))
goto help;
goto help;
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))
{
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
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))
{
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
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))
{
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
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))
{
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
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))
do_eet_remove(argv[2], argv[3]);
do_eet_remove(argv[2], argv[3]);
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))
do_eet_sign(argv[2], argv[3], argv[4]);
do_eet_sign(argv[2], argv[3], argv[4]);
else
goto help;
goto help;
eina_log_domain_unregister(_eet_main_log_dom);
eet_shutdown();

View File

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

View File

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

View File

@ -82,48 +82,48 @@ _my_cache_descriptor_init(void)
// Describe the members to be saved:
// Use a temporary macro so we don't type a lot, also avoid errors:
#define ADD_BASIC(member, eet_type)\
EET_DATA_DESCRIPTOR_ADD_BASIC\
(_my_message_descriptor, My_Message, # member, member, eet_type)
#define ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_message_descriptor, My_Message, # member, member, eet_type)
ADD_BASIC(screen_name, EET_T_STRING);
ADD_BASIC(name, EET_T_STRING);
ADD_BASIC(message, EET_T_STRING);
ADD_BASIC(id, EET_T_UINT);
ADD_BASIC(status_id, EET_T_UINT);
ADD_BASIC(date, EET_T_UINT);
ADD_BASIC(timeline, EET_T_UINT);
ADD_BASIC(name, EET_T_STRING);
ADD_BASIC(message, EET_T_STRING);
ADD_BASIC(id, EET_T_UINT);
ADD_BASIC(status_id, EET_T_UINT);
ADD_BASIC(date, EET_T_UINT);
ADD_BASIC(timeline, EET_T_UINT);
#undef ADD_BASIC
#define ADD_BASIC(member, eet_type)\
EET_DATA_DESCRIPTOR_ADD_BASIC\
(_my_post_descriptor, My_Post, # member, member, eet_type)
ADD_BASIC(dm_to, EET_T_STRING);
#define ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_post_descriptor, My_Post, # member, member, eet_type)
ADD_BASIC(dm_to, EET_T_STRING);
ADD_BASIC(message, EET_T_STRING);
#undef ADD_BASIC
#define ADD_BASIC(member, eet_type)\
EET_DATA_DESCRIPTOR_ADD_BASIC\
(_my_account_descriptor, My_Account, # member, member, eet_type)
#define ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_account_descriptor, My_Account, # member, member, eet_type)
ADD_BASIC(name, EET_T_STRING);
ADD_BASIC(id, EET_T_UINT);
ADD_BASIC(id, EET_T_UINT);
#undef ADD_BASIC
EET_DATA_DESCRIPTOR_ADD_LIST
(_my_account_descriptor, My_Account, "messages", messages,
_my_message_descriptor);
(_my_account_descriptor, My_Account, "messages", messages,
_my_message_descriptor);
EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY
(_my_account_descriptor, My_Account, "posts", posts,
_my_post_descriptor);
(_my_account_descriptor, My_Account, "posts", posts,
_my_post_descriptor);
#define ADD_BASIC(member, eet_type)\
EET_DATA_DESCRIPTOR_ADD_BASIC\
(_my_cache_descriptor, My_Cache, # member, member, eet_type)
#define ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_cache_descriptor, My_Cache, # member, member, eet_type)
ADD_BASIC(version, EET_T_UINT);
#undef ADD_BASIC
EET_DATA_DESCRIPTOR_ADD_HASH
(_my_cache_descriptor, My_Cache, "accounts", accounts,
_my_account_descriptor);
(_my_cache_descriptor, My_Cache, "accounts", accounts,
_my_account_descriptor);
} /* _my_cache_descriptor_init */
static void
@ -138,21 +138,21 @@ _my_cache_descriptor_shutdown(void)
// need to check if the pointer came from mmaped area in eet_dictionary
// or it was allocated with eina_stringshare_add()
static void
_eet_string_free(const char * str)
_eet_string_free(const char *str)
{
if (!str)
return;
return;
if ((_my_cache_dict) && (eet_dictionary_string_check(_my_cache_dict, str)))
return;
return;
eina_stringshare_del(str);
} /* _eet_string_free */
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)
{
fprintf(stderr, "ERROR: could not calloc My_Message\n");
@ -164,7 +164,7 @@ _my_message_new(const char * message)
} /* _my_message_new */
static void
_my_message_free(My_Message * msg)
_my_message_free(My_Message *msg)
{
_eet_string_free(msg->screen_name);
_eet_string_free(msg->name);
@ -173,7 +173,8 @@ _my_message_free(My_Message * msg)
} /* _my_message_free */
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;
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;
acc->posts_count = new_count;
acc->posts = post;
return EINA_TRUE;;
return EINA_TRUE;
} /* _my_post_new */
static void
_my_post_free(My_Post * post)
_my_post_free(My_Post *post)
{
_eet_string_free(post->dm_to);
_eet_string_free(post->message);
} /* _my_post_free */
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)
{
fprintf(stderr, "ERROR: could not calloc My_Account\n");
@ -212,15 +213,15 @@ _my_account_new(const char * name)
} /* _my_account_new */
static void
_my_account_free(My_Account * acc)
_my_account_free(My_Account *acc)
{
My_Message * m;
My_Message *m;
int i;
_eet_string_free(acc->name);
EINA_LIST_FREE(acc->messages, m)
_my_message_free(m);
_my_message_free(m);
for (i = 0; i < acc->posts_count; i++)
_my_post_free(&acc->posts[i]);
@ -232,7 +233,7 @@ _my_account_free(My_Account * acc)
static My_Cache *
_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)
{
fprintf(stderr, "ERROR: could not calloc My_Cache\n");
@ -246,32 +247,36 @@ _my_cache_new(void)
} /* _my_cache_new */
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);
return EINA_TRUE;
}
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_free(my_cache->accounts);
free(my_cache);
} /* _my_cache_free */
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);
} /* _my_cache_account_find */
static My_Cache *
_my_cache_load(const char * filename)
_my_cache_load(const char *filename)
{
My_Cache * my_cache;
Eet_File * ef = eet_open(filename, EET_FILE_MODE_READ);
My_Cache *my_cache;
Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ);
if (!ef)
{
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)
eet_close(_my_cache_file);
eet_close(_my_cache_file);
_my_cache_file = ef;
_my_cache_dict = eet_dictionary_get(ef);
@ -304,10 +309,11 @@ _my_cache_load(const char * filename)
} /* _my_cache_load */
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];
Eet_File * ef;
Eet_File *ef;
Eina_Bool ret;
unsigned int i, len;
struct stat st;
@ -335,7 +341,7 @@ _my_cache_save(const My_Cache * my_cache, const char * filename)
}
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:
// 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;
} /* _my_cache_save */
int main(int argc, char * argv[])
int
main(int argc,
char *argv[])
{
My_Cache * my_cache;
const Eina_List * l_acc;
My_Cache *my_cache;
const Eina_List *l_acc;
Eina_Iterator *it;
My_Account * acc;
My_Account *acc;
int ret = 0;
if (argc < 3)
@ -399,58 +407,58 @@ int main(int argc, char * argv[])
{
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)
{
acc = _my_account_new(argv[4]);
eina_hash_direct_add(my_cache->accounts, acc->name, acc);
}
else
fprintf(stderr, "ERROR: account '%s' already exists.\n",
argv[4]);
fprintf(stderr, "ERROR: account '%s' already exists.\n",
argv[4]);
}
else
fprintf(stderr,
"ERROR: wrong number of parameters (%d).\n",
argc);
fprintf(stderr,
"ERROR: wrong number of parameters (%d).\n",
argc);
}
else if (strcmp(argv[3], "post") == 0)
{
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)
{
_my_post_add(acc, argv[5]);
}
else
fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]);
fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]);
}
else
fprintf(stderr,
"ERROR: wrong number of parameters (%d).\n",
argc);
fprintf(stderr,
"ERROR: wrong number of parameters (%d).\n",
argc);
}
else if (strcmp(argv[3], "message") == 0)
{
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)
{
My_Message * msg = _my_message_new(argv[5]);
My_Message *msg = _my_message_new(argv[5]);
acc->messages = eina_list_append(acc->messages, msg);
}
else
fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]);
fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]);
}
else
fprintf(stderr,
"ERROR: wrong number of parameters (%d).\n",
argc);
fprintf(stderr,
"ERROR: wrong number of parameters (%d).\n",
argc);
}
else
fprintf(stderr, "ERROR: unknown action '%s'\n", argv[2]);
fprintf(stderr, "ERROR: unknown action '%s'\n", argv[2]);
}
printf("My_Cache:\n"
@ -460,52 +468,52 @@ int main(int argc, char * argv[])
eina_hash_population(my_cache->accounts));
it = eina_hash_iterator_data_new(my_cache->accounts);
EINA_ITERATOR_FOREACH(it, acc)
{
const My_Post * post;
{
const My_Post *post;
printf("\t > %-#8x '%.20s' stats: m=%u, p=%u\n",
acc->id, acc->name ? acc->name : "",
eina_list_count(acc->messages),
acc->posts_count);
printf("\t > %-#8x '%.20s' stats: m=%u, p=%u\n",
acc->id, acc->name ? acc->name : "",
eina_list_count(acc->messages),
acc->posts_count);
if (eina_list_count(acc->messages))
{
const Eina_List * l;
const My_Message * msg;
printf("\t |messages:\n");
if (eina_list_count(acc->messages))
{
const Eina_List *l;
const My_Message *msg;
printf("\t |messages:\n");
EINA_LIST_FOREACH(acc->messages, l, msg)
{
printf("\t | %-8x '%s' [%s]: '%.20s'\n",
msg->id,
msg->name ? msg->name : "",
msg->screen_name ? msg->screen_name : "",
msg->message ? msg->message : "");
}
}
EINA_LIST_FOREACH(acc->messages, l, msg)
{
printf("\t | %-8x '%s' [%s]: '%.20s'\n",
msg->id,
msg->name ? msg->name : "",
msg->screen_name ? msg->screen_name : "",
msg->message ? msg->message : "");
}
}
if (acc->posts_count)
{
const My_Post * post;
int i;
printf("\t |posts:\n");
if (acc->posts_count)
{
const My_Post *post;
int i;
printf("\t |posts:\n");
for (i = 0; i < acc->posts_count; i++)
{
post = &acc->posts[i];
if (post->dm_to)
printf("\t | @%s: '%.20s'\n", post->dm_to, post->message);
else
printf("\t | '%.20s'\n", post->message);
}
}
for (i = 0; i < acc->posts_count; i++)
{
post = &acc->posts[i];
if (post->dm_to)
printf("\t | @%s: '%.20s'\n", post->dm_to, post->message);
else
printf("\t | '%.20s'\n", post->message);
}
}
printf("\n");
}
printf("\n");
}
eina_iterator_free(it);
if (!_my_cache_save(my_cache, argv[2]))
ret = -3;
ret = -3;
_my_cache_free(my_cache);

View File

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

View File

@ -17,17 +17,17 @@
typedef struct
{
unsigned int version; // it is recommended to use versioned configuration!
const char * name;
const char *name;
int id;
int not_saved_value; // example of not saved data inside!
Eina_Bool enabled;
Eina_List * subs;
Eina_List *subs;
} My_Conf_Type;
typedef struct
{
const char * server;
int port;
const char *server;
int port;
} My_Conf_Subtype;
// 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
// shared by different functions (load/save) of this and only this
// file.
static Eet_Data_Descriptor * _my_conf_descriptor;
static Eet_Data_Descriptor * _my_conf_sub_descriptor;
static Eet_Data_Descriptor *_my_conf_descriptor;
static Eet_Data_Descriptor *_my_conf_sub_descriptor;
static void
_my_conf_descriptor_init(void)
@ -66,24 +66,24 @@ _my_conf_descriptor_init(void)
// Describe the members to be saved:
// Use a temporary macro so we don't type a lot, also avoid errors:
#define MY_CONF_ADD_BASIC(member, eet_type)\
EET_DATA_DESCRIPTOR_ADD_BASIC\
(_my_conf_descriptor, My_Conf_Type, # member, member, eet_type)
#define MY_CONF_SUB_ADD_BASIC(member, eet_type)\
EET_DATA_DESCRIPTOR_ADD_BASIC\
(_my_conf_sub_descriptor, My_Conf_Subtype, # member, member, eet_type)
#define MY_CONF_ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_conf_descriptor, My_Conf_Type, # member, member, eet_type)
#define MY_CONF_SUB_ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \
(_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(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(name, EET_T_STRING);
MY_CONF_ADD_BASIC(id, EET_T_INT);
MY_CONF_ADD_BASIC(name, EET_T_STRING);
MY_CONF_ADD_BASIC(id, EET_T_INT);
MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR);
// And add the sub descriptor as a linked list at 'subs' in the main struct
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_SUB_ADD_BASIC
@ -99,8 +99,8 @@ _my_conf_descriptor_shutdown(void)
static My_Conf_Type *
_my_conf_new(void)
{
My_Conf_Type * my_conf = calloc(1, sizeof(My_Conf_Type));
My_Conf_Subtype * sub;
My_Conf_Type *my_conf = calloc(1, sizeof(My_Conf_Type));
My_Conf_Subtype *sub;
if (!my_conf)
{
fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n");
@ -122,24 +122,24 @@ _my_conf_new(void)
} /* _my_conf_new */
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_stringshare_del(sub->server);
free(sub);
}
{
eina_stringshare_del(sub->server);
free(sub);
}
eina_stringshare_del(my_conf->name);
free(my_conf);
} /* _my_conf_free */
static My_Conf_Type *
_my_conf_load(const char * filename)
_my_conf_load(const char *filename)
{
My_Conf_Type * my_conf;
Eet_File * ef = eet_open(filename, EET_FILE_MODE_READ);
My_Conf_Type *my_conf;
Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ);
if (!ef)
{
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);
if (!my_conf)
goto end;
goto end;
if (my_conf->version < 0x112233)
{
@ -166,10 +166,11 @@ end:
} /* _my_conf_load */
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];
Eet_File * ef;
Eet_File *ef;
Eina_Bool ret;
unsigned int i, len;
struct stat st;
@ -197,7 +198,7 @@ _my_conf_save(const My_Conf_Type * my_conf, const char * filename)
}
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);
if (ret)
@ -209,11 +210,13 @@ _my_conf_save(const My_Conf_Type * my_conf, const char * filename)
return ret;
} /* _my_conf_save */
int main(int argc, char * argv[])
int
main(int argc,
char *argv[])
{
My_Conf_Type * my_conf;
const My_Conf_Subtype * sub;
const Eina_List * l;
My_Conf_Type *my_conf;
const My_Conf_Subtype *sub;
const Eina_List *l;
int ret = 0;
if (argc != 3)
@ -250,12 +253,12 @@ int main(int argc, char * argv[])
my_conf->enabled);
EINA_LIST_FOREACH(my_conf->subs, l, sub)
printf("\t\tserver: '%s', port: %d\n",
sub->server ? sub->server : "",
sub->port);
printf("\t\tserver: '%s', port: %d\n",
sub->server ? sub->server : "",
sub->port);
if (!_my_conf_save(my_conf, argv[2]))
ret = -3;
ret = -3;
_my_conf_free(my_conf);

View File

@ -17,7 +17,7 @@
typedef struct
{
unsigned int version; // it is recommended to use versioned configuration!
const char * name;
const char *name;
int id;
int not_saved_value; // example of not saved data inside!
Eina_Bool enabled;
@ -31,7 +31,7 @@ static const char MY_CONF_FILE_ENTRY[] = "config";
// keep the descriptor static global, so it can be
// shared by different functions (load/save) of this and only this
// file.
static Eet_Data_Descriptor * _my_conf_descriptor;
static Eet_Data_Descriptor *_my_conf_descriptor;
static void
_my_conf_descriptor_init(void)
@ -55,13 +55,13 @@ _my_conf_descriptor_init(void)
// Describe the members to be saved:
// Use a temporary macro so we don't type a lot, also avoid errors:
#define MY_CONF_ADD_BASIC(member, eet_type)\
EET_DATA_DESCRIPTOR_ADD_BASIC\
(_my_conf_descriptor, My_Conf_Type, # member, member, eet_type)
#define MY_CONF_ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_conf_descriptor, My_Conf_Type, # member, member, eet_type)
MY_CONF_ADD_BASIC(version, EET_T_UINT);
MY_CONF_ADD_BASIC(name, EET_T_STRING);
MY_CONF_ADD_BASIC(id, EET_T_INT);
MY_CONF_ADD_BASIC(name, EET_T_STRING);
MY_CONF_ADD_BASIC(id, EET_T_INT);
MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR);
#undef MY_CONF_ADD_BASIC
@ -76,7 +76,7 @@ _my_conf_descriptor_shutdown(void)
static My_Conf_Type *
_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)
{
fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n");
@ -89,17 +89,17 @@ _my_conf_new(void)
} /* _my_conf_new */
static void
_my_conf_free(My_Conf_Type * my_conf)
_my_conf_free(My_Conf_Type *my_conf)
{
eina_stringshare_del(my_conf->name);
free(my_conf);
} /* _my_conf_free */
static My_Conf_Type *
_my_conf_load(const char * filename)
_my_conf_load(const char *filename)
{
My_Conf_Type * my_conf;
Eet_File * ef = eet_open(filename, EET_FILE_MODE_READ);
My_Conf_Type *my_conf;
Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ);
if (!ef)
{
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);
if (!my_conf)
goto end;
goto end;
if (my_conf->version < 0x112233)
{
@ -126,10 +126,11 @@ end:
} /* _my_conf_load */
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];
Eet_File * ef;
Eet_File *ef;
Eina_Bool ret;
unsigned int i, len;
struct stat st;
@ -157,7 +158,7 @@ _my_conf_save(const My_Conf_Type * my_conf, const char * filename)
}
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);
if (ret)
@ -169,9 +170,11 @@ _my_conf_save(const My_Conf_Type * my_conf, const char * filename)
return ret;
} /* _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;
if (argc != 3)
@ -207,7 +210,7 @@ int main(int argc, char * argv[])
my_conf->enabled);
if (!_my_conf_save(my_conf, argv[2]))
ret = -3;
ret = -3;
_my_conf_free(my_conf);

View File

@ -12,25 +12,25 @@ create_eet_file(void)
char buf[1024], *ptr;
int size, len, i;
const char *some_strings[] = {
"And some more strings",
"spread across several",
"elements of an array!"
"And some more strings",
"spread across several",
"elements of an array!"
};
const char some_data[] =
"\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\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\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"
"\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"
"\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"
"\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"
"\x79\x20\x6c\x6f\x61\x64\x65\x64\x20\x69\x6e\x20\x6d\x65\x6d\x6f"
"\x72\x79\x2e\x0a\x00";
"\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\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\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"
"\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"
"\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"
"\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"
"\x79\x20\x6c\x6f\x61\x64\x65\x64\x20\x69\x6e\x20\x6d\x65\x6d\x6f"
"\x72\x79\x2e\x0a\x00";
ef = eet_open("/tmp/my_file.eet", EET_FILE_MODE_WRITE);
if (!ef) return 0;
@ -60,67 +60,68 @@ create_eet_file(void)
eet_delete(ef, "/several/strings");
return (eet_close(ef) == EET_ERROR_NONE);
return eet_close(ef) == EET_ERROR_NONE;
}
int
main(void)
{
Eet_File *ef;
char *ret, **list;
int size, num, i;
Eet_File *ef;
char *ret, **list;
int size, num, i;
eet_init();
eet_init();
if (!create_eet_file())
return -1;
if (!create_eet_file())
return -1;
ef = eet_open("/tmp/my_file.eet", EET_FILE_MODE_READ);
if (!ef) return -1;
ef = eet_open("/tmp/my_file.eet", EET_FILE_MODE_READ);
if (!ef) return -1;
list = eet_list(ef, "*", &num);
if (list)
{
for (i = 0; i < num; i++)
printf("Key stored: %s\n", list[i]);
free(list);
}
list = eet_list(ef, "*", &num);
if (list)
{
for (i = 0; i < num; i++)
printf("Key stored: %s\n", list[i]);
free(list);
}
ret = eet_read(ef, "/key/to_store/at", &size);
if (ret)
{
printf("Data read (%i bytes):\n%s\n", size, ret);
free(ret);
}
ret = eet_read(ef, "/key/to_store/at", &size);
if (ret)
{
printf("Data read (%i bytes):\n%s\n", size, ret);
free(ret);
}
ret = eet_read(ef, "/several/strings", &size);
if (ret)
{
printf("More data read (%i bytes):\n%s\n", size, ret);
free(ret);
}
ret = eet_read(ef, "/several/strings", &size);
if (ret)
{
printf("More data read (%i bytes):\n%s\n", size, ret);
free(ret);
}
ret = eet_read(ef, "/some/mysterious/data", &size);
if (ret)
{
Eet_File *ef2;
ret = eet_read(ef, "/some/mysterious/data", &size);
if (ret)
{
Eet_File *ef2;
ef2 = eet_memopen_read(ret, size);
ef2 = eet_memopen_read(ret, size);
num = eet_num_entries(ef2);
printf("Mysterious data has %d entries\n", num);
num = eet_num_entries(ef2);
printf("Mysterious data has %d entries\n", num);
printf("Mysterious data:\n%s\n",
(char *)eet_read_direct(ef2, "/mysterious/data", NULL));
printf("Mysterious data:\n%s\n",
(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>
typedef enum _Eet_Convert_Type Eet_Convert_Type;
typedef enum _Eet_Convert_Type Eet_Convert_Type;
enum _Eet_Convert_Type
{
@ -13,8 +13,8 @@ enum _Eet_Convert_Type
EET_D_FIXED_POINT = 1 << 4
};
typedef struct _Eet_String Eet_String;
typedef struct _Eet_Convert Eet_Convert;
typedef struct _Eet_String Eet_String;
typedef struct _Eet_Convert Eet_Convert;
struct _Eet_Convert
{
@ -27,15 +27,15 @@ struct _Eet_Convert
struct _Eet_String
{
const char *str;
const char *str;
int len;
int len;
int next;
int prev;
int next;
int prev;
unsigned char hash;
unsigned char allocated : 1;
unsigned char hash;
unsigned char allocated : 1;
};
struct _Eet_Dictionary
{
@ -101,61 +101,82 @@ extern int _eet_log_dom_global;
#endif /* ifdef CRIT */
#define CRIT(...) EINA_LOG_DOM_CRIT(_eet_log_dom_global, __VA_ARGS__)
Eet_Dictionary * eet_dictionary_add(void);
void eet_dictionary_free(Eet_Dictionary *ed);
int eet_dictionary_string_add(Eet_Dictionary *ed,
const char *string);
int eet_dictionary_string_get_size(const Eet_Dictionary *ed,
int index);
const char * eet_dictionary_string_get_char(const Eet_Dictionary *ed,
int index);
Eina_Bool eet_dictionary_string_get_float(const Eet_Dictionary *ed,
int index,
float *result);
Eina_Bool eet_dictionary_string_get_double(const Eet_Dictionary *ed,
int index,
double *result);
Eina_Bool eet_dictionary_string_get_fp(const Eet_Dictionary *ed,
int index,
Eina_F32p32 *result);
int eet_dictionary_string_get_hash(const Eet_Dictionary *ed,
int index);
Eet_Dictionary *
eet_dictionary_add(void);
void
eet_dictionary_free(Eet_Dictionary *ed);
int
eet_dictionary_string_add(Eet_Dictionary *ed,
const char *string);
int
eet_dictionary_string_get_size(const Eet_Dictionary *ed,
int index);
const char *
eet_dictionary_string_get_char(const Eet_Dictionary *ed,
int index);
Eina_Bool
eet_dictionary_string_get_float(const Eet_Dictionary *ed,
int index,
float *result);
Eina_Bool
eet_dictionary_string_get_double(const Eet_Dictionary *ed,
int index,
double *result);
Eina_Bool
eet_dictionary_string_get_fp(const Eet_Dictionary *ed,
int index,
Eina_F32p32 *result);
int
eet_dictionary_string_get_hash(const Eet_Dictionary *ed,
int index);
int _eet_hash_gen(const char *key, int hash_size);
int _eet_hash_gen(const char *key,
int hash_size);
const void * eet_identity_check(const void *data_base,
unsigned int data_length,
void **sha1,
int *sha1_length,
const void *signature_base,
unsigned int signature_length,
const void **raw_signature_base,
unsigned int *raw_signature_length,
int *x509_length);
void * eet_identity_compute_sha1(const void *data_base,
unsigned int data_length,
int *sha1_length);
Eet_Error eet_cipher(const void *data,
unsigned int size,
const char *key,
unsigned int length,
void **result,
unsigned int *result_length);
Eet_Error eet_decipher(const void *data,
unsigned int size,
const char *key,
unsigned int length,
void **result,
unsigned int *result_length);
Eet_Error eet_identity_sign(FILE *fp,
Eet_Key *key);
void eet_identity_unref(Eet_Key *key);
void eet_identity_ref(Eet_Key *key);
const void *
eet_identity_check(const void *data_base,
unsigned int data_length,
void **sha1,
int *sha1_length,
const void *signature_base,
unsigned int signature_length,
const void **raw_signature_base,
unsigned int *raw_signature_length,
int *x509_length);
void *
eet_identity_compute_sha1(const void *data_base,
unsigned int data_length,
int *sha1_length);
Eet_Error
eet_cipher(const void *data,
unsigned int size,
const char *key,
unsigned int length,
void **result,
unsigned int *result_length);
Eet_Error
eet_decipher(const void *data,
unsigned int size,
const char *key,
unsigned int length,
void **result,
unsigned int *result_length);
Eet_Error
eet_identity_sign(FILE *fp,
Eet_Key *key);
void
eet_identity_unref(Eet_Key *key);
void
eet_identity_ref(Eet_Key *key);
void eet_node_shutdown(void);
int eet_node_init(void);
Eet_Node * eet_node_new(void);
void eet_node_free(Eet_Node *node);
void
eet_node_shutdown(void);
int
eet_node_init(void);
Eet_Node *
eet_node_new(void);
void
eet_node_free(Eet_Node *node);
#ifndef PATH_MAX
# define PATH_MAX 4096

View File

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

View File

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

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

View File

@ -16,7 +16,7 @@
# ifdef __cplusplus
extern "C"
# endif /* ifdef __cplusplus */
void * alloca (size_t);
void *alloca(size_t);
#endif /* ifdef HAVE_ALLOCA_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_source_mgr pub;
struct jpeg_source_mgr pub;
const unsigned char *buf;
size_t len;
@ -65,7 +65,7 @@ static void
_eet_jpeg_membuf_src_init(j_decompress_ptr cinfo)
{
/* FIXME: Use attribute unused */
(void)cinfo;
(void)cinfo;
} /* _eet_jpeg_membuf_src_init */
static boolean
@ -108,7 +108,7 @@ eet_jpeg_membuf_src(j_decompress_ptr cinfo,
src = calloc(1, sizeof(*src));
if (!src)
return -1;
return -1;
src->self = src;
@ -143,7 +143,7 @@ static void
_eet_jpeg_membuf_dst_init(j_compress_ptr cinfo)
{
/* FIXME: Use eina attribute */
(void)cinfo;
(void)cinfo;
} /* _eet_jpeg_membuf_dst_init */
static boolean
@ -162,7 +162,7 @@ _eet_jpeg_membuf_dst_flush(j_compress_ptr cinfo)
}
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->pub.free_in_buffer += dst->len;
dst->len *= 2;
@ -200,7 +200,7 @@ eet_jpeg_membuf_dst(j_compress_ptr cinfo,
dst = calloc(1, sizeof(*dst));
if (!dst)
return -1;
return -1;
dst->buf = malloc(32768);
if (!dst->buf)
@ -227,54 +227,61 @@ eet_jpeg_membuf_dst(j_compress_ptr cinfo,
/*---*/
static void _JPEGFatalErrorHandler(j_common_ptr cinfo);
static void _JPEGErrorHandler(j_common_ptr cinfo);
static void _JPEGErrorHandler2(j_common_ptr cinfo,
int msg_level);
static void _JPEGFatalErrorHandler(j_common_ptr cinfo);
static void _JPEGErrorHandler(j_common_ptr cinfo);
static void _JPEGErrorHandler2(j_common_ptr cinfo,
int msg_level);
static int eet_data_image_jpeg_header_decode(const void *data,
int size,
unsigned int *w,
unsigned int *h);
static int eet_data_image_jpeg_rgb_decode(const void *data,
int size,
unsigned int src_x,
unsigned int src_y,
unsigned int *d,
unsigned int w,
unsigned int h,
unsigned int row_stride);
static void * eet_data_image_jpeg_alpha_decode(const void *data,
int size,
unsigned int src_x,
unsigned int src_y,
unsigned int *d,
unsigned int w,
unsigned int h,
unsigned int row_stride);
static void * eet_data_image_lossless_convert(int *size,
const void *data,
unsigned int w,
unsigned int h,
int alpha);
static void * eet_data_image_lossless_compressed_convert(int *size,
const void *data,
unsigned int w,
unsigned int h,
int alpha,
int compression);
static void * eet_data_image_jpeg_convert(int *size,
const void *data,
unsigned int w,
unsigned int h,
int alpha,
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);
static int
eet_data_image_jpeg_header_decode(const void *data,
int size,
unsigned int *w,
unsigned int *h);
static int
eet_data_image_jpeg_rgb_decode(const void *data,
int size,
unsigned int src_x,
unsigned int src_y,
unsigned int *d,
unsigned int w,
unsigned int h,
unsigned int row_stride);
static void *
eet_data_image_jpeg_alpha_decode(const void *data,
int size,
unsigned int src_x,
unsigned int src_y,
unsigned int *d,
unsigned int w,
unsigned int h,
unsigned int row_stride);
static void *
eet_data_image_lossless_convert(int *size,
const void *data,
unsigned int w,
unsigned int h,
int alpha);
static void *
eet_data_image_lossless_compressed_convert(int *size,
const void *data,
unsigned int w,
unsigned int h,
int alpha,
int compression);
static void *
eet_data_image_jpeg_convert(int *size,
const void *data,
unsigned int w,
unsigned int h,
int alpha,
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) =\
((((unsigned long long)(x) & 0x00000000000000ffULL) << 56) |\
(((unsigned long long)(x) & 0x000000000000ff00ULL) << 40) |\
(((unsigned long long)(x) & 0x0000000000ff0000ULL) << 24) |\
(((unsigned long long)(x) & 0x00000000ff000000ULL) << 8) |\
(((unsigned long long)(x) & 0x000000ff00000000ULL) >> 8) |\
(((unsigned long long)(x) & 0x0000ff0000000000ULL) >> 24) |\
(((unsigned long long)(x) & 0x00ff000000000000ULL) >> 40) |\
(((unsigned long long)(x) & 0xff00000000000000ULL) >> 56))
#define SWAP32(x) (x) =\
((((int)(x) & 0x000000ff) << 24) |\
(((int)(x) & 0x0000ff00) << 8) |\
(((int)(x) & 0x00ff0000) >> 8) |\
(((int)(x) & 0xff000000) >> 24))
#define SWAP16(x) (x) =\
((((short)(x) & 0x00ff) << 8) |\
(((short)(x) & 0xff00) >> 8))
#define SWAP64(x) (x) = \
((((unsigned long long)(x) & 0x00000000000000ffULL) << 56) | \
(((unsigned long long)(x) & 0x000000000000ff00ULL) << 40) | \
(((unsigned long long)(x) & 0x0000000000ff0000ULL) << 24) | \
(((unsigned long long)(x) & 0x00000000ff000000ULL) << 8) | \
(((unsigned long long)(x) & 0x000000ff00000000ULL) >> 8) | \
(((unsigned long long)(x) & 0x0000ff0000000000ULL) >> 24) | \
(((unsigned long long)(x) & 0x00ff000000000000ULL) >> 40) | \
(((unsigned long long)(x) & 0xff00000000000000ULL) >> 56))
#define SWAP32(x) (x) = \
((((int)(x) & 0x000000ff) << 24) | \
(((int)(x) & 0x0000ff00) << 8) | \
(((int)(x) & 0x00ff0000) >> 8) | \
(((int)(x) & 0xff000000) >> 24))
#define SWAP16(x) (x) = \
((((short)(x) & 0x00ff) << 8) | \
(((short)(x) & 0xff00) >> 8))
#ifdef CONV8
# undef CONV8
@ -336,22 +343,22 @@ _JPEGErrorHandler(j_common_ptr cinfo __UNUSED__)
{
/* emptr errmgr; */
/* errmgr = (emptr) cinfo->err; */
/* cinfo->err->output_message(cinfo);*/
/* longjmp(errmgr->setjmp_buffer, 1);*/
return;
/* errmgr = (emptr) cinfo->err; */
/* cinfo->err->output_message(cinfo);*/
/* longjmp(errmgr->setjmp_buffer, 1);*/
return;
} /* _JPEGErrorHandler */
static void
_JPEGErrorHandler2(j_common_ptr cinfo __UNUSED__,
int msg_level __UNUSED__)
int msg_level __UNUSED__)
{
/* emptr errmgr; */
/* errmgr = (emptr) cinfo->err; */
/* cinfo->err->output_message(cinfo);*/
/* longjmp(errmgr->setjmp_buffer, 1);*/
return;
/* errmgr = (emptr) cinfo->err; */
/* cinfo->err->output_message(cinfo);*/
/* longjmp(errmgr->setjmp_buffer, 1);*/
return;
} /* _JPEGErrorHandler2 */
static int
@ -370,7 +377,7 @@ eet_data_image_jpeg_header_decode(const void *data,
jerr.pub.emit_message = _JPEGErrorHandler2;
jerr.pub.output_message = _JPEGErrorHandler;
if (setjmp(jerr.setjmp_buffer))
return 0;
return 0;
jpeg_create_decompress(&cinfo);
@ -395,7 +402,7 @@ eet_data_image_jpeg_header_decode(const void *data,
jpeg_destroy_decompress(&cinfo);
if ((*w < 1) || (*h < 1) || (*w > 8192) || (*h > 8192))
return 0;
return 0;
return 1;
} /* 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 */
if (!d)
return 0;
return 0;
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.output_message = _JPEGErrorHandler;
if (setjmp(jerr.setjmp_buffer))
return 0;
return 0;
jpeg_create_decompress(&cinfo);
@ -474,13 +481,13 @@ eet_data_image_jpeg_rgb_decode(const void *data,
if (cinfo.output_components == 3)
{
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)
{
jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
scans = cinfo.rec_outbuf_height;
if ((ih - l) < scans)
scans = ih - l;
scans = ih - l;
ptr = tdata;
@ -488,7 +495,7 @@ eet_data_image_jpeg_rgb_decode(const void *data,
{
y = src_y - l;
if (src_y < l)
y = 0;
y = 0;
for (ptr += 3 * iw * y; y < scans && (y + l) < (src_y + h);
y++)
@ -498,8 +505,8 @@ eet_data_image_jpeg_rgb_decode(const void *data,
for (x = 0; x < w; x++)
{
*ptr2 =
(0xff000000) |
((ptr[0]) << 16) | ((ptr[1]) << 8) | (ptr[2]);
(0xff000000) |
((ptr[0]) << 16) | ((ptr[1]) << 8) | (ptr[2]);
ptr += 3;
ptr2++;
}
@ -512,13 +519,13 @@ eet_data_image_jpeg_rgb_decode(const void *data,
else if (cinfo.output_components == 1)
{
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)
{
jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
scans = cinfo.rec_outbuf_height;
if (((ih) - l) < scans)
scans = (ih) - l;
scans = (ih) - l;
ptr = tdata;
@ -526,7 +533,7 @@ eet_data_image_jpeg_rgb_decode(const void *data,
{
y = src_y - l;
if (src_y < l)
y = 0;
y = 0;
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++)
{
*ptr2 =
(0xff000000) |
((ptr[0]) << 16) | ((ptr[0]) << 8) | (ptr[0]);
(0xff000000) |
((ptr[0]) << 16) | ((ptr[0]) << 8) | (ptr[0]);
ptr++;
ptr2++;
}
@ -577,7 +584,7 @@ eet_data_image_jpeg_alpha_decode(const void *data,
jerr.pub.emit_message = _JPEGErrorHandler2;
jerr.pub.output_message = _JPEGErrorHandler;
if (setjmp(jerr.setjmp_buffer))
return NULL;
return NULL;
jpeg_create_decompress(&cinfo);
@ -621,13 +628,13 @@ eet_data_image_jpeg_alpha_decode(const void *data,
if (cinfo.output_components == 1)
{
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)
{
jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
scans = cinfo.rec_outbuf_height;
if ((h - l) < scans)
scans = h - l;
scans = h - l;
ptr = tdata;
@ -635,7 +642,7 @@ eet_data_image_jpeg_alpha_decode(const void *data,
{
y = src_y - l;
if (src_y < l)
y = 0;
y = 0;
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++)
{
*ptr2 =
((*ptr2) & 0x00ffffff) |
((ptr[0]) << 24);
((*ptr2) & 0x00ffffff) |
((ptr[0]) << 24);
ptr++;
ptr2++;
}
@ -675,9 +682,9 @@ eet_data_image_lossless_convert(int *size,
v = htonl(0x12345678);
if (v == 0x12345678)
_eet_image_words_bigendian = 1;
_eet_image_words_bigendian = 1;
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));
if (!d)
return NULL;
return NULL;
header = (int *)d;
memset(d, 0, 32);
@ -724,9 +731,9 @@ eet_data_image_lossless_compressed_convert(int *size,
v = htonl(0x12345678);
if (v == 0x12345678)
_eet_image_words_bigendian = 1;
_eet_image_words_bigendian = 1;
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));
if (!d)
return NULL;
return NULL;
buflen = (((w * h * 101) / 100) + 3) * 4;
comp = malloc(buflen);
@ -811,7 +818,7 @@ eet_data_image_jpeg_convert(int *size,
jerr.pub.emit_message = _JPEGErrorHandler2;
jerr.pub.output_message = _JPEGErrorHandler;
if (setjmp(jerr.setjmp_buffer))
return NULL;
return NULL;
jpeg_create_compress(&cinfo);
@ -884,9 +891,9 @@ eet_data_image_jpeg_alpha_convert(int *size,
v = htonl(0x12345678);
if (v == 0x12345678)
_eet_image_words_bigendian = 1;
_eet_image_words_bigendian = 1;
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.output_message = _JPEGErrorHandler;
if (setjmp(jerr.setjmp_buffer))
return NULL;
return NULL;
jpeg_create_compress(&cinfo);
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]);
}
memcpy(d + 12, d1, sz1);
memcpy(d + 12, d1, sz1);
memcpy(d + 12 + sz1, d2, sz2);
free(d1);
@ -1119,20 +1126,20 @@ eet_data_image_read_cipher(Eet_File *ef,
int size;
if (!cipher_key)
data = (void *)eet_read_direct(ef, name, &size);
data = (void *)eet_read_direct(ef, name, &size);
if (!data)
{
data = eet_read_cipher(ef, name, &size, cipher_key);
free_data = 1;
if (!data)
return NULL;
return NULL;
}
d = eet_data_image_decode(data, size, w, h, alpha, comp, quality, lossy);
if (free_data)
free(data);
free(data);
return d;
} /* eet_data_image_read_cipher */
@ -1172,14 +1179,14 @@ eet_data_image_read_to_surface_cipher(Eet_File *ef,
int size;
if (!cipher_key)
data = (void *)eet_read_direct(ef, name, &size);
data = (void *)eet_read_direct(ef, name, &size);
if (!data)
{
data = eet_read_cipher(ef, name, &size, cipher_key);
free_data = 1;
if (!data)
return 0;
return 0;
}
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);
if (free_data)
free(data);
free(data);
return res;
} /* eet_data_image_read_to_surface_cipher */
@ -1230,20 +1237,20 @@ eet_data_image_header_read_cipher(Eet_File *ef,
int d;
if (!cipher_key)
data = (void *)eet_read_direct(ef, name, &size);
data = (void *)eet_read_direct(ef, name, &size);
if (!data)
{
data = eet_read_cipher(ef, name, &size, cipher_key);
free_data = 1;
if (!data)
return 0;
return 0;
}
d = eet_data_image_header_decode(data, size, w, h, alpha,
comp, quality, lossy);
if (free_data)
free(data);
free(data);
return d;
} /* eet_data_image_header_read_cipher */
@ -1282,21 +1289,21 @@ eet_data_image_encode_cipher(const void *data,
if (lossy == 0)
{
if (comp > 0)
d = eet_data_image_lossless_compressed_convert(&size, data,
w, h, alpha, comp);
d = eet_data_image_lossless_compressed_convert(&size, data,
w, h, alpha, comp);
/* eet_data_image_lossless_compressed_convert will refuse to compress something
if the result is bigger than the entry. */
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
{
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
d = eet_data_image_jpeg_alpha_convert(&size, data,
w, h, alpha, quality);
d = eet_data_image_jpeg_alpha_convert(&size, data,
w, h, alpha, quality);
}
if (cipher_key)
@ -1305,18 +1312,18 @@ eet_data_image_encode_cipher(const void *data,
&ciphered_sz))
{
if (d)
free(d);
free(d);
d = ciphered_d;
size = ciphered_sz;
}
else
if (ciphered_d)
free(ciphered_d);
free(ciphered_d);
}
if (size_ret)
*size_ret = size;
*size_ret = size;
return d;
} /* eet_data_image_encode_cipher */
@ -1360,7 +1367,7 @@ eet_data_image_header_decode_cipher(const void *data,
}
else
if (deciphered_d)
free(deciphered_d);
free(deciphered_d);
}
if (_eet_image_words_bigendian == -1)
@ -1369,13 +1376,13 @@ eet_data_image_header_decode_cipher(const void *data,
v = htonl(0x12345678);
if (v == 0x12345678)
_eet_image_words_bigendian = 1;
_eet_image_words_bigendian = 1;
else
_eet_image_words_bigendian = 0;
_eet_image_words_bigendian = 0;
}
if (size < 32)
return 0;
return 0;
memcpy(header, data, 32);
if (_eet_image_words_bigendian)
@ -1394,28 +1401,28 @@ eet_data_image_header_decode_cipher(const void *data,
al = header[3];
cp = header[4];
if ((iw < 1) || (ih < 1) || (iw > 8192) || (ih > 8192))
return 0;
return 0;
if ((cp == 0) && (size < ((iw * ih * 4) + 32)))
return 0;
return 0;
if (w)
*w = iw;
*w = iw;
if (h)
*h = ih;
*h = ih;
if (alpha)
*alpha = al ? 1 : 0;
*alpha = al ? 1 : 0;
if (comp)
*comp = cp;
*comp = cp;
if (lossy)
*lossy = 0;
*lossy = 0;
if (quality)
*quality = 100;
*quality = 100;
return 1;
}
@ -1434,22 +1441,22 @@ eet_data_image_header_decode_cipher(const void *data,
if (ok)
{
if (w)
*w = iw;
*w = iw;
if (h)
*h = ih;
*h = ih;
if (alpha)
*alpha = 1;
*alpha = 1;
if (comp)
*comp = 0;
*comp = 0;
if (lossy)
*lossy = 1;
*lossy = 1;
if (quality)
*quality = 75;
*quality = 75;
return 1;
}
@ -1463,22 +1470,22 @@ eet_data_image_header_decode_cipher(const void *data,
if (ok)
{
if (w)
*w = iw;
*w = iw;
if (h)
*h = ih;
*h = ih;
if (alpha)
*alpha = 0;
*alpha = 0;
if (comp)
*comp = 0;
*comp = 0;
if (lossy)
*lossy = 1;
*lossy = 1;
if (quality)
*quality = 75;
*quality = 75;
return 1;
}
@ -1521,14 +1528,14 @@ _eet_data_image_copy_buffer(const unsigned int *src,
src += src_x + src_y * src_w;
if (row_stride == src_w * 4 && w == src_w)
memcpy(dst, src, row_stride * h);
memcpy(dst, src, row_stride * h);
else
{
unsigned int *over = dst;
unsigned int y;
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 */
@ -1554,8 +1561,8 @@ _eet_data_image_decode_inside(const void *data,
body = ((unsigned int *)data) + 8;
if (!comp)
_eet_data_image_copy_buffer(body, src_x, src_y, src_w, d,
w, h, row_stride);
_eet_data_image_copy_buffer(body, src_x, src_y, src_w, d,
w, h, row_stride);
else
{
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;
uLongf dlen = src_w * src_h * 4;
/* FIXME: This could create a huge alloc. So compressed
data and tile could not always work. */
/* FIXME: This could create a huge alloc. So compressed
data and tile could not always work. */
dtmp = malloc(dlen);
if (!dtmp)
return 0;
return 0;
uncompress(dtmp, &dlen, (Bytef *)body, (uLongf)(size - 32));
@ -1622,15 +1629,15 @@ _eet_data_image_decode_inside(const void *data,
dt += sz1;
if (!eet_data_image_jpeg_alpha_decode(dt, sz2, src_x, src_y,
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,
h, row_stride))
return 0;
return 0;
}
else
abort();
abort();
return 1;
} /* _eet_data_image_decode_inside */
@ -1662,17 +1669,17 @@ eet_data_image_decode_cipher(const void *data,
}
else
if (deciphered_d)
free(deciphered_d);
free(deciphered_d);
}
/* 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,
&iquality, &ilossy))
return NULL;
return NULL;
d = malloc(iw * ih * 4);
if (!d)
return NULL;
return NULL;
if (!_eet_data_image_decode_inside(data, size, 0, 0, iw, ih, d, iw, ih, iw *
4, ialpha, icompress, iquality, ilossy))
@ -1682,22 +1689,22 @@ eet_data_image_decode_cipher(const void *data,
}
if (w)
*w = iw;
*w = iw;
if (h)
*h = ih;
*h = ih;
if (alpha)
*alpha = ialpha;
*alpha = ialpha;
if (comp)
*comp = icompress;
*comp = icompress;
if (quality)
*quality = iquality;
*quality = iquality;
if (lossy)
*lossy = ilossy;
*lossy = ilossy;
return d;
} /* eet_data_image_decode_cipher */
@ -1746,39 +1753,39 @@ eet_data_image_decode_to_surface_cipher(const void *data,
}
else
if (deciphered_d)
free(deciphered_d);
free(deciphered_d);
}
/* 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,
&iquality, &ilossy))
return 0;
return 0;
if (!d)
return 0;
return 0;
if (w * 4 > row_stride)
return 0;
return 0;
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,
row_stride, ialpha, icompress, iquality,
ilossy))
return 0;
return 0;
if (alpha)
*alpha = ialpha;
*alpha = ialpha;
if (comp)
*comp = icompress;
*comp = icompress;
if (quality)
*quality = iquality;
*quality = iquality;
if (lossy)
*lossy = ilossy;
*lossy = ilossy;
return 1;
} /* eet_data_image_decode_to_surface_cipher */
@ -1798,8 +1805,8 @@ eet_data_image_decode_to_surface(const void *data,
int *lossy)
{
return eet_data_image_decode_to_surface_cipher(data, NULL, size,
src_x, src_y, d,
w, h, row_stride,
src_x, src_y, d,
w, h, row_stride,
alpha, comp, quality,
lossy);
} /* 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));
if (!result)
return NULL;
return NULL;
memset(result, 0, sizeof (Eet_Node));
return result;
@ -43,7 +43,7 @@ _eet_node_new(const char *name,
n = eet_node_new();
if (!n)
return NULL;
return NULL;
n->type = type;
n->name = eina_stringshare_add(name);
@ -52,57 +52,58 @@ _eet_node_new(const char *name,
} /* _eet_node_new */
static void
_eet_node_append(Eet_Node *n, Eina_List *nodes)
_eet_node_append(Eet_Node *n,
Eina_List *nodes)
{
Eet_Node *value;
Eina_List *l;
EINA_LIST_REVERSE_FOREACH(nodes, l, value)
{
value->next = n->values;
n->values = value;
}
{
value->next = n->values;
n->values = value;
}
} /* _eet_node_append */
#define EET_NODE_NEW(Eet_type, Name, Value, Type)\
EAPI Eet_Node *\
eet_node_ ## Name ## _new(const char *name, Type Value)\
{\
Eet_Node *n;\
\
n = _eet_node_new(name, Eet_type);\
if (!n) { return NULL; }\
\
n->data.value.Value = Value;\
\
return n;\
}
#define EET_NODE_NEW(Eet_type, Name, Value, Type) \
EAPI Eet_Node * \
eet_node_ ## Name ## _new(const char *name, Type Value) \
{ \
Eet_Node *n; \
\
n = _eet_node_new(name, Eet_type); \
if (!n) { return NULL; } \
\
n->data.value.Value = Value; \
\
return n; \
}
#define EET_NODE_STR_NEW(Eet_type, Name, Value, Type)\
EAPI Eet_Node *\
eet_node_ ## Name ## _new(const char *name, Type Value)\
{\
Eet_Node *n;\
\
n = _eet_node_new(name, Eet_type);\
if (!n) { return NULL; }\
\
n->data.value.Value = eina_stringshare_add(Value);\
\
return n;\
}
#define EET_NODE_STR_NEW(Eet_type, Name, Value, Type) \
EAPI Eet_Node * \
eet_node_ ## Name ## _new(const char *name, Type Value) \
{ \
Eet_Node *n; \
\
n = _eet_node_new(name, Eet_type); \
if (!n) { return NULL; } \
\
n->data.value.Value = eina_stringshare_add(Value); \
\
return n; \
}
EET_NODE_NEW(EET_T_CHAR, char, c, char)
EET_NODE_NEW(EET_T_SHORT, short, s, short)
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_FLOAT, float, f, float)
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_USHORT, unsigned_short, us, unsigned short)
EET_NODE_NEW(EET_T_UINT, unsigned_int, ui, unsigned int)
EET_NODE_NEW(EET_T_CHAR, char, c, char)
EET_NODE_NEW(EET_T_SHORT, short, s, short)
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_FLOAT, float, f, float)
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_USHORT, unsigned_short, us, unsigned short)
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_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 *
@ -112,7 +113,7 @@ eet_node_null_new(const char *name)
n = _eet_node_new(name, EET_T_NULL);
if (!n)
return NULL;
return 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);
if (!n)
return NULL;
return NULL;
_eet_node_append(n, nodes);
@ -143,7 +144,7 @@ eet_node_array_new(const char *name,
n = _eet_node_new(name, EET_G_ARRAY);
if (!n)
return NULL;
return NULL;
n->count = count;
@ -160,7 +161,7 @@ eet_node_var_array_new(const char *name,
n = _eet_node_new(name, EET_G_VAR_ARRAY);
if (!n)
return NULL;
return NULL;
n->count = eina_list_count(nodes);
@ -178,11 +179,11 @@ eet_node_hash_new(const char *name,
Eet_Node *n;
if (!node)
return NULL;
return NULL;
n = _eet_node_new(name, EET_G_HASH);
if (!n)
return NULL;
return NULL;
n->key = eina_stringshare_add(key);
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);
if (!n)
return NULL;
return NULL;
_eet_node_append(n, nodes);
@ -216,11 +217,11 @@ eet_node_struct_child_new(const char *parent,
if (!child) return NULL;
if (child->type != EET_G_UNKNOWN)
return child;
return child;
n = _eet_node_new(parent, EET_G_UNKNOWN);
if (!n)
return NULL;
return NULL;
_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);
for (nn = parent->values; nn; nn = nn->next)
if (nn->name == tmp && nn->type == EET_G_LIST)
{
Eet_Node *n;
if (nn->name == tmp && nn->type == EET_G_LIST)
{
Eet_Node *n;
if (!nn->values)
nn->values = child;
else
{
for (n = nn->values; n->next; n = n->next)
;
n->next = child;
}
if (!nn->values)
nn->values = child;
else
{
for (n = nn->values; n->next; n = n->next)
;
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. */
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);
for (prev = NULL, nn = parent->values; nn; prev = nn, nn = nn->next)
if (nn->name == tmp && nn->type == child->type)
{
if (prev)
prev->next = nn->next;
else
parent->values = nn->next;
if (nn->name == tmp && nn->type == child->type)
{
if (prev)
prev->next = nn->next;
else
parent->values = nn->next;
nn->next = NULL;
eet_node_del(nn);
nn->next = NULL;
eet_node_del(nn);
break;
}
break;
}
if (prev)
{
@ -357,7 +358,6 @@ eet_node_hash_add(Eet_Node *parent,
parent->values = nn;
} /* eet_node_hash_add */
int
eet_node_type_get(Eet_Node *node)
{
@ -386,29 +386,29 @@ eet_node_del(Eet_Node *n)
Eet_Node *tmp;
if (!n)
return;
return;
switch (n->type)
{
case EET_G_HASH:
eina_stringshare_del(n->key);
eina_stringshare_del(n->key);
case EET_G_UNKNOWN:
case EET_G_VAR_ARRAY:
case EET_G_ARRAY:
case EET_G_LIST:
for (nn = n->values; nn; )
{
tmp = nn;
nn = nn->next;
eet_node_del(tmp);
}
break;
for (nn = n->values; nn; )
{
tmp = nn;
nn = nn->next;
eet_node_del(tmp);
}
break;
case EET_T_STRING:
case EET_T_INLINED_STRING:
eina_stringshare_del(n->data.value.str);
break;
eina_stringshare_del(n->data.value.str);
break;
case EET_T_CHAR:
case EET_T_SHORT:
@ -419,7 +419,7 @@ eet_node_del(Eet_Node *n)
case EET_T_UCHAR:
case EET_T_USHORT:
case EET_T_UINT:
break;
break;
} /* switch */
eina_stringshare_del(n->name);
@ -451,9 +451,9 @@ static const char *eet_node_dump_t_name[14][2] = {
};
static void
eet_node_dump_level(int level,
eet_node_dump_level(int level,
Eet_Dump_Callback dumpfunc,
void *dumpdata)
void *dumpdata)
{
int i;
@ -470,17 +470,17 @@ eet_node_string_escape(const char *str)
for (strp = str; *strp; strp++)
{
if (*strp == '\"')
sz += 2;
sz += 2;
else if (*strp == '\\')
sz += 2;
sz += 2;
else if (*strp == '\n')
sz += 2;
sz += 2;
else
sz += 1;
sz += 1;
}
s = malloc(sz + 1);
if (!s)
return NULL;
return NULL;
for (strp = str, sp = s; *strp; strp++, sp++)
{
@ -493,33 +493,34 @@ eet_node_string_escape(const char *str)
}
if (*strp == '\n')
*sp = 'n';
*sp = 'n';
else
*sp = *strp;
*sp = *strp;
}
*sp = 0;
return s;
} /* eet_node_string_escape */
static void
eet_node_dump_string_escape(void *dumpdata,
eet_node_dump_string_escape(void *dumpdata,
Eet_Dump_Callback dumpfunc,
const char *str)
const char *str)
{
char *s;
s = eet_node_string_escape(str);
if (!s)
return;
return;
dumpfunc(dumpdata, s);
free(s);
} /* eet_node_dump_string_escape */
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,
void *dumpdata)
void *dumpdata)
{
const char *type_name = NULL;
char tbuf[256];
@ -533,95 +534,95 @@ eet_node_dump_simple_type(Eet_Node *n, int level,
# undef EET_T_TYPE
#endif /* ifdef EET_T_TYPE */
#define EET_T_TYPE(Eet_Type, Type)\
case Eet_Type:\
{\
dumpfunc(dumpdata, eet_node_dump_t_name[Eet_Type][0]);\
snprintf(tbuf,\
sizeof (tbuf),\
eet_node_dump_t_name[Eet_Type][1],\
n->data.value.Type);\
dumpfunc(dumpdata, tbuf);\
break;\
}
#define EET_T_TYPE(Eet_Type, Type) \
case Eet_Type: \
{ \
dumpfunc(dumpdata, eet_node_dump_t_name[Eet_Type][0]); \
snprintf(tbuf, \
sizeof (tbuf), \
eet_node_dump_t_name[Eet_Type][1], \
n->data.value.Type); \
dumpfunc(dumpdata, tbuf); \
break; \
}
switch (n->type)
{
EET_T_TYPE(EET_T_CHAR, c);
EET_T_TYPE(EET_T_SHORT, s);
EET_T_TYPE(EET_T_INT, i);
EET_T_TYPE(EET_T_LONG_LONG, l);
EET_T_TYPE(EET_T_FLOAT, f);
EET_T_TYPE(EET_T_DOUBLE, d);
EET_T_TYPE(EET_T_UCHAR, uc);
EET_T_TYPE(EET_T_USHORT, us);
EET_T_TYPE(EET_T_UINT, ui);
EET_T_TYPE(EET_T_CHAR, c);
EET_T_TYPE(EET_T_SHORT, s);
EET_T_TYPE(EET_T_INT, i);
EET_T_TYPE(EET_T_LONG_LONG, l);
EET_T_TYPE(EET_T_FLOAT, f);
EET_T_TYPE(EET_T_DOUBLE, d);
EET_T_TYPE(EET_T_UCHAR, uc);
EET_T_TYPE(EET_T_USHORT, us);
EET_T_TYPE(EET_T_UINT, ui);
EET_T_TYPE(EET_T_ULONG_LONG, ul);
case EET_T_INLINED_STRING:
type_name = "inlined: \"";
type_name = "inlined: \"";
case EET_T_STRING:
if (!type_name)
type_name = "string: \"";
if (!type_name)
type_name = "string: \"";
dumpfunc(dumpdata, type_name);
eet_node_dump_string_escape(dumpdata, dumpfunc, n->data.value.str);
dumpfunc(dumpdata, "\"");
break;
dumpfunc(dumpdata, type_name);
eet_node_dump_string_escape(dumpdata, dumpfunc, n->data.value.str);
dumpfunc(dumpdata, "\"");
break;
case EET_T_NULL:
dumpfunc(dumpdata, "null");
break;
dumpfunc(dumpdata, "null");
break;
default:
dumpfunc(dumpdata, "???: ???");
break;
dumpfunc(dumpdata, "???: ???");
break;
} /* switch */
dumpfunc(dumpdata, ";\n");
} /* eet_node_dump_simple_type */
static void
eet_node_dump_group_start(int level,
eet_node_dump_group_start(int level,
Eet_Dump_Callback dumpfunc,
void *dumpdata,
int group_type,
const char *name)
void *dumpdata,
int group_type,
const char *name)
{
int chnk_type;
chnk_type = (group_type >= EET_G_UNKNOWN && group_type <= EET_G_HASH) ?
group_type : EET_G_LAST;
group_type : EET_G_LAST;
eet_node_dump_level(level, dumpfunc, dumpdata);
dumpfunc(dumpdata, "group \"");
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, " {\n");
dumpfunc(dumpdata, " {\n");
} /* eet_node_dump_group_start */
static void
eet_node_dump_group_end(int level,
eet_node_dump_group_end(int level,
Eet_Dump_Callback dumpfunc,
void *dumpdata)
void *dumpdata)
{
eet_node_dump_level(level, dumpfunc, dumpdata);
dumpfunc(dumpdata, "}\n");
} /* eet_node_dump_group_end */
void
eet_node_dump(Eet_Node *n,
int dumplevel,
eet_node_dump(Eet_Node *n,
int dumplevel,
Eet_Dump_Callback dumpfunc,
void *dumpdata)
void *dumpdata)
{
Eet_Node *it;
if (!n)
return;
return;
switch (n->type)
{
@ -630,36 +631,36 @@ eet_node_dump(Eet_Node *n,
case EET_G_UNKNOWN:
case EET_G_HASH:
case EET_G_LIST:
eet_node_dump_group_start(dumplevel,
dumpfunc,
dumpdata,
n->type,
n->name);
eet_node_dump_group_start(dumplevel,
dumpfunc,
dumpdata,
n->type,
n->name);
if (n->type == EET_G_VAR_ARRAY
|| n->type == EET_G_ARRAY)
{
char tbuf[256];
if (n->type == EET_G_VAR_ARRAY
|| n->type == EET_G_ARRAY)
{
char tbuf[256];
eet_node_dump_level(dumplevel, dumpfunc, dumpdata);
dumpfunc(dumpdata, " count ");
eina_convert_itoa(n->count, tbuf);
dumpfunc(dumpdata, tbuf);
dumpfunc(dumpdata, ";\n");
}
else if (n->type == EET_G_HASH)
{
eet_node_dump_level(dumplevel, dumpfunc, dumpdata);
dumpfunc(dumpdata, " key \"");
eet_node_dump_string_escape(dumpdata, dumpfunc, n->key);
dumpfunc(dumpdata, "\";\n");
}
eet_node_dump_level(dumplevel, dumpfunc, dumpdata);
dumpfunc(dumpdata, " count ");
eina_convert_itoa(n->count, tbuf);
dumpfunc(dumpdata, tbuf);
dumpfunc(dumpdata, ";\n");
}
else if (n->type == EET_G_HASH)
{
eet_node_dump_level(dumplevel, dumpfunc, dumpdata);
dumpfunc(dumpdata, " key \"");
eet_node_dump_string_escape(dumpdata, dumpfunc, n->key);
dumpfunc(dumpdata, "\";\n");
}
for (it = n->values; it; it = it->next)
eet_node_dump(it, dumplevel + 2, dumpfunc, dumpdata);
for (it = n->values; it; it = it->next)
eet_node_dump(it, dumplevel + 2, dumpfunc, dumpdata);
eet_node_dump_group_end(dumplevel, dumpfunc, dumpdata);
break;
eet_node_dump_group_end(dumplevel, dumpfunc, dumpdata);
break;
case EET_T_STRING:
case EET_T_INLINED_STRING:
@ -673,8 +674,8 @@ eet_node_dump(Eet_Node *n,
case EET_T_USHORT:
case EET_T_UINT:
case EET_T_ULONG_LONG:
eet_node_dump_simple_type(n, dumplevel, dumpfunc, dumpdata);
break;
eet_node_dump_simple_type(n, dumplevel, dumpfunc, dumpdata);
break;
} /* switch */
} /* eet_node_dump */
@ -692,7 +693,7 @@ eet_node_walk(void *parent,
if (!root)
{
if (parent)
cb->struct_add(parent, name, NULL, user_data);
cb->struct_add(parent, name, NULL, user_data);
return NULL;
}
@ -700,50 +701,50 @@ eet_node_walk(void *parent,
switch (root->type)
{
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)
eet_node_walk(me, it->name, it, cb, user_data);
for (it = root->values; it; it = it->next)
eet_node_walk(me, it->name, it, cb, user_data);
break;
break;
case EET_G_VAR_ARRAY:
case EET_G_ARRAY:
me = cb->array(root->type == EET_G_VAR_ARRAY ? EINA_TRUE : EINA_FALSE,
root->name, root->count, user_data);
me = cb->array(root->type == EET_G_VAR_ARRAY ? EINA_TRUE : EINA_FALSE,
root->name, root->count, user_data);
for (i = 0, it = root->values; it; it = it->next)
cb->insert(me, i++, eet_node_walk(NULL,
NULL,
it,
cb,
user_data), user_data);
for (i = 0, it = root->values; it; it = it->next)
cb->insert(me, i++, eet_node_walk(NULL,
NULL,
it,
cb,
user_data), user_data);
break;
break;
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)
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,
for (it = root->values; it; it = it->next)
cb->append(me, eet_node_walk(NULL,
NULL,
root->values,
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,
root->values,
cb,
user_data), user_data);
case EET_T_STRING:
case EET_T_INLINED_STRING:
case EET_T_CHAR:
@ -756,12 +757,12 @@ eet_node_walk(void *parent,
case EET_T_USHORT:
case EET_T_UINT:
case EET_T_ULONG_LONG:
me = cb->simple(root->type, &root->data, user_data);
break;
me = cb->simple(root->type, &root->data, user_data);
break;
} /* switch */
if (parent)
cb->struct_add(parent, name, me, user_data);
cb->struct_add(parent, name, me, user_data);
return me;
} /* eet_node_walk */
@ -779,10 +780,10 @@ eet_node_init(void)
#endif
tmp = getenv("EET_MEMPOOL");
if (tmp && tmp[0])
choice = tmp;
choice = tmp;
_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;
} /* eet_node_init */

View File

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

View File

@ -6,48 +6,52 @@
#include "eet_suite.h"
static char *
_eet_str_direct_alloc(const char * str)
_eet_str_direct_alloc(const char *str)
{
return (char *)str;
} /* _eet_str_direct_alloc */
static void
_eet_str_direct_free(const char * str)
_eet_str_direct_free(const char *str)
{
/* FIXME: Use attribute unused */
(void)str;
(void)str;
} /* _eet_str_direct_free */
static void
_eet_eina_hash_foreach(void * hash, Eina_Hash_Foreach cb, void * fdata)
_eet_eina_hash_foreach(void *hash,
Eina_Hash_Foreach cb,
void *fdata)
{
if (hash)
eina_hash_foreach(hash, cb, fdata);
eina_hash_foreach(hash, cb, fdata);
} /* _eet_eina_hash_foreach */
/* Internal wrapper for eina_hash */
static Eina_Hash *
_eet_eina_hash_add(Eina_Hash * hash, const char * key, const void * data)
_eet_eina_hash_add(Eina_Hash *hash,
const char *key,
const void *data)
{
if (!hash)
hash = eina_hash_string_superfast_new(NULL);
hash = eina_hash_string_superfast_new(NULL);
if (!hash)
return NULL;
return NULL;
eina_hash_add(hash, key, data);
return hash;
} /* _eet_eina_hash_add */
static void
_eet_eina_hash_free(Eina_Hash * hash)
_eet_eina_hash_free(Eina_Hash *hash)
{
if (hash)
eina_hash_free(hash);
eina_hash_free(hash);
} /* _eet_eina_hash_free */
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->func.mem_alloc = NULL;

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,7 @@
#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 */