forked from wolfSSL/wolfssl
user no longer has to call CyaSSL_Init
This commit is contained in:
61
src/ssl.c
61
src/ssl.c
@ -103,12 +103,21 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* prevent multiple mutex initializations */
|
||||||
|
static volatile int initRefCount = 0;
|
||||||
|
static CyaSSL_Mutex count_mutex; /* init ref count mutex */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CYASSL_CTX* CyaSSL_CTX_new(CYASSL_METHOD* method)
|
CYASSL_CTX* CyaSSL_CTX_new(CYASSL_METHOD* method)
|
||||||
{
|
{
|
||||||
CYASSL_CTX* ctx = NULL;
|
CYASSL_CTX* ctx = NULL;
|
||||||
|
|
||||||
CYASSL_ENTER("CYASSL_CTX_new");
|
CYASSL_ENTER("CYASSL_CTX_new");
|
||||||
|
|
||||||
|
if (initRefCount == 0)
|
||||||
|
CyaSSL_Init(); /* user no longer forced to call Init themselves */
|
||||||
|
|
||||||
if (method == NULL)
|
if (method == NULL)
|
||||||
return ctx;
|
return ctx;
|
||||||
|
|
||||||
@ -899,6 +908,31 @@ int AddCA(CYASSL_CERT_MANAGER* cm, buffer der, int type, int verify)
|
|||||||
|
|
||||||
#endif /* NO_SESSION_CACHE */
|
#endif /* NO_SESSION_CACHE */
|
||||||
|
|
||||||
|
|
||||||
|
int CyaSSL_Init(void)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
CYASSL_ENTER("CyaSSL_Init");
|
||||||
|
|
||||||
|
if (initRefCount == 0) {
|
||||||
|
#ifndef NO_SESSION_CACHE
|
||||||
|
if (InitMutex(&session_mutex) != 0)
|
||||||
|
ret = BAD_MUTEX_ERROR;
|
||||||
|
#endif
|
||||||
|
if (InitMutex(&count_mutex) != 0)
|
||||||
|
ret = BAD_MUTEX_ERROR;
|
||||||
|
}
|
||||||
|
if (ret == 0) {
|
||||||
|
LockMutex(&count_mutex);
|
||||||
|
initRefCount++;
|
||||||
|
UnLockMutex(&count_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef NO_CERTS
|
#ifndef NO_CERTS
|
||||||
|
|
||||||
/* Remove PEM header/footer, convert to ASN1, store any encrypted data
|
/* Remove PEM header/footer, convert to ASN1, store any encrypted data
|
||||||
@ -2921,33 +2955,6 @@ int CyaSSL_dtls_got_timeout(CYASSL* ssl)
|
|||||||
|
|
||||||
#endif /* NO_CYASSL_SERVER */
|
#endif /* NO_CYASSL_SERVER */
|
||||||
|
|
||||||
/* prevent multiple mutex initializations */
|
|
||||||
static volatile int initRefCount = 0;
|
|
||||||
static CyaSSL_Mutex count_mutex; /* init ref count mutex */
|
|
||||||
|
|
||||||
int CyaSSL_Init(void)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
CYASSL_ENTER("CyaSSL_Init");
|
|
||||||
|
|
||||||
if (initRefCount == 0) {
|
|
||||||
#ifndef NO_SESSION_CACHE
|
|
||||||
if (InitMutex(&session_mutex) != 0)
|
|
||||||
ret = BAD_MUTEX_ERROR;
|
|
||||||
#endif
|
|
||||||
if (InitMutex(&count_mutex) != 0)
|
|
||||||
ret = BAD_MUTEX_ERROR;
|
|
||||||
}
|
|
||||||
if (ret == 0) {
|
|
||||||
LockMutex(&count_mutex);
|
|
||||||
initRefCount++;
|
|
||||||
UnLockMutex(&count_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int CyaSSL_Cleanup(void)
|
int CyaSSL_Cleanup(void)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user