From c4f682606a31fbd8f75cfd8e54a3997142e6e23d Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Wed, 21 Apr 2021 15:44:15 +0430 Subject: [PATCH] LookupServer: Use dbgln_if instead of #if Also adds a missing AK::Formatter specialisation for DNSName, required for the debug calls to actually work (!) --- Userland/Services/LookupServer/DNSName.h | 8 ++++++++ Userland/Services/LookupServer/DNSPacket.cpp | 21 ++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Userland/Services/LookupServer/DNSName.h b/Userland/Services/LookupServer/DNSName.h index 585af15a690..be2289a5ad9 100644 --- a/Userland/Services/LookupServer/DNSName.h +++ b/Userland/Services/LookupServer/DNSName.h @@ -56,3 +56,11 @@ private: OutputStream& operator<<(OutputStream& stream, const DNSName&); } + +template<> +struct AK::Formatter : Formatter { + void format(FormatBuilder& builder, const LookupServer::DNSName& value) + { + return Formatter::format(builder, value.as_string()); + } +}; diff --git a/Userland/Services/LookupServer/DNSPacket.cpp b/Userland/Services/LookupServer/DNSPacket.cpp index 5ff8685742b..b2ba9552c08 100644 --- a/Userland/Services/LookupServer/DNSPacket.cpp +++ b/Userland/Services/LookupServer/DNSPacket.cpp @@ -28,6 +28,7 @@ #include "DNSPacket.h" #include "DNSName.h" #include "DNSPacketHeader.h" +#include #include #include #include @@ -124,13 +125,11 @@ Optional DNSPacket::from_raw_packet(const u8* raw_data, size_t raw_si } auto& header = *(const DNSPacketHeader*)(raw_data); -#ifdef LOOKUPSERVER_DEBUG - dbgln("Got packet (ID: {})", header.id()); - dbgln(" Question count: {}", header.question_count()); - dbgln(" Answer count: {}", header.answer_count()); - dbgln(" Authority count: {}", header.authority_count()); - dbgln("Additional count: {}", header.additional_count()); -#endif + dbgln_if(LOOKUPSERVER_DEBUG, "Got packet (ID: {})", header.id()); + dbgln_if(LOOKUPSERVER_DEBUG, " Question count: {}", header.question_count()); + dbgln_if(LOOKUPSERVER_DEBUG, " Answer count: {}", header.answer_count()); + dbgln_if(LOOKUPSERVER_DEBUG, " Authority count: {}", header.authority_count()); + dbgln_if(LOOKUPSERVER_DEBUG, "Additional count: {}", header.additional_count()); DNSPacket packet; packet.m_id = header.id(); @@ -152,10 +151,8 @@ Optional DNSPacket::from_raw_packet(const u8* raw_data, size_t raw_si auto& record_and_class = *(const RawDNSAnswerQuestion*)&raw_data[offset]; packet.m_questions.empend(name, record_and_class.record_type, record_and_class.class_code); offset += 4; -#ifdef LOOKUPSERVER_DEBUG auto& question = packet.m_questions.last(); - dbgln("Question #{}: name=_{}_, type={}, class={}", i, question.name(), question.record_type(), question.class_code()); -#endif + dbgln_if(LOOKUPSERVER_DEBUG, "Question #{}: name=_{}_, type={}, class={}", i, question.name(), question.record_type(), question.class_code()); } for (u16 i = 0; i < header.answer_count(); ++i) { @@ -176,9 +173,7 @@ Optional DNSPacket::from_raw_packet(const u8* raw_data, size_t raw_si // FIXME: Parse some other record types perhaps? dbgln("data=(unimplemented record type {})", record.type()); } -#ifdef LOOKUPSERVER_DEBUG - dbgln("Answer #{}: name=_{}_, type={}, ttl={}, length={}, data=_{}_", i, name, record.type(), record.ttl(), record.data_length(), data); -#endif + dbgln_if(LOOKUPSERVER_DEBUG, "Answer #{}: name=_{}_, type={}, ttl={}, length={}, data=_{}_", i, name, record.type(), record.ttl(), record.data_length(), data); packet.m_answers.empend(name, record.type(), record.record_class(), record.ttl(), data); offset += record.data_length(); }