commit 828af2a9a5c39996b791bfb9af48cdd1bedf509f
parent ad9931275357614ed810d6851c81d4782797e59b
Author: Jacki <jacki@thejackimonster.de>
Date: Wed, 3 Jan 2024 01:06:56 +0100
Implement client-side blocking of contacts
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
5 files changed, 129 insertions(+), 61 deletions(-)
diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2021--2023 GNUnet e.V.
+ Copyright (C) 2021--2024 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -34,6 +34,7 @@
*/
/**@{*/
+#include <gnunet/gnunet_common.h>
#include <gnunet/gnunet_util_lib.h>
/**
@@ -354,7 +355,7 @@ GNUNET_CHAT_stop (struct GNUNET_CHAT_Handle *handle);
* @param[in] name Account name
* @return #GNUNET_OK on success, #GNUNET_NO on failure and otherwise #GNUNET_SYSERR
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_account_create (struct GNUNET_CHAT_Handle *handle,
const char* name);
@@ -366,7 +367,7 @@ GNUNET_CHAT_account_create (struct GNUNET_CHAT_Handle *handle,
* @param[in] name Account name
* @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_account_delete(struct GNUNET_CHAT_Handle *handle,
const char* name);
@@ -421,7 +422,7 @@ GNUNET_CHAT_get_connected (const struct GNUNET_CHAT_Handle *handle);
* @param[in,out] handle Chat handle
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_update (struct GNUNET_CHAT_Handle *handle);
/**
@@ -431,7 +432,7 @@ GNUNET_CHAT_update (struct GNUNET_CHAT_Handle *handle);
* @param[in] name New name or NULL
* @return #GNUNET_YES on success, #GNUNET_NO on failure and #GNUNET_SYSERR if <i>handle</i> is NULL
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_set_name (struct GNUNET_CHAT_Handle *handle,
const char *name);
@@ -620,7 +621,7 @@ GNUNET_CHAT_iterate_groups (struct GNUNET_CHAT_Handle *handle,
* @param[in,out] contact Cntact
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_contact_delete (struct GNUNET_CHAT_Contact *contact);
/**
@@ -689,20 +690,41 @@ GNUNET_CHAT_contact_get_user_pointer (const struct GNUNET_CHAT_Contact *contact)
* it has sent messages with.
*
* @param[in] contact Contact
- * @return GNUNET_YES if the contact is owned, otherwise GNUNET_NO
- * and GNUNET_SYSERR on failure
+ * @return #GNUNET_YES if the contact is owned, otherwise# GNUNET_NO
+ * and #GNUNET_SYSERR on failure
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_contact_is_owned (const struct GNUNET_CHAT_Contact *contact);
/**
+ * Blocks or unblocks a given <i>contact</i> by the current account.
+ *
+ * @param[in,out] contact Contact
+ * @param[in] blocked #GNUNET_YES to block, #GNUNET_NO to unblock
+ */
+void
+GNUNET_CHAT_contact_set_blocked (struct GNUNET_CHAT_Contact *contact,
+ enum GNUNET_GenericReturnValue blocked);
+
+/**
+ * Returns if a given <i>contact</i> is blocked by the current account and
+ * whether messages of it should be filtered.
+ *
+ * @param[in] contact Contact
+ * @return #GNUNET_YES if the contact is blocked, #GNUNET_SYSERR on failure and
+ * #GNUNET_NO otherwise
+ */
+enum GNUNET_GenericReturnValue
+GNUNET_CHAT_contact_is_blocked (const struct GNUNET_CHAT_Contact *contact);
+
+/**
* Leaves a specific <i>group</i> chat and frees its memory if it is not shared
* with other groups or contacts.
*
* @param[in,out] group Group
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group);
/**
@@ -813,7 +835,7 @@ GNUNET_CHAT_group_get_context (struct GNUNET_CHAT_Group *group);
* @return #GNUNET_OK if usable, #GNUNET_NO if the context has been requested,
* #GNUNET_SYSERR otherwise.
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_context_get_status (const struct GNUNET_CHAT_Context *context);
/**
@@ -873,7 +895,7 @@ GNUNET_CHAT_context_get_user_pointer (const struct GNUNET_CHAT_Context *context)
* @param[in] text Text
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context,
const char *text);
@@ -885,7 +907,7 @@ GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context,
* @param[in] message Message (optional)
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_context_send_read_receipt (struct GNUNET_CHAT_Context *context,
const struct GNUNET_CHAT_Message *message);
@@ -914,7 +936,7 @@ GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context,
* @param[in] file File handle
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_context_share_file (struct GNUNET_CHAT_Context *context,
const struct GNUNET_CHAT_File *file);
@@ -981,7 +1003,7 @@ GNUNET_CHAT_message_get_sender (const struct GNUNET_CHAT_Message *message);
* @param[in] message Message
* @return #GNUNET_YES if the message was sent, otherwise #GNUNET_NO
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_message_is_sent (const struct GNUNET_CHAT_Message *message);
/**
@@ -992,7 +1014,7 @@ GNUNET_CHAT_message_is_sent (const struct GNUNET_CHAT_Message *message);
* @return #GNUNET_YES if the message was privately received,
* otherwise #GNUNET_NO
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_message_is_private (const struct GNUNET_CHAT_Message *message);
/**
@@ -1059,7 +1081,7 @@ GNUNET_CHAT_message_get_target (const struct GNUNET_CHAT_Message *message);
* @param[in] delay Relative delay
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_message_delete (const struct GNUNET_CHAT_Message *message,
struct GNUNET_TIME_Relative delay);
@@ -1108,7 +1130,7 @@ GNUNET_CHAT_file_get_local_size (const struct GNUNET_CHAT_File *file);
* @param[in] file File handle
* @return #GNUNET_YES during active upload, #GNUNET_NO otherwise
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_file_is_uploading (const struct GNUNET_CHAT_File *file);
/**
@@ -1163,7 +1185,7 @@ GNUNET_CHAT_file_get_user_pointer (const struct GNUNET_CHAT_File *file);
* @param[in] file File handle
* @return #GNUNET_YES during active download, #GNUNET_NO otherwise
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_file_is_downloading (const struct GNUNET_CHAT_File *file);
/**
@@ -1175,7 +1197,7 @@ GNUNET_CHAT_file_is_downloading (const struct GNUNET_CHAT_File *file);
* @param[in,out] cls Closure for file downloading (optional)
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file,
GNUNET_CHAT_FileDownloadCallback callback,
void *cls);
@@ -1186,7 +1208,7 @@ GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file,
* @param[in,out] file File handle
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_file_pause_download (struct GNUNET_CHAT_File *file);
/**
@@ -1195,7 +1217,7 @@ GNUNET_CHAT_file_pause_download (struct GNUNET_CHAT_File *file);
* @param[in,out] file File handle
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_file_resume_download (struct GNUNET_CHAT_File *file);
/**
@@ -1204,7 +1226,7 @@ GNUNET_CHAT_file_resume_download (struct GNUNET_CHAT_File *file);
* @param[in,out] file File handle
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file);
/**
@@ -1213,7 +1235,7 @@ GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file);
* @param[in] file File handle
* @return #GNUNET_YES during active unindexing, #GNUNET_NO otherwise
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_file_is_unindexing (const struct GNUNET_CHAT_File *file);
/**
@@ -1225,7 +1247,7 @@ GNUNET_CHAT_file_is_unindexing (const struct GNUNET_CHAT_File *file);
* @param[in,out] cls Closure for file unindexing (optional)
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file,
GNUNET_CHAT_FileUnindexCallback callback,
void *cls);
diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2021--2023 GNUnet e.V.
+ Copyright (C) 2021--2024 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
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,
contact->public_key = NULL;
contact->user_pointer = NULL;
- contact->is_owned = GNUNET_NO;
+ contact->owned = GNUNET_NO;
+ contact->blocked = GNUNET_NO;
contact_update_key (contact);
return contact;
diff --git a/src/gnunet_chat_contact.h b/src/gnunet_chat_contact.h
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2021--2022 GNUnet e.V.
+ Copyright (C) 2021--2024 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -25,6 +25,7 @@
#ifndef GNUNET_CHAT_CONTACT_H_
#define GNUNET_CHAT_CONTACT_H_
+#include <gnunet/gnunet_common.h>
#include <gnunet/gnunet_messenger_service.h>
#include <gnunet/gnunet_util_lib.h>
@@ -41,7 +42,8 @@ struct GNUNET_CHAT_Contact
char *public_key;
void *user_pointer;
- int is_owned;
+ enum GNUNET_GenericReturnValue owned;
+ enum GNUNET_GenericReturnValue blocked;
};
/**
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2021--2023 GNUnet e.V.
+ Copyright (C) 2021--2024 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -31,6 +31,7 @@
#include "gnunet_chat_message.h"
#include "gnunet_chat_util.h"
+#include <gnunet/gnunet_messenger_service.h>
#include <gnunet/gnunet_util_lib.h>
#include <stdio.h>
@@ -635,11 +636,11 @@ on_handle_message_callback(void *cls)
case GNUNET_MESSENGER_KIND_DELETE:
{
struct GNUNET_CHAT_Message *target = GNUNET_CONTAINER_multihashmap_get(
- context->messages, &(message->msg->body.deletion.hash)
+ context->messages, &(message->msg->body.deletion.hash)
);
if (target)
- target->msg = NULL;
+ target->msg = NULL;
break;
}
default:
@@ -651,6 +652,22 @@ on_handle_message_callback(void *cls)
if (!(handle->msg_cb))
return;
+ const struct GNUNET_MESSENGER_Contact *sender;
+ sender = GNUNET_MESSENGER_get_sender(context->room, &(message->hash));
+
+ if (!sender)
+ return;
+
+ struct GNUNET_ShortHashCode shorthash;
+ util_shorthash_from_member(sender, &shorthash);
+
+ struct GNUNET_CHAT_Contact *contact = GNUNET_CONTAINER_multishortmap_get(
+ handle->contacts, &shorthash
+ );
+
+ if ((!contact) || (GNUNET_YES == contact->blocked))
+ return;
+
handle->msg_cb(handle->msg_cls, context, message);
}
@@ -698,7 +715,7 @@ on_handle_message (void *cls,
);
if (flags & GNUNET_MESSENGER_FLAG_SENT)
- contact->is_owned = GNUNET_YES;
+ contact->owned = GNUNET_YES;
struct GNUNET_TIME_Absolute *time = GNUNET_CONTAINER_multishortmap_get(
context->timestamps, &shorthash
@@ -751,7 +768,7 @@ on_handle_message (void *cls,
if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(
context->invites, hash, invitation,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
- invitation_destroy(invitation);
+ invitation_destroy(invitation);
break;
}
case GNUNET_MESSENGER_KIND_FILE:
@@ -762,11 +779,11 @@ on_handle_message (void *cls,
);
struct GNUNET_CHAT_File *file = GNUNET_CONTAINER_multihashmap_get(
- context->handle->files, &(msg->body.file.hash)
+ context->handle->files, &(msg->body.file.hash)
);
if (file)
- break;
+ break;
file = file_create_from_message(
context->handle, &(msg->body.file)
@@ -775,7 +792,7 @@ on_handle_message (void *cls,
if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(
context->handle->files, &(file->hash), file,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
- file_destroy(file);
+ file_destroy(file);
break;
}
case GNUNET_MESSENGER_KIND_DELETE:
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2021--2023 GNUnet e.V.
+ Copyright (C) 2021--2024 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -24,6 +24,7 @@
#include "gnunet_chat_lib.h"
+#include <gnunet/gnunet_common.h>
#include <libgen.h>
#include <limits.h>
#include <strings.h>
@@ -87,7 +88,7 @@ GNUNET_CHAT_stop (struct GNUNET_CHAT_Handle *handle)
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_account_create (struct GNUNET_CHAT_Handle *handle,
const char* name)
{
@@ -105,7 +106,7 @@ GNUNET_CHAT_account_create (struct GNUNET_CHAT_Handle *handle,
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_account_delete(struct GNUNET_CHAT_Handle *handle,
const char* name)
{
@@ -195,7 +196,7 @@ GNUNET_CHAT_get_connected (const struct GNUNET_CHAT_Handle *handle)
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_update (struct GNUNET_CHAT_Handle *handle)
{
GNUNET_CHAT_VERSION_ASSERT();
@@ -207,7 +208,7 @@ GNUNET_CHAT_update (struct GNUNET_CHAT_Handle *handle)
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_set_name (struct GNUNET_CHAT_Handle *handle,
const char *name)
{
@@ -602,7 +603,7 @@ GNUNET_CHAT_iterate_groups (struct GNUNET_CHAT_Handle *handle,
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_contact_delete (struct GNUNET_CHAT_Contact *contact)
{
GNUNET_CHAT_VERSION_ASSERT();
@@ -729,7 +730,7 @@ GNUNET_CHAT_contact_get_user_pointer (const struct GNUNET_CHAT_Contact *contact)
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_contact_is_owned (const struct GNUNET_CHAT_Contact *contact)
{
GNUNET_CHAT_VERSION_ASSERT();
@@ -737,11 +738,36 @@ GNUNET_CHAT_contact_is_owned (const struct GNUNET_CHAT_Contact *contact)
if (!contact)
return GNUNET_SYSERR;
- return contact->is_owned;
+ return contact->owned;
}
-int
+void
+GNUNET_CHAT_contact_set_blocked (struct GNUNET_CHAT_Contact *contact,
+ enum GNUNET_GenericReturnValue blocked)
+{
+ GNUNET_CHAT_VERSION_ASSERT();
+
+ if ((!contact) || ((GNUNET_YES != blocked) && (GNUNET_NO != blocked)))
+ return;
+
+ contact->blocked = blocked;
+}
+
+
+enum GNUNET_GenericReturnValue
+GNUNET_CHAT_contact_is_blocked (const struct GNUNET_CHAT_Contact *contact)
+{
+ GNUNET_CHAT_VERSION_ASSERT();
+
+ if (!contact)
+ return GNUNET_SYSERR;
+
+ return contact->blocked;
+}
+
+
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group)
{
GNUNET_CHAT_VERSION_ASSERT();
@@ -933,7 +959,7 @@ GNUNET_CHAT_group_get_context (struct GNUNET_CHAT_Group *group)
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_context_get_status (const struct GNUNET_CHAT_Context *context)
{
GNUNET_CHAT_VERSION_ASSERT();
@@ -1072,7 +1098,7 @@ GNUNET_CHAT_context_get_user_pointer (const struct GNUNET_CHAT_Context *context)
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context,
const char *text)
{
@@ -1092,7 +1118,7 @@ GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context,
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_context_send_read_receipt (struct GNUNET_CHAT_Context *context,
const struct GNUNET_CHAT_Message *message)
{
@@ -1246,7 +1272,7 @@ file_binding:
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_context_share_file (struct GNUNET_CHAT_Context *context,
const struct GNUNET_CHAT_File *file)
{
@@ -1373,7 +1399,7 @@ GNUNET_CHAT_message_get_sender (const struct GNUNET_CHAT_Message *message)
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_message_is_sent (const struct GNUNET_CHAT_Message *message)
{
GNUNET_CHAT_VERSION_ASSERT();
@@ -1388,7 +1414,7 @@ GNUNET_CHAT_message_is_sent (const struct GNUNET_CHAT_Message *message)
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_message_is_private (const struct GNUNET_CHAT_Message *message)
{
GNUNET_CHAT_VERSION_ASSERT();
@@ -1500,7 +1526,7 @@ GNUNET_CHAT_message_get_target (const struct GNUNET_CHAT_Message *message)
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_message_delete (const struct GNUNET_CHAT_Message *message,
struct GNUNET_TIME_Relative delay)
{
@@ -1582,7 +1608,7 @@ GNUNET_CHAT_file_get_local_size (const struct GNUNET_CHAT_File *file)
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_file_is_uploading (const struct GNUNET_CHAT_File *file)
{
GNUNET_CHAT_VERSION_ASSERT();
@@ -1680,7 +1706,7 @@ GNUNET_CHAT_file_get_user_pointer (const struct GNUNET_CHAT_File *file)
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_file_is_downloading (const struct GNUNET_CHAT_File *file)
{
GNUNET_CHAT_VERSION_ASSERT();
@@ -1692,7 +1718,7 @@ GNUNET_CHAT_file_is_downloading (const struct GNUNET_CHAT_File *file)
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file,
GNUNET_CHAT_FileDownloadCallback callback,
void *cls)
@@ -1760,7 +1786,7 @@ GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file,
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_file_pause_download (struct GNUNET_CHAT_File *file)
{
GNUNET_CHAT_VERSION_ASSERT();
@@ -1773,7 +1799,7 @@ GNUNET_CHAT_file_pause_download (struct GNUNET_CHAT_File *file)
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_file_resume_download (struct GNUNET_CHAT_File *file)
{
GNUNET_CHAT_VERSION_ASSERT();
@@ -1786,7 +1812,7 @@ GNUNET_CHAT_file_resume_download (struct GNUNET_CHAT_File *file)
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file)
{
GNUNET_CHAT_VERSION_ASSERT();
@@ -1800,7 +1826,7 @@ GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file)
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_file_is_unindexing (const struct GNUNET_CHAT_File *file)
{
GNUNET_CHAT_VERSION_ASSERT();
@@ -1812,7 +1838,7 @@ GNUNET_CHAT_file_is_unindexing (const struct GNUNET_CHAT_File *file)
}
-int
+enum GNUNET_GenericReturnValue
GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file,
GNUNET_CHAT_FileUnindexCallback callback,
void *cls)