From 4d139943f2407144d5f8e3dc5a673f24850d43d0 Mon Sep 17 00:00:00 2001 From: fearlessTobi Date: Sun, 16 Sep 2018 20:05:51 +0200 Subject: Port web_service from Citra --- src/web_service/CMakeLists.txt | 16 ++++ src/web_service/json.h | 18 +++++ src/web_service/telemetry_json.cpp | 94 ++++++++++++++++++++++++ src/web_service/telemetry_json.h | 59 +++++++++++++++ src/web_service/verify_login.cpp | 27 +++++++ src/web_service/verify_login.h | 22 ++++++ src/web_service/web_backend.cpp | 147 +++++++++++++++++++++++++++++++++++++ src/web_service/web_backend.h | 91 +++++++++++++++++++++++ 8 files changed, 474 insertions(+) create mode 100644 src/web_service/CMakeLists.txt create mode 100644 src/web_service/json.h create mode 100644 src/web_service/telemetry_json.cpp create mode 100644 src/web_service/telemetry_json.h create mode 100644 src/web_service/verify_login.cpp create mode 100644 src/web_service/verify_login.h create mode 100644 src/web_service/web_backend.cpp create mode 100644 src/web_service/web_backend.h (limited to 'src/web_service') diff --git a/src/web_service/CMakeLists.txt b/src/web_service/CMakeLists.txt new file mode 100644 index 000000000..ef77728c0 --- /dev/null +++ b/src/web_service/CMakeLists.txt @@ -0,0 +1,16 @@ +add_library(web_service STATIC + telemetry_json.cpp + telemetry_json.h + verify_login.cpp + verify_login.h + web_backend.cpp + web_backend.h +) + +create_target_directory_groups(web_service) + +get_directory_property(OPENSSL_LIBS + DIRECTORY ${CMAKE_SOURCE_DIR}/externals/libressl + DEFINITION OPENSSL_LIBS) +add_definitions(-DCPPHTTPLIB_OPENSSL_SUPPORT) +target_link_libraries(web_service PUBLIC common json-headers ${OPENSSL_LIBS} httplib lurlparser) diff --git a/src/web_service/json.h b/src/web_service/json.h new file mode 100644 index 000000000..88b31501e --- /dev/null +++ b/src/web_service/json.h @@ -0,0 +1,18 @@ +// Copyright 2018 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +// This hack is needed to support json.hpp on platforms where the C++17 stdlib +// lacks std::string_view. See https://github.com/nlohmann/json/issues/735. +// clang-format off +#if !__has_include() && __has_include() +# include +# define string_view experimental::string_view +# include +# undef string_view +#else +# include +#endif +// clang-format on diff --git a/src/web_service/telemetry_json.cpp b/src/web_service/telemetry_json.cpp new file mode 100644 index 000000000..a0b7f9c4e --- /dev/null +++ b/src/web_service/telemetry_json.cpp @@ -0,0 +1,94 @@ +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include "common/assert.h" +#include "common/detached_tasks.h" +#include "web_service/telemetry_json.h" +#include "web_service/web_backend.h" + +namespace WebService { + +template +void TelemetryJson::Serialize(Telemetry::FieldType type, const std::string& name, T value) { + sections[static_cast(type)][name] = value; +} + +void TelemetryJson::SerializeSection(Telemetry::FieldType type, const std::string& name) { + TopSection()[name] = sections[static_cast(type)]; +} + +void TelemetryJson::Visit(const Telemetry::Field& field) { + Serialize(field.GetType(), field.GetName(), field.GetValue()); +} + +void TelemetryJson::Visit(const Telemetry::Field& field) { + Serialize(field.GetType(), field.GetName(), field.GetValue()); +} + +void TelemetryJson::Visit(const Telemetry::Field& field) { + Serialize(field.GetType(), field.GetName(), field.GetValue()); +} + +void TelemetryJson::Visit(const Telemetry::Field& field) { + Serialize(field.GetType(), field.GetName(), field.GetValue()); +} + +void TelemetryJson::Visit(const Telemetry::Field& field) { + Serialize(field.GetType(), field.GetName(), field.GetValue()); +} + +void TelemetryJson::Visit(const Telemetry::Field& field) { + Serialize(field.GetType(), field.GetName(), field.GetValue()); +} + +void TelemetryJson::Visit(const Telemetry::Field& field) { + Serialize(field.GetType(), field.GetName(), field.GetValue()); +} + +void TelemetryJson::Visit(const Telemetry::Field& field) { + Serialize(field.GetType(), field.GetName(), field.GetValue()); +} + +void TelemetryJson::Visit(const Telemetry::Field& field) { + Serialize(field.GetType(), field.GetName(), field.GetValue()); +} + +void TelemetryJson::Visit(const Telemetry::Field& field) { + Serialize(field.GetType(), field.GetName(), field.GetValue()); +} + +void TelemetryJson::Visit(const Telemetry::Field& field) { + Serialize(field.GetType(), field.GetName(), field.GetValue()); +} + +void TelemetryJson::Visit(const Telemetry::Field& field) { + Serialize(field.GetType(), field.GetName(), field.GetValue()); +} + +void TelemetryJson::Visit(const Telemetry::Field& field) { + Serialize(field.GetType(), field.GetName(), std::string(field.GetValue())); +} + +void TelemetryJson::Visit(const Telemetry::Field& field) { + Serialize(field.GetType(), field.GetName(), field.GetValue().count()); +} + +void TelemetryJson::Complete() { + SerializeSection(Telemetry::FieldType::App, "App"); + SerializeSection(Telemetry::FieldType::Session, "Session"); + SerializeSection(Telemetry::FieldType::Performance, "Performance"); + SerializeSection(Telemetry::FieldType::UserFeedback, "UserFeedback"); + SerializeSection(Telemetry::FieldType::UserConfig, "UserConfig"); + SerializeSection(Telemetry::FieldType::UserSystem, "UserSystem"); + + auto content = TopSection().dump(); + // Send the telemetry async but don't handle the errors since they were written to the log + Common::DetachedTasks::AddTask( + [host{this->host}, username{this->username}, token{this->token}, content]() { + Client{host, username, token}.PostJson("/telemetry", content, true); + }); +} + +} // namespace WebService diff --git a/src/web_service/telemetry_json.h b/src/web_service/telemetry_json.h new file mode 100644 index 000000000..9bc886538 --- /dev/null +++ b/src/web_service/telemetry_json.h @@ -0,0 +1,59 @@ +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include "common/telemetry.h" +#include "common/web_result.h" +#include "web_service/json.h" + +namespace WebService { + +/** + * Implementation of VisitorInterface that serialized telemetry into JSON, and submits it to the + * yuzu web service + */ +class TelemetryJson : public Telemetry::VisitorInterface { +public: + TelemetryJson(const std::string& host, const std::string& username, const std::string& token) + : host(host), username(username), token(token) {} + ~TelemetryJson() = default; + + void Visit(const Telemetry::Field& field) override; + void Visit(const Telemetry::Field& field) override; + void Visit(const Telemetry::Field& field) override; + void Visit(const Telemetry::Field& field) override; + void Visit(const Telemetry::Field& field) override; + void Visit(const Telemetry::Field& field) override; + void Visit(const Telemetry::Field& field) override; + void Visit(const Telemetry::Field& field) override; + void Visit(const Telemetry::Field& field) override; + void Visit(const Telemetry::Field& field) override; + void Visit(const Telemetry::Field& field) override; + void Visit(const Telemetry::Field& field) override; + void Visit(const Telemetry::Field& field) override; + void Visit(const Telemetry::Field& field) override; + + void Complete() override; + +private: + nlohmann::json& TopSection() { + return sections[static_cast(Telemetry::FieldType::None)]; + } + + template + void Serialize(Telemetry::FieldType type, const std::string& name, T value); + + void SerializeSection(Telemetry::FieldType type, const std::string& name); + + nlohmann::json output; + std::array sections; + std::string host; + std::string username; + std::string token; +}; + +} // namespace WebService diff --git a/src/web_service/verify_login.cpp b/src/web_service/verify_login.cpp new file mode 100644 index 000000000..02e1b74f3 --- /dev/null +++ b/src/web_service/verify_login.cpp @@ -0,0 +1,27 @@ +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "web_service/json.h" +#include "web_service/verify_login.h" +#include "web_service/web_backend.h" + +namespace WebService { + +bool VerifyLogin(const std::string& host, const std::string& username, const std::string& token) { + Client client(host, username, token); + auto reply = client.GetJson("/profile", false).returned_data; + if (reply.empty()) { + return false; + } + nlohmann::json json = nlohmann::json::parse(reply); + const auto iter = json.find("username"); + + if (iter == json.end()) { + return username.empty(); + } + + return username == *iter; +} + +} // namespace WebService diff --git a/src/web_service/verify_login.h b/src/web_service/verify_login.h new file mode 100644 index 000000000..39db32dbb --- /dev/null +++ b/src/web_service/verify_login.h @@ -0,0 +1,22 @@ +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include + +namespace WebService { + +/** + * Checks if username and token is valid + * @param host the web API URL + * @param username yuzu username to use for authentication. + * @param token yuzu token to use for authentication. + * @returns a bool indicating whether the verification succeeded + */ +bool VerifyLogin(const std::string& host, const std::string& username, const std::string& token); + +} // namespace WebService diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp new file mode 100644 index 000000000..a726fb8eb --- /dev/null +++ b/src/web_service/web_backend.cpp @@ -0,0 +1,147 @@ +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#include +#include +#include "common/logging/log.h" +#include "common/web_result.h" +#include "core/settings.h" +#include "web_service/web_backend.h" + +namespace WebService { + +static constexpr char API_VERSION[]{"1"}; + +constexpr int HTTP_PORT = 80; +constexpr int HTTPS_PORT = 443; + +constexpr int TIMEOUT_SECONDS = 30; + +Client::JWTCache Client::jwt_cache{}; + +Client::Client(const std::string& host, const std::string& username, const std::string& token) + : host(host), username(username), token(token) { + if (username == jwt_cache.username && token == jwt_cache.token) { + jwt = jwt_cache.jwt; + } +} + +Common::WebResult Client::GenericJson(const std::string& method, const std::string& path, + const std::string& data, const std::string& jwt, + const std::string& username, const std::string& token) { + if (cli == nullptr) { + auto parsedUrl = LUrlParser::clParseURL::ParseURL(host); + int port; + if (parsedUrl.m_Scheme == "http") { + if (!parsedUrl.GetPort(&port)) { + port = HTTP_PORT; + } + cli = + std::make_unique(parsedUrl.m_Host.c_str(), port, TIMEOUT_SECONDS); + } else if (parsedUrl.m_Scheme == "https") { + if (!parsedUrl.GetPort(&port)) { + port = HTTPS_PORT; + } + cli = std::make_unique(parsedUrl.m_Host.c_str(), port, + TIMEOUT_SECONDS); + } else { + LOG_ERROR(WebService, "Bad URL scheme {}", parsedUrl.m_Scheme); + return Common::WebResult{Common::WebResult::Code::InvalidURL, "Bad URL scheme"}; + } + } + if (cli == nullptr) { + LOG_ERROR(WebService, "Invalid URL {}", host + path); + return Common::WebResult{Common::WebResult::Code::InvalidURL, "Invalid URL"}; + } + + httplib::Headers params; + if (!jwt.empty()) { + params = { + {std::string("Authorization"), fmt::format("Bearer {}", jwt)}, + }; + } else if (!username.empty()) { + params = { + {std::string("x-username"), username}, + {std::string("x-token"), token}, + }; + } + + params.emplace(std::string("api-version"), std::string(API_VERSION)); + if (method != "GET") { + params.emplace(std::string("Content-Type"), std::string("application/json")); + }; + + httplib::Request request; + request.method = method; + request.path = path; + request.headers = params; + request.body = data; + + httplib::Response response; + + if (!cli->send(request, response)) { + LOG_ERROR(WebService, "{} to {} returned null", method, host + path); + return Common::WebResult{Common::WebResult::Code::LibError, "Null response"}; + } + + if (response.status >= 400) { + LOG_ERROR(WebService, "{} to {} returned error status code: {}", method, host + path, + response.status); + return Common::WebResult{Common::WebResult::Code::HttpError, + std::to_string(response.status)}; + } + + auto content_type = response.headers.find("content-type"); + + if (content_type == response.headers.end()) { + LOG_ERROR(WebService, "{} to {} returned no content", method, host + path); + return Common::WebResult{Common::WebResult::Code::WrongContent, ""}; + } + + if (content_type->second.find("application/json") == std::string::npos && + content_type->second.find("text/html; charset=utf-8") == std::string::npos) { + LOG_ERROR(WebService, "{} to {} returned wrong content: {}", method, host + path, + content_type->second); + return Common::WebResult{Common::WebResult::Code::WrongContent, "Wrong content"}; + } + return Common::WebResult{Common::WebResult::Code::Success, "", response.body}; +} + +void Client::UpdateJWT() { + if (!username.empty() && !token.empty()) { + auto result = GenericJson("POST", "/jwt/internal", "", "", username, token); + if (result.result_code != Common::WebResult::Code::Success) { + LOG_ERROR(WebService, "UpdateJWT failed"); + } else { + jwt_cache.username = username; + jwt_cache.token = token; + jwt_cache.jwt = jwt = result.returned_data; + } + } +} + +Common::WebResult Client::GenericJson(const std::string& method, const std::string& path, + const std::string& data, bool allow_anonymous) { + if (jwt.empty()) { + UpdateJWT(); + } + + if (jwt.empty() && !allow_anonymous) { + LOG_ERROR(WebService, "Credentials must be provided for authenticated requests"); + return Common::WebResult{Common::WebResult::Code::CredentialsMissing, "Credentials needed"}; + } + + auto result = GenericJson(method, path, data, jwt); + if (result.result_string == "401") { + // Try again with new JWT + UpdateJWT(); + result = GenericJson(method, path, data, jwt); + } + + return result; +} + +} // namespace WebService diff --git a/src/web_service/web_backend.h b/src/web_service/web_backend.h new file mode 100644 index 000000000..549bcce29 --- /dev/null +++ b/src/web_service/web_backend.h @@ -0,0 +1,91 @@ +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include +#include +#include +#include "common/common_types.h" +#include "common/web_result.h" + +namespace httplib { +class Client; +} + +namespace WebService { + +class Client { +public: + Client(const std::string& host, const std::string& username, const std::string& token); + + /** + * Posts JSON to the specified path. + * @param path the URL segment after the host address. + * @param data String of JSON data to use for the body of the POST request. + * @param allow_anonymous If true, allow anonymous unauthenticated requests. + * @return the result of the request. + */ + Common::WebResult PostJson(const std::string& path, const std::string& data, + bool allow_anonymous) { + return GenericJson("POST", path, data, allow_anonymous); + } + + /** + * Gets JSON from the specified path. + * @param path the URL segment after the host address. + * @param allow_anonymous If true, allow anonymous unauthenticated requests. + * @return the result of the request. + */ + Common::WebResult GetJson(const std::string& path, bool allow_anonymous) { + return GenericJson("GET", path, "", allow_anonymous); + } + + /** + * Deletes JSON to the specified path. + * @param path the URL segment after the host address. + * @param data String of JSON data to use for the body of the DELETE request. + * @param allow_anonymous If true, allow anonymous unauthenticated requests. + * @return the result of the request. + */ + Common::WebResult DeleteJson(const std::string& path, const std::string& data, + bool allow_anonymous) { + return GenericJson("DELETE", path, data, allow_anonymous); + } + +private: + /// A generic function handles POST, GET and DELETE request together + Common::WebResult GenericJson(const std::string& method, const std::string& path, + const std::string& data, bool allow_anonymous); + + /** + * A generic function with explicit authentication method specified + * JWT is used if the jwt parameter is not empty + * username + token is used if jwt is empty but username and token are not empty + * anonymous if all of jwt, username and token are empty + */ + Common::WebResult GenericJson(const std::string& method, const std::string& path, + const std::string& data, const std::string& jwt = "", + const std::string& username = "", const std::string& token = ""); + + // Retrieve a new JWT from given username and token + void UpdateJWT(); + + std::string host; + std::string username; + std::string token; + std::string jwt; + std::unique_ptr cli; + + struct JWTCache { + std::string username; + std::string token; + std::string jwt; + }; + static JWTCache jwt_cache; +}; + +} // namespace WebService -- cgit v1.2.3 From b4ace6ec6f86079b3bd297f95dfe133240b53e15 Mon Sep 17 00:00:00 2001 From: fearlessTobi Date: Mon, 17 Sep 2018 17:16:01 +0200 Subject: Address a bunch of review comments --- src/common/web_result.h | 2 +- src/core/telemetry_session.cpp | 11 ++++++----- src/core/telemetry_session.h | 2 +- src/web_service/telemetry_json.cpp | 5 +++++ src/web_service/telemetry_json.h | 5 ++--- src/web_service/web_backend.cpp | 8 ++++---- src/yuzu/compatdb.cpp | 6 +++++- src/yuzu/compatdb.h | 1 - src/yuzu/configuration/configure_web.cpp | 2 +- src/yuzu/discord_impl.h | 2 +- src/yuzu/main.cpp | 2 +- 11 files changed, 27 insertions(+), 19 deletions(-) (limited to 'src/web_service') diff --git a/src/common/web_result.h b/src/common/web_result.h index 13610a7ea..969926674 100644 --- a/src/common/web_result.h +++ b/src/common/web_result.h @@ -21,4 +21,4 @@ struct WebResult { std::string result_string; std::string returned_data; }; -} // namespace Commo \ No newline at end of file +} // namespace Common diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp index 09c85297a..c02188adc 100644 --- a/src/core/telemetry_session.cpp +++ b/src/core/telemetry_session.cpp @@ -28,11 +28,12 @@ static u64 GenerateTelemetryId() { mbedtls_entropy_context entropy; mbedtls_entropy_init(&entropy); mbedtls_ctr_drbg_context ctr_drbg; - const char* personalization = "yuzu Telemetry ID"; + std::string personalization = "yuzu Telemetry ID"; mbedtls_ctr_drbg_init(&ctr_drbg); - mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, - (const unsigned char*)personalization, strlen(personalization)); + ASSERT(mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, + reinterpret_cast(personalization.c_str()), + personalization.size()) == 0) ASSERT(mbedtls_ctr_drbg_random(&ctr_drbg, reinterpret_cast(&telemetry_id), sizeof(u64)) == 0); @@ -88,7 +89,7 @@ u64 RegenerateTelemetryId() { return new_telemetry_id; } -bool VerifyLogin(std::string username, std::string token) { +bool VerifyLogin(const std::string& username, const std::string& token) { #ifdef ENABLE_WEB_SERVICE return WebService::VerifyLogin(Settings::values.web_api_url, username, token); #else @@ -120,7 +121,7 @@ TelemetrySession::TelemetrySession() { u64 program_id{}; const Loader::ResultStatus res{System::GetInstance().GetAppLoader().ReadProgramId(program_id)}; if (res == Loader::ResultStatus::Success) { - std::string formatted_program_id{fmt::format("{:016X}", program_id)}; + const std::string formatted_program_id{fmt::format("{:016X}", program_id)}; AddField(Telemetry::FieldType::Session, "ProgramId", formatted_program_id); std::string name; diff --git a/src/core/telemetry_session.h b/src/core/telemetry_session.h index e6976ad45..cec271df0 100644 --- a/src/core/telemetry_session.h +++ b/src/core/telemetry_session.h @@ -56,6 +56,6 @@ u64 RegenerateTelemetryId(); * @param func A function that gets exectued when the verification is finished * @returns Future with bool indicating whether the verification succeeded */ -bool VerifyLogin(std::string username, std::string token); +bool VerifyLogin(const std::string& username, const std::string& token); } // namespace Core diff --git a/src/web_service/telemetry_json.cpp b/src/web_service/telemetry_json.cpp index a0b7f9c4e..033ea1ea4 100644 --- a/src/web_service/telemetry_json.cpp +++ b/src/web_service/telemetry_json.cpp @@ -10,6 +10,11 @@ namespace WebService { +TelemetryJson::TelemetryJson(const std::string& host, const std::string& username, + const std::string& token) + : host(std::move(host)), username(std::move(username)), token(std::move(token)) {} +TelemetryJson::~TelemetryJson() = default; + template void TelemetryJson::Serialize(Telemetry::FieldType type, const std::string& name, T value) { sections[static_cast(type)][name] = value; diff --git a/src/web_service/telemetry_json.h b/src/web_service/telemetry_json.h index 9bc886538..29d565964 100644 --- a/src/web_service/telemetry_json.h +++ b/src/web_service/telemetry_json.h @@ -18,9 +18,8 @@ namespace WebService { */ class TelemetryJson : public Telemetry::VisitorInterface { public: - TelemetryJson(const std::string& host, const std::string& username, const std::string& token) - : host(host), username(username), token(token) {} - ~TelemetryJson() = default; + TelemetryJson(const std::string& host, const std::string& username, const std::string& token); + ~TelemetryJson(); void Visit(const Telemetry::Field& field) override; void Visit(const Telemetry::Field& field) override; diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp index a726fb8eb..3a3f44dc2 100644 --- a/src/web_service/web_backend.cpp +++ b/src/web_service/web_backend.cpp @@ -13,12 +13,12 @@ namespace WebService { -static constexpr char API_VERSION[]{"1"}; +constexpr char API_VERSION[]{"1"}; -constexpr int HTTP_PORT = 80; -constexpr int HTTPS_PORT = 443; +constexpr u32 HTTP_PORT = 80; +constexpr u32 HTTPS_PORT = 443; -constexpr int TIMEOUT_SECONDS = 30; +constexpr u32 TIMEOUT_SECONDS = 30; Client::JWTCache Client::jwt_cache{}; diff --git a/src/yuzu/compatdb.cpp b/src/yuzu/compatdb.cpp index 45f8b4461..91e754274 100644 --- a/src/yuzu/compatdb.cpp +++ b/src/yuzu/compatdb.cpp @@ -27,7 +27,11 @@ CompatDB::CompatDB(QWidget* parent) CompatDB::~CompatDB() = default; -enum class CompatDBPage { Intro = 0, Selection = 1, Final = 2 }; +enum class CompatDBPage { + Intro = 0, + Selection = 1, + Final = 2, +}; void CompatDB::Submit() { QButtonGroup* compatibility = new QButtonGroup(this); diff --git a/src/yuzu/compatdb.h b/src/yuzu/compatdb.h index 0a0f27cca..ca0dd11d6 100644 --- a/src/yuzu/compatdb.h +++ b/src/yuzu/compatdb.h @@ -21,7 +21,6 @@ public: private: std::unique_ptr ui; -private slots: void Submit(); void EnableNext(); }; diff --git a/src/yuzu/configuration/configure_web.cpp b/src/yuzu/configuration/configure_web.cpp index cfca08014..4b5c39e26 100644 --- a/src/yuzu/configuration/configure_web.cpp +++ b/src/yuzu/configuration/configure_web.cpp @@ -25,7 +25,7 @@ ConfigureWeb::ConfigureWeb(QWidget* parent) this->setConfiguration(); } -ConfigureWeb::~ConfigureWeb() {} +ConfigureWeb::~ConfigureWeb() = default; void ConfigureWeb::setConfiguration() { ui->web_credentials_disclaimer->setWordWrap(true); diff --git a/src/yuzu/discord_impl.h b/src/yuzu/discord_impl.h index d71428c10..4bfda8cdf 100644 --- a/src/yuzu/discord_impl.h +++ b/src/yuzu/discord_impl.h @@ -11,7 +11,7 @@ namespace DiscordRPC { class DiscordImpl : public DiscordInterface { public: DiscordImpl(); - ~DiscordImpl(); + ~DiscordImpl() override; void Pause() override; void Update() override; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 2d6e0d4fc..f236c63c5 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -115,7 +115,7 @@ void GMainWindow::ShowTelemetryCallout() { } UISettings::values.callout_flags |= static_cast(CalloutFlag::Telemetry); - static const QString telemetry_message = + const QString telemetry_message = tr("Anonymous " "data is collected to help improve yuzu. " "

