libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

commit ecccdbe89ad906f5d995e45ec1ff40117d642b18
parent 62d9bd1120633b094b813b66c49f94db8f2f8abb
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Thu, 29 Jul 2021 22:24:45 +0200

Added creating chat contacts for each known messenger contact

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>

Diffstat:
Minclude/gnunet_chat_lib.h | 27++++++++++++++++++++++++++-
Msrc/gnunet_chat_contact.c | 2--
Msrc/gnunet_chat_handle_intern.c | 70+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Msrc/gnunet_chat_lib.c | 19+++++++++++++++++++
Msrc/gnunet_chat_lib_intern.c | 22++++++++++++++++++++++
5 files changed, 132 insertions(+), 8 deletions(-)

diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h @@ -173,7 +173,19 @@ typedef int */ typedef int (*GNUNET_CHAT_ContextMessageCallback) (void *cls, struct GNUNET_CHAT_Context *context, - struct GNUNET_CHAT_Message *message); + const struct GNUNET_CHAT_Message *message); + +/** + * TODO + * + * @param cls + * @param context + * @param file + * @return + */ +typedef int +(*GNUNET_CHAT_ContextFileCallback) (void *cls, struct GNUNET_CHAT_Context *context, + struct GNUNET_CHAT_File *file); /** * TODO @@ -537,6 +549,19 @@ GNUNET_CHAT_context_iterate_messages (struct GNUNET_CHAT_Context *context, /** * TODO * + * @param context + * @param callback + * @param cls + * @return + */ +int +GNUNET_CHAT_context_iterate_files (struct GNUNET_CHAT_Context *context, + GNUNET_CHAT_ContextFileCallback callback, + void *cls); + +/** + * TODO + * * @param message * @return */ diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c @@ -33,8 +33,6 @@ contact_create_from_member (struct GNUNET_CHAT_Handle *handle, contact->handle = handle; contact->context = NULL; - // TODO: search for private context? create private context? - contact->member = member; contact->user_pointer = NULL; diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c @@ -190,21 +190,24 @@ struct GNUNET_CHAT_CheckHandleRoomMembers int check_handle_room_members (void* cls, GNUNET_UNUSED struct GNUNET_MESSENGER_Room *room, - const struct GNUNET_MESSENGER_Contact *contact) + const struct GNUNET_MESSENGER_Contact *member) { struct GNUNET_CHAT_CheckHandleRoomMembers *check = cls; - const struct GNUNET_IDENTITY_PublicKey *contact_key = ( - GNUNET_MESSENGER_contact_get_key(contact) + const struct GNUNET_IDENTITY_PublicKey *member_key = ( + GNUNET_MESSENGER_contact_get_key(member) ); - if (0 == GNUNET_memcmp(contact_key, check->ignore_key)) + if (0 == GNUNET_memcmp(member_key, check->ignore_key)) return GNUNET_YES; if (check->contact) + { + check->contact = NULL; return GNUNET_NO; + } - check->contact = contact; + check->contact = member; return GNUNET_YES; } @@ -246,6 +249,8 @@ request_handle_context_by_room (struct GNUNET_CHAT_Handle *handle, handle, check.contact ); + contact->context = context; + struct GNUNET_ShortHashCode shorthash; util_shorthash_from_member(check.contact, &shorthash); @@ -295,15 +300,70 @@ find_handle_rooms (void *cls, struct GNUNET_MESSENGER_Room *room, return GNUNET_YES; } +int +scan_handle_room_members (void* cls, + GNUNET_UNUSED struct GNUNET_MESSENGER_Room *room, + const struct GNUNET_MESSENGER_Contact *member) +{ + struct GNUNET_CHAT_Handle *handle = cls; + + struct GNUNET_ShortHashCode shorthash; + util_shorthash_from_member(member, &shorthash); + + if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains( + handle->contacts, &shorthash)) + return GNUNET_YES; + + struct GNUNET_CHAT_Contact *contact = contact_create_from_member( + handle, member + ); + + if (GNUNET_OK == GNUNET_CONTAINER_multishortmap_put( + handle->contacts, &shorthash, contact, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) + return GNUNET_YES; + + contact_destroy(contact); + return GNUNET_NO; +} + +int +scan_handle_rooms (void *cls, struct GNUNET_MESSENGER_Room *room, + GNUNET_UNUSED const struct GNUNET_MESSENGER_Contact *member) +{ + struct GNUNET_CHAT_Handle *handle = cls; + + const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key(room); + + struct GNUNET_CHAT_Group *group = GNUNET_CONTAINER_multihashmap_get( + handle->groups, key + ); + + if (!group) + return GNUNET_YES; + + GNUNET_MESSENGER_iterate_members(room, scan_handle_room_members, handle); + return GNUNET_YES; +} + void on_handle_identity(void *cls, GNUNET_UNUSED struct GNUNET_MESSENGER_Handle *messenger) { struct GNUNET_CHAT_Handle *handle = cls; + if ((0 < GNUNET_CONTAINER_multihashmap_size(handle->contexts)) || + (0 < GNUNET_CONTAINER_multihashmap_size(handle->groups)) || + (0 < GNUNET_CONTAINER_multishortmap_size(handle->contacts))) + return; + GNUNET_MESSENGER_find_rooms( handle->messenger, NULL, find_handle_rooms, handle ); + + GNUNET_MESSENGER_find_rooms( + handle->messenger, NULL, scan_handle_rooms, handle + ); } void diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c @@ -591,6 +591,25 @@ GNUNET_CHAT_context_iterate_messages (struct GNUNET_CHAT_Context *context, } +int +GNUNET_CHAT_context_iterate_files (struct GNUNET_CHAT_Context *context, + GNUNET_CHAT_ContextFileCallback callback, + void *cls) +{ + if (!context) + return GNUNET_SYSERR; + + struct GNUNET_CHAT_ContextIterateFiles it; + it.context = context; + it.cb = callback; + it.cls = cls; + + return GNUNET_CONTAINER_multihashmap_iterate( + context->files, it_context_iterate_files, &it + ); +} + + enum GNUNET_CHAT_MessageKind GNUNET_CHAT_message_get_kind (const struct GNUNET_CHAT_Message *message) { diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c @@ -117,6 +117,28 @@ it_context_iterate_messages (void *cls, return it->cb(it->cls, it->context, message); } +struct GNUNET_CHAT_ContextIterateFiles +{ + struct GNUNET_CHAT_Context *context; + GNUNET_CHAT_ContextFileCallback cb; + void *cls; +}; + +int +it_context_iterate_files (void *cls, + GNUNET_UNUSED const struct GNUNET_HashCode *key, + void *value) +{ + struct GNUNET_CHAT_ContextIterateFiles *it = cls; + + if (!(it->cb)) + return GNUNET_YES; + + struct GNUNET_CHAT_File *file = value; + + return it->cb(it->cls, it->context, file); +} + struct GNUNET_CHAT_MessageIterateReadReceipts { const struct GNUNET_CHAT_Message *message;