blob: 544e3cae825b23a8bfd3c1aa7b499e40d3a18752 [file] [log] [blame]
Jeff Thompson47eecfc2013-07-07 22:56:46 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson47eecfc2013-07-07 22:56:46 -07004 * See COPYING for copyright and distribution information.
Jeff Thompson5d89cb92013-06-27 15:57:15 -07005 */
6
7#ifndef NDN_NAME_H
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07008#define NDN_NAME_H
Jeff Thompson5d89cb92013-06-27 15:57:15 -07009
Jeff Thompson93034532013-10-08 11:52:43 -070010#include "util/blob.h"
11
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070012#ifdef __cplusplus
Jeff Thompson5d89cb92013-06-27 15:57:15 -070013extern "C" {
14#endif
15
Jeff Thompson2934a5b2013-07-03 17:45:53 -070016/**
17 * An ndn_NameComponent holds a pointer to the component value.
18 */
Jeff Thompsonb0fd64f2013-06-27 16:02:36 -070019struct ndn_NameComponent {
Jeff Thompson93034532013-10-08 11:52:43 -070020 struct ndn_Blob value; /**< A Blob with a pointer to the pre-allocated buffer for the component value */
Jeff Thompson5d89cb92013-06-27 15:57:15 -070021};
22
Jeff Thompson2934a5b2013-07-03 17:45:53 -070023/**
24 *
25 * @param self pointer to the ndn_NameComponent struct
26 * @param value the pre-allocated buffer for the component value
27 * @param valueLength the number of bytes in value
28 */
Jeff Thompson97223af2013-09-24 17:01:27 -070029static inline void ndn_NameComponent_initialize(struct ndn_NameComponent *self, uint8_t *value, size_t valueLength)
Jeff Thompsonb0fd64f2013-06-27 16:02:36 -070030{
Jeff Thompson93034532013-10-08 11:52:43 -070031 ndn_Blob_initialize(&self->value, value, valueLength);
Jeff Thompsonb0fd64f2013-06-27 16:02:36 -070032}
Jeff Thompson5d89cb92013-06-27 15:57:15 -070033
Jeff Thompson2934a5b2013-07-03 17:45:53 -070034/**
35 * An ndn_Name holds an array of ndn_NameComponent.
36 */
Jeff Thompson5d89cb92013-06-27 15:57:15 -070037struct ndn_Name {
Jeff Thompson08d56292013-06-27 18:20:44 -070038 struct ndn_NameComponent *components; /**< pointer to the array of components. */
Jeff Thompson97223af2013-09-24 17:01:27 -070039 size_t maxComponents; /**< the number of elements in the allocated components array */
40 size_t nComponents; /**< the number of components in the name */
Jeff Thompson5d89cb92013-06-27 15:57:15 -070041};
42
Jeff Thompson08d56292013-06-27 18:20:44 -070043/**
44 * Initialize an ndn_Name struct with the components array.
45 * @param self pointer to the ndn_Name struct
Jeff Thompson2934a5b2013-07-03 17:45:53 -070046 * @param components the pre-allocated array of ndn_NameComponent
Jeff Thompson08d56292013-06-27 18:20:44 -070047 * @param maxComponents the number of elements in the allocated components array
48 */
Jeff Thompson97223af2013-09-24 17:01:27 -070049static inline void ndn_Name_initialize(struct ndn_Name *self, struct ndn_NameComponent *components, size_t maxComponents)
Jeff Thompsonb0fd64f2013-06-27 16:02:36 -070050{
Jeff Thompson08d56292013-06-27 18:20:44 -070051 self->components = components;
52 self->maxComponents = maxComponents;
Jeff Thompsonb0fd64f2013-06-27 16:02:36 -070053 self->nComponents = 0;
54}
Jeff Thompson5d89cb92013-06-27 15:57:15 -070055
Jeff Thompsonf1ba9bd2013-08-12 17:43:08 -070056/**
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 */
62int ndn_Name_match(struct ndn_Name *self, struct ndn_Name *name);
63
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070064#ifdef __cplusplus
Jeff Thompson5d89cb92013-06-27 15:57:15 -070065}
66#endif
67
Jeff Thompson08d56292013-06-27 18:20:44 -070068#endif
Jeff Thompson5d89cb92013-06-27 15:57:15 -070069