blob: b596c50f511dd71670c75f70f6da108485937507 [file] [log] [blame]
Jeff Thompson47eecfc2013-07-07 22:56:46 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
Jeff Thompsonb7f95562013-07-03 18:36:42 -07004 */
5
6#ifndef NDN_INTEREST_H
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07007#define NDN_INTEREST_H
Jeff Thompsonb7f95562013-07-03 18:36:42 -07008
Jeff Thompson53412192013-08-06 13:35:50 -07009#include "name.h"
10#include "publisher-public-key-digest.h"
Jeff Thompsonb7f95562013-07-03 18:36:42 -070011
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070012#ifdef __cplusplus
Jeff Thompsonb7f95562013-07-03 18:36:42 -070013extern "C" {
14#endif
15
Jeff Thompsonf084ec62013-07-09 12:32:52 -070016typedef enum {
17 ndn_Exclude_COMPONENT = 0,
18 ndn_Exclude_ANY = 1
19} ndn_ExcludeType;
20
21/**
22 * An ndn_ExcludeEntry holds an ndn_ExcludeType, and if it is a COMPONENT, it holds a pointer to the component value.
23 */
24struct ndn_ExcludeEntry {
25 ndn_ExcludeType type;
26 unsigned char *component; /**< pointer to the pre-allocated buffer for the component value */
27 unsigned int componentLength; /**< the number of bytes in value */
28};
29
30/**
31 *
32 * @param self pointer to the ndn_NameComponent struct
33 * @param type one of the ndn_ExcludeType enum
34 * @param component the pre-allocated buffer for the component value, only used if type is ndn_Exclude_COMPONENT
35 * @param componentLength the number of bytes in value, only used if type is ndn_Exclude_COMPONENT
36 */
37static inline void ndn_ExcludeEntry_init(struct ndn_ExcludeEntry *self, ndn_ExcludeType type, unsigned char *component, unsigned int componentLength)
38{
39 self->type = type;
40 self->component = component;
41 self->componentLength = componentLength;
42}
43
44/**
45 * An ndn_Exclude holds an array of ndn_ExcludeEntry.
46 */
47struct ndn_Exclude {
48 struct ndn_ExcludeEntry *entries; /**< pointer to the array of entries. */
49 unsigned int maxEntries; /**< the number of elements in the allocated entries array */
50 unsigned int nEntries; /**< the number of entries in the exclude, 0 for no exclude */
51};
52/**
53 * Initialize an ndn_Exclude struct with the entries array.
54 * @param self pointer to the ndn_Exclude struct
55 * @param entries the pre-allocated array of ndn_ExcludeEntry
56 * @param maxEntries the number of elements in the allocated entries array
57 */
58static inline void ndn_Exclude_init(struct ndn_Exclude *self, struct ndn_ExcludeEntry *entries, unsigned int maxEntries)
59{
60 self->entries = entries;
61 self->maxEntries = maxEntries;
62 self->nEntries = 0;
63}
64
Jeff Thompsonba70f8c2013-07-08 15:34:20 -070065enum {
66 ndn_Interest_CHILD_SELECTOR_LEFT = 0,
67 ndn_Interest_CHILD_SELECTOR_RIGHT = 1,
68 ndn_Interest_ANSWER_CONTENT_STORE = 1,
69 ndn_Interest_ANSWER_GENERATED = 2,
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070070 ndn_Interest_ANSWER_STALE = 4, // Stale answer OK
71 ndn_Interest_MARK_STALE = 16, // Must have scope 0. Michael calls this a "hack"
Jeff Thompsonba70f8c2013-07-08 15:34:20 -070072
73 ndn_Interest_DEFAULT_ANSWER_ORIGIN_KIND = ndn_Interest_ANSWER_CONTENT_STORE | ndn_Interest_ANSWER_GENERATED
74};
75
Jeff Thompson8238d002013-07-10 11:56:49 -070076/**
77 * An ndn_Interest holds an ndn_Name and other fields for an interest.
78 */
Jeff Thompsonb7f95562013-07-03 18:36:42 -070079struct ndn_Interest {
80 struct ndn_Name name;
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070081 int minSuffixComponents; /**< -1 for none */
82 int maxSuffixComponents; /**< -1 for none */
Jeff Thompson8238d002013-07-10 11:56:49 -070083 struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest;
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070084 struct ndn_Exclude exclude;
85 int childSelector; /**< -1 for none */
86 int answerOriginKind; /**< -1 for none */
87 int scope; /**< -1 for none */
88 double interestLifetimeMilliseconds; /**< milliseconds. -1.0 for none */
89 unsigned char *nonce; /**< pointer to pre-allocated buffer. 0 for none */
Jeff Thompson88ab5dd2013-07-07 20:47:46 -070090 unsigned int nonceLength; /**< length of nonce. 0 for none */
Jeff Thompsonb7f95562013-07-03 18:36:42 -070091};
92
Jeff Thompsonf084ec62013-07-09 12:32:52 -070093/**
Jeff Thompsonb825c632013-07-10 17:59:29 -070094 * Initialize an ndn_Interest struct with the pre-allocated nameComponents and excludeEntries,
Jeff Thompsonf084ec62013-07-09 12:32:52 -070095 * and defaults for all the values.
96 * @param self pointer to the ndn_Interest struct
97 * @param nameComponents the pre-allocated array of ndn_NameComponent
98 * @param maxNameComponents the number of elements in the allocated nameComponents array
99 * @param excludeEntries the pre-allocated array of ndn_ExcludeEntry
100 * @param maxExcludeEntries the number of elements in the allocated excludeEntries array
101 */
102static inline void ndn_Interest_init
103 (struct ndn_Interest *self, struct ndn_NameComponent *nameComponents, unsigned int maxNameComponents,
104 struct ndn_ExcludeEntry *excludeEntries, unsigned int maxExcludeEntries)
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700105{
106 ndn_Name_init(&self->name, nameComponents, maxNameComponents);
Jeff Thompson2d27e2f2013-08-09 12:55:00 -0700107 self->minSuffixComponents = -1;
Jeff Thompsonf2e5e282013-07-08 15:26:16 -0700108 self->maxSuffixComponents = -1;
Jeff Thompson8238d002013-07-10 11:56:49 -0700109 ndn_PublisherPublicKeyDigest_init(&self->publisherPublicKeyDigest);
Jeff Thompsonf084ec62013-07-09 12:32:52 -0700110 ndn_Exclude_init(&self->exclude, excludeEntries, maxExcludeEntries);
Jeff Thompson2d27e2f2013-08-09 12:55:00 -0700111 self->childSelector = -1;
112 self->answerOriginKind = -1;
113 self->scope = -1;
114 self->interestLifetimeMilliseconds = -1.0;
115 self->nonce = 0;
116 self->nonceLength = 0;
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700117}
118
Jeff Thompson2d27e2f2013-08-09 12:55:00 -0700119#ifdef __cplusplus
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700120}
121#endif
122
123#endif
124