All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
interest.h
1 
21 #ifndef NDN_INTEREST_H
22 #define NDN_INTEREST_H
23 
24 #include <ndn-cpp/c/interest-types.h>
25 #include "name.h"
26 #include "key-locator.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
39 static __inline void ndn_ExcludeEntry_initialize(struct ndn_ExcludeEntry *self, ndn_ExcludeType type, const uint8_t *component, size_t componentLength)
40 {
41  self->type = type;
42  ndn_NameComponent_initialize(&self->component, component, componentLength);
43 }
44 
50 static __inline void
51 ndn_ExcludeEntry_setFromExcludeEntry
52  (struct ndn_ExcludeEntry *self, const struct ndn_ExcludeEntry *other)
53 {
54  *self = *other;
55 }
56 
63 static __inline void ndn_Exclude_initialize(struct ndn_Exclude *self, struct ndn_ExcludeEntry *entries, size_t maxEntries)
64 {
65  self->entries = entries;
66  self->maxEntries = maxEntries;
67  self->nEntries = 0;
68 }
69 
73 static __inline void
74 ndn_Exclude_clear(struct ndn_Exclude *self)
75 {
76  self->nEntries = 0;
77 }
78 
85 ndn_Error
86 ndn_Exclude_appendAny(struct ndn_Exclude *self);
87 
97 ndn_Error
98 ndn_Exclude_appendComponent
99  (struct ndn_Exclude *self, const uint8_t* component, size_t componentLength);
100 
108 ndn_Error
109 ndn_Exclude_setFromExclude
110  (struct ndn_Exclude *self, const struct ndn_Exclude *other);
111 
123 static __inline void ndn_Interest_initialize
124  (struct ndn_Interest *self, struct ndn_NameComponent *nameComponents, size_t maxNameComponents,
125  struct ndn_ExcludeEntry *excludeEntries, size_t maxExcludeEntries, struct ndn_NameComponent *keyNameComponents,
126  size_t maxKeyNameComponents)
127 {
128  ndn_Name_initialize(&self->name, nameComponents, maxNameComponents);
129  self->minSuffixComponents = -1;
130  self->maxSuffixComponents = -1;
131  ndn_Exclude_initialize(&self->exclude, excludeEntries, maxExcludeEntries);
132  self->childSelector = -1;
133  self->mustBeFresh = 1;
134  self->interestLifetimeMilliseconds = -1.0;
135  ndn_Blob_initialize(&self->nonce, 0, 0);
136  ndn_KeyLocator_initialize(&self->keyLocator, keyNameComponents, maxKeyNameComponents);
137  ndn_Blob_initialize(&self->forwardingHintWireEncoding, 0, 0);
138  ndn_Blob_initialize(&self->linkWireEncoding, 0, 0);
139  self->selectedDelegationIndex = -1;
140 }
141 
147 static __inline int ndn_Interest_getCanBePrefix(const struct ndn_Interest *self)
148 {
149  // Use the closest v0.2 semantics. CanBePrefix is the opposite of exact
150  // match where MaxSuffixComponents is 1 (for the implicit digest).
151  return self->maxSuffixComponents != 1;
152 }
153 
159 static __inline int ndn_Interest_getMustBeFresh(const struct ndn_Interest *self)
160 {
161  return self->mustBeFresh;
162 }
163 
170 static __inline void
171 ndn_Interest_setCanBePrefix(struct ndn_Interest *self, int canBePrefix)
172 {
173  // Use the closest v0.2 semantics. CanBePrefix is the opposite of exact
174  // match where MaxSuffixComponents is 1 (for the implicit digest).
175  self->maxSuffixComponents = (canBePrefix ? -1 : 1);
176 }
177 
184 static __inline void
185 ndn_Interest_setMustBeFresh(struct ndn_Interest *self, int mustBeFresh)
186 {
187  self->mustBeFresh = (mustBeFresh ? 1 : 0);
188 }
189 
197 static __inline ndn_Error
198 ndn_Interest_setFromInterest
199  (struct ndn_Interest *self, const struct ndn_Interest *other)
200 {
201  ndn_Error error;
202 
203  if (other == self)
204  // Setting to itself. Do nothing.
205  return NDN_ERROR_success;
206 
207  if ((error = ndn_Name_setFromName(&self->name, &other->name)))
208  return error;
209  self->minSuffixComponents = other->minSuffixComponents;
210  self->maxSuffixComponents = other->maxSuffixComponents;
211  if ((error = ndn_Exclude_setFromExclude(&self->exclude, &other->exclude)))
212  return error;
213  self->childSelector = other->childSelector;
214  self->mustBeFresh = other->mustBeFresh;
215  self->interestLifetimeMilliseconds = other->interestLifetimeMilliseconds;
216  ndn_Blob_setFromBlob(&self->nonce, &other->nonce);
217  if ((error = ndn_KeyLocator_setFromKeyLocator
218  (&self->keyLocator, &other->keyLocator)))
219  return error;
220  ndn_Blob_setFromBlob(&self->forwardingHintWireEncoding, &other->forwardingHintWireEncoding);
221  ndn_Blob_setFromBlob(&self->linkWireEncoding, &other->linkWireEncoding);
222  self->selectedDelegationIndex = other->selectedDelegationIndex;
223 
224  return NDN_ERROR_success;
225 }
226 
227 #ifdef __cplusplus
228 }
229 #endif
230 
231 #endif
232 
An ndn_ExcludeEntry holds an ndn_ExcludeType, and if it is a COMPONENT, it holds a pointer to the com...
Definition: interest-types.h:39
int mustBeFresh
bool.
Definition: interest-types.h:68
int childSelector
-1 for none
Definition: interest-types.h:67
struct ndn_Blob forwardingHintWireEncoding
The blob whose value is a pointer to a pre-allocated buffer of the encoded sequence of delegation set...
Definition: interest-types.h:71
int selectedDelegationIndex
-1 for none
Definition: interest-types.h:74
struct ndn_Blob nonce
The blob whose value is a pointer to a pre-allocated buffer.
Definition: interest-types.h:70
ndn_Milliseconds interestLifetimeMilliseconds
-1.0 for none
Definition: interest-types.h:69
An ndn_Interest holds an ndn_Name and other fields for an interest.
Definition: interest-types.h:61
int minSuffixComponents
-1 for none
Definition: interest-types.h:63
An ndn_Exclude holds an array of ndn_ExcludeEntry.
Definition: interest-types.h:47
An ndn_NameComponent holds a pointer to the component value.
Definition: name-types.h:47
struct ndn_Blob linkWireEncoding
The link whose value is a pointer to a pre-allocated buffer.
Definition: interest-types.h:73
int maxSuffixComponents
-1 for none
Definition: interest-types.h:64