Sunshine latest
Self-hosted game stream host for Moonlight.
confighttp.cpp File Reference

Definitions for the Web UI Config HTTP server. More...

#include <algorithm>
#include <charconv>
#include <filesystem>
#include <format>
#include <fstream>
#include <new>
#include <optional>
#include <string_view>
#include <utility>
#include <vector>
#include <boost/algorithm/string.hpp>
#include <boost/asio/ssl/context.hpp>
#include <boost/filesystem.hpp>
#include <lizardbyte/common/env.h>
#include <nlohmann/json.hpp>
#include <Simple-Web-Server/crypto.hpp>
#include <Simple-Web-Server/server_https.hpp>
#include "platform/virtualhid_input.h"
#include "platform/windows/misc.h"
#include "platform/windows/utf_utils.h"
#include <Windows.h>
#include "config.h"
#include "confighttp.h"
#include "crypto.h"
#include "display_device.h"
#include "file_handler.h"
#include "globals.h"
#include "httpcommon.h"
#include "input.h"
#include "logging.h"
#include "network.h"
#include "nvhttp.h"
#include "platform/common.h"
#include "process.h"
#include "rtsp.h"
#include "system_tray.h"
#include "utility.h"
#include "uuid.h"
Include dependency graph for confighttp.cpp:

Classes

struct  confighttp::csrf_token_t
 CSRF token value and its expiration deadline. More...
class  confighttp::registry_key_t
 RAII wrapper for a Windows registry key handle. More...
class  confighttp::scoped_sensitive_string_clear_t
 Overwrite a request-local sensitive string when leaving scope. More...

Typedefs

using confighttp::args_t = SimpleWeb::CaseInsensitiveMultimap
 Case-insensitive map used for HTTP headers and query parameters.
using confighttp::https_handler_t = std::function<void(resp_https_t, req_https_t)>
 Handler signature for configuration UI HTTPS routes.
using confighttp::https_server_t = SimpleWeb::Server<SimpleWeb::HTTPS>
 HTTPS server type used for Sunshine's configuration UI.
using confighttp::req_https_t = std::shared_ptr<SimpleWeb::ServerBase<SimpleWeb::HTTPS>::Request>
 Shared HTTPS request object received by configuration handlers.
using confighttp::resp_https_t = std::shared_ptr<SimpleWeb::ServerBase<SimpleWeb::HTTPS>::Response>
 Shared HTTPS response object passed to configuration handlers.

Enumerations

enum class  confighttp::op_e { ADD , REMOVE }
 Client certificate operations accepted by the configuration API. More...

Functions

bool confighttp::authenticate (const resp_https_t &response, const req_https_t &request)
 Authenticate the user.
void confighttp::bad_request (const resp_https_t &response, const req_https_t &request, const std::string &error_message)
 Send a 400 Bad Request response.
void confighttp::browseDirectory (const resp_https_t &response, const req_https_t &request)
 Browse the server filesystem.
nlohmann::json confighttp::build_browse_entries (const fs::path &dir_path, const std::string &type_str)
 Lists, filters, and sorts the entries of a directory for the browse API.
nlohmann::json confighttp::build_driver_status (bool installed, const std::string &version, std::string_view minimum_version)
 Build a standard driver status response.
nlohmann::json confighttp::build_virtualhid_license_status (const lvh::LicenseResult &result)
 Convert a libvirtualhid license result into a Web UI response.
void confighttp::cancelPairing (const resp_https_t &response, const req_https_t &request)
 Cancel a client pairing request that is waiting for PIN approval. The body for the delete request should be JSON serialized in the following format:
bool confighttp::check_app_index (const resp_https_t &response, const req_https_t &request, int index)
 Validates the application index and sends an error response if invalid.
bool confighttp::check_content_type (const resp_https_t &response, const req_https_t &request, const std::string_view &contentType)
 Validate the request content type and send a bad request when mismatched.
