aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-02-17 13:38:19 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-02-17 13:38:19 +0100
commit2d86ca47e55589718307872999b8cb362b818ba0 (patch)
treeff84ff383db2c48c9b86a0a31543313d10d6ac28
parent349ec7b8d1452f3361b962ec8b845fc85acf052e (diff)
downloadlibgnunetchat-2d86ca47e55589718307872999b8cb362b818ba0.tar.gz
libgnunetchat-2d86ca47e55589718307872999b8cb362b818ba0.zip
Implemented account specific directories for configurations and files
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/gnunet_chat_account.c28
-rw-r--r--src/gnunet_chat_account.h5
-rw-r--r--src/gnunet_chat_context.c8
-rw-r--r--src/gnunet_chat_group.c4
-rw-r--r--src/gnunet_chat_handle.c14
-rw-r--r--src/gnunet_chat_handle.h3
-rw-r--r--src/gnunet_chat_handle_intern.c15
-rw-r--r--src/gnunet_chat_lib.c35
8 files changed, 95 insertions, 17 deletions
diff --git a/src/gnunet_chat_account.c b/src/gnunet_chat_account.c
index 53163ae..2e93c9c 100644
--- a/src/gnunet_chat_account.c
+++ b/src/gnunet_chat_account.c
@@ -34,6 +34,7 @@ account_create_from_ego(struct GNUNET_IDENTITY_Ego *ego,
34 struct GNUNET_CHAT_Account *account = GNUNET_new(struct GNUNET_CHAT_Account); 34 struct GNUNET_CHAT_Account *account = GNUNET_new(struct GNUNET_CHAT_Account);
35 35
36 account->ego = ego; 36 account->ego = ego;
37 account->directory = NULL;
37 account->name = NULL; 38 account->name = NULL;
38 39
39 util_set_name_field(name, &(account->name)); 40 util_set_name_field(name, &(account->name));
@@ -44,6 +45,30 @@ account_create_from_ego(struct GNUNET_IDENTITY_Ego *ego,
44} 45}
45 46
46void 47void
48account_update_directory (struct GNUNET_CHAT_Account *account,
49 const char *base_directory)
50{
51 GNUNET_assert((account) && (base_directory));
52
53 if (account->directory)
54 GNUNET_free(account->directory);
55
56 struct GNUNET_IDENTITY_PublicKey key;
57 GNUNET_IDENTITY_ego_get_public_key(account->ego, &key);
58
59 char *key_string = GNUNET_IDENTITY_public_key_to_string(&key);
60
61 if (!key_string)
62 {
63 account->directory = NULL;
64 return;
65 }
66
67 util_get_dirname(base_directory, key_string, &(account->directory));
68 GNUNET_free(key_string);
69}
70
71void
47account_destroy(struct GNUNET_CHAT_Account *account) 72account_destroy(struct GNUNET_CHAT_Account *account)
48{ 73{
49 GNUNET_assert(account); 74 GNUNET_assert(account);
@@ -51,5 +76,8 @@ account_destroy(struct GNUNET_CHAT_Account *account)
51 if (account->name) 76 if (account->name)
52 GNUNET_free(account->name); 77 GNUNET_free(account->name);
53 78
79 if (account->directory)
80 GNUNET_free(account->directory);
81
54 GNUNET_free(account); 82 GNUNET_free(account);
55} 83}
diff --git a/src/gnunet_chat_account.h b/src/gnunet_chat_account.h
index a00b8a5..40d8392 100644
--- a/src/gnunet_chat_account.h
+++ b/src/gnunet_chat_account.h
@@ -32,6 +32,7 @@
32struct GNUNET_CHAT_Account 32struct GNUNET_CHAT_Account
33{ 33{
34 struct GNUNET_IDENTITY_Ego *ego; 34 struct GNUNET_IDENTITY_Ego *ego;
35 char *directory;
35 char *name; 36 char *name;
36 37
37 void *user_pointer; 38 void *user_pointer;
@@ -42,6 +43,10 @@ account_create_from_ego(struct GNUNET_IDENTITY_Ego *ego,
42 const char *name); 43 const char *name);
43 44
44void 45void
46account_update_directory (struct GNUNET_CHAT_Account *account,
47 const char *base_directory);
48
49void
45account_destroy(struct GNUNET_CHAT_Account *account); 50account_destroy(struct GNUNET_CHAT_Account *account);
46 51
47#endif /* GNUNET_CHAT_ACCOUNT_H_ */ 52#endif /* GNUNET_CHAT_ACCOUNT_H_ */
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c
index d023f10..316ffc1 100644
--- a/src/gnunet_chat_context.c
+++ b/src/gnunet_chat_context.c
@@ -169,7 +169,7 @@ context_load_config (struct GNUNET_CHAT_Context *context)
169 (context->handle) && 169 (context->handle) &&
170 (context->room)); 170 (context->room));
171 171
172 const char *directory = context->handle->directory; 172 const char *directory = handle_get_directory(context->handle);
173 173
174 if (!directory) 174 if (!directory)
175 return; 175 return;
@@ -228,7 +228,7 @@ context_save_config (const struct GNUNET_CHAT_Context *context)
228 (context->handle) && 228 (context->handle) &&
229 (context->room)); 229 (context->room));
230 230
231 const char *directory = context->handle->directory; 231 const char *directory = handle_get_directory(context->handle);
232 232
233 if (!directory) 233 if (!directory)
234 return; 234 return;
@@ -309,13 +309,13 @@ context_scan_configs (struct GNUNET_CHAT_Handle *handle)
309{ 309{
310 GNUNET_assert((handle) && (handle->messenger)); 310 GNUNET_assert((handle) && (handle->messenger));
311 311
312 const char *directory = handle->directory; 312 const char *directory = handle_get_directory(handle);
313 313
314 if (!directory) 314 if (!directory)
315 return; 315 return;
316 316
317 char* dirname; 317 char* dirname;
318 util_get_dirname(handle->directory, "chats", &dirname); 318 util_get_dirname(directory, "chats", &dirname);
319 319
320 if (GNUNET_YES != GNUNET_DISK_directory_test(dirname, GNUNET_YES)) 320 if (GNUNET_YES != GNUNET_DISK_directory_test(dirname, GNUNET_YES))
321 goto free_dirname; 321 goto free_dirname;
diff --git a/src/gnunet_chat_group.c b/src/gnunet_chat_group.c
index 979af18..7fcc98e 100644
--- a/src/gnunet_chat_group.c
+++ b/src/gnunet_chat_group.c
@@ -104,7 +104,7 @@ group_load_config (struct GNUNET_CHAT_Group *group)
104{ 104{
105 GNUNET_assert((group) && (group->handle)); 105 GNUNET_assert((group) && (group->handle));
106 106
107 const char *directory = group->handle->directory; 107 const char *directory = handle_get_directory(group->handle);
108 108
109 if ((!directory) || (!(group->context))) 109 if ((!directory) || (!(group->context)))
110 return; 110 return;
@@ -145,7 +145,7 @@ group_save_config (const struct GNUNET_CHAT_Group *group)
145{ 145{
146 GNUNET_assert((group) && (group->handle)); 146 GNUNET_assert((group) && (group->handle));
147 147
148 const char *directory = group->handle->directory; 148 const char *directory = handle_get_directory(group->handle);
149 149
150 if ((!directory) || (!(group->context))) 150 if ((!directory) || (!(group->context)))
151 return; 151 return;
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
index a8f24e7..732dfbd 100644
--- a/src/gnunet_chat_handle.c
+++ b/src/gnunet_chat_handle.c
@@ -260,6 +260,20 @@ handle_disconnect (struct GNUNET_CHAT_Handle *handle)
260 handle_update_key(handle); 260 handle_update_key(handle);
261} 261}
262 262
263const char*
264handle_get_directory (const struct GNUNET_CHAT_Handle *handle)
265{
266 GNUNET_assert(handle);
267
268 if (!(handle->directory))
269 return NULL;
270
271 if (!(handle->current))
272 return handle->directory;
273 else
274 return handle->current->directory;
275}
276
263void 277void
264handle_send_internal_message (struct GNUNET_CHAT_Handle *handle, 278handle_send_internal_message (struct GNUNET_CHAT_Handle *handle,
265 struct GNUNET_CHAT_Context *context, 279 struct GNUNET_CHAT_Context *context,
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h
index 0c0440e..6004e5d 100644
--- a/src/gnunet_chat_handle.h
+++ b/src/gnunet_chat_handle.h
@@ -106,6 +106,9 @@ handle_connect (struct GNUNET_CHAT_Handle *handle,
106void 106void
107handle_disconnect (struct GNUNET_CHAT_Handle *handle); 107handle_disconnect (struct GNUNET_CHAT_Handle *handle);
108 108
109const char*
110handle_get_directory (const struct GNUNET_CHAT_Handle *handle);
111
109void 112void
110handle_send_internal_message (struct GNUNET_CHAT_Handle *handle, 113handle_send_internal_message (struct GNUNET_CHAT_Handle *handle,
111 struct GNUNET_CHAT_Context *context, 114 struct GNUNET_CHAT_Context *context,
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
index e3f660d..f4ec2e9 100644
--- a/src/gnunet_chat_handle_intern.c
+++ b/src/gnunet_chat_handle_intern.c
@@ -207,10 +207,7 @@ on_handle_gnunet_identity(void *cls,
207 struct GNUNET_CHAT_Handle* handle = cls; 207 struct GNUNET_CHAT_Handle* handle = cls;
208 208
209 if ((!name) || (!ego)) 209 if ((!name) || (!ego))
210 { 210 goto send_refresh;
211 handle_send_internal_message(handle, NULL, GNUNET_CHAT_FLAG_REFRESH, NULL);
212 return;
213 }
214 211
215 struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head; 212 struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head;
216 213
@@ -223,13 +220,13 @@ on_handle_gnunet_identity(void *cls,
223 (0 == strcmp(accounts->account->name, name))) 220 (0 == strcmp(accounts->account->name, name)))
224 { 221 {
225 accounts->account->ego = ego; 222 accounts->account->ego = ego;
226 return; 223 goto send_refresh;
227 } 224 }
228 225
229 if (ego == accounts->account->ego) 226 if (ego == accounts->account->ego)
230 { 227 {
231 util_set_name_field(name, &(accounts->account->name)); 228 util_set_name_field(name, &(accounts->account->name));
232 return; 229 goto send_refresh;
233 } 230 }
234 231
235skip_account: 232skip_account:
@@ -239,11 +236,17 @@ skip_account:
239 accounts = GNUNET_new(struct GNUNET_CHAT_InternalAccounts); 236 accounts = GNUNET_new(struct GNUNET_CHAT_InternalAccounts);
240 accounts->account = account_create_from_ego(ego, name); 237 accounts->account = account_create_from_ego(ego, name);
241 238
239 if (handle->directory)
240 account_update_directory(accounts->account, handle->directory);
241
242 GNUNET_CONTAINER_DLL_insert_tail( 242 GNUNET_CONTAINER_DLL_insert_tail(
243 handle->accounts_head, 243 handle->accounts_head,
244 handle->accounts_tail, 244 handle->accounts_tail,
245 accounts 245 accounts
246 ); 246 );
247
248send_refresh:
249 handle_send_internal_message(handle, NULL, GNUNET_CHAT_FLAG_REFRESH, NULL);
247} 250}
248 251
249int 252int
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index b273441..f4e8d42 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -759,6 +759,11 @@ GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context,
759 if (GNUNET_OK != util_hash_file(path, &hash)) 759 if (GNUNET_OK != util_hash_file(path, &hash))
760 return NULL; 760 return NULL;
761 761
762 const char *directory = handle_get_directory(context->handle);
763
764 if (!directory)
765 return NULL;
766
762 struct GNUNET_CHAT_File *file = GNUNET_CONTAINER_multihashmap_get( 767 struct GNUNET_CHAT_File *file = GNUNET_CONTAINER_multihashmap_get(
763 context->handle->files, 768 context->handle->files,
764 &hash 769 &hash
@@ -766,7 +771,7 @@ GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context,
766 771
767 char *filename; 772 char *filename;
768 util_get_filename ( 773 util_get_filename (
769 context->handle->directory, "files", &hash, &filename 774 directory, "files", &hash, &filename
770 ); 775 );
771 776
772 if (file) 777 if (file)
@@ -1128,9 +1133,14 @@ GNUNET_CHAT_file_get_local_size (const struct GNUNET_CHAT_File *file)
1128 if (!file) 1133 if (!file)
1129 return 0; 1134 return 0;
1130 1135
1136 const char *directory = handle_get_directory(file->handle);
1137
1138 if (!directory)
1139 return 0;
1140
1131 char *filename; 1141 char *filename;
1132 util_get_filename ( 1142 util_get_filename (
1133 file->handle->directory, "files", &(file->hash), &filename 1143 directory, "files", &(file->hash), &filename
1134 ); 1144 );
1135 1145
1136 uint64_t size; 1146 uint64_t size;
@@ -1161,9 +1171,14 @@ GNUNET_CHAT_file_open_preview (struct GNUNET_CHAT_File *file)
1161 if (file->preview) 1171 if (file->preview)
1162 return file->preview; 1172 return file->preview;
1163 1173
1174 const char *directory = handle_get_directory(file->handle);
1175
1176 if (!directory)
1177 return NULL;
1178
1164 char *filename; 1179 char *filename;
1165 util_get_filename ( 1180 util_get_filename (
1166 file->handle->directory, "files", &(file->hash), &filename 1181 directory, "files", &(file->hash), &filename
1167 ); 1182 );
1168 1183
1169 if (GNUNET_YES != GNUNET_DISK_file_test(filename)) 1184 if (GNUNET_YES != GNUNET_DISK_file_test(filename))
@@ -1251,11 +1266,16 @@ GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file,
1251 return GNUNET_OK; 1266 return GNUNET_OK;
1252 } 1267 }
1253 1268
1269 const char *directory = handle_get_directory(file->handle);
1270
1271 if (!directory)
1272 return GNUNET_SYSERR;
1273
1254 const uint64_t size = GNUNET_FS_uri_chk_get_file_size(file->uri); 1274 const uint64_t size = GNUNET_FS_uri_chk_get_file_size(file->uri);
1255 1275
1256 char *filename; 1276 char *filename;
1257 util_get_filename ( 1277 util_get_filename (
1258 file->handle->directory, "files", &(file->hash), &filename 1278 directory, "files", &(file->hash), &filename
1259 ); 1279 );
1260 1280
1261 uint64_t offset; 1281 uint64_t offset;
@@ -1362,9 +1382,14 @@ GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file,
1362 if (file->unindex) 1382 if (file->unindex)
1363 return GNUNET_OK; 1383 return GNUNET_OK;
1364 1384
1385 const char *directory = handle_get_directory(file->handle);
1386
1387 if (!directory)
1388 return GNUNET_SYSERR;
1389
1365 char *filename; 1390 char *filename;
1366 util_get_filename ( 1391 util_get_filename (
1367 file->handle->directory, "files", &(file->hash), &filename 1392 directory, "files", &(file->hash), &filename
1368 ); 1393 );
1369 1394
1370 file->unindex = GNUNET_FS_unindex_start( 1395 file->unindex = GNUNET_FS_unindex_start(