]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/protobuf.hh
Standardize license text in all PDNS files
[thirdparty/pdns.git] / pdns / protobuf.hh
CommitLineData
12471842
PL
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 */
d9d3f9c1
RG
22#pragma once
23
24#include <cstddef>
25#include <string>
26
27#include "config.h"
28
29#include "dnsname.hh"
30#include "iputils.hh"
31
32#ifdef HAVE_PROTOBUF
33#include <boost/uuid/uuid.hpp>
34#include <boost/uuid/uuid_generators.hpp>
35#include "dnsmessage.pb.h"
36#endif /* HAVE_PROTOBUF */
37
38class DNSProtoBufMessage
39{
40public:
41 enum DNSProtoBufMessageType {
42 Query,
43 Response
44 };
45
46 DNSProtoBufMessage()
47 {
48 }
49
50 DNSProtoBufMessage(DNSProtoBufMessage::DNSProtoBufMessageType type);
51
52 ~DNSProtoBufMessage()
53 {
54 }
55
56 void setQuestion(const DNSName& qname, uint16_t qtype, uint16_t qclass);
57 void setEDNSSubnet(const Netmask& subnet);
58 void setBytes(size_t bytes);
59 void setTime(time_t sec, uint32_t usec);
58307a85 60 void setQueryTime(time_t sec, uint32_t usec);
d9d3f9c1
RG
61 void setResponseCode(uint8_t rcode);
62 void addRRsFromPacket(const char* packet, const size_t len);
63 void serialize(std::string& data) const;
64 std::string toDebugString() const;
65
66#ifdef HAVE_PROTOBUF
67 DNSProtoBufMessage(DNSProtoBufMessage::DNSProtoBufMessageType type, const boost::uuids::uuid& uuid, const ComboAddress* requestor, const ComboAddress* responder, const DNSName& domain, int qtype, uint16_t qclass, uint16_t qid, bool isTCP, size_t bytes);
68 void update(const boost::uuids::uuid& uuid, const ComboAddress* requestor, const ComboAddress* responder, bool isTCP, uint16_t id);
69 void setUUID(const boost::uuids::uuid& uuid);
70
71protected:
72 PBDNSMessage d_message;
73#endif /* HAVE_PROTOBUF */
74};