blob: 0a736dc97434bfe620e78b8174c16d086fc8d5c4 [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();
22 for (unsigned int i = 0; i < excludeStruct.nEntries; ++i)
23 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();
30 for (unsigned int i = 0; i < excludeStruct.nEntries; ++i) {
31 ndn_ExcludeEntry *entry = &excludeStruct.entries[i];
32
33 if (entry->type == ndn_Exclude_COMPONENT)
Jeff Thompson38d0e082013-08-12 18:07:44 -070034 addComponent(entry->component.value, entry->component.valueLength);
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 Thompson412226d2013-09-12 15:55:46 -070076 nonce_ = Blob(interestStruct.nonce, interestStruct.nonceLength);
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 Thompsond9e278c2013-07-08 15:20:13 -070091
92 interestStruct.nonceLength = nonce_.size();
93 if (nonce_.size() > 0)
Jeff Thompson10ad12a2013-09-24 16:19:11 -070094 interestStruct.nonce = (uint8_t *)nonce_.buf();
Jeff Thompsond9e278c2013-07-08 15:20:13 -070095 else
96 interestStruct.nonce = 0;
97}
Jeff Thompsonb7f95562013-07-03 18:36:42 -070098
99}
100