Fix namespace pollution.
This commit is contained in:
parent
9ea5b0625e
commit
d00283927f
17
src/global.c
17
src/global.c
@ -37,12 +37,12 @@
|
|||||||
|
|
||||||
#include "libssh2_priv.h"
|
#include "libssh2_priv.h"
|
||||||
|
|
||||||
int libssh2_initialized = 0;
|
static int _libssh2_initialized = 0;
|
||||||
int libssh2_init_flags = 0;
|
static int _libssh2_init_flags = 0;
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_init(int flags)
|
LIBSSH2_API int libssh2_init(int flags)
|
||||||
{
|
{
|
||||||
if (!(flags & LIBSSH2_INIT_NO_CRYPTO_INIT)) {
|
if (libssh2_initialized == 0 && !(flags & LIBSSH2_INIT_NO_CRYPTO_INIT)) {
|
||||||
libssh2_crypto_init();
|
libssh2_crypto_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,11 +57,18 @@ LIBSSH2_API void libssh2_exit()
|
|||||||
if (libssh2_initialized == 0)
|
if (libssh2_initialized == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
libssh2_initialized--;
|
||||||
|
|
||||||
if (!(libssh2_init_flags & LIBSSH2_INIT_NO_CRYPTO_INIT)) {
|
if (!(libssh2_init_flags & LIBSSH2_INIT_NO_CRYPTO_INIT)) {
|
||||||
libssh2_crypto_exit();
|
libssh2_crypto_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
libssh2_initialized--;
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_libssh2_init_if_needed (void)
|
||||||
|
{
|
||||||
|
if (_libssh2_initialized)
|
||||||
|
libssh2_init (0);
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (c) 2004-2008, Sara Golemon <sarag@libssh2.org>
|
/* Copyright (c) 2004-2008, 2010, Sara Golemon <sarag@libssh2.org>
|
||||||
* Copyright (c) 2009 by Daniel Stenberg
|
* Copyright (c) 2009 by Daniel Stenberg
|
||||||
* Copyright (c) 2010 Simon Josefsson
|
* Copyright (c) 2010 Simon Josefsson
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
@ -1200,6 +1200,8 @@ int _libssh2_pem_decode_sequence(unsigned char **data, unsigned int *datalen);
|
|||||||
int _libssh2_pem_decode_integer(unsigned char **data, unsigned int *datalen,
|
int _libssh2_pem_decode_integer(unsigned char **data, unsigned int *datalen,
|
||||||
unsigned char **i, unsigned int *ilen);
|
unsigned char **i, unsigned int *ilen);
|
||||||
|
|
||||||
|
/* global.c */
|
||||||
|
void _libssh2_init_if_needed (void);
|
||||||
|
|
||||||
/* Conveniance-macros to allow code like this;
|
/* Conveniance-macros to allow code like this;
|
||||||
|
|
||||||
@ -1247,6 +1249,4 @@ int _libssh2_pem_decode_integer(unsigned char **data, unsigned int *datalen,
|
|||||||
|
|
||||||
#define ARRAY_SIZE(a) (sizeof ((a)) / sizeof ((a)[0]))
|
#define ARRAY_SIZE(a) (sizeof ((a)) / sizeof ((a)[0]))
|
||||||
|
|
||||||
extern int libssh2_initialized;
|
|
||||||
|
|
||||||
#endif /* LIBSSH2_H */
|
#endif /* LIBSSH2_H */
|
||||||
|
@ -358,8 +358,7 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa,
|
|||||||
(pem_read_bio_func) &PEM_read_bio_RSAPrivateKey;
|
(pem_read_bio_func) &PEM_read_bio_RSAPrivateKey;
|
||||||
(void) session;
|
(void) session;
|
||||||
|
|
||||||
if (!libssh2_initialized)
|
_libssh2_init_if_needed ();
|
||||||
libssh2_init(0);
|
|
||||||
|
|
||||||
return read_private_key_from_file((void **) rsa, read_rsa,
|
return read_private_key_from_file((void **) rsa, read_rsa,
|
||||||
filename, passphrase);
|
filename, passphrase);
|
||||||
@ -375,8 +374,7 @@ _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa,
|
|||||||
(pem_read_bio_func) &PEM_read_bio_DSAPrivateKey;
|
(pem_read_bio_func) &PEM_read_bio_DSAPrivateKey;
|
||||||
(void) session;
|
(void) session;
|
||||||
|
|
||||||
if (!libssh2_initialized)
|
_libssh2_init_if_needed ();
|
||||||
libssh2_init(0);
|
|
||||||
|
|
||||||
return read_private_key_from_file((void **) dsa, read_dsa,
|
return read_private_key_from_file((void **) dsa, read_dsa,
|
||||||
filename, passphrase);
|
filename, passphrase);
|
||||||
|
@ -457,8 +457,7 @@ libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)),
|
|||||||
session->api_block_mode = 1; /* blocking API by default */
|
session->api_block_mode = 1; /* blocking API by default */
|
||||||
_libssh2_debug(session, LIBSSH2_TRACE_TRANS,
|
_libssh2_debug(session, LIBSSH2_TRACE_TRANS,
|
||||||
"New session resource allocated");
|
"New session resource allocated");
|
||||||
if (!libssh2_initialized)
|
_libssh2_init_if_needed ();
|
||||||
libssh2_init(0);
|
|
||||||
}
|
}
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user