gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] branch master updated: MESSENGER: Add talk mode to cli applicat


From: gnunet
Subject: [gnunet] branch master updated: MESSENGER: Add talk mode to cli application using discourses
Date: Sat, 08 Jun 2024 04:52:51 +0200

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

thejackimonster pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 7c930c44d MESSENGER: Add talk mode to cli application using discourses
7c930c44d is described below

commit 7c930c44de3e4f226d500599e2d2f7ae14895932
Author: TheJackiMonster <thejackimonster@gmail.com>
AuthorDate: Sat Jun 8 04:52:33 2024 +0200

    MESSENGER: Add talk mode to cli application using discourses
    
    Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
---
 src/cli/messenger/gnunet-messenger.c | 87 ++++++++++++++++++++++++++++++------
 1 file changed, 73 insertions(+), 14 deletions(-)

diff --git a/src/cli/messenger/gnunet-messenger.c 
b/src/cli/messenger/gnunet-messenger.c
index 6bff0b25d..c690c8f24 100644
--- a/src/cli/messenger/gnunet-messenger.c
+++ b/src/cli/messenger/gnunet-messenger.c
@@ -33,6 +33,8 @@
 const struct GNUNET_CONFIGURATION_Handle *config;
 struct GNUNET_MESSENGER_Handle *messenger;
 
+int talk_mode;
+
 /**
  * Function called whenever a message is received or sent.
  *
@@ -52,6 +54,16 @@ on_message (void *cls,
             const struct GNUNET_HashCode *hash,
             enum GNUNET_MESSENGER_MessageFlags flags)
 {
+  if (GNUNET_YES == talk_mode)
+  {
+    if (GNUNET_MESSENGER_KIND_TALK == message->header.kind)
+    {
+      write(1, message->body.talk.data, message->body.talk.length);
+    }
+
+    goto skip_printing;
+  }
+
   const char *sender_name = GNUNET_MESSENGER_contact_get_name (sender);
   const char *recipient_name = GNUNET_MESSENGER_contact_get_name (recipient);
 
@@ -99,7 +111,19 @@ on_message (void *cls,
       else
         printf ("<");
 
-      printf (" '%s' says: \"%s\"\n", sender_name, message->body.text.text);
+      printf (" '%s' says: \"%s\"\n", sender_name, 
+              message->body.text.text);
+      break;
+    }
+  case GNUNET_MESSENGER_KIND_FILE:
+    {
+      if (flags & GNUNET_MESSENGER_FLAG_SENT)
+        printf (">");
+      else
+        printf ("<");
+
+      printf(" '%s' shares: \"%s\"\n%s\n", sender_name, 
+             message->body.file.name, message->body.file.uri);
       break;
     }
   default:
@@ -110,6 +134,7 @@ on_message (void *cls,
     }
   }
 
+skip_printing:
   if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) &&
       (flags & GNUNET_MESSENGER_FLAG_SENT))
   {
@@ -125,6 +150,19 @@ on_message (void *cls,
     GNUNET_MESSENGER_send_message (room, &response, NULL);
 
     GNUNET_free (response.body.name.name);
+
+    if (GNUNET_YES != talk_mode)
+      return;
+
+    response.header.kind = GNUNET_MESSENGER_KIND_SUBSCRIBE;
+    response.body.subscribe.flags = 
GNUNET_MESSENGER_FLAG_SUBSCRIPTION_KEEP_ALIVE;
+    response.body.subscribe.time =
+      GNUNET_TIME_relative_hton (GNUNET_TIME_relative_get_second_());
+
+    memset(&(response.body.subscribe.discourse), 0,
+           sizeof(response.body.subscribe.discourse));
+    
+    GNUNET_MESSENGER_send_message (room, &response, NULL);
   }
 }
 
@@ -185,6 +223,9 @@ int private_mode;
 static void
 read_stdio (void *cls)
 {
+  struct GNUNET_MESSENGER_Room *room = cls;
+  struct GNUNET_MESSENGER_Message message;
+
   read_task = NULL;
 
   char buffer[MAX_BUFFER_SIZE];
@@ -198,16 +239,25 @@ read_stdio (void *cls)
     return;
   }
 
-  if (buffer[length - 1] == '\n')
-    buffer[length - 1] = '\0';
-  else
-    buffer[length] = '\0';
+  if (GNUNET_YES == talk_mode)
+  {
+    message.header.kind = GNUNET_MESSENGER_KIND_TALK;
+    message.body.talk.length = length;
+    message.body.talk.data = buffer;
 
-  struct GNUNET_MESSENGER_Room *room = cls;
+    memset(&(message.body.talk.discourse), 0,
+           sizeof(message.body.talk.discourse));
+  }
+  else
+  {
+    if (buffer[length - 1] == '\n')
+      buffer[length - 1] = '\0';
+    else
+      buffer[length] = '\0';
 
-  struct GNUNET_MESSENGER_Message message;
-  message.header.kind = GNUNET_MESSENGER_KIND_TEXT;
-  message.body.text.text = buffer;
+    message.header.kind = GNUNET_MESSENGER_KIND_TEXT;
+    message.body.text.text = buffer;
+  }
 
   if (GNUNET_YES == private_mode)
     GNUNET_MESSENGER_iterate_members (room, iterate_send_private_message,
@@ -251,7 +301,8 @@ idle (void *cls)
 {
   struct GNUNET_MESSENGER_Room *room = cls;
 
-  printf ("* You joined the room.\n");
+  if (GNUNET_YES != talk_mode)
+    printf ("* You joined the room.\n");
 
   read_task = GNUNET_SCHEDULER_add_now (listen_stdio, room);
 }
@@ -290,6 +341,11 @@ on_identity (void *cls,
                                                                   
public_key))))
     door = &door_peer;
 
+  struct GNUNET_MESSENGER_Room *room;
+  
+  if (GNUNET_YES == talk_mode)
+    goto skip_welcome;
+
   const char *name = GNUNET_MESSENGER_get_name (handle);
 
   if (! name)
@@ -297,17 +353,18 @@ on_identity (void *cls,
 
   printf ("* Welcome to the messenger, '%s'!\n", name);
 
-  struct GNUNET_MESSENGER_Room *room;
-
+skip_welcome:
   if (door)
   {
-    printf ("* You try to entry a room...\n");
+    if (GNUNET_YES != talk_mode)
+      printf ("* You try to entry a room...\n");
 
     room = GNUNET_MESSENGER_enter_room (messenger, door, &key);
   }
   else
   {
-    printf ("* You try to open a room...\n");
+    if (GNUNET_YES != talk_mode)
+      printf ("* You try to open a room...\n");
 
     room = GNUNET_MESSENGER_open_room (messenger, &key);
   }
@@ -405,6 +462,8 @@ main (int argc,
                                  &room_key),
     GNUNET_GETOPT_option_flag ('p', "private", "flag to enable private mode",
                                &private_mode),
+    GNUNET_GETOPT_option_flag ('t', "talk", "flag to enable talk mode",
+                               &talk_mode),
     GNUNET_GETOPT_OPTION_END
   };
 

-- 
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]