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 *) */
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);
}
/* {{{ 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;
}
/* }}} */
#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)
}
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;
# 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)