Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014, Regents of the University of California. |
| 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_QUERY_HPP |
| 21 | #define NDNS_QUERY_HPP |
| 22 | |
| 23 | #include "rr.hpp" |
| 24 | |
| 25 | #include <ndn-cxx/name.hpp> |
| 26 | |
| 27 | namespace ndn { |
| 28 | namespace ndns { |
| 29 | |
| 30 | class Query |
| 31 | { |
| 32 | public: |
| 33 | |
| 34 | enum QueryType { |
| 35 | QUERY_DNS, |
| 36 | QUERY_DNS_R |
| 37 | }; |
| 38 | |
shockjiang | a5ae48c | 2014-07-27 23:21:41 -0700 | [diff] [blame^] | 39 | static std::string |
| 40 | toString(const QueryType& qType) |
| 41 | { |
| 42 | std::string label; |
| 43 | switch (qType) |
| 44 | { |
| 45 | case QUERY_DNS: |
| 46 | label = "DNS"; |
| 47 | break; |
| 48 | case QUERY_DNS_R: |
| 49 | label = "DNS-R"; |
| 50 | break; |
| 51 | default: |
| 52 | label = "Default"; |
| 53 | break; |
| 54 | } |
| 55 | return label; |
| 56 | |
| 57 | } |
| 58 | |
| 59 | static const QueryType |
| 60 | toQueryType(const std::string& str) |
| 61 | { |
| 62 | QueryType atype; |
| 63 | if (str == "DNS") { |
| 64 | atype = QUERY_DNS; |
| 65 | } |
| 66 | else if (str == "DNS-R") { |
| 67 | atype = QUERY_DNS_R; |
| 68 | } |
| 69 | else { |
| 70 | atype = QUERY_DNS; |
| 71 | } |
| 72 | return atype; |
| 73 | } |
| 74 | |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 75 | Query(); |
| 76 | |
| 77 | virtual ~Query(); |
| 78 | |
| 79 | const Name& getAuthorityZone() const { |
| 80 | return m_authorityZone; |
| 81 | } |
| 82 | |
| 83 | void setAuthorityZone(const Name& authorityZone) { |
| 84 | m_authorityZone = authorityZone; |
| 85 | } |
| 86 | |
| 87 | time::milliseconds getInterestLifetime() const { |
| 88 | return m_interestLifetime; |
| 89 | } |
| 90 | |
| 91 | void setInterestLifetime(time::milliseconds interestLifetime) { |
| 92 | m_interestLifetime = interestLifetime; |
| 93 | } |
| 94 | |
| 95 | enum QueryType getQueryType() const { |
| 96 | return m_queryType; |
| 97 | } |
| 98 | |
| 99 | void setQueryType(enum QueryType queryType) { |
| 100 | m_queryType = queryType; |
| 101 | } |
| 102 | |
| 103 | const Name& getRrLabel() const { |
| 104 | return m_rrLabel; |
| 105 | } |
| 106 | |
| 107 | void setRrLabel(const Name& rrLabel) { |
| 108 | m_rrLabel = rrLabel; |
| 109 | } |
| 110 | |
shockjiang | a5ae48c | 2014-07-27 23:21:41 -0700 | [diff] [blame^] | 111 | const RR::RRType& getRrType() const { |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 112 | return m_rrType; |
| 113 | } |
| 114 | |
shockjiang | a5ae48c | 2014-07-27 23:21:41 -0700 | [diff] [blame^] | 115 | void setRrType(const RR::RRType& rrType) { |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 116 | m_rrType = rrType; |
| 117 | } |
| 118 | |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 119 | |
| 120 | private: |
| 121 | template<bool T> |
| 122 | size_t |
| 123 | wireEncode(EncodingImpl<T> & block) const; |
| 124 | |
| 125 | public: |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 126 | Interest |
shockjiang | a5ae48c | 2014-07-27 23:21:41 -0700 | [diff] [blame^] | 127 | toInterest() const; |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 128 | |
shockjiang | a5ae48c | 2014-07-27 23:21:41 -0700 | [diff] [blame^] | 129 | bool |
| 130 | fromInterest(const Name &name, const Interest& interest); |
| 131 | |
| 132 | bool |
| 133 | fromInterest(const Interest& interest); |
| 134 | |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 135 | |
| 136 | public: |
| 137 | Name m_authorityZone; |
| 138 | enum QueryType m_queryType; |
| 139 | time::milliseconds m_interestLifetime; |
| 140 | Name m_rrLabel; |
shockjiang | a5ae48c | 2014-07-27 23:21:41 -0700 | [diff] [blame^] | 141 | enum RR::RRType m_rrType; |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 142 | |
| 143 | mutable Block m_wire; |
| 144 | }; |
| 145 | |
shockjiang | a5ae48c | 2014-07-27 23:21:41 -0700 | [diff] [blame^] | 146 | |
| 147 | inline std::ostream& |
| 148 | operator<<(std::ostream& os, const Query& query) |
| 149 | { |
| 150 | os<<"Query: authorityZone="<<query.getAuthorityZone().toUri() |
| 151 | <<" queryType="<<Query::toString(query.getQueryType()) |
| 152 | <<" rrLabel="<<query.getRrLabel().toUri() |
| 153 | <<" rrType="<<RR::toString(query.getRrType()); |
| 154 | return os; |
| 155 | } |
| 156 | |
| 157 | |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 158 | } // namespace ndns |
| 159 | } // namespace ndn |
| 160 | |
| 161 | #endif // NDNS_QUERY_HPP |