void confighttp::closeApp (const resp_https_t &response, const req_https_t &request)
 Close the currently running application.
void confighttp::deleteApp (const resp_https_t &response, const req_https_t &request)
 Delete an application.
std::string confighttp::generate_csrf_token (const std::string &client_id)
 Generate a new CSRF token for a client.
std::string confighttp::get_client_id (const req_https_t &request)
 Get a unique client identifier for CSRF token management.
nlohmann::json confighttp::get_vigembus_driver_status ()
 Build ViGEmBus fallback driver version and installation status.
nlohmann::json confighttp::get_virtualhid_driver_status ()
 Build libvirtualhid driver version and installation status.
nlohmann::json confighttp::get_windows_drives ()
 Builds a JSON array of available Windows drive letters.
void confighttp::getApps (const resp_https_t &response, const req_https_t &request)
 Get the list of available applications.
void confighttp::getAsset (const resp_https_t &response, const req_https_t &request)
 Get an asset.
void confighttp::getClients (const resp_https_t &response, const req_https_t &request)
 Get the list of paired clients.
void confighttp::getConfig (const resp_https_t &response, const req_https_t &request)
 Get the configuration settings.
void confighttp::getCover (const resp_https_t &response, const req_https_t &request)
 Get an application's image.
void confighttp::getCSRFToken (const resp_https_t &response, const req_https_t &request)
 Get a CSRF token for the authenticated user.
void confighttp::getFaviconImage (const resp_https_t &response, const req_https_t &request)
 Get the favicon image.
void confighttp::getLocale (const resp_https_t &response, const req_https_t &request)
 Get the locale setting. This endpoint does not require authentication.
void confighttp::getLogs (const resp_https_t &response, const req_https_t &request)
 Get the logs from the log file.
void confighttp::getPage (const resp_https_t &response, const req_https_t &request, const char *html_file, const bool require_auth, const bool redirect_if_username)
 Get an HTML page.
void confighttp::getPendingPairings (const resp_https_t &response, const req_https_t &request)
 List client pairing requests that are waiting for PIN approval.
void confighttp::getSunshineLogoImage (const resp_https_t &response, const req_https_t &request)
 Get the Sunshine logo image.
void confighttp::getVirtualInputLicense (const resp_https_t &response, const req_https_t &request)
 Get the current libvirtualhid machine license status.
void confighttp::getVirtualInputStatus (const resp_https_t &response, const req_https_t &request)
 Get virtual input driver version and installation status.
bool confighttp::is_browsable_executable (const fs::directory_entry &entry, const fs::file_status &status)
 Checks whether a directory entry qualifies as an executable file.
bool confighttp::is_driver_version_development (std::string_view version)
 Check whether a detected driver version identifies a development build.
bool confighttp::is_driver_version_supported (std::string_view version, std::string_view minimum_version)
 Check whether a detected driver version satisfies a minimum version.
bool confighttp::isChildPath (fs::path const &base, fs::path const &query)
 Check if a path is a child of another path.
void confighttp::not_found (const resp_https_t &response, const req_https_t &request, const std::string &error_message)
 Send a 404 Not Found response.
std::optional< std::vector< unsigned int > > confighttp::parse_driver_version (std::string_view version)
 Parse a dotted driver version into numeric components.
std::optional< unsigned int > confighttp::parse_driver_version_part (std::string_view part)
 Parse one dotted driver-version component.
void confighttp::print_req (const req_https_t &request)
 Log the request details.
std::string confighttp::read_libvirtualhid_driver_version ()
 Read the installed libvirtualhid driver version from the Windows device registry.
std::optional< std::wstring > confighttp::read_registry_string_value (HKEY key, const wchar_t *value_name)
 Read a string value from a Windows registry key.
void confighttp::resetDisplayDevicePersistence (const resp_https_t &response, const req_https_t &request)
 Reset the display device persistence.
