-GArik: fix typo
[oweals/gnunet.git] / src / chat / gnunet-chat.c
index 450996382e59c530048c82887e5fbd3ffc40d3f2..4abc58c9f030c29e7102543e936a22089afeffde 100644 (file)
@@ -44,7 +44,8 @@ static struct GNUNET_CONTAINER_MetaData *meta;
 
 static struct GNUNET_CHAT_Room *room;
 
-static GNUNET_SCHEDULER_TaskIdentifier handle_cmd_task = GNUNET_SCHEDULER_NO_TASK;
+static GNUNET_SCHEDULER_TaskIdentifier handle_cmd_task =
+    GNUNET_SCHEDULER_NO_TASK;
 
 struct ChatCommand
 {
@@ -66,15 +67,31 @@ static void
 free_user_list ()
 {
   struct UserList *next;
+
   while (NULL != users)
-    {
-      next = users->next;
-      GNUNET_free (users);
-      users = next;
-    }
+  {
+    next = users->next;
+    GNUNET_free (users);
+    users = next;
+  }
 }
 
-static int do_help (const char *args, const void *xtra);
+static int
+do_help (const char *args, const void *xtra);
+
+
+/**
+ * Callback used for notification that we have joined the room.
+ *
+ * @param cls closure
+ * @return GNUNET_OK
+ */
+static int
+join_cb (void *cls)
+{
+  FPRINTF (stdout, "%s",  _("Joined\n"));
+  return GNUNET_OK;
+}
 
 
 /**
@@ -83,21 +100,22 @@ static int do_help (const char *args, const void *xtra);
  * @param cls closure, NULL
  * @param room in which room was the message received?
  * @param sender what is the ID of the sender? (maybe NULL)
- * @param meta information about the joining member
+ * @param member_info information about the joining member
  * @param message the message text
+ * @param timestamp time when the member joined
  * @param options options for the message
  * @return GNUNET_OK to accept the message now, GNUNET_NO to
  *         accept (but user is away), GNUNET_SYSERR to signal denied delivery
  */
 static int
-receive_cb (void *cls,
-           struct GNUNET_CHAT_Room *room,
-           const GNUNET_HashCode *sender,
-           const struct GNUNET_CONTAINER_MetaData *meta,
-           const char *message,
-           enum GNUNET_CHAT_MsgOptions options)
+receive_cb (void *cls, struct GNUNET_CHAT_Room *room,
+            const GNUNET_HashCode * sender,
+            const struct GNUNET_CONTAINER_MetaData *member_info,
+            const char *message, struct GNUNET_TIME_Absolute timestamp,
+            enum GNUNET_CHAT_MsgOptions options)
 {
   char *nick;
+  char *time;
   const char *fmt;
 
   if (NULL != sender)
@@ -105,47 +123,49 @@ receive_cb (void *cls,
   else
     nick = GNUNET_strdup (_("anonymous"));
   fmt = NULL;
-  switch (options)
-    {
-    case GNUNET_CHAT_MSG_OPTION_NONE:
-    case GNUNET_CHAT_MSG_ANONYMOUS:
-      fmt = _("`%s' said: %s\n");
-      break;
-    case GNUNET_CHAT_MSG_PRIVATE:
-      fmt = _("`%s' said to you: %s\n");
-      break;
-    case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ANONYMOUS:
-      fmt = _("`%s' said to you: %s\n");
-      break;
-    case GNUNET_CHAT_MSG_AUTHENTICATED:
-      fmt = _("`%s' said for sure: %s\n");
-      break;
-    case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_AUTHENTICATED:
-      fmt = _("`%s' said to you for sure: %s\n");
-      break;
-    case GNUNET_CHAT_MSG_ACKNOWLEDGED:
-      fmt = _("`%s' was confirmed that you received: %s\n");
-      break;
-    case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED:
-      fmt = _("`%s' was confirmed that you and only you received: %s\n");
-      break;
-    case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_ACKNOWLEDGED:
-      fmt = _("`%s' was confirmed that you received from him or her: %s\n");
-      break;
-    case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED:
-      fmt =
-       _
-       ("`%s' was confirmed that you and only you received from him or her: %s\n");
-      break;
-    case GNUNET_CHAT_MSG_OFF_THE_RECORD:
-      fmt = _("`%s' said off the record: %s\n");
-      break;
-    default:
-      fmt = _("<%s> said using an unknown message type: %s\n");
-      break;
-    }
-  fprintf (stdout, fmt, nick, message);
+  switch ((int) options)
+  {
+  case GNUNET_CHAT_MSG_OPTION_NONE:
+  case GNUNET_CHAT_MSG_ANONYMOUS:
+    fmt = _("(%s) `%s' said: %s\n");
+    break;
+  case GNUNET_CHAT_MSG_PRIVATE:
+    fmt = _("(%s) `%s' said to you: %s\n");
+    break;
+  case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ANONYMOUS:
+    fmt = _("(%s) `%s' said to you: %s\n");
+    break;
+  case GNUNET_CHAT_MSG_AUTHENTICATED:
+    fmt = _("(%s) `%s' said for sure: %s\n");
+    break;
+  case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_AUTHENTICATED:
+    fmt = _("(%s) `%s' said to you for sure: %s\n");
+    break;
+  case GNUNET_CHAT_MSG_ACKNOWLEDGED:
+    fmt = _("(%s) `%s' was confirmed that you received: %s\n");
+    break;
+  case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED:
+    fmt = _("(%s) `%s' was confirmed that you and only you received: %s\n");
+    break;
+  case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_ACKNOWLEDGED:
+    fmt = _("(%s) `%s' was confirmed that you received from him or her: %s\n");
+    break;
+  case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED:
+    fmt =
+        _
+        ("(%s) `%s' was confirmed that you and only you received from him or her: %s\n");
+    break;
+  case GNUNET_CHAT_MSG_OFF_THE_RECORD:
+    fmt = _("(%s) `%s' said off the record: %s\n");
+    break;
+  default:
+    fmt = _("(%s) <%s> said using an unknown message type: %s\n");
+    break;
+  }
+  time = GNUNET_STRINGS_absolute_time_to_string (timestamp);
+  FPRINTF (stdout, fmt, time, nick, message);
   GNUNET_free (nick);
+  GNUNET_free (time);
   return GNUNET_OK;
 }
 
@@ -158,24 +178,19 @@ receive_cb (void *cls,
  * @param orig_seq_number sequence number of the original message
  * @param timestamp when was the message received?
  * @param receiver who is confirming the receipt?
- * @param msg_hash hash of the original message
- * @param receipt signature confirming delivery
  * @return GNUNET_OK to continue, GNUNET_SYSERR to refuse processing further
  *         confirmations from anyone for this message
  */
 static int
-confirmation_cb (void *cls,
-                struct GNUNET_CHAT_Room *room,
-                uint32_t orig_seq_number,
-                struct GNUNET_TIME_Absolute timestamp,
-                const GNUNET_HashCode *receiver,
-                const GNUNET_HashCode *msg_hash,
-                const struct GNUNET_CRYPTO_RsaSignature *receipt)
+confirmation_cb (void *cls, struct GNUNET_CHAT_Room *room,
+                 uint32_t orig_seq_number,
+                 struct GNUNET_TIME_Absolute timestamp,
+                 const GNUNET_HashCode * receiver)
 {
   char *nick;
 
   nick = GNUNET_PSEUDONYM_id_to_name (cfg, receiver);
-  fprintf (stdout, _("'%s' acknowledged message #%d\n"), nick, orig_seq_number);
+  FPRINTF (stdout, _("'%s' acknowledged message #%d\n"), nick, orig_seq_number);
   return GNUNET_OK;
 }
 
@@ -191,10 +206,9 @@ confirmation_cb (void *cls,
  * @return GNUNET_OK
  */
 static int
-member_list_cb (void *cls,
-               const struct GNUNET_CONTAINER_MetaData *member_info,
-               const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *member_id,
-               enum GNUNET_CHAT_MsgOptions options)
+member_list_cb (void *cls, const struct GNUNET_CONTAINER_MetaData *member_info,
+                const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *member_id,
+                enum GNUNET_CHAT_MsgOptions options)
 {
   char *nick;
   GNUNET_HashCode id;
@@ -202,59 +216,49 @@ member_list_cb (void *cls,
   struct UserList *prev;
 
   GNUNET_CRYPTO_hash (member_id,
-                     sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
-                     &id);
+                      sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                      &id);
   nick = GNUNET_PSEUDONYM_id_to_name (cfg, &id);
-  fprintf (stdout, member_info != NULL
-          ? _("`%s' entered the room\n") : _("`%s' left the room\n"), nick);
+  FPRINTF (stdout,
+           member_info !=
+           NULL ? _("`%s' entered the room\n") : _("`%s' left the room\n"),
+           nick);
   GNUNET_free (nick);
   if (NULL != member_info)
+  {
+    /* user joining */
+    pos = GNUNET_malloc (sizeof (struct UserList));
+    pos->next = users;
+    pos->pkey = *member_id;
+    pos->ignored = GNUNET_NO;
+    users = pos;
+  }
+  else
+  {
+    /* user leaving */
+    prev = NULL;
+    pos = users;
+    while ((NULL != pos) &&
+           (0 !=
+            memcmp (&pos->pkey, member_id,
+                    sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))))
+    {
+      prev = pos;
+      pos = pos->next;
+    }
+    if (NULL == pos)
     {
-      /* user joining */
-      pos = GNUNET_malloc (sizeof (struct UserList));
-      pos->next = users;
-      pos->pkey = *member_id;
-      pos->ignored = GNUNET_NO;
-      users = pos;
+      GNUNET_break (0);
     }
-  else
+    else
     {
-      /* user leaving */
-      prev = NULL;
-      pos = users;
-      while ((NULL != pos) &&
-            (0 != memcmp (&pos->pkey,
-                          member_id,
-                          sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))))
-       {
-         prev = pos;
-         pos = pos->next;
-       }
-      if (NULL == pos)
-       {
-         GNUNET_break (0);
-       }
+      if (NULL == prev)
+        users = pos->next;
       else
-       {
-         if (NULL == prev)
-           users = pos->next;
-         else
-           prev->next = pos->next;
-         GNUNET_free (pos);
-       }
+        prev->next = pos->next;
+      GNUNET_free (pos);
     }
-  return GNUNET_OK;
-}
-
-
-static int
-do_transmit (const char *msg, const void *xtra)
-{
-  uint32_t seq;
-  GNUNET_CHAT_send_message (room,
-                           msg,
-                           GNUNET_CHAT_MSG_OPTION_NONE,
-                           NULL, &seq);
+  }
   return GNUNET_OK;
 }
 
@@ -271,21 +275,18 @@ do_join (const char *arg, const void *xtra)
   free_user_list ();
   GNUNET_free (room_name);
   room_name = GNUNET_strdup (arg);
-  room = GNUNET_CHAT_join_room (cfg,
-                               nickname,
-                               meta,
-                               room_name,
-                               -1,
-                               &receive_cb, NULL,
-                               &member_list_cb, NULL,
-                               &confirmation_cb, NULL, &me);
+  room =
+      GNUNET_CHAT_join_room (cfg, nickname, meta, room_name, -1, &join_cb, NULL,
+                             &receive_cb, NULL, &member_list_cb, NULL,
+                             &confirmation_cb, NULL, &me);
   if (NULL == room)
-    {
-      fprintf (stdout, _("Could not change username\n"));
-      return GNUNET_SYSERR;
-    }
+  {
+    FPRINTF (stdout, "%s",  _("Could not change username\n"));
+    return GNUNET_SYSERR;
+  }
   my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me);
-  fprintf (stdout, _("Joined room `%s' as user `%s'\n"), room_name, my_name);
+  FPRINTF (stdout, _("Joining room `%s' as user `%s'...\n"), room_name,
+           my_name);
   GNUNET_free (my_name);
   return GNUNET_OK;
 }
