diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2022-03-30 16:53:02 +0200 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2022-03-30 16:53:02 +0200 |
commit | 2134dfccf8be89fa5e1e595d6ec65a56ac357d78 (patch) | |
tree | dc08a1c0c1d12f7c560cde5646b6b40ede19ad1e | |
parent | 1ba9b0280a52207e4ac4288f1427566f1d5667c4 (diff) | |
download | libgnunetchat-2134dfccf8be89fa5e1e595d6ec65a56ac357d78.tar.gz libgnunetchat-2134dfccf8be89fa5e1e595d6ec65a56ac357d78.zip |
Removed application specific directory and adjusted test cases
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | include/gnunet_chat_lib.h | 5 | ||||
-rw-r--r-- | src/gnunet_chat_handle.c | 38 | ||||
-rw-r--r-- | src/gnunet_chat_handle.h | 1 | ||||
-rw-r--r-- | src/gnunet_chat_lib.c | 9 | ||||
-rw-r--r-- | tests/test_gnunet_chat_handle.c | 8 |
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 | |||
322 | uint64_t size); | 322 | uint64_t size); |
323 | 323 | ||
324 | /** | 324 | /** |
325 | * Start a chat handle with a certain configuration and a selected application | 325 | * Start a chat handle with a certain configuration. |
326 | * <i>directory</i>. | ||
327 | * | 326 | * |
328 | * A custom callback for warnings and message events can be provided optionally | 327 | * A custom callback for warnings and message events can be provided optionally |
329 | * together with their respective closures. | 328 | * together with their respective closures. |
330 | * | 329 | * |
331 | * @param[in] cfg Configuration | 330 | * @param[in] cfg Configuration |
332 | * @param[in] directory Application directory path (optional) | ||
333 | * @param[in] msg_cb Callback for message events (optional) | 331 | * @param[in] msg_cb Callback for message events (optional) |
334 | * @param[in,out] msg_cls Closure for message events (optional) | 332 | * @param[in,out] msg_cls Closure for message events (optional) |
335 | * @return Chat handle | 333 | * @return Chat handle |
336 | */ | 334 | */ |
337 | struct GNUNET_CHAT_Handle* | 335 | struct GNUNET_CHAT_Handle* |
338 | GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 336 | GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg, |
339 | const char *directory, | ||
340 | GNUNET_CHAT_ContextMessageCallback msg_cb, | 337 | GNUNET_CHAT_ContextMessageCallback msg_cb, |
341 | void *msg_cls); | 338 | void *msg_cls); |
342 | 339 | ||
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 @@ | |||
28 | 28 | ||
29 | struct GNUNET_CHAT_Handle* | 29 | struct GNUNET_CHAT_Handle* |
30 | handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, | 30 | handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, |
31 | const char *directory, | ||
32 | GNUNET_CHAT_ContextMessageCallback msg_cb, | 31 | GNUNET_CHAT_ContextMessageCallback msg_cb, |
33 | void *msg_cls) | 32 | void *msg_cls) |
34 | { | 33 | { |
@@ -44,11 +43,40 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, | |||
44 | handle->internal_head = NULL; | 43 | handle->internal_head = NULL; |
45 | handle->internal_tail = NULL; | 44 | handle->internal_tail = NULL; |
46 | 45 | ||
47 | if ((directory) && | 46 | handle->directory = NULL; |
48 | (GNUNET_YES == GNUNET_DISK_directory_test(directory, GNUNET_YES))) | 47 | |
49 | handle->directory = GNUNET_strdup(directory); | 48 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, |
50 | else | 49 | GNUNET_MESSENGER_SERVICE_NAME, |
50 | "MESSENGER_DIR", | ||
51 | &(handle->directory))) | ||
52 | { | ||
53 | if (handle->directory) | ||
54 | GNUNET_free(handle->directory); | ||
55 | |||
56 | handle->directory = NULL; | ||
57 | } | ||
58 | else if ((GNUNET_YES != GNUNET_DISK_directory_test(handle->directory, GNUNET_YES)) && | ||
59 | (GNUNET_OK != GNUNET_DISK_directory_create(handle->directory))) | ||
60 | { | ||
61 | GNUNET_free(handle->directory); | ||
62 | |||
51 | handle->directory = NULL; | 63 | handle->directory = NULL; |
64 | } | ||
65 | |||
66 | if (handle->directory) | ||
67 | { | ||
68 | char *chat_directory = NULL; | ||
69 | util_get_dirname(handle->directory, "chat", &chat_directory); | ||
70 | |||
71 | if ((GNUNET_YES != GNUNET_DISK_directory_test(chat_directory, GNUNET_YES)) && | ||
72 | (GNUNET_OK != GNUNET_DISK_directory_create(chat_directory))) | ||
73 | GNUNET_free(chat_directory); | ||
74 | else | ||
75 | { | ||
76 | GNUNET_free(handle->directory); | ||
77 | handle->directory = chat_directory; | ||
78 | } | ||
79 | } | ||
52 | 80 | ||
53 | handle->msg_cb = msg_cb; | 81 | handle->msg_cb = msg_cb; |
54 | handle->msg_cls = msg_cls; | 82 | 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 | |||
122 | 122 | ||
123 | struct GNUNET_CHAT_Handle* | 123 | struct GNUNET_CHAT_Handle* |
124 | handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, | 124 | handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, |
125 | const char *directory, | ||
126 | GNUNET_CHAT_ContextMessageCallback msg_cb, | 125 | GNUNET_CHAT_ContextMessageCallback msg_cb, |
127 | void *msg_cls); | 126 | void *msg_cls); |
128 | 127 | ||
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 @@ | |||
47 | 47 | ||
48 | struct GNUNET_CHAT_Handle* | 48 | struct GNUNET_CHAT_Handle* |
49 | GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 49 | GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg, |
50 | const char *directory, | ||
51 | GNUNET_CHAT_ContextMessageCallback msg_cb, void *msg_cls) | 50 | GNUNET_CHAT_ContextMessageCallback msg_cb, void *msg_cls) |
52 | { | 51 | { |
53 | GNUNET_CHAT_VERSION_ASSERT(); | 52 | GNUNET_CHAT_VERSION_ASSERT(); |
@@ -56,8 +55,9 @@ GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
56 | return NULL; | 55 | return NULL; |
57 | 56 | ||
58 | return handle_create_from_config( | 57 | return handle_create_from_config( |
59 | cfg, directory, | 58 | cfg, |
60 | msg_cb, msg_cls | 59 | msg_cb, |
60 | msg_cls | ||
61 | ); | 61 | ); |
62 | } | 62 | } |
63 | 63 | ||
@@ -1094,9 +1094,6 @@ GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context, | |||
1094 | if ((!context) || (!path) || (!(context->room))) | 1094 | if ((!context) || (!path) || (!(context->room))) |
1095 | return NULL; | 1095 | return NULL; |
1096 | 1096 | ||
1097 | if (!(context->handle->directory)) | ||
1098 | return NULL; | ||
1099 | |||
1100 | struct GNUNET_HashCode hash; | 1097 | struct GNUNET_HashCode hash; |
1101 | if (GNUNET_OK != util_hash_file(path, &hash)) | 1098 | if (GNUNET_OK != util_hash_file(path, &hash)) |
1102 | return NULL; | 1099 | 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) | |||
29 | { | 29 | { |
30 | struct GNUNET_CHAT_Handle *handle; | 30 | struct GNUNET_CHAT_Handle *handle; |
31 | 31 | ||
32 | handle = GNUNET_CHAT_start(cfg, "", "Init", NULL, NULL); | 32 | handle = GNUNET_CHAT_start(cfg, NULL, NULL); |
33 | ck_assert_ptr_ne(handle, NULL); | 33 | ck_assert_ptr_ne(handle, NULL); |
34 | 34 | ||
35 | GNUNET_CHAT_stop(handle); | 35 | GNUNET_CHAT_stop(handle); |
@@ -57,7 +57,7 @@ on_gnunet_chat_handle_login_msg(void *cls, | |||
57 | void | 57 | void |
58 | call_gnunet_chat_handle_login(const struct GNUNET_CONFIGURATION_Handle *cfg) | 58 | call_gnunet_chat_handle_login(const struct GNUNET_CONFIGURATION_Handle *cfg) |
59 | { | 59 | { |
60 | login_handle = GNUNET_CHAT_start(cfg, "", "Login", on_gnunet_chat_handle_login_msg, NULL); | 60 | login_handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_login_msg, NULL); |
61 | ck_assert_ptr_ne(login_handle, NULL); | 61 | ck_assert_ptr_ne(login_handle, NULL); |
62 | } | 62 | } |
63 | 63 | ||
@@ -76,7 +76,7 @@ on_gnunet_chat_handle_access_msg(void *cls, | |||
76 | ck_assert_ptr_eq(cls, NULL); | 76 | ck_assert_ptr_eq(cls, NULL); |
77 | ck_assert_ptr_eq(context, NULL); | 77 | ck_assert_ptr_eq(context, NULL); |
78 | 78 | ||
79 | const struct GNUNET_IDENTITY_PublicKey *key; | 79 | const char *key; |
80 | const char *name; | 80 | const char *name; |
81 | int result; | 81 | int result; |
82 | 82 | ||
@@ -124,7 +124,7 @@ call_gnunet_chat_handle_access(const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
124 | { | 124 | { |
125 | access_logins = 0; | 125 | access_logins = 0; |
126 | 126 | ||
127 | access_handle = GNUNET_CHAT_start(cfg, "", "Access", on_gnunet_chat_handle_access_msg, NULL); | 127 | access_handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_access_msg, NULL); |
128 | ck_assert_ptr_ne(access_handle, NULL); | 128 | ck_assert_ptr_ne(access_handle, NULL); |
129 | } | 129 | } |
130 | 130 | ||