aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/messenger_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger/messenger_api.c')
-rw-r--r--src/messenger/messenger_api.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/messenger/messenger_api.c b/src/messenger/messenger_api.c
index b42bb40cc..0536a3154 100644
--- a/src/messenger/messenger_api.c
+++ b/src/messenger/messenger_api.c
@@ -574,6 +574,50 @@ GNUNET_MESSENGER_close_room (struct GNUNET_MESSENGER_Room *room)
574 send_close_room (room->handle, room); 574 send_close_room (room->handle, room);
575} 575}
576 576
577struct GNUNET_MESSENGER_RoomFind
578{
579 struct GNUNET_MESSENGER_Contact *contact;
580 GNUNET_MESSENGER_MemberCallback callback;
581 size_t counter;
582 void *cls;
583};
584
585static int
586iterate_find_room (void* cls, const struct GNUNET_HashCode *key, void *value)
587{
588 struct GNUNET_MESSENGER_RoomFind *find = cls;
589 struct GNUNET_MESSENGER_Room *room = value;
590
591 if ((find->counter > 0) && ((!find->contact) || (GNUNET_YES == find_room_member(room, find->contact))))
592 {
593 find->counter--;
594
595 if (!find->callback)
596 return GNUNET_YES;
597
598 return find->callback(find->cls, room, find->contact);
599 }
600 else
601 return GNUNET_NO;
602}
603
604int
605GNUNET_MESSENGER_find_rooms (const struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_MESSENGER_Contact *contact,
606 GNUNET_MESSENGER_MemberCallback callback, void *cls)
607{
608 if (!handle)
609 return GNUNET_SYSERR;
610
611 struct GNUNET_MESSENGER_RoomFind find;
612
613 find.contact = contact;
614 find.callback = callback;
615 find.counter = (contact? contact->rc : SIZE_MAX);
616 find.cls = cls;
617
618 return GNUNET_CONTAINER_multihashmap_iterate(handle->rooms, iterate_find_room, &find);
619}
620
577struct GNUNET_MESSENGER_Contact* 621struct GNUNET_MESSENGER_Contact*
578GNUNET_MESSENGER_get_sender (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash) 622GNUNET_MESSENGER_get_sender (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash)
579{ 623{
@@ -693,7 +737,7 @@ GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room, const st
693 737
694int 738int
695GNUNET_MESSENGER_iterate_members (struct GNUNET_MESSENGER_Room *room, GNUNET_MESSENGER_MemberCallback callback, 739GNUNET_MESSENGER_iterate_members (struct GNUNET_MESSENGER_Room *room, GNUNET_MESSENGER_MemberCallback callback,
696 void* cls) 740 void *cls)
697{ 741{
698 if (!room) 742 if (!room)
699 return GNUNET_SYSERR; 743 return GNUNET_SYSERR;