1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2017 Nathan Osman
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  * IN THE SOFTWARE.
23  */
24 
25 #include <QDebug>
26 
27 #include <qmdnsengine/dns.h>
28 #include <qmdnsengine/record.h>
29 
30 #include "record_p.h"
31 
32 using namespace QMdnsEngine;
33 
RecordPrivate()34 RecordPrivate::RecordPrivate()
35     : type(0),
36       flushCache(false),
37       ttl(3600),
38       priority(0),
39       weight(0),
40       port(0)
41 {
42 }
43 
Record()44 Record::Record()
45     : d(new RecordPrivate)
46 {
47 }
48 
Record(const Record & other)49 Record::Record(const Record &other)
50     : d(new RecordPrivate)
51 {
52     *this = other;
53 }
54 
operator =(const Record & other)55 Record &Record::operator=(const Record &other)
56 {
57     *d = *other.d;
58     return *this;
59 }
60 
operator ==(const Record & other) const61 bool Record::operator==(const Record &other) const
62 {
63     return d->name == other.d->name &&
64         d->type == other.d->type &&
65         d->address == other.d->address &&
66         d->target == other.d->target &&
67         d->nextDomainName == other.d->nextDomainName &&
68         d->priority == other.d->priority &&
69         d->weight == other.d->weight &&
70         d->port == other.d->port &&
71         d->attributes == other.d->attributes &&
72         d->bitmap == other.d->bitmap;
73 }
74 
operator !=(const Record & other) const75 bool Record::operator!=(const Record &other) const
76 {
77     return !(*this == other);
78 }
79 
~Record()80 Record::~Record()
81 {
82     delete d;
83 }
84 
name() const85 QByteArray Record::name() const
86 {
87     return d->name;
88 }
89 
setName(const QByteArray & name)90 void Record::setName(const QByteArray &name)
91 {
92     d->name = name;
93 }
94 
type() const95 quint16 Record::type() const
96 {
97     return d->type;
98 }
99 
setType(quint16 type)100 void Record::setType(quint16 type)
101 {
102     d->type = type;
103 }
104 
flushCache() const105 bool Record::flushCache() const
106 {
107     return d->flushCache;
108 }
109 
setFlushCache(bool flushCache)110 void Record::setFlushCache(bool flushCache)
111 {
112     d->flushCache = flushCache;
113 }
114 
ttl() const115 quint32 Record::ttl() const
116 {
117     return d->ttl;
118 }
119 
setTtl(quint32 ttl)120 void Record::setTtl(quint32 ttl)
121 {
122     d->ttl = ttl;
123 }
124 
address() const125 QHostAddress Record::address() const
126 {
127     return d->address;
128 }
129 
setAddress(const QHostAddress & address)130 void Record::setAddress(const QHostAddress &address)
131 {
132     d->address = address;
133 }
134 
target() const135 QByteArray Record::target() const
136 {
137     return d->target;
138 }
139 
setTarget(const QByteArray & target)140 void Record::setTarget(const QByteArray &target)
141 {
142     d->target = target;
143 }
144 
nextDomainName() const145 QByteArray Record::nextDomainName() const
146 {
147     return d->nextDomainName;
148 }
149 
setNextDomainName(const QByteArray & nextDomainName)150 void Record::setNextDomainName(const QByteArray &nextDomainName)
151 {
152     d->nextDomainName = nextDomainName;
153 }
154 
priority() const155 quint16 Record::priority() const
156 {
157     return d->priority;
158 }
159 
setPriority(quint16 priority)160 void Record::setPriority(quint16 priority)
161 {
162     d->priority = priority;
163 }
164 
weight() const165 quint16 Record::weight() const
166 {
167     return d->weight;
168 }
169 
setWeight(quint16 weight)170 void Record::setWeight(quint16 weight)
171 {
172     d->weight = weight;
173 }
174 
port() const175 quint16 Record::port() const
176 {
177     return d->port;
178 }
179 
setPort(quint16 port)180 void Record::setPort(quint16 port)
181 {
182     d->port = port;
183 }
184 
attributes() const185 QMap<QByteArray, QByteArray> Record::attributes() const
186 {
187     return d->attributes;
188 }
189 
setAttributes(const QMap<QByteArray,QByteArray> & attributes)190 void Record::setAttributes(const QMap<QByteArray, QByteArray> &attributes)
191 {
192     d->attributes = attributes;
193 }
194 
addAttribute(const QByteArray & key,const QByteArray & value)195 void Record::addAttribute(const QByteArray &key, const QByteArray &value)
196 {
197     d->attributes.insert(key, value);
198 }
199 
bitmap() const200 Bitmap Record::bitmap() const
201 {
202     return d->bitmap;
203 }
204 
setBitmap(const Bitmap & bitmap)205 void Record::setBitmap(const Bitmap &bitmap)
206 {
207     d->bitmap = bitmap;
208 }
209 
operator <<(QDebug dbg,const Record & record)210 QDebug QMdnsEngine::operator<<(QDebug dbg, const Record &record)
211 {
212     QDebugStateSaver saver(dbg);
213     Q_UNUSED(saver);
214 
215     dbg.noquote().nospace() << "Record(" << typeName(record.type()) << " " << record.name() << ")";
216 
217     return dbg;
218 }
219