+/* {{{ CURL *http_curl_init(http_request *) */
+PHP_HTTP_API CURL * _http_curl_init_ex(CURL *ch, http_request *request)
+{
+ if (ch || (ch = curl_easy_init())) {
+#if defined(ZTS)
+ HTTP_CURL_OPT_EX(ch, NOSIGNAL, 1);
+#endif
+ HTTP_CURL_OPT_EX(ch, HEADER, 0);
+ HTTP_CURL_OPT_EX(ch, FILETIME, 1);
+ HTTP_CURL_OPT_EX(ch, AUTOREFERER, 1);
+ HTTP_CURL_OPT_EX(ch, VERBOSE, 1);
+ HTTP_CURL_OPT_EX(ch, HEADERFUNCTION, NULL);
+ HTTP_CURL_OPT_EX(ch, DEBUGFUNCTION, http_curl_raw_callback);
+ HTTP_CURL_OPT_EX(ch, READFUNCTION, http_curl_read_callback);
+ HTTP_CURL_OPT_EX(ch, IOCTLFUNCTION, http_curl_ioctl_callback);
+ HTTP_CURL_OPT_EX(ch, WRITEFUNCTION, http_curl_dummy_callback);
+
+ /* set context */
+ if (request) {
+ HTTP_CURL_OPT_EX(ch, PRIVATE, request);
+ HTTP_CURL_OPT_EX(ch, DEBUGDATA, request);
+ HTTP_CURL_OPT_EX(ch, ERRORBUFFER, request->_error);
+
+ /* attach curl handle */
+ request->ch = ch;
+ /* set defaults (also in http_request_reset()) */
+ http_request_defaults(request);
+ }
+ }
+
+ return ch;
+}
+/* }}} */
+
+/* {{{ void http_curl_free(CURL **) */
+PHP_HTTP_API void _http_curl_free(CURL **ch)
+{
+ if (*ch) {
+ /* avoid nasty segfaults with already cleaned up callbacks */
+ HTTP_CURL_OPT_EX(*ch, NOPROGRESS, 1);
+ HTTP_CURL_OPT_EX(*ch, PROGRESSFUNCTION, NULL);
+ HTTP_CURL_OPT_EX(*ch, VERBOSE, 0);
+ HTTP_CURL_OPT_EX(*ch, DEBUGFUNCTION, NULL);
+ curl_easy_cleanup(*ch);
+ *ch = NULL;
+ }
+}
+/* }}} */
+