user no longer has to call CyaSSL_Init

pull/1/head
toddouska 2012-12-06 09:26:59 -08:00
parent ca7e5d2463
commit 5ecca5a89d
1 changed files with 34 additions and 27 deletions

View File

@ -103,12 +103,21 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
#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* ctx = NULL;
CYASSL_ENTER("CYASSL_CTX_new");
if (initRefCount == 0)
CyaSSL_Init(); /* user no longer forced to call Init themselves */
if (method == NULL)
return ctx;
@ -899,6 +908,31 @@ int AddCA(CYASSL_CERT_MANAGER* cm, buffer der, int type, int verify)
#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
/* 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 */
/* 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)
{