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 | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef NDN_INTEREST_H |
| 7 | #define NDN_INTEREST_H |
| 8 | |
| 9 | #include "Name.h" |
| 10 | |
| 11 | #ifdef __cplusplus |
| 12 | extern "C" { |
| 13 | #endif |
| 14 | |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 15 | typedef enum { |
| 16 | ndn_Exclude_COMPONENT = 0, |
| 17 | ndn_Exclude_ANY = 1 |
| 18 | } ndn_ExcludeType; |
| 19 | |
| 20 | /** |
| 21 | * An ndn_ExcludeEntry holds an ndn_ExcludeType, and if it is a COMPONENT, it holds a pointer to the component value. |
| 22 | */ |
| 23 | struct ndn_ExcludeEntry { |
| 24 | ndn_ExcludeType type; |
| 25 | unsigned char *component; /**< pointer to the pre-allocated buffer for the component value */ |
| 26 | unsigned int componentLength; /**< the number of bytes in value */ |
| 27 | }; |
| 28 | |
| 29 | /** |
| 30 | * |
| 31 | * @param self pointer to the ndn_NameComponent struct |
| 32 | * @param type one of the ndn_ExcludeType enum |
| 33 | * @param component the pre-allocated buffer for the component value, only used if type is ndn_Exclude_COMPONENT |
| 34 | * @param componentLength the number of bytes in value, only used if type is ndn_Exclude_COMPONENT |
| 35 | */ |
| 36 | static inline void ndn_ExcludeEntry_init(struct ndn_ExcludeEntry *self, ndn_ExcludeType type, unsigned char *component, unsigned int componentLength) |
| 37 | { |
| 38 | self->type = type; |
| 39 | self->component = component; |
| 40 | self->componentLength = componentLength; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * An ndn_Exclude holds an array of ndn_ExcludeEntry. |
| 45 | */ |
| 46 | struct ndn_Exclude { |
| 47 | struct ndn_ExcludeEntry *entries; /**< pointer to the array of entries. */ |
| 48 | unsigned int maxEntries; /**< the number of elements in the allocated entries array */ |
| 49 | unsigned int nEntries; /**< the number of entries in the exclude, 0 for no exclude */ |
| 50 | }; |
| 51 | /** |
| 52 | * Initialize an ndn_Exclude struct with the entries array. |
| 53 | * @param self pointer to the ndn_Exclude struct |
| 54 | * @param entries the pre-allocated array of ndn_ExcludeEntry |
| 55 | * @param maxEntries the number of elements in the allocated entries array |
| 56 | */ |
| 57 | static inline void ndn_Exclude_init(struct ndn_Exclude *self, struct ndn_ExcludeEntry *entries, unsigned int maxEntries) |
| 58 | { |
| 59 | self->entries = entries; |
| 60 | self->maxEntries = maxEntries; |
| 61 | self->nEntries = 0; |
| 62 | } |
| 63 | |
Jeff Thompson | ba70f8c | 2013-07-08 15:34:20 -0700 | [diff] [blame] | 64 | enum { |
| 65 | ndn_Interest_CHILD_SELECTOR_LEFT = 0, |
| 66 | ndn_Interest_CHILD_SELECTOR_RIGHT = 1, |
| 67 | ndn_Interest_ANSWER_CONTENT_STORE = 1, |
| 68 | ndn_Interest_ANSWER_GENERATED = 2, |
| 69 | ndn_Interest_ANSWER_STALE = 4, // Stale answer OK |
| 70 | ndn_Interest_MARK_STALE = 16, // Must have scope 0. Michael calls this a "hack" |
| 71 | |
| 72 | ndn_Interest_DEFAULT_ANSWER_ORIGIN_KIND = ndn_Interest_ANSWER_CONTENT_STORE | ndn_Interest_ANSWER_GENERATED |
| 73 | }; |
| 74 | |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 75 | struct ndn_Interest { |
| 76 | struct ndn_Name name; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 77 | int minSuffixComponents; /**< -1 for none */ |
Jeff Thompson | f2e5e28 | 2013-07-08 15:26:16 -0700 | [diff] [blame] | 78 | int maxSuffixComponents; /**< -1 for none */ |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 79 | unsigned char *publisherPublicKeyDigest; /**< pointer to pre-allocated buffer. 0 for none */ |
Jeff Thompson | 88ab5dd | 2013-07-07 20:47:46 -0700 | [diff] [blame] | 80 | unsigned int publisherPublicKeyDigestLength; /**< length of publisherPublicKeyDigest. 0 for none */ |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 81 | struct ndn_Exclude exclude; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 82 | int childSelector; /**< -1 for none */ |
| 83 | int answerOriginKind; /**< -1 for none */ |
| 84 | int scope; /**< -1 for none */ |
| 85 | int interestLifetime; /**< milliseconds. -1 for none */ |
| 86 | unsigned char *nonce; /**< pointer to pre-allocated buffer. 0 for none */ |
Jeff Thompson | 88ab5dd | 2013-07-07 20:47:46 -0700 | [diff] [blame] | 87 | unsigned int nonceLength; /**< length of nonce. 0 for none */ |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 90 | /** |
| 91 | * Initialize an ndn_Interest_init struct with the pre-allocated nameComponents and excludeEntries, |
| 92 | * and defaults for all the values. |
| 93 | * @param self pointer to the ndn_Interest struct |
| 94 | * @param nameComponents the pre-allocated array of ndn_NameComponent |
| 95 | * @param maxNameComponents the number of elements in the allocated nameComponents array |
| 96 | * @param excludeEntries the pre-allocated array of ndn_ExcludeEntry |
| 97 | * @param maxExcludeEntries the number of elements in the allocated excludeEntries array |
| 98 | */ |
| 99 | static inline void ndn_Interest_init |
| 100 | (struct ndn_Interest *self, struct ndn_NameComponent *nameComponents, unsigned int maxNameComponents, |
| 101 | struct ndn_ExcludeEntry *excludeEntries, unsigned int maxExcludeEntries) |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 102 | { |
| 103 | ndn_Name_init(&self->name, nameComponents, maxNameComponents); |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 104 | self->minSuffixComponents = -1; |
Jeff Thompson | f2e5e28 | 2013-07-08 15:26:16 -0700 | [diff] [blame] | 105 | self->maxSuffixComponents = -1; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 106 | self->publisherPublicKeyDigest = 0; |
Jeff Thompson | 462618c | 2013-07-08 15:22:15 -0700 | [diff] [blame] | 107 | self->publisherPublicKeyDigestLength = 0; |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 108 | ndn_Exclude_init(&self->exclude, excludeEntries, maxExcludeEntries); |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 109 | self->childSelector = -1; |
| 110 | self->answerOriginKind = -1; |
| 111 | self->scope = -1; |
| 112 | self->interestLifetime = -1; |
Jeff Thompson | 462618c | 2013-07-08 15:22:15 -0700 | [diff] [blame] | 113 | self->nonce = 0; |
| 114 | self->nonceLength = 0; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | #ifdef __cplusplus |
| 118 | } |
| 119 | #endif |
| 120 | |
| 121 | #endif |
| 122 | |