diff options
Diffstat (limited to 'src/include/gnunet_mq_lib.h')
-rw-r--r-- | src/include/gnunet_mq_lib.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h index 3f67dc365..2a459636a 100644 --- a/src/include/gnunet_mq_lib.h +++ b/src/include/gnunet_mq_lib.h | |||
@@ -528,6 +528,51 @@ struct GNUNET_MQ_MessageHandler | |||
528 | 528 | ||
529 | 529 | ||
530 | /** | 530 | /** |
531 | * Insert code for a "check_" function that verifies that | ||
532 | * a given variable-length message received over the network | ||
533 | * is followed by another variable-length message that fits | ||
534 | * exactly with the given size. If the message @a m | ||
535 | * is not followed by another `struct GNUNET_MessageHeader` | ||
536 | * with a size that adds up to the total size, an error is logged | ||
537 | * and the function is returned with #GNUNET_NO. | ||
538 | * | ||
539 | * @param an IPC message with proper type to determine | ||
540 | * the size, starting with a `struct GNUNET_MessageHeader` | ||
541 | */ | ||
542 | #define GNUNET_MQ_check_boxed_message(m) \ | ||
543 | { \ | ||
544 | const struct GNUNET_MessageHeader *inbox = \ | ||
545 | (const struct GNUNET_MessageHeader *) &m[1]; \ | ||
546 | const struct GNUNET_MessageHeader *hdr = \ | ||
547 | (const struct GNUNET_MessageHeader *) m; \ | ||
548 | uint16_t slen = ntohs (hdr->size) - sizeof (*m); \ | ||
549 | if ( (slen < sizeof (struct GNUNET_MessageHeader))||\ | ||
550 | (slen != ntohs (inbox->size)) ) \ | ||
551 | { \ | ||
552 | GNUNET_break (0); \ | ||
553 | return GNUNET_NO; \ | ||
554 | } \ | ||
555 | } | ||
556 | |||
557 | |||
558 | /** | ||
559 | * Call the message message handler that was registered | ||
560 | * for the type of the given message in the given @a handlers list. | ||
561 | * | ||
562 | * This function is indended to be used for the implementation | ||
563 | * of message queues. | ||
564 | * | ||
565 | * @param handlers a set of handlers | ||
566 | * @param mh message to dispatch | ||
567 | * @return #GNUNET_OK on success, #GNUNET_NO if no handler matched, | ||
568 | * #GNUNET_SYSERR if message was rejected by check function | ||
569 | */ | ||
570 | int | ||
571 | GNUNET_MQ_handle_message (const struct GNUNET_MQ_MessageHandler *handlers, | ||
572 | const struct GNUNET_MessageHeader *mh); | ||
573 | |||
574 | |||
575 | /** | ||
531 | * Create a new envelope. | 576 | * Create a new envelope. |
532 | * | 577 | * |
533 | * @param mhp message header to store the allocated message header in, can be NULL | 578 | * @param mhp message header to store the allocated message header in, can be NULL |