- add ob_(deflate|inflate)handler
[m6w6/ext-http] / http_request_api.c
index 3528d3ccd8c4f16fc8462f9f850105ac2f3813de..f6ee54eb50bdf04dd0b3d171857a40fb2ea66bf2 100644 (file)
 #              endif /* HTTP_HAVE_OPENSSL || HTTP_HAVE_GNUTLS */
 #      endif /* PHP_WIN32 */
 #endif /* ZTS && HTTP_HAVE_SSL */
-/* }}} */
-
-ZEND_EXTERN_MODULE_GLOBALS(http);
 
 #ifdef HTTP_NEED_SSL_TSL
 static inline void http_ssl_init(void);
 static inline void http_ssl_cleanup(void);
 #endif
+/* }}} */
 
+/* {{{ MINIT */
 PHP_MINIT_FUNCTION(http_request)
 {
 #ifdef HTTP_NEED_SSL_TSL
@@ -92,7 +91,9 @@ PHP_MINIT_FUNCTION(http_request)
 
        return SUCCESS;
 }
+/* }}} */
 
+/* {{{ MSHUTDOWN */
 PHP_MSHUTDOWN_FUNCTION(http_request)
 {
        curl_global_cleanup();
@@ -101,7 +102,9 @@ PHP_MSHUTDOWN_FUNCTION(http_request)
 #endif
        return SUCCESS;
 }
+/* }}} */
 
+/* {{{ MACROS */
 #ifndef HAVE_CURL_EASY_STRERROR
 #      define curl_easy_strerror(dummy) "unkown error"
 #endif
@@ -162,15 +165,25 @@ PHP_MSHUTDOWN_FUNCTION(http_request)
        }
 
 #define HTTP_CURL_OPT(OPTION, p) curl_easy_setopt(request->ch, CURLOPT_##OPTION, (p))
-#define HTTP_CURL_OPT_STRING(keyname) HTTP_CURL_OPT_STRING_EX(keyname, keyname)
-#define HTTP_CURL_OPT_SSL_STRING(keyname) HTTP_CURL_OPT_STRING_EX(keyname, SSL##keyname)
-#define HTTP_CURL_OPT_SSL_STRING_(keyname) HTTP_CURL_OPT_STRING_EX(keyname, SSL_##keyname)
-#define HTTP_CURL_OPT_STRING_EX(keyname, optname) \
+#define HTTP_CURL_OPT_STRING(keyname, obdc) HTTP_CURL_OPT_STRING_EX(keyname, keyname, obdc)
+#define HTTP_CURL_OPT_SSL_STRING(keyname, obdc) HTTP_CURL_OPT_STRING_EX(keyname, SSL##keyname, obdc)
+#define HTTP_CURL_OPT_SSL_STRING_(keyname,obdc ) HTTP_CURL_OPT_STRING_EX(keyname, SSL_##keyname, obdc)
+#define HTTP_CURL_OPT_STRING_EX(keyname, optname, obdc) \
        if (!strcasecmp(key, #keyname)) { \
-               convert_to_string(*param); \
-               HTTP_CURL_OPT(optname, Z_STRVAL_PP(param)); \
+               int ok = 1; \
+               zval *orig = *param; \
+               convert_to_string_ex(param); \
+               if (obdc) { \
+                       HTTP_CHECK_OPEN_BASEDIR(Z_STRVAL_PP(param), ok = 0); \
+               } \
                key = NULL; \
-               continue; \
+               if (ok) { \
+                       HTTP_CURL_OPT(optname, Z_STRVAL_PP(param)); \
+                       if (orig != *param) zval_ptr_dtor(param); \
+                       continue; \
+               } \
+               if (orig != *param) zval_ptr_dtor(param); \
+               return FAILURE; \
        }
 #define HTTP_CURL_OPT_LONG(keyname) HTTP_OPT_SSL_LONG_EX(keyname, keyname)
 #define HTTP_CURL_OPT_SSL_LONG(keyname) HTTP_CURL_OPT_LONG_EX(keyname, SSL##keyname)
@@ -182,7 +195,9 @@ PHP_MSHUTDOWN_FUNCTION(http_request)
                key = NULL; \
                continue; \
        }
