2017-06-28 03:01:49 +00:00
|
|
|
// Copyright 2017 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-09-19 01:18:26 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <future>
|
2017-06-28 03:18:52 +00:00
|
|
|
#include <string>
|
2017-10-31 09:02:42 +00:00
|
|
|
#include <tuple>
|
2018-08-25 19:39:23 +00:00
|
|
|
#include <httplib.h>
|
2017-10-31 09:02:42 +00:00
|
|
|
#include "common/announce_multiplayer_room.h"
|
2017-06-28 03:18:52 +00:00
|
|
|
#include "common/common_types.h"
|
|
|
|
|
2018-08-25 19:39:23 +00:00
|
|
|
namespace LUrlParser {
|
|
|
|
class clParseURL;
|
|
|
|
}
|
|
|
|
|
2017-06-28 03:01:49 +00:00
|
|
|
namespace WebService {
|
|
|
|
|
2017-06-28 03:18:52 +00:00
|
|
|
/**
|
2018-08-25 19:39:23 +00:00
|
|
|
* Requests a new JWT if necessary
|
|
|
|
* @param force_new_token If true, force to request a new token from the server.
|
|
|
|
* @param username Citra username to use for authentication.
|
|
|
|
* @param token Citra token to use for authentication.
|
|
|
|
* @return string with the current JWT toke
|
|
|
|
*/
|
|
|
|
std::string UpdateCoreJWT(bool force_new_token, const std::string& username,
|
|
|
|
const std::string& token);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Posts JSON to a api.citra-emu.org.
|
|
|
|
* @param url URL of the api.citra-emu.org endpoint to post data to.
|
|
|
|
* @param parsed_url Parsed URL used for the POST request.
|
|
|
|
* @param params Headers sent for the POST request.
|
|
|
|
* @param data String of JSON data to use for the body of the POST request.
|
|
|
|
* @param data If true, a JWT is requested in the function
|
|
|
|
* @return future with the returned value of the POST
|
|
|
|
*/
|
|
|
|
static Common::WebResult PostJsonAsyncFn(const std::string& url,
|
|
|
|
const LUrlParser::clParseURL& parsed_url,
|
|
|
|
const httplib::Headers& params, const std::string& data,
|
|
|
|
bool is_jwt_requested);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Posts JSON to api.citra-emu.org.
|
|
|
|
* @param url URL of the api.citra-emu.org endpoint to post data to.
|
2017-06-28 03:18:52 +00:00
|
|
|
* @param data String of JSON data to use for the body of the POST request.
|
2017-08-24 01:09:34 +00:00
|
|
|
* @param allow_anonymous If true, allow anonymous unauthenticated requests.
|
2018-08-25 19:39:23 +00:00
|
|
|
* @return future with the returned value of the POST
|
|
|
|
*/
|
|
|
|
std::future<Common::WebResult> PostJson(const std::string& url, const std::string& data,
|
|
|
|
bool allow_anonymous);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Posts JSON to api.citra-emu.org.
|
|
|
|
* @param url URL of the api.citra-emu.org endpoint to post data to.
|
2017-08-24 01:09:34 +00:00
|
|
|
* @param username Citra username to use for authentication.
|
|
|
|
* @param token Citra token to use for authentication.
|
2017-10-31 09:02:42 +00:00
|
|
|
* @return future with the error or result of the POST
|
2017-06-28 03:18:52 +00:00
|
|
|
*/
|
2018-08-25 19:39:23 +00:00
|
|
|
std::future<Common::WebResult> PostJson(const std::string& url, const std::string& username,
|
|
|
|
const std::string& token);
|
2017-06-28 03:18:52 +00:00
|
|
|
|
2017-09-19 01:18:26 +00:00
|
|
|
/**
|
2018-08-25 19:39:23 +00:00
|
|
|
* Gets JSON from api.citra-emu.org.
|
2017-09-19 01:18:26 +00:00
|
|
|
* @param func A function that gets exectued when the json as a string is received
|
2018-08-25 19:39:23 +00:00
|
|
|
* @param url URL of the api.citra-emu.org endpoint to post data to.
|
2017-09-19 01:18:26 +00:00
|
|
|
* @param allow_anonymous If true, allow anonymous unauthenticated requests.
|
|
|
|
* @return future that holds the return value T of the func
|
|
|
|
*/
|
|
|
|
template <typename T>
|
|
|
|
std::future<T> GetJson(std::function<T(const std::string&)> func, const std::string& url,
|
2018-08-25 19:39:23 +00:00
|
|
|
bool allow_anonymous);
|
2017-09-19 01:18:26 +00:00
|
|
|
|
2017-10-31 09:02:42 +00:00
|
|
|
/**
|
2018-08-25 19:39:23 +00:00
|
|
|
* Delete JSON to api.citra-emu.org.
|
|
|
|
* @param url URL of the api.citra-emu.org endpoint to post data to.
|
2017-10-31 09:02:42 +00:00
|
|
|
* @param data String of JSON data to use for the body of the DELETE request.
|
|
|
|
*/
|
2018-08-25 19:39:23 +00:00
|
|
|
void DeleteJson(const std::string& url, const std::string& data);
|
2017-10-31 09:02:42 +00:00
|
|
|
|
2017-06-28 03:01:49 +00:00
|
|
|
} // namespace WebService
|