Would you like to share your usage data with us?"); -- cgit v1.2.3 From 62f9409ba3e114b40b6923808290c02bf5af3d2c Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Mon, 17 Sep 2018 14:28:58 -0400 Subject: web_backend: protect jwt cache with a mutex --- src/web_service/web_backend.cpp | 2 ++ src/web_service/web_backend.h | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src/web_service') diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp index 3a3f44dc2..5df4df5eb 100644 --- a/src/web_service/web_backend.cpp +++ b/src/web_service/web_backend.cpp @@ -24,6 +24,7 @@ Client::JWTCache Client::jwt_cache{}; Client::Client(const std::string& host, const std::string& username, const std::string& token) : host(host), username(username), token(token) { + std::lock_guard lock(jwt_cache.mutex); if (username == jwt_cache.username && token == jwt_cache.token) { jwt = jwt_cache.jwt; } @@ -116,6 +117,7 @@ void Client::UpdateJWT() { if (result.result_code != Common::WebResult::Code::Success) { LOG_ERROR(WebService, "UpdateJWT failed"); } else { + std::lock_guard lock(jwt_cache.mutex); jwt_cache.username = username; jwt_cache.token = token; jwt_cache.jwt = jwt = result.returned_data; diff --git a/src/web_service/web_backend.h b/src/web_service/web_backend.h index 549bcce29..d75fbcc15 100644 --- a/src/web_service/web_backend.h +++ b/src/web_service/web_backend.h @@ -5,7 +5,7 @@ #pragma once #include -#include +#include #include #include #include @@ -81,6 +81,7 @@ private: std::unique_ptr cli; struct JWTCache { + std::mutex mutex; std::string username; std::string token; std::string jwt; -- cgit v1.2.3 From aa484688623db59df3ef334a63eff98d98e362f3 Mon Sep 17 00:00:00 2001 From: fearlessTobi Date: Wed, 19 Sep 2018 20:04:45 +0200 Subject: Review comments - part 3 --- externals/CMakeLists.txt | 2 +- src/web_service/json.h | 18 ------------------ src/web_service/telemetry_json.h | 2 +- src/web_service/verify_login.cpp | 2 +- src/yuzu/configuration/configure_web.cpp | 6 +++--- src/yuzu/main.cpp | 2 +- src/yuzu_cmd/default_ini.h | 2 +- 7 files changed, 8 insertions(+), 26 deletions(-) delete mode 100644 src/web_service/json.h (limited to 'src/web_service') diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 6a573881d..1261062e8 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -80,9 +80,9 @@ endif() if (ENABLE_WEB_SERVICE) # LibreSSL set(LIBRESSL_SKIP_INSTALL ON CACHE BOOL "") - add_definitions(-DHAVE_INET_NTOP) add_subdirectory(libressl EXCLUDE_FROM_ALL) target_include_directories(ssl INTERFACE ./libressl/include) + target_compile_definitions(ssl PRIVATE -DHAVE_INET_NTOP) # lurlparser add_subdirectory(lurlparser EXCLUDE_FROM_ALL) diff --git a/src/web_service/json.h b/src/web_service/json.h deleted file mode 100644 index 88b31501e..000000000 --- a/src/web_service/json.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2018 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -// This hack is needed to support json.hpp on platforms where the C++17 stdlib -// lacks std::string_view. See https://github.com/nlohmann/json/issues/735. -// clang-format off -#if !__has_include() && __has_include() -# include -# define string_view experimental::string_view -# include -# undef string_view -#else -# include -#endif -// clang-format on diff --git a/src/web_service/telemetry_json.h b/src/web_service/telemetry_json.h index 29d565964..0fe6f9a3e 100644 --- a/src/web_service/telemetry_json.h +++ b/src/web_service/telemetry_json.h @@ -6,9 +6,9 @@ #include #include +#include #include "common/telemetry.h" #include "common/web_result.h" -#include "web_service/json.h" namespace WebService { diff --git a/src/web_service/verify_login.cpp b/src/web_service/verify_login.cpp index 02e1b74f3..124aa3863 100644 --- a/src/web_service/verify_login.cpp +++ b/src/web_service/verify_login.cpp @@ -2,7 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include "web_service/json.h" +#include #include "web_service/verify_login.h" #include "web_service/web_backend.h" diff --git a/src/yuzu/configuration/configure_web.cpp b/src/yuzu/configuration/configure_web.cpp index 4b5c39e26..d6bd3d309 100644 --- a/src/yuzu/configuration/configure_web.cpp +++ b/src/yuzu/configuration/configure_web.cpp @@ -31,18 +31,18 @@ void ConfigureWeb::setConfiguration() { ui->web_credentials_disclaimer->setWordWrap(true); ui->telemetry_learn_more->setOpenExternalLinks(true); ui->telemetry_learn_more->setText(tr("Learn more")); ui->web_signup_link->setOpenExternalLinks(true); ui->web_signup_link->setText( - tr("Sign up")); ui->web_token_info_link->setOpenExternalLinks(true); ui->web_token_info_link->setText( - tr("What is my token?")); ui->toggle_telemetry->setChecked(Settings::values.enable_telemetry); diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index f236c63c5..52743aefd 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -116,7 +116,7 @@ void GMainWindow::ShowTelemetryCallout() { UISettings::values.callout_flags |= static_cast(CalloutFlag::Telemetry); const QString telemetry_message = - tr("Anonymous " + tr("Anonymous " "data is collected to help improve yuzu. " "

