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 | 37527d6 | 2013-08-21 11:15:54 -0700 | [diff] [blame^] | 39 | string Exclude::toUri() const |
| 40 | { |
| 41 | if (entries_.size() == 0) |
| 42 | return ""; |
| 43 | |
| 44 | ostringstream result; |
| 45 | for (unsigned i = 0; i < entries_.size(); ++i) { |
| 46 | if (i > 0) |
| 47 | result << ","; |
| 48 | |
| 49 | if (entries_[i].getType() == ndn_Exclude_ANY) |
| 50 | result << "*"; |
| 51 | else |
| 52 | Name::toEscapedString(entries_[i].getComponent().getValue(), result); |
| 53 | } |
| 54 | |
| 55 | return result.str(); |
| 56 | } |
| 57 | |
Jeff Thompson | dd3d229 | 2013-07-10 11:59:44 -0700 | [diff] [blame] | 58 | void Interest::set(const struct ndn_Interest &interestStruct) |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 59 | { |
| 60 | name_.set(interestStruct.name); |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 61 | minSuffixComponents_ = interestStruct.minSuffixComponents; |
| 62 | maxSuffixComponents_ = interestStruct.maxSuffixComponents; |
| 63 | |
| 64 | publisherPublicKeyDigest_.set(interestStruct.publisherPublicKeyDigest); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 65 | |
| 66 | exclude_.set(interestStruct.exclude); |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 67 | childSelector_ = interestStruct.childSelector; |
| 68 | answerOriginKind_ = interestStruct.answerOriginKind; |
| 69 | scope_ = interestStruct.scope; |
| 70 | interestLifetimeMilliseconds_ = interestStruct.interestLifetimeMilliseconds; |
Jeff Thompson | 51dd5fd | 2013-07-10 19:27:18 -0700 | [diff] [blame] | 71 | setVector(nonce_, interestStruct.nonce, interestStruct.nonceLength); |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 72 | } |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 73 | |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 74 | void Interest::get(struct ndn_Interest &interestStruct) const |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 75 | { |
| 76 | name_.get(interestStruct.name); |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 77 | interestStruct.minSuffixComponents = minSuffixComponents_; |
Jeff Thompson | f2e5e28 | 2013-07-08 15:26:16 -0700 | [diff] [blame] | 78 | interestStruct.maxSuffixComponents = maxSuffixComponents_; |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 79 | publisherPublicKeyDigest_.get(interestStruct.publisherPublicKeyDigest); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 80 | exclude_.get(interestStruct.exclude); |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 81 | interestStruct.childSelector = childSelector_; |
| 82 | interestStruct.answerOriginKind = answerOriginKind_; |
| 83 | interestStruct.scope = scope_; |
Jeff Thompson | 5a5e8b7 | 2013-07-11 14:28:03 -0700 | [diff] [blame] | 84 | interestStruct.interestLifetimeMilliseconds = interestLifetimeMilliseconds_; |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 85 | |
| 86 | interestStruct.nonceLength = nonce_.size(); |
| 87 | if (nonce_.size() > 0) |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 88 | interestStruct.nonce = (unsigned char *)&nonce_[0]; |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 89 | else |
| 90 | interestStruct.nonce = 0; |
| 91 | } |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 92 | |
| 93 | } |
| 94 | |