diff options
Diffstat (limited to 'src/service/messenger/messenger_api.c')
-rw-r--r-- | src/service/messenger/messenger_api.c | 93 |
1 files changed, 54 insertions, 39 deletions
diff --git a/src/service/messenger/messenger_api.c b/src/service/messenger/messenger_api.c index 9f31ebb00..269fb2999 100644 --- a/src/service/messenger/messenger_api.c +++ b/src/service/messenger/messenger_api.c | |||
@@ -182,7 +182,8 @@ handle_room_sync (void *cls, | |||
182 | 182 | ||
183 | static void | 183 | static void |
184 | enqueue_message_to_room (struct GNUNET_MESSENGER_Room *room, | 184 | enqueue_message_to_room (struct GNUNET_MESSENGER_Room *room, |
185 | struct GNUNET_MESSENGER_Message *message); | 185 | struct GNUNET_MESSENGER_Message *message, |
186 | struct GNUNET_MESSENGER_Message *transcript); | ||
186 | 187 | ||
187 | static void | 188 | static void |
188 | handle_member_id (void *cls, | 189 | handle_member_id (void *cls, |
@@ -218,8 +219,7 @@ handle_member_id (void *cls, | |||
218 | if (! message) | 219 | if (! message) |
219 | return; | 220 | return; |
220 | 221 | ||
221 | enqueue_message_to_room (room, message); | 222 | enqueue_message_to_room (room, message, NULL); |
222 | destroy_message (message); | ||
223 | } | 223 | } |
224 | 224 | ||
225 | 225 | ||
@@ -367,8 +367,7 @@ handle_miss_message (void *cls, | |||
367 | if (! message) | 367 | if (! message) |
368 | return; | 368 | return; |
369 | 369 | ||
370 | enqueue_message_to_room (room, message); | 370 | enqueue_message_to_room (room, message, NULL); |
371 | destroy_message (message); | ||
372 | } | 371 | } |
373 | 372 | ||
374 | 373 | ||
@@ -664,6 +663,7 @@ GNUNET_MESSENGER_disconnect (struct GNUNET_MESSENGER_Handle *handle) | |||
664 | static void | 663 | static void |
665 | send_message_to_room (struct GNUNET_MESSENGER_Room *room, | 664 | send_message_to_room (struct GNUNET_MESSENGER_Room *room, |
666 | struct GNUNET_MESSENGER_Message *message, | 665 | struct GNUNET_MESSENGER_Message *message, |
666 | struct GNUNET_MESSENGER_Message *transcript, | ||
667 | const struct GNUNET_CRYPTO_PrivateKey *key) | 667 | const struct GNUNET_CRYPTO_PrivateKey *key) |
668 | { | 668 | { |
669 | const struct GNUNET_ShortHashCode *sender_id = get_room_sender_id (room); | 669 | const struct GNUNET_ShortHashCode *sender_id = get_room_sender_id (room); |
@@ -697,6 +697,9 @@ send_message_to_room (struct GNUNET_MESSENGER_Room *room, | |||
697 | hash_message (message, msg_length, msg_buffer, &hash); | 697 | hash_message (message, msg_length, msg_buffer, &hash); |
698 | sign_message (message, msg_length, msg_buffer, &hash, key); | 698 | sign_message (message, msg_length, msg_buffer, &hash, key); |
699 | 699 | ||
700 | if (transcript) | ||
701 | GNUNET_memcpy (&(transcript->body.transcript.hash), &hash, sizeof(hash)); | ||
702 | |||
700 | GNUNET_memcpy (&(room->last_message), &hash, sizeof(room->last_message)); | 703 | GNUNET_memcpy (&(room->last_message), &hash, sizeof(room->last_message)); |
701 | 704 | ||
702 | GNUNET_MQ_send (room->handle->mq, env); | 705 | GNUNET_MQ_send (room->handle->mq, env); |
@@ -708,7 +711,8 @@ send_message_to_room (struct GNUNET_MESSENGER_Room *room, | |||
708 | 711 | ||
709 | static void | 712 | static void |
710 | enqueue_message_to_room (struct GNUNET_MESSENGER_Room *room, | 713 | enqueue_message_to_room (struct GNUNET_MESSENGER_Room *room, |
711 | struct GNUNET_MESSENGER_Message *message) | 714 | struct GNUNET_MESSENGER_Message *message, |
715 | struct GNUNET_MESSENGER_Message *transcript) | ||
712 | { | 716 | { |
713 | const struct GNUNET_CRYPTO_PrivateKey *key = get_handle_key (room->handle); | 717 | const struct GNUNET_CRYPTO_PrivateKey *key = get_handle_key (room->handle); |
714 | enum GNUNET_GenericReturnValue priority; | 718 | enum GNUNET_GenericReturnValue priority; |
@@ -723,7 +727,7 @@ enqueue_message_to_room (struct GNUNET_MESSENGER_Room *room, | |||
723 | break; | 727 | break; |
724 | } | 728 | } |
725 | 729 | ||
726 | enqueue_to_messages (&(room->queue), key, message, priority); | 730 | enqueue_to_messages (&(room->queue), key, message, transcript, priority); |
727 | 731 | ||
728 | if (GNUNET_YES != is_room_available (room)) | 732 | if (GNUNET_YES != is_room_available (room)) |
729 | return; | 733 | return; |
@@ -739,6 +743,8 @@ static enum GNUNET_GenericReturnValue | |||
739 | dequeue_messages_from_room (struct GNUNET_MESSENGER_Room *room) | 743 | dequeue_messages_from_room (struct GNUNET_MESSENGER_Room *room) |
740 | { | 744 | { |
741 | struct GNUNET_MESSENGER_Message *message = NULL; | 745 | struct GNUNET_MESSENGER_Message *message = NULL; |
746 | struct GNUNET_MESSENGER_Message *transcript = NULL; | ||
747 | struct GNUNET_CRYPTO_PublicKey pubkey; | ||
742 | struct GNUNET_CRYPTO_PrivateKey key; | 748 | struct GNUNET_CRYPTO_PrivateKey key; |
743 | 749 | ||
744 | if (GNUNET_YES != is_room_available (room)) | 750 | if (GNUNET_YES != is_room_available (room)) |
@@ -748,10 +754,31 @@ dequeue_messages_from_room (struct GNUNET_MESSENGER_Room *room) | |||
748 | if (message) | 754 | if (message) |
749 | destroy_message (message); | 755 | destroy_message (message); |
750 | 756 | ||
751 | message = dequeue_from_messages (&(room->queue), &key); | 757 | message = dequeue_from_messages (&(room->queue), &key, &transcript); |
758 | |||
759 | if (!message) | ||
760 | { | ||
761 | message = transcript; | ||
762 | continue; | ||
763 | } | ||
764 | |||
765 | send_message_to_room (room, message, transcript, &key); | ||
766 | |||
767 | if (!transcript) | ||
768 | continue; | ||
769 | |||
770 | GNUNET_CRYPTO_key_get_public(&key, &pubkey); | ||
771 | |||
772 | if (GNUNET_YES == encrypt_message(transcript, &pubkey)) | ||
773 | send_message_to_room (room, transcript, NULL, &key); | ||
774 | else | ||
775 | { | ||
776 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
777 | "Sending transcript aborted: Encryption failed!\n"); | ||
778 | |||
779 | destroy_message (transcript); | ||
780 | } | ||
752 | 781 | ||
753 | if (message) | ||
754 | send_message_to_room (room, message, &key); | ||
755 | } while (message); | 782 | } while (message); |
756 | 783 | ||
757 | return GNUNET_YES; | 784 | return GNUNET_YES; |
@@ -788,8 +815,7 @@ iterate_send_name_to_room (void *cls, | |||
788 | if (! message) | 815 | if (! message) |
789 | return GNUNET_NO; | 816 | return GNUNET_NO; |
790 | 817 | ||
791 | enqueue_message_to_room (room, message); | 818 | enqueue_message_to_room (room, message, NULL); |
792 | destroy_message (message); | ||
793 | return GNUNET_YES; | 819 | return GNUNET_YES; |
794 | } | 820 | } |
795 | 821 | ||
@@ -839,8 +865,7 @@ iterate_send_key_to_room (void *cls, | |||
839 | if (! message) | 865 | if (! message) |
840 | return GNUNET_NO; | 866 | return GNUNET_NO; |
841 | 867 | ||
842 | enqueue_message_to_room (room, message); | 868 | enqueue_message_to_room (room, message, NULL); |
843 | destroy_message (message); | ||
844 | return GNUNET_YES; | 869 | return GNUNET_YES; |
845 | } | 870 | } |
846 | 871 | ||
@@ -937,10 +962,7 @@ GNUNET_MESSENGER_close_room (struct GNUNET_MESSENGER_Room *room) | |||
937 | struct GNUNET_MESSENGER_Message *message = create_message_leave (); | 962 | struct GNUNET_MESSENGER_Message *message = create_message_leave (); |
938 | 963 | ||
939 | if (message) | 964 | if (message) |
940 | { | 965 | enqueue_message_to_room (room, message, NULL); |
941 | enqueue_message_to_room (room, message); | ||
942 | destroy_message (message); | ||
943 | } | ||
944 | } | 966 | } |
945 | 967 | ||
946 | 968 | ||
@@ -1057,8 +1079,9 @@ send_message_to_room_with_key (struct GNUNET_MESSENGER_Room *room, | |||
1057 | struct GNUNET_MESSENGER_Message *message, | 1079 | struct GNUNET_MESSENGER_Message *message, |
1058 | const struct GNUNET_CRYPTO_PublicKey *public_key) | 1080 | const struct GNUNET_CRYPTO_PublicKey *public_key) |
1059 | { | 1081 | { |
1082 | struct GNUNET_MESSENGER_Message *transcript = NULL; | ||
1083 | |||
1060 | char *original_name; | 1084 | char *original_name; |
1061 | char *changed_name = NULL; | ||
1062 | 1085 | ||
1063 | if (GNUNET_MESSENGER_KIND_NAME != message->header.kind) | 1086 | if (GNUNET_MESSENGER_KIND_NAME != message->header.kind) |
1064 | goto skip_naming; | 1087 | goto skip_naming; |
@@ -1073,44 +1096,37 @@ send_message_to_room_with_key (struct GNUNET_MESSENGER_Room *room, | |||
1073 | if ((handle_name) && (GNUNET_YES == room->use_handle_name) && | 1096 | if ((handle_name) && (GNUNET_YES == room->use_handle_name) && |
1074 | ((! original_name) || (0 == strlen (original_name)))) | 1097 | ((! original_name) || (0 == strlen (original_name)))) |
1075 | { | 1098 | { |
1076 | changed_name = GNUNET_strdup (handle_name); | 1099 | if (original_name) |
1077 | message->body.name.name = changed_name; | 1100 | GNUNET_free (original_name); |
1101 | |||
1102 | message->body.name.name = GNUNET_strdup (handle_name); | ||
1078 | } | 1103 | } |
1079 | 1104 | ||
1080 | skip_naming: | 1105 | skip_naming: |
1081 | if (public_key) | 1106 | if (public_key) |
1082 | { | 1107 | { |
1083 | struct GNUNET_MESSENGER_Message *original = message; | 1108 | transcript = transcribe_message (message, public_key); |
1084 | message = copy_message (original); | ||
1085 | 1109 | ||
1086 | if (GNUNET_YES != encrypt_message (message, public_key)) | 1110 | if (GNUNET_YES != encrypt_message (message, public_key)) |
1087 | { | 1111 | { |
1088 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1112 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1089 | "Sending message aborted: Encryption failed!\n"); | 1113 | "Sending message aborted: Encryption failed!\n"); |
1114 | |||
1115 | if (transcript) | ||
1116 | destroy_message(transcript); | ||
1090 | 1117 | ||
1091 | destroy_message (message); | 1118 | destroy_message (message); |
1092 | message = original; | 1119 | return; |
1093 | |||
1094 | goto reset_naming; | ||
1095 | } | 1120 | } |
1096 | } | 1121 | } |
1097 | 1122 | ||
1098 | enqueue_message_to_room (room, message); | 1123 | enqueue_message_to_room (room, message, transcript); |
1099 | |||
1100 | reset_naming: | ||
1101 | if (changed_name) | ||
1102 | GNUNET_free (changed_name); | ||
1103 | |||
1104 | if (GNUNET_MESSENGER_KIND_NAME != message->header.kind) | ||
1105 | return; | ||
1106 | |||
1107 | message->body.name.name = original_name; | ||
1108 | } | 1124 | } |
1109 | 1125 | ||
1110 | 1126 | ||
1111 | void | 1127 | void |
1112 | GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, | 1128 | GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, |
1113 | struct GNUNET_MESSENGER_Message *message, | 1129 | const struct GNUNET_MESSENGER_Message *message, |
1114 | const struct GNUNET_MESSENGER_Contact *contact) | 1130 | const struct GNUNET_MESSENGER_Contact *contact) |
1115 | { | 1131 | { |
1116 | if ((! room) || (! message)) | 1132 | if ((! room) || (! message)) |
@@ -1148,7 +1164,7 @@ GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, | |||
1148 | else | 1164 | else |
1149 | public_key = NULL; | 1165 | public_key = NULL; |
1150 | 1166 | ||
1151 | send_message_to_room_with_key (room, message, public_key); | 1167 | send_message_to_room_with_key (room, copy_message(message), public_key); |
1152 | } | 1168 | } |
1153 | 1169 | ||
1154 | 1170 | ||
@@ -1261,5 +1277,4 @@ GNUNET_MESSENGER_send_ticket (struct GNUNET_MESSENGER_Room *room, | |||
1261 | } | 1277 | } |
1262 | 1278 | ||
1263 | send_message_to_room_with_key (room, message, &(ticket->audience)); | 1279 | send_message_to_room_with_key (room, message, &(ticket->audience)); |
1264 | destroy_message (message); | ||
1265 | } | 1280 | } |