remove pass_state callback flag
[m6w6/ext-http] / php_http_client.c
index de09590ffd23d2a1b1f968cc9b82f11d5dc00a6d..5aca3bce113917231e7be63815f9975a92e0b521 100644 (file)
@@ -13,6 +13,7 @@
 #include "php_http_api.h"
 
 #include <ext/spl/spl_observer.h>
+#include <ext/standard/php_array.h>
 
 PHP_HTTP_API php_http_client_t *php_http_client_init(php_http_client_t *h, php_http_client_ops_t *ops, php_http_resource_factory_t *rf, void *init_arg TSRMLS_DC)
 {
@@ -296,11 +297,8 @@ zend_object_value php_http_client_object_new_ex(zend_class_entry *ce, php_http_c
 
        o = ecalloc(1, sizeof(*o));
        zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
-#if PHP_VERSION_ID < 50339
-       zend_hash_copy(((zend_object *) o)->properties, &(ce->default_properties), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*));
-#else
        object_properties_init((zend_object *) o, ce);
-#endif
+       
        ov.handle = zend_objects_store_put(o, NULL, php_http_client_object_free, NULL TSRMLS_CC);
        ov.handlers = &php_http_client_object_handlers;
 
@@ -355,6 +353,7 @@ STATUS php_http_client_object_handle_request(zval *zclient, zval **zreq TSRMLS_D
        php_http_client_object_t *obj = zend_object_store_get_object(zclient TSRMLS_CC);
        php_http_client_progress_t *progress;
        zval *zoptions;
+       HashTable options;
 
        /* do we have a valid request? */
        if (*zreq) {
@@ -376,12 +375,19 @@ STATUS php_http_client_object_handle_request(zval *zclient, zval **zreq TSRMLS_D
        /* reset transfer info */
        zend_update_property_null(php_http_client_class_entry, zclient, ZEND_STRL("transferInfo") TSRMLS_CC);
 
+
        /* set client options */
+       zend_hash_init(&options, 0, NULL, ZVAL_PTR_DTOR, 0);
        zoptions = zend_read_property(php_http_client_class_entry, zclient, ZEND_STRL("options"), 0 TSRMLS_CC);
-       php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_SETTINGS, Z_ARRVAL_P(zoptions));
-       /* set request options */
+       if (Z_TYPE_P(zoptions) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(zoptions))) {
+               php_array_merge(&options, Z_ARRVAL_P(zoptions), 1 TSRMLS_CC);
+       }
        zoptions = zend_read_property(php_http_client_request_get_class_entry(), *zreq, ZEND_STRL("options"), 0 TSRMLS_CC);
-       php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_SETTINGS, Z_ARRVAL_P(zoptions));
+       if (Z_TYPE_P(zoptions) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(zoptions))) {
+               php_array_merge(&options, Z_ARRVAL_P(zoptions), 1 TSRMLS_CC);
+       }
+       php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_SETTINGS, &options);
+       zend_hash_destroy(&options);
 
        /* set progress callback */
        if (SUCCESS == php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO, &progress)) {
@@ -389,7 +395,6 @@ STATUS php_http_client_object_handle_request(zval *zclient, zval **zreq TSRMLS_D
                        php_http_client_progress_callback_t *callback = emalloc(sizeof(*callback));
 
                        callback->type = PHP_HTTP_CLIENT_PROGRESS_CALLBACK_USER;
-                       callback->pass_state = 0;
                        MAKE_STD_ZVAL(callback->func.user);
                        array_init(callback->func.user);
                        Z_ADDREF_P(zclient);
@@ -422,10 +427,10 @@ STATUS php_http_client_object_handle_response(zval *zclient TSRMLS_DC)
        zval_ptr_dtor(&info);
 
        if ((msg = obj->client->response.message)) {
-               /* FIXME: update history */
                if (i_zend_is_true(zend_read_property(php_http_client_class_entry, zclient, ZEND_STRL("recordHistory"), 0 TSRMLS_CC))) {
                        zval *new_hist, *old_hist = zend_read_property(php_http_client_class_entry, zclient, ZEND_STRL("history"), 0 TSRMLS_CC);
-                       zend_object_value ov = php_http_client_object_message(zclient, php_http_message_copy(msg, NULL) TSRMLS_CC);
+                       php_http_message_t *zipped = php_http_message_zip(obj->client->response.message, obj->client->request.message);
+                       zend_object_value ov = php_http_client_object_message(zclient, zipped TSRMLS_CC);
 
                        MAKE_STD_ZVAL(new_hist);
                        ZVAL_OBJVAL(new_hist, ov, 0);
@@ -461,7 +466,7 @@ STATUS php_http_client_object_handle_response(zval *zclient TSRMLS_DC)
 
                        /* update the actual request message */
                        MAKE_STD_ZVAL(message);
-                       ZVAL_OBJVAL(message, php_http_message_object_new_ex(php_http_message_get_class_entry(), php_http_message_copy_ex(msg, NULL, 0), NULL TSRMLS_CC), 0);
+                       ZVAL_OBJVAL(message, php_http_message_object_new_ex(php_http_message_get_class_entry(), msg, NULL TSRMLS_CC), 0);
                        zend_update_property(php_http_client_class_entry, zclient, ZEND_STRL("requestMessage"), message TSRMLS_CC);
                        zval_ptr_dtor(&message);
                        obj->client->request.message = php_http_message_init(NULL, 0 TSRMLS_CC);
@@ -774,7 +779,7 @@ PHP_METHOD(HttpClient, addCookies)
        zval *opts = NULL;
 
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) {
-               php_http_client_options_set_subr(getThis(), ZEND_STRS("ssl"), opts, 0 TSRMLS_CC);
+               php_http_client_options_set_subr(getThis(), ZEND_STRS("cookies"), opts, 0 TSRMLS_CC);
 
                RETVAL_ZVAL(getThis(), 1, 0);
        }
@@ -919,7 +924,6 @@ PHP_METHOD(HttpClient, request)
 
        with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
                if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a!z!a!/", &meth_str, &meth_len, &url_str, &url_len, &zheader, &zbody, &zoptions)) {
-                       php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
                        php_http_message_object_t *msg_obj;
                        zend_object_value ov;
                        zval *req, *res = NULL;
@@ -958,7 +962,7 @@ PHP_METHOD(HttpClient, send)
        RETVAL_FALSE;
 
        with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
-               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O!", &zreq, php_http_client_request_get_class_entry())) {
+               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O!", &zreq, php_http_client_request_get_class_entry())) {
                        if (SUCCESS == php_http_client_object_handle_request(getThis(), &zreq TSRMLS_CC)) {
                                php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
                                php_http_message_object_t *req = zend_object_store_get_object(zreq TSRMLS_CC);
@@ -979,7 +983,7 @@ PHP_METHOD(HttpClient, send)
 
 PHP_MINIT_FUNCTION(http_client)
 {
-       PHP_HTTP_REGISTER_CLASS(http\\Client, AbstractClient, http_client, php_http_object_get_class_entry(), ZEND_ACC_ABSTRACT);
+       PHP_HTTP_REGISTER_CLASS(http\\Client, AbstractClient, http_client, php_http_object_get_class_entry(), ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
        php_http_client_class_entry->create_object = php_http_client_object_new;
        memcpy(&php_http_client_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
        php_http_client_object_handlers.clone_obj = php_http_client_object_clone;