blob: 5417fa09549f52c48afdad821d695f407df1c567 [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 Thompsonfe556862013-07-09 13:52:55 -070014void Exclude::get(struct ndn_Exclude &excludeStruct) const
15{
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 Thompsondd3d2292013-07-10 11:59:44 -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)
31 addComponent(entry->component, entry->componentLength);
32 else if (entry->type == ndn_Exclude_ANY)
33 addAny();
34 else
35 throw runtime_error("unrecognized ndn_ExcludeType");
36 }
37}
38
Jeff Thompsondd3d2292013-07-10 11:59:44 -070039void Interest::set(const struct ndn_Interest &interestStruct)
Jeff Thompsonb7f95562013-07-03 18:36:42 -070040{
41 name_.set(interestStruct.name);
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070042 minSuffixComponents_ = interestStruct.minSuffixComponents;
43 maxSuffixComponents_ = interestStruct.maxSuffixComponents;
44
45 publisherPublicKeyDigest_.set(interestStruct.publisherPublicKeyDigest);
Jeff Thompsonfe556862013-07-09 13:52:55 -070046
47 exclude_.set(interestStruct.exclude);
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070048 childSelector_ = interestStruct.childSelector;
49 answerOriginKind_ = interestStruct.answerOriginKind;
50 scope_ = interestStruct.scope;
51 interestLifetimeMilliseconds_ = interestStruct.interestLifetimeMilliseconds;
Jeff Thompson51dd5fd2013-07-10 19:27:18 -070052 setVector(nonce_, interestStruct.nonce, interestStruct.nonceLength);
Jeff Thompsonb7f95562013-07-03 18:36:42 -070053}
Jeff Thompsond9e278c2013-07-08 15:20:13 -070054
Jeff Thompsond345a5b2013-07-08 16:18:23 -070055void Interest::get(struct ndn_Interest &interestStruct) const
Jeff Thompsond9e278c2013-07-08 15:20:13 -070056{
57 name_.get(interestStruct.name);
Jeff Thompsond9e278c2013-07-08 15:20:13 -070058 interestStruct.minSuffixComponents = minSuffixComponents_;
Jeff Thompsonf2e5e282013-07-08 15:26:16 -070059 interestStruct.maxSuffixComponents = maxSuffixComponents_;
Jeff Thompson8238d002013-07-10 11:56:49 -070060 publisherPublicKeyDigest_.get(interestStruct.publisherPublicKeyDigest);
Jeff Thompsonfe556862013-07-09 13:52:55 -070061 exclude_.get(interestStruct.exclude);
Jeff Thompsond9e278c2013-07-08 15:20:13 -070062 interestStruct.childSelector = childSelector_;
63 interestStruct.answerOriginKind = answerOriginKind_;
64 interestStruct.scope = scope_;
Jeff Thompson5a5e8b72013-07-11 14:28:03 -070065 interestStruct.interestLifetimeMilliseconds = interestLifetimeMilliseconds_;
Jeff Thompsond9e278c2013-07-08 15:20:13 -070066
67 interestStruct.nonceLength = nonce_.size();
68 if (nonce_.size() > 0)
Jeff Thompsond345a5b2013-07-08 16:18:23 -070069 interestStruct.nonce = (unsigned char *)&nonce_[0];
Jeff Thompsond9e278c2013-07-08 15:20:13 -070070 else
71 interestStruct.nonce = 0;
72}
Jeff Thompsonb7f95562013-07-03 18:36:42 -070073
74}
75