void confighttp::resetPortalToken (const resp_https_t &response, const req_https_t &request)
 Authenticate a Web UI request and delete the saved XDG Portal restore token.
void confighttp::restart (const resp_https_t &response, const req_https_t &request)
 Authenticate a Web UI request and restart the Sunshine process.
void confighttp::saveApp (const resp_https_t &response, const req_https_t &request)
 Save an application. To save a new application, the index must be -1. To update an existing application, you must provide the current index of the application.
void confighttp::saveConfig (const resp_https_t &response, const req_https_t &request)
 Save the configuration settings.
void confighttp::savePassword (const resp_https_t &response, const req_https_t &request)
 Update existing credentials.
void confighttp::savePin (const resp_https_t &response, const req_https_t &request)
 Submit a PIN and return whether the selected client completes pairing.
void confighttp::send_redirect (const resp_https_t &response, const req_https_t &request, const char *path)
 Send a redirect response.
void confighttp::send_response (const resp_https_t &response, const nlohmann::json &output_tree)
 Send a response.
void confighttp::send_unauthorized (const resp_https_t &response, const req_https_t &request)
 Send a 401 Unauthorized response.
void confighttp::start ()
 Start the HTTPS configuration server.
void confighttp::unpair (const resp_https_t &response, const req_https_t &request)
 Unpair a client.
void confighttp::unpairAll (const resp_https_t &response, const req_https_t &request)
 Unpair all clients.
void confighttp::updateClient (resp_https_t response, req_https_t request)
 Enable or disable a client.
void confighttp::updateVirtualInputLicense (const resp_https_t &response, const req_https_t &request)
 Activate, validate, or deactivate the libvirtualhid machine license.
void confighttp::uploadCover (const resp_https_t &response, const req_https_t &request)
 Upload a cover image.
bool confighttp::validate_csrf_token (const resp_https_t &response, const req_https_t &request, const std::string &client_id)
 Validate CSRF token.
bool confighttp::validate_stored_csrf_token (const resp_https_t &response, const req_https_t &request, const std::string_view client_id, const std::string_view provided_token)
 Validate a stored CSRF token for a client against a provided token string.
std::string_view confighttp::virtualhid_license_state_name (lvh::LicenseState state)
 Return a stable Web UI name for a libvirtualhid license state.

Variables

constexpr auto confighttp::CSRF_TOKEN_LIFETIME = std::chrono::hours(1)
 Amount of time a generated CSRF token remains valid.
constexpr auto confighttp::CSRF_TOKEN_SIZE = 32
 Number of random bytes used when generating a CSRF token.
std::map< std::string, csrf_token_t, std::less<> > confighttp::csrf_tokens
 CSRF tokens by client identifier. NOSONAR(cpp:S5421) - intentionally mutable global.
std::mutex confighttp::csrf_tokens_mutex
 Mutex protecting CSRF token storage. NOSONAR(cpp:S5421) - intentionally mutable global.
constexpr std::string_view confighttp::libvirtualhid_minimum_version = LIBVIRTUALHID_MINIMUM_VERSION
 Minimum supported libvirtualhid driver version.
constexpr auto confighttp::VIGEMBUS_MINIMUM_VERSION = "1.17.0.0"sv
 Minimum supported ViGEmBus fallback driver version. // NOSONAR(cpp:S1313): not an IP address.

Detailed Description

Definitions for the Web UI Config HTTP server.

Todo
Authentication, better handling of routes common to nvhttp, cleanup

Enumeration Type Documentation

◆ op_e

enum class confighttp::op_e
strong

Client certificate operations accepted by the configuration API.

Enumerator
ADD 

Add client.

REMOVE 

Remove client.

Function Documentation

◆ authenticate()

bool confighttp::authenticate ( const resp_https_t & response,
const req_https_t & request )

Authenticate the user.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
Returns
True if the user is authenticated, false otherwise.

