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