summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/compat.c (renamed from tools/compat.c)0
-rw-r--r--common/compat.h (renamed from tools/compat.h)0
-rw-r--r--p11-kit/Makefile.am3
-rw-r--r--p11-kit/compat.c114
-rw-r--r--p11-kit/compat.h149
-rw-r--r--p11-kit/conf.c2
-rw-r--r--p11-kit/debug.c1
-rw-r--r--p11-kit/private.h2
-rw-r--r--p11-kit/util.c66
-rw-r--r--p11-kit/util.h111
-rw-r--r--tests/mock-module.c2
-rw-r--r--tests/test-init.c2
-rw-r--r--tools/Makefile.am3
-rw-r--r--tools/p11-kit.c4
14 files changed, 186 insertions, 273 deletions
diff --git a/tools/compat.c b/common/compat.c
index 93ba77c..93ba77c 100644
--- a/tools/compat.c
+++ b/common/compat.c
diff --git a/tools/compat.h b/common/compat.h
index 1562964..1562964 100644
--- a/tools/compat.h
+++ b/common/compat.h
diff --git a/p11-kit/Makefile.am b/p11-kit/Makefile.am
index 8605c15..b855fb7 100644
--- a/p11-kit/Makefile.am
+++ b/p11-kit/Makefile.am
@@ -15,7 +15,6 @@ inc_HEADERS = \
MODULE_SRCS = \
util.c util.h \
- compat.c compat.h \
conf.c conf.h \
debug.c debug.h \
hashmap.c hashmap.h \
@@ -66,7 +65,7 @@ libp11_kit_testable_la_CFLAGS = \
$(NULL)
libp11_kit_compat_la_SOURCES = \
- compat.c compat.h
+ util.c util.h
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = p11-kit-1.pc
diff --git a/p11-kit/compat.c b/p11-kit/compat.c
deleted file mode 100644
index db0b0ce..0000000
--- a/p11-kit/compat.c
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (c) 2011 Collabora Ltd.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- * Author: Stef Walter <stefw@collabora.co.uk>
- */
-
-#include "config.h"
-
-#include "compat.h"
-#include "private.h"
-
-#include <assert.h>
-
-#ifdef OS_UNIX
-
-void
-_p11_mutex_init (mutex_t *mutex)
-{
- pthread_mutexattr_t attr;
- int ret;
-
- pthread_mutexattr_init (&attr);
- pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
- ret = pthread_mutex_init (mutex, &attr);
- assert (ret == 0);
- pthread_mutexattr_destroy (&attr);
-}
-
-#endif /* OS_UNIX */
-
-#ifdef OS_WIN32
-
-const char *
-_p11_module_error (void)
-{
- DWORD code = GetLastError();
- p11_local *local;
- LPVOID msg_buf;
-
- local = _p11_library_get_thread_local ();
-
- FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, code,
- MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPSTR)&msg_buf, 0, NULL);
-
- if (local->last_error)
- LocalFree (local->last_error);
- local->last_error = msg_buf;
-
- return msg_buf;
-}
-
-int
-_p11_thread_create (thread_t *thread,
- thread_routine routine,
- void *arg)
-{
- assert (thread);
-
- *thread = CreateThread (NULL, 0,
- (LPTHREAD_START_ROUTINE)routine,
- arg, 0, NULL);
-
- if (*thread == NULL)
- return GetLastError ();
-
- return 0;
-}
-
-int
-_p11_thread_join (thread_t thread)
-{
- DWORD res;
-
- res = WaitForSingleObject (thread, INFINITE);
- if (res == WAIT_FAILED)
- return GetLastError ();
-
- CloseHandle (thread);
- return 0;
-}
-
-#endif /* OS_WIN32 */
diff --git a/p11-kit/compat.h b/p11-kit/compat.h
deleted file mode 100644
index 4b839b2..0000000
--- a/p11-kit/compat.h
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Copyright (c) 2011 Collabora Ltd.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- * Author: Stef Walter <stefw@collabora.co.uk>
- */
-
-#ifndef __COMPAT_H__
-#define __COMPAT_H__
-
-#include "config.h"
-
-/* -----------------------------------------------------------------------------
- * WIN32
- */
-
-#ifdef OS_WIN32
-
-#ifndef _WIN32_WINNT
-#define _WIN32_WINNT 0x500
-#endif
-
-#ifndef _WIN32_IE
-#define _WIN32_IE 0x500
-#endif
-
-#define WIN32_LEAN_AND_MEAN 1
-#include <windows.h>
-
-/* Oh ... my ... god */
-#undef CreateMutex
-
-typedef CRITICAL_SECTION mutex_t;
-
-typedef HANDLE thread_t;
-
-#define _p11_mutex_init(m) \
- (InitializeCriticalSection (m))
-#define _p11_mutex_lock(m) \
- (EnterCriticalSection (m))
-#define _p11_mutex_unlock(m) \
- (LeaveCriticalSection (m))
-#define _p11_mutex_uninit(m) \
- (DeleteCriticalSection (m))
-
-typedef void * (*thread_routine) (void *arg);
-
-int _p11_thread_create (thread_t *thread, thread_routine, void *arg);
-
-int _p11_thread_join (thread_t thread);
-
-#define _p11_thread_self() \
- (GetCurrentThread ())
-
-typedef HMODULE dl_module_t;
-
-#define _p11_module_open(f) \
- (LoadLibrary (f))
-#define _p11_module_close(d) \
- (FreeLibrary (d))
-#define _p11_module_symbol(d, s) \
- ((void *)GetProcAddress ((d), (s)))
-
-const char * _p11_module_error (void);
-
-#define _p11_sleep_ms(ms) \
- (Sleep (ms))
-
-#endif /* OS_WIN32 */
-
-/* ----------------------------------------------------------------------------
- * UNIX
- */
-
-#ifdef OS_UNIX
-
-#include <pthread.h>
-#include <dlfcn.h>
-#include <time.h>
-
-typedef pthread_mutex_t mutex_t;
-
-void _p11_mutex_init (mutex_t *mutex);
-
-#define _p11_mutex_lock(m) \
- (pthread_mutex_lock (m))
-#define _p11_mutex_unlock(m) \
- (pthread_mutex_unlock (m))
-#define _p11_mutex_uninit(m) \
- (pthread_mutex_destroy(m))
-
-typedef pthread_t thread_t;
-
-typedef void * (*thread_routine) (void *arg);
-
-#define _p11_thread_create(t, r, a) \
- (pthread_create ((t), NULL, (r), (a)))
-#define _p11_thread_join(t) \
- (pthread_join ((t), NULL))
-#define _p11_thread_self(m) \
- (pthread_self ())
-
-typedef void * dl_module_t;
-
-#define _p11_module_open(f) \
- (dlopen ((f), RTLD_LOCAL | RTLD_NOW))
-#define _p11_module_close(d) \
- (dlclose(d))
-#define _p11_module_error() \
- (dlerror ())
-#define _p11_module_symbol(d, s) \
- (dlsym ((d), (s)))
-
-#define _p11_sleep_ms(ms) \
- do { int _ms = (ms); \
- struct timespec _ts = { _ms / 1000, (_ms % 1000) * 1000 * 1000 }; \
- nanosleep (&_ts, NULL); \
- } while(0)
-
-#endif /* OS_UNIX */
-
-#endif /* __COMPAT_H__ */
diff --git a/p11-kit/conf.c b/p11-kit/conf.c
index 6b82d53..5c09ff5 100644
--- a/p11-kit/conf.c
+++ b/p11-kit/conf.c
@@ -37,11 +37,11 @@
#include "config.h"
-#include "compat.h"
#include "conf.h"
#define DEBUG_FLAG DEBUG_CONF
#include "debug.h"
#include "private.h"
+#include "util.h"
#include <sys/param.h>
#include <sys/stat.h>
diff --git a/p11-kit/debug.c b/p11-kit/debug.c
index 6616459..37095be 100644
--- a/p11-kit/debug.c
+++ b/p11-kit/debug.c
@@ -36,7 +36,6 @@
#include "config.h"
-#include "compat.h"
#include "debug.h"
#include <assert.h>
diff --git a/p11-kit/private.h b/p11-kit/private.h
index 36acb7e..da9fbae 100644
--- a/p11-kit/private.h
+++ b/p11-kit/private.h
@@ -36,7 +36,7 @@
#define __P11_KIT_PRIVATE_H__
#include "pkcs11.h"
-#include "compat.h"
+#include "util.h"
extern mutex_t _p11_mutex;
diff --git a/p11-kit/util.c b/p11-kit/util.c
index 97a113b..63183b1 100644
--- a/p11-kit/util.c
+++ b/p11-kit/util.c
@@ -303,6 +303,19 @@ _p11_library_uninit (void)
_p11_mutex_uninit (&_p11_mutex);
}
+void
+_p11_mutex_init (mutex_t *mutex)
+{
+ pthread_mutexattr_t attr;
+ int ret;
+
+ pthread_mutexattr_init (&attr);
+ pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
+ ret = pthread_mutex_init (mutex, &attr);
+ assert (ret == 0);
+ pthread_mutexattr_destroy (&attr);
+}
+
#if defined (HAVE_PROGRAM_INVOCATION_SHORT_NAME) && !HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
extern char *program_invocation_short_name;
#endif
@@ -398,6 +411,59 @@ _p11_library_uninit (void)
_p11_mutex_uninit (&_p11_mutex);
}
+const char *
+_p11_module_error (void)
+{
+ DWORD code = GetLastError();
+ p11_local *local;
+ LPVOID msg_buf;
+
+ local = _p11_library_get_thread_local ();
+
+ FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, code,
+ MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPSTR)&msg_buf, 0, NULL);
+
+ if (local->last_error)
+ LocalFree (local->last_error);
+ local->last_error = msg_buf;
+
+ return msg_buf;
+}
+
+int
+_p11_thread_create (thread_t *thread,
+ thread_routine routine,
+ void *arg)
+{
+ assert (thread);
+
+ *thread = CreateThread (NULL, 0,
+ (LPTHREAD_START_ROUTINE)routine,
+ arg, 0, NULL);
+
+ if (*thread == NULL)
+ return GetLastError ();
+
+ return 0;
+}
+
+int
+_p11_thread_join (thread_t thread)
+{
+ DWORD res;
+
+ res = WaitForSingleObject (thread, INFINITE);
+ if (res == WAIT_FAILED)
+ return GetLastError ();
+
+ CloseHandle (thread);
+ return 0;
+}
+
BOOL WINAPI
DllMain (HINSTANCE instance,
DWORD reason,
diff --git a/p11-kit/util.h b/p11-kit/util.h
index 36c8c24..aa7ed19 100644
--- a/p11-kit/util.h
+++ b/p11-kit/util.h
@@ -37,8 +37,119 @@
#ifndef __UTIL_H__
#define __UTIL_H__
+#include "config.h"
+
#include <sys/types.h>
void* _p11_realloc (void *memory, size_t length);
+/* -----------------------------------------------------------------------------
+ * WIN32
+ */
+
+#ifdef OS_WIN32
+
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x500
+#endif
+
+#ifndef _WIN32_IE
+#define _WIN32_IE 0x500
+#endif
+
+#define WIN32_LEAN_AND_MEAN 1
+#include <windows.h>
+
+/* Oh ... my ... god */
+#undef CreateMutex
+
+typedef CRITICAL_SECTION mutex_t;
+
+typedef HANDLE thread_t;
+
+#define _p11_mutex_init(m) \
+ (InitializeCriticalSection (m))
+#define _p11_mutex_lock(m) \
+ (EnterCriticalSection (m))
+#define _p11_mutex_unlock(m) \
+ (LeaveCriticalSection (m))
+#define _p11_mutex_uninit(m) \
+ (DeleteCriticalSection (m))
+
+typedef void * (*thread_routine) (void *arg);
+
+int _p11_thread_create (thread_t *thread, thread_routine, void *arg);
+
+int _p11_thread_join (thread_t thread);
+
+#define _p11_thread_self() \
+ (GetCurrentThread ())
+
+typedef HMODULE dl_module_t;
+
+#define _p11_module_open(f) \
+ (LoadLibrary (f))
+#define _p11_module_close(d) \
+ (FreeLibrary (d))
+#define _p11_module_symbol(d, s) \
+ ((void *)GetProcAddress ((d), (s)))
+
+const char * _p11_module_error (void);
+
+#define _p11_sleep_ms(ms) \
+ (Sleep (ms))
+
+#endif /* OS_WIN32 */
+
+/* ----------------------------------------------------------------------------
+ * UNIX
+ */
+
+#ifdef OS_UNIX
+
+#include <pthread.h>
+#include <dlfcn.h>
+#include <time.h>
+
+typedef pthread_mutex_t mutex_t;
+
+void _p11_mutex_init (mutex_t *mutex);
+
+#define _p11_mutex_lock(m) \
+ (pthread_mutex_lock (m))
+#define _p11_mutex_unlock(m) \
+ (pthread_mutex_unlock (m))
+#define _p11_mutex_uninit(m) \
+ (pthread_mutex_destroy(m))
+
+typedef pthread_t thread_t;
+
+typedef void * (*thread_routine) (void *arg);
+
+#define _p11_thread_create(t, r, a) \
+ (pthread_create ((t), NULL, (r), (a)))
+#define _p11_thread_join(t) \
+ (pthread_join ((t), NULL))
+#define _p11_thread_self(m) \
+ (pthread_self ())
+
+typedef void * dl_module_t;
+
+#define _p11_module_open(f) \
+ (dlopen ((f), RTLD_LOCAL | RTLD_NOW))
+#define _p11_module_close(d) \
+ (dlclose(d))
+#define _p11_module_error() \
+ (dlerror ())
+#define _p11_module_symbol(d, s) \
+ (dlsym ((d), (s)))
+
+#define _p11_sleep_ms(ms) \
+ do { int _ms = (ms); \
+ struct timespec _ts = { _ms / 1000, (_ms % 1000) * 1000 * 1000 }; \
+ nanosleep (&_ts, NULL); \
+ } while(0)
+
+#endif /* OS_UNIX */
+
#endif /* __UTIL_H__ */
diff --git a/tests/mock-module.c b/tests/mock-module.c
index 9cb1831..36515d0 100644
--- a/tests/mock-module.c
+++ b/tests/mock-module.c
@@ -38,7 +38,7 @@
#include "pkcs11.h"
#include "mock-module.h"
-#include "p11-kit/compat.h"
+#include "p11-kit/util.h"
#include <stdarg.h>
#include <stdio.h>
diff --git a/tests/test-init.c b/tests/test-init.c
index 10790a8..be970aa 100644
--- a/tests/test-init.c
+++ b/tests/test-init.c
@@ -44,8 +44,8 @@
#include <time.h>
#include <unistd.h>
-#include "p11-kit/compat.h"
#include "p11-kit/p11-kit.h"
+#include "p11-kit/util.h"
#include "mock-module.h"
diff --git a/tools/Makefile.am b/tools/Makefile.am
index e38d1a4..cec6bfc 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -8,7 +8,8 @@ bin_PROGRAMS = \
p11-kit
p11_kit_SOURCES = \
- compat.c compat.h \
+ $(top_srcdir)/common/compat.c \
+ $(top_srcdir)/common/compat.h \
p11-kit.c
p11_kit_LDADD = \
diff --git a/tools/p11-kit.c b/tools/p11-kit.c
index f63779e..d4b0759 100644
--- a/tools/p11-kit.c
+++ b/tools/p11-kit.c
@@ -34,7 +34,7 @@
#include "config.h"
-#include "compat.h"
+#include "common/compat.h"
#include <assert.h>
#include <ctype.h>
@@ -146,7 +146,7 @@ print_token_info (CK_FUNCTION_LIST_PTR module, CK_SLOT_ID slot_id)
X(CKF_LOGIN_REQUIRED, "login-required");
X(CKF_USER_PIN_INITIALIZED, "user-pin-initialized");
X(CKF_RESTORE_KEY_NOT_NEEDED, "restore-key-not-needed");
- X(CKF_CLOCK_ON_TOKEN, "clock-on-tokne");
+ X(CKF_CLOCK_ON_TOKEN, "clock-on-token");
X(CKF_PROTECTED_AUTHENTICATION_PATH, "protected-authentication-path");
X(CKF_DUAL_CRYPTO_OPERATIONS, "dual-crypto-operations");
X(CKF_TOKEN_INITIALIZED, "token-initialized");