commit 155016406d44a5a12a123a91a8eaf8aaa62e7430
parent 2825c2b3391e1f65d58b6754ea603b83fd6959f1
Author: Jacki <jacki@thejackimonster.de>
Date: Fri, 5 Jan 2024 03:24:31 +0100
Implement setting and deleting attributes with handle
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
7 files changed, 263 insertions(+), 3 deletions(-)
diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h
@@ -35,6 +35,7 @@
/**@{*/
#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_time_lib.h>
#include <gnunet/gnunet_util_lib.h>
/**
@@ -488,6 +489,32 @@ const char*
GNUNET_CHAT_get_key (const struct GNUNET_CHAT_Handle *handle);
/**
+ * Updates an attribute of a chat handle for related communication under a given
+ * <i>name</i> and a custom <i>value</i>.
+ *
+ * @param[in,out] handle Chat handle
+ * @param[in] name Attribute name
+ * @param[in] value Attribute value
+ * @param[in] expires Expiration time or NULL
+ */
+void
+GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle,
+ const char *name,
+ const char *value,
+ const struct GNUNET_TIME_Relative *expires);
+
+/**
+ * Deletes an attribute of a chat handle for related communication under a given
+ * <i>name</i>.
+ *
+ * @param[in,out] handle Chat handle
+ * @param[in] name Attribute name
+ */
+void
+GNUNET_CHAT_delete_attribute (struct GNUNET_CHAT_Handle *handle,
+ const char *name);
+
+/**
* Convert an UTF-8 String to a chat URI which will be newly allocated.
*
* @param[in] uri UTF-8 string to parse
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
@@ -99,6 +99,9 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg,
handle->lookups_head = NULL;
handle->lookups_tail = NULL;
+ handle->attributes_head = NULL;
+ handle->attributes_tail = NULL;
+
handle->tickets_head = NULL;
handle->tickets_tail = NULL;
@@ -460,6 +463,29 @@ handle_disconnect (struct GNUNET_CHAT_Handle *handle)
GNUNET_free(lobbies);
}
+ struct GNUNET_CHAT_AttributeProcess *attributes;
+ while (handle->attributes_head)
+ {
+ attributes = handle->attributes_head;
+
+ if (attributes->attribute)
+ GNUNET_free(attributes->attribute);
+
+ if (attributes->iter)
+ GNUNET_RECLAIM_get_attributes_stop(attributes->iter);
+
+ if (attributes->op)
+ GNUNET_RECLAIM_cancel(attributes->op);
+
+ GNUNET_CONTAINER_DLL_remove(
+ handle->attributes_head,
+ handle->attributes_tail,
+ attributes
+ );
+
+ GNUNET_free(attributes);
+ }
+
GNUNET_CONTAINER_multihashmap_destroy(handle->groups);
GNUNET_CONTAINER_multishortmap_destroy(handle->contacts);
GNUNET_CONTAINER_multihashmap_destroy(handle->contexts);
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h
@@ -31,6 +31,7 @@
#include <gnunet/gnunet_identity_service.h>
#include <gnunet/gnunet_messenger_service.h>
#include <gnunet/gnunet_namestore_service.h>
+#include <gnunet/gnunet_reclaim_lib.h>
#include <gnunet/gnunet_reclaim_service.h>
#include <gnunet/gnunet_util_lib.h>
@@ -81,6 +82,19 @@ struct GNUNET_CHAT_UriLookups
struct GNUNET_CHAT_UriLookups *prev;
};
+struct GNUNET_CHAT_AttributeProcess
+{
+ struct GNUNET_CHAT_Handle *handle;
+
+ struct GNUNET_RECLAIM_Attribute *attribute;
+
+ struct GNUNET_RECLAIM_AttributeIterator *iter;
+ struct GNUNET_RECLAIM_Operation *op;
+
+ struct GNUNET_CHAT_AttributeProcess *next;
+ struct GNUNET_CHAT_AttributeProcess *prev;
+};
+
struct GNUNET_CHAT_TicketProcess
{
struct GNUNET_CHAT_Handle *handle;
@@ -120,6 +134,9 @@ struct GNUNET_CHAT_Handle
struct GNUNET_CHAT_UriLookups *lookups_head;
struct GNUNET_CHAT_UriLookups *lookups_tail;
+ struct GNUNET_CHAT_AttributeProcess *attributes_head;
+ struct GNUNET_CHAT_AttributeProcess *attributes_tail;
+
struct GNUNET_CHAT_TicketProcess *tickets_head;
struct GNUNET_CHAT_TicketProcess *tickets_tail;
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
@@ -311,7 +311,25 @@ cont_revoke_ticket_with_status (void *cls,
tickets->op = NULL;
- GNUNET_RECLAIM_ticket_iteration_next(tickets->iter);
+ struct GNUNET_CHAT_Handle *handle = tickets->handle;
+
+ if (GNUNET_SYSERR == success)
+ {
+ handle_send_internal_message(
+ handle,
+ NULL,
+ GNUNET_CHAT_KIND_WARNING,
+ emsg
+ );
+
+ if (tickets->iter)
+ GNUNET_RECLAIM_ticket_iteration_stop(tickets->iter);
+
+ return;
+ }
+
+ if (tickets->iter)
+ GNUNET_RECLAIM_ticket_iteration_next(tickets->iter);
}
void
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -26,6 +26,9 @@
#include <gnunet/gnunet_common.h>
#include <gnunet/gnunet_messenger_service.h>
+#include <gnunet/gnunet_reclaim_lib.h>
+#include <gnunet/gnunet_reclaim_service.h>
+#include <gnunet/gnunet_time_lib.h>
#include <libgen.h>
#include <limits.h>
#include <strings.h>
@@ -257,6 +260,137 @@ GNUNET_CHAT_get_key (const struct GNUNET_CHAT_Handle *handle)
}
+void
+GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle,
+ const char *name,
+ const char *value,
+ const struct GNUNET_TIME_Relative *expires)
+{
+ GNUNET_CHAT_VERSION_ASSERT();
+
+ if ((!handle) || (handle->destruction))
+ return;
+
+ const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key(
+ handle
+ );
+
+ if ((!key) || (!name))
+ return;
+
+ struct GNUNET_CHAT_AttributeProcess *attributes = GNUNET_new(
+ struct GNUNET_CHAT_AttributeProcess
+ );
+
+ memset(attributes, 0, sizeof(struct GNUNET_CHAT_AttributeProcess));
+
+ attributes->handle = handle;
+ attributes->attribute = GNUNET_RECLAIM_attribute_new(
+ name,
+ NULL,
+ GNUNET_RECLAIM_ATTRIBUTE_TYPE_NONE,
+ NULL,
+ 0
+ );
+
+ if (!attributes->attribute)
+ {
+ GNUNET_free(attributes);
+ return;
+ }
+
+ if (value)
+ {
+ void *data = NULL;
+
+ enum GNUNET_GenericReturnValue result;
+ result = GNUNET_RECLAIM_attribute_string_to_value(
+ GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING,
+ value,
+ &data,
+ &(attributes->attribute->data_size)
+ );
+
+ if (GNUNET_OK != result)
+ {
+ GNUNET_free(attributes->attribute);
+ GNUNET_free(attributes);
+ return;
+ }
+
+ attributes->attribute->data = data;
+ }
+
+ attributes->op = GNUNET_RECLAIM_attribute_store(
+ handle->reclaim,
+ key,
+ attributes->attribute,
+ expires,
+ cont_update_attribute_with_status,
+ attributes
+ );
+
+ GNUNET_CONTAINER_DLL_insert_tail(
+ handle->attributes_head,
+ handle->attributes_tail,
+ attributes
+ );
+}
+
+
+void
+GNUNET_CHAT_delete_attribute (struct GNUNET_CHAT_Handle *handle,
+ const char *name)
+{
+ GNUNET_CHAT_VERSION_ASSERT();
+
+ if ((!handle) || (handle->destruction))
+ return;
+
+ const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key(
+ handle
+ );
+
+ if ((!key) || (!name))
+ return;
+
+ struct GNUNET_CHAT_AttributeProcess *attributes = GNUNET_new(
+ struct GNUNET_CHAT_AttributeProcess
+ );
+
+ memset(attributes, 0, sizeof(struct GNUNET_CHAT_AttributeProcess));
+
+ attributes->handle = handle;
+ attributes->attribute = GNUNET_RECLAIM_attribute_new(
+ name,
+ NULL,
+ GNUNET_RECLAIM_ATTRIBUTE_TYPE_NONE,
+ NULL,
+ 0
+ );
+
+ if (!attributes->attribute)
+ {
+ GNUNET_free(attributes);
+ return;
+ }
+
+ attributes->op = GNUNET_RECLAIM_attribute_delete(
+ handle->reclaim,
+ key,
+ attributes->attribute,
+ cont_update_attribute_with_status,
+ attributes
+ );
+
+ GNUNET_CONTAINER_DLL_insert_tail(
+ handle->attributes_head,
+ handle->attributes_tail,
+ attributes
+ );
+}
+
+
struct GNUNET_CHAT_Uri*
GNUNET_CHAT_uri_parse (const char *uri,
char **emsg)
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c
@@ -22,6 +22,7 @@
* @file gnunet_chat_lib_intern.c
*/
+#include <gnunet/gnunet_common.h>
#include <stdlib.h>
#define GNUNET_UNUSED __attribute__ ((unused))
@@ -308,3 +309,37 @@ it_message_iterate_read_receipts (void *cls,
return GNUNET_YES;
}
+
+void
+cont_update_attribute_with_status (void *cls,
+ int32_t success,
+ const char *emsg)
+{
+ GNUNET_assert(cls);
+
+ struct GNUNET_CHAT_AttributeProcess *attributes = (
+ (struct GNUNET_CHAT_AttributeProcess*) cls
+ );
+
+ attributes->op = NULL;
+
+ struct GNUNET_CHAT_Handle *handle = attributes->handle;
+
+ if (GNUNET_SYSERR == success)
+ {
+ handle_send_internal_message(
+ handle,
+ NULL,
+ GNUNET_CHAT_KIND_WARNING,
+ emsg
+ );
+
+ return;
+ }
+
+ GNUNET_CONTAINER_DLL_remove(
+ handle->attributes_head,
+ handle->attributes_tail,
+ attributes
+ );
+}
diff --git a/src/gnunet_chat_ticket.c b/src/gnunet_chat_ticket.c
@@ -48,11 +48,14 @@ ticket_create_from_message (struct GNUNET_CHAT_Handle *handle,
struct GNUNET_CHAT_Ticket *ticket = GNUNET_new(struct GNUNET_CHAT_Ticket);
- memset(ticket, 0, sizeof(struct GNUNET_CHAT_Ticket));
-
ticket->handle = handle;
ticket->issuer = issuer;
+ ticket->callback = NULL;
+ ticket->closure = NULL;
+
+ ticket->op = NULL;
+
GNUNET_memcpy(&(ticket->ticket.identity), identity, sizeof(ticket->ticket.identity));
GNUNET_memcpy(&(ticket->ticket.audience), audience, sizeof(ticket->ticket.audience));
GNUNET_memcpy(&(ticket->ticket.rnd), &(message->identifier), sizeof(ticket->ticket.rnd));