aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-04-03 03:22:56 +0200
committerTheJackiMonster <thejackimonster@gmail.com>2022-04-03 03:22:56 +0200
commit4e7fe777d6bb03b88ae3e0ac781f366f5296b23d (patch)
tree4353a294f0306e56f0be20c7c054775cd80c15f1
parentcd4754e94da6553f93c0d499a1feb95025b44638 (diff)
downloadlibgnunetchat-4e7fe777d6bb03b88ae3e0ac781f366f5296b23d.tar.gz
libgnunetchat-4e7fe777d6bb03b88ae3e0ac781f366f5296b23d.zip
Implement relogin after renaming and add doxygen docs
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/gnunet_chat_account.h20
-rw-r--r--src/gnunet_chat_contact.c2
-rw-r--r--src/gnunet_chat_contact.h30
-rw-r--r--src/gnunet_chat_context.h49
-rw-r--r--src/gnunet_chat_file.h83
-rw-r--r--src/gnunet_chat_group.h21
-rw-r--r--src/gnunet_chat_handle.c31
-rw-r--r--src/gnunet_chat_handle.h102
-rw-r--r--src/gnunet_chat_handle_intern.c20
-rw-r--r--src/gnunet_chat_invitation.h15
-rw-r--r--src/gnunet_chat_lib.c44
-rw-r--r--src/gnunet_chat_lib_intern.c16
-rw-r--r--src/gnunet_chat_lobby.h22
-rw-r--r--src/gnunet_chat_message.h28
-rw-r--r--src/gnunet_chat_uri.h13
-rw-r--r--src/gnunet_chat_util.c5
-rw-r--r--src/gnunet_chat_util.h106
-rw-r--r--tests/test_gnunet_chat_handle.c14
18 files changed, 546 insertions, 75 deletions
diff --git a/src/gnunet_chat_account.h b/src/gnunet_chat_account.h
index 40d8392..45ca869 100644
--- a/src/gnunet_chat_account.h
+++ b/src/gnunet_chat_account.h
@@ -38,14 +38,34 @@ struct GNUNET_CHAT_Account
38 void *user_pointer; 38 void *user_pointer;
39}; 39};
40 40
41/**
42 * Creates a chat account using a given <i>ego</i> and
43 * a matching <i>name</i>.
44 *
45 * @param[in] ego EGO
46 * @param[in] name Name
47 * @return New chat account
48 */
41struct GNUNET_CHAT_Account* 49struct GNUNET_CHAT_Account*
42account_create_from_ego(struct GNUNET_IDENTITY_Ego *ego, 50account_create_from_ego(struct GNUNET_IDENTITY_Ego *ego,
43 const char *name); 51 const char *name);
44 52
53/**
54 * Updates the stored directory path by a chat <i>account</i>
55 * using its current ego and key information.
56 *
57 * @param[in,out] account Chat account
58 * @param[in] base_directory The base directory for the accounts
59 */
45void 60void
46account_update_directory (struct GNUNET_CHAT_Account *account, 61account_update_directory (struct GNUNET_CHAT_Account *account,
47 const char *base_directory); 62 const char *base_directory);
48 63
64/**
65 * Destroys a chat <i>account</i> and frees its memory.
66 *
67 * @param[in,out] account Chat account
68 */
49void 69void
50account_destroy(struct GNUNET_CHAT_Account *account); 70account_destroy(struct GNUNET_CHAT_Account *account);
51 71
diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c
index 1f88cad..5b6c1a5 100644
--- a/src/gnunet_chat_contact.c
+++ b/src/gnunet_chat_contact.c
@@ -71,7 +71,7 @@ contact_update_key (struct GNUNET_CHAT_Contact *contact)
71} 71}
72 72
73struct GNUNET_CHAT_Context* 73struct GNUNET_CHAT_Context*
74contact_find_context (struct GNUNET_CHAT_Contact *contact) 74contact_find_context (const struct GNUNET_CHAT_Contact *contact)
75{ 75{
76 GNUNET_assert(contact); 76 GNUNET_assert(contact);
77 77
diff --git a/src/gnunet_chat_contact.h b/src/gnunet_chat_contact.h
index cf0dded..54918cc 100644
--- a/src/gnunet_chat_contact.h
+++ b/src/gnunet_chat_contact.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2021 GNUnet e.V. 3 Copyright (C) 2021--2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -46,16 +46,42 @@ struct GNUNET_CHAT_Contact
46 int is_owned; 46 int is_owned;
47}; 47};
48 48
49/**
50 * Creates a chat contact using a given messenger <i>contact</i>
51 * with a selected chat <i>handle</i>.
52 *
53 * @param[in,out] handle Chat handle
54 * @param[in] member Messenger contact
55 * @return New chat contact
56 */
49struct GNUNET_CHAT_Contact* 57struct GNUNET_CHAT_Contact*
50contact_create_from_member (struct GNUNET_CHAT_Handle *handle, 58contact_create_from_member (struct GNUNET_CHAT_Handle *handle,
51 const struct GNUNET_MESSENGER_Contact *member); 59 const struct GNUNET_MESSENGER_Contact *member);
52 60
61/**
62 * Updates the string representation of the public key from
63 * a given chat <i>contact</i>.
64 *
65 * @param[in,out] contact Chat contact
66 */
53void 67void
54contact_update_key (struct GNUNET_CHAT_Contact *contact); 68contact_update_key (struct GNUNET_CHAT_Contact *contact);
55 69
70/**
71 * Searches for a chat context containing a given chat
72 * <i>contact</i> and the least amount of other members.
73 *
74 * @param[in] contact Chat contact
75 * @return Chat context or NULL
76 */
56struct GNUNET_CHAT_Context* 77struct GNUNET_CHAT_Context*
57contact_find_context (struct GNUNET_CHAT_Contact *contact); 78contact_find_context (const struct GNUNET_CHAT_Contact *contact);
58 79
80/**
81 * Destroys a chat <i>contact</i> and frees its memory.
82 *
83 * @param[in,out] contact Chat contact
84 */
59void 85void
60contact_destroy (struct GNUNET_CHAT_Contact* contact); 86contact_destroy (struct GNUNET_CHAT_Contact* contact);
61 87
diff --git a/src/gnunet_chat_context.h b/src/gnunet_chat_context.h
index 5bafe53..66e777a 100644
--- a/src/gnunet_chat_context.h
+++ b/src/gnunet_chat_context.h
@@ -61,31 +61,80 @@ struct GNUNET_CHAT_Context
61 struct GNUNET_NAMESTORE_QueueEntry *query; 61 struct GNUNET_NAMESTORE_QueueEntry *query;
62}; 62};
63 63
64/**
65 * Creates a chat context from a messenger <i>room</i>
66 * with a selected chat <i>handle</i>.
67 *
68 * @param[in,out] handle Chat handle
69 * @param[in,out] room Messenger room
70 * @return New chat context
71 */
64struct GNUNET_CHAT_Context* 72struct GNUNET_CHAT_Context*
65context_create_from_room (struct GNUNET_CHAT_Handle *handle, 73context_create_from_room (struct GNUNET_CHAT_Handle *handle,
66 struct GNUNET_MESSENGER_Room *room); 74 struct GNUNET_MESSENGER_Room *room);
67 75
76/**
77 * Creates a chat context from a messenger <i>contact</i>
78 * with a selected chat <i>handle</i>.
79 *
80 * @param[in,out] handle Chat handle
81 * @param[in] contact Messenger contact
82 * @return New chat context
83 */
68struct GNUNET_CHAT_Context* 84struct GNUNET_CHAT_Context*
69context_create_from_contact (struct GNUNET_CHAT_Handle *handle, 85context_create_from_contact (struct GNUNET_CHAT_Handle *handle,
70 const struct GNUNET_MESSENGER_Contact *contact); 86 const struct GNUNET_MESSENGER_Contact *contact);
71 87
88/**
89 * Destroys a chat <i>context</i> and frees its memory.
90 *
91 * @param[in,out] context Chat context
92 */
72void 93void
73context_destroy (struct GNUNET_CHAT_Context* context); 94context_destroy (struct GNUNET_CHAT_Context* context);
74 95
96/**
97 * Updates the connected messenger <i>room</i> of a
98 * selected chat <i>context</i>.
99 *
100 * @param[in,out] context Chat context
101 * @param[in,out] room Messenger room
102 */
75void 103void
76context_update_room (struct GNUNET_CHAT_Context *context, 104context_update_room (struct GNUNET_CHAT_Context *context,
77 struct GNUNET_MESSENGER_Room *room); 105 struct GNUNET_MESSENGER_Room *room);
78 106
107/**
108 * Updates the <i>nick</i> of a selected chat <i>context</i>.
109 *
110 * @param[in,out] context Chat context
111 * @param[in] nick Nick name
112 */
79void 113void
80context_update_nick (struct GNUNET_CHAT_Context *context, 114context_update_nick (struct GNUNET_CHAT_Context *context,
81 const char *nick); 115 const char *nick);
82 116
117/**
118 * Reads the <i>data</i> of records under a given <i>label</i>
119 * and updates the chat <i>context</i> with it.
120 *
121 * @param[in,out] context Chat context
122 * @param[in] label Label
123 * @param[in] count Count of data
124 * @param[in] data Records data
125 */
83void 126void
84context_read_records (struct GNUNET_CHAT_Context *context, 127context_read_records (struct GNUNET_CHAT_Context *context,
85 const char *label, 128 const char *label,
86 unsigned int count, 129 unsigned int count,
87 const struct GNUNET_GNSRECORD_Data *data); 130 const struct GNUNET_GNSRECORD_Data *data);
88 131
132/**
133 * Writes the data from a selected chat <i>context</i> into
134 * the namestore as private records.
135 *
136 * @param[in,out] context Chat context
137 */
89void 138void
90context_write_records (struct GNUNET_CHAT_Context *context); 139context_write_records (struct GNUNET_CHAT_Context *context);
91 140
diff --git a/src/gnunet_chat_file.h b/src/gnunet_chat_file.h
index 8aa1465..5208f18 100644
--- a/src/gnunet_chat_file.h
+++ b/src/gnunet_chat_file.h
@@ -103,45 +103,128 @@ struct GNUNET_CHAT_File
103 void *user_pointer; 103 void *user_pointer;
104}; 104};
105 105
106/**
107 * Creates a chat file handle from a file body in a
108 * <i>message</i> with a selected chat <i>handle</i>.
109 *
110 * @param[in,out] handle Chat handle
111 * @param[in] message File message body
112 * @return New chat file handle
113 */
106struct GNUNET_CHAT_File* 114struct GNUNET_CHAT_File*
107file_create_from_message (struct GNUNET_CHAT_Handle *handle, 115file_create_from_message (struct GNUNET_CHAT_Handle *handle,
108 const struct GNUNET_MESSENGER_MessageFile *message); 116 const struct GNUNET_MESSENGER_MessageFile *message);
109 117
118/**
119 * Creates a chat file handle from a local file on disk
120 * under a given <i>name</i> using a <i>hash</i> and a
121 * selected symmetric <i>key</i> with a selected chat
122 * <i>handle</i>.
123 *
124 * @param[in,out] handle Chat handle
125 * @param[in] name File name
126 * @param[in] hash File hash
127 * @param[in] key Symmetric key
128 * @return New chat file handle
129 */
110struct GNUNET_CHAT_File* 130struct GNUNET_CHAT_File*
111file_create_from_disk (struct GNUNET_CHAT_Handle *handle, 131file_create_from_disk (struct GNUNET_CHAT_Handle *handle,
112 const char *name, 132 const char *name,
113 const struct GNUNET_HashCode *hash, 133 const struct GNUNET_HashCode *hash,
114 const struct GNUNET_CRYPTO_SymmetricSessionKey *key); 134 const struct GNUNET_CRYPTO_SymmetricSessionKey *key);
115 135
136/**
137 * Destroys a chat <i>file</i> handle and frees its memory.
138 *
139 * @param[in,out] file Chat file handle
140 */
116void 141void
117file_destroy (struct GNUNET_CHAT_File *file); 142file_destroy (struct GNUNET_CHAT_File *file);
118 143
144/**
145 * Binds a chat <i>context</i>, a callback and a closure
146 * to a given chat <i>file</i> handle to be called on any
147 * progress uploading the regarding file.
148 *
149 * @param[in,out] file Chat file handle
150 * @param[in,out] context Chat context
151 * @param[in] cb Callback for upload progress
152 * @param[in,out] cls Closure
153 */
119void 154void
120file_bind_upload (struct GNUNET_CHAT_File *file, 155file_bind_upload (struct GNUNET_CHAT_File *file,
121 struct GNUNET_CHAT_Context *context, 156 struct GNUNET_CHAT_Context *context,
122 GNUNET_CHAT_FileUploadCallback cb, 157 GNUNET_CHAT_FileUploadCallback cb,
123 void *cls); 158 void *cls);
124 159
160/**
161 * Binds a callback and a closure to a given chat <i>file</i>
162 * handle to be called on any progress downloading the
163 * regarding file.
164 *
165 * @param[in,out] file Chat file handle
166 * @param[in] cb Callback for download progress
167 * @param[in,out] cls Closure
168 */
125void 169void
126file_bind_downlaod (struct GNUNET_CHAT_File *file, 170file_bind_downlaod (struct GNUNET_CHAT_File *file,
127 GNUNET_CHAT_FileDownloadCallback cb, 171 GNUNET_CHAT_FileDownloadCallback cb,
128 void *cls); 172 void *cls);
129 173
174/**
175 * Binds a callback and a closure to a given chat <i>file</i>
176 * handle to be called on any progress unindexing the
177 * regarding file.
178 *
179 * @param[in,out] file Chat file handle
180 * @param[in] cb Callback for unindex progress
181 * @param[in,out] cls Closure
182 */
130void 183void
131file_bind_unindex (struct GNUNET_CHAT_File *file, 184file_bind_unindex (struct GNUNET_CHAT_File *file,
132 GNUNET_CHAT_FileUnindexCallback cb, 185 GNUNET_CHAT_FileUnindexCallback cb,
133 void *cls); 186 void *cls);
134 187
188/**
189 * Calls the regarding events and bound callback of a given
190 * chat <i>file</i> handle to a file upload progress using
191 * the provided state of <i>completed</i> bytes and its file
192 * <i>size</i>.
193 *
194 * @param[in,out] file Chat file handle
195 * @param[in] completed Amount of uploaded bytes
196 * @param[in] size Full file size
197 */
135void 198void
136file_update_upload (struct GNUNET_CHAT_File *file, 199file_update_upload (struct GNUNET_CHAT_File *file,
137 uint64_t completed, 200 uint64_t completed,
138 uint64_t size); 201 uint64_t size);
139 202
203/**
204 * Calls the regarding events and bound callback of a given
205 * chat <i>file</i> handle to a file download progress using
206 * the provided state of <i>completed</i> bytes and its file
207 * <i>size</i>.
208 *
209 * @param[in,out] file Chat file handle
210 * @param[in] completed Amount of downloaded bytes
211 * @param[in] size Full file size
212 */
140void 213void
141file_update_download (struct GNUNET_CHAT_File *file, 214file_update_download (struct GNUNET_CHAT_File *file,
142 uint64_t completed, 215 uint64_t completed,
143 uint64_t size); 216 uint64_t size);
144 217
218/**
219 * Calls the regarding events and bound callback of a given
220 * chat <i>file</i> handle to a file unindex progress using
221 * the provided state of <i>completed</i> bytes and its file
222 * <i>size</i>.
223 *
224 * @param[in,out] file Chat file handle
225 * @param[in] completed Amount of unindexed bytes
226 * @param[in] size Full file size
227 */
145void 228void
146file_update_unindex (struct GNUNET_CHAT_File *file, 229file_update_unindex (struct GNUNET_CHAT_File *file,
147 uint64_t completed, 230 uint64_t completed,
diff --git a/src/gnunet_chat_group.h b/src/gnunet_chat_group.h
index 4c2bf9d..af576a0 100644
--- a/src/gnunet_chat_group.h
+++ b/src/gnunet_chat_group.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2021 GNUnet e.V. 3 Copyright (C) 2021--2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -47,13 +47,32 @@ struct GNUNET_CHAT_Group
47 void *user_pointer; 47 void *user_pointer;
48}; 48};
49 49
50/**
51 * Creates a chat group from a chat <i>context</i>
52 * with a selected chat <i>handle</i>.
53 *
54 * @param[in,out] handle Chat handle
55 * @param[in,out] context Chat context
56 * @return New chat group
57 */
50struct GNUNET_CHAT_Group* 58struct GNUNET_CHAT_Group*
51group_create_from_context (struct GNUNET_CHAT_Handle *handle, 59group_create_from_context (struct GNUNET_CHAT_Handle *handle,
52 struct GNUNET_CHAT_Context *context); 60 struct GNUNET_CHAT_Context *context);
53 61
62/**
63 * Destroys a chat <i>group</i> and frees its memory.
64 *
65 * @param[in,out] group Chat group
66 */
54void 67void
55group_destroy (struct GNUNET_CHAT_Group* group); 68group_destroy (struct GNUNET_CHAT_Group* group);
56 69
70/**
71 * Publishes a selected chat <i>group</i> under the
72 * topic of its context.
73 *
74 * @param[in,out] group Chat group
75 */
57void 76void
58group_publish (struct GNUNET_CHAT_Group* group); 77group_publish (struct GNUNET_CHAT_Group* group);
59 78
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
index cbbbcc7..b9b1d3e 100644
--- a/src/gnunet_chat_handle.c
+++ b/src/gnunet_chat_handle.c
@@ -168,39 +168,32 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle)
168 GNUNET_NAMESTORE_disconnect(handle->namestore); 168 GNUNET_NAMESTORE_disconnect(handle->namestore);
169 169
170 struct GNUNET_CHAT_InternalAccounts *accounts; 170 struct GNUNET_CHAT_InternalAccounts *accounts;
171 accounts = handle->accounts_head;
172
173 while (accounts)
174 {
175 if (accounts->op)
176 GNUNET_IDENTITY_cancel(accounts->op);
177
178 accounts->op = NULL;
179 accounts = accounts->next;
180 }
181
182 if (handle->identity)
183 GNUNET_IDENTITY_disconnect(handle->identity);
184
185 if (handle->arm)
186 GNUNET_ARM_disconnect(handle->arm);
187 171
188 while (handle->accounts_head) 172 while (handle->accounts_head)
189 { 173 {
190 accounts = handle->accounts_head; 174 accounts = handle->accounts_head;
191 175
176 if (accounts->op)
177 GNUNET_IDENTITY_cancel(accounts->op);
178
192 if (accounts->account) 179 if (accounts->account)
193 account_destroy(accounts->account); 180 account_destroy(accounts->account);
194 181
195 GNUNET_CONTAINER_DLL_remove( 182 GNUNET_CONTAINER_DLL_remove(
196 handle->accounts_head, 183 handle->accounts_head,
197 handle->accounts_tail, 184 handle->accounts_tail,
198 accounts 185 accounts
199 ); 186 );
200 187
201 GNUNET_free(accounts); 188 GNUNET_free(accounts);
202 } 189 }
203 190
191 if (handle->identity)
192 GNUNET_IDENTITY_disconnect(handle->identity);
193
194 if (handle->arm)
195 GNUNET_ARM_disconnect(handle->arm);
196
204 if (handle->directory) 197 if (handle->directory)
205 GNUNET_free(handle->directory); 198 GNUNET_free(handle->directory);
206 199
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h
index 2cc6349..3028186 100644
--- a/src/gnunet_chat_handle.h
+++ b/src/gnunet_chat_handle.h
@@ -124,52 +124,154 @@ struct GNUNET_CHAT_Handle
124 void *user_pointer; 124 void *user_pointer;
125}; 125};
126 126
127/**
128 * Creates a chat handle with a selected configuration,
129 * a custom message callback and a custom closure for
130 * the callback.
131 *
132 * @param[in] cfg Configuration
133 * @param[in] msg_cb Message callback
134 * @param[in,out] msg_cls Closure
135 * @return New chat handle
136 */
127struct GNUNET_CHAT_Handle* 137struct GNUNET_CHAT_Handle*
128handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, 138handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg,
129 GNUNET_CHAT_ContextMessageCallback msg_cb, 139 GNUNET_CHAT_ContextMessageCallback msg_cb,
130 void *msg_cls); 140 void *msg_cls);
131 141
142/**
143 * Updates the string representation of the public key from
144 * a given chat <i>handle</i>.
145 *
146 * @param[in,out] handle Chat handle
147 */
132void 148void
133handle_update_key (struct GNUNET_CHAT_Handle *handle); 149handle_update_key (struct GNUNET_CHAT_Handle *handle);
134 150
151/**
152 * Destroys a chat <i>handle</i> and frees its memory.
153 *
154 * @param[in,out] handle Chat handle
155 */
135void 156void
136handle_destroy (struct GNUNET_CHAT_Handle *handle); 157handle_destroy (struct GNUNET_CHAT_Handle *handle);
137 158
159/**
160 * Connects a given chat <i>handle</i> to a selected
161 * chat <i>account</i> using it for further operations.
162 *
163 * @param[in,out] handle Chat handle
164 * @param[in] account Chat account
165 */
138void 166void
139handle_connect (struct GNUNET_CHAT_Handle *handle, 167handle_connect (struct GNUNET_CHAT_Handle *handle,
140 const struct GNUNET_CHAT_Account *account); 168 const struct GNUNET_CHAT_Account *account);
141 169
170/**
171 * Disconnects a given chat <i>handle</i> from its current
172 * connected chat account.
173 *
174 * @param[in,out] handle Chat handle
175 */
142void 176void
143handle_disconnect (struct GNUNET_CHAT_Handle *handle); 177handle_disconnect (struct GNUNET_CHAT_Handle *handle);
144 178
179/**
180 * Returns the main directory path to store information
181 * of a given chat <i>handle</i>.
182 *
183 * @param[in] handle Chat handle
184 * @return Directory path
185 */
145const char* 186const char*
146handle_get_directory (const struct GNUNET_CHAT_Handle *handle); 187handle_get_directory (const struct GNUNET_CHAT_Handle *handle);
147 188
189/**
190 * Returns the private key from the current connected chat
191 * account of a given chat <i>handle</i>.
192 *
193 * @param[in] handle Chat handle
194 * @return EGOs private key or NULL
195 */
148const struct GNUNET_IDENTITY_PrivateKey* 196const struct GNUNET_IDENTITY_PrivateKey*
149handle_get_key (const struct GNUNET_CHAT_Handle *handle); 197handle_get_key (const struct GNUNET_CHAT_Handle *handle);
150 198
199/**
200 * Sends an internal chat message from a given chat
201 * <i>handle</i> with an optional chat <i>context</i>,
202 * a custom <i>flag</i> and an optional <i>warning</i> text.
203 *
204 * @param[in,out] handle Chat handle
205 * @param[in,out] context Chat context or NULL
206 * @param[in] flag Chat message flag
207 * @param[in] warning Warning text
208 */
151void 209void
152handle_send_internal_message (struct GNUNET_CHAT_Handle *handle, 210handle_send_internal_message (struct GNUNET_CHAT_Handle *handle,
153 struct GNUNET_CHAT_Context *context, 211 struct GNUNET_CHAT_Context *context,
154 enum GNUNET_CHAT_MessageFlag flag, 212 enum GNUNET_CHAT_MessageFlag flag,
155 const char *warning); 213 const char *warning);
156 214
215/**
216 * Sends a name message to a messenger <i>room</i> with
217 * a selected chat <i>handle</i>.
218 *
219 * @param[in,out] handle Chat handle
220 * @param[in,out] room Messenger room
221 */
157void 222void
158handle_send_room_name (struct GNUNET_CHAT_Handle *handle, 223handle_send_room_name (struct GNUNET_CHAT_Handle *handle,
159 struct GNUNET_MESSENGER_Room *room); 224 struct GNUNET_MESSENGER_Room *room);
160 225
226/**
227 * Checks a given chat <i>handle</i> for any chat context
228 * connected with a messenger <i>room</i>, creates it if
229 * necessary and manages its context type.
230 *
231 * @param[in,out] handle Chat handle
232 * @param[in,out] room Messenger room
233 * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR
234 */
161int 235int
162handle_request_context_by_room (struct GNUNET_CHAT_Handle *handle, 236handle_request_context_by_room (struct GNUNET_CHAT_Handle *handle,
163 struct GNUNET_MESSENGER_Room *room); 237 struct GNUNET_MESSENGER_Room *room);
164 238
239/**
240 * Returns the chat contact registered for a given messenger
241 * <i>contact</i> by a selected chat <i>handle</i>.
242 *
243 * @param[in] handle Chat handle
244 * @param[in] contact Messenger contact
245 * @return Chat contact or NULL
246 */
165struct GNUNET_CHAT_Contact* 247struct GNUNET_CHAT_Contact*
166handle_get_contact_from_messenger (const struct GNUNET_CHAT_Handle *handle, 248handle_get_contact_from_messenger (const struct GNUNET_CHAT_Handle *handle,
167 const struct GNUNET_MESSENGER_Contact *contact); 249 const struct GNUNET_MESSENGER_Contact *contact);
168 250
251/**
252 * Returns the chat group registered for a given messenger
253 * <i>room</i> by a selected chat <i>handle</i>.
254 *
255 * @param[in] handle Chat handle
256 * @param[in] room Messenger room
257 * @return Chat group or NULL
258 */
169struct GNUNET_CHAT_Group* 259struct GNUNET_CHAT_Group*
170handle_get_group_from_messenger (const struct GNUNET_CHAT_Handle *handle, 260handle_get_group_from_messenger (const struct GNUNET_CHAT_Handle *handle,
171 const struct GNUNET_MESSENGER_Room *room); 261 const struct GNUNET_MESSENGER_Room *room);
172 262
263/**
264 * Processes the <i>data</i> of records under a given
265 * <i>label</i> and creates a matching chat <i>context</i>
266 * with it if it does not exist already, registered by a chat
267 * <i>handle</i>, to be updated.
268 *
269 * @param[in,out] handle Chat handle
270 * @param[in] label Namestore label
271 * @param[in] count Count of data
272 * @param[in] data Records data
273 * @return Chat context or NULL
274 */
173struct GNUNET_CHAT_Context* 275struct GNUNET_CHAT_Context*
174handle_process_records (struct GNUNET_CHAT_Handle *handle, 276handle_process_records (struct GNUNET_CHAT_Handle *handle,
175 const char *label, 277 const char *label,
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
index 63758a8..e278eaf 100644
--- a/src/gnunet_chat_handle_intern.c
+++ b/src/gnunet_chat_handle_intern.c
@@ -219,12 +219,12 @@ notify_handle_fs_progress(void* cls,
219void 219void
220on_handle_gnunet_identity(void *cls, 220on_handle_gnunet_identity(void *cls,
221 struct GNUNET_IDENTITY_Ego *ego, 221 struct GNUNET_IDENTITY_Ego *ego,
222 GNUNET_UNUSED void **ctx, 222 void **ctx,
223 const char *name) 223 const char *name)
224{ 224{
225 struct GNUNET_CHAT_Handle* handle = cls; 225 struct GNUNET_CHAT_Handle* handle = cls;
226 226
227 if (!name) 227 if (!ctx)
228 return; 228 return;
229 229
230 if (!ego) 230 if (!ego)
@@ -241,9 +241,22 @@ on_handle_gnunet_identity(void *cls,
241 goto check_matching_name; 241 goto check_matching_name;
242 242
243 if (name) 243 if (name)
244 {
244 util_set_name_field(name, &(accounts->account->name)); 245 util_set_name_field(name, &(accounts->account->name));
246
247 if (handle->current == accounts->account)
248 handle_send_internal_message(
249 handle,
250 NULL,
251 GNUNET_CHAT_FLAG_LOGIN,
252 NULL
253 );
254 }
245 else 255 else
246 { 256 {
257 if (handle->current == accounts->account)
258 handle_disconnect(handle);
259
247 account_destroy(accounts->account); 260 account_destroy(accounts->account);
248 261
249 GNUNET_CONTAINER_DLL_remove( 262 GNUNET_CONTAINER_DLL_remove(
@@ -269,6 +282,9 @@ skip_account:
269 accounts = accounts->next; 282 accounts = accounts->next;
270 } 283 }
271 284
285 if (!name)
286 return;
287
272 accounts = GNUNET_new(struct GNUNET_CHAT_InternalAccounts); 288 accounts = GNUNET_new(struct GNUNET_CHAT_InternalAccounts);
273 accounts->account = account_create_from_ego(ego, name); 289 accounts->account = account_create_from_ego(ego, name);
274 290
diff --git a/src/gnunet_chat_invitation.h b/src/gnunet_chat_invitation.h
index 433131e..a0d76de 100644
--- a/src/gnunet_chat_invitation.h
+++ b/src/gnunet_chat_invitation.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2021 GNUnet e.V. 3 Copyright (C) 2021--2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -42,10 +42,23 @@ struct GNUNET_CHAT_Invitation
42 GNUNET_PEER_Id door; 42 GNUNET_PEER_Id door;
43}; 43};
44 44
45/**
46 * Creates a chat invitation from a invite body in a
47 * <i>message</i> with a selected chat <i>context</i>.
48 *
49 * @param[in,out] context Chat context
50 * @param[in] message Invite message body
51 * @return New chat invitation
52 */
45struct GNUNET_CHAT_Invitation* 53struct GNUNET_CHAT_Invitation*
46invitation_create_from_message (struct GNUNET_CHAT_Context *context, 54invitation_create_from_message (struct GNUNET_CHAT_Context *context,
47 const struct GNUNET_MESSENGER_MessageInvite *message); 55 const struct GNUNET_MESSENGER_MessageInvite *message);
48 56
57/**
58 * Destroys a chat <i>invitation</i> and frees its memory.
59 *
60 * @param[in,out] invitation Chat invitation
61 */
49void 62void
50invitation_destroy (struct GNUNET_CHAT_Invitation *invitation); 63invitation_destroy (struct GNUNET_CHAT_Invitation *invitation);
51 64
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index 6739d15..c52ddf4 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -70,8 +70,11 @@ GNUNET_CHAT_stop (struct GNUNET_CHAT_Handle *handle)
70 if ((!handle) || (handle->destruction)) 70 if ((!handle) || (handle->destruction))
71 return; 71 return;
72 72
73 handle->destruction = GNUNET_SCHEDULER_add_now( 73 handle->destruction = GNUNET_SCHEDULER_add_at_with_priority(
74 task_handle_destruction, handle 74 GNUNET_TIME_absolute_get(),
75 GNUNET_SCHEDULER_PRIORITY_IDLE,
76 task_handle_destruction,
77 handle
75 ); 78 );
76} 79}
77 80
@@ -82,7 +85,7 @@ GNUNET_CHAT_account_create (struct GNUNET_CHAT_Handle *handle,
82{ 85{
83 GNUNET_CHAT_VERSION_ASSERT(); 86 GNUNET_CHAT_VERSION_ASSERT();
84 87
85 if ((!handle) || (!name)) 88 if ((!handle) || (handle->destruction) || (!name))
86 return GNUNET_SYSERR; 89 return GNUNET_SYSERR;
87 90
88 struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head; 91 struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head;
@@ -134,7 +137,7 @@ GNUNET_CHAT_account_delete(struct GNUNET_CHAT_Handle *handle,
134{ 137{
135 GNUNET_CHAT_VERSION_ASSERT(); 138 GNUNET_CHAT_VERSION_ASSERT();
136 139
137 if ((!handle) || (!name)) 140 if ((!handle) || (handle->destruction) || (!name))
138 return GNUNET_SYSERR; 141 return GNUNET_SYSERR;
139 142
140 struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head; 143 struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head;
@@ -161,7 +164,7 @@ GNUNET_CHAT_account_delete(struct GNUNET_CHAT_Handle *handle,
161 handle->identity, 164 handle->identity,
162 name, 165 name,
163 cb_account_deletion, 166 cb_account_deletion,
164 accounts 167 handle
165 ); 168 );
166 169
167 return (accounts->op? GNUNET_OK : GNUNET_SYSERR); 170 return (accounts->op? GNUNET_OK : GNUNET_SYSERR);
@@ -175,7 +178,7 @@ GNUNET_CHAT_iterate_accounts (const struct GNUNET_CHAT_Handle *handle,
175{ 178{
176 GNUNET_CHAT_VERSION_ASSERT(); 179 GNUNET_CHAT_VERSION_ASSERT();
177 180
178 if (!handle) 181 if ((!handle) || (handle->destruction))
179 return GNUNET_SYSERR; 182 return GNUNET_SYSERR;
180 183
181 int result = 0; 184 int result = 0;
@@ -205,7 +208,7 @@ GNUNET_CHAT_connect (struct GNUNET_CHAT_Handle *handle,
205{ 208{
206 GNUNET_CHAT_VERSION_ASSERT(); 209 GNUNET_CHAT_VERSION_ASSERT();
207 210
208 if (!handle) 211 if ((!handle) || (handle->destruction))
209 return; 212 return;
210 213
211 if (handle->current == account) 214 if (handle->current == account)
@@ -226,7 +229,7 @@ GNUNET_CHAT_disconnect (struct GNUNET_CHAT_Handle *handle)
226{ 229{
227 GNUNET_CHAT_VERSION_ASSERT(); 230 GNUNET_CHAT_VERSION_ASSERT();
228 231
229 if ((!handle) || (!(handle->current))) 232 if ((!handle) || (handle->destruction) || (!(handle->current)))
230 return; 233 return;
231 234
232 handle_disconnect(handle); 235 handle_disconnect(handle);
@@ -238,7 +241,7 @@ GNUNET_CHAT_get_connected (const struct GNUNET_CHAT_Handle *handle)
238{ 241{
239 GNUNET_CHAT_VERSION_ASSERT(); 242 GNUNET_CHAT_VERSION_ASSERT();
240 243
241 if (!handle) 244 if ((!handle) || (handle->destruction))
242 return NULL; 245 return NULL;
243 246
244 return handle->current; 247 return handle->current;
@@ -250,7 +253,7 @@ GNUNET_CHAT_update (struct GNUNET_CHAT_Handle *handle)
250{ 253{
251 GNUNET_CHAT_VERSION_ASSERT(); 254 GNUNET_CHAT_VERSION_ASSERT();
252 255
253 if (!handle) 256 if ((!handle) || (handle->destruction))
254 return GNUNET_SYSERR; 257 return GNUNET_SYSERR;
255 258
256 return GNUNET_MESSENGER_update(handle->messenger); 259 return GNUNET_MESSENGER_update(handle->messenger);
@@ -263,7 +266,7 @@ GNUNET_CHAT_set_name (struct GNUNET_CHAT_Handle *handle,
263{ 266{
264 GNUNET_CHAT_VERSION_ASSERT(); 267 GNUNET_CHAT_VERSION_ASSERT();
265 268
266 if (!handle) 269 if ((!handle) || (handle->destruction))
267 return GNUNET_SYSERR; 270 return GNUNET_SYSERR;
268 271
269 if (!name) 272 if (!name)
@@ -278,7 +281,7 @@ GNUNET_CHAT_get_name (const struct GNUNET_CHAT_Handle *handle)
278{ 281{
279 GNUNET_CHAT_VERSION_ASSERT(); 282 GNUNET_CHAT_VERSION_ASSERT();
280 283
281 if (!handle) 284 if ((!handle) || (handle->destruction))
282 return NULL; 285 return NULL;
283 286
284 return GNUNET_MESSENGER_get_name(handle->messenger); 287 return GNUNET_MESSENGER_get_name(handle->messenger);
@@ -290,7 +293,7 @@ GNUNET_CHAT_get_key (const struct GNUNET_CHAT_Handle *handle)
290{ 293{
291 GNUNET_CHAT_VERSION_ASSERT(); 294 GNUNET_CHAT_VERSION_ASSERT();
292 295
293 if (!handle) 296 if ((!handle) || (handle->destruction))
294 return NULL; 297 return NULL;
295 298
296 return handle->public_key; 299 return handle->public_key;
@@ -390,7 +393,7 @@ GNUNET_CHAT_lobby_open (struct GNUNET_CHAT_Handle *handle,
390{ 393{
391 GNUNET_CHAT_VERSION_ASSERT(); 394 GNUNET_CHAT_VERSION_ASSERT();
392 395
393 if (!handle) 396 if ((!handle) || (handle->destruction))
394 return NULL; 397 return NULL;
395 398
396 struct GNUNET_CHAT_InternalLobbies *lobbies = GNUNET_new( 399 struct GNUNET_CHAT_InternalLobbies *lobbies = GNUNET_new(
@@ -448,7 +451,7 @@ GNUNET_CHAT_lobby_join (struct GNUNET_CHAT_Handle *handle,
448{ 451{
449 GNUNET_CHAT_VERSION_ASSERT(); 452 GNUNET_CHAT_VERSION_ASSERT();
450 453
451 if ((!handle) || (!uri) || (!(handle->gns))) 454 if ((!handle) || (handle->destruction) || (!uri) || (!(handle->gns)))
452 return; 455 return;
453 456
454 struct GNUNET_CHAT_UriLookups *lookups = GNUNET_new( 457 struct GNUNET_CHAT_UriLookups *lookups = GNUNET_new(
@@ -482,7 +485,7 @@ GNUNET_CHAT_set_user_pointer (struct GNUNET_CHAT_Handle *handle,
482{ 485{
483 GNUNET_CHAT_VERSION_ASSERT(); 486 GNUNET_CHAT_VERSION_ASSERT();
484 487
485 if (!handle) 488 if ((!handle) || (handle->destruction))
486 return; 489 return;
487 490
488 handle->user_pointer = user_pointer; 491 handle->user_pointer = user_pointer;
@@ -494,7 +497,7 @@ GNUNET_CHAT_get_user_pointer (const struct GNUNET_CHAT_Handle *handle)
494{ 497{
495 GNUNET_CHAT_VERSION_ASSERT(); 498 GNUNET_CHAT_VERSION_ASSERT();
496 499
497 if (!handle) 500 if ((!handle) || (handle->destruction))
498 return NULL; 501 return NULL;
499 502
500 return handle->user_pointer; 503 return handle->user_pointer;
@@ -508,7 +511,7 @@ GNUNET_CHAT_iterate_contacts (struct GNUNET_CHAT_Handle *handle,
508{ 511{
509 GNUNET_CHAT_VERSION_ASSERT(); 512 GNUNET_CHAT_VERSION_ASSERT();
510 513
511 if ((!handle) || (!(handle->contacts))) 514 if ((!handle) || (handle->destruction) || (!(handle->contacts)))
512 return GNUNET_SYSERR; 515 return GNUNET_SYSERR;
513 516
514 struct GNUNET_CHAT_HandleIterateContacts it; 517 struct GNUNET_CHAT_HandleIterateContacts it;
@@ -565,7 +568,8 @@ GNUNET_CHAT_group_create (struct GNUNET_CHAT_Handle *handle,
565{ 568{
566 GNUNET_CHAT_VERSION_ASSERT(); 569 GNUNET_CHAT_VERSION_ASSERT();
567 570
568 if ((!handle) || (!(handle->groups)) || (!(handle->contexts))) 571 if ((!handle) || (handle->destruction) ||
572 (!(handle->groups)) || (!(handle->contexts)))
569 return NULL; 573 return NULL;
570 574
571 struct GNUNET_HashCode key; 575 struct GNUNET_HashCode key;
@@ -629,7 +633,7 @@ GNUNET_CHAT_iterate_groups (struct GNUNET_CHAT_Handle *handle,
629{ 633{
630 GNUNET_CHAT_VERSION_ASSERT(); 634 GNUNET_CHAT_VERSION_ASSERT();
631 635
632 if ((!handle) || (!(handle->groups))) 636 if ((!handle) || (handle->destruction) || (!(handle->groups)))
633 return GNUNET_SYSERR; 637 return GNUNET_SYSERR;
634 638
635 struct GNUNET_CHAT_HandleIterateGroups it; 639 struct GNUNET_CHAT_HandleIterateGroups it;
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c
index a430fe5..c4f570b 100644
--- a/src/gnunet_chat_lib_intern.c
+++ b/src/gnunet_chat_lib_intern.c
@@ -68,27 +68,13 @@ cb_account_deletion (void *cls,
68{ 68{
69 GNUNET_assert(cls); 69 GNUNET_assert(cls);
70 70
71 struct GNUNET_CHAT_InternalAccounts *accounts = ( 71 struct GNUNET_CHAT_Handle *handle = (struct GNUNET_CHAT_Handle*) cls;
72 (struct GNUNET_CHAT_InternalAccounts*) cls
73 );
74
75 struct GNUNET_CHAT_Handle *handle = accounts->handle;
76 72
77 if (emsg) 73 if (emsg)
78 { 74 {
79 handle_send_internal_message(handle, NULL, GNUNET_CHAT_FLAG_WARNING, emsg); 75 handle_send_internal_message(handle, NULL, GNUNET_CHAT_FLAG_WARNING, emsg);
80 return; 76 return;
81 } 77 }
82
83 GNUNET_CONTAINER_DLL_remove(
84 handle->accounts_head,
85 handle->accounts_tail,
86 accounts
87 );
88
89 GNUNET_free(accounts);
90
91 handle_send_internal_message(handle, NULL, GNUNET_CHAT_FLAG_REFRESH, NULL);
92} 78}
93 79
94void 80void
diff --git a/src/gnunet_chat_lobby.h b/src/gnunet_chat_lobby.h
index bc37cfc..c77fbae 100644
--- a/src/gnunet_chat_lobby.h
+++ b/src/gnunet_chat_lobby.h
@@ -53,12 +53,34 @@ struct GNUNET_CHAT_Lobby
53 void *cls; 53 void *cls;
54}; 54};
55 55
56/**
57 * Creates a new chat lobby using a given chat <i>handle</i>.
58 *
59 * @param[in,out] handle Chat handle
60 * @return New chat lobby
61 */
56struct GNUNET_CHAT_Lobby* 62struct GNUNET_CHAT_Lobby*
57lobby_create (struct GNUNET_CHAT_Handle *handle); 63lobby_create (struct GNUNET_CHAT_Handle *handle);
58 64
65/**
66 * Destroys a chat <i>lobby</i> and frees its memory.
67 *
68 * @param[in,out] lobby Chat lobby
69 */
59void 70void
60lobby_destroy (struct GNUNET_CHAT_Lobby *lobby); 71lobby_destroy (struct GNUNET_CHAT_Lobby *lobby);
61 72
73/**
74 * Opens a chat <i>lobby</i> and closes it automatically
75 * after a selected <i>delay</i>. Once the lobby is open
76 * a given <i>callback</i> will be called with a custom
77 * closure.
78 *
79 * @param[in,out] lobby Chat lobby
80 * @param[in] delay Delay to close down the lobby again
81 * @param[in] callback Lobby opening callback
82 * @param[in,out] cls Closure
83 */
62void 84void
63lobby_open (struct GNUNET_CHAT_Lobby *lobby, 85lobby_open (struct GNUNET_CHAT_Lobby *lobby,
64 struct GNUNET_TIME_Relative delay, 86 struct GNUNET_TIME_Relative delay,
diff --git a/src/gnunet_chat_message.h b/src/gnunet_chat_message.h
index 59737ac..e39cc9c 100644
--- a/src/gnunet_chat_message.h
+++ b/src/gnunet_chat_message.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2021 GNUnet e.V. 3 Copyright (C) 2021--2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -64,17 +64,43 @@ struct GNUNET_CHAT_Message
64 enum GNUNET_CHAT_MessageFlag flag; 64 enum GNUNET_CHAT_MessageFlag flag;
65}; 65};
66 66
67/**
68 * Creates a chat message representing an actual message
69 * from the messenger service in a given chat <i>context</i>
70 * with a valid <i>hash</i> and message <i>flags</i>
71 *
72 * @param[in,out] context Chat context
73 * @param[in] hash Message hash
74 * @param[in] flags Message flags
75 * @param[in] msg Messenger message
76 * @return New chat message
77 */
67struct GNUNET_CHAT_Message* 78struct GNUNET_CHAT_Message*
68message_create_from_msg (struct GNUNET_CHAT_Context *context, 79message_create_from_msg (struct GNUNET_CHAT_Context *context,
69 const struct GNUNET_HashCode *hash, 80 const struct GNUNET_HashCode *hash,
70 enum GNUNET_MESSENGER_MessageFlags flags, 81 enum GNUNET_MESSENGER_MessageFlags flags,
71 const struct GNUNET_MESSENGER_Message *msg); 82 const struct GNUNET_MESSENGER_Message *msg);
72 83
84/**
85 * Creates an internal chat message with an optional chat
86 * <i>context</i>, a custom <i>flag</i> and an optional
87 * <i>warning</i> text.
88 *
89 * @param[in,out] context Chat context or NULL
90 * @param[in] flag Chat message flag
91 * @param[in] warning Warning text
92 * @return New internal chat message
93 */
73struct GNUNET_CHAT_Message* 94struct GNUNET_CHAT_Message*
74message_create_internally (struct GNUNET_CHAT_Context *context, 95message_create_internally (struct GNUNET_CHAT_Context *context,
75 enum GNUNET_CHAT_MessageFlag flag, 96 enum GNUNET_CHAT_MessageFlag flag,
76 const char *warning); 97 const char *warning);
77 98
99/**
100 * Destroys a chat <i>message</i> and frees its memory.
101 *
102 * @param[in,out] message Chat message
103 */
78void 104void
79message_destroy (struct GNUNET_CHAT_Message* message); 105message_destroy (struct GNUNET_CHAT_Message* message);
80 106
diff --git a/src/gnunet_chat_uri.h b/src/gnunet_chat_uri.h
index 0074123..a79f02a 100644
--- a/src/gnunet_chat_uri.h
+++ b/src/gnunet_chat_uri.h
@@ -38,10 +38,23 @@ struct GNUNET_CHAT_Uri
38 char *label; 38 char *label;
39}; 39};
40 40
41/**
42 * Creates a chat uri with a selected key as <i>zone</i>
43 * and a <i>label</i>.
44 *
45 * @param[in] zone URI zone
46 * @param[in] label URI label
47 * @return New chat uri
48 */
41struct GNUNET_CHAT_Uri* 49struct GNUNET_CHAT_Uri*
42uri_create (const struct GNUNET_IDENTITY_PublicKey *zone, 50uri_create (const struct GNUNET_IDENTITY_PublicKey *zone,
43 const char *label); 51 const char *label);
44 52
53/**
54 * Destroys a chat <i>uri</i> and frees its memory.
55 *
56 * @param[in,out] uri Chat uri
57 */
45void 58void
46uri_destroy (struct GNUNET_CHAT_Uri *uri); 59uri_destroy (struct GNUNET_CHAT_Uri *uri);
47 60
diff --git a/src/gnunet_chat_util.c b/src/gnunet_chat_util.c
index ae70918..de17e0c 100644
--- a/src/gnunet_chat_util.c
+++ b/src/gnunet_chat_util.c
@@ -314,8 +314,9 @@ util_get_context_label (enum GNUNET_CHAT_ContextType type,
314 ); 314 );
315} 315}
316 316
317int util_lobby_name (const struct GNUNET_HashCode *hash, 317int
318 char **name) 318util_lobby_name (const struct GNUNET_HashCode *hash,
319 char **name)
319{ 320{
320 return GNUNET_asprintf ( 321 return GNUNET_asprintf (
321 name, 322 name,
diff --git a/src/gnunet_chat_util.h b/src/gnunet_chat_util.h
index c94c32c..55f13de 100644
--- a/src/gnunet_chat_util.h
+++ b/src/gnunet_chat_util.h
@@ -32,50 +32,146 @@
32#include <gnunet/gnunet_messenger_service.h> 32#include <gnunet/gnunet_messenger_service.h>
33#include <gnunet/gnunet_util_lib.h> 33#include <gnunet/gnunet_util_lib.h>
34 34
35/**
36 * Enum for the types of chat contexts.
37 */
35enum GNUNET_CHAT_ContextType 38enum GNUNET_CHAT_ContextType
36{ 39{
37 GNUNET_CHAT_CONTEXT_TYPE_CONTACT = 1, 40 /**
38 GNUNET_CHAT_CONTEXT_TYPE_GROUP = 2, 41 * Contact context type
39 GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN = 0 42 */
43 GNUNET_CHAT_CONTEXT_TYPE_CONTACT = 1,/**< GNUNET_CHAT_CONTEXT_TYPE_CONTACT */
44
45 /**
46 * Group context type
47 */
48 GNUNET_CHAT_CONTEXT_TYPE_GROUP = 2,/**< GNUNET_CHAT_CONTEXT_TYPE_GROUP */
49
50 /**
51 * Unknown context type
52 */
53 GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN = 0 /**< GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN */
40}; 54};
41 55
56/**
57 * Converts a unique messenger contact, being consistent <i>member</i>
58 * of multiple messenger rooms via memory consistency, into a short
59 * hash variant for map access as key.
60 *
61 * @param[in] member Messenger contact
62 * @param[out] shorthash Short hash
63 */
42void 64void
43util_shorthash_from_member (const struct GNUNET_MESSENGER_Contact *member, 65util_shorthash_from_member (const struct GNUNET_MESSENGER_Contact *member,
44 struct GNUNET_ShortHashCode *shorthash); 66 struct GNUNET_ShortHashCode *shorthash);
45 67
68/**
69 * Updates the stored content of a <i>field</i> with
70 * a given <i>name</i>.
71 *
72 * @param[in] name Name
73 * @param[out] field String field
74 */
46void 75void
47util_set_name_field (const char *name, char **field); 76util_set_name_field (const char *name, char **field);
48 77
78/**
79 * Generates the <i>hash</i> of a file under a given
80 * <i>filename</i>.
81 *
82 * @param[in] filename File name
83 * @param[out] hash Hash of file
84 * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR
85 */
49int 86int
50util_hash_file (const char *filename, struct GNUNET_HashCode *hash); 87util_hash_file (const char *filename, struct GNUNET_HashCode *hash);
51 88
89/**
90 * Encrypts a file inplace under a given <i>filename</i>
91 * with a selected symmetric <i>key</i> and its <i>hash</i>
92 * as initialization vector.
93 *
94 * @param[in] filename File name
95 * @param[in] hash Hash of file
96 * @param[in] key Symmetric key
97 * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR
98 */
52int 99int
53util_encrypt_file (const char *filename, 100util_encrypt_file (const char *filename,
54 const struct GNUNET_HashCode *hash, 101 const struct GNUNET_HashCode *hash,
55 const struct GNUNET_CRYPTO_SymmetricSessionKey *key); 102 const struct GNUNET_CRYPTO_SymmetricSessionKey *key);
56 103
104/**
105 * Decrypts a file inplace under a given <i>filename</i>
106 * with a selected symmetric <i>key</i> and its <i>hash</i>
107 * as parameter for the initialization vector and comparison
108 * to verify success.
109 *
110 * @param[in] filename File name
111 * @param[in] hash Hash of file
112 * @param[in] key Symmetric key
113 * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR
114 */
57int 115int
58util_decrypt_file (const char *filename, 116util_decrypt_file (const char *filename,
59 const struct GNUNET_HashCode *hash, 117 const struct GNUNET_HashCode *hash,
60 const struct GNUNET_CRYPTO_SymmetricSessionKey *key); 118 const struct GNUNET_CRYPTO_SymmetricSessionKey *key);
61 119
120/**
121 * Append the path of a <i>directory</i> and a custom
122 * subdirectory name to a composed <i>filename</i>.
123 *
124 * @param[in] directory Directory path
125 * @param[in] subdir Subdirectory name
126 * @param[out] filename Filename
127 * @return Number of bytes in filename excluding 0-termination
128 */
62int 129int
63util_get_dirname (const char *directory, 130util_get_dirname (const char *directory,
64 const char *subdir, 131 const char *subdir,
65 char **filename); 132 char **filename);
66 133
134/**
135 * Append the path of a <i>directory</i>, a custom
136 * subdirectory name and a <i>hash</i> to a composed
137 * <i>filename</i>.
138 *
139 * @param[in] directory Directory path
140 * @param[in] subdir Subdirectory name
141 * @param[in] hash Hash
142 * @param[out] filename Filename
143 * @return Number of bytes in filename excluding 0-termination
144 */
67int 145int
68util_get_filename (const char *directory, 146util_get_filename (const char *directory,
69 const char *subdir, 147 const char *subdir,
70 const struct GNUNET_HashCode *hash, 148 const struct GNUNET_HashCode *hash,
71 char **filename); 149 char **filename);
72 150
151/**
152 * Construct a composed <i>label</i> from a given context
153 * <i>type</i> and the <i>hash</i> of the contexts room.
154 *
155 * @param[in] type Chat context type
156 * @param[in] hash Hash of room
157 * @param[out] label Namestore label
158 * @return Number of bytes in label excluding 0-termination
159 */
73int 160int
74util_get_context_label (enum GNUNET_CHAT_ContextType type, 161util_get_context_label (enum GNUNET_CHAT_ContextType type,
75 const struct GNUNET_HashCode *hash, 162 const struct GNUNET_HashCode *hash,
76 char **label); 163 char **label);
77 164
78int util_lobby_name (const struct GNUNET_HashCode *hash, 165/**
79 char **name); 166 * Provide a standardized <i>name</i> for a lobby using
167 * a given <i>hash</i> of its internal room.
168 *
169 * @param[in] hash Hash of room
170 * @param[out] name Name of lobby
171 * @return Number of bytes in name excluding 0-termination
172 */
173int
174util_lobby_name (const struct GNUNET_HashCode *hash,
175 char **name);
80 176
81#endif /* GNUNET_CHAT_UTIL_H_ */ 177#endif /* GNUNET_CHAT_UTIL_H_ */
diff --git a/tests/test_gnunet_chat_handle.c b/tests/test_gnunet_chat_handle.c
index 6bc6fbf..c8a9e89 100644
--- a/tests/test_gnunet_chat_handle.c
+++ b/tests/test_gnunet_chat_handle.c
@@ -255,7 +255,7 @@ skip_search_account:
255 else 255 else
256 { 256 {
257 ck_assert_ptr_ne(dup, NULL); 257 ck_assert_ptr_ne(dup, NULL);
258 // ck_assert_str_ne(key, dup); // TODO: needs to be implemented in service! 258 ck_assert_str_ne(key, dup);
259 259
260 GNUNET_free(dup); 260 GNUNET_free(dup);
261 261
@@ -303,7 +303,7 @@ on_gnunet_chat_handle_rename_it(void *cls,
303 ck_assert_ptr_ne(name, NULL); 303 ck_assert_ptr_ne(name, NULL);
304 ck_assert_ptr_eq(GNUNET_CHAT_get_connected(handle), NULL); 304 ck_assert_ptr_eq(GNUNET_CHAT_get_connected(handle), NULL);
305 305
306 if (0 == strcmp(name, "gnunet_chat_handle_rename_A")) 306 if (0 == strcmp(name, "gnunet_chat_handle_rename_a"))
307 { 307 {
308 GNUNET_CHAT_connect(chat, account); 308 GNUNET_CHAT_connect(chat, account);
309 return GNUNET_NO; 309 return GNUNET_NO;
@@ -346,6 +346,8 @@ skip_search_account:
346 const char *name = GNUNET_CHAT_get_name(handle); 346 const char *name = GNUNET_CHAT_get_name(handle);
347 ck_assert_ptr_ne(name, NULL); 347 ck_assert_ptr_ne(name, NULL);
348 348
349 printf("login: %s\n", name);
350
349 char *dup = (char*) GNUNET_CHAT_get_user_pointer(handle); 351 char *dup = (char*) GNUNET_CHAT_get_user_pointer(handle);
350 352
351 if (!dup) 353 if (!dup)
@@ -359,10 +361,10 @@ skip_search_account:
359 361
360 ck_assert_int_eq(GNUNET_CHAT_set_name( 362 ck_assert_int_eq(GNUNET_CHAT_set_name(
361 handle, 363 handle,
362 "gnunet_chat_handle_rename_B" 364 "gnunet_chat_handle_rename_b"
363 ), GNUNET_YES); 365 ), GNUNET_YES);
364 } 366 }
365 else 367 else if (0 != strcmp(name, dup))
366 { 368 {
367 ck_assert_ptr_ne(dup, NULL); 369 ck_assert_ptr_ne(dup, NULL);
368 ck_assert_str_ne(name, dup); 370 ck_assert_str_ne(name, dup);
@@ -373,7 +375,7 @@ skip_search_account:
373 375
374 ck_assert_int_eq(GNUNET_CHAT_account_delete( 376 ck_assert_int_eq(GNUNET_CHAT_account_delete(
375 handle, 377 handle,
376 "gnunet_chat_handle_rename_B" 378 "gnunet_chat_handle_rename_b"
377 ), GNUNET_OK); 379 ), GNUNET_OK);
378 380
379 GNUNET_CHAT_stop(handle); 381 GNUNET_CHAT_stop(handle);
@@ -391,7 +393,7 @@ call_gnunet_chat_handle_rename(const struct GNUNET_CONFIGURATION_Handle *cfg)
391 ck_assert_ptr_ne(handle, NULL); 393 ck_assert_ptr_ne(handle, NULL);
392 ck_assert_int_eq(GNUNET_CHAT_account_create( 394 ck_assert_int_eq(GNUNET_CHAT_account_create(
393 handle, 395 handle,
394 "gnunet_chat_handle_rename_A" 396 "gnunet_chat_handle_rename_a"
395 ), GNUNET_OK); 397 ), GNUNET_OK);
396} 398}
397 399