Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 7 | #include <stdexcept> |
Jeff Thompson | 51dd5fd | 2013-07-10 19:27:18 -0700 | [diff] [blame] | 8 | #include "common.hpp" |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 9 | #include "interest.hpp" |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 10 | |
| 11 | using namespace std; |
| 12 | |
| 13 | namespace ndn { |
| 14 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 15 | void |
| 16 | Exclude::get(struct ndn_Exclude& excludeStruct) const |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 17 | { |
| 18 | if (excludeStruct.maxEntries < entries_.size()) |
| 19 | throw runtime_error("excludeStruct.maxEntries must be >= this exclude getEntryCount()"); |
| 20 | |
| 21 | excludeStruct.nEntries = entries_.size(); |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 22 | for (size_t i = 0; i < excludeStruct.nEntries; ++i) |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 23 | entries_[i].get(excludeStruct.entries[i]); |
| 24 | } |
| 25 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 26 | void |
| 27 | Exclude::set(const struct ndn_Exclude& excludeStruct) |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 28 | { |
| 29 | entries_.clear(); |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 30 | for (size_t i = 0; i < excludeStruct.nEntries; ++i) { |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 31 | ndn_ExcludeEntry *entry = &excludeStruct.entries[i]; |
| 32 | |
| 33 | if (entry->type == ndn_Exclude_COMPONENT) |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame^] | 34 | addComponent(entry->component.value.value, entry->component.value.length); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 35 | else if (entry->type == ndn_Exclude_ANY) |
| 36 | addAny(); |
| 37 | else |
| 38 | throw runtime_error("unrecognized ndn_ExcludeType"); |
| 39 | } |
| 40 | } |
| 41 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 42 | string |
| 43 | Exclude::toUri() const |
Jeff Thompson | 37527d6 | 2013-08-21 11:15:54 -0700 | [diff] [blame] | 44 | { |
| 45 | if (entries_.size() == 0) |
| 46 | return ""; |
| 47 | |
| 48 | ostringstream result; |
| 49 | for (unsigned i = 0; i < entries_.size(); ++i) { |
| 50 | if (i > 0) |
| 51 | result << ","; |
| 52 | |
| 53 | if (entries_[i].getType() == ndn_Exclude_ANY) |
| 54 | result << "*"; |
| 55 | else |
Jeff Thompson | 9bdb3b2 | 2013-09-12 12:42:13 -0700 | [diff] [blame] | 56 | Name::toEscapedString(*entries_[i].getComponent().getValue(), result); |
Jeff Thompson | 37527d6 | 2013-08-21 11:15:54 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | return result.str(); |
| 60 | } |
| 61 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 62 | void |
| 63 | Interest::set(const struct ndn_Interest& interestStruct) |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 64 | { |
| 65 | name_.set(interestStruct.name); |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 66 | minSuffixComponents_ = interestStruct.minSuffixComponents; |
| 67 | maxSuffixComponents_ = interestStruct.maxSuffixComponents; |
| 68 | |
| 69 | publisherPublicKeyDigest_.set(interestStruct.publisherPublicKeyDigest); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 70 | |
| 71 | exclude_.set(interestStruct.exclude); |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 72 | childSelector_ = interestStruct.childSelector; |
| 73 | answerOriginKind_ = interestStruct.answerOriginKind; |
| 74 | scope_ = interestStruct.scope; |
| 75 | interestLifetimeMilliseconds_ = interestStruct.interestLifetimeMilliseconds; |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame^] | 76 | nonce_ = Blob(interestStruct.nonce); |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 77 | } |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 78 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 79 | void |
| 80 | Interest::get(struct ndn_Interest& interestStruct) const |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 81 | { |
| 82 | name_.get(interestStruct.name); |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 83 | interestStruct.minSuffixComponents = minSuffixComponents_; |
Jeff Thompson | f2e5e28 | 2013-07-08 15:26:16 -0700 | [diff] [blame] | 84 | interestStruct.maxSuffixComponents = maxSuffixComponents_; |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 85 | publisherPublicKeyDigest_.get(interestStruct.publisherPublicKeyDigest); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 86 | exclude_.get(interestStruct.exclude); |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 87 | interestStruct.childSelector = childSelector_; |
| 88 | interestStruct.answerOriginKind = answerOriginKind_; |
| 89 | interestStruct.scope = scope_; |
Jeff Thompson | 5a5e8b7 | 2013-07-11 14:28:03 -0700 | [diff] [blame] | 90 | interestStruct.interestLifetimeMilliseconds = interestLifetimeMilliseconds_; |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame^] | 91 | nonce_.get(interestStruct.nonce); |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 92 | } |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 93 | |
| 94 | } |
| 95 | |