Skip to content

Commit 06830ac

Browse files
committed
Hide DNS enum types from global space.
1 parent 66b004e commit 06830ac

10 files changed

Lines changed: 238 additions & 168 deletions

File tree

CMakeLists_Headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ set(INCLUDE_HEADERS
6565
src/protocol/mysql_parser.h
6666
src/protocol/mysql_types.h
6767
src/protocol/mysql_byteorder.h
68+
src/protocol/dns_types.h
6869
src/protocol/dns_parser.h
6970
src/protocol/DnsMessage.h
7071
src/protocol/DnsUtil.h

src/client/WFDnsClient.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <atomic>
2222
#include "URIParser.h"
2323
#include "StringUtil.h"
24+
#include "dns_types.h"
25+
#include "DnsMessage.h"
2426
#include "WFDnsClient.h"
2527

2628
using namespace protocol;

src/client/WFDnsClient.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@
2222
#include <string>
2323
#include <atomic>
2424
#include "WFTaskFactory.h"
25+
#include "dns_types.h"
2526
#include "DnsMessage.h"
2627

2728
class WFDnsClient
2829
{
2930
public:
30-
WFDnsClient() : params(NULL) { }
31-
virtual ~WFDnsClient() { }
32-
3331
int init(const std::string& url);
3432
int init(const std::string& url, const std::string& search_list,
3533
int ndots, int attempts, bool rotate);
@@ -41,6 +39,9 @@ class WFDnsClient
4139
private:
4240
void *params;
4341
std::atomic<size_t> id;
42+
43+
public:
44+
virtual ~WFDnsClient() { }
4445
};
4546

4647
#endif

src/factory/DnsTaskImpl.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <string>
2020
#include <atomic>
21+
#include "dns_types.h"
2122
#include "DnsMessage.h"
2223
#include "WFTaskError.h"
2324
#include "WFTaskFactory.h"

src/protocol/DnsMessage.cc

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include <errno.h>
2020
#include "PlatformSocket.h"
21+
#include "dns_types.h"
22+
#include "dns_parser.h"
2123
#include "DnsMessage.h"
2224

2325
#define DNS_LABELS_MAX 63
@@ -215,6 +217,135 @@ DnsMessage& DnsMessage::operator = (DnsMessage&& msg)
215217
return *this;
216218
}
217219

