Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 6 | #include <stdexcept> |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 7 | #include "Interest.hpp" |
| 8 | |
| 9 | using namespace std; |
| 10 | |
| 11 | namespace ndn { |
| 12 | |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 13 | void 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 | |
Jeff Thompson | dd3d229 | 2013-07-10 11:59:44 -0700 | [diff] [blame] | 23 | void Exclude::set(const struct ndn_Exclude &excludeStruct) |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 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 Thompson | dd3d229 | 2013-07-10 11:59:44 -0700 | [diff] [blame] | 38 | void Interest::set(const struct ndn_Interest &interestStruct) |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 39 | { |
| 40 | name_.set(interestStruct.name); |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 41 | minSuffixComponents_ = interestStruct.minSuffixComponents; |
Jeff Thompson | f2e5e28 | 2013-07-08 15:26:16 -0700 | [diff] [blame] | 42 | maxSuffixComponents_ = interestStruct.maxSuffixComponents; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 43 | |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 44 | publisherPublicKeyDigest_.set(interestStruct.publisherPublicKeyDigest); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 45 | |
| 46 | exclude_.set(interestStruct.exclude); |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 47 | 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 Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 56 | |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 57 | void Interest::get(struct ndn_Interest &interestStruct) const |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 58 | { |
| 59 | name_.get(interestStruct.name); |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 60 | interestStruct.minSuffixComponents = minSuffixComponents_; |
Jeff Thompson | f2e5e28 | 2013-07-08 15:26:16 -0700 | [diff] [blame] | 61 | interestStruct.maxSuffixComponents = maxSuffixComponents_; |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 62 | publisherPublicKeyDigest_.get(interestStruct.publisherPublicKeyDigest); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 63 | exclude_.get(interestStruct.exclude); |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 64 | 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 Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 71 | interestStruct.nonce = (unsigned char *)&nonce_[0]; |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 72 | else |
| 73 | interestStruct.nonce = 0; |
| 74 | } |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 75 | |
| 76 | } |
| 77 | |