Would you like to share your usage data with us?"); if (QMessageBox::question(this, tr("Telemetry"), telemetry_message) != QMessageBox::Yes) { diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h index eaa64da39..762396e3b 100644 --- a/src/yuzu_cmd/default_ini.h +++ b/src/yuzu_cmd/default_ini.h @@ -205,7 +205,7 @@ enable_telemetry = # URL for Web API web_api_url = https://api.yuzu-emu.org # Username and token for yuzu Web Service -# See https://services.citra-emu.org/ for more info +# See https://profile.yuzu-emu.org/ for more info yuzu_username = yuzu_token = )"; -- cgit v1.2.3 From ac06105dfe9c7e5306e1f4cac0ee12dc5f72f14e Mon Sep 17 00:00:00 2001 From: fearlessTobi Date: Sat, 29 Sep 2018 02:51:28 +0200 Subject: Review comments -part 4 --- CMakeLists.txt | 7 ------- src/core/CMakeLists.txt | 1 + src/web_service/web_backend.cpp | 4 ++-- src/yuzu/CMakeLists.txt | 4 ++++ 4 files changed, 7 insertions(+), 9 deletions(-) (limited to 'src/web_service') diff --git a/CMakeLists.txt b/CMakeLists.txt index 047443704..5e94e57ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -325,13 +325,6 @@ if (ENABLE_QT) find_package(Qt5 REQUIRED COMPONENTS Widgets OpenGL ${QT_PREFIX_HINT}) endif() -if (ENABLE_WEB_SERVICE) - add_definitions(-DENABLE_WEB_SERVICE) -endif() -if (YUZU_ENABLE_COMPATIBILITY_REPORTING) - add_definitions(-DYUZU_ENABLE_COMPATIBILITY_REPORTING) -endif() - # Platform-specific library requirements # ====================================== diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 95f8b5d4a..378d8128d 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -395,6 +395,7 @@ create_target_directory_groups(core) target_link_libraries(core PUBLIC common PRIVATE audio_core video_core) target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt lz4_static mbedtls opus unicorn open_source_archives) if (ENABLE_WEB_SERVICE) + add_definitions(-DENABLE_WEB_SERVICE) target_link_libraries(core PUBLIC json-headers web_service) endif() diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp index 5df4df5eb..787b0fbcb 100644 --- a/src/web_service/web_backend.cpp +++ b/src/web_service/web_backend.cpp @@ -13,7 +13,7 @@ namespace WebService { -constexpr char API_VERSION[]{"1"}; +constexpr std::array API_VERSION{'1'}; constexpr u32 HTTP_PORT = 80; constexpr u32 HTTPS_PORT = 443; @@ -70,7 +70,7 @@ Common::WebResult Client::GenericJson(const std::string& method, const std::stri }; } - params.emplace(std::string("api-version"), std::string(API_VERSION)); + params.emplace(std::string("api-version"), std::string(API_VERSION.begin(), API_VERSION.end())); if (method != "GET") { params.emplace(std::string("Content-Type"), std::string("application/json")); }; diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index f93ba2569..04464ad5e 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt @@ -120,6 +120,10 @@ target_link_libraries(yuzu PRIVATE common core input_common video_core) target_link_libraries(yuzu PRIVATE Boost::boost glad Qt5::OpenGL Qt5::Widgets) target_link_libraries(yuzu PRIVATE ${PLATFORM_LIBRARIES} Threads::Threads) +if (YUZU_ENABLE_COMPATIBILITY_REPORTING) + add_definitions(-DYUZU_ENABLE_COMPATIBILITY_REPORTING) +endif() + if (USE_DISCORD_PRESENCE) target_sources(yuzu PUBLIC discord_impl.cpp -- cgit v1.2.3 From e4daf4bee522c046e5e01eeed2c5b12bd91f489e Mon Sep 17 00:00:00 2001 From: fearlessTobi Date: Tue, 2 Oct 2018 16:04:10 +0200 Subject: Review comments - part 5 --- src/common/detached_tasks.h | 1 + src/web_service/CMakeLists.txt | 4 ++-- src/yuzu/configuration/configure_web.cpp | 8 +++----- src/yuzu/main.cpp | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) (limited to 'src/web_service') diff --git a/src/common/detached_tasks.h b/src/common/detached_tasks.h index eae27788d..5dd8fc27b 100644 --- a/src/common/detached_tasks.h +++ b/src/common/detached_tasks.h @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #pragma once + #include #include diff --git a/src/web_service/CMakeLists.txt b/src/web_service/CMakeLists.txt index ef77728c0..1c83e9c34 100644 --- a/src/web_service/CMakeLists.txt +++ b/src/web_service/CMakeLists.txt @@ -12,5 +12,5 @@ create_target_directory_groups(web_service) get_directory_property(OPENSSL_LIBS DIRECTORY ${CMAKE_SOURCE_DIR}/externals/libressl DEFINITION OPENSSL_LIBS) -add_definitions(-DCPPHTTPLIB_OPENSSL_SUPPORT) -target_link_libraries(web_service PUBLIC common json-headers ${OPENSSL_LIBS} httplib lurlparser) +target_compile_definitions(web_service PUBLIC -DCPPHTTPLIB_OPENSSL_SUPPORT) +target_link_libraries(web_service PRIVATE common json-headers ${OPENSSL_LIBS} httplib lurlparser) diff --git a/src/yuzu/configuration/configure_web.cpp b/src/yuzu/configuration/configure_web.cpp index d6bd3d309..5fb9251db 100644 --- a/src/yuzu/configuration/configure_web.cpp +++ b/src/yuzu/configuration/configure_web.cpp @@ -30,11 +30,9 @@ ConfigureWeb::~ConfigureWeb() = default; void ConfigureWeb::setConfiguration() { ui->web_credentials_disclaimer->setWordWrap(true); ui->telemetry_learn_more->setOpenExternalLinks(true); - ui->telemetry_learn_more->setText(tr("Learn more")); + ui->telemetry_learn_more->setText( + tr("Learn more")); ui->web_signup_link->setOpenExternalLinks(true); ui->web_signup_link->setText( diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 52743aefd..147e7fcad 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -116,7 +116,7 @@ void GMainWindow::ShowTelemetryCallout() { UISettings::values.callout_flags |= static_cast(CalloutFlag::Telemetry); const QString telemetry_message = - tr("Anonymous " + tr("Anonymous " "data is collected to help improve yuzu. " "

Would you like to share your usage data with us?"); if (QMessageBox::question(this, tr("Telemetry"), telemetry_message) != QMessageBox::Yes) { -- cgit v1.2.3