X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_curl_api.c;h=aa40ba6b94a2d112e8c86ce3053a5f11e560449b;hp=e2d59110b8cc9123af0613c1cbd6e9f10f60f1a0;hb=935edd6c43530eb35c79d8ec8e0920f7d07f5f62;hpb=d04466a4756cc1ccf2fc17fa807ee0d372d912a7 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)));