gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] 04/08: MESSENGER: Add recipient to message callback


From: gnunet
Subject: [gnunet] 04/08: MESSENGER: Add recipient to message callback
Date: Sat, 20 Jan 2024 10:08:33 +0100

This is an automated email from the git hooks/post-receive script.

thejackimonster pushed a commit to branch master
in repository gnunet.

commit 02ab26ff0802f4b88a34d198aa518058e6c80a77
Author: TheJackiMonster <thejackimonster@gmail.com>
AuthorDate: Sat Jan 20 01:19:29 2024 +0100

    MESSENGER: Add recipient to message callback
    
    Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
---
 src/cli/messenger/gnunet-messenger.c               |  9 +++-
 src/include/gnunet_messenger_service.h             |  5 +-
 src/service/messenger/messenger_api.c              | 55 ++++++++++++++--------
 .../messenger/messenger_api_cmd_start_service.c    | 27 ++++++-----
 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 @@
 /*
    This file is part of GNUnet.
-   Copyright (C) 2020--2023 GNUnet e.V.
+   Copyright (C) 2020--2024 GNUnet e.V.
 
    GNUnet is free software: you can redistribute it and/or modify it
    under the terms of the GNU Affero General Public License as published
@@ -46,21 +46,26 @@ void
 on_message (void *cls,
             struct GNUNET_MESSENGER_Room *room,
             const struct GNUNET_MESSENGER_Contact *sender,
+            const struct GNUNET_MESSENGER_Contact *recipient,
             const struct GNUNET_MESSENGER_Message *message,
             const struct GNUNET_HashCode *hash,
             enum GNUNET_MESSENGER_MessageFlags flags)
 {
   const char *sender_name = GNUNET_MESSENGER_contact_get_name (sender);
+  const char *recipient_name = GNUNET_MESSENGER_contact_get_name (recipient);
 
   if (! sender_name)
     sender_name = "anonymous";
 
+  if (! recipient_name)
+    recipient_name = "anonymous";
+
   printf ("[%s ->", GNUNET_h2s (&(message->header.previous)));
   printf (" %s]", GNUNET_h2s (hash));
   printf ("[%s] ", GNUNET_sh2s (&(message->header.sender_id)));
 
   if (flags & GNUNET_MESSENGER_FLAG_PRIVATE)
-    printf ("*");
+    printf ("*( '%s' ) ", recipient_name);
 
   switch (message->header.kind)
   {
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 @@
 /*
    This file is part of GNUnet.
-   Copyright (C) 2020--2023 GNUnet e.V.
+   Copyright (C) 2020--2024 GNUnet e.V.
 
    GNUnet is free software: you can redistribute it and/or modify it
    under the terms of the GNU Affero General Public License as published
@@ -697,6 +697,7 @@ enum GNUNET_MESSENGER_ConnectionFlags
  * @param[in/out] cls Closure from #GNUNET_MESSENGER_connect
  * @param[in] room Room handle
  * @param[in] sender Sender of message
+ * @param[in] recipient Recipient of message
  * @param[in] message Newly received or sent message
  * @param[in] hash Hash identifying the message
  * @param[in] flags Flags of the message
@@ -707,6 +708,8 @@ typedef void
                                      const struct
                                      GNUNET_MESSENGER_Contact *sender,
                                      const struct
+                                     GNUNET_MESSENGER_Contact *recipient,
+                                     const struct
                                      GNUNET_MESSENGER_Message *message,
                                      const struct GNUNET_HashCode *hash,
                                      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 @@
 
 #include "gnunet_reclaim_service.h"
 #include "messenger_api_contact.h"
+#include "messenger_api_contact_store.h"
 #include "messenger_api_handle.h"
 #include "messenger_api_message.h"
 #include "messenger_api_message_kind.h"
@@ -305,33 +306,49 @@ handle_recv_message (void *cls,
 
   struct GNUNET_MESSENGER_Room *room = get_handle_room (handle, key);
 
-  if (room)
+  if (!room)
   {
-    struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store (
-      handle);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unknown room for this client: %s\n",
+                GNUNET_h2s (key));
+    
+    goto skip_message;
+  }
 
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Raw contact from sender and context: (%s : %s)\n",
-                GNUNET_h2s (sender), GNUNET_h2s_full (context));
+  struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store (
+    handle);
 
-    struct GNUNET_MESSENGER_Contact *contact = get_store_contact_raw (
-      store, context, sender
-      );
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Raw contact from sender and context: (%s : %s)\n",
+              GNUNET_h2s (sender), GNUNET_h2s_full (context));
 
-    contact = handle_room_message (room, contact, private_message ?
-                                   private_message : &message, hash, flags);
+  struct GNUNET_MESSENGER_Contact *contact = get_store_contact_raw (
+    store, context, sender);
+  
+  struct GNUNET_MESSENGER_Contact *recipient = NULL;
 
-    const struct GNUNET_MESSENGER_Message *stored_message = get_room_message (
-      room, hash);
+  if (private_message)
+  {
+    const struct GNUNET_CRYPTO_PublicKey *recipient_key;
+
+    if (GNUNET_MESSENGER_KIND_TRANSCRIPT == private_message->header.kind)
+      recipient_key = &(private_message->body.transcript.key);
+    else
+      recipient_key = get_handle_pubkey(handle);
 
-    if (handle->msg_callback)
-      handle->msg_callback (handle->msg_cls, room, contact, stored_message,
-                            hash, flags);
+    recipient = get_store_contact(store, context, recipient_key);
   }
-  else
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unknown room for this client: %s\n",
-                GNUNET_h2s (key));
 
+  contact = handle_room_message (room, contact, private_message ?
+                                  private_message : &message, hash, flags);
+
+  const struct GNUNET_MESSENGER_Message *stored_message = get_room_message (
+    room, hash);
+
+  if (handle->msg_callback)
+    handle->msg_callback (handle->msg_cls, room, contact, recipient,
+                          stored_message, hash, flags);
+
+skip_message:
   cleanup_message (&message);
 
   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 @@
 /*
-      This file is part of GNUnet
-      Copyright (C) 2023 GNUnet e.V.
+   This file is part of GNUnet
+   Copyright (C) 2023--2024 GNUnet e.V.
 
-      GNUnet is free software: you can redistribute it and/or modify it
-      under the terms of the GNU Affero General Public License as published
-      by the Free Software Foundation, either version 3 of the License,
-      or (at your option) any later version.
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
 
-      GNUnet is distributed in the hope that it will be useful, but
-      WITHOUT ANY WARRANTY; without even the implied warranty of
-      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-      Affero General Public License for more details.
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
 
-      You should have received a copy of the GNU Affero General Public License
-      along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-     SPDX-License-Identifier: AGPL3.0-or-later
+   SPDX-License-Identifier: AGPL3.0-or-later
  */
 
 /**
@@ -35,6 +35,7 @@ static void
 on_message_cb (void *cls,
                struct GNUNET_MESSENGER_Room *room,
                const struct GNUNET_MESSENGER_Contact *sender,
+               const struct GNUNET_MESSENGER_Contact *recipient,
                const struct GNUNET_MESSENGER_Message *message,
                const struct GNUNET_HashCode *hash,
                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,
 
 /**
  * Transcribes a <i>message</i> as a new transcript message using a given 
public
- * <i>key</i> from the receipient of the encrypted message content.
+ * <i>key</i> from the recipient of the encrypted message content.
  *
  * @param[in] message Message
  * @param[in] key Public key

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]