+#ifdef HTTP_NEED_SSL
+
+static MUTEX_T *http_ssl_mutex = NULL;
+
+static void http_ssl_lock(int mode, int n, const char * file, int line)
+{
+ if (mode & CRYPTO_LOCK) {
+ tsrm_mutex_lock(http_ssl_mutex[n]);
+ } else {
+ tsrm_mutex_unlock(http_ssl_mutex[n]);
+ }
+}
+
+static unsigned long http_ssl_id(void)
+{
+ return (unsigned long) tsrm_thread_id();
+}
+
+static inline zend_bool http_ssl_init(void)
+{
+ curl_version_info_data *cvid = curl_version_info(CURLVERSION_NOW);
+
+ if (cvid && (cvid->features & CURL_VERSION_SSL)) {
+ int i, c = CRYPTO_num_locks();
+
+ http_ssl_mutex = malloc(c * sizeof(MUTEX_T));
+
+ for (i = 0; i < c; ++i) {
+ http_ssl_mutex[i] = tsrm_mutex_alloc();
+ }
+
+ CRYPTO_set_id_callback(http_ssl_id);
+ CRYPTO_set_locking_callback(http_ssl_lock);
+
+ return 1;
+ }
+
+ return 0;
+}
+
+static inline void http_ssl_cleanup(void)
+{
+ if (http_ssl_mutex) {
+ 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_ssl_mutex[i]);
+ }
+
+ free(http_ssl_mutex);
+ http_ssl_mutex = NULL;
+ }
+}
+#endif /* HTTP_NEED_SSL */
+
+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/" HTTP_PEXT_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(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);