diff options
Diffstat (limited to 'src/gnunet_chat_context.c')
-rw-r--r-- | src/gnunet_chat_context.c | 72 |
1 files changed, 21 insertions, 51 deletions
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c index a4f3db0..c1e792c 100644 --- a/src/gnunet_chat_context.c +++ b/src/gnunet_chat_context.c | |||
@@ -42,6 +42,7 @@ context_create_from_room (struct GNUNET_CHAT_Handle *handle, | |||
42 | context->type = GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN; | 42 | context->type = GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN; |
43 | context->nick = NULL; | 43 | context->nick = NULL; |
44 | context->topic = NULL; | 44 | context->topic = NULL; |
45 | context->deleted = GNUNET_NO; | ||
45 | 46 | ||
46 | context->timestamps = GNUNET_CONTAINER_multishortmap_create(8, GNUNET_NO); | 47 | context->timestamps = GNUNET_CONTAINER_multishortmap_create(8, GNUNET_NO); |
47 | context->messages = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); | 48 | context->messages = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); |
@@ -57,6 +58,8 @@ context_create_from_room (struct GNUNET_CHAT_Handle *handle, | |||
57 | 8, GNUNET_NO | 58 | 8, GNUNET_NO |
58 | ); | 59 | ); |
59 | 60 | ||
61 | context->query = NULL; | ||
62 | |||
60 | return context; | 63 | return context; |
61 | } | 64 | } |
62 | 65 | ||
@@ -73,6 +76,7 @@ context_create_from_contact (struct GNUNET_CHAT_Handle *handle, | |||
73 | context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; | 76 | context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; |
74 | context->nick = NULL; | 77 | context->nick = NULL; |
75 | context->topic = NULL; | 78 | context->topic = NULL; |
79 | context->deleted = GNUNET_NO; | ||
76 | 80 | ||
77 | context->timestamps = GNUNET_CONTAINER_multishortmap_create(4, GNUNET_NO); | 81 | context->timestamps = GNUNET_CONTAINER_multishortmap_create(4, GNUNET_NO); |
78 | context->messages = GNUNET_CONTAINER_multihashmap_create(4, GNUNET_NO); | 82 | context->messages = GNUNET_CONTAINER_multihashmap_create(4, GNUNET_NO); |
@@ -88,6 +92,8 @@ context_create_from_contact (struct GNUNET_CHAT_Handle *handle, | |||
88 | 8, GNUNET_NO | 92 | 8, GNUNET_NO |
89 | ); | 93 | ); |
90 | 94 | ||
95 | context->query = NULL; | ||
96 | |||
91 | return context; | 97 | return context; |
92 | } | 98 | } |
93 | 99 | ||
@@ -100,6 +106,9 @@ context_destroy (struct GNUNET_CHAT_Context *context) | |||
100 | (context->invites) && | 106 | (context->invites) && |
101 | (context->files)); | 107 | (context->files)); |
102 | 108 | ||
109 | if (context->query) | ||
110 | GNUNET_NAMESTORE_cancel(context->query); | ||
111 | |||
103 | GNUNET_CONTAINER_multishortmap_iterate( | 112 | GNUNET_CONTAINER_multishortmap_iterate( |
104 | context->timestamps, it_destroy_context_timestamps, NULL | 113 | context->timestamps, it_destroy_context_timestamps, NULL |
105 | ); | 114 | ); |
@@ -292,14 +301,21 @@ context_write_records (struct GNUNET_CHAT_Context *context) | |||
292 | topic = NULL; | 301 | topic = NULL; |
293 | } | 302 | } |
294 | 303 | ||
295 | unsigned int count = 1; | 304 | char *label; |
305 | util_get_context_label(context->type, hash, &label); | ||
296 | 306 | ||
307 | unsigned int count = 0; | ||
297 | struct GNUNET_GNSRECORD_Data data [3]; | 308 | struct GNUNET_GNSRECORD_Data data [3]; |
309 | |||
310 | if (GNUNET_YES == context->deleted) | ||
311 | goto skip_record_data; | ||
312 | |||
298 | data[0].record_type = GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY; | 313 | data[0].record_type = GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY; |
299 | data[0].data = &room; | 314 | data[0].data = &room; |
300 | data[0].data_size = sizeof(room); | 315 | data[0].data_size = sizeof(room); |
301 | data[0].expiration_time = expiration.abs_value_us; | 316 | data[0].expiration_time = expiration.abs_value_us; |
302 | data[0].flags = GNUNET_GNSRECORD_RF_PRIVATE; | 317 | data[0].flags = GNUNET_GNSRECORD_RF_PRIVATE; |
318 | count++; | ||
303 | 319 | ||
304 | if (nick) | 320 | if (nick) |
305 | { | 321 | { |
@@ -329,9 +345,7 @@ context_write_records (struct GNUNET_CHAT_Context *context) | |||
329 | count++; | 345 | count++; |
330 | } | 346 | } |
331 | 347 | ||
332 | char *label; | 348 | skip_record_data: |
333 | util_get_context_label(context->type, hash, &label); | ||
334 | |||
335 | GNUNET_NAMESTORE_records_store( | 349 | GNUNET_NAMESTORE_records_store( |
336 | context->handle->namestore, | 350 | context->handle->namestore, |
337 | zone, | 351 | zone, |
@@ -348,52 +362,8 @@ context_write_records (struct GNUNET_CHAT_Context *context) | |||
348 | void | 362 | void |
349 | context_delete_records (struct GNUNET_CHAT_Context *context) | 363 | context_delete_records (struct GNUNET_CHAT_Context *context) |
350 | { | 364 | { |
351 | GNUNET_assert((context) && | 365 | GNUNET_assert(context); |
352 | (context->handle) && | ||
353 | (context->room)); | ||
354 | |||
355 | const struct GNUNET_IDENTITY_PrivateKey *zone = handle_get_key( | ||
356 | context->handle | ||
357 | ); | ||
358 | |||
359 | if (!zone) | ||
360 | return; | ||
361 | |||
362 | const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key( | ||
363 | context->room | ||
364 | ); | ||
365 | |||
366 | const char *type_string = "chat"; | ||
367 | |||
368 | switch (context->type) | ||
369 | { | ||
370 | case GNUNET_CHAT_CONTEXT_TYPE_CONTACT: | ||
371 | type_string = "contact"; | ||
372 | break; | ||
373 | case GNUNET_CHAT_CONTEXT_TYPE_GROUP: | ||
374 | type_string = "group"; | ||
375 | break; | ||
376 | default: | ||
377 | break; | ||
378 | } | ||
379 | |||
380 | char *label; | ||
381 | GNUNET_asprintf ( | ||
382 | &label, | ||
383 | "%s_%s", | ||
384 | type_string, | ||
385 | GNUNET_h2s(hash) | ||
386 | ); | ||
387 | |||
388 | GNUNET_NAMESTORE_records_store( | ||
389 | context->handle->namestore, | ||
390 | zone, | ||
391 | label, | ||
392 | 0, | ||
393 | NULL, | ||
394 | cont_context_write_records, | ||
395 | context | ||
396 | ); | ||
397 | 366 | ||
398 | GNUNET_free(label); | 367 | context->deleted = GNUNET_YES; |
368 | context_write_records(context); | ||
399 | } | 369 | } |