Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Yumin Xia | 6343c5b | 2016-10-20 15:45:50 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California. |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 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> |
Yumin Xia | 4e56189 | 2016-10-21 10:48:01 -0700 | [diff] [blame] | 27 | #include <ndn-cxx/link.hpp> |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 28 | |
| 29 | namespace ndn { |
| 30 | namespace ndns { |
| 31 | |
| 32 | /** |
Alexander Afanasyev | df2e939 | 2016-03-10 11:50:53 -0800 | [diff] [blame] | 33 | * @brief NDNS Query abstraction |
| 34 | * |
| 35 | * Query is an Interest whose name follows the format: |
| 36 | * |
Yumin Xia | 6343c5b | 2016-10-20 15:45:50 -0700 | [diff] [blame] | 37 | * <zone> [<KEY>|<NDNS>|<NDNS-R>] <rrLabel> <rrType> |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 38 | */ |
| 39 | class Query : noncopyable |
| 40 | { |
| 41 | public: |
| 42 | Query(); |
| 43 | |
Yumin Xia | 6343c5b | 2016-10-20 15:45:50 -0700 | [diff] [blame] | 44 | Query(const Name& zone, const name::Component& queryType); |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 45 | |
| 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 Afanasyev | df2e939 | 2016-03-10 11:50:53 -0800 | [diff] [blame] | 54 | * |
Alexander Afanasyev | df2e939 | 2016-03-10 11:50:53 -0800 | [diff] [blame] | 55 | * @param zone NDNS zone |
Yumin Xia | 6343c5b | 2016-10-20 15:45:50 -0700 | [diff] [blame] | 56 | * @param interest The Interest to parse; the Interest must have correct zone, |
Alexander Afanasyev | df2e939 | 2016-03-10 11:50:53 -0800 | [diff] [blame] | 57 | * otherwise it's undefined behavior |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 58 | */ |
| 59 | bool |
Yumin Xia | 6343c5b | 2016-10-20 15:45:50 -0700 | [diff] [blame] | 60 | fromInterest(const Name& zone, const Interest& interest); |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 61 | |
| 62 | bool |
| 63 | operator==(const Query& other) const |
| 64 | { |
Yumin Xia | 6343c5b | 2016-10-20 15:45:50 -0700 | [diff] [blame] | 65 | return (getZone() == other.getZone() && |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 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 | |
| 76 | public: |
| 77 | |
| 78 | /** |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 79 | * @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 Xia | 4e56189 | 2016-10-21 10:48:01 -0700 | [diff] [blame] | 169 | /** |
| 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 Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 187 | private: |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 188 | Name m_zone; |
| 189 | name::Component m_queryType; |
| 190 | Name m_rrLabel; |
| 191 | name::Component m_rrType; |
| 192 | time::milliseconds m_interestLifetime; |
Yumin Xia | 4e56189 | 2016-10-21 10:48:01 -0700 | [diff] [blame] | 193 | Block m_link; |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 194 | }; |
| 195 | |
| 196 | std::ostream& |
| 197 | operator<<(std::ostream& os, const Query& query); |
| 198 | |
| 199 | } // namespace ndns |
| 200 | } // namespace ndn |
| 201 | |
| 202 | #endif // NDNS_CLIENTS_QUERY_HPP |