+/* }}} */
 
+/* {{{ forward declarations */
 #define http_request_option(r, o, k, t) _http_request_option_ex((r), (o), (k), sizeof(k), (t) TSRMLS_CC)
 #define http_request_option_ex(r, o, k, l, t) _http_request_option_ex((r), (o), (k), (l), (t) TSRMLS_CC)
 static inline zval *_http_request_option_ex(http_request *request, HashTable *options, char *key, size_t keylen, int type TSRMLS_DC);
@@ -192,15 +207,17 @@ static int http_curl_progress_callback(void *, double, double, double, double);
 static int http_curl_raw_callback(CURL *, curl_infotype, char *, size_t, void *);
 static int http_curl_dummy_callback(char *data, size_t n, size_t l, void *s) { return n*l; }
 static curlioerr http_curl_ioctl_callback(CURL *, curliocmd, void *);
+/* }}} */
 
-PHP_HTTP_API http_request *_http_request_init_ex(http_request *request, CURL *ch, http_request_method meth, const char *url TSRMLS_DC)
+/* {{{ http_request *http_request_init(http_request *) */
+PHP_HTTP_API http_request *_http_request_init_ex(http_request *request, CURL *ch, http_request_method meth, const char *url ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
 {
        http_request *r;
        
        if (request) {
                r = request;
        } else {
-               r = emalloc(sizeof(http_request));
+               r = emalloc_rel(sizeof(http_request));
        }
        memset(r, 0, sizeof(http_request));
        
@@ -210,17 +227,16 @@ PHP_HTTP_API http_request *_http_request_init_ex(http_request *request, CURL *ch
        
        phpstr_init(&r->conv.request);
        phpstr_init_ex(&r->conv.response, HTTP_CURLBUF_SIZE, 0);
-       
-       zend_hash_init(&r->info, 0, NULL, ZVAL_PTR_DTOR, 0);
-       
        phpstr_init(&r->_cache.cookies);
        zend_hash_init(&r->_cache.options, 0, NULL, ZVAL_PTR_DTOR, 0);
        
-       TSRMLS_SET_CTX(request->tsrm_ls);
+       TSRMLS_SET_CTX(r->tsrm_ls);
        
        return r;
 }
+/* }}} */
 
+/* {{{ void http_request_dtor(http_request *) */
 PHP_HTTP_API void _http_request_dtor(http_request *request)
 {
        TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
@@ -235,13 +251,7 @@ PHP_HTTP_API void _http_request_dtor(http_request *request)
                request->ch = NULL;
        }
        
-       STR_SET(request->url, NULL);
-       
-       request->conv.last_type = 0;
-       phpstr_dtor(&request->conv.request);
-       phpstr_dtor(&request->conv.response);
-       
-       zend_hash_destroy(&request->info);
+       http_request_reset(request);
        
        phpstr_dtor(&request->_cache.cookies);
        zend_hash_destroy(&request->_cache.options);
@@ -249,90 +259,124 @@ PHP_HTTP_API void _http_request_dtor(http_request *request)
                curl_slist_free_all(request->_cache.headers);
                request->_cache.headers = NULL;
        }
+       if (request->_progress_callback) {
+               zval_ptr_dtor(&request->_progress_callback);
+               request->_progress_callback = NULL;
+       }
 }
+/* }}} */
 
+/* {{{ void http_request_free(http_request **) */
 PHP_HTTP_API void _http_request_free(http_request **request)
 {
        if (*request) {
                TSRMLS_FETCH_FROM_CTX((*request)->tsrm_ls);
+               http_request_body_free(&(*request)->body);
                http_request_dtor(*request);
                efree(*request);
                *request = NULL;
        }
 }
