libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

commit 0f107aba69354e4aa04e63e2df180f18b56a33eb
parent 7e2a4bc0df9d13a2cc67852ee18e3f964d415ecf
Author: Jacki <jacki@thejackimonster.de>
Date:   Mon, 15 Apr 2024 01:55:12 +0200

Fix attribute storing value as replacement

Signed-off-by: Jacki <jacki@thejackimonster.de>

Diffstat:
Msrc/gnunet_chat_handle.h | 3+++
Msrc/gnunet_chat_lib.c | 21+++++++++++----------
Msrc/gnunet_chat_lib_intern.c | 92++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 105 insertions(+), 11 deletions(-)

diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h @@ -34,6 +34,7 @@ #include <gnunet/gnunet_namestore_service.h> #include <gnunet/gnunet_reclaim_lib.h> #include <gnunet/gnunet_reclaim_service.h> +#include <gnunet/gnunet_time_lib.h> #include <gnunet/gnunet_util_lib.h> #include "gnunet_chat_lib.h" @@ -97,7 +98,9 @@ struct GNUNET_CHAT_AttributeProcess struct GNUNET_CHAT_Contact *contact; struct GNUNET_RECLAIM_Attribute *attribute; + struct GNUNET_TIME_Relative expires; char *name; + void *data; GNUNET_CHAT_AttributeCallback callback; void *closure; diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c @@ -300,6 +300,8 @@ GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle, memset(attributes, 0, sizeof(struct GNUNET_CHAT_AttributeProcess)); attributes->handle = handle; + attributes->name = GNUNET_strdup(name); + attributes->expires = expires; attributes->attribute = GNUNET_RECLAIM_attribute_new( name, NULL, @@ -314,7 +316,7 @@ GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle, return; } - void *data = NULL; + attributes->data = NULL; if (value) { @@ -322,7 +324,7 @@ GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle, result = GNUNET_RECLAIM_attribute_string_to_value( GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING, value, - &(data), + &(attributes->data), &(attributes->attribute->data_size) ); @@ -334,15 +336,17 @@ GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle, } attributes->attribute->type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING; - attributes->attribute->data = data; + attributes->attribute->data = attributes->data; } - attributes->op = GNUNET_RECLAIM_attribute_store( + attributes->iter = GNUNET_RECLAIM_get_attributes_start( handle->reclaim, key, - attributes->attribute, - &expires, - cont_update_attribute_with_status, + cb_task_error_iterate_attribute, + attributes, + cb_store_attribute, + attributes, + cb_task_finish_iterate_attribute, attributes ); @@ -351,9 +355,6 @@ GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle, handle->attributes_tail, attributes ); - - if (data) - GNUNET_free(data); } diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c @@ -459,11 +459,39 @@ cb_task_finish_iterate_attribute (void *cls) struct GNUNET_CHAT_Handle *handle = attributes->handle; + const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key( + handle + ); + attributes->iter = NULL; + if (attributes->name) + GNUNET_free(attributes->name); + + attributes->name = NULL; + + if ((! attributes->op) && (key) && + (attributes->attribute)) + attributes->op = GNUNET_RECLAIM_attribute_store( + handle->reclaim, + key, + attributes->attribute, + &(attributes->expires), + cont_update_attribute_with_status, + attributes + ); + + if (attributes->data) + GNUNET_free(attributes->data); + + attributes->data = NULL; + if (attributes->op) return; + if (attributes->attribute) + GNUNET_free(attributes->attribute); + GNUNET_CONTAINER_DLL_remove( handle->attributes_head, handle->attributes_tail, @@ -493,6 +521,69 @@ cb_task_error_iterate_attribute (void *cls) } void +cb_store_attribute (void *cls, + const struct GNUNET_CRYPTO_PublicKey *identity, + const struct GNUNET_RECLAIM_Attribute *attribute) +{ + GNUNET_assert(cls); + + struct GNUNET_CHAT_AttributeProcess *attributes = ( + (struct GNUNET_CHAT_AttributeProcess*) cls + ); + + struct GNUNET_CHAT_Handle *handle = attributes->handle; + + const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key( + handle + ); + + if (! attributes->name) + { + if (attributes->iter) + GNUNET_RECLAIM_get_attributes_stop(attributes->iter); + + attributes->iter = NULL; + return; + } + + if (0 == strcmp(attribute->name, attributes->name)) + { + if (attributes->iter) + GNUNET_RECLAIM_get_attributes_stop(attributes->iter); + + attributes->iter = NULL; + + if (attributes->attribute) + { + attributes->attribute->credential = attribute->credential; + attributes->attribute->flag = attribute->flag; + attributes->attribute->id = attribute->id; + } + + attributes->op = GNUNET_RECLAIM_attribute_store( + handle->reclaim, + key, + attributes->attribute, + &(attributes->expires), + cont_update_attribute_with_status, + attributes + ); + + if (attributes->data) + GNUNET_free(attributes->data); + + attributes->data = NULL; + + GNUNET_free(attributes->name); + attributes->name = NULL; + return; + } + + if (attributes->iter) + GNUNET_RECLAIM_get_attributes_next(attributes->iter); +} + +void cb_delete_attribute (void *cls, const struct GNUNET_CRYPTO_PublicKey *identity, const struct GNUNET_RECLAIM_Attribute *attribute) @@ -520,7 +611,6 @@ cb_delete_attribute (void *cls, if (0 == strcmp(attribute->name, attributes->name)) { - if (attributes->iter) GNUNET_RECLAIM_get_attributes_stop(attributes->iter);