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 | 51dd5fd | 2013-07-10 19:27:18 -0700 | [diff] [blame] | 7 | #include "common.hpp" |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 8 | #include "interest.hpp" |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 9 | |
| 10 | using namespace std; |
| 11 | |
| 12 | namespace ndn { |
| 13 | |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 14 | void 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 Thompson | dd3d229 | 2013-07-10 11:59:44 -0700 | [diff] [blame] | 24 | void Exclude::set(const struct ndn_Exclude &excludeStruct) |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 25 | { |
| 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) |
Jeff Thompson | 38d0e08 | 2013-08-12 18:07:44 -0700 | [diff] [blame^] | 31 | addComponent(entry->component.value, entry->component.valueLength); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 32 | else if (entry->type == ndn_Exclude_ANY) |
| 33 | addAny(); |
| 34 | else |
| 35 | throw runtime_error("unrecognized ndn_ExcludeType"); |
| 36 | } |
| 37 | } |
| 38 | |
Jeff Thompson | dd3d229 | 2013-07-10 11:59:44 -0700 | [diff] [blame] | 39 | void Interest::set(const struct ndn_Interest &interestStruct) |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 40 | { |
| 41 | name_.set(interestStruct.name); |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 42 | minSuffixComponents_ = interestStruct.minSuffixComponents; |
| 43 | maxSuffixComponents_ = interestStruct.maxSuffixComponents; |
| 44 | |
| 45 | publisherPublicKeyDigest_.set(interestStruct.publisherPublicKeyDigest); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 46 | |
| 47 | exclude_.set(interestStruct.exclude); |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 48 | childSelector_ = interestStruct.childSelector; |
| 49 | answerOriginKind_ = interestStruct.answerOriginKind; |
| 50 | scope_ = interestStruct.scope; |
| 51 | interestLifetimeMilliseconds_ = interestStruct.interestLifetimeMilliseconds; |
Jeff Thompson | 51dd5fd | 2013-07-10 19:27:18 -0700 | [diff] [blame] | 52 | setVector(nonce_, interestStruct.nonce, interestStruct.nonceLength); |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 53 | } |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 54 | |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 55 | void Interest::get(struct ndn_Interest &interestStruct) const |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 56 | { |
| 57 | name_.get(interestStruct.name); |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 58 | interestStruct.minSuffixComponents = minSuffixComponents_; |
Jeff Thompson | f2e5e28 | 2013-07-08 15:26:16 -0700 | [diff] [blame] | 59 | interestStruct.maxSuffixComponents = maxSuffixComponents_; |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 60 | publisherPublicKeyDigest_.get(interestStruct.publisherPublicKeyDigest); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 61 | exclude_.get(interestStruct.exclude); |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 62 | interestStruct.childSelector = childSelector_; |
| 63 | interestStruct.answerOriginKind = answerOriginKind_; |
| 64 | interestStruct.scope = scope_; |
Jeff Thompson | 5a5e8b7 | 2013-07-11 14:28:03 -0700 | [diff] [blame] | 65 | interestStruct.interestLifetimeMilliseconds = interestLifetimeMilliseconds_; |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 66 | |
| 67 | interestStruct.nonceLength = nonce_.size(); |
| 68 | if (nonce_.size() > 0) |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 69 | interestStruct.nonce = (unsigned char *)&nonce_[0]; |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 70 | else |
| 71 | interestStruct.nonce = 0; |
| 72 | } |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 73 | |
| 74 | } |
| 75 | |