diff options
Diffstat (limited to 'src/regex/regex_api_search.c')
-rw-r--r-- | src/regex/regex_api_search.c | 155 |
1 files changed, 78 insertions, 77 deletions
diff --git a/src/regex/regex_api_search.c b/src/regex/regex_api_search.c index 6a6a49a81..960719cbd 100644 --- a/src/regex/regex_api_search.c +++ b/src/regex/regex_api_search.c | |||
@@ -30,13 +30,14 @@ | |||
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 | { | ||
40 | /** | 41 | /** |
41 | * Connection to the regex service. | 42 | * Connection to the regex service. |
42 | */ | 43 | */ |
@@ -70,7 +71,7 @@ struct GNUNET_REGEX_Search { | |||
70 | * @param s context for the search search for | 71 | * @param s context for the search search for |
71 | */ | 72 | */ |
72 | static void | 73 | static void |
73 | search_reconnect(struct GNUNET_REGEX_Search *s); | 74 | search_reconnect (struct GNUNET_REGEX_Search *s); |
74 | 75 | ||
75 | 76 | ||
76 | /** | 77 | /** |
@@ -82,18 +83,18 @@ search_reconnect(struct GNUNET_REGEX_Search *s); | |||
82 | * @return #GNUNET_SYSERR if @a rm is not well-formed. | 83 | * @return #GNUNET_SYSERR if @a rm is not well-formed. |
83 | */ | 84 | */ |
84 | static int | 85 | static int |
85 | check_search_response(void *cls, | 86 | check_search_response (void *cls, |
86 | const struct ResultMessage *result) | 87 | const struct ResultMessage *result) |
87 | { | 88 | { |
88 | uint16_t size = ntohs(result->header.size) - sizeof(*result); | 89 | uint16_t size = ntohs (result->header.size) - sizeof(*result); |
89 | uint16_t gpl = ntohs(result->get_path_length); | 90 | uint16_t gpl = ntohs (result->get_path_length); |
90 | uint16_t ppl = ntohs(result->put_path_length); | 91 | uint16_t ppl = ntohs (result->put_path_length); |
91 | 92 | ||
92 | if (size != (gpl + ppl) * sizeof(struct GNUNET_PeerIdentity)) | 93 | if (size != (gpl + ppl) * sizeof(struct GNUNET_PeerIdentity)) |
93 | { | 94 | { |
94 | GNUNET_break(0); | 95 | GNUNET_break (0); |
95 | return GNUNET_SYSERR; | 96 | return GNUNET_SYSERR; |
96 | } | 97 | } |
97 | return GNUNET_OK; | 98 | return GNUNET_OK; |
98 | } | 99 | } |
99 | 100 | ||
@@ -106,24 +107,24 @@ check_search_response(void *cls, | |||
106 | * @param result the message | 107 | * @param result the message |
107 | */ | 108 | */ |
108 | static void | 109 | static void |
109 | handle_search_response(void *cls, | 110 | handle_search_response (void *cls, |
110 | const struct ResultMessage *result) | 111 | const struct ResultMessage *result) |
111 | { | 112 | { |
112 | struct GNUNET_REGEX_Search *s = cls; | 113 | struct GNUNET_REGEX_Search *s = cls; |
113 | uint16_t gpl = ntohs(result->get_path_length); | 114 | uint16_t gpl = ntohs (result->get_path_length); |
114 | uint16_t ppl = ntohs(result->put_path_length); | 115 | uint16_t ppl = ntohs (result->put_path_length); |
115 | const struct GNUNET_PeerIdentity *pid; | 116 | const struct GNUNET_PeerIdentity *pid; |
116 | 117 | ||
117 | pid = &result->id; | 118 | pid = &result->id; |
118 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 119 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
119 | "Got regex result %s\n", | 120 | "Got regex result %s\n", |
120 | GNUNET_i2s(pid)); | 121 | GNUNET_i2s (pid)); |
121 | s->callback(s->callback_cls, | 122 | s->callback (s->callback_cls, |
122 | pid, | 123 | pid, |
123 | &pid[1], | 124 | &pid[1], |
124 | gpl, | 125 | gpl, |
125 | &pid[1 + gpl], | 126 | &pid[1 + gpl], |
126 | ppl); | 127 | ppl); |
127 | } | 128 | } |
128 | 129 | ||
129 | 130 | ||
@@ -135,14 +136,14 @@ handle_search_response(void *cls, | |||
135 | * @param error error code | 136 | * @param error error code |
136 | */ | 137 | */ |
137 | static void | 138 | static void |
138 | mq_error_handler(void *cls, | 139 | mq_error_handler (void *cls, |
139 | enum GNUNET_MQ_Error error) | 140 | enum GNUNET_MQ_Error error) |
140 | { | 141 | { |
141 | struct GNUNET_REGEX_Search *s = cls; | 142 | struct GNUNET_REGEX_Search *s = cls; |
142 | 143 | ||
143 | GNUNET_MQ_destroy(s->mq); | 144 | GNUNET_MQ_destroy (s->mq); |
144 | s->mq = NULL; | 145 | s->mq = NULL; |
145 | search_reconnect(s); | 146 | search_reconnect (s); |
146 | } | 147 | } |
147 | 148 | ||
148 | 149 | ||
@@ -152,35 +153,35 @@ mq_error_handler(void *cls, | |||
152 | * @param s context for the search search for | 153 | * @param s context for the search search for |
153 | */ | 154 | */ |
154 | static void | 155 | static void |
155 | search_reconnect(struct GNUNET_REGEX_Search *s) | 156 | search_reconnect (struct GNUNET_REGEX_Search *s) |
156 | { | 157 | { |
157 | struct GNUNET_MQ_MessageHandler handlers[] = { | 158 | struct GNUNET_MQ_MessageHandler handlers[] = { |
158 | GNUNET_MQ_hd_var_size(search_response, | 159 | GNUNET_MQ_hd_var_size (search_response, |
159 | GNUNET_MESSAGE_TYPE_REGEX_RESULT, | 160 | GNUNET_MESSAGE_TYPE_REGEX_RESULT, |
160 | struct ResultMessage, | 161 | struct ResultMessage, |
161 | s), | 162 | s), |
162 | GNUNET_MQ_handler_end() | 163 | GNUNET_MQ_handler_end () |
163 | }; | 164 | }; |
164 | size_t slen = strlen(s->string) + 1; | 165 | size_t slen = strlen (s->string) + 1; |
165 | struct GNUNET_MQ_Envelope *env; | 166 | struct GNUNET_MQ_Envelope *env; |
166 | struct RegexSearchMessage *rsm; | 167 | struct RegexSearchMessage *rsm; |
167 | 168 | ||
168 | GNUNET_assert(NULL == s->mq); | 169 | GNUNET_assert (NULL == s->mq); |
169 | s->mq = GNUNET_CLIENT_connect(s->cfg, | 170 | s->mq = GNUNET_CLIENT_connect (s->cfg, |
170 | "regex", | 171 | "regex", |
171 | handlers, | 172 | handlers, |
172 | &mq_error_handler, | 173 | &mq_error_handler, |
173 | s); | 174 | s); |
174 | if (NULL == s->mq) | 175 | if (NULL == s->mq) |
175 | return; | 176 | return; |
176 | env = GNUNET_MQ_msg_extra(rsm, | 177 | env = GNUNET_MQ_msg_extra (rsm, |
177 | slen, | 178 | slen, |
178 | GNUNET_MESSAGE_TYPE_REGEX_SEARCH); | 179 | GNUNET_MESSAGE_TYPE_REGEX_SEARCH); |
179 | GNUNET_memcpy(&rsm[1], | 180 | GNUNET_memcpy (&rsm[1], |
180 | s->string, | 181 | s->string, |
181 | slen); | 182 | slen); |
182 | GNUNET_MQ_send(s->mq, | 183 | GNUNET_MQ_send (s->mq, |
183 | env); | 184 | env); |
184 | } | 185 | } |
185 | 186 | ||
186 | 187 | ||
@@ -197,37 +198,37 @@ search_reconnect(struct GNUNET_REGEX_Search *s) | |||
197 | * Must be freed by calling #GNUNET_REGEX_search_cancel(). | 198 | * Must be freed by calling #GNUNET_REGEX_search_cancel(). |
198 | */ | 199 | */ |
199 | struct GNUNET_REGEX_Search * | 200 | struct GNUNET_REGEX_Search * |
200 | GNUNET_REGEX_search(const struct GNUNET_CONFIGURATION_Handle *cfg, | 201 | GNUNET_REGEX_search (const struct GNUNET_CONFIGURATION_Handle *cfg, |
201 | const char *string, | 202 | const char *string, |
202 | GNUNET_REGEX_Found callback, | 203 | GNUNET_REGEX_Found callback, |
203 | void *callback_cls) | 204 | void *callback_cls) |
204 | { | 205 | { |
205 | struct GNUNET_REGEX_Search *s; | 206 | struct GNUNET_REGEX_Search *s; |
206 | size_t slen = strlen(string) + 1; | 207 | size_t slen = strlen (string) + 1; |
207 | 208 | ||
208 | if (slen + sizeof(struct RegexSearchMessage) >= GNUNET_MAX_MESSAGE_SIZE) | 209 | if (slen + sizeof(struct RegexSearchMessage) >= GNUNET_MAX_MESSAGE_SIZE) |
209 | { | 210 | { |
210 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 211 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
211 | _("Search string `%s' is too long!\n"), | 212 | _ ("Search string `%s' is too long!\n"), |
212 | string); | 213 | string); |
213 | GNUNET_break(0); | 214 | GNUNET_break (0); |
214 | return NULL; | 215 | return NULL; |
215 | } | 216 | } |
216 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 217 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
217 | "Starting regex search for %s\n", | 218 | "Starting regex search for %s\n", |
218 | string); | 219 | string); |
219 | s = GNUNET_new(struct GNUNET_REGEX_Search); | 220 | s = GNUNET_new (struct GNUNET_REGEX_Search); |
220 | s->cfg = cfg; | 221 | s->cfg = cfg; |
221 | s->string = GNUNET_strdup(string); | 222 | s->string = GNUNET_strdup (string); |
222 | s->callback = callback; | 223 | s->callback = callback; |
223 | s->callback_cls = callback_cls; | 224 | s->callback_cls = callback_cls; |
224 | search_reconnect(s); | 225 | search_reconnect (s); |
225 | if (NULL == s->mq) | 226 | if (NULL == s->mq) |
226 | { | 227 | { |
227 | GNUNET_free(s->string); | 228 | GNUNET_free (s->string); |
228 | GNUNET_free(s); | 229 | GNUNET_free (s); |
229 | return NULL; | 230 | return NULL; |
230 | } | 231 | } |
231 | return s; | 232 | return s; |
232 | } | 233 | } |
233 | 234 | ||
@@ -238,11 +239,11 @@ GNUNET_REGEX_search(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
238 | * @param s Handle returned by a previous #GNUNET_REGEX_search() call. | 239 | * @param s Handle returned by a previous #GNUNET_REGEX_search() call. |
239 | */ | 240 | */ |
240 | void | 241 | void |
241 | GNUNET_REGEX_search_cancel(struct GNUNET_REGEX_Search *s) | 242 | GNUNET_REGEX_search_cancel (struct GNUNET_REGEX_Search *s) |
242 | { | 243 | { |
243 | GNUNET_MQ_destroy(s->mq); | 244 | GNUNET_MQ_destroy (s->mq); |
244 | GNUNET_free(s->string); | 245 | GNUNET_free (s->string); |
245 | GNUNET_free(s); | 246 | GNUNET_free (s); |
246 | } | 247 | } |
247 | 248 | ||
248 | 249 | ||