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

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



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

View File

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

View File

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

View File

@ -11,7 +11,8 @@
// will be automatically handled. The other members will have their
// space reserved and zeroed (as it uses calloc()), but not
// saved or loaded from eet files.
typedef struct {
typedef struct
{
unsigned int version; // it is recommended to use versioned configuration!
const char *name;
int id;
@ -20,7 +21,8 @@ typedef struct {
Eina_List *subs;
} My_Conf_Type;
typedef struct {
typedef struct
{
const char *server;
int port;
} My_Conf_Subtype;

View File

@ -11,7 +11,8 @@
// will be automatically handled. The other members will have their
// space reserved and zeroed (as it uses calloc()), but not
// saved or loaded from eet files.
typedef struct {
typedef struct
{
unsigned int version; // it is recommended to use versioned configuration!
const char *name;
int id;

View File

@ -346,7 +346,8 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_File_Group
*/
EAPI int eet_dictionary_string_check(Eet_Dictionary *ed, const char *string);
EAPI int eet_dictionary_string_check(Eet_Dictionary *ed,
const char *string);
/**
* Read a specified entry from an eet file and return data
@ -392,7 +393,9 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_File_Group
*/
EAPI const void *eet_read_direct(Eet_File *ef, const char *name, int *size_ret);
EAPI const void * eet_read_direct(Eet_File *ef,
const char *name,
int *size_ret);
/**
* Write a specified entry to an eet file handle
@ -422,7 +425,11 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_File_Group
*/
EAPI int eet_write(Eet_File *ef, const char *name, const void *data, int size, int compress);
EAPI int eet_write(Eet_File *ef,
const char *name,
const void *data,
int size,
int compress);
/**
* Delete a specified entry from an Eet file being written or re-written
@ -458,7 +465,10 @@ extern "C" {
* @since 1.3.3
* @ingroup Eet_File_Group
*/
EAPI Eina_Bool eet_alias(Eet_File *ef, const char *name, const char *destination, int compress);
EAPI Eina_Bool eet_alias(Eet_File *ef,
const char *name,
const char *destination,
int compress);
/**
@ -538,7 +548,10 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_File_Cipher_Group
*/
EAPI void *eet_read_cipher(Eet_File *ef, const char *name, int *size_ret, const char *cipher_key);
EAPI void * eet_read_cipher(Eet_File *ef,
const char *name,
int *size_ret,
const char *cipher_key);
/**
* Write a specified entry to an eet file handle using a cipher.
@ -569,7 +582,12 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_File_Cipher_Group
*/
EAPI int eet_write_cipher(Eet_File *ef, const char *name, const void *data, int size, int compress, const char *cipher_key);
EAPI int eet_write_cipher(Eet_File *ef,
const char *name,
const void *data,
int size,
int compress,
const char *cipher_key);
/**
@ -615,7 +633,14 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_File_Image_Group
*/
EAPI int eet_data_image_header_read(Eet_File *ef, const char *name, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
EAPI int eet_data_image_header_read(Eet_File *ef,
const char *name,
unsigned int *w,
unsigned int *h,
int *alpha,
int *compress,
int *quality,
int *lossy);
/**
* Read image data from the named key in the eet file.
@ -655,7 +680,14 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_File_Image_Group
*/
EAPI void *eet_data_image_read(Eet_File *ef, const char *name, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
EAPI void *eet_data_image_read(Eet_File *ef,
const char *name,
unsigned int *w,
unsigned int *h,
int *alpha,
int *compress,
int *quality,
int *lossy);
/**
* Read image data from the named key in the eet file.
@ -697,7 +729,18 @@ extern "C" {
* @since 1.0.2
* @ingroup Eet_File_Image_Group
*/
EAPI int eet_data_image_read_to_surface(Eet_File *ef, const char *name, unsigned int src_x, unsigned int src_y, unsigned int *d, unsigned int w, unsigned int h, unsigned int row_stride, int *alpha, int *compress, int *quality, int *lossy);
EAPI int eet_data_image_read_to_surface(Eet_File *ef,
const char *name,
unsigned int src_x,
unsigned int src_y,
unsigned int *d,
unsigned int w,
unsigned int h,
unsigned int row_stride,
int *alpha,
int *compress,
int *quality,
int *lossy);
/**
* Write image data to the named key in an eet file.
@ -734,7 +777,15 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_File_Image_Group
*/
EAPI int eet_data_image_write(Eet_File *ef, const char *name, const void *data, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy);
EAPI int eet_data_image_write(Eet_File *ef,
const char *name,
const void *data,
unsigned int w,
unsigned int h,
int alpha,
int compress,
int quality,
int lossy);
/**
* Decode Image data header only to get information.
@ -772,7 +823,14 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_File_Image_Group
*/
EAPI int eet_data_image_header_decode(const void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
EAPI int eet_data_image_header_decode(const void *data,
int size,
unsigned int *w,
unsigned int *h,
int *alpha,
int *compress,
int *quality,
int *lossy);
/**
* Decode Image data into pixel data.
@ -812,7 +870,14 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_File_Image_Group
*/
EAPI void *eet_data_image_decode(const void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
EAPI void *eet_data_image_decode(const void *data,
int size,
unsigned int *w,
unsigned int *h,
int *alpha,
int *compress,
int *quality,
int *lossy);
/**
* Decode Image data into pixel data.
@ -854,7 +919,18 @@ extern "C" {
* @since 1.0.2
* @ingroup Eet_File_Image_Group
*/
EAPI int eet_data_image_decode_to_surface(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, int *alpha, int *compress, int *quality, int *lossy);
EAPI int eet_data_image_decode_to_surface(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,
int *alpha,
int *compress,
int *quality,
int *lossy);
/**
* Encode image data for storage or transmission.
@ -890,7 +966,14 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_File_Image_Group
*/
EAPI void *eet_data_image_encode(const void *data, int *size_ret, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy);
EAPI void *eet_data_image_encode(const void *data,
int *size_ret,
unsigned int w,
unsigned int h,
int alpha,
int compress,
int quality,
int lossy);
/**
* @defgroup Eet_File_Image_Cipher_Group Image Store and Load using a Cipher
@ -940,7 +1023,15 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_File_Image_Cipher_Group
*/
EAPI int eet_data_image_header_read_cipher(Eet_File *ef, const char *name, const char *cipher_key, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
EAPI int eet_data_image_header_read_cipher(Eet_File *ef,
const char *name,
const char *cipher_key,
unsigned int *w,
unsigned int *h,
int *alpha,
int *compress,
int *quality,
int *lossy);
/**
* Read image data from the named key in the eet file using a cipher.
@ -981,7 +1072,15 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_File_Image_Cipher_Group
*/
EAPI void *eet_data_image_read_cipher(Eet_File *ef, const char *name, const char *cipher_key, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
EAPI void *eet_data_image_read_cipher(Eet_File *ef,
const char *name,
const char *cipher_key,
unsigned int *w,
unsigned int *h,
int *alpha,
int *compress,
int *quality,
int *lossy);
/**
* Read image data from the named key in the eet file using a cipher.
@ -1024,7 +1123,19 @@ extern "C" {
* @since 1.0.2
* @ingroup Eet_File_Image_Cipher_Group
*/
EAPI int eet_data_image_read_to_surface_cipher(Eet_File *ef, const char *name, const char *cipher_key, unsigned int src_x, unsigned int src_y, unsigned int *d, unsigned int w, unsigned int h, unsigned int row_stride, int *alpha, int *compress, int *quality, int *lossy);
EAPI int eet_data_image_read_to_surface_cipher(Eet_File *ef,
const char *name,
const char *cipher_key,
unsigned int src_x,
unsigned int src_y,
unsigned int *d,
unsigned int w,
unsigned int h,
unsigned int row_stride,
int *alpha,
int *compress,
int *quality,
int *lossy);
/**
* Write image data to the named key in an eet file using a cipher.
@ -1062,7 +1173,16 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_File_Image_Cipher_Group
*/
EAPI int eet_data_image_write_cipher(Eet_File *ef, const char *name, const char *cipher_key, const void *data, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy);
EAPI int eet_data_image_write_cipher(Eet_File *ef,
const char *name,
const char *cipher_key,
const void *data,
unsigned int w,
unsigned int h,
int alpha,
int compress,
int quality,
int lossy);
/**
@ -1102,7 +1222,15 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_File_Image_Cipher_Group
*/
EAPI int eet_data_image_header_decode_cipher(const void *data, const char *cipher_key, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
EAPI int eet_data_image_header_decode_cipher(const void *data,
const char *cipher_key,
int size,
unsigned int *w,
unsigned int *h,
int *alpha,
int *compress,
int *quality,
int *lossy);
/**
* Decode Image data into pixel data using a cipher.
@ -1143,7 +1271,15 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_File_Image_Cipher_Group
*/
EAPI void *eet_data_image_decode_cipher(const void *data, const char *cipher_key, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
EAPI void *eet_data_image_decode_cipher(const void *data,
const char *cipher_key,
int size,
unsigned int *w,
unsigned int *h,
int *alpha,
int *compress,
int *quality,
int *lossy);
/**
* Decode Image data into pixel data using a cipher.
@ -1186,7 +1322,19 @@ extern "C" {
* @since 1.0.2
* @ingroup Eet_File_Image_Cipher_Group
*/
EAPI int eet_data_image_decode_to_surface_cipher(const void *data, const char *cipher_key, int size, unsigned int src_x, unsigned int src_y, unsigned int *d, unsigned int w, unsigned int h, unsigned int row_stride, int *alpha, int *compress, int *quality, int *lossy);
EAPI int eet_data_image_decode_to_surface_cipher(const void *data,
const char *cipher_key,
int size,
unsigned int src_x,
unsigned int src_y,
unsigned int *d,
unsigned int w,
unsigned int h,
unsigned int row_stride,
int *alpha,
int *compress,
int *quality,
int *lossy);
/**
* Encode image data for storage or transmission using a cipher.
@ -1223,7 +1371,15 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_File_Image_Cipher_Group
*/
EAPI void *eet_data_image_encode_cipher(const void *data, const char *cipher_key, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy, int *size_ret);
EAPI void *eet_data_image_encode_cipher(const void *data,
const char *cipher_key,
unsigned int w,
unsigned int h,
int alpha,
int compress,
int quality,
int lossy,
int *size_ret);
/**
@ -1263,7 +1419,8 @@ extern "C" {
* @since 1.2.0
* @ingroup Eet_Cipher_Group
*/
typedef int (*Eet_Key_Password_Callback)(char *buffer, int size, int rwflag, void *data);
typedef int (*Eet_Key_Password_Callback)(char *buffer, int size, int rwflag,
void *data);
/**
* Create an Eet_Key needed for signing an eet file.
@ -1282,7 +1439,9 @@ extern "C" {
* @since 1.2.0
* @ingroup Eet_Cipher_Group
*/
EAPI Eet_Key* eet_identity_open(const char *certificate_file, const char *private_key_file, Eet_Key_Password_Callback cb);
EAPI Eet_Key * eet_identity_open(const char *certificate_file,
const char *private_key_file,
Eet_Key_Password_Callback cb);
/**
* Close and release all ressource used by an Eet_Key. An
@ -1369,7 +1528,10 @@ extern "C" {
* @since 1.2.0
* @ingroup Eet_Cipher_Group
*/
EAPI void eet_identity_certificate_print(const unsigned char *certificate, int der_length, FILE *out);
EAPI void eet_identity_certificate_print(
const unsigned char *certificate,
int der_length,
FILE *out);
/**
@ -1597,7 +1759,8 @@ extern "C" {
int version; /**< ABI version as #EET_DATA_DESCRIPTOR_CLASS_VERSION */
const char *name; /**< Name of data type to be serialized */
int size; /**< Size in bytes of data type to be serialized */
struct {
struct
{
void *(*mem_alloc)(size_t size); /**< how to allocate memory (usually malloc()) */
void (*mem_free)(void *mem); /**< how to free memory (usually free()) */
char *(*str_alloc)(const char *str); /**< how to allocate a string */
@ -1606,7 +1769,9 @@ extern "C" {
void *(*list_append)(void *l, void *d); /**< how to append data @p d to list which head node is @p l */
void *(*list_data)(void *l); /**< retrieves the data from node @p l */
void *(*list_free)(void *l); /**< free all the nodes from the list which head node is @p l */
void (*hash_foreach) (void *h, int (*func) (void *h, const char *k, void *dt, void *fdt), void *fdt); /**< iterates over all elements in the hash @p h in no specific order */
void (*hash_foreach)(void *h,
int (*func)(void *h, const char *k, void *dt,
void *fdt), void *fdt); /**< iterates over all elements in the hash @p h in no specific order */
void *(*hash_add)(void *h, const char *k, void *d); /**< add a new data @p d as key @p k in hash @p h */
void (*hash_free)(void *h); /**< free all entries from the hash @p h */
char *(*str_direct_alloc)(const char *str); /**< how to allocate a string directly from file backed/mmaped region pointed by @p str */
@ -1659,15 +1824,29 @@ extern "C" {
* @deprecated use eet_data_descriptor_stream_new() or
* eet_data_descriptor_file_new()
*/
EINA_DEPRECATED EAPI Eet_Data_Descriptor *eet_data_descriptor_new(const char *name, int size, void *(*func_list_next) (void *l), void *(*func_list_append) (void *l, void *d), void *(*func_list_data) (void *l), void *(*func_list_free) (void *l), void (*func_hash_foreach) (void *h, int (*func) (void *h, const char *k, void *dt, void *fdt), void *fdt), void *(*func_hash_add) (void *h, const char *k, void *d), void (*func_hash_free) (void *h));
EINA_DEPRECATED EAPI Eet_Data_Descriptor *eet_data_descriptor_new(
const char *name,
int size,
void *(*func_list_next)(void *l),
void *(*func_list_append)(void *l, void *d),
void *(*func_list_data)(void *l),
void *(*func_list_free)(void *l),
void (*func_hash_foreach)(void *h, int (*func)(void *h,
const char *k,
void *dt,
void *fdt), void *fdt),
void *(*func_hash_add)(void *h, const char *k, void *d),
void (*func_hash_free)(void *h));
/*
* FIXME:
*
* moving to this api from the old above. this will break things when the
* move happens - but be warned
*/
EINA_DEPRECATED EAPI Eet_Data_Descriptor *eet_data_descriptor2_new(const Eet_Data_Descriptor_Class *eddc);
EINA_DEPRECATED EAPI Eet_Data_Descriptor *eet_data_descriptor3_new(const Eet_Data_Descriptor_Class *eddc);
EINA_DEPRECATED EAPI Eet_Data_Descriptor *eet_data_descriptor2_new(
const Eet_Data_Descriptor_Class *eddc);
EINA_DEPRECATED EAPI Eet_Data_Descriptor *eet_data_descriptor3_new(
const Eet_Data_Descriptor_Class *eddc);
/**
* This function creates a new data descriptore and returns a handle to the
@ -1693,7 +1872,8 @@ extern "C" {
* @since 1.2.3
* @ingroup Eet_Data_Group
*/
EAPI Eet_Data_Descriptor *eet_data_descriptor_stream_new(const Eet_Data_Descriptor_Class *eddc);
EAPI Eet_Data_Descriptor * eet_data_descriptor_stream_new(
const Eet_Data_Descriptor_Class *eddc);
/**
* This function creates a new data descriptore and returns a handle to the
@ -1722,7 +1902,8 @@ extern "C" {
* @since 1.2.3
* @ingroup Eet_Data_Group
*/
EAPI Eet_Data_Descriptor *eet_data_descriptor_file_new(const Eet_Data_Descriptor_Class *eddc);
EAPI Eet_Data_Descriptor * eet_data_descriptor_file_new(
const Eet_Data_Descriptor_Class *eddc);
/**
* This function is an helper that set all the parameter of an
@ -1738,7 +1919,11 @@ extern "C" {
* @since 1.2.3
* @ingroup Eet_Data_Group
*/
EAPI Eina_Bool eet_eina_stream_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc, const char *name, int size);
EAPI Eina_Bool
eet_eina_stream_data_descriptor_class_set(
Eet_Data_Descriptor_Class *eddc,
const char *name,
int size);
/**
* This macro is an helper that set all the parameter of an
@ -1753,7 +1938,9 @@ extern "C" {
* @since 1.2.3
* @ingroup Eet_Data_Group
*/
#define EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(Clas, Type) (eet_eina_stream_data_descriptor_class_set(Clas, #Type , sizeof (Type)))
#define EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(Clas, \
Type) ( \
eet_eina_stream_data_descriptor_class_set(Clas, # Type, sizeof (Type)))
/**
* This function is an helper that set all the parameter of an
@ -1769,7 +1956,10 @@ extern "C" {
* @since 1.2.3
* @ingroup Eet_Data_Group
*/
EAPI Eina_Bool eet_eina_file_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc, const char *name, int size);
EAPI Eina_Bool eet_eina_file_data_descriptor_class_set(
Eet_Data_Descriptor_Class *eddc,
const char *name,
int size);
/**
* This macro is an helper that set all the parameter of an
@ -1784,7 +1974,9 @@ extern "C" {
* @since 1.2.3
* @ingroup Eet_Data_Group
*/
#define EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(Clas, Type) (eet_eina_file_data_descriptor_class_set(Clas, #Type , sizeof (Type)))
#define EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(Clas, \
Type) ( \
eet_eina_file_data_descriptor_class_set(Clas, # Type, sizeof (Type)))
/**
* This function frees a data descriptor when it is not needed anymore.
@ -1825,7 +2017,14 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_Data_Group
*/
EAPI void eet_data_descriptor_element_add(Eet_Data_Descriptor *edd, const char *name, int type, int group_type, int offset, /* int count_offset, */int count, const char *counter_name, Eet_Data_Descriptor *subtype);
EAPI void eet_data_descriptor_element_add(Eet_Data_Descriptor *edd,
const char *name,
int type,
int group_type,
int offset,
/* int count_offset, */ int count,
const char *counter_name,
Eet_Data_Descriptor *subtype);
/**
* Read a data structure from an eet file and decodes it.
@ -1854,7 +2053,9 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_Data_Group
*/
EAPI void *eet_data_read(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name);
EAPI void *eet_data_read(Eet_File *ef,
Eet_Data_Descriptor *edd,
const char *name);
/**
* Write a data structure from memory and store in an eet file.
@ -1873,7 +2074,11 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_Data_Group
*/
EAPI int eet_data_write(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const void *data, int compress);
EAPI int eet_data_write(Eet_File *ef,
Eet_Data_Descriptor *edd,
const char *name,
const void *data,
int compress);
/**
* Dump an eet encoded data structure into ascii text
@ -1922,7 +2127,9 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_Data_Group
*/
EAPI int eet_data_text_dump(const void *data_in, int size_in, void (*dumpfunc) (void *data, const char *str), void *dumpdata);
EAPI int eet_data_text_dump(const void *data_in, int size_in, void (*dumpfunc)(
void *data,
const char *str), void *dumpdata);
/**
* Take an ascii encoding from eet_data_text_dump() and re-encode in binary.
@ -1968,7 +2175,9 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_Data_Group
*/
EAPI int eet_data_dump(Eet_File *ef, const char *name, void (*dumpfunc) (void *data, const char *str), void *dumpdata);
EAPI int eet_data_dump(Eet_File *ef, const char *name, void (*dumpfunc)(
void *data,
const char *str), void *dumpdata);
/**
* Take an ascii encoding from eet_data_dump() and re-encode in binary.
@ -1992,7 +2201,11 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_Data_Group
*/
EAPI int eet_data_undump(Eet_File *ef, const char *name, const char *text, int textlen, int compress);
EAPI int eet_data_undump(Eet_File *ef,
const char *name,
const char *text,
int textlen,
int compress);
/**
* Decode a data structure from an arbitary location in memory.
@ -2021,7 +2234,9 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_Data_Group
*/
EAPI void *eet_data_descriptor_decode(Eet_Data_Descriptor *edd, const void *data_in, int size_in);
EAPI void *eet_data_descriptor_decode(Eet_Data_Descriptor *edd,
const void *data_in,
int size_in);
/**
* Encode a dsata struct to memory and return that encoded data.
@ -2052,7 +2267,9 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_Data_Group
*/
EAPI void *eet_data_descriptor_encode(Eet_Data_Descriptor *edd, const void *data_in, int *size_ret);
EAPI void *eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
const void *data_in,
int *size_ret);
/**
* Add a basic data element to a data descriptor.
@ -2083,7 +2300,8 @@ extern "C" {
struct_type ___ett; \
\
eet_data_descriptor_element_add(edd, name, type, EET_G_UNKNOWN, \
(char *)(&(___ett.member)) - (char *)(&(___ett)), \
(char *)(& (___ett.member)) - \
(char *)(& (___ett)), \
0, /* 0, */ NULL, NULL); \
}
@ -2110,7 +2328,8 @@ extern "C" {
struct_type ___ett; \
\
eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_UNKNOWN, \
(char *)(&(___ett.member)) - (char *)(&(___ett)), \
(char *)(& (___ett.member)) - \
(char *)(& (___ett)), \
0, /* 0, */ NULL, subtype); \
}
@ -2136,7 +2355,8 @@ extern "C" {
struct_type ___ett; \
\
eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_LIST, \
(char *)(&(___ett.member)) - (char *)(&(___ett)), \
(char *)(& (___ett.member)) - \
(char *)(& (___ett)), \
0, /* 0, */ NULL, subtype); \
}
@ -2162,7 +2382,8 @@ extern "C" {
struct_type ___ett; \
\
eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_HASH, \
(char *)(&(___ett.member)) - (char *)(&(___ett)), \
(char *)(& (___ett.member)) - \
(char *)(& (___ett)), \
0, /* 0, */ NULL, subtype); \
}
@ -2189,8 +2410,10 @@ extern "C" {
struct_type ___ett; \
\
eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_ARRAY, \
(char *)(&(___ett.member)) - (char *)(&(___ett)), \
/* 0, */sizeof(___ett.member)/sizeof(___ett.member[0]), NULL, subtype); \
(char *)(& (___ett.member)) - \
(char *)(& (___ett)), \
/* 0, */ sizeof(___ett.member) / \
sizeof(___ett.member[0]), NULL, subtype); \
}
/**
@ -2211,13 +2434,24 @@ extern "C" {
* @since 1.0.2
* @ingroup Eet_Data_Group
*/
#define EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY(edd, struct_type, name, member, subtype) \
#define EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY(edd, \
struct_type, \
name, \
member, \
subtype) \
{ \
struct_type ___ett; \
\
eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_VAR_ARRAY, \
(char *)(&(___ett.member)) - (char *)(&(___ett)), \
(char *)(&(___ett.member ## _count)) - (char *)(&(___ett)), /* 0, */NULL, subtype); \
eet_data_descriptor_element_add(edd, \
name, \
EET_T_UNKNOW, \
EET_G_VAR_ARRAY, \
(char *)(& (___ett.member)) - \
(char *)(& (___ett)), \
(char *)(& (___ett.member ## _count)) - \
(char *)(& (___ett)), \
/* 0, */ NULL, \
subtype); \
}
/**
@ -2239,13 +2473,20 @@ extern "C" {
* @ingroup Eet_Data_Group
* @see Eet_Data_Descriptor_Class
*/
#define EET_DATA_DESCRIPTOR_ADD_UNION(edd, struct_type, name, member, type_member, unified_type) \
#define EET_DATA_DESCRIPTOR_ADD_UNION(edd, \
struct_type, \
name, \
member, \
type_member, \
unified_type) \
{ \
struct_type ___ett; \
\
eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_UNION, \
(char *) (&(___ett.member)) - (char *)(&(___ett)), \
(char *) (&(___ett.type_member)) - (char *)(&(___ett)), \
(char *)(& (___ett.member)) - \
(char *)(& (___ett)), \
(char *)(& (___ett.type_member)) - \
(char *)(& (___ett)), \
NULL, unified_type); \
}
@ -2270,13 +2511,20 @@ extern "C" {
* @ingroup Eet_Data_Group
* @see Eet_Data_Descriptor_Class
*/
#define EET_DATA_DESCRIPTOR_ADD_VARIANT(edd, struct_type, name, member, type_member, unified_type) \
#define EET_DATA_DESCRIPTOR_ADD_VARIANT(edd, \
struct_type, \
name, \
member, \
type_member, \
unified_type) \
{ \
struct_type ___ett; \
\
eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_VARIANT, \
(char *) (&(___ett.member)) - (char *)(&(___ett)), \
(char *) (&(___ett.type_member)) - (char *)(&(___ett)), \
(char *)(& (___ett.member)) - \
(char *)(& (___ett)), \
(char *)(& (___ett.type_member)) - \
(char *)(& (___ett)), \
NULL, unified_type); \
}
@ -2291,7 +2539,14 @@ extern "C" {
* @see Eet_Data_Descriptor_Class
*/
#define EET_DATA_DESCRIPTOR_ADD_MAPPING(unified_type, name, subtype) \
eet_data_descriptor_element_add(unified_type, name, EET_T_UNKNOW, EET_G_UNKNOWN, 0, 0, NULL, subtype);
eet_data_descriptor_element_add(unified_type, \
name, \
EET_T_UNKNOW, \
EET_G_UNKNOWN, \
0, \
0, \
NULL, \
subtype);
/**
* @defgroup Eet_Data_Cipher_Group Eet Data Serialization using A Ciphers
@ -2332,7 +2587,10 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_Data_Cipher_Group
*/
EAPI void *eet_data_read_cipher(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const char *cipher_key);
EAPI void *eet_data_read_cipher(Eet_File *ef,
Eet_Data_Descriptor *edd,
const char *name,
const char *cipher_key);
/**
* Write a data structure from memory and store in an eet file
@ -2353,7 +2611,12 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_Data_Cipher_Group
*/
EAPI int eet_data_write_cipher(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const char *cipher_key, const void *data, int compress);
EAPI int eet_data_write_cipher(Eet_File *ef,
Eet_Data_Descriptor *edd,
const char *name,
const char *cipher_key,
const void *data,
int compress);
/**
* Dump an eet encoded data structure into ascii text using a cipher.
@ -2403,7 +2666,11 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_Data_Cipher_Group
*/
EAPI int eet_data_text_dump_cipher(const void *data_in, const char *cipher_key, int size_in, void (*dumpfunc) (void *data, const char *str), void *dumpdata);
EAPI int eet_data_text_dump_cipher(const void *data_in,
const char *cipher_key,
int size_in,
void (*dumpfunc)(void *data, const char *str),
void *dumpdata);
/**
* Take an ascii encoding from eet_data_text_dump() and re-encode
@ -2426,7 +2693,10 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_Data_Cipher_Group
*/
EAPI void *eet_data_text_undump_cipher(const char *text, const char *cipher_key, int textlen, int *size_ret);
EAPI void *eet_data_text_undump_cipher(const char *text,
const char *cipher_key,
int textlen,
int *size_ret);
/**
* Dump an eet encoded data structure from an eet file into ascii
@ -2453,7 +2723,11 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_Data_Cipher_Group
*/
EAPI int eet_data_dump_cipher(Eet_File *ef, const char *name, const char *cipher_key, void (*dumpfunc) (void *data, const char *str), void *dumpdata);
EAPI int eet_data_dump_cipher(Eet_File *ef,
const char *name,
const char *cipher_key,
void (*dumpfunc)(void *data, const char *str),
void *dumpdata);
/**
* Take an ascii encoding from eet_data_dump() and re-encode in
@ -2479,7 +2753,12 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_Data_Cipher_Group
*/
EAPI int eet_data_undump_cipher(Eet_File *ef, const char *name, const char *cipher_key, const char *text, int textlen, int compress);
EAPI int eet_data_undump_cipher(Eet_File *ef,
const char *name,
const char *cipher_key,
const char *text,
int textlen,
int compress);
/**
* Decode a data structure from an arbitary location in memory
@ -2510,7 +2789,10 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_Data_Cipher_Group
*/
EAPI void *eet_data_descriptor_decode_cipher(Eet_Data_Descriptor *edd, const void *data_in, const char *cipher_key, int size_in);
EAPI void *eet_data_descriptor_decode_cipher(Eet_Data_Descriptor *edd,
const void *data_in,
const char *cipher_key,
int size_in);
/**
* Encode a data struct to memory and return that encoded data
@ -2543,7 +2825,10 @@ extern "C" {
* @since 1.0.0
* @ingroup Eet_Data_Cipher_Group
*/
EAPI void *eet_data_descriptor_encode_cipher(Eet_Data_Descriptor *edd, const void *data_in, const char *cipher_key, int *size_ret);
EAPI void *eet_data_descriptor_encode_cipher(Eet_Data_Descriptor *edd,
const void *data_in,
const char *cipher_key,
int *size_ret);
/**
* @defgroup Eet_Node_Group Low-level Serialization Structures.
@ -2649,7 +2934,8 @@ extern "C" {
* TODO FIX ME
* @ingroup Eet_Node_Group
*/
EAPI Eet_Node *eet_node_unsigned_long_long_new(const char *name, unsigned long long l);
EAPI Eet_Node *eet_node_unsigned_long_long_new(const char *name,
unsigned long long l);
/**
* TODO FIX ME
@ -2691,7 +2977,9 @@ extern "C" {
* TODO FIX ME
* @ingroup Eet_Node_Group
*/
EAPI Eet_Node *eet_node_hash_new(const char *name, const char *key, Eet_Node *node);
EAPI Eet_Node *eet_node_hash_new(const char *name,
const char *key,
Eet_Node *node);
/**
* TODO FIX ME
@ -2710,26 +2998,35 @@ extern "C" {
* TODO FIX ME
* @ingroup Eet_Node_Group
*/
EAPI void eet_node_list_append(Eet_Node *parent, const char *name, Eet_Node *child);
EAPI void eet_node_list_append(Eet_Node *parent,
const char *name,
Eet_Node *child);
/**
* TODO FIX ME
* @ingroup Eet_Node_Group
*/
EAPI void eet_node_struct_append(Eet_Node *parent, const char *name, Eet_Node *child);
EAPI void eet_node_struct_append(Eet_Node *parent,
const char *name,
Eet_Node *child);
/**
* TODO FIX ME
* @ingroup Eet_Node_Group
*/
EAPI void eet_node_hash_add(Eet_Node *parent, const char *name, const char *key, Eet_Node *child);
EAPI void eet_node_hash_add(Eet_Node *parent,
const char *name,
const char *key,
Eet_Node *child);
/**
* TODO FIX ME
* @ingroup Eet_Node_Group
*/
EAPI void eet_node_dump(Eet_Node *n, int dumplevel, void (*dumpfunc) (void *data, const char *str), void *dumpdata);
EAPI void eet_node_dump(Eet_Node *n, int dumplevel, void (*dumpfunc)(
void *data,
const char *str), void *dumpdata);
/**
* TODO FIX ME
@ -2741,25 +3038,35 @@ extern "C" {
* TODO FIX ME
* @ingroup Eet_Node_Group
*/
EAPI void *eet_data_node_encode_cipher(Eet_Node *node, const char *cipher_key, int *size_ret);
EAPI void * eet_data_node_encode_cipher(Eet_Node *node,
const char *cipher_key,
int *size_ret);
/**
* TODO FIX ME
* @ingroup Eet_Node_Group
*/
EAPI Eet_Node *eet_data_node_decode_cipher(const void *data_in, const char *cipher_key, int size_in);
EAPI Eet_Node *eet_data_node_decode_cipher(const void *data_in,
const char *cipher_key,
int size_in);
/**
* TODO FIX ME
* @ingroup Eet_Node_Group
*/
EAPI Eet_Node *eet_data_node_read_cipher(Eet_File *ef, const char *name, const char *cipher_key);
EAPI Eet_Node *eet_data_node_read_cipher(Eet_File *ef,
const char *name,
const char *cipher_key);
/**
* TODO FIX ME
* @ingroup Eet_Node_Group
*/
EAPI int eet_data_node_write_cipher(Eet_File *ef, const char *name, const char *cipher_key, Eet_Node *node, int compress);
EAPI int eet_data_node_write_cipher(Eet_File *ef,
const char *name,
const char *cipher_key,
Eet_Node *node,
int compress);
/* EXPERIMENTAL: THIS API MAY CHANGE IN THE FUTURE, USE IT ONLY IF YOU KNOW WHAT YOU ARE DOING. */
@ -2776,16 +3083,23 @@ extern "C" {
struct _Eet_Node_Walk
{
void *(*struct_alloc)(const char *type, void *user_data);
void (*struct_add)(void *parent, const char *name, void *child, void *user_data);
void *(*array)(Eina_Bool variable, const char *name, int count, void *user_data);
void (*struct_add)(void *parent, const char *name, void *child,
void *user_data);
void *(*array)(Eina_Bool variable, const char *name, int count,
void *user_data);
void (*insert)(void *array, int index, void *child, void *user_data);
void *(*list)(const char *name, void *user_data);
void (*append)(void *list, void *child, void *user_data);
void *(*hash)(void *parent, const char *name, const char *key, void *value, void *user_data);
void *(*hash)(void *parent, const char *name, const char *key, void *value,
void *user_data);
void *(*simple)(int type, Eet_Node_Data *data, void *user_data);
};
EAPI void *eet_node_walk(void *parent, const char *name, Eet_Node *root, Eet_Node_Walk *cb, void *user_data);
EAPI void *eet_node_walk(void *parent,
const char *name,
Eet_Node *root,
Eet_Node_Walk *cb,
void *user_data);
/*******/
@ -2810,7 +3124,8 @@ extern "C" {
*
* @ingroup Eet_Connection_Group
*/
typedef Eina_Bool Eet_Read_Cb(const void *eet_data, size_t size, void *user_data);
typedef Eina_Bool Eet_Read_Cb (const void *eet_data, size_t size,
void *user_data);
/**
* @typedef Eet_Write_Cb
@ -2832,7 +3147,9 @@ extern "C" {
* @since 1.2.4
* @ingroup Eet_Connection_Group
*/
EAPI Eet_Connection *eet_connection_new(Eet_Read_Cb *eet_read_cb, Eet_Write_Cb *eet_write_cb, const void *user_data);
EAPI Eet_Connection *eet_connection_new(Eet_Read_Cb *eet_read_cb,
Eet_Write_Cb *eet_write_cb,
const void *user_data);
/**
* Process a raw packet received over the link
@ -2848,7 +3165,9 @@ extern "C" {
* @since 1.2.4
* @ingroup Eet_Connection_Group
*/
EAPI int eet_connection_received(Eet_Connection *conn, const void *data, size_t size);
EAPI int eet_connection_received(Eet_Connection *conn,
const void *data,
size_t size);
/**
* Convert a complex structure and prepare it to be send.
@ -2867,7 +3186,10 @@ extern "C" {
* @since 1.2.4
* @ingroup Eet_Connection_Group
*/
EAPI Eina_Bool eet_connection_send(Eet_Connection *conn, Eet_Data_Descriptor *edd, const void *data_in, const char *cipher_key);
EAPI Eina_Bool eet_connection_send(Eet_Connection *conn,
Eet_Data_Descriptor *edd,
const void *data_in,
const char *cipher_key);
/**
* Convert a Eet_Node tree and prepare it to be send.
@ -2885,7 +3207,9 @@ extern "C" {
* @since 1.2.4
* @ingroup Eet_Connection_Group
*/
EAPI Eina_Bool eet_connection_node_send(Eet_Connection *conn, Eet_Node *node, const char *cipher_key);
EAPI Eina_Bool eet_connection_node_send(Eet_Connection *conn,
Eet_Node *node,
const char *cipher_key);
/**
* Close a connection and lost its track.
@ -2896,7 +3220,8 @@ extern "C" {
* @since 1.2.4
* @ingroup Eet_Connection_Group
*/
EAPI void *eet_connection_close(Eet_Connection *conn, Eina_Bool *on_going);
EAPI void * eet_connection_close(Eet_Connection *conn,
Eina_Bool *on_going);
/***************************************************************************/

View File

@ -101,25 +101,50 @@ extern int _eet_log_dom_global;
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_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);
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,
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,
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_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);
@ -134,9 +159,9 @@ void eet_node_free(Eet_Node *node);
#endif
#ifdef DNDEBUG
# define EET_ASSERT(Test, Do) if (Test == 0) Do;
# define EET_ASSERT(Test, Do) if (Test == 0) {Do; }
#else
# define EET_ASSERT(Test, Do) if (Test == 0) abort();
# define EET_ASSERT(Test, Do) if (Test == 0) {abort(); }
#endif
#endif

View File

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

View File

@ -42,7 +42,8 @@ void *alloca (size_t);
#define MAGIC_EET_DATA_PACKET 0x4270ACE1
typedef struct _Eet_Message Eet_Message;
struct _Eet_Message {
struct _Eet_Message
{
int magic;
int size;
};
@ -138,7 +139,9 @@ eet_connection_received(Eet_Connection *conn, const void *data, size_t size)
}
/* Partial receive */
copy_size = (conn->size - conn->received >= size) ? size : conn->size - conn->received;
copy_size =
(conn->size - conn->received >=
size) ? size : conn->size - conn->received;
memcpy((char *)conn->buffer + conn->received, data, copy_size);
conn->received += copy_size;
@ -181,18 +184,26 @@ _eet_connection_raw_send(Eet_Connection *conn, void *data, int data_size)
memcpy(message + 1, data, data_size);
conn->eet_write_cb(message, data_size + sizeof (Eet_Message), conn->user_data);
conn->eet_write_cb(message,
data_size + sizeof (Eet_Message),
conn->user_data);
return EINA_TRUE;
}
EAPI Eina_Bool
eet_connection_send(Eet_Connection *conn, Eet_Data_Descriptor *edd, const void *data_in, const char *cipher_key)
eet_connection_send(Eet_Connection *conn,
Eet_Data_Descriptor *edd,
const void *data_in,
const char *cipher_key)
{
void *flat_data;
int data_size;
Eina_Bool ret = EINA_FALSE;
flat_data = eet_data_descriptor_encode_cipher(edd, data_in, cipher_key, &data_size);
flat_data = eet_data_descriptor_encode_cipher(edd,
data_in,
cipher_key,
&data_size);
if (!flat_data)
return EINA_FALSE;
@ -204,7 +215,9 @@ eet_connection_send(Eet_Connection *conn, Eet_Data_Descriptor *edd, const void *
}
EAPI Eina_Bool
eet_connection_node_send(Eet_Connection *conn, Eet_Node *node, const char *cipher_key)
eet_connection_node_send(Eet_Connection *conn,
Eet_Node *node,
const char *cipher_key)
{
void *data;
int data_size;

File diff suppressed because it is too large Load Diff

View File

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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@ -21,15 +21,19 @@ _eet_str_direct_free(const char *str)
static void
_eet_eina_hash_foreach(void *hash, Eina_Hash_Foreach cb, void *fdata)
{
if (hash) eina_hash_foreach(hash, cb, fdata);
if (hash)
eina_hash_foreach(hash, cb, fdata);
}
/* Internal wrapper for eina_hash */
static Eina_Hash *
_eet_eina_hash_add(Eina_Hash *hash, const char *key, const void *data)
{
if (!hash) hash = eina_hash_string_superfast_new(NULL);
if (!hash) return NULL;
if (!hash)
hash = eina_hash_string_superfast_new(NULL);
if (!hash)
return NULL;
eina_hash_add(hash, key, data);
return hash;
@ -38,7 +42,8 @@ _eet_eina_hash_add(Eina_Hash *hash, const char *key, const void *data)
static void
_eet_eina_hash_free(Eina_Hash *hash)
{
if (hash) eina_hash_free(hash);
if (hash)
eina_hash_free(hash);
}
void

File diff suppressed because it is too large Load Diff