update curl info
[m6w6/ext-http] / php_http_curl.c
index 307d488f371a871786623955608589605b712d37..5fea9fea4f864a06baf78124bcc1ca5d8a442860 100644 (file)
@@ -1,19 +1,26 @@
-
-#include "php_http.h"
-#include "php_http_request.h"
-#include "php_http_request_pool.h"
+/*
+    +--------------------------------------------------------------------+
+    | PECL :: http                                                       |
+    +--------------------------------------------------------------------+
+    | Redistribution and use in source and binary forms, with or without |
+    | modification, are permitted provided that the conditions mentioned |
+    | in the accompanying LICENSE file are met.                          |
+    +--------------------------------------------------------------------+
+    | Copyright (c) 2004-2011, Michael Wallner <mike@php.net>            |
+    +--------------------------------------------------------------------+
+*/
+
+#include "php_http_api.h"
+
+#if PHP_HTTP_HAVE_CURL
 
 #include <curl/curl.h>
 #define PHP_HTTP_CURL_VERSION(x, y, z) (LIBCURL_VERSION_NUM >= (((x)<<16) + ((y)<<8) + (z)))
 
-#ifdef PHP_HTTP_HAVE_EVENT
+#if PHP_HTTP_HAVE_EVENT
 #      include <event.h>
 #endif
 
