blob: d96d58c90515ccc77cd6ab7e23e0cb95bca276c4 [file] [log] [blame]
Shock Jiang01712f32014-10-01 14:34:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yumin Xia6343c5b2016-10-20 15:45:50 -07003 * Copyright (c) 2014-2016, Regents of the University of California.
Shock Jiang01712f32014-10-01 14:34:16 -07004 *
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>
Yumin Xia4e561892016-10-21 10:48:01 -070027#include <ndn-cxx/link.hpp>
Shock Jiang01712f32014-10-01 14:34:16 -070028
29namespace ndn {
30namespace ndns {
31
32/**
Alexander Afanasyevdf2e9392016-03-10 11:50:53 -080033 * @brief NDNS Query abstraction
34 *
35 * Query is an Interest whose name follows the format:
36 *
Yumin Xia6343c5b2016-10-20 15:45:50 -070037 * <zone> [<KEY>|<NDNS>|<NDNS-R>] <rrLabel> <rrType>
Shock Jiang01712f32014-10-01 14:34:16 -070038 */
39class Query : noncopyable
40{
41public:
42 Query();
43
Yumin Xia6343c5b2016-10-20 15:45:50 -070044 Query(const Name& zone, const name::Component& queryType);
Shock Jiang01712f32014-10-01 14:34:16 -070045
46 /**
47 * @brief construct an Interest according to the query abstraction
48 */
49 Interest
50 toInterest() const;
51
52 /**
53 * @brief extract the query information (rrLabel, rrType) from a Interest
Alexander Afanasyevdf2e9392016-03-10 11:50:53 -080054 *
Alexander Afanasyevdf2e9392016-03-10 11:50:53 -080055 * @param zone NDNS zone
Yumin Xia6343c5b2016-10-20 15:45:50 -070056 * @param interest The Interest to parse; the Interest must have correct zone,
Alexander Afanasyevdf2e9392016-03-10 11:50:53 -080057 * otherwise it's undefined behavior
Shock Jiang01712f32014-10-01 14:34:16 -070058 */
59 bool
Yumin Xia6343c5b2016-10-20 15:45:50 -070060 fromInterest(const Name& zone, const Interest& interest);
Shock Jiang01712f32014-10-01 14:34:16 -070061
62 bool
63 operator==(const Query& other) const
64 {
Yumin Xia6343c5b2016-10-20 15:45:50 -070065 return (getZone() == other.getZone() &&
Shock Jiang01712f32014-10-01 14:34:16 -070066 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 /**
Shock Jiang01712f32014-10-01 14:34:16 -070079 * @brief get name of authoritative zone
80 */
81 const Name&
82 getZone() const
83 {
84 return m_zone;
85 }
86
87 /**
88 * @brief set name of authoritative zone
89 */
90 void
91 setZone(const Name& zone)
92 {
93 m_zone = zone;
94 }
95
96 /**
97 * @brief get lifetime of the Interest
98 */
99 const time::milliseconds&
100 getInterestLifetime() const
101 {
102 return m_interestLifetime;
103 }
104
105 /**
106 * @brief set lifetime of the Interest
107 */
108 void
109 setInterestLifetime(const time::milliseconds& interestLifetime)
110 {
111 m_interestLifetime = interestLifetime;
112 }
113
114
115 /**
116 * @brief get query type
117 */
118 const name::Component&
119 getQueryType() const
120 {
121 return m_queryType;
122 }
123
124 /**
125 * @brief get query type
126 */
127 void
128 setQueryType(const name::Component& queryType)
129 {
130 m_queryType = queryType;
131 }
132
133 /**
134 * @brief get label of resource record
135 */
136 const Name&
137 getRrLabel() const
138 {
139 return m_rrLabel;
140 }
141
142 /**
143 * @brief set label of resource record
144 */
145 void
146 setRrLabel(const Name& rrLabel)
147 {
148 m_rrLabel = rrLabel;
149 }
150
151 /**
152 * @brief get type resource record
153 */
154 const name::Component&
155 getRrType() const
156 {
157 return m_rrType;
158 }
159
160 /**
161 * @brief set type resource record
162 */
163 void
164 setRrType(const name::Component& rrType)
165 {
166 m_rrType = rrType;
167 }
168
Yumin Xia4e561892016-10-21 10:48:01 -0700169 /**
170 * @brief set link object
171 */
172 void
173 setLink(const Block& link)
174 {
175 m_link = link;
176 }
177
178 /**
179 * @brief get Link object
180 */
181 const Block&
182 getLink() const
183 {
184 return m_link;
185 }
186
Shock Jiang01712f32014-10-01 14:34:16 -0700187private:
Shock Jiang01712f32014-10-01 14:34:16 -0700188 Name m_zone;
189 name::Component m_queryType;
190 Name m_rrLabel;
191 name::Component m_rrType;
192 time::milliseconds m_interestLifetime;
Yumin Xia4e561892016-10-21 10:48:01 -0700193 Block m_link;
Shock Jiang01712f32014-10-01 14:34:16 -0700194};
195
196std::ostream&
197operator<<(std::ostream& os, const Query& query);
198
199} // namespace ndns
200} // namespace ndn
201
202#endif // NDNS_CLIENTS_QUERY_HPP