220+
inline struct list_head *DnsMessage::get_section(int section)
221+
{
222+
switch (section)
223+
{
224+
case DNS_ANSWER_SECTION:
225+
return &parser->answer_list;
226+
case DNS_AUTHORITY_SECTION:
227+
return &parser->authority_list;
228+
case DNS_ADDITIONAL_SECTION:
229+
return &parser->additional_list;
230+
default:
231+
errno = EINVAL;
232+
return NULL;
233+
}
234+
}
235+
236+
int DnsMessage::add_a_record(int section, const char *name,
237+
uint16_t rclass, uint32_t ttl,
238+
const void *data)
239+
{
240+
struct list_head *list = get_section(section);
241+
242+
if (!list)
243+
return -1;
244+
245+
return dns_add_raw_record(name, DNS_TYPE_A, rclass, ttl, 4, data, list);
246+
}
247+
248+
int DnsMessage::add_aaaa_record(int section, const char *name,
249+
uint16_t rclass, uint32_t ttl,
250+
const void *data)
251+
{
252+
struct list_head *list = get_section(section);
253+
254+
if (!list)
255+
return -1;
256+
257+
return dns_add_raw_record(name, DNS_TYPE_AAAA, rclass, ttl, 16, data, list);
258+
}
259+
260+
int DnsMessage::add_ns_record(int section, const char *name,
261+
uint16_t rclass, uint32_t ttl,
262+
const char *data)
263+
{
264+
struct list_head *list = get_section(section);
265+
266+
if (!list)
267+
return -1;
268+
269+
return dns_add_str_record(name, DNS_TYPE_NS, rclass, ttl, data, list);
270+
}
271+
272+
int DnsMessage::add_cname_record(int section, const char *name,
273+
uint16_t rclass, uint32_t ttl,
274+
const char *data)
275+
{
276+
struct list_head *list = get_section(section);
277+
278+
if (!list)
279+
return -1;
280+
281+
return dns_add_str_record(name, DNS_TYPE_CNAME, rclass, ttl, data, list);
282+
}
283+
284+
int DnsMessage::add_ptr_record(int section, const char *name,
285+
uint16_t rclass, uint32_t ttl,
286+
const char *data)
287+
{
288+
struct list_head *list = get_section(section);
289+
290+
if (!list)
291+
return -1;
292+
293+
return dns_add_str_record(name, DNS_TYPE_PTR, rclass, ttl, data, list);
294+
}
295+
296+
int DnsMessage::add_soa_record(int section, const char *name,
297+
uint16_t rclass, uint32_t ttl,
298+
const char *mname, const char *rname,
299+
uint32_t serial, int32_t refresh,
300+
int32_t retry, int32_t expire, uint32_t minimum)
301+
{
302+
struct list_head *list = get_section(section);
303+
304+
if (!list)
305+
return -1;
306+
307+
return dns_add_soa_record(name, rclass, ttl, mname, rname, serial,
308+
refresh, retry, expire, minimum, list);
309+
}
310+
311+
int DnsMessage::add_srv_record(int section, const char *name,
312+
uint16_t rclass, uint32_t ttl,
313+
uint16_t priority, uint16_t weight,
314+
uint16_t port, const char *target)
315+
{
316+
struct list_head *list = get_section(section);
317+
318+
if (!list)
319+
return -1;
320+
321+
return dns_add_srv_record(name, rclass, ttl, priority, weight,
322+
port, target, list);
323+
}
324+
325+
int DnsMessage::add_mx_record(int section, const char *name,
326+
uint16_t rclass, uint32_t ttl,
327+
int16_t preference, const char *exchange)
328+
{
329+
struct list_head *list = get_section(section);
330+
331+
if (!list)
332+
return -1;
333+
334+
return dns_add_mx_record(name, rclass, ttl, preference, exchange, list);
335+
}
336+
337+
int DnsMessage::add_raw_record(int section, const char *name, uint16_t type,
338+
uint16_t rclass, uint32_t ttl,
339+
const void *data, uint16_t dlen)
340+
{
341+
struct list_head *list = get_section(section);
342+
343+
if (!list)
344+
return -1;
345+
346+
return dns_add_raw_record(name, type, rclass, ttl, dlen, data, list);
347+
}
348+
218349
int DnsMessage::encode_reply()
219350
{
220351
dns_record_cursor_t cursor;

src/protocol/DnsMessage.h

Lines changed: 11 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -154,118 +154,42 @@ class DnsMessage : public ProtocolMessage
154154

155155
int add_a_record(int section, const char *name,
156156
uint16_t rclass, uint32_t ttl,
157-
const void *data)
158-
{
159-
struct list_head *list = get_section(section);
160-
161-
if (!list)
162-
return -1;
163-
164-
return dns_add_raw_record(name, DNS_TYPE_A, rclass, ttl, 4, data, list);
165-
}
157+
const void *data);
166158

167159
int add_aaaa_record(int section, const char *name,
168160
uint16_t rclass, uint32_t ttl,
169-
const void *data)
170-
{
171-
struct list_head *list = get_section(section);
172-
173-
if (!list)
174-
return -1;
175-
176-
return dns_add_raw_record(name, DNS_TYPE_AAAA, rclass, ttl,
177-
16, data, list);
178-
}
161+
const void *data);
179162

180163
int add_ns_record(int section, const char *name,
181164
uint16_t rclass, uint32_t ttl,
182-
const char *data)
183-
{
184-
struct list_head *list = get_section(section);
185-
186-
if (!list)
187-
return -1;
188-
189-
return dns_add_str_record(name, DNS_TYPE_NS, rclass, ttl, data, list);
190-
}
165+
const char *data);
191166

192167
int add_cname_record(int section, const char *name,
193168
uint16_t rclass, uint32_t ttl,
194-
const char *data)
195-
{
196-
struct list_head *list = get_section(section);
197-
198-
if (!list)
199-
return -1;
200-
201-
return dns_add_str_record(name, DNS_TYPE_CNAME, rclass, ttl,
202-
data, list);
203-
}
169+
const char *data);
204170

