Merged silc_1_0_branch to trunk.
[silc.git] / apps / irssi / src / silc / core / silc-servers.c
index c72705885798aecbb23ae7ee873220e5619c7737..0287eb772649ac12d94a9766660881d03276f01b 100644 (file)
@@ -1,14 +1,14 @@
 /*
   silc-server.c : irssi
 
-  Copyright (C) 2000 - 2001 Timo Sirainen
-                            Pekka Riikonen <priikone@poseidon.pspt.fi>
+  Copyright (C) 2000 - 2003 Timo Sirainen
+                            Pekka Riikonen <priikone@silcnet.org>
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
-  
+
   This program 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
 void silc_servers_reconnect_init(void);
 void silc_servers_reconnect_deinit(void);
 
-static void silc_send_channel(SILC_SERVER_REC *server,
-                             char *channel, char *msg)
+static int silc_send_channel(SILC_SERVER_REC *server,
+                             char *channel, char *msg,
+                             SilcMessageFlags flags)
 {
   SILC_CHANNEL_REC *rec;
-  
+
   rec = silc_channel_find(server, channel);
   if (rec == NULL || rec->entry == NULL) {
-    cmd_return_error(CMDERR_NOT_JOINED);
-    return;
+    cmd_return_error_value(CMDERR_NOT_JOINED, FALSE);
   }
 
-  silc_client_send_channel_message(silc_client, server->conn, rec->entry, 
-                                  NULL, SILC_MESSAGE_FLAG_UTF8,
-                                  msg, strlen(msg), TRUE);
+  silc_client_send_channel_message(silc_client, server->conn, rec->entry,
+                                  NULL, flags, msg, strlen(msg), TRUE);
+  return TRUE;
 }
 
 typedef struct {
@@ -89,7 +89,7 @@ static void silc_send_msg_clients(SilcClient client,
   char *nickname = NULL;
 
   if (!clients_count) {
-    printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, 
+    printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
              "%s: There is no such client", rec->nick);
   } else {
     if (clients_count > 1) {
@@ -97,11 +97,11 @@ static void silc_send_msg_clients(SilcClient client,
 
       /* Find the correct one. The rec->nick might be a formatted nick
         so this will find the correct one. */
-      clients = silc_client_get_clients_local(silc_client, server->conn, 
-                                             nickname, rec->nick, 
+      clients = silc_client_get_clients_local(silc_client, server->conn,
+                                             nickname, rec->nick,
                                              &clients_count);
       if (!clients) {
-       printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, 
+       printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
                  "%s: There is no such client", rec->nick);
        silc_free(nickname);
        goto out;
@@ -113,29 +113,29 @@ static void silc_send_msg_clients(SilcClient client,
 
     /* Still check for exact math for nickname, this compares the
        real (formatted) nickname and the nick (maybe formatted) that
-       use gave. This is to assure that `nick' does not match 
+       use gave. This is to assure that `nick' does not match
        `nick@host'. */
     if (strcasecmp(rec->nick, clients[0]->nickname)) {
-      printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, 
+      printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
                "%s: There is no such client", rec->nick);
       goto out;
     }
 
     /* Send the private message */
-    silc_client_send_private_message(client, conn, target, 
+    silc_client_send_private_message(client, conn, target,
                                     rec->flags,
                                     rec->msg, rec->len,
                                     TRUE);
   }
-  
+
  out:
   g_free(rec->nick);
   g_free(rec->msg);
   g_free(rec);
 }
 
