From 935edd6c43530eb35c79d8ec8e0920f7d07f5f62 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Tue, 3 May 2005 08:42:49 +0000 Subject: [PATCH] - add progress callback --- http_curl_api.c | 30 ++++++++++++++++++++++++++++++ http_functions.c | 1 + 2 files changed, 31 insertions(+) diff --git a/http_curl_api.c b/http_curl_api.c index e2d5911..aa40ba6 100644 --- a/http_curl_api.c +++ b/http_curl_api.c @@ -90,6 +90,7 @@ static void _http_curl_setopts(CURL *ch, const char *url, HashTable *options, ph static inline zval *_http_curl_getopt_ex(HashTable *options, char *key, size_t keylen, int type TSRMLS_DC); static size_t http_curl_callback(char *, size_t, size_t, void *); +static int http_curl_progress(void *, double, double, double, double); #define http_curl_getinfo(c, h) _http_curl_getinfo((c), (h) TSRMLS_CC) static inline void _http_curl_getinfo(CURL *ch, HashTable *info TSRMLS_DC); @@ -110,6 +111,26 @@ static size_t http_curl_callback(char *buf, size_t len, size_t n, void *s) } /* }}} */ +/* {{{ static int http_curl_progress(void *, double, double, double, double) */ +static int http_curl_progress(void *data, double dltotal, double dlnow, double ultotal, double ulnow) +{ + int i; + zval *params_pass[4], params_local[4], retval, *func = (zval *) data; + TSRMLS_FETCH(); + + for (i = 0; i < 5; ++i) { + params_pass[i] = ¶ms_local[i]; + } + + ZVAL_DOUBLE(params_pass[0], dltotal); + ZVAL_DOUBLE(params_pass[1], dlnow); + ZVAL_DOUBLE(params_pass[2], ultotal); + ZVAL_DOUBLE(params_pass[3], ulnow); + + return call_user_function(EG(function_table), NULL, func, &retval, 4, params_pass TSRMLS_CC); +} +/* }}} */ + /* {{{ static inline zval *http_curl_getopt(HashTable *, char *, size_t, int) */ static inline zval *_http_curl_getopt_ex(HashTable *options, char *key, size_t keylen, int type TSRMLS_DC) { @@ -169,6 +190,15 @@ static void _http_curl_setopts(CURL *ch, const char *url, HashTable *options, ph HTTP_CURL_OPT(ERRORBUFFER, HTTP_G(curlerr)); #endif + /* progress callback */ + if (zoption = http_curl_getopt(options, "onprogress", 0)) { + HTTP_CURL_OPT(NOPROGRESS, 0); + HTTP_CURL_OPT(PROGRESSFUNCTION, http_curl_progress); + HTTP_CURL_OPT(PROGRESSDATA, zoption); + } else { + HTTP_CURL_OPT(NOPROGRESS, 1); + } + /* proxy */ if (zoption = http_curl_getopt(options, "proxyhost", IS_STRING)) { HTTP_CURL_OPT(PROXY, http_curl_copystr(Z_STRVAL_P(zoption))); diff --git a/http_functions.c b/http_functions.c index 9bf3399..61fa519 100644 --- a/http_functions.c +++ b/http_functions.c @@ -670,6 +670,7 @@ PHP_FUNCTION(http_get_request_headers) * - lastmodified: int, timestamp for If-(Un)Modified-Since header * - timeout: int, seconds the request may take * - connecttimeout: int, seconds the connect may take + * - onprogress: mixed, progress callback * * * The optional third parameter will be filled with some additional information -- 2.30.2