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. |
shockjiang | e9c1ab9 | 2014-07-21 12:02:52 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 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/>. |
shockjiang | e9c1ab9 | 2014-07-21 12:02:52 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 20 | #include "query.hpp" |
shockjiang | e9c1ab9 | 2014-07-21 12:02:52 -0700 | [diff] [blame] | 21 | |
| 22 | namespace ndn { |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 23 | namespace ndns { |
shockjiang | e9c1ab9 | 2014-07-21 12:02:52 -0700 | [diff] [blame] | 24 | |
| 25 | Query::Query() |
shockjiang | a5ae48c | 2014-07-27 23:21:41 -0700 | [diff] [blame^] | 26 | : m_queryType (QUERY_DNS) |
| 27 | , m_interestLifetime(time::milliseconds(4000)) |
| 28 | , m_rrType(RR::NS) |
shockjiang | e9c1ab9 | 2014-07-21 12:02:52 -0700 | [diff] [blame] | 29 | { |
shockjiang | e9c1ab9 | 2014-07-21 12:02:52 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | Query::~Query() { |
shockjiang | e9c1ab9 | 2014-07-21 12:02:52 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | |
shockjiang | a5ae48c | 2014-07-27 23:21:41 -0700 | [diff] [blame^] | 36 | bool |
| 37 | Query::fromInterest(const Name &name, const Interest &interest) |
| 38 | { |
| 39 | return fromInterest(interest); |
| 40 | } |
| 41 | |
| 42 | bool |
| 43 | Query::fromInterest(const Interest& interest) |
shockjiang | e9c1ab9 | 2014-07-21 12:02:52 -0700 | [diff] [blame] | 44 | { |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 45 | Name interestName; |
| 46 | interestName = interest.getName(); |
shockjiang | e9c1ab9 | 2014-07-21 12:02:52 -0700 | [diff] [blame] | 47 | |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 48 | int qtflag = -1; |
| 49 | size_t len = interestName.size(); |
| 50 | for (size_t i=0; i<len; i++) |
shockjiang | e9c1ab9 | 2014-07-21 12:02:52 -0700 | [diff] [blame] | 51 | { |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 52 | std::string comp = interestName.get(i).toUri(); |
| 53 | if (comp == toString(QUERY_DNS) || comp == toString(QUERY_DNS_R)) |
| 54 | { |
| 55 | qtflag = i; |
| 56 | break; |
| 57 | } |
shockjiang | e9c1ab9 | 2014-07-21 12:02:52 -0700 | [diff] [blame] | 58 | }//for |
| 59 | |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 60 | if (qtflag == -1) |
shockjiang | e9c1ab9 | 2014-07-21 12:02:52 -0700 | [diff] [blame] | 61 | { |
shockjiang | a5ae48c | 2014-07-27 23:21:41 -0700 | [diff] [blame^] | 62 | std::cerr << "There is no QueryType in the Interest Name: "<< interestName << std::endl; |
| 63 | return false; |
shockjiang | e9c1ab9 | 2014-07-21 12:02:52 -0700 | [diff] [blame] | 64 | } |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 65 | this->m_queryType = toQueryType(interestName.get(qtflag).toUri()); |
shockjiang | a5ae48c | 2014-07-27 23:21:41 -0700 | [diff] [blame^] | 66 | this->m_rrType = RR::toRRType(interestName.get(len-1).toUri()); |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 67 | this->m_authorityZone = interestName.getPrefix(qtflag); //the DNS/DNS-R is not included |
| 68 | this->m_interestLifetime = interest.getInterestLifetime(); |
shockjiang | a5ae48c | 2014-07-27 23:21:41 -0700 | [diff] [blame^] | 69 | this->m_rrLabel = interestName.getSubName(qtflag+1, len-qtflag-2); |
| 70 | return true; |
shockjiang | e9c1ab9 | 2014-07-21 12:02:52 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | Interest |
shockjiang | a5ae48c | 2014-07-27 23:21:41 -0700 | [diff] [blame^] | 74 | Query::toInterest() const |
shockjiang | e9c1ab9 | 2014-07-21 12:02:52 -0700 | [diff] [blame] | 75 | { |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 76 | Name name = this->m_authorityZone; |
| 77 | name.append(toString(this->m_queryType)); |
| 78 | name.append(this->m_rrLabel); |
shockjiang | a5ae48c | 2014-07-27 23:21:41 -0700 | [diff] [blame^] | 79 | name.append(RR::toString(this->m_rrType)); |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 80 | Selectors selector; |
| 81 | //selector.setMustBeFresh(true); |
shockjiang | e9c1ab9 | 2014-07-21 12:02:52 -0700 | [diff] [blame] | 82 | |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 83 | Interest interest = Interest(name, selector, -1, this->m_interestLifetime); |
| 84 | return interest; |
shockjiang | e9c1ab9 | 2014-07-21 12:02:52 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame] | 87 | } // namespace ndns |
| 88 | } // namespace ndn |