blob: e1a6af7a9ccc30ef735a35439b79eb3fb529235c [file] [log] [blame]
Jeff Thompson47eecfc2013-07-07 22:56:46 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson47eecfc2013-07-07 22:56:46 -07004 * See COPYING for copyright and distribution information.
Jeff Thompsonb7f95562013-07-03 18:36:42 -07005 */
6
Jeff Thompsonfe556862013-07-09 13:52:55 -07007#include <stdexcept>
Jeff Thompson51dd5fd2013-07-10 19:27:18 -07008#include "common.hpp"
Jeff Thompson53412192013-08-06 13:35:50 -07009#include "interest.hpp"
Jeff Thompsonb7f95562013-07-03 18:36:42 -070010
11using namespace std;
12
13namespace ndn {
14
Jeff Thompson0050abe2013-09-17 12:50:25 -070015void
16Exclude::get(struct ndn_Exclude& excludeStruct) const
Jeff Thompsonfe556862013-07-09 13:52:55 -070017{
18 if (excludeStruct.maxEntries < entries_.size())
19 throw runtime_error("excludeStruct.maxEntries must be >= this exclude getEntryCount()");
20
21 excludeStruct.nEntries = entries_.size();
Jeff Thompson97223af2013-09-24 17:01:27 -070022 for (size_t i = 0; i < excludeStruct.nEntries; ++i)
Jeff Thompsonfe556862013-07-09 13:52:55 -070023 entries_[i].get(excludeStruct.entries[i]);
24}
25
Jeff Thompson0050abe2013-09-17 12:50:25 -070026void
27Exclude::set(const struct ndn_Exclude& excludeStruct)
Jeff Thompsonfe556862013-07-09 13:52:55 -070028{
29 entries_.clear();
Jeff Thompson97223af2013-09-24 17:01:27 -070030 for (size_t i = 0; i < excludeStruct.nEntries; ++i) {
Jeff Thompsonfe556862013-07-09 13:52:55 -070031 ndn_ExcludeEntry *entry = &excludeStruct.entries[i];
32
33 if (entry->type == ndn_Exclude_COMPONENT)
Jeff Thompson93034532013-10-08 11:52:43 -070034 addComponent(entry->component.value.value, entry->component.value.length);
Jeff Thompsonfe556862013-07-09 13:52:55 -070035 else if (entry->type == ndn_Exclude_ANY)
36 addAny();
37 else
38 throw runtime_error("unrecognized ndn_ExcludeType");
39 }
40}
41
Jeff Thompson0050abe2013-09-17 12:50:25 -070042string
43Exclude::toUri() const
Jeff Thompson37527d62013-08-21 11:15:54 -070044{
45 if (entries_.size() == 0)
46 return "";
47
48 ostringstream result;
49 for (unsigned i = 0; i < entries_.size(); ++i) {
50 if (i > 0)
51 result << ",";
52
53 if (entries_[i].getType() == ndn_Exclude_ANY)
54 result << "*";
55 else
Jeff Thompson9bdb3b22013-09-12 12:42:13 -070056 Name::toEscapedString(*entries_[i].getComponent().getValue(), result);
Jeff Thompson37527d62013-08-21 11:15:54 -070057 }
58
59 return result.str();
60}
61
Jeff Thompson0050abe2013-09-17 12:50:25 -070062void
63Interest::set(const struct ndn_Interest& interestStruct)
Jeff Thompsonb7f95562013-07-03 18:36:42 -070064{
65 name_.set(interestStruct.name);
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070066 minSuffixComponents_ = interestStruct.minSuffixComponents;
67 maxSuffixComponents_ = interestStruct.maxSuffixComponents;
68
69 publisherPublicKeyDigest_.set(interestStruct.publisherPublicKeyDigest);
Jeff Thompsonfe556862013-07-09 13:52:55 -070070
71 exclude_.set(interestStruct.exclude);
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070072 childSelector_ = interestStruct.childSelector;
73 answerOriginKind_ = interestStruct.answerOriginKind;
74 scope_ = interestStruct.scope;
75 interestLifetimeMilliseconds_ = interestStruct.interestLifetimeMilliseconds;
Jeff Thompson93034532013-10-08 11:52:43 -070076 nonce_ = Blob(interestStruct.nonce);
Jeff Thompsonb7f95562013-07-03 18:36:42 -070077}
Jeff Thompsond9e278c2013-07-08 15:20:13 -070078
Jeff Thompson0050abe2013-09-17 12:50:25 -070079void
80Interest::get(struct ndn_Interest& interestStruct) const
Jeff Thompsond9e278c2013-07-08 15:20:13 -070081{
82 name_.get(interestStruct.name);
Jeff Thompsond9e278c2013-07-08 15:20:13 -070083 interestStruct.minSuffixComponents = minSuffixComponents_;
Jeff Thompsonf2e5e282013-07-08 15:26:16 -070084 interestStruct.maxSuffixComponents = maxSuffixComponents_;
Jeff Thompson8238d002013-07-10 11:56:49 -070085 publisherPublicKeyDigest_.get(interestStruct.publisherPublicKeyDigest);
Jeff Thompsonfe556862013-07-09 13:52:55 -070086 exclude_.get(interestStruct.exclude);
Jeff Thompsond9e278c2013-07-08 15:20:13 -070087 interestStruct.childSelector = childSelector_;
88 interestStruct.answerOriginKind = answerOriginKind_;
89 interestStruct.scope = scope_;
Jeff Thompson5a5e8b72013-07-11 14:28:03 -070090 interestStruct.interestLifetimeMilliseconds = interestLifetimeMilliseconds_;
Jeff Thompson93034532013-10-08 11:52:43 -070091 nonce_.get(interestStruct.nonce);
Jeff Thompsond9e278c2013-07-08 15:20:13 -070092}
Jeff Thompsonb7f95562013-07-03 18:36:42 -070093
94}
95