blob: 99199c886ec4cbd41696a88dd57d5487aeacc12e [file] [log] [blame]
Jeff Thompson47eecfc2013-07-07 22:56:46 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
Jeff Thompson5d89cb92013-06-27 15:57:15 -07004 */
5
6#ifndef NDN_NAME_H
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07007#define NDN_NAME_H
Jeff Thompson5d89cb92013-06-27 15:57:15 -07008
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07009#ifdef __cplusplus
Jeff Thompson5d89cb92013-06-27 15:57:15 -070010extern "C" {
11#endif
12
Jeff Thompson2934a5b2013-07-03 17:45:53 -070013/**
14 * An ndn_NameComponent holds a pointer to the component value.
15 */
Jeff Thompsonb0fd64f2013-06-27 16:02:36 -070016struct ndn_NameComponent {
Jeff Thompson2934a5b2013-07-03 17:45:53 -070017 unsigned char *value; /**< pointer to the pre-allocated buffer for the component value */
Jeff Thompson08d56292013-06-27 18:20:44 -070018 unsigned int valueLength; /**< the number of bytes in value */
Jeff Thompson5d89cb92013-06-27 15:57:15 -070019};
20
Jeff Thompson2934a5b2013-07-03 17:45:53 -070021/**
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 Thompsond1427fb2013-08-29 17:20:32 -070027static inline void ndn_NameComponent_initialize(struct ndn_NameComponent *self, unsigned char *value, unsigned int valueLength)
Jeff Thompsonb0fd64f2013-06-27 16:02:36 -070028{
29 self->value = value;
30 self->valueLength = valueLength;
31}
Jeff Thompson5d89cb92013-06-27 15:57:15 -070032
Jeff Thompson2934a5b2013-07-03 17:45:53 -070033/**
34 * An ndn_Name holds an array of ndn_NameComponent.
35 */
Jeff Thompson5d89cb92013-06-27 15:57:15 -070036struct ndn_Name {
Jeff Thompson08d56292013-06-27 18:20:44 -070037 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 Thompson5d89cb92013-06-27 15:57:15 -070040};
41
Jeff Thompson08d56292013-06-27 18:20:44 -070042/**
43 * Initialize an ndn_Name struct with the components array.
44 * @param self pointer to the ndn_Name struct
Jeff Thompson2934a5b2013-07-03 17:45:53 -070045 * @param components the pre-allocated array of ndn_NameComponent
Jeff Thompson08d56292013-06-27 18:20:44 -070046 * @param maxComponents the number of elements in the allocated components array
47 */
Jeff Thompsond1427fb2013-08-29 17:20:32 -070048static inline void ndn_Name_initialize(struct ndn_Name *self, struct ndn_NameComponent *components, unsigned int maxComponents)
Jeff Thompsonb0fd64f2013-06-27 16:02:36 -070049{
Jeff Thompson08d56292013-06-27 18:20:44 -070050 self->components = components;
51 self->maxComponents = maxComponents;
Jeff Thompsonb0fd64f2013-06-27 16:02:36 -070052 self->nComponents = 0;
53}
Jeff Thompson5d89cb92013-06-27 15:57:15 -070054
Jeff Thompsonf1ba9bd2013-08-12 17:43:08 -070055/**
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 */
61int ndn_Name_match(struct ndn_Name *self, struct ndn_Name *name);
62
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070063#ifdef __cplusplus
Jeff Thompson5d89cb92013-06-27 15:57:15 -070064}
65#endif
66
Jeff Thompson08d56292013-06-27 18:20:44 -070067#endif
Jeff Thompson5d89cb92013-06-27 15:57:15 -070068