+/* }}} */
 
-/* {{{ http_request_reset(http_request *) */
+/* {{{ void http_request_reset(http_request *) */
 PHP_HTTP_API void _http_request_reset(http_request *request)
 {
-#ifdef HAVE_CURL_EASY_RESET
-       curl_easy_reset(request->ch);
-#endif
-
+       TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
        STR_SET(request->url, NULL);
+       request->conv.last_type = 0;
        phpstr_dtor(&request->conv.request);
        phpstr_dtor(&request->conv.response);
+       http_request_body_dtor(request->body);
+}
+/* }}} */
 
+/* {{{ void http_request_defaults(http_request *) */
+PHP_HTTP_API void _http_request_defaults(http_request *request)
+{
+       if (request->ch) {
+#ifdef HAVE_CURL_EASY_RESET
+               curl_easy_reset(request->ch);
+#endif
 #if defined(ZTS)
-       HTTP_CURL_OPT(NOSIGNAL, 1);
+               HTTP_CURL_OPT(NOSIGNAL, 1);
 #endif
-       HTTP_CURL_OPT(HEADER, 0);
-       HTTP_CURL_OPT(FILETIME, 1);
-       HTTP_CURL_OPT(AUTOREFERER, 1);
-       HTTP_CURL_OPT(VERBOSE, 1);
-       HTTP_CURL_OPT(HEADERFUNCTION, NULL);
-       HTTP_CURL_OPT(DEBUGFUNCTION, http_curl_raw_callback);
-       HTTP_CURL_OPT(READFUNCTION, http_curl_read_callback);
-       HTTP_CURL_OPT(IOCTLFUNCTION, http_curl_ioctl_callback);
-       HTTP_CURL_OPT(WRITEFUNCTION, http_curl_dummy_callback);
-       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);
-       HTTP_CURL_OPT(PROXYAUTH, 0);
-       HTTP_CURL_OPT(INTERFACE, NULL);
-       HTTP_CURL_OPT(PORT, 0);
-       HTTP_CURL_OPT(USERPWD, NULL);
-       HTTP_CURL_OPT(HTTPAUTH, 0);
-       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);
-       HTTP_CURL_OPT(SSLCERTTYPE, NULL);
-       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);
-       HTTP_CURL_OPT(CAPATH, NULL);
-       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(IOCTLDATA, NULL);
-       HTTP_CURL_OPT(READDATA, NULL);
-       HTTP_CURL_OPT(INFILESIZE, 0);
+               HTTP_CURL_OPT(PRIVATE, request);
+               HTTP_CURL_OPT(ERRORBUFFER, request->_error);
+               HTTP_CURL_OPT(HEADER, 0);
+               HTTP_CURL_OPT(FILETIME, 1);
+               HTTP_CURL_OPT(AUTOREFERER, 1);
+               HTTP_CURL_OPT(VERBOSE, 1);
+               HTTP_CURL_OPT(HEADERFUNCTION, NULL);
+               HTTP_CURL_OPT(DEBUGFUNCTION, http_curl_raw_callback);
+               HTTP_CURL_OPT(READFUNCTION, http_curl_read_callback);
+               HTTP_CURL_OPT(IOCTLFUNCTION, http_curl_ioctl_callback);
+               HTTP_CURL_OPT(WRITEFUNCTION, http_curl_dummy_callback);
+               HTTP_CURL_OPT(PROGRESSFUNCTION, NULL);
+               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);
+               HTTP_CURL_OPT(PROXYAUTH, 0);
+               HTTP_CURL_OPT(INTERFACE, NULL);
+               HTTP_CURL_OPT(PORT, 0);
+               HTTP_CURL_OPT(USERPWD, NULL);
+               HTTP_CURL_OPT(HTTPAUTH, 0);
+               HTTP_CURL_OPT(ENCODING, NULL);
+               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);
+               HTTP_CURL_OPT(SSLCERTTYPE, NULL);
+               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);
+               HTTP_CURL_OPT(CAPATH, NULL);
+               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(IOCTLDATA, NULL);
+               HTTP_CURL_OPT(READDATA, NULL);
+               HTTP_CURL_OPT(INFILESIZE, 0);
+       }
 }
 /* }}} */
 
