]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dnsbackend.hh
removed some dead code
[thirdparty/pdns.git] / pdns / dnsbackend.hh
1 /*
2 PowerDNS Versatile Database Driven Nameserver
3 Copyright (C) 2002 PowerDNS.COM BV
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 // $Id: dnsbackend.hh,v 1.5 2002/12/30 21:00:56 ahu Exp $
20 /* (C) 2002 POWERDNS.COM BV */
21
22 #ifndef DNSBACKEND_HH
23 #define DNSBACKEND_HH
24
25 class DNSPacket;
26
27 #include "utility.hh"
28 #include <string>
29 #include <vector>
30 #include <map>
31 #include <sys/types.h>
32 #include "ahuexception.hh"
33 #include <set>
34
35 #ifndef WIN32
36 # include <sys/socket.h>
37 # include <dirent.h>
38 #endif // WIN32
39
40 #include "qtype.hh"
41 #include "dns.hh"
42 using namespace std;
43
44
45 class DNSBackend;
46 struct DomainInfo
47 {
48 u_int32_t id;
49 string zone;
50 string master;
51 u_int32_t notified_serial;
52 u_int32_t serial;
53 time_t last_check;
54 enum {Master,Slave,Native} kind;
55 DNSBackend *backend;
56 };
57
58 class DNSPacket;
59
60
61 //! This virtual base class defines the interface for backends for the ahudns.
62 /** To create a backend, inherit from this class and implement functions for all virtual methods.
63 Methods should not throw an exception if they are sure they did not find the requested data. However,
64 if an error occurred which prevented them temporarily from performing a lockup, they should throw a DBException,
65 which will cause the nameserver to send out a ServFail or take other evasive action. Probably only locking
66 issues should lead to DBExceptions.
67
68 More serious errors, which may indicate that the database connection is hosed, or a configuration error occurred, should
69 lead to the throwing of an AhuException. This exception will fall straight through the UeberBackend and the PacketHandler
70 and be caught by the Distributor, which will delete your DNSBackend instance and spawn a new one.
71 */
72 class DNSBackend
73 {
74 public:
75 //! lookup() initiates a lookup. A lookup without results should not throw!
76 virtual void lookup(const QType &qtype, const string &qdomain, DNSPacket *pkt_p=0, int zoneId=-1)=0;
77 virtual bool get(DNSResourceRecord &)=0; //!< retrieves one DNSResource record, returns false if no more were available
78 //! Initiates a list of the specified domain
79 /** Once initiated, DNSResourceRecord objects can be retrieved using get(). Should return false
80 if the backend does not consider itself responsible for the id passed.
81 \param domain_id ID of which a list is requested
82 */
83 virtual bool list(int domain_id)=0;
84
85 virtual ~DNSBackend(){};
86
87 //! fills the soadata struct with the SOA details. Returns false if there is no SOA.
88 virtual bool getSOA(const string &name, SOAData &soadata);
89
90 //! returns true if master ip is master for domain name.
91 virtual bool isMaster(const string &name, const string &ip)
92 {
93 return false;
94 }
95
96 //! starts the transaction for updating domain qname (FIXME: what is id?)
97 virtual bool startTransaction(const string &qname, int id=-1)
98 {
99 return false;
100 }
101
102 //! commits the transaction started by startTransaction
103 virtual bool commitTransaction()
104 {
105 return false;
106 }
107
108 //! aborts the transaction started by strartTransaction, should leave state unaltered
109 virtual bool abortTransaction()
110 {
111 return false;
112 }
113
114 virtual void reload()
115 {
116 }
117
118 virtual void rediscover(string* status=0)
119 {
120 }
121
122 //! feeds a record to a zone, needs a call to startTransaction first
123 virtual bool feedRecord(const DNSResourceRecord &rr)
124 {
125 return false; // no problem!
126 }
127 //! if this returns true, DomainInfo di contains information about the domain
128 virtual bool getDomainInfo(const string &domain, DomainInfo &di)
129 {
130 return false;
131 }
132 //! slave capable backends should return a list of slaves that should be rechecked for staleness
133 virtual void getUnfreshSlaveInfos(vector<DomainInfo>* domains)
134 {
135 }
136
137 //! get a list of IP addresses that should also be notified for a domain
138 virtual void alsoNotifies(const string &domain, set<string> *ips)
139 {
140 }
141
142 //! get list of domains that have been changed since their last notification to slaves
143 virtual void getUpdatedMasters(vector<DomainInfo>* domains)
144 {
145 }
146
147 //! Called by PowerDNS to inform a backend that a domain has been checked for freshness
148 virtual void setFresh(u_int32_t domain_id)
149 {
150
151 }
152 //! Called by PowerDNS to inform a backend that the changes in the domain have been reported to slaves
153 virtual void setNotified(u_int32_t id, u_int32_t serial)
154 {
155 }
156
157 //! Can be called to seed the getArg() function with a prefix
158 void setArgPrefix(const string &prefix);
159
160 //! determine if ip is a supermaster or a domain
161 virtual bool superMasterBackend(const string &ip, const string &domain, const vector<DNSResourceRecord>&nsset, string *account, DNSBackend **db)
162 {
163 return false;
164 }
165
166 //! called by PowerDNS to create a slave record for a superMaster
167 virtual bool createSlaveDomain(const string &ip, const string &domain, const string &account)
168 {
169 return false;
170 }
171
172 protected:
173 bool mustDo(const string &key);
174 const string &getArg(const string &key);
175 int getArgAsNum(const string &key);
176 string getRemote(DNSPacket *p);
177 bool getRemote(DNSPacket *p, struct sockaddr *in, Utility::socklen_t *len);
178
179 private:
180 string d_prefix;
181 };
182
183 class BackendFactory
184 {
185 public:
186 BackendFactory(const string &name) : d_name(name) {}
187 virtual ~BackendFactory(){}
188 virtual DNSBackend *make(const string &suffix)=0;
189 virtual void declareArguments(const string &suffix=""){}
190 const string &getName() const;
191
192 protected:
193 void declare(const string &suffix, const string &param, const string &explanation, const string &value);
194
195 private:
196 const string d_name;
197 };
198
199 class BackendMakerClass
200 {
201 public:
202 void report(BackendFactory *bf);
203 void launch(const string &instr);
204 vector<DNSBackend *>all();
205 void load(const string &module);
206 int numLauncheable();
207 vector<string> getModules();
208
209 private:
210 void load_all();
211 typedef map<string,BackendFactory *>d_repository_t;
212 d_repository_t d_repository;
213 vector<pair<string,string> >d_instances;
214 };
215
216 extern BackendMakerClass &BackendMakers();
217
218 //! Exception that can be thrown by a DNSBackend to indicate a failure
219 class DBException : public AhuException
220 {
221 public:
222 DBException(const string &reason) : AhuException(reason){}
223 };
224
225
226 #endif