From: Peter van Dijk Date: Thu, 17 Mar 2016 10:11:40 +0000 (+0100) Subject: add DNSName::toLogString X-Git-Tag: dnsdist-1.0.0-beta1~76^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ab84270c70a6030c84e977e600e5b26e594ad7f;p=thirdparty%2Fpdns.git add DNSName::toLogString --- diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index fece6db044..de30cf67fe 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -137,6 +137,23 @@ std::string DNSName::toString(const std::string& separator, const bool trailing) return ret.substr(0, ret.size()-!trailing); } +std::string DNSName::toLogString() const +{ + if (empty()) { + return "(empty)"; + } + + if(isRoot()) + return "."; + + std::string ret; + for(const auto& s : getRawLabels()) { + ret+= escapeLabel(s) + "."; + } + + return ret; +} + std::string DNSName::toDNSString() const { if (empty()) diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index cd9ad2618d..a0662cb26a 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -52,6 +52,7 @@ public: bool operator!=(const DNSName& other) const { return !(*this == other); } std::string toString(const std::string& separator=".", const bool trailing=true) const; //!< Our human-friendly, escaped, representation + std::string toLogString() const; //!< like plain toString, but returns (empty) on empty names std::string toStringNoDot() const { return toString(".", false); } std::string toStringRootDot() const { if(isRoot()) return "."; else return toString(".", false); } std::string toDNSString() const; //!< Our representation in DNS native format