+PHP_HTTP_API void _http_request_set_progress_callback(http_request *request, zval *cb)
+{
+       TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
+       
+       if (request->_progress_callback) {
+               zval_ptr_dtor(&request->_progress_callback);
+       }
+       if (cb) {
+               ZVAL_ADDREF(cb);
+       }
+       request->_progress_callback = cb;
+}
+
+/* {{{ STATUS http_request_prepare(http_request *, HashTable *) */
 PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *options)
 {
        zval *zoption;
@@ -342,15 +386,18 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
        
        HTTP_CHECK_CURL_INIT(request->ch, curl_easy_init(), return FAILURE);
        
+       http_request_defaults(request);
+       
        /* set options */
        HTTP_CURL_OPT(DEBUGDATA, request);
        HTTP_CURL_OPT(URL, request->url);
 
-       /* progress callback * /
+       /* progress callback */
        if ((zoption = http_request_option(request, options, "onprogress", 0))) {
                HTTP_CURL_OPT(NOPROGRESS, 0);
+               HTTP_CURL_OPT(PROGRESSDATA, request);
                HTTP_CURL_OPT(PROGRESSFUNCTION, http_curl_progress_callback);
-               HTTP_CURL_OPT(PROGRESSDATA,  http_request_callback_data(zoption));
+               http_request_set_progress_callback(request, zoption);
        }
 
        /* proxy */
@@ -388,15 +435,6 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
                HTTP_CURL_OPT(HTTPAUTH, Z_LVAL_P(zoption));
        }
 
-       /* compress, empty string enables all supported if libcurl was build with zlib support */
-       if ((zoption = http_request_option(request, options, "compress", IS_BOOL)) && Z_LVAL_P(zoption)) {
-#ifdef HTTP_HAVE_CURL_ZLIB
-               HTTP_CURL_OPT(ENCODING, "gzip, deflate");
-#else
-               HTTP_CURL_OPT(ENCODING, "gzip;q=1.0, deflate;q=0.5, *;q=0.1");
-#endif
-       }
-
        /* redirects, defaults to 0 */
        if ((zoption = http_request_option(request, options, "redirect", IS_LONG))) {
                HTTP_CURL_OPT(FOLLOWLOCATION, Z_LVAL_P(zoption) ? 1 : 0);
@@ -417,29 +455,30 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
        }
 
        /* additional headers, array('name' => 'value') */
+       if (request->_cache.headers) {
+               curl_slist_free_all(request->_cache.headers);
+               request->_cache.headers = NULL;
+       }
        if ((zoption = http_request_option(request, options, "headers", IS_ARRAY))) {
                char *header_key;
                ulong header_idx;
                HashPosition pos;
 
-               if (request->_cache.headers) {
-                       curl_slist_free_all(request->_cache.headers);
-                       request->_cache.headers = NULL;
-               }
-               
                FOREACH_KEY(pos, zoption, header_key, header_idx) {
                        if (header_key) {
                                zval **header_val;
                                if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_P(zoption), (void **) &header_val, &pos)) {
                                        char header[1024] = {0};
-                                       zval *cpy, *val = convert_to_type_ex(IS_STRING, *header_val, &cpy);
+                                       zval val;
                                        
-                                       snprintf(header, 1023, "%s: %s", header_key, Z_STRVAL_P(val));
-                                       request->_cache.headers = curl_slist_append(request->_cache.headers, header);
+                                       val = **header_val;
+                                       zval_copy_ctor(&val);
+                                       INIT_PZVAL(&val);
+                                       convert_to_string(&val);
                                        
-                                       if (cpy) {
-                                               zval_ptr_dtor(&cpy);
-                                       }
+                                       snprintf(header, 1023, "%s: %s", header_key, Z_STRVAL(val));
+                                       request->_cache.headers = curl_slist_append(request->_cache.headers, header);
+                                       zval_dtor(&val);
                                }
 
                                /* reset */
@@ -447,39 +486,27 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
                        }
                }
        }
