commit b6a01c094dd3053b106afe1e680d1141ff3ecd43
parent bb53d7eccadc872fc580c05953c44772e7563f3a
Author: Jacki <jacki@thejackimonster.de>
Date: Mon, 29 Apr 2024 18:22:03 +0200
Delete files of account on account deletion, cleanup test files
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
4 files changed, 75 insertions(+), 37 deletions(-)
diff --git a/src/gnunet_chat_account.c b/src/gnunet_chat_account.c
@@ -31,7 +31,7 @@
#include <gnunet/gnunet_messenger_service.h>
struct GNUNET_CHAT_Account*
-account_create(const char *name)
+account_create (const char *name)
{
GNUNET_assert(name);
@@ -49,8 +49,8 @@ account_create(const char *name)
}
struct GNUNET_CHAT_Account*
-account_create_from_ego(struct GNUNET_IDENTITY_Ego *ego,
- const char *name)
+account_create_from_ego (struct GNUNET_IDENTITY_Ego *ego,
+ const char *name)
{
GNUNET_assert((ego) && (name));
@@ -105,9 +105,9 @@ account_get_key (const struct GNUNET_CHAT_Account *account)
}
void
-account_update_ego(struct GNUNET_CHAT_Account *account,
- struct GNUNET_CHAT_Handle *handle,
- struct GNUNET_IDENTITY_Ego *ego)
+account_update_ego (struct GNUNET_CHAT_Account *account,
+ struct GNUNET_CHAT_Handle *handle,
+ struct GNUNET_IDENTITY_Ego *ego)
{
GNUNET_assert((account) && (handle) && (ego) && (account->ego != ego));
@@ -142,7 +142,26 @@ account_update_ego(struct GNUNET_CHAT_Account *account,
}
void
-account_destroy(struct GNUNET_CHAT_Account *account)
+account_delete (struct GNUNET_CHAT_Account *account)
+{
+ GNUNET_assert(account);
+
+ if (!(account->directory))
+ return;
+
+ if (GNUNET_YES != GNUNET_DISK_directory_test(account->directory,
+ GNUNET_NO))
+ return;
+
+ if (GNUNET_OK != GNUNET_DISK_directory_remove(account->directory))
+ return;
+
+ GNUNET_free(account->directory);
+ account->directory = NULL;
+}
+
+void
+account_destroy (struct GNUNET_CHAT_Account *account)
{
GNUNET_assert(account);
diff --git a/src/gnunet_chat_account.h b/src/gnunet_chat_account.h
@@ -47,7 +47,7 @@ struct GNUNET_CHAT_Account
* @return New chat account
*/
struct GNUNET_CHAT_Account*
-account_create(const char *name);
+account_create (const char *name);
/**
* Creates a chat account using a given <i>ego</i> and
@@ -58,8 +58,8 @@ account_create(const char *name);
* @return New chat account
*/
struct GNUNET_CHAT_Account*
-account_create_from_ego(struct GNUNET_IDENTITY_Ego *ego,
- const char *name);
+account_create_from_ego (struct GNUNET_IDENTITY_Ego *ego,
+ const char *name);
/**
* Updates the stored directory path by a chat <i>account</i>
@@ -92,9 +92,18 @@ account_get_key (const struct GNUNET_CHAT_Account *account);
* @param[in] ego EGO
*/
void
-account_update_ego(struct GNUNET_CHAT_Account *account,
- struct GNUNET_CHAT_Handle *handle,
- struct GNUNET_IDENTITY_Ego *ego);
+account_update_ego (struct GNUNET_CHAT_Account *account,
+ struct GNUNET_CHAT_Handle *handle,
+ struct GNUNET_IDENTITY_Ego *ego);
+
+/**
+ * Deletes all local files and data remaining a given
+ * chat <i>account</i>.
+ *
+ * @param[in,out] account Chat account
+ */
+void
+account_delete (struct GNUNET_CHAT_Account *account);
/**
* Destroys a chat <i>account</i> and frees its memory.
@@ -102,6 +111,6 @@ account_update_ego(struct GNUNET_CHAT_Account *account,
* @param[in,out] account Chat account
*/
void
-account_destroy(struct GNUNET_CHAT_Account *account);
+account_destroy (struct GNUNET_CHAT_Account *account);
#endif /* GNUNET_CHAT_ACCOUNT_H_ */
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
@@ -436,6 +436,7 @@ cb_account_deletion (void *cls,
GNUNET_ErrorCode_get_hint(ec)
);
else
+ {
handle_send_internal_message(
accounts->handle,
accounts->account,
@@ -444,6 +445,9 @@ cb_account_deletion (void *cls,
NULL
);
+ account_delete(accounts->account);
+ }
+
account_destroy(accounts->account);
internal_accounts_destroy(accounts);
}
diff --git a/tests/test_gnunet_chat_file.c b/tests/test_gnunet_chat_file.c
@@ -34,14 +34,14 @@ on_gnunet_chat_file_send_it(void *cls,
{
struct GNUNET_CHAT_Handle *chat = (struct GNUNET_CHAT_Handle*) cls;
- ck_assert_ptr_ne(chat, NULL);
+ ck_assert_ptr_nonnull(chat);
ck_assert_ptr_eq(handle, chat);
- ck_assert_ptr_ne(account, NULL);
+ ck_assert_ptr_nonnull(account);
const char *name = GNUNET_CHAT_account_get_name(account);
- ck_assert_ptr_ne(name, NULL);
- ck_assert_ptr_eq(GNUNET_CHAT_get_connected(handle), NULL);
+ ck_assert_ptr_nonnull(name);
+ ck_assert_ptr_null(GNUNET_CHAT_get_connected(handle));
if (0 == strcmp(name, "gnunet_chat_file_send"))
{
@@ -60,8 +60,8 @@ on_gnunet_chat_file_send_upload(void *cls,
{
struct GNUNET_CHAT_Handle *handle = (struct GNUNET_CHAT_Handle*) cls;
- ck_assert_ptr_ne(handle, NULL);
- ck_assert_ptr_ne(file, NULL);
+ ck_assert_ptr_nonnull(handle);
+ ck_assert_ptr_nonnull(file);
ck_assert_uint_le(completed, size);
uint64_t check_size = GNUNET_CHAT_file_get_size(file);
@@ -82,8 +82,8 @@ on_gnunet_chat_file_send_unindex(void *cls,
{
struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) cls;
- ck_assert_ptr_ne(context, NULL);
- ck_assert_ptr_ne(file, NULL);
+ ck_assert_ptr_nonnull(context);
+ ck_assert_ptr_nonnull(file);
ck_assert_uint_le(completed, size);
if (completed > size)
@@ -99,12 +99,14 @@ on_gnunet_chat_file_send_msg(void *cls,
struct GNUNET_CHAT_Context *context,
const struct GNUNET_CHAT_Message *message)
{
+ static char *filename = NULL;
+
struct GNUNET_CHAT_Handle *handle = *(
(struct GNUNET_CHAT_Handle**) cls
);
- ck_assert_ptr_ne(handle, NULL);
- ck_assert_ptr_ne(message, NULL);
+ ck_assert_ptr_nonnull(handle);
+ ck_assert_ptr_nonnull(message);
enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message);
struct GNUNET_CHAT_File *file;
@@ -117,7 +119,7 @@ on_gnunet_chat_file_send_msg(void *cls,
goto skip_search_account;
ck_assert(kind == GNUNET_CHAT_KIND_REFRESH);
- ck_assert_ptr_eq(context, NULL);
+ ck_assert_ptr_null(context);
ck_assert_int_ne(GNUNET_CHAT_iterate_accounts(
handle,
@@ -134,24 +136,25 @@ skip_search_account:
goto skip_file_upload;
ck_assert(kind == GNUNET_CHAT_KIND_LOGIN);
- ck_assert_ptr_eq(context, NULL);
+ ck_assert_ptr_null(context);
struct GNUNET_CHAT_Group *group = GNUNET_CHAT_group_create(
handle,
"gnunet_chat_file_send_group"
);
- ck_assert_ptr_ne(group, NULL);
+ ck_assert_ptr_nonnull(group);
struct GNUNET_CHAT_Context *group_context = GNUNET_CHAT_group_get_context(
group
);
- ck_assert_ptr_ne(group_context, NULL);
+ ck_assert_ptr_nonnull(group_context);
+ ck_assert_ptr_null(filename);
- char *filename = GNUNET_DISK_mktemp("gnunet_chat_file_send_name");
+ filename = GNUNET_DISK_mktemp("gnunet_chat_file_send_name");
- ck_assert_ptr_ne(filename, NULL);
+ ck_assert_ptr_nonnull(filename);
file = GNUNET_CHAT_context_send_file(
group_context,
@@ -160,20 +163,18 @@ skip_search_account:
handle
);
- GNUNET_free(filename);
-
- ck_assert_ptr_ne(file, NULL);
+ ck_assert_ptr_nonnull(file);
skip_file_upload:
if (GNUNET_CHAT_KIND_FILE != kind)
return GNUNET_YES;
ck_assert(kind == GNUNET_CHAT_KIND_FILE);
- ck_assert_ptr_ne(context, NULL);
+ ck_assert_ptr_nonnull(context);
file = GNUNET_CHAT_message_get_file(message);
- ck_assert_ptr_ne(file, NULL);
+ ck_assert_ptr_nonnull(file);
ck_assert_int_eq(GNUNET_CHAT_file_unindex(
file,
@@ -185,7 +186,12 @@ skip_file_upload:
exit_file_test:
ck_assert(kind == GNUNET_CHAT_KIND_TEXT);
- ck_assert_ptr_ne(context, NULL);
+ ck_assert_ptr_nonnull(context);
+ ck_assert_ptr_nonnull(filename);
+
+ remove(filename);
+ GNUNET_free(filename);
+ filename = NULL;
const char* text = GNUNET_CHAT_message_get_text(message);
@@ -205,7 +211,7 @@ call_gnunet_chat_file_send(const struct GNUNET_CONFIGURATION_Handle *cfg)
static struct GNUNET_CHAT_Handle *handle = NULL;
handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_file_send_msg, &handle);
- ck_assert_ptr_ne(handle, NULL);
+ ck_assert_ptr_nonnull(handle);
ck_assert_int_eq(GNUNET_CHAT_account_create(
handle,
"gnunet_chat_file_send"