◆ bad_request()

void confighttp::bad_request ( const resp_https_t & response,
const req_https_t & request,
const std::string & error_message )

Send a 400 Bad Request response.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
error_messageThe error message to include in the response.

◆ browseDirectory()

void confighttp::browseDirectory ( const resp_https_t & response,
const req_https_t & request )

Browse the server filesystem.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
Note
On Windows, an empty or root path returns the list of available drive letters.
On non-Windows, an empty path defaults to the filesystem root ("/").

◆ build_browse_entries()

nlohmann::json confighttp::build_browse_entries ( const fs::path & dir_path,
const std::string & type_str )

Lists, filters, and sorts the entries of a directory for the browse API.

Parameters
dir_pathThe directory to list.
type_strFilter type: "directory", "executable", "file", or "any".
Returns
Sorted JSON array of entry objects with name/type/path fields.

◆ build_driver_status()

nlohmann::json confighttp::build_driver_status ( bool installed,
const std::string & version,
std::string_view minimum_version )

Build a standard driver status response.

Parameters
installedWhether the driver was detected.
versionDetected driver version.
minimum_versionMinimum supported driver version, or empty for any version.
Returns
Driver status JSON object.

◆ build_virtualhid_license_status()

nlohmann::json confighttp::build_virtualhid_license_status ( const lvh::LicenseResult & result)

Convert a libvirtualhid license result into a Web UI response.

Parameters
resultLicense operation result.
Returns
License status JSON object without the submitted license key.

◆ cancelPairing()

void confighttp::cancelPairing ( const resp_https_t & response,
const req_https_t & request )

Cancel a client pairing request that is waiting for PIN approval. The body for the delete request should be JSON serialized in the following format:

Cancel an explicitly selected pairing request.

{
"pairing_id": "<pairing_id>"
}

Parameters
responseHTTP response object to populate.
requestHTTP request data from the client.

◆ check_app_index()

bool confighttp::check_app_index ( const resp_https_t & response,
const req_https_t & request,
int index )

Validates the application index and sends an error response if invalid.

Check app index.

Parameters
responseHTTP response object to populate.
requestHTTP request data from the client.
indexZero-based index of the item being addressed.
Returns
True when the request passes validation and processing may continue.

◆ check_content_type()

bool confighttp::check_content_type ( const resp_https_t & response,
const req_https_t & request,
const std::string_view & contentType )

Validate the request content type and send a bad request when mismatched.

Check content type.

Parameters
responseHTTP response object to populate.
requestHTTP request data from the client.
contentTypeExpected HTTP content type.
Returns
True when the request passes validation and processing may continue.

◆ closeApp()

void confighttp::closeApp ( const resp_https_t & response,
const req_https_t & request )

Close the currently running application.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ deleteApp()

void confighttp::deleteApp ( const resp_https_t & response,
const req_https_t & request )

Delete an application.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ generate_csrf_token()

std::string confighttp::generate_csrf_token ( const std::string & client_id)

Generate a new CSRF token for a client.

Parameters
client_idA unique identifier for the client (e.g., session ID or username).
Returns
The generated CSRF token.

◆ get_client_id()

std::string confighttp::get_client_id ( const req_https_t & request)

Get a unique client identifier for CSRF token management.

Parameters
requestThe HTTP request object.
Returns
A unique identifier based on username or IP address.

◆ get_vigembus_driver_status()

nlohmann::json confighttp::get_vigembus_driver_status ( )

Build ViGEmBus fallback driver version and installation status.

Returns
ViGEmBus fallback driver status JSON.

◆ get_virtualhid_driver_status()

nlohmann::json confighttp::get_virtualhid_driver_status ( )

Build libvirtualhid driver version and installation status.

Returns
libvirtualhid driver status JSON.

◆ get_windows_drives()

nlohmann::json confighttp::get_windows_drives ( )

Builds a JSON array of available Windows drive letters.

