mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:27:45 +00:00
LookupServer: Turn #defines into enum classes and add formatter
This commit is contained in:
parent
6e70888315
commit
7b3bed7910
11 changed files with 120 additions and 49 deletions
|
@ -7,21 +7,35 @@
|
|||
#pragma once
|
||||
|
||||
#include "DNSName.h"
|
||||
#include <AK/Format.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace LookupServer {
|
||||
|
||||
enum class DNSRecordType : u16 {
|
||||
A = 1,
|
||||
NS = 2,
|
||||
CNAME = 5,
|
||||
SOA = 6,
|
||||
PTR = 12,
|
||||
MX = 15,
|
||||
};
|
||||
|
||||
enum class DNSRecordClass : u16 {
|
||||
IN = 1
|
||||
};
|
||||
|
||||
#define MDNS_CACHE_FLUSH 0x8000
|
||||
|
||||
class DNSAnswer {
|
||||
public:
|
||||
DNSAnswer(const DNSName& name, u16 type, u16 class_code, u32 ttl, const String& record_data, bool mdns_cache_flush);
|
||||
DNSAnswer(const DNSName& name, DNSRecordType type, DNSRecordClass class_code, u32 ttl, const String& record_data, bool mdns_cache_flush);
|
||||
|
||||
const DNSName& name() const { return m_name; }
|
||||
u16 type() const { return m_type; }
|
||||
u16 class_code() const { return m_class_code; }
|
||||
u16 raw_class_code() const { return m_class_code | (m_mdns_cache_flush ? MDNS_CACHE_FLUSH : 0); }
|
||||
DNSRecordType type() const { return m_type; }
|
||||
DNSRecordClass class_code() const { return m_class_code; }
|
||||
u16 raw_class_code() const { return (u16)m_class_code | (m_mdns_cache_flush ? MDNS_CACHE_FLUSH : 0); }
|
||||
u32 ttl() const { return m_ttl; }
|
||||
const String& record_data() const { return m_record_data; }
|
||||
bool mdns_cache_flush() const { return m_mdns_cache_flush; }
|
||||
|
@ -30,8 +44,8 @@ public:
|
|||
|
||||
private:
|
||||
DNSName m_name;
|
||||
u16 m_type { 0 };
|
||||
u16 m_class_code { 0 };
|
||||
DNSRecordType m_type { 0 };
|
||||
DNSRecordClass m_class_code { 0 };
|
||||
u32 m_ttl { 0 };
|
||||
time_t m_expiration_time { 0 };
|
||||
String m_record_data;
|
||||
|
@ -39,3 +53,24 @@ private:
|
|||
};
|
||||
|
||||
}
|
||||
template<>
|
||||
struct AK::Formatter<LookupServer::DNSRecordType> : StandardFormatter {
|
||||
Formatter() = default;
|
||||
explicit Formatter(StandardFormatter formatter)
|
||||
: StandardFormatter(formatter)
|
||||
{
|
||||
}
|
||||
|
||||
void format(AK::FormatBuilder&, LookupServer::DNSRecordType);
|
||||
};
|
||||
|
||||
template<>
|
||||
struct AK::Formatter<LookupServer::DNSRecordClass> : StandardFormatter {
|
||||
Formatter() = default;
|
||||
explicit Formatter(StandardFormatter formatter)
|
||||
: StandardFormatter(formatter)
|
||||
{
|
||||
}
|
||||
|
||||
void format(AK::FormatBuilder&, LookupServer::DNSRecordClass);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue