Merge commit from fork

This commit is contained in:
Dave Lane authored and GitHub committed 2026-09-02 19:48:25 -04:00
1 parent 1583e7c4a7
commit ccf97e3879
9 files changed
+903 -91

No files matched your search

+87 -10
View File
@@ -1704,18 +1704,86 @@ namespace confighttp {
}
/**
* @brief Send a pin code to the host. The pin is generated from the Moonlight client during the pairing process.
* @param response The HTTP response object.
* @param request The HTTP request object.
* @brief List client pairing requests that are waiting for PIN approval.
*
* @api_examples{/api/pin| GET| null}
*/
void getPendingPairings(const resp_https_t &response, const req_https_t &request) {
if (!authenticate(response, request)) {
return;
}
print_req(request);
nlohmann::json output_tree;
output_tree["pairings"] = nlohmann::json::array();
for (const auto &pairing : nvhttp::get_pending_pairings()) {
output_tree["pairings"].push_back({
{"id", pairing.id},
{"name", pairing.name},
{"address", pairing.address},
});
}
send_response(response, output_tree);
}
/**
* @brief 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:
* @code{.json}
* {
* "pairing_id": "<pairing_id>"
* }
* @endcode
*
* @api_examples{/api/pin| DELETE| {"pairing_id":"0123456789abcdef0123456789abcdef"}}
*/
void cancelPairing(const resp_https_t &response, const req_https_t &request) {
if (!check_content_type(response, request, "application/json")) {
return;
}
if (!authenticate(response, request)) {
return;
}
const std::string client_id = get_client_id(request);
if (!validate_csrf_token(response, request, client_id)) {
return;
}
print_req(request);
std::stringstream ss;
ss << request->content.rdbuf();
try {
const nlohmann::json input_tree = nlohmann::json::parse(ss);
const std::string pairing_id = input_tree.value("pairing_id", "");
if (!nvhttp::is_valid_pairing_id(pairing_id)) {
bad_request(response, request, "pairing_id must contain exactly 32 hexadecimal characters");
return;
}
nlohmann::json output_tree;
output_tree["status"] = nvhttp::cancel_pairing(pairing_id);
send_response(response, output_tree);
} catch (std::exception &e) {
BOOST_LOG(warning) << "CancelPairing: "sv << e.what();
bad_request(response, request, e.what());
}
}
/**
* @brief Send a PIN code to the explicitly selected pairing request.
* The body for the post request should be JSON serialized in the following format:
* @code{.json}
* {
* "pairing_id": "<pairing_id>",
* "pin": "<pin>",
* "name": "Friendly Client Name"
* }
* @endcode
*
* @api_examples{/api/pin| POST| {"pin":"1234","name":"My PC"}}
* @api_examples{/api/pin| POST| {"pairing_id":"0123456789abcdef0123456789abcdef","pin":"1234","name":"My PC"}}
*/
void savePin(const resp_https_t &response, const req_https_t &request) {
if (!check_content_type(response, request, "application/json")) {
@@ -1738,15 +1806,22 @@ namespace confighttp {
nlohmann::json output_tree;
nlohmann::json input_tree = nlohmann::json::parse(ss);
const std::string name = input_tree.value("name", "");
const std::string pairing_id = input_tree.value("pairing_id", "");
const std::string pin = input_tree.value("pin", "");
int _pin = 0;
_pin = std::stoi(pin);
if (_pin < 0 || _pin > 9999) {
bad_request(response, request, "PIN must be between 0000 and 9999");
if (!nvhttp::is_valid_pairing_id(pairing_id)) {
bad_request(response, request, "pairing_id must contain exactly 32 hexadecimal characters");
return;
}
if (!nvhttp::is_valid_pairing_pin(pin)) {
bad_request(response, request, "PIN must contain exactly 4 numeric digits");
return;
}
if (!nvhttp::is_valid_pairing_name(name)) {
bad_request(response, request, "Client name must contain between 1 and 128 bytes");
return;
}
output_tree["status"] = nvhttp::pin(pin, name);
output_tree["status"] = nvhttp::pin(pairing_id, pin, name);
send_response(response, output_tree);
} catch (std::exception &e) {
BOOST_LOG(warning) << "SavePin: "sv << e.what();
@@ -2217,6 +2292,8 @@ namespace confighttp {
server.resource["^/api/covers/upload$"]["POST"] = uploadCover;
server.resource["^/api/csrf-token$"]["GET"] = getCSRFToken;
server.resource["^/api/password$"]["POST"] = savePassword;
server.resource["^/api/pin$"]["DELETE"] = cancelPairing;
server.resource["^/api/pin$"]["GET"] = getPendingPairings;
server.resource["^/api/pin$"]["POST"] = savePin;
server.resource["^/api/logs$"]["GET"] = getLogs;
server.resource["^/api/reset-display-device-persistence$"]["POST"] = resetDisplayDevicePersistence;