mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:27:45 +00:00
LookupServer: Move into LookupServer
namespace
This commit is contained in:
parent
7e9122950e
commit
314f966745
10 changed files with 37 additions and 1 deletions
|
@ -27,6 +27,8 @@
|
||||||
#include "DNSAnswer.h"
|
#include "DNSAnswer.h"
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
namespace LookupServer {
|
||||||
|
|
||||||
DNSAnswer::DNSAnswer(const String& name, u16 type, u16 class_code, u32 ttl, const String& record_data)
|
DNSAnswer::DNSAnswer(const String& name, u16 type, u16 class_code, u32 ttl, const String& record_data)
|
||||||
: m_name(name)
|
: m_name(name)
|
||||||
, m_type(type)
|
, m_type(type)
|
||||||
|
@ -44,3 +46,5 @@ bool DNSAnswer::has_expired() const
|
||||||
{
|
{
|
||||||
return time(nullptr) >= m_expiration_time;
|
return time(nullptr) >= m_expiration_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
|
||||||
|
namespace LookupServer {
|
||||||
|
|
||||||
class DNSAnswer {
|
class DNSAnswer {
|
||||||
public:
|
public:
|
||||||
DNSAnswer(const String& name, u16 type, u16 class_code, u32 ttl, const String& record_data);
|
DNSAnswer(const String& name, u16 type, u16 class_code, u32 ttl, const String& record_data);
|
||||||
|
@ -49,3 +51,5 @@ private:
|
||||||
time_t m_expiration_time { 0 };
|
time_t m_expiration_time { 0 };
|
||||||
String m_record_data;
|
String m_record_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
#include <AK/Endian.h>
|
#include <AK/Endian.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
|
||||||
|
namespace LookupServer {
|
||||||
|
|
||||||
class [[gnu::packed]] DNSPacket {
|
class [[gnu::packed]] DNSPacket {
|
||||||
public:
|
public:
|
||||||
DNSPacket()
|
DNSPacket()
|
||||||
|
@ -113,3 +115,5 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(sizeof(DNSPacket) == 12);
|
static_assert(sizeof(DNSPacket) == 12);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
namespace LookupServer {
|
||||||
|
|
||||||
const u16 C_IN = 1;
|
const u16 C_IN = 1;
|
||||||
|
|
||||||
DNSRequest::DNSRequest()
|
DNSRequest::DNSRequest()
|
||||||
|
@ -94,3 +96,5 @@ ByteBuffer DNSRequest::to_byte_buffer() const
|
||||||
|
|
||||||
return stream.copy_into_contiguous_buffer();
|
return stream.copy_into_contiguous_buffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
#define T_PTR 12
|
#define T_PTR 12
|
||||||
#define T_MX 15
|
#define T_MX 15
|
||||||
|
|
||||||
|
namespace LookupServer {
|
||||||
|
|
||||||
enum class ShouldRandomizeCase {
|
enum class ShouldRandomizeCase {
|
||||||
No = 0,
|
No = 0,
|
||||||
Yes
|
Yes
|
||||||
|
@ -63,3 +65,5 @@ private:
|
||||||
u16 m_id { 0 };
|
u16 m_id { 0 };
|
||||||
Vector<DNSQuestion> m_questions;
|
Vector<DNSQuestion> m_questions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
#include <AK/IPv4Address.h>
|
#include <AK/IPv4Address.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
|
||||||
|
namespace LookupServer {
|
||||||
|
|
||||||
static String parse_dns_name(const u8* data, size_t& offset, size_t max_offset, size_t recursion_level = 0);
|
static String parse_dns_name(const u8* data, size_t& offset, size_t max_offset, size_t recursion_level = 0);
|
||||||
|
|
||||||
class [[gnu::packed]] DNSRecordWithoutName {
|
class [[gnu::packed]] DNSRecordWithoutName {
|
||||||
|
@ -151,3 +153,5 @@ String parse_dns_name(const u8* data, size_t& offset, size_t max_offset, size_t
|
||||||
}
|
}
|
||||||
return String::copy(buf);
|
return String::copy(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
|
||||||
|
namespace LookupServer {
|
||||||
|
|
||||||
class DNSResponse {
|
class DNSResponse {
|
||||||
public:
|
public:
|
||||||
static Optional<DNSResponse> from_raw_response(const u8*, size_t);
|
static Optional<DNSResponse> from_raw_response(const u8*, size_t);
|
||||||
|
@ -75,3 +77,5 @@ private:
|
||||||
Vector<DNSQuestion> m_questions;
|
Vector<DNSQuestion> m_questions;
|
||||||
Vector<DNSAnswer> m_answers;
|
Vector<DNSAnswer> m_answers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -41,6 +41,8 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
namespace LookupServer {
|
||||||
|
|
||||||
LookupServer::LookupServer()
|
LookupServer::LookupServer()
|
||||||
{
|
{
|
||||||
auto config = Core::ConfigFile::get_for_system("LookupServer");
|
auto config = Core::ConfigFile::get_for_system("LookupServer");
|
||||||
|
@ -277,3 +279,5 @@ Vector<String> LookupServer::lookup(const String& hostname, const String& namese
|
||||||
}
|
}
|
||||||
return responses;
|
return responses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
#include "DNSResponse.h"
|
#include "DNSResponse.h"
|
||||||
#include <LibCore/Object.h>
|
#include <LibCore/Object.h>
|
||||||
|
|
||||||
|
namespace LookupServer {
|
||||||
|
|
||||||
class DNSAnswer;
|
class DNSAnswer;
|
||||||
|
|
||||||
class LookupServer final : public Core::Object {
|
class LookupServer final : public Core::Object {
|
||||||
|
@ -53,3 +55,5 @@ private:
|
||||||
HashMap<String, String> m_etc_hosts;
|
HashMap<String, String> m_etc_hosts;
|
||||||
HashMap<String, CachedLookup> m_lookup_cache;
|
HashMap<String, CachedLookup> m_lookup_cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::EventLoop event_loop;
|
Core::EventLoop event_loop;
|
||||||
auto server = LookupServer::construct();
|
auto server = LookupServer::LookupServer::construct();
|
||||||
|
|
||||||
if (pledge("stdio accept inet", nullptr) < 0) {
|
if (pledge("stdio accept inet", nullptr) < 0) {
|
||||||
perror("pledge");
|
perror("pledge");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue