blob: bf76684b4175efd64a86132115f70ed94f8c99a8 [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>
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 *
Yumin Xia6343c5b2016-10-20 15:45:50 -070036 * <zone> [<KEY>|<NDNS>|<NDNS-R>] <rrLabel> <rrType>
Shock Jiang01712f32014-10-01 14:34:16 -070037 */
38class Query : noncopyable
39{
40public:
41 Query();
42
Yumin Xia6343c5b2016-10-20 15:45:50 -070043 Query(const Name& zone, const name::Component& queryType);
Shock Jiang01712f32014-10-01 14:34:16 -070044
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 *
Alexander Afanasyevdf2e9392016-03-10 11:50:53 -080054 * @param zone NDNS zone
Yumin Xia6343c5b2016-10-20 15:45:50 -070055 * @param interest The Interest to parse; the Interest must have correct zone,
Alexander Afanasyevdf2e9392016-03-10 11:50:53 -080056 * otherwise it's undefined behavior
Shock Jiang01712f32014-10-01 14:34:16 -070057 */
58 bool
Yumin Xia6343c5b2016-10-20 15:45:50 -070059 fromInterest(const Name& zone, const Interest& interest);
Shock Jiang01712f32014-10-01 14:34:16 -070060
61 bool
62 operator==(const Query& other) const
63 {
Yumin Xia6343c5b2016-10-20 15:45:50 -070064 return (getZone() == other.getZone() &&
Shock Jiang01712f32014-10-01 14:34:16 -070065 getQueryType() == other.getQueryType() && getRrLabel() == other.getRrLabel() &&
66 getRrType() == other.getRrType());
67 }
68
69 bool
70 operator!=(const Query& other) const
71 {
72 return !(*this == other);
73 }
74
75public:
76
77 /**
Shock Jiang01712f32014-10-01 14:34:16 -070078 * @brief get name of authoritative zone
79 */
80 const Name&
81 getZone() const
82 {
83 return m_zone;
84 }
85
86 /**
87 * @brief set name of authoritative zone
88 */
89 void
90 setZone(const Name& zone)
91 {
92 m_zone = zone;
93 }
94
95 /**
96 * @brief get lifetime of the Interest
97 */
98 const time::milliseconds&
99 getInterestLifetime() const
100 {
101 return m_interestLifetime;
102 }
103
104 /**
105 * @brief set lifetime of the Interest
106 */
107 void
108 setInterestLifetime(const time::milliseconds& interestLifetime)
109 {
110 m_interestLifetime = interestLifetime;
111 }
112
113
114 /**
115 * @brief get query type
116 */
117 const name::Component&
118 getQueryType() const
119 {
120 return m_queryType;
121 }
122
123 /**
124 * @brief get query type
125 */
126 void
127 setQueryType(const name::Component& queryType)
128 {
129 m_queryType = queryType;
130 }
131
132 /**
133 * @brief get label of resource record
134 */
135 const Name&
136 getRrLabel() const
137 {
138 return m_rrLabel;
139 }
140
141 /**
142 * @brief set label of resource record
143 */
144 void
145 setRrLabel(const Name& rrLabel)
146 {
147 m_rrLabel = rrLabel;
148 }
149
150 /**
151 * @brief get type resource record
152 */
153 const name::Component&
154 getRrType() const
155 {
156 return m_rrType;
157 }
158
159 /**
160 * @brief set type resource record
161 */
162 void
163 setRrType(const name::Component& rrType)
164 {
165 m_rrType = rrType;
166 }
167
168private:
Shock Jiang01712f32014-10-01 14:34:16 -0700169 Name m_zone;
170 name::Component m_queryType;
171 Name m_rrLabel;
172 name::Component m_rrType;
173 time::milliseconds m_interestLifetime;
174};
175
176std::ostream&
177operator<<(std::ostream& os, const Query& query);
178
179} // namespace ndns
180} // namespace ndn
181
182#endif // NDNS_CLIENTS_QUERY_HPP