2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/util/ssl-init.h"
18 #include "hphp/util/mutex.h"
19 #include "hphp/util/process.h"
20 #include <openssl/crypto.h>
23 ///////////////////////////////////////////////////////////////////////////////
25 static Mutex
*s_locks
= nullptr;
27 static unsigned long callback_thread_id() {
28 return (unsigned long)Process::GetThreadId();
31 static void callback_locking(int mode
, int type
, const char *file
, int line
) {
32 if (mode
& CRYPTO_LOCK
) {
35 s_locks
[type
].unlock();
39 static bool s_isSSLInited
= false;
41 class SSLUnitializer
{
47 static SSLUnitializer s_ssl_uninitializer
;
49 void SSLInit::Init() {
50 assert(!s_isSSLInited
);
51 s_locks
= new Mutex
[CRYPTO_num_locks()];
52 CRYPTO_set_id_callback((unsigned long (*)())callback_thread_id
);
53 CRYPTO_set_locking_callback(
54 (void (*)(int mode
, int type
, const char *file
, int line
))
59 bool SSLInit::IsInited() {
63 ///////////////////////////////////////////////////////////////////////////////