* fix header ids
[m6w6/ext-http] / http_curl_api.c
index 7a53beb10c471cfefd67d869a767e6b9bacfda4e..0669db4d22f6d9379f5f18872f9a288aa64b5879 100644 (file)
 
 ZEND_DECLARE_MODULE_GLOBALS(http)
 
+#if LIBCURL_VERSION_NUM >= 0x070c01
+#      define http_curl_reset(ch) curl_easy_reset(ch)
+#else
+#      define http_curl_reset(ch)
+#endif
+
 #define http_curl_startup(ch, clean_curl, URL, options) \
        if (!ch) { \
                if (!(ch = curl_easy_init())) { \
@@ -50,10 +56,23 @@ ZEND_DECLARE_MODULE_GLOBALS(http)
                        return FAILURE; \
                } \
                clean_curl = 1; \
+       } else { \
+               http_curl_reset(ch); \
        } \
        http_curl_initbuf(); \
        http_curl_setopts(ch, URL, options);
 
+#define http_curl_perform(ch, clean_curl) \
+       { \
+               CURLcode result; \
+               if (CURLE_OK != (result = curl_easy_perform(ch))) { \
+                       http_curl_cleanup(ch, clean_curl); \
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not perform request: %s", curl_easy_strerror(result)); \
+                       return FAILURE; \
+               } \
+       }
+
+
 
 #define http_curl_cleanup(ch, clean_curl) \
        http_curl_freestr(); \
@@ -203,7 +222,7 @@ static inline void _http_curl_setopts(CURL *ch, const char *url, HashTable *opti
        curl_easy_setopt(ch, CURLOPT_AUTOREFERER, 1);
        curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, http_curl_body_callback);
        curl_easy_setopt(ch, CURLOPT_HEADERFUNCTION, http_curl_hdrs_callback);
-#if defined(ZTS) && (LIBCURL_VERSION_NUM >= 71000)
+#if defined(ZTS) && (LIBCURL_VERSION_NUM >= 0x070a00)
        curl_easy_setopt(ch, CURLOPT_NOSIGNAL, 1);
 #endif
 
@@ -222,7 +241,7 @@ static inline void _http_curl_setopts(CURL *ch, const char *url, HashTable *opti
                if (zoption = http_curl_getopt1(options, "proxyauth", IS_STRING)) {
                        curl_easy_setopt(ch, CURLOPT_PROXYUSERPWD, http_curl_copystr(Z_STRVAL_P(zoption)));
                }
-#if LIBCURL_VERSION_NUM >= 71007
+#if LIBCURL_VERSION_NUM >= 0x070a07
                /* auth method */
                if (zoption = http_curl_getopt1(options, "proxyauthtype", IS_LONG)) {
                        curl_easy_setopt(ch, CURLOPT_PROXYAUTH, Z_LVAL_P(zoption));
@@ -234,7 +253,7 @@ static inline void _http_curl_setopts(CURL *ch, const char *url, HashTable *opti
        if (zoption = http_curl_getopt1(options, "interface", IS_STRING)) {
                curl_easy_setopt(ch, CURLOPT_INTERFACE, http_curl_copystr(Z_STRVAL_P(zoption)));
        }
-       
+
        /* another port */
        if (zoption = http_curl_getopt1(options, "port", IS_LONG)) {
                curl_easy_setopt(ch, CURLOPT_PORT, Z_LVAL_P(zoption));
@@ -244,7 +263,7 @@ static inline void _http_curl_setopts(CURL *ch, const char *url, HashTable *opti
        if (zoption = http_curl_getopt1(options, "httpauth", IS_STRING)) {
                curl_easy_setopt(ch, CURLOPT_USERPWD, http_curl_copystr(Z_STRVAL_P(zoption)));
        }
-#if LIBCURL_VERSION_NUM >= 71006
+#if LIBCURL_VERSION_NUM >= 0x070a06
        if (zoption = http_curl_getopt1(options, "httpauthtype", IS_LONG)) {
                curl_easy_setopt(ch, CURLOPT_HTTPAUTH, Z_LVAL_P(zoption));
        }
@@ -350,7 +369,7 @@ static inline void _http_curl_setopts(CURL *ch, const char *url, HashTable *opti
        if (zoption = http_curl_getopt1(options, "maxfilesize", IS_LONG)) {
                curl_easy_setopt(ch, CURLOPT_MAXFILESIZE, Z_LVAL_P(zoption));
        }
-       
+
        /* lastmodified */
        if (zoption = http_curl_getopt1(options, "lastmodified", IS_LONG)) {
                curl_easy_setopt(ch, CURLOPT_TIMECONDITION, range_req ? CURL_TIMECOND_IFUNMODSINCE : CURL_TIMECOND_IFMODSINCE);
@@ -409,14 +428,14 @@ static inline void _http_curl_getinfo(CURL *ch, HashTable *info TSRMLS_DC)
 
        HTTP_CURL_INFO(EFFECTIVE_URL);
 
-#if LIBCURL_VERSION_NUM >= 71007
+#if LIBCURL_VERSION_NUM >= 0x070a07
        HTTP_CURL_INFO(RESPONSE_CODE);
 #else
        HTTP_CURL_INFO_EX(HTTP_CODE, RESPONSE_CODE);
 #endif
        HTTP_CURL_INFO(HTTP_CONNECTCODE);
 
-#if LIBCURL_VERSION_NUM >= 70500
+#if LIBCURL_VERSION_NUM >= 0x070500
        HTTP_CURL_INFO(FILETIME);
 #endif
        HTTP_CURL_INFO(TOTAL_TIME);
@@ -424,7 +443,7 @@ static inline void _http_curl_getinfo(CURL *ch, HashTable *info TSRMLS_DC)
        HTTP_CURL_INFO(CONNECT_TIME);
        HTTP_CURL_INFO(PRETRANSFER_TIME);
        HTTP_CURL_INFO(STARTTRANSFER_TIME);
-#if LIBCURL_VERSION_NUM >= 70907
+#if LIBCURL_VERSION_NUM >= 0x070907
        HTTP_CURL_INFO(REDIRECT_TIME);
        HTTP_CURL_INFO(REDIRECT_COUNT);
 #endif
@@ -438,8 +457,8 @@ static inline void _http_curl_getinfo(CURL *ch, HashTable *info TSRMLS_DC)
        HTTP_CURL_INFO(REQUEST_SIZE);
 
        HTTP_CURL_INFO(SSL_VERIFYRESULT);
-#if LIBCURL_VERSION_NUM >= 71203
-       /*HTTP_CURL_INFO(SSL_ENGINES); 
+#if LIBCURL_VERSION_NUM >= 0x070c03
+       /*HTTP_CURL_INFO(SSL_ENGINES);
                todo: CURLINFO_SLIST */
 #endif
 
@@ -447,20 +466,20 @@ static inline void _http_curl_getinfo(CURL *ch, HashTable *info TSRMLS_DC)
        HTTP_CURL_INFO(CONTENT_LENGTH_UPLOAD);
        HTTP_CURL_INFO(CONTENT_TYPE);
 
-#if LIBCURL_VERSION_NUM >= 71003
+#if LIBCURL_VERSION_NUM >= 0x070a03
        /*HTTP_CURL_INFO(PRIVATE);*/
 #endif
 
-#if LIBCURL_VERSION_NUM >= 71008
+#if LIBCURL_VERSION_NUM >= 0x070a08
        HTTP_CURL_INFO(HTTPAUTH_AVAIL);
        HTTP_CURL_INFO(PROXYAUTH_AVAIL);
 #endif
 
-#if LIBCURL_VERSION_NUM >= 71202
+#if LIBCURL_VERSION_NUM >= 0x070c02
        /*HTTP_CURL_INFO(OS_ERRNO);*/
 #endif
 
-#if LIBCURL_VERSION_NUM >= 71203
+#if LIBCURL_VERSION_NUM >= 0x070c03
        HTTP_CURL_INFO(NUM_CONNECTS);
 #endif
 }
@@ -474,13 +493,8 @@ PHP_HTTP_API STATUS _http_get_ex(CURL *ch, const char *URL, HashTable *options,
 
        http_curl_startup(ch, clean_curl, URL, options);
        curl_easy_setopt(ch, CURLOPT_HTTPGET, 1);
-
-       if (CURLE_OK != curl_easy_perform(ch)) {
-               http_curl_cleanup(ch, clean_curl);
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not perform request");
-               return FAILURE;
-       }
-
+       http_curl_perform(ch, clean_curl);
+       
        if (info) {
                http_curl_getinfo(ch, info);
        }
@@ -499,12 +513,7 @@ PHP_HTTP_API STATUS _http_head_ex(CURL *ch, const char *URL, HashTable *options,
 
        http_curl_startup(ch, clean_curl, URL, options);
        curl_easy_setopt(ch, CURLOPT_NOBODY, 1);
-
-       if (CURLE_OK != curl_easy_perform(ch)) {
-               http_curl_cleanup(ch, clean_curl);
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not perform request");
-               return FAILURE;
-       }
+       http_curl_perform(ch, clean_curl);
 
        if (info) {
                http_curl_getinfo(ch, info);
@@ -527,12 +536,7 @@ PHP_HTTP_API STATUS _http_post_data_ex(CURL *ch, const char *URL, char *postdata
        curl_easy_setopt(ch, CURLOPT_POST, 1);
        curl_easy_setopt(ch, CURLOPT_POSTFIELDS, postdata);
        curl_easy_setopt(ch, CURLOPT_POSTFIELDSIZE, postdata_len);
-
-       if (CURLE_OK != curl_easy_perform(ch)) {
-               http_curl_cleanup(ch, clean_curl);
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not perform request");
-               return FAILURE;
-       }
+       http_curl_perform(ch, clean_curl);
 
        if (info) {
                http_curl_getinfo(ch, info);
@@ -583,12 +587,7 @@ PHP_HTTP_API STATUS _http_post_curldata_ex(CURL *ch, const char *URL,
        http_curl_startup(ch, clean_curl, URL, options);
        curl_easy_setopt(ch, CURLOPT_POST, 1);
        curl_easy_setopt(ch, CURLOPT_HTTPPOST, curldata);
-
-       if (CURLE_OK != curl_easy_perform(ch)) {
-               http_curl_cleanup(ch, clean_curl);
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not perform request");
-               return FAILURE;
-       }
+       http_curl_perform(ch, clean_curl);
 
        if (info) {
                http_curl_getinfo(ch, info);