summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-03-30 16:53:02 +0200
committerTheJackiMonster <thejackimonster@gmail.com>2022-03-30 16:53:02 +0200
commit2134dfccf8be89fa5e1e595d6ec65a56ac357d78 (patch)
treedc08a1c0c1d12f7c560cde5646b6b40ede19ad1e
parent1ba9b0280a52207e4ac4288f1427566f1d5667c4 (diff)
Removed application specific directory and adjusted test cases
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--include/gnunet_chat_lib.h5
-rw-r--r--src/gnunet_chat_handle.c38
-rw-r--r--src/gnunet_chat_handle.h1
-rw-r--r--src/gnunet_chat_lib.c9
-rw-r--r--tests/test_gnunet_chat_handle.c8
5 files changed, 41 insertions, 20 deletions
diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h
index cc604cd..9e3fd04 100644
--- a/include/gnunet_chat_lib.h
+++ b/include/gnunet_chat_lib.h
@@ -322,21 +322,18 @@ typedef void
uint64_t size);
/**
- * Start a chat handle with a certain configuration and a selected application
- * <i>directory</i>.
+ * Start a chat handle with a certain configuration.
*
* A custom callback for warnings and message events can be provided optionally
* together with their respective closures.
*
* @param[in] cfg Configuration
- * @param[in] directory Application directory path (optional)
* @param[in] msg_cb Callback for message events (optional)
* @param[in,out] msg_cls Closure for message events (optional)
* @return Chat handle
*/
struct GNUNET_CHAT_Handle*
GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *directory,
GNUNET_CHAT_ContextMessageCallback msg_cb,
void *msg_cls);
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
index 45f7861..d23741b 100644
--- a/src/gnunet_chat_handle.c
+++ b/src/gnunet_chat_handle.c
@@ -28,7 +28,6 @@
struct GNUNET_CHAT_Handle*
handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg,
- const char *directory,
GNUNET_CHAT_ContextMessageCallback msg_cb,
void *msg_cls)
{
@@ -44,11 +43,40 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg,
handle->internal_head = NULL;
handle->internal_tail = NULL;
- if ((directory) &&
- (GNUNET_YES == GNUNET_DISK_directory_test(directory, GNUNET_YES)))
- handle->directory = GNUNET_strdup(directory);
- else
+ handle->directory = NULL;
+
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg,
+ GNUNET_MESSENGER_SERVICE_NAME,
+ "MESSENGER_DIR",
+ &(handle->directory)))
+ {
+ if (handle->directory)
+ GNUNET_free(handle->directory);
+
+ handle->directory = NULL;
+ }
+ else if ((GNUNET_YES != GNUNET_DISK_directory_test(handle->directory, GNUNET_YES)) &&
+ (GNUNET_OK != GNUNET_DISK_directory_create(handle->directory)))
+ {
+ GNUNET_free(handle->directory);
+
handle->directory = NULL;
+ }
+
+ if (handle->directory)
+ {
+ char *chat_directory = NULL;
+ util_get_dirname(handle->directory, "chat", &chat_directory);
+
+ if ((GNUNET_YES != GNUNET_DISK_directory_test(chat_directory, GNUNET_YES)) &&
+ (GNUNET_OK != GNUNET_DISK_directory_create(chat_directory)))
+ GNUNET_free(chat_directory);
+ else
+ {
+ GNUNET_free(handle->directory);
+ handle->directory = chat_directory;
+ }
+ }
handle->msg_cb = msg_cb;
handle->msg_cls = msg_cls;
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h
index 28cfacc..5702206 100644
--- a/src/gnunet_chat_handle.h
+++ b/src/gnunet_chat_handle.h
@@ -122,7 +122,6 @@ struct GNUNET_CHAT_Handle
struct GNUNET_CHAT_Handle*
handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg,
- const char *directory,
GNUNET_CHAT_ContextMessageCallback msg_cb,
void *msg_cls);
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index 1fcc419..72db7cd 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -47,7 +47,6 @@
struct GNUNET_CHAT_Handle*
GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *directory,
GNUNET_CHAT_ContextMessageCallback msg_cb, void *msg_cls)
{
GNUNET_CHAT_VERSION_ASSERT();
@@ -56,8 +55,9 @@ GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
return NULL;
return handle_create_from_config(
- cfg, directory,
- msg_cb, msg_cls
+ cfg,
+ msg_cb,
+ msg_cls
);
}
@@ -1094,9 +1094,6 @@ GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context,
if ((!context) || (!path) || (!(context->room)))
return NULL;
- if (!(context->handle->directory))
- return NULL;
-
struct GNUNET_HashCode hash;
if (GNUNET_OK != util_hash_file(path, &hash))
return NULL;
diff --git a/tests/test_gnunet_chat_handle.c b/tests/test_gnunet_chat_handle.c
index b1854cf..efa2ba9 100644
--- a/tests/test_gnunet_chat_handle.c
+++ b/tests/test_gnunet_chat_handle.c
@@ -29,7 +29,7 @@ call_gnunet_chat_handle_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_CHAT_Handle *handle;
- handle = GNUNET_CHAT_start(cfg, "", "Init", NULL, NULL);
+ handle = GNUNET_CHAT_start(cfg, NULL, NULL);
ck_assert_ptr_ne(handle, NULL);
GNUNET_CHAT_stop(handle);
@@ -57,7 +57,7 @@ on_gnunet_chat_handle_login_msg(void *cls,
void
call_gnunet_chat_handle_login(const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- login_handle = GNUNET_CHAT_start(cfg, "", "Login", on_gnunet_chat_handle_login_msg, NULL);
+ login_handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_login_msg, NULL);
ck_assert_ptr_ne(login_handle, NULL);
}
@@ -76,7 +76,7 @@ on_gnunet_chat_handle_access_msg(void *cls,
ck_assert_ptr_eq(cls, NULL);
ck_assert_ptr_eq(context, NULL);
- const struct GNUNET_IDENTITY_PublicKey *key;
+ const char *key;
const char *name;
int result;
@@ -124,7 +124,7 @@ call_gnunet_chat_handle_access(const struct GNUNET_CONFIGURATION_Handle *cfg)
{
access_logins = 0;
- access_handle = GNUNET_CHAT_start(cfg, "", "Access", on_gnunet_chat_handle_access_msg, NULL);
+ access_handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_access_msg, NULL);
ck_assert_ptr_ne(access_handle, NULL);
}