-static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg,
-                       int msg_len, SilcMessageFlags flags)
+static int silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg,
+                         int msg_len, SilcMessageFlags flags)
 {
   PRIVMSG_REC *rec;
   SilcClientEntry *clients;
@@ -145,11 +145,11 @@ static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg,
   if (!silc_parse_userfqdn(nick, &nickname, NULL)) {
     printformat_module("fe-common/silc", server, NULL,
                       MSGLEVEL_CRAP, SILCTXT_BAD_NICK, nick);
-    return;
+    return FALSE;
   }
 
   /* Find client entry */
-  clients = silc_client_get_clients_local(silc_client, server->conn, 
+  clients = silc_client_get_clients_local(silc_client, server->conn,
                                          nickname, nick, &clients_count);
   if (!clients) {
     rec = g_new0(PRIVMSG_REC, 1);
@@ -163,32 +163,37 @@ static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg,
     silc_client_get_clients(silc_client, server->conn,
                            nickname, NULL, silc_send_msg_clients, rec);
     silc_free(nickname);
-    return;
+    return FALSE;
   }
 
   /* Send the private message directly */
   silc_free(nickname);
-  silc_client_send_private_message(silc_client, server->conn, 
+  silc_client_send_private_message(silc_client, server->conn,
                                   clients[0], flags,
                                   msg, msg_len, TRUE);
+  return TRUE;
 }
 
 void silc_send_mime(SILC_SERVER_REC *server, WI_ITEM_REC *to,
-                   const char *data, int data_len,
+                   const char *data,
                    const char *enc, const char *type)
 {
   SILC_CHANNEL_REC *channel;
   QUERY_REC *query;
+  char *unescaped_data;
+  SilcUInt32 unescaped_data_len;
   char *mime_data;
   int mime_data_len;
-  
-  if (!(IS_SILC_SERVER(server)) || (data == NULL) || (to == NULL) || 
+
+  if (!(IS_SILC_SERVER(server)) || (data == NULL) || (to == NULL) ||
       (enc == NULL) || (type == NULL))
     return;
-           
+
+  unescaped_data = silc_unescape_data(data, &unescaped_data_len);
+
 #define SILC_MIME_HEADER "MIME-Version: 1.0\r\nContent-Type: %s\r\nContent-Transfer-Encoding: %s\r\n\r\n"
 
-  mime_data_len = data_len + strlen(SILC_MIME_HEADER) - 4
+  mime_data_len = unescaped_data_len + strlen(SILC_MIME_HEADER) - 4
     + strlen(enc) + strlen(type);
   if (mime_data_len >= SILC_PACKET_MAX_LEN)
     return;
@@ -197,23 +202,24 @@ void silc_send_mime(SILC_SERVER_REC *server, WI_ITEM_REC *to,
   mime_data = silc_calloc(mime_data_len, sizeof(*mime_data));
   snprintf(mime_data, mime_data_len, SILC_MIME_HEADER, type, enc);
   memmove(mime_data + strlen(SILC_MIME_HEADER) - 4 + strlen(enc) + strlen(type),
-         data, data_len);
+         unescaped_data, unescaped_data_len);
 
 #undef SILC_MIME_HEADER
 
   if (IS_SILC_CHANNEL(to)) {
     channel = SILC_CHANNEL(to);
-    silc_client_send_channel_message(silc_client, server->conn, channel->entry, 
+    silc_client_send_channel_message(silc_client, server->conn, channel->entry,
                                     NULL, SILC_MESSAGE_FLAG_DATA,
                                     mime_data, mime_data_len, TRUE);
   } else if (IS_SILC_QUERY(to)) {
     query = SILC_QUERY(to);
     silc_send_msg(server, query->name, mime_data, mime_data_len,
                  SILC_MESSAGE_FLAG_DATA);
-    
+
   }
 
   silc_free(mime_data);
+  silc_free(unescaped_data);
 }
 
 static int isnickflag_func(char flag)
@@ -249,7 +255,8 @@ static void send_message(SILC_SERVER_REC *server, char *target,
   }
 
   if (target_type == SEND_TARGET_CHANNEL)
-    silc_send_channel(server, target, message ? message : msg);
+    silc_send_channel(server, target, message ? message : msg,
+                     SILC_MESSAGE_FLAG_UTF8);
   else
     silc_send_msg(server, target, message ? message : msg,
                  message ? strlen(message) : strlen(msg),
@@ -258,7 +265,7 @@ static void send_message(SILC_SERVER_REC *server, char *target,
   silc_free(message);
 }
 
-void silc_send_heartbeat(SilcSocketConnection sock, 
+void silc_send_heartbeat(SilcSocketConnection sock,
                         void *hb_context)
 {
   SILC_SERVER_REC *server = SILC_SERVER(hb_context);
@@ -266,8 +273,8 @@ void silc_send_heartbeat(SilcSocketConnection sock,
   if (server == NULL)
     return;
 
-  silc_client_packet_send(silc_client, sock, SILC_PACKET_HEARTBEAT,
-                         NULL, 0, NULL, NULL, NULL, 0, FALSE);
+  silc_client_send_packet(silc_client, server->conn, SILC_PACKET_HEARTBEAT,
+                         NULL, 0);
 }
 
 static void sig_connected(SILC_SERVER_REC *server)
@@ -347,7 +354,7 @@ SERVER_REC *silc_server_init_connect(SERVER_CONNECT_REC *conn)
   SILC_SERVER_REC *server;
 
   g_return_val_if_fail(IS_SILC_SERVER_CONNECT(conn), NULL);
-  if (conn->address == NULL || *conn->address == '\0') 
+  if (conn->address == NULL || *conn->address == '\0')
     return NULL;
   if (conn->nick == NULL || *conn->nick == '\0') {
     silc_say_error("Cannot connect: nickname is not set");
@@ -359,7 +366,7 @@ SERVER_REC *silc_server_init_connect(SERVER_CONNECT_REC *conn)
   server->connrec = (SILC_SERVER_CONNECT_REC *)conn;
   server_connect_ref(conn);
 
-  if (server->connrec->port <= 0) 
+  if (server->connrec->port <= 0)
     server->connrec->port = 706;
 
   server_connect_init((SERVER_REC *)server);
@@ -375,7 +382,7 @@ void silc_server_connect(SERVER_REC *server)
   }
 }
 
-/* Return a string of all channels in server in server->channels_join() 
+/* Return a string of all channels in server in server->channels_join()
    format */
 
 char *silc_server_get_channels(SILC_SERVER_REC *server)
@@ -389,7 +396,7 @@ char *silc_server_get_channels(SILC_SERVER_REC *server)
   chans = g_string_new(NULL);
   for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
     CHANNEL_REC *channel = tmp->data;
-    
+
     g_string_sprintfa(chans, "%s,", channel->name);
   }
 
@@ -398,7 +405,7 @@ char *silc_server_get_channels(SILC_SERVER_REC *server)
 
   ret = chans->str;
   g_string_free(chans, FALSE);
-  
+
   return ret;
 }
 
@@ -414,7 +421,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|change [<arguments>] */
 /* SYNTAX: KICK <channel> <nickname>[@<hostname>] [<comment>] */
-/* SYNTAX: KILL <nickname>[@<hostname>] [<comment>] */
+/* SYNTAX: KILL <nickname>[@<hostname>] [<comment>] [-pubkey] */
 /* SYNTAX: OPER <username> [-pubkey] */
 /* SYNTAX: SILCOPER <username> [-pubkey] */
 /* SYNTAX: TOPIC <channel> [<topic>] */
@@ -435,54 +442,27 @@ char *silc_server_get_channels(SILC_SERVER_REC *server)
 /* SYNTAX: PING */
 /* SYNTAX: SCONNECT <server> [<port>] */
 /* SYNTAX: USERS <channel> */
-/* SYNTAX: FILE SEND <filepath> <nickname> [<local IP> [<local port>]] */
-/* SYNTAX: FILE RECEIVE [<nickname>] */
+/* SYNTAX: FILE SEND <filepath> <nickname> [<local IP> [<local port>]] [-no-listener]*/
+/* SYNTAX: FILE ACCEPT [<nickname>] */
 /* SYNTAX: FILE CLOSE [<nickname>] */
 /* SYNTAX: FILE */
-/* SYNTAX: JOIN <channel> [<passphrase>] [-cipher <cipher>] [-hmac <hmac>] [-founder] */
+/* SYNTAX: JOIN <channel> [<passphrase>] [-cipher <cipher>] [-hmac <hmac>] [-founder] [-auth [<pubkeyfile> <privkeyfile> [<privkey passphrase>]]]*/
 /* SYNTAX: DETACH */
 /* SYNTAX: WATCH [<-add | -del> <nickname>] */
 /* SYNTAX: STATS */
 /* SYNTAX: ATTR [<-del> <option> [{ <value>}]] */
+/* SYNTAX: SMSG [<-channel>] <target> <message> */
 
 void silc_command_exec(SILC_SERVER_REC *server,
                       const char *command, const char *args)
 {
-  SilcUInt32 argc = 0;
-  unsigned char **argv;
-  SilcUInt32 *argv_lens, *argv_types;
-  char *data, *tmpcmd;
-  SilcClientCommand cmd;
-  SilcClientCommandContext ctx;
-
+  char *data;
   g_return_if_fail(server != NULL);
 
-  tmpcmd = g_strdup(command); 
-  g_strup(tmpcmd);
-  cmd = silc_client_command_find(silc_client, tmpcmd);
-  g_free(tmpcmd);
-  if (cmd == NULL)
-    return;
-  
-  /* Now parse all arguments */
+  /* Call the command */
   data = g_strconcat(command, " ", args, NULL);
-  silc_parse_command_line(data, &argv, &argv_lens,
-                         &argv_types, &argc, cmd->max_args);
+  silc_client_command_call(silc_client, server->conn, data);
   g_free(data);
-
-  /* Allocate command context. This and its internals must be free'd
-     by the command routine receiving it. */
-  ctx = silc_client_command_alloc();
-  ctx->client = silc_client;
-  ctx->conn = server->conn;
-  ctx->command = cmd;
-  ctx->argc = argc;
-  ctx->argv = argv;
-  ctx->argv_lens = argv_lens;
-  ctx->argv_types = argv_types;
-  
-  /* Execute command */
-  silc_client_command_call(cmd, ctx);
 }
 
 /* Generic command function to call any SILC command directly. */
@@ -523,6 +503,77 @@ static void command_sconnect(const char *data, SILC_SERVER_REC *server)
   signal_stop();
 }
 
+/* SMSG command, to send digitally signed messages */
+
+static void command_smsg(const char *data, SILC_SERVER_REC *server,
+                        WI_ITEM_REC *item)
+{
+  GHashTable *optlist;
+  char *target, *origtarget, *msg;
+  void *free_arg;
+  int free_ret, target_type;
+
+  g_return_if_fail(data != NULL);
+  if (server == NULL || !server->connected)
+    cmd_param_error(CMDERR_NOT_CONNECTED);
+
+  if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS |
+                     PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
+                     "msg", &optlist, &target, &msg))
+    return;
+  if (*target == '\0' || *msg == '\0')
+    cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
+
+  origtarget = target;
+  free_ret = FALSE;
+
+  if (strcmp(target, "*") == 0) {
+    if (item == NULL)
+      cmd_param_error(CMDERR_NOT_JOINED);
+
+    target_type = IS_CHANNEL(item) ?
+      SEND_TARGET_CHANNEL : SEND_TARGET_NICK;
+    target = (char *) window_item_get_target(item);
+  } else if (g_hash_table_lookup(optlist, "channel") != NULL) {
+    target_type = SEND_TARGET_CHANNEL;
+  } else {
+    target_type = server_ischannel(SERVER(server), target) ?
+      SEND_TARGET_CHANNEL : SEND_TARGET_NICK;
+  }
+
+  if (target != NULL) {
+    char *message = NULL;
+    int len, result;
+
+    if (!silc_term_utf8()) {
+      len = silc_utf8_encoded_len(msg, strlen(msg), SILC_STRING_LANGUAGE);
+      message = silc_calloc(len + 1, sizeof(*message));
+      g_return_if_fail(message != NULL);
+      silc_utf8_encode(msg, strlen(msg), SILC_STRING_LANGUAGE, message, len);
+    }
+
+    if (target_type == SEND_TARGET_CHANNEL)
+      result = silc_send_channel(server, target, message ? message : msg,
+                                SILC_MESSAGE_FLAG_UTF8 |
+                                SILC_MESSAGE_FLAG_SIGNED);
+    else
+      result = silc_send_msg(server, target, message ? message : msg,
+                            message ? strlen(message) : strlen(msg),
+                            SILC_MESSAGE_FLAG_UTF8 |
+                            SILC_MESSAGE_FLAG_SIGNED);
+    silc_free(message);
+    if (!result)
+      goto out;
+  }
+
+  signal_emit(target != NULL && target_type == SEND_TARGET_CHANNEL ?
+             "message signed_own_public" : "message signed_own_private", 4,
+             server, msg, target, origtarget);
+out:
+  if (free_ret && target != NULL) g_free(target);
+  cmd_params_free(free_arg);
+}
+
 /* FILE command */
 
 SILC_TASK_CALLBACK(silc_client_file_close_later)
@@ -568,12 +619,12 @@ static void silc_client_file_monitor(SilcClient client,
   if (status == SILC_CLIENT_FILE_MONITOR_ERROR) {
     if (error == SILC_CLIENT_FILE_NO_SUCH_FILE)
       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
-                        SILCTXT_FILE_ERROR_NO_SUCH_FILE, 
-                        client_entry->nickname, 
+                        SILCTXT_FILE_ERROR_NO_SUCH_FILE,
+                        client_entry->nickname,
                         filepath ? filepath : "[N/A]");
     else if (error == SILC_CLIENT_FILE_PERMISSION_DENIED)
       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
-                        SILCTXT_FILE_ERROR_PERMISSION_DENIED, 
+                        SILCTXT_FILE_ERROR_PERMISSION_DENIED,
                         client_entry->nickname);
     else
       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
@@ -662,7 +713,7 @@ static void silc_client_command_file_get_clients(SilcClient client,
   FileGetClients internal = (FileGetClients)context;
 
   if (!clients) {
-    printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown nick: %s", 
+    printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown nick: %s",
              internal->nick);
     silc_free(internal->data);
     silc_free(internal->nick);
@@ -694,6 +745,7 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
   char *local_ip = NULL;
   SilcUInt32 local_port = 0;
   SilcUInt32 session_id;
+  bool do_not_bind = FALSE;
 
   CMD_SILC_SERVER(server);
   if (!server || !IS_SILC_SERVER(server) || !server->connected)
@@ -703,7 +755,7 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
 
   /* Now parse all arguments */
   tmp = g_strconcat("FILE", " ", data, NULL);
-  silc_parse_command_line(tmp, &argv, &argv_lens, &argv_types, &argc, 6);
+  silc_parse_command_line(tmp, &argv, &argv_lens, &argv_types, &argc, 7);
   g_free(tmp);
 
   if (argc == 1)
@@ -712,12 +764,12 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
   if (argc >= 2) {
     if (!strcasecmp(argv[1], "send"))
       type = 1;
-    if (!strcasecmp(argv[1], "receive"))
+    if (!strcasecmp(argv[1], "accept"))
       type = 2;
     if (!strcasecmp(argv[1], "close"))
       type = 3;
   }
-  
+
   if (type == 0)
     cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
 
@@ -732,7 +784,7 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
                         MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[3]);
       goto out;
     }
