Coverage Report

Created: 2025-06-13 06:28

/src/pdns/pdns/rcpgenerator.hh
Line
Count
Source (jump to first uncovered line)
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
  const string getRemaining() const {
72
0
    return d_string.substr(d_pos);
73
0
  }
74
75
76
  bool eof();
77
private:
78
  string d_string;
79
  ZoneName d_zone;
80
  string::size_type d_pos{0};
81
  string::size_type d_end;
82
  void skipSpaces();
83
};
84
85
class RecordTextWriter
86
{
87
public:
88
  RecordTextWriter(string& str, bool noDot=false);
89
  void xfrNodeOrLocatorID(const NodeOrLocatorID& val);
90
  void xfr48BitInt(const uint64_t& val);
91
  void xfr32BitInt(const uint32_t& val);
92
  void xfr16BitInt(const uint16_t& val);
93
  void xfr8BitInt(const uint8_t& val);
94
  void xfrIP(const uint32_t& val);
95
  void xfrIP6(const std::string& val);
96
  void xfrCAWithoutPort(uint8_t version, ComboAddress &val);
97
  void xfrCAPort(ComboAddress &val);
98
  void xfrTime(const uint32_t& val);
99
  void xfrBase32HexBlob(const string& val);
100
101
  void xfrType(const uint16_t& val);
102
  void xfrName(const DNSName& val, bool compress=false);
103
  void xfrText(const string& val, bool multi=false, bool lenField=true);
104
  void xfrUnquotedText(const string& val, bool lenField=true);
105
  void xfrBlobNoSpaces(const string& val, int len=-1);
106
  void xfrBlob(const string& val, int len=-1);
107
  void xfrHexBlob(const string& val, bool keepReading=false);
108
  void xfrSvcParamKeyVals(const set<SvcParam>& val);
109
0
  bool eof() { return true; };
110
111
  void xfrSVCBValueList(const vector<string> &val);
112
113
0
  const string getRemaining() const {
114
0
     return "";
115
0
  }
116
private:
117
  string& d_string;
118
  bool d_nodot;
119
};