updates.
[silc.git] / apps / irssi / src / silc / core / silc-servers.c
index 4afc351790fa9bd65f574b910c5af4782d70bade..210740a1b863ae196f6bea2c3665cdfb4536205c 100644 (file)
@@ -37,6 +37,7 @@
 #include "silc-servers.h"
 #include "silc-channels.h"
 #include "silc-queries.h"
+#include "silc-nicklist.h"
 #include "window-item-def.h"
 
 #include "fe-common/core/printtext.h"
@@ -204,10 +205,10 @@ static void sig_connected(SILC_SERVER_REC *server)
 
 static void sig_disconnected(SILC_SERVER_REC *server)
 {
-  if (!IS_SILC_SERVER(server) || server->conn == NULL)
+  if (!IS_SILC_SERVER(server))
     return;
   
-  if (server->conn->sock != NULL) {
+  if (server->conn && server->conn->sock != NULL) {
     silc_client_close_connection(silc_client, NULL, server->conn);
     
     /* SILC closes the handle */
@@ -284,7 +285,7 @@ char *silc_server_get_channels(SILC_SERVER_REC *server)
 /* SYNTAX: KEY MSG <nickname> set|unset|list|agreement|negotiate [<arguments>] */
 /* SYNTAX: KEY CHANNEL <channel> set|unset|list|agreement|negotiate [<arguments>] */
 /* SYNTAX: KICK <channel> <nickname>[@<hostname>] [<comment>] */
-/* SYNTAX: KILL <channel> <nickname>[@<hostname>] [<comment>] */
+/* SYNTAX: KILL <nickname>[@<hostname>] [<comment>] */
 /* SYNTAX: OPER <username> [-pubkey] */
 /* SYNTAX: SILCOPER <username> [-pubkey] */
 /* SYNTAX: TOPIC <channel> [<topic>] */
@@ -398,6 +399,90 @@ static void event_text(const char *line, SILC_SERVER_REC *server,
   signal_stop();
 }
 
+typedef struct {
+  SILC_SERVER_REC *server;
+  char *data;
+  WI_ITEM_REC *item;
+} *FileGetClients;
+
+SILC_CLIENT_CMD_FUNC(file_get_clients)
+{
+  FileGetClients internal = (FileGetClients)context;
+  signal_emit("command file", 3, internal->data, internal->server,
+             internal->item);
+  silc_free(internal->data);
+  silc_free(internal);
+}
+
+static void command_file(const char *data, SILC_SERVER_REC *server,
+                        WI_ITEM_REC *item)
+{
+  SilcClientConnection conn;
+  SilcClientEntry client_entry;
+  char *nickname, *tmp;
+  unsigned char **argv;
+  uint32 argc;
+  uint32 *argv_lens, *argv_types;
+  int type;
+
+  if (!server || !IS_SILC_SERVER(server) || !server->connected)
+    cmd_return_error(CMDERR_NOT_CONNECTED);
+
+  conn = server->conn;
+
+  /* Now parse all arguments */
+  tmp = g_strconcat("KEY", " ", data, NULL);
+  silc_parse_command_line(tmp, &argv, &argv_lens, &argv_types, &argc, 4);
+  g_free(tmp);
+
+  type = 0;
+  if (!strcasecmp(argv[1], "send"))
+    type = 1;
+  if (!strcasecmp(argv[1], "receive"))
+    type = 2;
+  
+  /* Parse the typed nickname. */
+  if (!silc_parse_userfqdn(argv[3], &nickname, NULL)) {
+    printformat_module("fe-common/silc", server, NULL,
+                      MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
+    return;
+  }
+
+  /* Find client entry */
+  client_entry = silc_idlist_get_client(silc_client, conn, nickname, 
+                                       argv[3], TRUE);
+  if (!client_entry) {
+    FileGetClients inter = silc_calloc(1, sizeof(*inter));
+    inter->server = server;
+    inter->data = strdup(data);
+    inter->item = item;
+    
+    /* Client entry not found, it was requested thus mark this to be
+       pending command. */
+    silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY, 
+                               conn->cmd_ident, 
+                               NULL, silc_client_command_file_get_clients, 
+                               inter);
+    goto out;
+  }
+
+  switch (type) {
+  case 1:
+    silc_client_file_send(silc_client, conn, NULL, NULL, client_entry,
+                         argv[2]);
+    break;
+
+  case 2:
+    break;
+
+  default:
+    break;
+  }
+
+ out:
+  silc_free(nickname);
+}
+
 void silc_server_init(void)
 {
   silc_servers_reconnect_init();
@@ -427,6 +512,7 @@ void silc_server_init(void)
   command_bind("shutdown", MODULE_NAME, (SIGNAL_FUNC) command_self);
   command_bind("getkey", MODULE_NAME, (SIGNAL_FUNC) command_self);
   command_bind("sconnect", MODULE_NAME, (SIGNAL_FUNC) command_sconnect);
+  command_bind("file", MODULE_NAME, (SIGNAL_FUNC) command_file);
 
   command_set_options("connect", "+silcnet");
 }
@@ -460,4 +546,5 @@ void silc_server_deinit(void)
   command_unbind("shutdown", (SIGNAL_FUNC) command_self);
   command_unbind("getkey", (SIGNAL_FUNC) command_self);
   command_unbind("sconnect", (SIGNAL_FUNC) command_sconnect);
+  command_unbind("file", (SIGNAL_FUNC) command_file);
 }