-    
+
     /* Find client entry */
     entrys = silc_client_get_clients_local(silc_client, conn, nickname,
                                           argv[3], &entry_count);
@@ -749,14 +801,26 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
     client_entry = entrys[0];
     silc_free(entrys);
 
-    if (argc >= 5)
-      local_ip = argv[4];
-    if (argc >= 6)
-      local_port = atoi(argv[5]);
+    if (argc >= 5) {
+      if (!strcasecmp(argv[4], "-no-listener"))
+       do_not_bind = TRUE;
+      else
+       local_ip = argv[4];
+    }
+    if (argc >= 6) {
+      if (!strcasecmp(argv[5], "-no-listener"))
+       do_not_bind = TRUE;
+      else
+       local_port = atoi(argv[5]);
+    }
+    if (argc >= 7) {
+      if (!strcasecmp(argv[6], "-no-listener"))
+       do_not_bind = TRUE;
+    }
 
-    ret = 
-      silc_client_file_send(silc_client, conn, silc_client_file_monitor, 
-                           server, local_ip, local_port, 
+    ret =
+      silc_client_file_send(silc_client, conn, silc_client_file_monitor,
+                           server, local_ip, local_port, do_not_bind,
                            client_entry, argv[2], &session_id);
     if (ret == SILC_CLIENT_FILE_OK) {
       ftp = silc_calloc(1, sizeof(*ftp));
@@ -779,7 +843,7 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
                           client_entry->nickname);
       if (ret == SILC_CLIENT_FILE_NO_SUCH_FILE)
        printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
-                          SILCTXT_FILE_ERROR_NO_SUCH_FILE, 
+                          SILCTXT_FILE_ERROR_NO_SUCH_FILE,
                           client_entry->nickname, argv[2]);
     }
 
