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 | |
| 23 | void 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 Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 38 | void Interest::set(struct ndn_Interest &interestStruct) |
| 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 | |
| 44 | publisherPublicKeyDigest_.clear(); |
| 45 | if (interestStruct.publisherPublicKeyDigest) |
| 46 | publisherPublicKeyDigest_.insert |
| 47 | (publisherPublicKeyDigest_.begin(), interestStruct.publisherPublicKeyDigest, interestStruct.publisherPublicKeyDigest + interestStruct.publisherPublicKeyDigestLength); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame^] | 48 | |
| 49 | exclude_.set(interestStruct.exclude); |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 50 | 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 Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 59 | |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 60 | void Interest::get(struct ndn_Interest &interestStruct) const |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 61 | { |
| 62 | name_.get(interestStruct.name); |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 63 | interestStruct.minSuffixComponents = minSuffixComponents_; |
Jeff Thompson | f2e5e28 | 2013-07-08 15:26:16 -0700 | [diff] [blame] | 64 | interestStruct.maxSuffixComponents = maxSuffixComponents_; |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 65 | |
| 66 | interestStruct.publisherPublicKeyDigestLength = publisherPublicKeyDigest_.size(); |
| 67 | if (publisherPublicKeyDigest_.size() > 0) |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 68 | interestStruct.publisherPublicKeyDigest = (unsigned char *)&publisherPublicKeyDigest_[0]; |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 69 | else |
| 70 | interestStruct.publisherPublicKeyDigest = 0; |
| 71 | |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame^] | 72 | exclude_.get(interestStruct.exclude); |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 73 | 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 Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 80 | interestStruct.nonce = (unsigned char *)&nonce_[0]; |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 81 | else |
| 82 | interestStruct.nonce = 0; |
| 83 | } |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 84 | |
| 85 | } |
| 86 | |