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