Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame^] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
Jeff Thompson | 5d89cb9 | 2013-06-27 15:57:15 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef NDN_NAME_H |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 8 | #define NDN_NAME_H |
Jeff Thompson | 5d89cb9 | 2013-06-27 15:57:15 -0700 | [diff] [blame] | 9 | |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 10 | #ifdef __cplusplus |
Jeff Thompson | 5d89cb9 | 2013-06-27 15:57:15 -0700 | [diff] [blame] | 11 | extern "C" { |
| 12 | #endif |
| 13 | |
Jeff Thompson | 2934a5b | 2013-07-03 17:45:53 -0700 | [diff] [blame] | 14 | /** |
| 15 | * An ndn_NameComponent holds a pointer to the component value. |
| 16 | */ |
Jeff Thompson | b0fd64f | 2013-06-27 16:02:36 -0700 | [diff] [blame] | 17 | struct ndn_NameComponent { |
Jeff Thompson | 2934a5b | 2013-07-03 17:45:53 -0700 | [diff] [blame] | 18 | unsigned char *value; /**< pointer to the pre-allocated buffer for the component value */ |
Jeff Thompson | 08d5629 | 2013-06-27 18:20:44 -0700 | [diff] [blame] | 19 | unsigned int valueLength; /**< the number of bytes in value */ |
Jeff Thompson | 5d89cb9 | 2013-06-27 15:57:15 -0700 | [diff] [blame] | 20 | }; |
| 21 | |
Jeff Thompson | 2934a5b | 2013-07-03 17:45:53 -0700 | [diff] [blame] | 22 | /** |
| 23 | * |
| 24 | * @param self pointer to the ndn_NameComponent struct |
| 25 | * @param value the pre-allocated buffer for the component value |
| 26 | * @param valueLength the number of bytes in value |
| 27 | */ |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 28 | static inline void ndn_NameComponent_initialize(struct ndn_NameComponent *self, unsigned char *value, unsigned int valueLength) |
Jeff Thompson | b0fd64f | 2013-06-27 16:02:36 -0700 | [diff] [blame] | 29 | { |
| 30 | self->value = value; |
| 31 | self->valueLength = valueLength; |
| 32 | } |
Jeff Thompson | 5d89cb9 | 2013-06-27 15:57:15 -0700 | [diff] [blame] | 33 | |
Jeff Thompson | 2934a5b | 2013-07-03 17:45:53 -0700 | [diff] [blame] | 34 | /** |
| 35 | * An ndn_Name holds an array of ndn_NameComponent. |
| 36 | */ |
Jeff Thompson | 5d89cb9 | 2013-06-27 15:57:15 -0700 | [diff] [blame] | 37 | struct ndn_Name { |
Jeff Thompson | 08d5629 | 2013-06-27 18:20:44 -0700 | [diff] [blame] | 38 | struct ndn_NameComponent *components; /**< pointer to the array of components. */ |
| 39 | unsigned int maxComponents; /**< the number of elements in the allocated components array */ |
| 40 | unsigned int nComponents; /**< the number of components in the name */ |
Jeff Thompson | 5d89cb9 | 2013-06-27 15:57:15 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
Jeff Thompson | 08d5629 | 2013-06-27 18:20:44 -0700 | [diff] [blame] | 43 | /** |
| 44 | * Initialize an ndn_Name struct with the components array. |
| 45 | * @param self pointer to the ndn_Name struct |
Jeff Thompson | 2934a5b | 2013-07-03 17:45:53 -0700 | [diff] [blame] | 46 | * @param components the pre-allocated array of ndn_NameComponent |
Jeff Thompson | 08d5629 | 2013-06-27 18:20:44 -0700 | [diff] [blame] | 47 | * @param maxComponents the number of elements in the allocated components array |
| 48 | */ |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 49 | static inline void ndn_Name_initialize(struct ndn_Name *self, struct ndn_NameComponent *components, unsigned int maxComponents) |
Jeff Thompson | b0fd64f | 2013-06-27 16:02:36 -0700 | [diff] [blame] | 50 | { |
Jeff Thompson | 08d5629 | 2013-06-27 18:20:44 -0700 | [diff] [blame] | 51 | self->components = components; |
| 52 | self->maxComponents = maxComponents; |
Jeff Thompson | b0fd64f | 2013-06-27 16:02:36 -0700 | [diff] [blame] | 53 | self->nComponents = 0; |
| 54 | } |
Jeff Thompson | 5d89cb9 | 2013-06-27 15:57:15 -0700 | [diff] [blame] | 55 | |
Jeff Thompson | f1ba9bd | 2013-08-12 17:43:08 -0700 | [diff] [blame] | 56 | /** |
| 57 | * Return true if the N components of this name are the same as the first N components of the given name. |
| 58 | * @param self A pointer to the ndn_Name struct. |
| 59 | * @param name A pointer to the other name to match. |
| 60 | * @return 1 if this matches the given name, 0 otherwise. This always returns 1 if this name is empty. |
| 61 | */ |
| 62 | int ndn_Name_match(struct ndn_Name *self, struct ndn_Name *name); |
| 63 | |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 64 | #ifdef __cplusplus |
Jeff Thompson | 5d89cb9 | 2013-06-27 15:57:15 -0700 | [diff] [blame] | 65 | } |
| 66 | #endif |
| 67 | |
Jeff Thompson | 08d5629 | 2013-06-27 18:20:44 -0700 | [diff] [blame] | 68 | #endif |
Jeff Thompson | 5d89cb9 | 2013-06-27 15:57:15 -0700 | [diff] [blame] | 69 | |