-#include <ext/spl/spl_iterators.h>
-#include <Zend/zend_interfaces.h>
-
-
 typedef struct php_http_curl_request {
        CURL *handle;
 
@@ -21,6 +28,7 @@ typedef struct php_http_curl_request {
                HashTable cache;
 
                struct curl_slist *headers;
+               struct curl_slist *resolve;
                php_http_buffer_t cookies;
 
                long redirects;
@@ -47,26 +55,15 @@ typedef struct php_http_curl_request_pool {
 
        int unfinished;  /* int because of curl_multi_perform() */
 
-#ifdef PHP_HTTP_HAVE_EVENT
+#if PHP_HTTP_HAVE_EVENT
        struct event *timeout;
        unsigned useevents:1;
        unsigned runsocket:1;
 #endif
 } php_http_curl_request_pool_t;
 
-#ifdef ZTS
-typedef struct php_http_curl_request_datashare_lock {
-       CURL *ch;
-       MUTEX_T mx;
-} php_http_curl_request_datashare_lock_t;
-#endif
-
 typedef struct php_http_curl_request_datashare {
        CURLSH *handle;
-
-#ifdef ZTS
-       php_http_curl_request_datashare_lock_t *locks;
-#endif
 } php_http_curl_request_datashare_t;
 
 #define PHP_HTTP_CURL_OPT_STRING(OPTION, ldiff, obdc) \
@@ -76,7 +73,7 @@ typedef struct php_http_curl_request_datashare {
        }
 #define PHP_HTTP_CURL_OPT_STRING_EX(keyname, optname, obdc) \
        if (!strcasecmp(key.str, keyname)) { \
-               zval *copy = cache_option(&curl->options.cache, keyname, strlen(keyname)+1, 0, php_http_zsep(IS_STRING, *param)); \
+               zval *copy = cache_option(&curl->options.cache, keyname, strlen(keyname)+1, 0, php_http_ztyp(IS_STRING, *param)); \
                if (obdc) { \
                        if (SUCCESS != php_check_open_basedir(Z_STRVAL_P(copy) TSRMLS_CC)) { \
                                return FAILURE; \
@@ -93,7 +90,7 @@ typedef struct php_http_curl_request_datashare {
        }
 #define PHP_HTTP_CURL_OPT_LONG_EX(keyname, optname) \
        if (!strcasecmp(key.str, keyname)) { \
-               zval *copy = php_http_zsep(IS_LONG, *param); \
+               zval *copy = php_http_ztyp(IS_LONG, *param); \
                curl_easy_setopt(ch, optname, Z_LVAL_P(copy)); \
                zval_ptr_dtor(&copy); \
                continue; \
@@ -113,6 +110,70 @@ static inline php_http_curl_request_storage_t *get_storage(CURL *ch) {
        return st;
 }
 
+/* resource_factory ops */
+
+static void *php_http_curl_ctor(void *opaque TSRMLS_DC)
+{
+       void *ch;
+
+       if ((ch = curl_easy_init())) {
+               get_storage(ch);
+               return ch;
+       }
+       return NULL;
+}
+
+static void *php_http_curl_copy(void *opaque, void *handle TSRMLS_DC)
+{
+       void *ch;
+
+       if ((ch = curl_easy_duphandle(handle))) {
+               curl_easy_reset(ch);
+               get_storage(ch);
+               return ch;
+       }
+       return NULL;
+}
+
+static void php_http_curl_dtor(void *opaque, void *handle TSRMLS_DC)
+{
+       php_http_curl_request_storage_t *st = get_storage(handle);
+
+       curl_easy_cleanup(handle);
+
+       if (st) {
+               if (st->url) {
+                       pefree(st->url, 1);
+               }
+               if (st->cookiestore) {
+                       pefree(st->cookiestore, 1);
+               }
+               pefree(st, 1);
+       }
+}
+
+static void *php_http_curlm_ctor(void *opaque TSRMLS_DC)
+{
+       return curl_multi_init();
+}
+
+static void php_http_curlm_dtor(void *opaque, void *handle TSRMLS_DC)
+{
+       curl_multi_cleanup(handle);
+}
+
+static void *php_http_curlsh_ctor(void *opaque TSRMLS_DC)
+{
+       return curl_share_init();
+}
+
+static void php_http_curlsh_dtor(void *opaque, void *handle TSRMLS_DC)
+{
+       curl_share_cleanup(handle);
+}
+
+/* callbacks */
+
 static size_t php_http_curl_read_callback(void *data, size_t len, size_t n, void *ctx)
 {
        php_http_message_body_t *body = ctx;
@@ -164,7 +225,39 @@ static int php_http_curl_raw_callback(CURL *ch, curl_infotype type, char *data,
        php_http_request_t *h = ctx;
        php_http_curl_request_t *curl = h->ctx;
        unsigned flags = 0;
+       TSRMLS_FETCH_FROM_CTX(h->ts);
 
+       /* catch progress */
+       switch (type) {
+               case CURLINFO_TEXT:
+                       if (php_memnstr(data, ZEND_STRL("About to connect"), data + length)) {
+                               curl->progress.state.info = "resolve";
+                       } else if (php_memnstr(data, ZEND_STRL("Trying"), data + length)) {
+                               curl->progress.state.info = "connect";
+                       } else if (php_memnstr(data, ZEND_STRL("Connected"), data + length)) {
+                               curl->progress.state.info = "connected";
+                       } else if (php_memnstr(data, ZEND_STRL("left intact"), data + length)) {
+                               curl->progress.state.info = "not disconnected";
+                       } else if (php_memnstr(data, ZEND_STRL("closed"), data + length)) {
+                               curl->progress.state.info = "disconnected";
+                       } else if (php_memnstr(data, ZEND_STRL("Issue another request"), data + length)) {
+                               curl->progress.state.info = "redirect";
+                       }
+                       php_http_request_progress_notify(&curl->progress TSRMLS_CC);
+                       break;
+               case CURLINFO_HEADER_OUT:
+               case CURLINFO_DATA_OUT:
+               case CURLINFO_SSL_DATA_OUT:
+                       curl->progress.state.info = "send";
+                       break;
+               case CURLINFO_HEADER_IN:
+               case CURLINFO_DATA_IN:
+               case CURLINFO_SSL_DATA_IN:
+                       curl->progress.state.info = "receive";
+                       break;
+               default:
+                       break;
+       }
        /* process data */
        switch (type) {
                case CURLINFO_HEADER_IN:
@@ -198,7 +291,7 @@ static int php_http_curl_dummy_callback(char *data, size_t n, size_t l, void *s)
        return n*l;
 }
 
-static STATUS php_http_curl_request_prepare(php_http_request_t *h, php_http_request_method_t meth, const char *url, php_http_message_body_t *body)
+static STATUS php_http_curl_request_prepare(php_http_request_t *h, const char *meth, const char *url, php_http_message_body_t *body)
 {
        php_http_curl_request_t *curl = h->ctx;
        php_http_curl_request_storage_t *storage = get_storage(curl->handle);
@@ -212,30 +305,28 @@ static STATUS php_http_curl_request_prepare(php_http_request_t *h, php_http_requ
        curl_easy_setopt(curl->handle, CURLOPT_URL, storage->url);
 
        /* request method */
-       switch (meth) {
-               case PHP_HTTP_GET:
+       switch (php_http_select_str(meth, 4, "GET", "HEAD", "POST", "PUT")) {
+               case 0:
                        curl_easy_setopt(curl->handle, CURLOPT_HTTPGET, 1L);
                        break;
 
-               case PHP_HTTP_HEAD:
+               case 1:
                        curl_easy_setopt(curl->handle, CURLOPT_NOBODY, 1L);
                        break;
 
-               case PHP_HTTP_POST:
+               case 2:
                        curl_easy_setopt(curl->handle, CURLOPT_POST, 1L);
                        break;
 
-               case PHP_HTTP_PUT:
+               case 3:
                        curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 1L);
                        break;
 
                default: {
-                       const char *name = php_http_request_method_name(meth);
-
-                       if (name) {
-                               curl_easy_setopt(curl->handle, CURLOPT_CUSTOMREQUEST, name);
+                       if (meth) {
+                               curl_easy_setopt(curl->handle, CURLOPT_CUSTOMREQUEST, meth);
                        } else {
-                               php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_METHOD, "Unsupported request method: %d (%s)", meth, url);
+                               php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_METHOD, "Unsupported request method: '%s' (%s)", meth, url);
                                return FAILURE;
                        }
                        break;
@@ -250,17 +341,12 @@ static STATUS php_http_curl_request_prepare(php_http_request_t *h, php_http_requ
                 * same semantics as those specified in section 9« reveal that not any single defined HTTP/1.1 method
                 * does not allow a request body.
                 */
-               switch (meth) {
-                       default: {
-                               size_t body_size = php_http_message_body_size(body);
-
-                               curl_easy_setopt(curl->handle, CURLOPT_IOCTLDATA, body);
-                               curl_easy_setopt(curl->handle, CURLOPT_READDATA, body);
-                               curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, body_size);
-                               curl_easy_setopt(curl->handle, CURLOPT_POSTFIELDSIZE, body_size);
-                               break;
-                       }
-               }
+               size_t body_size = php_http_message_body_size(body);
+
+               curl_easy_setopt(curl->handle, CURLOPT_IOCTLDATA, body);
+               curl_easy_setopt(curl->handle, CURLOPT_READDATA, body);
+               curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, body_size);
+               curl_easy_setopt(curl->handle, CURLOPT_POSTFIELDSIZE, body_size);
        }
 
        return SUCCESS;
@@ -302,7 +388,7 @@ static void php_http_curl_request_pool_responsehandler(php_http_request_pool_t *
 }
 
 
-#ifdef PHP_HTTP_HAVE_EVENT
+#if PHP_HTTP_HAVE_EVENT
 
 typedef struct php_http_request_pool_event {
        struct event evnt;
@@ -391,7 +477,7 @@ static int php_http_curl_request_pool_socket_callback(CURL *easy, curl_socket_t
                        ev = ecalloc(1, sizeof(php_http_request_pool_event_t));
                        ev->pool = pool;
                        curl_multi_assign(curl->handle, sock, ev);
-                       event_base_set(PHP_HTTP_G->request_pool.event_base, &ev->evnt);
+                       event_base_set(PHP_HTTP_G->curl.event_base, &ev->evnt);
                } else {
                        event_del(&ev->evnt);
                }
@@ -409,6 +495,7 @@ static int php_http_curl_request_pool_socket_callback(CURL *easy, curl_socket_t
 
                        case CURL_POLL_REMOVE:
                                efree(ev);
+                               /* no break */
                        case CURL_POLL_NONE:
                                return 0;
 
@@ -442,7 +529,7 @@ static void php_http_curl_request_pool_timer_callback(CURLM *multi, long timeout
 
                        if (!event_initialized(curl->timeout)) {
                                event_set(curl->timeout, -1, 0, php_http_curl_request_pool_timeout_callback, pool);
-                               event_base_set(PHP_HTTP_G->request_pool.event_base, curl->timeout);
+                               event_base_set(PHP_HTTP_G->curl.event_base, curl->timeout);
                        } else if (event_pending(curl->timeout, EV_TIMEOUT, NULL)) {
                                event_del(curl->timeout);
                        }
@@ -478,7 +565,7 @@ static inline zval *get_option(HashTable *cache, HashTable *options, char *key,
                ulong h = zend_hash_func(key, keylen);
 
                if (SUCCESS == zend_hash_quick_find(options, key, keylen, h, (void *) &zoption)) {
-                       zval *option = php_http_zsep(type, *zoption);
+                       zval *option = php_http_ztyp(type, *zoption);
 
                        if (cache) {
                                zval *cached = cache_option(cache, key, keylen, h, option);
@@ -499,6 +586,7 @@ static STATUS set_options(php_http_request_t *h, HashTable *options)
        int range_req = 0;
        php_http_curl_request_t *curl = h->ctx;
        CURL *ch = curl->handle;
+       TSRMLS_FETCH_FROM_CTX(h->ts);
 
        /* proxy */
        if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("proxyhost"), IS_STRING))) {
@@ -537,6 +625,30 @@ static STATUS set_options(php_http_request_t *h, HashTable *options)
        if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("ipresolve"), IS_LONG)) && Z_LVAL_P(zoption)) {
                curl_easy_setopt(ch, CURLOPT_IPRESOLVE, Z_LVAL_P(zoption));
        }
+#if PHP_HTTP_CURL_VERSION(7,21,3)
+       if (curl->options.resolve) {
+               curl_slist_free_all(curl->options.resolve);
+               curl->options.resolve = NULL;
+       }
+       if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("resolve"), IS_ARRAY))) {
+               php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
+               HashPosition pos;
+               zval **data;
+
+               FOREACH_KEYVAL(pos, zoption, key, data) {
+                       zval *cpy = php_http_ztyp(IS_STRING, *data);
+
+                       curl->options.resolve = curl_slist_append(curl->options.resolve, Z_STRVAL_P(cpy));
+
+                       zval_ptr_dtor(&cpy);
+               }
+       }
+#endif
+#if PHP_HTTP_CURL_VERSION(7,24,0)
+       if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("dns_servers"), IS_STRING)) && Z_STRLEN_P(zoption)) {
+               curl_easy_setopt(ch, CURLOPT_DNS_SERVERS, Z_STRVAL_P(zoption));
+       }
+#endif
 
        /* limits */
        if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("low_speed_limit"), IS_LONG))) {
@@ -575,8 +687,8 @@ static STATUS set_options(php_http_request_t *h, HashTable *options)
                        if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void *) &prs)) {
                                zend_hash_move_forward(Z_ARRVAL_P(zoption));
                                if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void *) &pre)) {
-                                       zval *prs_cpy = php_http_zsep(IS_LONG, *prs);
-                                       zval *pre_cpy = php_http_zsep(IS_LONG, *pre);
+                                       zval *prs_cpy = php_http_ztyp(IS_LONG, *prs);
+                                       zval *pre_cpy = php_http_ztyp(IS_LONG, *pre);
 
                                        if (Z_LVAL_P(prs_cpy) && Z_LVAL_P(pre_cpy)) {
                                                curl_easy_setopt(ch, CURLOPT_LOCALPORT, MIN(Z_LVAL_P(prs_cpy), Z_LVAL_P(pre_cpy)));
@@ -674,8 +786,8 @@ static STATUS set_options(php_http_request_t *h, HashTable *options)
                                        if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(rr), (void *) &re, &pos2)) {
                                                if (    ((Z_TYPE_PP(rb) == IS_LONG) || ((Z_TYPE_PP(rb) == IS_STRING) && is_numeric_string(Z_STRVAL_PP(rb), Z_STRLEN_PP(rb), NULL, NULL, 1))) &&
                                                                ((Z_TYPE_PP(re) == IS_LONG) || ((Z_TYPE_PP(re) == IS_STRING) && is_numeric_string(Z_STRVAL_PP(re), Z_STRLEN_PP(re), NULL, NULL, 1)))) {
-                                                       zval *rbl = php_http_zsep(IS_LONG, *rb);
-                                                       zval *rel = php_http_zsep(IS_LONG, *re);
+                                                       zval *rbl = php_http_ztyp(IS_LONG, *rb);
+                                                       zval *rel = php_http_ztyp(IS_LONG, *re);
 
                                                        if ((Z_LVAL_P(rbl) >= 0) && (Z_LVAL_P(rel) >= 0)) {
                                                                php_http_buffer_appendf(&rs, "%ld-%ld,", Z_LVAL_P(rbl), Z_LVAL_P(rel));
@@ -715,7 +827,7 @@ static STATUS set_options(php_http_request_t *h, HashTable *options)
                php_http_buffer_init(&header);
                FOREACH_KEYVAL(pos, zoption, header_key, header_val) {
                        if (header_key.type == HASH_KEY_IS_STRING) {
-                               zval *header_cpy = php_http_zsep(IS_STRING, *header_val);
+                               zval *header_cpy = php_http_ztyp(IS_STRING, *header_val);
 
                                if (!strcasecmp(header_key.str, "range")) {
                                        range_req = 1;
@@ -769,7 +881,7 @@ static STATUS set_options(php_http_request_t *h, HashTable *options)
                        zval *urlenc_cookies = NULL;
                        /* check whether cookies should not be urlencoded; default is to urlencode them */
                        if ((!(urlenc_cookies = get_option(&curl->options.cache, options, ZEND_STRS("encodecookies"), IS_BOOL))) || Z_BVAL_P(urlenc_cookies)) {
-                               if (SUCCESS == php_http_url_encode_hash_recursive(HASH_OF(zoption), &curl->options.cookies, "; ", lenof("; "), NULL, 0 TSRMLS_CC)) {
+                               if (SUCCESS == php_http_url_encode_hash_ex(HASH_OF(zoption), &curl->options.cookies, ZEND_STRS(";"), ZEND_STRS("="), NULL, 0 TSRMLS_CC)) {
                                        php_http_buffer_fix(&curl->options.cookies);
                                        curl_easy_setopt(ch, CURLOPT_COOKIE, curl->options.cookies.data);
                                }
@@ -780,7 +892,7 @@ static STATUS set_options(php_http_request_t *h, HashTable *options)
 
                                FOREACH_KEYVAL(pos, zoption, cookie_key, cookie_val) {
                                        if (cookie_key.type == HASH_KEY_IS_STRING) {
-                                               zval *val = php_http_zsep(IS_STRING, *cookie_val);
+                                               zval *val = php_http_ztyp(IS_STRING, *cookie_val);
                                                php_http_buffer_appendf(&curl->options.cookies, "%s=%s; ", cookie_key.str, Z_STRVAL_P(val));
                                                zval_ptr_dtor(&val);
                                        }
@@ -973,7 +1085,6 @@ static STATUS get_info(CURL *ch, HashTable *info)
                add_assoc_zval_ex(&array, "ssl_engines", sizeof("ssl_engines"), subarray);
                curl_slist_free_all(s);
        }
-#if PHP_HTTP_CURL_VERSION(7,14,1)
        if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_COOKIELIST, &s)) {
                MAKE_STD_ZVAL(subarray);
                array_init(subarray);
@@ -985,12 +1096,9 @@ static STATUS get_info(CURL *ch, HashTable *info)
                add_assoc_zval_ex(&array, "cookies", sizeof("cookies"), subarray);
                curl_slist_free_all(s);
        }
-#endif
-#if PHP_HTTP_CURL_VERSION(7,18,2)
        if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_REDIRECT_URL, &c)) {
                add_assoc_string_ex(&array, "redirect_url", sizeof("redirect_url"), c ? c : "", 1);
        }
-#endif
 #if PHP_HTTP_CURL_VERSION(7,19,0)
        if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_PRIMARY_IP, &c)) {
                add_assoc_string_ex(&array, "primary_ip", sizeof("primary_ip"), c ? c : "", 1);
@@ -1006,7 +1114,24 @@ static STATUS get_info(CURL *ch, HashTable *info)
                add_assoc_long_ex(&array, "condition_unmet", sizeof("condition_unmet"), l);
        }
 #endif
+#if PHP_HTTP_CURL_VERSION(7,21,0)
+       if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_PRIMARY_PORT, &l)) {
+               add_assoc_long_ex(&array, "primary_port", sizeof("primary_port"), l);
+       }
+#endif
+#if PHP_HTTP_CURL_VERSION(7,21,0)
+       if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_LOCAL_IP, &c)) {
+               add_assoc_string_ex(&array, "local_ip", sizeof("local_ip"), c ? c : "", 1);
+       }
+#endif
+#if PHP_HTTP_CURL_VERSION(7,21,0)
+       if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_LOCAL_PORT, &l)) {
+               add_assoc_long_ex(&array, "local_port", sizeof("local_port"), l);
+       }
+#endif
+
        /* END::CURLINFO */
