blob: 797fa35a2458bce0783e905d08ed3cf9b01690d8 [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
Jeff Thompson8238d002013-07-10 11:56:49 -070044 publisherPublicKeyDigest_.set(interestStruct.publisherPublicKeyDigest);
Jeff Thompsonfe556862013-07-09 13:52:55 -070045
46 exclude_.set(interestStruct.exclude);
Jeff Thompsonb7f95562013-07-03 18:36:42 -070047 childSelector_ = interestStruct.childSelector;
48 answerOriginKind_ = interestStruct.answerOriginKind;
49 scope_ = interestStruct.scope;
50 interestLifetime_ = interestStruct.interestLifetime;
51 nonce_.clear();
52 if (interestStruct.nonce)
53 nonce_.insert
54 (nonce_.begin(), interestStruct.nonce, interestStruct.nonce + interestStruct.nonceLength);
55}
Jeff Thompsond9e278c2013-07-08 15:20:13 -070056
Jeff Thompsond345a5b2013-07-08 16:18:23 -070057void Interest::get(struct ndn_Interest &interestStruct) const
Jeff Thompsond9e278c2013-07-08 15:20:13 -070058{
59 name_.get(interestStruct.name);
Jeff Thompsond9e278c2013-07-08 15:20:13 -070060 interestStruct.minSuffixComponents = minSuffixComponents_;
Jeff Thompsonf2e5e282013-07-08 15:26:16 -070061 interestStruct.maxSuffixComponents = maxSuffixComponents_;
Jeff Thompson8238d002013-07-10 11:56:49 -070062 publisherPublicKeyDigest_.get(interestStruct.publisherPublicKeyDigest);
Jeff Thompsonfe556862013-07-09 13:52:55 -070063 exclude_.get(interestStruct.exclude);
Jeff Thompsond9e278c2013-07-08 15:20:13 -070064 interestStruct.childSelector = childSelector_;
65 interestStruct.answerOriginKind = answerOriginKind_;
66 interestStruct.scope = scope_;
67 interestStruct.interestLifetime = interestLifetime_;
68
69 interestStruct.nonceLength = nonce_.size();
70 if (nonce_.size() > 0)
Jeff Thompsond345a5b2013-07-08 16:18:23 -070071 interestStruct.nonce = (unsigned char *)&nonce_[0];
Jeff Thompsond9e278c2013-07-08 15:20:13 -070072 else
73 interestStruct.nonce = 0;
74}
Jeff Thompsonb7f95562013-07-03 18:36:42 -070075
76}
77