updates.
[silc.git] / apps / irssi / src / silc / core / silc-channels.c
index 82d6d08020b5dfc40417820aacc2e81611aaddde..459dedd6a5d1d332b8c95d61f37703b026652749 100644 (file)
@@ -89,7 +89,6 @@ static void silc_channels_join(SILC_SERVER_REC *server,
       continue;
     }
 
-    silc_channel_create(server, channel, FALSE);
     silc_command_exec(server, "JOIN", channel);
     g_free(channel);
   }
@@ -289,12 +288,16 @@ static void event_nick(SILC_SERVER_REC *server, va_list va)
 static void event_cmode(SILC_SERVER_REC *server, va_list va)
 {
   SILC_CHANNEL_REC *chanrec;
+  void *entry;
   SilcClientEntry client;
+  SilcServerEntry server_entry;
   SilcChannelEntry channel;
   char *mode;
   uint32 modei;
+  SilcIdType idtype;
 
-  client = va_arg(va, SilcClientEntry);
+  idtype = va_arg(va, int);
+  entry = va_arg(va, void *);
   modei = va_arg(va, uint32);
   (void)va_arg(va, char *);
   (void)va_arg(va, char *);
@@ -311,10 +314,19 @@ static void event_cmode(SILC_SERVER_REC *server, va_list va)
     signal_emit("channel mode changed", 1, chanrec);
   }
   
-  printformat_module("fe-common/silc", server, channel->channel_name,
-                    MSGLEVEL_MODES, SILCTXT_CHANNEL_CMODE,
-                    channel->channel_name, mode ? mode : "removed all",
-                    client->nickname);
+  if (idtype == SILC_ID_CLIENT) {
+    client = (SilcClientEntry)entry;
+    printformat_module("fe-common/silc", server, channel->channel_name,
+                      MSGLEVEL_MODES, SILCTXT_CHANNEL_CMODE,
+                      channel->channel_name, mode ? mode : "removed all",
+                      client->nickname);
+  } else {
+    server_entry = (SilcServerEntry)entry;
+    printformat_module("fe-common/silc", server, channel->channel_name,
+                      MSGLEVEL_MODES, SILCTXT_CHANNEL_CMODE,
+                      channel->channel_name, mode ? mode : "removed all",
+                      server_entry->server_name);
+  }
   
   g_free(mode);
 }
@@ -468,6 +480,14 @@ static void event_kill(SILC_SERVER_REC *server, va_list va)
                       MSGLEVEL_CRAP, SILCTXT_CHANNEL_KILLED_YOU, 
                       tmp ? tmp : "");
   } else {
+    GSList *nicks, *tmpn;
+    nicks = nicklist_get_same_unique(SERVER(server), client_entry);
+    for (tmpn = nicks; tmpn != NULL; tmpn = tmpn->next->next) {
+      CHANNEL_REC *channel = tmpn->data;
+      NICK_REC *nickrec = tmpn->next->data;
+      nicklist_remove(channel, nickrec);
+    }
+
     printformat_module("fe-common/silc", server, NULL,
                       MSGLEVEL_CRAP, SILCTXT_CHANNEL_KILLED, 
                       client_entry->nickname,
@@ -680,6 +700,7 @@ static void command_away(const char *data, SILC_SERVER_REC *server,
 
 typedef struct {
   int type;                    /* 1 = msg, 2 = channel */
+  bool responder;
   SILC_SERVER_REC *server;
 } *KeyInternal;
 
@@ -709,7 +730,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);
+                                             NULL, key, i->responder);
       printformat_module("fe-common/silc", i->server, NULL, MSGLEVEL_NOTICES,
                         SILCTXT_KEY_AGREEMENT_PRIVMSG, 
                         client_entry->nickname);
@@ -773,8 +794,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
   SilcClientConnection conn = server->conn;
   SilcClientEntry client_entry = NULL;
   SilcChannelEntry channel_entry = NULL;
-  uint32 num = 0;
-  char *nickname = NULL, *serv = NULL, *tmp;
+  char *nickname = NULL, *tmp;
   int command = 0, port = 0, type = 0;
   char *hostname = NULL;
   KeyInternal internal = NULL;
@@ -791,7 +811,8 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
   g_free(tmp);
 
   if (argc < 4) {
-    silc_say(silc_client, conn, "Usage: /KEY msg|channel <nickname|channel> "
+    silc_say(silc_client, conn, SILC_CLIENT_MESSAGE_INFO,
+            "Usage: /KEY msg|channel <nickname|channel> "
             "set|unset|agreement|negotiate [<arguments>]");
     return;
   }
@@ -803,7 +824,8 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
     type = 2;
 
   if (type == 0) {
-    silc_say(silc_client, conn, "Usage: /KEY msg|channel <nickname|channel> "
+    silc_say(silc_client, conn, SILC_CLIENT_MESSAGE_INFO,
+            "Usage: /KEY msg|channel <nickname|channel> "
             "set|unset|agreement|negotiate [<arguments>]");
     return;
   }
@@ -813,7 +835,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
       nickname = "*";
     } else {
       /* Parse the typed nickname. */
-      if (!silc_parse_nickname(argv[2], &nickname, &serv, &num)) {
+      if (!silc_parse_userfqdn(argv[2], &nickname, NULL)) {
        printformat_module("fe-common/silc", server, NULL,
                           MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
        return;
@@ -821,7 +843,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
       
       /* Find client entry */
       client_entry = silc_idlist_get_client(silc_client, conn, nickname, 
-                                           serv, num, TRUE);
+                                           argv[2], TRUE);
       if (!client_entry) {
        KeyGetClients inter = silc_calloc(1, sizeof(*inter));
        inter->server = server;
@@ -845,10 +867,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
 
     if (argv[2][0] == '*') {
       if (!conn->current_channel) {
-       if (nickname)
-         silc_free(nickname);
-       if (serv)
-         silc_free(serv);
+       silc_free(nickname);
        cmd_return_error(CMDERR_NOT_JOINED);
       }
       name = conn->current_channel->channel_name;
@@ -858,10 +877,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
 
     channel_entry = silc_client_get_channel(silc_client, conn, name);
     if (!channel_entry) {
-      if (nickname)
-       silc_free(nickname);
-      if (serv)
-       silc_free(serv);
+      silc_free(nickname);
       cmd_return_error(CMDERR_NOT_JOINED);
     }
   }
@@ -881,13 +897,13 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
                                              argv[5], argv[4],
                                              argv_lens[4],
                                              (argv[4][0] == '*' ?
-                                              TRUE : FALSE));
+                                              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));
+                                              TRUE : FALSE), FALSE);
 
        /* Send the key to the remote client so that it starts using it
           too. */
@@ -1009,7 +1025,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
          else
            strcat(buf, "*generated*");
 
-         silc_say(silc_client, conn, "%s", buf);
+         silc_say(silc_client, conn, SILC_CLIENT_MESSAGE_INFO, "%s", buf);
        }
       } else {
        printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
@@ -1040,7 +1056,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
          else
            strcat(buf, "*generated*");
 
-         silc_say(silc_client, conn, "%s", buf);
+         silc_say(silc_client, conn, SILC_CLIENT_MESSAGE_INFO, "%s", buf);
        }
       }
 
