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 }
138 
144 static __inline int ndn_Interest_getMustBeFresh(const struct ndn_Interest *self)
145 {
146  return self->mustBeFresh;
147 }
148 
156 static __inline void
157 ndn_Interest_setMustBeFresh(struct ndn_Interest *self, int mustBeFresh)
158 {
159  self->mustBeFresh = (mustBeFresh ? 1 : 0);
160 }
161 
169 static __inline ndn_Error
170 ndn_Interest_setFromInterest
171  (struct ndn_Interest *self, const struct ndn_Interest *other)
172 {
173  ndn_Error error;
174 
175  if (other == self)
176  // Setting to itself. Do nothing.
177  return NDN_ERROR_success;
178 
179  if ((error = ndn_Name_setFromName(&self->name, &other->name)))
180  return error;
181  self->minSuffixComponents = other->minSuffixComponents;
182  self->maxSuffixComponents = other->maxSuffixComponents;
183  if ((error = ndn_Exclude_setFromExclude(&self->exclude, &other->exclude)))
184  return error;
185  self->childSelector = other->childSelector;
186  self->mustBeFresh = other->mustBeFresh;
187  self->interestLifetimeMilliseconds = other->interestLifetimeMilliseconds;
188  ndn_Blob_setFromBlob(&self->nonce, &other->nonce);
189  if ((error = ndn_KeyLocator_setFromKeyLocator
190  (&self->keyLocator, &other->keyLocator)))
191  return error;
192 
193  return NDN_ERROR_success;
194 }
195 
196 #ifdef __cplusplus
197 }
198 #endif
199 
200 #endif
201 
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 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
int maxSuffixComponents
-1 for none
Definition: interest-types.h:64