blob: 453dba39334a9d6d51724308cb161d675f3016fb [file] [log] [blame]
Jeff Thompson47eecfc2013-07-07 22:56:46 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
Jeff Thompsonb7f95562013-07-03 18:36:42 -07004 */
5
Jeff Thompsonfe556862013-07-09 13:52:55 -07006#include <stdexcept>
Jeff Thompson51dd5fd2013-07-10 19:27:18 -07007#include "common.hpp"
Jeff Thompson53412192013-08-06 13:35:50 -07008#include "interest.hpp"
Jeff Thompsonb7f95562013-07-03 18:36:42 -07009
10using namespace std;
11
12namespace ndn {
13
Jeff Thompson1656e6a2013-08-29 18:01:48 -070014void Exclude::get(struct ndn_Exclude& excludeStruct) const
Jeff Thompsonfe556862013-07-09 13:52:55 -070015{
16 if (excludeStruct.maxEntries < entries_.size())
17 throw runtime_error("excludeStruct.maxEntries must be >= this exclude getEntryCount()");
18
19 excludeStruct.nEntries = entries_.size();
20 for (unsigned int i = 0; i < excludeStruct.nEntries; ++i)
21 entries_[i].get(excludeStruct.entries[i]);
22}
23
Jeff Thompson1656e6a2013-08-29 18:01:48 -070024void Exclude::set(const struct ndn_Exclude& excludeStruct)
Jeff Thompsonfe556862013-07-09 13:52:55 -070025{
26 entries_.clear();
27 for (unsigned int i = 0; i < excludeStruct.nEntries; ++i) {
28 ndn_ExcludeEntry *entry = &excludeStruct.entries[i];
29
30 if (entry->type == ndn_Exclude_COMPONENT)
Jeff Thompson38d0e082013-08-12 18:07:44 -070031 addComponent(entry->component.value, entry->component.valueLength);
Jeff Thompsonfe556862013-07-09 13:52:55 -070032 else if (entry->type == ndn_Exclude_ANY)
33 addAny();
34 else
35 throw runtime_error("unrecognized ndn_ExcludeType");
36 }
37}
38
Jeff Thompson37527d62013-08-21 11:15:54 -070039string Exclude::toUri() const
40{
41 if (entries_.size() == 0)
42 return "";
43
44 ostringstream result;
45 for (unsigned i = 0; i < entries_.size(); ++i) {
46 if (i > 0)
47 result << ",";
48
49 if (entries_[i].getType() == ndn_Exclude_ANY)
50 result << "*";
51 else
Jeff Thompson9bdb3b22013-09-12 12:42:13 -070052 Name::toEscapedString(*entries_[i].getComponent().getValue(), result);
Jeff Thompson37527d62013-08-21 11:15:54 -070053 }
54
55 return result.str();
56}
57
Jeff Thompson1656e6a2013-08-29 18:01:48 -070058void Interest::set(const struct ndn_Interest& interestStruct)
Jeff Thompsonb7f95562013-07-03 18:36:42 -070059{
60 name_.set(interestStruct.name);
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070061 minSuffixComponents_ = interestStruct.minSuffixComponents;
62 maxSuffixComponents_ = interestStruct.maxSuffixComponents;
63
64 publisherPublicKeyDigest_.set(interestStruct.publisherPublicKeyDigest);
Jeff Thompsonfe556862013-07-09 13:52:55 -070065
66 exclude_.set(interestStruct.exclude);
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070067 childSelector_ = interestStruct.childSelector;
68 answerOriginKind_ = interestStruct.answerOriginKind;
69 scope_ = interestStruct.scope;
70 interestLifetimeMilliseconds_ = interestStruct.interestLifetimeMilliseconds;
Jeff Thompson412226d2013-09-12 15:55:46 -070071 nonce_ = Blob(interestStruct.nonce, interestStruct.nonceLength);
Jeff Thompsonb7f95562013-07-03 18:36:42 -070072}
Jeff Thompsond9e278c2013-07-08 15:20:13 -070073
Jeff Thompson1656e6a2013-08-29 18:01:48 -070074void Interest::get(struct ndn_Interest& interestStruct) const
Jeff Thompsond9e278c2013-07-08 15:20:13 -070075{
76 name_.get(interestStruct.name);
Jeff Thompsond9e278c2013-07-08 15:20:13 -070077 interestStruct.minSuffixComponents = minSuffixComponents_;
Jeff Thompsonf2e5e282013-07-08 15:26:16 -070078 interestStruct.maxSuffixComponents = maxSuffixComponents_;
Jeff Thompson8238d002013-07-10 11:56:49 -070079 publisherPublicKeyDigest_.get(interestStruct.publisherPublicKeyDigest);
Jeff Thompsonfe556862013-07-09 13:52:55 -070080 exclude_.get(interestStruct.exclude);
Jeff Thompsond9e278c2013-07-08 15:20:13 -070081 interestStruct.childSelector = childSelector_;
82 interestStruct.answerOriginKind = answerOriginKind_;
83 interestStruct.scope = scope_;
Jeff Thompson5a5e8b72013-07-11 14:28:03 -070084 interestStruct.interestLifetimeMilliseconds = interestLifetimeMilliseconds_;
Jeff Thompsond9e278c2013-07-08 15:20:13 -070085
86 interestStruct.nonceLength = nonce_.size();
87 if (nonce_.size() > 0)
Jeff Thompson412226d2013-09-12 15:55:46 -070088 interestStruct.nonce = (unsigned char *)nonce_.buf();
Jeff Thompsond9e278c2013-07-08 15:20:13 -070089 else
90 interestStruct.nonce = 0;
91}
Jeff Thompsonb7f95562013-07-03 18:36:42 -070092
93}
94