Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 2 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 5 | * See COPYING for copyright and distribution information. |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 8 | #include <stdexcept> |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 9 | #include <ndn-cpp/common.hpp> |
| 10 | #include <ndn-cpp/interest.hpp> |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 11 | |
| 12 | using namespace std; |
| 13 | |
| 14 | namespace ndn { |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame^] | 15 | |
| 16 | bool |
| 17 | Interest::matchesName(const Name &name) const |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 18 | { |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame^] | 19 | if (!name_.isPrefixOf(name)) |
| 20 | return false; |
| 21 | |
| 22 | if (minSuffixComponents_ >= 0 && |
| 23 | // Add 1 for the implicit digest. |
| 24 | !(name.size() + 1 - name_.size() >= minSuffixComponents_)) |
| 25 | return false; |
| 26 | |
| 27 | if (maxSuffixComponents_ >= 0 && |
| 28 | // Add 1 for the implicit digest. |
| 29 | !(name.size() + 1 - name_.size() <= maxSuffixComponents_)) |
| 30 | return false; |
| 31 | |
| 32 | if (!exclude_.empty() && name.size() > name_.size() && |
| 33 | exclude_.isExcluded(name[name_.size()])) |
| 34 | return false; |
| 35 | |
| 36 | return true; |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame^] | 39 | std::ostream & |
| 40 | operator << (std::ostream &os, const Interest &interest) |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 41 | { |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame^] | 42 | os << interest.getName(); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 43 | |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame^] | 44 | char delim = '?'; |
| 45 | |
| 46 | if (interest.getMinSuffixComponents() >= 0) { |
| 47 | os << delim << "ndn.MinSuffixComponents=" << interest.getMinSuffixComponents(); |
| 48 | delim = '&'; |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 49 | } |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame^] | 50 | if (interest.getMaxSuffixComponents() >= 0) { |
| 51 | os << delim << "ndn.MaxSuffixComponents=" << interest.getMaxSuffixComponents(); |
| 52 | delim = '&'; |
Jeff Thompson | 37527d6 | 2013-08-21 11:15:54 -0700 | [diff] [blame] | 53 | } |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame^] | 54 | if (interest.getChildSelector() >= 0) { |
| 55 | os << delim << "ndn.ChildSelector=" << interest.getChildSelector(); |
| 56 | delim = '&'; |
Jeff Thompson | 13e280b | 2013-12-03 13:12:23 -0800 | [diff] [blame] | 57 | } |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame^] | 58 | if (interest.getMustBeFresh()) { |
| 59 | os << delim << "ndn.MustBeFresh=" << interest.getMustBeFresh(); |
| 60 | delim = '&'; |
Jeff Thompson | 13e280b | 2013-12-03 13:12:23 -0800 | [diff] [blame] | 61 | } |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame^] | 62 | if (interest.getScope() >= 0) { |
| 63 | os << delim << "ndn.Scope=" << interest.getScope(); |
| 64 | delim = '&'; |
Jeff Thompson | 13e280b | 2013-12-03 13:12:23 -0800 | [diff] [blame] | 65 | } |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame^] | 66 | if (interest.getInterestLifetime() >= 0) { |
| 67 | os << delim << "ndn.InterestLifetime=" << interest.getInterestLifetime(); |
| 68 | delim = '&'; |
| 69 | } |
| 70 | |
| 71 | if (interest.getNonce() > 0) { |
| 72 | os << delim << "ndn.Nonce=" << interest.getNonce(); |
| 73 | delim = '&'; |
| 74 | } |
| 75 | if (!interest.getExclude().empty()) { |
| 76 | os << delim << "ndn.Exclude=" << interest.getExclude(); |
| 77 | delim = '&'; |
| 78 | } |
| 79 | |
| 80 | return os; |
Jeff Thompson | 13e280b | 2013-12-03 13:12:23 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 83 | } |