Changed callbacks type
Этот коммит содержится в:
родитель
9f02a817ff
Коммит
b7af2b2959
@ -256,26 +256,9 @@ LIBSSH_API int ssh_set_callbacks(ssh_session session, ssh_callbacks cb);
|
|||||||
|
|
||||||
typedef int (*ssh_thread_callback) (void **lock);
|
typedef int (*ssh_thread_callback) (void **lock);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Type of the threading solution implemented behind
|
|
||||||
* these callbacks
|
|
||||||
*/
|
|
||||||
enum ssh_threads_type_e {
|
|
||||||
/** The thread callbacks do nothing */
|
|
||||||
ssh_threads_type_noop,
|
|
||||||
/** The thread callbacks use pthread */
|
|
||||||
ssh_threads_type_pthread,
|
|
||||||
/** The thread callbacks use win32 threads */
|
|
||||||
ssh_threads_type_win32,
|
|
||||||
/** The thread callbacks use pth */
|
|
||||||
ssh_threads_type_pth,
|
|
||||||
/** The thread callbacks are unknown or different */
|
|
||||||
ssh_threads_type_other
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef unsigned long (*ssh_thread_id_callback) (void);
|
typedef unsigned long (*ssh_thread_id_callback) (void);
|
||||||
struct ssh_threads_callbacks_struct {
|
struct ssh_threads_callbacks_struct {
|
||||||
enum ssh_threads_type_e type;
|
const char *type;
|
||||||
ssh_thread_callback mutex_init;
|
ssh_thread_callback mutex_init;
|
||||||
ssh_thread_callback mutex_destroy;
|
ssh_thread_callback mutex_destroy;
|
||||||
ssh_thread_callback mutex_lock;
|
ssh_thread_callback mutex_lock;
|
||||||
@ -298,7 +281,6 @@ LIBSSH_API int ssh_threads_set_callbacks(struct ssh_threads_callbacks_struct
|
|||||||
|
|
||||||
extern struct ssh_threads_callbacks_struct ssh_threads_pthread;
|
extern struct ssh_threads_callbacks_struct ssh_threads_pthread;
|
||||||
extern struct ssh_threads_callbacks_struct ssh_threads_noop;
|
extern struct ssh_threads_callbacks_struct ssh_threads_noop;
|
||||||
extern struct ssh_threads_callbacks_struct ssh_threads_native;
|
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -41,7 +41,7 @@ static unsigned long threads_id_noop (void){
|
|||||||
|
|
||||||
struct ssh_threads_callbacks_struct ssh_threads_noop =
|
struct ssh_threads_callbacks_struct ssh_threads_noop =
|
||||||
{
|
{
|
||||||
.type=ssh_threads_type_noop,
|
.type="threads_noop",
|
||||||
.mutex_init=threads_noop,
|
.mutex_init=threads_noop,
|
||||||
.mutex_destroy=threads_noop,
|
.mutex_destroy=threads_noop,
|
||||||
.mutex_lock=threads_noop,
|
.mutex_lock=threads_noop,
|
||||||
@ -60,7 +60,11 @@ static struct gcry_thread_cbs gcrypt_threads_callbacks;
|
|||||||
static int libgcrypt_thread_init(void){
|
static int libgcrypt_thread_init(void){
|
||||||
if(user_callbacks == NULL)
|
if(user_callbacks == NULL)
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
gcrypt_threads_callbacks.option= GCRY_THREAD_OPTION_VERSION << 8 || GCRY_THREAD_OPTION_USER;
|
if(user_callbacks == &ssh_threads_noop){
|
||||||
|
gcrypt_threads_callbacks.option= GCRY_THREAD_OPTION_VERSION << 8 || GCRY_THREAD_OPTION_DEFAULT;
|
||||||
|
} else {
|
||||||
|
gcrypt_threads_callbacks.option= GCRY_THREAD_OPTION_VERSION << 8 || GCRY_THREAD_OPTION_USER;
|
||||||
|
}
|
||||||
gcrypt_threads_callbacks.mutex_init=user_callbacks->mutex_init;
|
gcrypt_threads_callbacks.mutex_init=user_callbacks->mutex_init;
|
||||||
gcrypt_threads_callbacks.mutex_destroy=user_callbacks->mutex_destroy;
|
gcrypt_threads_callbacks.mutex_destroy=user_callbacks->mutex_destroy;
|
||||||
gcrypt_threads_callbacks.mutex_lock=user_callbacks->mutex_lock;
|
gcrypt_threads_callbacks.mutex_lock=user_callbacks->mutex_lock;
|
||||||
@ -87,6 +91,8 @@ static void libcrypto_lock_callback(int mode, int i, const char *file, int line)
|
|||||||
static int libcrypto_thread_init(){
|
static int libcrypto_thread_init(){
|
||||||
int n=CRYPTO_num_locks();
|
int n=CRYPTO_num_locks();
|
||||||
int i;
|
int i;
|
||||||
|
if(user_callbacks == &ssh_threads_noop)
|
||||||
|
return SSH_OK;
|
||||||
libcrypto_mutexes=malloc(sizeof(void *) * n);
|
libcrypto_mutexes=malloc(sizeof(void *) * n);
|
||||||
if (libcrypto_mutexes == NULL)
|
if (libcrypto_mutexes == NULL)
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
|
@ -80,7 +80,7 @@ static unsigned long ssh_pthread_thread_id (void){
|
|||||||
|
|
||||||
struct ssh_threads_callbacks_struct ssh_threads_pthread =
|
struct ssh_threads_callbacks_struct ssh_threads_pthread =
|
||||||
{
|
{
|
||||||
.type=ssh_threads_type_pthread,
|
.type="threads_pthread",
|
||||||
.mutex_init=ssh_pthread_mutex_init,
|
.mutex_init=ssh_pthread_mutex_init,
|
||||||
.mutex_destroy=ssh_pthread_mutex_destroy,
|
.mutex_destroy=ssh_pthread_mutex_destroy,
|
||||||
.mutex_lock=ssh_pthread_mutex_lock,
|
.mutex_lock=ssh_pthread_mutex_lock,
|
||||||
@ -88,16 +88,4 @@ struct ssh_threads_callbacks_struct ssh_threads_pthread =
|
|||||||
.thread_id=ssh_pthread_thread_id
|
.thread_id=ssh_pthread_thread_id
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef THREAD_NATIVE_PTHREAD
|
|
||||||
struct ssh_threads_callbacks_struct ssh_threads_native =
|
|
||||||
{
|
|
||||||
.type=ssh_threads_type_pthread,
|
|
||||||
.mutex_init=ssh_pthread_mutex_init,
|
|
||||||
.mutex_destroy=ssh_pthread_mutex_destroy,
|
|
||||||
.mutex_lock=ssh_pthread_mutex_lock,
|
|
||||||
.mutex_unlock=ssh_pthread_mutex_unlock,
|
|
||||||
.thread_id=ssh_pthread_thread_id
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* HAVE_PTHREAD */
|
#endif /* HAVE_PTHREAD */
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user