diff options
Diffstat (limited to 'src/messenger/messenger_api_room.c')
-rw-r--r-- | src/messenger/messenger_api_room.c | 75 |
1 files changed, 51 insertions, 24 deletions
diff --git a/src/messenger/messenger_api_room.c b/src/messenger/messenger_api_room.c index 0d9237a2e..6e2d33f48 100644 --- a/src/messenger/messenger_api_room.c +++ b/src/messenger/messenger_api_room.c | |||
@@ -28,7 +28,8 @@ | |||
28 | #include "messenger_api_handle.h" | 28 | #include "messenger_api_handle.h" |
29 | 29 | ||
30 | struct GNUNET_MESSENGER_Room* | 30 | struct GNUNET_MESSENGER_Room* |
31 | create_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key) | 31 | create_room (struct GNUNET_MESSENGER_Handle *handle, |
32 | const struct GNUNET_HashCode *key) | ||
32 | { | 33 | { |
33 | GNUNET_assert((handle) && (key)); | 34 | GNUNET_assert((handle) && (key)); |
34 | 35 | ||
@@ -49,7 +50,9 @@ create_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCod | |||
49 | } | 50 | } |
50 | 51 | ||
51 | static int | 52 | static int |
52 | iterate_destroy_message (void *cls, const struct GNUNET_HashCode *key, void *value) | 53 | iterate_destroy_message (void *cls, |
54 | const struct GNUNET_HashCode *key, | ||
55 | void *value) | ||
53 | { | 56 | { |
54 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = value; | 57 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = value; |
55 | 58 | ||
@@ -83,7 +86,8 @@ destroy_room (struct GNUNET_MESSENGER_Room *room) | |||
83 | } | 86 | } |
84 | 87 | ||
85 | const struct GNUNET_MESSENGER_Message* | 88 | const struct GNUNET_MESSENGER_Message* |
86 | get_room_message (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash) | 89 | get_room_message (const struct GNUNET_MESSENGER_Room *room, |
90 | const struct GNUNET_HashCode *hash) | ||
87 | { | 91 | { |
88 | GNUNET_assert((room) && (hash)); | 92 | GNUNET_assert((room) && (hash)); |
89 | 93 | ||
@@ -95,7 +99,8 @@ get_room_message (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_ | |||
95 | } | 99 | } |
96 | 100 | ||
97 | struct GNUNET_MESSENGER_Contact* | 101 | struct GNUNET_MESSENGER_Contact* |
98 | get_room_sender (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash) | 102 | get_room_sender (const struct GNUNET_MESSENGER_Room *room, |
103 | const struct GNUNET_HashCode *hash) | ||
99 | { | 104 | { |
100 | GNUNET_assert((room) && (hash)); | 105 | GNUNET_assert((room) && (hash)); |
101 | 106 | ||
@@ -107,8 +112,10 @@ get_room_sender (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_H | |||
107 | } | 112 | } |
108 | 113 | ||
109 | static struct GNUNET_MESSENGER_Contact* | 114 | static struct GNUNET_MESSENGER_Contact* |
110 | handle_join_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, | 115 | handle_join_message (struct GNUNET_MESSENGER_Room *room, |
111 | const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | 116 | struct GNUNET_MESSENGER_Contact *sender, |
117 | const struct GNUNET_MESSENGER_Message *message, | ||
118 | const struct GNUNET_HashCode *hash) | ||
112 | { | 119 | { |
113 | if (!sender) | 120 | if (!sender) |
114 | { | 121 | { |
@@ -129,8 +136,10 @@ handle_join_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER | |||
129 | } | 136 | } |
130 | 137 | ||
131 | static void | 138 | static void |
132 | handle_leave_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, | 139 | handle_leave_message (struct GNUNET_MESSENGER_Room *room, |
133 | const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | 140 | struct GNUNET_MESSENGER_Contact *sender, |
141 | const struct GNUNET_MESSENGER_Message *message, | ||
142 | const struct GNUNET_HashCode *hash) | ||
134 | { | 143 | { |
135 | if ((!sender) || | 144 | if ((!sender) || |
136 | (GNUNET_YES != GNUNET_CONTAINER_multishortmap_remove(room->members, &(message->header.sender_id), sender))) | 145 | (GNUNET_YES != GNUNET_CONTAINER_multishortmap_remove(room->members, &(message->header.sender_id), sender))) |
@@ -144,8 +153,10 @@ handle_leave_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGE | |||
144 | } | 153 | } |
145 | 154 | ||
146 | static void | 155 | static void |
147 | handle_name_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, | 156 | handle_name_message (struct GNUNET_MESSENGER_Room *room, |
148 | const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | 157 | struct GNUNET_MESSENGER_Contact *sender, |
158 | const struct GNUNET_MESSENGER_Message *message, | ||
159 | const struct GNUNET_HashCode *hash) | ||
149 | { | 160 | { |
150 | if (!sender) | 161 | if (!sender) |
151 | return; | 162 | return; |
@@ -154,8 +165,10 @@ handle_name_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER | |||
154 | } | 165 | } |
155 | 166 | ||
156 | static void | 167 | static void |
157 | handle_key_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, | 168 | handle_key_message (struct GNUNET_MESSENGER_Room *room, |
158 | const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | 169 | struct GNUNET_MESSENGER_Contact *sender, |
170 | const struct GNUNET_MESSENGER_Message *message, | ||
171 | const struct GNUNET_HashCode *hash) | ||
159 | { | 172 | { |
160 | if (!sender) | 173 | if (!sender) |
161 | return; | 174 | return; |
@@ -169,8 +182,10 @@ handle_key_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_ | |||
169 | } | 182 | } |
170 | 183 | ||
171 | static void | 184 | static void |
172 | handle_id_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, | 185 | handle_id_message (struct GNUNET_MESSENGER_Room *room, |
173 | const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | 186 | struct GNUNET_MESSENGER_Contact *sender, |
187 | const struct GNUNET_MESSENGER_Message *message, | ||
188 | const struct GNUNET_HashCode *hash) | ||
174 | { | 189 | { |
175 | if ((!sender) || | 190 | if ((!sender) || |
176 | (GNUNET_YES != GNUNET_CONTAINER_multishortmap_remove(room->members, &(message->header.sender_id), sender)) || | 191 | (GNUNET_YES != GNUNET_CONTAINER_multishortmap_remove(room->members, &(message->header.sender_id), sender)) || |
@@ -188,8 +203,10 @@ handle_id_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_C | |||
188 | } | 203 | } |
189 | 204 | ||
190 | static void | 205 | static void |
191 | handle_miss_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, | 206 | handle_miss_message (struct GNUNET_MESSENGER_Room *room, |
192 | const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | 207 | struct GNUNET_MESSENGER_Contact *sender, |
208 | const struct GNUNET_MESSENGER_Message *message, | ||
209 | const struct GNUNET_HashCode *hash) | ||
193 | { | 210 | { |
194 | if ((room->contact_id) && (0 == GNUNET_memcmp(&(message->header.sender_id), room->contact_id))) | 211 | if ((room->contact_id) && (0 == GNUNET_memcmp(&(message->header.sender_id), room->contact_id))) |
195 | { | 212 | { |
@@ -201,8 +218,10 @@ handle_miss_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER | |||
201 | } | 218 | } |
202 | 219 | ||
203 | static void | 220 | static void |
204 | handle_delete_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, | 221 | handle_delete_message (struct GNUNET_MESSENGER_Room *room, |
205 | const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | 222 | struct GNUNET_MESSENGER_Contact *sender, |
223 | const struct GNUNET_MESSENGER_Message *message, | ||
224 | const struct GNUNET_HashCode *hash) | ||
206 | { | 225 | { |
207 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = GNUNET_CONTAINER_multihashmap_get ( | 226 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = GNUNET_CONTAINER_multihashmap_get ( |
208 | room->messages, &(message->body.deletion.hash) | 227 | room->messages, &(message->body.deletion.hash) |
@@ -217,8 +236,10 @@ handle_delete_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENG | |||
217 | } | 236 | } |
218 | 237 | ||
219 | struct GNUNET_MESSENGER_Contact* | 238 | struct GNUNET_MESSENGER_Contact* |
220 | handle_room_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, | 239 | handle_room_message (struct GNUNET_MESSENGER_Room *room, |
221 | const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | 240 | struct GNUNET_MESSENGER_Contact *sender, |
241 | const struct GNUNET_MESSENGER_Message *message, | ||
242 | const struct GNUNET_HashCode *hash) | ||
222 | { | 243 | { |
223 | if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains (room->messages, hash)) | 244 | if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains (room->messages, hash)) |
224 | return sender; | 245 | return sender; |
@@ -276,7 +297,9 @@ struct GNUNET_MESSENGER_MemberCall | |||
276 | }; | 297 | }; |
277 | 298 | ||
278 | static int | 299 | static int |
279 | iterate_local_members (void* cls, const struct GNUNET_ShortHashCode *key, void *value) | 300 | iterate_local_members (void* cls, |
301 | const struct GNUNET_ShortHashCode *key, | ||
302 | void *value) | ||
280 | { | 303 | { |
281 | struct GNUNET_MESSENGER_MemberCall *call = cls; | 304 | struct GNUNET_MESSENGER_MemberCall *call = cls; |
282 | struct GNUNET_MESSENGER_Contact *contact = value; | 305 | struct GNUNET_MESSENGER_Contact *contact = value; |
@@ -285,7 +308,8 @@ iterate_local_members (void* cls, const struct GNUNET_ShortHashCode *key, void * | |||
285 | } | 308 | } |
286 | 309 | ||
287 | int | 310 | int |
288 | iterate_room_members (struct GNUNET_MESSENGER_Room *room, GNUNET_MESSENGER_MemberCallback callback, | 311 | iterate_room_members (struct GNUNET_MESSENGER_Room *room, |
312 | GNUNET_MESSENGER_MemberCallback callback, | ||
289 | void* cls) | 313 | void* cls) |
290 | { | 314 | { |
291 | GNUNET_assert(room); | 315 | GNUNET_assert(room); |
@@ -311,7 +335,9 @@ struct GNUNET_MESSENGER_MemberFind | |||
311 | }; | 335 | }; |
312 | 336 | ||
313 | static int | 337 | static int |
314 | iterate_find_member (void* cls, const struct GNUNET_ShortHashCode *key, void *value) | 338 | iterate_find_member (void* cls, |
339 | const struct GNUNET_ShortHashCode *key, | ||
340 | void *value) | ||
315 | { | 341 | { |
316 | struct GNUNET_MESSENGER_MemberFind *find = cls; | 342 | struct GNUNET_MESSENGER_MemberFind *find = cls; |
317 | struct GNUNET_MESSENGER_Contact *contact = value; | 343 | struct GNUNET_MESSENGER_Contact *contact = value; |
@@ -326,7 +352,8 @@ iterate_find_member (void* cls, const struct GNUNET_ShortHashCode *key, void *va | |||
326 | } | 352 | } |
327 | 353 | ||
328 | int | 354 | int |
329 | find_room_member (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *contact) | 355 | find_room_member (const struct GNUNET_MESSENGER_Room *room, |
356 | const struct GNUNET_MESSENGER_Contact *contact) | ||
330 | { | 357 | { |
331 | GNUNET_assert(room); | 358 | GNUNET_assert(room); |
332 | 359 | ||