- fix access of private properties
[m6w6/ext-http] / http_request_object.c
index f763b482898c408613dcb5fade3891035e51909c..6307539058e7c76879d78104b3b85dfe0f987994 100644 (file)
@@ -215,6 +215,7 @@ HTTP_END_ARGS;
 #define http_request_object_declare_default_properties() _http_request_object_declare_default_properties(TSRMLS_C)
 static inline void _http_request_object_declare_default_properties(TSRMLS_D);
 
+#define OBJ_PROP_CE http_request_object_ce
 zend_class_entry *http_request_object_ce;
 zend_function_entry http_request_object_fe[] = {
        HTTP_REQUEST_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
@@ -446,7 +447,7 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
                        php_stream *stream = php_stream_open_wrapper(Z_STRVAL_P(GET_PROP(obj, putFile)), "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL);
                        
                        if (stream && !php_stream_stat(stream, &ssb)) {
-                               http_request_body_init_ex(obj->request->body, HTTP_REQUEST_BODY_UPLOADFILE, stream, ssb.sb.st_size, 1);
+                               obj->request->body = http_request_body_init_ex(obj->request->body, HTTP_REQUEST_BODY_UPLOADFILE, stream, ssb.sb.st_size, 1);
                        } else {
                                status = FAILURE;
                        }
@@ -465,7 +466,9 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
                                if (Z_STRLEN_P(ctype)) {
                                        zval **headers, *opts = GET_PROP(obj, options);
                                        
-                                       if ((SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void **) &headers)) && (Z_TYPE_PP(headers) == IS_ARRAY)) {
+                                       if (    (Z_TYPE_P(opts) == IS_ARRAY) &&
+                                                       (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void **) &headers)) && 
+                                                       (Z_TYPE_PP(headers) == IS_ARRAY)) {
                                                zval **ct_header;
                                                
                                                /* only override if not already set */
@@ -478,7 +481,8 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
                                                MAKE_STD_ZVAL(headers);
                                                array_init(headers);
                                                add_assoc_stringl(headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
-                                               add_assoc_zval(opts, "headers", headers);
+                                               zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addheaders", NULL, headers);
+                                               zval_ptr_dtor(&headers);
                                        }
                                }
 
@@ -515,6 +519,23 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
                }
                
                http_request_prepare(obj->request, Z_ARRVAL_P(options));
+               
+               /* check if there's a onProgress method and add it as progress callback if one isn't already set */
+               if (zend_hash_exists(&Z_OBJCE_P(getThis())->function_table, "onprogress", sizeof("onprogress"))) {
+                       zval **entry, *pcb;
+                       
+                       if (    (Z_TYPE_P(options) != IS_ARRAY)
+                               ||      (SUCCESS != zend_hash_find(Z_ARRVAL_P(options), "onprogress", sizeof("onprogress"), (void **) &entry)
+                               ||      (!zval_is_true(*entry)))) {
+                               MAKE_STD_ZVAL(pcb);
+                               array_init(pcb);
+                               ZVAL_ADDREF(getThis());
+                               add_next_index_zval(pcb, getThis());
+                               add_next_index_stringl(pcb, "onprogress", lenof("onprogress"), 1);
+                               http_request_set_progress_callback(obj->request, pcb);
+                               zval_ptr_dtor(&pcb);
+                       }
+               }
        }
 
        return status;