From: Axel Viala Date: Mon, 22 Aug 2022 10:17:16 +0000 (+0200) Subject: WIP: Clean-up DNSName constructor unify with string_view. X-Git-Tag: dnsdist-1.8.0-rc1~209^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=72a7ae39dba9b8507c29ac2e0a7ba9ffc1881daf;p=thirdparty%2Fpdns.git WIP: Clean-up DNSName constructor unify with string_view. --- diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index 74a166a596..747225e02b 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -53,8 +53,11 @@ void DNSName::throwSafeRangeError(const std::string& msg, const char* buf, size_ throw std::range_error(msg + label + dots); } -DNSName::DNSName(const char* p, size_t length) +DNSName::DNSName(const std::string_view sw) { + const char* p = sw.data(); + size_t length = sw.length(); + if(length == 0 || (length == 1 && p[0]=='.')) { d_storage.assign(1, (char)0); } else { diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index a88c2586e0..90c752be3f 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -97,9 +98,8 @@ public: } DNSName(const DNSName& a) = default; DNSName(DNSName&& a) = default; - explicit DNSName(const char* p): DNSName(p, std::strlen(p)) {} //!< Constructs from a human formatted, escaped presentation - 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 + + explicit DNSName(const std::string_view sw); //!< 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).