summaryrefslogtreecommitdiff
path: root/src/web_service
diff options
context:
space:
mode:
authorGravatar James Rowe2018-01-11 19:21:20 -0700
committerGravatar James Rowe2018-01-12 19:11:03 -0700
commitebf9a784a9f7f4148a669dbb39e7cd50df779a14 (patch)
treed585685a1c0a34b903af1d086d62560bf56bb29f /src/web_service
parentconfig: Default CPU core to Unicorn. (diff)
downloadyuzu-ebf9a784a9f7f4148a669dbb39e7cd50df779a14.tar.gz
yuzu-ebf9a784a9f7f4148a669dbb39e7cd50df779a14.tar.xz
yuzu-ebf9a784a9f7f4148a669dbb39e7cd50df779a14.zip
Massive removal of unused modules
Diffstat (limited to '')
-rw-r--r--src/web_service/CMakeLists.txt16
-rw-r--r--src/web_service/telemetry_json.cpp86
-rw-r--r--src/web_service/telemetry_json.h59
-rw-r--r--src/web_service/verify_login.cpp28
-rw-r--r--src/web_service/verify_login.h24
-rw-r--r--src/web_service/web_backend.cpp140
-rw-r--r--src/web_service/web_backend.h39
7 files changed, 0 insertions, 392 deletions
diff --git a/src/web_service/CMakeLists.txt b/src/web_service/CMakeLists.txt
deleted file mode 100644
index c93811892..000000000
--- a/src/web_service/CMakeLists.txt
+++ /dev/null
@@ -1,16 +0,0 @@
1set(SRCS
2 telemetry_json.cpp
3 verify_login.cpp
4 web_backend.cpp
5 )
6
7set(HEADERS
8 telemetry_json.h
9 verify_login.h
10 web_backend.h
11 )
12
13create_directory_groups(${SRCS} ${HEADERS})
14
15add_library(web_service STATIC ${SRCS} ${HEADERS})
16target_link_libraries(web_service PUBLIC common cpr json-headers)
diff --git a/src/web_service/telemetry_json.cpp b/src/web_service/telemetry_json.cpp
deleted file mode 100644
index 6ad2ffcd4..000000000
--- a/src/web_service/telemetry_json.cpp
+++ /dev/null
@@ -1,86 +0,0 @@
1// Copyright 2017 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "common/assert.h"
6#include "web_service/telemetry_json.h"
7#include "web_service/web_backend.h"
8
9namespace WebService {
10
11template <class T>
12void TelemetryJson::Serialize(Telemetry::FieldType type, const std::string& name, T value) {
13 sections[static_cast<u8>(type)][name] = value;
14}
15
16void TelemetryJson::SerializeSection(Telemetry::FieldType type, const std::string& name) {
17 TopSection()[name] = sections[static_cast<unsigned>(type)];
18}
19
20void TelemetryJson::Visit(const Telemetry::Field<bool>& field) {
21 Serialize(field.GetType(), field.GetName(), field.GetValue());
22}
23
24void TelemetryJson::Visit(const Telemetry::Field<double>& field) {
25 Serialize(field.GetType(), field.GetName(), field.GetValue());
26}
27
28void TelemetryJson::Visit(const Telemetry::Field<float>& field) {
29 Serialize(field.GetType(), field.GetName(), field.GetValue());
30}
31
32void TelemetryJson::Visit(const Telemetry::Field<u8>& field) {
33 Serialize(field.GetType(), field.GetName(), field.GetValue());
34}
35
36void TelemetryJson::Visit(const Telemetry::Field<u16>& field) {
37 Serialize(field.GetType(), field.GetName(), field.GetValue());
38}
39
40void TelemetryJson::Visit(const Telemetry::Field<u32>& field) {
41 Serialize(field.GetType(), field.GetName(), field.GetValue());
42}
43
44void TelemetryJson::Visit(const Telemetry::Field<u64>& field) {
45 Serialize(field.GetType(), field.GetName(), field.GetValue());
46}
47
48void TelemetryJson::Visit(const Telemetry::Field<s8>& field) {
49 Serialize(field.GetType(), field.GetName(), field.GetValue());
50}
51
52void TelemetryJson::Visit(const Telemetry::Field<s16>& field) {
53 Serialize(field.GetType(), field.GetName(), field.GetValue());
54}
55
56void TelemetryJson::Visit(const Telemetry::Field<s32>& field) {
57 Serialize(field.GetType(), field.GetName(), field.GetValue());
58}
59
60void TelemetryJson::Visit(const Telemetry::Field<s64>& field) {
61 Serialize(field.GetType(), field.GetName(), field.GetValue());
62}
63
64void TelemetryJson::Visit(const Telemetry::Field<std::string>& field) {
65 Serialize(field.GetType(), field.GetName(), field.GetValue());
66}
67
68void TelemetryJson::Visit(const Telemetry::Field<const char*>& field) {
69 Serialize(field.GetType(), field.GetName(), std::string(field.GetValue()));
70}
71
72void TelemetryJson::Visit(const Telemetry::Field<std::chrono::microseconds>& field) {
73 Serialize(field.GetType(), field.GetName(), field.GetValue().count());
74}
75
76void TelemetryJson::Complete() {
77 SerializeSection(Telemetry::FieldType::App, "App");
78 SerializeSection(Telemetry::FieldType::Session, "Session");
79 SerializeSection(Telemetry::FieldType::Performance, "Performance");
80 SerializeSection(Telemetry::FieldType::UserFeedback, "UserFeedback");
81 SerializeSection(Telemetry::FieldType::UserConfig, "UserConfig");
82 SerializeSection(Telemetry::FieldType::UserSystem, "UserSystem");
83 PostJson(endpoint_url, TopSection().dump(), true, username, token);
84}
85
86} // namespace WebService
diff --git a/src/web_service/telemetry_json.h b/src/web_service/telemetry_json.h
deleted file mode 100644
index 9e78c6803..000000000
--- a/src/web_service/telemetry_json.h
+++ /dev/null
@@ -1,59 +0,0 @@
1// Copyright 2017 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <array>
8#include <string>
9#include <json.hpp>
10#include "common/telemetry.h"
11
12namespace WebService {
13
14/**
15 * Implementation of VisitorInterface that serialized telemetry into JSON, and submits it to the
16 * Citra web service
17 */
18class TelemetryJson : public Telemetry::VisitorInterface {
19public:
20 TelemetryJson(const std::string& endpoint_url, const std::string& username,
21 const std::string& token)
22 : endpoint_url(endpoint_url), username(username), token(token) {}
23 ~TelemetryJson() = default;
24
25 void Visit(const Telemetry::Field<bool>& field) override;
26 void Visit(const Telemetry::Field<double>& field) override;
27 void Visit(const Telemetry::Field<float>& field) override;
28 void Visit(const Telemetry::Field<u8>& field) override;
29 void Visit(const Telemetry::Field<u16>& field) override;
30 void Visit(const Telemetry::Field<u32>& field) override;
31 void Visit(const Telemetry::Field<u64>& field) override;
32 void Visit(const Telemetry::Field<s8>& field) override;
33 void Visit(const Telemetry::Field<s16>& field) override;
34 void Visit(const Telemetry::Field<s32>& field) override;
35 void Visit(const Telemetry::Field<s64>& field) override;
36 void Visit(const Telemetry::Field<std::string>& field) override;
37 void Visit(const Telemetry::Field<const char*>& field) override;
38 void Visit(const Telemetry::Field<std::chrono::microseconds>& field) override;
39
40 void Complete() override;
41
42private:
43 nlohmann::json& TopSection() {
44 return sections[static_cast<u8>(Telemetry::FieldType::None)];
45 }
46
47 template <class T>
48 void Serialize(Telemetry::FieldType type, const std::string& name, T value);
49
50 void SerializeSection(Telemetry::FieldType type, const std::string& name);
51
52 nlohmann::json output;
53 std::array<nlohmann::json, 7> sections;
54 std::string endpoint_url;
55 std::string username;
56 std::string token;
57};
58
59} // namespace WebService
diff --git a/src/web_service/verify_login.cpp b/src/web_service/verify_login.cpp
deleted file mode 100644
index 1bc3b5afe..000000000
--- a/src/web_service/verify_login.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
1// Copyright 2017 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <json.hpp>
6#include "web_service/verify_login.h"
7#include "web_service/web_backend.h"
8
9namespace WebService {
10
11std::future<bool> VerifyLogin(std::string& username, std::string& token,
12 const std::string& endpoint_url, std::function<void()> func) {
13 auto get_func = [func, username](const std::string& reply) -> bool {
14 func();
15 if (reply.empty())
16 return false;
17 nlohmann::json json = nlohmann::json::parse(reply);
18 std::string result;
19 try {
20 result = json["username"];
21 } catch (const nlohmann::detail::out_of_range&) {
22 }
23 return result == username;
24 };
25 return GetJson<bool>(get_func, endpoint_url, false, username, token);
26}
27
28} // namespace WebService
diff --git a/src/web_service/verify_login.h b/src/web_service/verify_login.h
deleted file mode 100644
index 303f5dbbc..000000000
--- a/src/web_service/verify_login.h
+++ /dev/null
@@ -1,24 +0,0 @@
1// Copyright 2017 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <functional>
8#include <future>
9#include <string>
10
11namespace WebService {
12
13/**
14 * Checks if username and token is valid
15 * @param username Citra username to use for authentication.
16 * @param token Citra token to use for authentication.
17 * @param endpoint_url URL of the services.citra-emu.org endpoint.
18 * @param func A function that gets exectued when the verification is finished
19 * @returns Future with bool indicating whether the verification succeeded
20 */
21std::future<bool> VerifyLogin(std::string& username, std::string& token,
22 const std::string& endpoint_url, std::function<void()> func);
23
24} // namespace WebService
diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp
deleted file mode 100644
index b17d82f9c..000000000
--- a/src/web_service/web_backend.cpp
+++ /dev/null
@@ -1,140 +0,0 @@
1// Copyright 2017 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#ifdef _WIN32
6#include <winsock.h>
7#endif
8
9#include <cstdlib>
10#include <thread>
11#include <cpr/cpr.h>
12#include "common/logging/log.h"
13#include "web_service/web_backend.h"
14
15namespace WebService {
16
17static constexpr char API_VERSION[]{"1"};
18
19static std::unique_ptr<cpr::Session> g_session;
20
21void Win32WSAStartup() {
22#ifdef _WIN32
23 // On Windows, CPR/libcurl does not properly initialize Winsock. The below code is used to
24 // initialize Winsock globally, which fixes this problem. Without this, only the first CPR
25 // session will properly be created, and subsequent ones will fail.
26 WSADATA wsa_data;
27 const int wsa_result{WSAStartup(MAKEWORD(2, 2), &wsa_data)};
28 if (wsa_result) {
29 LOG_CRITICAL(WebService, "WSAStartup failed: %d", wsa_result);
30 }
31#endif
32}
33
34void PostJson(const std::string& url, const std::string& data, bool allow_anonymous,
35 const std::string& username, const std::string& token) {
36 if (url.empty()) {
37 LOG_ERROR(WebService, "URL is invalid");
38 return;
39 }
40
41 const bool are_credentials_provided{!token.empty() && !username.empty()};
42 if (!allow_anonymous && !are_credentials_provided) {
43 LOG_ERROR(WebService, "Credentials must be provided for authenticated requests");
44 return;
45 }
46
47 Win32WSAStartup();
48
49 // Built request header
50 cpr::Header header;
51 if (are_credentials_provided) {
52 // Authenticated request if credentials are provided
53 header = {{"Content-Type", "application/json"},
54 {"x-username", username.c_str()},
55 {"x-token", token.c_str()},
56 {"api-version", API_VERSION}};
57 } else {
58 // Otherwise, anonymous request
59 header = cpr::Header{{"Content-Type", "application/json"}, {"api-version", API_VERSION}};
60 }
61
62 // Post JSON asynchronously
63 static std::future<void> future;
64 future = cpr::PostCallback(
65 [](cpr::Response r) {
66 if (r.error) {
67 LOG_ERROR(WebService, "POST returned cpr error: %u:%s",
68 static_cast<u32>(r.error.code), r.error.message.c_str());
69 return;
70 }
71 if (r.status_code >= 400) {
72 LOG_ERROR(WebService, "POST returned error status code: %u", r.status_code);
73 return;
74 }
75 if (r.header["content-type"].find("application/json") == std::string::npos) {
76 LOG_ERROR(WebService, "POST returned wrong content: %s",
77 r.header["content-type"].c_str());
78 return;
79 }
80 },
81 cpr::Url{url}, cpr::Body{data}, header);
82}
83
84template <typename T>
85std::future<T> GetJson(std::function<T(const std::string&)> func, const std::string& url,
86 bool allow_anonymous, const std::string& username,
87 const std::string& token) {
88 if (url.empty()) {
89 LOG_ERROR(WebService, "URL is invalid");
90 return std::async(std::launch::async, [func{std::move(func)}]() { return func(""); });
91 }
92
93 const bool are_credentials_provided{!token.empty() && !username.empty()};
94 if (!allow_anonymous && !are_credentials_provided) {
95 LOG_ERROR(WebService, "Credentials must be provided for authenticated requests");
96 return std::async(std::launch::async, [func{std::move(func)}]() { return func(""); });
97 }
98
99 Win32WSAStartup();
100
101 // Built request header
102 cpr::Header header;
103 if (are_credentials_provided) {
104 // Authenticated request if credentials are provided
105 header = {{"Content-Type", "application/json"},
106 {"x-username", username.c_str()},
107 {"x-token", token.c_str()},
108 {"api-version", API_VERSION}};
109 } else {
110 // Otherwise, anonymous request
111 header = cpr::Header{{"Content-Type", "application/json"}, {"api-version", API_VERSION}};
112 }
113
114 // Get JSON asynchronously
115 return cpr::GetCallback(
116 [func{std::move(func)}](cpr::Response r) {
117 if (r.error) {
118 LOG_ERROR(WebService, "GET returned cpr error: %u:%s",
119 static_cast<u32>(r.error.code), r.error.message.c_str());
120 return func("");
121 }
122 if (r.status_code >= 400) {
123 LOG_ERROR(WebService, "GET returned error code: %u", r.status_code);
124 return func("");
125 }
126 if (r.header["content-type"].find("application/json") == std::string::npos) {
127 LOG_ERROR(WebService, "GET returned wrong content: %s",
128 r.header["content-type"].c_str());
129 return func("");
130 }
131 return func(r.text);
132 },
133 cpr::Url{url}, header);
134}
135
136template std::future<bool> GetJson(std::function<bool(const std::string&)> func,
137 const std::string& url, bool allow_anonymous,
138 const std::string& username, const std::string& token);
139
140} // namespace WebService
diff --git a/src/web_service/web_backend.h b/src/web_service/web_backend.h
deleted file mode 100644
index a63c75d13..000000000
--- a/src/web_service/web_backend.h
+++ /dev/null
@@ -1,39 +0,0 @@
1// Copyright 2017 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <functional>
8#include <future>
9#include <string>
10#include "common/common_types.h"
11
12namespace WebService {
13
14/**
15 * Posts JSON to services.citra-emu.org.
16 * @param url URL of the services.citra-emu.org endpoint to post data to.
17 * @param data String of JSON data to use for the body of the POST request.
18 * @param allow_anonymous If true, allow anonymous unauthenticated requests.
19 * @param username Citra username to use for authentication.
20 * @param token Citra token to use for authentication.
21 */
22void PostJson(const std::string& url, const std::string& data, bool allow_anonymous,
23 const std::string& username = {}, const std::string& token = {});
24
25/**
26 * Gets JSON from services.citra-emu.org.
27 * @param func A function that gets exectued when the json as a string is received
28 * @param url URL of the services.citra-emu.org endpoint to post data to.
29 * @param allow_anonymous If true, allow anonymous unauthenticated requests.
30 * @param username Citra username to use for authentication.
31 * @param token Citra token to use for authentication.
32 * @return future that holds the return value T of the func
33 */
34template <typename T>
35std::future<T> GetJson(std::function<T(const std::string&)> func, const std::string& url,
36 bool allow_anonymous, const std::string& username = {},
37 const std::string& token = {});
38
39} // namespace WebService