blob: b2ab0245dc0b4fc770ad9b28d36fb631218c3223 [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>
11#include "c/interest.h"
Jeff Thompsonb7f95562013-07-03 18:36:42 -070012
13using namespace std;
14
15namespace ndn {
16
Jeff Thompson0050abe2013-09-17 12:50:25 -070017void
Jeff Thompson25b4e612013-10-10 16:03:24 -070018ExcludeEntry::get(struct ndn_ExcludeEntry& excludeEntryStruct) const
19{
20 excludeEntryStruct.type = type_;
21 if (type_ == ndn_Exclude_COMPONENT)
22 component_.get(excludeEntryStruct.component);
23}
24
25void
Jeff Thompson0050abe2013-09-17 12:50:25 -070026Exclude::get(struct ndn_Exclude& excludeStruct) const
Jeff Thompsonfe556862013-07-09 13:52:55 -070027{
28 if (excludeStruct.maxEntries < entries_.size())
29 throw runtime_error("excludeStruct.maxEntries must be >= this exclude getEntryCount()");
30
31 excludeStruct.nEntries = entries_.size();
Jeff Thompson97223af2013-09-24 17:01:27 -070032 for (size_t i = 0; i < excludeStruct.nEntries; ++i)
Jeff Thompsonfe556862013-07-09 13:52:55 -070033 entries_[i].get(excludeStruct.entries[i]);
34}
35
Jeff Thompson0050abe2013-09-17 12:50:25 -070036void
37Exclude::set(const struct ndn_Exclude& excludeStruct)
Jeff Thompsonfe556862013-07-09 13:52:55 -070038{
39 entries_.clear();
Jeff Thompson97223af2013-09-24 17:01:27 -070040 for (size_t i = 0; i < excludeStruct.nEntries; ++i) {
Jeff Thompsonfe556862013-07-09 13:52:55 -070041 ndn_ExcludeEntry *entry = &excludeStruct.entries[i];
42
43 if (entry->type == ndn_Exclude_COMPONENT)
Jeff Thompson3a715632013-10-31 11:36:35 -070044 appendComponent(entry->component.value.value, entry->component.value.length);
Jeff Thompsonfe556862013-07-09 13:52:55 -070045 else if (entry->type == ndn_Exclude_ANY)
Jeff Thompson3a715632013-10-31 11:36:35 -070046 appendAny();
Jeff Thompsonfe556862013-07-09 13:52:55 -070047 else
48 throw runtime_error("unrecognized ndn_ExcludeType");
49 }
50}
51
Jeff Thompson0050abe2013-09-17 12:50:25 -070052string
53Exclude::toUri() const
Jeff Thompson37527d62013-08-21 11:15:54 -070054{
Jeff Thompsone589c3f2013-10-12 17:30:50 -070055 if (entries_.size() == 0)
56 return "";
Jeff Thompson37527d62013-08-21 11:15:54 -070057
58 ostringstream result;
59 for (unsigned i = 0; i < entries_.size(); ++i) {
60 if (i > 0)
61 result << ",";
62
63 if (entries_[i].getType() == ndn_Exclude_ANY)
64 result << "*";
65 else
Jeff Thompson9bdb3b22013-09-12 12:42:13 -070066 Name::toEscapedString(*entries_[i].getComponent().getValue(), result);
Jeff Thompson37527d62013-08-21 11:15:54 -070067 }
68
69 return result.str();
70}
71
Jeff Thompson0050abe2013-09-17 12:50:25 -070072void
73Interest::set(const struct ndn_Interest& interestStruct)
Jeff Thompsonb7f95562013-07-03 18:36:42 -070074{
75 name_.set(interestStruct.name);
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070076 minSuffixComponents_ = interestStruct.minSuffixComponents;
77 maxSuffixComponents_ = interestStruct.maxSuffixComponents;
78
79 publisherPublicKeyDigest_.set(interestStruct.publisherPublicKeyDigest);
Jeff Thompsonfe556862013-07-09 13:52:55 -070080
81 exclude_.set(interestStruct.exclude);
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070082 childSelector_ = interestStruct.childSelector;
83 answerOriginKind_ = interestStruct.answerOriginKind;
84 scope_ = interestStruct.scope;
85 interestLifetimeMilliseconds_ = interestStruct.interestLifetimeMilliseconds;
Jeff Thompson93034532013-10-08 11:52:43 -070086 nonce_ = Blob(interestStruct.nonce);
Jeff Thompsonb7f95562013-07-03 18:36:42 -070087}
Jeff Thompsond9e278c2013-07-08 15:20:13 -070088
Jeff Thompson0050abe2013-09-17 12:50:25 -070089void
90Interest::get(struct ndn_Interest& interestStruct) const
Jeff Thompsond9e278c2013-07-08 15:20:13 -070091{
92 name_.get(interestStruct.name);
Jeff Thompsond9e278c2013-07-08 15:20:13 -070093 interestStruct.minSuffixComponents = minSuffixComponents_;
Jeff Thompsonf2e5e282013-07-08 15:26:16 -070094 interestStruct.maxSuffixComponents = maxSuffixComponents_;
Jeff Thompson8238d002013-07-10 11:56:49 -070095 publisherPublicKeyDigest_.get(interestStruct.publisherPublicKeyDigest);
Jeff Thompsonfe556862013-07-09 13:52:55 -070096 exclude_.get(interestStruct.exclude);
Jeff Thompsond9e278c2013-07-08 15:20:13 -070097 interestStruct.childSelector = childSelector_;
98 interestStruct.answerOriginKind = answerOriginKind_;
99 interestStruct.scope = scope_;
Jeff Thompson5a5e8b72013-07-11 14:28:03 -0700100 interestStruct.interestLifetimeMilliseconds = interestLifetimeMilliseconds_;
Jeff Thompson93034532013-10-08 11:52:43 -0700101 nonce_.get(interestStruct.nonce);
Jeff Thompsond9e278c2013-07-08 15:20:13 -0700102}
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700103
104}
105