@@ -1080,7 +1096,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
        
        strcat(buf, "<hidden>");
 
-       silc_say(silc_client, conn, "%s", buf);
+       silc_say(silc_client, conn, SILC_CLIENT_MESSAGE_INFO, "%s", buf);
       }
       
       silc_client_free_channel_private_keys(keys, keys_count);
@@ -1119,7 +1135,8 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
   }
 
   if (command == 0) {
-    silc_say(silc_client, conn, "Usage: /KEY msg|channel <nickname|channel> "
+    silc_say(silc_client, conn, SILC_CLIENT_MESSAGE_INFO,
+            "Usage: /KEY msg|channel <nickname|channel> "
             "set|unset|agreement|negotiate [<arguments>]");
     goto out;
   }
@@ -1127,14 +1144,18 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
   if (command == 4 && client_entry) {
     printformat_module("fe-common/silc", server, NULL, MSGLEVEL_NOTICES,
                       SILCTXT_KEY_AGREEMENT, argv[2]);
+    internal->responder = TRUE;
     silc_client_send_key_agreement(silc_client, conn, client_entry, hostname, 
                                   port, 120, keyagr_completion, internal);
+    if (!hostname)
+      silc_free(internal);
     goto out;
   }
 
   if (command == 5 && client_entry && hostname) {
     printformat_module("fe-common/silc", server, NULL, MSGLEVEL_NOTICES,
                       SILCTXT_KEY_AGREEMENT_NEGOTIATE, argv[2]);
+    internal->responder = FALSE;
     silc_client_perform_key_agreement(silc_client, conn, client_entry, 
                                      hostname, port, keyagr_completion, 
                                      internal);
@@ -1142,10 +1163,15 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
   }
 
  out:
-  if (nickname)
-    silc_free(nickname);
-  if (serv)
-    silc_free(serv);
+  silc_free(nickname);
+}
+
+/* Lists locally saved client and server public keys. */
+
+static void command_listkeys(const char *data, SILC_SERVER_REC *server,
+                            WI_ITEM_REC *item)
+{
+
 }
 
 void silc_channels_init(void)
@@ -1174,6 +1200,7 @@ void silc_channels_init(void)
   command_bind("notice", MODULE_NAME, (SIGNAL_FUNC) command_notice);
   command_bind("away", MODULE_NAME, (SIGNAL_FUNC) command_away);
   command_bind("key", MODULE_NAME, (SIGNAL_FUNC) command_key);
+  command_bind("listkeys", MODULE_NAME, (SIGNAL_FUNC) command_listkeys);
 
   silc_nicklist_init();
 }
@@ -1206,6 +1233,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);
 
   silc_nicklist_deinit();
 }