* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+
#include "rec-taskqueue.hh"
#include "taskqueue.hh"
#include "lock.hh"
class TimedSet
{
public:
- TimedSet(time_t t) :
- d_expiry_seconds(t)
+ TimedSet(time_t time) :
+ d_expiry_seconds(time)
{
}
// This purge is relatively cheap, as we're walking an ordered index
uint64_t erased = 0;
auto& ind = d_set.template get<time_t>();
- auto it = ind.begin();
- while (it != ind.end()) {
- if (it->d_ttd < now) {
+ auto iter = ind.begin();
+ while (iter != ind.end()) {
+ if (iter->d_ttd < now) {
++erased;
- it = ind.erase(it);
+ iter = ind.erase(iter);
}
else {
break;
private:
struct Entry
{
- Entry(const pdns::ResolveTask& task, time_t ttd) :
- d_task(task), d_ttd(ttd) {}
+ Entry(pdns::ResolveTask task, time_t ttd) :
+ d_task(std::move(task)), d_ttd(ttd) {}
pdns::ResolveTask d_task;
time_t d_ttd;
};
- typedef multi_index_container<Entry,
- indexed_by<
- ordered_unique<tag<pdns::ResolveTask>, member<Entry, pdns::ResolveTask, &Entry::d_task>>,
- ordered_non_unique<tag<time_t>, member<Entry, time_t, &Entry::d_ttd>>>>
- timed_set_t;
+ using timed_set_t = multi_index_container<
+ Entry,
+ indexed_by<ordered_unique<tag<pdns::ResolveTask>,
+ member<Entry, pdns::ResolveTask, &Entry::d_task>>,
+ ordered_non_unique<tag<time_t>,
+ member<Entry, time_t, &Entry::d_ttd>>>>;
timed_set_t d_set;
time_t d_expiry_seconds;
unsigned int d_count{0};
{
auto log = g_slog->withName("taskq")->withValues("name", Logging::Loggable(task.d_qname), "qtype", Logging::Loggable(QType(task.d_qtype).toString()), "netmask", Logging::Loggable(task.d_netmask.empty() ? "" : task.d_netmask.toString()));
const string msg = "Exception while running a background ResolveTask";
- SyncRes sr(now);
+ SyncRes resolver(now);
vector<DNSRecord> ret;
- sr.setRefreshAlmostExpired(task.d_refreshMode);
- sr.setQuerySource(task.d_netmask);
- bool ex = true;
+ resolver.setRefreshAlmostExpired(task.d_refreshMode);
+ resolver.setQuerySource(task.d_netmask);
+ bool exceptionOccurred = true;
try {
log->info(Logr::Debug, "resolving", "refresh", Logging::Loggable(task.d_refreshMode));
- int res = sr.beginResolve(task.d_qname, QType(task.d_qtype), QClass::IN, ret);
- ex = false;
+ int res = resolver.beginResolve(task.d_qname, QType(task.d_qtype), QClass::IN, ret);
+ exceptionOccurred = false;
log->info(Logr::Debug, "done", "rcode", Logging::Loggable(res), "records", Logging::Loggable(ret.size()));
}
catch (const std::exception& e) {
catch (...) {
log->error(Logr::Error, msg, "Unexpectec exception");
}
- if (ex) {
+ if (exceptionOccurred) {
if (task.d_refreshMode) {
++s_almost_expired_tasks.exceptions;
}
{
auto log = g_slog->withName("taskq")->withValues("method", Logging::Loggable("tryDoT"), "name", Logging::Loggable(task.d_qname), "qtype", Logging::Loggable(QType(task.d_qtype).toString()), "ip", Logging::Loggable(task.d_ip));
const string msg = "Exception while running a background tryDoT task";
- SyncRes sr(now);
+ SyncRes resolver(now);
vector<DNSRecord> ret;
- sr.setRefreshAlmostExpired(false);
- bool ex = true;
+ resolver.setRefreshAlmostExpired(false);
+ bool exceptionOccurred = true;
try {
log->info(Logr::Debug, "trying DoT");
- bool ok = sr.tryDoT(task.d_qname, QType(task.d_qtype), task.d_nsname, task.d_ip, now.tv_sec);
- ex = false;
- log->info(Logr::Debug, "done", "ok", Logging::Loggable(ok));
+ bool tryOK = resolver.tryDoT(task.d_qname, QType(task.d_qtype), task.d_nsname, task.d_ip, now.tv_sec);
+ exceptionOccurred = false;
+ log->info(Logr::Debug, "done", "ok", Logging::Loggable(tryOK));
}
catch (const std::exception& e) {
log->error(Logr::Error, msg, e.what());
catch (...) {
log->error(Logr::Error, msg, "Unexpected exception");
}
- if (ex) {
+ if (exceptionOccurred) {
++s_resolve_tasks.exceptions;
}
else {
}
}
-bool pushTryDoTTask(const DNSName& qname, uint16_t qtype, const ComboAddress& ip, time_t deadline, const DNSName& nsname)
+bool pushTryDoTTask(const DNSName& qname, uint16_t qtype, const ComboAddress& ipAddress, time_t deadline, const DNSName& nsname)
{
if (SyncRes::isUnsupported(qtype)) {
auto log = g_slog->withName("taskq")->withValues("name", Logging::Loggable(qname), "qtype", Logging::Loggable(QType(qtype).toString()));
return false;
}
- pdns::ResolveTask task{qname, qtype, deadline, false, tryDoT, ip, nsname, {}};
+ pdns::ResolveTask task{qname, qtype, deadline, false, tryDoT, ipAddress, nsname, {}};
bool pushed = s_taskQueue.lock()->queue.push(std::move(task));
if (pushed) {
++s_almost_expired_tasks.pushed;
}
}
- ostringstream ss;
+ ostringstream strStream;
// Clear <foo>-from-file if set, so our changes take effect
- ss << aclType << "-file=" << endl;
+ strStream << aclType << "-file=" << endl;
// Clear ACL setting, and provide a "parent" value
- ss << aclType << "=" << endl;
- ss << aclType << "+=" << nmg.toString() << endl;
+ strStream << aclType << "=" << endl;
+ strStream << aclType << "+=" << nmg.toString() << endl;
- apiWriteConfigFile(aclType, ss.str());
+ apiWriteConfigFile(aclType, strStream.str());
parseACLs();
static void fillZone(const DNSName& zonename, HttpResponse* resp)
{
auto iter = SyncRes::t_sstorage.domainmap->find(zonename);
- if (iter == SyncRes::t_sstorage.domainmap->end())
+ if (iter == SyncRes::t_sstorage.domainmap->end()) {
throw ApiException("Could not find domain '" + zonename.toLogString() + "'");
+ }
const SyncRes::AuthDomain& zone = iter->second;
Json::array servers;
for (const ComboAddress& server : zone.d_servers) {
- servers.push_back(server.toStringWithPort());
+ servers.push_back(server.toStringWithPort()); // NOLINT: union
}
Json::array records;
- for (const SyncRes::AuthDomain::records_t::value_type& dr : zone.d_records) {
+ for (const SyncRes::AuthDomain::records_t::value_type& record : zone.d_records) {
records.push_back(Json::object{
- {"name", dr.d_name.toString()},
- {"type", DNSRecordContent::NumberToType(dr.d_type)},
- {"ttl", (double)dr.d_ttl},
- {"content", dr.getContent()->getZoneRepresentation()}});
+ {"name", record.d_name.toString()},
+ {"type", DNSRecordContent::NumberToType(record.d_type)},
+ {"ttl", (double)record.d_ttl},
+ {"content", record.getContent()->getZoneRepresentation()}});
}
// id is the canonical lookup key, which doesn't actually match the name (in some cases)
resp->setJsonBody(doc);
}
-static void doCreateZone(const Json document)
+static void doCreateZone(const Json& document)
{
if (::arg()["api-config-dir"].empty()) {
throw ApiException("Config Option \"api-config-dir\" must be set");
string singleIPTarget = document["single_target_ip"].string_value();
string kind = toUpper(stringFromJson(document, "kind"));
- bool rd = boolFromJson(document, "recursion_desired");
+ bool rdFlag = boolFromJson(document, "recursion_desired");
string confbasename = "zone-" + apiZoneNameToId(zone);
if (kind == "NATIVE") {
- if (rd)
+ if (rdFlag) {
throw ApiException("kind=Native and recursion_desired are mutually exclusive");
+ }
if (!singleIPTarget.empty()) {
try {
ComboAddress rem(singleIPTarget);
- if (rem.sin4.sin_family != AF_INET)
+ if (rem.sin4.sin_family != AF_INET) { // NOLINT: union
throw ApiException("");
- singleIPTarget = rem.toString();
+ }
+ singleIPTarget = rem.toString(); // NOLINT: union
}
catch (...) {
throw ApiException("Single IP target '" + singleIPTarget + "' is invalid");
else if (kind == "FORWARDED") {
string serverlist;
for (const auto& value : document["servers"].array_items()) {
- string server = value.string_value();
- if (server == "") {
+ const string& server = value.string_value();
+ if (server.empty()) {
throw ApiException("Forwarded-to server must not be an empty string");
}
try {
- ComboAddress ca = parseIPAndPort(server, 53);
+ ComboAddress address = parseIPAndPort(server, 53);
if (!serverlist.empty()) {
serverlist += ";";
}
- serverlist += ca.toStringWithPort();
+ serverlist += address.toStringWithPort(); // NOLINT: union
}
catch (const PDNSException& e) {
throw ApiException(e.reason);
}
}
- if (serverlist == "")
+ if (serverlist.empty()) {
throw ApiException("Need at least one upstream server when forwarding");
+ }
- if (rd) {
+ if (rdFlag) {
apiWriteConfigFile(confbasename, "forward-zones-recurse+=" + zonename + "=" + serverlist);
}
else {
DNSName zonename = apiNameToDNSName(stringFromJson(document, "name"));
auto iter = SyncRes::t_sstorage.domainmap->find(zonename);
- if (iter != SyncRes::t_sstorage.domainmap->end())
+ if (iter != SyncRes::t_sstorage.domainmap->end()) {
throw ApiException("Zone already exists");
+ }
doCreateZone(document);
reloadZoneConfiguration();
return;
}
- if (req->method != "GET")
+ if (req->method != "GET") {
throw HttpMethodNotAllowedException();
+ }
Json::array doc;
for (const SyncRes::domainmap_t::value_type& val : *SyncRes::t_sstorage.domainmap) {
const SyncRes::AuthDomain& zone = val.second;
Json::array servers;
for (const ComboAddress& server : zone.d_servers) {
- servers.push_back(server.toStringWithPort());
+ servers.push_back(server.toStringWithPort()); // NOLINT: union
}
// id is the canonical lookup key, which doesn't actually match the name (in some cases)
string zoneId = apiZoneNameToId(val.first);
{
DNSName zonename = apiZoneIdToName(req->parameters["id"]);
- SyncRes::domainmap_t::const_iterator iter = SyncRes::t_sstorage.domainmap->find(zonename);
- if (iter == SyncRes::t_sstorage.domainmap->end())
+ auto iter = SyncRes::t_sstorage.domainmap->find(zonename);
+ if (iter == SyncRes::t_sstorage.domainmap->end()) {
throw ApiException("Could not find domain '" + zonename.toLogString() + "'");
+ }
if (req->method == "PUT") {
Json document = req->json();
static void apiServerSearchData(HttpRequest* req, HttpResponse* resp)
{
- if (req->method != "GET")
+ if (req->method != "GET") {
throw HttpMethodNotAllowedException();
+ }
- string q = req->getvars["q"];
- if (q.empty())
+ string qVar = req->getvars["q"];
+ if (qVar.empty()) {
throw ApiException("Query q can't be blank");
+ }
Json::array doc;
for (const SyncRes::domainmap_t::value_type& val : *SyncRes::t_sstorage.domainmap) {
string zoneId = apiZoneNameToId(val.first);
string zoneName = val.first.toString();
- if (pdns_ci_find(zoneName, q) != string::npos) {
+ if (pdns_ci_find(zoneName, qVar) != string::npos) {
doc.push_back(Json::object{
{"type", "zone"},
{"zone_id", zoneId},
}
// if zone name is an exact match, don't bother with returning all records/comments in it
- if (val.first == DNSName(q)) {
+ if (val.first == DNSName(qVar)) {
continue;
}
const SyncRes::AuthDomain& zone = val.second;
- for (const SyncRes::AuthDomain::records_t::value_type& rr : zone.d_records) {
- if (pdns_ci_find(rr.d_name.toString(), q) == string::npos && pdns_ci_find(rr.getContent()->getZoneRepresentation(), q) == string::npos)
+ for (const SyncRes::AuthDomain::records_t::value_type& resourceRec : zone.d_records) {
+ if (pdns_ci_find(resourceRec.d_name.toString(), qVar) == string::npos && pdns_ci_find(resourceRec.getContent()->getZoneRepresentation(), qVar) == string::npos) {
continue;
+ }
doc.push_back(Json::object{
{"type", "record"},
{"zone_id", zoneId},
{"zone_name", zoneName},
- {"name", rr.d_name.toString()},
- {"content", rr.getContent()->getZoneRepresentation()}});
+ {"name", resourceRec.d_name.toString()},
+ {"content", resourceRec.getContent()->getZoneRepresentation()}});
}
}
resp->setJsonBody(doc);
static void apiServerCacheFlush(HttpRequest* req, HttpResponse* resp)
{
- if (req->method != "PUT")
+ if (req->method != "PUT") {
throw HttpMethodNotAllowedException();
+ }
DNSName canon = apiNameToDNSName(req->getvars["domain"]);
- bool subtree = (req->getvars.count("subtree") > 0 && req->getvars["subtree"].compare("true") == 0);
+ bool subtree = req->getvars.count("subtree") > 0 && req->getvars["subtree"] == "true";
uint16_t qtype = 0xffff;
- if (req->getvars.count("type")) {
+ if (req->getvars.count("type") != 0) {
qtype = QType::chartocode(req->getvars["type"].c_str());
}
static void apiServerRPZStats(HttpRequest* req, HttpResponse* resp)
{
- if (req->method != "GET")
+ if (req->method != "GET") {
throw HttpMethodNotAllowedException();
+ }
auto luaconf = g_luaconfs.getLocal();
auto numZones = luaconf->dfe.size();
for (size_t i = 0; i < numZones; i++) {
auto zone = luaconf->dfe.getZone(i);
- if (zone == nullptr)
+ if (zone == nullptr) {
continue;
+ }
const auto& name = zone->getName();
auto stats = getRPZZoneStats(name);
- if (stats == nullptr)
+ if (stats == nullptr) {
continue;
+ }
Json::object zoneInfo = {
{"transfers_failed", (double)stats->d_failedTransfers},
{"transfers_success", (double)stats->d_successfulTransfers},
{
static MetricDefinitionStorage s_metricDefinitions;
- if (req->method != "GET")
+ if (req->method != "GET") {
throw HttpMethodNotAllowedException();
+ }
std::ostringstream output;
MetricDefinition metricDetails;
if (s_metricDefinitions.getMetricDetails(metricName, metricDetails)) {
- std::string prometheusTypeName = s_metricDefinitions.getPrometheusStringMetricType(
+ std::string prometheusTypeName = MetricDefinitionStorage::getPrometheusStringMetricType(
metricDetails.d_prometheusType);
if (prometheusTypeName.empty()) {
{
resp->headers["Cache-Control"] = "max-age=86400";
- if (req->url.path == "/")
+ if (req->url.path == "/") {
req->url.path = "/index.html";
+}
const string charset = "; charset=utf-8";
- if (boost::ends_with(req->url.path, ".html"))
+ if (boost::ends_with(req->url.path, ".html")) {
resp->headers["Content-Type"] = "text/html" + charset;
- else if (boost::ends_with(req->url.path, ".css"))
+ } else if (boost::ends_with(req->url.path, ".css")) {
resp->headers["Content-Type"] = "text/css" + charset;
- else if (boost::ends_with(req->url.path, ".js"))
+ } else if (boost::ends_with(req->url.path, ".js")) {
resp->headers["Content-Type"] = "application/javascript" + charset;
- else if (boost::ends_with(req->url.path, ".png"))
+ } else if (boost::ends_with(req->url.path, ".png")) {
resp->headers["Content-Type"] = "image/png";
+ }
resp->headers["X-Content-Type-Options"] = "nosniff";
resp->headers["X-Frame-Options"] = "deny";
resp->headers["X-XSS-Protection"] = "1; mode=block";
// resp->headers["Content-Security-Policy"] = "default-src 'self'; style-src 'self' 'unsafe-inline'";
- if (!req->url.path.empty() && g_urlmap.count(req->url.path.c_str() + 1)) {
- resp->body = g_urlmap.at(req->url.path.c_str() + 1);
+ if (!req->url.path.empty() && (g_urlmap.count(req->url.path.substr(1)) != 0)) {
+ resp->body = g_urlmap.at(req->url.path.substr(1));
resp->status = 200;
}
else {
"Number of remote logging events")},
};
-#define CHECK_PROMETHEUS_METRICS 0
+constexpr bool CHECK_PROMETHEUS_METRICS = false;
-#if CHECK_PROMETHEUS_METRICS
static void validatePrometheusMetrics()
{
MetricDefinitionStorage s_metricDefinitions;
}
}
}
-#endif
RecursorWebServer::RecursorWebServer(FDMultiplexer* fdm)
{
-#if CHECK_PROMETHEUS_METRICS
- validatePrometheusMetrics();
-#endif
+ if (CHECK_PROMETHEUS_METRICS) {
+ validatePrometheusMetrics();
+ }
d_ws = make_unique<AsyncWebServer>(fdm, arg()["webserver-address"], arg().asNum("webserver-port"));
d_ws->setSLog(g_slog->withName("webserver"));
// legacy dispatch
d_ws->registerApiHandler(
- "/jsonstat", [this](HttpRequest* req, HttpResponse* resp) { jsonstat(req, resp); }, true);
+ "/jsonstat", [](HttpRequest* req, HttpResponse* resp) { jsonstat(req, resp); }, true);
d_ws->registerApiHandler("/api/v1/servers/localhost/cache/flush", apiServerCacheFlush);
d_ws->registerApiHandler("/api/v1/servers/localhost/config/allow-from", apiServerConfigAllowFrom);
d_ws->registerApiHandler("/api/v1/servers/localhost/config/allow-notify-from", &apiServerConfigAllowNotifyFrom);
d_ws->registerApiHandler("/api/v1", apiDiscoveryV1);
d_ws->registerApiHandler("/api", apiDiscovery);
- for (const auto& u : g_urlmap) {
- d_ws->registerWebHandler("/" + u.first, serveStuff);
+ for (const auto& url : g_urlmap) {
+ d_ws->registerWebHandler("/" + url.first, serveStuff);
}
d_ws->registerWebHandler("/", serveStuff);
{
string command;
- if (req->getvars.count("command")) {
+ if (req->getvars.count("command") != 0) {
command = req->getvars["command"];
req->getvars.erase("command");
}
vector<query_t> queries;
bool filter = !req->getvars["public-filtered"].empty();
- if (req->getvars["name"] == "servfail-queries")
+ if (req->getvars["name"] == "servfail-queries") {
queries = broadcastAccFunction<vector<query_t>>(pleaseGetServfailQueryRing);
- else if (req->getvars["name"] == "bogus-queries")
+ }
+ else if (req->getvars["name"] == "bogus-queries") {
queries = broadcastAccFunction<vector<query_t>>(pleaseGetBogusQueryRing);
- else if (req->getvars["name"] == "queries")
+ }
+ else if (req->getvars["name"] == "queries") {
queries = broadcastAccFunction<vector<query_t>>(pleaseGetQueryRing);
+ }
typedef map<query_t, unsigned int> counts_t;
counts_t counts;
- for (const query_t& q : queries) {
- if (filter)
- counts[pair(getRegisteredName(q.first), q.second)]++;
- else
- counts[pair(q.first, q.second)]++;
+ for (const query_t& count : queries) {
+ if (filter) {
+ counts[pair(getRegisteredName(count.first), count.second)]++;
+ } else {
+ counts[pair(count.first, count.second)]++;
+ }
}
typedef std::multimap<int, query_t> rcounts_t;
rcounts_t rcounts;
- for (counts_t::const_iterator i = counts.begin(); i != counts.end(); ++i)
- rcounts.emplace(-i->second, i->first);
+ for (const auto& count : counts) {
+ rcounts.emplace(-count.second, count.first);
+ }
Json::array entries;
- unsigned int tot = 0, totIncluded = 0;
- for (const rcounts_t::value_type& q : rcounts) {
- totIncluded -= q.first;
+ unsigned int tot = 0;
+ unsigned int totIncluded = 0;
+ for (const rcounts_t::value_type& count : rcounts) {
+ totIncluded -= count.first;
entries.push_back(Json::array{
- -q.first, q.second.first.toLogString(), DNSRecordContent::NumberToType(q.second.second)});
- if (tot++ >= 100)
+ -count.first, count.second.first.toLogString(), DNSRecordContent::NumberToType(count.second.second)});
+ if (tot++ >= 100) {
break;
+}
}
if (queries.size() != totIncluded) {
entries.push_back(Json::array{
resp->setJsonBody(Json::object{{"entries", entries}});
return;
}
- else if (command == "get-remote-ring") {
+ if (command == "get-remote-ring") {
vector<ComboAddress> queries;
- if (req->getvars["name"] == "remotes")
+ if (req->getvars["name"] == "remotes") {
queries = broadcastAccFunction<vector<ComboAddress>>(pleaseGetRemotes);
- else if (req->getvars["name"] == "servfail-remotes")
+ } else if (req->getvars["name"] == "servfail-remotes") {
queries = broadcastAccFunction<vector<ComboAddress>>(pleaseGetServfailRemotes);
- else if (req->getvars["name"] == "bogus-remotes")
+ } else if (req->getvars["name"] == "bogus-remotes") {
queries = broadcastAccFunction<vector<ComboAddress>>(pleaseGetBogusRemotes);
- else if (req->getvars["name"] == "large-answer-remotes")
+ } else if (req->getvars["name"] == "large-answer-remotes") {
queries = broadcastAccFunction<vector<ComboAddress>>(pleaseGetLargeAnswerRemotes);
- else if (req->getvars["name"] == "timeouts")
+ } else if (req->getvars["name"] == "timeouts") {
queries = broadcastAccFunction<vector<ComboAddress>>(pleaseGetTimeouts);
-
+ }
typedef map<ComboAddress, unsigned int, ComboAddress::addressOnlyLessThan> counts_t;
counts_t counts;
- for (const ComboAddress& q : queries) {
- counts[q]++;
+ for (const ComboAddress& query : queries) {
+ counts[query]++;
}
typedef std::multimap<int, ComboAddress> rcounts_t;
rcounts_t rcounts;
- for (counts_t::const_iterator i = counts.begin(); i != counts.end(); ++i)
- rcounts.emplace(-i->second, i->first);
+ for (const auto& count : counts) {
+ rcounts.emplace(-count.second, count.first);
+ }
Json::array entries;
- unsigned int tot = 0, totIncluded = 0;
- for (const rcounts_t::value_type& q : rcounts) {
- totIncluded -= q.first;
+ unsigned int tot = 0;
+ unsigned int totIncluded = 0;
+ for (const rcounts_t::value_type& count : rcounts) {
+ totIncluded -= count.first;
entries.push_back(Json::array{
- -q.first, q.second.toString()});
- if (tot++ >= 100)
+ -count.first, count.second.toString()}); // NOLINT: union
+ if (tot++ >= 100) {
break;
+ }
}
if (queries.size() != totIncluded) {
entries.push_back(Json::array{
resp->setJsonBody(Json::object{{"entries", entries}});
return;
}
- else {
- resp->setErrorResult("Command '" + command + "' not found", 404);
- }
+ resp->setErrorResult("Command '" + command + "' not found", 404);
}
-void AsyncServerNewConnectionMT(void* p)
+void AsyncServerNewConnectionMT(void* arg)
{
- AsyncServer* server = (AsyncServer*)p;
+ auto* server = static_cast<AsyncServer*>(arg);
try {
auto socket = server->accept(); // this is actually a shared_ptr
}
// This is an entry point from FDM, so it needs to catch everything.
-void AsyncWebServer::serveConnection(std::shared_ptr<Socket> client) const
+void AsyncWebServer::serveConnection(const std::shared_ptr<Socket>& socket) const
{
- if (!client->acl(d_acl)) {
+ if (!socket->acl(d_acl)) {
return;
}
try {
YaHTTP::AsyncRequestLoader yarl;
yarl.initialize(&req);
- client->setNonBlocking();
+ socket->setNonBlocking();
const struct timeval timeout
{
};
std::shared_ptr<TLSCtx> tlsCtx{nullptr};
if (d_loglevel > WebServer::LogLevel::None) {
- client->getRemote(remote);
+ socket->getRemote(remote);
}
- auto handler = std::make_shared<TCPIOHandler>("", false, client->releaseHandle(), timeout, tlsCtx);
+ auto handler = std::make_shared<TCPIOHandler>("", false, socket->releaseHandle(), timeout, tlsCtx);
PacketBuffer data;
try {
while (!req.complete) {
auto ret = arecvtcp(data, 16384, handler, true);
if (ret == LWResult::Result::Success) {
- string str(reinterpret_cast<const char*>(data.data()), data.size());
+ string str(reinterpret_cast<const char*>(data.data()), data.size()); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
req.complete = yarl.feed(str);
}
else {
logRequest(req, remote);
WebServer::handleRequest(req, resp);
- ostringstream ss;
- resp.write(ss);
- const string& s = ss.str();
- reply.insert(reply.end(), s.cbegin(), s.cend());
+ ostringstream stringStream;
+ resp.write(stringStream);
+ const string& str = stringStream.str();
+ reply.insert(reply.end(), str.cbegin(), str.cend());
logResponse(resp, remote, logprefix);
req.d_slog->error(Logr::Error, e.reason, "Exception handing request", "exception", Logging::Loggable("PDNSException")));
}
catch (std::exception& e) {
- if (strstr(e.what(), "timeout") == 0)
+ if (strstr(e.what(), "timeout") == nullptr) {
SLOG(g_log << Logger::Error << logprefix << "STL Exception: " << e.what() << endl,
req.d_slog->error(Logr::Error, e.what(), "Exception handing request", "exception", Logging::Loggable("std::exception")));
+ }
}
catch (...) {
SLOG(g_log << Logger::Error << logprefix << "Unknown exception" << endl,
void AsyncWebServer::go()
{
- if (!d_server)
+ if (!d_server) {
return;
+ }
auto server = std::dynamic_pointer_cast<AsyncServer>(d_server);
- if (!server)
+ if (!server) {
return;
- server->asyncWaitForConnections(d_fdm, [this](const std::shared_ptr<Socket>& c) { serveConnection(c); });
+ }
+ server->asyncWaitForConnections(d_fdm, [this](const std::shared_ptr<Socket>& socket) { serveConnection(socket); });
}