From 2e7655bfff677e9427b7b90cab0a237b4ee7e747 Mon Sep 17 00:00:00 2001 From: Xander Frangos <33106561+xanderfrangos@users.noreply.github.com> Date: Sat, 20 Jan 2024 02:58:15 -0500 Subject: [PATCH] During unpairing, also remove cert from client.certs --- src/nvhttp.cpp | 29 ++++++++++++++++++++++------- src/nvhttp.h | 2 +- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/nvhttp.cpp b/src/nvhttp.cpp index 1ac44cbe50c..93f72edbdf2 100644 --- a/src/nvhttp.cpp +++ b/src/nvhttp.cpp @@ -1162,18 +1162,33 @@ namespace nvhttp { * nvhttp::unpair_client("4D7BB2DD-5704-A405-B41C-891A022932E1"); * ``` */ - bool + int unpair_client(std::string uniqueID) { + int removed = 0; for (auto &[_, client] : map_id_client) { - for (auto it = client.named_certs.begin(); it != client.named_certs.end();) - { - if ((*it).uniqueID == uniqueID) + for (auto it = client.named_certs.begin(); it != client.named_certs.end();) { + if ((*it).uniqueID == uniqueID) { + // Find matching cert and remove it + for (auto cert = client.certs.begin(); cert != client.certs.end();) { + if ((*cert) == (*it).cert) { + cert = client.certs.erase(cert); + removed++; + } + else { + ++cert; + } + } + + // And then remove the named cert it = client.named_certs.erase(it); - else + removed++; + } + else { ++it; - } + } + } } save_state(); - return true; + return removed; } } // namespace nvhttp diff --git a/src/nvhttp.h b/src/nvhttp.h index f150bae14e1..6fdf202ac29 100644 --- a/src/nvhttp.h +++ b/src/nvhttp.h @@ -47,7 +47,7 @@ namespace nvhttp { start(); bool pin(std::string pin, std::string name); - bool + int unpair_client(std::string uniqueid); boost::property_tree::ptree get_all_clients();