File: test-common.hh

package info (click to toggle)
pdns-recursor 5.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,108 kB
  • sloc: cpp: 109,513; javascript: 20,651; python: 5,657; sh: 5,069; makefile: 780; ansic: 582; xml: 37
file content (42 lines) | stat: -rw-r--r-- 1,214 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

#include "dnsrecords.hh"
#include "iputils.hh"

static inline std::shared_ptr<DNSRecordContent> getRecordContent(uint16_t type, const std::string& content)
{
  std::shared_ptr<DNSRecordContent> result = nullptr;

  if (type == QType::NS) {
    result = std::make_shared<NSRecordContent>(DNSName(content));
  }
  else if (type == QType::A) {
    result = std::make_shared<ARecordContent>(ComboAddress(content));
  }
  else if (type == QType::AAAA) {
    result = std::make_shared<AAAARecordContent>(ComboAddress(content));
  }
  else if (type == QType::CNAME) {
    result = std::make_shared<CNAMERecordContent>(DNSName(content));
  }
  else if (type == QType::OPT) {
    result = std::make_shared<OPTRecordContent>();
  }
  else {
    result = DNSRecordContent::make(type, QClass::IN, content);
  }

  return result;
}

static inline void addRecordToList(std::vector<DNSRecord>& records, const DNSName& name, uint16_t type, const std::string& content, DNSResourceRecord::Place place=DNSResourceRecord::ANSWER, uint32_t ttl=3600)
{
  DNSRecord rec;
  rec.d_place = place;
  rec.d_name = name;
  rec.d_type = type;
  rec.d_ttl = ttl;

  rec.setContent(getRecordContent(type, content));

  records.push_back(rec);
}