From: Fred Morcos Date: Wed, 18 May 2022 11:51:39 +0000 (+0200) Subject: Whitespace & cleanup X-Git-Tag: auth-4.8.0-alpha0~63^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84d4747edb7dc1a31d1d0ab7511890a951a7d782;p=thirdparty%2Fpdns.git Whitespace & cleanup --- diff --git a/ext/lmdb-safe/lmdb-safe.hh b/ext/lmdb-safe/lmdb-safe.hh index 33bfa8f131..c900fccd4c 100644 --- a/ext/lmdb-safe/lmdb-safe.hh +++ b/ext/lmdb-safe/lmdb-safe.hh @@ -1,4 +1,5 @@ #pragma once +#include #include #include #include @@ -17,14 +18,14 @@ using std::string_view; /* open issues: * * - missing convenience functions (string_view, string) - */ + */ /* The error strategy. Anything that "should never happen" turns into an exception. But things like 'duplicate entry' or 'no such key' are for you to deal with. */ /* - Thread safety: we are as safe as lmdb. You can talk to MDBEnv from as many threads as you want + Thread safety: we are as safe as lmdb. You can talk to MDBEnv from as many threads as you want */ /** MDBDbi is our only 'value type' object, as 1) a dbi is actually an integer @@ -35,13 +36,13 @@ public: MDBDbi(): d_dbi(-1) { } - explicit MDBDbi(MDB_env* env, MDB_txn* txn, string_view dbname, int flags); + explicit MDBDbi(MDB_env* env, MDB_txn* txn, string_view dbname, int flags); operator const MDB_dbi&() const { return d_dbi; } - + MDB_dbi d_dbi; }; @@ -64,7 +65,7 @@ public: } MDBDbi openDB(const string_view dbname, int flags); - + MDBRWTransaction getRWTransaction(); MDBROTransaction getROTransaction(); @@ -106,7 +107,7 @@ struct MDBOutVal T ret; if(d_mdbval.mv_size != sizeof(T)) throw std::runtime_error("MDB data has wrong length for type"); - + memcpy(&ret, d_mdbval.mv_data, sizeof(T)); return ret; } @@ -121,7 +122,7 @@ struct MDBOutVal T ret; if(d_mdbval.mv_size != sizeof(T)) throw std::runtime_error("MDB data has wrong length for type"); - + memcpy(&ret, d_mdbval.mv_data, sizeof(T)); return ret; } @@ -131,11 +132,11 @@ struct MDBOutVal { if(d_mdbval.mv_size != sizeof(T)) throw std::runtime_error("MDB data has wrong length for type"); - + return reinterpret_cast(d_mdbval.mv_data); } - - + + MDB_val d_mdbval; }; @@ -159,7 +160,7 @@ public: template ::value, T>::type* = nullptr> - MDBInVal(T i) + MDBInVal(T i) { memcpy(&d_memory[0], &i, sizeof(i)); d_mdbval.mv_size = sizeof(T); @@ -171,20 +172,20 @@ public: d_mdbval.mv_size = strlen(s); d_mdbval.mv_data = (void*)s; } - - MDBInVal(const string_view& v) + + MDBInVal(const string_view& v) { d_mdbval.mv_size = v.size(); d_mdbval.mv_data = (void*)&v[0]; } - MDBInVal(const std::string& v) + MDBInVal(const std::string& v) { d_mdbval.mv_size = v.size(); d_mdbval.mv_data = (void*)&v[0]; } - + template static MDBInVal fromStruct(const T& t) { @@ -193,7 +194,7 @@ public: ret.d_mdbval.mv_data = (void*)&t; return ret; } - + operator MDB_val&() { return d_mdbval; @@ -250,7 +251,7 @@ public: const_cast(&val.d_mdbval)); if(rc && rc != MDB_NOTFOUND) throw std::runtime_error("getting data: " + std::string(mdb_strerror(rc))); - + return rc; } @@ -263,7 +264,7 @@ public: return rc; } - + // this is something you can do, readonly MDBDbi openDB(string_view dbname, int flags) { @@ -272,7 +273,7 @@ public: MDBROCursor getCursor(const MDBDbi&); MDBROCursor getROCursor(const MDBDbi&); - + operator MDB_txn*() { return d_txn; @@ -288,8 +289,8 @@ public: } }; -/* - A cursor in a read-only transaction must be closed explicitly, before or after its transaction ends. It can be reused with mdb_cursor_renew() before finally closing it. +/* + A cursor in a read-only transaction must be closed explicitly, before or after its transaction ends. It can be reused with mdb_cursor_renew() before finally closing it. "If the parent transaction commits, the cursor must not be used again." */ @@ -379,7 +380,7 @@ public: throw std::runtime_error("Unable to find from cursor: " + std::string(mdb_strerror(rc))); return rc; } - + int lower_bound(const MDBInVal& in, MDBOutVal& key, MDBOutVal& data) { key.d_mdbval = in.d_mdbval; @@ -390,7 +391,7 @@ public: return rc; } - + int nextprev(MDBOutVal& key, MDBOutVal& data, MDB_cursor_op op) { int rc = mdb_cursor_get(d_cursor, const_cast(&key.d_mdbval), &data.d_mdbval, op); @@ -499,12 +500,12 @@ public: MDBRWTransactionImpl &operator=(MDBRWTransactionImpl&& rhs) = delete; ~MDBRWTransactionImpl() override; - + void commit() override; void abort() override; void clear(MDB_dbi dbi); - + void put(MDB_dbi dbi, const MDBInVal& key, const MDBInVal& val, int flags=0) { if(!d_txn) @@ -535,7 +536,7 @@ public: return rc; } - + int get(MDBDbi& dbi, const MDBInVal& key, MDBOutVal& val) { if(!d_txn) @@ -556,7 +557,7 @@ public: val = out.get(); return rc; } - + MDBDbi openDB(string_view dbname, int flags) { return MDBDbi(environment().d_env, d_txn, dbname, flags); @@ -569,7 +570,7 @@ public: MDBROTransaction getROTransaction(); }; -/* "A cursor in a write-transaction can be closed before its transaction ends, and will otherwise be closed when its transaction ends" +/* "A cursor in a write-transaction can be closed before its transaction ends, and will otherwise be closed when its transaction ends" This is a problem for us since it may means we are closing the cursor twice, which is bad */ class MDBRWCursor : public MDBGenCursor @@ -592,7 +593,7 @@ public: throw std::runtime_error("mdb_cursor_put: " + std::string(mdb_strerror(rc))); } - + int put(const MDBOutVal& key, const MDBOutVal& data, int flags=0) { // XXX check errors @@ -607,4 +608,3 @@ public: } }; - diff --git a/ext/lmdb-safe/lmdb-typed.hh b/ext/lmdb-safe/lmdb-typed.hh index 8fdce35227..3e119daf5a 100644 --- a/ext/lmdb-safe/lmdb-typed.hh +++ b/ext/lmdb-safe/lmdb-typed.hh @@ -1,4 +1,5 @@ #pragma once +#include #include #include "lmdb-safe.hh" #include @@ -14,7 +15,7 @@ // using std::endl; -/* +/* Open issues: Everything should go into a namespace @@ -30,7 +31,7 @@ /** Return the highest ID used in a database. Returns 0 for an empty DB. - This makes us start everything at ID=1, which might make it possible to + This makes us start everything at ID=1, which might make it possible to treat id 0 as special */ unsigned int MDBGetMaxID(MDBRWTransaction& txn, MDBDbi& dbi); @@ -51,7 +52,7 @@ std::string serToString(const T& t) boost::iostreams::back_insert_device inserter(serial_str); boost::iostreams::stream > s(inserter); boost::archive::binary_oarchive oa(s, boost::archive::no_header | boost::archive::no_codecvt); - + oa << t; return serial_str; } @@ -83,7 +84,7 @@ inline std::string keyConv(const T& t) return std::string((char*)&t, sizeof(t)); } -// this is how to override specific types.. it is ugly +// this is how to override specific types.. it is ugly template::value,T>::type* = nullptr> inline std::string keyConv(const T& t) { @@ -91,7 +92,7 @@ inline std::string keyConv(const T& t) } -/** This is a struct that implements index operations, but +/** This is a struct that implements index operations, but only the operations that are broadcast to all indexes. Specifically, to deal with databases with less than the maximum number of interfaces, this only includes calls that should be @@ -136,7 +137,7 @@ struct index_on : LMDBIndexOps> { return c.*PtrToMember; } - + typedef Type type; }; @@ -152,7 +153,7 @@ struct index_on_function : LMDBIndexOps void del(MDBRWTransaction& txn, const Class& t, uint32_t id) {} - + void openDB(std::shared_ptr& env, string_view str, int flags) { - + } typedef uint32_t type; // dummy }; @@ -194,9 +195,9 @@ public: #undef openMacro } - + // we get a lot of our smarts from this tuple, it enables get<0> etc - typedef std::tuple tuple_t; + typedef std::tuple tuple_t; tuple_t d_tuple; // We support readonly and rw transactions. Here we put the Readonly operations @@ -230,7 +231,7 @@ public: MDBOutVal data; if((*d_parent.d_txn)->get(d_parent.d_parent->d_main, id, data)) return false; - + serFromString(data.get(), t); return true; } @@ -283,7 +284,7 @@ public: if(d_end) return; d_prefix.clear(); - + if(d_cursor.get(d_key, d_id, MDB_GET_CURRENT)) { d_end = true; return; @@ -303,7 +304,7 @@ public: d_cursor(std::move(cursor)), d_on_index(true), // is this an iterator on main database or on index? d_one_key(false), - d_prefix(prefix), + d_prefix(prefix), d_end(false) { if(d_end) @@ -323,28 +324,28 @@ public: serFromString(d_id.get(), d_t); } - + std::function filter; void del() { d_cursor.del(); } - + bool operator!=(const eiter_t& rhs) const { return !d_end; } - + bool operator==(const eiter_t& rhs) const { return d_end; } - + const T& operator*() { return d_t; } - + const T* operator->() { return &d_t; @@ -372,13 +373,13 @@ public: throw std::runtime_error("Missing id field"); if(filter && !filter(data)) goto next; - + serFromString(data.get(), d_t); } else { if(filter && !filter(data)) goto next; - + serFromString(d_id.get(), d_t); } } @@ -407,8 +408,8 @@ public: { return d_key; } - - + + // transaction we are part of Parent* d_parent; typename Parent::cursor_t d_cursor; @@ -426,9 +427,9 @@ public: iter_t genbegin(MDB_cursor_op op) { typename Parent::cursor_t cursor = (*d_parent.d_txn)->getCursor(std::get(d_parent.d_parent->d_tuple).d_idx); - + MDBOutVal out, id; - + if(cursor.get(out, id, op)) { // on_index, one_key, end return iter_t{&d_parent, std::move(cursor), true, false, true}; @@ -452,11 +453,11 @@ public: iter_t begin() { typename Parent::cursor_t cursor = (*d_parent.d_txn)->getCursor(d_parent.d_parent->d_main); - + MDBOutVal out, id; - + if(cursor.get(out, id, MDB_FIRST)) { - // on_index, one_key, end + // on_index, one_key, end return iter_t{&d_parent, std::move(cursor), false, false, true}; } @@ -478,9 +479,9 @@ public: MDBInVal in(keystr); MDBOutVal out, id; out.d_mdbval = in.d_mdbval; - + if(cursor.get(out, id, op)) { - // on_index, one_key, end + // on_index, one_key, end return iter_t{&d_parent, std::move(cursor), true, false, true}; } @@ -510,9 +511,9 @@ public: MDBInVal in(keyString); MDBOutVal out, id; out.d_mdbval = in.d_mdbval; - + if(cursor.get(out, id, MDB_SET)) { - // on_index, one_key, end + // on_index, one_key, end return {iter_t{&d_parent, std::move(cursor), true, true, true}, eiter_t()}; } @@ -529,34 +530,34 @@ public: MDBInVal in(keyString); MDBOutVal out, id; out.d_mdbval = in.d_mdbval; - + if(cursor.get(out, id, MDB_SET_RANGE)) { - // on_index, one_key, end + // on_index, one_key, end return {iter_t{&d_parent, std::move(cursor), true, true, true}, eiter_t()}; } return {iter_t(&d_parent, std::move(cursor), keyString), eiter_t()}; }; - + Parent& d_parent; }; - + class ROTransaction : public ReadonlyOperations { public: - explicit ROTransaction(TypedDBI* parent) : ReadonlyOperations(*this), d_parent(parent), d_txn(std::make_shared(d_parent->d_env->getROTransaction())) + explicit ROTransaction(TypedDBI* parent) : ReadonlyOperations(*this), d_parent(parent), d_txn(std::make_shared(d_parent->d_env->getROTransaction())) { } - explicit ROTransaction(TypedDBI* parent, std::shared_ptr txn) : ReadonlyOperations(*this), d_parent(parent), d_txn(txn) + explicit ROTransaction(TypedDBI* parent, std::shared_ptr txn) : ReadonlyOperations(*this), d_parent(parent), d_txn(txn) { } - + ROTransaction(ROTransaction&& rhs) : ReadonlyOperations(*this), d_parent(rhs.d_parent),d_txn(std::move(rhs.d_txn)) - + { rhs.d_parent = 0; } @@ -565,14 +566,14 @@ public: { return d_txn; } - + typedef MDBROCursor cursor_t; TypedDBI* d_parent; - std::shared_ptr d_txn; - }; + std::shared_ptr d_txn; + }; + - class RWTransaction : public ReadonlyOperations { public: @@ -585,7 +586,7 @@ public: { } - + RWTransaction(RWTransaction&& rhs) : ReadonlyOperations(*this), d_parent(rhs.d_parent), d_txn(std::move(rhs.d_txn)) @@ -622,10 +623,10 @@ public: void modify(uint32_t id, std::function func) { T t; - if(!this->get(id, t)) + if(!this->get(id, t)) throw std::runtime_error("Could not modify id "+std::to_string(id)); func(t); - + del(id); // this is the lazy way. We could test for changed index fields put(t, id); } @@ -634,9 +635,9 @@ public: void del(uint32_t id) { T t; - if(!this->get(id, t)) + if(!this->get(id, t)) return; - + (*d_txn)->del(d_parent->d_main, id); clearIndex(id, t); } @@ -675,7 +676,7 @@ public: return d_txn; } - + private: // clear this ID from all indexes void clearIndex(uint32_t id, const T& t) @@ -685,7 +686,7 @@ public: clearMacro(1); clearMacro(2); clearMacro(3); -#undef clearMacro +#undef clearMacro } public: @@ -721,14 +722,9 @@ public: { return d_env; } - + private: std::shared_ptr d_env; MDBDbi d_main; std::string d_name; }; - - - - - diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index f27b50c389..d0b655703a 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -61,14 +61,14 @@ uint32_t burtleCI(const unsigned char* k, uint32_t length, uint32_t init); //#include -/* Quest in life: +/* Quest in life: accept escaped ascii presentations of DNS names and store them "natively" accept a DNS packet with an offset, and extract a DNS name from it build up DNSNames with prepend and append of 'raw' unescaped labels Be able to turn them into ASCII and "DNS name in a packet" again on request - Provide some common operators for comparison, detection of being part of another domain + Provide some common operators for comparison, detection of being part of another domain NOTE: For now, everything MUST be . terminated, otherwise it is an error */ @@ -98,7 +98,7 @@ public: explicit DNSName(const char* p, size_t len); //!< Constructs from a human formatted, escaped presentation explicit DNSName(const std::string& str) : DNSName(str.c_str(), str.length()) {}; //!< Constructs from a human formatted, escaped presentation DNSName(const char* p, int len, int offset, bool uncompress, uint16_t* qtype=nullptr, uint16_t* qclass=nullptr, unsigned int* consumed=nullptr, uint16_t minOffset=0); //!< Construct from a DNS Packet, taking the first question if offset=12. If supplied, consumed is set to the number of bytes consumed from the packet, which will not be equal to the wire length of the resulting name in case of compression. - + bool isPartOf(const DNSName& rhs) const; //!< Are we part of the rhs name? Note that name.isPartOf(name). inline bool operator==(const DNSName& rhs) const; //!< DNS-native comparison (case insensitive) - empty compares to empty bool operator!=(const DNSName& other) const { return !(*this == other); } @@ -162,7 +162,7 @@ public: bool operator<(const DNSName& rhs) const // this delivers _some_ kind of ordering, but not one useful in a DNS context. Really fast though. { - return std::lexicographical_compare(d_storage.rbegin(), d_storage.rend(), + return std::lexicographical_compare(d_storage.rbegin(), d_storage.rend(), rhs.d_storage.rbegin(), rhs.d_storage.rend(), [](const unsigned char& a, const unsigned char& b) { return dns_tolower(a) < dns_tolower(b); @@ -170,7 +170,7 @@ public: } inline bool canonCompare(const DNSName& rhs) const; - bool slowCanonCompare(const DNSName& rhs) const; + bool slowCanonCompare(const DNSName& rhs) const; #if BOOST_VERSION >= 105300 typedef boost::container::string string_t; @@ -230,7 +230,7 @@ inline bool DNSName::canonCompare(const DNSName& rhs) const // // 0,2,6,a // 0,4,a - + uint8_t ourpos[64], rhspos[64]; uint8_t ourcount=0, rhscount=0; //cout<<"Asked to compare "<> children; mutable bool endNode; @@ -582,16 +582,19 @@ namespace std { } DNSName::string_t segmentDNSNameRaw(const char* input, size_t inputlen); // from ragel + bool DNSName::operator==(const DNSName& rhs) const { - if(rhs.empty() != empty() || rhs.d_storage.size() != d_storage.size()) + if (rhs.empty() != empty() || rhs.d_storage.size() != d_storage.size()) { return false; + } - auto us = d_storage.cbegin(); - auto p = rhs.d_storage.cbegin(); - for(; us != d_storage.cend() && p != rhs.d_storage.cend(); ++us, ++p) { - if(dns_tolower(*p) != dns_tolower(*us)) + const auto* us = d_storage.cbegin(); + const auto* p = rhs.d_storage.cbegin(); + for (; us != d_storage.cend() && p != rhs.d_storage.cend(); ++us, ++p) { + if (dns_tolower(*p) != dns_tolower(*us)) { return false; + } } return true; } diff --git a/pdns/dnsparser.hh b/pdns/dnsparser.hh index 980e327e44..fbb850efee 100644 --- a/pdns/dnsparser.hh +++ b/pdns/dnsparser.hh @@ -25,7 +25,7 @@ #include #include #include -#include +#include // #include #include "misc.hh" @@ -343,11 +343,11 @@ struct DNSRecord return lzrp < rzrp; } - bool operator==(const DNSRecord& rhs) const { - if(d_type != rhs.d_type || d_class != rhs.d_class || d_name != rhs.d_name) + if (d_type != rhs.d_type || d_class != rhs.d_class || d_name != rhs.d_name) { return false; + } return *d_content == *rhs.d_content; } diff --git a/pdns/packetcache.hh b/pdns/packetcache.hh index eba68221f6..e9141b3bb5 100644 --- a/pdns/packetcache.hh +++ b/pdns/packetcache.hh @@ -175,7 +175,7 @@ public: = 15 */ const dnsheader_aligned dnsheaderdata(query.data()); - const struct dnsheader* dh = dnsheaderdata.get(); + const struct dnsheader* dh = dnsheaderdata.get(); if (ntohs(dh->qdcount) != 1 || ntohs(dh->ancount) != 0 || ntohs(dh->nscount) != 0 || ntohs(dh->arcount) != 1 || (pos + 15) >= querySize || optionsToIgnore.empty()) { return cachedQuery.compare(pos, cachedQuerySize - pos, query, pos, querySize - pos) == 0; } diff --git a/pdns/reczones.cc b/pdns/reczones.cc index b3f649ea0d..d81678ffc0 100644 --- a/pdns/reczones.cc +++ b/pdns/reczones.cc @@ -19,9 +19,11 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif + #include "syncres.hh" #include "arguments.hh" #include "zoneparser-tng.hh" @@ -291,8 +293,8 @@ static void convertServersForAD(const std::string& zone, const std::string& inpu ad.d_servers.clear(); vector addresses; - for (vector::const_iterator iter = servers.begin(); iter != servers.end(); ++iter) { - ComboAddress addr = parseIPAndPort(*iter, 53); + for (auto server = servers.begin(); server != servers.end(); ++server) { + ComboAddress addr = parseIPAndPort(*server, 53); ad.d_servers.push_back(addr); if (verbose) { addresses.push_back(addr.toStringWithPort()); @@ -540,8 +542,12 @@ std::tuple, std::shared_ptr> newSet->insert(ad.d_name); } } - SLOG(g_log << Logger::Warning << "Done parsing " << newMap->size() - before << " forwarding instructions from file '" << ::arg()["forward-zones-file"] << "'" << endl, - log->info(Logr::Notice, "Done parsing forwarding instructions from file", "file", Logging::Loggable(::arg()["forward-zones-file"]), "count", Logging::Loggable(newMap->size() - before))); + SLOG(g_log << Logger::Warning << "Done parsing " << newMap->size() - before + << " forwarding instructions from file '" + << ::arg()["forward-zones-file"] << "'" << endl, + log->info(Logr::Notice, "Done parsing forwarding instructions from file", "file", + Logging::Loggable(::arg()["forward-zones-file"]), "count", + Logging::Loggable(newMap->size() - before))); } if (::arg().mustDo("export-etc-hosts")) { @@ -605,8 +611,8 @@ std::tuple, std::shared_ptr> parts.clear(); stringtok(parts, ::arg()["allow-notify-for"], " ,\t\n\r"); - for (parts_t::const_iterator iter = parts.begin(); iter != parts.end(); ++iter) { - newSet->insert(DNSName(*iter)); + for (auto& part : parts) { + newSet->insert(DNSName(part)); } if (auto anff = ::arg()["allow-notify-for-file"]; !anff.empty()) { diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 58759b8864..e817d9d3f7 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -151,7 +151,7 @@ public: ordered_non_unique, member> >> { void reset(index::type &ind, iterator it) { - ind.modify(it, [](EDNSStatus &s) { s.mode = EDNSStatus::EDNSMode::UNKNOWN; s.modeSetAt = 0; }); + ind.modify(it, [](EDNSStatus &s) { s.mode = EDNSStatus::EDNSMode::UNKNOWN; s.modeSetAt = 0; }); } void setMode(index::type &ind, iterator it, EDNSStatus::EDNSMode mode) { it->mode = mode; @@ -519,7 +519,7 @@ public: static const int event_trace_to_log = 2; static int s_event_trace_enabled; static bool s_save_parent_ns_set; - + std::unordered_map d_discardedPolicies; DNSFilterEngine::Policy d_appliedPolicy; std::unordered_set d_policyTags; @@ -953,4 +953,3 @@ struct ThreadTimes return *this; } }; -