blob: 2caffb19032bf527bf97061eb7d532918a690244 [file] [log] [blame]
Jeff Thompson25b4e612013-10-10 16:03:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Jeff Thompson47eecfc2013-07-07 22:56:46 -07002/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07003 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson47eecfc2013-07-07 22:56:46 -07005 * See COPYING for copyright and distribution information.
Jeff Thompsonb7f95562013-07-03 18:36:42 -07006 */
7
Jeff Thompsonfe556862013-07-09 13:52:55 -07008#include <stdexcept>
Jeff Thompson25b4e612013-10-10 16:03:24 -07009#include <ndn-cpp/common.hpp>
10#include <ndn-cpp/interest.hpp>
Jeff Thompsonb7f95562013-07-03 18:36:42 -070011
12using namespace std;
13
14namespace ndn {
Alexander Afanasyev84681982014-01-03 13:26:09 -080015
16bool
17Interest::matchesName(const Name &name) const
Jeff Thompson25b4e612013-10-10 16:03:24 -070018{
Alexander Afanasyev84681982014-01-03 13:26:09 -080019 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 Thompson25b4e612013-10-10 16:03:24 -070037}
38
Alexander Afanasyev84681982014-01-03 13:26:09 -080039std::ostream &
40operator << (std::ostream &os, const Interest &interest)
Jeff Thompsonfe556862013-07-09 13:52:55 -070041{
Alexander Afanasyev84681982014-01-03 13:26:09 -080042 os << interest.getName();
Jeff Thompsonfe556862013-07-09 13:52:55 -070043
Alexander Afanasyev84681982014-01-03 13:26:09 -080044 char delim = '?';
45
46 if (interest.getMinSuffixComponents() >= 0) {
47 os << delim << "ndn.MinSuffixComponents=" << interest.getMinSuffixComponents();
48 delim = '&';
Jeff Thompsonfe556862013-07-09 13:52:55 -070049 }
Alexander Afanasyev84681982014-01-03 13:26:09 -080050 if (interest.getMaxSuffixComponents() >= 0) {
51 os << delim << "ndn.MaxSuffixComponents=" << interest.getMaxSuffixComponents();
52 delim = '&';
Jeff Thompson37527d62013-08-21 11:15:54 -070053 }
Alexander Afanasyev84681982014-01-03 13:26:09 -080054 if (interest.getChildSelector() >= 0) {
55 os << delim << "ndn.ChildSelector=" << interest.getChildSelector();
56 delim = '&';
Jeff Thompson13e280b2013-12-03 13:12:23 -080057 }
Alexander Afanasyev84681982014-01-03 13:26:09 -080058 if (interest.getMustBeFresh()) {
59 os << delim << "ndn.MustBeFresh=" << interest.getMustBeFresh();
60 delim = '&';
Jeff Thompson13e280b2013-12-03 13:12:23 -080061 }
Alexander Afanasyev84681982014-01-03 13:26:09 -080062 if (interest.getScope() >= 0) {
63 os << delim << "ndn.Scope=" << interest.getScope();
64 delim = '&';
Jeff Thompson13e280b2013-12-03 13:12:23 -080065 }
Alexander Afanasyev84681982014-01-03 13:26:09 -080066 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 Thompson13e280b2013-12-03 13:12:23 -080081}
82
Jeff Thompsonb7f95562013-07-03 18:36:42 -070083}