blob: 438fecd6db81a7f11e501ff884aab34ffe3e51bc [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 Thompsonb7f95562013-07-03 18:36:42 -07005 */
6
7#ifndef NDN_INTEREST_H
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07008#define NDN_INTEREST_H
Jeff Thompsonb7f95562013-07-03 18:36:42 -07009
Jeff Thompson25b4e612013-10-10 16:03:24 -070010#include <ndn-cpp/c/interest-types.h>
Jeff Thompson53412192013-08-06 13:35:50 -070011#include "name.h"
12#include "publisher-public-key-digest.h"
Jeff Thompsonb7f95562013-07-03 18:36:42 -070013
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070014#ifdef __cplusplus
Jeff Thompsonb7f95562013-07-03 18:36:42 -070015extern "C" {
16#endif
17
Jeff Thompsonf084ec62013-07-09 12:32:52 -070018/**
19 * An ndn_ExcludeEntry holds an ndn_ExcludeType, and if it is a COMPONENT, it holds a pointer to the component value.
20 */
21struct ndn_ExcludeEntry {
22 ndn_ExcludeType type;
Jeff Thompson38d0e082013-08-12 18:07:44 -070023 struct ndn_NameComponent component;
Jeff Thompsonf084ec62013-07-09 12:32:52 -070024};
25
26/**
27 *
28 * @param self pointer to the ndn_NameComponent struct
29 * @param type one of the ndn_ExcludeType enum
30 * @param component the pre-allocated buffer for the component value, only used if type is ndn_Exclude_COMPONENT
31 * @param componentLength the number of bytes in value, only used if type is ndn_Exclude_COMPONENT
32 */
Jeff Thompson97223af2013-09-24 17:01:27 -070033static inline void ndn_ExcludeEntry_initialize(struct ndn_ExcludeEntry *self, ndn_ExcludeType type, uint8_t *component, size_t componentLength)
Jeff Thompsonf084ec62013-07-09 12:32:52 -070034{
35 self->type = type;
Jeff Thompsond1427fb2013-08-29 17:20:32 -070036 ndn_NameComponent_initialize(&self->component, component, componentLength);
Jeff Thompsonf084ec62013-07-09 12:32:52 -070037}
38
39/**
40 * An ndn_Exclude holds an array of ndn_ExcludeEntry.
41 */
42struct ndn_Exclude {
43 struct ndn_ExcludeEntry *entries; /**< pointer to the array of entries. */
Jeff Thompson97223af2013-09-24 17:01:27 -070044 size_t maxEntries; /**< the number of elements in the allocated entries array */
45 size_t nEntries; /**< the number of entries in the exclude, 0 for no exclude */
Jeff Thompsonf084ec62013-07-09 12:32:52 -070046};
47/**
48 * Initialize an ndn_Exclude struct with the entries array.
Jeff Thompson3548a962013-08-12 18:23:09 -070049 * @param self A pointer to the ndn_Exclude struct.
Jeff Thompsonf084ec62013-07-09 12:32:52 -070050 * @param entries the pre-allocated array of ndn_ExcludeEntry
51 * @param maxEntries the number of elements in the allocated entries array
52 */
Jeff Thompson97223af2013-09-24 17:01:27 -070053static inline void ndn_Exclude_initialize(struct ndn_Exclude *self, struct ndn_ExcludeEntry *entries, size_t maxEntries)
Jeff Thompsonf084ec62013-07-09 12:32:52 -070054{
55 self->entries = entries;
56 self->maxEntries = maxEntries;
57 self->nEntries = 0;
58}
59
Jeff Thompson2e0e0882013-08-12 17:55:13 -070060/**
61 * Compare the components using NDN component ordering.
62 * A component is less if it is shorter, otherwise if equal length do a byte comparison.
63 * @param component1 A pointer to the first name component.
64 * @param component2 A pointer to the second name component.
65 * @return -1 if component1 is less than component2, 1 if greater or 0 if equal.
66 */
67int ndn_Exclude_compareComponents(struct ndn_NameComponent *component1, struct ndn_NameComponent *component2);
68
Jeff Thompson3548a962013-08-12 18:23:09 -070069/**
70 * Check if the component matches any of the exclude criteria.
71 * @param self A pointer to the ndn_Exclude struct.
72 * @param component A pointer to the name component to check.
73 * @return 1 if the component matches any of the exclude criteria, otherwise 0.
74 */
75int ndn_Exclude_matches(struct ndn_Exclude *self, struct ndn_NameComponent *component);
76
Jeff Thompsonba70f8c2013-07-08 15:34:20 -070077enum {
78 ndn_Interest_CHILD_SELECTOR_LEFT = 0,
79 ndn_Interest_CHILD_SELECTOR_RIGHT = 1,
Jeff Thompson635f1b02013-09-25 17:30:00 -070080
81 ndn_Interest_ANSWER_NO_CONTENT_STORE = 0,
Jeff Thompsonba70f8c2013-07-08 15:34:20 -070082 ndn_Interest_ANSWER_CONTENT_STORE = 1,
83 ndn_Interest_ANSWER_GENERATED = 2,
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070084 ndn_Interest_ANSWER_STALE = 4, // Stale answer OK
85 ndn_Interest_MARK_STALE = 16, // Must have scope 0. Michael calls this a "hack"
Jeff Thompsonba70f8c2013-07-08 15:34:20 -070086
87 ndn_Interest_DEFAULT_ANSWER_ORIGIN_KIND = ndn_Interest_ANSWER_CONTENT_STORE | ndn_Interest_ANSWER_GENERATED
88};
89
Jeff Thompson8238d002013-07-10 11:56:49 -070090/**
91 * An ndn_Interest holds an ndn_Name and other fields for an interest.
92 */
Jeff Thompsonb7f95562013-07-03 18:36:42 -070093struct ndn_Interest {
94 struct ndn_Name name;
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070095 int minSuffixComponents; /**< -1 for none */
96 int maxSuffixComponents; /**< -1 for none */
Jeff Thompson8238d002013-07-10 11:56:49 -070097 struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest;
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070098 struct ndn_Exclude exclude;
99 int childSelector; /**< -1 for none */
100 int answerOriginKind; /**< -1 for none */
101 int scope; /**< -1 for none */
Jeff Thompson9a8e82f2013-10-17 14:13:43 -0700102 ndn_Milliseconds interestLifetimeMilliseconds; /**< milliseconds. -1.0 for none */
Jeff Thompson93034532013-10-08 11:52:43 -0700103 struct ndn_Blob nonce; /**< The blob whose value is a pointer to a pre-allocated buffer. 0 for none */
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700104};
105
Jeff Thompsonf084ec62013-07-09 12:32:52 -0700106/**
Jeff Thompsonb825c632013-07-10 17:59:29 -0700107 * Initialize an ndn_Interest struct with the pre-allocated nameComponents and excludeEntries,
Jeff Thompsonf084ec62013-07-09 12:32:52 -0700108 * and defaults for all the values.
109 * @param self pointer to the ndn_Interest struct
110 * @param nameComponents the pre-allocated array of ndn_NameComponent
111 * @param maxNameComponents the number of elements in the allocated nameComponents array
112 * @param excludeEntries the pre-allocated array of ndn_ExcludeEntry
113 * @param maxExcludeEntries the number of elements in the allocated excludeEntries array
114 */
Jeff Thompsond1427fb2013-08-29 17:20:32 -0700115static inline void ndn_Interest_initialize
Jeff Thompson97223af2013-09-24 17:01:27 -0700116 (struct ndn_Interest *self, struct ndn_NameComponent *nameComponents, size_t maxNameComponents,
117 struct ndn_ExcludeEntry *excludeEntries, size_t maxExcludeEntries)
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700118{
Jeff Thompsond1427fb2013-08-29 17:20:32 -0700119 ndn_Name_initialize(&self->name, nameComponents, maxNameComponents);
Jeff Thompson2d27e2f2013-08-09 12:55:00 -0700120 self->minSuffixComponents = -1;
Jeff Thompsonf2e5e282013-07-08 15:26:16 -0700121 self->maxSuffixComponents = -1;
Jeff Thompsond1427fb2013-08-29 17:20:32 -0700122 ndn_PublisherPublicKeyDigest_initialize(&self->publisherPublicKeyDigest);
123 ndn_Exclude_initialize(&self->exclude, excludeEntries, maxExcludeEntries);
Jeff Thompson2d27e2f2013-08-09 12:55:00 -0700124 self->childSelector = -1;
125 self->answerOriginKind = -1;
126 self->scope = -1;
127 self->interestLifetimeMilliseconds = -1.0;
Jeff Thompson93034532013-10-08 11:52:43 -0700128 ndn_Blob_initialize(&self->nonce, 0, 0);
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700129}
130
Jeff Thompsonac9b2c82013-08-13 10:51:59 -0700131/**
132 * Check if self's name matches the given name (using ndn_Name_match) and the given name also conforms to the
133 * interest selectors.
134 * @param self A pointer to the ndn_Interest struct.
135 * @param name A pointer to the name to check.
136 * @return 1 if the name and interest selectors match, 0 otherwise.
137 */
138int ndn_Interest_matchesName(struct ndn_Interest *self, struct ndn_Name *name);
139
Jeff Thompson2d27e2f2013-08-09 12:55:00 -0700140#ifdef __cplusplus
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700141}
142#endif
143
144#endif
145