MCPcopy Create free account
hub / github.com/ClassicOldSong/Apollo / pair

Function pair

src/nvhttp.cpp:704–829  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

702
703 template <class T>
704 void pair(std::shared_ptr<typename SimpleWeb::ServerBase<T>::Response> response, std::shared_ptr<typename SimpleWeb::ServerBase<T>::Request> request) {
705 print_req<T>(request);
706
707 pt::ptree tree;
708
709 auto fg = util::fail_guard([&]() {
710 std::ostringstream data;
711
712 pt::write_xml(data, tree);
713 response->write(data.str());
714 response->close_connection_after_response = true;
715 });
716
717 if (!config::sunshine.enable_pairing) {
718 tree.put("root.<xmlattr>.status_code", 403);
719 tree.put("root.<xmlattr>.status_message", "Pairing is disabled for this instance");
720
721 return;
722 }
723
724 auto args = request->parse_query_string();
725 if (args.find("uniqueid"s) == std::end(args)) {
726 tree.put("root.<xmlattr>.status_code", 400);
727 tree.put("root.<xmlattr>.status_message", "Missing uniqueid parameter");
728
729 return;
730 }
731
732 auto uniqID {get_arg(args, "uniqueid")};
733
734 args_t::const_iterator it;
735 if (it = args.find("phrase"); it != std::end(args)) {
736 if (it->second == "getservercert"sv) {
737 pair_session_t sess;
738
739 auto deviceName { get_arg(args, "devicename") };
740
741 if (deviceName == "roth"sv) {
742 deviceName = "Legacy Moonlight Client";
743 }
744
745 sess.client.uniqueID = std::move(uniqID);
746 sess.client.name = std::move(deviceName);
747 sess.client.cert = util::from_hex_vec(get_arg(args, "clientcert"), true);
748
749 BOOST_LOG(debug) << sess.client.cert;
750 auto ptr = map_id_sess.emplace(sess.client.uniqueID, std::move(sess)).first;
751
752 ptr->second.async_insert_pin.salt = std::move(get_arg(args, "salt"));
753
754 auto it = args.find("otpauth");
755 if (it != std::end(args)) {
756 if (one_time_pin.empty() || (std::chrono::steady_clock::now() - otp_creation_time > OTP_EXPIRE_DURATION)) {
757 one_time_pin.clear();
758 otp_passphrase.clear();
759 otp_device_name.clear();
760 tree.put("root.<xmlattr>.status_code", 503);
761 tree.put("root.<xmlattr>.status_message", "OTP auth not available.");

Callers

nothing calls this directly

Calls 15

fail_guardFunction · 0.85
get_argFunction · 0.85
moveFunction · 0.85
from_hex_vecFunction · 0.85
hexFunction · 0.85
getservercertFunction · 0.85
randFunction · 0.85
update_tray_require_pinFunction · 0.85
clientchallengeFunction · 0.85
serverchallengerespFunction · 0.85
clientpairingsecretFunction · 0.85
writeMethod · 0.80

Tested by

no test coverage detected