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