Merged silc_1_0_branch to trunk.
[silc.git] / apps / irssi / src / silc / core / silc-channels.c
index 005763bf6439d0b636f2b89c72ecfb6b7508a0d2..2ebdcc7ab42de108834ae6b9405a080ad8b704ba 100644 (file)
 
 #include "silc-commands.h"
 
+void sig_mime(SILC_SERVER_REC *server, SILC_CHANNEL_REC *channel,
+               const char *blob, const char *enc, const char *type,
+               const char *nick)
+{
+
+  if (!(IS_SILC_SERVER(server)))
+    return;
+  
+  printformat_module("fe-common/silc", server, 
+                        channel == NULL ? NULL : channel->name,
+                        MSGLEVEL_CRAP, SILCTXT_MESSAGE_DATA,
+                        nick == NULL ? "[<unknown>]" : nick, type);
+
+}
+
 SILC_CHANNEL_REC *silc_channel_create(SILC_SERVER_REC *server,
                                      const char *name,
                                      const char *visible_name,
@@ -109,6 +124,11 @@ static void sig_server_quit(SILC_SERVER_REC *server, const char *msg)
     silc_command_exec(server, "QUIT", msg);
 }
 
+static void sig_gui_quit(SILC_SERVER_REC *server, const char *msg)
+{
+  silc_client_stop(silc_client);
+}
+
 /* Find Irssi channel entry by SILC channel entry */
 
 SILC_CHANNEL_REC *silc_channel_find_entry(SILC_SERVER_REC *server,
@@ -356,17 +376,14 @@ static void command_notice(const char *data, SILC_SERVER_REC *server,
 /* AWAY local command.  Sends UMODE command that sets the SILC_UMODE_GONE
    flag. */
 
-static void command_away(const char *data, SILC_SERVER_REC *server,
-                        WI_ITEM_REC *item)
+bool silc_set_away(const char *reason, SILC_SERVER_REC *server)
 {
   bool set;
-
-  CMD_SILC_SERVER(server);
-
+  
   if (!IS_SILC_SERVER(server) || !server->connected)
-    cmd_return_error(CMDERR_NOT_CONNECTED);
-
-  if (*data == '\0') {
+    return FALSE;
+  
+  if (*reason == '\0') {
     /* Remove any possible away message */
     silc_client_set_away_message(silc_client, server->conn, NULL);
     set = FALSE;
@@ -375,21 +392,37 @@ static void command_away(const char *data, SILC_SERVER_REC *server,
                       SILCTXT_UNSET_AWAY);
   } else {
     /* Set the away message */
-    silc_client_set_away_message(silc_client, server->conn, (char *)data);
+    silc_client_set_away_message(silc_client, server->conn, (char *)reason);
     set = TRUE;
 
     printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP, 
-                      SILCTXT_SET_AWAY, data);
+                      SILCTXT_SET_AWAY, reason);
   }
 
   server->usermode_away = set;
   g_free_and_null(server->away_reason);
   if (set)
-    server->away_reason = g_strdup((char *)data);
+    server->away_reason = g_strdup((char *)reason);
 
   signal_emit("away mode changed", 1, server);
 
-  silc_command_exec(server, "UMODE", set ? "+g" : "-g");
+  return set;
+}
+
+static void command_away(const char *data, SILC_SERVER_REC *server,
+                        WI_ITEM_REC *item)
+{
+  CMD_SILC_SERVER(server);
+
+  if (!IS_SILC_SERVER(server) || !server->connected)
+    cmd_return_error(CMDERR_NOT_CONNECTED);
+
+  g_free_and_null(server->away_reason);
+  if ((data) && (*data != '\0'))
+    server->away_reason = g_strdup(data);
+  
+  silc_command_exec(server, "UMODE", 
+                   (server->away_reason != NULL) ? "+g" : "-g");
 }
 
 typedef struct {
@@ -424,7 +457,7 @@ static void keyagr_completion(SilcClient client,
       /* Set the private key for this client */
       silc_client_del_private_message_key(client, conn, client_entry);
       silc_client_add_private_message_key_ske(client, conn, client_entry,
-                                             NULL, key, i->responder);
+                                             NULL, NULL, key, i->responder);
       printformat_module("fe-common/silc", i->server, NULL, MSGLEVEL_CRAP,
                         SILCTXT_KEY_AGREEMENT_PRIVMSG, 
                         client_entry->nickname);
@@ -612,23 +645,36 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
     command = 1;
 
     if (argc >= 5) {
+      char *cipher = NULL, *hmac = NULL;
+
       if (type == 1 && client_entry) {
        /* Set private message key */
+       bool responder = FALSE;
        
        silc_client_del_private_message_key(silc_client, conn, client_entry);
 
-       if (argc >= 6)
-         silc_client_add_private_message_key(silc_client, conn, client_entry,
-                                             argv[5], argv[4],
-                                             argv_lens[4],
-                                             (argv[4][0] == '*' ?
-                                              TRUE : FALSE), FALSE);
-       else
-         silc_client_add_private_message_key(silc_client, conn, client_entry,
-                                             NULL, argv[4],
-                                             argv_lens[4],
-                                             (argv[4][0] == '*' ?
-                                              TRUE : FALSE), FALSE);
+       if (argc >= 6) {
+         if (!strcasecmp(argv[5], "-responder"))
+           responder = TRUE;
+         else
+           cipher = argv[5];
+       }
+       if (argc >= 7) {
+         if (!strcasecmp(argv[6], "-responder"))
+           responder = TRUE;
+         else
+           hmac = argv[6];
+       }
+       if (argc >= 8) {
+         if (!strcasecmp(argv[7], "-responder"))
+           responder = TRUE;
+       }
+
+       silc_client_add_private_message_key(silc_client, conn, client_entry,
+                                           cipher, hmac,
+                                           argv[4], argv_lens[4],
+                                           (argv[4][0] == '*' ?
+                                            TRUE : FALSE), responder);
 
        /* Send the key to the remote client so that it starts using it
           too. */
@@ -639,8 +685,6 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
        */
       } else if (type == 2) {
        /* Set private channel key */
-       char *cipher = NULL, *hmac = NULL;
-
        if (!(channel_entry->mode & SILC_CHANNEL_MODE_PRIVKEY)) {
          printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
                             SILCTXT_CH_PRIVATE_KEY_NOMODE, 
@@ -977,6 +1021,8 @@ void silc_channels_init(void)
   signal_add("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed);
   signal_add("server connected", (SIGNAL_FUNC) sig_connected);
   signal_add("server quit", (SIGNAL_FUNC) sig_server_quit);
+  signal_add("gui exit", (SIGNAL_FUNC) sig_gui_quit);
+  signal_add("mime", (SIGNAL_FUNC) sig_mime);
 
   command_bind_silc("part", MODULE_NAME, (SIGNAL_FUNC) command_part);
   command_bind_silc("me", MODULE_NAME, (SIGNAL_FUNC) command_me);
@@ -984,7 +1030,7 @@ void silc_channels_init(void)
   command_bind_silc("notice", MODULE_NAME, (SIGNAL_FUNC) command_notice);
   command_bind_silc("away", MODULE_NAME, (SIGNAL_FUNC) command_away);
   command_bind_silc("key", MODULE_NAME, (SIGNAL_FUNC) command_key);
-  command_bind_silc("listkeys", MODULE_NAME, (SIGNAL_FUNC) command_listkeys);
+/*  command_bind_silc("listkeys", MODULE_NAME, (SIGNAL_FUNC) command_listkeys); */
 
   silc_nicklist_init();
 }
@@ -994,6 +1040,8 @@ void silc_channels_deinit(void)
   signal_remove("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed);
   signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
   signal_remove("server quit", (SIGNAL_FUNC) sig_server_quit);
+  signal_remove("gui exit", (SIGNAL_FUNC) sig_gui_quit);
+  signal_remove("mime", (SIGNAL_FUNC) sig_mime);
 
   command_unbind("part", (SIGNAL_FUNC) command_part);
   command_unbind("me", (SIGNAL_FUNC) command_me);
@@ -1001,7 +1049,7 @@ void silc_channels_deinit(void)
   command_unbind("notice", (SIGNAL_FUNC) command_notice);
   command_unbind("away", (SIGNAL_FUNC) command_away);
   command_unbind("key", (SIGNAL_FUNC) command_key);
-  command_unbind("listkeys", (SIGNAL_FUNC) command_listkeys);
+/*  command_unbind("listkeys", (SIGNAL_FUNC) command_listkeys); */
 
   silc_nicklist_deinit();
 }