Returns
JSON array of drive-letter entries.

◆ getApps()

void confighttp::getApps ( const resp_https_t & response,
const req_https_t & request )

Get the list of available applications.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ getAsset()

void confighttp::getAsset ( const resp_https_t & response,
const req_https_t & request )

Get an asset.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ getClients()

void confighttp::getClients ( const resp_https_t & response,
const req_https_t & request )

Get the list of paired clients.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ getConfig()

void confighttp::getConfig ( const resp_https_t & response,
const req_https_t & request )

Get the configuration settings.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ getCover()

void confighttp::getCover ( const resp_https_t & response,
const req_https_t & request )

Get an application's image.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
Note
The index in the url path is the application index.

◆ getCSRFToken()

void confighttp::getCSRFToken ( const resp_https_t & response,
const req_https_t & request )

Get a CSRF token for the authenticated user.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ getFaviconImage()

void confighttp::getFaviconImage ( const resp_https_t & response,
const req_https_t & request )

Get the favicon image.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
Todo

combine function with getSunshineLogoImage and possibly getNodeModules

use mime_types map

◆ getLocale()

void confighttp::getLocale ( const resp_https_t & response,
const req_https_t & request )

Get the locale setting. This endpoint does not require authentication.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ getLogs()

void confighttp::getLogs ( const resp_https_t & response,
const req_https_t & request )

Get the logs from the log file.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ getPage()

void confighttp::getPage ( const resp_https_t & response,
const req_https_t & request,
const char * html_file,
const bool require_auth,
const bool redirect_if_username )

Get an HTML page.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
html_fileThe HTML file to serve (relative to WEB_DIR).
require_authWhether to require authentication (default: true).
redirect_if_usernameIf true, redirect to "/" when the username is set (for welcome page).

◆ getPendingPairings()

void confighttp::getPendingPairings ( const resp_https_t & response,
const req_https_t & request )

List client pairing requests that are waiting for PIN approval.

List authenticated pairing requests awaiting operator approval.

Parameters
responseHTTP response object to populate.
requestHTTP request data from the client.

◆ getSunshineLogoImage()

void confighttp::getSunshineLogoImage ( const resp_https_t & response,
const req_https_t & request )

Get the Sunshine logo image.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
Todo

combine function with getFaviconImage and possibly getNodeModules

use mime_types map

◆ getVirtualInputLicense()

void confighttp::getVirtualInputLicense ( const resp_https_t & response,
const req_https_t & request )

Get the current libvirtualhid machine license status.

Parameters
responseHTTP response object.
requestAuthenticated HTTP request.

◆ getVirtualInputStatus()

void confighttp::getVirtualInputStatus ( const resp_https_t & response,
const req_https_t & request )

Get virtual input driver version and installation status.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ is_browsable_executable()

bool confighttp::is_browsable_executable ( const fs::directory_entry & entry,
const fs::file_status & status )

Checks whether a directory entry qualifies as an executable file.

Parameters
entryThe directory entry to check.
statusThe cached file status for the entry.
Returns
True if the file should be included in an executable-type listing.

◆ is_driver_version_development()

bool confighttp::is_driver_version_development ( std::string_view version)

Check whether a detected driver version identifies a development build.

Numeric versions beginning with 0.0 and containing at least three components are development builds.

Parameters
versionDetected driver version.
Returns
True when the version identifies a development build.

◆ is_driver_version_supported()

bool confighttp::is_driver_version_supported ( std::string_view version,
std::string_view minimum_version )

Check whether a detected driver version satisfies a minimum version.

Empty minimum versions accept any detected version. Non-empty minimum versions require a fully numeric dotted version string. Development versions beginning with 0.0 are always accepted.

Parameters
versionDetected driver version.
minimum_versionMinimum supported driver version, or empty for any version.
Returns
True when the driver version is supported.

◆ isChildPath()

