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  ndn_Blob_initialize(&self->value, value, valueLength);
43 }
44 
52 static __inline int
53 ndn_NameComponent_isSegment(const struct ndn_NameComponent *self)
54 {
55  return (self->value.length >= 1 && self->value.value[0] == 0x00 &&
56  self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
57 }
58 
66 static __inline int
67 ndn_NameComponent_isSegmentOffset(const struct ndn_NameComponent *self)
68 {
69  return (self->value.length >= 1 && self->value.value[0] == 0xFB &&
70  self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
71 }
72 
80 static __inline int
81 ndn_NameComponent_isVersion(const struct ndn_NameComponent *self)
82 {
83  return (self->value.length >= 1 && self->value.value[0] == 0xFD &&
84  self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
85 }
86 
94 static __inline int
95 ndn_NameComponent_isTimestamp(const struct ndn_NameComponent *self)
96 {
97  return (self->value.length >= 1 && self->value.value[0] == 0xFC &&
98  self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
99 }
100 
108 static __inline int
109 ndn_NameComponent_isSequenceNumber(const struct ndn_NameComponent *self)
110 {
111  return (self->value.length >= 1 && self->value.value[0] == 0xFE &&
112  self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
113 }
114 
120 static __inline int
121 ndn_NameComponent_isGeneric(const struct ndn_NameComponent *self)
122 {
123  return self->type == ndn_NameComponentType_GENERIC ? 1 : 0;
124 }
125 
131 static __inline int
132 ndn_NameComponent_isImplicitSha256Digest(const struct ndn_NameComponent *self)
133 {
134  return self->type == ndn_NameComponentType_IMPLICIT_SHA256_DIGEST ? 1 : 0;
135 }
136 
142 uint64_t ndn_NameComponent_toNumber(const struct ndn_NameComponent *self);
143 
151 ndn_Error ndn_NameComponent_toNumberWithMarker
152  (const struct ndn_NameComponent *self, uint8_t marker, uint64_t *result);
153 
163 static __inline ndn_Error
164 ndn_NameComponent_toSegment
165  (const struct ndn_NameComponent *self, uint64_t *result)
166 {
167  return ndn_NameComponent_toNumberWithMarker(self, 0x00, result);
168 }
169 
179 static __inline ndn_Error
180 ndn_NameComponent_toSegmentOffset
181  (const struct ndn_NameComponent *self, uint64_t *result)
182 {
183  return ndn_NameComponent_toNumberWithMarker(self, 0xFB, result);
184 }
185 
197 static __inline ndn_Error
198 ndn_NameComponent_toVersion
199  (const struct ndn_NameComponent *self, uint64_t *result)
200 {
201  return ndn_NameComponent_toNumberWithMarker(self, 0xFD, result);
202 }
203 
214 static __inline ndn_Error
215 ndn_NameComponent_toTimestamp
216  (const struct ndn_NameComponent *self, uint64_t *result)
217 {
218  return ndn_NameComponent_toNumberWithMarker(self, 0xFC, result);
219 }
220 
230 static __inline ndn_Error
231 ndn_NameComponent_toSequenceNumber
232  (const struct ndn_NameComponent *self, uint64_t *result)
233 {
234  return ndn_NameComponent_toNumberWithMarker(self, 0xFE, result);
235 }
236 
245 ndn_Error ndn_NameComponent_toNumberWithPrefix
246  (const struct ndn_NameComponent *self, const uint8_t *prefix,
247  size_t prefixLength, uint64_t *result);
248 
256 int
257 ndn_NameComponent_hasPrefix
258  (const struct ndn_NameComponent *self, const uint8_t *prefix,
259  size_t prefixLength);
260 
267 int ndn_NameComponent_equals
268  (const struct ndn_NameComponent *self, const struct ndn_NameComponent *other);
269 
278 int ndn_NameComponent_compare
279  (const struct ndn_NameComponent *self, const struct ndn_NameComponent *other);
280 
286 static __inline void
287 ndn_NameComponent_setFromNameComponent
288  (struct ndn_NameComponent *self, const struct ndn_NameComponent *other)
289 {
290  *self = *other;
291 }
292 
306 ndn_Error
307 ndn_NameComponent_setFromNumber
308  (struct ndn_NameComponent *self, uint64_t number, uint8_t *buffer,
309  size_t bufferLength);
310 
325 ndn_Error
326 ndn_NameComponent_setFromNumberWithMarker
327  (struct ndn_NameComponent *self, uint64_t number, uint8_t marker,
328  uint8_t *buffer, size_t bufferLength);
329 
343 static __inline ndn_Error
344 ndn_NameComponent_setSegment
345  (struct ndn_NameComponent *self, uint64_t segment, uint8_t* buffer,
346  size_t bufferLength)
347 {
348  return ndn_NameComponent_setFromNumberWithMarker
349  (self, segment, 0x00, buffer, bufferLength);
350 }
351 
365 static __inline ndn_Error
366 ndn_NameComponent_setSegmentOffset
367  (struct ndn_NameComponent *self, uint64_t segmentOffset, uint8_t* buffer,
368  size_t bufferLength)
369 {
370  return ndn_NameComponent_setFromNumberWithMarker
371  (self, segmentOffset, 0xFB, buffer, bufferLength);
372 }
373 
388 static __inline ndn_Error
389 ndn_NameComponent_setVersion
390  (struct ndn_NameComponent *self, uint64_t version, uint8_t* buffer,
391  size_t bufferLength)
392 {
393  return ndn_NameComponent_setFromNumberWithMarker
394  (self, version, 0xFD, buffer, bufferLength);
395 }
396 
411 static __inline ndn_Error
412 ndn_NameComponent_setTimestamp
413  (struct ndn_NameComponent *self, uint64_t timestamp, uint8_t* buffer,
414  size_t bufferLength)
415 {
416  return ndn_NameComponent_setFromNumberWithMarker
417  (self, timestamp, 0xFC, buffer, bufferLength);
418 }
419 
433 static __inline ndn_Error
434 ndn_NameComponent_setSequenceNumber
435  (struct ndn_NameComponent *self, uint64_t sequenceNumber, uint8_t* buffer,
436  size_t bufferLength)
437 {
438  return ndn_NameComponent_setFromNumberWithMarker
439  (self, sequenceNumber, 0xFE, buffer, bufferLength);
440 }
441 
451 ndn_Error
452 ndn_NameComponent_setImplicitSha256Digest
453  (struct ndn_NameComponent *self, const uint8_t* digest, size_t digestLength);
454 
461 static __inline void ndn_Name_initialize(struct ndn_Name *self, struct ndn_NameComponent *components, size_t maxComponents)
462 {
463  self->components = components;
464  self->maxComponents = maxComponents;
465  self->nComponents = 0;
466 }
467 
472 static __inline void
473 ndn_Name_clear(struct ndn_Name *self) { self->nComponents = 0; }
474 
483 int ndn_Name_equals(const struct ndn_Name *self, const struct ndn_Name *name);
484 
491 int ndn_Name_match(const struct ndn_Name *self, const struct ndn_Name *name);
492 
500 ndn_Error ndn_Name_appendComponent(struct ndn_Name *self, const uint8_t* value, size_t valueLength);
501 
508 static __inline ndn_Error ndn_Name_appendBlob(struct ndn_Name *self, struct ndn_Blob *value)
509 {
510  return ndn_Name_appendComponent(self, value->value, value->length);
511 }
512 
523 static __inline ndn_Error ndn_Name_appendImplicitSha256Digest
524  (struct ndn_Name *self, const uint8_t* digest, size_t digestLength)
525 {
526  ndn_Error error;
527  // Add an empty component.
528  if ((error = ndn_Name_appendComponent(self, 0, 0)))
529  return error;
530  return ndn_NameComponent_setImplicitSha256Digest
531  (&self->components[self->nComponents - 1], digest, digestLength);
532 }
533 
540 ndn_Error ndn_Name_appendString(struct ndn_Name *self, const char * value);
541 
549 ndn_Error
550 ndn_Name_setFromName(struct ndn_Name *self, const struct ndn_Name *other);
551 
552 #ifdef __cplusplus
553 }
554 #endif
555 
556 #endif
557 
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:41
An ndn_Name holds an array of ndn_NameComponent.
Definition: name-types.h:49
const uint8_t * value
pointer to the pre-allocated buffer for the value.
Definition: blob-types.h:34
Copyright (C) 2015-2016 Regents of the University of California.
Definition: blob-types.h:33