Wed Apr 6 11:30:11 2011

Asterisk developer's documentation


ssl.c File Reference

Common OpenSSL support code. More...

#include "asterisk.h"
#include <openssl/ssl.h>
#include <openssl/err.h>
#include "asterisk/_private.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"

Go to the source code of this file.

Functions

int ast_ssl_init (void)
static void ssl_lock (int mode, int n, const char *file, int line)
static unsigned long ssl_threadid (void)

Variables

static ast_mutex_tssl_locks
static int ssl_num_locks


Detailed Description

Common OpenSSL support code.

Author:
Russell Bryant <russell@digium.com>

Definition in file ssl.c.


Function Documentation

int ast_ssl_init ( void   ) 

Provided by ssl.c

Definition at line 73 of file ssl.c.

References ast_calloc, ast_mutex_init, ssl_lock(), ssl_locks, and ssl_threadid().

Referenced by main().

00074 {
00075 #ifdef HAVE_OPENSSL
00076    unsigned int i;
00077 
00078    SSL_library_init();
00079    SSL_load_error_strings();
00080    ERR_load_crypto_strings();
00081    ERR_load_BIO_strings();
00082    OpenSSL_add_all_algorithms();
00083 
00084    /* Make OpenSSL thread-safe. */
00085 
00086    CRYPTO_set_id_callback(ssl_threadid);
00087 
00088    ssl_num_locks = CRYPTO_num_locks();
00089    if (!(ssl_locks = ast_calloc(ssl_num_locks, sizeof(ssl_locks[0])))) {
00090       return -1;
00091    }
00092    for (i = 0; i < ssl_num_locks; i++) {
00093       ast_mutex_init(&ssl_locks[i]);
00094    }
00095    CRYPTO_set_locking_callback(ssl_lock);
00096 
00097 #endif /* HAVE_OPENSSL */
00098    return 0;
00099 }

static void ssl_lock ( int  mode,
int  n,
const char *  file,
int  line 
) [static]

Definition at line 51 of file ssl.c.

References ast_log(), ast_mutex_lock, ast_mutex_unlock, LOG_ERROR, and ssl_locks.

Referenced by ast_ssl_init().

00052 {
00053    if (n < 0 || n >= ssl_num_locks) {
00054       ast_log(LOG_ERROR, "OpenSSL is full of LIES!!! - "
00055             "ssl_num_locks '%d' - n '%d'\n",
00056             ssl_num_locks, n);
00057       return;
00058    }
00059 
00060    if (mode & CRYPTO_LOCK) {
00061       ast_mutex_lock(&ssl_locks[n]);
00062    } else {
00063       ast_mutex_unlock(&ssl_locks[n]);
00064    }
00065 }

static unsigned long ssl_threadid ( void   )  [static]

Definition at line 46 of file ssl.c.

Referenced by ast_ssl_init().

00047 {
00048    return (unsigned long)pthread_self();
00049 }


Variable Documentation

ast_mutex_t* ssl_locks [static]

Definition at line 42 of file ssl.c.

Referenced by ast_ssl_init(), and ssl_lock().

int ssl_num_locks [static]

Definition at line 44 of file ssl.c.


Generated on Wed Apr 6 11:30:11 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7