Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame^] | 2 | /* |
| 3 | * Copyright (c) 2014-2017, 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 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame^] | 62 | void |
| 63 | setDelegationListFromLink(const Link& link); |
| 64 | |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 65 | bool |
| 66 | operator==(const Query& other) const |
| 67 | { |
Yumin Xia | 6343c5b | 2016-10-20 15:45:50 -0700 | [diff] [blame] | 68 | return (getZone() == other.getZone() && |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 69 | 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 | |
| 79 | public: |
| 80 | |
| 81 | /** |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 82 | * @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 Xia | 4e56189 | 2016-10-21 10:48:01 -0700 | [diff] [blame] | 172 | /** |
| 173 | * @brief set link object |
| 174 | */ |
| 175 | void |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame^] | 176 | setDelegationList(const DelegationList& delegations) |
Yumin Xia | 4e56189 | 2016-10-21 10:48:01 -0700 | [diff] [blame] | 177 | { |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame^] | 178 | m_delegationList = delegations; |
Yumin Xia | 4e56189 | 2016-10-21 10:48:01 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /** |
| 182 | * @brief get Link object |
| 183 | */ |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame^] | 184 | const DelegationList& |
| 185 | getDelegationList() const |
Yumin Xia | 4e56189 | 2016-10-21 10:48:01 -0700 | [diff] [blame] | 186 | { |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame^] | 187 | return m_delegationList; |
Yumin Xia | 4e56189 | 2016-10-21 10:48:01 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 190 | private: |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 191 | Name m_zone; |
| 192 | name::Component m_queryType; |
| 193 | Name m_rrLabel; |
| 194 | name::Component m_rrType; |
| 195 | time::milliseconds m_interestLifetime; |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame^] | 196 | DelegationList m_delegationList; |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 197 | }; |
| 198 | |
| 199 | std::ostream& |
| 200 | operator<<(std::ostream& os, const Query& query); |
| 201 | |
| 202 | } // namespace ndns |
| 203 | } // namespace ndn |
| 204 | |
| 205 | #endif // NDNS_CLIENTS_QUERY_HPP |