diff --git a/Userland/Libraries/CMakeLists.txt b/Userland/Libraries/CMakeLists.txt index cf19348520a..6b3cb12b76d 100644 --- a/Userland/Libraries/CMakeLists.txt +++ b/Userland/Libraries/CMakeLists.txt @@ -15,6 +15,7 @@ add_subdirectory(LibDesktop) add_subdirectory(LibDeviceTree) add_subdirectory(LibDiff) add_subdirectory(LibDl) +add_subdirectory(LibDNS) add_subdirectory(LibDSP) add_subdirectory(LibEDID) add_subdirectory(LibELF) diff --git a/Userland/Libraries/LibDNS/CMakeLists.txt b/Userland/Libraries/LibDNS/CMakeLists.txt new file mode 100644 index 00000000000..332ebbd00bd --- /dev/null +++ b/Userland/Libraries/LibDNS/CMakeLists.txt @@ -0,0 +1,8 @@ +set(SOURCES + DNSAnswer.cpp + DNSName.cpp + DNSPacket.cpp +) + +serenity_lib(LibDNS dns) +target_link_libraries(LibDNS LibC) diff --git a/Userland/Services/LookupServer/DNSAnswer.cpp b/Userland/Libraries/LibDNS/DNSAnswer.cpp similarity index 64% rename from Userland/Services/LookupServer/DNSAnswer.cpp rename to Userland/Libraries/LibDNS/DNSAnswer.cpp index 06f8b516c0e..2997027a33f 100644 --- a/Userland/Services/LookupServer/DNSAnswer.cpp +++ b/Userland/Libraries/LibDNS/DNSAnswer.cpp @@ -8,7 +8,7 @@ #include #include -namespace LookupServer { +namespace DNS { DNSAnswer::DNSAnswer(DNSName const& name, DNSRecordType type, DNSRecordClass class_code, u32 ttl, String const& record_data, bool mdns_cache_flush) : m_name(name) @@ -28,26 +28,26 @@ bool DNSAnswer::has_expired() const } -ErrorOr AK::Formatter::format(AK::FormatBuilder& builder, LookupServer::DNSRecordType value) +ErrorOr AK::Formatter::format(AK::FormatBuilder& builder, DNS::DNSRecordType value) { switch (value) { - case LookupServer::DNSRecordType::A: + case DNS::DNSRecordType::A: return builder.put_string("A"); - case LookupServer::DNSRecordType::NS: + case DNS::DNSRecordType::NS: return builder.put_string("NS"); - case LookupServer::DNSRecordType::CNAME: + case DNS::DNSRecordType::CNAME: return builder.put_string("CNAME"); - case LookupServer::DNSRecordType::SOA: + case DNS::DNSRecordType::SOA: return builder.put_string("SOA"); - case LookupServer::DNSRecordType::PTR: + case DNS::DNSRecordType::PTR: return builder.put_string("PTR"); - case LookupServer::DNSRecordType::MX: + case DNS::DNSRecordType::MX: return builder.put_string("MX"); - case LookupServer::DNSRecordType::TXT: + case DNS::DNSRecordType::TXT: return builder.put_string("TXT"); - case LookupServer::DNSRecordType::AAAA: + case DNS::DNSRecordType::AAAA: return builder.put_string("AAAA"); - case LookupServer::DNSRecordType::SRV: + case DNS::DNSRecordType::SRV: return builder.put_string("SRV"); } @@ -56,10 +56,10 @@ ErrorOr AK::Formatter::format(AK::FormatBuild return {}; } -ErrorOr AK::Formatter::format(AK::FormatBuilder& builder, LookupServer::DNSRecordClass value) +ErrorOr AK::Formatter::format(AK::FormatBuilder& builder, DNS::DNSRecordClass value) { switch (value) { - case LookupServer::DNSRecordClass::IN: + case DNS::DNSRecordClass::IN: return builder.put_string("IN"); } diff --git a/Userland/Services/LookupServer/DNSAnswer.h b/Userland/Libraries/LibDNS/DNSAnswer.h similarity index 83% rename from Userland/Services/LookupServer/DNSAnswer.h rename to Userland/Libraries/LibDNS/DNSAnswer.h index 4a65dad0db0..714804aaf86 100644 --- a/Userland/Services/LookupServer/DNSAnswer.h +++ b/Userland/Libraries/LibDNS/DNSAnswer.h @@ -11,7 +11,7 @@ #include #include -namespace LookupServer { +namespace DNS { enum class DNSRecordType : u16 { A = 1, @@ -58,23 +58,23 @@ private: } template<> -struct AK::Formatter : StandardFormatter { +struct AK::Formatter : StandardFormatter { Formatter() = default; explicit Formatter(StandardFormatter formatter) : StandardFormatter(formatter) { } - ErrorOr format(AK::FormatBuilder&, LookupServer::DNSRecordType); + ErrorOr format(AK::FormatBuilder&, DNS::DNSRecordType); }; template<> -struct AK::Formatter : StandardFormatter { +struct AK::Formatter : StandardFormatter { Formatter() = default; explicit Formatter(StandardFormatter formatter) : StandardFormatter(formatter) { } - ErrorOr format(AK::FormatBuilder&, LookupServer::DNSRecordClass); + ErrorOr format(AK::FormatBuilder&, DNS::DNSRecordClass); }; diff --git a/Userland/Services/LookupServer/DNSName.cpp b/Userland/Libraries/LibDNS/DNSName.cpp similarity index 99% rename from Userland/Services/LookupServer/DNSName.cpp rename to Userland/Libraries/LibDNS/DNSName.cpp index a29cbec521c..281ee416462 100644 --- a/Userland/Services/LookupServer/DNSName.cpp +++ b/Userland/Libraries/LibDNS/DNSName.cpp @@ -10,7 +10,7 @@ #include #include -namespace LookupServer { +namespace DNS { DNSName::DNSName(String const& name) { diff --git a/Userland/Services/LookupServer/DNSName.h b/Userland/Libraries/LibDNS/DNSName.h similarity index 84% rename from Userland/Services/LookupServer/DNSName.h rename to Userland/Libraries/LibDNS/DNSName.h index 375f61c1b70..74aeb447fc4 100644 --- a/Userland/Services/LookupServer/DNSName.h +++ b/Userland/Libraries/LibDNS/DNSName.h @@ -10,7 +10,7 @@ #include #include -namespace LookupServer { +namespace DNS { class DNSName { public: @@ -40,8 +40,8 @@ OutputStream& operator<<(OutputStream& stream, DNSName const&); } template<> -struct AK::Formatter : Formatter { - ErrorOr format(FormatBuilder& builder, LookupServer::DNSName const& value) +struct AK::Formatter : Formatter { + ErrorOr format(FormatBuilder& builder, DNS::DNSName const& value) { return Formatter::format(builder, value.as_string()); } diff --git a/Userland/Services/LookupServer/DNSPacket.cpp b/Userland/Libraries/LibDNS/DNSPacket.cpp similarity index 99% rename from Userland/Services/LookupServer/DNSPacket.cpp rename to Userland/Libraries/LibDNS/DNSPacket.cpp index 90753cde26f..305d98fa392 100644 --- a/Userland/Services/LookupServer/DNSPacket.cpp +++ b/Userland/Libraries/LibDNS/DNSPacket.cpp @@ -14,7 +14,7 @@ #include #include -namespace LookupServer { +namespace DNS { void DNSPacket::add_question(DNSQuestion const& question) { diff --git a/Userland/Services/LookupServer/DNSPacket.h b/Userland/Libraries/LibDNS/DNSPacket.h similarity index 99% rename from Userland/Services/LookupServer/DNSPacket.h rename to Userland/Libraries/LibDNS/DNSPacket.h index 60225cec0cf..d531ad9073b 100644 --- a/Userland/Services/LookupServer/DNSPacket.h +++ b/Userland/Libraries/LibDNS/DNSPacket.h @@ -13,7 +13,7 @@ #include #include -namespace LookupServer { +namespace DNS { enum class ShouldRandomizeCase { No = 0, diff --git a/Userland/Services/LookupServer/DNSPacketHeader.h b/Userland/Libraries/LibDNS/DNSPacketHeader.h similarity index 99% rename from Userland/Services/LookupServer/DNSPacketHeader.h rename to Userland/Libraries/LibDNS/DNSPacketHeader.h index 9b3f6271223..40ddcfe946b 100644 --- a/Userland/Services/LookupServer/DNSPacketHeader.h +++ b/Userland/Libraries/LibDNS/DNSPacketHeader.h @@ -9,7 +9,7 @@ #include #include -namespace LookupServer { +namespace DNS { class [[gnu::packed]] DNSPacketHeader { public: diff --git a/Userland/Services/LookupServer/DNSQuestion.h b/Userland/Libraries/LibDNS/DNSQuestion.h similarity index 97% rename from Userland/Services/LookupServer/DNSQuestion.h rename to Userland/Libraries/LibDNS/DNSQuestion.h index eaa83bb5667..5897f8e2f6d 100644 --- a/Userland/Services/LookupServer/DNSQuestion.h +++ b/Userland/Libraries/LibDNS/DNSQuestion.h @@ -9,7 +9,7 @@ #include "DNSName.h" #include -namespace LookupServer { +namespace DNS { #define MDNS_WANTS_UNICAST_RESPONSE 0x8000 diff --git a/Userland/Services/LookupServer/CMakeLists.txt b/Userland/Services/LookupServer/CMakeLists.txt index 05187fb073e..b4be1ec03c4 100644 --- a/Userland/Services/LookupServer/CMakeLists.txt +++ b/Userland/Services/LookupServer/CMakeLists.txt @@ -8,9 +8,6 @@ compile_ipc(LookupServer.ipc LookupServerEndpoint.h) compile_ipc(LookupClient.ipc LookupClientEndpoint.h) set(SOURCES - DNSAnswer.cpp - DNSName.cpp - DNSPacket.cpp DNSServer.cpp LookupServer.cpp LookupServerEndpoint.h @@ -21,4 +18,4 @@ set(SOURCES ) serenity_bin(LookupServer) -target_link_libraries(LookupServer LibCore LibIPC LibMain) +target_link_libraries(LookupServer LibCore LibDNS LibIPC LibMain) diff --git a/Userland/Services/LookupServer/ConnectionFromClient.cpp b/Userland/Services/LookupServer/ConnectionFromClient.cpp index 6212e9af9e2..ad2b2918ee5 100644 --- a/Userland/Services/LookupServer/ConnectionFromClient.cpp +++ b/Userland/Services/LookupServer/ConnectionFromClient.cpp @@ -5,12 +5,14 @@ */ #include "ConnectionFromClient.h" -#include "DNSPacket.h" #include "LookupServer.h" #include +#include namespace LookupServer { +using namespace DNS; + static HashMap> s_connections; ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr socket, int client_id) diff --git a/Userland/Services/LookupServer/DNSServer.cpp b/Userland/Services/LookupServer/DNSServer.cpp index 7d3846f0d0a..c01772fa566 100644 --- a/Userland/Services/LookupServer/DNSServer.cpp +++ b/Userland/Services/LookupServer/DNSServer.cpp @@ -5,12 +5,14 @@ */ #include "DNSServer.h" -#include "DNSPacket.h" #include "LookupServer.h" #include +#include namespace LookupServer { +using namespace DNS; + DNSServer::DNSServer(Object* parent) : Core::UDPServer(parent) { diff --git a/Userland/Services/LookupServer/LookupServer.cpp b/Userland/Services/LookupServer/LookupServer.cpp index e45bd6e697e..d7a984f594e 100644 --- a/Userland/Services/LookupServer/LookupServer.cpp +++ b/Userland/Services/LookupServer/LookupServer.cpp @@ -6,7 +6,6 @@ #include "LookupServer.h" #include "ConnectionFromClient.h" -#include "DNSPacket.h" #include #include #include @@ -16,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git a/Userland/Services/LookupServer/LookupServer.h b/Userland/Services/LookupServer/LookupServer.h index 6f5a90d904b..28a3b7c6183 100644 --- a/Userland/Services/LookupServer/LookupServer.h +++ b/Userland/Services/LookupServer/LookupServer.h @@ -7,17 +7,17 @@ #pragma once #include "ConnectionFromClient.h" -#include "DNSName.h" -#include "DNSPacket.h" #include "DNSServer.h" #include "MulticastDNS.h" #include #include +#include +#include #include namespace LookupServer { -class DNSAnswer; +using namespace DNS; class LookupServer final : public Core::Object { C_OBJECT(LookupServer); diff --git a/Userland/Services/LookupServer/MulticastDNS.cpp b/Userland/Services/LookupServer/MulticastDNS.cpp index b7b4a4490e6..6cc571a68af 100644 --- a/Userland/Services/LookupServer/MulticastDNS.cpp +++ b/Userland/Services/LookupServer/MulticastDNS.cpp @@ -5,7 +5,6 @@ */ #include "MulticastDNS.h" -#include "DNSPacket.h" #include #include #include diff --git a/Userland/Services/LookupServer/MulticastDNS.h b/Userland/Services/LookupServer/MulticastDNS.h index 23fc71d430e..14b05960bef 100644 --- a/Userland/Services/LookupServer/MulticastDNS.h +++ b/Userland/Services/LookupServer/MulticastDNS.h @@ -6,15 +6,17 @@ #pragma once -#include "DNSAnswer.h" -#include "DNSName.h" -#include "DNSPacket.h" #include #include +#include +#include +#include #include namespace LookupServer { +using namespace DNS; + class MulticastDNS : public Core::UDPServer { C_OBJECT(MulticastDNS) public: