fixed config.w32 for build with curl enabled
[m6w6/ext-http] / php_http_curl_client.c
index b2beba6bc310c4e5a1ec55276e8774d9a862adb9..c0930db8866aecd1f6a6233a145f5c61cb266fa8 100644 (file)
@@ -10,9 +10,6 @@
     +--------------------------------------------------------------------+
 */
 
-#include <php/Zend/zend.h>
-#include <php/Zend/zend_API.h>
-
 #include "php_http_api.h"
 
 /* resource_factory ops */
@@ -22,7 +19,7 @@ static void *php_http_curl_ctor(void *opaque TSRMLS_DC)
        void *ch;
 
        if ((ch = curl_easy_init())) {
-               get_storage(ch);
+               php_http_curl_client_get_storage(ch);
                return ch;
        }
        return NULL;
@@ -34,7 +31,7 @@ static void *php_http_curl_copy(void *opaque, void *handle TSRMLS_DC)
 
        if ((ch = curl_easy_duphandle(handle))) {
                curl_easy_reset(ch);
-               get_storage(ch);
+               php_http_curl_client_get_storage(ch);
                return ch;
        }
        return NULL;
@@ -42,7 +39,7 @@ static void *php_http_curl_copy(void *opaque, void *handle TSRMLS_DC)
 
 static void php_http_curl_dtor(void *opaque, void *handle TSRMLS_DC)
 {
-       php_http_curl_client_storage_t *st = get_storage(handle);
+       php_http_curl_client_storage_t *st = php_http_curl_client_get_storage(handle);
 
        curl_easy_cleanup(handle);
 
@@ -359,7 +356,7 @@ static STATUS get_info(CURL *ch, HashTable *info)
                }
        }
 #endif
-       add_assoc_string_ex(&array, "error", sizeof("error"), get_storage(ch)->errorbuffer, 1);
+       add_assoc_string_ex(&array, "error", sizeof("error"), php_http_curl_client_get_storage(ch)->errorbuffer, 1);
 
        return SUCCESS;
 }
