LookupServer: Use dbgln_if instead of #if

Also adds a missing AK::Formatter specialisation for DNSName, required
for the debug calls to actually work (!)
This commit is contained in:
Ali Mohammad Pur 2021-04-21 15:44:15 +04:30 committed by Linus Groh
parent 36c17d5371
commit c4f682606a
Notes: sideshowbarker 2024-07-18 19:18:36 +09:00
2 changed files with 16 additions and 13 deletions

View file

@ -56,3 +56,11 @@ private:
OutputStream& operator<<(OutputStream& stream, const DNSName&);
}
template<>
struct AK::Formatter<LookupServer::DNSName> : Formatter<StringView> {
void format(FormatBuilder& builder, const LookupServer::DNSName& value)
{
return Formatter<StringView>::format(builder, value.as_string());
}
};

View file

@ -28,6 +28,7 @@
#include "DNSPacket.h"
#include "DNSName.h"
#include "DNSPacketHeader.h"
#include <AK/Debug.h>
#include <AK/IPv4Address.h>
#include <AK/MemoryStream.h>
#include <AK/StringBuilder.h>
@ -124,13 +125,11 @@ Optional<DNSPacket> 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> 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> 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();
}