commit 848297dd441fd443ba537c13296c6adb92d6487f
parent fda46ecbdd01b652f5d7efe12945f2131ea001d6
Author: Jacki <jacki@thejackimonster.de>
Date: Sat, 5 Oct 2024 22:20:57 +0200
Merge file directories for different accounts into one
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
5 files changed, 35 insertions(+), 78 deletions(-)
diff --git a/src/gnunet_chat_account.c b/src/gnunet_chat_account.c
@@ -40,7 +40,6 @@ account_create (const char *name)
account->ego = NULL;
account->created = GNUNET_NO;
- account->directory = NULL;
account->name = NULL;
util_set_name_field(name, &(account->name));
@@ -64,36 +63,6 @@ account_create_from_ego (struct GNUNET_IDENTITY_Ego *ego,
return account;
}
-void
-account_update_directory (struct GNUNET_CHAT_Account *account,
- const char *base_directory)
-{
- GNUNET_assert((account) && (base_directory));
-
- if (account->directory)
- GNUNET_free(account->directory);
-
- if (!(account->ego))
- {
- account->directory = NULL;
- return;
- }
-
- struct GNUNET_CRYPTO_PublicKey key;
- GNUNET_IDENTITY_ego_get_public_key(account->ego, &key);
-
- char *key_string = GNUNET_CRYPTO_public_key_to_string(&key);
-
- if (!key_string)
- {
- account->directory = NULL;
- return;
- }
-
- util_get_dirname(base_directory, key_string, &(account->directory));
- GNUNET_free(key_string);
-}
-
const struct GNUNET_CRYPTO_PrivateKey*
account_get_key (const struct GNUNET_CHAT_Account *account)
{
@@ -107,6 +76,14 @@ account_get_key (const struct GNUNET_CHAT_Account *account)
);
}
+const char*
+account_get_name (const struct GNUNET_CHAT_Account *account)
+{
+ GNUNET_assert(account);
+
+ return account->name;
+}
+
void
account_update_ego (struct GNUNET_CHAT_Account *account,
struct GNUNET_CHAT_Handle *handle,
@@ -125,9 +102,6 @@ account_update_ego (struct GNUNET_CHAT_Account *account,
if (!(account->ego))
return;
- if (handle->directory)
- account_update_directory(account, handle->directory);
-
if ((handle->current == account) && (handle->messenger))
{
GNUNET_MESSENGER_set_key(
@@ -153,18 +127,7 @@ 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;
+ // TODO: clear namestore entries
}
void
@@ -175,8 +138,5 @@ account_destroy (struct GNUNET_CHAT_Account *account)
if (account->name)
GNUNET_free(account->name);
- if (account->directory)
- GNUNET_free(account->directory);
-
GNUNET_free(account);
}
diff --git a/src/gnunet_chat_account.h b/src/gnunet_chat_account.h
@@ -36,7 +36,6 @@ struct GNUNET_CHAT_Account
struct GNUNET_IDENTITY_Ego *ego;
enum GNUNET_GenericReturnValue created;
- char *directory;
char *name;
void *user_pointer;
@@ -64,17 +63,6 @@ account_create_from_ego (struct GNUNET_IDENTITY_Ego *ego,
const char *name);
/**
- * Updates the stored directory path by a chat <i>account</i>
- * using its current ego and key information.
- *
- * @param[in,out] account Chat account
- * @param[in] base_directory The base directory for the accounts
- */
-void
-account_update_directory (struct GNUNET_CHAT_Account *account,
- const char *base_directory);
-
-/**
* Returns the private key from a given chat
* <i>account</i>.
*
@@ -85,6 +73,15 @@ const struct GNUNET_CRYPTO_PrivateKey*
account_get_key (const struct GNUNET_CHAT_Account *account);
/**
+ * Returns the name from a given chat <i>account</i>.
+ *
+ * @param[in] account Chat account
+ * @return Name or NULL
+ */
+const char*
+account_get_name (const struct GNUNET_CHAT_Account *account);
+
+/**
* Updates the key from a given chat <i>account</i> using
* the chat <i>handle</i> and a specific <i>ego</i> matching
* the accounts name.
@@ -99,8 +96,7 @@ account_update_ego (struct GNUNET_CHAT_Account *account,
struct GNUNET_IDENTITY_Ego *ego);
/**
- * Deletes all local files and data remaining a given
- * chat <i>account</i>.
+ * Deletes all data remaining a given chat <i>account</i>.
*
* @param[in,out] account Chat account
*/
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
@@ -24,6 +24,7 @@
#include "gnunet_chat_handle.h"
+#include "gnunet_chat_account.h"
#include "gnunet_chat_handle_intern.c"
#include "gnunet_chat_message.h"
#include <gnunet/gnunet_arm_service.h>
@@ -349,8 +350,10 @@ handle_connect (struct GNUNET_CHAT_Handle *handle,
const struct GNUNET_CRYPTO_PrivateKey *key;
key = account_get_key(account);
+ const char *name = account_get_name(account);
+
handle->messenger = GNUNET_MESSENGER_connect(
- handle->cfg, account->name, key,
+ handle->cfg, name, key,
on_handle_message,
handle
);
@@ -502,8 +505,11 @@ find_accounts_by_name (struct GNUNET_CHAT_Handle *handle,
if (!(accounts->account))
goto skip_account;
- if ((accounts->account->name) &&
- (0 == strcmp(accounts->account->name, name)))
+ const char *account_name = account_get_name(
+ accounts->account
+ );
+
+ if ((account_name) && (0 == strcmp(account_name, name)))
break;
skip_account:
@@ -706,13 +712,7 @@ handle_get_directory (const struct GNUNET_CHAT_Handle *handle)
{
GNUNET_assert(handle);
- if (!(handle->directory))
- return NULL;
-
- if (!(handle->current))
- return handle->directory;
- else
- return handle->current->directory;
+ return handle->directory;
}
char*
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
@@ -371,9 +371,6 @@ skip_account:
account_create_from_ego(ego, name)
);
- if (handle->directory)
- account_update_directory(accounts->account, handle->directory);
-
send_refresh:
if (handle->refresh)
return;
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -177,7 +177,11 @@ GNUNET_CHAT_find_account (const struct GNUNET_CHAT_Handle *handle,
if ((!(accounts->account)) || (accounts->op))
goto skip_account;
- if (0 == strcmp(accounts->account->name, name))
+ const char *account_name = account_get_name(
+ accounts->account
+ );
+
+ if (0 == strcmp(account_name, name))
return accounts->account;
skip_account:
@@ -947,7 +951,7 @@ GNUNET_CHAT_account_get_name (const struct GNUNET_CHAT_Account *account)
if (!account)
return NULL;
- return account->name;
+ return account_get_name(account);
}