Coverage Report

Created: 2025-07-04 06:59

/src/pdns/pdns/zoneparser-tng.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 <string>
24
#include <cstdio>
25
#include <stdexcept>
26
#include <stack>
27
#include <deque>
28
29
#include "namespaces.hh"
30
31
class ZoneParserTNG
32
{
33
public:
34
  ZoneParserTNG(const string& fname, ZoneName zname=g_rootzonename, string reldir="", bool upgradeContent=false);
35
  ZoneParserTNG(const vector<string>& zonedata, ZoneName zname, bool upgradeContent=false);
36
37
  ~ZoneParserTNG();
38
  bool get(DNSResourceRecord& rr, std::string* comment=0);
39
  typedef runtime_error exception;
40
  typedef std::deque<pair<string::size_type, string::size_type> > parts_t;
41
  ZoneName getZoneName();
42
  string getLineOfFile(); // for error reporting purposes
43
  pair<string,int> getLineNumAndFile(); // idem
44
  void disableGenerate()
45
0
  {
46
0
    d_generateEnabled = false;
47
0
  }
48
  void setMaxGenerateSteps(size_t max)
49
4.87k
  {
50
4.87k
    d_maxGenerateSteps = max;
51
4.87k
  }
52
  void setMaxIncludes(size_t max)
53
4.87k
  {
54
4.87k
    d_maxIncludes = max;
55
4.87k
  }
56
  void setDefaultTTL(int ttl)
57
0
  {
58
0
    d_defaultttl = ttl;
59
0
    d_havespecificttl = true;
60
0
  }
61
private:
62
  bool getLine();
63
  bool getTemplateLine();
64
  void stackFile(const std::string& fname);
65
  unsigned makeTTLFromZone(const std::string& str);
66
67
  struct filestate {
68
    filestate(FILE* fp, string filename) :
69
0
      d_fp(fp), d_filename(std::move(filename)) {}
70
    FILE *d_fp;
71
    string d_filename;
72
    int d_lineno{0};
73
  };
74
75
  parts_t d_parts;
76
  string d_reldir;
77
  string d_line;
78
  DNSName d_prevqname;
79
  ZoneName d_zonename;
80
  string d_templateline;
81
  vector<string> d_zonedata;
82
  vector<string>::iterator d_zonedataline;
83
  std::stack<filestate> d_filestates;
84
  parts_t d_templateparts;
85
  size_t d_maxGenerateSteps{0};
86
  size_t d_maxIncludes{20};
87
  int d_defaultttl;
88
  uint32_t d_templatecounter, d_templatestop, d_templatestep;
89
  bool d_havespecificttl;
90
  bool d_fromfile;
91
  bool d_generateEnabled{true};
92
  bool d_upgradeContent;
93
  bool d_templateCounterWrapped{false};
94
};