You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

81 lines
2.4 KiB

  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 "namespaces.hh"
  28. class ZoneParserTNG
  29. {
  30. public:
  31. ZoneParserTNG(const string& fname, const DNSName& zname=g_rootdnsname, const string& reldir="");
  32. ZoneParserTNG(const vector<string> zonedata, const DNSName& zname);
  33. ~ZoneParserTNG();
  34. bool get(DNSResourceRecord& rr, std::string* comment=0);
  35. typedef runtime_error exception;
  36. typedef deque<pair<string::size_type, string::size_type> > parts_t;
  37. DNSName getZoneName();
  38. string getLineOfFile(); // for error reporting purposes
  39. pair<string,int> getLineNumAndFile(); // idem
  40. void disableGenerate()
  41. {
  42. d_generateEnabled = false;
  43. }
  44. void setMaxGenerateSteps(size_t max)
  45. {
  46. d_maxGenerateSteps = max;
  47. }
  48. private:
  49. bool getLine();
  50. bool getTemplateLine();
  51. void stackFile(const std::string& fname);
  52. unsigned makeTTLFromZone(const std::string& str);
  53. struct filestate {
  54. filestate(FILE* fp, string filename) : d_fp(fp), d_filename(filename), d_lineno(0){}
  55. FILE *d_fp;
  56. string d_filename;
  57. int d_lineno;
  58. };
  59. parts_t d_parts;
  60. string d_reldir;
  61. string d_line;
  62. DNSName d_prevqname;
  63. DNSName d_zonename;
  64. string d_templateline;
  65. vector<string> d_zonedata;
  66. vector<string>::iterator d_zonedataline;
  67. std::stack<filestate> d_filestates;
  68. parts_t d_templateparts;
  69. size_t d_maxGenerateSteps{0};
  70. int d_defaultttl;
  71. uint32_t d_templatecounter, d_templatestop, d_templatestep;
  72. bool d_havedollarttl;
  73. bool d_fromfile;
  74. bool d_generateEnabled{true};
  75. };