@@ -303,28 +304,20 @@ do_nick (const char *msg, const void *xtra)
   GNUNET_CONTAINER_meta_data_destroy (meta);
   nickname = GNUNET_strdup (msg);
   meta = GNUNET_CONTAINER_meta_data_create ();
-  GNUNET_CONTAINER_meta_data_insert (meta,
-                                    "<gnunet>",
-                                    EXTRACTOR_METATYPE_TITLE,
-                                    EXTRACTOR_METAFORMAT_UTF8,
-                                    "text/plain",
-                                    nickname,
-                                    strlen(nickname)+1);
-  room = GNUNET_CHAT_join_room (cfg,
-                               nickname,
-                               meta,
-                               room_name,
-                               -1,
-                               &receive_cb, NULL,
-                               &member_list_cb, NULL,
-                               &confirmation_cb, NULL, &me);
+  GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", EXTRACTOR_METATYPE_TITLE,
+                                     EXTRACTOR_METAFORMAT_UTF8, "text/plain",
+                                     nickname, strlen (nickname) + 1);
+  room =
+      GNUNET_CHAT_join_room (cfg, nickname, meta, room_name, -1, &join_cb, NULL,
+                             &receive_cb, NULL, &member_list_cb, NULL,
+                             &confirmation_cb, NULL, &me);
   if (NULL == room)
