aboutsummaryrefslogtreecommitdiff
path: root/src/service/messenger/messenger_api_room.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/messenger/messenger_api_room.c')
-rw-r--r--src/service/messenger/messenger_api_room.c45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/service/messenger/messenger_api_room.c b/src/service/messenger/messenger_api_room.c
index e1970b668..e83c9d7d3 100644
--- a/src/service/messenger/messenger_api_room.c
+++ b/src/service/messenger/messenger_api_room.c
@@ -27,10 +27,13 @@
27 27
28#include "gnunet_common.h" 28#include "gnunet_common.h"
29#include "gnunet_messenger_service.h" 29#include "gnunet_messenger_service.h"
30
30#include "messenger_api_contact_store.h" 31#include "messenger_api_contact_store.h"
31#include "messenger_api_handle.h" 32#include "messenger_api_handle.h"
32#include "messenger_api_message.h" 33#include "messenger_api_message.h"
33#include "messenger_api_message_control.h" 34#include "messenger_api_message_control.h"
35#include "messenger_api_message_kind.h"
36
34#include <string.h> 37#include <string.h>
35 38
36struct GNUNET_MESSENGER_Room* 39struct GNUNET_MESSENGER_Room*
@@ -59,7 +62,10 @@ create_room (struct GNUNET_MESSENGER_Handle *handle,
59 room->members = GNUNET_CONTAINER_multishortmap_create (8, GNUNET_NO); 62 room->members = GNUNET_CONTAINER_multishortmap_create (8, GNUNET_NO);
60 room->links = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); 63 room->links = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO);
61 64
65 room->subscriptions = GNUNET_CONTAINER_multishortmap_create (8, GNUNET_NO);
66
62 init_queue_messages (&(room->queue)); 67 init_queue_messages (&(room->queue));
68 room->queue_task = NULL;
63 69
64 room->control = create_message_control (room); 70 room->control = create_message_control (room);
65 71
@@ -92,6 +98,24 @@ iterate_destroy_link (void *cls,
92} 98}
93 99
94 100
101static enum GNUNET_GenericReturnValue
102iterate_destroy_subscription (void *cls,
103 const struct GNUNET_ShortHashCode *key,
104 void *value)
105{
106 struct GNUNET_MESSENGER_RoomSubscription *subscription = value;
107
108 if (subscription->task)
109 GNUNET_SCHEDULER_cancel (subscription->task);
110
111 if (subscription->message)
112 destroy_message (subscription->message);
113
114 GNUNET_free (subscription);
115 return GNUNET_YES;
116}
117
118
95void 119void
96destroy_room (struct GNUNET_MESSENGER_Room *room) 120destroy_room (struct GNUNET_MESSENGER_Room *room)
97{ 121{
@@ -99,9 +123,21 @@ destroy_room (struct GNUNET_MESSENGER_Room *room)
99 123
100 destroy_message_control (room->control); 124 destroy_message_control (room->control);
101 125
126 if (room->queue_task)
127 GNUNET_SCHEDULER_cancel (room->queue_task);
128
102 clear_queue_messages (&(room->queue)); 129 clear_queue_messages (&(room->queue));
103 clear_list_tunnels (&(room->entries)); 130 clear_list_tunnels (&(room->entries));
104 131
132 if (room->subscriptions)
133 {
134 GNUNET_CONTAINER_multishortmap_iterate (room->subscriptions,
135 iterate_destroy_subscription,
136 NULL);
137
138 GNUNET_CONTAINER_multishortmap_destroy (room->subscriptions);
139 }
140
105 if (room->messages) 141 if (room->messages)
106 { 142 {
107 GNUNET_CONTAINER_multihashmap_iterate (room->messages, 143 GNUNET_CONTAINER_multihashmap_iterate (room->messages,
@@ -300,6 +336,7 @@ handle_join_message (struct GNUNET_MESSENGER_Room *room,
300 .sender_id), 336 .sender_id),
301 entry->sender, 337 entry->sender,
302 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE))) 338 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)))
339
303 increase_contact_rc (entry->sender); 340 increase_contact_rc (entry->sender);
304} 341}
305 342
@@ -393,6 +430,7 @@ handle_id_message (struct GNUNET_MESSENGER_Room *room,
393 id.id), 430 id.id),
394 entry->sender, 431 entry->sender,
395 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE))) 432 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)))
433
396 return; 434 return;
397 435
398 struct GNUNET_HashCode context, next_context; 436 struct GNUNET_HashCode context, next_context;
@@ -574,7 +612,8 @@ read_transcript:
574 612
575 original->recipient = get_store_contact (store, 613 original->recipient = get_store_contact (store,
576 NULL, 614 NULL,
577 &(entry->message->body.transcript.key)); 615 &(entry->message->body.transcript.key
616 ));
578 617
579 if (original->message) 618 if (original->message)
580 { 619 {
@@ -826,12 +865,14 @@ link_room_message (struct GNUNET_MESSENGER_Room *room,
826 return; 865 return;
827 866
828 struct GNUNET_HashCode *value = GNUNET_memdup (other, sizeof(struct 867 struct GNUNET_HashCode *value = GNUNET_memdup (other, sizeof(struct
829 GNUNET_HashCode)); 868 GNUNET_HashCode))
869 ;
830 if (! value) 870 if (! value)
831 return; 871 return;
832 872
833 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (room->links, hash, value, 873 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (room->links, hash, value,
834 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)) 874 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE))
875
835 GNUNET_free (value); 876 GNUNET_free (value);
836} 877}
837 878