From: Michael Wallner Date: Sat, 31 Dec 2005 10:37:54 +0000 (+0000) Subject: - fix access of private properties X-Git-Tag: RELEASE_0_21_0~6 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=0630e63c82f6e4841577881cdd4b0c3cc4478e4c;p=m6w6%2Fext-http - fix access of private properties - fix progress callback - change onprogress callback param to be an array instead of 4 single params - add progress callback if not set and inherited request object defines onProgress() --- diff --git a/http_request_api.c b/http_request_api.c index f7d3089..8dc72dd 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -366,10 +366,16 @@ PHP_HTTP_API void _http_request_set_progress_callback(http_request *request, zva if (request->_progress_callback) { zval_ptr_dtor(&request->_progress_callback); } - if (cb) { + if ((request->_progress_callback = cb)) { ZVAL_ADDREF(cb); + HTTP_CURL_OPT(NOPROGRESS, 0); + HTTP_CURL_OPT(PROGRESSDATA, request); + HTTP_CURL_OPT(PROGRESSFUNCTION, http_curl_progress_callback); + } else { + HTTP_CURL_OPT(NOPROGRESS, 1); + HTTP_CURL_OPT(PROGRESSDATA, NULL); + HTTP_CURL_OPT(PROGRESSFUNCTION, NULL); } - request->_progress_callback = cb; } /* {{{ STATUS http_request_prepare(http_request *, HashTable *) */ @@ -389,10 +395,7 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti HTTP_CURL_OPT(URL, request->url); /* 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); + if ((zoption = http_request_option(request, options, "onprogress", -1))) { http_request_set_progress_callback(request, zoption); } @@ -713,30 +716,26 @@ 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 *ctx, double dltotal, double dlnow, double ultotal, double ulnow) { - int rc; - zval *params_pass[4], params_local[4], retval; + zval *param, retval; http_request *request = (http_request *) ctx; TSRMLS_FETCH_FROM_CTX(request->tsrm_ls); - params_pass[0] = ¶ms_local[0]; - params_pass[1] = ¶ms_local[1]; - params_pass[2] = ¶ms_local[2]; - params_pass[3] = ¶ms_local[3]; - - INIT_PZVAL(params_pass[0]); - INIT_PZVAL(params_pass[1]); - INIT_PZVAL(params_pass[2]); - INIT_PZVAL(params_pass[3]); - ZVAL_DOUBLE(params_pass[0], dltotal); - ZVAL_DOUBLE(params_pass[1], dlnow); - ZVAL_DOUBLE(params_pass[2], ultotal); - ZVAL_DOUBLE(params_pass[3], ulnow); - INIT_PZVAL(&retval); ZVAL_NULL(&retval); - rc = call_user_function(EG(function_table), NULL, request->_progress_callback, &retval, 4, params_pass TSRMLS_CC); + + MAKE_STD_ZVAL(param); + array_init(param); + add_assoc_double(param, "dltotal", dltotal); + add_assoc_double(param, "dlnow", dlnow); + add_assoc_double(param, "ultotal", ultotal); + add_assoc_double(param, "ulnow", ulnow); + + call_user_function(EG(function_table), NULL, request->_progress_callback, &retval, 1, ¶m TSRMLS_CC); + + zval_ptr_dtor(¶m); zval_dtor(&retval); - return rc; + + return 0; } /* }}} */ diff --git a/http_request_object.c b/http_request_object.c index 7567b96..6307539 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -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) @@ -518,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; diff --git a/php_http_std_defs.h b/php_http_std_defs.h index 61a5563..8824e70 100644 --- a/php_http_std_defs.h +++ b/php_http_std_defs.h @@ -248,12 +248,12 @@ typedef int STATUS; # define DCL_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n)-1, (v), (ZEND_ACC_ ##a) TSRMLS_CC) # define DCL_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n)-1, (ZEND_ACC_ ##a) TSRMLS_CC) # define UPD_PROP(o, t, n, v) UPD_PROP_EX(o, getThis(), t, n, v) -# define UPD_PROP_EX(o, this, t, n, v) zend_update_property_ ##t(o->zo.ce, this, (#n), sizeof(#n)-1, (v) TSRMLS_CC) -# define UPD_STRL(o, n, v, l) zend_update_property_stringl(o->zo.ce, getThis(), (#n), sizeof(#n)-1, (v), (l) TSRMLS_CC) +# define UPD_PROP_EX(o, this, t, n, v) zend_update_property_ ##t(OBJ_PROP_CE, this, (#n), sizeof(#n)-1, (v) TSRMLS_CC) +# define UPD_STRL(o, n, v, l) zend_update_property_stringl(OBJ_PROP_CE, getThis(), (#n), sizeof(#n)-1, (v), (l) TSRMLS_CC) # define SET_PROP(o, n, z) SET_PROP_EX(o, getThis(), n, z) -# define SET_PROP_EX(o, this, n, z) zend_update_property(o->zo.ce, this, (#n), sizeof(#n)-1, (z) TSRMLS_CC) +# define SET_PROP_EX(o, this, n, z) zend_update_property(OBJ_PROP_CE, this, (#n), sizeof(#n)-1, (z) TSRMLS_CC) # define GET_PROP(o, n) GET_PROP_EX(o, getThis(), n) -# define GET_PROP_EX(o, this, n) zend_read_property(o->zo.ce, this, (#n), sizeof(#n)-1, 0 TSRMLS_CC) +# define GET_PROP_EX(o, this, n) zend_read_property(OBJ_PROP_CE, this, (#n), sizeof(#n)-1, 0 TSRMLS_CC) # define DCL_CONST(t, n, v) zend_declare_class_constant_ ##t(ce, (n), sizeof(n)-1, (v) TSRMLS_CC)