+
 #if PHP_HTTP_CURL_VERSION(7,19,1) && defined(PHP_HTTP_HAVE_OPENSSL)
        {
                int i;
@@ -1046,74 +1171,20 @@ static STATUS get_info(CURL *ch, HashTable *info)
 }
 
 
-#ifdef ZTS
-static void *php_http_curl_request_datashare_locks_init(void)
-{
-       int i;
-       php_http_curl_request_datashare_lock_t *locks = pecalloc(CURL_LOCK_DATA_LAST, sizeof(*locks), 1);
-
-       if (locks) {
-               for (i = 0; i < CURL_LOCK_DATA_LAST; ++i) {
-                       locks[i].mx = tsrm_mutex_alloc();
-               }
-       }
-
-       return locks;
-}
-
-static void php_http_curl_request_datashare_locks_dtor(void *l)
-{
-       int i;
-       php_http_curl_request_datashare_lock_t *locks = l;
-
-       for (i = 0; i < CURL_LOCK_DATA_LAST; ++i) {
-               tsrm_mutex_free(locks[i].mx);
-       }
-       pefree(locks, 1);
-}
-
-static void php_http_curl_request_datashare_lock_func(CURL *handle, curl_lock_data data, curl_lock_access locktype, void *userptr)
-{
-       php_http_curl_request_datashare_lock_t *locks = userptr;
-
-       /* TSRM can't distinguish shared/exclusive locks */
-       tsrm_mutex_lock(locks[data].mx);
-       locks[data].ch = handle;
-}
-
-static void php_http_curl_request_datashare_unlock_func(CURL *handle, curl_lock_data data, void *userptr)
-{
-       php_http_curl_request_datashare_lock_t *locks = userptr;
-
-       if (locks[data].ch == handle) {
-               tsrm_mutex_unlock(locks[data].mx);
-       }
-}
-#endif
-
-
-
 /* request datashare handler ops */
 
