diff options
author | Jacki <jacki@thejackimonster.de> | 2024-01-03 01:06:56 +0100 |
---|---|---|
committer | Jacki <jacki@thejackimonster.de> | 2024-01-03 01:06:56 +0100 |
commit | 828af2a9a5c39996b791bfb9af48cdd1bedf509f (patch) | |
tree | c3fe55757e8f0a034dc53a984cb752c4a06baf55 | |
parent | ad9931275357614ed810d6851c81d4782797e59b (diff) | |
download | libgnunetchat-828af2a9a5c39996b791bfb9af48cdd1bedf509f.tar.gz libgnunetchat-828af2a9a5c39996b791bfb9af48cdd1bedf509f.zip |
Implement client-side blocking of contacts
Signed-off-by: Jacki <jacki@thejackimonster.de>
-rw-r--r-- | include/gnunet/gnunet_chat_lib.h | 72 | ||||
-rw-r--r-- | src/gnunet_chat_contact.c | 5 | ||||
-rw-r--r-- | src/gnunet_chat_contact.h | 6 | ||||
-rw-r--r-- | src/gnunet_chat_handle_intern.c | 33 | ||||
-rw-r--r-- | src/gnunet_chat_lib.c | 74 |
5 files changed, 129 insertions, 61 deletions
diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h index b8c44bf..9275988 100644 --- a/include/gnunet/gnunet_chat_lib.h +++ b/include/gnunet/gnunet_chat_lib.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2021--2023 GNUnet e.V. | 3 | Copyright (C) 2021--2024 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -34,6 +34,7 @@ | |||
34 | */ | 34 | */ |
35 | /**@{*/ | 35 | /**@{*/ |
36 | 36 | ||
37 | #include <gnunet/gnunet_common.h> | ||
37 | #include <gnunet/gnunet_util_lib.h> | 38 | #include <gnunet/gnunet_util_lib.h> |
38 | 39 | ||
39 | /** | 40 | /** |
@@ -354,7 +355,7 @@ GNUNET_CHAT_stop (struct GNUNET_CHAT_Handle *handle); | |||
354 | * @param[in] name Account name | 355 | * @param[in] name Account name |
355 | * @return #GNUNET_OK on success, #GNUNET_NO on failure and otherwise #GNUNET_SYSERR | 356 | * @return #GNUNET_OK on success, #GNUNET_NO on failure and otherwise #GNUNET_SYSERR |
356 | */ | 357 | */ |
357 | int | 358 | enum GNUNET_GenericReturnValue |
358 | GNUNET_CHAT_account_create (struct GNUNET_CHAT_Handle *handle, | 359 | GNUNET_CHAT_account_create (struct GNUNET_CHAT_Handle *handle, |
359 | const char* name); | 360 | const char* name); |
360 | 361 | ||
@@ -366,7 +367,7 @@ GNUNET_CHAT_account_create (struct GNUNET_CHAT_Handle *handle, | |||
366 | * @param[in] name Account name | 367 | * @param[in] name Account name |
367 | * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR | 368 | * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR |
368 | */ | 369 | */ |
369 | int | 370 | enum GNUNET_GenericReturnValue |
370 | GNUNET_CHAT_account_delete(struct GNUNET_CHAT_Handle *handle, | 371 | GNUNET_CHAT_account_delete(struct GNUNET_CHAT_Handle *handle, |
371 | const char* name); | 372 | const char* name); |
372 | 373 | ||
@@ -421,7 +422,7 @@ GNUNET_CHAT_get_connected (const struct GNUNET_CHAT_Handle *handle); | |||
421 | * @param[in,out] handle Chat handle | 422 | * @param[in,out] handle Chat handle |
422 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 423 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
423 | */ | 424 | */ |
424 | int | 425 | enum GNUNET_GenericReturnValue |
425 | GNUNET_CHAT_update (struct GNUNET_CHAT_Handle *handle); | 426 | GNUNET_CHAT_update (struct GNUNET_CHAT_Handle *handle); |
426 | 427 | ||
427 | /** | 428 | /** |
@@ -431,7 +432,7 @@ GNUNET_CHAT_update (struct GNUNET_CHAT_Handle *handle); | |||
431 | * @param[in] name New name or NULL | 432 | * @param[in] name New name or NULL |
432 | * @return #GNUNET_YES on success, #GNUNET_NO on failure and #GNUNET_SYSERR if <i>handle</i> is NULL | 433 | * @return #GNUNET_YES on success, #GNUNET_NO on failure and #GNUNET_SYSERR if <i>handle</i> is NULL |
433 | */ | 434 | */ |
434 | int | 435 | enum GNUNET_GenericReturnValue |
435 | GNUNET_CHAT_set_name (struct GNUNET_CHAT_Handle *handle, | 436 | GNUNET_CHAT_set_name (struct GNUNET_CHAT_Handle *handle, |
436 | const char *name); | 437 | const char *name); |
437 | 438 | ||
@@ -620,7 +621,7 @@ GNUNET_CHAT_iterate_groups (struct GNUNET_CHAT_Handle *handle, | |||
620 | * @param[in,out] contact Cntact | 621 | * @param[in,out] contact Cntact |
621 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 622 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
622 | */ | 623 | */ |
623 | int | 624 | enum GNUNET_GenericReturnValue |
624 | GNUNET_CHAT_contact_delete (struct GNUNET_CHAT_Contact *contact); | 625 | GNUNET_CHAT_contact_delete (struct GNUNET_CHAT_Contact *contact); |
625 | 626 | ||
626 | /** | 627 | /** |
@@ -689,20 +690,41 @@ GNUNET_CHAT_contact_get_user_pointer (const struct GNUNET_CHAT_Contact *contact) | |||
689 | * it has sent messages with. | 690 | * it has sent messages with. |
690 | * | 691 | * |
691 | * @param[in] contact Contact | 692 | * @param[in] contact Contact |
692 | * @return GNUNET_YES if the contact is owned, otherwise GNUNET_NO | 693 | * @return #GNUNET_YES if the contact is owned, otherwise# GNUNET_NO |
693 | * and GNUNET_SYSERR on failure | 694 | * and #GNUNET_SYSERR on failure |
694 | */ | 695 | */ |
695 | int | 696 | enum GNUNET_GenericReturnValue |
696 | GNUNET_CHAT_contact_is_owned (const struct GNUNET_CHAT_Contact *contact); | 697 | GNUNET_CHAT_contact_is_owned (const struct GNUNET_CHAT_Contact *contact); |
697 | 698 | ||
698 | /** | 699 | /** |
700 | * Blocks or unblocks a given <i>contact</i> by the current account. | ||
701 | * | ||
702 | * @param[in,out] contact Contact | ||
703 | * @param[in] blocked #GNUNET_YES to block, #GNUNET_NO to unblock | ||
704 | */ | ||
705 | void | ||
706 | GNUNET_CHAT_contact_set_blocked (struct GNUNET_CHAT_Contact *contact, | ||
707 | enum GNUNET_GenericReturnValue blocked); | ||
708 | |||
709 | /** | ||
710 | * Returns if a given <i>contact</i> is blocked by the current account and | ||
711 | * whether messages of it should be filtered. | ||
712 | * | ||
713 | * @param[in] contact Contact | ||
714 | * @return #GNUNET_YES if the contact is blocked, #GNUNET_SYSERR on failure and | ||
715 | * #GNUNET_NO otherwise | ||
716 | */ | ||
717 | enum GNUNET_GenericReturnValue | ||
718 | GNUNET_CHAT_contact_is_blocked (const struct GNUNET_CHAT_Contact *contact); | ||
719 | |||
720 | /** | ||
699 | * Leaves a specific <i>group</i> chat and frees its memory if it is not shared | 721 | * Leaves a specific <i>group</i> chat and frees its memory if it is not shared |
700 | * with other groups or contacts. | 722 | * with other groups or contacts. |
701 | * | 723 | * |
702 | * @param[in,out] group Group | 724 | * @param[in,out] group Group |
703 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 725 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
704 | */ | 726 | */ |
705 | int | 727 | enum GNUNET_GenericReturnValue |
706 | GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group); | 728 | GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group); |
707 | 729 | ||
708 | /** | 730 | /** |
@@ -813,7 +835,7 @@ GNUNET_CHAT_group_get_context (struct GNUNET_CHAT_Group *group); | |||
813 | * @return #GNUNET_OK if usable, #GNUNET_NO if the context has been requested, | 835 | * @return #GNUNET_OK if usable, #GNUNET_NO if the context has been requested, |
814 | * #GNUNET_SYSERR otherwise. | 836 | * #GNUNET_SYSERR otherwise. |
815 | */ | 837 | */ |
816 | int | 838 | enum GNUNET_GenericReturnValue |
817 | GNUNET_CHAT_context_get_status (const struct GNUNET_CHAT_Context *context); | 839 | GNUNET_CHAT_context_get_status (const struct GNUNET_CHAT_Context *context); |
818 | 840 | ||
819 | /** | 841 | /** |
@@ -873,7 +895,7 @@ GNUNET_CHAT_context_get_user_pointer (const struct GNUNET_CHAT_Context *context) | |||
873 | * @param[in] text Text | 895 | * @param[in] text Text |
874 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 896 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
875 | */ | 897 | */ |
876 | int | 898 | enum GNUNET_GenericReturnValue |
877 | GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context, | 899 | GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context, |
878 | const char *text); | 900 | const char *text); |
879 | 901 | ||
@@ -885,7 +907,7 @@ GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context, | |||
885 | * @param[in] message Message (optional) | 907 | * @param[in] message Message (optional) |
886 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 908 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
887 | */ | 909 | */ |
888 | int | 910 | enum GNUNET_GenericReturnValue |
889 | GNUNET_CHAT_context_send_read_receipt (struct GNUNET_CHAT_Context *context, | 911 | GNUNET_CHAT_context_send_read_receipt (struct GNUNET_CHAT_Context *context, |
890 | const struct GNUNET_CHAT_Message *message); | 912 | const struct GNUNET_CHAT_Message *message); |
891 | 913 | ||
@@ -914,7 +936,7 @@ GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context, | |||
914 | * @param[in] file File handle | 936 | * @param[in] file File handle |
915 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 937 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
916 | */ | 938 | */ |
917 | int | 939 | enum GNUNET_GenericReturnValue |
918 | GNUNET_CHAT_context_share_file (struct GNUNET_CHAT_Context *context, | 940 | GNUNET_CHAT_context_share_file (struct GNUNET_CHAT_Context *context, |
919 | const struct GNUNET_CHAT_File *file); | 941 | const struct GNUNET_CHAT_File *file); |
920 | 942 | ||
@@ -981,7 +1003,7 @@ GNUNET_CHAT_message_get_sender (const struct GNUNET_CHAT_Message *message); | |||
981 | * @param[in] message Message | 1003 | * @param[in] message Message |
982 | * @return #GNUNET_YES if the message was sent, otherwise #GNUNET_NO | 1004 | * @return #GNUNET_YES if the message was sent, otherwise #GNUNET_NO |
983 | */ | 1005 | */ |
984 | int | 1006 | enum GNUNET_GenericReturnValue |
985 | GNUNET_CHAT_message_is_sent (const struct GNUNET_CHAT_Message *message); | 1007 | GNUNET_CHAT_message_is_sent (const struct GNUNET_CHAT_Message *message); |
986 | 1008 | ||
987 | /** | 1009 | /** |
@@ -992,7 +1014,7 @@ GNUNET_CHAT_message_is_sent (const struct GNUNET_CHAT_Message *message); | |||
992 | * @return #GNUNET_YES if the message was privately received, | 1014 | * @return #GNUNET_YES if the message was privately received, |
993 | * otherwise #GNUNET_NO | 1015 | * otherwise #GNUNET_NO |
994 | */ | 1016 | */ |
995 | int | 1017 | enum GNUNET_GenericReturnValue |
996 | GNUNET_CHAT_message_is_private (const struct GNUNET_CHAT_Message *message); | 1018 | GNUNET_CHAT_message_is_private (const struct GNUNET_CHAT_Message *message); |
997 | 1019 | ||
998 | /** | 1020 | /** |
@@ -1059,7 +1081,7 @@ GNUNET_CHAT_message_get_target (const struct GNUNET_CHAT_Message *message); | |||
1059 | * @param[in] delay Relative delay | 1081 | * @param[in] delay Relative delay |
1060 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 1082 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
1061 | */ | 1083 | */ |
1062 | int | 1084 | enum GNUNET_GenericReturnValue |
1063 | GNUNET_CHAT_message_delete (const struct GNUNET_CHAT_Message *message, | 1085 | GNUNET_CHAT_message_delete (const struct GNUNET_CHAT_Message *message, |
1064 | struct GNUNET_TIME_Relative delay); | 1086 | struct GNUNET_TIME_Relative delay); |
1065 | 1087 | ||
@@ -1108,7 +1130,7 @@ GNUNET_CHAT_file_get_local_size (const struct GNUNET_CHAT_File *file); | |||
1108 | * @param[in] file File handle | 1130 | * @param[in] file File handle |
1109 | * @return #GNUNET_YES during active upload, #GNUNET_NO otherwise | 1131 | * @return #GNUNET_YES during active upload, #GNUNET_NO otherwise |
1110 | */ | 1132 | */ |
1111 | int | 1133 | enum GNUNET_GenericReturnValue |
1112 | GNUNET_CHAT_file_is_uploading (const struct GNUNET_CHAT_File *file); | 1134 | GNUNET_CHAT_file_is_uploading (const struct GNUNET_CHAT_File *file); |
1113 | 1135 | ||
1114 | /** | 1136 | /** |
@@ -1163,7 +1185,7 @@ GNUNET_CHAT_file_get_user_pointer (const struct GNUNET_CHAT_File *file); | |||
1163 | * @param[in] file File handle | 1185 | * @param[in] file File handle |
1164 | * @return #GNUNET_YES during active download, #GNUNET_NO otherwise | 1186 | * @return #GNUNET_YES during active download, #GNUNET_NO otherwise |
1165 | */ | 1187 | */ |
1166 | int | 1188 | enum GNUNET_GenericReturnValue |
1167 | GNUNET_CHAT_file_is_downloading (const struct GNUNET_CHAT_File *file); | 1189 | GNUNET_CHAT_file_is_downloading (const struct GNUNET_CHAT_File *file); |
1168 | 1190 | ||
1169 | /** | 1191 | /** |
@@ -1175,7 +1197,7 @@ GNUNET_CHAT_file_is_downloading (const struct GNUNET_CHAT_File *file); | |||
1175 | * @param[in,out] cls Closure for file downloading (optional) | 1197 | * @param[in,out] cls Closure for file downloading (optional) |
1176 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 1198 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
1177 | */ | 1199 | */ |
1178 | int | 1200 | enum GNUNET_GenericReturnValue |
1179 | GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, | 1201 | GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, |
1180 | GNUNET_CHAT_FileDownloadCallback callback, | 1202 | GNUNET_CHAT_FileDownloadCallback callback, |
1181 | void *cls); | 1203 | void *cls); |
@@ -1186,7 +1208,7 @@ GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, | |||
1186 | * @param[in,out] file File handle | 1208 | * @param[in,out] file File handle |
1187 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 1209 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
1188 | */ | 1210 | */ |
1189 | int | 1211 | enum GNUNET_GenericReturnValue |
1190 | GNUNET_CHAT_file_pause_download (struct GNUNET_CHAT_File *file); | 1212 | GNUNET_CHAT_file_pause_download (struct GNUNET_CHAT_File *file); |
1191 | 1213 | ||
1192 | /** | 1214 | /** |
@@ -1195,7 +1217,7 @@ GNUNET_CHAT_file_pause_download (struct GNUNET_CHAT_File *file); | |||
1195 | * @param[in,out] file File handle | 1217 | * @param[in,out] file File handle |
1196 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 1218 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
1197 | */ | 1219 | */ |
1198 | int | 1220 | enum GNUNET_GenericReturnValue |
1199 | GNUNET_CHAT_file_resume_download (struct GNUNET_CHAT_File *file); | 1221 | GNUNET_CHAT_file_resume_download (struct GNUNET_CHAT_File *file); |
1200 | 1222 | ||
1201 | /** | 1223 | /** |
@@ -1204,7 +1226,7 @@ GNUNET_CHAT_file_resume_download (struct GNUNET_CHAT_File *file); | |||
1204 | * @param[in,out] file File handle | 1226 | * @param[in,out] file File handle |
1205 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 1227 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
1206 | */ | 1228 | */ |
1207 | int | 1229 | enum GNUNET_GenericReturnValue |
1208 | GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file); | 1230 | GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file); |
1209 | 1231 | ||
1210 | /** | 1232 | /** |
@@ -1213,7 +1235,7 @@ GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file); | |||
1213 | * @param[in] file File handle | 1235 | * @param[in] file File handle |
1214 | * @return #GNUNET_YES during active unindexing, #GNUNET_NO otherwise | 1236 | * @return #GNUNET_YES during active unindexing, #GNUNET_NO otherwise |
1215 | */ | 1237 | */ |
1216 | int | 1238 | enum GNUNET_GenericReturnValue |
1217 | GNUNET_CHAT_file_is_unindexing (const struct GNUNET_CHAT_File *file); | 1239 | GNUNET_CHAT_file_is_unindexing (const struct GNUNET_CHAT_File *file); |
1218 | 1240 | ||
1219 | /** | 1241 | /** |
@@ -1225,7 +1247,7 @@ GNUNET_CHAT_file_is_unindexing (const struct GNUNET_CHAT_File *file); | |||
1225 | * @param[in,out] cls Closure for file unindexing (optional) | 1247 | * @param[in,out] cls Closure for file unindexing (optional) |
1226 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 1248 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
1227 | */ | 1249 | */ |
1228 | int | 1250 | enum GNUNET_GenericReturnValue |
1229 | GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file, | 1251 | GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file, |
1230 | GNUNET_CHAT_FileUnindexCallback callback, | 1252 | GNUNET_CHAT_FileUnindexCallback callback, |
1231 | void *cls); | 1253 | void *cls); |
diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c index 1a64689..f639fcf 100644 --- a/src/gnunet_chat_contact.c +++ b/src/gnunet_chat_contact.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2021--2023 GNUnet e.V. | 3 | Copyright (C) 2021--2024 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -44,7 +44,8 @@ contact_create_from_member (struct GNUNET_CHAT_Handle *handle, | |||
44 | contact->public_key = NULL; | 44 | contact->public_key = NULL; |
45 | contact->user_pointer = NULL; | 45 | contact->user_pointer = NULL; |
46 | 46 | ||
47 | contact->is_owned = GNUNET_NO; | 47 | contact->owned = GNUNET_NO; |
48 | contact->blocked = GNUNET_NO; | ||
48 | 49 | ||
49 | contact_update_key (contact); | 50 | contact_update_key (contact); |
50 | return contact; | 51 | return contact; |
diff --git a/src/gnunet_chat_contact.h b/src/gnunet_chat_contact.h index 41b793c..ed5dc4d 100644 --- a/src/gnunet_chat_contact.h +++ b/src/gnunet_chat_contact.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2021--2022 GNUnet e.V. | 3 | Copyright (C) 2021--2024 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -25,6 +25,7 @@ | |||
25 | #ifndef GNUNET_CHAT_CONTACT_H_ | 25 | #ifndef GNUNET_CHAT_CONTACT_H_ |
26 | #define GNUNET_CHAT_CONTACT_H_ | 26 | #define GNUNET_CHAT_CONTACT_H_ |
27 | 27 | ||
28 | #include <gnunet/gnunet_common.h> | ||
28 | #include <gnunet/gnunet_messenger_service.h> | 29 | #include <gnunet/gnunet_messenger_service.h> |
29 | #include <gnunet/gnunet_util_lib.h> | 30 | #include <gnunet/gnunet_util_lib.h> |
30 | 31 | ||
@@ -41,7 +42,8 @@ struct GNUNET_CHAT_Contact | |||
41 | char *public_key; | 42 | char *public_key; |
42 | void *user_pointer; | 43 | void *user_pointer; |
43 | 44 | ||
44 | int is_owned; | 45 | enum GNUNET_GenericReturnValue owned; |
46 | enum GNUNET_GenericReturnValue blocked; | ||
45 | }; | 47 | }; |
46 | 48 | ||
47 | /** | 49 | /** |
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c index da1f571..e0d0df8 100644 --- a/src/gnunet_chat_handle_intern.c +++ b/src/gnunet_chat_handle_intern.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2021--2023 GNUnet e.V. | 3 | Copyright (C) 2021--2024 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -31,6 +31,7 @@ | |||
31 | #include "gnunet_chat_message.h" | 31 | #include "gnunet_chat_message.h" |
32 | #include "gnunet_chat_util.h" | 32 | #include "gnunet_chat_util.h" |
33 | 33 | ||
34 | #include <gnunet/gnunet_messenger_service.h> | ||
34 | #include <gnunet/gnunet_util_lib.h> | 35 | #include <gnunet/gnunet_util_lib.h> |
35 | #include <stdio.h> | 36 | #include <stdio.h> |
36 | 37 | ||
@@ -635,11 +636,11 @@ on_handle_message_callback(void *cls) | |||
635 | case GNUNET_MESSENGER_KIND_DELETE: | 636 | case GNUNET_MESSENGER_KIND_DELETE: |
636 | { | 637 | { |
637 | struct GNUNET_CHAT_Message *target = GNUNET_CONTAINER_multihashmap_get( | 638 | struct GNUNET_CHAT_Message *target = GNUNET_CONTAINER_multihashmap_get( |
638 | context->messages, &(message->msg->body.deletion.hash) | 639 | context->messages, &(message->msg->body.deletion.hash) |
639 | ); | 640 | ); |
640 | 641 | ||
641 | if (target) | 642 | if (target) |
642 | target->msg = NULL; | 643 | target->msg = NULL; |
643 | break; | 644 | break; |
644 | } | 645 | } |
645 | default: | 646 | default: |
@@ -651,6 +652,22 @@ on_handle_message_callback(void *cls) | |||
651 | if (!(handle->msg_cb)) | 652 | if (!(handle->msg_cb)) |
652 | return; | 653 | return; |
653 | 654 | ||
655 | const struct GNUNET_MESSENGER_Contact *sender; | ||
656 | sender = GNUNET_MESSENGER_get_sender(context->room, &(message->hash)); | ||
657 | |||
658 | if (!sender) | ||
659 | return; | ||
660 | |||
661 | struct GNUNET_ShortHashCode shorthash; | ||
662 | util_shorthash_from_member(sender, &shorthash); | ||
663 | |||
664 | struct GNUNET_CHAT_Contact *contact = GNUNET_CONTAINER_multishortmap_get( | ||
665 | handle->contacts, &shorthash | ||
666 | ); | ||
667 | |||
668 | if ((!contact) || (GNUNET_YES == contact->blocked)) | ||
669 | return; | ||
670 | |||
654 | handle->msg_cb(handle->msg_cls, context, message); | 671 | handle->msg_cb(handle->msg_cls, context, message); |
655 | } | 672 | } |
656 | 673 | ||
@@ -698,7 +715,7 @@ on_handle_message (void *cls, | |||
698 | ); | 715 | ); |
699 | 716 | ||
700 | if (flags & GNUNET_MESSENGER_FLAG_SENT) | 717 | if (flags & GNUNET_MESSENGER_FLAG_SENT) |
701 | contact->is_owned = GNUNET_YES; | 718 | contact->owned = GNUNET_YES; |
702 | 719 | ||
703 | struct GNUNET_TIME_Absolute *time = GNUNET_CONTAINER_multishortmap_get( | 720 | struct GNUNET_TIME_Absolute *time = GNUNET_CONTAINER_multishortmap_get( |
704 | context->timestamps, &shorthash | 721 | context->timestamps, &shorthash |
@@ -751,7 +768,7 @@ on_handle_message (void *cls, | |||
751 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( | 768 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( |
752 | context->invites, hash, invitation, | 769 | context->invites, hash, invitation, |
753 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 770 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
754 | invitation_destroy(invitation); | 771 | invitation_destroy(invitation); |
755 | break; | 772 | break; |
756 | } | 773 | } |
757 | case GNUNET_MESSENGER_KIND_FILE: | 774 | case GNUNET_MESSENGER_KIND_FILE: |
@@ -762,11 +779,11 @@ on_handle_message (void *cls, | |||
762 | ); | 779 | ); |
763 | 780 | ||
764 | struct GNUNET_CHAT_File *file = GNUNET_CONTAINER_multihashmap_get( | 781 | struct GNUNET_CHAT_File *file = GNUNET_CONTAINER_multihashmap_get( |
765 | context->handle->files, &(msg->body.file.hash) | 782 | context->handle->files, &(msg->body.file.hash) |
766 | ); | 783 | ); |
767 | 784 | ||
768 | if (file) | 785 | if (file) |
769 | break; | 786 | break; |
770 | 787 | ||
771 | file = file_create_from_message( | 788 | file = file_create_from_message( |
772 | context->handle, &(msg->body.file) | 789 | context->handle, &(msg->body.file) |
@@ -775,7 +792,7 @@ on_handle_message (void *cls, | |||
775 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( | 792 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( |
776 | context->handle->files, &(file->hash), file, | 793 | context->handle->files, &(file->hash), file, |
777 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 794 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
778 | file_destroy(file); | 795 | file_destroy(file); |
779 | break; | 796 | break; |
780 | } | 797 | } |
781 | case GNUNET_MESSENGER_KIND_DELETE: | 798 | case GNUNET_MESSENGER_KIND_DELETE: |
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c index 5eded0c..aa2ae6a 100644 --- a/src/gnunet_chat_lib.c +++ b/src/gnunet_chat_lib.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2021--2023 GNUnet e.V. | 3 | Copyright (C) 2021--2024 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -24,6 +24,7 @@ | |||
24 | 24 | ||
25 | #include "gnunet_chat_lib.h" | 25 | #include "gnunet_chat_lib.h" |
26 | 26 | ||
27 | #include <gnunet/gnunet_common.h> | ||
27 | #include <libgen.h> | 28 | #include <libgen.h> |
28 | #include <limits.h> | 29 | #include <limits.h> |
29 | #include <strings.h> | 30 | #include <strings.h> |
@@ -87,7 +88,7 @@ GNUNET_CHAT_stop (struct GNUNET_CHAT_Handle *handle) | |||
87 | } | 88 | } |
88 | 89 | ||
89 | 90 | ||
90 | int | 91 | enum GNUNET_GenericReturnValue |
91 | GNUNET_CHAT_account_create (struct GNUNET_CHAT_Handle *handle, | 92 | GNUNET_CHAT_account_create (struct GNUNET_CHAT_Handle *handle, |
92 | const char* name) | 93 | const char* name) |
93 | { | 94 | { |
@@ -105,7 +106,7 @@ GNUNET_CHAT_account_create (struct GNUNET_CHAT_Handle *handle, | |||
105 | } | 106 | } |
106 | 107 | ||
107 | 108 | ||
108 | int | 109 | enum GNUNET_GenericReturnValue |
109 | GNUNET_CHAT_account_delete(struct GNUNET_CHAT_Handle *handle, | 110 | GNUNET_CHAT_account_delete(struct GNUNET_CHAT_Handle *handle, |
110 | const char* name) | 111 | const char* name) |
111 | { | 112 | { |
@@ -195,7 +196,7 @@ GNUNET_CHAT_get_connected (const struct GNUNET_CHAT_Handle *handle) | |||
195 | } | 196 | } |
196 | 197 | ||
197 | 198 | ||
198 | int | 199 | enum GNUNET_GenericReturnValue |
199 | GNUNET_CHAT_update (struct GNUNET_CHAT_Handle *handle) | 200 | GNUNET_CHAT_update (struct GNUNET_CHAT_Handle *handle) |
200 | { | 201 | { |
201 | GNUNET_CHAT_VERSION_ASSERT(); | 202 | GNUNET_CHAT_VERSION_ASSERT(); |
@@ -207,7 +208,7 @@ GNUNET_CHAT_update (struct GNUNET_CHAT_Handle *handle) | |||
207 | } | 208 | } |
208 | 209 | ||
209 | 210 | ||
210 | int | 211 | enum GNUNET_GenericReturnValue |
211 | GNUNET_CHAT_set_name (struct GNUNET_CHAT_Handle *handle, | 212 | GNUNET_CHAT_set_name (struct GNUNET_CHAT_Handle *handle, |
212 | const char *name) | 213 | const char *name) |
213 | { | 214 | { |
@@ -602,7 +603,7 @@ GNUNET_CHAT_iterate_groups (struct GNUNET_CHAT_Handle *handle, | |||
602 | } | 603 | } |
603 | 604 | ||
604 | 605 | ||
605 | int | 606 | enum GNUNET_GenericReturnValue |
606 | GNUNET_CHAT_contact_delete (struct GNUNET_CHAT_Contact *contact) | 607 | GNUNET_CHAT_contact_delete (struct GNUNET_CHAT_Contact *contact) |
607 | { | 608 | { |
608 | GNUNET_CHAT_VERSION_ASSERT(); | 609 | GNUNET_CHAT_VERSION_ASSERT(); |
@@ -729,7 +730,7 @@ GNUNET_CHAT_contact_get_user_pointer (const struct GNUNET_CHAT_Contact *contact) | |||
729 | } | 730 | } |
730 | 731 | ||
731 | 732 | ||
732 | int | 733 | enum GNUNET_GenericReturnValue |
733 | GNUNET_CHAT_contact_is_owned (const struct GNUNET_CHAT_Contact *contact) | 734 | GNUNET_CHAT_contact_is_owned (const struct GNUNET_CHAT_Contact *contact) |
734 | { | 735 | { |
735 | GNUNET_CHAT_VERSION_ASSERT(); | 736 | GNUNET_CHAT_VERSION_ASSERT(); |
@@ -737,11 +738,36 @@ GNUNET_CHAT_contact_is_owned (const struct GNUNET_CHAT_Contact *contact) | |||
737 | if (!contact) | 738 | if (!contact) |
738 | return GNUNET_SYSERR; | 739 | return GNUNET_SYSERR; |
739 | 740 | ||
740 | return contact->is_owned; | 741 | return contact->owned; |
741 | } | 742 | } |
742 | 743 | ||
743 | 744 | ||
744 | int | 745 | void |
746 | GNUNET_CHAT_contact_set_blocked (struct GNUNET_CHAT_Contact *contact, | ||
747 | enum GNUNET_GenericReturnValue blocked) | ||
748 | { | ||
749 | GNUNET_CHAT_VERSION_ASSERT(); | ||
750 | |||
751 | if ((!contact) || ((GNUNET_YES != blocked) && (GNUNET_NO != blocked))) | ||
752 | return; | ||
753 | |||
754 | contact->blocked = blocked; | ||
755 | } | ||
756 | |||
757 | |||
758 | enum GNUNET_GenericReturnValue | ||
759 | GNUNET_CHAT_contact_is_blocked (const struct GNUNET_CHAT_Contact *contact) | ||
760 | { | ||
761 | GNUNET_CHAT_VERSION_ASSERT(); | ||
762 | |||
763 | if (!contact) | ||
764 | return GNUNET_SYSERR; | ||
765 | |||
766 | return contact->blocked; | ||
767 | } | ||
768 | |||
769 | |||
770 | enum GNUNET_GenericReturnValue | ||
745 | GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group) | 771 | GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group) |
746 | { | 772 | { |
747 | GNUNET_CHAT_VERSION_ASSERT(); | 773 | GNUNET_CHAT_VERSION_ASSERT(); |
@@ -933,7 +959,7 @@ GNUNET_CHAT_group_get_context (struct GNUNET_CHAT_Group *group) | |||
933 | } | 959 | } |
934 | 960 | ||
935 | 961 | ||
936 | int | 962 | enum GNUNET_GenericReturnValue |
937 | GNUNET_CHAT_context_get_status (const struct GNUNET_CHAT_Context *context) | 963 | GNUNET_CHAT_context_get_status (const struct GNUNET_CHAT_Context *context) |
938 | { | 964 | { |
939 | GNUNET_CHAT_VERSION_ASSERT(); | 965 | GNUNET_CHAT_VERSION_ASSERT(); |
@@ -1072,7 +1098,7 @@ GNUNET_CHAT_context_get_user_pointer (const struct GNUNET_CHAT_Context *context) | |||
1072 | } | 1098 | } |
1073 | 1099 | ||
1074 | 1100 | ||
1075 | int | 1101 | enum GNUNET_GenericReturnValue |
1076 | GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context, | 1102 | GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context, |
1077 | const char *text) | 1103 | const char *text) |
1078 | { | 1104 | { |
@@ -1092,7 +1118,7 @@ GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context, | |||
1092 | } | 1118 | } |
1093 | 1119 | ||
1094 | 1120 | ||
1095 | int | 1121 | enum GNUNET_GenericReturnValue |
1096 | GNUNET_CHAT_context_send_read_receipt (struct GNUNET_CHAT_Context *context, | 1122 | GNUNET_CHAT_context_send_read_receipt (struct GNUNET_CHAT_Context *context, |
1097 | const struct GNUNET_CHAT_Message *message) | 1123 | const struct GNUNET_CHAT_Message *message) |
1098 | { | 1124 | { |
@@ -1246,7 +1272,7 @@ file_binding: | |||
1246 | } | 1272 | } |
1247 | 1273 | ||
1248 | 1274 | ||
1249 | int | 1275 | enum GNUNET_GenericReturnValue |
1250 | GNUNET_CHAT_context_share_file (struct GNUNET_CHAT_Context *context, | 1276 | GNUNET_CHAT_context_share_file (struct GNUNET_CHAT_Context *context, |
1251 | const struct GNUNET_CHAT_File *file) | 1277 | const struct GNUNET_CHAT_File *file) |
1252 | { | 1278 | { |
@@ -1373,7 +1399,7 @@ GNUNET_CHAT_message_get_sender (const struct GNUNET_CHAT_Message *message) | |||
1373 | } | 1399 | } |
1374 | 1400 | ||
1375 | 1401 | ||
1376 | int | 1402 | enum GNUNET_GenericReturnValue |
1377 | GNUNET_CHAT_message_is_sent (const struct GNUNET_CHAT_Message *message) | 1403 | GNUNET_CHAT_message_is_sent (const struct GNUNET_CHAT_Message *message) |
1378 | { | 1404 | { |
1379 | GNUNET_CHAT_VERSION_ASSERT(); | 1405 | GNUNET_CHAT_VERSION_ASSERT(); |
@@ -1388,7 +1414,7 @@ GNUNET_CHAT_message_is_sent (const struct GNUNET_CHAT_Message *message) | |||
1388 | } | 1414 | } |
1389 | 1415 | ||
1390 | 1416 | ||
1391 | int | 1417 | enum GNUNET_GenericReturnValue |
1392 | GNUNET_CHAT_message_is_private (const struct GNUNET_CHAT_Message *message) | 1418 | GNUNET_CHAT_message_is_private (const struct GNUNET_CHAT_Message *message) |
1393 | { | 1419 | { |
1394 | GNUNET_CHAT_VERSION_ASSERT(); | 1420 | GNUNET_CHAT_VERSION_ASSERT(); |
@@ -1500,7 +1526,7 @@ GNUNET_CHAT_message_get_target (const struct GNUNET_CHAT_Message *message) | |||
1500 | } | 1526 | } |
1501 | 1527 | ||
1502 | 1528 | ||
1503 | int | 1529 | enum GNUNET_GenericReturnValue |
1504 | GNUNET_CHAT_message_delete (const struct GNUNET_CHAT_Message *message, | 1530 | GNUNET_CHAT_message_delete (const struct GNUNET_CHAT_Message *message, |
1505 | struct GNUNET_TIME_Relative delay) | 1531 | struct GNUNET_TIME_Relative delay) |
1506 | { | 1532 | { |
@@ -1582,7 +1608,7 @@ GNUNET_CHAT_file_get_local_size (const struct GNUNET_CHAT_File *file) | |||
1582 | } | 1608 | } |
1583 | 1609 | ||
1584 | 1610 | ||
1585 | int | 1611 | enum GNUNET_GenericReturnValue |
1586 | GNUNET_CHAT_file_is_uploading (const struct GNUNET_CHAT_File *file) | 1612 | GNUNET_CHAT_file_is_uploading (const struct GNUNET_CHAT_File *file) |
1587 | { | 1613 | { |
1588 | GNUNET_CHAT_VERSION_ASSERT(); | 1614 | GNUNET_CHAT_VERSION_ASSERT(); |
@@ -1680,7 +1706,7 @@ GNUNET_CHAT_file_get_user_pointer (const struct GNUNET_CHAT_File *file) | |||
1680 | } | 1706 | } |
1681 | 1707 | ||
1682 | 1708 | ||
1683 | int | 1709 | enum GNUNET_GenericReturnValue |
1684 | GNUNET_CHAT_file_is_downloading (const struct GNUNET_CHAT_File *file) | 1710 | GNUNET_CHAT_file_is_downloading (const struct GNUNET_CHAT_File *file) |
1685 | { | 1711 | { |
1686 | GNUNET_CHAT_VERSION_ASSERT(); | 1712 | GNUNET_CHAT_VERSION_ASSERT(); |
@@ -1692,7 +1718,7 @@ GNUNET_CHAT_file_is_downloading (const struct GNUNET_CHAT_File *file) | |||
1692 | } | 1718 | } |
1693 | 1719 | ||
1694 | 1720 | ||
1695 | int | 1721 | enum GNUNET_GenericReturnValue |
1696 | GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, | 1722 | GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, |
1697 | GNUNET_CHAT_FileDownloadCallback callback, | 1723 | GNUNET_CHAT_FileDownloadCallback callback, |
1698 | void *cls) | 1724 | void *cls) |
@@ -1760,7 +1786,7 @@ GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, | |||
1760 | } | 1786 | } |
1761 | 1787 | ||
1762 | 1788 | ||
1763 | int | 1789 | enum GNUNET_GenericReturnValue |
1764 | GNUNET_CHAT_file_pause_download (struct GNUNET_CHAT_File *file) | 1790 | GNUNET_CHAT_file_pause_download (struct GNUNET_CHAT_File *file) |
1765 | { | 1791 | { |
1766 | GNUNET_CHAT_VERSION_ASSERT(); | 1792 | GNUNET_CHAT_VERSION_ASSERT(); |
@@ -1773,7 +1799,7 @@ GNUNET_CHAT_file_pause_download (struct GNUNET_CHAT_File *file) | |||
1773 | } | 1799 | } |
1774 | 1800 | ||
1775 | 1801 | ||
1776 | int | 1802 | enum GNUNET_GenericReturnValue |
1777 | GNUNET_CHAT_file_resume_download (struct GNUNET_CHAT_File *file) | 1803 | GNUNET_CHAT_file_resume_download (struct GNUNET_CHAT_File *file) |
1778 | { | 1804 | { |
1779 | GNUNET_CHAT_VERSION_ASSERT(); | 1805 | GNUNET_CHAT_VERSION_ASSERT(); |
@@ -1786,7 +1812,7 @@ GNUNET_CHAT_file_resume_download (struct GNUNET_CHAT_File *file) | |||
1786 | } | 1812 | } |
1787 | 1813 | ||
1788 | 1814 | ||
1789 | int | 1815 | enum GNUNET_GenericReturnValue |
1790 | GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file) | 1816 | GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file) |
1791 | { | 1817 | { |
1792 | GNUNET_CHAT_VERSION_ASSERT(); | 1818 | GNUNET_CHAT_VERSION_ASSERT(); |
@@ -1800,7 +1826,7 @@ GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file) | |||
1800 | } | 1826 | } |
1801 | 1827 | ||
1802 | 1828 | ||
1803 | int | 1829 | enum GNUNET_GenericReturnValue |
1804 | GNUNET_CHAT_file_is_unindexing (const struct GNUNET_CHAT_File *file) | 1830 | GNUNET_CHAT_file_is_unindexing (const struct GNUNET_CHAT_File *file) |
1805 | { | 1831 | { |
1806 | GNUNET_CHAT_VERSION_ASSERT(); | 1832 | GNUNET_CHAT_VERSION_ASSERT(); |
@@ -1812,7 +1838,7 @@ GNUNET_CHAT_file_is_unindexing (const struct GNUNET_CHAT_File *file) | |||
1812 | } | 1838 | } |
1813 | 1839 | ||
1814 | 1840 | ||
1815 | int | 1841 | enum GNUNET_GenericReturnValue |
1816 | GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file, | 1842 | GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file, |
1817 | GNUNET_CHAT_FileUnindexCallback callback, | 1843 | GNUNET_CHAT_FileUnindexCallback callback, |
1818 | void *cls) | 1844 | void *cls) |