blob: 7b6de331e9adfa5f8274c55e217e764f78a8231f [file] [log] [blame]
Shock Jiang01712f32014-10-01 14:34:16 -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_CLIENTS_QUERY_HPP
21#define NDNS_CLIENTS_QUERY_HPP
22
23#include "ndns-label.hpp"
24#include "ndns-enum.hpp"
25
26#include <ndn-cxx/name.hpp>
27
28namespace ndn {
29namespace ndns {
30
31/**
32 * @brief NDNS Query abstraction. Query is an Interest whose name follows the format:
33 * <hint> /xF0. <zone> [<KEY>|<NDNS>|<NDNS-R>] <rrLabel> <rrType>
34 */
35class Query : noncopyable
36{
37public:
38 Query();
39
40 Query(const Name& hint, const Name& zone, const name::Component& queryType);
41
42 /**
43 * @brief construct an Interest according to the query abstraction
44 */
45 Interest
46 toInterest() const;
47
48 /**
49 * @brief extract the query information (rrLabel, rrType) from a Interest
50 * @param[in] interest The Interest to parse; the Interest must have correct hint and zone,
51 * otherwise it's undefined behavior
52 */
53 bool
54 fromInterest(const Name& hint, const Name& zone, const Interest& interest);
55
56 bool
57 operator==(const Query& other) const
58 {
59 return (getHint() == other.getHint() && getZone() == other.getZone() &&
60 getQueryType() == other.getQueryType() && getRrLabel() == other.getRrLabel() &&
61 getRrType() == other.getRrType());
62 }
63
64 bool
65 operator!=(const Query& other) const
66 {
67 return !(*this == other);
68 }
69
70public:
71
72 /**
73 * @brief get forwarding hint. default empty hint (empty() == True),
74 * hint won't add to the name
75 */
76 const Name&
77 getHint() const
78 {
79 return m_hint;
80 }
81
82 /**
83 * @brief set forwarding hint. default empty hint (empty() == True),
84 * hint won't add to the name
85 */
86 void
87 setHint(const Name& hint)
88 {
89 m_hint = hint;
90 }
91
92
93 /**
94 * @brief get name of authoritative zone
95 */
96 const Name&
97 getZone() const
98 {
99 return m_zone;
100 }
101
102 /**
103 * @brief set name of authoritative zone
104 */
105 void
106 setZone(const Name& zone)
107 {
108 m_zone = zone;
109 }
110
111 /**
112 * @brief get lifetime of the Interest
113 */
114 const time::milliseconds&
115 getInterestLifetime() const
116 {
117 return m_interestLifetime;
118 }
119
120 /**
121 * @brief set lifetime of the Interest
122 */
123 void
124 setInterestLifetime(const time::milliseconds& interestLifetime)
125 {
126 m_interestLifetime = interestLifetime;
127 }
128
129
130 /**
131 * @brief get query type
132 */
133 const name::Component&
134 getQueryType() const
135 {
136 return m_queryType;
137 }
138
139 /**
140 * @brief get query type
141 */
142 void
143 setQueryType(const name::Component& queryType)
144 {
145 m_queryType = queryType;
146 }
147
148 /**
149 * @brief get label of resource record
150 */
151 const Name&
152 getRrLabel() const
153 {
154 return m_rrLabel;
155 }
156
157 /**
158 * @brief set label of resource record
159 */
160 void
161 setRrLabel(const Name& rrLabel)
162 {
163 m_rrLabel = rrLabel;
164 }
165
166 /**
167 * @brief get type resource record
168 */
169 const name::Component&
170 getRrType() const
171 {
172 return m_rrType;
173 }
174
175 /**
176 * @brief set type resource record
177 */
178 void
179 setRrType(const name::Component& rrType)
180 {
181 m_rrType = rrType;
182 }
183
184private:
185 Name m_hint;
186 Name m_zone;
187 name::Component m_queryType;
188 Name m_rrLabel;
189 name::Component m_rrType;
190 time::milliseconds m_interestLifetime;
191};
192
193std::ostream&
194operator<<(std::ostream& os, const Query& query);
195
196} // namespace ndns
197} // namespace ndn
198
199#endif // NDNS_CLIENTS_QUERY_HPP