aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacki <jacki@thejackimonster.de>2024-01-05 03:24:31 +0100
committerJacki <jacki@thejackimonster.de>2024-01-05 03:24:31 +0100
commit155016406d44a5a12a123a91a8eaf8aaa62e7430 (patch)
treeebc809005fbcaee9d15c9984f74a3e5487c21b6a
parent2825c2b3391e1f65d58b6754ea603b83fd6959f1 (diff)
downloadlibgnunetchat-155016406d44a5a12a123a91a8eaf8aaa62e7430.tar.gz
libgnunetchat-155016406d44a5a12a123a91a8eaf8aaa62e7430.zip
Implement setting and deleting attributes with handle
Signed-off-by: Jacki <jacki@thejackimonster.de>
-rw-r--r--include/gnunet/gnunet_chat_lib.h27
-rw-r--r--src/gnunet_chat_handle.c26
-rw-r--r--src/gnunet_chat_handle.h17
-rw-r--r--src/gnunet_chat_handle_intern.c20
-rw-r--r--src/gnunet_chat_lib.c134
-rw-r--r--src/gnunet_chat_lib_intern.c35
-rw-r--r--src/gnunet_chat_ticket.c7
7 files changed, 263 insertions, 3 deletions
diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h
index 0a2fd7c..8026cf6 100644
--- a/include/gnunet/gnunet_chat_lib.h
+++ b/include/gnunet/gnunet_chat_lib.h
@@ -35,6 +35,7 @@
35/**@{*/ 35/**@{*/
36 36
37#include <gnunet/gnunet_common.h> 37#include <gnunet/gnunet_common.h>
38#include <gnunet/gnunet_time_lib.h>
38#include <gnunet/gnunet_util_lib.h> 39#include <gnunet/gnunet_util_lib.h>
39 40
40/** 41/**
@@ -488,6 +489,32 @@ const char*
488GNUNET_CHAT_get_key (const struct GNUNET_CHAT_Handle *handle); 489GNUNET_CHAT_get_key (const struct GNUNET_CHAT_Handle *handle);
489 490
490/** 491/**
492 * Updates an attribute of a chat handle for related communication under a given
493 * <i>name</i> and a custom <i>value</i>.
494 *
495 * @param[in,out] handle Chat handle
496 * @param[in] name Attribute name
497 * @param[in] value Attribute value
498 * @param[in] expires Expiration time or NULL
499 */
500void
501GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle,
502 const char *name,
503 const char *value,
504 const struct GNUNET_TIME_Relative *expires);
505
506/**
507 * Deletes an attribute of a chat handle for related communication under a given
508 * <i>name</i>.
509 *
510 * @param[in,out] handle Chat handle
511 * @param[in] name Attribute name
512 */
513void
514GNUNET_CHAT_delete_attribute (struct GNUNET_CHAT_Handle *handle,
515 const char *name);
516
517/**
491 * Convert an UTF-8 String to a chat URI which will be newly allocated. 518 * Convert an UTF-8 String to a chat URI which will be newly allocated.
492 * 519 *
493 * @param[in] uri UTF-8 string to parse 520 * @param[in] uri UTF-8 string to parse
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
index 25eecc6..b58a8ab 100644
--- 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,
99 handle->lookups_head = NULL; 99 handle->lookups_head = NULL;
100 handle->lookups_tail = NULL; 100 handle->lookups_tail = NULL;
101 101
102 handle->attributes_head = NULL;
103 handle->attributes_tail = NULL;
104
102 handle->tickets_head = NULL; 105 handle->tickets_head = NULL;
103 handle->tickets_tail = NULL; 106 handle->tickets_tail = NULL;
104 107
@@ -460,6 +463,29 @@ handle_disconnect (struct GNUNET_CHAT_Handle *handle)
460 GNUNET_free(lobbies); 463 GNUNET_free(lobbies);
461 } 464 }
462 465
466 struct GNUNET_CHAT_AttributeProcess *attributes;
467 while (handle->attributes_head)
468 {
469 attributes = handle->attributes_head;
470
471 if (attributes->attribute)
472 GNUNET_free(attributes->attribute);
473
474 if (attributes->iter)
475 GNUNET_RECLAIM_get_attributes_stop(attributes->iter);
476
477 if (attributes->op)
478 GNUNET_RECLAIM_cancel(attributes->op);
479
480 GNUNET_CONTAINER_DLL_remove(
481 handle->attributes_head,
482 handle->attributes_tail,
483 attributes
484 );
485
486 GNUNET_free(attributes);
487 }
488
463 GNUNET_CONTAINER_multihashmap_destroy(handle->groups); 489 GNUNET_CONTAINER_multihashmap_destroy(handle->groups);
464 GNUNET_CONTAINER_multishortmap_destroy(handle->contacts); 490 GNUNET_CONTAINER_multishortmap_destroy(handle->contacts);
465 GNUNET_CONTAINER_multihashmap_destroy(handle->contexts); 491 GNUNET_CONTAINER_multihashmap_destroy(handle->contexts);
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h
index 40667fe..33d6b95 100644
--- a/src/gnunet_chat_handle.h
+++ b/src/gnunet_chat_handle.h
@@ -31,6 +31,7 @@
31#include <gnunet/gnunet_identity_service.h> 31#include <gnunet/gnunet_identity_service.h>
32#include <gnunet/gnunet_messenger_service.h> 32#include <gnunet/gnunet_messenger_service.h>
33#include <gnunet/gnunet_namestore_service.h> 33#include <gnunet/gnunet_namestore_service.h>
34#include <gnunet/gnunet_reclaim_lib.h>
34#include <gnunet/gnunet_reclaim_service.h> 35#include <gnunet/gnunet_reclaim_service.h>
35#include <gnunet/gnunet_util_lib.h> 36#include <gnunet/gnunet_util_lib.h>
36 37
@@ -81,6 +82,19 @@ struct GNUNET_CHAT_UriLookups
81 struct GNUNET_CHAT_UriLookups *prev; 82 struct GNUNET_CHAT_UriLookups *prev;
82}; 83};
83 84
85struct GNUNET_CHAT_AttributeProcess
86{
87 struct GNUNET_CHAT_Handle *handle;
88
89 struct GNUNET_RECLAIM_Attribute *attribute;
90
91 struct GNUNET_RECLAIM_AttributeIterator *iter;
92 struct GNUNET_RECLAIM_Operation *op;
93
94 struct GNUNET_CHAT_AttributeProcess *next;
95 struct GNUNET_CHAT_AttributeProcess *prev;
96};
97
84struct GNUNET_CHAT_TicketProcess 98struct GNUNET_CHAT_TicketProcess
85{ 99{
86 struct GNUNET_CHAT_Handle *handle; 100 struct GNUNET_CHAT_Handle *handle;
@@ -120,6 +134,9 @@ struct GNUNET_CHAT_Handle
120 struct GNUNET_CHAT_UriLookups *lookups_head; 134 struct GNUNET_CHAT_UriLookups *lookups_head;
121 struct GNUNET_CHAT_UriLookups *lookups_tail; 135 struct GNUNET_CHAT_UriLookups *lookups_tail;
122 136
137 struct GNUNET_CHAT_AttributeProcess *attributes_head;
138 struct GNUNET_CHAT_AttributeProcess *attributes_tail;
139
123 struct GNUNET_CHAT_TicketProcess *tickets_head; 140 struct GNUNET_CHAT_TicketProcess *tickets_head;
124 struct GNUNET_CHAT_TicketProcess *tickets_tail; 141 struct GNUNET_CHAT_TicketProcess *tickets_tail;
125 142
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
index 46243f8..296d63b 100644
--- 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,
311 311
312 tickets->op = NULL; 312 tickets->op = NULL;
313 313
314 GNUNET_RECLAIM_ticket_iteration_next(tickets->iter); 314 struct GNUNET_CHAT_Handle *handle = tickets->handle;
315
316 if (GNUNET_SYSERR == success)
317 {
318 handle_send_internal_message(
319 handle,
320 NULL,
321 GNUNET_CHAT_KIND_WARNING,
322 emsg
323 );
324
325 if (tickets->iter)
326 GNUNET_RECLAIM_ticket_iteration_stop(tickets->iter);
327
328 return;
329 }
330
331 if (tickets->iter)
332 GNUNET_RECLAIM_ticket_iteration_next(tickets->iter);
315} 333}
316 334
317void 335void
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index 5ab0a31..644e444 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -26,6 +26,9 @@
26 26
27#include <gnunet/gnunet_common.h> 27#include <gnunet/gnunet_common.h>
28#include <gnunet/gnunet_messenger_service.h> 28#include <gnunet/gnunet_messenger_service.h>
29#include <gnunet/gnunet_reclaim_lib.h>
30#include <gnunet/gnunet_reclaim_service.h>
31#include <gnunet/gnunet_time_lib.h>
29#include <libgen.h> 32#include <libgen.h>
30#include <limits.h> 33#include <limits.h>
31#include <strings.h> 34#include <strings.h>
@@ -257,6 +260,137 @@ GNUNET_CHAT_get_key (const struct GNUNET_CHAT_Handle *handle)
257} 260}
258 261
259 262
263void
264GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle,
265 const char *name,
266 const char *value,
267 const struct GNUNET_TIME_Relative *expires)
268{
269 GNUNET_CHAT_VERSION_ASSERT();
270
271 if ((!handle) || (handle->destruction))
272 return;
273
274 const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key(
275 handle
276 );
277
278 if ((!key) || (!name))
279 return;
280
281 struct GNUNET_CHAT_AttributeProcess *attributes = GNUNET_new(
282 struct GNUNET_CHAT_AttributeProcess
283 );
284
285 memset(attributes, 0, sizeof(struct GNUNET_CHAT_AttributeProcess));
286
287 attributes->handle = handle;
288 attributes->attribute = GNUNET_RECLAIM_attribute_new(
289 name,
290 NULL,
291 GNUNET_RECLAIM_ATTRIBUTE_TYPE_NONE,
292 NULL,
293 0
294 );
295
296 if (!attributes->attribute)
297 {
298 GNUNET_free(attributes);
299 return;
300 }
301
302 if (value)
303 {
304 void *data = NULL;
305
306 enum GNUNET_GenericReturnValue result;
307 result = GNUNET_RECLAIM_attribute_string_to_value(
308 GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING,
309 value,
310 &data,
311 &(attributes->attribute->data_size)
312 );
313
314 if (GNUNET_OK != result)
315 {
316 GNUNET_free(attributes->attribute);
317 GNUNET_free(attributes);
318 return;
319 }
320
321 attributes->attribute->data = data;
322 }
323
324 attributes->op = GNUNET_RECLAIM_attribute_store(
325 handle->reclaim,
326 key,
327 attributes->attribute,
328 expires,
329 cont_update_attribute_with_status,
330 attributes
331 );
332
333 GNUNET_CONTAINER_DLL_insert_tail(
334 handle->attributes_head,
335 handle->attributes_tail,
336 attributes
337 );
338}
339
340
341void
342GNUNET_CHAT_delete_attribute (struct GNUNET_CHAT_Handle *handle,
343 const char *name)
344{
345 GNUNET_CHAT_VERSION_ASSERT();
346
347 if ((!handle) || (handle->destruction))
348 return;
349
350 const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key(
351 handle
352 );
353
354 if ((!key) || (!name))
355 return;
356
357 struct GNUNET_CHAT_AttributeProcess *attributes = GNUNET_new(
358 struct GNUNET_CHAT_AttributeProcess
359 );
360
361 memset(attributes, 0, sizeof(struct GNUNET_CHAT_AttributeProcess));
362
363 attributes->handle = handle;
364 attributes->attribute = GNUNET_RECLAIM_attribute_new(
365 name,
366 NULL,
367 GNUNET_RECLAIM_ATTRIBUTE_TYPE_NONE,
368 NULL,
369 0
370 );
371
372 if (!attributes->attribute)
373 {
374 GNUNET_free(attributes);
375 return;
376 }
377
378 attributes->op = GNUNET_RECLAIM_attribute_delete(
379 handle->reclaim,
380 key,
381 attributes->attribute,
382 cont_update_attribute_with_status,
383 attributes
384 );
385
386 GNUNET_CONTAINER_DLL_insert_tail(
387 handle->attributes_head,
388 handle->attributes_tail,
389 attributes
390 );
391}
392
393
260struct GNUNET_CHAT_Uri* 394struct GNUNET_CHAT_Uri*
261GNUNET_CHAT_uri_parse (const char *uri, 395GNUNET_CHAT_uri_parse (const char *uri,
262 char **emsg) 396 char **emsg)
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c
index b977509..32af3c8 100644
--- a/src/gnunet_chat_lib_intern.c
+++ b/src/gnunet_chat_lib_intern.c
@@ -22,6 +22,7 @@
22 * @file gnunet_chat_lib_intern.c 22 * @file gnunet_chat_lib_intern.c
23 */ 23 */
24 24
25#include <gnunet/gnunet_common.h>
25#include <stdlib.h> 26#include <stdlib.h>
26 27
27#define GNUNET_UNUSED __attribute__ ((unused)) 28#define GNUNET_UNUSED __attribute__ ((unused))
@@ -308,3 +309,37 @@ it_message_iterate_read_receipts (void *cls,
308 309
309 return GNUNET_YES; 310 return GNUNET_YES;
310} 311}
312
313void
314cont_update_attribute_with_status (void *cls,
315 int32_t success,
316 const char *emsg)
317{
318 GNUNET_assert(cls);
319
320 struct GNUNET_CHAT_AttributeProcess *attributes = (
321 (struct GNUNET_CHAT_AttributeProcess*) cls
322 );
323
324 attributes->op = NULL;
325
326 struct GNUNET_CHAT_Handle *handle = attributes->handle;
327
328 if (GNUNET_SYSERR == success)
329 {
330 handle_send_internal_message(
331 handle,
332 NULL,
333 GNUNET_CHAT_KIND_WARNING,
334 emsg
335 );
336
337 return;
338 }
339
340 GNUNET_CONTAINER_DLL_remove(
341 handle->attributes_head,
342 handle->attributes_tail,
343 attributes
344 );
345}
diff --git a/src/gnunet_chat_ticket.c b/src/gnunet_chat_ticket.c
index 4aa0066..fc18972 100644
--- 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,
48 48
49 struct GNUNET_CHAT_Ticket *ticket = GNUNET_new(struct GNUNET_CHAT_Ticket); 49 struct GNUNET_CHAT_Ticket *ticket = GNUNET_new(struct GNUNET_CHAT_Ticket);
50 50
51 memset(ticket, 0, sizeof(struct GNUNET_CHAT_Ticket));
52
53 ticket->handle = handle; 51 ticket->handle = handle;
54 ticket->issuer = issuer; 52 ticket->issuer = issuer;
55 53
54 ticket->callback = NULL;
55 ticket->closure = NULL;
56
57 ticket->op = NULL;
58
56 GNUNET_memcpy(&(ticket->ticket.identity), identity, sizeof(ticket->ticket.identity)); 59 GNUNET_memcpy(&(ticket->ticket.identity), identity, sizeof(ticket->ticket.identity));
57 GNUNET_memcpy(&(ticket->ticket.audience), audience, sizeof(ticket->ticket.audience)); 60 GNUNET_memcpy(&(ticket->ticket.audience), audience, sizeof(ticket->ticket.audience));
58 GNUNET_memcpy(&(ticket->ticket.rnd), &(message->identifier), sizeof(ticket->ticket.rnd)); 61 GNUNET_memcpy(&(ticket->ticket.rnd), &(message->identifier), sizeof(ticket->ticket.rnd));