All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
name.h
1 
21 #ifndef NDN_NAME_H
22 #define NDN_NAME_H
23 
24 #include <ndn-cpp/c/name-types.h>
25 #include <ndn-cpp/c/errors.h>
26 #include "util/blob.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
39 static __inline void ndn_NameComponent_initialize(struct ndn_NameComponent *self, const uint8_t *value, size_t valueLength)
40 {
41  self->type = ndn_NameComponentType_GENERIC;
42  self->otherTypeCode = -1;
43  ndn_Blob_initialize(&self->value, value, valueLength);
44 }
45 
56 static __inline void
57 ndn_NameComponent_setType
58  (struct ndn_NameComponent *self, ndn_NameComponentType type,
59  int otherTypeCode)
60 {
61  self->type = type;
62  self->otherTypeCode =
63  (type == ndn_NameComponentType_OTHER_CODE ? otherTypeCode : -1);
64 }
65 
73 static __inline int
74 ndn_NameComponent_isSegment(const struct ndn_NameComponent *self)
75 {
76  return (self->value.length >= 1 && self->value.value[0] == 0x00 &&
77  self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
78 }
79 
87 static __inline int
88 ndn_NameComponent_isSegmentOffset(const struct ndn_NameComponent *self)
89 {
90  return (self->value.length >= 1 && self->value.value[0] == 0xFB &&
91  self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
92 }
93 
101 static __inline int
102 ndn_NameComponent_isVersion(const struct ndn_NameComponent *self)
103 {
104  return (self->value.length >= 1 && self->value.value[0] == 0xFD &&
105  self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
106 }
107 
115 static __inline int
116 ndn_NameComponent_isTimestamp(const struct ndn_NameComponent *self)
117 {
118  return (self->value.length >= 1 && self->value.value[0] == 0xFC &&
119  self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
120 }
121 
129 static __inline int
130 ndn_NameComponent_isSequenceNumber(const struct ndn_NameComponent *self)
131 {
132  return (self->value.length >= 1 && self->value.value[0] == 0xFE &&
133  self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
134 }
135 
141 static __inline int
142 ndn_NameComponent_isGeneric(const struct ndn_NameComponent *self)
143 {
144  return self->type == ndn_NameComponentType_GENERIC ? 1 : 0;
145 }
146 
152 static __inline int
153 ndn_NameComponent_isImplicitSha256Digest(const struct ndn_NameComponent *self)
154 {
155  return self->type == ndn_NameComponentType_IMPLICIT_SHA256_DIGEST ? 1 : 0;
156 }
157 
163 static __inline int
164 ndn_NameComponent_isParametersSha256Digest(const struct ndn_NameComponent *self)
165 {
166  return self->type == ndn_NameComponentType_PARAMETERS_SHA256_DIGEST ? 1 : 0;
167 }
168 
174 uint64_t ndn_NameComponent_toNumber(const struct ndn_NameComponent *self);
175 
183 ndn_Error ndn_NameComponent_toNumberWithMarker
184  (const struct ndn_NameComponent *self, uint8_t marker, uint64_t *result);
185 
195 static __inline ndn_Error
196 ndn_NameComponent_toSegment
197  (const struct ndn_NameComponent *self, uint64_t *result)
198 {
199  return ndn_NameComponent_toNumberWithMarker(self, 0x00, result);
200 }
201 
211 static __inline ndn_Error
212 ndn_NameComponent_toSegmentOffset
213  (const struct ndn_NameComponent *self, uint64_t *result)
214 {
215  return ndn_NameComponent_toNumberWithMarker(self, 0xFB, result);
216 }
217 
229 static __inline ndn_Error
230 ndn_NameComponent_toVersion
231  (const struct ndn_NameComponent *self, uint64_t *result)
232 {
233  return ndn_NameComponent_toNumberWithMarker(self, 0xFD, result);
234 }
235 
246 static __inline ndn_Error
247 ndn_NameComponent_toTimestamp
248  (const struct ndn_NameComponent *self, uint64_t *result)
249 {
250  return ndn_NameComponent_toNumberWithMarker(self, 0xFC, result);
251 }
252 
262 static __inline ndn_Error
263 ndn_NameComponent_toSequenceNumber
264  (const struct ndn_NameComponent *self, uint64_t *result)
265 {
266  return ndn_NameComponent_toNumberWithMarker(self, 0xFE, result);
267 }
268 
277 ndn_Error ndn_NameComponent_toNumberWithPrefix
278  (const struct ndn_NameComponent *self, const uint8_t *prefix,
279  size_t prefixLength, uint64_t *result);
280 
288 int
289 ndn_NameComponent_hasPrefix
290  (const struct ndn_NameComponent *self, const uint8_t *prefix,
291  size_t prefixLength);
292 
299 int ndn_NameComponent_equals
300  (const struct ndn_NameComponent *self, const struct ndn_NameComponent *other);
301 
310 int ndn_NameComponent_compare
311  (const struct ndn_NameComponent *self, const struct ndn_NameComponent *other);
312 
318 static __inline void
319 ndn_NameComponent_setFromNameComponent
320  (struct ndn_NameComponent *self, const struct ndn_NameComponent *other)
321 {
322  *self = *other;
323 }
324 
338 ndn_Error
339 ndn_NameComponent_setFromNumber
340  (struct ndn_NameComponent *self, uint64_t number, uint8_t *buffer,
341  size_t bufferLength);
342 
357 ndn_Error
358 ndn_NameComponent_setFromNumberWithMarker
359  (struct ndn_NameComponent *self, uint64_t number, uint8_t marker,
360  uint8_t *buffer, size_t bufferLength);
361 
375 static __inline ndn_Error
376 ndn_NameComponent_setSegment
377  (struct ndn_NameComponent *self, uint64_t segment, uint8_t* buffer,
378  size_t bufferLength)
379 {
380  return ndn_NameComponent_setFromNumberWithMarker
381  (self, segment, 0x00, buffer, bufferLength);
382 }
383 
397 static __inline ndn_Error
398 ndn_NameComponent_setSegmentOffset
399  (struct ndn_NameComponent *self, uint64_t segmentOffset, uint8_t* buffer,
400  size_t bufferLength)
401 {
402  return ndn_NameComponent_setFromNumberWithMarker
403  (self, segmentOffset, 0xFB, buffer, bufferLength);
404 }
405 
420 static __inline ndn_Error
421 ndn_NameComponent_setVersion
422  (struct ndn_NameComponent *self, uint64_t version, uint8_t* buffer,
423  size_t bufferLength)
424 {
425  return ndn_NameComponent_setFromNumberWithMarker
426  (self, version, 0xFD, buffer, bufferLength);
427 }
428 
443 static __inline ndn_Error
444 ndn_NameComponent_setTimestamp
445  (struct ndn_NameComponent *self, uint64_t timestamp, uint8_t* buffer,
446  size_t bufferLength)
447 {
448  return ndn_NameComponent_setFromNumberWithMarker
449  (self, timestamp, 0xFC, buffer, bufferLength);
450 }
451 
465 static __inline ndn_Error
466 ndn_NameComponent_setSequenceNumber
467  (struct ndn_NameComponent *self, uint64_t sequenceNumber, uint8_t* buffer,
468  size_t bufferLength)
469 {
470  return ndn_NameComponent_setFromNumberWithMarker
471  (self, sequenceNumber, 0xFE, buffer, bufferLength);
472 }
473 
483 ndn_Error
484 ndn_NameComponent_setImplicitSha256Digest
485  (struct ndn_NameComponent *self, const uint8_t* digest, size_t digestLength);
486 
496 ndn_Error
497 ndn_NameComponent_setParametersSha256Digest
498  (struct ndn_NameComponent *self, const uint8_t* digest, size_t digestLength);
499 
506 static __inline void ndn_Name_initialize(struct ndn_Name *self, struct ndn_NameComponent *components, size_t maxComponents)
507 {
508  self->components = components;
509  self->maxComponents = maxComponents;
510  self->nComponents = 0;
511 }
512 
517 static __inline void
518 ndn_Name_clear(struct ndn_Name *self) { self->nComponents = 0; }
519 
528 int ndn_Name_equals(const struct ndn_Name *self, const struct ndn_Name *name);
529 
536 int ndn_Name_match(const struct ndn_Name *self, const struct ndn_Name *name);
537 
545 ndn_Error ndn_Name_appendComponent(struct ndn_Name *self, const uint8_t* value, size_t valueLength);
546 
556 ndn_Error ndn_Name_appendNameComponent
557  (struct ndn_Name *self, const struct ndn_NameComponent *component);
558 
567 ndn_Error ndn_Name_appendName(struct ndn_Name *self, const struct ndn_Name *name);
568 
575 static __inline ndn_Error ndn_Name_appendBlob(struct ndn_Name *self, struct ndn_Blob *value)
576 {
577  return ndn_Name_appendComponent(self, value->value, value->length);
578 }
579 
590 static __inline ndn_Error ndn_Name_appendImplicitSha256Digest
591  (struct ndn_Name *self, const uint8_t* digest, size_t digestLength)
592 {
593  ndn_Error error;
594  // Add an empty component.
595  if ((error = ndn_Name_appendComponent(self, 0, 0)))
596  return error;
597  return ndn_NameComponent_setImplicitSha256Digest
598  (&self->components[self->nComponents - 1], digest, digestLength);
599 }
600 
612 static __inline ndn_Error ndn_Name_appendParametersSha256Digest
613  (struct ndn_Name *self, const uint8_t* digest, size_t digestLength)
614 {
615  ndn_Error error;
616  // Add an empty component.
617  if ((error = ndn_Name_appendComponent(self, 0, 0)))
618  return error;
619  return ndn_NameComponent_setParametersSha256Digest
620  (&self->components[self->nComponents - 1], digest, digestLength);
621 }
622 
629 ndn_Error ndn_Name_appendString(struct ndn_Name *self, const char * value);
630 
638 ndn_Error
639 ndn_Name_setFromName(struct ndn_Name *self, const struct ndn_Name *other);
640 
641 #ifdef __cplusplus
642 }
643 #endif
644 
645 #endif
646 
size_t length
the number of bytes in value.
Definition: blob-types.h:35
An ndn_NameComponent holds a pointer to the component value.
Definition: name-types.h:47
An ndn_Name holds an array of ndn_NameComponent.
Definition: name-types.h:56
const uint8_t * value
pointer to the pre-allocated buffer for the value.
Definition: blob-types.h:34
Copyright (C) 2015-2018 Regents of the University of California.
Definition: blob-types.h:33