-    {
-      fprintf (stdout, _("Could not change username\n"));
-      return GNUNET_SYSERR;
-    }
+  {
+    FPRINTF (stdout, "%s",  _("Could not change username\n"));
+    return GNUNET_SYSERR;
+  }
   my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me);
-  fprintf (stdout, _("Changed username to `%s'\n"), my_name);
+  FPRINTF (stdout, _("Changed username to `%s'\n"), my_name);
   GNUNET_free (my_name);
   return GNUNET_OK;
 }
@@ -337,25 +330,35 @@ do_names (const char *msg, const void *xtra)
   struct UserList *pos;
   GNUNET_HashCode pid;
 
-  fprintf (stdout, _("Users in room `%s': "), room_name);
+  FPRINTF (stdout, _("Users in room `%s': "), room_name);
   pos = users;
   while (NULL != pos)
-    {
-      GNUNET_CRYPTO_hash (&pos->pkey,
-                         sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
-                         &pid);
-      name = GNUNET_PSEUDONYM_id_to_name (cfg, &pid);
-      fprintf (stdout, "`%s' ", name);
-      GNUNET_free (name);
-      pos = pos->next;
-    }
-  fprintf (stdout, "\n");
+  {
+    GNUNET_CRYPTO_hash (&pos->pkey,
+                        sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                        &pid);
+    name = GNUNET_PSEUDONYM_id_to_name (cfg, &pid);
+    FPRINTF (stdout, "`%s' ", name);
+    GNUNET_free (name);
+    pos = pos->next;
+  }
+  FPRINTF (stdout, "%s",  "\n");
   return GNUNET_OK;
 }
 
 
 static int
