Skip to content

Commit

Permalink
chore: gcc internal error reproducible
Browse files Browse the repository at this point in the history
Gcc internal error reproducible.

Signed-off-by: Melg Eight <public.melg8@gmail.com>
Signed-off-by: melg8 <public.melg8@gmail.com>
  • Loading branch information
melg8 committed May 9, 2024
1 parent cf64c5d commit de971c0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
1 change: 1 addition & 0 deletions conanfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ boost/1.84.0
catch2/3.4.0
ctre/3.8.1
fmt/10.2.1
glaze/2.6.1
gsl-lite/0.40.0
libassert/2.0.2
openssl/3.1.2
Expand Down
4 changes: 3 additions & 1 deletion sources/coal/application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ find_package(spdlog REQUIRED)
find_package(libassert REQUIRED)
find_package(fmt REQUIRED)
find_package(ctre REQUIRED)
find_package(glaze REQUIRED)

option(SPDLOG_NO_EXCEPTIONS "Compile with -fno-exceptions. Call abort() on any spdlog exceptions" ON)

Expand Down Expand Up @@ -37,11 +38,12 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compiler_flags(-Wno-mismatched-new-delete)
endif()

target_link_libraries(coal PUBLIC Boost::cobalt
target_link_libraries(coal PRIVATE Boost::cobalt
Boost::json
Boost::url
ctre::ctre
fmt::fmt
glaze::glaze
libassert::assert
OpenSSL::SSL
spdlog::spdlog)
40 changes: 34 additions & 6 deletions sources/coal/application/sources/auth_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,47 @@ cobalt::promise<Result<HttpResponse>> LoginTo(std::string_view url_text,

cobalt::promise<Result<UserAuthData>> AuthTo(std::string_view server_url,
const Credentials& credentials) {
const auto maybe_answer = co_await CallApiMethod(
const auto maybe_response = co_await CallApiMethod(
server_url, "signup_or_login", FormatOnlyLoginData(credentials));
if (maybe_answer.has_error()) {
co_return maybe_answer.error();
if (maybe_response.has_error()) {
co_return maybe_response.error();
}
const auto answer = maybe_answer.value();
const auto body = answer.body();
const auto response = maybe_response.value();
const auto body = response.body();
if (!body.contains("Logged In!")) {
spdlog::error("Can't login, server response: {}", body);
co_return Result<UserAuthData>{
std::make_error_code(std::errc::permission_denied)};
}
co_return FromResponse(answer);
co_return FromResponse(response);
}

[[nodiscard]] static std::string AuthCookieFrom(
const UserAuthData& user_auth_data) {
return fmt::format("auth={}-{}", user_auth_data.id, user_auth_data.token);
}

[[nodiscard]] static Result<ServersAndCharacters> ServersAndCharactersFrom(
[[maybe_unused]] const std::string json_body) {
if (json_body.empty()) {
spdlog::error("Got empty json body for servers and characters parsing");
return {}; // TODO(melg): add proper error code.
}

return {};
}

cobalt::promise<Result<ServersAndCharacters>> GetServersAndCharacters(
std::string_view url_text, UserAuthData user_auth_data) {
const auto auth_cookie = AuthCookieFrom(user_auth_data);
const auto maybe_answer = co_await CallApiMethod(
url_text, "servers_and_characters", "{}", {auth_cookie});
if (maybe_answer.has_error()) {
spdlog::error("Can't obtains servers and characters: {}",
maybe_answer.error().message());
co_return maybe_answer.error();
}
co_return ServersAndCharactersFrom(maybe_answer.value().body());
}

} // namespace coal
13 changes: 13 additions & 0 deletions sources/coal/application/sources/auth_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <boost/cobalt.hpp>

#include <string>
#include <utility>

namespace coal {
namespace cobalt = boost::cobalt;
Expand All @@ -24,6 +25,15 @@ struct UserAuthData {
std::string token = {};
};

struct Character {};

using Characters = std::vector<Character>;

struct Server {};
using Servers = std::vector<Server>;

using ServersAndCharacters = std::pair<Servers, Characters>;

cobalt::promise<Result<HttpResponse>> CallApiMethod(std::string_view url_text,
std::string_view method,
std::string_view args,
Expand All @@ -35,6 +45,9 @@ cobalt::promise<Result<HttpResponse>> LoginTo(std::string_view url_text,
cobalt::promise<Result<UserAuthData>> AuthTo(std::string_view server_url,
const Credentials& credentials);

cobalt::promise<Result<ServersAndCharacters>> GetServersAndCharacters(
std::string_view url_text, UserAuthData user_auth_data);

} // namespace coal

#endif // AUTH_CLIENT_H

0 comments on commit de971c0

Please sign in to comment.