blob: 382db2efccc10d6904ca136a60481af8c7524a45 [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 Thompsonb7f95562013-07-03 18:36:42 -07007#include "Interest.hpp"
8
9using namespace std;
10
11namespace ndn {
12
Jeff Thompsonfe556862013-07-09 13:52:55 -070013void Exclude::get(struct ndn_Exclude &excludeStruct) const
14{
15 if (excludeStruct.maxEntries < entries_.size())
16 throw runtime_error("excludeStruct.maxEntries must be >= this exclude getEntryCount()");
17
18 excludeStruct.nEntries = entries_.size();
19 for (unsigned int i = 0; i < excludeStruct.nEntries; ++i)
20 entries_[i].get(excludeStruct.entries[i]);
21}
22
23void Exclude::set(struct ndn_Exclude &excludeStruct)
24{
25 entries_.clear();
26 for (unsigned int i = 0; i < excludeStruct.nEntries; ++i) {
27 ndn_ExcludeEntry *entry = &excludeStruct.entries[i];
28
29 if (entry->type == ndn_Exclude_COMPONENT)
30 addComponent(entry->component, entry->componentLength);
31 else if (entry->type == ndn_Exclude_ANY)
32 addAny();
33 else
34 throw runtime_error("unrecognized ndn_ExcludeType");
35 }
36}
37
Jeff Thompsonb7f95562013-07-03 18:36:42 -070038void Interest::set(struct ndn_Interest &interestStruct)
39{
40 name_.set(interestStruct.name);
Jeff Thompsonb7f95562013-07-03 18:36:42 -070041 minSuffixComponents_ = interestStruct.minSuffixComponents;
Jeff Thompsonf2e5e282013-07-08 15:26:16 -070042 maxSuffixComponents_ = interestStruct.maxSuffixComponents;
Jeff Thompsonb7f95562013-07-03 18:36:42 -070043
44 publisherPublicKeyDigest_.clear();
45 if (interestStruct.publisherPublicKeyDigest)
46 publisherPublicKeyDigest_.insert
47 (publisherPublicKeyDigest_.begin(), interestStruct.publisherPublicKeyDigest, interestStruct.publisherPublicKeyDigest + interestStruct.publisherPublicKeyDigestLength);
Jeff Thompsonfe556862013-07-09 13:52:55 -070048
49 exclude_.set(interestStruct.exclude);
Jeff Thompsonb7f95562013-07-03 18:36:42 -070050 childSelector_ = interestStruct.childSelector;
51 answerOriginKind_ = interestStruct.answerOriginKind;
52 scope_ = interestStruct.scope;
53 interestLifetime_ = interestStruct.interestLifetime;
54 nonce_.clear();
55 if (interestStruct.nonce)
56 nonce_.insert
57 (nonce_.begin(), interestStruct.nonce, interestStruct.nonce + interestStruct.nonceLength);
58}
Jeff Thompsond9e278c2013-07-08 15:20:13 -070059
Jeff Thompsond345a5b2013-07-08 16:18:23 -070060void Interest::get(struct ndn_Interest &interestStruct) const
Jeff Thompsond9e278c2013-07-08 15:20:13 -070061{
62 name_.get(interestStruct.name);
Jeff Thompsond9e278c2013-07-08 15:20:13 -070063 interestStruct.minSuffixComponents = minSuffixComponents_;
Jeff Thompsonf2e5e282013-07-08 15:26:16 -070064 interestStruct.maxSuffixComponents = maxSuffixComponents_;
Jeff Thompsond9e278c2013-07-08 15:20:13 -070065
66 interestStruct.publisherPublicKeyDigestLength = publisherPublicKeyDigest_.size();
67 if (publisherPublicKeyDigest_.size() > 0)
Jeff Thompsond345a5b2013-07-08 16:18:23 -070068 interestStruct.publisherPublicKeyDigest = (unsigned char *)&publisherPublicKeyDigest_[0];
Jeff Thompsond9e278c2013-07-08 15:20:13 -070069 else
70 interestStruct.publisherPublicKeyDigest = 0;
71
Jeff Thompsonfe556862013-07-09 13:52:55 -070072 exclude_.get(interestStruct.exclude);
Jeff Thompsond9e278c2013-07-08 15:20:13 -070073 interestStruct.childSelector = childSelector_;
74 interestStruct.answerOriginKind = answerOriginKind_;
75 interestStruct.scope = scope_;
76 interestStruct.interestLifetime = interestLifetime_;
77
78 interestStruct.nonceLength = nonce_.size();
79 if (nonce_.size() > 0)
Jeff Thompsond345a5b2013-07-08 16:18:23 -070080 interestStruct.nonce = (unsigned char *)&nonce_[0];
Jeff Thompsond9e278c2013-07-08 15:20:13 -070081 else
82 interestStruct.nonce = 0;
83}
Jeff Thompsonb7f95562013-07-03 18:36:42 -070084
85}
86