-do_pm (const char *msg, const void *xtra)
+do_send (const char *msg, const void *xtra)
+{
+  uint32_t seq;
+
+  GNUNET_CHAT_send_message (room, msg, GNUNET_CHAT_MSG_OPTION_NONE, NULL, &seq);
+  return GNUNET_OK;
+}
+
+
+static int
+do_send_pm (const char *msg, const void *xtra)
 {
   char *user;
   GNUNET_HashCode uid;
@@ -364,65 +367,70 @@ do_pm (const char *msg, const void *xtra)
   struct UserList *pos;
 
   if (NULL == strstr (msg, " "))
-    {
-      fprintf (stderr, _("Syntax: /msg USERNAME MESSAGE"));
-      return GNUNET_OK;
-    }
+  {
+    FPRINTF (stderr, "%s",  _("Syntax: /msg USERNAME MESSAGE"));
+    return GNUNET_OK;
+  }
   user = GNUNET_strdup (msg);
   strstr (user, " ")[0] = '\0';
   msg += strlen (user) + 1;
   if (GNUNET_OK != GNUNET_PSEUDONYM_name_to_id (cfg, user, &uid))
-    {
-      fprintf (stderr, _("Unknown user `%s'\n"), user);
-      GNUNET_free (user);
-      return GNUNET_OK;
-    }
+  {
+    FPRINTF (stderr, _("Unknown user `%s'\n"), user);
+    GNUNET_free (user);
+    return GNUNET_OK;
+  }
   pos = users;
   while (NULL != pos)
-    {
-      GNUNET_CRYPTO_hash (&pos->pkey,
-                         sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
-                         &pid);
-      if (0 == memcmp (&pid, &uid, sizeof (GNUNET_HashCode)))
-       break;
-      pos = pos->next;
-    }
+  {
+    GNUNET_CRYPTO_hash (&pos->pkey,
+                        sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                        &pid);
+    if (0 == memcmp (&pid, &uid, sizeof (GNUNET_HashCode)))
+      break;
+    pos = pos->next;
+  }
   if (NULL == pos)
-    {
-      fprintf (stderr, _("User `%s' is currently not in the room!\n"), user);
-      GNUNET_free (user);
-      return GNUNET_OK;
-    }
-  GNUNET_CHAT_send_message (room,
-                           msg,
-                           GNUNET_CHAT_MSG_PRIVATE,
-                           &pos->pkey,
-                           &seq);
+  {
+    FPRINTF (stderr, _("User `%s' is currently not in the room!\n"), user);
+    GNUNET_free (user);
+    return GNUNET_OK;
+  }
+  GNUNET_CHAT_send_message (room, msg, GNUNET_CHAT_MSG_PRIVATE, &pos->pkey,
+                            &seq);
   GNUNET_free (user);
   return GNUNET_OK;
 }
 
 
 static int
