From 51f3316475f649b8e17eeb95f1b46e7762345d09 Mon Sep 17 00:00:00 2001 From: pradeep kumar B Date: Mon, 20 Jun 2016 11:05:55 +0530 Subject: [capi-http] Implemented the Progress callback for download/upload requests Change-Id: I5d2137585472cd78c91b36be9bdc2b166408b228 Signed-off-by: pradeep kumar B --- src/http_transaction.c | 20 ++++++++++++++++++++ test/http_test.c | 8 ++++++++ 2 files changed, 28 insertions(+) diff --git a/src/http_transaction.c b/src/http_transaction.c index 11689da..9473985 100644 --- a/src/http_transaction.c +++ b/src/http_transaction.c @@ -143,6 +143,22 @@ size_t __http_debug_received(CURL* easy_handle, curl_infotype type, gchar* byte, return 0; } +int __progress_cb(void *user_data, double dltotal, double dlnow, double ultotal, double ulnow) +{ + __http_transaction_h *transaction = (__http_transaction_h *)user_data; + + double total_download = dltotal; + double current_download = dlnow; + double total_upload = ultotal; + double current_upload = ulnow; + + if (transaction->progress_cb) + transaction->progress_cb(transaction, total_download, current_download, + total_upload, current_upload, transaction->progress_user_data); + + return 0; +} + //LCOV_EXCL_START int http_transaction_set_authentication_info(http_transaction_h http_transaction) { @@ -346,6 +362,10 @@ int _transaction_submit(gpointer user_data) curl_easy_setopt(transaction->easy_handle, CURLOPT_READDATA, transaction); } + curl_easy_setopt(transaction->easy_handle, CURLOPT_NOPROGRESS, FALSE); + curl_easy_setopt(transaction->easy_handle, CURLOPT_PROGRESSFUNCTION, __progress_cb); + curl_easy_setopt(transaction->easy_handle, CURLOPT_PROGRESSDATA, transaction); + curl_easy_setopt(transaction->easy_handle, CURLOPT_VERBOSE, 1L); curl_easy_setopt(transaction->easy_handle, CURLOPT_DEBUGFUNCTION, __http_debug_received); curl_easy_setopt(transaction->easy_handle, CURLOPT_ERRORBUFFER, transaction->error); diff --git a/test/http_test.c b/test/http_test.c index 738d6dc..ebf32d3 100644 --- a/test/http_test.c +++ b/test/http_test.c @@ -96,6 +96,13 @@ void __transaction_aborted_cb(http_transaction_h transaction, int reason, void * DBG("aborted reason: %d\n", reason); } +void __transaction_progress_cb(http_transaction_h transaction, double download_total, double download_now, double upload_total, double upload_now, void *user_data) +{ + PRG("__transaction_progress_cb", transaction); + DBG("Download ====>: DOWN(%lf/%lf)\n", download_total, download_now); + DBG("Upload ====>: UP(%lf/%lf)\n", upload_total, upload_now); +} + void _register_callbacks(http_transaction_h transaction) { http_transaction_set_received_header_cb(transaction, __transaction_header_cb, NULL); @@ -103,6 +110,7 @@ void _register_callbacks(http_transaction_h transaction) http_transaction_set_uploaded_cb(transaction, __transaction_write_cb, NULL); http_transaction_set_completed_cb(transaction, __transaction_completed_cb, NULL); http_transaction_set_aborted_cb(transaction, __transaction_aborted_cb, NULL); + http_transaction_set_progress_cb(transaction, __transaction_progress_cb, NULL); } int test_http_init(void) -- cgit v1.2.3