Capture by-value instead of by-reference

This commit is contained in:
Brenton Bostick 2023-05-17 14:30:05 -04:00
commit 4ba74f579b

View file

@ -814,7 +814,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
httplib::Server &s, httplib::Server &s,
const std::function<void(const httplib::Request&, httplib::Response&, std::string)> setContent) const std::function<void(const httplib::Request&, httplib::Response&, std::string)> setContent)
{ {
s.Get("/controller/network", [&](const httplib::Request &req, httplib::Response &res) { s.Get("/controller/network", [=](const httplib::Request &req, httplib::Response &res) {
std::set<uint64_t> networkIds; std::set<uint64_t> networkIds;
_db.networks(networkIds); _db.networks(networkIds);
char tmp[64]; char tmp[64];
@ -828,7 +828,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
setContent(req, res, out.dump()); setContent(req, res, out.dump());
}); });
s.Get("/controller/network/([0-9a-fA-F]{16})", [&](const httplib::Request &req, httplib::Response &res) { s.Get("/controller/network/([0-9a-fA-F]{16})", [=](const httplib::Request &req, httplib::Response &res) {
auto networkID = req.matches[1]; auto networkID = req.matches[1];
uint64_t nwid = Utils::hexStrToU64(networkID.str().c_str()); uint64_t nwid = Utils::hexStrToU64(networkID.str().c_str());
json network; json network;
@ -840,7 +840,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
setContent(req, res, network.dump()); setContent(req, res, network.dump());
}); });
auto createNewNetwork = [&](const httplib::Request &req, httplib::Response &res) { auto createNewNetwork = [=](const httplib::Request &req, httplib::Response &res) {
fprintf(stderr, "creating new network (new style)\n"); fprintf(stderr, "creating new network (new style)\n");
uint64_t nwid = 0; uint64_t nwid = 0;
uint64_t nwidPrefix = (Utils::hexStrToU64(_signingIdAddressString.c_str()) << 24) & 0xffffffffff000000ULL; uint64_t nwidPrefix = (Utils::hexStrToU64(_signingIdAddressString.c_str()) << 24) & 0xffffffffff000000ULL;
@ -864,7 +864,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
s.Put("/controller/network", createNewNetwork); s.Put("/controller/network", createNewNetwork);
s.Post("/controller/network", createNewNetwork); s.Post("/controller/network", createNewNetwork);
auto createNewNetworkOldAndBusted = [&](const httplib::Request &req, httplib::Response &res) { auto createNewNetworkOldAndBusted = [=](const httplib::Request &req, httplib::Response &res) {
auto inID = req.matches[1].str(); auto inID = req.matches[1].str();
if (inID != _signingIdAddressString) { if (inID != _signingIdAddressString) {
@ -893,7 +893,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
s.Put("/controller/network/([0-9a-fA-F]{10})______", createNewNetworkOldAndBusted); s.Put("/controller/network/([0-9a-fA-F]{10})______", createNewNetworkOldAndBusted);
s.Post("/controller/network/([0-9a-fA-F]{10})______", createNewNetworkOldAndBusted); s.Post("/controller/network/([0-9a-fA-F]{10})______", createNewNetworkOldAndBusted);
s.Delete("/controller/network/([0-9a-fA-F]{16})", [&](const httplib::Request &req, httplib::Response &res) { s.Delete("/controller/network/([0-9a-fA-F]{16})", [=](const httplib::Request &req, httplib::Response &res) {
auto networkID = req.matches[1].str(); auto networkID = req.matches[1].str();
uint64_t nwid = Utils::hexStrToU64(networkID.c_str()); uint64_t nwid = Utils::hexStrToU64(networkID.c_str());
@ -907,7 +907,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
setContent(req, res, network.dump()); setContent(req, res, network.dump());
}); });
s.Get("/controller/network/([0-9a-fA-F]{16})/member", [&](const httplib::Request &req, httplib::Response &res) { s.Get("/controller/network/([0-9a-fA-F]{16})/member", [=](const httplib::Request &req, httplib::Response &res) {
auto networkID = req.matches[1]; auto networkID = req.matches[1];
uint64_t nwid = Utils::hexStrToU64(networkID.str().c_str()); uint64_t nwid = Utils::hexStrToU64(networkID.str().c_str());
json network; json network;
@ -933,7 +933,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
setContent(req, res, out.dump()); setContent(req, res, out.dump());
}); });
s.Get("/controller/network/([0-9a-fA-F]{16})/member/([0-9a-fA-F]{10})", [&](const httplib::Request &req, httplib::Response &res) { s.Get("/controller/network/([0-9a-fA-F]{16})/member/([0-9a-fA-F]{10})", [=](const httplib::Request &req, httplib::Response &res) {
auto networkID = req.matches[1]; auto networkID = req.matches[1];
auto memberID = req.matches[2]; auto memberID = req.matches[2];
uint64_t nwid = Utils::hexStrToU64(networkID.str().c_str()); uint64_t nwid = Utils::hexStrToU64(networkID.str().c_str());
@ -948,7 +948,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
setContent(req, res, member.dump()); setContent(req, res, member.dump());
}); });
auto memberPost = [&](const httplib::Request &req, httplib::Response &res) { auto memberPost = [=](const httplib::Request &req, httplib::Response &res) {
auto networkID = req.matches[1].str(); auto networkID = req.matches[1].str();
auto memberID = req.matches[2].str(); auto memberID = req.matches[2].str();
uint64_t nwid = Utils::hexStrToU64(networkID.c_str()); uint64_t nwid = Utils::hexStrToU64(networkID.c_str());
@ -1054,7 +1054,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
s.Put("/controller/network/([0-9a-fA-F]{16})/member/([0-9a-fA-F]{10})", memberPost); s.Put("/controller/network/([0-9a-fA-F]{16})/member/([0-9a-fA-F]{10})", memberPost);
s.Post("/controller/network/([0-9a-fA-F]{16})/member/([0-9a-fA-F]{10})", memberPost); s.Post("/controller/network/([0-9a-fA-F]{16})/member/([0-9a-fA-F]{10})", memberPost);
s.Delete("/controller/network/([0-9a-fA-F]{16})/member/([0-9a-fA-F]{10})", [&](const httplib::Request &req, httplib::Response &res) { s.Delete("/controller/network/([0-9a-fA-F]{16})/member/([0-9a-fA-F]{10})", [=](const httplib::Request &req, httplib::Response &res) {
auto networkID = req.matches[1].str(); auto networkID = req.matches[1].str();
auto memberID = req.matches[2].str(); auto memberID = req.matches[2].str();