Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef NDN_INTEREST_H |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 8 | #define NDN_INTEREST_H |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 9 | |
Yingdi Yu | 61ec272 | 2014-01-20 14:22:32 -0800 | [diff] [blame^] | 10 | #include <ndn-cpp-dev/c/interest-types.h> |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 11 | #include "name.h" |
| 12 | #include "publisher-public-key-digest.h" |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 13 | |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 14 | #ifdef __cplusplus |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 15 | extern "C" { |
| 16 | #endif |
| 17 | |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 18 | /** |
| 19 | * An ndn_ExcludeEntry holds an ndn_ExcludeType, and if it is a COMPONENT, it holds a pointer to the component value. |
| 20 | */ |
| 21 | struct ndn_ExcludeEntry { |
| 22 | ndn_ExcludeType type; |
Jeff Thompson | 38d0e08 | 2013-08-12 18:07:44 -0700 | [diff] [blame] | 23 | struct ndn_NameComponent component; |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 24 | }; |
| 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 Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 33 | static inline void ndn_ExcludeEntry_initialize(struct ndn_ExcludeEntry *self, ndn_ExcludeType type, uint8_t *component, size_t componentLength) |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 34 | { |
| 35 | self->type = type; |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 36 | ndn_NameComponent_initialize(&self->component, component, componentLength); |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | /** |
| 40 | * An ndn_Exclude holds an array of ndn_ExcludeEntry. |
| 41 | */ |
| 42 | struct ndn_Exclude { |
| 43 | struct ndn_ExcludeEntry *entries; /**< pointer to the array of entries. */ |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 44 | 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 Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 46 | }; |
| 47 | /** |
| 48 | * Initialize an ndn_Exclude struct with the entries array. |
Jeff Thompson | 3548a96 | 2013-08-12 18:23:09 -0700 | [diff] [blame] | 49 | * @param self A pointer to the ndn_Exclude struct. |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 50 | * @param entries the pre-allocated array of ndn_ExcludeEntry |
| 51 | * @param maxEntries the number of elements in the allocated entries array |
| 52 | */ |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 53 | static inline void ndn_Exclude_initialize(struct ndn_Exclude *self, struct ndn_ExcludeEntry *entries, size_t maxEntries) |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 54 | { |
| 55 | self->entries = entries; |
| 56 | self->maxEntries = maxEntries; |
| 57 | self->nEntries = 0; |
| 58 | } |
| 59 | |
Jeff Thompson | 2e0e088 | 2013-08-12 17:55:13 -0700 | [diff] [blame] | 60 | /** |
| 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 | */ |
| 67 | int ndn_Exclude_compareComponents(struct ndn_NameComponent *component1, struct ndn_NameComponent *component2); |
| 68 | |
Jeff Thompson | 3548a96 | 2013-08-12 18:23:09 -0700 | [diff] [blame] | 69 | /** |
| 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 | */ |
| 75 | int ndn_Exclude_matches(struct ndn_Exclude *self, struct ndn_NameComponent *component); |
| 76 | |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 77 | /** |
| 78 | * An ndn_Interest holds an ndn_Name and other fields for an interest. |
| 79 | */ |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 80 | struct ndn_Interest { |
| 81 | struct ndn_Name name; |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 82 | int minSuffixComponents; /**< -1 for none */ |
| 83 | int maxSuffixComponents; /**< -1 for none */ |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 84 | struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest; |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 85 | struct ndn_Exclude exclude; |
| 86 | int childSelector; /**< -1 for none */ |
| 87 | int answerOriginKind; /**< -1 for none */ |
| 88 | int scope; /**< -1 for none */ |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 89 | ndn_Milliseconds interestLifetimeMilliseconds; /**< milliseconds. -1.0 for none */ |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame] | 90 | struct ndn_Blob nonce; /**< The blob whose value is a pointer to a pre-allocated buffer. 0 for none */ |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 93 | /** |
Jeff Thompson | b825c63 | 2013-07-10 17:59:29 -0700 | [diff] [blame] | 94 | * Initialize an ndn_Interest struct with the pre-allocated nameComponents and excludeEntries, |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 95 | * 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 | */ |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 102 | static inline void ndn_Interest_initialize |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 103 | (struct ndn_Interest *self, struct ndn_NameComponent *nameComponents, size_t maxNameComponents, |
| 104 | struct ndn_ExcludeEntry *excludeEntries, size_t maxExcludeEntries) |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 105 | { |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 106 | ndn_Name_initialize(&self->name, nameComponents, maxNameComponents); |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 107 | self->minSuffixComponents = -1; |
Jeff Thompson | f2e5e28 | 2013-07-08 15:26:16 -0700 | [diff] [blame] | 108 | self->maxSuffixComponents = -1; |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 109 | ndn_PublisherPublicKeyDigest_initialize(&self->publisherPublicKeyDigest); |
| 110 | ndn_Exclude_initialize(&self->exclude, excludeEntries, maxExcludeEntries); |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 111 | self->childSelector = -1; |
| 112 | self->answerOriginKind = -1; |
| 113 | self->scope = -1; |
| 114 | self->interestLifetimeMilliseconds = -1.0; |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame] | 115 | ndn_Blob_initialize(&self->nonce, 0, 0); |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Jeff Thompson | ac9b2c8 | 2013-08-13 10:51:59 -0700 | [diff] [blame] | 118 | /** |
| 119 | * Check if self's name matches the given name (using ndn_Name_match) and the given name also conforms to the |
| 120 | * interest selectors. |
| 121 | * @param self A pointer to the ndn_Interest struct. |
| 122 | * @param name A pointer to the name to check. |
| 123 | * @return 1 if the name and interest selectors match, 0 otherwise. |
| 124 | */ |
| 125 | int ndn_Interest_matchesName(struct ndn_Interest *self, struct ndn_Name *name); |
| 126 | |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 127 | #ifdef __cplusplus |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 128 | } |
| 129 | #endif |
| 130 | |
| 131 | #endif |
| 132 | |