forked from enlightenment/efl
parent
55d0190185
commit
f7019f134d
|
@ -4,55 +4,54 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
#endif /* ifdef HAVE_CONFIG_H */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifndef _MSC_VER
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#endif /* ifndef _MSC_VER */
|
||||
|
||||
#ifdef HAVE_EVIL
|
||||
# include <Evil.h>
|
||||
#endif
|
||||
#endif /* ifdef HAVE_EVIL */
|
||||
|
||||
#include <Eet.h>
|
||||
|
||||
|
||||
static int _eet_main_log_dom = -1;
|
||||
|
||||
#ifdef EET_DEFAULT_LOG_COLOR
|
||||
#undef EET_DEFAULT_LOG_COLOR
|
||||
#endif
|
||||
#endif /* ifdef EET_DEFAULT_LOG_COLOR */
|
||||
#define EET_DEFAULT_LOG_COLOR EINA_COLOR_CYAN
|
||||
#ifdef ERR
|
||||
#undef ERR
|
||||
#endif
|
||||
#define ERR(...) EINA_LOG_DOM_ERR(_eet_main_log_dom, __VA_ARGS__)
|
||||
#endif /* ifdef ERR */
|
||||
#define ERR(...) EINA_LOG_DOM_ERR(_eet_main_log_dom, __VA_ARGS__)
|
||||
#ifdef DBG
|
||||
#undef DBG
|
||||
#endif
|
||||
#define DBG(...) EINA_LOG_DOM_DBG(_eet_main_log_dom, __VA_ARGS__)
|
||||
#endif /* ifdef DBG */
|
||||
#define DBG(...) EINA_LOG_DOM_DBG(_eet_main_log_dom, __VA_ARGS__)
|
||||
#ifdef INF
|
||||
#undef INF
|
||||
#endif
|
||||
#define INF(...) EINA_LOG_DOM_INFO(_eet_main_log_dom, __VA_ARGS__)
|
||||
#endif /* ifdef INF */
|
||||
#define INF(...) EINA_LOG_DOM_INFO(_eet_main_log_dom, __VA_ARGS__)
|
||||
#ifdef WRN
|
||||
#undef WRN
|
||||
#endif
|
||||
#define WRN(...) EINA_LOG_DOM_WARN(_eet_main_log_dom, __VA_ARGS__)
|
||||
#endif /* ifdef WRN */
|
||||
#define WRN(...) EINA_LOG_DOM_WARN(_eet_main_log_dom, __VA_ARGS__)
|
||||
#ifdef CRIT
|
||||
#undef CRIT
|
||||
#endif
|
||||
#endif /* ifdef CRIT */
|
||||
#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)
|
||||
|
@ -70,18 +69,18 @@ do_eet_list(const char *file)
|
|||
}
|
||||
|
||||
eet_close(ef);
|
||||
}
|
||||
} /* 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)
|
||||
|
@ -113,22 +112,22 @@ do_eet_extract(const char *file,
|
|||
fclose(f);
|
||||
free(data);
|
||||
eet_close(ef);
|
||||
}
|
||||
} /* 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)
|
||||
|
@ -152,19 +151,19 @@ do_eet_decode(const char *file,
|
|||
|
||||
fclose(f);
|
||||
eet_close(ef);
|
||||
}
|
||||
} /* 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)
|
||||
|
@ -203,20 +202,20 @@ do_eet_insert(const char *file,
|
|||
eet_write_cipher(ef, key, data, size, compress, crypto_key);
|
||||
free(data);
|
||||
eet_close(ef);
|
||||
}
|
||||
} /* 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)
|
||||
|
@ -260,12 +259,12 @@ do_eet_encode(const char *file,
|
|||
|
||||
free(text);
|
||||
eet_close(ef);
|
||||
}
|
||||
} /* 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)
|
||||
|
@ -276,13 +275,13 @@ do_eet_remove(const char *file, const char *key)
|
|||
|
||||
eet_delete(ef, key);
|
||||
eet_close(ef);
|
||||
}
|
||||
} /* 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;
|
||||
|
||||
|
@ -302,13 +301,13 @@ do_eet_check(const char *file)
|
|||
fprintf(stdout, "Signature length %i.\n", sign_length);
|
||||
|
||||
eet_close(ef);
|
||||
}
|
||||
} /* 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)
|
||||
|
@ -330,10 +329,10 @@ do_eet_sign(const char *file, const char *private_key, const char *public_key)
|
|||
eet_identity_set(ef, key);
|
||||
|
||||
eet_close(ef);
|
||||
}
|
||||
} /* do_eet_sign */
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(int argc, char ** argv)
|
||||
{
|
||||
if (!eet_init())
|
||||
return -1;
|
||||
|
@ -397,7 +396,7 @@ help:
|
|||
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]);
|
||||
else if ((!strcmp(argv[1], "-s")) && (argc > 4))
|
||||
|
@ -408,4 +407,5 @@ help:
|
|||
eina_log_domain_unregister(_eet_main_log_dom);
|
||||
eet_shutdown();
|
||||
return 0;
|
||||
}
|
||||
} /* main */
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
// complex real-world structures based on elmdentica database
|
||||
typedef struct
|
||||
{
|
||||
const char *screen_name;
|
||||
const char *name;
|
||||
const char *message;
|
||||
const char * screen_name;
|
||||
const char * name;
|
||||
const char * message;
|
||||
unsigned int id;
|
||||
unsigned int status_id;
|
||||
unsigned int date;
|
||||
|
@ -20,22 +20,22 @@ typedef struct
|
|||
|
||||
typedef struct
|
||||
{
|
||||
const char *dm_to;
|
||||
const char *message;
|
||||
const char * dm_to;
|
||||
const char * message;
|
||||
} My_Post;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int id;
|
||||
const char *name;
|
||||
Eina_List *messages;
|
||||
Eina_List *posts;
|
||||
const char * name;
|
||||
Eina_List * messages;
|
||||
Eina_List * posts;
|
||||
} My_Account;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int version; // it is recommended to use versioned configuration!
|
||||
Eina_List *accounts;
|
||||
Eina_List * accounts;
|
||||
} My_Cache;
|
||||
|
||||
// string that represents the entry in eet file, you might like to have
|
||||
|
@ -46,14 +46,14 @@ static const char MY_CACHE_FILE_ENTRY[] = "cache";
|
|||
// 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_cache_descriptor;
|
||||
static Eet_Data_Descriptor *_my_account_descriptor;
|
||||
static Eet_Data_Descriptor *_my_message_descriptor;
|
||||
static Eet_Data_Descriptor *_my_post_descriptor;
|
||||
static Eet_Data_Descriptor * _my_cache_descriptor;
|
||||
static Eet_Data_Descriptor * _my_account_descriptor;
|
||||
static Eet_Data_Descriptor * _my_message_descriptor;
|
||||
static Eet_Data_Descriptor * _my_post_descriptor;
|
||||
|
||||
// keep file handle alive, so mmap()ed strings are all alive as well
|
||||
static Eet_File *_my_cache_file = NULL;
|
||||
static Eet_Dictionary *_my_cache_dict = NULL;
|
||||
static Eet_File * _my_cache_file = NULL;
|
||||
static Eet_Dictionary * _my_cache_dict = NULL;
|
||||
|
||||
static void
|
||||
_my_cache_descriptor_init(void)
|
||||
|
@ -78,8 +78,8 @@ _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 \
|
||||
#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);
|
||||
|
@ -90,15 +90,15 @@ _my_cache_descriptor_init(void)
|
|||
ADD_BASIC(timeline, EET_T_UINT);
|
||||
#undef ADD_BASIC
|
||||
|
||||
#define ADD_BASIC(member, eet_type) \
|
||||
EET_DATA_DESCRIPTOR_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);
|
||||
ADD_BASIC(message, EET_T_STRING);
|
||||
#undef ADD_BASIC
|
||||
|
||||
#define ADD_BASIC(member, eet_type) \
|
||||
EET_DATA_DESCRIPTOR_ADD_BASIC \
|
||||
#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);
|
||||
|
@ -111,8 +111,8 @@ _my_cache_descriptor_init(void)
|
|||
(_my_account_descriptor, My_Account, "posts", posts,
|
||||
_my_post_descriptor);
|
||||
|
||||
#define ADD_BASIC(member, eet_type) \
|
||||
EET_DATA_DESCRIPTOR_ADD_BASIC \
|
||||
#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
|
||||
|
@ -120,7 +120,7 @@ _my_cache_descriptor_init(void)
|
|||
EET_DATA_DESCRIPTOR_ADD_LIST
|
||||
(_my_cache_descriptor, My_Cache, "accounts", accounts,
|
||||
_my_account_descriptor);
|
||||
}
|
||||
} /* _my_cache_descriptor_init */
|
||||
|
||||
static void
|
||||
_my_cache_descriptor_shutdown(void)
|
||||
|
@ -129,12 +129,12 @@ _my_cache_descriptor_shutdown(void)
|
|||
eet_data_descriptor_free(_my_account_descriptor);
|
||||
eet_data_descriptor_free(_my_message_descriptor);
|
||||
eet_data_descriptor_free(_my_post_descriptor);
|
||||
}
|
||||
} /* _my_cache_descriptor_shutdown */
|
||||
|
||||
// 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;
|
||||
|
@ -143,12 +143,12 @@ _eet_string_free(const char *str)
|
|||
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");
|
||||
|
@ -157,21 +157,21 @@ _my_message_new(const char *message)
|
|||
|
||||
msg->message = eina_stringshare_add(message);
|
||||
return msg;
|
||||
}
|
||||
} /* _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);
|
||||
_eet_string_free(msg->message);
|
||||
free(msg);
|
||||
}
|
||||
} /* _my_message_free */
|
||||
|
||||
static My_Post *
|
||||
_my_post_new(const char *message)
|
||||
_my_post_new(const char * message)
|
||||
{
|
||||
My_Post *post = calloc(1, sizeof(My_Post));
|
||||
My_Post * post = calloc(1, sizeof(My_Post));
|
||||
if (!post)
|
||||
{
|
||||
fprintf(stderr, "ERROR: could not calloc My_Post\n");
|
||||
|
@ -180,20 +180,20 @@ _my_post_new(const char *message)
|
|||
|
||||
post->message = eina_stringshare_add(message);
|
||||
return post;
|
||||
}
|
||||
} /* _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);
|
||||
free(post);
|
||||
}
|
||||
} /* _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");
|
||||
|
@ -202,13 +202,13 @@ _my_account_new(const char *name)
|
|||
|
||||
acc->name = eina_stringshare_add(name);
|
||||
return acc;
|
||||
}
|
||||
} /* _my_account_new */
|
||||
|
||||
static void
|
||||
_my_account_free(My_Account *acc)
|
||||
_my_account_free(My_Account * acc)
|
||||
{
|
||||
My_Message *m;
|
||||
My_Post *p;
|
||||
My_Message * m;
|
||||
My_Post * p;
|
||||
|
||||
_eet_string_free(acc->name);
|
||||
|
||||
|
@ -219,12 +219,12 @@ _my_account_free(My_Account *acc)
|
|||
_my_post_free(p);
|
||||
|
||||
free(acc);
|
||||
}
|
||||
} /* _my_account_free */
|
||||
|
||||
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");
|
||||
|
@ -233,34 +233,34 @@ _my_cache_new(void)
|
|||
|
||||
my_cache->version = 1;
|
||||
return my_cache;
|
||||
}
|
||||
} /* _my_cache_new */
|
||||
|
||||
static void
|
||||
_my_cache_free(My_Cache *my_cache)
|
||||
_my_cache_free(My_Cache * my_cache)
|
||||
{
|
||||
My_Account *acc;
|
||||
My_Account * acc;
|
||||
EINA_LIST_FREE(my_cache->accounts, acc)
|
||||
_my_account_free(acc);
|
||||
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)
|
||||
{
|
||||
My_Account *acc;
|
||||
Eina_List *l;
|
||||
My_Account * acc;
|
||||
Eina_List * l;
|
||||
EINA_LIST_FOREACH(my_cache->accounts, l, acc)
|
||||
if (strcmp(acc->name, name) == 0)
|
||||
return acc;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
} /* _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);
|
||||
|
@ -290,13 +290,13 @@ _my_cache_load(const char *filename)
|
|||
_my_cache_dict = eet_dictionary_get(ef);
|
||||
|
||||
return my_cache;
|
||||
}
|
||||
} /* _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;
|
||||
|
@ -343,13 +343,13 @@ _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_Account *acc;
|
||||
My_Cache * my_cache;
|
||||
const Eina_List * l_acc;
|
||||
My_Account * acc;
|
||||
int ret = 0;
|
||||
|
||||
if (argc < 3)
|
||||
|
@ -387,7 +387,7 @@ 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]);
|
||||
|
@ -399,7 +399,7 @@ int main(int argc, char *argv[])
|
|||
argv[4]);
|
||||
}
|
||||
else
|
||||
fprintf(stderr,
|
||||
fprintf(stderr,
|
||||
"ERROR: wrong number of parameters (%d).\n",
|
||||
argc);
|
||||
}
|
||||
|
@ -407,17 +407,17 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
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 *post = _my_post_new(argv[5]);
|
||||
My_Post * post = _my_post_new(argv[5]);
|
||||
acc->posts = eina_list_append(acc->posts, post);
|
||||
}
|
||||
else
|
||||
fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]);
|
||||
}
|
||||
else
|
||||
fprintf(stderr,
|
||||
fprintf(stderr,
|
||||
"ERROR: wrong number of parameters (%d).\n",
|
||||
argc);
|
||||
}
|
||||
|
@ -425,32 +425,32 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
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]);
|
||||
}
|
||||
else
|
||||
fprintf(stderr,
|
||||
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"
|
||||
printf("My_Cache:\n"
|
||||
"\tversion.: %#x\n"
|
||||
"\taccounts: %u\n",
|
||||
my_cache->version,
|
||||
eina_list_count(my_cache->accounts));
|
||||
EINA_LIST_FOREACH(my_cache->accounts, l_acc, 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 : "",
|
||||
|
@ -459,8 +459,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
if (eina_list_count(acc->messages))
|
||||
{
|
||||
const Eina_List *l;
|
||||
const My_Message *msg;
|
||||
const Eina_List * l;
|
||||
const My_Message * msg;
|
||||
printf("\t |messages:\n");
|
||||
|
||||
EINA_LIST_FOREACH(acc->messages, l, msg)
|
||||
|
@ -475,11 +475,11 @@ int main(int argc, char *argv[])
|
|||
|
||||
if (eina_list_count(acc->posts))
|
||||
{
|
||||
const Eina_List *l;
|
||||
const My_Post *post;
|
||||
printf("\t |posts:\n");
|
||||
const Eina_List * l;
|
||||
const My_Post * post;
|
||||
printf("\t |posts:\n");
|
||||
|
||||
EINA_LIST_FOREACH(acc->posts, l, post)
|
||||
EINA_LIST_FOREACH(acc->posts, l, post)
|
||||
{
|
||||
if (post->dm_to)
|
||||
printf("\t | @%s: '%.20s'\n", post->dm_to, post->message);
|
||||
|
@ -488,7 +488,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if (!_my_cache_save(my_cache, argv[2]))
|
||||
|
@ -502,4 +502,5 @@ end:
|
|||
eina_shutdown();
|
||||
|
||||
return ret;
|
||||
}
|
||||
} /* main */
|
||||
|
||||
|
|
|
@ -14,17 +14,17 @@
|
|||
typedef struct
|
||||
{
|
||||
unsigned int version; // it is recommended to use versioned configuration!
|
||||
const char *name;
|
||||
int id;
|
||||
int not_saved_value; // example of not saved data inside!
|
||||
Eina_Bool enabled;
|
||||
Eina_List *subs;
|
||||
const char * name;
|
||||
int id;
|
||||
int not_saved_value; // example of not saved data inside!
|
||||
Eina_Bool enabled;
|
||||
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
|
||||
|
@ -32,12 +32,11 @@ typedef struct
|
|||
// different strings
|
||||
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)
|
||||
|
@ -64,11 +63,11 @@ _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 \
|
||||
#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 \
|
||||
#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);
|
||||
|
@ -85,20 +84,20 @@ _my_conf_descriptor_init(void)
|
|||
|
||||
#undef MY_CONF_ADD_BASIC
|
||||
#undef MY_CONF_SUB_ADD_BASIC
|
||||
}
|
||||
} /* _my_conf_descriptor_init */
|
||||
|
||||
static void
|
||||
_my_conf_descriptor_shutdown(void)
|
||||
{
|
||||
eet_data_descriptor_free(_my_conf_sub_descriptor);
|
||||
eet_data_descriptor_free(_my_conf_descriptor);
|
||||
}
|
||||
} /* _my_conf_descriptor_shutdown */
|
||||
|
||||
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");
|
||||
|
@ -117,12 +116,12 @@ _my_conf_new(void)
|
|||
}
|
||||
|
||||
return my_conf;
|
||||
}
|
||||
} /* _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);
|
||||
|
@ -131,13 +130,13 @@ _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);
|
||||
|
@ -161,13 +160,13 @@ _my_conf_load(const char *filename)
|
|||
end:
|
||||
eet_close(ef);
|
||||
return my_conf;
|
||||
}
|
||||
} /* _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;
|
||||
|
@ -205,13 +204,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)
|
||||
|
@ -236,7 +235,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
printf("My_Conf_Type:\n"
|
||||
printf("My_Conf_Type:\n"
|
||||
"\tversion: %#x\n"
|
||||
"\tname...: '%s'\n"
|
||||
"\tid.....: %d\n"
|
||||
|
@ -263,4 +262,5 @@ end:
|
|||
eina_shutdown();
|
||||
|
||||
return ret;
|
||||
}
|
||||
} /* main */
|
||||
|
||||
|
|
|
@ -14,10 +14,10 @@
|
|||
typedef struct
|
||||
{
|
||||
unsigned int version; // it is recommended to use versioned configuration!
|
||||
const char *name;
|
||||
int id;
|
||||
int not_saved_value; // example of not saved data inside!
|
||||
Eina_Bool enabled;
|
||||
const char * name;
|
||||
int id;
|
||||
int not_saved_value; // example of not saved data inside!
|
||||
Eina_Bool enabled;
|
||||
} My_Conf_Type;
|
||||
|
||||
// string that represents the entry in eet file, you might like to have
|
||||
|
@ -25,11 +25,10 @@ typedef struct
|
|||
// different strings
|
||||
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)
|
||||
|
@ -53,8 +52,8 @@ _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 \
|
||||
#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);
|
||||
|
@ -63,18 +62,18 @@ _my_conf_descriptor_init(void)
|
|||
MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR);
|
||||
|
||||
#undef MY_CONF_ADD_BASIC
|
||||
}
|
||||
} /* _my_conf_descriptor_init */
|
||||
|
||||
static void
|
||||
_my_conf_descriptor_shutdown(void)
|
||||
{
|
||||
eet_data_descriptor_free(_my_conf_descriptor);
|
||||
}
|
||||
} /* _my_conf_descriptor_shutdown */
|
||||
|
||||
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");
|
||||
|
@ -84,20 +83,20 @@ _my_conf_new(void)
|
|||
my_conf->version = 0x112233;
|
||||
my_conf->enabled = EINA_TRUE;
|
||||
return my_conf;
|
||||
}
|
||||
} /* _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);
|
||||
|
@ -121,13 +120,13 @@ _my_conf_load(const char *filename)
|
|||
end:
|
||||
eet_close(ef);
|
||||
return my_conf;
|
||||
}
|
||||
} /* _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;
|
||||
|
@ -165,11 +164,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)
|
||||
|
@ -194,7 +193,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
printf("My_Conf_Type:\n"
|
||||
printf("My_Conf_Type:\n"
|
||||
"\tversion: %#x\n"
|
||||
"\tname...: '%s'\n"
|
||||
"\tid.....: %d\n"
|
||||
|
@ -215,4 +214,5 @@ end:
|
|||
eina_shutdown();
|
||||
|
||||
return ret;
|
||||
}
|
||||
} /* main */
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -7,60 +7,60 @@
|
|||
|
||||
#include <Eina.h>
|
||||
|
||||
typedef enum _Eet_Convert_Type Eet_Convert_Type;
|
||||
typedef enum _Eet_Convert_Type Eet_Convert_Type;
|
||||
|
||||
enum _Eet_Convert_Type
|
||||
{
|
||||
EET_D_NOT_CONVERTED = 0,
|
||||
EET_D_FLOAT = 1 << 1,
|
||||
EET_D_DOUBLE = 1 << 2,
|
||||
EET_D_FIXED_POINT = 1 << 4
|
||||
EET_D_FLOAT = 1 << 1,
|
||||
EET_D_DOUBLE = 1 << 2,
|
||||
EET_D_FIXED_POINT = 1 << 4
|
||||
};
|
||||
|
||||
typedef struct _Eet_String Eet_String;
|
||||
typedef struct _Eet_String Eet_String;
|
||||
|
||||
struct _Eet_String
|
||||
{
|
||||
const char *mmap;
|
||||
char *str;
|
||||
const char * mmap;
|
||||
char * str;
|
||||
|
||||
int hash;
|
||||
int len;
|
||||
int hash;
|
||||
int len;
|
||||
|
||||
int next;
|
||||
int prev;
|
||||
int next;
|
||||
int prev;
|
||||
|
||||
float f;
|
||||
double d;
|
||||
Eina_F32p32 fp;
|
||||
float f;
|
||||
double d;
|
||||
Eina_F32p32 fp;
|
||||
|
||||
Eet_Convert_Type type;
|
||||
};
|
||||
struct _Eet_Dictionary
|
||||
{
|
||||
Eet_String *all;
|
||||
Eet_String * all;
|
||||
|
||||
int size;
|
||||
int offset;
|
||||
int size;
|
||||
int offset;
|
||||
|
||||
int hash[256];
|
||||
int hash[256];
|
||||
|
||||
int count;
|
||||
int total;
|
||||
int count;
|
||||
int total;
|
||||
|
||||
const char *start;
|
||||
const char *end;
|
||||
const char * start;
|
||||
const char * end;
|
||||
};
|
||||
|
||||
struct _Eet_Node
|
||||
{
|
||||
int type;
|
||||
int count;
|
||||
const char *name;
|
||||
const char *key;
|
||||
Eet_Node *values;
|
||||
Eet_Node *next;
|
||||
Eet_Node *parent;
|
||||
int type;
|
||||
int count;
|
||||
const char * name;
|
||||
const char * key;
|
||||
Eet_Node * values;
|
||||
Eet_Node * next;
|
||||
Eet_Node * parent;
|
||||
Eet_Node_Data data;
|
||||
};
|
||||
|
||||
|
@ -76,92 +76,93 @@ extern int _eet_log_dom_global;
|
|||
*/
|
||||
#ifdef EET_DEFAULT_LOG_COLOR
|
||||
# undef EET_DEFAULT_LOG_COLOR
|
||||
#endif
|
||||
#endif /* ifdef EET_DEFAULT_LOG_COLOR */
|
||||
#define EET_DEFAULT_LOG_COLOR EINA_COLOR_CYAN
|
||||
#ifdef ERR
|
||||
# undef ERR
|
||||
#endif
|
||||
#define ERR(...) EINA_LOG_DOM_ERR(_eet_log_dom_global, __VA_ARGS__)
|
||||
#endif /* ifdef ERR */
|
||||
#define ERR(...) EINA_LOG_DOM_ERR(_eet_log_dom_global, __VA_ARGS__)
|
||||
#ifdef DBG
|
||||
# undef DBG
|
||||
#endif
|
||||
#define DBG(...) EINA_LOG_DOM_DBG(_eet_log_dom_global, __VA_ARGS__)
|
||||
#endif /* ifdef DBG */
|
||||
#define DBG(...) EINA_LOG_DOM_DBG(_eet_log_dom_global, __VA_ARGS__)
|
||||
#ifdef INF
|
||||
# undef INF
|
||||
#endif
|
||||
#define INF(...) EINA_LOG_DOM_INFO(_eet_log_dom_global, __VA_ARGS__)
|
||||
#endif /* ifdef INF */
|
||||
#define INF(...) EINA_LOG_DOM_INFO(_eet_log_dom_global, __VA_ARGS__)
|
||||
#ifdef WRN
|
||||
# undef WRN
|
||||
#endif
|
||||
#define WRN(...) EINA_LOG_DOM_WARN(_eet_log_dom_global, __VA_ARGS__)
|
||||
#endif /* ifdef WRN */
|
||||
#define WRN(...) EINA_LOG_DOM_WARN(_eet_log_dom_global, __VA_ARGS__)
|
||||
#ifdef CRIT
|
||||
# undef CRIT
|
||||
#endif
|
||||
#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
|
||||
#endif
|
||||
#endif /* ifndef PATH_MAX */
|
||||
|
||||
#ifdef DNDEBUG
|
||||
# define EET_ASSERT(Test, Do) if (Test == 0) {Do; }
|
||||
#else
|
||||
#else /* ifdef DNDEBUG */
|
||||
# define EET_ASSERT(Test, Do) if (Test == 0) {abort(); }
|
||||
#endif
|
||||
#endif /* ifdef DNDEBUG */
|
||||
|
||||
#endif
|
||||
#endif /* ifndef _EET_PRIVATE_H */
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
#endif /* ifdef HAVE_CONFIG_H */
|
||||
|
||||
#ifdef HAVE_ALLOCA_H
|
||||
# include <alloca.h>
|
||||
|
@ -11,13 +11,13 @@
|
|||
#elif defined _MSC_VER
|
||||
# include <malloc.h>
|
||||
# define alloca _alloca
|
||||
#else
|
||||
#else /* ifdef HAVE_ALLOCA_H */
|
||||
# include <stddef.h>
|
||||
# ifdef __cplusplus
|
||||
extern "C"
|
||||
# endif
|
||||
void *alloca (size_t);
|
||||
#endif
|
||||
# endif /* ifdef __cplusplus */
|
||||
void * alloca (size_t);
|
||||
#endif /* ifdef HAVE_ALLOCA_H */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -27,17 +27,17 @@ void *alloca (size_t);
|
|||
|
||||
#ifndef _MSC_VER
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#endif /* ifndef _MSC_VER */
|
||||
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
#endif /* ifdef HAVE_NETINET_IN_H */
|
||||
|
||||
#ifdef HAVE_SIGNATURE
|
||||
# ifdef HAVE_GNUTLS
|
||||
# include <gnutls/gnutls.h>
|
||||
# include <gnutls/x509.h>
|
||||
# else
|
||||
# else /* ifdef HAVE_GNUTLS */
|
||||
# include <openssl/rsa.h>
|
||||
# include <openssl/objects.h>
|
||||
# include <openssl/err.h>
|
||||
|
@ -47,23 +47,23 @@ void *alloca (size_t);
|
|||
# include <openssl/evp.h>
|
||||
# include <openssl/x509.h>
|
||||
# include <openssl/pem.h>
|
||||
# endif
|
||||
#endif
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
#endif /* ifdef HAVE_SIGNATURE */
|
||||
|
||||
#ifdef HAVE_OPENSSL
|
||||
# include <openssl/sha.h>
|
||||
#endif
|
||||
# include <openssl/sha.h>
|
||||
#endif /* ifdef HAVE_OPENSSL */
|
||||
|
||||
#ifdef HAVE_CIPHER
|
||||
# ifdef HAVE_GNUTLS
|
||||
# include <gnutls/x509.h>
|
||||
# include <gcrypt.h>
|
||||
# else
|
||||
# else /* ifdef HAVE_GNUTLS */
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/hmac.h>
|
||||
# include <openssl/rand.h>
|
||||
# endif
|
||||
#endif
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
#endif /* ifdef HAVE_CIPHER */
|
||||
|
||||
#include "Eet.h"
|
||||
#include "Eet_private.h"
|
||||
|
@ -71,58 +71,58 @@ void *alloca (size_t);
|
|||
#define EET_MAGIC_SIGN 0x1ee74271
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
# define MAX_KEY_LEN 32
|
||||
# define MAX_IV_LEN 16
|
||||
#else
|
||||
# define MAX_KEY_LEN EVP_MAX_KEY_LENGTH
|
||||
# define MAX_IV_LEN EVP_MAX_IV_LENGTH
|
||||
#endif
|
||||
# define MAX_KEY_LEN 32
|
||||
# define MAX_IV_LEN 16
|
||||
#else /* ifdef HAVE_GNUTLS */
|
||||
# define MAX_KEY_LEN EVP_MAX_KEY_LENGTH
|
||||
# define MAX_IV_LEN EVP_MAX_IV_LENGTH
|
||||
#endif /* ifdef HAVE_GNUTLS */
|
||||
|
||||
#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);
|
||||
# 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);
|
||||
#endif
|
||||
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);
|
||||
#endif /* ifdef HAVE_CIPHER */
|
||||
|
||||
struct _Eet_Key
|
||||
{
|
||||
int references;
|
||||
int references;
|
||||
#ifdef HAVE_SIGNATURE
|
||||
# ifdef HAVE_GNUTLS
|
||||
gnutls_x509_crt_t certificate;
|
||||
gnutls_x509_crt_t certificate;
|
||||
gnutls_x509_privkey_t private_key;
|
||||
# else
|
||||
X509 *certificate;
|
||||
EVP_PKEY *private_key;
|
||||
# endif
|
||||
#endif
|
||||
# else /* ifdef HAVE_GNUTLS */
|
||||
X509 * certificate;
|
||||
EVP_PKEY * private_key;
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
#endif /* ifdef HAVE_SIGNATURE */
|
||||
};
|
||||
|
||||
EAPI Eet_Key *
|
||||
eet_identity_open(const char *certificate_file,
|
||||
const char *private_key_file,
|
||||
eet_identity_open(const char * certificate_file,
|
||||
const char * private_key_file,
|
||||
Eet_Key_Password_Callback cb)
|
||||
{
|
||||
#ifdef HAVE_SIGNATURE
|
||||
/* Signature declarations */
|
||||
Eet_Key *key = NULL;
|
||||
FILE *fp = NULL;
|
||||
Eet_Key * key = NULL;
|
||||
FILE * fp = NULL;
|
||||
# ifdef HAVE_GNUTLS
|
||||
/* Gnutls private declarations */
|
||||
int fd = -1;
|
||||
struct stat st;
|
||||
void *data = NULL;
|
||||
void * data = NULL;
|
||||
gnutls_datum_t load_file = { NULL, 0 };
|
||||
char pass[1024];
|
||||
|
||||
|
@ -208,7 +208,7 @@ eet_identity_open(const char *certificate_file,
|
|||
if (munmap(data, st.st_size))
|
||||
goto on_error;
|
||||
|
||||
fclose(fp);
|
||||
fclose(fp);
|
||||
|
||||
return key;
|
||||
|
||||
|
@ -230,10 +230,10 @@ on_error:
|
|||
if (data)
|
||||
munmap(data, st.st_size);
|
||||
|
||||
# else
|
||||
# else /* ifdef HAVE_GNUTLS */
|
||||
/* Openssl private declarations */
|
||||
EVP_PKEY *pkey = NULL;
|
||||
X509 *cert = NULL;
|
||||
EVP_PKEY * pkey = NULL;
|
||||
X509 * cert = NULL;
|
||||
|
||||
/* Load the X509 certificate in memory. */
|
||||
fp = fopen(certificate_file, "r");
|
||||
|
@ -278,13 +278,13 @@ on_error:
|
|||
if (pkey)
|
||||
EVP_PKEY_free(pkey);
|
||||
|
||||
# endif
|
||||
#endif
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
#endif /* ifdef HAVE_SIGNATURE */
|
||||
return NULL;
|
||||
}
|
||||
} /* eet_identity_open */
|
||||
|
||||
EAPI void
|
||||
eet_identity_close(Eet_Key *key)
|
||||
eet_identity_close(Eet_Key * key)
|
||||
{
|
||||
#ifdef HAVE_SIGNATURE
|
||||
if (!key || (key->references > 0))
|
||||
|
@ -293,20 +293,21 @@ eet_identity_close(Eet_Key *key)
|
|||
# ifdef HAVE_GNUTLS
|
||||
gnutls_x509_crt_deinit(key->certificate);
|
||||
gnutls_x509_privkey_deinit(key->private_key);
|
||||
# else
|
||||
# else /* ifdef HAVE_GNUTLS */
|
||||
X509_free(key->certificate);
|
||||
EVP_PKEY_free(key->private_key);
|
||||
# endif
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
free(key);
|
||||
#endif
|
||||
}
|
||||
#endif /* ifdef HAVE_SIGNATURE */
|
||||
} /* eet_identity_close */
|
||||
|
||||
EAPI void
|
||||
eet_identity_print(Eet_Key *key, FILE *out)
|
||||
eet_identity_print(Eet_Key * key,
|
||||
FILE * out)
|
||||
{
|
||||
#ifdef HAVE_SIGNATURE
|
||||
# ifdef HAVE_GNUTLS
|
||||
const char *names[6] = {
|
||||
const char * names[6] = {
|
||||
"Modulus",
|
||||
"Public exponent",
|
||||
"Private exponent",
|
||||
|
@ -318,7 +319,7 @@ eet_identity_print(Eet_Key *key, FILE *out)
|
|||
gnutls_datum_t data = { NULL, 0 };
|
||||
gnutls_datum_t rsa_raw[6];
|
||||
size_t size = 128;
|
||||
char *res = NULL;
|
||||
char * res = NULL;
|
||||
char buf[33];
|
||||
unsigned int i, j;
|
||||
|
||||
|
@ -344,9 +345,7 @@ eet_identity_print(Eet_Key *key, FILE *out)
|
|||
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
while ((err =
|
||||
gnutls_hex_encode(rsa_raw + i, res,
|
||||
&size)) ==
|
||||
while ((err = gnutls_hex_encode(rsa_raw + i, res, &size)) ==
|
||||
GNUTLS_E_SHORT_MEMORY_BUFFER)
|
||||
{
|
||||
size += 128;
|
||||
|
@ -370,7 +369,8 @@ 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))
|
||||
if (gnutls_x509_crt_print(key->certificate, GNUTLS_X509_CRT_FULL,
|
||||
&data))
|
||||
goto on_error;
|
||||
|
||||
fprintf(out, "%s\n", data.data);
|
||||
|
@ -386,10 +386,10 @@ on_error:
|
|||
gnutls_free(data.data);
|
||||
|
||||
return;
|
||||
# else
|
||||
RSA *rsa;
|
||||
DSA *dsa;
|
||||
DH *dh;
|
||||
# else /* ifdef HAVE_GNUTLS */
|
||||
RSA * rsa;
|
||||
DSA * dsa;
|
||||
DH * dh;
|
||||
|
||||
if (!key)
|
||||
return;
|
||||
|
@ -417,39 +417,40 @@ on_error:
|
|||
|
||||
fprintf(out, "Public certificate:\n");
|
||||
X509_print_fp(out, key->certificate);
|
||||
# endif
|
||||
#else
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
#else /* ifdef HAVE_SIGNATURE */
|
||||
ERR("You need to compile signature support in EET.");
|
||||
#endif
|
||||
}
|
||||
#endif /* ifdef HAVE_SIGNATURE */
|
||||
} /* eet_identity_print */
|
||||
|
||||
void
|
||||
eet_identity_ref(Eet_Key *key)
|
||||
eet_identity_ref(Eet_Key * key)
|
||||
{
|
||||
if (key == NULL)
|
||||
return;
|
||||
|
||||
key->references++;
|
||||
}
|
||||
} /* eet_identity_ref */
|
||||
|
||||
void
|
||||
eet_identity_unref(Eet_Key *key)
|
||||
eet_identity_unref(Eet_Key * key)
|
||||
{
|
||||
if (key == NULL)
|
||||
return;
|
||||
|
||||
key->references--;
|
||||
eet_identity_close(key);
|
||||
}
|
||||
} /* eet_identity_unref */
|
||||
|
||||
void *
|
||||
eet_identity_compute_sha1(const void *data_base, unsigned int data_length,
|
||||
int *sha1_length)
|
||||
eet_identity_compute_sha1(const void * data_base,
|
||||
unsigned int data_length,
|
||||
int * sha1_length)
|
||||
{
|
||||
void *result;
|
||||
void * result;
|
||||
|
||||
#ifdef HAVE_SIGNATURE
|
||||
# ifdef HAVE_GNUTLS
|
||||
# ifdef HAVE_GNUTLS
|
||||
result = malloc(gcry_md_get_algo_dlen(GCRY_MD_SHA1));
|
||||
if (!result)
|
||||
return NULL;
|
||||
|
@ -458,8 +459,8 @@ eet_identity_compute_sha1(const void *data_base, unsigned int data_length,
|
|||
if (sha1_length)
|
||||
*sha1_length = gcry_md_get_algo_dlen(GCRY_MD_SHA1);
|
||||
|
||||
# else
|
||||
# ifdef HAVE_OPENSSL
|
||||
# else /* ifdef HAVE_GNUTLS */
|
||||
# ifdef HAVE_OPENSSL
|
||||
result = malloc(SHA_DIGEST_LENGTH);
|
||||
if (!result)
|
||||
return NULL;
|
||||
|
@ -468,37 +469,38 @@ eet_identity_compute_sha1(const void *data_base, unsigned int data_length,
|
|||
if (sha1_length)
|
||||
*sha1_length = SHA_DIGEST_LENGTH;
|
||||
|
||||
# else
|
||||
# else /* ifdef HAVE_OPENSSL */
|
||||
result = NULL;
|
||||
# endif
|
||||
# endif
|
||||
#else
|
||||
# endif /* ifdef HAVE_OPENSSL */
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
#else /* ifdef HAVE_SIGNATURE */
|
||||
result = NULL;
|
||||
#endif
|
||||
#endif /* ifdef HAVE_SIGNATURE */
|
||||
|
||||
return result;
|
||||
}
|
||||
} /* eet_identity_compute_sha1 */
|
||||
|
||||
Eet_Error
|
||||
eet_identity_sign(FILE *fp, Eet_Key *key)
|
||||
eet_identity_sign(FILE * fp,
|
||||
Eet_Key * key)
|
||||
{
|
||||
#ifdef HAVE_SIGNATURE
|
||||
Eet_Error err = EET_ERROR_NONE;
|
||||
struct stat st_buf;
|
||||
void *data;
|
||||
void * data;
|
||||
int fd;
|
||||
int head[3];
|
||||
unsigned char *sign = NULL;
|
||||
unsigned char *cert = NULL;
|
||||
unsigned char * sign = NULL;
|
||||
unsigned char * cert = NULL;
|
||||
# ifdef HAVE_GNUTLS
|
||||
gnutls_datum_t datum = { NULL, 0 };
|
||||
size_t sign_len = 0;
|
||||
size_t cert_len = 0;
|
||||
# else
|
||||
# else /* ifdef HAVE_GNUTLS */
|
||||
EVP_MD_CTX md_ctx;
|
||||
unsigned int sign_len = 0;
|
||||
int cert_len = 0;
|
||||
# endif
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
|
||||
/* A few check and flush pending write. */
|
||||
if (!fp || !key || !key->certificate || !key->private_key)
|
||||
|
@ -568,7 +570,7 @@ eet_identity_sign(FILE *fp, Eet_Key *key)
|
|||
goto on_error;
|
||||
}
|
||||
|
||||
# else
|
||||
# else /* ifdef HAVE_GNUTLS */
|
||||
sign_len = EVP_PKEY_size(key->private_key);
|
||||
sign = malloc(sign_len);
|
||||
if (sign == NULL)
|
||||
|
@ -600,7 +602,7 @@ eet_identity_sign(FILE *fp, Eet_Key *key)
|
|||
goto on_error;
|
||||
}
|
||||
|
||||
# endif
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
/* Append the signature at the end of the file. */
|
||||
head[0] = (int)htonl ((unsigned int)EET_MAGIC_SIGN);
|
||||
head[1] = (int)htonl ((unsigned int)sign_len);
|
||||
|
@ -629,36 +631,36 @@ on_error:
|
|||
if (cert)
|
||||
free(cert);
|
||||
|
||||
# else
|
||||
# else /* ifdef HAVE_GNUTLS */
|
||||
if (cert)
|
||||
OPENSSL_free(cert);
|
||||
|
||||
# endif
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
if (sign)
|
||||
free(sign);
|
||||
|
||||
munmap(data, st_buf.st_size);
|
||||
return err;
|
||||
#else
|
||||
#else /* ifdef HAVE_SIGNATURE */
|
||||
return EET_ERROR_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
}
|
||||
#endif /* ifdef HAVE_SIGNATURE */
|
||||
} /* eet_identity_sign */
|
||||
|
||||
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)
|
||||
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
|
||||
const int *header = signature_base;
|
||||
const unsigned char *sign;
|
||||
const unsigned char *cert_der;
|
||||
const int * header = signature_base;
|
||||
const unsigned char * sign;
|
||||
const unsigned char * cert_der;
|
||||
int sign_len;
|
||||
int cert_len;
|
||||
int magic;
|
||||
|
@ -688,10 +690,10 @@ eet_identity_check(const void *data_base,
|
|||
gnutls_datum_t datum;
|
||||
gnutls_datum_t signature;
|
||||
# if EET_USE_NEW_GNUTLS_API
|
||||
unsigned char *hash;
|
||||
unsigned char * hash;
|
||||
gcry_md_hd_t md;
|
||||
int err;
|
||||
# endif
|
||||
# endif /* if EET_USE_NEW_GNUTLS_API */
|
||||
|
||||
/* Create an understanding certificate structure for gnutls */
|
||||
datum.data = (void *)cert_der;
|
||||
|
@ -717,7 +719,7 @@ eet_identity_check(const void *data_base,
|
|||
hash = gcry_md_read(md, GCRY_MD_SHA1);
|
||||
if (hash == NULL)
|
||||
{
|
||||
gcry_md_close(md);
|
||||
gcry_md_close(md);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -726,7 +728,7 @@ eet_identity_check(const void *data_base,
|
|||
|
||||
if (!gnutls_x509_crt_verify_hash(cert, 0, &datum, &signature))
|
||||
{
|
||||
gcry_md_close(md);
|
||||
gcry_md_close(md);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -744,7 +746,7 @@ eet_identity_check(const void *data_base,
|
|||
}
|
||||
|
||||
gcry_md_close(md);
|
||||
# else
|
||||
# else /* if EET_USE_NEW_GNUTLS_API */
|
||||
datum.data = (void *)data_base;
|
||||
datum.size = data_length;
|
||||
|
||||
|
@ -757,13 +759,13 @@ eet_identity_check(const void *data_base,
|
|||
*sha1_length = -1;
|
||||
}
|
||||
|
||||
# endif
|
||||
# endif /* if EET_USE_NEW_GNUTLS_API */
|
||||
gnutls_x509_crt_deinit(cert);
|
||||
|
||||
# else
|
||||
const unsigned char *tmp;
|
||||
EVP_PKEY *pkey;
|
||||
X509 *x509;
|
||||
# else /* ifdef HAVE_GNUTLS */
|
||||
const unsigned char * tmp;
|
||||
EVP_PKEY * pkey;
|
||||
X509 * x509;
|
||||
EVP_MD_CTX md_ctx;
|
||||
int err;
|
||||
|
||||
|
@ -799,7 +801,7 @@ eet_identity_check(const void *data_base,
|
|||
if (err != 1)
|
||||
return NULL;
|
||||
|
||||
# endif
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
if (x509_length)
|
||||
*x509_length = cert_len;
|
||||
|
||||
|
@ -810,15 +812,15 @@ eet_identity_check(const void *data_base,
|
|||
*raw_signature_length = sign_len;
|
||||
|
||||
return cert_der;
|
||||
#else
|
||||
#else /* ifdef HAVE_SIGNATURE */
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
#endif /* ifdef HAVE_SIGNATURE */
|
||||
} /* eet_identity_check */
|
||||
|
||||
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)
|
||||
|
@ -854,9 +856,9 @@ on_error:
|
|||
gnutls_free(datum.data);
|
||||
|
||||
gnutls_x509_crt_deinit(cert);
|
||||
# else
|
||||
const unsigned char *tmp;
|
||||
X509 *x509;
|
||||
# else /* ifdef HAVE_GNUTLS */
|
||||
const unsigned char * tmp;
|
||||
X509 * x509;
|
||||
|
||||
/* Strange but d2i_X509 seems to put 0 all over the place. */
|
||||
tmp = alloca(der_length);
|
||||
|
@ -868,27 +870,27 @@ on_error:
|
|||
return;
|
||||
}
|
||||
|
||||
INF("Public certificate :");
|
||||
X509_print_fp(out, x509);
|
||||
INF("Public certificate :");
|
||||
X509_print_fp(out, x509);
|
||||
|
||||
X509_free(x509);
|
||||
# endif
|
||||
#else
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
#else /* ifdef HAVE_SIGNATURE */
|
||||
ERR("You need to compile signature support in EET.");
|
||||
#endif
|
||||
}
|
||||
#endif /* ifdef HAVE_SIGNATURE */
|
||||
} /* eet_identity_certificate_print */
|
||||
|
||||
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 */
|
||||
unsigned int *ret = NULL;
|
||||
unsigned int * ret = NULL;
|
||||
unsigned char iv[MAX_IV_LEN];
|
||||
unsigned char ik[MAX_KEY_LEN];
|
||||
unsigned char key_material[MAX_IV_LEN + MAX_KEY_LEN];
|
||||
|
@ -900,22 +902,22 @@ eet_cipher(const void *data,
|
|||
/* Gcrypt declarations */
|
||||
gcry_error_t err = 0;
|
||||
gcry_cipher_hd_t cipher;
|
||||
# else
|
||||
# else /* ifdef HAVE_GNUTLS */
|
||||
/* Openssl declarations*/
|
||||
EVP_CIPHER_CTX ctx;
|
||||
unsigned int *buffer;
|
||||
unsigned int * buffer;
|
||||
int tmp_len;
|
||||
# endif
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
|
||||
# ifdef HAVE_GNUTLS
|
||||
/* Gcrypt salt generation */
|
||||
gcry_create_nonce((unsigned char *)&salt, sizeof(salt));
|
||||
# else
|
||||
# else /* ifdef HAVE_GNUTLS */
|
||||
/* Openssl salt generation */
|
||||
if (!RAND_bytes((unsigned char *)&salt, sizeof (unsigned int)))
|
||||
return EET_ERROR_PRNG_NOT_SEEDED;
|
||||
|
||||
#endif
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
|
||||
eet_pbkdf2_sha1(key,
|
||||
length,
|
||||
|
@ -925,10 +927,10 @@ eet_cipher(const void *data,
|
|||
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);
|
||||
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(key_material, 0, sizeof (key_material));
|
||||
|
||||
crypted_length = ((((size + sizeof (unsigned int)) >> 5) + 1) << 5);
|
||||
ret = malloc(crypted_length + sizeof(unsigned int));
|
||||
|
@ -941,10 +943,10 @@ eet_cipher(const void *data,
|
|||
}
|
||||
|
||||
*ret = salt;
|
||||
memset(&salt, 0, sizeof (salt));
|
||||
memset(&salt, 0, sizeof (salt));
|
||||
tmp = htonl(size);
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
# ifdef HAVE_GNUTLS
|
||||
*(ret + 1) = tmp;
|
||||
memcpy(ret + 2, data, size);
|
||||
|
||||
|
@ -977,7 +979,7 @@ eet_cipher(const void *data,
|
|||
|
||||
/* Gcrypt close the cipher */
|
||||
gcry_cipher_close(cipher);
|
||||
# else
|
||||
# else /* ifdef HAVE_GNUTLS */
|
||||
buffer = alloca(crypted_length);
|
||||
*buffer = tmp;
|
||||
|
||||
|
@ -996,7 +998,8 @@ eet_cipher(const void *data,
|
|||
|
||||
/* Openssl encrypt */
|
||||
if (!EVP_EncryptUpdate(&ctx, (unsigned char *)(ret + 1), &tmp_len,
|
||||
(unsigned char *)buffer, size + sizeof (unsigned int)))
|
||||
(unsigned char *)buffer,
|
||||
size + sizeof(unsigned int)))
|
||||
goto on_error;
|
||||
|
||||
/* Openssl close the cipher */
|
||||
|
@ -1005,7 +1008,7 @@ eet_cipher(const void *data,
|
|||
goto on_error;
|
||||
|
||||
EVP_CIPHER_CTX_cleanup(&ctx);
|
||||
# endif
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
|
||||
/* Set return values */
|
||||
if (result_length)
|
||||
|
@ -1027,12 +1030,12 @@ on_error:
|
|||
if (opened)
|
||||
gcry_cipher_close(cipher);
|
||||
|
||||
# else
|
||||
# else /* ifdef HAVE_GNUTLS */
|
||||
/* Openssl error */
|
||||
if (opened)
|
||||
EVP_CIPHER_CTX_cleanup(&ctx);
|
||||
|
||||
# endif
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
/* General error */
|
||||
free(ret);
|
||||
if (result)
|
||||
|
@ -1042,8 +1045,8 @@ on_error:
|
|||
*result_length = 0;
|
||||
|
||||
return EET_ERROR_ENCRYPT_FAILED;
|
||||
#else
|
||||
/* Cipher not supported */
|
||||
#else /* ifdef HAVE_CIPHER */
|
||||
/* Cipher not supported */
|
||||
(void)data;
|
||||
(void)size;
|
||||
(void)key;
|
||||
|
@ -1051,20 +1054,20 @@ on_error:
|
|||
(void)result;
|
||||
(void)result_length;
|
||||
return EET_ERROR_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
}
|
||||
#endif /* ifdef HAVE_CIPHER */
|
||||
} /* eet_cipher */
|
||||
|
||||
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;
|
||||
unsigned int *ret = NULL;
|
||||
const unsigned int * over = data;
|
||||
unsigned int * ret = NULL;
|
||||
unsigned char ik[MAX_KEY_LEN];
|
||||
unsigned char iv[MAX_IV_LEN];
|
||||
unsigned char key_material[MAX_KEY_LEN + MAX_IV_LEN];
|
||||
|
@ -1080,12 +1083,8 @@ eet_decipher(const void *data,
|
|||
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,
|
||||
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);
|
||||
|
@ -1124,18 +1123,15 @@ eet_decipher(const void *data,
|
|||
memset(ik, 0, sizeof (ik));
|
||||
|
||||
/* Gcrypt decrypt */
|
||||
err = gcry_cipher_decrypt(cipher,
|
||||
ret,
|
||||
tmp_len,
|
||||
((unsigned int *)data) + 1,
|
||||
tmp_len);
|
||||
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);
|
||||
|
||||
# else
|
||||
# else /* ifdef HAVE_GNUTLS */
|
||||
EVP_CIPHER_CTX ctx;
|
||||
int opened = 0;
|
||||
|
||||
|
@ -1156,7 +1152,7 @@ eet_decipher(const void *data,
|
|||
|
||||
/* Openssl close the cipher*/
|
||||
EVP_CIPHER_CTX_cleanup(&ctx);
|
||||
# endif
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
/* Get the decrypted data size */
|
||||
tmp = *ret;
|
||||
tmp = ntohl(tmp);
|
||||
|
@ -1190,7 +1186,7 @@ on_error:
|
|||
if (opened)
|
||||
EVP_CIPHER_CTX_cleanup(&ctx);
|
||||
|
||||
# endif
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
if (result)
|
||||
*result = NULL;
|
||||
|
||||
|
@ -1201,7 +1197,7 @@ on_error:
|
|||
free(ret);
|
||||
|
||||
return EET_ERROR_DECRYPT_FAILED;
|
||||
#else
|
||||
#else /* ifdef HAVE_CIPHER */
|
||||
(void)data;
|
||||
(void)size;
|
||||
(void)key;
|
||||
|
@ -1209,18 +1205,21 @@ on_error:
|
|||
(void)result;
|
||||
(void)result_length;
|
||||
return EET_ERROR_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
}
|
||||
#endif /* ifdef HAVE_CIPHER */
|
||||
} /* eet_decipher */
|
||||
|
||||
#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)
|
||||
eet_hmac_sha1(const void * key,
|
||||
size_t key_len,
|
||||
const void * data,
|
||||
size_t data_len,
|
||||
unsigned char * res)
|
||||
{
|
||||
size_t hlen = gcry_md_get_algo_dlen (GCRY_MD_SHA1);
|
||||
gcry_md_hd_t mdh;
|
||||
unsigned char *hash;
|
||||
unsigned char * hash;
|
||||
gpg_error_t err;
|
||||
|
||||
err = gcry_md_open(&mdh, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC);
|
||||
|
@ -1248,22 +1247,23 @@ eet_hmac_sha1(const void *key, size_t key_len,
|
|||
gcry_md_close(mdh);
|
||||
|
||||
return 0;
|
||||
}
|
||||
# endif
|
||||
} /* eet_hmac_sha1 */
|
||||
|
||||
# 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)
|
||||
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)
|
||||
{
|
||||
unsigned char digest[20];
|
||||
unsigned char tab[4];
|
||||
unsigned char *p = res;
|
||||
unsigned char *buf;
|
||||
unsigned char * p = res;
|
||||
unsigned char * buf;
|
||||
unsigned long i;
|
||||
int digest_len = 20;
|
||||
int len = res_len;
|
||||
|
@ -1272,7 +1272,7 @@ eet_pbkdf2_sha1(const char *key,
|
|||
# ifdef HAVE_GNUTLS
|
||||
# else
|
||||
HMAC_CTX hctx;
|
||||
# endif
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
|
||||
buf = alloca(salt_len + 4);
|
||||
if (!buf)
|
||||
|
@ -1294,21 +1294,21 @@ eet_pbkdf2_sha1(const char *key,
|
|||
memcpy(buf, salt, salt_len);
|
||||
memcpy(buf + salt_len, tab, 4);
|
||||
eet_hmac_sha1(key, key_len, buf, salt_len + 4, digest);
|
||||
# else
|
||||
# else /* ifdef HAVE_GNUTLS */
|
||||
HMAC_Init(&hctx, key, key_len, EVP_sha1());
|
||||
HMAC_Update(&hctx, salt, salt_len);
|
||||
HMAC_Update(&hctx, tab, 4);
|
||||
HMAC_Final(&hctx, digest, NULL);
|
||||
# endif
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
memcpy(p, digest, tmp_len);
|
||||
|
||||
for (j = 1; j < iter; j++)
|
||||
{
|
||||
# ifdef HAVE_GNUTLS
|
||||
eet_hmac_sha1(key, key_len, digest, 20, digest);
|
||||
# else
|
||||
# else /* ifdef HAVE_GNUTLS */
|
||||
HMAC(EVP_sha1(), key, key_len, digest, 20, digest, NULL);
|
||||
# endif
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
for (k = 0; k < tmp_len; k++)
|
||||
p[k] ^= digest[k];
|
||||
}
|
||||
|
@ -1317,7 +1317,8 @@ eet_pbkdf2_sha1(const char *key,
|
|||
# ifdef HAVE_GNUTLS
|
||||
# else
|
||||
HMAC_cleanup(&hctx);
|
||||
# endif
|
||||
# endif /* ifdef HAVE_GNUTLS */
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
} /* eet_pbkdf2_sha1 */
|
||||
|
||||
#endif /* ifdef HAVE_CIPHER */
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
#endif /* ifdef HAVE_CONFIG_H */
|
||||
|
||||
#ifdef HAVE_ALLOCA_H
|
||||
# include <alloca.h>
|
||||
|
@ -15,24 +15,24 @@
|
|||
#elif defined _MSC_VER
|
||||
# include <malloc.h>
|
||||
# define alloca _alloca
|
||||
#else
|
||||
#else /* ifdef HAVE_ALLOCA_H */
|
||||
# include <stddef.h>
|
||||
# ifdef __cplusplus
|
||||
extern "C"
|
||||
# endif
|
||||
void *alloca (size_t);
|
||||
#endif
|
||||
# endif /* ifdef __cplusplus */
|
||||
void * alloca (size_t);
|
||||
#endif /* ifdef HAVE_ALLOCA_H */
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
#endif /* ifdef HAVE_NETINET_IN_H */
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <winsock2.h>
|
||||
#endif
|
||||
#endif /* ifdef _WIN32 */
|
||||
|
||||
#include <Eina.h>
|
||||
|
||||
|
@ -41,7 +41,7 @@ void *alloca (size_t);
|
|||
|
||||
#define MAGIC_EET_DATA_PACKET 0x4270ACE1
|
||||
|
||||
typedef struct _Eet_Message Eet_Message;
|
||||
typedef struct _Eet_Message Eet_Message;
|
||||
struct _Eet_Message
|
||||
{
|
||||
int magic;
|
||||
|
@ -50,23 +50,23 @@ struct _Eet_Message
|
|||
|
||||
struct _Eet_Connection
|
||||
{
|
||||
Eet_Read_Cb *eet_read_cb;
|
||||
Eet_Write_Cb *eet_write_cb;
|
||||
void *user_data;
|
||||
Eet_Read_Cb * eet_read_cb;
|
||||
Eet_Write_Cb * eet_write_cb;
|
||||
void * user_data;
|
||||
|
||||
size_t allocated;
|
||||
size_t size;
|
||||
size_t received;
|
||||
size_t allocated;
|
||||
size_t size;
|
||||
size_t received;
|
||||
|
||||
void *buffer;
|
||||
void * buffer;
|
||||
};
|
||||
|
||||
EAPI Eet_Connection *
|
||||
eet_connection_new(Eet_Read_Cb *eet_read_cb,
|
||||
Eet_Write_Cb *eet_write_cb,
|
||||
const void *user_data)
|
||||
eet_connection_new(Eet_Read_Cb * eet_read_cb,
|
||||
Eet_Write_Cb * eet_write_cb,
|
||||
const void * user_data)
|
||||
{
|
||||
Eet_Connection *conn;
|
||||
Eet_Connection * conn;
|
||||
|
||||
if (!eet_read_cb || !eet_write_cb)
|
||||
return NULL;
|
||||
|
@ -80,12 +80,14 @@ eet_connection_new(Eet_Read_Cb *eet_read_cb,
|
|||
conn->user_data = (void *)user_data;
|
||||
|
||||
return conn;
|
||||
}
|
||||
} /* eet_connection_new */
|
||||
|
||||
EAPI int
|
||||
eet_connection_received(Eet_Connection *conn, const void *data, size_t size)
|
||||
eet_connection_received(Eet_Connection * conn,
|
||||
const void * data,
|
||||
size_t size)
|
||||
{
|
||||
if (!conn || !data || !size)
|
||||
if ((!conn) || (!data) || (!size))
|
||||
return size;
|
||||
|
||||
do {
|
||||
|
@ -93,7 +95,7 @@ eet_connection_received(Eet_Connection *conn, const void *data, size_t size)
|
|||
|
||||
if (conn->size == 0)
|
||||
{
|
||||
const Eet_Message *msg;
|
||||
const Eet_Message * msg;
|
||||
size_t packet_size;
|
||||
|
||||
if (size < sizeof (Eet_Message))
|
||||
|
@ -127,7 +129,7 @@ eet_connection_received(Eet_Connection *conn, const void *data, size_t size)
|
|||
conn->size = packet_size;
|
||||
if (conn->allocated < conn->size)
|
||||
{
|
||||
void *tmp;
|
||||
void * tmp;
|
||||
|
||||
tmp = realloc(conn->buffer, conn->size);
|
||||
if (!tmp)
|
||||
|
@ -167,12 +169,14 @@ eet_connection_received(Eet_Connection *conn, const void *data, size_t size)
|
|||
} while (size > 0);
|
||||
|
||||
return size;
|
||||
}
|
||||
} /* eet_connection_received */
|
||||
|
||||
static Eina_Bool
|
||||
_eet_connection_raw_send(Eet_Connection *conn, void *data, int data_size)
|
||||
_eet_connection_raw_send(Eet_Connection * conn,
|
||||
void * data,
|
||||
int data_size)
|
||||
{
|
||||
Eet_Message *message;
|
||||
Eet_Message * message;
|
||||
|
||||
/* Message should never be above 64K */
|
||||
if (data_size > 64 * 1024)
|
||||
|
@ -182,21 +186,21 @@ _eet_connection_raw_send(Eet_Connection *conn, void *data, int data_size)
|
|||
message->magic = htonl(MAGIC_EET_DATA_PACKET);
|
||||
message->size = htonl(data_size);
|
||||
|
||||
memcpy(message + 1, data, data_size);
|
||||
memcpy(message + 1, data, data_size);
|
||||
|
||||
conn->eet_write_cb(message,
|
||||
data_size + sizeof (Eet_Message),
|
||||
conn->user_data);
|
||||
return EINA_TRUE;
|
||||
}
|
||||
} /* _eet_connection_raw_send */
|
||||
|
||||
EAPI Eina_Bool
|
||||
eet_connection_send(Eet_Connection *conn,
|
||||
Eet_Data_Descriptor *edd,
|
||||
const void *data_in,
|
||||
const char *cipher_key)
|
||||
eet_connection_send(Eet_Connection * conn,
|
||||
Eet_Data_Descriptor * edd,
|
||||
const void * data_in,
|
||||
const char * cipher_key)
|
||||
{
|
||||
void *flat_data;
|
||||
void * flat_data;
|
||||
int data_size;
|
||||
Eina_Bool ret = EINA_FALSE;
|
||||
|
||||
|
@ -212,14 +216,14 @@ eet_connection_send(Eet_Connection *conn,
|
|||
|
||||
free(flat_data);
|
||||
return ret;
|
||||
}
|
||||
} /* eet_connection_send */
|
||||
|
||||
EAPI Eina_Bool
|
||||
eet_connection_node_send(Eet_Connection *conn,
|
||||
Eet_Node *node,
|
||||
const char *cipher_key)
|
||||
eet_connection_node_send(Eet_Connection * conn,
|
||||
Eet_Node * node,
|
||||
const char * cipher_key)
|
||||
{
|
||||
void *data;
|
||||
void * data;
|
||||
int data_size;
|
||||
Eina_Bool ret = EINA_FALSE;
|
||||
|
||||
|
@ -232,12 +236,13 @@ eet_connection_node_send(Eet_Connection *conn,
|
|||
|
||||
free(data);
|
||||
return ret;
|
||||
}
|
||||
} /* eet_connection_node_send */
|
||||
|
||||
EAPI void *
|
||||
eet_connection_close(Eet_Connection *conn, Eina_Bool *on_going)
|
||||
eet_connection_close(Eet_Connection * conn,
|
||||
Eina_Bool * on_going)
|
||||
{
|
||||
void *user_data;
|
||||
void * user_data;
|
||||
|
||||
if (!conn)
|
||||
return NULL;
|
||||
|
@ -251,4 +256,5 @@ eet_connection_close(Eet_Connection *conn, Eina_Bool *on_going)
|
|||
free(conn);
|
||||
|
||||
return user_data;
|
||||
}
|
||||
} /* eet_connection_close */
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -4,7 +4,7 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
#endif /* ifdef HAVE_CONFIG_H */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -18,7 +18,7 @@
|
|||
Eet_Dictionary *
|
||||
eet_dictionary_add(void)
|
||||
{
|
||||
Eet_Dictionary *new;
|
||||
Eet_Dictionary * new;
|
||||
|
||||
new = calloc(1, sizeof (Eet_Dictionary));
|
||||
if (!new)
|
||||
|
@ -27,10 +27,10 @@ eet_dictionary_add(void)
|
|||
memset(new->hash, -1, sizeof (int) * 256);
|
||||
|
||||
return new;
|
||||
}
|
||||
} /* eet_dictionary_add */
|
||||
|
||||
void
|
||||
eet_dictionary_free(Eet_Dictionary *ed)
|
||||
eet_dictionary_free(Eet_Dictionary * ed)
|
||||
{
|
||||
if (ed)
|
||||
{
|
||||
|
@ -41,14 +41,16 @@ eet_dictionary_free(Eet_Dictionary *ed)
|
|||
free(ed->all[i].str);
|
||||
|
||||
if (ed->all)
|
||||
free(ed->all);
|
||||
free(ed->all);
|
||||
|
||||
free(ed);
|
||||
free(ed);
|
||||
}
|
||||
}
|
||||
} /* eet_dictionary_free */
|
||||
|
||||
static int
|
||||
_eet_dictionary_lookup(Eet_Dictionary *ed, const char *string, int hash)
|
||||
_eet_dictionary_lookup(Eet_Dictionary * ed,
|
||||
const char * string,
|
||||
int hash)
|
||||
{
|
||||
int prev = -1;
|
||||
int current;
|
||||
|
@ -73,13 +75,14 @@ _eet_dictionary_lookup(Eet_Dictionary *ed, const char *string, int hash)
|
|||
return prev;
|
||||
|
||||
return current;
|
||||
}
|
||||
} /* _eet_dictionary_lookup */
|
||||
|
||||
int
|
||||
eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
|
||||
eet_dictionary_string_add(Eet_Dictionary * ed,
|
||||
const char * string)
|
||||
{
|
||||
Eet_String *current;
|
||||
char *str;
|
||||
Eet_String * current;
|
||||
char * str;
|
||||
int hash;
|
||||
int idx;
|
||||
int len;
|
||||
|
@ -105,7 +108,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
|
|||
|
||||
if (ed->total == ed->count)
|
||||
{
|
||||
Eet_String *new;
|
||||
Eet_String * new;
|
||||
int total;
|
||||
|
||||
total = ed->total + 8;
|
||||
|
@ -154,10 +157,11 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
|
|||
}
|
||||
|
||||
return ed->count++;
|
||||
}
|
||||
} /* eet_dictionary_string_add */
|
||||
|
||||
int
|
||||
eet_dictionary_string_get_size(const Eet_Dictionary *ed, int idx)
|
||||
eet_dictionary_string_get_size(const Eet_Dictionary * ed,
|
||||
int idx)
|
||||
{
|
||||
if (!ed)
|
||||
return 0;
|
||||
|
@ -169,10 +173,11 @@ eet_dictionary_string_get_size(const Eet_Dictionary *ed, int idx)
|
|||
return ed->all[idx].len;
|
||||
|
||||
return 0;
|
||||
}
|
||||
} /* eet_dictionary_string_get_size */
|
||||
|
||||
int
|
||||
eet_dictionary_string_get_hash(const Eet_Dictionary *ed, int idx)
|
||||
eet_dictionary_string_get_hash(const Eet_Dictionary * ed,
|
||||
int idx)
|
||||
{
|
||||
if (!ed)
|
||||
return -1;
|
||||
|
@ -184,10 +189,11 @@ eet_dictionary_string_get_hash(const Eet_Dictionary *ed, int idx)
|
|||
return ed->all[idx].hash;
|
||||
|
||||
return -1;
|
||||
}
|
||||
} /* eet_dictionary_string_get_hash */
|
||||
|
||||
const char *
|
||||
eet_dictionary_string_get_char(const Eet_Dictionary *ed, int idx)
|
||||
eet_dictionary_string_get_char(const Eet_Dictionary * ed,
|
||||
int idx)
|
||||
{
|
||||
if (!ed)
|
||||
return NULL;
|
||||
|
@ -205,22 +211,22 @@ eet_dictionary_string_get_char(const Eet_Dictionary *ed, int idx)
|
|||
ed->all[idx].mmap = NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
#else /* ifdef _WIN32 */
|
||||
if (ed->all[idx].mmap)
|
||||
return ed->all[idx].mmap;
|
||||
|
||||
#endif
|
||||
#endif /* ifdef _WIN32 */
|
||||
return ed->all[idx].str;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
} /* eet_dictionary_string_get_char */
|
||||
|
||||
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'))
|
||||
{
|
||||
|
@ -231,10 +237,12 @@ _eet_dictionary_string_get_me_cache(const char *s,
|
|||
}
|
||||
|
||||
return EINA_FALSE;
|
||||
}
|
||||
} /* _eet_dictionary_string_get_me_cache */
|
||||
|
||||
static inline Eina_Bool
|
||||
_eet_dictionary_string_get_float_cache(const char *s, int len, float *result)
|
||||
_eet_dictionary_string_get_float_cache(const char * s,
|
||||
int len,
|
||||
float * result)
|
||||
{
|
||||
int mantisse;
|
||||
int exponent;
|
||||
|
@ -250,10 +258,12 @@ _eet_dictionary_string_get_float_cache(const char *s, int len, float *result)
|
|||
}
|
||||
|
||||
return EINA_FALSE;
|
||||
}
|
||||
} /* _eet_dictionary_string_get_float_cache */
|
||||
|
||||
static inline Eina_Bool
|
||||
_eet_dictionary_string_get_double_cache(const char *s, int len, double *result)
|
||||
_eet_dictionary_string_get_double_cache(const char * s,
|
||||
int len,
|
||||
double * result)
|
||||
{
|
||||
int mantisse;
|
||||
int exponent;
|
||||
|
@ -269,10 +279,12 @@ _eet_dictionary_string_get_double_cache(const char *s, int len, double *result)
|
|||
}
|
||||
|
||||
return EINA_FALSE;
|
||||
}
|
||||
} /* _eet_dictionary_string_get_double_cache */
|
||||
|
||||
static inline Eina_Bool
|
||||
_eet_dictionary_test(const Eet_Dictionary *ed, int idx, void *result)
|
||||
_eet_dictionary_test(const Eet_Dictionary * ed,
|
||||
int idx,
|
||||
void * result)
|
||||
{
|
||||
if (!result)
|
||||
return EINA_FALSE;
|
||||
|
@ -287,19 +299,19 @@ _eet_dictionary_test(const Eet_Dictionary *ed, int idx, void *result)
|
|||
return EINA_FALSE;
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
} /* _eet_dictionary_test */
|
||||
|
||||
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 (!(ed->all[idx].type & EET_D_FLOAT))
|
||||
{
|
||||
const char *str;
|
||||
const char * str;
|
||||
|
||||
str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
|
||||
|
||||
|
@ -321,19 +333,19 @@ eet_dictionary_string_get_float(const Eet_Dictionary *ed,
|
|||
|
||||
*result = ed->all[idx].f;
|
||||
return EINA_TRUE;
|
||||
}
|
||||
} /* eet_dictionary_string_get_float */
|
||||
|
||||
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 (!(ed->all[idx].type & EET_D_DOUBLE))
|
||||
{
|
||||
const char *str;
|
||||
const char * str;
|
||||
|
||||
str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
|
||||
|
||||
|
@ -355,19 +367,19 @@ eet_dictionary_string_get_double(const Eet_Dictionary *ed,
|
|||
|
||||
*result = ed->all[idx].d;
|
||||
return EINA_TRUE;
|
||||
}
|
||||
} /* eet_dictionary_string_get_double */
|
||||
|
||||
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 (!(ed->all[idx].type & EET_D_FIXED_POINT))
|
||||
{
|
||||
const char *str;
|
||||
const char * str;
|
||||
Eina_F32p32 fp;
|
||||
|
||||
str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
|
||||
|
@ -381,19 +393,18 @@ eet_dictionary_string_get_fp(const Eet_Dictionary *ed,
|
|||
|
||||
*result = ed->all[idx].fp;
|
||||
return EINA_TRUE;
|
||||
}
|
||||
} /* eet_dictionary_string_get_fp */
|
||||
|
||||
EAPI int
|
||||
eet_dictionary_string_check(Eet_Dictionary *ed, const char *string)
|
||||
eet_dictionary_string_check(Eet_Dictionary * ed,
|
||||
const char * string)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (ed == NULL
|
||||
|| string == NULL)
|
||||
if ((ed == NULL) || (string == NULL))
|
||||
return 0;
|
||||
|
||||
if (ed->start <= string
|
||||
&& string < ed->end)
|
||||
if ((ed->start <= string) && (string < ed->end))
|
||||
return 1;
|
||||
|
||||
for (i = 0; i < ed->count; ++i)
|
||||
|
@ -401,4 +412,5 @@ eet_dictionary_string_check(Eet_Dictionary *ed, const char *string)
|
|||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
} /* eet_dictionary_string_check */
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -4,26 +4,26 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
#endif /* ifdef HAVE_CONFIG_H */
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef HAVE_EVIL
|
||||
# include <Evil.h>
|
||||
#endif
|
||||
#endif /* ifdef HAVE_EVIL */
|
||||
|
||||
#include <Eina.h>
|
||||
|
||||
#include "Eet.h"
|
||||
#include "Eet_private.h"
|
||||
|
||||
static Eina_Mempool *_eet_node_mp = NULL;
|
||||
static Eina_Mempool * _eet_node_mp = NULL;
|
||||
|
||||
Eet_Node *
|
||||
eet_node_new(void)
|
||||
{
|
||||
Eet_Node *result;
|
||||
Eet_Node * result;
|
||||
|
||||
result = eina_mempool_malloc(_eet_node_mp, sizeof (Eet_Node));
|
||||
if (!result)
|
||||
|
@ -31,18 +31,19 @@ eet_node_new(void)
|
|||
|
||||
memset(result, 0, sizeof (Eet_Node));
|
||||
return result;
|
||||
}
|
||||
} /* eet_node_new */
|
||||
|
||||
void
|
||||
eet_node_free(Eet_Node *node)
|
||||
eet_node_free(Eet_Node * node)
|
||||
{
|
||||
eina_mempool_free(_eet_node_mp, node);
|
||||
}
|
||||
} /* eet_node_free */
|
||||
|
||||
static Eet_Node *
|
||||
_eet_node_new(const char *name, int type)
|
||||
_eet_node_new(const char * name,
|
||||
int type)
|
||||
{
|
||||
Eet_Node *n;
|
||||
Eet_Node * n;
|
||||
|
||||
n = eet_node_new();
|
||||
if (!n)
|
||||
|
@ -52,47 +53,47 @@ _eet_node_new(const char *name, int type)
|
|||
n->name = eina_stringshare_add(name);
|
||||
|
||||
return n;
|
||||
}
|
||||
} /* _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;
|
||||
Eet_Node * value;
|
||||
Eina_List * l;
|
||||
|
||||
EINA_LIST_REVERSE_FOREACH(nodes, l, 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)
|
||||
|
@ -109,9 +110,9 @@ 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 *
|
||||
eet_node_null_new(const char *name)
|
||||
eet_node_null_new(const char * name)
|
||||
{
|
||||
Eet_Node *n;
|
||||
Eet_Node * n;
|
||||
|
||||
n = _eet_node_new(name, EET_T_NULL);
|
||||
if (!n)
|
||||
|
@ -123,9 +124,10 @@ eet_node_null_new(const char *name)
|
|||
}
|
||||
|
||||
Eet_Node *
|
||||
eet_node_list_new(const char *name, Eina_List *nodes)
|
||||
eet_node_list_new(const char * name,
|
||||
Eina_List * nodes)
|
||||
{
|
||||
Eet_Node *n;
|
||||
Eet_Node * n;
|
||||
|
||||
n = _eet_node_new(name, EET_G_LIST);
|
||||
if (!n)
|
||||
|
@ -134,12 +136,14 @@ eet_node_list_new(const char *name, Eina_List *nodes)
|
|||
_eet_node_append(n, nodes);
|
||||
|
||||
return n;
|
||||
}
|
||||
} /* eet_node_list_new */
|
||||
|
||||
Eet_Node *
|
||||
eet_node_array_new(const char *name, int count, Eina_List *nodes)
|
||||
eet_node_array_new(const char * name,
|
||||
int count,
|
||||
Eina_List * nodes)
|
||||
{
|
||||
Eet_Node *n;
|
||||
Eet_Node * n;
|
||||
|
||||
n = _eet_node_new(name, EET_G_ARRAY);
|
||||
if (!n)
|
||||
|
@ -150,12 +154,13 @@ eet_node_array_new(const char *name, int count, Eina_List *nodes)
|
|||
_eet_node_append(n, nodes);
|
||||
|
||||
return n;
|
||||
}
|
||||
} /* eet_node_array_new */
|
||||
|
||||
Eet_Node *
|
||||
eet_node_var_array_new(const char *name, Eina_List *nodes)
|
||||
eet_node_var_array_new(const char * name,
|
||||
Eina_List * nodes)
|
||||
{
|
||||
Eet_Node *n;
|
||||
Eet_Node * n;
|
||||
|
||||
n = _eet_node_new(name, EET_G_VAR_ARRAY);
|
||||
if (!n)
|
||||
|
@ -166,13 +171,15 @@ eet_node_var_array_new(const char *name, Eina_List *nodes)
|
|||
_eet_node_append(n, nodes);
|
||||
|
||||
return n;
|
||||
}
|
||||
} /* eet_node_var_array_new */
|
||||
|
||||
Eet_Node *
|
||||
eet_node_hash_new(const char *name, const char *key, Eet_Node *node)
|
||||
eet_node_hash_new(const char * name,
|
||||
const char * key,
|
||||
Eet_Node * node)
|
||||
{
|
||||
Eina_List *nodes;
|
||||
Eet_Node *n;
|
||||
Eina_List * nodes;
|
||||
Eet_Node * n;
|
||||
|
||||
if (!node)
|
||||
return NULL;
|
||||
|
@ -187,12 +194,13 @@ eet_node_hash_new(const char *name, const char *key, Eet_Node *node)
|
|||
_eet_node_append(n, nodes);
|
||||
|
||||
return n;
|
||||
}
|
||||
} /* eet_node_hash_new */
|
||||
|
||||
Eet_Node *
|
||||
eet_node_struct_new(const char *name, Eina_List *nodes)
|
||||
eet_node_struct_new(const char * name,
|
||||
Eina_List * nodes)
|
||||
{
|
||||
Eet_Node *n;
|
||||
Eet_Node * n;
|
||||
|
||||
n = _eet_node_new(name, EET_G_UNKNOWN);
|
||||
if (!n)
|
||||
|
@ -201,12 +209,13 @@ eet_node_struct_new(const char *name, Eina_List *nodes)
|
|||
_eet_node_append(n, nodes);
|
||||
|
||||
return n;
|
||||
}
|
||||
} /* eet_node_struct_new */
|
||||
|
||||
Eet_Node *
|
||||
eet_node_struct_child_new(const char *parent, Eet_Node *child)
|
||||
eet_node_struct_child_new(const char * parent,
|
||||
Eet_Node * child)
|
||||
{
|
||||
Eet_Node *n;
|
||||
Eet_Node * n;
|
||||
|
||||
if (child->type != EET_G_UNKNOWN)
|
||||
return child;
|
||||
|
@ -218,20 +227,22 @@ eet_node_struct_child_new(const char *parent, Eet_Node *child)
|
|||
_eet_node_append(n, eina_list_prepend(NULL, child));
|
||||
|
||||
return n;
|
||||
}
|
||||
} /* eet_node_struct_child_new */
|
||||
|
||||
void
|
||||
eet_node_list_append(Eet_Node *parent, const char *name, Eet_Node *child)
|
||||
eet_node_list_append(Eet_Node * parent,
|
||||
const char * name,
|
||||
Eet_Node * child)
|
||||
{
|
||||
const char *tmp;
|
||||
Eet_Node *nn;
|
||||
const char * tmp;
|
||||
Eet_Node * nn;
|
||||
|
||||
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;
|
||||
Eet_Node * n;
|
||||
|
||||
if (!nn->values)
|
||||
nn->values = child;
|
||||
|
@ -256,22 +267,24 @@ eet_node_list_append(Eet_Node *parent, const char *name, Eet_Node *child)
|
|||
nn->next = parent->values;
|
||||
parent->values = nn;
|
||||
|
||||
eina_stringshare_del(tmp);
|
||||
}
|
||||
eina_stringshare_del(tmp);
|
||||
} /* eet_node_list_append */
|
||||
|
||||
void
|
||||
eet_node_struct_append(Eet_Node *parent, const char *name, Eet_Node *child)
|
||||
eet_node_struct_append(Eet_Node * parent,
|
||||
const char * name,
|
||||
Eet_Node * child)
|
||||
{
|
||||
const char *tmp;
|
||||
Eet_Node *prev;
|
||||
Eet_Node *nn;
|
||||
const char * tmp;
|
||||
Eet_Node * prev;
|
||||
Eet_Node * nn;
|
||||
|
||||
if (parent->type != EET_G_UNKNOWN)
|
||||
{
|
||||
ERR("[%s] is not a structure. Will not insert [%s] in it",
|
||||
parent->name,
|
||||
name);
|
||||
eet_node_del(child);
|
||||
eet_node_del(child);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -302,16 +315,16 @@ eet_node_struct_append(Eet_Node *parent, const char *name, Eet_Node *child)
|
|||
parent->values = child;
|
||||
}
|
||||
|
||||
eina_stringshare_del(tmp);
|
||||
}
|
||||
eina_stringshare_del(tmp);
|
||||
} /* eet_node_struct_append */
|
||||
|
||||
void
|
||||
eet_node_hash_add(Eet_Node *parent,
|
||||
const char *name,
|
||||
const char *key,
|
||||
Eet_Node *child)
|
||||
eet_node_hash_add(Eet_Node * parent,
|
||||
const char * name,
|
||||
const char * key,
|
||||
Eet_Node * child)
|
||||
{
|
||||
Eet_Node *nn;
|
||||
Eet_Node * nn;
|
||||
|
||||
/* No list found, so create it. */
|
||||
nn = eet_node_hash_new(name, key, child);
|
||||
|
@ -319,13 +332,13 @@ eet_node_hash_add(Eet_Node *parent,
|
|||
/* And add it to the parent. */
|
||||
nn->next = parent->values;
|
||||
parent->values = nn;
|
||||
}
|
||||
} /* eet_node_hash_add */
|
||||
|
||||
void
|
||||
eet_node_del(Eet_Node *n)
|
||||
eet_node_del(Eet_Node * n)
|
||||
{
|
||||
Eet_Node *nn;
|
||||
Eet_Node *tmp;
|
||||
Eet_Node * nn;
|
||||
Eet_Node * tmp;
|
||||
|
||||
if (!n)
|
||||
return;
|
||||
|
@ -362,13 +375,13 @@ eet_node_del(Eet_Node *n)
|
|||
case EET_T_USHORT:
|
||||
case EET_T_UINT:
|
||||
break;
|
||||
}
|
||||
} /* switch */
|
||||
|
||||
eina_stringshare_del(n->name);
|
||||
eet_node_free(n);
|
||||
}
|
||||
eina_stringshare_del(n->name);
|
||||
eet_node_free(n);
|
||||
} /* eet_node_del */
|
||||
|
||||
static const char *eet_node_dump_g_name[6] = {
|
||||
static const char * eet_node_dump_g_name[6] = {
|
||||
"struct",
|
||||
"array",
|
||||
"var_array",
|
||||
|
@ -377,7 +390,7 @@ static const char *eet_node_dump_g_name[6] = {
|
|||
"???"
|
||||
};
|
||||
|
||||
static const char *eet_node_dump_t_name[14][2] = {
|
||||
static const char * eet_node_dump_t_name[14][2] = {
|
||||
{ "???: ", "???" },
|
||||
{ "char: ", "%hhi" },
|
||||
{ "short: ", "%hi" },
|
||||
|
@ -393,20 +406,20 @@ 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;
|
||||
|
||||
for (i = 0; i < level; i++) dumpfunc(dumpdata, " ");
|
||||
}
|
||||
} /* eet_node_dump_level */
|
||||
|
||||
static char *
|
||||
eet_node_string_escape(const char *str)
|
||||
eet_node_string_escape(const char * str)
|
||||
{
|
||||
char *s, *sp;
|
||||
const char *strp;
|
||||
char * s, * sp;
|
||||
const char * strp;
|
||||
int sz = 0;
|
||||
|
||||
for (strp = str; *strp; strp++)
|
||||
|
@ -441,14 +454,14 @@ eet_node_string_escape(const char *str)
|
|||
}
|
||||
*sp = 0;
|
||||
return s;
|
||||
}
|
||||
} /* eet_node_string_escape */
|
||||
|
||||
static void
|
||||
eet_node_dump_string_escape(void *dumpdata, void dumpfunc(void *data,
|
||||
const char *str),
|
||||
const char *str)
|
||||
eet_node_dump_string_escape(void * dumpdata,
|
||||
void dumpfunc(void * data, const char * str),
|
||||
const char * str)
|
||||
{
|
||||
char *s;
|
||||
char * s;
|
||||
|
||||
s = eet_node_string_escape(str);
|
||||
if (!s)
|
||||
|
@ -456,35 +469,35 @@ eet_node_dump_string_escape(void *dumpdata, void dumpfunc(void *data,
|
|||
|
||||
dumpfunc(dumpdata, s);
|
||||
free(s);
|
||||
}
|
||||
} /* eet_node_dump_string_escape */
|
||||
|
||||
static void
|
||||
eet_node_dump_simple_type(Eet_Node *n, int level,
|
||||
void (*dumpfunc)(void *data,
|
||||
const char *str), void *dumpdata)
|
||||
eet_node_dump_simple_type(Eet_Node * n, int level,
|
||||
void (* dumpfunc)(void * data, const char * str),
|
||||
void * dumpdata)
|
||||
{
|
||||
const char *type_name = NULL;
|
||||
const char * type_name = NULL;
|
||||
char tbuf[256];
|
||||
|
||||
eet_node_dump_level(level, dumpfunc, dumpdata);
|
||||
dumpfunc(dumpdata, "value \"");
|
||||
eet_node_dump_string_escape(dumpdata, dumpfunc, n->name);
|
||||
dumpfunc(dumpdata, "\" ");
|
||||
dumpfunc(dumpdata, "\" ");
|
||||
|
||||
#ifdef EET_T_TYPE
|
||||
# undef EET_T_TYPE
|
||||
#endif
|
||||
#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)
|
||||
|
@ -519,16 +532,17 @@ eet_node_dump_simple_type(Eet_Node *n, int level,
|
|||
default:
|
||||
dumpfunc(dumpdata, "???: ???");
|
||||
break;
|
||||
}
|
||||
} /* switch */
|
||||
|
||||
dumpfunc(dumpdata, ";\n");
|
||||
}
|
||||
dumpfunc(dumpdata, ";\n");
|
||||
} /* eet_node_dump_simple_type */
|
||||
|
||||
static void
|
||||
eet_node_dump_group_start(int level, void (*dumpfunc)(void *data,
|
||||
const char *str),
|
||||
void *dumpdata,
|
||||
int group_type, const char *name)
|
||||
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;
|
||||
|
||||
|
@ -542,23 +556,24 @@ eet_node_dump_group_start(int level, void (*dumpfunc)(void *data,
|
|||
|
||||
dumpfunc(dumpdata, eet_node_dump_g_name[chnk_type - EET_G_UNKNOWN]);
|
||||
dumpfunc(dumpdata, " {\n");
|
||||
}
|
||||
} /* eet_node_dump_group_start */
|
||||
|
||||
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");
|
||||
}
|
||||
} /* eet_node_dump_group_end */
|
||||
|
||||
void
|
||||
eet_node_dump(Eet_Node *n, int dumplevel, void (*dumpfunc)(void *data,
|
||||
const char *str),
|
||||
void *dumpdata)
|
||||
eet_node_dump(Eet_Node * n,
|
||||
int dumplevel,
|
||||
void (* dumpfunc)(void * data, const char * str),
|
||||
void * dumpdata)
|
||||
{
|
||||
Eet_Node *it;
|
||||
Eet_Node * it;
|
||||
|
||||
if (!n)
|
||||
return;
|
||||
|
@ -615,18 +630,18 @@ eet_node_dump(Eet_Node *n, int dumplevel, void (*dumpfunc)(void *data,
|
|||
case EET_T_ULONG_LONG:
|
||||
eet_node_dump_simple_type(n, dumplevel, dumpfunc, dumpdata);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} /* switch */
|
||||
} /* eet_node_dump */
|
||||
|
||||
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;
|
||||
Eet_Node * it;
|
||||
void * me = NULL;
|
||||
int i;
|
||||
|
||||
if (!root)
|
||||
|
@ -643,7 +658,7 @@ eet_node_walk(void *parent,
|
|||
me = cb->struct_alloc(root->name, user_data);
|
||||
|
||||
for (it = root->values; it != NULL; it = it->next)
|
||||
eet_node_walk(me, it->name, it, cb, user_data);
|
||||
eet_node_walk(me, it->name, it, cb, user_data);
|
||||
|
||||
break;
|
||||
|
||||
|
@ -698,19 +713,19 @@ eet_node_walk(void *parent,
|
|||
case EET_T_ULONG_LONG:
|
||||
me = cb->simple(root->type, &root->data, user_data);
|
||||
break;
|
||||
}
|
||||
} /* switch */
|
||||
|
||||
if (parent)
|
||||
cb->struct_add(parent, name, me, user_data);
|
||||
|
||||
return me;
|
||||
}
|
||||
} /* eet_node_walk */
|
||||
|
||||
int
|
||||
eet_node_init(void)
|
||||
{
|
||||
const char *choice;
|
||||
const char *tmp;
|
||||
const char * choice;
|
||||
const char * tmp;
|
||||
|
||||
choice = "chained_mempool";
|
||||
tmp = getenv("EET_MEMPOOL");
|
||||
|
@ -721,11 +736,12 @@ eet_node_init(void)
|
|||
eina_mempool_add(choice, "eet-node-alloc", NULL, sizeof(Eet_Node), 1024);
|
||||
|
||||
return _eet_node_mp ? 1 : 0;
|
||||
}
|
||||
} /* eet_node_init */
|
||||
|
||||
void
|
||||
eet_node_shutdown(void)
|
||||
{
|
||||
eina_mempool_del(_eet_node_mp);
|
||||
_eet_node_mp = NULL;
|
||||
}
|
||||
} /* eet_node_shutdown */
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
#endif /* ifdef HAVE_CONFIG_H */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
@ -13,12 +13,13 @@
|
|||
#include "Eet_private.h"
|
||||
|
||||
int
|
||||
_eet_hash_gen(const char *key, int hash_size)
|
||||
_eet_hash_gen(const char * key,
|
||||
int hash_size)
|
||||
{
|
||||
int hash_num = 0;
|
||||
int value, i;
|
||||
int mask;
|
||||
unsigned char *ptr;
|
||||
unsigned char * ptr;
|
||||
|
||||
/* no string - index 0 */
|
||||
if (!key)
|
||||
|
@ -35,5 +36,5 @@ _eet_hash_gen(const char *key, int hash_size)
|
|||
hash_num &= mask;
|
||||
/* return it */
|
||||
return hash_num;
|
||||
}
|
||||
} /* _eet_hash_gen */
|
||||
|
||||
|
|
|
@ -6,28 +6,28 @@
|
|||
#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;
|
||||
}
|
||||
} /* _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);
|
||||
}
|
||||
} /* _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);
|
||||
|
@ -37,17 +37,17 @@ _eet_eina_hash_add(Eina_Hash *hash, const char *key, const void *data)
|
|||
|
||||
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);
|
||||
}
|
||||
} /* _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;
|
||||
|
@ -63,5 +63,5 @@ eet_test_setup_eddc(Eet_Data_Descriptor_Class *eddc)
|
|||
eddc->func.hash_free = (void *)_eet_eina_hash_free;
|
||||
eddc->func.str_direct_alloc = (void *)_eet_str_direct_alloc;
|
||||
eddc->func.str_direct_free = (void *)_eet_str_direct_free;
|
||||
}
|
||||
} /* eet_test_setup_eddc */
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,7 +3,6 @@
|
|||
|
||||
#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 */
|
||||
|
|
Loading…
Reference in New Issue