Mercurial > minori
comparison src/core/http.cc @ 175:9b10175be389
dep/json: update to v3.11.3
anime/db: save anime list to database, very much untested and likely won't work as intended
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 30 Nov 2023 13:52:26 -0500 |
parents | f5940a575d83 |
children | 53211cb1e7f5 |
comparison
equal
deleted
inserted
replaced
174:f88eda79c60a | 175:9b10175be389 |
---|---|
1 #include "core/http.h" | 1 #include "core/http.h" |
2 #include "core/session.h" | 2 #include "core/session.h" |
3 #include <QByteArray> | 3 #include <QByteArray> |
4 #include <QMessageBox> | |
5 #include <curl/curl.h> | 4 #include <curl/curl.h> |
6 #include <string> | 5 #include <string> |
7 #include <vector> | 6 #include <vector> |
7 #include <iostream> | |
8 | 8 |
9 namespace HTTP { | 9 namespace HTTP { |
10 | 10 |
11 static size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userdata) { | 11 static size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userdata) { |
12 reinterpret_cast<QByteArray*>(userdata)->append(reinterpret_cast<char*>(contents), size * nmemb); | 12 reinterpret_cast<QByteArray*>(userdata)->append(reinterpret_cast<char*>(contents), size * nmemb); |
29 /* Use system certs... useful on Windows. */ | 29 /* Use system certs... useful on Windows. */ |
30 curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA); | 30 curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA); |
31 CURLcode res = curl_easy_perform(curl); | 31 CURLcode res = curl_easy_perform(curl); |
32 session.IncrementRequests(); | 32 session.IncrementRequests(); |
33 curl_easy_cleanup(curl); | 33 curl_easy_cleanup(curl); |
34 if (res != CURLE_OK) { | 34 if (res != CURLE_OK) |
35 QMessageBox box(QMessageBox::Icon::Critical, "", | 35 std::cerr << "curl_easy_perform(curl) failed!: " << curl_easy_strerror(res) << std::endl; |
36 QString("curl_easy_perform(curl) failed!: ") + QString(curl_easy_strerror(res))); | |
37 box.exec(); | |
38 } | |
39 } | 36 } |
40 return userdata; | 37 return userdata; |
41 } | 38 } |
42 | 39 |
43 QByteArray Post(const std::string& url, const std::string& data, const std::vector<std::string>& headers) { | 40 QByteArray Post(const std::string& url, const std::string& data, const std::vector<std::string>& headers) { |
57 /* Use system certs... useful on Windows. */ | 54 /* Use system certs... useful on Windows. */ |
58 curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA); | 55 curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA); |
59 CURLcode res = curl_easy_perform(curl); | 56 CURLcode res = curl_easy_perform(curl); |
60 session.IncrementRequests(); | 57 session.IncrementRequests(); |
61 curl_easy_cleanup(curl); | 58 curl_easy_cleanup(curl); |
62 if (res != CURLE_OK) { | 59 if (res != CURLE_OK) |
63 QMessageBox box(QMessageBox::Icon::Critical, "", | 60 std::cerr << "curl_easy_perform(curl) failed!: " << curl_easy_strerror(res) << std::endl; |
64 QString("curl_easy_perform(curl) failed!: ") + QString(curl_easy_strerror(res))); | |
65 box.exec(); | |
66 } | |
67 } | 61 } |
68 return userdata; | 62 return userdata; |
69 } | 63 } |
70 | 64 |
71 } // namespace HTTP | 65 } // namespace HTTP |