@@ -793,7 +857,7 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
                           MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
        goto out;
       }
-    
+
       /* Find client entry */
       entrys = silc_client_get_clients_local(silc_client, conn, nickname,
                                             argv[2], &entry_count);
@@ -816,7 +880,7 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
        goto out;
       }
 
-      ret = silc_client_file_receive(silc_client, conn, 
+      ret = silc_client_file_receive(silc_client, conn,
                                     silc_client_file_monitor, server, NULL,
                                     server->current_session->session_id);
       if (ret != SILC_CLIENT_FILE_OK) {
@@ -836,7 +900,7 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
     silc_dlist_start(server->ftp_sessions);
     while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
       if (ftp->client_entry == client_entry && !ftp->filepath) {
-       ret = silc_client_file_receive(silc_client, conn, 
+       ret = silc_client_file_receive(silc_client, conn,
                                       silc_client_file_monitor, server,
                                       NULL, ftp->session_id);
        if (ret != SILC_CLIENT_FILE_OK) {
@@ -869,7 +933,7 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
                           MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
        goto out;
       }
-    
+
       /* Find client entry */
       entrys = silc_client_get_clients_local(silc_client, conn, nickname,
                                             argv[2], &entry_count);
@@ -891,8 +955,8 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
                           MSGLEVEL_CRAP, SILCTXT_FILE_NA);
        goto out;
       }
-      silc_client_file_close(silc_client, conn, 
+
+      silc_client_file_close(silc_client, conn,
                             server->current_session->session_id);
       printformat_module("fe-common/silc", server, NULL,
                         MSGLEVEL_CRAP, SILCTXT_FILE_CLOSED,
@@ -946,7 +1010,7 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
     while ((ftp = silc_dlist_get(server->ftp_sessions)) != SILC_LIST_END) {
       printformat_module("fe-common/silc", server, NULL,
                         MSGLEVEL_CRAP, SILCTXT_FILE_SHOW_LINE,
-                        ftp->client_entry->nickname, 
+                        ftp->client_entry->nickname,
                         ftp->send ? "send" : "receive",
                         (SilcUInt32)(ftp->offset + 1023) / 1024,
                         (SilcUInt32)(ftp->filesize + 1023) / 1024,
@@ -998,6 +1062,7 @@ void silc_server_init(void)
   command_bind_silc("watch", MODULE_NAME, (SIGNAL_FUNC) command_self);
   command_bind_silc("stats", MODULE_NAME, (SIGNAL_FUNC) command_self);
   command_bind_silc("attr", MODULE_NAME, (SIGNAL_FUNC) command_attr);
+  command_bind_silc("smsg", MODULE_NAME, (SIGNAL_FUNC) command_smsg);
 
   command_set_options("connect", "+silcnet");
 }
@@ -1036,6 +1101,7 @@ void silc_server_deinit(void)
   command_unbind("watch", (SIGNAL_FUNC) command_self);
   command_unbind("stats", (SIGNAL_FUNC) command_self);
   command_unbind("attr", (SIGNAL_FUNC) command_attr);
+  command_unbind("smsg", (SIGNAL_FUNC) command_smsg);
 }
 
 void silc_server_free_ftp(SILC_SERVER_REC *server,