Async 1.8.0
AsyncResourceRecord.h
Go to the documentation of this file.
1
31#ifndef ASYNC_DNS_RESOURCE_RECORD_INCLUDED
32#define ASYNC_DNS_RESOURCE_RECORD_INCLUDED
33
34
35/****************************************************************************
36 *
37 * System Includes
38 *
39 ****************************************************************************/
40
41#include <string>
42#include <sstream>
43#include <map>
44
45
46/****************************************************************************
47 *
48 * Project Includes
49 *
50 ****************************************************************************/
51
52#include <AsyncIpAddress.h>
53
54
55/****************************************************************************
56 *
57 * Local Includes
58 *
59 ****************************************************************************/
60
61
62
63/****************************************************************************
64 *
65 * Forward declarations
66 *
67 ****************************************************************************/
68
69
70
71/****************************************************************************
72 *
73 * Namespace
74 *
75 ****************************************************************************/
76
77namespace Async
78{
79
80
81/****************************************************************************
82 *
83 * Forward declarations of classes inside of the declared namespace
84 *
85 ****************************************************************************/
86
87
88
89/****************************************************************************
90 *
91 * Defines & typedefs
92 *
93 ****************************************************************************/
94
95
96
97/****************************************************************************
98 *
99 * Exported Global Variables
100 *
101 ****************************************************************************/
102
103
104
105/****************************************************************************
106 *
107 * Class definitions
108 *
109 ****************************************************************************/
110
121{
122 public:
123 enum class Type { A, PTR, CNAME, SRV };
124 enum class Class { IN };
125
126 static const std::string& typeToString(Type type)
127 {
128 static const std::map<Type, std::string> type_map = {
129 {Type::A, "A"}, {Type::PTR, "PTR"}, {Type::CNAME, "CNAME"},
130 {Type::SRV, "SRV"}
131 };
132 static const std::string UNKNOWN = "?";
133 const auto& it = type_map.find(type);
134 if (it == type_map.end())
135 {
136 return UNKNOWN;
137 }
138 return it->second;
139 }
140
144 DnsResourceRecord(const std::string& name, uint32_t ttl)
145 : m_name(name), m_ttl(ttl) {}
146
151
156
160 virtual ~DnsResourceRecord(void) {}
161
167 Class classId(void) const { return Class::IN; }
168 const char* classStr(void) const { return "IN"; }
169
170 virtual const Type type(void) const = 0;
171 const std::string& typeStr(void) const
172 {
173 return typeToString(type());
174 }
175
176 virtual std::string toString(void) const
177 {
178 std::ostringstream os;
179 os << name() << "\t" << ttl() << "\t" << classStr() << "\t"
180 << typeStr() << "\t";
181 return os.str();
182 }
183
184 void setName(const std::string& name) { m_name = name; }
185 const std::string& name(void) const { return m_name; }
186
187 void setTtl(uint32_t ttl) { m_ttl = ttl; }
188 uint32_t ttl(void) const { return m_ttl; }
189
190 private:
191 std::string m_name;
192 uint32_t m_ttl;
193
194}; /* class DnsResourceRecord */
195
196
198{
199 public:
200 static const Type staticType(void) { return Type::A; }
201
202 DnsResourceRecordA(const std::string& name, uint32_t ttl,
203 const IpAddress& ip=IpAddress())
204 : DnsResourceRecord(name, ttl), m_ip(ip) {}
206
207 virtual const Type type(void) const { return staticType(); }
208 virtual std::string toString(void) const
209 {
210 std::ostringstream os;
211 os << DnsResourceRecord::toString() << ip();
212 return os.str();
213 }
214
215 void setIp(const IpAddress& ip) { m_ip = ip; }
216 const IpAddress& ip(void) const { return m_ip; }
217
218 private:
219 IpAddress m_ip;
220};
221
222
224{
225 public:
226 static const Type staticType(void) { return Type::PTR; }
227
228 DnsResourceRecordPTR(const std::string& name, uint32_t ttl,
229 const std::string& dname="")
230 : DnsResourceRecord(name, ttl), m_dname(dname) {}
232
233 virtual const Type type(void) const { return staticType(); }
234 virtual std::string toString(void) const
235 {
236 std::ostringstream os;
238 return os.str();
239 }
240
241 void setName(const std::string& dname) { m_dname = dname; }
242 const std::string& dname(void) const { return m_dname; }
243
244 private:
245 std::string m_dname;
246};
247
248
250{
251 public:
252 static const Type staticType(void) { return Type::CNAME; }
253
254 DnsResourceRecordCNAME(const std::string& name, uint32_t ttl,
255 const std::string& cname="")
256 : DnsResourceRecord(name, ttl), m_cname(cname) {}
258
259 virtual const Type type(void) const { return staticType(); }
260 virtual std::string toString(void) const
261 {
262 std::ostringstream os;
264 return os.str();
265 }
266
267 void setName(const std::string& cname) { m_cname = cname; }
268 const std::string& cname(void) const { return m_cname; }
269
270 private:
271 std::string m_cname;
272};
273
274
276{
277 public:
278 static const Type staticType(void) { return Type::SRV; }
279
280 DnsResourceRecordSRV(const std::string& name, uint32_t ttl,
281 unsigned int prio, unsigned int weight,
282 unsigned int port, const std::string& target)
283 : DnsResourceRecord(name, ttl), m_prio(prio), m_weight(weight),
284 m_port(port), m_target(target) {}
286
287 virtual const Type type(void) const { return staticType(); }
288 virtual std::string toString(void) const
289 {
290 std::ostringstream os;
291 os << DnsResourceRecord::toString() << prio() << " " << weight()
292 << " " << port() << " " << target();
293 return os.str();
294 }
295
296 void setPrio(unsigned int prio) { m_prio = prio; }
297 unsigned int prio(void) const { return m_prio; }
298
299 void setWeight(unsigned int weight) { m_weight = weight; }
300 unsigned int weight(void) const { return m_weight; }
301
302 void setPort(unsigned int port) { m_port = port; }
303 unsigned int port(void) const { return m_port; }
304
305 void setTarget(const std::string& target) { m_target = target; }
306 const std::string& target(void) const { return m_target; }
307
308 private:
309 unsigned int m_prio;
310 unsigned int m_weight;
311 unsigned int m_port;
312 std::string m_target;
313};
314
315
316} /* namespace Async */
317
318#endif /* ASYNC_DNS_RESOURCE_RECORD_INCLUDED */
319
320/*
321 * This file has not been truncated
322 */
Platform independent representation of an IP address.
A class for representing an A DNS resource record.
static const Type staticType(void)
const Ip & ip(void) const
The IP address for this record.
const IpAddress & ip(void) const
DnsResourceRecordA(const std::string &name, uint32_t ttl, const IpAddress &ip=IpAddress())
virtual std::string toString(void) const
The string representation of this record.
void setIp(const IpAddress &ip)
virtual const Type type(void) const
The type of record.
A class for representing a CNAME DNS resource record.
const CName & cname(void) const
The FQDN for this record.
static const Type staticType(void)
virtual std::string toString(void) const
The string representation of this record.
void setName(const std::string &cname)
const std::string & cname(void) const
DnsResourceRecordCNAME(const std::string &name, uint32_t ttl, const std::string &cname="")
virtual const Type type(void) const
The type of record.
A class for representing a PTR DNS resource record.
DnsResourceRecordPTR(const std::string &name, uint32_t ttl, const std::string &dname="")
const DName & dname(void) const
The FQDN for this record.
void setName(const std::string &dname)
const std::string & dname(void) const
static const Type staticType(void)
virtual std::string toString(void) const
The string representation of this record.
virtual const Type type(void) const
The type of record.
A class for representing a SRV DNS resource record.
void setPrio(unsigned int prio)
unsigned int prio(void) const
Prio prio(void) const
The prio for this record.
DnsResourceRecordSRV(const std::string &name, uint32_t ttl, unsigned int prio, unsigned int weight, unsigned int port, const std::string &target)
void setWeight(unsigned int weight)
unsigned int port(void) const
Port port(void) const
The network port for this record.
Weight weight(void) const
The weight for this record.
unsigned int weight(void) const
const Target & target(void) const
The FQDN for this record.
virtual std::string toString(void) const
The string representation of this record.
const std::string & target(void) const
static const Type staticType(void)
void setTarget(const std::string &target)
virtual const Type type(void) const
The type of record.
void setPort(unsigned int port)
The base class for representing a DNS resource record.
const std::string & typeStr(void) const
DnsResourceRecord & operator=(const DnsResourceRecord &)=delete
Disallow copy assignment.
virtual ~DnsResourceRecord(void)
Destructor.
virtual std::string toString(void) const
DnsResourceRecord(const std::string &name, uint32_t ttl)
Default constructor.
const Name & name(void) const
The name of this record.
void setName(const std::string &name)
static const std::string & typeToString(Type type)
DnsResourceRecord(const DnsResourceRecord &)=delete
Disallow copy construction.
virtual const Type type(void) const =0
The type of record.
const std::string & name(void) const
const char * classStr(void) const
Class classId(void) const
A_brief_member_function_description.
Ttl ttl(void) const
The TTL for this record.
A class for representing an IP address in an OS independent way.
Namespace for the asynchronous programming classes.