summaryrefslogtreecommitdiff
path: root/src/http.cpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2022-07-07 03:09:54 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2022-07-07 03:09:54 -0400
commit41776fbd023df1c4a70ffa46e8f81c6aea9f7b7f (patch)
tree12529298666543801a0e46c1fa83099e69968ddc /src/http.cpp
parent5c7631e71382b0c1727bd8e1487a7e41feaf2efc (diff)
downloadabaddon-portaudio-41776fbd023df1c4a70ffa46e8f81c6aea9f7b7f.tar.gz
abaddon-portaudio-41776fbd023df1c4a70ffa46e8f81c6aea9f7b7f.zip
add upload progress bar
Diffstat (limited to 'src/http.cpp')
-rw-r--r--src/http.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/http.cpp b/src/http.cpp
index 14fe3f5..f4d45a2 100644
--- a/src/http.cpp
+++ b/src/http.cpp
@@ -36,8 +36,11 @@ request::request(request &&other) noexcept
, m_header_list(std::exchange(other.m_header_list, nullptr))
, m_error_buf(other.m_error_buf)
, m_form(std::exchange(other.m_form, nullptr))
- , m_read_streams(std::move(other.m_read_streams)) {
- // i think this is correct???
+ , m_read_streams(std::move(other.m_read_streams))
+ , m_progress_callback(std::move(other.m_progress_callback)) {
+ if (m_progress_callback) {
+ curl_easy_setopt(m_curl, CURLOPT_XFERINFODATA, this);
+ }
}
request::~request() {
@@ -59,6 +62,22 @@ const char *request::get_method() const {
return m_method;
}
+size_t http_req_xferinfofunc(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) {
+ if (ultotal > 0) {
+ auto *req = reinterpret_cast<request *>(clientp);
+ req->m_progress_callback(ultotal, ulnow);
+ }
+
+ return 0;
+}
+
+void request::set_progress_callback(std::function<void(curl_off_t, curl_off_t)> func) {
+ m_progress_callback = std::move(func);
+ curl_easy_setopt(m_curl, CURLOPT_NOPROGRESS, 0L);
+ curl_easy_setopt(m_curl, CURLOPT_XFERINFOFUNCTION, http_req_xferinfofunc);
+ curl_easy_setopt(m_curl, CURLOPT_XFERINFODATA, this);
+}
+
void request::set_verify_ssl(bool verify) {
curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYPEER, verify ? 1L : 0L);
}