Added WHOWAS command to server and client.
[runtime.git] / lib / silcclient / command.c
index e81fa2303ca92db5cc93d989b34e5e0858fb2bcc..e01a9b19500102e37c105659a68b4d988c02fa60 100644 (file)
@@ -20,6 +20,7 @@
 /* $Id$ */
 
 #include "clientlibincludes.h"
+#include "client_internal.h"
 
 /* Client command list. */
 SilcClientCommand silc_command_list[] =
@@ -41,7 +42,7 @@ SilcClientCommand silc_command_list[] =
   SILC_CLIENT_CMD(ping, PING, "PING", SILC_CF_LAG | SILC_CF_REG, 2),
   SILC_CLIENT_CMD(oper, OPER, "OPER",
                  SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER, 2),
-  SILC_CLIENT_CMD(join, JOIN, "JOIN", SILC_CF_LAG | SILC_CF_REG, 4),
+  SILC_CLIENT_CMD(join, JOIN, "JOIN", SILC_CF_LAG | SILC_CF_REG, 5),
   SILC_CLIENT_CMD(motd, MOTD, "MOTD", SILC_CF_LAG | SILC_CF_REG, 2),
   SILC_CLIENT_CMD(umode, UMODE, "UMODE", SILC_CF_LAG | SILC_CF_REG, 2),
   SILC_CLIENT_CMD(cmode, CMODE, "CMODE", SILC_CF_LAG | SILC_CF_REG, 4),
@@ -75,7 +76,7 @@ SilcClientCommand silc_command_list[] =
   cmd, FALSE, cmd->command->cmd)
 
 /* Generic function to send any command. The arguments must be sent already
-   encoded into correct form in correct order. */
+   encoded into correct form and in correct order. */
 
 void silc_client_send_command(SilcClient client, SilcClientConnection conn,
                              SilcCommand command, unsigned short ident,
@@ -201,8 +202,7 @@ void silc_client_command_free(SilcClientCommandContext ctx)
 /* Duplicate Command Context by adding reference counter. The context won't
    be free'd untill it hits zero. */
 
-SilcClientCommandContext 
-silc_client_command_dup(SilcClientCommandContext ctx)
+SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx)
 {
   ctx->users++;
   SILC_LOG_DEBUG(("Command context %p refcnt %d->%d", ctx, ctx->users - 1,
@@ -217,6 +217,16 @@ static void silc_client_command_destructor(void *context)
   silc_client_command_free((SilcClientCommandContext)context);
 }
 
+/* silc_client_get_client completion callback */
+void silc_client_command_completion(SilcClient client,
+                                   SilcClientConnection conn,
+                                   SilcClientEntry clients,
+                                   unsigned int clients_count,
+                                   void *context)
+{
+
+}
+
 /* Command WHOIS. This command is used to query information about 
    specific user. */
 
@@ -258,8 +268,45 @@ SILC_CLIENT_CMD_FUNC(whois)
   silc_client_command_free(cmd);
 }
 
+/* Command WHOWAS. This command is used to query history information about
+   specific user that used to exist in the network. */
+
 SILC_CLIENT_CMD_FUNC(whowas)
 {
+  SilcClientCommandContext cmd = (SilcClientCommandContext)context;
+  SilcClientConnection conn = cmd->conn;
+  SilcBuffer buffer;
+
+  if (!cmd->conn) {
+    SILC_NOT_CONNECTED(cmd->client, cmd->conn);
+    COMMAND_ERROR;
+    goto out;
+  }
+
+  if (cmd->argc < 2 || cmd->argc > 3) {
+    cmd->client->ops->say(cmd->client, conn, 
+            "Usage: /WHOWAS <nickname>[@<server>] [<count>]");
+    COMMAND_ERROR;
+    goto out;
+  }
+
+  buffer = silc_command_payload_encode(SILC_COMMAND_WHOWAS,
+                                      cmd->argc - 1, ++cmd->argv,
+                                      ++cmd->argv_lens, ++cmd->argv_types,
+                                      0);
+  silc_client_packet_send(cmd->client, cmd->conn->sock,
+                         SILC_PACKET_COMMAND, NULL, 0, NULL, NULL,
+                         buffer->data, buffer->len, TRUE);
+  silc_buffer_free(buffer);
+  cmd->argv--;
+  cmd->argv_lens--;
+  cmd->argv_types--;
+
+  /* Notify application */
+  COMMAND;
+
+ out:
+  silc_client_command_free(cmd);
 }
 
 /* Command IDENTIFY. This command is used to query information about 
@@ -341,7 +388,7 @@ SILC_CLIENT_CMD_FUNC(nick)
   buffer = silc_command_payload_encode(SILC_COMMAND_NICK,
                                       cmd->argc - 1, ++cmd->argv,
                                       ++cmd->argv_lens, ++cmd->argv_types,
-                                      0);
+                                      ++cmd->conn->cmd_ident);
   silc_client_packet_send(cmd->client, cmd->conn->sock,
                          SILC_PACKET_COMMAND, NULL, 0, NULL, NULL,
                          buffer->data, buffer->len, TRUE);
@@ -490,7 +537,7 @@ SILC_CLIENT_CMD_FUNC(invite)
   }
 
   /* Find channel entry */
-  channel_entry = silc_idlist_get_channel(client, conn, cmd->argv[2]);
+  channel_entry = silc_client_get_channel(client, conn, cmd->argv[2]);
   if (!channel_entry) {
     cmd->client->ops->say(cmd->client, conn, "You are not on that channel");
     COMMAND_ERROR;
@@ -531,7 +578,7 @@ SILC_TASK_CALLBACK(silc_client_command_quit_cb)
 
   /* Close connection */
   q->client->ops->disconnect(q->client, q->conn);
-  silc_client_close_connection(q->client, q->conn->sock);
+  silc_client_close_connection(q->client, q->conn->sock->user_data);
 
   silc_free(q);
 }
@@ -834,7 +881,7 @@ SILC_CLIENT_CMD_FUNC(cmode)
   } else {
     name = cmd->argv[1];
 
-    channel = silc_idlist_get_channel(cmd->client, conn, name);
+    channel = silc_client_get_channel(cmd->client, conn, name);
     if (!channel) {
       cmd->client->ops->say(cmd->client, conn, "You are on that channel");
       COMMAND_ERROR;
@@ -1023,7 +1070,7 @@ SILC_CLIENT_CMD_FUNC(cumode)
   } else {
     name = cmd->argv[1];
 
-    channel = silc_idlist_get_channel(cmd->client, conn, name);
+    channel = silc_client_get_channel(cmd->client, conn, name);
     if (!channel) {
       cmd->client->ops->say(cmd->client, conn, "You are on that channel");
       COMMAND_ERROR;