+       if ((zoption = http_request_option(request, options, "compress", IS_BOOL)) && Z_LVAL_P(zoption)) {
+               request->_cache.headers = curl_slist_append(request->_cache.headers, "Accept-Encoding: gzip;q=1.0,deflate;q=0.5,*;q=0.1");
+       }
+       HTTP_CURL_OPT(HTTPHEADER, request->_cache.headers);
 
        /* cookies, array('name' => 'value') */
        if ((zoption = http_request_option(request, options, "cookies", IS_ARRAY))) {
-               char *cookie_key = NULL;
-               ulong cookie_idx = 0;
-               HashPosition pos;
-               
                phpstr_dtor(&request->_cache.cookies);
-
-               FOREACH_KEY(pos, zoption, cookie_key, cookie_idx) {
-                       if (cookie_key) {
-                               zval **cookie_val;
-                               if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_P(zoption), (void **) &cookie_val, &pos)) {
-                                       zval *cpy, *val = convert_to_type_ex(IS_STRING, *cookie_val, &cpy);
-                                       
-                                       phpstr_appendf(&request->_cache.cookies, "%s=%s; ", cookie_key, Z_STRVAL_P(val));
-                                       
-                                       if (cpy) {
-                                               zval_ptr_dtor(&cpy);
-                                       }
-                               }
-
-                               /* reset */
-                               cookie_key = NULL;
-                       }
-               }
-
-               if (request->_cache.cookies.used) {
+               if (SUCCESS == http_urlencode_hash_recursive(HASH_OF(zoption), &request->_cache.cookies, "; ", sizeof("; ")-1, NULL, 0)) {
                        phpstr_fix(&request->_cache.cookies);
                        HTTP_CURL_OPT(COOKIE, request->_cache.cookies.data);
                }
        }
 
