blob: 61b1cffe9150f759a173806c21c9a01aac613313 [file] [log] [blame]
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -07001/* -*- 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
27namespace ndn {
28namespace ndns {
29
30class Query
31{
32public:
33
34 enum QueryType {
35 QUERY_DNS,
36 QUERY_DNS_R
37 };
38
shockjianga5ae48c2014-07-27 23:21:41 -070039 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 Afanasyev6e3d1ac2014-07-21 12:47:49 -070075 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
shockjianga5ae48c2014-07-27 23:21:41 -0700111 const RR::RRType& getRrType() const {
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700112 return m_rrType;
113 }
114
shockjianga5ae48c2014-07-27 23:21:41 -0700115 void setRrType(const RR::RRType& rrType) {
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700116 m_rrType = rrType;
117 }
118
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700119
120private:
121 template<bool T>
122 size_t
123 wireEncode(EncodingImpl<T> & block) const;
124
125public:
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700126 Interest
shockjianga5ae48c2014-07-27 23:21:41 -0700127 toInterest() const;
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700128
shockjianga5ae48c2014-07-27 23:21:41 -0700129 bool
130 fromInterest(const Name &name, const Interest& interest);
131
132 bool
133 fromInterest(const Interest& interest);
134
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700135
136public:
137 Name m_authorityZone;
138 enum QueryType m_queryType;
139 time::milliseconds m_interestLifetime;
140 Name m_rrLabel;
shockjianga5ae48c2014-07-27 23:21:41 -0700141 enum RR::RRType m_rrType;
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700142
143 mutable Block m_wire;
144};
145
shockjianga5ae48c2014-07-27 23:21:41 -0700146
147inline std::ostream&
148operator<<(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 Afanasyev6e3d1ac2014-07-21 12:47:49 -0700158} // namespace ndns
159} // namespace ndn
160
161#endif // NDNS_QUERY_HPP