205171
int add_ptr_record(int section, const char *name,
206172
uint16_t rclass, uint32_t ttl,
207-
const char *data)
208-
{
209-
struct list_head *list = get_section(section);
210-
211-
if (!list)
212-
return -1;
213-
214-
return dns_add_str_record(name, DNS_TYPE_PTR, rclass, ttl, data, list);
215-
}
173+
const char *data);
216174

217175
int add_soa_record(int section, const char *name,
218176
uint16_t rclass, uint32_t ttl,
219177
const char *mname, const char *rname,
220178
uint32_t serial, int32_t refresh,
221-
int32_t retry, int32_t expire, uint32_t minimum)
222-
{
223-
struct list_head *list = get_section(section);
224-
225-
if (!list)
226-
return -1;
227-
228-
return dns_add_soa_record(name, rclass, ttl, mname, rname, serial,
229-
refresh, retry, expire, minimum, list);
230-
}
179+
int32_t retry, int32_t expire, uint32_t minimum);
231180

232181
int add_srv_record(int section, const char *name,
233182
uint16_t rclass, uint32_t ttl,
234-
uint16_t priority, uint16_t weight, uint16_t port,
235-
const char *target)
236-
{
237-
struct list_head *list = get_section(section);
238-
239-
if (!list)
240-
return -1;
241-
242-
return dns_add_srv_record(name, rclass, ttl,
243-
priority, weight, port, target, list);
244-
}
183+
uint16_t priority, uint16_t weight,
184+
uint16_t port, const char *target);
245185

246186
int add_mx_record(int section, const char *name,
247187
uint16_t rclass, uint32_t ttl,
248-
int16_t preference, const char *exchange)
249-
{
250-
struct list_head *list = get_section(section);
251-
252-
if (!list)
253-
return -1;
254-
255-
return dns_add_mx_record(name, rclass, ttl, preference, exchange, list);
256-
}
188+
int16_t preference, const char *exchange);
257189

258190
int add_raw_record(int section, const char *name, uint16_t type,
259191
uint16_t rclass, uint32_t ttl,
260-
const void *data, uint16_t dlen)
261-
{
262-
struct list_head *list = get_section(section);
263-
264-
if (!list)
265-
return -1;
266-
267-
return dns_add_raw_record(name, type, rclass, ttl, dlen, data, list);
268-
}
192+
const void *data, uint16_t dlen);
269193

270194
// Inner use only
271195
bool is_single_packet() const
@@ -305,22 +229,7 @@ class DnsMessage : public ProtocolMessage
305229
private:
306230
int encode_reply();
307231
int encode_truncation_reply();
308-
309-
struct list_head *get_section(int section)
310-
{
311-
switch (section)
312-
{
313-
case DNS_ANSWER_SECTION:
314-
return &(parser->answer_list);
315-
case DNS_AUTHORITY_SECTION:
316-
return &(parser->authority_list);
317-
case DNS_ADDITIONAL_SECTION:
318-
return &(parser->additional_list);
319-
default:
320-
errno = EINVAL;
321-
return NULL;
322-
}
323-
}
232+
struct list_head *get_section(int section);
324233

325234
// size of msgbuf, but in network byte order
326235
uint16_t msgsize;

src/protocol/DnsUtil.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <string>
2020
#include "PlatformSocket.h"
21+
#include "dns_types.h"
2122
#include "DnsUtil.h"
2223

2324
namespace protocol
@@ -90,7 +91,7 @@ int DnsUtil::getaddrinfo(const DnsResponse *resp,
9091
if (ai == NULL)
9192
{
9293
if (res)
93-
freeaddrinfo(res);
94+
DnsUtil::freeaddrinfo(res);
9495
return EAI_MEMORY;
9596
}
9697

src/protocol/dns_parser.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <stdlib.h>
2121
#include <stdint.h>
2222
#include "PlatformSocket.h"
23+
#include "dns_types.h"
2324
#include "dns_parser.h"
2425

2526
#define DNS_LABELS_MAX 63

0 commit comments

Comments
 (0)