aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-02-13 03:44:34 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-02-13 03:44:34 +0100
commitffbadef904ae1e32eb54671647527b99e70d2266 (patch)
treef37392ecbe00aaab329f62c211c965c75c7b58d0
parent90545e798c5d046cec0742bbc26f794da0c248ca (diff)
downloadlibgnunetchat-ffbadef904ae1e32eb54671647527b99e70d2266.tar.gz
libgnunetchat-ffbadef904ae1e32eb54671647527b99e70d2266.zip
Adding a list of egos to add accounts
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/gnunet_chat_handle.c31
-rw-r--r--src/gnunet_chat_handle.h13
-rw-r--r--src/gnunet_chat_handle_intern.c30
3 files changed, 72 insertions, 2 deletions
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
index a4be709..f4e86b2 100644
--- 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,
54 handle->msg_cb = msg_cb; 54 handle->msg_cb = msg_cb;
55 handle->msg_cls = msg_cls; 55 handle->msg_cls = msg_cls;
56 56
57 handle->identities_head = NULL;
58 handle->identities_tail = NULL;
59
57 handle->files = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); 60 handle->files = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO);
58 handle->contexts = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); 61 handle->contexts = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO);
59 handle->contacts = GNUNET_CONTAINER_multishortmap_create(8, GNUNET_NO); 62 handle->contacts = GNUNET_CONTAINER_multishortmap_create(8, GNUNET_NO);
@@ -84,6 +87,12 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg,
84 87
85 GNUNET_free(fs_client_name); 88 GNUNET_free(fs_client_name);
86 89
90 handle->identity = GNUNET_IDENTITY_connect(
91 handle->cfg,
92 on_handle_gnunet_identity,
93 handle
94 );
95
87 handle->messenger = GNUNET_MESSENGER_connect( 96 handle->messenger = GNUNET_MESSENGER_connect(
88 handle->cfg, name, 97 handle->cfg, name,
89 on_handle_identity, handle, 98 on_handle_identity, handle,
@@ -147,7 +156,10 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle)
147 if (handle->messenger) 156 if (handle->messenger)
148 GNUNET_MESSENGER_disconnect(handle->messenger); 157 GNUNET_MESSENGER_disconnect(handle->messenger);
149 158
150 if (handle->files) 159 if (handle->identity)
160 GNUNET_IDENTITY_disconnect(handle->identity);
161
162 if (handle->fs)
151 GNUNET_FS_stop(handle->fs); 163 GNUNET_FS_stop(handle->fs);
152 164
153 if (handle->arm) 165 if (handle->arm)
@@ -162,6 +174,23 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle)
162 GNUNET_CONTAINER_multihashmap_destroy(handle->contexts); 174 GNUNET_CONTAINER_multihashmap_destroy(handle->contexts);
163 GNUNET_CONTAINER_multihashmap_destroy(handle->files); 175 GNUNET_CONTAINER_multihashmap_destroy(handle->files);
164 176
177 struct GNUNET_CHAT_InternalIdentities *identities;
178 while (handle->identities_head)
179 {
180 identities = handle->identities_head;
181
182 if (identities->name)
183 GNUNET_free(identities->name);
184
185 GNUNET_CONTAINER_DLL_remove(
186 handle->identities_head,
187 handle->identities_tail,
188 identities
189 );
190
191 GNUNET_free(identities);
192 }
193
165 if (handle->directory) 194 if (handle->directory)
166 GNUNET_free(handle->directory); 195 GNUNET_free(handle->directory);
167 196
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h
index 90cbd8a..047afab 100644
--- a/src/gnunet_chat_handle.h
+++ b/src/gnunet_chat_handle.h
@@ -31,6 +31,7 @@
31#include <gnunet/gnunet_container_lib.h> 31#include <gnunet/gnunet_container_lib.h>
32#include <gnunet/gnunet_arm_service.h> 32#include <gnunet/gnunet_arm_service.h>
33#include <gnunet/gnunet_fs_service.h> 33#include <gnunet/gnunet_fs_service.h>
34#include <gnunet/gnunet_identity_service.h>
34#include <gnunet/gnunet_messenger_service.h> 35#include <gnunet/gnunet_messenger_service.h>
35#include <gnunet/gnunet_scheduler_lib.h> 36#include <gnunet/gnunet_scheduler_lib.h>
36#include <gnunet/gnunet_util_lib.h> 37#include <gnunet/gnunet_util_lib.h>
@@ -45,6 +46,14 @@ struct GNUNET_CHAT_InternalMessages
45 struct GNUNET_CHAT_InternalMessages *prev; 46 struct GNUNET_CHAT_InternalMessages *prev;
46}; 47};
47 48
49struct GNUNET_CHAT_InternalIdentities
50{
51 char *name;
52 struct GNUNET_IDENTITY_Ego *ego;
53 struct GNUNET_CHAT_InternalIdentities *next;
54 struct GNUNET_CHAT_InternalIdentities *prev;
55};
56
48struct GNUNET_CHAT_Handle 57struct GNUNET_CHAT_Handle
49{ 58{
50 const struct GNUNET_CONFIGURATION_Handle* cfg; 59 const struct GNUNET_CONFIGURATION_Handle* cfg;
@@ -58,6 +67,9 @@ struct GNUNET_CHAT_Handle
58 GNUNET_CHAT_ContextMessageCallback msg_cb; 67 GNUNET_CHAT_ContextMessageCallback msg_cb;
59 void *msg_cls; 68 void *msg_cls;
60 69
70 struct GNUNET_CHAT_InternalIdentities *identities_head;
71 struct GNUNET_CHAT_InternalIdentities *identities_tail;
72
61 struct GNUNET_CONTAINER_MultiHashMap *files; 73 struct GNUNET_CONTAINER_MultiHashMap *files;
62 struct GNUNET_CONTAINER_MultiHashMap *contexts; 74 struct GNUNET_CONTAINER_MultiHashMap *contexts;
63 struct GNUNET_CONTAINER_MultiShortmap *contacts; 75 struct GNUNET_CONTAINER_MultiShortmap *contacts;
@@ -65,6 +77,7 @@ struct GNUNET_CHAT_Handle
65 77
66 struct GNUNET_ARM_Handle *arm; 78 struct GNUNET_ARM_Handle *arm;
67 struct GNUNET_FS_Handle *fs; 79 struct GNUNET_FS_Handle *fs;
80 struct GNUNET_IDENTITY_Handle *identity;
68 struct GNUNET_MESSENGER_Handle *messenger; 81 struct GNUNET_MESSENGER_Handle *messenger;
69 82
70 char *public_key; 83 char *public_key;
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
index 57f1c5b..5b11876 100644
--- a/src/gnunet_chat_handle_intern.c
+++ b/src/gnunet_chat_handle_intern.c
@@ -74,7 +74,8 @@ on_handle_arm_connection(void *cls,
74} 74}
75 75
76void* 76void*
77notify_handle_fs_progress(void* cls, const struct GNUNET_FS_ProgressInfo* info) 77notify_handle_fs_progress(void* cls,
78 const struct GNUNET_FS_ProgressInfo* info)
78{ 79{
79 struct GNUNET_CHAT_Handle *chat = cls; 80 struct GNUNET_CHAT_Handle *chat = cls;
80 81
@@ -197,6 +198,31 @@ notify_handle_fs_progress(void* cls, const struct GNUNET_FS_ProgressInfo* info)
197 return NULL; 198 return NULL;
198} 199}
199 200
201void
202on_handle_gnunet_identity(void *cls,
203 struct GNUNET_IDENTITY_Ego *ego,
204 GNUNET_UNUSED void **ctx,
205 const char *name)
206{
207 struct GNUNET_CHAT_Handle* handle = cls;
208
209 if (!name)
210 return;
211
212 struct GNUNET_CHAT_InternalIdentities *identities = GNUNET_new(
213 struct GNUNET_CHAT_InternalIdentities
214 );
215
216 identities->name = GNUNET_strdup(name);
217 identities->ego = ego;
218
219 GNUNET_CONTAINER_DLL_insert_tail(
220 handle->identities_head,
221 handle->identities_tail,
222 identities
223 );
224}
225
200int 226int
201intern_provide_contact_for_member(struct GNUNET_CHAT_Handle *handle, 227intern_provide_contact_for_member(struct GNUNET_CHAT_Handle *handle,
202 const struct GNUNET_MESSENGER_Contact *member, 228 const struct GNUNET_MESSENGER_Contact *member,
@@ -341,6 +367,8 @@ on_handle_message (void *cls,
341 (GNUNET_OK != intern_provide_contact_for_member(handle, sender, NULL))) 367 (GNUNET_OK != intern_provide_contact_for_member(handle, sender, NULL)))
342 return; 368 return;
343 369
370 GNUNET_MESSENGER_get_message(room, &(msg->header.previous));
371
344 struct GNUNET_CHAT_Context *context = GNUNET_CONTAINER_multihashmap_get( 372 struct GNUNET_CHAT_Context *context = GNUNET_CONTAINER_multihashmap_get(
345 handle->contexts, GNUNET_MESSENGER_room_get_key(room) 373 handle->contexts, GNUNET_MESSENGER_room_get_key(room)
346 ); 374 );