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 | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 15 | void Exclude::get(struct ndn_Exclude& excludeStruct) const |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 16 | { |
| 17 | if (excludeStruct.maxEntries < entries_.size()) |
| 18 | throw runtime_error("excludeStruct.maxEntries must be >= this exclude getEntryCount()"); |
| 19 | |
| 20 | excludeStruct.nEntries = entries_.size(); |
| 21 | for (unsigned int i = 0; i < excludeStruct.nEntries; ++i) |
| 22 | entries_[i].get(excludeStruct.entries[i]); |
| 23 | } |
| 24 | |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 25 | void Exclude::set(const struct ndn_Exclude& excludeStruct) |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 26 | { |
| 27 | entries_.clear(); |
| 28 | for (unsigned int i = 0; i < excludeStruct.nEntries; ++i) { |
| 29 | ndn_ExcludeEntry *entry = &excludeStruct.entries[i]; |
| 30 | |
| 31 | if (entry->type == ndn_Exclude_COMPONENT) |
Jeff Thompson | 38d0e08 | 2013-08-12 18:07:44 -0700 | [diff] [blame] | 32 | addComponent(entry->component.value, entry->component.valueLength); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 33 | else if (entry->type == ndn_Exclude_ANY) |
| 34 | addAny(); |
| 35 | else |
| 36 | throw runtime_error("unrecognized ndn_ExcludeType"); |
| 37 | } |
| 38 | } |
| 39 | |
Jeff Thompson | 37527d6 | 2013-08-21 11:15:54 -0700 | [diff] [blame] | 40 | string Exclude::toUri() const |
| 41 | { |
| 42 | if (entries_.size() == 0) |
| 43 | return ""; |
| 44 | |
| 45 | ostringstream result; |
| 46 | for (unsigned i = 0; i < entries_.size(); ++i) { |
| 47 | if (i > 0) |
| 48 | result << ","; |
| 49 | |
| 50 | if (entries_[i].getType() == ndn_Exclude_ANY) |
| 51 | result << "*"; |
| 52 | else |
Jeff Thompson | 9bdb3b2 | 2013-09-12 12:42:13 -0700 | [diff] [blame] | 53 | Name::toEscapedString(*entries_[i].getComponent().getValue(), result); |
Jeff Thompson | 37527d6 | 2013-08-21 11:15:54 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | return result.str(); |
| 57 | } |
| 58 | |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 59 | void Interest::set(const struct ndn_Interest& interestStruct) |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 60 | { |
| 61 | name_.set(interestStruct.name); |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 62 | minSuffixComponents_ = interestStruct.minSuffixComponents; |
| 63 | maxSuffixComponents_ = interestStruct.maxSuffixComponents; |
| 64 | |
| 65 | publisherPublicKeyDigest_.set(interestStruct.publisherPublicKeyDigest); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 66 | |
| 67 | exclude_.set(interestStruct.exclude); |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 68 | childSelector_ = interestStruct.childSelector; |
| 69 | answerOriginKind_ = interestStruct.answerOriginKind; |
| 70 | scope_ = interestStruct.scope; |
| 71 | interestLifetimeMilliseconds_ = interestStruct.interestLifetimeMilliseconds; |
Jeff Thompson | 412226d | 2013-09-12 15:55:46 -0700 | [diff] [blame] | 72 | nonce_ = Blob(interestStruct.nonce, interestStruct.nonceLength); |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 73 | } |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 74 | |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 75 | void Interest::get(struct ndn_Interest& interestStruct) const |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 76 | { |
| 77 | name_.get(interestStruct.name); |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 78 | interestStruct.minSuffixComponents = minSuffixComponents_; |
Jeff Thompson | f2e5e28 | 2013-07-08 15:26:16 -0700 | [diff] [blame] | 79 | interestStruct.maxSuffixComponents = maxSuffixComponents_; |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 80 | publisherPublicKeyDigest_.get(interestStruct.publisherPublicKeyDigest); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 81 | exclude_.get(interestStruct.exclude); |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 82 | interestStruct.childSelector = childSelector_; |
| 83 | interestStruct.answerOriginKind = answerOriginKind_; |
| 84 | interestStruct.scope = scope_; |
Jeff Thompson | 5a5e8b7 | 2013-07-11 14:28:03 -0700 | [diff] [blame] | 85 | interestStruct.interestLifetimeMilliseconds = interestLifetimeMilliseconds_; |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 86 | |
| 87 | interestStruct.nonceLength = nonce_.size(); |
| 88 | if (nonce_.size() > 0) |
Jeff Thompson | 412226d | 2013-09-12 15:55:46 -0700 | [diff] [blame] | 89 | interestStruct.nonce = (unsigned char *)nonce_.buf(); |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 90 | else |
| 91 | interestStruct.nonce = 0; |
| 92 | } |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 93 | |
| 94 | } |
| 95 | |