diff options
Diffstat (limited to 'src/regex/regex_api_search.c')
-rw-r--r-- | src/regex/regex_api_search.c | 167 |
1 files changed, 83 insertions, 84 deletions
diff --git a/src/regex/regex_api_search.c b/src/regex/regex_api_search.c index ebd1a69f3..6a6a49a81 100644 --- a/src/regex/regex_api_search.c +++ b/src/regex/regex_api_search.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file regex/regex_api_search.c | 21 | * @file regex/regex_api_search.c |
22 | * @brief access regex service to discover | 22 | * @brief access regex service to discover |
@@ -30,14 +30,13 @@ | |||
30 | #include "gnunet_regex_service.h" | 30 | #include "gnunet_regex_service.h" |
31 | #include "regex_ipc.h" | 31 | #include "regex_ipc.h" |
32 | 32 | ||
33 | #define LOG(kind,...) GNUNET_log_from (kind, "regex-api",__VA_ARGS__) | 33 | #define LOG(kind, ...) GNUNET_log_from(kind, "regex-api", __VA_ARGS__) |
34 | 34 | ||
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Handle to store data about a regex search. | 37 | * Handle to store data about a regex search. |
38 | */ | 38 | */ |
39 | struct GNUNET_REGEX_Search | 39 | struct GNUNET_REGEX_Search { |
40 | { | ||
41 | /** | 40 | /** |
42 | * Connection to the regex service. | 41 | * Connection to the regex service. |
43 | */ | 42 | */ |
@@ -71,7 +70,7 @@ struct GNUNET_REGEX_Search | |||
71 | * @param s context for the search search for | 70 | * @param s context for the search search for |
72 | */ | 71 | */ |
73 | static void | 72 | static void |
74 | search_reconnect (struct GNUNET_REGEX_Search *s); | 73 | search_reconnect(struct GNUNET_REGEX_Search *s); |
75 | 74 | ||
76 | 75 | ||
77 | /** | 76 | /** |
@@ -83,18 +82,18 @@ search_reconnect (struct GNUNET_REGEX_Search *s); | |||
83 | * @return #GNUNET_SYSERR if @a rm is not well-formed. | 82 | * @return #GNUNET_SYSERR if @a rm is not well-formed. |
84 | */ | 83 | */ |
85 | static int | 84 | static int |
86 | check_search_response (void *cls, | 85 | check_search_response(void *cls, |
87 | const struct ResultMessage *result) | 86 | const struct ResultMessage *result) |
88 | { | 87 | { |
89 | uint16_t size = ntohs (result->header.size) - sizeof (*result); | 88 | uint16_t size = ntohs(result->header.size) - sizeof(*result); |
90 | uint16_t gpl = ntohs (result->get_path_length); | 89 | uint16_t gpl = ntohs(result->get_path_length); |
91 | uint16_t ppl = ntohs (result->put_path_length); | 90 | uint16_t ppl = ntohs(result->put_path_length); |
92 | 91 | ||
93 | if (size != (gpl + ppl) * sizeof (struct GNUNET_PeerIdentity)) | 92 | if (size != (gpl + ppl) * sizeof(struct GNUNET_PeerIdentity)) |
94 | { | 93 | { |
95 | GNUNET_break (0); | 94 | GNUNET_break(0); |
96 | return GNUNET_SYSERR; | 95 | return GNUNET_SYSERR; |
97 | } | 96 | } |
98 | return GNUNET_OK; | 97 | return GNUNET_OK; |
99 | } | 98 | } |
100 | 99 | ||
@@ -107,24 +106,24 @@ check_search_response (void *cls, | |||
107 | * @param result the message | 106 | * @param result the message |
108 | */ | 107 | */ |
109 | static void | 108 | static void |
110 | handle_search_response (void *cls, | 109 | handle_search_response(void *cls, |
111 | const struct ResultMessage *result) | 110 | const struct ResultMessage *result) |
112 | { | 111 | { |
113 | struct GNUNET_REGEX_Search *s = cls; | 112 | struct GNUNET_REGEX_Search *s = cls; |
114 | uint16_t gpl = ntohs (result->get_path_length); | 113 | uint16_t gpl = ntohs(result->get_path_length); |
115 | uint16_t ppl = ntohs (result->put_path_length); | 114 | uint16_t ppl = ntohs(result->put_path_length); |
116 | const struct GNUNET_PeerIdentity *pid; | 115 | const struct GNUNET_PeerIdentity *pid; |
117 | 116 | ||
118 | pid = &result->id; | 117 | pid = &result->id; |
119 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 118 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
120 | "Got regex result %s\n", | 119 | "Got regex result %s\n", |
121 | GNUNET_i2s (pid)); | 120 | GNUNET_i2s(pid)); |
122 | s->callback (s->callback_cls, | 121 | s->callback(s->callback_cls, |
123 | pid, | 122 | pid, |
124 | &pid[1], | 123 | &pid[1], |
125 | gpl, | 124 | gpl, |
126 | &pid[1 + gpl], | 125 | &pid[1 + gpl], |
127 | ppl); | 126 | ppl); |
128 | } | 127 | } |
129 | 128 | ||
130 | 129 | ||
@@ -136,14 +135,14 @@ handle_search_response (void *cls, | |||
136 | * @param error error code | 135 | * @param error error code |
137 | */ | 136 | */ |
138 | static void | 137 | static void |
139 | mq_error_handler (void *cls, | 138 | mq_error_handler(void *cls, |
140 | enum GNUNET_MQ_Error error) | 139 | enum GNUNET_MQ_Error error) |
141 | { | 140 | { |
142 | struct GNUNET_REGEX_Search *s = cls; | 141 | struct GNUNET_REGEX_Search *s = cls; |
143 | 142 | ||
144 | GNUNET_MQ_destroy (s->mq); | 143 | GNUNET_MQ_destroy(s->mq); |
145 | s->mq = NULL; | 144 | s->mq = NULL; |
146 | search_reconnect (s); | 145 | search_reconnect(s); |
147 | } | 146 | } |
148 | 147 | ||
149 | 148 | ||
@@ -153,35 +152,35 @@ mq_error_handler (void *cls, | |||
153 | * @param s context for the search search for | 152 | * @param s context for the search search for |
154 | */ | 153 | */ |
155 | static void | 154 | static void |
156 | search_reconnect (struct GNUNET_REGEX_Search *s) | 155 | search_reconnect(struct GNUNET_REGEX_Search *s) |
157 | { | 156 | { |
158 | struct GNUNET_MQ_MessageHandler handlers[] = { | 157 | struct GNUNET_MQ_MessageHandler handlers[] = { |
159 | GNUNET_MQ_hd_var_size (search_response, | 158 | GNUNET_MQ_hd_var_size(search_response, |
160 | GNUNET_MESSAGE_TYPE_REGEX_RESULT, | 159 | GNUNET_MESSAGE_TYPE_REGEX_RESULT, |
161 | struct ResultMessage, | 160 | struct ResultMessage, |
162 | s), | 161 | s), |
163 | GNUNET_MQ_handler_end () | 162 | GNUNET_MQ_handler_end() |
164 | }; | 163 | }; |
165 | size_t slen = strlen (s->string) + 1; | 164 | size_t slen = strlen(s->string) + 1; |
166 | struct GNUNET_MQ_Envelope *env; | 165 | struct GNUNET_MQ_Envelope *env; |
167 | struct RegexSearchMessage *rsm; | 166 | struct RegexSearchMessage *rsm; |
168 | 167 | ||
169 | GNUNET_assert (NULL == s->mq); | 168 | GNUNET_assert(NULL == s->mq); |
170 | s->mq = GNUNET_CLIENT_connect (s->cfg, | 169 | s->mq = GNUNET_CLIENT_connect(s->cfg, |
171 | "regex", | 170 | "regex", |
172 | handlers, | 171 | handlers, |
173 | &mq_error_handler, | 172 | &mq_error_handler, |
174 | s); | 173 | s); |
175 | if (NULL == s->mq) | 174 | if (NULL == s->mq) |
176 | return; | 175 | return; |
177 | env = GNUNET_MQ_msg_extra (rsm, | 176 | env = GNUNET_MQ_msg_extra(rsm, |
178 | slen, | 177 | slen, |
179 | GNUNET_MESSAGE_TYPE_REGEX_SEARCH); | 178 | GNUNET_MESSAGE_TYPE_REGEX_SEARCH); |
180 | GNUNET_memcpy (&rsm[1], | 179 | GNUNET_memcpy(&rsm[1], |
181 | s->string, | 180 | s->string, |
182 | slen); | 181 | slen); |
183 | GNUNET_MQ_send (s->mq, | 182 | GNUNET_MQ_send(s->mq, |
184 | env); | 183 | env); |
185 | } | 184 | } |
186 | 185 | ||
187 | 186 | ||
@@ -198,37 +197,37 @@ search_reconnect (struct GNUNET_REGEX_Search *s) | |||
198 | * Must be freed by calling #GNUNET_REGEX_search_cancel(). | 197 | * Must be freed by calling #GNUNET_REGEX_search_cancel(). |
199 | */ | 198 | */ |
200 | struct GNUNET_REGEX_Search * | 199 | struct GNUNET_REGEX_Search * |
201 | GNUNET_REGEX_search (const struct GNUNET_CONFIGURATION_Handle *cfg, | 200 | GNUNET_REGEX_search(const struct GNUNET_CONFIGURATION_Handle *cfg, |
202 | const char *string, | 201 | const char *string, |
203 | GNUNET_REGEX_Found callback, | 202 | GNUNET_REGEX_Found callback, |
204 | void *callback_cls) | 203 | void *callback_cls) |
205 | { | 204 | { |
206 | struct GNUNET_REGEX_Search *s; | 205 | struct GNUNET_REGEX_Search *s; |
207 | size_t slen = strlen (string) + 1; | 206 | size_t slen = strlen(string) + 1; |
208 | 207 | ||
209 | if (slen + sizeof (struct RegexSearchMessage) >= GNUNET_MAX_MESSAGE_SIZE) | 208 | if (slen + sizeof(struct RegexSearchMessage) >= GNUNET_MAX_MESSAGE_SIZE) |
210 | { | 209 | { |
211 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 210 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
212 | _("Search string `%s' is too long!\n"), | 211 | _("Search string `%s' is too long!\n"), |
213 | string); | 212 | string); |
214 | GNUNET_break (0); | 213 | GNUNET_break(0); |
215 | return NULL; | 214 | return NULL; |
216 | } | 215 | } |
217 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 216 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
218 | "Starting regex search for %s\n", | 217 | "Starting regex search for %s\n", |
219 | string); | 218 | string); |
220 | s = GNUNET_new (struct GNUNET_REGEX_Search); | 219 | s = GNUNET_new(struct GNUNET_REGEX_Search); |
221 | s->cfg = cfg; | 220 | s->cfg = cfg; |
222 | s->string = GNUNET_strdup (string); | 221 | s->string = GNUNET_strdup(string); |
223 | s->callback = callback; | 222 | s->callback = callback; |
224 | s->callback_cls = callback_cls; | 223 | s->callback_cls = callback_cls; |
225 | search_reconnect (s); | 224 | search_reconnect(s); |
226 | if (NULL == s->mq) | 225 | if (NULL == s->mq) |
227 | { | 226 | { |
228 | GNUNET_free (s->string); | 227 | GNUNET_free(s->string); |
229 | GNUNET_free (s); | 228 | GNUNET_free(s); |
230 | return NULL; | 229 | return NULL; |
231 | } | 230 | } |
232 | return s; | 231 | return s; |
233 | } | 232 | } |
234 | 233 | ||
@@ -239,11 +238,11 @@ GNUNET_REGEX_search (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
239 | * @param s Handle returned by a previous #GNUNET_REGEX_search() call. | 238 | * @param s Handle returned by a previous #GNUNET_REGEX_search() call. |
240 | */ | 239 | */ |
241 | void | 240 | void |
242 | GNUNET_REGEX_search_cancel (struct GNUNET_REGEX_Search *s) | 241 | GNUNET_REGEX_search_cancel(struct GNUNET_REGEX_Search *s) |
243 | { | 242 | { |
244 | GNUNET_MQ_destroy (s->mq); | 243 | GNUNET_MQ_destroy(s->mq); |
245 | GNUNET_free (s->string); | 244 | GNUNET_free(s->string); |
246 | GNUNET_free (s); | 245 | GNUNET_free(s); |
247 | } | 246 | } |
248 | 247 | ||
249 | 248 | ||