diff options
Diffstat (limited to 'src/service/messenger/messenger_api_room.c')
-rw-r--r-- | src/service/messenger/messenger_api_room.c | 281 |
1 files changed, 205 insertions, 76 deletions
diff --git a/src/service/messenger/messenger_api_room.c b/src/service/messenger/messenger_api_room.c index c3e8bc957..1aca8a7d5 100644 --- a/src/service/messenger/messenger_api_room.c +++ b/src/service/messenger/messenger_api_room.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2020--2021 GNUnet e.V. | 3 | Copyright (C) 2020--2023 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -32,24 +32,33 @@ struct GNUNET_MESSENGER_Room* | |||
32 | create_room (struct GNUNET_MESSENGER_Handle *handle, | 32 | create_room (struct GNUNET_MESSENGER_Handle *handle, |
33 | const struct GNUNET_HashCode *key) | 33 | const struct GNUNET_HashCode *key) |
34 | { | 34 | { |
35 | GNUNET_assert((handle) && (key)); | 35 | GNUNET_assert ((handle) && (key)); |
36 | 36 | ||
37 | struct GNUNET_MESSENGER_Room *room = GNUNET_new(struct GNUNET_MESSENGER_Room); | 37 | struct GNUNET_MESSENGER_Room *room = GNUNET_new (struct |
38 | GNUNET_MESSENGER_Room); | ||
38 | 39 | ||
39 | room->handle = handle; | 40 | room->handle = handle; |
40 | GNUNET_memcpy(&(room->key), key, sizeof(*key)); | 41 | GNUNET_memcpy (&(room->key), key, sizeof(*key)); |
42 | |||
43 | memset (&(room->last_message), 0, sizeof(room->last_message)); | ||
41 | 44 | ||
42 | room->opened = GNUNET_NO; | 45 | room->opened = GNUNET_NO; |
43 | room->contact_id = NULL; | 46 | room->use_handle_name = GNUNET_YES; |
47 | room->wait_for_sync = GNUNET_NO; | ||
48 | |||
49 | room->sender_id = NULL; | ||
44 | 50 | ||
45 | init_list_tunnels (&(room->entries)); | 51 | init_list_tunnels (&(room->entries)); |
46 | 52 | ||
47 | room->messages = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | 53 | room->messages = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); |
48 | room->members = GNUNET_CONTAINER_multishortmap_create (8, GNUNET_NO); | 54 | room->members = GNUNET_CONTAINER_multishortmap_create (8, GNUNET_NO); |
49 | 55 | ||
56 | init_queue_messages (&(room->queue)); | ||
57 | |||
50 | return room; | 58 | return room; |
51 | } | 59 | } |
52 | 60 | ||
61 | |||
53 | static int | 62 | static int |
54 | iterate_destroy_message (void *cls, | 63 | iterate_destroy_message (void *cls, |
55 | const struct GNUNET_HashCode *key, | 64 | const struct GNUNET_HashCode *key, |
@@ -58,21 +67,24 @@ iterate_destroy_message (void *cls, | |||
58 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = value; | 67 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = value; |
59 | 68 | ||
60 | destroy_message (entry->message); | 69 | destroy_message (entry->message); |
61 | GNUNET_free(entry); | 70 | GNUNET_free (entry); |
62 | 71 | ||
63 | return GNUNET_YES; | 72 | return GNUNET_YES; |
64 | } | 73 | } |
65 | 74 | ||
75 | |||
66 | void | 76 | void |
67 | destroy_room (struct GNUNET_MESSENGER_Room *room) | 77 | destroy_room (struct GNUNET_MESSENGER_Room *room) |
68 | { | 78 | { |
69 | GNUNET_assert(room); | 79 | GNUNET_assert (room); |
70 | 80 | ||
81 | clear_queue_messages (&(room->queue)); | ||
71 | clear_list_tunnels (&(room->entries)); | 82 | clear_list_tunnels (&(room->entries)); |
72 | 83 | ||
73 | if (room->messages) | 84 | if (room->messages) |
74 | { | 85 | { |
75 | GNUNET_CONTAINER_multihashmap_iterate (room->messages, iterate_destroy_message, NULL); | 86 | GNUNET_CONTAINER_multihashmap_iterate (room->messages, |
87 | iterate_destroy_message, NULL); | ||
76 | 88 | ||
77 | GNUNET_CONTAINER_multihashmap_destroy (room->messages); | 89 | GNUNET_CONTAINER_multihashmap_destroy (room->messages); |
78 | } | 90 | } |
@@ -80,169 +92,274 @@ destroy_room (struct GNUNET_MESSENGER_Room *room) | |||
80 | if (room->members) | 92 | if (room->members) |
81 | GNUNET_CONTAINER_multishortmap_destroy (room->members); | 93 | GNUNET_CONTAINER_multishortmap_destroy (room->members); |
82 | 94 | ||
83 | if (room->contact_id) | 95 | if (room->sender_id) |
84 | GNUNET_free(room->contact_id); | 96 | GNUNET_free (room->sender_id); |
85 | 97 | ||
86 | GNUNET_free(room); | 98 | GNUNET_free (room); |
87 | } | 99 | } |
88 | 100 | ||
101 | |||
102 | enum GNUNET_GenericReturnValue | ||
103 | is_room_available (const struct GNUNET_MESSENGER_Room *room) | ||
104 | { | ||
105 | GNUNET_assert (room); | ||
106 | |||
107 | if (! get_room_sender_id (room)) | ||
108 | return GNUNET_NO; | ||
109 | |||
110 | if ((GNUNET_YES == room->opened) || (room->entries.head)) | ||
111 | return GNUNET_YES; | ||
112 | else | ||
113 | return GNUNET_NO; | ||
114 | } | ||
115 | |||
116 | |||
117 | const struct GNUNET_ShortHashCode* | ||
118 | get_room_sender_id (const struct GNUNET_MESSENGER_Room *room) | ||
119 | { | ||
120 | GNUNET_assert (room); | ||
121 | |||
122 | return room->sender_id; | ||
123 | } | ||
124 | |||
125 | |||
126 | void | ||
127 | set_room_sender_id (struct GNUNET_MESSENGER_Room *room, | ||
128 | const struct GNUNET_ShortHashCode *id) | ||
129 | { | ||
130 | GNUNET_assert (room); | ||
131 | |||
132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Set member id for room: %s\n", | ||
133 | GNUNET_h2s (&(room->key))); | ||
134 | |||
135 | if (! id) | ||
136 | { | ||
137 | if (room->sender_id) | ||
138 | GNUNET_free (room->sender_id); | ||
139 | |||
140 | room->sender_id = NULL; | ||
141 | return; | ||
142 | } | ||
143 | |||
144 | if (! room->sender_id) | ||
145 | room->sender_id = GNUNET_new (struct GNUNET_ShortHashCode); | ||
146 | |||
147 | GNUNET_memcpy (room->sender_id, id, sizeof(struct GNUNET_ShortHashCode)); | ||
148 | } | ||
149 | |||
150 | |||
89 | const struct GNUNET_MESSENGER_Message* | 151 | const struct GNUNET_MESSENGER_Message* |
90 | get_room_message (const struct GNUNET_MESSENGER_Room *room, | 152 | get_room_message (const struct GNUNET_MESSENGER_Room *room, |
91 | const struct GNUNET_HashCode *hash) | 153 | const struct GNUNET_HashCode *hash) |
92 | { | 154 | { |
93 | GNUNET_assert((room) && (hash)); | 155 | GNUNET_assert ((room) && (hash)); |
94 | 156 | ||
95 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = GNUNET_CONTAINER_multihashmap_get ( | 157 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = |
158 | GNUNET_CONTAINER_multihashmap_get ( | ||
96 | room->messages, hash | 159 | room->messages, hash |
97 | ); | 160 | ); |
98 | 161 | ||
99 | return (entry? entry->message : NULL); | 162 | return (entry? entry->message : NULL); |
100 | } | 163 | } |
101 | 164 | ||
165 | |||
102 | struct GNUNET_MESSENGER_Contact* | 166 | struct GNUNET_MESSENGER_Contact* |
103 | get_room_sender (const struct GNUNET_MESSENGER_Room *room, | 167 | get_room_sender (const struct GNUNET_MESSENGER_Room *room, |
104 | const struct GNUNET_HashCode *hash) | 168 | const struct GNUNET_HashCode *hash) |
105 | { | 169 | { |
106 | GNUNET_assert((room) && (hash)); | 170 | GNUNET_assert ((room) && (hash)); |
107 | 171 | ||
108 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = GNUNET_CONTAINER_multihashmap_get ( | 172 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = |
173 | GNUNET_CONTAINER_multihashmap_get ( | ||
109 | room->messages, hash | 174 | room->messages, hash |
110 | ); | 175 | ); |
111 | 176 | ||
112 | return (entry? entry->sender : NULL); | 177 | return (entry? entry->sender : NULL); |
113 | } | 178 | } |
114 | 179 | ||
180 | |||
115 | static struct GNUNET_MESSENGER_Contact* | 181 | static struct GNUNET_MESSENGER_Contact* |
116 | handle_join_message (struct GNUNET_MESSENGER_Room *room, | 182 | handle_join_message (struct GNUNET_MESSENGER_Room *room, |
117 | struct GNUNET_MESSENGER_Contact *sender, | 183 | struct GNUNET_MESSENGER_Contact *sender, |
118 | const struct GNUNET_MESSENGER_Message *message, | 184 | const struct GNUNET_MESSENGER_Message *message, |
119 | const struct GNUNET_HashCode *hash) | 185 | const struct GNUNET_HashCode *hash) |
120 | { | 186 | { |
121 | if (!sender) | 187 | if (! sender) |
122 | { | 188 | { |
123 | struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store(room->handle); | 189 | struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store ( |
190 | room->handle); | ||
124 | struct GNUNET_HashCode context; | 191 | struct GNUNET_HashCode context; |
125 | 192 | ||
126 | get_context_from_member(&(room->key), &(message->header.sender_id), &context); | 193 | get_context_from_member (&(room->key), &(message->header.sender_id), |
194 | &context); | ||
127 | 195 | ||
128 | sender = get_store_contact(store, &context, &(message->body.join.key)); | 196 | sender = get_store_contact (store, &context, &(message->body.join.key)); |
129 | } | 197 | } |
130 | 198 | ||
131 | if ((GNUNET_YES != GNUNET_CONTAINER_multishortmap_contains_value(room->members, &(message->header.sender_id), sender)) && | 199 | if ((GNUNET_YES != GNUNET_CONTAINER_multishortmap_contains_value ( |
132 | (GNUNET_OK == GNUNET_CONTAINER_multishortmap_put(room->members, &(message->header.sender_id), sender, | 200 | room->members, &(message->header.sender_id), sender)) && |
133 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE))) | 201 | (GNUNET_OK == GNUNET_CONTAINER_multishortmap_put (room->members, |
134 | increase_contact_rc(sender); | 202 | &(message->header. |
203 | sender_id), sender, | ||
204 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE))) | ||
205 | increase_contact_rc (sender); | ||
135 | 206 | ||
136 | return sender; | 207 | return sender; |
137 | } | 208 | } |
138 | 209 | ||
210 | |||
139 | static void | 211 | static void |
140 | handle_leave_message (struct GNUNET_MESSENGER_Room *room, | 212 | handle_leave_message (struct GNUNET_MESSENGER_Room *room, |
141 | struct GNUNET_MESSENGER_Contact *sender, | 213 | struct GNUNET_MESSENGER_Contact *sender, |
142 | const struct GNUNET_MESSENGER_Message *message, | 214 | const struct GNUNET_MESSENGER_Message *message, |
143 | const struct GNUNET_HashCode *hash) | 215 | const struct GNUNET_HashCode *hash) |
144 | { | 216 | { |
145 | if ((!sender) || | 217 | if ((! sender) || |
146 | (GNUNET_YES != GNUNET_CONTAINER_multishortmap_remove(room->members, &(message->header.sender_id), sender))) | 218 | (GNUNET_YES != GNUNET_CONTAINER_multishortmap_remove (room->members, |
219 | &(message->header. | ||
220 | sender_id), | ||
221 | sender))) | ||
147 | return; | 222 | return; |
148 | 223 | ||
149 | struct GNUNET_HashCode context; | 224 | if (GNUNET_YES == decrease_contact_rc (sender)) |
150 | get_context_from_member(&(room->key), &(message->header.sender_id), &context); | 225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
151 | 226 | "A contact does not share any room with you anymore!\n"); | |
152 | if (GNUNET_YES == decrease_contact_rc(sender)) | ||
153 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "A contact does not share any room with you anymore!\n"); | ||
154 | } | 227 | } |
155 | 228 | ||
229 | |||
156 | static void | 230 | static void |
157 | handle_name_message (struct GNUNET_MESSENGER_Room *room, | 231 | handle_name_message (struct GNUNET_MESSENGER_Room *room, |
158 | struct GNUNET_MESSENGER_Contact *sender, | 232 | struct GNUNET_MESSENGER_Contact *sender, |
159 | const struct GNUNET_MESSENGER_Message *message, | 233 | const struct GNUNET_MESSENGER_Message *message, |
160 | const struct GNUNET_HashCode *hash) | 234 | const struct GNUNET_HashCode *hash, |
235 | enum GNUNET_MESSENGER_MessageFlags flags) | ||
161 | { | 236 | { |
162 | if (!sender) | 237 | if (GNUNET_MESSENGER_FLAG_SENT & flags) |
238 | { | ||
239 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
240 | "Set rule for using handle name in room: %s\n", | ||
241 | GNUNET_h2s (&(room->key))); | ||
242 | |||
243 | const char *handle_name = get_handle_name (room->handle); | ||
244 | |||
245 | if ((handle_name) && (0 == strcmp (handle_name, message->body.name.name))) | ||
246 | room->use_handle_name = GNUNET_YES; | ||
247 | } | ||
248 | |||
249 | if (! sender) | ||
163 | return; | 250 | return; |
164 | 251 | ||
165 | set_contact_name (sender, message->body.name.name); | 252 | set_contact_name (sender, message->body.name.name); |
166 | } | 253 | } |
167 | 254 | ||
255 | |||
168 | static void | 256 | static void |
169 | handle_key_message (struct GNUNET_MESSENGER_Room *room, | 257 | handle_key_message (struct GNUNET_MESSENGER_Room *room, |
170 | struct GNUNET_MESSENGER_Contact *sender, | 258 | struct GNUNET_MESSENGER_Contact *sender, |
171 | const struct GNUNET_MESSENGER_Message *message, | 259 | const struct GNUNET_MESSENGER_Message *message, |
172 | const struct GNUNET_HashCode *hash) | 260 | const struct GNUNET_HashCode *hash) |
173 | { | 261 | { |
174 | if (!sender) | 262 | if (! sender) |
175 | return; | 263 | return; |
176 | 264 | ||
177 | struct GNUNET_HashCode context; | 265 | struct GNUNET_HashCode context; |
178 | get_context_from_member(&(room->key), &(message->header.sender_id), &context); | 266 | get_context_from_member (&(room->key), &(message->header.sender_id), |
267 | &context); | ||
179 | 268 | ||
180 | struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store(room->handle); | 269 | struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store ( |
270 | room->handle); | ||
181 | 271 | ||
182 | update_store_contact(store, sender, &context, &context, &(message->body.key.key)); | 272 | update_store_contact (store, sender, &context, &context, |
273 | &(message->body.key.key)); | ||
183 | } | 274 | } |
184 | 275 | ||
276 | |||
185 | static void | 277 | static void |
186 | handle_id_message (struct GNUNET_MESSENGER_Room *room, | 278 | handle_id_message (struct GNUNET_MESSENGER_Room *room, |
187 | struct GNUNET_MESSENGER_Contact *sender, | 279 | struct GNUNET_MESSENGER_Contact *sender, |
188 | const struct GNUNET_MESSENGER_Message *message, | 280 | const struct GNUNET_MESSENGER_Message *message, |
189 | const struct GNUNET_HashCode *hash) | 281 | const struct GNUNET_HashCode *hash, |
282 | enum GNUNET_MESSENGER_MessageFlags flags) | ||
190 | { | 283 | { |
191 | if ((!sender) || | 284 | if (GNUNET_MESSENGER_FLAG_SENT & flags) |
192 | (GNUNET_YES != GNUNET_CONTAINER_multishortmap_remove(room->members, &(message->header.sender_id), sender)) || | 285 | set_room_sender_id (room, &(message->body.id.id)); |
193 | (GNUNET_OK != GNUNET_CONTAINER_multishortmap_put(room->members, &(message->body.id.id), sender, | 286 | |
194 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE))) | 287 | if ((! sender) || |
288 | (GNUNET_YES != GNUNET_CONTAINER_multishortmap_remove (room->members, | ||
289 | &(message->header. | ||
290 | sender_id), | ||
291 | sender)) || | ||
292 | (GNUNET_OK != GNUNET_CONTAINER_multishortmap_put (room->members, | ||
293 | &(message->body.id.id), | ||
294 | sender, | ||
295 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE))) | ||
195 | return; | 296 | return; |
196 | 297 | ||
197 | struct GNUNET_HashCode context, next_context; | 298 | struct GNUNET_HashCode context, next_context; |
198 | get_context_from_member(&(room->key), &(message->header.sender_id), &context); | 299 | get_context_from_member (&(room->key), &(message->header.sender_id), |
199 | get_context_from_member(&(room->key), &(message->body.id.id), &next_context); | 300 | &context); |
301 | get_context_from_member (&(room->key), &(message->body.id.id), &next_context); | ||
200 | 302 | ||
201 | struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store(room->handle); | 303 | struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store ( |
304 | room->handle); | ||
202 | 305 | ||
203 | update_store_contact(store, sender, &context, &next_context, get_contact_key(sender)); | 306 | update_store_contact (store, sender, &context, &next_context, |
307 | get_contact_key (sender)); | ||
204 | } | 308 | } |
205 | 309 | ||
310 | |||
206 | static void | 311 | static void |
207 | handle_miss_message (struct GNUNET_MESSENGER_Room *room, | 312 | handle_miss_message (struct GNUNET_MESSENGER_Room *room, |
208 | struct GNUNET_MESSENGER_Contact *sender, | 313 | struct GNUNET_MESSENGER_Contact *sender, |
209 | const struct GNUNET_MESSENGER_Message *message, | 314 | const struct GNUNET_MESSENGER_Message *message, |
210 | const struct GNUNET_HashCode *hash) | 315 | const struct GNUNET_HashCode *hash, |
316 | enum GNUNET_MESSENGER_MessageFlags flags) | ||
211 | { | 317 | { |
212 | if ((room->contact_id) && (0 == GNUNET_memcmp(&(message->header.sender_id), room->contact_id))) | 318 | if (GNUNET_MESSENGER_FLAG_SENT & flags) |
213 | { | 319 | { |
214 | struct GNUNET_MESSENGER_ListTunnel *match = find_list_tunnels (&(room->entries), &(message->body.miss.peer), NULL); | 320 | struct GNUNET_MESSENGER_ListTunnel *match = find_list_tunnels ( |
321 | &(room->entries), &(message->body.miss.peer), NULL); | ||
215 | 322 | ||
216 | if (match) | 323 | if (match) |
217 | remove_from_list_tunnels (&(room->entries), match); | 324 | remove_from_list_tunnels (&(room->entries), match); |
218 | } | 325 | } |
219 | } | 326 | } |
220 | 327 | ||
328 | |||
221 | static void | 329 | static void |
222 | handle_delete_message (struct GNUNET_MESSENGER_Room *room, | 330 | handle_delete_message (struct GNUNET_MESSENGER_Room *room, |
223 | struct GNUNET_MESSENGER_Contact *sender, | 331 | struct GNUNET_MESSENGER_Contact *sender, |
224 | const struct GNUNET_MESSENGER_Message *message, | 332 | const struct GNUNET_MESSENGER_Message *message, |
225 | const struct GNUNET_HashCode *hash) | 333 | const struct GNUNET_HashCode *hash) |
226 | { | 334 | { |
227 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = GNUNET_CONTAINER_multihashmap_get ( | 335 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = |
336 | GNUNET_CONTAINER_multihashmap_get ( | ||
228 | room->messages, &(message->body.deletion.hash) | 337 | room->messages, &(message->body.deletion.hash) |
229 | ); | 338 | ); |
230 | 339 | ||
231 | if ((entry) && ((entry->sender == sender) || (get_handle_contact (room->handle, &(room->key)) == sender)) && | 340 | if ((entry) && ((entry->sender == sender) || (get_handle_contact ( |
232 | (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (room->messages, &(message->body.deletion.hash), entry))) | 341 | room->handle, &(room->key)) == |
342 | sender)) && | ||
343 | (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (room->messages, | ||
344 | &(message->body. | ||
345 | deletion.hash), | ||
346 | entry))) | ||
233 | { | 347 | { |
234 | destroy_message (entry->message); | 348 | destroy_message (entry->message); |
235 | GNUNET_free(entry); | 349 | GNUNET_free (entry); |
236 | } | 350 | } |
237 | } | 351 | } |
238 | 352 | ||
353 | |||
239 | struct GNUNET_MESSENGER_Contact* | 354 | struct GNUNET_MESSENGER_Contact* |
240 | handle_room_message (struct GNUNET_MESSENGER_Room *room, | 355 | handle_room_message (struct GNUNET_MESSENGER_Room *room, |
241 | struct GNUNET_MESSENGER_Contact *sender, | 356 | struct GNUNET_MESSENGER_Contact *sender, |
242 | const struct GNUNET_MESSENGER_Message *message, | 357 | const struct GNUNET_MESSENGER_Message *message, |
243 | const struct GNUNET_HashCode *hash) | 358 | const struct GNUNET_HashCode *hash, |
359 | enum GNUNET_MESSENGER_MessageFlags flags) | ||
244 | { | 360 | { |
245 | if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains (room->messages, hash)) | 361 | if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains (room->messages, |
362 | hash)) | ||
246 | return sender; | 363 | return sender; |
247 | 364 | ||
248 | switch (message->header.kind) | 365 | switch (message->header.kind) |
@@ -254,16 +371,16 @@ handle_room_message (struct GNUNET_MESSENGER_Room *room, | |||
254 | handle_leave_message (room, sender, message, hash); | 371 | handle_leave_message (room, sender, message, hash); |
255 | break; | 372 | break; |
256 | case GNUNET_MESSENGER_KIND_NAME: | 373 | case GNUNET_MESSENGER_KIND_NAME: |
257 | handle_name_message (room, sender, message, hash); | 374 | handle_name_message (room, sender, message, hash, flags); |
258 | break; | 375 | break; |
259 | case GNUNET_MESSENGER_KIND_KEY: | 376 | case GNUNET_MESSENGER_KIND_KEY: |
260 | handle_key_message (room, sender, message, hash); | 377 | handle_key_message (room, sender, message, hash); |
261 | break; | 378 | break; |
262 | case GNUNET_MESSENGER_KIND_ID: | 379 | case GNUNET_MESSENGER_KIND_ID: |
263 | handle_id_message (room, sender, message, hash); | 380 | handle_id_message (room, sender, message, hash, flags); |
264 | break; | 381 | break; |
265 | case GNUNET_MESSENGER_KIND_MISS: | 382 | case GNUNET_MESSENGER_KIND_MISS: |
266 | handle_miss_message (room, sender, message, hash); | 383 | handle_miss_message (room, sender, message, hash, flags); |
267 | break; | 384 | break; |
268 | case GNUNET_MESSENGER_KIND_DELETE: | 385 | case GNUNET_MESSENGER_KIND_DELETE: |
269 | handle_delete_message (room, sender, message, hash); | 386 | handle_delete_message (room, sender, message, hash); |
@@ -272,24 +389,30 @@ handle_room_message (struct GNUNET_MESSENGER_Room *room, | |||
272 | break; | 389 | break; |
273 | } | 390 | } |
274 | 391 | ||
275 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = GNUNET_new(struct GNUNET_MESSENGER_RoomMessageEntry); | 392 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = GNUNET_new (struct |
393 | GNUNET_MESSENGER_RoomMessageEntry); | ||
276 | 394 | ||
277 | if (!entry) | 395 | if (! entry) |
278 | return sender; | 396 | return sender; |
279 | 397 | ||
280 | entry->sender = sender; | 398 | entry->sender = sender; |
281 | entry->message = copy_message (message); | 399 | entry->message = copy_message (message); |
282 | 400 | ||
283 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (room->messages, hash, entry, | 401 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (room->messages, hash, |
402 | entry, | ||
284 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 403 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
285 | { | 404 | { |
286 | destroy_message (entry->message); | 405 | destroy_message (entry->message); |
287 | GNUNET_free(entry); | 406 | GNUNET_free (entry); |
288 | } | 407 | } |
289 | 408 | ||
409 | if (flags & GNUNET_MESSENGER_FLAG_RECENT) | ||
410 | GNUNET_memcpy (&(room->last_message), hash, sizeof(room->last_message)); | ||
411 | |||
290 | return sender; | 412 | return sender; |
291 | } | 413 | } |
292 | 414 | ||
415 | |||
293 | struct GNUNET_MESSENGER_MemberCall | 416 | struct GNUNET_MESSENGER_MemberCall |
294 | { | 417 | { |
295 | struct GNUNET_MESSENGER_Room *room; | 418 | struct GNUNET_MESSENGER_Room *room; |
@@ -298,25 +421,26 @@ struct GNUNET_MESSENGER_MemberCall | |||
298 | }; | 421 | }; |
299 | 422 | ||
300 | static int | 423 | static int |
301 | iterate_local_members (void* cls, | 424 | iterate_local_members (void *cls, |
302 | const struct GNUNET_ShortHashCode *key, | 425 | const struct GNUNET_ShortHashCode *key, |
303 | void *value) | 426 | void *value) |
304 | { | 427 | { |
305 | struct GNUNET_MESSENGER_MemberCall *call = cls; | 428 | struct GNUNET_MESSENGER_MemberCall *call = cls; |
306 | struct GNUNET_MESSENGER_Contact *contact = value; | 429 | struct GNUNET_MESSENGER_Contact *contact = value; |
307 | 430 | ||
308 | return call->callback(call->cls, call->room, contact); | 431 | return call->callback (call->cls, call->room, contact); |
309 | } | 432 | } |
310 | 433 | ||
434 | |||
311 | int | 435 | int |
312 | iterate_room_members (struct GNUNET_MESSENGER_Room *room, | 436 | iterate_room_members (struct GNUNET_MESSENGER_Room *room, |
313 | GNUNET_MESSENGER_MemberCallback callback, | 437 | GNUNET_MESSENGER_MemberCallback callback, |
314 | void* cls) | 438 | void *cls) |
315 | { | 439 | { |
316 | GNUNET_assert(room); | 440 | GNUNET_assert (room); |
317 | 441 | ||
318 | if (!callback) | 442 | if (! callback) |
319 | return GNUNET_CONTAINER_multishortmap_iterate(room->members, NULL, NULL); | 443 | return GNUNET_CONTAINER_multishortmap_iterate (room->members, NULL, NULL); |
320 | 444 | ||
321 | struct GNUNET_MESSENGER_MemberCall call; | 445 | struct GNUNET_MESSENGER_MemberCall call; |
322 | 446 | ||
@@ -324,11 +448,14 @@ iterate_room_members (struct GNUNET_MESSENGER_Room *room, | |||
324 | call.callback = callback; | 448 | call.callback = callback; |
325 | call.cls = cls; | 449 | call.cls = cls; |
326 | 450 | ||
327 | GNUNET_assert(callback); | 451 | GNUNET_assert (callback); |
328 | 452 | ||
329 | return GNUNET_CONTAINER_multishortmap_iterate(room->members, iterate_local_members, &call); | 453 | return GNUNET_CONTAINER_multishortmap_iterate (room->members, |
454 | iterate_local_members, | ||
455 | &call); | ||
330 | } | 456 | } |
331 | 457 | ||
458 | |||
332 | struct GNUNET_MESSENGER_MemberFind | 459 | struct GNUNET_MESSENGER_MemberFind |
333 | { | 460 | { |
334 | const struct GNUNET_MESSENGER_Contact *contact; | 461 | const struct GNUNET_MESSENGER_Contact *contact; |
@@ -336,7 +463,7 @@ struct GNUNET_MESSENGER_MemberFind | |||
336 | }; | 463 | }; |
337 | 464 | ||
338 | static int | 465 | static int |
339 | iterate_find_member (void* cls, | 466 | iterate_find_member (void *cls, |
340 | const struct GNUNET_ShortHashCode *key, | 467 | const struct GNUNET_ShortHashCode *key, |
341 | void *value) | 468 | void *value) |
342 | { | 469 | { |
@@ -352,18 +479,20 @@ iterate_find_member (void* cls, | |||
352 | return GNUNET_YES; | 479 | return GNUNET_YES; |
353 | } | 480 | } |
354 | 481 | ||
482 | |||
355 | int | 483 | int |
356 | find_room_member (const struct GNUNET_MESSENGER_Room *room, | 484 | find_room_member (const struct GNUNET_MESSENGER_Room *room, |
357 | const struct GNUNET_MESSENGER_Contact *contact) | 485 | const struct GNUNET_MESSENGER_Contact *contact) |
358 | { | 486 | { |
359 | GNUNET_assert(room); | 487 | GNUNET_assert (room); |
360 | 488 | ||
361 | struct GNUNET_MESSENGER_MemberFind find; | 489 | struct GNUNET_MESSENGER_MemberFind find; |
362 | 490 | ||
363 | find.contact = contact; | 491 | find.contact = contact; |
364 | find.result = GNUNET_NO; | 492 | find.result = GNUNET_NO; |
365 | 493 | ||
366 | GNUNET_CONTAINER_multishortmap_iterate(room->members, iterate_find_member, &find); | 494 | GNUNET_CONTAINER_multishortmap_iterate (room->members, iterate_find_member, |
495 | &find); | ||
367 | 496 | ||
368 | return find.result; | 497 | return find.result; |
369 | } | 498 | } |