blob: 0fe5ce7fac02cb0ed5d24154f01a3c5cb5fd7619 [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 Thompson1656e6a2013-08-29 18:01:48 -070015void Exclude::get(struct ndn_Exclude& excludeStruct) const
Jeff Thompsonfe556862013-07-09 13:52:55 -070016{
17 if (excludeStruct.maxEntries < entries_.size())
18 throw runtime_error("excludeStruct.maxEntries must be >= this exclude getEntryCount()");
19
20 excludeStruct.nEntries = entries_.size();
21 for (unsigned int i = 0; i < excludeStruct.nEntries; ++i)
22 entries_[i].get(excludeStruct.entries[i]);
23}
24
Jeff Thompson1656e6a2013-08-29 18:01:48 -070025void Exclude::set(const struct ndn_Exclude& excludeStruct)
Jeff Thompsonfe556862013-07-09 13:52:55 -070026{
27 entries_.clear();
28 for (unsigned int i = 0; i < excludeStruct.nEntries; ++i) {
29 ndn_ExcludeEntry *entry = &excludeStruct.entries[i];
30
31 if (entry->type == ndn_Exclude_COMPONENT)
Jeff Thompson38d0e082013-08-12 18:07:44 -070032 addComponent(entry->component.value, entry->component.valueLength);
Jeff Thompsonfe556862013-07-09 13:52:55 -070033 else if (entry->type == ndn_Exclude_ANY)
34 addAny();
35 else
36 throw runtime_error("unrecognized ndn_ExcludeType");
37 }
38}
39
Jeff Thompson37527d62013-08-21 11:15:54 -070040string Exclude::toUri() const
41{
42 if (entries_.size() == 0)
43 return "";
44
45 ostringstream result;
46 for (unsigned i = 0; i < entries_.size(); ++i) {
47 if (i > 0)
48 result << ",";
49
50 if (entries_[i].getType() == ndn_Exclude_ANY)
51 result << "*";
52 else
Jeff Thompson9bdb3b22013-09-12 12:42:13 -070053 Name::toEscapedString(*entries_[i].getComponent().getValue(), result);
Jeff Thompson37527d62013-08-21 11:15:54 -070054 }
55
56 return result.str();
57}
58
Jeff Thompson1656e6a2013-08-29 18:01:48 -070059void Interest::set(const struct ndn_Interest& interestStruct)
Jeff Thompsonb7f95562013-07-03 18:36:42 -070060{
61 name_.set(interestStruct.name);
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070062 minSuffixComponents_ = interestStruct.minSuffixComponents;
63 maxSuffixComponents_ = interestStruct.maxSuffixComponents;
64
65 publisherPublicKeyDigest_.set(interestStruct.publisherPublicKeyDigest);
Jeff Thompsonfe556862013-07-09 13:52:55 -070066
67 exclude_.set(interestStruct.exclude);
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070068 childSelector_ = interestStruct.childSelector;
69 answerOriginKind_ = interestStruct.answerOriginKind;
70 scope_ = interestStruct.scope;
71 interestLifetimeMilliseconds_ = interestStruct.interestLifetimeMilliseconds;
Jeff Thompson412226d2013-09-12 15:55:46 -070072 nonce_ = Blob(interestStruct.nonce, interestStruct.nonceLength);
Jeff Thompsonb7f95562013-07-03 18:36:42 -070073}
Jeff Thompsond9e278c2013-07-08 15:20:13 -070074
Jeff Thompson1656e6a2013-08-29 18:01:48 -070075void Interest::get(struct ndn_Interest& interestStruct) const
Jeff Thompsond9e278c2013-07-08 15:20:13 -070076{
77 name_.get(interestStruct.name);
Jeff Thompsond9e278c2013-07-08 15:20:13 -070078 interestStruct.minSuffixComponents = minSuffixComponents_;
Jeff Thompsonf2e5e282013-07-08 15:26:16 -070079 interestStruct.maxSuffixComponents = maxSuffixComponents_;
Jeff Thompson8238d002013-07-10 11:56:49 -070080 publisherPublicKeyDigest_.get(interestStruct.publisherPublicKeyDigest);
Jeff Thompsonfe556862013-07-09 13:52:55 -070081 exclude_.get(interestStruct.exclude);
Jeff Thompsond9e278c2013-07-08 15:20:13 -070082 interestStruct.childSelector = childSelector_;
83 interestStruct.answerOriginKind = answerOriginKind_;
84 interestStruct.scope = scope_;
Jeff Thompson5a5e8b72013-07-11 14:28:03 -070085 interestStruct.interestLifetimeMilliseconds = interestLifetimeMilliseconds_;
Jeff Thompsond9e278c2013-07-08 15:20:13 -070086
87 interestStruct.nonceLength = nonce_.size();
88 if (nonce_.size() > 0)
Jeff Thompson412226d2013-09-12 15:55:46 -070089 interestStruct.nonce = (unsigned char *)nonce_.buf();
Jeff Thompsond9e278c2013-07-08 15:20:13 -070090 else
91 interestStruct.nonce = 0;
92}
Jeff Thompsonb7f95562013-07-03 18:36:42 -070093
94}
95