-do_transmit_sig (const char *msg, const void *xtra)
+do_send_sig (const char *msg, const void *xtra)
 {
   uint32_t seq;
-  GNUNET_CHAT_send_message (room,
-                           msg,
-                           GNUNET_CHAT_MSG_AUTHENTICATED,
-                           NULL, &seq);
+
+  GNUNET_CHAT_send_message (room, msg, GNUNET_CHAT_MSG_AUTHENTICATED, NULL,
+                            &seq);
   return GNUNET_OK;
 }
 
 
 static int
-do_transmit_ack (const char *msg, const void *xtra)
+do_send_ack (const char *msg, const void *xtra)
 {
   uint32_t seq;
-  GNUNET_CHAT_send_message (room,
-                           msg,
-                           GNUNET_CHAT_MSG_ACKNOWLEDGED,
-                           NULL, &seq);
+
+  GNUNET_CHAT_send_message (room, msg, GNUNET_CHAT_MSG_ACKNOWLEDGED, NULL,
+                            &seq);
+  return GNUNET_OK;
+}
+
+
+static int
+do_send_anonymous (const char *msg, const void *xtra)
+{
+  uint32_t seq;
+
+  GNUNET_CHAT_send_message (room, msg, GNUNET_CHAT_MSG_ANONYMOUS, NULL, &seq);
   return GNUNET_OK;
 }
 
@@ -437,7 +445,7 @@ do_quit (const char *args, const void *xtra)
 static int
 do_unknown (const char *msg, const void *xtra)
 {
-  fprintf (stderr, _("Unknown command `%s'\n"), msg);
+  FPRINTF (stderr, _("Unknown command `%s'\n"), msg);
   return GNUNET_OK;
 }
 
@@ -454,19 +462,24 @@ static struct ChatCommand commands[] = {
    gettext_noop
    ("Use `/nick nickname' to change your nickname.  This will cause you to"
     " leave the current room and immediately rejoin it with the new name.")},
