libgnunetchat

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

commit ffbadef904ae1e32eb54671647527b99e70d2266
parent 90545e798c5d046cec0742bbc26f794da0c248ca
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Sun, 13 Feb 2022 03:44:34 +0100

Adding a list of egos to add accounts

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

Diffstat:
Msrc/gnunet_chat_handle.c | 31++++++++++++++++++++++++++++++-
Msrc/gnunet_chat_handle.h | 13+++++++++++++
Msrc/gnunet_chat_handle_intern.c | 30+++++++++++++++++++++++++++++-
3 files changed, 72 insertions(+), 2 deletions(-)

diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c @@ -54,6 +54,9 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, handle->msg_cb = msg_cb; handle->msg_cls = msg_cls; + handle->identities_head = NULL; + handle->identities_tail = NULL; + handle->files = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); handle->contexts = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); handle->contacts = GNUNET_CONTAINER_multishortmap_create(8, GNUNET_NO); @@ -84,6 +87,12 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, GNUNET_free(fs_client_name); + handle->identity = GNUNET_IDENTITY_connect( + handle->cfg, + on_handle_gnunet_identity, + handle + ); + handle->messenger = GNUNET_MESSENGER_connect( handle->cfg, name, on_handle_identity, handle, @@ -147,7 +156,10 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle) if (handle->messenger) GNUNET_MESSENGER_disconnect(handle->messenger); - if (handle->files) + if (handle->identity) + GNUNET_IDENTITY_disconnect(handle->identity); + + if (handle->fs) GNUNET_FS_stop(handle->fs); if (handle->arm) @@ -162,6 +174,23 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle) GNUNET_CONTAINER_multihashmap_destroy(handle->contexts); GNUNET_CONTAINER_multihashmap_destroy(handle->files); + struct GNUNET_CHAT_InternalIdentities *identities; + while (handle->identities_head) + { + identities = handle->identities_head; + + if (identities->name) + GNUNET_free(identities->name); + + GNUNET_CONTAINER_DLL_remove( + handle->identities_head, + handle->identities_tail, + identities + ); + + GNUNET_free(identities); + } + if (handle->directory) GNUNET_free(handle->directory); diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h @@ -31,6 +31,7 @@ #include <gnunet/gnunet_container_lib.h> #include <gnunet/gnunet_arm_service.h> #include <gnunet/gnunet_fs_service.h> +#include <gnunet/gnunet_identity_service.h> #include <gnunet/gnunet_messenger_service.h> #include <gnunet/gnunet_scheduler_lib.h> #include <gnunet/gnunet_util_lib.h> @@ -45,6 +46,14 @@ struct GNUNET_CHAT_InternalMessages struct GNUNET_CHAT_InternalMessages *prev; }; +struct GNUNET_CHAT_InternalIdentities +{ + char *name; + struct GNUNET_IDENTITY_Ego *ego; + struct GNUNET_CHAT_InternalIdentities *next; + struct GNUNET_CHAT_InternalIdentities *prev; +}; + struct GNUNET_CHAT_Handle { const struct GNUNET_CONFIGURATION_Handle* cfg; @@ -58,6 +67,9 @@ struct GNUNET_CHAT_Handle GNUNET_CHAT_ContextMessageCallback msg_cb; void *msg_cls; + struct GNUNET_CHAT_InternalIdentities *identities_head; + struct GNUNET_CHAT_InternalIdentities *identities_tail; + struct GNUNET_CONTAINER_MultiHashMap *files; struct GNUNET_CONTAINER_MultiHashMap *contexts; struct GNUNET_CONTAINER_MultiShortmap *contacts; @@ -65,6 +77,7 @@ struct GNUNET_CHAT_Handle struct GNUNET_ARM_Handle *arm; struct GNUNET_FS_Handle *fs; + struct GNUNET_IDENTITY_Handle *identity; struct GNUNET_MESSENGER_Handle *messenger; char *public_key; diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c @@ -74,7 +74,8 @@ on_handle_arm_connection(void *cls, } void* -notify_handle_fs_progress(void* cls, const struct GNUNET_FS_ProgressInfo* info) +notify_handle_fs_progress(void* cls, + const struct GNUNET_FS_ProgressInfo* info) { struct GNUNET_CHAT_Handle *chat = cls; @@ -197,6 +198,31 @@ notify_handle_fs_progress(void* cls, const struct GNUNET_FS_ProgressInfo* info) return NULL; } +void +on_handle_gnunet_identity(void *cls, + struct GNUNET_IDENTITY_Ego *ego, + GNUNET_UNUSED void **ctx, + const char *name) +{ + struct GNUNET_CHAT_Handle* handle = cls; + + if (!name) + return; + + struct GNUNET_CHAT_InternalIdentities *identities = GNUNET_new( + struct GNUNET_CHAT_InternalIdentities + ); + + identities->name = GNUNET_strdup(name); + identities->ego = ego; + + GNUNET_CONTAINER_DLL_insert_tail( + handle->identities_head, + handle->identities_tail, + identities + ); +} + int intern_provide_contact_for_member(struct GNUNET_CHAT_Handle *handle, const struct GNUNET_MESSENGER_Contact *member, @@ -341,6 +367,8 @@ on_handle_message (void *cls, (GNUNET_OK != intern_provide_contact_for_member(handle, sender, NULL))) return; + GNUNET_MESSENGER_get_message(room, &(msg->header.previous)); + struct GNUNET_CHAT_Context *context = GNUNET_CONTAINER_multihashmap_get( handle->contexts, GNUNET_MESSENGER_room_get_key(room) );