@@ -391,7 +388,7 @@ static STATUS php_http_curl_client_option_set_cookiestore(php_http_option_t *opt
        CURL *ch = curl->handle;
 
        if (val) {
-               php_http_curl_client_storage_t *storage = get_storage(curl->handle);
+               php_http_curl_client_storage_t *storage = php_http_curl_client_get_storage(curl->handle);
 
                if (storage->cookiestore) {
                        pefree(storage->cookiestore, 1);
@@ -439,8 +436,8 @@ static STATUS php_http_curl_client_option_set_cookies(php_http_option_t *opt, zv
                        }
 
                        php_http_buffer_fix(&curl->options.cookies);
-                       if (PHP_HTTP_BUFFER_LEN(&curl->options.cookies)) {
-                               if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_COOKIE, PHP_HTTP_BUFFER_VAL(&curl->options.cookies))) {
+                       if (curl->options.cookies.used) {
+                               if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_COOKIE, curl->options.cookies.data)) {
                                        return FAILURE;
                                }
                        }
@@ -509,7 +506,7 @@ static STATUS php_http_curl_client_option_set_etag(php_http_option_t *opt, zval
        php_http_buffer_init(&header);
        php_http_buffer_appendf(&header, is_quoted?"%s: %s":"%s: \"%s\"", curl->options.range_request?"If-Match":"If-None-Match", Z_STRVAL_P(val));
        php_http_buffer_fix(&header);
-       curl->options.headers = curl_slist_append(curl->options.headers, PHP_HTTP_BUFFER_VAL(&header));
+       curl->options.headers = curl_slist_append(curl->options.headers, header.data);
        php_http_buffer_dtor(&header);
        return SUCCESS;
 }
@@ -529,7 +526,7 @@ static STATUS php_http_curl_client_option_set_range(php_http_option_t *opt, zval
 
                FOREACH_VAL(pos, val, rr) {
                        if (Z_TYPE_PP(rr) == IS_ARRAY) {
-                               if (2 == php_http_array_list(*rr TSRMLS_CC, 2, &rb, &re)) {
+                               if (2 == php_http_array_list(Z_ARRVAL_PP(rr) TSRMLS_CC, 2, &rb, &re)) {
                                        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_ztyp(IS_LONG, *rb);
@@ -546,14 +543,14 @@ static STATUS php_http_curl_client_option_set_range(php_http_option_t *opt, zval
                        }
                }
 
-               if (PHP_HTTP_BUFFER_LEN(&curl->options.ranges)) {
+               if (curl->options.ranges.used) {
                        curl->options.range_request = 1;
                        /* ditch last comma */
-                       PHP_HTTP_BUFFER_VAL(&curl->options.ranges)[PHP_HTTP_BUFFER_LEN(&curl->options.ranges)-- -1] = '\0';
+                       curl->options.ranges.data[curl->options.ranges.used - 1] = '\0';
                }
        }
 
-       if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_RANGE, PHP_HTTP_BUFFER_VAL(&curl->options.ranges))) {
+       if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_RANGE, curl->options.ranges.data)) {
                return FAILURE;
        }
        return SUCCESS;
@@ -617,7 +614,7 @@ static STATUS php_http_curl_client_option_set_portrange(php_http_option_t *opt,
        if (val && Z_TYPE_P(val) != IS_NULL) {
                zval **z_port_start, *zps_copy = NULL, **z_port_end, *zpe_copy = NULL;
 
-               switch (php_http_array_list(val TSRMLS_CC, 2, &z_port_start, &z_port_end)) {
+               switch (php_http_array_list(Z_ARRVAL_P(val) TSRMLS_CC, 2, &z_port_start, &z_port_end)) {
                case 2:
                        zps_copy = php_http_ztyp(IS_LONG, *z_port_start);
                        zpe_copy = php_http_ztyp(IS_LONG, *z_port_end);
@@ -645,6 +642,7 @@ static STATUS php_http_curl_client_option_set_portrange(php_http_option_t *opt,
        return SUCCESS;
 }
 
+#if PHP_HTTP_CURL_VERSION(7,21,3)
 static STATUS php_http_curl_client_option_set_resolve(php_http_option_t *opt, zval *val, void *userdata)
 {
        php_http_client_t *h = userdata;
@@ -673,6 +671,7 @@ static STATUS php_http_curl_client_option_set_resolve(php_http_option_t *opt, zv
        }
        return SUCCESS;
 }
+#endif
 
 static void php_http_curl_client_options_init(php_http_options_t *registry TSRMLS_DC)
 {
@@ -1095,7 +1094,7 @@ static STATUS php_http_curl_client_reset(php_http_client_t *h)
        CURL *ch = curl->handle;
        php_http_curl_client_storage_t *st;
 
-       if ((st = get_storage(ch))) {
+       if ((st = php_http_curl_client_get_storage(ch))) {
                if (st->url) {
                        pefree(st->url, 1);
                        st->url = NULL;
@@ -1142,7 +1141,7 @@ PHP_HTTP_API STATUS php_http_curl_client_prepare(php_http_client_t *h, php_http_
 {
        size_t body_size;
        php_http_curl_client_t *curl = h->ctx;
-       php_http_curl_client_storage_t *storage = get_storage(curl->handle);
+       php_http_curl_client_storage_t *storage = php_http_curl_client_get_storage(curl->handle);
        TSRMLS_FETCH_FROM_CTX(h->ts);
 
        /* request url */
@@ -1201,7 +1200,7 @@ PHP_HTTP_API STATUS php_http_curl_client_prepare(php_http_client_t *h, php_http_
 
                                php_http_buffer_appendf(&header, "%s: %s", header_key.str, Z_STRVAL_P(header_cpy));
                                php_http_buffer_fix(&header);
-                               curl->options.headers = curl_slist_append(curl->options.headers, PHP_HTTP_BUFFER_VAL(&header));
+                               curl->options.headers = curl_slist_append(curl->options.headers, header.data);
                                php_http_buffer_reset(&header);
 
                                zval_ptr_dtor(&header_cpy);
@@ -1212,16 +1211,16 @@ PHP_HTTP_API STATUS php_http_curl_client_prepare(php_http_client_t *h, php_http_
        }
 
        /* attach request body */
-       if ((body_size = php_http_message_body_size(&msg->body))) {
+       if ((body_size = php_http_message_body_size(msg->body))) {
                /* RFC2616, section 4.3 (para. 4) states that »a message-body MUST NOT be included in a request if the
                 * specification of the request method (section 5.1.1) does not allow sending an entity-body in request.«
                 * Following the clause in section 5.1.1 (para. 2) that request methods »MUST be implemented with the
                 * same semantics as those specified in section 9« reveal that not any single defined HTTP/1.1 method
                 * does not allow a request body.
                 */
-               php_stream_rewind(php_http_message_body_stream(&msg->body));
-               curl_easy_setopt(curl->handle, CURLOPT_IOCTLDATA, &msg->body);
-               curl_easy_setopt(curl->handle, CURLOPT_READDATA, &msg->body);
+               php_stream_rewind(php_http_message_body_stream(msg->body));
+               curl_easy_setopt(curl->handle, CURLOPT_IOCTLDATA, msg->body);
+               curl_easy_setopt(curl->handle, CURLOPT_READDATA, msg->body);
                curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, body_size);
                curl_easy_setopt(curl->handle, CURLOPT_POSTFIELDSIZE, body_size);
        }
@@ -1234,7 +1233,7 @@ static STATUS php_http_curl_client_exec(php_http_client_t *h, php_http_message_t
        uint tries = 0;
        CURLcode result;
        php_http_curl_client_t *curl = h->ctx;
-       php_http_curl_client_storage_t *storage = get_storage(curl->handle);
+       php_http_curl_client_storage_t *storage = php_http_curl_client_get_storage(curl->handle);
        TSRMLS_FETCH_FROM_CTX(h->ts);
 
        if (SUCCESS != php_http_curl_client_prepare(h, msg)) {
@@ -1302,7 +1301,7 @@ static STATUS php_http_curl_client_setopt(php_http_client_t *h, php_http_client_
 
                case PHP_HTTP_CLIENT_OPT_COOKIES_ENABLE:
                        /* are cookies already enabled anyway? */
-                       if (!get_storage(curl->handle)->cookiestore) {
+                       if (!php_http_curl_client_get_storage(curl->handle)->cookiestore) {
                                if (CURLE_OK != curl_easy_setopt(curl->handle, CURLOPT_COOKIEFILE, "")) {
                                        return FAILURE;
                                }