summaryrefslogtreecommitdiff
path: root/src/lib/emile
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@samsung.com>2015-03-17 08:50:06 +0100
committerCedric BAIL <cedric@osg.samsung.com>2015-03-17 09:58:18 +0100
commitc3a1859e59464a4317d2aed7f6691b3220c0b3f8 (patch)
treef614131216586284aca8b0653d9a60349beac360 /src/lib/emile
parent97c703cdafe0aef85d48bd968635dd50586f1f2f (diff)
emile: make it cross platform.
Diffstat (limited to 'src/lib/emile')
-rw-r--r--src/lib/emile/emile_main.c63
1 files changed, 55 insertions, 8 deletions
diff --git a/src/lib/emile/emile_main.c b/src/lib/emile/emile_main.c
index 63f1c5aa8a..2e137d2009 100644
--- a/src/lib/emile/emile_main.c
+++ b/src/lib/emile/emile_main.c
@@ -19,20 +19,71 @@
19#include "Emile.h" 19#include "Emile.h"
20#include "emile_private.h" 20#include "emile_private.h"
21 21
22#ifdef HAVE_GNUTLS
23GCRY_THREAD_OPTION_PTHREAD_IMPL;
24#endif /* ifdef HAVE_GNUTLS */
25
26static Eina_Bool _emile_cipher_init = EINA_FALSE; 22static Eina_Bool _emile_cipher_init = EINA_FALSE;
27static unsigned int _emile_init_count = 0; 23static unsigned int _emile_init_count = 0;
28int _emile_log_dom_global = -1; 24int _emile_log_dom_global = -1;
29 25
26#ifdef HAVE_GNUTLS
27static int
28_emile_thread_mutex_init(void **priv)
29{
30 Eina_Lock *lock;
31
32 lock = malloc(sizeof (Eina_Lock));
33 if (!lock) return ENOMEM;
34
35 if (!eina_lock_new(lock))
36 {
37 free(lock);
38 return ENOMEM;
39 }
40
41 *priv = lock;
42 return 0;
43}
44
45static int
46_emile_thread_mutex_destroy(void **priv)
47{
48 eina_lock_free(*priv);
49 free(*priv);
50 return 0;
51}
52
53static int
54_emile_thread_mutex_lock(void **priv)
55{
56 if (eina_lock_take(*priv) == EINA_LOCK_FAIL)
57 return EINVAL;
58 return 0;
59}
60
61static int
62_emile_thread_mutex_unlock(void **priv)
63{
64 if (eina_lock_release(*priv) == EINA_LOCK_FAIL)
65 return EINVAL;
66 return 0;
67}
68
69static struct gcry_thread_cbs _emile_threads = {
70 (GCRY_THREAD_OPTION_PTHREAD | (GCRY_THREAD_OPTION_VERSION << 8)),
71 NULL, _emile_thread_mutex_init, _emile_thread_mutex_destroy,
72 _emile_thread_mutex_lock, _emile_thread_mutex_unlock,
73 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
74};
75#endif /* ifdef HAVE_GNUTLS */
76
30EAPI Eina_Bool 77EAPI Eina_Bool
31emile_cipher_init(void) 78emile_cipher_init(void)
32{ 79{
33 if (_emile_cipher_init) return EINA_TRUE; 80 if (_emile_cipher_init) return EINA_TRUE;
34 81
35#ifdef HAVE_GNUTLS 82#ifdef HAVE_GNUTLS
83 if (gcry_control(GCRYCTL_SET_THREAD_CBS, &_emile_threads))
84 WRN(
85 "YOU ARE USING PTHREADS, BUT I CANNOT INITIALIZE THREADSAFE GCRYPT OPERATIONS!");
86
36 /* Before the library can be used, it must initialize itself if needed. */ 87 /* Before the library can be used, it must initialize itself if needed. */
37 if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0) 88 if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0)
38 { 89 {
@@ -52,10 +103,6 @@ emile_cipher_init(void)
52 "BIG FAT WARNING: I AM UNABLE TO REQUEST SECMEM, Cryptographic operation are at risk !"); 103 "BIG FAT WARNING: I AM UNABLE TO REQUEST SECMEM, Cryptographic operation are at risk !");
53 } 104 }
54 105
55 if (gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread))
56 WRN(
57 "YOU ARE USING PTHREADS, BUT I CANNOT INITIALIZE THREADSAFE GCRYPT OPERATIONS!");
58
59 if (gnutls_global_init()) 106 if (gnutls_global_init())
60 return EINA_FALSE; 107 return EINA_FALSE;
61 108