~ubuntu-branches/ubuntu/utopic/pdns/utopic-updates

« back to all changes in this revision

Viewing changes to modules/tinydnsbackend/tinydnsbackend.hh

  • Committer: Package Import Robot
  • Author(s): Marc Haber, Marc Haber, Evgeni Golov
  • Date: 2012-05-11 23:51:27 UTC
  • mfrom: (1.1.9) (12.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20120511235127-v0qjuaplfckcb2cd
Tags: 3.1-1
[ Marc Haber ]
* Imported Upstream version 3.1
  * reduce column size for 'algorithm' to 50. Closes: #662935
  * handle smallcaps RRs. Closes: #656788
* refresh patches
* remove unused patches
* add patch to turn off the traceback handler at run time
* add patch for changeset 2575 (race condition with supermasters)
* fix mysql multiarch build failure, set cflags etc to hardening defaults
* do not run bootstrap a build time, using autotools_dev
* use dh-autoreconf, remove autofoo created files from
  patches/fix-mongodb-backend-patch
* fix dh invocation
* create MySQL databases with engine=innodb instead of type
* set debian/compat to 9
* Standards-Version: 3.9.3 (no changes needed)
* add myself to uploaders, change Vcs-Header to my git. Closes: #672550

[ Evgeni Golov ]
* use system libpolarssl if present, local copy otherwise.
  Closes: #671856, #656861

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef TINYDNSBACKEND_HH
 
2
#define TINYDNSBACKEND_HH
 
3
 
 
4
#include <pdns/dnsbackend.hh>
 
5
#include <pdns/logger.hh>
 
6
#include <pdns/iputils.hh>
 
7
#include <pdns/dnspacket.hh>
 
8
#include <cdb.h>
 
9
#include <sys/types.h>
 
10
#include <sys/stat.h>
 
11
#include <fcntl.h>
 
12
#include "cdb.hh"
 
13
#include <pdns/lock.hh>
 
14
#include <boost/multi_index_container.hpp>
 
15
#include <boost/multi_index/hashed_index.hpp>
 
16
#include <boost/multi_index/member.hpp>
 
17
 
 
18
using namespace ::boost;
 
19
using namespace ::boost::multi_index;
 
20
 
 
21
struct TinyDomainInfo {
 
22
        uint32_t id;
 
23
        uint32_t notified_serial;
 
24
        string zone;
 
25
 
 
26
        bool operator<(const TinyDomainInfo& tdi) const
 
27
        {
 
28
                return zone < tdi.zone;
 
29
        }
 
30
};
 
31
 
 
32
struct TDI_SerialModifier {
 
33
        TDI_SerialModifier (const int newSerial) : d_newSerial(newSerial) {}
 
34
 
 
35
        void operator()(TinyDomainInfo& tdi)
 
36
        {
 
37
                tdi.notified_serial = d_newSerial;
 
38
        }
 
39
 
 
40
        private:
 
41
                int d_newSerial;
 
42
};
 
43
 
 
44
 
 
45
class TinyDNSBackend : public DNSBackend
 
46
{
 
47
public:
 
48
        // Methods for simple operation
 
49
        TinyDNSBackend(const string &suffix);
 
50
        void lookup(const QType &qtype, const string &qdomain, DNSPacket *pkt_p=0, int zoneId=-1);
 
51
        bool list(const string &target, int domain_id);
 
52
        bool get(DNSResourceRecord &rr);
 
53
        void getAllDomains(vector<DomainInfo> *domains);
 
54
 
 
55
        //Master mode operation
 
56
        void getUpdatedMasters(vector<DomainInfo>* domains);
 
57
        void setNotified(uint32_t id, uint32_t serial);
 
58
private:
 
59
        vector<string> getLocations();
 
60
 
 
61
        //TypeDefs
 
62
        struct tag_zone{};
 
63
        struct tag_domainid{};
 
64
        typedef multi_index_container<
 
65
                TinyDomainInfo,
 
66
                indexed_by<
 
67
                        hashed_unique<tag<tag_zone>, member<TinyDomainInfo, string, &TinyDomainInfo::zone> >,
 
68
                        hashed_unique<tag<tag_domainid>, member<TinyDomainInfo, uint32_t, &TinyDomainInfo::id> >
 
69
                >
 
70
        > TDI_t;
 
71
        typedef map<string, TDI_t> TDI_suffix_t;
 
72
        typedef TDI_t::index<tag_zone>::type TDIByZone_t;
 
73
        typedef TDI_t::index<tag_domainid>::type TDIById_t;
 
74
 
 
75
        //data member variables
 
76
        uint64_t d_taiepoch;
 
77
        QType d_qtype;
 
78
        CDB *d_cdbReader;
 
79
        DNSPacket *d_dnspacket; // used for location and edns-client support.
 
80
        bool d_isWildcardQuery; // Indicate if the query received was a wildcard query.
 
81
        bool d_isAxfr; // Indicate if we received a list() and not a lookup().
 
82
        bool d_locations;
 
83
        bool d_timestamps;
 
84
        string d_suffix;
 
85
        
 
86
 
 
87
        // Statics
 
88
        static pthread_mutex_t s_domainInfoLock;
 
89
        static TDI_suffix_t s_domainInfo;
 
90
        static uint32_t s_lastId; // used to give a domain an id.
 
91
};
 
92
 
 
93
#endif // TINYDNSBACKEND_HH