summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--p11-kit/compat.c8
-rw-r--r--p11-kit/compat.h48
-rw-r--r--p11-kit/conf.c36
-rw-r--r--p11-kit/debug.c17
-rw-r--r--p11-kit/debug.h12
-rw-r--r--p11-kit/hashmap.c68
-rw-r--r--p11-kit/hashmap.h63
-rw-r--r--p11-kit/modules.c110
-rw-r--r--p11-kit/pin.c40
-rw-r--r--p11-kit/private.h4
-rw-r--r--p11-kit/proxy.c18
-rw-r--r--p11-kit/ptr-array.c28
-rw-r--r--p11-kit/ptr-array.h14
-rw-r--r--p11-kit/uri.c2
-rw-r--r--p11-kit/util.c12
-rw-r--r--p11-kit/util.h2
-rw-r--r--tests/conf-test.c140
-rw-r--r--tests/hash-test.c162
-rw-r--r--tests/mock-module.c10
-rw-r--r--tests/ptr-array-test.c122
-rw-r--r--tests/test-init.c22
-rw-r--r--tests/uri-test.c5
22 files changed, 484 insertions, 459 deletions
diff --git a/p11-kit/compat.c b/p11-kit/compat.c
index 5fe8a84..db0b0ce 100644
--- a/p11-kit/compat.c
+++ b/p11-kit/compat.c
@@ -42,7 +42,7 @@
#ifdef OS_UNIX
void
-mutex_init (mutex_t *mutex)
+_p11_mutex_init (mutex_t *mutex)
{
pthread_mutexattr_t attr;
int ret;
@@ -59,7 +59,7 @@ mutex_init (mutex_t *mutex)
#ifdef OS_WIN32
const char *
-module_error (void)
+_p11_module_error (void)
{
DWORD code = GetLastError();
p11_local *local;
@@ -82,7 +82,7 @@ module_error (void)
}
int
-thread_create (thread_t *thread,
+_p11_thread_create (thread_t *thread,
thread_routine routine,
void *arg)
{
@@ -99,7 +99,7 @@ thread_create (thread_t *thread,
}
int
-thread_join (thread_t thread)
+_p11_thread_join (thread_t thread)
{
DWORD res;
diff --git a/p11-kit/compat.h b/p11-kit/compat.h
index 4972b19..39dd67e 100644
--- a/p11-kit/compat.h
+++ b/p11-kit/compat.h
@@ -55,36 +55,36 @@ typedef CRITICAL_SECTION mutex_t;
typedef HANDLE thread_t;
-#define mutex_init(m) \
+#define _p11_mutex_init(m) \
(InitializeCriticalSection (m))
-#define mutex_lock(m) \
+#define _p11_mutex_lock(m) \
(EnterCriticalSection (m))
-#define mutex_unlock(m) \
+#define _p11_mutex_unlock(m) \
(LeaveCriticalSection (m))
-#define mutex_uninit(m) \
+#define _p11_mutex_uninit(m) \
(DeleteCriticalSection (m))
typedef void * (*thread_routine) (void *arg);
-int thread_create (thread_t *thread, thread_routine, void *arg);
+int _p11_thread_create (thread_t *thread, thread_routine, void *arg);
-int thread_join (thread_t thread);
+int _p11_thread_join (thread_t thread);
-#define thread_self() \
+#define _p11_thread_self() \
(GetCurrentThread ())
typedef HMODULE dl_module_t;
-#define module_open(f) \
+#define _p11_module_open(f) \
(LoadLibrary (f))
-#define module_close(d) \
+#define _p11_module_close(d) \
(FreeLibrary (d))
-#define module_symbol(d, s) \
+#define _p11_module_symbol(d, s) \
((void *)GetProcAddress ((d), (s)))
-const char * module_error (void);
+const char * _p11_module_error (void);
-#define sleep_ms(ms) \
+#define _p11_sleep_ms(ms) \
(Sleep (ms))
#endif /* OS_WIN32 */
@@ -101,38 +101,38 @@ const char * module_error (void);
typedef pthread_mutex_t mutex_t;
-void mutex_init (mutex_t *mutex);
+void _p11_mutex_init (mutex_t *mutex);
-#define mutex_lock(m) \
+#define _p11_mutex_lock(m) \
(pthread_mutex_lock (m))
-#define mutex_unlock(m) \
+#define _p11_mutex_unlock(m) \
(pthread_mutex_unlock (m))
-#define mutex_uninit(m) \
+#define _p11_mutex_uninit(m) \
(pthread_mutex_destroy(m))
typedef pthread_t thread_t;
typedef void * (*thread_routine) (void *arg);
-#define thread_create(t, r, a) \
+#define _p11_thread_create(t, r, a) \
(pthread_create ((t), NULL, (r), (a)))
-#define thread_join(t) \
+#define _p11_thread_join(t) \
(pthread_join ((t), NULL))
-#define thread_self(m) \
+#define _p11_thread_self(m) \
(pthread_self ())
typedef void * dl_module_t;
-#define module_open(f) \
+#define _p11_module_open(f) \
(dlopen ((f), RTLD_LOCAL | RTLD_NOW))
-#define module_close(d) \
+#define _p11_module_close(d) \
(dlclose(d))
-#define module_error() \
+#define _p11_module_error() \
(dlerror ())
-#define module_symbol(d, s) \
+#define _p11_module_symbol(d, s) \
(dlsym ((d), (s)))
-#define sleep_ms(ms) \
+#define _p11_sleep_ms(ms) \
do { int _ms = (ms); \
struct timespec _ts = { _ms / 1000, (_ms % 1000) * 1000 * 1000 }; \
nanosleep (&_ts, NULL); \
diff --git a/p11-kit/conf.c b/p11-kit/conf.c
index b05c8aa..d607bfd 100644
--- a/p11-kit/conf.c
+++ b/p11-kit/conf.c
@@ -220,10 +220,10 @@ _p11_conf_merge_defaults (hashmap *map, hashmap *defaults)
void *key;
void *value;
- hash_iterate (defaults, &iter);
- while (hash_next (&iter, &key, &value)) {
+ _p11_hash_iterate (defaults, &iter);
+ while (_p11_hash_next (&iter, &key, &value)) {
/* Only override if not set */
- if (hash_get (map, key))
+ if (_p11_hash_get (map, key))
continue;
key = strdup (key);
if (key == NULL) {
@@ -236,7 +236,7 @@ _p11_conf_merge_defaults (hashmap *map, hashmap *defaults)
errno = ENOMEM;
return -1;
}
- if (!hash_set (map, key, value)) {
+ if (!_p11_hash_set (map, key, value)) {
free (key);
free (value);
errno = ENOMEM;
@@ -269,7 +269,7 @@ _p11_conf_parse_file (const char* filename, int flags)
if (!data)
return NULL;
- map = hash_create (hash_string_hash, hash_string_equal, free, free);
+ map = _p11_hash_create (_p11_hash_string_hash, _p11_hash_string_equal, free, free);
if (map == NULL) {
free (data);
errno = ENOMEM;
@@ -316,7 +316,7 @@ _p11_conf_parse_file (const char* filename, int flags)
debug ("config value: %s: %s", name, value);
- if (!hash_set (map, name, value)) {
+ if (!_p11_hash_set (map, name, value)) {
free (name);
free (value);
error = ENOMEM;
@@ -327,7 +327,7 @@ _p11_conf_parse_file (const char* filename, int flags)
free (data);
if (error != 0) {
- hash_free (map);
+ _p11_hash_free (map);
map = NULL;
errno = error;
}
@@ -384,7 +384,7 @@ user_config_mode (hashmap *config, int defmode)
const char *mode;
/* Whether we should use or override from user directory */
- mode = hash_get (config, "user-config");
+ mode = _p11_hash_get (config, "user-config");
if (mode == NULL) {
return defmode;
} else if (strequal (mode, "none")) {
@@ -462,7 +462,7 @@ _p11_conf_load_globals (const char *system_conf, const char *user_conf,
/* If user config valid at all, then replace system with what we have */
if (mode != CONF_USER_NONE) {
- hash_free (config);
+ _p11_hash_free (config);
config = uconfig;
uconfig = NULL;
}
@@ -476,8 +476,8 @@ _p11_conf_load_globals (const char *system_conf, const char *user_conf,
finished:
free (path);
- hash_free (config);
- hash_free (uconfig);
+ _p11_hash_free (config);
+ _p11_hash_free (uconfig);
errno = error;
return result;
}
@@ -496,12 +496,12 @@ load_config_from_file (const char *configfile, const char *name, hashmap *config
if (!config)
return -1;
- prev = hash_get (configs, name);
+ prev = _p11_hash_get (configs, name);
if (prev == NULL) {
key = strdup (name);
if (key == NULL)
error = ENOMEM;
- else if (!hash_set (configs, key, config))
+ else if (!_p11_hash_set (configs, key, config))
error = errno;
else
config = NULL;
@@ -511,7 +511,7 @@ load_config_from_file (const char *configfile, const char *name, hashmap *config
}
/* If still set */
- hash_free (config);
+ _p11_hash_free (config);
if (error) {
errno = error;
@@ -598,8 +598,8 @@ _p11_conf_load_modules (int mode, const char *system_dir, const char *user_dir)
int error = 0;
/* A hash table of name -> config */
- configs = hash_create (hash_string_hash, hash_string_equal,
- free, (hash_destroy_func)hash_free);
+ configs = _p11_hash_create (_p11_hash_string_hash, _p11_hash_string_equal,
+ free, (hash_destroy_func)_p11_hash_free);
/* Load each user config first, if user config is allowed */
if (mode != CONF_USER_NONE) {
@@ -610,7 +610,7 @@ _p11_conf_load_modules (int mode, const char *system_dir, const char *user_dir)
error = errno;
free (path);
if (error != 0) {
- hash_free (configs);
+ _p11_hash_free (configs);
errno = error;
return NULL;
}
@@ -624,7 +624,7 @@ _p11_conf_load_modules (int mode, const char *system_dir, const char *user_dir)
if (mode != CONF_USER_ONLY) {
if (load_configs_from_directory (system_dir, configs) < 0) {
error = errno;
- hash_free (configs);
+ _p11_hash_free (configs);
errno = error;
return NULL;
}
diff --git a/p11-kit/debug.c b/p11-kit/debug.c
index 5766dae..b332407 100644
--- a/p11-kit/debug.c
+++ b/p11-kit/debug.c
@@ -63,7 +63,7 @@ static int debug_inited = 0;
static mutex_t debug_mutex;
/* global variable exported in debug.h */
-int debug_current_flags;
+int _p11_debug_current_flags = ~0;
static int
parse_environ_flags (void)
@@ -111,23 +111,24 @@ parse_environ_flags (void)
}
void
-debug_init (void)
+_p11_debug_init (void)
{
- debug_current_flags = parse_environ_flags ();
- mutex_init (&debug_mutex);
+ _p11_debug_current_flags = parse_environ_flags ();
+ _p11_mutex_init (&debug_mutex);
debug_inited = 1;
}
void
-debug_message (int flag, const char *format, ...)
+_p11_debug_message (int flag,
+ const char *format, ...)
{
char buffer[512];
va_list args;
assert (debug_inited);
- mutex_lock (&debug_mutex);
+ _p11_mutex_lock (&debug_mutex);
- if (flag & debug_current_flags) {
+ if (flag & _p11_debug_current_flags) {
va_start (args, format);
vsnprintf (buffer, sizeof (buffer), format, args);
buffer[sizeof (buffer) -1] = 0;
@@ -135,5 +136,5 @@ debug_message (int flag, const char *format, ...)
fprintf (stderr, "(p11-kit:%d) %s\n", getpid(), buffer);
}
- mutex_unlock (&debug_mutex);
+ _p11_mutex_unlock (&debug_mutex);
}
diff --git a/p11-kit/debug.h b/p11-kit/debug.h
index b8490dd..fab6800 100644
--- a/p11-kit/debug.h
+++ b/p11-kit/debug.h
@@ -43,11 +43,11 @@ typedef enum {
DEBUG_PROXY = 1 << 4,
} DebugFlags;
-extern int debug_current_flags;
+extern int _p11_debug_current_flags;
-void debug_init (void);
+void _p11_debug_init (void);
-void debug_message (int flag,
+void _p11_debug_message (int flag,
const char *format,
...);
@@ -75,13 +75,13 @@ void debug_message (int flag,
#undef debug
#define debug(format, ...) do { \
- if (DEBUG_FLAG & debug_current_flags) \
- debug_message (DEBUG_FLAG, "%s: " format, __PRETTY_FUNCTION__, ##__VA_ARGS__); \
+ if (DEBUG_FLAG & _p11_debug_current_flags) \
+ _p11_debug_message (DEBUG_FLAG, "%s: " format, __PRETTY_FUNCTION__, ##__VA_ARGS__); \
} while (0)
#undef debugging
#define debugging \
- (DEBUG_FLAG & debug_current_flags)
+ (DEBUG_FLAG & _p11_debug_current_flags)
#else /* !defined (WITH_DEBUG) */
diff --git a/p11-kit/hashmap.c b/p11-kit/hashmap.c
index 518a984..6e91c32 100644
--- a/p11-kit/hashmap.c
+++ b/p11-kit/hashmap.c
@@ -74,7 +74,9 @@ next_entry (hashiter *iter)
int
-hash_next (hashiter *iter, void **key, void **value)
+_p11_hash_next (hashiter *iter,
+ void **key,
+ void **value)
{
hashbucket *bucket = next_entry (iter);
if (bucket == NULL)
@@ -87,7 +89,8 @@ hash_next (hashiter *iter, void **key, void **value)
}
void
-hash_iterate (hashmap *map, hashiter *iter)
+_p11_hash_iterate (hashmap *map,
+ hashiter *iter)
{
iter->map = map;
iter->index = 0;
@@ -95,7 +98,9 @@ hash_iterate (hashmap *map, hashiter *iter)
}
static hashbucket **
-lookup_or_create_bucket (hashmap *map, const void *key, int create)
+lookup_or_create_bucket (hashmap *map,
+ const void *key,
+ int create)
{
hashbucket **bucketp;
unsigned int hash;
@@ -125,8 +130,9 @@ lookup_or_create_bucket (hashmap *map, const void *key, int create)
return bucketp;
}
-void*
-hash_get (hashmap *map, const void *key)
+void *
+_p11_hash_get (hashmap *map,
+ const void *key)
{
hashbucket **bucketp;
@@ -138,7 +144,9 @@ hash_get (hashmap *map, const void *key)
}
int
-hash_set (hashmap *map, void *key, void *val)
+_p11_hash_set (hashmap *map,
+ void *key,
+ void *val)
{
hashbucket **bucketp;
hashiter iter;
@@ -164,7 +172,7 @@ hash_set (hashmap *map, void *key, void *val)
/* Ignore failures, maybe we can expand later */
if(new_buckets) {
- hash_iterate (map, &iter);
+ _p11_hash_iterate (map, &iter);
while ((bucket = next_entry (&iter)) != NULL) {
unsigned int i = bucket->hashed & num_buckets;
bucket->next = new_buckets[i];
@@ -184,7 +192,10 @@ hash_set (hashmap *map, void *key, void *val)
}
int
-hash_steal (hashmap *map, const void *key, void **stolen_key, void **stolen_value)
+_p11_hash_steal (hashmap *map,
+ const void *key,
+ void **stolen_key,
+ void **stolen_value)
{
hashbucket **bucketp;
@@ -206,12 +217,13 @@ hash_steal (hashmap *map, const void *key, void **stolen_key, void **stolen_valu
}
int
-hash_remove (hashmap *map, const void *key)
+_p11_hash_remove (hashmap *map,
+ const void *key)
{
void *old_key;
void *old_value;
- if (!hash_steal (map, key, &old_key, &old_value))
+ if (!_p11_hash_steal (map, key, &old_key, &old_value))
return 0;
if (map->key_destroy_func)
@@ -222,7 +234,7 @@ hash_remove (hashmap *map, const void *key)
}
void
-hash_clear (hashmap *map)
+_p11_hash_clear (hashmap *map)
{
hashbucket *bucket, *next;
int i;
@@ -246,10 +258,10 @@ hash_clear (hashmap *map)
}
hashmap *
-hash_create (hash_hash_func hash_func,
- hash_equal_func equal_func,
- hash_destroy_func key_destroy_func,
- hash_destroy_func value_destroy_func)
+_p11_hash_create (hash_hash_func hash_func,
+ hash_equal_func equal_func,
+ hash_destroy_func key_destroy_func,
+ hash_destroy_func value_destroy_func)
{
hashmap *map;
@@ -278,7 +290,7 @@ hash_create (hash_hash_func hash_func,
}
void
-hash_free (hashmap *map)
+_p11_hash_free (hashmap *map)
{
hashbucket *bucket;
hashiter iter;
@@ -286,7 +298,7 @@ hash_free (hashmap *map)
if (!map)
return;
- hash_iterate (map, &iter);
+ _p11_hash_iterate (map, &iter);
while ((bucket = next_entry (&iter)) != NULL) {
if (map->key_destroy_func)
map->key_destroy_func (bucket->key);
@@ -302,13 +314,13 @@ hash_free (hashmap *map)
}
unsigned int
-hash_size (hashmap *map)
+_p11_hash_size (hashmap *map)
{
return map->num_items;
}
unsigned int
-hash_string_hash (const void *string)
+_p11_hash_string_hash (const void *string)
{
const char *p = string;
unsigned int hash = *p;
@@ -321,7 +333,8 @@ hash_string_hash (const void *string)
}
int
-hash_string_equal (const void *string_one, const void *string_two)
+_p11_hash_string_equal (const void *string_one,
+ const void *string_two)
{
assert (string_one);
assert (string_two);
@@ -330,14 +343,15 @@ hash_string_equal (const void *string_one, const void *string_two)
}
unsigned int
-hash_ulongptr_hash (const void *to_ulong)
+_p11_hash_ulongptr_hash (const void *to_ulong)
{
assert (to_ulong);
return (unsigned int)*((unsigned long*)to_ulong);
}
int
-hash_ulongptr_equal (const void *ulong_one, const void *ulong_two)
+_p11_hash_ulongptr_equal (const void *ulong_one,
+ const void *ulong_two)
{
assert (ulong_one);
assert (ulong_two);
@@ -345,14 +359,15 @@ hash_ulongptr_equal (const void *ulong_one, const void *ulong_two)
}
unsigned int
-hash_intptr_hash (const void *to_int)
+_p11_hash_intptr_hash (const void *to_int)
{
assert (to_int);
return (unsigned int)*((int*)to_int);
}
int
-hash_intptr_equal (const void *int_one, const void *int_two)
+_p11_hash_intptr_equal (const void *int_one,
+ const void *int_two)
{
assert (int_one);
assert (int_two);
@@ -360,13 +375,14 @@ hash_intptr_equal (const void *int_one, const void *int_two)
}
unsigned int
-hash_direct_hash (const void *ptr)
+_p11_hash_direct_hash (const void *ptr)
{
return (unsigned int)(unsigned long)ptr;
}
int
-hash_direct_equal (const void *ptr_one, const void *ptr_two)
+_p11_hash_direct_equal (const void *ptr_one,
+ const void *ptr_two)
{
return ptr_one == ptr_two;
}
diff --git a/p11-kit/hashmap.h b/p11-kit/hashmap.h
index a9292b7..3b35487 100644
--- a/p11-kit/hashmap.h
+++ b/p11-kit/hashmap.h
@@ -62,111 +62,112 @@ typedef struct _hashiter {
unsigned int index;
} hashiter;
-typedef unsigned int (*hash_hash_func) (const void *data);
+typedef unsigned int (*hash_hash_func) (const void *data);
-typedef int (*hash_equal_func) (const void *one,
+typedef int (*hash_equal_func) (const void *one,
const void *two);
-typedef void (*hash_destroy_func) (void *data);
+typedef void (*hash_destroy_func) (void *data);
/* -----------------------------------------------------------------------------
* MAIN
*/
/*
- * hash_create : Create a hash table
+ * _p11_hash_create : Create a hash table
* - returns an allocated hashtable
*/
-hashmap* hash_create (hash_hash_func hash_func,
+hashmap* _p11_hash_create (hash_hash_func hash_func,
hash_equal_func equal_func,
hash_destroy_func key_destroy_func,
hash_destroy_func value_destroy_func);
/*
- * hash_free : Free a hash table
+ * _p11_hash_free : Free a hash table
*/
-void hash_free (hashmap *map);
+void _p11_hash_free (hashmap *map);
/*
- * hash_size: Number of values in hash table
+ * _p11_hash_size: Number of values in hash table
* - returns the number of entries in hash table
*/
-unsigned int hash_size (hashmap *map);
+unsigned int _p11_hash_size (hashmap *map);
/*
- * hash_get: Retrieves a value from the hash table
+ * _p11_hash_get: Retrieves a value from the hash table
* - returns the value of the entry
*/
-void* hash_get (hashmap *map,
+void* _p11_hash_get (hashmap *map,
const void *key);
/*
- * hash_set: Set a value in the hash table
+ * _p11_hash_set: Set a value in the hash table
* - returns 1 if the entry was added properly
*/
-int hash_set (hashmap *map,
+int _p11_hash_set (hashmap *map,
void *key,
void *value);
/*
- * hash_remove: Remove a value from the hash table
+ * _p11_hash_remove: Remove a value from the hash table
* - returns 1 if the entry was found
*/
-int hash_remove (hashmap *map,
+int _p11_hash_remove (hashmap *map,
const void *key);
/*
- * hash_steal: Remove a value from the hash table without calling destroy funcs
+ * _p11_hash_steal: Remove a value from the hash table without calling
+ * destroy funcs
* - returns 1 if the entry was found
*/
-int hash_steal (hashmap *map,
+int _p11_hash_steal (hashmap *map,
const void *key,
void **stolen_key,
void **stolen_value);
/*
- * hash_first: Start enumerating through the hash table
+ * _p11_hash_iterate: Start enumerating through the hash table
* - returns a hash iterator
*/
-void hash_iterate (hashmap *map,
+void _p11_hash_iterate (hashmap *map,
hashiter *iter);
/*
- * hash_next: Enumerate through hash table
+ * _p11_hash_next: Enumerate through hash table
* - sets key and value to key and/or value
* - returns whether there was another entry
*/
-int hash_next (hashiter *iter,
+int _p11_hash_next (hashiter *iter,
void **key,
void **value);
/*
- * hash_clear: Clear all values from has htable.
+ * _p11_hash_clear: Clear all values from has htable.
*/
-void hash_clear (hashmap *map);
+void _p11_hash_clear (hashmap *map);
/* -----------------------------------------------------------------------------
* HASH FUNCTIONS
*/
-unsigned int hash_string_hash (const void *string);
+unsigned int _p11_hash_string_hash (const void *string);
-int hash_string_equal (const void *string_one,
+int _p11_hash_string_equal (const void *string_one,
const void *string_two);
-unsigned int hash_ulongptr_hash (const void *to_ulong);
+unsigned int _p11_hash_ulongptr_hash (const void *to_ulong);
-int hash_ulongptr_equal (const void *ulong_one,
+int _p11_hash_ulongptr_equal (const void *ulong_one,
const void *ulong_two);
-unsigned int hash_intptr_hash (const void *to_int);
+unsigned int _p11_hash_intptr_hash (const void *to_int);
-int hash_intptr_equal (const void *int_one,
+int _p11_hash_intptr_equal (const void *int_one,
const void *int_two);
-unsigned int hash_direct_hash (const void *ptr);
+unsigned int _p11_hash_direct_hash (const void *ptr);
-int hash_direct_equal (const void *ptr_one,
+int _p11_hash_direct_equal (const void *ptr_one,
const void *ptr_two);
#endif /* __HASHMAP_H__ */
diff --git a/p11-kit/modules.c b/p11-kit/modules.c
index 34926a4..1c56208 100644
--- a/p11-kit/modules.c
+++ b/p11-kit/modules.c
@@ -135,7 +135,7 @@ create_mutex (CK_VOID_PTR_PTR mut)
pmutex = malloc (sizeof (mutex_t));
if (!pmutex)
return CKR_HOST_MEMORY;
- mutex_init (pmutex);
+ _p11_mutex_init (pmutex);
*mut = pmutex;
return CKR_OK;
}
@@ -148,7 +148,7 @@ destroy_mutex (CK_VOID_PTR mut)
if (mut == NULL)
return CKR_MUTEX_BAD;
- mutex_uninit (pmutex);
+ _p11_mutex_uninit (pmutex);
free (pmutex);
return CKR_OK;
}
@@ -161,7 +161,7 @@ lock_mutex (CK_VOID_PTR mut)
if (mut == NULL)
return CKR_MUTEX_BAD;
- mutex_lock (pmutex);
+ _p11_mutex_lock (pmutex);
return CKR_OK;
}
@@ -173,7 +173,7 @@ unlock_mutex (CK_VOID_PTR mut)
if (mut == NULL)
return CKR_MUTEX_BAD;
- mutex_unlock (pmutex);
+ _p11_mutex_unlock (pmutex);
return CKR_OK;
}
@@ -192,10 +192,10 @@ free_module_unlocked (void *data)
assert (mod->ref_count == 0);
if (mod->dl_module)
- module_close (mod->dl_module);
+ _p11_module_close (mod->dl_module);
- mutex_uninit (&mod->initialize_mutex);
- hash_free (mod->config);
+ _p11_mutex_uninit (&mod->initialize_mutex);
+ _p11_hash_free (mod->config);
free (mod->name);
free (mod);
}
@@ -214,7 +214,7 @@ alloc_module_unlocked (void)
mod->init_args.LockMutex = lock_mutex;
mod->init_args.UnlockMutex = unlock_mutex;
mod->init_args.flags = CKF_OS_LOCKING_OK;
- mutex_init (&mod->initialize_mutex);
+ _p11_mutex_init (&mod->initialize_mutex);
return mod;
}
@@ -262,16 +262,16 @@ dlopen_and_get_function_list (Module *mod, const char *path)
assert (mod);
assert (path);
- mod->dl_module = module_open (path);
+ mod->dl_module = _p11_module_open (path);
if (mod->dl_module == NULL) {
- _p11_message ("couldn't load module: %s: %s", path, module_error ());
+ _p11_message ("couldn't load module: %s: %s", path, _p11_module_error ());
return CKR_GENERAL_ERROR;
}
- gfl = module_symbol (mod->dl_module, "C_GetFunctionList");
+ gfl = _p11_module_symbol (mod->dl_module, "C_GetFunctionList");
if (!gfl) {
_p11_message ("couldn't find C_GetFunctionList entry point in module: %s: %s",
- path, module_error ());
+ path, _p11_module_error ());
return CKR_GENERAL_ERROR;
}
@@ -304,14 +304,14 @@ load_module_from_file_unlocked (const char *path, Module **result)
}
/* Do we have a previous one like this, if so ignore load */
- prev = hash_get (gl.modules, mod->funcs);
+ prev = _p11_hash_get (gl.modules, mod->funcs);
if (prev != NULL) {
debug ("duplicate module %s, using previous", path);
free_module_unlocked (mod);
mod = prev;
- } else if (!hash_set (gl.modules, mod->funcs, mod)) {
+ } else if (!_p11_hash_set (gl.modules, mod->funcs, mod)) {
free_module_unlocked (mod);
return CKR_HOST_MEMORY;
}
@@ -349,7 +349,7 @@ take_config_and_load_module_unlocked (char **name, hashmap **config)
assert (config);
assert (*config);
- module_filename = hash_get (*config, "module");
+ module_filename = _p11_hash_get (*config, "module");
if (module_filename == NULL) {
debug ("no module path for module, skipping: %s", *name);
return CKR_OK;
@@ -360,7 +360,7 @@ take_config_and_load_module_unlocked (char **name, hashmap **config)
return CKR_HOST_MEMORY;
/* The hash map will take ownership of the variable */
- if (!hash_set (*config, "module", path)) {
+ if (!_p11_hash_set (*config, "module", path)) {
free (path);
return CKR_HOST_MEMORY;
}
@@ -381,7 +381,7 @@ take_config_and_load_module_unlocked (char **name, hashmap **config)
return rv;
}
- prev = hash_get (gl.modules, mod->funcs);
+ prev = _p11_hash_get (gl.modules, mod->funcs);
/* If same module was loaded previously, just take over config */
if (prev && !prev->name && !prev->config) {
@@ -398,7 +398,7 @@ take_config_and_load_module_unlocked (char **name, hashmap **config)
/* Add this new module to our hash table */
} else {
- if (!hash_set (gl.modules, mod->funcs, mod)) {
+ if (!_p11_hash_set (gl.modules, mod->funcs, mod)) {
free_module_unlocked (mod);
return CKR_HOST_MEMORY;
}
@@ -409,7 +409,7 @@ take_config_and_load_module_unlocked (char **name, hashmap **config)
* 'x-init-reserved' setting in the config. This only works with specific
* PKCS#11 modules, and is non-standard use of that field.
*/
- mod->init_args.pReserved = hash_get (mod->config, "x-init-reserved");
+ mod->init_args.pReserved = _p11_hash_get (mod->config, "x-init-reserved");
return CKR_OK;
}
@@ -440,7 +440,7 @@ load_registered_modules_unlocked (void)
P11_USER_CONFIG_MODULES);
if (configs == NULL) {
rv = (errno == ENOMEM) ? CKR_HOST_MEMORY : CKR_GENERAL_ERROR;
- hash_free (config);
+ _p11_hash_free (config);
return rv;
}
@@ -451,13 +451,13 @@ load_registered_modules_unlocked (void)
* Now go through each config and turn it into a module. As we iterate
* we steal the values of the config.
*/
- hash_iterate (configs, &iter);
- while (hash_next (&iter, &key, NULL)) {
- if (!hash_steal (configs, key, (void**)&name, (void**)&config))
+ _p11_hash_iterate (configs, &iter);
+ while (_p11_hash_next (&iter, &key, NULL)) {
+ if (!_p11_hash_steal (configs, key, (void**)&name, (void**)&config))
assert (0 && "not reached");
/* Is this a critical module, should abort loading of others? */
- critical = _p11_conf_parse_boolean (hash_get (config, "critical"), 0);
+ critical = _p11_conf_parse_boolean (_p11_hash_get (config, "critical"), 0);
rv = take_config_and_load_module_unlocked (&name, &config);
@@ -466,16 +466,16 @@ load_registered_modules_unlocked (void)
* by the above function call.
*/
free (name);
- hash_free (config);
+ _p11_hash_free (config);
if (critical && rv != CKR_OK) {
_p11_message ("aborting initializationg because module '%s' was marked as critical");
- hash_free (configs);
+ _p11_hash_free (configs);
return rv;
}
}
- hash_free (configs);
+ _p11_hash_free (configs);
return CKR_OK;
}
@@ -486,7 +486,7 @@ initialize_module_unlocked_reentrant (Module *mod)
thread_t self;
assert (mod);
- self = thread_self ();
+ self = _p11_thread_self ();
if (mod->initialize_thread == self) {
_p11_message ("p11-kit initialization called recursively");
@@ -501,7 +501,7 @@ initialize_module_unlocked_reentrant (Module *mod)
mod->initialize_thread = self;
/* Change over to the module specific mutex */
- mutex_lock (&mod->initialize_mutex);
+ _p11_mutex_lock (&mod->initialize_mutex);
_p11_unlock ();
if (!mod->initialize_called) {
@@ -522,7 +522,7 @@ initialize_module_unlocked_reentrant (Module *mod)
rv = CKR_OK;
}
- mutex_unlock (&mod->initialize_mutex);
+ _p11_mutex_unlock (&mod->initialize_mutex);
_p11_lock ();
/* Don't claim reference if failed */
@@ -547,8 +547,8 @@ reinitialize_after_fork (void)
_p11_lock ();
if (gl.modules) {
- hash_iterate (gl.modules, &iter);
- while (hash_next (&iter, NULL, (void **)&mod)) {
+ _p11_hash_iterate (gl.modules, &iter);
+ while (_p11_hash_next (&iter, NULL, (void **)&mod)) {
if (mod->initialize_called) {
mod->initialize_called = 0;
@@ -571,7 +571,7 @@ init_globals_unlocked (void)
static int once = 0;
if (!gl.modules)
- gl.modules = hash_create (hash_direct_hash, hash_direct_equal,
+ gl.modules = _p11_hash_create (_p11_hash_direct_hash, _p11_hash_direct_equal,
NULL, free_module_unlocked);
if (!gl.modules)
return CKR_HOST_MEMORY;
@@ -594,15 +594,15 @@ free_modules_when_no_refs_unlocked (void)
hashiter iter;
/* Check if any modules have a ref count */
- hash_iterate (gl.modules, &iter);
- while (hash_next (&iter, NULL, (void **)&mod)) {
+ _p11_hash_iterate (gl.modules, &iter);
+ while (_p11_hash_next (&iter, NULL, (void **)&mod)) {
if (mod->ref_count)
return;
}
- hash_free (gl.modules);
+ _p11_hash_free (gl.modules);
gl.modules = NULL;
- hash_free (gl.config);
+ _p11_hash_free (gl.config);
gl.config = NULL;
}
@@ -628,7 +628,7 @@ finalize_module_unlocked_reentrant (Module *mod)
*/
++mod->ref_count;
- mutex_lock (&mod->initialize_mutex);
+ _p11_mutex_lock (&mod->initialize_mutex);
_p11_unlock ();
if (mod->initialize_called) {
@@ -639,7 +639,7 @@ finalize_module_unlocked_reentrant (Module *mod)
mod->initialize_called = 0;
}
- mutex_unlock (&mod->initialize_mutex);
+ _p11_mutex_unlock (&mod->initialize_mutex);
_p11_lock ();
/* Match the increment above */
@@ -657,8 +657,8 @@ find_module_for_name_unlocked (const char *name)
assert (name);
- hash_iterate (gl.modules, &iter);
- while (hash_next (&iter, NULL, (void **)&mod))
+ _p11_hash_iterate (gl.modules, &iter);
+ while (_p11_hash_next (&iter, NULL, (void **)&mod))
if (mod->ref_count && mod->name && strcmp (name, mod->name) == 0)
return mod;
return NULL;
@@ -677,8 +677,8 @@ _p11_kit_initialize_registered_unlocked_reentrant (void)
rv = load_registered_modules_unlocked ();
if (rv == CKR_OK) {
- hash_iterate (gl.modules, &iter);
- while (hash_next (&iter, NULL, (void **)&mod)) {
+ _p11_hash_iterate (gl.modules, &iter);
+ while (_p11_hash_next (&iter, NULL, (void **)&mod)) {
/* Skip all modules that aren't registered */
if (!mod->name)
@@ -756,13 +756,13 @@ _p11_kit_finalize_registered_unlocked_reentrant (void)
/* WARNING: This function must be reentrant */
- to_finalize = calloc (hash_size (gl.modules), sizeof (Module *));
+ to_finalize = calloc (_p11_hash_size (gl.modules), sizeof (Module *));
if (!to_finalize)
return CKR_HOST_MEMORY;
count = 0;
- hash_iterate (gl.modules, &iter);
- while (hash_next (&iter, NULL, (void **)&mod)) {
+ _p11_hash_iterate (gl.modules, &iter);
+ while (_p11_hash_next (&iter, NULL, (void **)&mod)) {
/* Skip all modules that aren't registered */
if (mod->name)
@@ -835,10 +835,10 @@ _p11_kit_registered_modules_unlocked (void)
int i = 0;
if (gl.modules)
- result = calloc (hash_size (gl.modules) + 1, sizeof (CK_FUNCTION_LIST_PTR));
+ result = calloc (_p11_hash_size (gl.modules) + 1, sizeof (CK_FUNCTION_LIST_PTR));
if (result) {
- hash_iterate (gl.modules, &iter);
- while (hash_next (&iter, NULL, (void **)&mod)) {
+ _p11_hash_iterate (gl.modules, &iter);
+ while (_p11_hash_next (&iter, NULL, (void **)&mod)) {
if (mod->ref_count && mod->name)
result[i++] = mod->funcs;
}
@@ -902,7 +902,7 @@ p11_kit_registered_module_to_name (CK_FUNCTION_LIST_PTR module)
_p11_kit_clear_message ();
- mod = module && gl.modules ? hash_get (gl.modules, module) : NULL;
+ mod = module && gl.modules ? _p11_hash_get (gl.modules, module) : NULL;
if (mod && mod->name)
name = strdup (mod->name);
@@ -972,13 +972,13 @@ p11_kit_registered_option (CK_FUNCTION_LIST_PTR module, const char *field)
config = gl.config;
} else {
- mod = gl.modules ? hash_get (gl.modules, module) : NULL;
+ mod = gl.modules ? _p11_hash_get (gl.modules, module) : NULL;
if (mod)
config = mod->config;
}
if (config && field) {
- option = hash_get (config, field);
+ option = _p11_hash_get (config, field);
if (option)
option = strdup (option);
}
@@ -1037,7 +1037,7 @@ p11_kit_initialize_module (CK_FUNCTION_LIST_PTR module)
rv = init_globals_unlocked ();
if (rv == CKR_OK) {
- mod = hash_get (gl.modules, module);
+ mod = _p11_hash_get (gl.modules, module);
if (mod == NULL) {
debug ("allocating new module");
allocated = mod = alloc_module_unlocked ();
@@ -1049,7 +1049,7 @@ p11_kit_initialize_module (CK_FUNCTION_LIST_PTR module)
/* If this was newly allocated, add it to the list */
if (rv == CKR_OK && allocated) {
- if (hash_set (gl.modules, allocated->funcs, allocated))
+ if (_p11_hash_set (gl.modules, allocated->funcs, allocated))
allocated = NULL;
else
rv = CKR_HOST_MEMORY;
@@ -1119,7 +1119,7 @@ p11_kit_finalize_module (CK_FUNCTION_LIST_PTR module)
_p11_kit_clear_message ();
- mod = gl.modules ? hash_get (gl.modules, module) : NULL;
+ mod = gl.modules ? _p11_hash_get (gl.modules, module) : NULL;
if (mod == NULL) {
debug ("module not found");
rv = CKR_ARGUMENTS_BAD;
diff --git a/p11-kit/pin.c b/p11-kit/pin.c
index f74620a..531d0d0 100644
--- a/p11-kit/pin.c
+++ b/p11-kit/pin.c
@@ -220,8 +220,8 @@ p11_kit_pin_register_callback (const char *pin_source, p11_kit_pin_callback call
_p11_lock ();
if (gl.pin_sources == NULL) {
- gl.pin_sources = hash_create (hash_string_hash, hash_string_equal,
- free, (hash_destroy_func)ptr_array_free);
+ gl.pin_sources = _p11_hash_create (_p11_hash_string_hash, _p11_hash_string_equal,
+ free, (hash_destroy_func)_p11_ptr_array_free);
if (gl.pin_sources == NULL) {
errno = ENOMEM;
ret = -1;
@@ -229,15 +229,15 @@ p11_kit_pin_register_callback (const char *pin_source, p11_kit_pin_callback call
}
if (gl.pin_sources != NULL)
- callbacks = hash_get (gl.pin_sources, pin_source);
+ callbacks = _p11_hash_get (gl.pin_sources, pin_source);
if (callbacks == NULL) {
- callbacks = ptr_array_create (unref_pin_callback);
+ callbacks = _p11_ptr_array_create (unref_pin_callback);
if (callbacks == NULL) {
errno = ENOMEM;
ret = -1;
- } else if (!hash_set (gl.pin_sources, name, callbacks)) {
- ptr_array_free (callbacks);
+ } else if (!_p11_hash_set (gl.pin_sources, name, callbacks)) {
+ _p11_ptr_array_free (callbacks);
callbacks = NULL;
errno = ENOMEM;
ret = -1;
@@ -248,7 +248,7 @@ p11_kit_pin_register_callback (const char *pin_source, p11_kit_pin_callback call
}
if (callbacks != NULL) {
- if (ptr_array_add (callbacks, cb) < 0) {
+ if (_p11_ptr_array_add (callbacks, cb) < 0) {
errno = ENOMEM;
ret = -1;
} else {
@@ -289,23 +289,23 @@ p11_kit_pin_unregister_callback (const char *pin_source, p11_kit_pin_callback ca
_p11_lock ();
if (gl.pin_sources) {
- callbacks = hash_get (gl.pin_sources, pin_source);
+ callbacks = _p11_hash_get (gl.pin_sources, pin_source);
if (callbacks) {
- for (i = 0; i < ptr_array_count (callbacks); i++) {
- cb = ptr_array_at (callbacks, i);
+ for (i = 0; i < _p11_ptr_array_count (callbacks); i++) {
+ cb = _p11_ptr_array_at (callbacks, i);
if (cb->func == callback && cb->user_data == callback_data) {
- ptr_array_remove (callbacks, i);
+ _p11_ptr_array_remove (callbacks, i);
break;
}
}
- if (ptr_array_count (callbacks) == 0)
- hash_remove (gl.pin_sources, pin_source);
+ if (_p11_ptr_array_count (callbacks) == 0)
+ _p11_hash_remove (gl.pin_sources, pin_source);
}
/* When there are no more pin sources, get rid of the hash table */
- if (hash_size (gl.pin_sources) == 0) {
- hash_free (gl.pin_sources);
+ if (_p11_hash_size (gl.pin_sources) == 0) {
+ _p11_hash_free (gl.pin_sources);
gl.pin_sources = NULL;
}
}
@@ -358,15 +358,15 @@ p11_kit_pin_request (const char *pin_source, P11KitUri *pin_uri,
/* Find and ref the pin source data */
if (gl.pin_sources) {
- callbacks = hash_get (gl.pin_sources, pin_source);
+ callbacks = _p11_hash_get (gl.pin_sources, pin_source);
/* If we didn't find any snapshots try the global ones */
if (callbacks == NULL)
- callbacks = hash_get (gl.pin_sources, P11_KIT_PIN_FALLBACK);
+ callbacks = _p11_hash_get (gl.pin_sources, P11_KIT_PIN_FALLBACK);
if (callbacks != NULL) {
- snapshot = (PinCallback**)ptr_array_snapshot (callbacks);
- snapshot_count = ptr_array_count (callbacks);
+ snapshot = (PinCallback**)_p11_ptr_array_snapshot (callbacks);
+ snapshot_count = _p11_ptr_array_count (callbacks);
for (i = 0; i < snapshot_count; i++)
ref_pin_callback (snapshot[i]);
}
@@ -471,7 +471,7 @@ p11_kit_pin_file_callback (const char *pin_source,
for (;;) {
if (used + 256 > allocated) {
- buffer = xrealloc (buffer, used + 1024);
+ buffer = _p11_realloc (buffer, used + 1024);
if (buffer == NULL) {
error = ENOMEM;
break;
diff --git a/p11-kit/private.h b/p11-kit/private.h
index a8f46c5..d23c1e6 100644
--- a/p11-kit/private.h
+++ b/p11-kit/private.h
@@ -49,9 +49,9 @@ typedef struct {
#endif
} p11_local;
-#define _p11_lock() mutex_lock (&_p11_mutex);
+#define _p11_lock() _p11_mutex_lock (&_p11_mutex);
-#define _p11_unlock() mutex_unlock (&_p11_mutex);
+#define _p11_unlock() _p11_mutex_unlock (&_p11_mutex);
void _p11_message (const char* msg, ...);
diff --git a/p11-kit/proxy.c b/p11-kit/proxy.c
index ebb1309..d6e5006 100644
--- a/p11-kit/proxy.c
+++ b/p11-kit/proxy.c
@@ -147,7 +147,7 @@ map_session_to_real (CK_SESSION_HANDLE_PTR handle, Mapping *mapping, Session *se
rv = CKR_CRYPTOKI_NOT_INITIALIZED;
} else {
assert (gl.sessions);
- sess = hash_get (gl.sessions, handle);
+ sess = _p11_hash_get (gl.sessions, handle);
if (sess != NULL) {
*handle = sess->real_session;
rv = map_slot_unlocked (sess->wrap_slot, mapping);
@@ -177,7 +177,7 @@ finalize_mappings_unlocked (void)
gl.n_mappings = 0;
/* no more sessions */
- hash_free (gl.sessions);
+ _p11_hash_free (gl.sessions);
gl.sessions = NULL;
}
@@ -270,7 +270,7 @@ initialize_mappings_unlocked_reentrant (void)
break;
}
- mappings = xrealloc (mappings, sizeof (Mapping) * (n_mappings + count));
+ mappings = _p11_realloc (mappings, sizeof (Mapping) * (n_mappings + count));
if (!mappings) {
free (slots);
rv = CKR_HOST_MEMORY;
@@ -297,7 +297,7 @@ initialize_mappings_unlocked_reentrant (void)
assert (!gl.sessions);
gl.mappings = mappings;
gl.n_mappings = n_mappings;
- gl.sessions = hash_create (hash_ulongptr_hash, hash_ulongptr_equal, NULL, free);
+ gl.sessions = _p11_hash_create (_p11_hash_ulongptr_hash, _p11_hash_ulongptr_equal, NULL, free);
++gl.mappings_refs;
/* Any cleanup necessary for failure will happen at caller */
@@ -525,7 +525,7 @@ proxy_C_OpenSession (CK_SLOT_ID id, CK_FLAGS flags, CK_VOID_PTR user_data,
sess->wrap_slot = map.wrap_slot;
sess->real_session = *handle;
sess->wrap_session = ++gl.last_handle; /* TODO: Handle wrapping, and then collisions */
- hash_set (gl.sessions, &sess->wrap_session, sess);
+ _p11_hash_set (gl.sessions, &sess->wrap_session, sess);
*handle = sess->wrap_session;
}
@@ -552,7 +552,7 @@ proxy_C_CloseSession (CK_SESSION_HANDLE handle)
_p11_lock ();
if (gl.sessions)
- hash_remove (gl.sessions, &key);
+ _p11_hash_remove (gl.sessions, &key);
_p11_unlock ();
}
@@ -574,13 +574,13 @@ proxy_C_CloseAllSessions (CK_SLOT_ID id)
if (!gl.sessions) {
rv = CKR_CRYPTOKI_NOT_INITIALIZED;
} else {
- to_close = calloc (sizeof (CK_SESSION_HANDLE), hash_size (gl.sessions));
+ to_close = calloc (sizeof (CK_SESSION_HANDLE), _p11_hash_size (gl.sessions));
if (!to_close) {
rv = CKR_HOST_MEMORY;
} else {
- hash_iterate (gl.sessions, &iter);
+ _p11_hash_iterate (gl.sessions, &iter);
count = 0;
- while (hash_next (&iter, NULL, (void**)&sess)) {
+ while (_p11_hash_next (&iter, NULL, (void**)&sess)) {
if (sess->wrap_slot == id && to_close)
to_close[count++] = sess->wrap_session;
}
diff --git a/p11-kit/ptr-array.c b/p11-kit/ptr-array.c
index 6a5ac4f..f393641 100644
--- a/p11-kit/ptr-array.c
+++ b/p11-kit/ptr-array.c
@@ -45,7 +45,8 @@ struct ptr_array {
};
static int
-maybe_expand_array (ptr_array_t *array, unsigned int length)
+maybe_expand_array (ptr_array_t *array,
+ unsigned int length)
{
unsigned int new_allocated;
void **new_memory;
@@ -66,8 +67,8 @@ maybe_expand_array (ptr_array_t *array, unsigned int length)
return 1;
}
-ptr_array_t*
-ptr_array_create (ptr_array_destroy_func destroy_func)
+ptr_array_t *
+_p11_ptr_array_create (ptr_array_destroy_func destroy_func)
{
ptr_array_t *array;
@@ -76,7 +77,7 @@ ptr_array_create (ptr_array_destroy_func destroy_func)
return NULL;
if (!maybe_expand_array (array, 2)) {
- ptr_array_free (array);
+ _p11_ptr_array_free (array);
return NULL;
}
@@ -85,7 +86,7 @@ ptr_array_create (ptr_array_destroy_func destroy_func)
}
void
-ptr_array_free (ptr_array_t *array)
+_p11_ptr_array_free (ptr_array_t *array)
{
unsigned int i;
@@ -102,13 +103,14 @@ ptr_array_free (ptr_array_t *array)
}
unsigned int
-ptr_array_count (ptr_array_t *array)
+_p11_ptr_array_count (ptr_array_t *array)
{
return array->length;
}
int
-ptr_array_add (ptr_array_t *array, void *value)
+_p11_ptr_array_add (ptr_array_t *array,
+ void *value)
{
if (!maybe_expand_array (array, array->length + 1))
return 0;
@@ -119,7 +121,8 @@ ptr_array_add (ptr_array_t *array, void *value)
}
void
-ptr_array_remove (ptr_array_t *array, unsigned int index)
+_p11_ptr_array_remove (ptr_array_t *array,
+ unsigned int index)
{
if (array->destroy)
(array->destroy) (array->memory[index]);
@@ -128,14 +131,15 @@ ptr_array_remove (ptr_array_t *array, unsigned int index)
array->length--;
}
-void*
-ptr_array_at (ptr_array_t *array, unsigned int index)
+void *
+_p11_ptr_array_at (ptr_array_t *array,
+ unsigned int index)
{
return array->memory[index];
}
-void**
-ptr_array_snapshot (ptr_array_t *array)
+void **
+_p11_ptr_array_snapshot (ptr_array_t *array)
{
void **snapshot;
size_t bytes;
diff --git a/p11-kit/ptr-array.h b/p11-kit/ptr-array.h
index acd894d..ba7ec87 100644
--- a/p11-kit/ptr-array.h
+++ b/p11-kit/ptr-array.h
@@ -41,21 +41,21 @@ typedef struct ptr_array ptr_array_t;
typedef void (*ptr_array_destroy_func) (void *data);
-ptr_array_t* ptr_array_create (ptr_array_destroy_func destroy_func);
+ptr_array_t* _p11_ptr_array_create (ptr_array_destroy_func destroy_func);
-void ptr_array_free (ptr_array_t *array);
+void _p11_ptr_array_free (ptr_array_t *array);
-unsigned int ptr_array_count (ptr_array_t *array);
+unsigned int _p11_ptr_array_count (ptr_array_t *array);
-int ptr_array_add (ptr_array_t *array,
+int _p11_ptr_array_add (ptr_array_t *array,
void *value);
-void ptr_array_remove (ptr_array_t *array,
+void _p11_ptr_array_remove (ptr_array_t *array,
unsigned int index);
-void* ptr_array_at (ptr_array_t *array,
+void* _p11_ptr_array_at (ptr_array_t *array,
unsigned int index);
-void** ptr_array_snapshot (ptr_array_t *array);
+void** _p11_ptr_array_snapshot (ptr_array_t *array);
#endif /* __PTR_ARRAY_H__ */
diff --git a/p11-kit/uri.c b/p11-kit/uri.c
index bd057d5..e9989c8 100644
--- a/p11-kit/uri.c
+++ b/p11-kit/uri.c
@@ -806,7 +806,7 @@ format_raw_string (char **string, size_t *length, int *is_first,
namelen = strlen (name);
vallen = strlen (value);
- *string = xrealloc (*string, *length + namelen + vallen + 3);
+ *string = _p11_realloc (*string, *length + namelen + vallen + 3);
if (!*string)
return 0;
diff --git a/p11-kit/util.c b/p11-kit/util.c
index eab0b13..933365d 100644
--- a/p11-kit/util.c
+++ b/p11-kit/util.c
@@ -72,7 +72,7 @@ pthread_once_t _p11_once;
static int print_messages = 1;
void*
-xrealloc (void *memory, size_t length)
+_p11_realloc (void *memory, size_t length)
{
void *allocated = realloc (memory, length);
if (!allocated)
@@ -268,8 +268,8 @@ _p11_library_get_thread_local (void)
void
_p11_library_init (void)
{
- debug_init ();
- mutex_init (&_p11_mutex);
+ _p11_debug_init ();
+ _p11_mutex_init (&_p11_mutex);
pthread_key_create (&thread_local, free);
}
@@ -277,7 +277,7 @@ void
_p11_library_uninit (void)
{
pthread_key_delete (thread_local);
- mutex_uninit (&_p11_mutex);
+ _p11_mutex_uninit (&_p11_mutex);
}
#endif /* OS_UNIX */
@@ -309,7 +309,7 @@ void
_p11_library_init (void)
{
debug_init ();
- mutex_init (&_p11_mutex);
+ _p11_mutex_init (&_p11_mutex);
thread_local = TlsAlloc ();
}
@@ -332,7 +332,7 @@ _p11_library_uninit (void)
free_tls_value (data);
TlsFree (thread_local);
}
- mutex_uninit (&_p11_mutex);
+ _p11_mutex_uninit (&_p11_mutex);
}
BOOL WINAPI
diff --git a/p11-kit/util.h b/p11-kit/util.h
index 2e005c7..36c8c24 100644
--- a/p11-kit/util.h
+++ b/p11-kit/util.h
@@ -39,6 +39,6 @@
#include <sys/types.h>
-void* xrealloc (void *memory, size_t length);
+void* _p11_realloc (void *memory, size_t length);
#endif /* __UTIL_H__ */
diff --git a/tests/conf-test.c b/tests/conf-test.c
index 58cb2f4..b86ffa7 100644
--- a/tests/conf-test.c
+++ b/tests/conf-test.c
@@ -53,19 +53,19 @@ test_parse_conf_1 (CuTest *tc)
map = _p11_conf_parse_file (SRCDIR "/files/test-1.conf", 0);
CuAssertPtrNotNull (tc, map);
- value = hash_get (map, "key1");
+ value = _p11_hash_get (map, "key1");
CuAssertStrEquals (tc, "value1", value);
- value = hash_get (map, "with-colon");
+ value = _p11_hash_get (map, "with-colon");
CuAssertStrEquals (tc, "value-of-colon", value);
- value = hash_get (map, "with-whitespace");
+ value = _p11_hash_get (map, "with-whitespace");
CuAssertStrEquals (tc, "value-with-whitespace", value);
- value = hash_get (map, "embedded-comment");
+ value = _p11_hash_get (map, "embedded-comment");
CuAssertStrEquals (tc, "this is # not a comment", value);
- hash_free (map);
+ _p11_hash_free (map);
}
static void
@@ -76,9 +76,9 @@ test_parse_ignore_missing (CuTest *tc)
map = _p11_conf_parse_file (SRCDIR "/files/non-existant.conf", CONF_IGNORE_MISSING);
CuAssertPtrNotNull (tc, map);
- CuAssertIntEquals (tc, 0, hash_size (map));
+ CuAssertIntEquals (tc, 0, _p11_hash_size (map));
CuAssertPtrEquals (tc, NULL, (void*)p11_kit_message ());
- hash_free (map);
+ _p11_hash_free (map);
}
static void
@@ -97,25 +97,25 @@ test_merge_defaults (CuTest *tc)
hashmap *values;
hashmap *defaults;
- values = hash_create (hash_string_hash, hash_string_equal, free, free);
- defaults = hash_create (hash_string_hash, hash_string_equal, free, free);
+ values = _p11_hash_create (_p11_hash_string_hash, _p11_hash_string_equal, free, free);
+ defaults = _p11_hash_create (_p11_hash_string_hash, _p11_hash_string_equal, free, free);
- hash_set (values, strdup ("one"), strdup ("real1"));
- hash_set (values, strdup ("two"), strdup ("real2"));
+ _p11_hash_set (values, strdup ("one"), strdup ("real1"));
+ _p11_hash_set (values, strdup ("two"), strdup ("real2"));
- hash_set (defaults, strdup ("two"), strdup ("default2"));
- hash_set (defaults, strdup ("three"), strdup ("default3"));
+ _p11_hash_set (defaults, strdup ("two"), strdup ("default2"));
+ _p11_hash_set (defaults, strdup ("three"), strdup ("default3"));
if (_p11_conf_merge_defaults (values, defaults) < 0)
CuFail (tc, "should not be reached");
- hash_free (defaults);
+ _p11_hash_free (defaults);
- CuAssertStrEquals (tc, hash_get (values, "one"), "real1");
- CuAssertStrEquals (tc, hash_get (values, "two"), "real2");
- CuAssertStrEquals (tc, hash_get (values, "three"), "default3");
+ CuAssertStrEquals (tc, _p11_hash_get (values, "one"), "real1");
+ CuAssertStrEquals (tc, _p11_hash_get (values, "two"), "real2");
+ CuAssertStrEquals (tc, _p11_hash_get (values, "three"), "default3");
- hash_free (values);
+ _p11_hash_free (values);
}
static void
@@ -133,11 +133,11 @@ test_load_globals_merge (CuTest *tc)
CuAssertStrEquals (tc, NULL, p11_kit_message ());
CuAssertIntEquals (tc, CONF_USER_MERGE, user_mode);
- CuAssertStrEquals (tc, hash_get (config, "key1"), "system1");
- CuAssertStrEquals (tc, hash_get (config, "key2"), "user2");
- CuAssertStrEquals (tc, hash_get (config, "key3"), "user3");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "key1"), "system1");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "key2"), "user2");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "key3"), "user3");
- hash_free (config);
+ _p11_hash_free (config);
}
static void
@@ -155,11 +155,11 @@ test_load_globals_no_user (CuTest *tc)
CuAssertStrEquals (tc, NULL, p11_kit_message ());
CuAssertIntEquals (tc, CONF_USER_NONE, user_mode);
- CuAssertStrEquals (tc, hash_get (config, "key1"), "system1");
- CuAssertStrEquals (tc, hash_get (config, "key2"), "system2");
- CuAssertStrEquals (tc, hash_get (config, "key3"), "system3");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "key1"), "system1");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "key2"), "system2");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "key3"), "system3");
- hash_free (config);
+ _p11_hash_free (config);
}
static void
@@ -177,11 +177,11 @@ test_load_globals_user_sets_only (CuTest *tc)
CuAssertStrEquals (tc, NULL, p11_kit_message ());
CuAssertIntEquals (tc, CONF_USER_ONLY, user_mode);
- CuAssertStrEquals (tc, hash_get (config, "key1"), NULL);
- CuAssertStrEquals (tc, hash_get (config, "key2"), "user2");
- CuAssertStrEquals (tc, hash_get (config, "key3"), "user3");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "key1"), NULL);
+ CuAssertStrEquals (tc, _p11_hash_get (config, "key2"), "user2");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "key3"), "user3");
- hash_free (config);
+ _p11_hash_free (config);
}
static void
@@ -199,11 +199,11 @@ test_load_globals_system_sets_only (CuTest *tc)
CuAssertStrEquals (tc, NULL, p11_kit_message ());
CuAssertIntEquals (tc, CONF_USER_ONLY, user_mode);
- CuAssertStrEquals (tc, hash_get (config, "key1"), NULL);
- CuAssertStrEquals (tc, hash_get (config, "key2"), "user2");
- CuAssertStrEquals (tc, hash_get (config, "key3"), "user3");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "key1"), NULL);
+ CuAssertStrEquals (tc, _p11_hash_get (config, "key2"), "user2");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "key3"), "user3");
- hash_free (config);
+ _p11_hash_free (config);
}
static void
@@ -223,7 +223,7 @@ test_load_globals_system_sets_invalid (CuTest *tc)
CuAssertIntEquals (tc, EINVAL, error);
CuAssertPtrNotNull (tc, p11_kit_message ());
- hash_free (config);
+ _p11_hash_free (config);
}
static void
@@ -243,7 +243,7 @@ test_load_globals_user_sets_invalid (CuTest *tc)
CuAssertIntEquals (tc, EINVAL, error);
CuAssertPtrNotNull (tc, p11_kit_message ());
- hash_free (config);
+ _p11_hash_free (config);
}
static void
@@ -260,22 +260,22 @@ test_load_modules_merge (CuTest *tc)
CuAssertPtrNotNull (tc, configs);
CuAssertStrEquals (tc, NULL, p11_kit_message ());
- config = hash_get (configs, "one");
+ config = _p11_hash_get (configs, "one");
CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, hash_get (config, "module"), "/path/to/module-one");
- CuAssertStrEquals (tc, hash_get (config, "setting"), "user1");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "/path/to/module-one");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "setting"), "user1");
- config = hash_get (configs, "two");
+ config = _p11_hash_get (configs, "two");
CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, hash_get (config, "module"), "/path/to/module-two");
- CuAssertStrEquals (tc, hash_get (config, "setting"), "system2");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "/path/to/module-two");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "setting"), "system2");
- config = hash_get (configs, "three");
+ config = _p11_hash_get (configs, "three");
CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, hash_get (config, "module"), "/path/to/module-three");
- CuAssertStrEquals (tc, hash_get (config, "setting"), "user3");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "/path/to/module-three");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "setting"), "user3");
- hash_free (configs);
+ _p11_hash_free (configs);
}
static void
@@ -292,20 +292,20 @@ test_load_modules_user_none (CuTest *tc)
CuAssertPtrNotNull (tc, configs);
CuAssertStrEquals (tc, NULL, p11_kit_message ());
- config = hash_get (configs, "one");
+ config = _p11_hash_get (configs, "one");
CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, hash_get (config, "module"), "/path/to/module-one");
- CuAssertStrEquals (tc, hash_get (config, "setting"), "system1");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "/path/to/module-one");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "setting"), "system1");
- config = hash_get (configs, "two");
+ config = _p11_hash_get (configs, "two");
CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, hash_get (config, "module"), "/path/to/module-two");
- CuAssertStrEquals (tc, hash_get (config, "setting"), "system2");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "/path/to/module-two");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "setting"), "system2");
- config = hash_get (configs, "three");
+ config = _p11_hash_get (configs, "three");
CuAssertPtrEquals (tc, NULL, config);
- hash_free (configs);
+ _p11_hash_free (configs);
}
static void
@@ -322,20 +322,20 @@ test_load_modules_user_only (CuTest *tc)
CuAssertPtrNotNull (tc, configs);
CuAssertStrEquals (tc, NULL, p11_kit_message ());
- config = hash_get (configs, "one");
+ config = _p11_hash_get (configs, "one");
CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, hash_get (config, "module"), NULL);
- CuAssertStrEquals (tc, hash_get (config, "setting"), "user1");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "module"), NULL);
+ CuAssertStrEquals (tc, _p11_hash_get (config, "setting"), "user1");
- config = hash_get (configs, "two");
+ config = _p11_hash_get (configs, "two");
CuAssertPtrEquals (tc, NULL, config);
- config = hash_get (configs, "three");
+ config = _p11_hash_get (configs, "three");
CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, hash_get (config, "module"), "/path/to/module-three");
- CuAssertStrEquals (tc, hash_get (config, "setting"), "user3");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "/path/to/module-three");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "setting"), "user3");
- hash_free (configs);
+ _p11_hash_free (configs);
}
static void
@@ -352,20 +352,20 @@ test_load_modules_no_user (CuTest *tc)
CuAssertPtrNotNull (tc, configs);
CuAssertStrEquals (tc, NULL, p11_kit_message ());
- config = hash_get (configs, "one");
+ config = _p11_hash_get (configs, "one");
CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, hash_get (config, "module"), "/path/to/module-one");
- CuAssertStrEquals (tc, hash_get (config, "setting"), "system1");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "/path/to/module-one");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "setting"), "system1");
- config = hash_get (configs, "two");
+ config = _p11_hash_get (configs, "two");
CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, hash_get (config, "module"), "/path/to/module-two");
- CuAssertStrEquals (tc, hash_get (config, "setting"), "system2");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "/path/to/module-two");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "setting"), "system2");
- config = hash_get (configs, "three");
+ config = _p11_hash_get (configs, "three");
CuAssertPtrEquals (tc, NULL, config);
- hash_free (configs);
+ _p11_hash_free (configs);
}
int
diff --git a/tests/hash-test.c b/tests/hash-test.c
index 73edeab..b8fc69f 100644
--- a/tests/hash-test.c
+++ b/tests/hash-test.c
@@ -42,19 +42,19 @@
#include "hashmap.h"
static void
-test_hash_create (CuTest *tc)
+test__p11_hash_create (CuTest *tc)
{
hashmap *map;
- map = hash_create (hash_direct_hash, hash_direct_equal, NULL, NULL);
+ map = _p11_hash_create (_p11_hash_direct_hash, _p11_hash_direct_equal, NULL, NULL);
CuAssertPtrNotNull (tc, map);
- hash_free (map);
+ _p11_hash_free (map);
}
static void
-test_hash_free_null (CuTest *tc)
+test__p11_hash_free_null (CuTest *tc)
{
- hash_free (NULL);
+ _p11_hash_free (NULL);
}
static void
@@ -72,24 +72,24 @@ destroy_value (void *data)
}
static void
-test_hash_free_destroys (CuTest *tc)
+test__p11_hash_free_destroys (CuTest *tc)
{
hashmap *map;
int key = 0;
int value = 0;
- map = hash_create (hash_direct_hash, hash_direct_equal, destroy_key, destroy_value);
+ map = _p11_hash_create (_p11_hash_direct_hash, _p11_hash_direct_equal, destroy_key, destroy_value);
CuAssertPtrNotNull (tc, map);
- if (!hash_set (map, &key, &value))
+ if (!_p11_hash_set (map, &key, &value))
CuFail (tc, "should not be reached");
- hash_free (map);
+ _p11_hash_free (map);
CuAssertIntEquals (tc, 1, key);
CuAssertIntEquals (tc, 2, value);
}
static void
-test_hash_iterate (CuTest *tc)
+test__p11_hash_iterate (CuTest *tc)
{
hashmap *map;
hashiter iter;
@@ -99,42 +99,42 @@ test_hash_iterate (CuTest *tc)
void *pvalue;
int ret;
- map = hash_create (hash_direct_hash, hash_direct_equal, NULL, NULL);
+ map = _p11_hash_create (_p11_hash_direct_hash, _p11_hash_direct_equal, NULL, NULL);
CuAssertPtrNotNull (tc, map);
- if (!hash_set (map, &key, &value))
+ if (!_p11_hash_set (map, &key, &value))
CuFail (tc, "should not be reached");
- hash_iterate (map, &iter);
+ _p11_hash_iterate (map, &iter);
- ret = hash_next (&iter, &pkey, &pvalue);
+ ret = _p11_hash_next (&iter, &pkey, &pvalue);
CuAssertIntEquals (tc, 1, ret);
CuAssertPtrEquals (tc, pkey, &key);
CuAssertPtrEquals (tc, pvalue, &value);
- ret = hash_next (&iter, &pkey, &pvalue);
+ ret = _p11_hash_next (&iter, &pkey, &pvalue);
CuAssertIntEquals (tc, 0, ret);
- hash_free (map);
+ _p11_hash_free (map);
}
static void
-test_hash_set_get (CuTest *tc)
+test__p11_hash_set_get (CuTest *tc)
{
char *key = "KEY";
char *value = "VALUE";
char *check;
hashmap *map;
- map = hash_create (hash_string_hash, hash_string_equal, NULL, NULL);
- hash_set (map, key, value);
- check = hash_get (map, key);
+ map = _p11_hash_create (_p11_hash_string_hash, _p11_hash_string_equal, NULL, NULL);
+ _p11_hash_set (map, key, value);
+ check = _p11_hash_get (map, key);
CuAssertPtrEquals (tc, check, value);
- hash_free (map);
+ _p11_hash_free (map);
}
static void
-test_hash_set_get_remove (CuTest *tc)
+test__p11_hash_set_get_remove (CuTest *tc)
{
char *key = "KEY";
char *value = "VALUE";
@@ -142,63 +142,63 @@ test_hash_set_get_remove (CuTest *tc)
hashmap *map;
int ret;
- map = hash_create (hash_string_hash, hash_string_equal, NULL, NULL);
+ map = _p11_hash_create (_p11_hash_string_hash, _p11_hash_string_equal, NULL, NULL);
- if (!hash_set (map, key, value))
+ if (!_p11_hash_set (map, key, value))
CuFail (tc, "should not be reached");
- check = hash_get (map, key);
+ check = _p11_hash_get (map, key);
CuAssertPtrEquals (tc, check, value);
- ret = hash_remove (map, key);
+ ret = _p11_hash_remove (map, key);
CuAssertIntEquals (tc, ret, 1);
- ret = hash_remove (map, key);
+ ret = _p11_hash_remove (map, key);
CuAssertIntEquals (tc, ret, 0);
- check = hash_get (map, key);
+ check = _p11_hash_get (map, key);
CuAssert (tc, "should be null", check == NULL);
- hash_free (map);
+ _p11_hash_free (map);
}
static void
-test_hash_set_get_clear (CuTest *tc)
+test__p11_hash_set_get_clear (CuTest *tc)
{
char *key = "KEY";
char *value = "VALUE";
char *check;
hashmap *map;
- map = hash_create (hash_direct_hash, hash_direct_equal, NULL, NULL);
+ map = _p11_hash_create (_p11_hash_direct_hash, _p11_hash_direct_equal, NULL, NULL);
- if (!hash_set (map, key, value))
+ if (!_p11_hash_set (map, key, value))
CuFail (tc, "should not be reached");
- check = hash_get (map, key);
+ check = _p11_hash_get (map, key);
CuAssertPtrEquals (tc, check, value);
- hash_clear (map);
+ _p11_hash_clear (map);
- check = hash_get (map, key);
+ check = _p11_hash_get (map, key);
CuAssert (tc, "should be null", check == NULL);
- hash_free (map);
+ _p11_hash_free (map);
}
static void
-test_hash_remove_destroys (CuTest *tc)
+test__p11_hash_remove_destroys (CuTest *tc)
{
hashmap *map;
int key = 0;
int value = 0;
int ret;
- map = hash_create (hash_direct_hash, hash_direct_equal, destroy_key, destroy_value);
+ map = _p11_hash_create (_p11_hash_direct_hash, _p11_hash_direct_equal, destroy_key, destroy_value);
CuAssertPtrNotNull (tc, map);
- if (!hash_set (map, &key, &value))
+ if (!_p11_hash_set (map, &key, &value))
CuFail (tc, "should not be reached");
- ret = hash_remove (map, &key);
+ ret = _p11_hash_remove (map, &key);
CuAssertIntEquals (tc, ret, 1);
CuAssertIntEquals (tc, 1, key);
CuAssertIntEquals (tc, 2, value);
@@ -207,7 +207,7 @@ test_hash_remove_destroys (CuTest *tc)
key = 0;
value = 0;
- ret = hash_remove (map, &key);
+ ret = _p11_hash_remove (map, &key);
CuAssertIntEquals (tc, ret, 0);
CuAssertIntEquals (tc, 0, key);
CuAssertIntEquals (tc, 0, value);
@@ -216,14 +216,14 @@ test_hash_remove_destroys (CuTest *tc)
key = 0;
value = 0;
- hash_free (map);
+ _p11_hash_free (map);
CuAssertIntEquals (tc, 0, key);
CuAssertIntEquals (tc, 0, value);
}
static void
-test_hash_set_destroys (CuTest *tc)
+test__p11_hash_set_destroys (CuTest *tc)
{
hashmap *map;
int key = 0;
@@ -231,12 +231,12 @@ test_hash_set_destroys (CuTest *tc)
int value2 = 0;
int ret;
- map = hash_create (hash_direct_hash, hash_direct_equal, destroy_key, destroy_value);
+ map = _p11_hash_create (_p11_hash_direct_hash, _p11_hash_direct_equal, destroy_key, destroy_value);
CuAssertPtrNotNull (tc, map);
- if (!hash_set (map, &key, &value))
+ if (!_p11_hash_set (map, &key, &value))
CuFail (tc, "should not be reached");
- ret = hash_set (map, &key, &value2);
+ ret = _p11_hash_set (map, &key, &value2);
CuAssertIntEquals (tc, ret, 1);
CuAssertIntEquals (tc, 0, key);
CuAssertIntEquals (tc, 2, value);
@@ -246,7 +246,7 @@ test_hash_set_destroys (CuTest *tc)
value = 0;
value2 = 0;
- hash_free (map);
+ _p11_hash_free (map);
CuAssertIntEquals (tc, 1, key);
CuAssertIntEquals (tc, 0, value);
@@ -255,18 +255,18 @@ test_hash_set_destroys (CuTest *tc)
static void
-test_hash_clear_destroys (CuTest *tc)
+test__p11_hash_clear_destroys (CuTest *tc)
{
hashmap *map;
int key = 0;
int value = 0;
- map = hash_create (hash_direct_hash, hash_direct_equal, destroy_key, destroy_value);
+ map = _p11_hash_create (_p11_hash_direct_hash, _p11_hash_direct_equal, destroy_key, destroy_value);
CuAssertPtrNotNull (tc, map);
- if (!hash_set (map, &key, &value))
+ if (!_p11_hash_set (map, &key, &value))
CuFail (tc, "should not be reached");
- hash_clear (map);
+ _p11_hash_clear (map);
CuAssertIntEquals (tc, 1, key);
CuAssertIntEquals (tc, 2, value);
@@ -274,7 +274,7 @@ test_hash_clear_destroys (CuTest *tc)
key = 0;
value = 0;
- hash_clear (map);
+ _p11_hash_clear (map);
CuAssertIntEquals (tc, 0, key);
CuAssertIntEquals (tc, 0, value);
@@ -282,7 +282,7 @@ test_hash_clear_destroys (CuTest *tc)
key = 0;
value = 0;
- hash_free (map);
+ _p11_hash_free (map);
CuAssertIntEquals (tc, 0, key);
CuAssertIntEquals (tc, 0, value);
@@ -302,23 +302,23 @@ test_hash_add_check_lots_and_collisions (CuTest *tc)
int *value;
int i;
- map = hash_create (test_hash_intptr_with_collisions,
- hash_intptr_equal, NULL, free);
+ map = _p11_hash_create (test_hash_intptr_with_collisions,
+ _p11_hash_intptr_equal, NULL, free);
for (i = 0; i < 20000; ++i) {
value = malloc (sizeof (int));
*value = i;
- if (!hash_set (map, value, value))
+ if (!_p11_hash_set (map, value, value))
CuFail (tc, "should not be reached");
}
for (i = 0; i < 20000; ++i) {
- value = hash_get (map, &i);
+ value = _p11_hash_get (map, &i);
CuAssertPtrNotNull (tc, value);
CuAssertIntEquals (tc, i, *value);
}
- hash_free (map);
+ _p11_hash_free (map);
}
static void
@@ -328,28 +328,28 @@ test_hash_count (CuTest *tc)
int *value;
int i, ret;
- map = hash_create (hash_intptr_hash, hash_intptr_equal, NULL, free);
+ map = _p11_hash_create (_p11_hash_intptr_hash, _p11_hash_intptr_equal, NULL, free);
- CuAssertIntEquals (tc, 0, hash_size (map));
+ CuAssertIntEquals (tc, 0, _p11_hash_size (map));
for (i = 0; i < 20000; ++i) {
value = malloc (sizeof (int));
*value = i;
- if (!hash_set (map, value, value))
+ if (!_p11_hash_set (map, value, value))
CuFail (tc, "should not be reached");
- CuAssertIntEquals (tc, i + 1, hash_size (map));
+ CuAssertIntEquals (tc, i + 1, _p11_hash_size (map));
}
for (i = 0; i < 20000; ++i) {
- ret = hash_remove (map, &i);
+ ret = _p11_hash_remove (map, &i);
CuAssertIntEquals (tc, 1, ret);
- CuAssertIntEquals (tc, 20000 - (i + 1), hash_size (map));
+ CuAssertIntEquals (tc, 20000 - (i + 1), _p11_hash_size (map));
}
- hash_clear (map);
- CuAssertIntEquals (tc, 0, hash_size (map));
+ _p11_hash_clear (map);
+ CuAssertIntEquals (tc, 0, _p11_hash_size (map));
- hash_free (map);
+ _p11_hash_free (map);
}
static void
@@ -359,22 +359,22 @@ test_hash_ulongptr (CuTest *tc)
unsigned long *value;
unsigned long i;
- map = hash_create (hash_ulongptr_hash, hash_ulongptr_equal, NULL, free);
+ map = _p11_hash_create (_p11_hash_ulongptr_hash, _p11_hash_ulongptr_equal, NULL, free);
for (i = 0; i < 20000; ++i) {
value = malloc (sizeof (unsigned long));
*value = i;
- if (!hash_set (map, value, value))
+ if (!_p11_hash_set (map, value, value))
CuFail (tc, "should not be reached");
}
for (i = 0; i < 20000; ++i) {
- value = hash_get (map, &i);
+ value = _p11_hash_get (map, &i);
CuAssertPtrNotNull (tc, value);
CuAssertIntEquals (tc, i, *value);
}
- hash_free (map);
+ _p11_hash_free (map);
}
int
@@ -384,16 +384,16 @@ main (void)
CuSuite* suite = CuSuiteNew ();
int ret;
- SUITE_ADD_TEST (suite, test_hash_create);
- SUITE_ADD_TEST (suite, test_hash_set_get);
- SUITE_ADD_TEST (suite, test_hash_set_get_remove);
- SUITE_ADD_TEST (suite, test_hash_remove_destroys);
- SUITE_ADD_TEST (suite, test_hash_set_get_clear);
- SUITE_ADD_TEST (suite, test_hash_set_destroys);
- SUITE_ADD_TEST (suite, test_hash_clear_destroys);
- SUITE_ADD_TEST (suite, test_hash_free_null);
- SUITE_ADD_TEST (suite, test_hash_free_destroys);
- SUITE_ADD_TEST (suite, test_hash_iterate);
+ SUITE_ADD_TEST (suite, test__p11_hash_create);
+ SUITE_ADD_TEST (suite, test__p11_hash_set_get);
+ SUITE_ADD_TEST (suite, test__p11_hash_set_get_remove);
+ SUITE_ADD_TEST (suite, test__p11_hash_remove_destroys);
+ SUITE_ADD_TEST (suite, test__p11_hash_set_get_clear);
+ SUITE_ADD_TEST (suite, test__p11_hash_set_destroys);
+ SUITE_ADD_TEST (suite, test__p11_hash_clear_destroys);
+ SUITE_ADD_TEST (suite, test__p11_hash_free_null);
+ SUITE_ADD_TEST (suite, test__p11_hash_free_destroys);
+ SUITE_ADD_TEST (suite, test__p11_hash_iterate);
SUITE_ADD_TEST (suite, test_hash_add_check_lots_and_collisions);
SUITE_ADD_TEST (suite, test_hash_count);
SUITE_ADD_TEST (suite, test_hash_ulongptr);
diff --git a/tests/mock-module.c b/tests/mock-module.c
index 1b7822a..9cb1831 100644
--- a/tests/mock-module.c
+++ b/tests/mock-module.c
@@ -97,7 +97,7 @@ mock_C_Initialize (CK_VOID_PTR init_args)
debug (("C_Initialize: enter"));
- mutex_lock (&init_mutex);
+ _p11_mutex_lock (&init_mutex);
if (init_args != NULL) {
int supplied_ok;
@@ -148,7 +148,7 @@ done:
pkcs11_initialized_pid = 0;
}
- mutex_unlock (&init_mutex);
+ _p11_mutex_unlock (&init_mutex);
debug (("C_Initialize: %d", ret));
return ret;
@@ -161,13 +161,13 @@ mock_C_Finalize (CK_VOID_PTR reserved)
return_val_if_fail (pkcs11_initialized != 0, CKR_CRYPTOKI_NOT_INITIALIZED);
return_val_if_fail (reserved == NULL, CKR_ARGUMENTS_BAD);
- mutex_lock (&init_mutex);
+ _p11_mutex_lock (&init_mutex);
/* This should stop all other calls in */
pkcs11_initialized = 0;
pkcs11_initialized_pid = 0;
- mutex_unlock (&init_mutex);
+ _p11_mutex_unlock (&init_mutex);
debug (("C_Finalize: %d", CKR_OK));
return CKR_OK;
@@ -890,5 +890,5 @@ CK_FUNCTION_LIST mock_module_no_slots = {
void
mock_module_init (void)
{
- mutex_init (&init_mutex);
+ _p11_mutex_init (&init_mutex);
}
diff --git a/tests/ptr-array-test.c b/tests/ptr-array-test.c
index ff9959d..4eca468 100644
--- a/tests/ptr-array-test.c
+++ b/tests/ptr-array-test.c
@@ -42,19 +42,19 @@
#include "ptr-array.h"
static void
-test_ptr_array_create (CuTest *tc)
+test__p11_ptr_array_create (CuTest *tc)
{
ptr_array_t *array;
- array = ptr_array_create (NULL);
+ array = _p11_ptr_array_create (NULL);
CuAssertPtrNotNull (tc, array);
- ptr_array_free (array);
+ _p11_ptr_array_free (array);
}
static void
-test_ptr_array_free_null (CuTest *tc)
+test__p11_ptr_array_free_null (CuTest *tc)
{
- ptr_array_free (NULL);
+ _p11_ptr_array_free (NULL);
}
static void
@@ -65,23 +65,23 @@ destroy_value (void *data)
}
static void
-test_ptr_array_free_destroys (CuTest *tc)
+test__p11_ptr_array_free_destroys (CuTest *tc)
{
ptr_array_t *array;
int value = 0;
- array = ptr_array_create (destroy_value);
+ array = _p11_ptr_array_create (destroy_value);
CuAssertPtrNotNull (tc, array);
- if (!ptr_array_add (array, &value))
+ if (!_p11_ptr_array_add (array, &value))
CuFail (tc, "should not be reached");
- ptr_array_free (array);
+ _p11_ptr_array_free (array);
CuAssertIntEquals (tc, 2, value);
}
#if 0
static void
-test_hash_iterate (CuTest *tc)
+test__p11_hash_iterate (CuTest *tc)
{
hash_t *ht;
hash_iter_t hi;
@@ -91,134 +91,134 @@ test_hash_iterate (CuTest *tc)
void *pvalue;
int ret;
- ht = hash_create (hash_direct_hash, hash_direct_equal, NULL, NULL);
+ ht = _p11_hash_create (_p11_hash_direct_hash, _p11_hash_direct_equal, NULL, NULL);
CuAssertPtrNotNull (tc, ht);
- if (!hash_set (ht, &key, &value))
+ if (!_p11_hash_set (ht, &key, &value))
CuFail (tc, "should not be reached");
- hash_iterate (ht, &hi);
+ _p11_hash_iterate (ht, &hi);
- ret = hash_next (&hi, &pkey, &pvalue);
+ ret = _p11_hash_next (&hi, &pkey, &pvalue);
CuAssertIntEquals (tc, 1, ret);
CuAssertPtrEquals (tc, pkey, &key);
CuAssertPtrEquals (tc, pvalue, &value);
- ret = hash_next (&hi, &pkey, &pvalue);
+ ret = _p11_hash_next (&hi, &pkey, &pvalue);
CuAssertIntEquals (tc, 0, ret);
- hash_free (ht);
+ _p11_hash_free (ht);
}
#endif
static void
-test_ptr_array_add (CuTest *tc)
+test__p11_ptr_array_add (CuTest *tc)
{
char *value = "VALUE";
char *check;
ptr_array_t *array;
- array = ptr_array_create (NULL);
- if (!ptr_array_add (array, value))
+ array = _p11_ptr_array_create (NULL);
+ if (!_p11_ptr_array_add (array, value))
CuFail (tc, "should not be reached");
- CuAssertIntEquals (tc, 1, ptr_array_count (array));
+ CuAssertIntEquals (tc, 1, _p11_ptr_array_count (array));
- check = ptr_array_at (array, 0);
+ check = _p11_ptr_array_at (array, 0);
CuAssertPtrEquals (tc, check, value);
- ptr_array_free (array);
+ _p11_ptr_array_free (array);
}
static void
-test_ptr_array_add_remove (CuTest *tc)
+test__p11_ptr_array_add_remove (CuTest *tc)
{
char *value = "VALUE";
char *check;
ptr_array_t *array;
- array = ptr_array_create (NULL);
- if (!ptr_array_add (array, value))
+ array = _p11_ptr_array_create (NULL);
+ if (!_p11_ptr_array_add (array, value))
CuFail (tc, "should not be reached");
- CuAssertIntEquals (tc, 1, ptr_array_count (array));
+ CuAssertIntEquals (tc, 1, _p11_ptr_array_count (array));
- check = ptr_array_at (array, 0);
+ check = _p11_ptr_array_at (array, 0);
CuAssertPtrEquals (tc, check, value);
- ptr_array_remove (array, 0);
+ _p11_ptr_array_remove (array, 0);
- CuAssertIntEquals (tc, 0, ptr_array_count (array));
+ CuAssertIntEquals (tc, 0, _p11_ptr_array_count (array));
- ptr_array_free (array);
+ _p11_ptr_array_free (array);
}
static void
-test_ptr_array_remove_destroys (CuTest *tc)
+test__p11_ptr_array_remove_destroys (CuTest *tc)
{
ptr_array_t *array;
int value = 0;
- array = ptr_array_create (destroy_value);
- if (!ptr_array_add (array, &value))
+ array = _p11_ptr_array_create (destroy_value);
+ if (!_p11_ptr_array_add (array, &value))
CuFail (tc, "should not be reached");
- ptr_array_remove (array, 0);
+ _p11_ptr_array_remove (array, 0);
CuAssertIntEquals (tc, 2, value);
/* should not be destroyed again */
value = 0;
- ptr_array_free (array);
+ _p11_ptr_array_free (array);
CuAssertIntEquals (tc, 0, value);
}
static void
-test_ptr_array_remove_and_count (CuTest *tc)
+test__p11_ptr_array_remove_and_count (CuTest *tc)
{
ptr_array_t *array;
int *value;
int i;
- array = ptr_array_create (free);
+ array = _p11_ptr_array_create (free);
- CuAssertIntEquals (tc, 0, ptr_array_count (array));
+ CuAssertIntEquals (tc, 0, _p11_ptr_array_count (array));
for (i = 0; i < 20000; ++i) {
value = malloc (sizeof (int));
*value = i;
- if (!ptr_array_add (array, value))
+ if (!_p11_ptr_array_add (array, value))
CuFail (tc, "should not be reached");
- CuAssertIntEquals (tc, i + 1, ptr_array_count (array));
+ CuAssertIntEquals (tc, i + 1, _p11_ptr_array_count (array));
}
for (i = 10; i < 20000; ++i) {
- ptr_array_remove (array, 10);
- CuAssertIntEquals (tc, 20010 - (i + 1), ptr_array_count (array));
+ _p11_ptr_array_remove (array, 10);
+ CuAssertIntEquals (tc, 20010 - (i + 1), _p11_ptr_array_count (array));
}
- CuAssertIntEquals (tc, 10, ptr_array_count (array));
+ CuAssertIntEquals (tc, 10, _p11_ptr_array_count (array));
- ptr_array_free (array);
+ _p11_ptr_array_free (array);
}
static void
-test_ptr_array_snapshot (CuTest *tc)
+test__p11_ptr_array_snapshot (CuTest *tc)
{
ptr_array_t *array;
void **snapshot;
- array = ptr_array_create (NULL);
+ array = _p11_ptr_array_create (NULL);
- ptr_array_add (array, "1");
- ptr_array_add (array, "2");
- ptr_array_add (array, "3");
- ptr_array_add (array, "4");
- CuAssertIntEquals (tc, 4, ptr_array_count (array));
+ _p11_ptr_array_add (array, "1");
+ _p11_ptr_array_add (array, "2");
+ _p11_ptr_array_add (array, "3");
+ _p11_ptr_array_add (array, "4");
+ CuAssertIntEquals (tc, 4, _p11_ptr_array_count (array));
- snapshot = ptr_array_snapshot (array);
+ snapshot = _p11_ptr_array_snapshot (array);
CuAssertStrEquals (tc, "1", snapshot[0]);
CuAssertStrEquals (tc, "2", snapshot[1]);
@@ -226,7 +226,7 @@ test_ptr_array_snapshot (CuTest *tc)
CuAssertStrEquals (tc, "4", snapshot[3]);
free (snapshot);
- ptr_array_free (array);
+ _p11_ptr_array_free (array);
}
int
@@ -236,14 +236,14 @@ main (void)
CuSuite* suite = CuSuiteNew ();
int ret;
- SUITE_ADD_TEST (suite, test_ptr_array_create);
- SUITE_ADD_TEST (suite, test_ptr_array_add);
- SUITE_ADD_TEST (suite, test_ptr_array_add_remove);
- SUITE_ADD_TEST (suite, test_ptr_array_remove_destroys);
- SUITE_ADD_TEST (suite, test_ptr_array_remove_and_count);
- SUITE_ADD_TEST (suite, test_ptr_array_free_null);
- SUITE_ADD_TEST (suite, test_ptr_array_free_destroys);
- SUITE_ADD_TEST (suite, test_ptr_array_snapshot);
+ SUITE_ADD_TEST (suite, test__p11_ptr_array_create);
+ SUITE_ADD_TEST (suite, test__p11_ptr_array_add);
+ SUITE_ADD_TEST (suite, test__p11_ptr_array_add_remove);
+ SUITE_ADD_TEST (suite, test__p11_ptr_array_remove_destroys);
+ SUITE_ADD_TEST (suite, test__p11_ptr_array_remove_and_count);
+ SUITE_ADD_TEST (suite, test__p11_ptr_array_free_null);
+ SUITE_ADD_TEST (suite, test__p11_ptr_array_free_destroys);
+ SUITE_ADD_TEST (suite, test__p11_ptr_array_snapshot);
CuSuiteRun (suite);
CuSuiteSummary (suite, output);
diff --git a/tests/test-init.c b/tests/test-init.c
index 8367f10..af07860 100644
--- a/tests/test-init.c
+++ b/tests/test-init.c
@@ -135,11 +135,11 @@ static CK_RV
mock_C_Initialize__threaded_race (CK_VOID_PTR init_args)
{
/* Atomically increment value */
- mutex_lock (&race_mutex);
+ _p11_mutex_lock (&race_mutex);
initialization_count += 1;
- mutex_unlock (&race_mutex);
+ _p11_mutex_unlock (&race_mutex);
- sleep_ms (100);
+ _p11_sleep_ms (100);
return CKR_OK;
}
@@ -147,11 +147,11 @@ static CK_RV
mock_C_Finalize__threaded_race (CK_VOID_PTR reserved)
{
/* Atomically increment value */
- mutex_lock (&race_mutex);
+ _p11_mutex_lock (&race_mutex);
finalization_count += 1;
- mutex_unlock (&race_mutex);
+ _p11_mutex_unlock (&race_mutex);
- sleep_ms (100);
+ _p11_sleep_ms (100);
return CKR_OK;}
static void *
@@ -195,25 +195,25 @@ test_threaded_initialization (CuTest *tc)
finalization_count = 0;
for (i = 0; i < num_threads; i++) {
- ret = thread_create (&threads[i], initialization_thread, tc);
+ ret = _p11_thread_create (&threads[i], initialization_thread, tc);
CuAssertIntEquals (tc, 0, ret);
CuAssertTrue (tc, threads[i] != 0);
}
for (i = 0; i < num_threads; i++) {
- ret = thread_join (threads[i]);
+ ret = _p11_thread_join (threads[i]);
CuAssertIntEquals (tc, 0, ret);
threads[i] = 0;
}
for (i = 0; i < num_threads; i++) {
- ret = thread_create (&threads[i], finalization_thread, tc);
+ ret = _p11_thread_create (&threads[i], finalization_thread, tc);
CuAssertIntEquals (tc, 0, ret);
CuAssertTrue (tc, threads[i] != 0);
}
for (i = 0; i < num_threads; i++) {
- ret = thread_join (threads[i]);
+ ret = _p11_thread_join (threads[i]);
CuAssertIntEquals (tc, 0, ret);
threads[i] = 0;
}
@@ -230,7 +230,7 @@ main (void)
CuSuite* suite = CuSuiteNew ();
int ret;
- mutex_init (&race_mutex);
+ _p11_mutex_init (&race_mutex);
mock_module_init ();
_p11_library_init ();
diff --git a/tests/uri-test.c b/tests/uri-test.c
index 0e8c718..0d57835 100644
--- a/tests/uri-test.c
+++ b/tests/uri-test.c
@@ -40,7 +40,8 @@
#include <stdio.h>
#include <stdlib.h>
-#include "uri.h"
+#include "p11-kit/uri.h"
+#include "p11-kit/private.h"
static int
is_module_empty (P11KitUri *uri)
@@ -1159,6 +1160,8 @@ main (void)
CuSuite* suite = CuSuiteNew ();
int ret;
+ _p11_library_init ();
+
SUITE_ADD_TEST (suite, test_uri_parse);
SUITE_ADD_TEST (suite, test_uri_parse_bad_scheme);
SUITE_ADD_TEST (suite, test_uri_parse_with_label);