-  {"/msg ", &do_pm,
+  {"/msg ", &do_send_pm,
    gettext_noop
    ("Use `/msg nickname message' to send a private message to the specified"
     " user")},
-  {"/notice ", &do_pm,
+  {"/notice ", &do_send_pm,
    gettext_noop ("The `/notice' command is an alias for `/msg'")},
-  {"/query ", &do_pm,
+  {"/query ", &do_send_pm,
    gettext_noop ("The `/query' command is an alias for `/msg'")},
-  {"/sig ", &do_transmit_sig,
+  {"/sig ", &do_send_sig,
    gettext_noop ("Use `/sig message' to send a signed public message")},
-  {"/ack ", &do_transmit_ack,
+  {"/ack ", &do_send_ack,
    gettext_noop
    ("Use `/ack message' to require signed acknowledgment of the message")},
+  {"/anonymous ", &do_send_anonymous,
+   gettext_noop
+   ("Use `/anonymous message' to send a public anonymous message")},
+  {"/anon ", &do_send_anonymous,
+   gettext_noop ("The `/anon' command is an alias for `/anonymous'")},
   {"/quit", &do_quit,
    gettext_noop ("Use `/quit' to terminate gnunet-chat")},
   {"/leave", &do_quit,
@@ -477,15 +490,11 @@ static struct ChatCommand commands[] = {
   {"/help", &do_help,
    gettext_noop ("Use `/help command' to get help for a specific command")},
   /* Add standard commands:
-     /whois (print metadata),
-     /ignore (set flag, check on receive!) */
-  /* Add special commands (currently supported):
-     + anonymous msgs
-     + authenticated msgs
-   */
+   * /whois (print metadata),
+   * /ignore (set flag, check on receive!) */
   /* the following three commands must be last! */
   {"/", &do_unknown, NULL},
-  {"", &do_transmit, NULL},
+  {"", &do_send, NULL},
   {NULL, NULL, NULL},
 };
 
@@ -494,41 +503,40 @@ static int
 do_help (const char *args, const void *xtra)
 {
   int i;
+
   i = 0;
-  while ((NULL != args) &&
-        (0 != strlen (args)) && (commands[i].Action != &do_help))
+  while ((NULL != args) && (0 != strlen (args)) &&
+         (commands[i].Action != &do_help))
+  {
+    if (0 == strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1))
     {
-      if (0 ==
-         strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1))
-       {
-         fprintf (stdout, "%s\n", gettext (commands[i].helptext));
-         return GNUNET_OK;
-       }
-      i++;
+      FPRINTF (stdout, "%s\n", gettext (commands[i].helptext));
+      return GNUNET_OK;
     }
+    i++;
+  }
   i = 0;
-  fprintf (stdout, "Available commands:");
+  FPRINTF (stdout, "%s",  "Available commands:");
   while (commands[i].Action != &do_help)
-    {
-      fprintf (stdout, " %s", gettext (commands[i].command));
-      i++;
-    }
-  fprintf (stdout, "\n");
-  fprintf (stdout, "%s\n", gettext (commands[i].helptext));
+  {
+    FPRINTF (stdout, " %s", gettext (commands[i].command));
+    i++;
+  }
+  FPRINTF (stdout, "%s",  "\n");
+  FPRINTF (stdout, "%s\n", gettext (commands[i].helptext));
   return GNUNET_OK;
 }
 
 
-static void 
-do_stop_task (void *cls,
-             const struct GNUNET_SCHEDULER_TaskContext *tc)
+static void
+do_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   GNUNET_CHAT_leave_room (room);
   if (handle_cmd_task != GNUNET_SCHEDULER_NO_TASK)
-    {
-      GNUNET_SCHEDULER_cancel (handle_cmd_task);
-      handle_cmd_task = GNUNET_SCHEDULER_NO_TASK;
-    }     
+  {
+    GNUNET_SCHEDULER_cancel (handle_cmd_task);
+    handle_cmd_task = GNUNET_SCHEDULER_NO_TASK;
+  }
   free_user_list ();
   GNUNET_CONTAINER_meta_data_destroy (meta);
   GNUNET_free (room_name);
@@ -554,8 +562,9 @@ handle_command (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     goto next;
   i = 0;
   while ((NULL != commands[i].command) &&
-        (0 != strncasecmp (commands[i].command,
-                           message, strlen (commands[i].command))))
+         (0 !=
+          strncasecmp (commands[i].command, message,
+                       strlen (commands[i].command))))
     i++;
   if (GNUNET_OK !=
       commands[i].Action (&message[strlen (commands[i].command)], NULL))
@@ -563,10 +572,10 @@ handle_command (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
 next:
   handle_cmd_task =
-    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
-                                                                100),
-                                 &handle_command,
-                                 NULL);
+    GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_relative_multiply
+                                               (GNUNET_TIME_UNIT_MILLISECONDS, 100),
+                                               GNUNET_SCHEDULER_PRIORITY_UI,
+                                               &handle_command, NULL);
   return;
 
 out:
@@ -584,9 +593,7 @@ out:
  * @param c configuration
  */
 static void
-run (void *cls,
-     char *const *args,
-     const char *cfgfile,
+run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
   GNUNET_HashCode me;
@@ -595,48 +602,39 @@ run (void *cls,
   cfg = c;
   /* check arguments */
   if (NULL == nickname)
-    {
-      fprintf (stderr, _("You must specify a nickname\n"));
-      ret = -1;
-      return;
-    }
+  {
+    FPRINTF (stderr, "%s",  _("You must specify a nickname\n"));
+    ret = -1;
+    return;
+  }
   if (NULL == room_name)
     room_name = GNUNET_strdup ("gnunet");
   meta = GNUNET_CONTAINER_meta_data_create ();
-  GNUNET_CONTAINER_meta_data_insert (meta,
-                                    "<gnunet>",
-                                    EXTRACTOR_METATYPE_TITLE,
-                                    EXTRACTOR_METAFORMAT_UTF8,
-                                    "text/plain",
-                                    nickname,
-                                    strlen(nickname)+1);
-  room = GNUNET_CHAT_join_room (cfg,
-                               nickname,
-                               meta,
-                               room_name,
-                               -1,
-                               &receive_cb, NULL,
-                               &member_list_cb, NULL,
-                               &confirmation_cb, NULL, &me);
+  GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", EXTRACTOR_METATYPE_TITLE,
+                                     EXTRACTOR_METAFORMAT_UTF8, "text/plain",
+                                     nickname, strlen (nickname) + 1);
+  room =
+      GNUNET_CHAT_join_room (cfg, nickname, meta, room_name, -1, &join_cb, NULL,
+                             &receive_cb, NULL, &member_list_cb, NULL,
+                             &confirmation_cb, NULL, &me);
   if (NULL == room)
-    {
-      fprintf (stderr, _("Failed to join room `%s'\n"), room_name);
-      GNUNET_free (room_name);
-      GNUNET_free (nickname);
-      GNUNET_CONTAINER_meta_data_destroy (meta);
-      ret = -1;
-      return;
-    }
+  {
+    FPRINTF (stderr, _("Failed to join room `%s'\n"), room_name);
+    GNUNET_free (room_name);
+    GNUNET_free (nickname);
+    GNUNET_CONTAINER_meta_data_destroy (meta);
+    ret = -1;
+    return;
+  }
   my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me);
-  fprintf (stdout, _("Joined room `%s' as user `%s'\n"), room_name, my_name);
+  FPRINTF (stdout, _("Joining room `%s' as user `%s'...\n"), room_name,
+           my_name);
   GNUNET_free (my_name);
   handle_cmd_task =
-    GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
-                                       &handle_command,
-                                       NULL);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                               &do_stop_task,
-                               NULL);
+      GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
+                                          &handle_command, NULL);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_stop_task,
+                                NULL);
 }
 
 
@@ -651,6 +649,7 @@ int
 main (int argc, char *const *argv)
 {
   int flags;
+
   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
     {'n', "nick", "NAME",
      gettext_noop ("set the nickname to use (required)"),
@@ -667,11 +666,9 @@ main (int argc, char *const *argv)
   fcntl (0, F_SETFL, flags);
 #endif
   return (GNUNET_OK ==
-         GNUNET_PROGRAM_run (argc,
-                             argv,
-                             "gnunet-chat",
-                             gettext_noop ("Join a chat on GNUnet."),
-                             options, &run, NULL)) ? ret : 1;
+          GNUNET_PROGRAM_run (argc, argv, "gnunet-chat",
+                              gettext_noop ("Join a chat on GNUnet."), options,
+                              &run, NULL)) ? ret : 1;
 }
 
 /* end of gnunet-chat.c */