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 | |
| 6 | #ifndef NDN_INTEREST_HPP |
| 7 | #define NDN_INTEREST_HPP |
| 8 | |
| 9 | #include <vector> |
| 10 | #include "Name.hpp" |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 11 | #include "PublisherPublicKeyDigest.hpp" |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 12 | #include "c/Interest.h" |
| 13 | |
| 14 | namespace ndn { |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 15 | |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 16 | /** |
| 17 | * An ExcludeEntry holds an ndn_ExcludeType, and if it is a COMPONENT, it holds the component value. |
| 18 | */ |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 19 | class ExcludeEntry { |
| 20 | public: |
| 21 | /** |
| 22 | * Create an ExcludeEntry of type ndn_Exclude_ANY |
| 23 | */ |
| 24 | ExcludeEntry() |
| 25 | : type_(ndn_Exclude_ANY) |
| 26 | { |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Create an ExcludeEntry of type ndn_Exclude_COMPONENT |
| 31 | */ |
| 32 | ExcludeEntry(unsigned char *component, unsigned int componentLen) |
| 33 | : type_(ndn_Exclude_COMPONENT), component_(component, component + componentLen) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Set the type in the excludeEntryStruct and to point to this component, without copying any memory. |
| 39 | * WARNING: The resulting pointer in excludeEntryStruct is invalid after a further use of this object which could reallocate memory. |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 40 | * @param excludeEntryStruct the C ndn_NameComponent struct to receive the pointer |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 41 | */ |
| 42 | void get(struct ndn_ExcludeEntry &excludeEntryStruct) const |
| 43 | { |
| 44 | excludeEntryStruct.type = type_; |
| 45 | if (type_ == ndn_Exclude_COMPONENT) { |
| 46 | excludeEntryStruct.componentLength = component_.size(); |
| 47 | excludeEntryStruct.component = (unsigned char *)&component_[0]; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | ndn_ExcludeType getType() const { return type_; } |
| 52 | |
| 53 | const std::vector<unsigned char> &getComponent() const { return component_; } |
| 54 | |
| 55 | private: |
| 56 | ndn_ExcludeType type_; |
| 57 | std::vector<unsigned char> component_; /**< only used if type_ is ndn_Exclude_COMPONENT */ |
| 58 | }; |
| 59 | |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 60 | /** |
| 61 | * An Exclude holds a vector of ExcludeEntry. |
| 62 | */ |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 63 | class Exclude { |
| 64 | public: |
| 65 | /** |
| 66 | * Create a new Exclude with no entries. |
| 67 | */ |
| 68 | Exclude() { |
| 69 | } |
| 70 | |
| 71 | unsigned int getEntryCount() const { |
| 72 | return entries_.size(); |
| 73 | } |
| 74 | |
| 75 | const ExcludeEntry &getEntry(unsigned int i) const { return entries_[i]; } |
| 76 | |
| 77 | /** |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 78 | * Set the excludeStruct to point to the entries in this Exclude, without copying any memory. |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 79 | * WARNING: The resulting pointers in excludeStruct are invalid after a further use of this object which could reallocate memory. |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 80 | * @param excludeStruct a C ndn_Exclude struct where the entries array is already allocated |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 81 | */ |
| 82 | void get(struct ndn_Exclude &excludeStruct) const; |
| 83 | |
| 84 | /** |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 85 | * Clear this Exclude, and set the entries by copying from the ndn_Exclude struct. |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 86 | * @param excludeStruct a C ndn_Exclude struct |
| 87 | */ |
Jeff Thompson | dd3d229 | 2013-07-10 11:59:44 -0700 | [diff] [blame] | 88 | void set(const struct ndn_Exclude &excludeStruct); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * Add a new entry of type ndn_Exclude_ANY |
| 92 | */ |
| 93 | void addAny() |
| 94 | { |
| 95 | entries_.push_back(ExcludeEntry()); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Add a new entry of type ndn_Exclude_COMPONENT, copying from component of length compnentLength |
| 100 | */ |
| 101 | void addComponent(unsigned char *component, unsigned int componentLen) |
| 102 | { |
| 103 | entries_.push_back(ExcludeEntry(component, componentLen)); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Clear all the entries. |
| 108 | */ |
| 109 | void clear() { |
| 110 | entries_.clear(); |
| 111 | } |
| 112 | |
| 113 | private: |
| 114 | std::vector<ExcludeEntry> entries_; |
| 115 | }; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 116 | |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 117 | /** |
| 118 | * An Interest holds a Name and other fields for an interest. |
| 119 | */ |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 120 | class Interest { |
| 121 | public: |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 122 | void encode(std::vector<unsigned char> &output, WireFormat &wireFormat) const |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 123 | { |
| 124 | wireFormat.encodeInterest(*this, output); |
| 125 | } |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 126 | void encode(std::vector<unsigned char> &output) const |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 127 | { |
| 128 | encode(output, BinaryXMLWireFormat::instance()); |
| 129 | } |
| 130 | void decode(const unsigned char *input, unsigned int inputLength, WireFormat &wireFormat) |
| 131 | { |
| 132 | wireFormat.decodeInterest(*this, input, inputLength); |
| 133 | } |
| 134 | void decode(const unsigned char *input, unsigned int inputLength) |
| 135 | { |
| 136 | decode(input, inputLength, BinaryXMLWireFormat::instance()); |
| 137 | } |
| 138 | void decode(const std::vector<unsigned char> &input, WireFormat &wireFormat) |
| 139 | { |
| 140 | decode(&input[0], input.size(), wireFormat); |
| 141 | } |
| 142 | void decode(const std::vector<unsigned char> &input) |
| 143 | { |
| 144 | decode(&input[0], input.size()); |
| 145 | } |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 146 | |
| 147 | /** |
| 148 | * Set the interestStruct to point to the components in this interest, without copying any memory. |
| 149 | * WARNING: The resulting pointers in interestStruct are invalid after a further use of this object which could reallocate memory. |
| 150 | * @param interestStruct a C ndn_Interest struct where the name components array is already allocated. |
| 151 | */ |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 152 | void get(struct ndn_Interest &interestStruct) const; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 153 | |
Jeff Thompson | 12c2776 | 2013-07-09 15:05:11 -0700 | [diff] [blame] | 154 | Name &getName() { return name_; } |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 155 | const Name &getName() const { return name_; } |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 156 | |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 157 | int getMinSuffixComponents() const { return minSuffixComponents_; } |
| 158 | |
| 159 | int getMaxSuffixComponents() const { return maxSuffixComponents_; } |
Jeff Thompson | 0a68172 | 2013-07-08 16:21:54 -0700 | [diff] [blame] | 160 | |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 161 | PublisherPublicKeyDigest &getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; } |
| 162 | const PublisherPublicKeyDigest &getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; } |
Jeff Thompson | 0a68172 | 2013-07-08 16:21:54 -0700 | [diff] [blame] | 163 | |
Jeff Thompson | 12c2776 | 2013-07-09 15:05:11 -0700 | [diff] [blame] | 164 | Exclude &getExclude() { return exclude_; } |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 165 | const Exclude &getExclude() const { return exclude_; } |
Jeff Thompson | 0a68172 | 2013-07-08 16:21:54 -0700 | [diff] [blame] | 166 | |
| 167 | int getChildSelector() const { return childSelector_; } |
| 168 | |
| 169 | int getAnswerOriginKind() const { return answerOriginKind_; } |
| 170 | |
| 171 | int getScope() const { return scope_; } |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 172 | |
| 173 | int getInterestLifetime() const { return interestLifetime_; } |
Jeff Thompson | 0a68172 | 2013-07-08 16:21:54 -0700 | [diff] [blame] | 174 | |
| 175 | const std::vector<unsigned char> getNonce() const { return nonce_; } |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 176 | |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 177 | /** |
| 178 | * Clear this interest, and set the values by copying from the interest struct. |
| 179 | * @param interestStruct a C ndn_Interest struct |
| 180 | */ |
Jeff Thompson | dd3d229 | 2013-07-10 11:59:44 -0700 | [diff] [blame] | 181 | void set(const struct ndn_Interest &interestStruct); |
Jeff Thompson | eb316a8 | 2013-07-09 15:11:17 -0700 | [diff] [blame] | 182 | |
| 183 | void setMinSuffixComponents(int value) { minSuffixComponents_ = value; } |
| 184 | |
| 185 | void setMaxSuffixComponents(int value) { maxSuffixComponents_ = value; } |
| 186 | |
Jeff Thompson | eb316a8 | 2013-07-09 15:11:17 -0700 | [diff] [blame] | 187 | void setChildSelector(int value) { childSelector_ = value; } |
| 188 | |
| 189 | void setAnswerOriginKind(int value) { answerOriginKind_ = value; } |
| 190 | |
| 191 | void setScope(int value) { scope_ = value; } |
| 192 | |
| 193 | void setInterestLifetime(int value) { interestLifetime_ = value; } |
| 194 | |
| 195 | void setNonce(const std::vector<unsigned char> &value) { nonce_ = value; } |
| 196 | |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 197 | private: |
| 198 | |
| 199 | Name name_; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 200 | int minSuffixComponents_; |
Jeff Thompson | f2e5e28 | 2013-07-08 15:26:16 -0700 | [diff] [blame] | 201 | int maxSuffixComponents_; |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 202 | PublisherPublicKeyDigest publisherPublicKeyDigest_; |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 203 | Exclude exclude_; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 204 | int childSelector_; |
| 205 | int answerOriginKind_; |
| 206 | int scope_; |
| 207 | int interestLifetime_; |
| 208 | std::vector<unsigned char> nonce_; |
| 209 | }; |
| 210 | |
| 211 | } |
| 212 | |
| 213 | #endif |