1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 10:17:35 +00:00

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
2 changed files with 16 additions and 13 deletions

View file

@ -56,3 +56,11 @@ private:
OutputStream& operator<<(OutputStream& stream, const DNSName&); 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 "DNSPacket.h"
#include "DNSName.h" #include "DNSName.h"
#include "DNSPacketHeader.h" #include "DNSPacketHeader.h"
#include <AK/Debug.h>
#include <AK/IPv4Address.h> #include <AK/IPv4Address.h>
#include <AK/MemoryStream.h> #include <AK/MemoryStream.h>
#include <AK/StringBuilder.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); auto& header = *(const DNSPacketHeader*)(raw_data);
#ifdef LOOKUPSERVER_DEBUG dbgln_if(LOOKUPSERVER_DEBUG, "Got packet (ID: {})", header.id());
dbgln("Got packet (ID: {})", header.id()); dbgln_if(LOOKUPSERVER_DEBUG, " Question count: {}", header.question_count());
dbgln(" Question count: {}", header.question_count()); dbgln_if(LOOKUPSERVER_DEBUG, " Answer count: {}", header.answer_count());
dbgln(" Answer count: {}", header.answer_count()); dbgln_if(LOOKUPSERVER_DEBUG, " Authority count: {}", header.authority_count());
dbgln(" Authority count: {}", header.authority_count()); dbgln_if(LOOKUPSERVER_DEBUG, "Additional count: {}", header.additional_count());
dbgln("Additional count: {}", header.additional_count());
#endif
DNSPacket packet; DNSPacket packet;
packet.m_id = header.id(); 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]; auto& record_and_class = *(const RawDNSAnswerQuestion*)&raw_data[offset];
packet.m_questions.empend(name, record_and_class.record_type, record_and_class.class_code); packet.m_questions.empend(name, record_and_class.record_type, record_and_class.class_code);
offset += 4; offset += 4;
#ifdef LOOKUPSERVER_DEBUG
auto& question = packet.m_questions.last(); auto& question = packet.m_questions.last();
dbgln("Question #{}: name=_{}_, type={}, class={}", i, question.name(), question.record_type(), question.class_code()); dbgln_if(LOOKUPSERVER_DEBUG, "Question #{}: name=_{}_, type={}, class={}", i, question.name(), question.record_type(), question.class_code());
#endif
} }
for (u16 i = 0; i < header.answer_count(); ++i) { 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? // FIXME: Parse some other record types perhaps?
dbgln("data=(unimplemented record type {})", record.type()); dbgln("data=(unimplemented record type {})", record.type());
} }
#ifdef LOOKUPSERVER_DEBUG dbgln_if(LOOKUPSERVER_DEBUG, "Answer #{}: name=_{}_, type={}, ttl={}, length={}, data=_{}_", i, name, record.type(), record.ttl(), record.data_length(), data);
dbgln("Answer #{}: name=_{}_, type={}, ttl={}, length={}, data=_{}_", i, name, record.type(), record.ttl(), record.data_length(), data);
#endif
packet.m_answers.empend(name, record.type(), record.record_class(), record.ttl(), data); packet.m_answers.empend(name, record.type(), record.record_class(), record.ttl(), data);
offset += record.data_length(); offset += record.data_length();
} }