Coverage Report

Created: 2026-05-30 06:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pdns/pdns/rcpgenerator.hh
Line
Count
Source
1
/*
2
 * This file is part of PowerDNS or dnsdist.
3
 * Copyright -- PowerDNS.COM B.V. and its contributors
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of version 2 of the GNU General Public License as
7
 * published by the Free Software Foundation.
8
 *
9
 * In addition, for the avoidance of any doubt, permission is granted to
10
 * link this program with OpenSSL and to (re)distribute the binaries
11
 * produced as the result of such linking.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
 */
22
#pragma once
23
#include <inttypes.h>
24
#include <string>
25
#include <stdexcept>
26
27
#include "namespaces.hh"
28
#include "dnsname.hh"
29
#include "iputils.hh"
30
#include "misc.hh"
31
#include "svc-records.hh"
32
33
class RecordTextException : public runtime_error
34
{
35
public:
36
0
  RecordTextException(const string& str) : runtime_error(str)
37
0
  {}
38
};
39
40
class RecordTextReader
41
{
42
public:
43
  RecordTextReader(string  str, ZoneName  zone=ZoneName(""));
44
  void xfrNodeOrLocatorID(NodeOrLocatorID& val);
45
  void xfr64BitInt(uint64_t& val);
46
  void xfr48BitInt(uint64_t& val);
47
  void xfr32BitInt(uint32_t& val);
48
  void xfr16BitInt(uint16_t& val);
49
  void xfr8BitInt(uint8_t& val);
50
51
  void xfrType(uint16_t& val);
52
  void xfrIP(uint32_t& val);
53
  void xfrIP6(std::string& val);
54
  void xfrCAWithoutPort(uint8_t version, ComboAddress &val);
55
  void xfrCAPort(ComboAddress &val);
56
  void xfrTime(uint32_t& val);
57
58
  void xfrName(DNSName& val, bool compress=false);
59
  void xfrText(string& val, bool multi=false, bool lenField=true);
60
  void xfrUnquotedText(string& val, bool lenField=true);
61
  void xfrHexBlob(string& val, bool keepReading=false);
62
  void xfrBase32HexBlob(string& val);
63
64
  void xfrBlobNoSpaces(string& val, int len=-1);
65
  void xfrBlob(string& val, int len=-1);
66
67
  void xfrSvcParamKeyVals(set<SvcParam>& val);
68
  void xfrRFC1035CharString(string &val);
69
  void xfrSVCBValueList(vector<string> &val);
70
71
0
  std::string getRemaining() const {
72
0
    return d_string.substr(d_pos);
73
0
  }
74
75
  bool eof() const;
76
77
#if defined(PDNS_AUTH) // [
78
  /* This method is only there for parity with DNSParser::consumeRemaining(),
79
     see the comment there to know why it is needed.
80
  */
81
  void consumeRemaining() const
82
0
  {
83
0
  }
84
#endif // ]
85
86
private:
87
  string d_string;
88
  ZoneName d_zone;
89
  string::size_type d_pos{0};
90
  string::size_type d_end;
91
  void skipSpaces();
92
};
93
94
class RecordTextWriter
95
{
96
public:
97
  RecordTextWriter(string& str, bool noDot=false);
98
  void xfrNodeOrLocatorID(const NodeOrLocatorID& val);
99
  void xfr48BitInt(const uint64_t& val);
100
  void xfr32BitInt(const uint32_t& val);
101
  void xfr16BitInt(const uint16_t& val);
102
  void xfr8BitInt(const uint8_t& val);
103
  void xfrIP(const uint32_t& val);
104
  void xfrIP6(const std::string& val);
105
  void xfrCAWithoutPort(uint8_t version, ComboAddress &val);
106
  void xfrCAPort(ComboAddress &val);
107
  void xfrTime(const uint32_t& val);
108
  void xfrBase32HexBlob(const string& val);
109
110
  void xfrType(const uint16_t& val);
111
  void xfrName(const DNSName& val, bool compress=false);
112
  void xfrText(const string& val, bool multi=false, bool lenField=true);
113
  void xfrUnquotedText(const string& val, bool lenField=true);
114
  void xfrBlobNoSpaces(const string& val, int len=-1);
115
  void xfrBlob(const string& val, int len=-1);
116
  void xfrHexBlob(const string& val, bool keepReading=false);
117
  void xfrSvcParamKeyVals(const set<SvcParam>& val);
118
  void xfrSVCBValueList(const vector<string> &val);
119
120
0
  bool eof() const { return true; };
121
122
0
  std::string getRemaining() const {
123
0
     return "";
124
0
  }
125
126
  #if defined(PDNS_AUTH) // [
127
  /* This method is only there for parity with DNSParser::consumeRemaining(),
128
     see the comment there to know why it is needed.
129
  */
130
  void consumeRemaining() const
131
0
  {
132
0
  }
133
#endif // ]
134
private:
135
  string& d_string;
136
  bool d_nodot;
137
};