bool confighttp::isChildPath ( fs::path const & base,
fs::path const & query )

Check if a path is a child of another path.

Parameters
baseThe base path.
queryThe path to check.
Returns
True if the path is a child of the base path, false otherwise.

◆ not_found()

void confighttp::not_found ( const resp_https_t & response,
const req_https_t & request,
const std::string & error_message )

Send a 404 Not Found response.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
error_messageThe error message to include in the response.

◆ parse_driver_version()

std::optional< std::vector< unsigned int > > confighttp::parse_driver_version ( std::string_view version)

Parse a dotted driver version into numeric components.

Parameters
versionDriver version text.
Returns
Parsed version parts, or empty when invalid.

◆ parse_driver_version_part()

std::optional< unsigned int > confighttp::parse_driver_version_part ( std::string_view part)

Parse one dotted driver-version component.

Parameters
partVersion component text.
Returns
Parsed component value, or empty when invalid.

◆ print_req()

void confighttp::print_req ( const req_https_t & request)

Log the request details.

Parameters
requestThe HTTP request object.

◆ read_libvirtualhid_driver_version()

std::string confighttp::read_libvirtualhid_driver_version ( )

Read the installed libvirtualhid driver version from the Windows device registry.

Returns
Driver version string, or empty when unavailable.

◆ read_registry_string_value()

std::optional< std::wstring > confighttp::read_registry_string_value ( HKEY key,
const wchar_t * value_name )

Read a string value from a Windows registry key.

Parameters
keyRegistry key to query.
value_nameRegistry value name.
Returns
Registry string value, or empty when unavailable.

◆ resetDisplayDevicePersistence()

void confighttp::resetDisplayDevicePersistence ( const resp_https_t & response,
const req_https_t & request )

Reset the display device persistence.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ resetPortalToken()

void confighttp::resetPortalToken ( const resp_https_t & response,
const req_https_t & request )

Authenticate a Web UI request and delete the saved XDG Portal restore token.

On platforms without XDG Portal capture, this operation succeeds without changing the filesystem.

Parameters
responseHTTP response used for authentication, CSRF, and status output.
requestHTTP request carrying the client identity and CSRF token.

◆ restart()

void confighttp::restart ( const resp_https_t & response,
const req_https_t & request )

Authenticate a Web UI request and restart the Sunshine process.

Parameters
responseHTTP response used for authentication or CSRF failures.
requestHTTP request carrying the client identity and CSRF token.

◆ saveApp()

void confighttp::saveApp ( const resp_https_t & response,
const req_https_t & request )

Save an application. To save a new application, the index must be -1. To update an existing application, you must provide the current index of the application.

Parameters
responseThe HTTP response object.
requestThe HTTP request object. The body for the post request should be JSON serialized in the following format:
{
"name": "Application Name",
"output": "Log Output Path",
"cmd": "Command to run the application",
"index": -1,
"exclude-global-prep-cmd": false,
"elevated": false,
"auto-detach": true,
"wait-all": true,
"exit-timeout": 5,
"prep-cmd": [
{
"do": "Command to prepare",
"undo": "Command to undo preparation",
"elevated": false
}
],
"detached": [
"Detached command"
],
"image-path": "Full path to the application image. Must be a png file."
}

◆ saveConfig()

void confighttp::saveConfig ( const resp_https_t & response,
const req_https_t & request )

Save the configuration settings.

Parameters
responseThe HTTP response object.
requestThe HTTP request object. The body for the POST request should be JSON serialized in the following format:
{
"key": "value"
}
Attention
It is recommended to ONLY save the config settings that differ from the default behavior.

◆ savePassword()

void confighttp::savePassword ( const resp_https_t & response,
const req_https_t & request )

Update existing credentials.

Parameters
responseThe HTTP response object.
requestThe HTTP request object. The body for the post request should be JSON serialized in the following format:
{
"currentUsername": "Current Username",
"currentPassword": "Current Password",
"newUsername": "New Username",
"newPassword": "New Password",
"confirmNewPassword": "Confirm New Password"
}