+#if LIBCURL_VERSION_NUM >= 0x070f01
+       /* reset cookies */
+       if ((zoption = http_request_option(request, options, "resetcookies", IS_BOOL)) && Z_LVAL_P(zoption)) {
+               HTTP_CURL_OPT(COOKIELIST, "ALL");
+       }
+#endif
+       
        /* session cookies */
        if ((zoption = http_request_option(request, options, "cookiesession", IS_BOOL))) {
                if (Z_LVAL_P(zoption)) {
@@ -493,6 +520,7 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
 
        /* cookiestore, read initial cookies from that file and store cookies back into that file */
        if ((zoption = http_request_option(request, options, "cookiestore", IS_STRING)) && Z_STRLEN_P(zoption)) {
+               HTTP_CHECK_OPEN_BASEDIR(Z_STRVAL_P(zoption), return FAILURE);
                HTTP_CURL_OPT(COOKIEFILE, Z_STRVAL_P(zoption));
                HTTP_CURL_OPT(COOKIEJAR, Z_STRVAL_P(zoption));
        }
@@ -541,25 +569,25 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
 
                FOREACH_KEYVAL(pos, zoption, key, idx, param) {
                        if (key) {
-                               HTTP_CURL_OPT_SSL_STRING(CERT);
-                               HTTP_CURL_OPT_SSL_STRING(CERTTYPE);
-                               HTTP_CURL_OPT_SSL_STRING(CERTPASSWD);
+                               HTTP_CURL_OPT_SSL_STRING(CERT, 1);
+                               HTTP_CURL_OPT_SSL_STRING(CERTTYPE, 0);
+                               HTTP_CURL_OPT_SSL_STRING(CERTPASSWD, 0);
 
-                               HTTP_CURL_OPT_SSL_STRING(KEY);
-                               HTTP_CURL_OPT_SSL_STRING(KEYTYPE);
-                               HTTP_CURL_OPT_SSL_STRING(KEYPASSWD);
+                               HTTP_CURL_OPT_SSL_STRING(KEY, 0);
+                               HTTP_CURL_OPT_SSL_STRING(KEYTYPE, 0);
+                               HTTP_CURL_OPT_SSL_STRING(KEYPASSWD, 0);
 
-                               HTTP_CURL_OPT_SSL_STRING(ENGINE);
+                               HTTP_CURL_OPT_SSL_STRING(ENGINE, 0);
                                HTTP_CURL_OPT_SSL_LONG(VERSION);
 
                                HTTP_CURL_OPT_SSL_LONG_(VERIFYPEER);
                                HTTP_CURL_OPT_SSL_LONG_(VERIFYHOST);
-                               HTTP_CURL_OPT_SSL_STRING_(CIPHER_LIST);
+                               HTTP_CURL_OPT_SSL_STRING_(CIPHER_LIST, 0);
 
-                               HTTP_CURL_OPT_STRING(CAINFO);
-                               HTTP_CURL_OPT_STRING(CAPATH);
-                               HTTP_CURL_OPT_STRING(RANDOM_FILE);
-                               HTTP_CURL_OPT_STRING(EGDSOCKET);
+                               HTTP_CURL_OPT_STRING(CAINFO, 1);
+                               HTTP_CURL_OPT_STRING(CAPATH, 1);
+                               HTTP_CURL_OPT_STRING(RANDOM_FILE, 1);
+                               HTTP_CURL_OPT_STRING(EGDSOCKET, 1);
 
                                /* reset key */
                                key = NULL;
@@ -627,21 +655,23 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
 }
 /* }}} */
 
+/* {{{ void http_request_exec(http_request *) */
 PHP_HTTP_API void _http_request_exec(http_request *request)
 {
        CURLcode result;
        TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
        
        if (CURLE_OK != (result = curl_easy_perform(request->ch))) {
-               http_error_ex(HE_WARNING, HTTP_E_REQUEST, "%s (%s)", curl_easy_strerror(result), request->url);
+               http_error_ex(HE_WARNING, HTTP_E_REQUEST, "%s; %s (%s)", curl_easy_strerror(result), request->_error, request->url);
        }
 }
+/* }}} */
 
-/* {{{ void http_request_info(CURL *, HashTable *) */
+/* {{{ void http_request_info(http_request *, HashTable *) */
 PHP_HTTP_API void _http_request_info(http_request *request, HashTable *info)
 {
        zval array;
-       INIT_ZARR(array, &request->info);
+       INIT_ZARR(array, info);
 
        HTTP_CURL_INFO(EFFECTIVE_URL);
        HTTP_CURL_INFO(RESPONSE_CODE);
@@ -665,7 +695,6 @@ PHP_HTTP_API void _http_request_info(http_request *request, HashTable *info)
        HTTP_CURL_INFO(CONTENT_LENGTH_DOWNLOAD);
        HTTP_CURL_INFO(CONTENT_LENGTH_UPLOAD);
        HTTP_CURL_INFO(CONTENT_TYPE);
-       /*HTTP_CURL_INFO(PRIVATE);*/
        HTTP_CURL_INFO(HTTPAUTH_AVAIL);
        HTTP_CURL_INFO(PROXYAUTH_AVAIL);
        /*HTTP_CURL_INFO(OS_ERRNO);*/
@@ -673,10 +702,6 @@ PHP_HTTP_API void _http_request_info(http_request *request, HashTable *info)
 #if LIBCURL_VERSION_NUM >= 0x070e01
        HTTP_CURL_INFO_EX(COOKIELIST, cookies);
 #endif
-       
-       if (info) {
-               zend_hash_copy(info, &request->info, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
-       }
 }
 /* }}} */
 
@@ -693,11 +718,13 @@ static size_t http_curl_read_callback(void *data, size_t len, size_t n, void *ct
 }
 /* }}} */
 
-/* {{{ static int http_curl_progress_callback(void *, double, double, double, double) * /
-static int http_curl_progress_callback(void *data, double dltotal, double dlnow, double ultotal, double ulnow)
+/* {{{ static int http_curl_progress_callback(void *, double, double, double, double) */
+static int http_curl_progress_callback(void *ctx, double dltotal, double dlnow, double ultotal, double ulnow)
 {
+       int rc;
        zval *params_pass[4], params_local[4], retval;
-       HTTP_REQUEST_CALLBACK_DATA(data, zval *, func);
+       http_request *request = (http_request *) ctx;
+       TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
 
        params_pass[0] = &params_local[0];
        params_pass[1] = &params_local[1];
@@ -713,7 +740,11 @@ static int http_curl_progress_callback(void *data, double dltotal, double dlnow,
        ZVAL_DOUBLE(params_pass[2], ultotal);
        ZVAL_DOUBLE(params_pass[3], ulnow);
 
-       return call_user_function(EG(function_table), NULL, func, &retval, 4, params_pass TSRMLS_CC);
+       INIT_PZVAL(&retval);
+       ZVAL_NULL(&retval);
+       rc = call_user_function(EG(function_table), NULL, request->_progress_callback, &retval, 4, params_pass TSRMLS_CC);
+       zval_dtor(&retval);
+       return rc;
 }
 /* }}} */
 
@@ -789,9 +820,17 @@ static int http_curl_raw_callback(CURL *ch, curl_infotype type, char *data, size
 static inline zval *_http_request_option_ex(http_request *r, HashTable *options, char *key, size_t keylen, int type TSRMLS_DC)
 {
        zval **zoption;
+#ifdef ZEND_ENGINE_2
        ulong h = zend_get_hash_value(key, keylen);
-
-       if (!options || (SUCCESS != zend_hash_quick_find(options, key, keylen, h, (void **) &zoption))) {
+#endif
+       
+       if (!options || 
+#ifdef ZEND_ENGINE_2
+                       (SUCCESS != zend_hash_quick_find(options, key, keylen, h, (void **) &zoption))
+#else
+                       (SUCCESS != zend_hash_find(options, key, keylen, (void **) &zoption))
+#endif
+       ) {
                return NULL;
        }
 
@@ -809,10 +848,18 @@ static inline zval *_http_request_option_ex(http_request *r, HashTable *options,
                }
        }
        
-       ZVAL_ADDREF(*zoption);
-       _zend_hash_quick_add_or_update(&r->_cache.options, key, keylen, h, zoption, sizeof(zval *), NULL, 
-               zend_hash_quick_exists(&r->_cache.options, key, keylen, h)?HASH_UPDATE:HASH_ADD ZEND_FILE_LINE_CC);
-
+       /* cache strings */
+       if (type == IS_STRING) {
+               ZVAL_ADDREF(*zoption);
+#ifdef ZEND_ENGINE_2
+               _zend_hash_quick_add_or_update(&r->_cache.options, key, keylen, h, zoption, sizeof(zval *), NULL, 
+                       zend_hash_quick_exists(&r->_cache.options, key, keylen, h)?HASH_UPDATE:HASH_ADD ZEND_FILE_LINE_CC);
+#else
+               zend_hash_add_or_update(&r->_cache.options, key, keylen, zoption, sizeof(zval *), NULL,
+                       zend_hash_exists(&r->_cache.options, key, keylen)?HASH_UPDATE:HASH_ADD);
+#endif
+       }
+       
        return *zoption;
 }
 /* }}} */