diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2024-01-20 01:19:29 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2024-01-20 01:19:29 +0100 |
commit | 02ab26ff0802f4b88a34d198aa518058e6c80a77 (patch) | |
tree | c227b057d73ed313b0572a4f5e1171f792de8997 | |
parent | 75023517a747083670642ed489fc3b34729f6113 (diff) | |
download | gnunet-02ab26ff0802f4b88a34d198aa518058e6c80a77.tar.gz gnunet-02ab26ff0802f4b88a34d198aa518058e6c80a77.zip |
MESSENGER: Add recipient to message callback
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | src/cli/messenger/gnunet-messenger.c | 9 | ||||
-rw-r--r-- | src/include/gnunet_messenger_service.h | 5 | ||||
-rw-r--r-- | src/service/messenger/messenger_api.c | 55 | ||||
-rw-r--r-- | src/service/messenger/messenger_api_cmd_start_service.c | 27 | ||||
-rw-r--r-- | src/service/messenger/messenger_api_message.h | 2 |
5 files changed, 62 insertions, 36 deletions
diff --git a/src/cli/messenger/gnunet-messenger.c b/src/cli/messenger/gnunet-messenger.c index 6258ce712..e3c10d509 100644 --- a/src/cli/messenger/gnunet-messenger.c +++ b/src/cli/messenger/gnunet-messenger.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--2023 GNUnet e.V. | 3 | Copyright (C) 2020--2024 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 |
@@ -46,21 +46,26 @@ void | |||
46 | on_message (void *cls, | 46 | on_message (void *cls, |
47 | struct GNUNET_MESSENGER_Room *room, | 47 | struct GNUNET_MESSENGER_Room *room, |
48 | const struct GNUNET_MESSENGER_Contact *sender, | 48 | const struct GNUNET_MESSENGER_Contact *sender, |
49 | const struct GNUNET_MESSENGER_Contact *recipient, | ||
49 | const struct GNUNET_MESSENGER_Message *message, | 50 | const struct GNUNET_MESSENGER_Message *message, |
50 | const struct GNUNET_HashCode *hash, | 51 | const struct GNUNET_HashCode *hash, |
51 | enum GNUNET_MESSENGER_MessageFlags flags) | 52 | enum GNUNET_MESSENGER_MessageFlags flags) |
52 | { | 53 | { |
53 | const char *sender_name = GNUNET_MESSENGER_contact_get_name (sender); | 54 | const char *sender_name = GNUNET_MESSENGER_contact_get_name (sender); |
55 | const char *recipient_name = GNUNET_MESSENGER_contact_get_name (recipient); | ||
54 | 56 | ||
55 | if (! sender_name) | 57 | if (! sender_name) |
56 | sender_name = "anonymous"; | 58 | sender_name = "anonymous"; |
57 | 59 | ||
60 | if (! recipient_name) | ||
61 | recipient_name = "anonymous"; | ||
62 | |||
58 | printf ("[%s ->", GNUNET_h2s (&(message->header.previous))); | 63 | printf ("[%s ->", GNUNET_h2s (&(message->header.previous))); |
59 | printf (" %s]", GNUNET_h2s (hash)); | 64 | printf (" %s]", GNUNET_h2s (hash)); |
60 | printf ("[%s] ", GNUNET_sh2s (&(message->header.sender_id))); | 65 | printf ("[%s] ", GNUNET_sh2s (&(message->header.sender_id))); |
61 | 66 | ||
62 | if (flags & GNUNET_MESSENGER_FLAG_PRIVATE) | 67 | if (flags & GNUNET_MESSENGER_FLAG_PRIVATE) |
63 | printf ("*"); | 68 | printf ("*( '%s' ) ", recipient_name); |
64 | 69 | ||
65 | switch (message->header.kind) | 70 | switch (message->header.kind) |
66 | { | 71 | { |
diff --git a/src/include/gnunet_messenger_service.h b/src/include/gnunet_messenger_service.h index 4d3f4419e..c0c724795 100644 --- a/src/include/gnunet_messenger_service.h +++ b/src/include/gnunet_messenger_service.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2020--2023 GNUnet e.V. | 3 | Copyright (C) 2020--2024 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 |
@@ -697,6 +697,7 @@ enum GNUNET_MESSENGER_ConnectionFlags | |||
697 | * @param[in/out] cls Closure from #GNUNET_MESSENGER_connect | 697 | * @param[in/out] cls Closure from #GNUNET_MESSENGER_connect |
698 | * @param[in] room Room handle | 698 | * @param[in] room Room handle |
699 | * @param[in] sender Sender of message | 699 | * @param[in] sender Sender of message |
700 | * @param[in] recipient Recipient of message | ||
700 | * @param[in] message Newly received or sent message | 701 | * @param[in] message Newly received or sent message |
701 | * @param[in] hash Hash identifying the message | 702 | * @param[in] hash Hash identifying the message |
702 | * @param[in] flags Flags of the message | 703 | * @param[in] flags Flags of the message |
@@ -707,6 +708,8 @@ typedef void | |||
707 | const struct | 708 | const struct |
708 | GNUNET_MESSENGER_Contact *sender, | 709 | GNUNET_MESSENGER_Contact *sender, |
709 | const struct | 710 | const struct |
711 | GNUNET_MESSENGER_Contact *recipient, | ||
712 | const struct | ||
710 | GNUNET_MESSENGER_Message *message, | 713 | GNUNET_MESSENGER_Message *message, |
711 | const struct GNUNET_HashCode *hash, | 714 | const struct GNUNET_HashCode *hash, |
712 | enum GNUNET_MESSENGER_MessageFlags flags); | 715 | enum GNUNET_MESSENGER_MessageFlags flags); |
diff --git a/src/service/messenger/messenger_api.c b/src/service/messenger/messenger_api.c index 269fb2999..1528d00d2 100644 --- a/src/service/messenger/messenger_api.c +++ b/src/service/messenger/messenger_api.c | |||
@@ -31,6 +31,7 @@ | |||
31 | 31 | ||
32 | #include "gnunet_reclaim_service.h" | 32 | #include "gnunet_reclaim_service.h" |
33 | #include "messenger_api_contact.h" | 33 | #include "messenger_api_contact.h" |
34 | #include "messenger_api_contact_store.h" | ||
34 | #include "messenger_api_handle.h" | 35 | #include "messenger_api_handle.h" |
35 | #include "messenger_api_message.h" | 36 | #include "messenger_api_message.h" |
36 | #include "messenger_api_message_kind.h" | 37 | #include "messenger_api_message_kind.h" |
@@ -305,33 +306,49 @@ handle_recv_message (void *cls, | |||
305 | 306 | ||
306 | struct GNUNET_MESSENGER_Room *room = get_handle_room (handle, key); | 307 | struct GNUNET_MESSENGER_Room *room = get_handle_room (handle, key); |
307 | 308 | ||
308 | if (room) | 309 | if (!room) |
309 | { | 310 | { |
310 | struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store ( | 311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unknown room for this client: %s\n", |
311 | handle); | 312 | GNUNET_h2s (key)); |
313 | |||
314 | goto skip_message; | ||
315 | } | ||
312 | 316 | ||
313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 317 | struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store ( |
314 | "Raw contact from sender and context: (%s : %s)\n", | 318 | handle); |
315 | GNUNET_h2s (sender), GNUNET_h2s_full (context)); | ||
316 | 319 | ||
317 | struct GNUNET_MESSENGER_Contact *contact = get_store_contact_raw ( | 320 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
318 | store, context, sender | 321 | "Raw contact from sender and context: (%s : %s)\n", |
319 | ); | 322 | GNUNET_h2s (sender), GNUNET_h2s_full (context)); |
320 | 323 | ||
321 | contact = handle_room_message (room, contact, private_message ? | 324 | struct GNUNET_MESSENGER_Contact *contact = get_store_contact_raw ( |
322 | private_message : &message, hash, flags); | 325 | store, context, sender); |
326 | |||
327 | struct GNUNET_MESSENGER_Contact *recipient = NULL; | ||
323 | 328 | ||
324 | const struct GNUNET_MESSENGER_Message *stored_message = get_room_message ( | 329 | if (private_message) |
325 | room, hash); | 330 | { |
331 | const struct GNUNET_CRYPTO_PublicKey *recipient_key; | ||
332 | |||
333 | if (GNUNET_MESSENGER_KIND_TRANSCRIPT == private_message->header.kind) | ||
334 | recipient_key = &(private_message->body.transcript.key); | ||
335 | else | ||
336 | recipient_key = get_handle_pubkey(handle); | ||
326 | 337 | ||
327 | if (handle->msg_callback) | 338 | recipient = get_store_contact(store, context, recipient_key); |
328 | handle->msg_callback (handle->msg_cls, room, contact, stored_message, | ||
329 | hash, flags); | ||
330 | } | 339 | } |
331 | else | ||
332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unknown room for this client: %s\n", | ||
333 | GNUNET_h2s (key)); | ||
334 | 340 | ||
341 | contact = handle_room_message (room, contact, private_message ? | ||
342 | private_message : &message, hash, flags); | ||
343 | |||
344 | const struct GNUNET_MESSENGER_Message *stored_message = get_room_message ( | ||
345 | room, hash); | ||
346 | |||
347 | if (handle->msg_callback) | ||
348 | handle->msg_callback (handle->msg_cls, room, contact, recipient, | ||
349 | stored_message, hash, flags); | ||
350 | |||
351 | skip_message: | ||
335 | cleanup_message (&message); | 352 | cleanup_message (&message); |
336 | 353 | ||
337 | if (private_message) | 354 | if (private_message) |
diff --git a/src/service/messenger/messenger_api_cmd_start_service.c b/src/service/messenger/messenger_api_cmd_start_service.c index a35d338fd..4c9ce2849 100644 --- a/src/service/messenger/messenger_api_cmd_start_service.c +++ b/src/service/messenger/messenger_api_cmd_start_service.c | |||
@@ -1,21 +1,21 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2023 GNUnet e.V. | 3 | Copyright (C) 2023--2024 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 |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
@@ -35,6 +35,7 @@ static void | |||
35 | on_message_cb (void *cls, | 35 | on_message_cb (void *cls, |
36 | struct GNUNET_MESSENGER_Room *room, | 36 | struct GNUNET_MESSENGER_Room *room, |
37 | const struct GNUNET_MESSENGER_Contact *sender, | 37 | const struct GNUNET_MESSENGER_Contact *sender, |
38 | const struct GNUNET_MESSENGER_Contact *recipient, | ||
38 | const struct GNUNET_MESSENGER_Message *message, | 39 | const struct GNUNET_MESSENGER_Message *message, |
39 | const struct GNUNET_HashCode *hash, | 40 | const struct GNUNET_HashCode *hash, |
40 | enum GNUNET_MESSENGER_MessageFlags flags) | 41 | enum GNUNET_MESSENGER_MessageFlags flags) |
diff --git a/src/service/messenger/messenger_api_message.h b/src/service/messenger/messenger_api_message.h index afcd2deec..f2d5a3138 100644 --- a/src/service/messenger/messenger_api_message.h +++ b/src/service/messenger/messenger_api_message.h | |||
@@ -246,7 +246,7 @@ decrypt_message (struct GNUNET_MESSENGER_Message *message, | |||
246 | 246 | ||
247 | /** | 247 | /** |
248 | * Transcribes a <i>message</i> as a new transcript message using a given public | 248 | * Transcribes a <i>message</i> as a new transcript message using a given public |
249 | * <i>key</i> from the receipient of the encrypted message content. | 249 | * <i>key</i> from the recipient of the encrypted message content. |
250 | * | 250 | * |
251 | * @param[in] message Message | 251 | * @param[in] message Message |
252 | * @param[in] key Public key | 252 | * @param[in] key Public key |