]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/zoneparser-tng.hh
dnsdist: Fix DNS over plain HTTP broken by `reloadAllCertificates()`
[thirdparty/pdns.git] / pdns / zoneparser-tng.hh
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, DNSName zname=g_rootdnsname, string reldir="", bool upgradeContent=false);
35 ZoneParserTNG(const vector<string>& zonedata, DNSName 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 DNSName getZoneName();
42 string getLineOfFile(); // for error reporting purposes
43 pair<string,int> getLineNumAndFile(); // idem
44 void disableGenerate()
45 {
46 d_generateEnabled = false;
47 }
48 void setMaxGenerateSteps(size_t max)
49 {
50 d_maxGenerateSteps = max;
51 }
52 void setMaxIncludes(size_t max)
53 {
54 d_maxIncludes = max;
55 }
56 private:
57 bool getLine();
58 bool getTemplateLine();
59 void stackFile(const std::string& fname);
60 unsigned makeTTLFromZone(const std::string& str);
61
62 struct filestate {
63 filestate(FILE* fp, string filename) : d_fp(fp), d_filename(std::move(filename)), d_lineno(0){}
64 FILE *d_fp;
65 string d_filename;
66 int d_lineno;
67 };
68
69 parts_t d_parts;
70 string d_reldir;
71 string d_line;
72 DNSName d_prevqname;
73 DNSName d_zonename;
74 string d_templateline;
75 vector<string> d_zonedata;
76 vector<string>::iterator d_zonedataline;
77 std::stack<filestate> d_filestates;
78 parts_t d_templateparts;
79 size_t d_maxGenerateSteps{0};
80 size_t d_maxIncludes{20};
81 int d_defaultttl;
82 uint32_t d_templatecounter, d_templatestop, d_templatestep;
83 bool d_havedollarttl;
84 bool d_fromfile;
85 bool d_generateEnabled{true};
86 bool d_upgradeContent;
87 bool d_templateCounterWrapped{false};
88 };