blob: 48ef4641ede2d593b4006b279387ce37a11de31c [file] [log] [blame]
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, Regents of the University of California.
4 *
5 * This file is part of NDNS (Named Data Networking Domain Name Service).
6 * See AUTHORS.md for complete list of NDNS authors and contributors.
7 *
8 * NDNS is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef NDNS_QUERY_HPP
21#define NDNS_QUERY_HPP
22
23#include "rr.hpp"
24
25#include <ndn-cxx/name.hpp>
26
27namespace ndn {
28namespace ndns {
29
30class Query
31{
32public:
33
34 enum QueryType {
35 QUERY_DNS,
36 QUERY_DNS_R
37 };
38
39 Query();
40
41 virtual ~Query();
42
43 const Name& getAuthorityZone() const {
44 return m_authorityZone;
45 }
46
47 void setAuthorityZone(const Name& authorityZone) {
48 m_authorityZone = authorityZone;
49 }
50
51 time::milliseconds getInterestLifetime() const {
52 return m_interestLifetime;
53 }
54
55 void setInterestLifetime(time::milliseconds interestLifetime) {
56 m_interestLifetime = interestLifetime;
57 }
58
59 enum QueryType getQueryType() const {
60 return m_queryType;
61 }
62
63 void setQueryType(enum QueryType queryType) {
64 m_queryType = queryType;
65 }
66
67 const Name& getRrLabel() const {
68 return m_rrLabel;
69 }
70
71 void setRrLabel(const Name& rrLabel) {
72 m_rrLabel = rrLabel;
73 }
74
75 const RRType& getRrType() const {
76 return m_rrType;
77 }
78
79 void setRrType(const RRType& rrType) {
80 m_rrType = rrType;
81 }
82
83 static std::string
84 toString(QueryType qType)
85 {
86 std::string label;
87 switch (qType)
88 {
89 case QUERY_DNS:
90 label = "DNS";
91 break;
92 case QUERY_DNS_R:
93 label = "DNS-R";
94 break;
95 default:
96 label = "Default";
97 break;
98 }
99 return label;
100
101 }
102
103 static const QueryType
104 toQueryType(const std::string& str)
105 {
106 QueryType atype;
107 if (str == "DNS") {
108 atype = QUERY_DNS;
109 }
110 else if (str == "DNS-R") {
111 atype = QUERY_DNS_R;
112 }
113 else {
114 atype = QUERY_DNS;
115 }
116 return atype;
117 }
118
119private:
120 template<bool T>
121 size_t
122 wireEncode(EncodingImpl<T> & block) const;
123
124public:
125
126 const Block&
127 wireEncode() const;
128
129 void
130 wireDecode(const Block& wire);
131
132
133 Interest
134 toWire() const;
135
136 void
137 fromWire(const Name &name, const Interest& interest);
138
139public:
140 Name m_authorityZone;
141 enum QueryType m_queryType;
142 time::milliseconds m_interestLifetime;
143 Name m_rrLabel;
144 enum RRType m_rrType;
145
146 mutable Block m_wire;
147};
148
149} // namespace ndns
150} // namespace ndn
151
152#endif // NDNS_QUERY_HPP