GlosSITarget: Add API to insert launched-pids

pull/192/head
Peter Repukat 2 years ago
parent 18a960abab
commit cafb4e85a8

@ -176,6 +176,20 @@ std::vector<DWORD> AppLauncher::launchedPids()
return res;
}
void AppLauncher::addPids(const std::vector<DWORD>& pids)
{
pid_mutex_.lock();
for (const auto pid : pids) {
if (pid > 0 && std::ranges::find(pids_, pid) == pids_.end()) {
if (Settings::common.extendedLogging) {
spdlog::debug("Added PID {} via API", pid);
}
pids_.push_back(pid);
}
}
pid_mutex_.unlock();
}
#ifdef _WIN32
bool AppLauncher::IsProcessRunning(DWORD pid)
{

@ -38,6 +38,7 @@ class AppLauncher {
void close();
std::vector<DWORD> launchedPids();
void addPids(const std::vector<DWORD>& pids);
private:
std::function<void()> shutdown_;

@ -32,6 +32,36 @@ void HttpServer::run()
res.set_content(j.dump(), "text/json");
});
server_.Post("/launched-pids", [this](const httplib::Request& req, httplib::Response& res) {
try {
const nlohmann::json postbody = nlohmann::json::parse(req.body);
app_launcher_.addPids(postbody.get<std::vector<DWORD>>());
} catch (std::exception& e) {
res.status = 401;
res.set_content(nlohmann::json{
{"code", 401},
{"name", "Bad Request"},
{"message", e.what()},
}
.dump(),
"text/json");
return;
}
catch (...) {
res.status = 500;
res.set_content(nlohmann::json{
{"code", 500},
{"name", "Internal Server Error"},
{"message", "Unknown Error"},
}
.dump(),
"text/json");
return;
}
const nlohmann::json j = app_launcher_.launchedPids();
res.set_content(j.dump(), "text/json");
});
server_.Get("/settings", [this](const httplib::Request& req, httplib::Response& res) {
res.set_content(Settings::toJson().dump(), "text/json");
});

Loading…
Cancel
Save