◆ savePin()

void confighttp::savePin ( const resp_https_t & response,
const req_https_t & request )

Submit a PIN and return whether the selected client completes pairing.

Apply a PIN to an explicitly selected pairing request.

The request remains open for up to the configured ping_timeout while Moonlight completes the cryptographic handshake. A wrong PIN, protocol failure, cancellation, or timeout returns {"status":false}. The body for the post request should be JSON serialized in the following format:

{
"pairing_id": "<pairing_id>",
"pin": "<pin>",
"name": "Friendly Client Name"
}

Parameters
responseHTTP response object to populate.
requestHTTP request data from the client.

◆ send_redirect()

void confighttp::send_redirect ( const resp_https_t & response,
const req_https_t & request,
const char * path )

Send a redirect response.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
pathThe path to redirect to.

◆ send_response()

void confighttp::send_response ( const resp_https_t & response,
const nlohmann::json & output_tree )

Send a response.

Parameters
responseThe HTTP response object.
output_treeThe JSON tree to send.

◆ send_unauthorized()

void confighttp::send_unauthorized ( const resp_https_t & response,
const req_https_t & request )

Send a 401 Unauthorized response.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ unpair()

void confighttp::unpair ( const resp_https_t & response,
const req_https_t & request )

Unpair a client.

Parameters
responseThe HTTP response object.
requestThe HTTP request object. The body for the POST request should be JSON serialized in the following format:
{
"uuid": "<uuid>"
}

◆ unpairAll()

void confighttp::unpairAll ( const resp_https_t & response,
const req_https_t & request )

Unpair all clients.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ updateClient()

void confighttp::updateClient ( resp_https_t response,
req_https_t request )

Enable or disable a client.

Parameters
responseThe HTTP response object.
requestThe HTTP request object. The body for the POST request should be JSON serialized in the following format:
{
"uuid": "<uuid>",
"enabled": true
}

◆ updateVirtualInputLicense()

void confighttp::updateVirtualInputLicense ( const resp_https_t & response,
const req_https_t & request )

Activate, validate, or deactivate the libvirtualhid machine license.

Submitted license keys are used only for the synchronous broker call. They are never logged or saved in Sunshine's configuration, and extracted mutable copies are overwritten before the handler returns.

Parameters
responseHTTP response object.
requestAuthenticated HTTP request with a JSON action.

◆ uploadCover()

void confighttp::uploadCover ( const resp_https_t & response,
const req_https_t & request )

Upload a cover image.

Parameters
responseThe HTTP response object.
requestThe HTTP request object. The body for the post request should be JSON serialized in the following format:
{
"key": "igdb_<game_id>",
"url": "https://images.igdb.com/igdb/image/upload/t_cover_big_2x/<slug>.png"
}

◆ validate_csrf_token()

bool confighttp::validate_csrf_token ( const resp_https_t & response,
const req_https_t & request,
const std::string & client_id )

Validate CSRF token.

Parameters
responseHTTP response object to populate.
requestHTTP request data from the client.
client_idClient identifier used to look up the CSRF token.
Returns
True when the request passes validation and processing may continue.

◆ validate_stored_csrf_token()

bool confighttp::validate_stored_csrf_token ( const resp_https_t & response,
const req_https_t & request,
const std::string_view client_id,
const std::string_view provided_token )

Validate a stored CSRF token for a client against a provided token string.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
client_idA unique identifier for the client.
provided_tokenThe token string to validate.
Returns
True if the token is valid, false otherwise.

◆ virtualhid_license_state_name()

std::string_view confighttp::virtualhid_license_state_name ( lvh::LicenseState state)

Return a stable Web UI name for a libvirtualhid license state.

Parameters
stateLicense state.
Returns
Lowercase state name.