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->linkWireEncoding, 0, 0);
138  self->selectedDelegationIndex = -1;
139 }
140 
146 static __inline int ndn_Interest_getMustBeFresh(const struct ndn_Interest *self)
147 {
148  return self->mustBeFresh;
149 }
150 
158 static __inline void
159 ndn_Interest_setMustBeFresh(struct ndn_Interest *self, int mustBeFresh)
160 {
161  self->mustBeFresh = (mustBeFresh ? 1 : 0);
162 }
163 
171 static __inline ndn_Error
172 ndn_Interest_setFromInterest
173  (struct ndn_Interest *self, const struct ndn_Interest *other)
174 {
175  ndn_Error error;
176 
177  if (other == self)
178  // Setting to itself. Do nothing.
179  return NDN_ERROR_success;
180 
181  if ((error = ndn_Name_setFromName(&self->name, &other->name)))
182  return error;
183  self->minSuffixComponents = other->minSuffixComponents;
184  self->maxSuffixComponents = other->maxSuffixComponents;
185  if ((error = ndn_Exclude_setFromExclude(&self->exclude, &other->exclude)))
186  return error;
187  self->childSelector = other->childSelector;
188  self->mustBeFresh = other->mustBeFresh;
189  self->interestLifetimeMilliseconds = other->interestLifetimeMilliseconds;
190  ndn_Blob_setFromBlob(&self->nonce, &other->nonce);
191  if ((error = ndn_KeyLocator_setFromKeyLocator
192  (&self->keyLocator, &other->keyLocator)))
193  return error;
194  ndn_Blob_setFromBlob(&self->linkWireEncoding, &other->linkWireEncoding);
195  self->selectedDelegationIndex = other->selectedDelegationIndex;
196 
197  return NDN_ERROR_success;
198 }
199 
200 #ifdef __cplusplus
201 }
202 #endif
203 
204 #endif
205 
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
int selectedDelegationIndex
-1 for none
Definition: interest-types.h:72
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
Copyright (C) 2015-2016 Regents of the University of California.
Definition: name-types.h:33
struct ndn_Blob linkWireEncoding
The link whose value is a pointer to a pre-allocated buffer.
Definition: interest-types.h:71
int maxSuffixComponents
-1 for none
Definition: interest-types.h:64