diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-01-25 18:34:41 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-01-25 18:34:57 +0100 |
commit | 8e157def22a61958cd4b6c791da505a38062cc1d (patch) | |
tree | c7a53e64681bca90ad4cb69f5fe5e6f9fa0bd8e8 /src/util/mq.c | |
parent | 7536db9fc52657812e14c6890f2a95db8ca685b2 (diff) | |
download | gnunet-8e157def22a61958cd4b6c791da505a38062cc1d.tar.gz gnunet-8e157def22a61958cd4b6c791da505a38062cc1d.zip |
add prototypes for handlers for incoming messages
Diffstat (limited to 'src/util/mq.c')
-rw-r--r-- | src/util/mq.c | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/src/util/mq.c b/src/util/mq.c index 4dfcb72be..d2f5add19 100644 --- a/src/util/mq.c +++ b/src/util/mq.c | |||
@@ -215,6 +215,35 @@ void | |||
215 | GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq, | 215 | GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq, |
216 | const struct GNUNET_MessageHeader *mh) | 216 | const struct GNUNET_MessageHeader *mh) |
217 | { | 217 | { |
218 | int ret; | ||
219 | |||
220 | ret = GNUNET_MQ_handle_message (mq->handlers, | ||
221 | mh); | ||
222 | if (GNUNET_SYSERR == ret) | ||
223 | { | ||
224 | GNUNET_MQ_inject_error (mq, | ||
225 | GNUNET_MQ_ERROR_MALFORMED); | ||
226 | return; | ||
227 | } | ||
228 | } | ||
229 | |||
230 | |||
231 | /** | ||
232 | * Call the message message handler that was registered | ||
233 | * for the type of the given message in the given @a handlers list. | ||
234 | * | ||
235 | * This function is indended to be used for the implementation | ||
236 | * of message queues. | ||
237 | * | ||
238 | * @param handlers a set of handlers | ||
239 | * @param mh message to dispatch | ||
240 | * @return #GNUNET_OK on success, #GNUNET_NO if no handler matched, | ||
241 | * #GNUNET_SYSERR if message was rejected by check function | ||
242 | */ | ||
243 | int | ||
244 | GNUNET_MQ_handle_message (const struct GNUNET_MQ_MessageHandler *handlers, | ||
245 | const struct GNUNET_MessageHeader *mh) | ||
246 | { | ||
218 | const struct GNUNET_MQ_MessageHandler *handler; | 247 | const struct GNUNET_MQ_MessageHandler *handler; |
219 | int handled = GNUNET_NO; | 248 | int handled = GNUNET_NO; |
220 | uint16_t msize = ntohs (mh->size); | 249 | uint16_t msize = ntohs (mh->size); |
@@ -224,9 +253,9 @@ GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq, | |||
224 | "Received message of type %u and size %u\n", | 253 | "Received message of type %u and size %u\n", |
225 | mtype, msize); | 254 | mtype, msize); |
226 | 255 | ||
227 | if (NULL == mq->handlers) | 256 | if (NULL == handlers) |
228 | goto done; | 257 | goto done; |
229 | for (handler = mq->handlers; NULL != handler->cb; handler++) | 258 | for (handler = handlers; NULL != handler->cb; handler++) |
230 | { | 259 | { |
231 | if (handler->type == mtype) | 260 | if (handler->type == mtype) |
232 | { | 261 | { |
@@ -240,9 +269,7 @@ GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq, | |||
240 | LOG (GNUNET_ERROR_TYPE_ERROR, | 269 | LOG (GNUNET_ERROR_TYPE_ERROR, |
241 | "Received malformed message of type %u\n", | 270 | "Received malformed message of type %u\n", |
242 | (unsigned int) handler->type); | 271 | (unsigned int) handler->type); |
243 | GNUNET_MQ_inject_error (mq, | 272 | return GNUNET_SYSERR; |
244 | GNUNET_MQ_ERROR_MALFORMED); | ||
245 | break; | ||
246 | } | 273 | } |
247 | if ( (NULL == handler->mv) || | 274 | if ( (NULL == handler->mv) || |
248 | (GNUNET_OK == | 275 | (GNUNET_OK == |
@@ -257,17 +284,20 @@ GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq, | |||
257 | LOG (GNUNET_ERROR_TYPE_ERROR, | 284 | LOG (GNUNET_ERROR_TYPE_ERROR, |
258 | "Received malformed message of type %u\n", | 285 | "Received malformed message of type %u\n", |
259 | (unsigned int) handler->type); | 286 | (unsigned int) handler->type); |
260 | GNUNET_MQ_inject_error (mq, | 287 | return GNUNET_SYSERR; |
261 | GNUNET_MQ_ERROR_MALFORMED); | ||
262 | } | 288 | } |
263 | break; | 289 | break; |
264 | } | 290 | } |
265 | } | 291 | } |
266 | done: | 292 | done: |
267 | if (GNUNET_NO == handled) | 293 | if (GNUNET_NO == handled) |
294 | { | ||
268 | LOG (GNUNET_ERROR_TYPE_INFO, | 295 | LOG (GNUNET_ERROR_TYPE_INFO, |
269 | "No handler for message of type %u and size %u\n", | 296 | "No handler for message of type %u and size %u\n", |
270 | mtype, msize); | 297 | mtype, msize); |
298 | return GNUNET_NO; | ||
299 | } | ||
300 | return GNUNET_OK; | ||
271 | } | 301 | } |
272 | 302 | ||
273 | 303 | ||