remote::Storage just barely working.

This commit is contained in:
J-D-K
2025-07-04 13:06:47 -04:00
parent e29db89706
commit e27e0c8e51
92 changed files with 2240 additions and 1044 deletions

View File

@@ -1,4 +1,5 @@
#include "curl/curl.hpp"
#include "logger.hpp"
#include "stringutil.hpp"
namespace
@@ -7,16 +8,35 @@ namespace
constexpr size_t SIZE_UPLOAD_BUFFER = 0x10000;
} // namespace
bool curl::initialize(void)
bool curl::initialize()
{
return curl_global_init(CURL_GLOBAL_ALL) == CURLE_OK;
}
void curl::exit(void)
void curl::exit()
{
curl_global_cleanup();
}
bool curl::perform(curl::Handle &handle)
{
CURLcode error = curl_easy_perform(handle.get());
if (error != CURLE_OK)
{
logger::log("Error performing curl: %i.", error);
return false;
}
return true;
}
void curl::append_header(curl::HeaderList &list, std::string_view header)
{
// This is the only real way to accomplish this since slist is a linked list.
curl_slist *head = list.release();
head = curl_slist_append(head, header.data());
list.reset(head);
}
size_t curl::read_data_from_file(char *buffer, size_t size, size_t count, fslib::File *target)
{
// This should be good enough.
@@ -31,7 +51,7 @@ size_t curl::write_header_array(const char *buffer, size_t size, size_t count, c
size_t curl::write_response_string(const char *buffer, size_t size, size_t count, std::string *string)
{
string->append(buffer, buffer + (size * count));
string->append(buffer, size * count);
return size * count;
}
@@ -75,6 +95,43 @@ bool curl::get_header_value(const curl::HeaderArray &array, std::string_view hea
return false;
}
long curl::get_response_code(curl::Handle &handle)
{
long code = 0;
curl_easy_getinfo(handle.get(), CURLINFO_RESPONSE_CODE, &code);
return code;
}
bool curl::escape_string(curl::Handle &handle, std::string_view in, std::string &out)
{
char *escaped = curl_easy_escape(handle.get(), in.data(), in.length());
if (!escaped)
{
return false;
}
out.assign(escaped);
// I'm assuming this just calls free itself?
curl_free(escaped);
return true;
}
bool curl::unescape_string(curl::Handle &handle, std::string_view in, std::string &out)
{
int lengthOut{};
char *unescaped = curl_easy_unescape(handle.get(), in.data(), in.length(), &lengthOut);
if (!unescaped)
{
return false;
}
out.assign(unescaped);
curl_free(unescaped);
return true;
}
void curl::prepare_get(curl::Handle &curl)
{
// Reset handle. This is faster than making duplicates over and over.
@@ -98,6 +155,5 @@ void curl::prepare_upload(curl::Handle &curl)
curl::reset_handle(curl);
curl::set_option(curl, CURLOPT_UPLOAD, 1L);
curl::set_option(curl, CURLOPT_UPLOAD_BUFFERSIZE, SIZE_UPLOAD_BUFFER);
curl::set_option(curl, CURLOPT_ACCEPT_ENCODING, ""); // Not really sure this will have any affect here...
}