+#ifdef HTTP_NEED_OPENSSL_TSL
+/* {{{ */
+static MUTEX_T *http_openssl_tsl = NULL;
+
+static void http_ssl_lock(int mode, int n, const char * file, int line)
+{
+ if (mode & CRYPTO_LOCK) {
+ tsrm_mutex_lock(http_openssl_tsl[n]);
+ } else {
+ tsrm_mutex_unlock(http_openssl_tsl[n]);
+ }
+}
+
+static ulong http_ssl_id(void)
+{
+ return (ulong) tsrm_thread_id();
+}
+
+static inline void http_ssl_init(void)
+{
+ int i, c = CRYPTO_num_locks();
+
+ http_openssl_tsl = malloc(c * sizeof(MUTEX_T));
+
+ for (i = 0; i < c; ++i) {
+ http_openssl_tsl[i] = tsrm_mutex_alloc();
+ }
+
+ CRYPTO_set_id_callback(http_ssl_id);
+ CRYPTO_set_locking_callback(http_ssl_lock);
+}
+
+static inline void http_ssl_cleanup(void)
+{
+ if (http_openssl_tsl) {
+ int i, c = CRYPTO_num_locks();
+
+ CRYPTO_set_id_callback(NULL);
+ CRYPTO_set_locking_callback(NULL);
+
+ for (i = 0; i < c; ++i) {
+ tsrm_mutex_free(http_openssl_tsl[i]);
+ }
+
+ free(http_openssl_tsl);
+ http_openssl_tsl = NULL;
+ }
+}
+#endif /* HTTP_NEED_OPENSSL_TSL */
+/* }}} */
+
+#ifdef HTTP_NEED_GNUTLS_TSL
+/* {{{ */
+static int http_ssl_mutex_create(void **m)
+{
+ if (*((MUTEX_T *) m) = tsrm_mutex_alloc()) {
+ return SUCCESS;
+ } else {
+ return FAILURE;
+ }
+}
+
+static int http_ssl_mutex_destroy(void **m)
+{
+ tsrm_mutex_free(*((MUTEX_T *) m));
+ return SUCCESS;
+}
+
+static int http_ssl_mutex_lock(void **m)
+{
+ return tsrm_mutex_lock(*((MUTEX_T *) m));
+}
+
+static int http_ssl_mutex_unlock(void **m)
+{
+ return tsrm_mutex_unlock(*((MUTEX_T *) m));
+}
+
+static struct gcry_thread_cbs http_gnutls_tsl = {
+ GCRY_THREAD_OPTIONS_USER,
+ NULL,
+ http_ssl_mutex_create,
+ http_ssl_mutex_destroy,
+ http_ssl_mutex_lock,
+ http_ssl_mutex_unlock
+};
+
+static inline void http_ssl_init(void)
+{
+ gcry_control(GCRYCTL_SET_THREAD_CBS, &http_gnutls_tsl);
+}
+
+static inline void http_ssl_cleanup(void)
+{
+ return;
+}
+#endif /* HTTP_NEED_GNUTLS_TSL */
+/* }}} */
+
+/* {{{ http_curl_defaults(CURL *) */
+static inline void _http_curl_defaults(CURL *ch)
+{
+ HTTP_CURL_OPT(URL, NULL);
+ HTTP_CURL_OPT(NOPROGRESS, 1);
+ HTTP_CURL_OPT(PROXY, NULL);
+ HTTP_CURL_OPT(PROXYPORT, 0);
+ HTTP_CURL_OPT(PROXYUSERPWD, NULL);
+#if LIBCURL_VERSION_NUM >= 0x070a07
+ HTTP_CURL_OPT(PROXYAUTH, 0);
+#endif
+ HTTP_CURL_OPT(INTERFACE, NULL);
+ HTTP_CURL_OPT(PORT, 0);
+ HTTP_CURL_OPT(USERPWD, NULL);
+#if LIBCURL_VERSION_NUM >= 0x070a06
+ HTTP_CURL_OPT(HTTPAUTH, 0);
+#endif
+ HTTP_CURL_OPT(ENCODING, 0);
+ HTTP_CURL_OPT(FOLLOWLOCATION, 0);
+ HTTP_CURL_OPT(UNRESTRICTED_AUTH, 0);
+ HTTP_CURL_OPT(REFERER, NULL);
+ HTTP_CURL_OPT(USERAGENT, "PECL::HTTP/" PHP_EXT_HTTP_VERSION " (PHP/" PHP_VERSION ")");
+ HTTP_CURL_OPT(HTTPHEADER, NULL);
+ HTTP_CURL_OPT(COOKIE, NULL);
+ HTTP_CURL_OPT(COOKIEFILE, NULL);
+ HTTP_CURL_OPT(COOKIEJAR, NULL);
+ HTTP_CURL_OPT(RESUME_FROM, 0);
+ HTTP_CURL_OPT(MAXFILESIZE, 0);
+ HTTP_CURL_OPT(TIMECONDITION, 0);
+ HTTP_CURL_OPT(TIMEVALUE, 0);
+ HTTP_CURL_OPT(TIMEOUT, 0);
+ HTTP_CURL_OPT(CONNECTTIMEOUT, 3);
+ HTTP_CURL_OPT(SSLCERT, NULL);
+#if LIBCURL_VERSION_NUM >= 0x070903
+ HTTP_CURL_OPT(SSLCERTTYPE, NULL);
+#endif
+ HTTP_CURL_OPT(SSLCERTPASSWD, NULL);
+ HTTP_CURL_OPT(SSLKEY, NULL);
+ HTTP_CURL_OPT(SSLKEYTYPE, NULL);
+ HTTP_CURL_OPT(SSLKEYPASSWD, NULL);
+ HTTP_CURL_OPT(SSLENGINE, NULL);
+ HTTP_CURL_OPT(SSLVERSION, 0);
+ HTTP_CURL_OPT(SSL_VERIFYPEER, 0);
+ HTTP_CURL_OPT(SSL_VERIFYHOST, 0);
+ HTTP_CURL_OPT(SSL_CIPHER_LIST, NULL);
+ HTTP_CURL_OPT(CAINFO, NULL);
+#if LIBCURL_VERSION_NUM >= 0x070908
+ HTTP_CURL_OPT(CAPATH, NULL);
+#endif
+ HTTP_CURL_OPT(RANDOM_FILE, NULL);
+ HTTP_CURL_OPT(EGDSOCKET, NULL);
+ HTTP_CURL_OPT(POSTFIELDS, NULL);
+ HTTP_CURL_OPT(POSTFIELDSIZE, 0);
+ HTTP_CURL_OPT(HTTPPOST, NULL);
+ HTTP_CURL_OPT(READDATA, NULL);
+ HTTP_CURL_OPT(INFILESIZE, 0);
+}
+/* }}} */
+
+#endif /* HTTP_HAVE_CURL */
+