-static php_http_request_datashare_t *php_http_curl_request_datashare_init(php_http_request_datashare_t *h, void *handle TSRMLS_DC)
+static php_http_request_datashare_t *php_http_curl_request_datashare_init(php_http_request_datashare_t *h, void *handle)
 {
        php_http_curl_request_datashare_t *curl;
+       TSRMLS_FETCH_FROM_CTX(h->ts);
 
-       if (!handle && (SUCCESS != php_http_persistent_handle_acquire(ZEND_STRL("http_request_datashare.curl"), &handle TSRMLS_CC))) {
+       if (!handle && !(handle = php_http_resource_factory_handle_ctor(h->rf TSRMLS_CC))) {
+               php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_DATASHARE, "could not initialize curl share handle");
                return NULL;
        }
 
-       curl = pecalloc(1, sizeof(*curl), h->persistent);
+       curl = ecalloc(1, sizeof(*curl));
        curl->handle = handle;
-#ifdef ZTS
-       if (h->persistent) {
-               if (SUCCESS == php_http_persistent_handle_acquire(ZEND_STRL("http_request_datashare_lock.curl"), (void *) &curl->locks)) {
-                       curl_share_setopt(share->ch, CURLSHOPT_LOCKFUNC, php_http_curl_request_datashare_lock_func);
-                       curl_share_setopt(share->ch, CURLSHOPT_UNLOCKFUNC, php_http_curl_request_datashare_unlock_func);
-                       curl_share_setopt(share->ch, CURLSHOPT_USERDATA, curl->locks);
-               }
-       }
-#endif
        h->ctx = curl;
 
        return h;
@@ -1124,14 +1195,10 @@ static void php_http_curl_request_datashare_dtor(php_http_request_datashare_t *h
        php_http_curl_request_datashare_t *curl = h->ctx;
        TSRMLS_FETCH_FROM_CTX(h->ts);
 
-       php_http_persistent_handle_release(ZEND_STRL("http_request_datashare.curl"), &curl->handle TSRMLS_CC);
-
-#ifdef ZTS
-       if (h->persistent) {
-               php_http_persistent_handle_release(ZEND_STRL("http_request_datashare_lock.curl"), (void *) &curl->locks TSRMLS_CC);
-       }
-#endif
+       php_http_resource_factory_handle_dtor(h->rf, curl->handle TSRMLS_CC);
 
+       efree(curl);
+       h->ctx = NULL;
 }
 
 static STATUS php_http_curl_request_datashare_attach(php_http_request_datashare_t *h, php_http_request_t *r)
@@ -1178,7 +1245,7 @@ static STATUS php_http_curl_request_datashare_setopt(php_http_request_datashare_
                        break;
 
                case PHP_HTTP_REQUEST_DATASHARE_OPT_RESOLVER:
-                       if (CURLSHE_OK != (rc = curl_share_setopt(curl->handle, *((zend_bool *) arg) ? CURLSHOPT_SHARE : CURLSHOPT_UNSHARE, CURL_LOCK_DATA_COOKIE))) {
+                       if (CURLSHE_OK != (rc = curl_share_setopt(curl->handle, *((zend_bool *) arg) ? CURLSHOPT_SHARE : CURLSHOPT_UNSHARE, CURL_LOCK_DATA_DNS))) {
                                TSRMLS_FETCH_FROM_CTX(h->ts);
 
                                php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_DATASHARE, "Could not %s sharing of resolver data: %s",  *((zend_bool *) arg) ? "enable" : "disable", curl_share_strerror(rc));
@@ -1186,6 +1253,17 @@ static STATUS php_http_curl_request_datashare_setopt(php_http_request_datashare_
                        }
                        break;
 
+#if PHP_HTTP_CURL_VERSION(7,23,0)
+               case PHP_HTTP_REQUEST_DATASHARE_OPT_SSLSESSIONS:
+                       if (CURLSHE_OK != (rc = curl_share_setopt(curl->handle, *((zend_bool *) arg) ? CURLSHOPT_SHARE : CURLSHOPT_UNSHARE, CURL_LOCK_DATA_SSL_SESSION))) {
+                               TSRMLS_FETCH_FROM_CTX(h->ts);
+
+                               php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_DATASHARE, "Could not %s sharing of SSL session data: %s",  *((zend_bool *) arg) ? "enable" : "disable", curl_share_strerror(rc));
+                               return FAILURE;
+                       }
+                       break;
+#endif
+
                default:
                        return FAILURE;
        }
@@ -1193,7 +1271,14 @@ static STATUS php_http_curl_request_datashare_setopt(php_http_request_datashare_
        return SUCCESS;
 }
 
+static php_http_resource_factory_ops_t php_http_curlsh_resource_factory_ops = {
+       php_http_curlsh_ctor,
+       NULL,
+       php_http_curlsh_dtor
+};
+
 static php_http_request_datashare_ops_t php_http_curl_request_datashare_ops = {
+               &php_http_curlsh_resource_factory_ops,
                php_http_curl_request_datashare_init,
                NULL /* copy */,
                php_http_curl_request_datashare_dtor,
@@ -1211,11 +1296,13 @@ PHP_HTTP_API php_http_request_datashare_ops_t *php_http_curl_get_request_datasha
 
 /* request pool handler ops */
 
-static php_http_request_pool_t *php_http_curl_request_pool_init(php_http_request_pool_t *h, void *handle TSRMLS_DC)
+static php_http_request_pool_t *php_http_curl_request_pool_init(php_http_request_pool_t *h, void *handle)
 {
        php_http_curl_request_pool_t *curl;
+       TSRMLS_FETCH_FROM_CTX(h->ts);
 
-       if (!handle && (SUCCESS != php_http_persistent_handle_acquire(ZEND_STRL("http_request_pool.curl"), &handle TSRMLS_CC))) {
+       if (!handle && !(handle = php_http_resource_factory_handle_ctor(h->rf TSRMLS_CC))) {
+               php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_POOL, "could not initialize curl pool handle");
                return NULL;
        }
 
@@ -1232,7 +1319,7 @@ static void php_http_curl_request_pool_dtor(php_http_request_pool_t *h)
        php_http_curl_request_pool_t *curl = h->ctx;
        TSRMLS_FETCH_FROM_CTX(h->ts);
 
-#ifdef PHP_HTTP_HAVE_EVENT
+#if PHP_HTTP_HAVE_EVENT
        if (curl->timeout) {
                efree(curl->timeout);
                curl->timeout = NULL;
@@ -1240,17 +1327,19 @@ static void php_http_curl_request_pool_dtor(php_http_request_pool_t *h)
 #endif
        curl->unfinished = 0;
        php_http_request_pool_reset(h);
-       php_http_persistent_handle_release(ZEND_STRL("http_request_pool.curl"), &curl->handle TSRMLS_CC);
+
+       php_http_resource_factory_handle_dtor(h->rf, curl->handle TSRMLS_CC);
 
        efree(curl);
        h->ctx = NULL;
 }
 
-static STATUS php_http_curl_request_pool_attach(php_http_request_pool_t *h, php_http_request_t *r, php_http_request_method_t m, const char *url, php_http_message_body_t *body)
+static STATUS php_http_curl_request_pool_attach(php_http_request_pool_t *h, php_http_request_t *r, const char *m, const char *url, php_http_message_body_t *body)
 {
        php_http_curl_request_pool_t *curl = h->ctx;
        php_http_curl_request_t *recurl = r->ctx;
        CURLMcode rs;
+       TSRMLS_FETCH_FROM_CTX(h->ts);
 
        if (SUCCESS != php_http_curl_request_prepare(r, m, url, body)) {
                return FAILURE;
@@ -1270,6 +1359,7 @@ static STATUS php_http_curl_request_pool_detach(php_http_request_pool_t *h, php_
        php_http_curl_request_pool_t *curl = h->ctx;
        php_http_curl_request_t *recurl = r->ctx;
        CURLMcode rs = curl_multi_remove_handle(curl->handle, recurl->handle);
+       TSRMLS_FETCH_FROM_CTX(h->ts);
 
        if (CURLM_OK == rs) {
                return SUCCESS;
@@ -1292,9 +1382,9 @@ static STATUS php_http_curl_request_pool_wait(php_http_request_pool_t *h, struct
        struct timeval timeout;
        php_http_curl_request_pool_t *curl = h->ctx;
 
-#ifdef PHP_HTTP_HAVE_EVENT
+#if PHP_HTTP_HAVE_EVENT
        if (curl->useevents) {
-               TSRMLS_FETCH_FROM_CTX(pool->ts);
+               TSRMLS_FETCH_FROM_CTX(h->ts);
 
                php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "not implemented");
                return FAILURE;
@@ -1333,10 +1423,10 @@ static STATUS php_http_curl_request_pool_wait(php_http_request_pool_t *h, struct
 static int php_http_curl_request_pool_once(php_http_request_pool_t *h)
 {
        php_http_curl_request_pool_t *curl = h->ctx;
-       TSRMLS_FETCH_FROM_CTX(h->ts);
 
-#ifdef PHP_HTTP_HAVE_EVENT
+#if PHP_HTTP_HAVE_EVENT
        if (curl->useevents) {
+               TSRMLS_FETCH_FROM_CTX(h->ts);
                php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "not implemented");
                return FAILURE;
        }
@@ -1349,21 +1439,25 @@ static int php_http_curl_request_pool_once(php_http_request_pool_t *h)
        return curl->unfinished;
 
 }
+#if PHP_HTTP_HAVE_EVENT
 static void dolog(int i, const char *m) {
        fprintf(stderr, "%d: %s\n", i, m);
 }
+#endif
 static STATUS php_http_curl_request_pool_exec(php_http_request_pool_t *h)
 {
+       TSRMLS_FETCH_FROM_CTX(h->ts);
+
+#if PHP_HTTP_HAVE_EVENT
        php_http_curl_request_pool_t *curl = h->ctx;
 
-#ifdef PHP_HTTP_HAVE_EVENT
        if (curl->useevents) {
                event_set_log_callback(dolog);
                do {
 #if DBG_EVENTS
                        fprintf(stderr, "X");
 #endif
-                       event_base_dispatch(PHP_HTTP_G->request_pool.event_base);
+                       event_base_dispatch(PHP_HTTP_G->curl.event_base);
                } while (curl->unfinished);
        } else
 #endif
@@ -1420,7 +1514,14 @@ static STATUS php_http_curl_request_pool_setopt(php_http_request_pool_t *h, php_
        return SUCCESS;
 }
 
+static php_http_resource_factory_ops_t php_http_curlm_resource_factory_ops = {
+       php_http_curlm_ctor,
+       NULL,
+       php_http_curlm_dtor
+};
+
 static php_http_request_pool_ops_t php_http_curl_request_pool_ops = {
+               &php_http_curlm_resource_factory_ops,
                php_http_curl_request_pool_init,
                NULL /* copy */,
                php_http_curl_request_pool_dtor,
@@ -1447,7 +1548,8 @@ static php_http_request_t *php_http_curl_request_init(php_http_request_t *h, voi
        php_http_curl_request_t *ctx;
        TSRMLS_FETCH_FROM_CTX(h->ts);
 
-       if (!handle && (SUCCESS != php_http_persistent_handle_acquire(ZEND_STRL("http_request.curl"), &handle TSRMLS_CC))) {
+       if (!handle && !(handle = php_http_resource_factory_handle_ctor(h->rf TSRMLS_CC))) {
+               php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST, "could not initialize curl handle");
                return NULL;
        }
 
@@ -1474,7 +1576,7 @@ static php_http_request_t *php_http_curl_request_init(php_http_request_t *h, voi
        curl_easy_setopt(handle, CURLOPT_DEBUGDATA, h);
        curl_easy_setopt(handle, CURLOPT_PROGRESSDATA, h);
 
-       php_http_curl_request_reset(h TSRMLS_CC);
+       php_http_curl_request_reset(h);
 
        return h;
 }
@@ -1485,27 +1587,28 @@ static php_http_request_t *php_http_curl_request_copy(php_http_request_t *from,
        void *copy;
        TSRMLS_FETCH_FROM_CTX(from->ts);
 
-       if (SUCCESS != php_http_persistent_handle_accrete(ZEND_STRL("http_request.curl"), ctx->handle, &copy TSRMLS_CC)) {
+       if (!(copy = php_http_resource_factory_handle_copy(from->rf, ctx->handle TSRMLS_CC))) {
                return NULL;
        }
 
        if (to) {
                return php_http_curl_request_init(to, copy);
        } else {
-               return php_http_request_init(NULL, from->ops, copy TSRMLS_CC);
+               return php_http_request_init(NULL, from->ops, from->rf, copy TSRMLS_CC);
        }
 }
 
 static void php_http_curl_request_dtor(php_http_request_t *h)
 {
        php_http_curl_request_t *ctx = h->ctx;
+       TSRMLS_FETCH_FROM_CTX(h->ts);
 
        curl_easy_setopt(ctx->handle, CURLOPT_NOPROGRESS, 1L);
        curl_easy_setopt(ctx->handle, CURLOPT_PROGRESSFUNCTION, NULL);
        curl_easy_setopt(ctx->handle, CURLOPT_VERBOSE, 0L);
        curl_easy_setopt(ctx->handle, CURLOPT_DEBUGFUNCTION, NULL);
 
-       php_http_persistent_handle_release(ZEND_STRL("http_request.curl"), &ctx->handle TSRMLS_CC);
+       php_http_resource_factory_handle_dtor(h->rf, ctx->handle TSRMLS_CC);
 
        php_http_buffer_dtor(&ctx->options.cookies);
        zend_hash_destroy(&ctx->options.cache);
@@ -1514,11 +1617,7 @@ static void php_http_curl_request_dtor(php_http_request_t *h)
                curl_slist_free_all(ctx->options.headers);
                ctx->options.headers = NULL;
        }
-
-       if (ctx->progress.callback) {
-               zval_ptr_dtor(&ctx->progress.callback);
-               ctx->progress.callback = NULL;
-       }
+       php_http_request_progress_dtor(&ctx->progress TSRMLS_CC);
 
        efree(ctx);
        h->ctx = NULL;
@@ -1556,6 +1655,12 @@ static STATUS php_http_curl_request_reset(php_http_request_t *h)
        curl_easy_setopt(ch, CURLOPT_HTTPPROXYTUNNEL, 0L);
        curl_easy_setopt(ch, CURLOPT_DNS_CACHE_TIMEOUT, 60L);
        curl_easy_setopt(ch, CURLOPT_IPRESOLVE, 0);
+#if PHP_HTTP_CURL_VERSION(7,21,3)
+       curl_easy_setopt(ch, CURLOPT_RESOLVE, NULL);
+#endif
+#if PHP_HTTP_CURL_VERSION(7,24,0)
+       curl_easy_setopt(ch, CURLOPT_DNS_SERVERS, NULL);
+#endif
        curl_easy_setopt(ch, CURLOPT_LOW_SPEED_LIMIT, 0L);
        curl_easy_setopt(ch, CURLOPT_LOW_SPEED_TIME, 0L);
        /* LFS weirdance
@@ -1650,7 +1755,7 @@ static STATUS php_http_curl_request_reset(php_http_request_t *h)
        return SUCCESS;
 }
 
-static STATUS php_http_curl_request_exec(php_http_request_t *h, php_http_request_method_t meth, const char *url, php_http_message_body_t *body)
+static STATUS php_http_curl_request_exec(php_http_request_t *h, const char *meth, const char *url, php_http_message_body_t *body)
 {
        uint tries = 0;
        CURLcode result;
@@ -1703,6 +1808,7 @@ retry:
 static STATUS php_http_curl_request_setopt(php_http_request_t *h, php_http_request_setopt_opt_t opt, void *arg)
 {
        php_http_curl_request_t *curl = h->ctx;
+       TSRMLS_FETCH_FROM_CTX(h->ts);
 
        switch (opt) {
                case PHP_HTTP_REQUEST_OPT_SETTINGS:
@@ -1714,19 +1820,12 @@ static STATUS php_http_curl_request_setopt(php_http_request_t *h, php_http_reque
                                php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST, "Cannot change progress callback while executing it");
                                return FAILURE;
                        }
-                       if (arg) {
-                               Z_ADDREF_P(arg);
-                       }
                        if (curl->progress.callback) {
-                               zval_ptr_dtor(&curl->progress.callback);
+                               php_http_request_progress_dtor(&curl->progress TSRMLS_CC);
                        }
                        curl->progress.callback = arg;
                        break;
 
-               case PHP_HTTP_REQUEST_OPT_PROGRESS_CALLBACK_WANTS_STATE:
-                       curl->progress.pass_state = *((int *)arg);
-                       break;
-
                case PHP_HTTP_REQUEST_OPT_COOKIES_ENABLE:
                        /* are cookies already enabled anyway? */
                        if (!get_storage(curl->handle)->cookiestore) {
@@ -1781,7 +1880,14 @@ static STATUS php_http_curl_request_getopt(php_http_request_t *h, php_http_reque
        return SUCCESS;
 }
 
+static php_http_resource_factory_ops_t php_http_curl_resource_factory_ops = {
+       php_http_curl_ctor,
+       php_http_curl_copy,
+       php_http_curl_dtor
+};
+
 static php_http_request_ops_t php_http_curl_request_ops = {
+       &php_http_curl_resource_factory_ops,
        php_http_curl_request_init,
        php_http_curl_request_copy,
        php_http_curl_request_dtor,
@@ -1796,45 +1902,6 @@ PHP_HTTP_API php_http_request_ops_t *php_http_curl_get_request_ops(void)
        return &php_http_curl_request_ops;
 }
 
-/* safe curl wrappers */
-static void *safe_curl_init(void)
-{
-       void *ch;
-
-       if ((ch = curl_easy_init())) {
-               get_storage(ch);
-               return ch;
-       }
-       return NULL;
-}
-
-static void *safe_curl_copy(void *p)
-{
-       void *ch;
-
-       if ((ch = curl_easy_duphandle(p))) {
-               get_storage(ch);
-               return ch;
-       }
-       return NULL;
-}
-
-static void safe_curl_dtor(void *p) {
-       php_http_curl_request_storage_t *st = get_storage(p);
-
-       curl_easy_cleanup(p);
-
-       if (st) {
-               if (st->url) {
-                       pefree(st->url, 1);
-               }
-               if (st->cookiestore) {
-                       pefree(st->cookiestore, 1);
-               }
-               pefree(st, 1);
-       }
-}
-
 #if defined(ZTS) && defined(PHP_HTTP_HAVE_SSL)
 #      ifdef PHP_WIN32
 #              define PHP_HTTP_NEED_OPENSSL_TSL
@@ -1909,7 +1976,23 @@ static struct gcry_thread_cbs php_http_gnutls_tsl = {
 };
 #endif
 
+#define PHP_HTTP_BEGIN_ARGS(method, req_args)  PHP_HTTP_BEGIN_ARGS_EX(HttpCURL, method, 0, req_args)
+#define PHP_HTTP_EMPTY_ARGS(method)                            PHP_HTTP_EMPTY_ARGS_EX(HttpCURL, method, 0)
+#define PHP_HTTP_CURL_ME(method, visibility)   PHP_ME(HttpCURL, method, PHP_HTTP_ARGS(HttpCURL, method), visibility)
+#define PHP_HTTP_CURL_ALIAS(method, func)      PHP_HTTP_STATIC_ME_ALIAS(method, func, PHP_HTTP_ARGS(HttpCURL, method))
+#define PHP_HTTP_CURL_MALIAS(me, al, vis)      ZEND_FENTRY(me, ZEND_MN(HttpCURL_##al), PHP_HTTP_ARGS(HttpCURL, al), vis)
+
+PHP_HTTP_EMPTY_ARGS(__construct);
 
+zend_class_entry *php_http_curl_class_entry;
+zend_function_entry php_http_curl_method_entry[] = {
+       PHP_HTTP_CURL_ME(__construct, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR)
+
+       EMPTY_FUNCTION_ENTRY
+};
+
+PHP_METHOD(HttpCURL, __construct) {
+}
 
 PHP_MINIT_FUNCTION(http_curl)
 {
@@ -1942,15 +2025,15 @@ PHP_MINIT_FUNCTION(http_curl)
                return FAILURE;
        }
 
-       if (SUCCESS != php_http_persistent_handle_provide(ZEND_STRL("http_request_datashare.curl"), curl_share_init, (php_http_persistent_handle_dtor_t) curl_share_cleanup, NULL TSRMLS_CC)) {
+       if (SUCCESS != php_http_persistent_handle_provide(ZEND_STRL("http_request_datashare.curl"), &php_http_curlsh_resource_factory_ops, NULL, NULL)) {
                return FAILURE;
        }
 
-       if (SUCCESS != php_http_persistent_handle_provide(ZEND_STRL("http_request_pool.curl"), curl_multi_init, (php_http_persistent_handle_dtor_t) curl_multi_cleanup, NULL TSRMLS_CC)) {
+       if (SUCCESS != php_http_persistent_handle_provide(ZEND_STRL("http_request_pool.curl"), &php_http_curlm_resource_factory_ops, NULL, NULL)) {
                return FAILURE;
        }
 
-       if (SUCCESS != php_http_persistent_handle_provide(ZEND_STRL("http_request.curl"), safe_curl_init, safe_curl_dtor, safe_curl_copy)) {
+       if (SUCCESS != php_http_persistent_handle_provide(ZEND_STRL("http_request.curl"), &php_http_curl_resource_factory_ops, NULL, NULL)) {
                return FAILURE;
        }
 
@@ -1958,60 +2041,62 @@ PHP_MINIT_FUNCTION(http_curl)
                return FAILURE;
        }
 
+       PHP_HTTP_REGISTER_CLASS(http, CURL, http_curl, php_http_curl_class_entry, 0);
+
        /*
        * HTTP Protocol Version Constants
        */
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("VERSION_1_0"), CURL_HTTP_VERSION_1_0 TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("VERSION_1_1"), CURL_HTTP_VERSION_1_1 TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("VERSION_NONE"), CURL_HTTP_VERSION_NONE TSRMLS_CC); /* to be removed */
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("VERSION_ANY"), CURL_HTTP_VERSION_NONE TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("HTTP_VERSION_1_0"), CURL_HTTP_VERSION_1_0 TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("HTTP_VERSION_1_1"), CURL_HTTP_VERSION_1_1 TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("HTTP_VERSION_NONE"), CURL_HTTP_VERSION_NONE TSRMLS_CC); /* to be removed */
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("HTTP_VERSION_ANY"), CURL_HTTP_VERSION_NONE TSRMLS_CC);
 
        /*
        * SSL Version Constants
        */
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("SSL_VERSION_TLSv1"), CURL_SSLVERSION_TLSv1 TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("SSL_VERSION_SSLv2"), CURL_SSLVERSION_SSLv2 TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("SSL_VERSION_SSLv3"), CURL_SSLVERSION_SSLv3 TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("SSL_VERSION_ANY"), CURL_SSLVERSION_DEFAULT TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("SSL_VERSION_TLSv1"), CURL_SSLVERSION_TLSv1 TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("SSL_VERSION_SSLv2"), CURL_SSLVERSION_SSLv2 TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("SSL_VERSION_SSLv3"), CURL_SSLVERSION_SSLv3 TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("SSL_VERSION_ANY"), CURL_SSLVERSION_DEFAULT TSRMLS_CC);
 
        /*
        * DNS IPvX resolving
        */
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("IPRESOLVE_V4"), CURL_IPRESOLVE_V4 TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("IPRESOLVE_V6"), CURL_IPRESOLVE_V6 TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("IPRESOLVE_ANY"), CURL_IPRESOLVE_WHATEVER TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("IPRESOLVE_V4"), CURL_IPRESOLVE_V4 TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("IPRESOLVE_V6"), CURL_IPRESOLVE_V6 TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("IPRESOLVE_ANY"), CURL_IPRESOLVE_WHATEVER TSRMLS_CC);
 
        /*
        * Auth Constants
        */
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("AUTH_BASIC"), CURLAUTH_BASIC TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("AUTH_DIGEST"), CURLAUTH_DIGEST TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("AUTH_BASIC"), CURLAUTH_BASIC TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("AUTH_DIGEST"), CURLAUTH_DIGEST TSRMLS_CC);
 #if PHP_HTTP_CURL_VERSION(7,19,3)
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("AUTH_DIGEST_IE"), CURLAUTH_DIGEST_IE TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("AUTH_DIGEST_IE"), CURLAUTH_DIGEST_IE TSRMLS_CC);
 #endif
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("AUTH_NTLM"), CURLAUTH_NTLM TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("AUTH_GSSNEG"), CURLAUTH_GSSNEGOTIATE TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("AUTH_ANY"), CURLAUTH_ANY TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("AUTH_NTLM"), CURLAUTH_NTLM TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("AUTH_GSSNEG"), CURLAUTH_GSSNEGOTIATE TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("AUTH_ANY"), CURLAUTH_ANY TSRMLS_CC);
 
        /*
        * Proxy Type Constants
        */
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("PROXY_SOCKS4"), CURLPROXY_SOCKS4 TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("PROXY_SOCKS4A"), CURLPROXY_SOCKS5 TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("PROXY_SOCKS5_HOSTNAME"), CURLPROXY_SOCKS5 TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("PROXY_SOCKS5"), CURLPROXY_SOCKS5 TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("PROXY_HTTP"), CURLPROXY_HTTP TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("PROXY_SOCKS4"), CURLPROXY_SOCKS4 TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("PROXY_SOCKS4A"), CURLPROXY_SOCKS5 TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("PROXY_SOCKS5_HOSTNAME"), CURLPROXY_SOCKS5 TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("PROXY_SOCKS5"), CURLPROXY_SOCKS5 TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("PROXY_HTTP"), CURLPROXY_HTTP TSRMLS_CC);
 #      if PHP_HTTP_CURL_VERSION(7,19,4)
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("PROXY_HTTP_1_0"), CURLPROXY_HTTP_1_0 TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("PROXY_HTTP_1_0"), CURLPROXY_HTTP_1_0 TSRMLS_CC);
 #      endif
 
        /*
        * Post Redirection Constants
        */
 #if PHP_HTTP_CURL_VERSION(7,19,1)
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("POSTREDIR_301"), CURL_REDIR_POST_301 TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("POSTREDIR_302"), CURL_REDIR_POST_302 TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_request_class_entry, ZEND_STRL("POSTREDIR_ALL"), CURL_REDIR_POST_ALL TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("POSTREDIR_301"), CURL_REDIR_POST_301 TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("POSTREDIR_302"), CURL_REDIR_POST_302 TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_curl_class_entry, ZEND_STRL("POSTREDIR_ALL"), CURL_REDIR_POST_ALL TSRMLS_CC);
 #endif
 
        return SUCCESS;
@@ -2040,11 +2125,23 @@ PHP_MSHUTDOWN_FUNCTION(http_curl)
 
 PHP_RINIT_FUNCTION(http_curl)
 {
-#ifdef PHP_HTTP_HAVE_EVENT
-       if (!PHP_HTTP_G->request_pool.event_base && !(PHP_HTTP_G->request_pool.event_base = event_init())) {
+#if PHP_HTTP_HAVE_EVENT
+       if (!PHP_HTTP_G->curl.event_base && !(PHP_HTTP_G->curl.event_base = event_init())) {
                return FAILURE;
        }
 #endif
 
        return SUCCESS;
 }
+
+#endif /* PHP_HTTP_HAVE_CURL */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
+