Merge commit 'origin/silc.1.1.branch'
[silc.git] / apps / irssi / src / silc / core / silc-channels.c
index 5cc7807c42696df88002e5ba76a75af8ba47e9f0..4bd4e49ef556fb0d8a464fb930f8f014028eafa7 100644 (file)
@@ -111,7 +111,10 @@ static void silc_channels_join(SILC_SERVER_REC *server,
                               const char *channels, int automatic)
 {
   char **list, **tmp;
+  char *channel, *key;
   SILC_CHANNEL_REC *chanrec;
+  CHANNEL_SETUP_REC *schannel;
+  GString *tmpstr;
 
   list = g_strsplit(channels, ",", -1);
   for (tmp = list; *tmp != NULL; tmp++) {
@@ -119,7 +122,25 @@ static void silc_channels_join(SILC_SERVER_REC *server,
     if (chanrec)
       continue;
 
-    silc_command_exec(server, "JOIN", *tmp);
+    channel = *tmp;
+    key = strchr(channel, ' ');
+    if (key != NULL) {
+      *key = '\0';
+      key++;
+    }
+    tmpstr = g_string_new(NULL);
+
+    schannel = channel_setup_find(channel, server->connrec->chatnet);
+    if (key && *key != '\0')
+      g_string_sprintfa(tmpstr, "%s %s", channel, key);
+    else if (schannel && schannel->password && schannel->password[0] != '\0')
+      g_string_sprintfa(tmpstr, "%s %s", channel, schannel->password);
+    else
+      g_string_sprintfa(tmpstr, "%s", channel);
+
+
+    silc_command_exec(server, "JOIN", tmpstr->str);
+    g_string_free(tmpstr, FALSE);
   }
 
   g_strfreev(list);
@@ -574,7 +595,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
   SilcDList clients;
   SILC_CHANNEL_REC *chanrec = NULL;
   SilcChannelEntry channel_entry = NULL;
-  char nickname[128 + 1], *tmp;
+  char *nickname = NULL, *tmp;
   int command = 0, port = 0, type = 0;
   char *hostname = NULL;
   KeyInternal internal = NULL;
@@ -613,25 +634,23 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
 
   if (type == 1) {
     if (argv[2][0] == '*') {
-      strcpy(nickname, "*");
+      nickname = strdup("*");
     } else {
       /* Parse the typed nickname. */
-      if (!silc_parse_userfqdn(argv[2], nickname, sizeof(nickname), NULL, 0)) {
-       printformat_module("fe-common/silc", server, NULL,
-                          MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
-       return;
-      }
+      silc_client_nickname_parse(silc_client, conn, argv[2], &nickname);
+      if (!nickname)
+       nickname = strdup(argv[2]);
 
       /* Find client entry */
-      clients = silc_client_get_clients_local(silc_client, conn, nickname,
-                                             argv[2]);
+      clients = silc_client_get_clients_local(silc_client, conn, argv[2],
+                                             FALSE);
       if (!clients) {
        KeyGetClients inter = silc_calloc(1, sizeof(*inter));
        inter->server = server;
        inter->data = strdup(data);
        inter->nick = strdup(nickname);
        inter->item = item;
-       silc_client_get_clients(silc_client, conn, nickname, argv[2],
+       silc_client_get_clients(silc_client, conn, nickname, NULL,
                                silc_client_command_key_get_clients, inter);
        goto out;
       }
@@ -646,20 +665,16 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
     char *name;
 
     if (argv[2][0] == '*') {
-      if (!conn->current_channel) {
-       silc_free(nickname);
+      if (!conn->current_channel)
        cmd_return_error(CMDERR_NOT_JOINED);
-      }
       name = conn->current_channel->channel_name;
     } else {
       name = argv[2];
     }
 
     chanrec = silc_channel_find(server, name);
-    if (chanrec == NULL) {
-      silc_free(nickname);
+    if (chanrec == NULL)
       cmd_return_error(CMDERR_CHAN_NOT_FOUND);
-    }
     channel_entry = chanrec->entry;
   }
 
@@ -732,6 +747,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
        if (!ckeys)
          goto out;
 
+       silc_dlist_start(ckeys);
        if (!number || number > silc_dlist_count(ckeys)) {
          silc_dlist_uninit(ckeys);
          goto out;
@@ -843,12 +859,13 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
       if (!ckeys)
        goto out;
 
+      silc_dlist_start(ckeys);
       while ((ch = silc_dlist_get(ckeys))) {
        memset(buf, 0, sizeof(buf));
        strncat(buf, "  ", 2);
 
-       len = strlen(silc_cipher_get_name(ch->cipher));
-       strncat(buf, silc_cipher_get_name(ch->cipher),
+       len = strlen(silc_cipher_get_name(ch->send_key));
+       strncat(buf, silc_cipher_get_name(ch->send_key),
                len > 16 ? 16 : len);
        if (len < 16)
          for (i = 0; i < 16 - len; i++)
@@ -946,6 +963,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
       if (!ckeys)
        goto out;
 
+      silc_dlist_start(ckeys);
       if (argc == 4) {
        chanrec->cur_key++;
        if (chanrec->cur_key >= silc_dlist_count(ckeys))
@@ -1041,6 +1059,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
   }
 
  out:
+  silc_free(nickname);
   return;
 }
 
@@ -1055,7 +1074,8 @@ void silc_list_key(const char *pub_filename, int verbose)
   SilcUInt32 key_len = 0;
   int is_server_key = (strstr(pub_filename, "serverkeys") != NULL);
 
-  if (!silc_pkcs_load_public_key((char *)pub_filename, &public_key)) {
+  if (!silc_pkcs_load_public_key((char *)pub_filename, SILC_PKCS_ANY,
+                                &public_key)) {
     printformat_module("fe-common/silc", NULL, NULL,
                       MSGLEVEL_CRAP, SILCTXT_LISTKEY_LOADPUB,
                       pub_filename);
@@ -1070,10 +1090,12 @@ void silc_list_key(const char *pub_filename, int verbose)
     return;
   }
 
-  silc_pubkey = silc_pkcs_get_context(SILC_PKCS_SILC, public_key);
+  silc_pubkey = silc_pkcs_public_key_get_pkcs(SILC_PKCS_SILC, public_key);
   ident = &silc_pubkey->identifier;
 
-  pk = silc_pkcs_public_key_encode(public_key, &pk_len);
+  pk = silc_pkcs_public_key_encode(NULL, public_key, &pk_len);
+  if (!pk)
+    return;
   fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
   babbleprint = silc_hash_babbleprint(NULL, pk, pk_len);
   key_len = silc_pkcs_public_key_get_len(public_key);