From ea92eb7b2b96dab01cd7687afc43c34f914029fb Mon Sep 17 00:00:00 2001 From: JDierkse Date: Wed, 10 Jun 2020 11:48:41 +0200 Subject: [PATCH] Fix Line Endings --- Network/Dns/MulticastDnsClient.cpp | 64 +++--- Network/Dns/MulticastDnsClientImpl.cpp | 292 ++++++++++++------------- Network/Dns/MulticastDnsClientImpl.h | 104 ++++----- Network/Dns/NameImpl.h | 104 ++++----- Network/Dns/OperationCode.h | 44 ++-- Network/Dns/Packet.h | 158 ++++++------- Network/Dns/QueryImpl.h | 90 ++++---- Network/Dns/ResourceRecordImpl.h | 96 ++++---- Network/Dns/ResponseCode.h | 50 ++--- include/Dns/Class.h | 48 ++-- include/Dns/Name.h | 146 ++++++------- include/Dns/Query.h | 86 ++++---- include/Dns/QueryClass.h | 50 ++--- include/Dns/QueryType.h | 80 +++---- include/Dns/ResourceRecord.h | 88 ++++---- include/Dns/Type.h | 72 +++--- 16 files changed, 786 insertions(+), 786 deletions(-) diff --git a/Network/Dns/MulticastDnsClient.cpp b/Network/Dns/MulticastDnsClient.cpp index efde6ee..6601cfa 100644 --- a/Network/Dns/MulticastDnsClient.cpp +++ b/Network/Dns/MulticastDnsClient.cpp @@ -1,32 +1,32 @@ -#include "Dns/MulticastDnsClient.h" -#include "MulticastDnsClientImpl.h" - - -namespace Network { -namespace Dns { - -MulticastDnsClient::MulticastDnsClient(std::function&)> callback) : - m_pMulticastDnsClientImpl(new MulticastDnsClientImpl(std::bind(&MulticastDnsClient::Callback, this, std::placeholders::_1))), - m_callback(callback) -{ -} - -MulticastDnsClient::~MulticastDnsClient() = default; - -void MulticastDnsClient::Query(const Dns::Query& query) -{ - m_pMulticastDnsClientImpl->Query(*query.PImpl()); -} - -void MulticastDnsClient::Callback(const std::vector& answers) -{ - std::vector ans; - - for (auto& answer : answers) - ans.push_back(ResourceRecord(std::make_shared(answer))); - - m_callback(ans); -} - -} // namespace Dns -} // namespace Network +#include "Dns/MulticastDnsClient.h" +#include "MulticastDnsClientImpl.h" + + +namespace Network { +namespace Dns { + +MulticastDnsClient::MulticastDnsClient(std::function&)> callback) : + m_pMulticastDnsClientImpl(new MulticastDnsClientImpl(std::bind(&MulticastDnsClient::Callback, this, std::placeholders::_1))), + m_callback(callback) +{ +} + +MulticastDnsClient::~MulticastDnsClient() = default; + +void MulticastDnsClient::Query(const Dns::Query& query) +{ + m_pMulticastDnsClientImpl->Query(*query.PImpl()); +} + +void MulticastDnsClient::Callback(const std::vector& answers) +{ + std::vector ans; + + for (auto& answer : answers) + ans.push_back(ResourceRecord(std::make_shared(answer))); + + m_callback(ans); +} + +} // namespace Dns +} // namespace Network diff --git a/Network/Dns/MulticastDnsClientImpl.cpp b/Network/Dns/MulticastDnsClientImpl.cpp index 5ff3fba..6fd0fce 100644 --- a/Network/Dns/MulticastDnsClientImpl.cpp +++ b/Network/Dns/MulticastDnsClientImpl.cpp @@ -1,146 +1,146 @@ -#include "MulticastDnsClientImpl.h" -#include "MalformedPacket.h" -#include "Packet.h" -#include - - -namespace Network { -namespace Dns { - -MulticastDnsClientImpl::MulticastDnsClientImpl(std::function&)> callback) : - m_timer(m_ioService), - m_responseBuffer(1024), - m_socket(m_ioService, asio::ip::udp::v4()), - m_multicastEndpoint(asio::ip::address::from_string("224.0.0.251"), 5353), - m_callback(callback) -{ - m_socket.set_option(asio::socket_base::reuse_address(true)); - m_socket.set_option(asio::ip::multicast::join_group(m_multicastEndpoint.address())); - m_socket.set_option(asio::ip::multicast::hops(255)); - m_socket.bind(asio::ip::udp::endpoint(asio::ip::udp::v4(), 5353)); - - m_thread = std::thread([&] { m_ioService.run(); }); -} - -MulticastDnsClientImpl::~MulticastDnsClientImpl() -{ - m_ioService.stop(); - m_thread.join(); -} - -void MulticastDnsClientImpl::Query(const QueryImpl& query) -{ - m_query = query; - m_iterations = 3; - SendQuery(); -} - -void MulticastDnsClientImpl::SetTimer(int milliseconds) -{ - m_timer.cancel(); - m_timer.expires_from_now(std::chrono::milliseconds(milliseconds)); -} - -void MulticastDnsClientImpl::SendQuery() -{ - if (m_iterations == 0) - return; - m_iterations--; - - Packet packet; - packet.AddQuery(m_query); - - auto data = std::make_shared(packet.GetData()); - - m_socket.async_send_to( - asio::buffer(data->GetPtr(), data->GetLength()), - m_multicastEndpoint, - std::bind(&MulticastDnsClientImpl::HandleQuerySent, this, - std::placeholders::_1, - data - ) - ); -} - -void MulticastDnsClientImpl::HandleQuerySent(const asio::error_code & error, std::shared_ptr data) -{ - if (error == asio::error::operation_aborted) - { - SendQuery(); - } - else if (error) - { - std::stringstream ss; - ss << "MulticastDnsClientImpl::HandleQuerySent: " << error.message(); - Logging::Log(Logging::Severity::Error, ss.str()); - } - else - { - SetTimer(1000); - m_timer.async_wait(std::bind( - &MulticastDnsClientImpl::HandleQueryTimeout, this, - std::placeholders::_1 - )); - ReceiveQuery(); - } -} - -void MulticastDnsClientImpl::ReceiveQuery() -{ - m_socket.async_receive_from( - asio::buffer(m_responseBuffer), - m_receiveEndpoint, - std::bind(&MulticastDnsClientImpl::HandleQueryResponse, this, - std::placeholders::_1, - std::placeholders::_2 - ) - ); -} - -void MulticastDnsClientImpl::HandleQueryResponse(const asio::error_code & error, std::size_t size) -{ - if (error == asio::error::operation_aborted) - { - SendQuery(); - } - else if (error) - { - std::stringstream ss; - ss << "MulticastDnsClientImpl::HandleQueryResponse: " << error.message(); - Logging::Log(Logging::Severity::Error, ss.str()); - } - else - { - try - { - Packet packet(DataReader(m_responseBuffer.data(), size), 0); - if (packet.GetQuery()) - m_callback(packet.GetAnswers()); - } - catch(MalformedPacket& mp) - { - } - - ReceiveQuery(); - } -} - -void MulticastDnsClientImpl::HandleQueryTimeout(const asio::error_code & error) -{ - if (error == asio::error::operation_aborted) - { - } - else if (error) - { - std::stringstream ss; - ss << "MulticastDnsClientImpl::HandleQueryTimeout: " << error.message(); - Logging::Log(Logging::Severity::Error, ss.str()); - } - else - { - m_socket.cancel(); - } -} - -} // namespace Dns -} // namespace Network +#include "MulticastDnsClientImpl.h" +#include "MalformedPacket.h" +#include "Packet.h" +#include + + +namespace Network { +namespace Dns { + +MulticastDnsClientImpl::MulticastDnsClientImpl(std::function&)> callback) : + m_timer(m_ioService), + m_responseBuffer(1024), + m_socket(m_ioService, asio::ip::udp::v4()), + m_multicastEndpoint(asio::ip::address::from_string("224.0.0.251"), 5353), + m_callback(callback) +{ + m_socket.set_option(asio::socket_base::reuse_address(true)); + m_socket.set_option(asio::ip::multicast::join_group(m_multicastEndpoint.address())); + m_socket.set_option(asio::ip::multicast::hops(255)); + m_socket.bind(asio::ip::udp::endpoint(asio::ip::udp::v4(), 5353)); + + m_thread = std::thread([&] { m_ioService.run(); }); +} + +MulticastDnsClientImpl::~MulticastDnsClientImpl() +{ + m_ioService.stop(); + m_thread.join(); +} + +void MulticastDnsClientImpl::Query(const QueryImpl& query) +{ + m_query = query; + m_iterations = 3; + SendQuery(); +} + +void MulticastDnsClientImpl::SetTimer(int milliseconds) +{ + m_timer.cancel(); + m_timer.expires_from_now(std::chrono::milliseconds(milliseconds)); +} + +void MulticastDnsClientImpl::SendQuery() +{ + if (m_iterations == 0) + return; + m_iterations--; + + Packet packet; + packet.AddQuery(m_query); + + auto data = std::make_shared(packet.GetData()); + + m_socket.async_send_to( + asio::buffer(data->GetPtr(), data->GetLength()), + m_multicastEndpoint, + std::bind(&MulticastDnsClientImpl::HandleQuerySent, this, + std::placeholders::_1, + data + ) + ); +} + +void MulticastDnsClientImpl::HandleQuerySent(const asio::error_code & error, std::shared_ptr data) +{ + if (error == asio::error::operation_aborted) + { + SendQuery(); + } + else if (error) + { + std::stringstream ss; + ss << "MulticastDnsClientImpl::HandleQuerySent: " << error.message(); + Logging::Log(Logging::Severity::Error, ss.str()); + } + else + { + SetTimer(1000); + m_timer.async_wait(std::bind( + &MulticastDnsClientImpl::HandleQueryTimeout, this, + std::placeholders::_1 + )); + ReceiveQuery(); + } +} + +void MulticastDnsClientImpl::ReceiveQuery() +{ + m_socket.async_receive_from( + asio::buffer(m_responseBuffer), + m_receiveEndpoint, + std::bind(&MulticastDnsClientImpl::HandleQueryResponse, this, + std::placeholders::_1, + std::placeholders::_2 + ) + ); +} + +void MulticastDnsClientImpl::HandleQueryResponse(const asio::error_code & error, std::size_t size) +{ + if (error == asio::error::operation_aborted) + { + SendQuery(); + } + else if (error) + { + std::stringstream ss; + ss << "MulticastDnsClientImpl::HandleQueryResponse: " << error.message(); + Logging::Log(Logging::Severity::Error, ss.str()); + } + else + { + try + { + Packet packet(DataReader(m_responseBuffer.data(), size), 0); + if (packet.GetQuery()) + m_callback(packet.GetAnswers()); + } + catch(MalformedPacket& mp) + { + } + + ReceiveQuery(); + } +} + +void MulticastDnsClientImpl::HandleQueryTimeout(const asio::error_code & error) +{ + if (error == asio::error::operation_aborted) + { + } + else if (error) + { + std::stringstream ss; + ss << "MulticastDnsClientImpl::HandleQueryTimeout: " << error.message(); + Logging::Log(Logging::Severity::Error, ss.str()); + } + else + { + m_socket.cancel(); + } +} + +} // namespace Dns +} // namespace Network diff --git a/Network/Dns/MulticastDnsClientImpl.h b/Network/Dns/MulticastDnsClientImpl.h index 4bc09df..34f20cd 100644 --- a/Network/Dns/MulticastDnsClientImpl.h +++ b/Network/Dns/MulticastDnsClientImpl.h @@ -1,52 +1,52 @@ -#ifndef NETWORK_DNS_MULTICASTDNSCLIENTIMPL_H -#define NETWORK_DNS_MULTICASTDNSCLIENTIMPL_H - -#include "QueryImpl.h" -#include "ResourceRecordImpl.h" -#include -#include -#include -#include -#include - - -namespace Network { -namespace Dns { - -class MulticastDnsClientImpl -{ -public: - MulticastDnsClientImpl(std::function&)> callback); - ~MulticastDnsClientImpl(); - -public: - void Query(const QueryImpl& query); - -private: - void SetTimer(int milliseconds); - void SendQuery(); - void HandleQuerySent(const asio::error_code & error, std::shared_ptr data); - void ReceiveQuery(); - void HandleQueryResponse(const asio::error_code & error, std::size_t size); - void HandleQueryTimeout(const asio::error_code & error); - -private: - std::thread m_thread; - asio::io_service m_ioService; - asio::system_timer m_timer; - - std::vector m_responseBuffer; - - asio::ip::udp::socket m_socket; - asio::ip::udp::endpoint m_multicastEndpoint; - asio::ip::udp::endpoint m_receiveEndpoint; - - int m_iterations; - QueryImpl m_query; - std::function&)> m_callback; -}; - -} // namespace Dns -} // namespace Network - -#endif // NETWORK_DNS_MULTICASTDNSCLIENTIMPL_H +#ifndef NETWORK_DNS_MULTICASTDNSCLIENTIMPL_H +#define NETWORK_DNS_MULTICASTDNSCLIENTIMPL_H + +#include "QueryImpl.h" +#include "ResourceRecordImpl.h" +#include +#include +#include +#include +#include + + +namespace Network { +namespace Dns { + +class MulticastDnsClientImpl +{ +public: + MulticastDnsClientImpl(std::function&)> callback); + ~MulticastDnsClientImpl(); + +public: + void Query(const QueryImpl& query); + +private: + void SetTimer(int milliseconds); + void SendQuery(); + void HandleQuerySent(const asio::error_code & error, std::shared_ptr data); + void ReceiveQuery(); + void HandleQueryResponse(const asio::error_code & error, std::size_t size); + void HandleQueryTimeout(const asio::error_code & error); + +private: + std::thread m_thread; + asio::io_service m_ioService; + asio::system_timer m_timer; + + std::vector m_responseBuffer; + + asio::ip::udp::socket m_socket; + asio::ip::udp::endpoint m_multicastEndpoint; + asio::ip::udp::endpoint m_receiveEndpoint; + + int m_iterations; + QueryImpl m_query; + std::function&)> m_callback; +}; + +} // namespace Dns +} // namespace Network + +#endif // NETWORK_DNS_MULTICASTDNSCLIENTIMPL_H diff --git a/Network/Dns/NameImpl.h b/Network/Dns/NameImpl.h index 0ae1777..1fb6e6b 100644 --- a/Network/Dns/NameImpl.h +++ b/Network/Dns/NameImpl.h @@ -1,52 +1,52 @@ -#ifndef NETWORK_DNS_NAMEIMPL_H -#define NETWORK_DNS_NAMEIMPL_H - -#include "Data.h" -#include "DataReader.h" -#include -#include - - -namespace Network { -namespace Dns { - -class NameImpl -{ -public: - NameImpl(); - - template - NameImpl(const std::string& label, const Args& ...args) : NameImpl(args...) - { - m_labels.insert(m_labels.begin(), label); - } - - NameImpl(const std::vector& labels); - - std::string GetFirstLabel() const; - std::string GetName() const; - bool empty() const; - bool endsWith(const NameImpl& suffix) const; - Data GetData() const; - - void append(const std::string& label); - void prepend(const std::string& label); - - unsigned ReadFromData(DataReader reader, unsigned pos); - - void swap(NameImpl& x) noexcept; - - bool operator==(const NameImpl& name) const; - bool operator!=(const NameImpl& name) const; - bool operator<(const NameImpl& name) const; - - friend std::ostream& operator<<(std::ostream& stream, const NameImpl& name); - -private: - std::vector m_labels; -}; - -} // namespace Dns -} // namespace Network - -#endif // NETWORK_DNS_NAMEIMPL_H +#ifndef NETWORK_DNS_NAMEIMPL_H +#define NETWORK_DNS_NAMEIMPL_H + +#include "Data.h" +#include "DataReader.h" +#include +#include + + +namespace Network { +namespace Dns { + +class NameImpl +{ +public: + NameImpl(); + + template + NameImpl(const std::string& label, const Args& ...args) : NameImpl(args...) + { + m_labels.insert(m_labels.begin(), label); + } + + NameImpl(const std::vector& labels); + + std::string GetFirstLabel() const; + std::string GetName() const; + bool empty() const; + bool endsWith(const NameImpl& suffix) const; + Data GetData() const; + + void append(const std::string& label); + void prepend(const std::string& label); + + unsigned ReadFromData(DataReader reader, unsigned pos); + + void swap(NameImpl& x) noexcept; + + bool operator==(const NameImpl& name) const; + bool operator!=(const NameImpl& name) const; + bool operator<(const NameImpl& name) const; + + friend std::ostream& operator<<(std::ostream& stream, const NameImpl& name); + +private: + std::vector m_labels; +}; + +} // namespace Dns +} // namespace Network + +#endif // NETWORK_DNS_NAMEIMPL_H diff --git a/Network/Dns/OperationCode.h b/Network/Dns/OperationCode.h index d3b899f..2d6ca05 100644 --- a/Network/Dns/OperationCode.h +++ b/Network/Dns/OperationCode.h @@ -1,22 +1,22 @@ -#ifndef NETWORK_DNS_OPERATIONCODE_H -#define NETWORK_DNS_OPERATIONCODE_H - - -namespace Network { -namespace Dns { - -class OperationCode -{ -public: - enum type - { - QUERY = 0, - IQUERY = 1, - STATUS = 2 - }; -}; - -} // namespace Dns -} // namespace Network - -#endif // NETWORK_DNS_OPERATIONCODE_H +#ifndef NETWORK_DNS_OPERATIONCODE_H +#define NETWORK_DNS_OPERATIONCODE_H + + +namespace Network { +namespace Dns { + +class OperationCode +{ +public: + enum type + { + QUERY = 0, + IQUERY = 1, + STATUS = 2 + }; +}; + +} // namespace Dns +} // namespace Network + +#endif // NETWORK_DNS_OPERATIONCODE_H diff --git a/Network/Dns/Packet.h b/Network/Dns/Packet.h index cf0d0ba..6c7ce1b 100644 --- a/Network/Dns/Packet.h +++ b/Network/Dns/Packet.h @@ -1,79 +1,79 @@ -#ifndef NETWORK_DNS_PACKET_H -#define NETWORK_DNS_PACKET_H - -#include "Data.h" -#include "DataReader.h" -#include "OperationCode.h" -#include "QueryImpl.h" -#include "ResourceRecordImpl.h" -#include "ResponseCode.h" - - -namespace Network { -namespace Dns { - -class Packet -{ -public: - Packet(); - Packet(DataReader reader, unsigned pos); - - Data GetData() const; - - uint16_t GetIdentifier() const; - bool GetQuery() const; - OperationCode::type GetOperationCode() const; - bool GetAuthorativeAnswer() const; - bool GetTruncation() const; - bool GetRecursionDesired() const; - bool GetRecursionAvailable() const; - uint8_t GetZero() const; - ResponseCode::type GetResponseCode() const; - - std::vector GetQueries() const; - std::vector GetAnswers() const; - std::vector GetAuthorities() const; - std::vector GetAdditionalRecords() const; - - unsigned GetQueryCount() const; - unsigned GetAnswerCount() const; - unsigned GetAuthorityCount() const; - unsigned GetAdditionalRecordsCount() const; - - void SetIdentifier(uint16_t identifier); - void SetQuery(bool query); - void SetOperationCode(OperationCode::type oerationCode); - void SetAuthorativeAnswer(bool authorativeAnswer); - void SetTruncation(bool truncation); - void SetRecursionDesired(bool recursionDesired); - void SetRecursionAvailable(bool recursionAvailable); - void SetZero(uint8_t zero); - void SetResponseCode(ResponseCode::type responseCode); - - void AddQuery(const QueryImpl& query); - void AddAnswer(const ResourceRecordImpl& record); - void AddAuthority(const ResourceRecordImpl& record); - void AddAdditionalRecords(const ResourceRecordImpl& record); - - friend std::ostream& operator<<(std::ostream& stream, const Packet& packet); - -private: - unsigned m_identifier : 16; - unsigned m_query : 1; - unsigned m_authorativeAnswer : 1; - unsigned m_truncation : 1; - unsigned m_recursionDesired : 1; - unsigned m_recursionAvailable : 1; - unsigned m_zero : 3; - OperationCode::type m_operationCode; - ResponseCode::type m_responseCode; - std::vector m_queries; - std::vector m_answers; - std::vector m_authorities; - std::vector m_additionalRecords; -}; - -} // namespace Dns -} // namespace Network - -#endif // NETWORK_DNS_PACKET_H +#ifndef NETWORK_DNS_PACKET_H +#define NETWORK_DNS_PACKET_H + +#include "Data.h" +#include "DataReader.h" +#include "OperationCode.h" +#include "QueryImpl.h" +#include "ResourceRecordImpl.h" +#include "ResponseCode.h" + + +namespace Network { +namespace Dns { + +class Packet +{ +public: + Packet(); + Packet(DataReader reader, unsigned pos); + + Data GetData() const; + + uint16_t GetIdentifier() const; + bool GetQuery() const; + OperationCode::type GetOperationCode() const; + bool GetAuthorativeAnswer() const; + bool GetTruncation() const; + bool GetRecursionDesired() const; + bool GetRecursionAvailable() const; + uint8_t GetZero() const; + ResponseCode::type GetResponseCode() const; + + std::vector GetQueries() const; + std::vector GetAnswers() const; + std::vector GetAuthorities() const; + std::vector GetAdditionalRecords() const; + + unsigned GetQueryCount() const; + unsigned GetAnswerCount() const; + unsigned GetAuthorityCount() const; + unsigned GetAdditionalRecordsCount() const; + + void SetIdentifier(uint16_t identifier); + void SetQuery(bool query); + void SetOperationCode(OperationCode::type oerationCode); + void SetAuthorativeAnswer(bool authorativeAnswer); + void SetTruncation(bool truncation); + void SetRecursionDesired(bool recursionDesired); + void SetRecursionAvailable(bool recursionAvailable); + void SetZero(uint8_t zero); + void SetResponseCode(ResponseCode::type responseCode); + + void AddQuery(const QueryImpl& query); + void AddAnswer(const ResourceRecordImpl& record); + void AddAuthority(const ResourceRecordImpl& record); + void AddAdditionalRecords(const ResourceRecordImpl& record); + + friend std::ostream& operator<<(std::ostream& stream, const Packet& packet); + +private: + unsigned m_identifier : 16; + unsigned m_query : 1; + unsigned m_authorativeAnswer : 1; + unsigned m_truncation : 1; + unsigned m_recursionDesired : 1; + unsigned m_recursionAvailable : 1; + unsigned m_zero : 3; + OperationCode::type m_operationCode; + ResponseCode::type m_responseCode; + std::vector m_queries; + std::vector m_answers; + std::vector m_authorities; + std::vector m_additionalRecords; +}; + +} // namespace Dns +} // namespace Network + +#endif // NETWORK_DNS_PACKET_H diff --git a/Network/Dns/QueryImpl.h b/Network/Dns/QueryImpl.h index 7db5225..fcc75bf 100644 --- a/Network/Dns/QueryImpl.h +++ b/Network/Dns/QueryImpl.h @@ -1,45 +1,45 @@ -#ifndef NETWORK_DNS_QUERYIMPL_H -#define NETWORK_DNS_QUERYIMPL_H - -#include "Data.h" -#include "DataReader.h" -#include "NameImpl.h" -#include "Dns/QueryClass.h" -#include "Dns/QueryType.h" - - -namespace Network { -namespace Dns { - -class QueryImpl -{ -public: - QueryImpl(); - - bool GetUnicast() const; - QueryType::type GetType() const; - QueryClass::type GetClass() const; - NameImpl GetName() const; - - void SetUnicast(bool unicast); - void SetType(QueryType::type type); - void SetClass(QueryClass::type class_); - void SetName(const NameImpl& name); - - Data GetData() const; - - unsigned ReadFromData(DataReader reader, unsigned pos); - - friend std::ostream& operator<<(std::ostream & stream, const QueryImpl& query); - -private: - bool m_unicast; - NameImpl m_name; - QueryType::type m_type; - QueryClass::type m_class; -}; - -} // namespace Dns -} // namespace Network - -#endif // NETWORK_DNS_QUERYIMPL_H +#ifndef NETWORK_DNS_QUERYIMPL_H +#define NETWORK_DNS_QUERYIMPL_H + +#include "Data.h" +#include "DataReader.h" +#include "NameImpl.h" +#include "Dns/QueryClass.h" +#include "Dns/QueryType.h" + + +namespace Network { +namespace Dns { + +class QueryImpl +{ +public: + QueryImpl(); + + bool GetUnicast() const; + QueryType::type GetType() const; + QueryClass::type GetClass() const; + NameImpl GetName() const; + + void SetUnicast(bool unicast); + void SetType(QueryType::type type); + void SetClass(QueryClass::type class_); + void SetName(const NameImpl& name); + + Data GetData() const; + + unsigned ReadFromData(DataReader reader, unsigned pos); + + friend std::ostream& operator<<(std::ostream & stream, const QueryImpl& query); + +private: + bool m_unicast; + NameImpl m_name; + QueryType::type m_type; + QueryClass::type m_class; +}; + +} // namespace Dns +} // namespace Network + +#endif // NETWORK_DNS_QUERYIMPL_H diff --git a/Network/Dns/ResourceRecordImpl.h b/Network/Dns/ResourceRecordImpl.h index c437625..fee70e8 100644 --- a/Network/Dns/ResourceRecordImpl.h +++ b/Network/Dns/ResourceRecordImpl.h @@ -1,48 +1,48 @@ -#ifndef NETWORK_DNS_RESOURCERECORD_H -#define NETWORK_DNS_RESOURCERECORD_H - -#include "Data.h" -#include "DataReader.h" -#include "NameImpl.h" -#include "Dns/Class.h" -#include "Dns/Type.h" - - -namespace Network { -namespace Dns { - -class ResourceRecordImpl -{ -public: - NameImpl GetName() const; - Type::type GetType() const; - Class::type GetClass() const; - uint32_t GetTTL() const; - Data GetResourceData() const; - NameImpl GetResourceDataName() const; - - Data GetData() const; - - void SetName(const NameImpl& name); - void SetType(Type::type type); - void SetClass(Class::type dnsClass); - void SetTTL(uint32_t ttl); - void SetData(const Data& resourceData); - - unsigned ReadFromData(DataReader reader, unsigned pos); - - friend std::ostream& operator<<(std::ostream& stream, const ResourceRecordImpl& record); - -private: - NameImpl m_name; - Type::type m_type; - Class::type m_class; - uint32_t m_ttl; - Data m_resourceData; - NameImpl m_resourceDataName; -}; - -} // namespace Dns -} // namespace Network - -#endif // NETWORK_DNS_RESOURCERECORD_H +#ifndef NETWORK_DNS_RESOURCERECORD_H +#define NETWORK_DNS_RESOURCERECORD_H + +#include "Data.h" +#include "DataReader.h" +#include "NameImpl.h" +#include "Dns/Class.h" +#include "Dns/Type.h" + + +namespace Network { +namespace Dns { + +class ResourceRecordImpl +{ +public: + NameImpl GetName() const; + Type::type GetType() const; + Class::type GetClass() const; + uint32_t GetTTL() const; + Data GetResourceData() const; + NameImpl GetResourceDataName() const; + + Data GetData() const; + + void SetName(const NameImpl& name); + void SetType(Type::type type); + void SetClass(Class::type dnsClass); + void SetTTL(uint32_t ttl); + void SetData(const Data& resourceData); + + unsigned ReadFromData(DataReader reader, unsigned pos); + + friend std::ostream& operator<<(std::ostream& stream, const ResourceRecordImpl& record); + +private: + NameImpl m_name; + Type::type m_type; + Class::type m_class; + uint32_t m_ttl; + Data m_resourceData; + NameImpl m_resourceDataName; +}; + +} // namespace Dns +} // namespace Network + +#endif // NETWORK_DNS_RESOURCERECORD_H diff --git a/Network/Dns/ResponseCode.h b/Network/Dns/ResponseCode.h index 4e6930b..36a7daa 100644 --- a/Network/Dns/ResponseCode.h +++ b/Network/Dns/ResponseCode.h @@ -1,25 +1,25 @@ -#ifndef NETWORK_DNS_RESPONSECODE_H -#define NETWORK_DNS_RESPONSECODE_H - - -namespace Network { -namespace Dns { - -class ResponseCode -{ -public: - enum type - { - NO_ERROR = 0, - FORMAT_ERROR = 1, - SERVER_FAILURE = 2, - NAME_ERROR = 3, - NOT_IMPLEMENTED = 4, - REFUSED = 5 - }; -}; - -} // namespace Dns -} // namespace Network - -#endif // NETWORK_DNS_RESPONSECODE_H +#ifndef NETWORK_DNS_RESPONSECODE_H +#define NETWORK_DNS_RESPONSECODE_H + + +namespace Network { +namespace Dns { + +class ResponseCode +{ +public: + enum type + { + NO_ERROR = 0, + FORMAT_ERROR = 1, + SERVER_FAILURE = 2, + NAME_ERROR = 3, + NOT_IMPLEMENTED = 4, + REFUSED = 5 + }; +}; + +} // namespace Dns +} // namespace Network + +#endif // NETWORK_DNS_RESPONSECODE_H diff --git a/include/Dns/Class.h b/include/Dns/Class.h index b73942a..4ae8769 100644 --- a/include/Dns/Class.h +++ b/include/Dns/Class.h @@ -1,24 +1,24 @@ -#ifndef CLASS_H -#define CLASS_H - - -namespace Network { -namespace Dns { - -class Class -{ -public: - enum type - { - NONE = 0, - IN = 1, - CS = 2, - CH = 3, - HS = 4 - }; -}; - -} // namespace Dns -} // namespace Network - -#endif // CLASS_H +#ifndef CLASS_H +#define CLASS_H + + +namespace Network { +namespace Dns { + +class Class +{ +public: + enum type + { + NONE = 0, + IN = 1, + CS = 2, + CH = 3, + HS = 4 + }; +}; + +} // namespace Dns +} // namespace Network + +#endif // CLASS_H diff --git a/include/Dns/Name.h b/include/Dns/Name.h index 8ca5ae3..a39c5da 100644 --- a/include/Dns/Name.h +++ b/include/Dns/Name.h @@ -1,73 +1,73 @@ -#ifndef NAME_H -#define NAME_H - -#include -#include -#include -#include - - -namespace Network { -namespace Dns { - -class NameImpl; - -class Name -{ -public: - Name(); - - template - Name(const Args& ...args) : - Name(toStringVector(args...)) - { - } - - Name(const std::vector& labels); - - std::string GetFirstLabel() const; - std::string GetName() const; - bool empty() const; - bool endsWith(const Name& suffix) const; - - void append(const std::string& label); - void prepend(const std::string& label); - - void swap(Name& x) noexcept; - - bool operator==(const Name& name) const; - bool operator!=(const Name& name) const; - bool operator<(const Name& name) const; - -private: - Name(std::shared_ptr pNameImpl); - NameImpl* PImpl() const; - -private: - template - std::string toString(T&& t) - { - std::stringstream s; - s << std::forward(t); - return s.str(); - } - - template - std::vector toStringVector(T&&... args) - { - std::vector res { toString(std::forward(args))... }; - return res; - } - -private: - friend class Query; - friend class ResourceRecord; - -private: - std::shared_ptr m_pNameImpl; -}; - -} // namespace Dns -} // namespace Network - -#endif // NAME_H +#ifndef NAME_H +#define NAME_H + +#include +#include +#include +#include + + +namespace Network { +namespace Dns { + +class NameImpl; + +class Name +{ +public: + Name(); + + template + Name(const Args& ...args) : + Name(toStringVector(args...)) + { + } + + Name(const std::vector& labels); + + std::string GetFirstLabel() const; + std::string GetName() const; + bool empty() const; + bool endsWith(const Name& suffix) const; + + void append(const std::string& label); + void prepend(const std::string& label); + + void swap(Name& x) noexcept; + + bool operator==(const Name& name) const; + bool operator!=(const Name& name) const; + bool operator<(const Name& name) const; + +private: + Name(std::shared_ptr pNameImpl); + NameImpl* PImpl() const; + +private: + template + std::string toString(T&& t) + { + std::stringstream s; + s << std::forward(t); + return s.str(); + } + + template + std::vector toStringVector(T&&... args) + { + std::vector res { toString(std::forward(args))... }; + return res; + } + +private: + friend class Query; + friend class ResourceRecord; + +private: + std::shared_ptr m_pNameImpl; +}; + +} // namespace Dns +} // namespace Network + +#endif // NAME_H diff --git a/include/Dns/Query.h b/include/Dns/Query.h index d99ed54..1df0763 100644 --- a/include/Dns/Query.h +++ b/include/Dns/Query.h @@ -1,43 +1,43 @@ -#ifndef QUERY_H -#define QUERY_H - -#include "Name.h" -#include "QueryClass.h" -#include "QueryType.h" -#include - - -namespace Network { -namespace Dns { - -class QueryImpl; - -class Query -{ -public: - Query(); - - bool GetUnicast() const; - QueryType::type GetType() const; - QueryClass::type GetClass() const; - Name GetName() const; - - void SetUnicast(bool unicast); - void SetType(QueryType::type type); - void SetClass(QueryClass::type class_); - void SetName(const Name& name); - -private: - QueryImpl* PImpl() const; - -private: - friend class MulticastDnsClient; - -private: - std::shared_ptr m_pQueryImpl; -}; - -} // namespace Dns -} // namespace Network - -#endif // QUERY_H +#ifndef QUERY_H +#define QUERY_H + +#include "Name.h" +#include "QueryClass.h" +#include "QueryType.h" +#include + + +namespace Network { +namespace Dns { + +class QueryImpl; + +class Query +{ +public: + Query(); + + bool GetUnicast() const; + QueryType::type GetType() const; + QueryClass::type GetClass() const; + Name GetName() const; + + void SetUnicast(bool unicast); + void SetType(QueryType::type type); + void SetClass(QueryClass::type class_); + void SetName(const Name& name); + +private: + QueryImpl* PImpl() const; + +private: + friend class MulticastDnsClient; + +private: + std::shared_ptr m_pQueryImpl; +}; + +} // namespace Dns +} // namespace Network + +#endif // QUERY_H diff --git a/include/Dns/QueryClass.h b/include/Dns/QueryClass.h index 02aaefd..c496b40 100644 --- a/include/Dns/QueryClass.h +++ b/include/Dns/QueryClass.h @@ -1,25 +1,25 @@ -#ifndef QUERYCLASS_H -#define QUERYCLASS_H - - -namespace Network { -namespace Dns { - -class QueryClass -{ -public: - enum type - { - NONE = 0, - IN = 1, - CS = 2, - CH = 3, - HS = 4, - ANY = 255 - }; -}; - -} // namespace Dns -} // namespace Network - -#endif // QUERYCLASS_H +#ifndef QUERYCLASS_H +#define QUERYCLASS_H + + +namespace Network { +namespace Dns { + +class QueryClass +{ +public: + enum type + { + NONE = 0, + IN = 1, + CS = 2, + CH = 3, + HS = 4, + ANY = 255 + }; +}; + +} // namespace Dns +} // namespace Network + +#endif // QUERYCLASS_H diff --git a/include/Dns/QueryType.h b/include/Dns/QueryType.h index 91f3a96..0ef0696 100644 --- a/include/Dns/QueryType.h +++ b/include/Dns/QueryType.h @@ -1,40 +1,40 @@ -#ifndef QUERYTYPE_H -#define QUERYTYPE_H - - -namespace Network { -namespace Dns { - -class QueryType -{ -public: - enum type - { - NONE = 0, - A = 1, - NC = 2, - MD = 3, - MF = 4, - CNAME = 5, - SOA = 6, - MB = 7, - MG = 8, - MR = 9, - NULL_ = 10, - WKS = 11, - PTR = 12, - HINFO = 13, - MINFO = 14, - MX = 15, - TXT = 16, - AXFR = 252, - MAILB = 253, - MAILA = 254, - ANY = 255 - }; -}; - -} // namespace Dns -} // namespace Network - -#endif // QUERYTYPE_H +#ifndef QUERYTYPE_H +#define QUERYTYPE_H + + +namespace Network { +namespace Dns { + +class QueryType +{ +public: + enum type + { + NONE = 0, + A = 1, + NC = 2, + MD = 3, + MF = 4, + CNAME = 5, + SOA = 6, + MB = 7, + MG = 8, + MR = 9, + NULL_ = 10, + WKS = 11, + PTR = 12, + HINFO = 13, + MINFO = 14, + MX = 15, + TXT = 16, + AXFR = 252, + MAILB = 253, + MAILA = 254, + ANY = 255 + }; +}; + +} // namespace Dns +} // namespace Network + +#endif // QUERYTYPE_H diff --git a/include/Dns/ResourceRecord.h b/include/Dns/ResourceRecord.h index c07a1a4..8570162 100644 --- a/include/Dns/ResourceRecord.h +++ b/include/Dns/ResourceRecord.h @@ -1,44 +1,44 @@ -#ifndef RESOURCERECORD_H -#define RESOURCERECORD_H - -#include "Class.h" -#include "Name.h" -#include "Type.h" -#include - - -namespace Network { -namespace Dns { - -class ResourceRecordImpl; - -class ResourceRecord -{ -public: - Name GetName() const; - Type::type GetType() const; - Class::type GetClass() const; - uint32_t GetTTL() const; - - std::vector GetResourceData() const; - std::vector GetData() const; - - void SetName(const Name& name); - void SetType(Type::type type); - void SetClass(Class::type class_); - void SetTTL(uint32_t ttl); - -private: - ResourceRecord(std::shared_ptr pResourceRecordImpl); - -private: - friend class MulticastDnsClient; - -private: - std::shared_ptr m_pResourceRecordImpl; -}; - -} // namespace Dns -} // namespace Network - -#endif // RESOURCERECORD_H +#ifndef RESOURCERECORD_H +#define RESOURCERECORD_H + +#include "Class.h" +#include "Name.h" +#include "Type.h" +#include + + +namespace Network { +namespace Dns { + +class ResourceRecordImpl; + +class ResourceRecord +{ +public: + Name GetName() const; + Type::type GetType() const; + Class::type GetClass() const; + uint32_t GetTTL() const; + + std::vector GetResourceData() const; + std::vector GetData() const; + + void SetName(const Name& name); + void SetType(Type::type type); + void SetClass(Class::type class_); + void SetTTL(uint32_t ttl); + +private: + ResourceRecord(std::shared_ptr pResourceRecordImpl); + +private: + friend class MulticastDnsClient; + +private: + std::shared_ptr m_pResourceRecordImpl; +}; + +} // namespace Dns +} // namespace Network + +#endif // RESOURCERECORD_H diff --git a/include/Dns/Type.h b/include/Dns/Type.h index 971843b..61f192c 100644 --- a/include/Dns/Type.h +++ b/include/Dns/Type.h @@ -1,36 +1,36 @@ -#ifndef TYPE_H -#define TYPE_H - - -namespace Network { -namespace Dns { - -class Type -{ -public: - enum type - { - NONE = 0, - A = 1, - NC = 2, - MD = 3, - MF = 4, - CNAME = 5, - SOA = 6, - MB = 7, - MG = 8, - MR = 9, - NULL_ = 10, - WKS = 11, - PTR = 12, - HINFO = 13, - MINFO = 14, - MX = 15, - TXT = 16 - }; -}; - -} // namespace Dns -} // namespace Network - -#endif // TYPE_H +#ifndef TYPE_H +#define TYPE_H + + +namespace Network { +namespace Dns { + +class Type +{ +public: + enum type + { + NONE = 0, + A = 1, + NC = 2, + MD = 3, + MF = 4, + CNAME = 5, + SOA = 6, + MB = 7, + MG = 8, + MR = 9, + NULL_ = 10, + WKS = 11, + PTR = 12, + HINFO = 13, + MINFO = 14, + MX = 15, + TXT = 16 + }; +}; + +} // namespace Dns +} // namespace Network + +#endif // TYPE_H