blob: 6f8222bbd6decba124575bf3ea4ba16837226fa7 [file] [log] [blame]
Shock Jiang01712f32014-10-01 14:34:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Yumin Xia2c509c22017-02-09 14:37:36 -08002/*
3 * Copyright (c) 2014-2017, 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 Xia918343d2017-03-17 19:04:55 -070037 * <zone> [<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
Yumin Xia2c509c22017-02-09 14:37:36 -080062 void
63 setDelegationListFromLink(const Link& link);
64
Shock Jiang01712f32014-10-01 14:34:16 -070065 bool
66 operator==(const Query& other) const
67 {
Yumin Xia6343c5b2016-10-20 15:45:50 -070068 return (getZone() == other.getZone() &&
Shock Jiang01712f32014-10-01 14:34:16 -070069 getQueryType() == other.getQueryType() && getRrLabel() == other.getRrLabel() &&
70 getRrType() == other.getRrType());
71 }
72
73 bool
74 operator!=(const Query& other) const
75 {
76 return !(*this == other);
77 }
78
79public:
80
81 /**
Shock Jiang01712f32014-10-01 14:34:16 -070082 * @brief get name of authoritative zone
83 */
84 const Name&
85 getZone() const
86 {
87 return m_zone;
88 }
89
90 /**
91 * @brief set name of authoritative zone
92 */
93 void
94 setZone(const Name& zone)
95 {
96 m_zone = zone;
97 }
98
99 /**
100 * @brief get lifetime of the Interest
101 */
102 const time::milliseconds&
103 getInterestLifetime() const
104 {
105 return m_interestLifetime;
106 }
107
108 /**
109 * @brief set lifetime of the Interest
110 */
111 void
112 setInterestLifetime(const time::milliseconds& interestLifetime)
113 {
114 m_interestLifetime = interestLifetime;
115 }
116
117
118 /**
119 * @brief get query type
120 */
121 const name::Component&
122 getQueryType() const
123 {
124 return m_queryType;
125 }
126
127 /**
128 * @brief get query type
129 */
130 void
131 setQueryType(const name::Component& queryType)
132 {
133 m_queryType = queryType;
134 }
135
136 /**
137 * @brief get label of resource record
138 */
139 const Name&
140 getRrLabel() const
141 {
142 return m_rrLabel;
143 }
144
145 /**
146 * @brief set label of resource record
147 */
148 void
149 setRrLabel(const Name& rrLabel)
150 {
151 m_rrLabel = rrLabel;
152 }
153
154 /**
155 * @brief get type resource record
156 */
157 const name::Component&
158 getRrType() const
159 {
160 return m_rrType;
161 }
162
163 /**
164 * @brief set type resource record
165 */
166 void
167 setRrType(const name::Component& rrType)
168 {
169 m_rrType = rrType;
170 }
171
Yumin Xia4e561892016-10-21 10:48:01 -0700172 /**
173 * @brief set link object
174 */
175 void
Yumin Xia2c509c22017-02-09 14:37:36 -0800176 setDelegationList(const DelegationList& delegations)
Yumin Xia4e561892016-10-21 10:48:01 -0700177 {
Yumin Xia2c509c22017-02-09 14:37:36 -0800178 m_delegationList = delegations;
Yumin Xia4e561892016-10-21 10:48:01 -0700179 }
180
181 /**
182 * @brief get Link object
183 */
Yumin Xia2c509c22017-02-09 14:37:36 -0800184 const DelegationList&
185 getDelegationList() const
Yumin Xia4e561892016-10-21 10:48:01 -0700186 {
Yumin Xia2c509c22017-02-09 14:37:36 -0800187 return m_delegationList;
Yumin Xia4e561892016-10-21 10:48:01 -0700188 }
189
Shock Jiang01712f32014-10-01 14:34:16 -0700190private:
Shock Jiang01712f32014-10-01 14:34:16 -0700191 Name m_zone;
192 name::Component m_queryType;
193 Name m_rrLabel;
194 name::Component m_rrType;
195 time::milliseconds m_interestLifetime;
Yumin Xia2c509c22017-02-09 14:37:36 -0800196 DelegationList m_delegationList;
Shock Jiang01712f32014-10-01 14:34:16 -0700197};
198
199std::ostream&
200operator<<(std::ostream& os, const Query& query);
201
202} // namespace ndns
203} // namespace ndn
204
205#endif // NDNS_CLIENTS_QUERY_HPP