Mercurial > minori
annotate src/core/http.cc @ 229:adc20fa321c1
theme: force Fusion style on platforms other than Win32 or OS X
I was reluctant to do this, but most of the other styles just
look like pure shite regardless of whether I force a stylesheet
on them or not. KDE's style is actually hilariously bad paired
with my stylesheet, so I've decided to also make the stylesheet
Windows-specific as well, because that's really the only platform
where it makes sense in the first place.
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Wed, 10 Jan 2024 21:23:57 -0500 |
| parents | 53211cb1e7f5 |
| children | 2f5a9247e501 |
| rev | line source |
|---|---|
| 75 | 1 #include "core/http.h" |
| 2 #include "core/session.h" | |
| 3 #include <QByteArray> | |
| 4 #include <curl/curl.h> | |
| 5 #include <string> | |
| 6 #include <vector> | |
| 175 | 7 #include <iostream> |
| 75 | 8 |
| 9 namespace HTTP { | |
| 10 | |
| 77 | 11 static size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userdata) { |
| 75 | 12 reinterpret_cast<QByteArray*>(userdata)->append(reinterpret_cast<char*>(contents), size * nmemb); |
| 13 return size * nmemb; | |
| 14 } | |
| 15 | |
|
100
f5940a575d83
track/constants: add many more video formats
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
16 QByteArray Get(const std::string& url, const std::vector<std::string>& headers) { |
| 75 | 17 struct curl_slist* list = NULL; |
| 18 QByteArray userdata; | |
| 19 | |
| 20 CURL* curl = curl_easy_init(); | |
| 21 if (curl) { | |
| 77 | 22 for (const std::string& h : headers) { |
| 75 | 23 list = curl_slist_append(list, h.c_str()); |
| 24 } | |
| 77 | 25 curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); |
| 26 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list); | |
| 75 | 27 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &userdata); |
| 28 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &WriteCallback); | |
| 29 /* Use system certs... useful on Windows. */ | |
| 30 curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA); | |
|
221
53211cb1e7f5
library: add initial library stuff
Paper <paper@paper.us.eu.org>
parents:
175
diff
changeset
|
31 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); // threading |
| 75 | 32 CURLcode res = curl_easy_perform(curl); |
| 33 session.IncrementRequests(); | |
| 34 curl_easy_cleanup(curl); | |
| 175 | 35 if (res != CURLE_OK) |
| 36 std::cerr << "curl_easy_perform(curl) failed!: " << curl_easy_strerror(res) << std::endl; | |
| 75 | 37 } |
| 77 | 38 return userdata; |
| 75 | 39 } |
| 40 | |
|
100
f5940a575d83
track/constants: add many more video formats
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
41 QByteArray Post(const std::string& url, const std::string& data, const std::vector<std::string>& headers) { |
| 77 | 42 struct curl_slist* list = NULL; |
| 43 QByteArray userdata; | |
| 75 | 44 |
| 45 CURL* curl = curl_easy_init(); | |
| 46 if (curl) { | |
| 47 for (const std::string& h : headers) { | |
| 48 list = curl_slist_append(list, h.c_str()); | |
| 49 } | |
| 50 curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); | |
| 51 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str()); | |
| 52 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list); | |
| 53 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &userdata); | |
| 77 | 54 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &WriteCallback); |
| 75 | 55 /* Use system certs... useful on Windows. */ |
| 56 curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA); | |
|
221
53211cb1e7f5
library: add initial library stuff
Paper <paper@paper.us.eu.org>
parents:
175
diff
changeset
|
57 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); // threading |
| 75 | 58 CURLcode res = curl_easy_perform(curl); |
| 59 session.IncrementRequests(); | |
| 60 curl_easy_cleanup(curl); | |
| 175 | 61 if (res != CURLE_OK) |
| 62 std::cerr << "curl_easy_perform(curl) failed!: " << curl_easy_strerror(res) << std::endl; | |
| 75 | 63 } |
| 77 | 64 return userdata; |
| 75 | 65 } |
| 66 | |
| 76 | 67 } // namespace HTTP |
