diff --git a/include/remote/Form.hpp b/include/remote/Form.hpp index 9a9a345..0716ba5 100644 --- a/include/remote/Form.hpp +++ b/include/remote/Form.hpp @@ -9,35 +9,26 @@ namespace remote public: Form() = default; - /// @brief Copy constructor - /// @param form Form to copy from. - Form(const Form &form); - - /// @brief Move constructor. - /// @param form Form to copy from. - Form(Form &&form) noexcept; - - /// @brief = Operator. - /// @param form Form to copy. - Form &operator=(const Form &form) noexcept; - - /// @brief = Move operator. - /// @param form Form to rob of its life. - Form &operator=(Form &&form); - /// @brief Appends a parameter to the form/URL encoded text. /// @param param Parameter to append. /// @param value Value to append. Form &append_parameter(std::string_view param, std::string_view value); - /// @brief Returns the C string of the form string. - const char *get() const noexcept; - /// @brief Returns m_form.length() size_t length() const noexcept; + /// @brief Returns m_formBuffer; + /// @return + const char *get() const noexcept; + private: - /// @brief String containing the actual data posted. - std::string m_form{}; + /// @brief Size used for the buffer. + static inline constexpr int SIZE_FORM_BUFFER = 0x800; + + /// @brief Current offset if the form. + int m_offset{}; + + /// @brief Buffer for the form. + char m_formBuffer[SIZE_FORM_BUFFER] = {0}; }; } // namespace remote diff --git a/source/remote/Form.cpp b/source/remote/Form.cpp index e05875f..725f339 100644 --- a/source/remote/Form.cpp +++ b/source/remote/Form.cpp @@ -1,28 +1,24 @@ #include "remote/Form.hpp" -remote::Form::Form(const remote::Form &form) { m_form = form.m_form; } - -remote::Form::Form(remote::Form &&form) noexcept { m_form = std::move(form.m_form); } - -remote::Form &remote::Form::operator=(const remote::Form &form) -{ - m_form = form.m_form; - return *this; -} - -remote::Form &remote::Form::operator=(remote::Form &&form) noexcept -{ - m_form = std::move(form.m_form); - return *this; -} +#include remote::Form &remote::Form::append_parameter(std::string_view param, std::string_view value) { - if (!m_form.empty() && m_form.back() != '&') { m_form.append("&"); } - m_form.append(param).append("=").append(value); + if (m_offset > 0 && m_formBuffer[m_offset] != '&') { m_formBuffer[m_offset++] = '&'; } + + const size_t paramLength = param.length(); + std::memcpy(&m_formBuffer[m_offset], param.data(), paramLength); + m_offset += paramLength; + + m_formBuffer[m_offset++] = '='; + + const size_t valueLength = value.length(); + std::memcpy(&m_formBuffer[m_offset], value.data(), valueLength); + m_offset += valueLength; + return *this; } -const char *remote::Form::get() const noexcept { return m_form.c_str(); } +const char *remote::Form::get() const noexcept { return m_formBuffer; } -size_t remote::Form::length() const noexcept { return m_form.length(); } +size_t remote::Form::length() const noexcept { return m_offset; } diff --git a/source/remote/GoogleDrive.cpp b/source/remote/GoogleDrive.cpp index 55bf06f..71df6d9 100644 --- a/source/remote/GoogleDrive.cpp +++ b/source/remote/GoogleDrive.cpp @@ -422,6 +422,7 @@ bool remote::GoogleDrive::get_sign_in_data(std::string &message, std::string &co curl::set_option(m_curl, CURLOPT_WRITEFUNCTION, curl::write_response_string); curl::set_option(m_curl, CURLOPT_WRITEDATA, &response); curl::set_option(m_curl, CURLOPT_POSTFIELDS, post.get()); + curl::set_option(m_curl, CURLOPT_POSTFIELDSIZE, post.length()); if (!curl::perform(m_curl)) { return false; } @@ -473,6 +474,7 @@ bool remote::GoogleDrive::poll_sign_in(std::string_view code) curl::set_option(m_curl, CURLOPT_WRITEFUNCTION, curl::write_response_string); curl::set_option(m_curl, CURLOPT_WRITEDATA, &response); curl::set_option(m_curl, CURLOPT_POSTFIELDS, post.get()); + curl::set_option(m_curl, CURLOPT_POSTFIELDSIZE, post.length()); if (!curl::perform(m_curl) || response.empty()) { return false; } diff --git a/source/ui/TitleView.cpp b/source/ui/TitleView.cpp index c0ed7ed..7cec71e 100644 --- a/source/ui/TitleView.cpp +++ b/source/ui/TitleView.cpp @@ -22,7 +22,7 @@ ui::TitleView::TitleView(data::User *user) void ui::TitleView::update(bool hasFocus) { - if (m_titleTiles.empty() || !hasFocus) { return; } + if (m_titleTiles.empty()) { return; } m_bounding->update(hasFocus); TitleView::handle_input();