aboutsummaryrefslogtreecommitdiff
path: root/src/service/messenger/messenger_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/messenger/messenger_api.c')
-rw-r--r--src/service/messenger/messenger_api.c102
1 files changed, 12 insertions, 90 deletions
diff --git a/src/service/messenger/messenger_api.c b/src/service/messenger/messenger_api.c
index 7623e21c5..dc2e6045a 100644
--- a/src/service/messenger/messenger_api.c
+++ b/src/service/messenger/messenger_api.c
@@ -24,7 +24,6 @@
24 */ 24 */
25 25
26#include "gnunet_common.h" 26#include "gnunet_common.h"
27#include "gnunet_core_service.h"
28#include "gnunet_messenger_service.h" 27#include "gnunet_messenger_service.h"
29 28
30#include "gnunet-service-messenger.h" 29#include "gnunet-service-messenger.h"
@@ -109,7 +108,7 @@ handle_room_open (void *cls,
109 if (! room) 108 if (! room)
110 return; 109 return;
111 110
112 GNUNET_memcpy (&(room->last_message), prev, sizeof(room->last_message)); 111 update_room_last_message (room, prev);
113 112
114 dequeue_messages_from_room (room); 113 dequeue_messages_from_room (room);
115} 114}
@@ -134,7 +133,7 @@ handle_room_entry (void *cls,
134 if (! room) 133 if (! room)
135 return; 134 return;
136 135
137 GNUNET_memcpy (&(room->last_message), prev, sizeof(room->last_message)); 136 update_room_last_message (room, prev);
138 137
139 dequeue_messages_from_room (room); 138 dequeue_messages_from_room (room);
140} 139}
@@ -152,7 +151,7 @@ handle_room_close (void *cls,
152 struct GNUNET_MESSENGER_Room *room = get_handle_room (handle, key); 151 struct GNUNET_MESSENGER_Room *room = get_handle_room (handle, key);
153 152
154 if (room) 153 if (room)
155 GNUNET_memcpy (&(room->last_message), prev, sizeof(room->last_message)); 154 update_room_last_message (room, prev);
156 155
157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Closed room: %s\n", GNUNET_h2s (key)); 156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Closed room: %s\n", GNUNET_h2s (key));
158 157
@@ -174,7 +173,7 @@ handle_room_sync (void *cls,
174 if (! room) 173 if (! room)
175 return; 174 return;
176 175
177 GNUNET_memcpy (&(room->last_message), prev, sizeof(room->last_message)); 176 update_room_last_message (room, prev);
178 177
179 room->wait_for_sync = GNUNET_NO; 178 room->wait_for_sync = GNUNET_NO;
180 179
@@ -225,12 +224,6 @@ handle_member_id (void *cls,
225} 224}
226 225
227 226
228static void
229delete_message_in_room (struct GNUNET_MESSENGER_Room *room,
230 const struct GNUNET_HashCode *hash,
231 const struct GNUNET_TIME_Relative delay);
232
233
234static enum GNUNET_GenericReturnValue 227static enum GNUNET_GenericReturnValue
235check_recv_message (void *cls, 228check_recv_message (void *cls,
236 const struct GNUNET_MESSENGER_RecvMessage *msg) 229 const struct GNUNET_MESSENGER_RecvMessage *msg)
@@ -281,8 +274,7 @@ handle_recv_message (void *cls,
281 const struct GNUNET_HashCode *hash = &(msg->hash); 274 const struct GNUNET_HashCode *hash = &(msg->hash);
282 275
283 enum GNUNET_MESSENGER_MessageFlags flags = ( 276 enum GNUNET_MESSENGER_MessageFlags flags = (
284 (enum GNUNET_MESSENGER_MessageFlags) (msg->flags) 277 (enum GNUNET_MESSENGER_MessageFlags) (msg->flags));
285 );
286 278
287 const uint16_t length = ntohs (msg->header.size) - sizeof(*msg); 279 const uint16_t length = ntohs (msg->header.size) - sizeof(*msg);
288 const char *buffer = ((const char*) msg) + sizeof(*msg); 280 const char *buffer = ((const char*) msg) + sizeof(*msg);
@@ -290,28 +282,8 @@ handle_recv_message (void *cls,
290 struct GNUNET_MESSENGER_Message message; 282 struct GNUNET_MESSENGER_Message message;
291 decode_message (&message, length, buffer, GNUNET_YES, NULL); 283 decode_message (&message, length, buffer, GNUNET_YES, NULL);
292 284
293 struct GNUNET_MESSENGER_Message *private_message = NULL;
294 const struct GNUNET_MESSENGER_Message *handle_msg = &message;
295
296 if (GNUNET_MESSENGER_KIND_PRIVATE == message.header.kind)
297 {
298 private_message = copy_message (&message);
299
300 if (GNUNET_YES != decrypt_message (private_message, get_handle_key (
301 handle)))
302 {
303 destroy_message (private_message);
304 private_message = NULL;
305 }
306 }
307
308 if (private_message)
309 flags |= GNUNET_MESSENGER_FLAG_PRIVATE;
310
311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message: %s\n", 285 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message: %s\n",
312 GNUNET_MESSENGER_name_of_kind (private_message ? 286 GNUNET_MESSENGER_name_of_kind (message.header.kind));
313 private_message->header.kind :
314 message.header.kind));
315 287
316 struct GNUNET_MESSENGER_Room *room = get_handle_room (handle, key); 288 struct GNUNET_MESSENGER_Room *room = get_handle_room (handle, key);
317 289
@@ -332,66 +304,16 @@ handle_recv_message (void *cls,
332 304
333 struct GNUNET_MESSENGER_Contact *contact = get_store_contact_raw ( 305 struct GNUNET_MESSENGER_Contact *contact = get_store_contact_raw (
334 store, context, sender); 306 store, context, sender);
335
336 struct GNUNET_MESSENGER_Contact *recipient = NULL;
337
338 if (!private_message)
339 goto skip_recipient;
340
341 const struct GNUNET_CRYPTO_PublicKey *recipient_key;
342
343 if (GNUNET_MESSENGER_KIND_TRANSCRIPT == private_message->header.kind)
344 {
345 struct GNUNET_MESSENGER_Message *transcript;
346 307
347 recipient_key = &(private_message->body.transcript.key); 308 handle_room_message (room, contact, &message, hash, flags);
348 transcript = read_transcript_message(private_message);
349 309
350 if (transcript) 310 if (flags & GNUNET_MESSENGER_FLAG_RECENT)
351 { 311 update_room_last_message (room, hash);
352 destroy_message(private_message);
353 private_message = transcript;
354 }
355 }
356 else
357 recipient_key = get_handle_pubkey(handle);
358 312
359 recipient = get_store_contact(store, context, recipient_key); 313 callback_room_message (room, hash);
360
361skip_recipient:
362 if (private_message)
363 handle_msg = private_message;
364
365 if ((GNUNET_MESSENGER_KIND_DELETE == handle_msg->header.kind) &&
366 (GNUNET_MESSENGER_FLAG_SENT & flags))
367 {
368 struct GNUNET_TIME_Relative delay;
369 struct GNUNET_TIME_Absolute action;
370
371 delay = GNUNET_TIME_relative_ntoh (handle_msg->body.deletion.delay);
372
373 action = GNUNET_TIME_absolute_ntoh (handle_msg->header.timestamp);
374 action = GNUNET_TIME_absolute_add (action, delay);
375
376 delay = GNUNET_TIME_absolute_get_difference (GNUNET_TIME_absolute_get (), action);
377
378 link_room_deletion (room, &(handle_msg->body.deletion.hash), delay, delete_message_in_room);
379 }
380
381 contact = handle_room_message (room, contact, recipient, handle_msg, hash, flags);
382
383 const struct GNUNET_MESSENGER_Message *stored_message = get_room_message (
384 room, hash);
385
386 if (handle->msg_callback)
387 handle->msg_callback (handle->msg_cls, room, contact, recipient,
388 stored_message, hash, flags);
389 314
390skip_message: 315skip_message:
391 cleanup_message (&message); 316 cleanup_message (&message);
392
393 if (private_message)
394 destroy_message (private_message);
395} 317}
396 318
397 319
@@ -752,7 +674,7 @@ send_message_to_room (struct GNUNET_MESSENGER_Room *room,
752 hash_message (message, msg_length, msg_buffer, hash); 674 hash_message (message, msg_length, msg_buffer, hash);
753 sign_message (message, msg_length, msg_buffer, hash, key); 675 sign_message (message, msg_length, msg_buffer, hash, key);
754 676
755 GNUNET_memcpy (&(room->last_message), hash, sizeof(room->last_message)); 677 update_room_last_message (room, hash);
756 678
757 GNUNET_MQ_send (room->handle->mq, env); 679 GNUNET_MQ_send (room->handle->mq, env);
758 680
@@ -1243,7 +1165,7 @@ GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room,
1243} 1165}
1244 1166
1245 1167
1246static void 1168void
1247delete_message_in_room (struct GNUNET_MESSENGER_Room *room, 1169delete_message_in_room (struct GNUNET_MESSENGER_Room *room,
1248 const struct GNUNET_HashCode *hash, 1170 const struct GNUNET_HashCode *hash,
1249 const struct GNUNET_TIME_Relative delay) 1171 const struct GNUNET_TIME_Relative delay)