Fix Line Endings

This commit is contained in:
2020-06-10 11:48:41 +02:00
parent 56a1e5bb7a
commit ea92eb7b2b
16 changed files with 786 additions and 786 deletions
+32 -32
View File
@@ -1,32 +1,32 @@
#include "Dns/MulticastDnsClient.h" #include "Dns/MulticastDnsClient.h"
#include "MulticastDnsClientImpl.h" #include "MulticastDnsClientImpl.h"
namespace Network { namespace Network {
namespace Dns { namespace Dns {
MulticastDnsClient::MulticastDnsClient(std::function<void(const std::vector<ResourceRecord>&)> callback) : MulticastDnsClient::MulticastDnsClient(std::function<void(const std::vector<ResourceRecord>&)> callback) :
m_pMulticastDnsClientImpl(new MulticastDnsClientImpl(std::bind(&MulticastDnsClient::Callback, this, std::placeholders::_1))), m_pMulticastDnsClientImpl(new MulticastDnsClientImpl(std::bind(&MulticastDnsClient::Callback, this, std::placeholders::_1))),
m_callback(callback) m_callback(callback)
{ {
} }
MulticastDnsClient::~MulticastDnsClient() = default; MulticastDnsClient::~MulticastDnsClient() = default;
void MulticastDnsClient::Query(const Dns::Query& query) void MulticastDnsClient::Query(const Dns::Query& query)
{ {
m_pMulticastDnsClientImpl->Query(*query.PImpl()); m_pMulticastDnsClientImpl->Query(*query.PImpl());
} }
void MulticastDnsClient::Callback(const std::vector<ResourceRecordImpl>& answers) void MulticastDnsClient::Callback(const std::vector<ResourceRecordImpl>& answers)
{ {
std::vector<ResourceRecord> ans; std::vector<ResourceRecord> ans;
for (auto& answer : answers) for (auto& answer : answers)
ans.push_back(ResourceRecord(std::make_shared<ResourceRecordImpl>(answer))); ans.push_back(ResourceRecord(std::make_shared<ResourceRecordImpl>(answer)));
m_callback(ans); m_callback(ans);
} }
} // namespace Dns } // namespace Dns
} // namespace Network } // namespace Network
+146 -146
View File
@@ -1,146 +1,146 @@
#include "MulticastDnsClientImpl.h" #include "MulticastDnsClientImpl.h"
#include "MalformedPacket.h" #include "MalformedPacket.h"
#include "Packet.h" #include "Packet.h"
#include <Logging.h> #include <Logging.h>
namespace Network { namespace Network {
namespace Dns { namespace Dns {
MulticastDnsClientImpl::MulticastDnsClientImpl(std::function<void(const std::vector<ResourceRecordImpl>&)> callback) : MulticastDnsClientImpl::MulticastDnsClientImpl(std::function<void(const std::vector<ResourceRecordImpl>&)> callback) :
m_timer(m_ioService), m_timer(m_ioService),
m_responseBuffer(1024), m_responseBuffer(1024),
m_socket(m_ioService, asio::ip::udp::v4()), m_socket(m_ioService, asio::ip::udp::v4()),
m_multicastEndpoint(asio::ip::address::from_string("224.0.0.251"), 5353), m_multicastEndpoint(asio::ip::address::from_string("224.0.0.251"), 5353),
m_callback(callback) m_callback(callback)
{ {
m_socket.set_option(asio::socket_base::reuse_address(true)); 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::join_group(m_multicastEndpoint.address()));
m_socket.set_option(asio::ip::multicast::hops(255)); m_socket.set_option(asio::ip::multicast::hops(255));
m_socket.bind(asio::ip::udp::endpoint(asio::ip::udp::v4(), 5353)); m_socket.bind(asio::ip::udp::endpoint(asio::ip::udp::v4(), 5353));
m_thread = std::thread([&] { m_ioService.run(); }); m_thread = std::thread([&] { m_ioService.run(); });
} }
MulticastDnsClientImpl::~MulticastDnsClientImpl() MulticastDnsClientImpl::~MulticastDnsClientImpl()
{ {
m_ioService.stop(); m_ioService.stop();
m_thread.join(); m_thread.join();
} }
void MulticastDnsClientImpl::Query(const QueryImpl& query) void MulticastDnsClientImpl::Query(const QueryImpl& query)
{ {
m_query = query; m_query = query;
m_iterations = 3; m_iterations = 3;
SendQuery(); SendQuery();
} }
void MulticastDnsClientImpl::SetTimer(int milliseconds) void MulticastDnsClientImpl::SetTimer(int milliseconds)
{ {
m_timer.cancel(); m_timer.cancel();
m_timer.expires_from_now(std::chrono::milliseconds(milliseconds)); m_timer.expires_from_now(std::chrono::milliseconds(milliseconds));
} }
void MulticastDnsClientImpl::SendQuery() void MulticastDnsClientImpl::SendQuery()
{ {
if (m_iterations == 0) if (m_iterations == 0)
return; return;
m_iterations--; m_iterations--;
Packet packet; Packet packet;
packet.AddQuery(m_query); packet.AddQuery(m_query);
auto data = std::make_shared<Data>(packet.GetData()); auto data = std::make_shared<Data>(packet.GetData());
m_socket.async_send_to( m_socket.async_send_to(
asio::buffer(data->GetPtr(), data->GetLength()), asio::buffer(data->GetPtr(), data->GetLength()),
m_multicastEndpoint, m_multicastEndpoint,
std::bind(&MulticastDnsClientImpl::HandleQuerySent, this, std::bind(&MulticastDnsClientImpl::HandleQuerySent, this,
std::placeholders::_1, std::placeholders::_1,
data data
) )
); );
} }
void MulticastDnsClientImpl::HandleQuerySent(const asio::error_code & error, std::shared_ptr<Data> data) void MulticastDnsClientImpl::HandleQuerySent(const asio::error_code & error, std::shared_ptr<Data> data)
{ {
if (error == asio::error::operation_aborted) if (error == asio::error::operation_aborted)
{ {
SendQuery(); SendQuery();
} }
else if (error) else if (error)
{ {
std::stringstream ss; std::stringstream ss;
ss << "MulticastDnsClientImpl::HandleQuerySent: " << error.message(); ss << "MulticastDnsClientImpl::HandleQuerySent: " << error.message();
Logging::Log(Logging::Severity::Error, ss.str()); Logging::Log(Logging::Severity::Error, ss.str());
} }
else else
{ {
SetTimer(1000); SetTimer(1000);
m_timer.async_wait(std::bind( m_timer.async_wait(std::bind(
&MulticastDnsClientImpl::HandleQueryTimeout, this, &MulticastDnsClientImpl::HandleQueryTimeout, this,
std::placeholders::_1 std::placeholders::_1
)); ));
ReceiveQuery(); ReceiveQuery();
} }
} }
void MulticastDnsClientImpl::ReceiveQuery() void MulticastDnsClientImpl::ReceiveQuery()
{ {
m_socket.async_receive_from( m_socket.async_receive_from(
asio::buffer(m_responseBuffer), asio::buffer(m_responseBuffer),
m_receiveEndpoint, m_receiveEndpoint,
std::bind(&MulticastDnsClientImpl::HandleQueryResponse, this, std::bind(&MulticastDnsClientImpl::HandleQueryResponse, this,
std::placeholders::_1, std::placeholders::_1,
std::placeholders::_2 std::placeholders::_2
) )
); );
} }
void MulticastDnsClientImpl::HandleQueryResponse(const asio::error_code & error, std::size_t size) void MulticastDnsClientImpl::HandleQueryResponse(const asio::error_code & error, std::size_t size)
{ {
if (error == asio::error::operation_aborted) if (error == asio::error::operation_aborted)
{ {
SendQuery(); SendQuery();
} }
else if (error) else if (error)
{ {
std::stringstream ss; std::stringstream ss;
ss << "MulticastDnsClientImpl::HandleQueryResponse: " << error.message(); ss << "MulticastDnsClientImpl::HandleQueryResponse: " << error.message();
Logging::Log(Logging::Severity::Error, ss.str()); Logging::Log(Logging::Severity::Error, ss.str());
} }
else else
{ {
try try
{ {
Packet packet(DataReader(m_responseBuffer.data(), size), 0); Packet packet(DataReader(m_responseBuffer.data(), size), 0);
if (packet.GetQuery()) if (packet.GetQuery())
m_callback(packet.GetAnswers()); m_callback(packet.GetAnswers());
} }
catch(MalformedPacket& mp) catch(MalformedPacket& mp)
{ {
} }
ReceiveQuery(); ReceiveQuery();
} }
} }
void MulticastDnsClientImpl::HandleQueryTimeout(const asio::error_code & error) void MulticastDnsClientImpl::HandleQueryTimeout(const asio::error_code & error)
{ {
if (error == asio::error::operation_aborted) if (error == asio::error::operation_aborted)
{ {
} }
else if (error) else if (error)
{ {
std::stringstream ss; std::stringstream ss;
ss << "MulticastDnsClientImpl::HandleQueryTimeout: " << error.message(); ss << "MulticastDnsClientImpl::HandleQueryTimeout: " << error.message();
Logging::Log(Logging::Severity::Error, ss.str()); Logging::Log(Logging::Severity::Error, ss.str());
} }
else else
{ {
m_socket.cancel(); m_socket.cancel();
} }
} }
} // namespace Dns } // namespace Dns
} // namespace Network } // namespace Network
+52 -52
View File
@@ -1,52 +1,52 @@
#ifndef NETWORK_DNS_MULTICASTDNSCLIENTIMPL_H #ifndef NETWORK_DNS_MULTICASTDNSCLIENTIMPL_H
#define NETWORK_DNS_MULTICASTDNSCLIENTIMPL_H #define NETWORK_DNS_MULTICASTDNSCLIENTIMPL_H
#include "QueryImpl.h" #include "QueryImpl.h"
#include "ResourceRecordImpl.h" #include "ResourceRecordImpl.h"
#include <asio.hpp> #include <asio.hpp>
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
namespace Network { namespace Network {
namespace Dns { namespace Dns {
class MulticastDnsClientImpl class MulticastDnsClientImpl
{ {
public: public:
MulticastDnsClientImpl(std::function<void(const std::vector<ResourceRecordImpl>&)> callback); MulticastDnsClientImpl(std::function<void(const std::vector<ResourceRecordImpl>&)> callback);
~MulticastDnsClientImpl(); ~MulticastDnsClientImpl();
public: public:
void Query(const QueryImpl& query); void Query(const QueryImpl& query);
private: private:
void SetTimer(int milliseconds); void SetTimer(int milliseconds);
void SendQuery(); void SendQuery();
void HandleQuerySent(const asio::error_code & error, std::shared_ptr<Data> data); void HandleQuerySent(const asio::error_code & error, std::shared_ptr<Data> data);
void ReceiveQuery(); void ReceiveQuery();
void HandleQueryResponse(const asio::error_code & error, std::size_t size); void HandleQueryResponse(const asio::error_code & error, std::size_t size);
void HandleQueryTimeout(const asio::error_code & error); void HandleQueryTimeout(const asio::error_code & error);
private: private:
std::thread m_thread; std::thread m_thread;
asio::io_service m_ioService; asio::io_service m_ioService;
asio::system_timer m_timer; asio::system_timer m_timer;
std::vector<uint8_t> m_responseBuffer; std::vector<uint8_t> m_responseBuffer;
asio::ip::udp::socket m_socket; asio::ip::udp::socket m_socket;
asio::ip::udp::endpoint m_multicastEndpoint; asio::ip::udp::endpoint m_multicastEndpoint;
asio::ip::udp::endpoint m_receiveEndpoint; asio::ip::udp::endpoint m_receiveEndpoint;
int m_iterations; int m_iterations;
QueryImpl m_query; QueryImpl m_query;
std::function<void(const std::vector<ResourceRecordImpl>&)> m_callback; std::function<void(const std::vector<ResourceRecordImpl>&)> m_callback;
}; };
} // namespace Dns } // namespace Dns
} // namespace Network } // namespace Network
#endif // NETWORK_DNS_MULTICASTDNSCLIENTIMPL_H #endif // NETWORK_DNS_MULTICASTDNSCLIENTIMPL_H
+52 -52
View File
@@ -1,52 +1,52 @@
#ifndef NETWORK_DNS_NAMEIMPL_H #ifndef NETWORK_DNS_NAMEIMPL_H
#define NETWORK_DNS_NAMEIMPL_H #define NETWORK_DNS_NAMEIMPL_H
#include "Data.h" #include "Data.h"
#include "DataReader.h" #include "DataReader.h"
#include <string> #include <string>
#include <vector> #include <vector>
namespace Network { namespace Network {
namespace Dns { namespace Dns {
class NameImpl class NameImpl
{ {
public: public:
NameImpl(); NameImpl();
template<typename ...Args> template<typename ...Args>
NameImpl(const std::string& label, const Args& ...args) : NameImpl(args...) NameImpl(const std::string& label, const Args& ...args) : NameImpl(args...)
{ {
m_labels.insert(m_labels.begin(), label); m_labels.insert(m_labels.begin(), label);
} }
NameImpl(const std::vector<std::string>& labels); NameImpl(const std::vector<std::string>& labels);
std::string GetFirstLabel() const; std::string GetFirstLabel() const;
std::string GetName() const; std::string GetName() const;
bool empty() const; bool empty() const;
bool endsWith(const NameImpl& suffix) const; bool endsWith(const NameImpl& suffix) const;
Data GetData() const; Data GetData() const;
void append(const std::string& label); void append(const std::string& label);
void prepend(const std::string& label); void prepend(const std::string& label);
unsigned ReadFromData(DataReader reader, unsigned pos); unsigned ReadFromData(DataReader reader, unsigned pos);
void swap(NameImpl& x) noexcept; void swap(NameImpl& x) noexcept;
bool operator==(const NameImpl& name) const; bool operator==(const NameImpl& name) const;
bool operator!=(const NameImpl& name) const; 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); friend std::ostream& operator<<(std::ostream& stream, const NameImpl& name);
private: private:
std::vector<std::string> m_labels; std::vector<std::string> m_labels;
}; };
} // namespace Dns } // namespace Dns
} // namespace Network } // namespace Network
#endif // NETWORK_DNS_NAMEIMPL_H #endif // NETWORK_DNS_NAMEIMPL_H
+22 -22
View File
@@ -1,22 +1,22 @@
#ifndef NETWORK_DNS_OPERATIONCODE_H #ifndef NETWORK_DNS_OPERATIONCODE_H
#define NETWORK_DNS_OPERATIONCODE_H #define NETWORK_DNS_OPERATIONCODE_H
namespace Network { namespace Network {
namespace Dns { namespace Dns {
class OperationCode class OperationCode
{ {
public: public:
enum type enum type
{ {
QUERY = 0, QUERY = 0,
IQUERY = 1, IQUERY = 1,
STATUS = 2 STATUS = 2
}; };
}; };
} // namespace Dns } // namespace Dns
} // namespace Network } // namespace Network
#endif // NETWORK_DNS_OPERATIONCODE_H #endif // NETWORK_DNS_OPERATIONCODE_H
+79 -79
View File
@@ -1,79 +1,79 @@
#ifndef NETWORK_DNS_PACKET_H #ifndef NETWORK_DNS_PACKET_H
#define NETWORK_DNS_PACKET_H #define NETWORK_DNS_PACKET_H
#include "Data.h" #include "Data.h"
#include "DataReader.h" #include "DataReader.h"
#include "OperationCode.h" #include "OperationCode.h"
#include "QueryImpl.h" #include "QueryImpl.h"
#include "ResourceRecordImpl.h" #include "ResourceRecordImpl.h"
#include "ResponseCode.h" #include "ResponseCode.h"
namespace Network { namespace Network {
namespace Dns { namespace Dns {
class Packet class Packet
{ {
public: public:
Packet(); Packet();
Packet(DataReader reader, unsigned pos); Packet(DataReader reader, unsigned pos);
Data GetData() const; Data GetData() const;
uint16_t GetIdentifier() const; uint16_t GetIdentifier() const;
bool GetQuery() const; bool GetQuery() const;
OperationCode::type GetOperationCode() const; OperationCode::type GetOperationCode() const;
bool GetAuthorativeAnswer() const; bool GetAuthorativeAnswer() const;
bool GetTruncation() const; bool GetTruncation() const;
bool GetRecursionDesired() const; bool GetRecursionDesired() const;
bool GetRecursionAvailable() const; bool GetRecursionAvailable() const;
uint8_t GetZero() const; uint8_t GetZero() const;
ResponseCode::type GetResponseCode() const; ResponseCode::type GetResponseCode() const;
std::vector<QueryImpl> GetQueries() const; std::vector<QueryImpl> GetQueries() const;
std::vector<ResourceRecordImpl> GetAnswers() const; std::vector<ResourceRecordImpl> GetAnswers() const;
std::vector<ResourceRecordImpl> GetAuthorities() const; std::vector<ResourceRecordImpl> GetAuthorities() const;
std::vector<ResourceRecordImpl> GetAdditionalRecords() const; std::vector<ResourceRecordImpl> GetAdditionalRecords() const;
unsigned GetQueryCount() const; unsigned GetQueryCount() const;
unsigned GetAnswerCount() const; unsigned GetAnswerCount() const;
unsigned GetAuthorityCount() const; unsigned GetAuthorityCount() const;
unsigned GetAdditionalRecordsCount() const; unsigned GetAdditionalRecordsCount() const;
void SetIdentifier(uint16_t identifier); void SetIdentifier(uint16_t identifier);
void SetQuery(bool query); void SetQuery(bool query);
void SetOperationCode(OperationCode::type oerationCode); void SetOperationCode(OperationCode::type oerationCode);
void SetAuthorativeAnswer(bool authorativeAnswer); void SetAuthorativeAnswer(bool authorativeAnswer);
void SetTruncation(bool truncation); void SetTruncation(bool truncation);
void SetRecursionDesired(bool recursionDesired); void SetRecursionDesired(bool recursionDesired);
void SetRecursionAvailable(bool recursionAvailable); void SetRecursionAvailable(bool recursionAvailable);
void SetZero(uint8_t zero); void SetZero(uint8_t zero);
void SetResponseCode(ResponseCode::type responseCode); void SetResponseCode(ResponseCode::type responseCode);
void AddQuery(const QueryImpl& query); void AddQuery(const QueryImpl& query);
void AddAnswer(const ResourceRecordImpl& record); void AddAnswer(const ResourceRecordImpl& record);
void AddAuthority(const ResourceRecordImpl& record); void AddAuthority(const ResourceRecordImpl& record);
void AddAdditionalRecords(const ResourceRecordImpl& record); void AddAdditionalRecords(const ResourceRecordImpl& record);
friend std::ostream& operator<<(std::ostream& stream, const Packet& packet); friend std::ostream& operator<<(std::ostream& stream, const Packet& packet);
private: private:
unsigned m_identifier : 16; unsigned m_identifier : 16;
unsigned m_query : 1; unsigned m_query : 1;
unsigned m_authorativeAnswer : 1; unsigned m_authorativeAnswer : 1;
unsigned m_truncation : 1; unsigned m_truncation : 1;
unsigned m_recursionDesired : 1; unsigned m_recursionDesired : 1;
unsigned m_recursionAvailable : 1; unsigned m_recursionAvailable : 1;
unsigned m_zero : 3; unsigned m_zero : 3;
OperationCode::type m_operationCode; OperationCode::type m_operationCode;
ResponseCode::type m_responseCode; ResponseCode::type m_responseCode;
std::vector<QueryImpl> m_queries; std::vector<QueryImpl> m_queries;
std::vector<ResourceRecordImpl> m_answers; std::vector<ResourceRecordImpl> m_answers;
std::vector<ResourceRecordImpl> m_authorities; std::vector<ResourceRecordImpl> m_authorities;
std::vector<ResourceRecordImpl> m_additionalRecords; std::vector<ResourceRecordImpl> m_additionalRecords;
}; };
} // namespace Dns } // namespace Dns
} // namespace Network } // namespace Network
#endif // NETWORK_DNS_PACKET_H #endif // NETWORK_DNS_PACKET_H
+45 -45
View File
@@ -1,45 +1,45 @@
#ifndef NETWORK_DNS_QUERYIMPL_H #ifndef NETWORK_DNS_QUERYIMPL_H
#define NETWORK_DNS_QUERYIMPL_H #define NETWORK_DNS_QUERYIMPL_H
#include "Data.h" #include "Data.h"
#include "DataReader.h" #include "DataReader.h"
#include "NameImpl.h" #include "NameImpl.h"
#include "Dns/QueryClass.h" #include "Dns/QueryClass.h"
#include "Dns/QueryType.h" #include "Dns/QueryType.h"
namespace Network { namespace Network {
namespace Dns { namespace Dns {
class QueryImpl class QueryImpl
{ {
public: public:
QueryImpl(); QueryImpl();
bool GetUnicast() const; bool GetUnicast() const;
QueryType::type GetType() const; QueryType::type GetType() const;
QueryClass::type GetClass() const; QueryClass::type GetClass() const;
NameImpl GetName() const; NameImpl GetName() const;
void SetUnicast(bool unicast); void SetUnicast(bool unicast);
void SetType(QueryType::type type); void SetType(QueryType::type type);
void SetClass(QueryClass::type class_); void SetClass(QueryClass::type class_);
void SetName(const NameImpl& name); void SetName(const NameImpl& name);
Data GetData() const; Data GetData() const;
unsigned ReadFromData(DataReader reader, unsigned pos); unsigned ReadFromData(DataReader reader, unsigned pos);
friend std::ostream& operator<<(std::ostream & stream, const QueryImpl& query); friend std::ostream& operator<<(std::ostream & stream, const QueryImpl& query);
private: private:
bool m_unicast; bool m_unicast;
NameImpl m_name; NameImpl m_name;
QueryType::type m_type; QueryType::type m_type;
QueryClass::type m_class; QueryClass::type m_class;
}; };
} // namespace Dns } // namespace Dns
} // namespace Network } // namespace Network
#endif // NETWORK_DNS_QUERYIMPL_H #endif // NETWORK_DNS_QUERYIMPL_H
+48 -48
View File
@@ -1,48 +1,48 @@
#ifndef NETWORK_DNS_RESOURCERECORD_H #ifndef NETWORK_DNS_RESOURCERECORD_H
#define NETWORK_DNS_RESOURCERECORD_H #define NETWORK_DNS_RESOURCERECORD_H
#include "Data.h" #include "Data.h"
#include "DataReader.h" #include "DataReader.h"
#include "NameImpl.h" #include "NameImpl.h"
#include "Dns/Class.h" #include "Dns/Class.h"
#include "Dns/Type.h" #include "Dns/Type.h"
namespace Network { namespace Network {
namespace Dns { namespace Dns {
class ResourceRecordImpl class ResourceRecordImpl
{ {
public: public:
NameImpl GetName() const; NameImpl GetName() const;
Type::type GetType() const; Type::type GetType() const;
Class::type GetClass() const; Class::type GetClass() const;
uint32_t GetTTL() const; uint32_t GetTTL() const;
Data GetResourceData() const; Data GetResourceData() const;
NameImpl GetResourceDataName() const; NameImpl GetResourceDataName() const;
Data GetData() const; Data GetData() const;
void SetName(const NameImpl& name); void SetName(const NameImpl& name);
void SetType(Type::type type); void SetType(Type::type type);
void SetClass(Class::type dnsClass); void SetClass(Class::type dnsClass);
void SetTTL(uint32_t ttl); void SetTTL(uint32_t ttl);
void SetData(const Data& resourceData); void SetData(const Data& resourceData);
unsigned ReadFromData(DataReader reader, unsigned pos); unsigned ReadFromData(DataReader reader, unsigned pos);
friend std::ostream& operator<<(std::ostream& stream, const ResourceRecordImpl& record); friend std::ostream& operator<<(std::ostream& stream, const ResourceRecordImpl& record);
private: private:
NameImpl m_name; NameImpl m_name;
Type::type m_type; Type::type m_type;
Class::type m_class; Class::type m_class;
uint32_t m_ttl; uint32_t m_ttl;
Data m_resourceData; Data m_resourceData;
NameImpl m_resourceDataName; NameImpl m_resourceDataName;
}; };
} // namespace Dns } // namespace Dns
} // namespace Network } // namespace Network
#endif // NETWORK_DNS_RESOURCERECORD_H #endif // NETWORK_DNS_RESOURCERECORD_H
+25 -25
View File
@@ -1,25 +1,25 @@
#ifndef NETWORK_DNS_RESPONSECODE_H #ifndef NETWORK_DNS_RESPONSECODE_H
#define NETWORK_DNS_RESPONSECODE_H #define NETWORK_DNS_RESPONSECODE_H
namespace Network { namespace Network {
namespace Dns { namespace Dns {
class ResponseCode class ResponseCode
{ {
public: public:
enum type enum type
{ {
NO_ERROR = 0, NO_ERROR = 0,
FORMAT_ERROR = 1, FORMAT_ERROR = 1,
SERVER_FAILURE = 2, SERVER_FAILURE = 2,
NAME_ERROR = 3, NAME_ERROR = 3,
NOT_IMPLEMENTED = 4, NOT_IMPLEMENTED = 4,
REFUSED = 5 REFUSED = 5
}; };
}; };
} // namespace Dns } // namespace Dns
} // namespace Network } // namespace Network
#endif // NETWORK_DNS_RESPONSECODE_H #endif // NETWORK_DNS_RESPONSECODE_H
+24 -24
View File
@@ -1,24 +1,24 @@
#ifndef CLASS_H #ifndef CLASS_H
#define CLASS_H #define CLASS_H
namespace Network { namespace Network {
namespace Dns { namespace Dns {
class Class class Class
{ {
public: public:
enum type enum type
{ {
NONE = 0, NONE = 0,
IN = 1, IN = 1,
CS = 2, CS = 2,
CH = 3, CH = 3,
HS = 4 HS = 4
}; };
}; };
} // namespace Dns } // namespace Dns
} // namespace Network } // namespace Network
#endif // CLASS_H #endif // CLASS_H
+73 -73
View File
@@ -1,73 +1,73 @@
#ifndef NAME_H #ifndef NAME_H
#define NAME_H #define NAME_H
#include <memory> #include <memory>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
namespace Network { namespace Network {
namespace Dns { namespace Dns {
class NameImpl; class NameImpl;
class Name class Name
{ {
public: public:
Name(); Name();
template<typename ...Args> template<typename ...Args>
Name(const Args& ...args) : Name(const Args& ...args) :
Name(toStringVector(args...)) Name(toStringVector(args...))
{ {
} }
Name(const std::vector<std::string>& labels); Name(const std::vector<std::string>& labels);
std::string GetFirstLabel() const; std::string GetFirstLabel() const;
std::string GetName() const; std::string GetName() const;
bool empty() const; bool empty() const;
bool endsWith(const Name& suffix) const; bool endsWith(const Name& suffix) const;
void append(const std::string& label); void append(const std::string& label);
void prepend(const std::string& label); void prepend(const std::string& label);
void swap(Name& x) noexcept; void swap(Name& x) noexcept;
bool operator==(const Name& name) const; bool operator==(const Name& name) const;
bool operator!=(const Name& name) const; bool operator!=(const Name& name) const;
bool operator<(const Name& name) const; bool operator<(const Name& name) const;
private: private:
Name(std::shared_ptr<NameImpl> pNameImpl); Name(std::shared_ptr<NameImpl> pNameImpl);
NameImpl* PImpl() const; NameImpl* PImpl() const;
private: private:
template <class T> template <class T>
std::string toString(T&& t) std::string toString(T&& t)
{ {
std::stringstream s; std::stringstream s;
s << std::forward<T>(t); s << std::forward<T>(t);
return s.str(); return s.str();
} }
template <class... T> template <class... T>
std::vector<std::string> toStringVector(T&&... args) std::vector<std::string> toStringVector(T&&... args)
{ {
std::vector<std::string> res { toString(std::forward<T>(args))... }; std::vector<std::string> res { toString(std::forward<T>(args))... };
return res; return res;
} }
private: private:
friend class Query; friend class Query;
friend class ResourceRecord; friend class ResourceRecord;
private: private:
std::shared_ptr<NameImpl> m_pNameImpl; std::shared_ptr<NameImpl> m_pNameImpl;
}; };
} // namespace Dns } // namespace Dns
} // namespace Network } // namespace Network
#endif // NAME_H #endif // NAME_H
+43 -43
View File
@@ -1,43 +1,43 @@
#ifndef QUERY_H #ifndef QUERY_H
#define QUERY_H #define QUERY_H
#include "Name.h" #include "Name.h"
#include "QueryClass.h" #include "QueryClass.h"
#include "QueryType.h" #include "QueryType.h"
#include <memory> #include <memory>
namespace Network { namespace Network {
namespace Dns { namespace Dns {
class QueryImpl; class QueryImpl;
class Query class Query
{ {
public: public:
Query(); Query();
bool GetUnicast() const; bool GetUnicast() const;
QueryType::type GetType() const; QueryType::type GetType() const;
QueryClass::type GetClass() const; QueryClass::type GetClass() const;
Name GetName() const; Name GetName() const;
void SetUnicast(bool unicast); void SetUnicast(bool unicast);
void SetType(QueryType::type type); void SetType(QueryType::type type);
void SetClass(QueryClass::type class_); void SetClass(QueryClass::type class_);
void SetName(const Name& name); void SetName(const Name& name);
private: private:
QueryImpl* PImpl() const; QueryImpl* PImpl() const;
private: private:
friend class MulticastDnsClient; friend class MulticastDnsClient;
private: private:
std::shared_ptr<QueryImpl> m_pQueryImpl; std::shared_ptr<QueryImpl> m_pQueryImpl;
}; };
} // namespace Dns } // namespace Dns
} // namespace Network } // namespace Network
#endif // QUERY_H #endif // QUERY_H
+25 -25
View File
@@ -1,25 +1,25 @@
#ifndef QUERYCLASS_H #ifndef QUERYCLASS_H
#define QUERYCLASS_H #define QUERYCLASS_H
namespace Network { namespace Network {
namespace Dns { namespace Dns {
class QueryClass class QueryClass
{ {
public: public:
enum type enum type
{ {
NONE = 0, NONE = 0,
IN = 1, IN = 1,
CS = 2, CS = 2,
CH = 3, CH = 3,
HS = 4, HS = 4,
ANY = 255 ANY = 255
}; };
}; };
} // namespace Dns } // namespace Dns
} // namespace Network } // namespace Network
#endif // QUERYCLASS_H #endif // QUERYCLASS_H
+40 -40
View File
@@ -1,40 +1,40 @@
#ifndef QUERYTYPE_H #ifndef QUERYTYPE_H
#define QUERYTYPE_H #define QUERYTYPE_H
namespace Network { namespace Network {
namespace Dns { namespace Dns {
class QueryType class QueryType
{ {
public: public:
enum type enum type
{ {
NONE = 0, NONE = 0,
A = 1, A = 1,
NC = 2, NC = 2,
MD = 3, MD = 3,
MF = 4, MF = 4,
CNAME = 5, CNAME = 5,
SOA = 6, SOA = 6,
MB = 7, MB = 7,
MG = 8, MG = 8,
MR = 9, MR = 9,
NULL_ = 10, NULL_ = 10,
WKS = 11, WKS = 11,
PTR = 12, PTR = 12,
HINFO = 13, HINFO = 13,
MINFO = 14, MINFO = 14,
MX = 15, MX = 15,
TXT = 16, TXT = 16,
AXFR = 252, AXFR = 252,
MAILB = 253, MAILB = 253,
MAILA = 254, MAILA = 254,
ANY = 255 ANY = 255
}; };
}; };
} // namespace Dns } // namespace Dns
} // namespace Network } // namespace Network
#endif // QUERYTYPE_H #endif // QUERYTYPE_H
+44 -44
View File
@@ -1,44 +1,44 @@
#ifndef RESOURCERECORD_H #ifndef RESOURCERECORD_H
#define RESOURCERECORD_H #define RESOURCERECORD_H
#include "Class.h" #include "Class.h"
#include "Name.h" #include "Name.h"
#include "Type.h" #include "Type.h"
#include <memory> #include <memory>
namespace Network { namespace Network {
namespace Dns { namespace Dns {
class ResourceRecordImpl; class ResourceRecordImpl;
class ResourceRecord class ResourceRecord
{ {
public: public:
Name GetName() const; Name GetName() const;
Type::type GetType() const; Type::type GetType() const;
Class::type GetClass() const; Class::type GetClass() const;
uint32_t GetTTL() const; uint32_t GetTTL() const;
std::vector<uint8_t> GetResourceData() const; std::vector<uint8_t> GetResourceData() const;
std::vector<uint8_t> GetData() const; std::vector<uint8_t> GetData() const;
void SetName(const Name& name); void SetName(const Name& name);
void SetType(Type::type type); void SetType(Type::type type);
void SetClass(Class::type class_); void SetClass(Class::type class_);
void SetTTL(uint32_t ttl); void SetTTL(uint32_t ttl);
private: private:
ResourceRecord(std::shared_ptr<ResourceRecordImpl> pResourceRecordImpl); ResourceRecord(std::shared_ptr<ResourceRecordImpl> pResourceRecordImpl);
private: private:
friend class MulticastDnsClient; friend class MulticastDnsClient;
private: private:
std::shared_ptr<ResourceRecordImpl> m_pResourceRecordImpl; std::shared_ptr<ResourceRecordImpl> m_pResourceRecordImpl;
}; };
} // namespace Dns } // namespace Dns
} // namespace Network } // namespace Network
#endif // RESOURCERECORD_H #endif // RESOURCERECORD_H
+36 -36
View File
@@ -1,36 +1,36 @@
#ifndef TYPE_H #ifndef TYPE_H
#define TYPE_H #define TYPE_H
namespace Network { namespace Network {
namespace Dns { namespace Dns {
class Type class Type
{ {
public: public:
enum type enum type
{ {
NONE = 0, NONE = 0,
A = 1, A = 1,
NC = 2, NC = 2,
MD = 3, MD = 3,
MF = 4, MF = 4,
CNAME = 5, CNAME = 5,
SOA = 6, SOA = 6,
MB = 7, MB = 7,
MG = 8, MG = 8,
MR = 9, MR = 9,
NULL_ = 10, NULL_ = 10,
WKS = 11, WKS = 11,
PTR = 12, PTR = 12,
HINFO = 13, HINFO = 13,
MINFO = 14, MINFO = 14,
MX = 15, MX = 15,
TXT = 16 TXT = 16
}; };
}; };
} // namespace Dns } // namespace Dns
} // namespace Network } // namespace Network
#endif // TYPE_H #endif // TYPE_H