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