Add support for autosendcmd on channel entries to the
[silc.git] / apps / irssi / src / silc / core / silc-channels.c
index bf233bfdae05f1885cb4733ff2c9a2a8fe683254..055c6d7247a4df4d17af5379c96848a295408356 100644 (file)
@@ -31,6 +31,7 @@
 #include "rawlog.h"
 #include "misc.h"
 #include "settings.h"
+#include "special-vars.h"
 
 #include "channels-setup.h"
 
@@ -161,6 +162,25 @@ static void sig_server_quit(SILC_SERVER_REC *server, const char *msg)
     silc_command_exec(server, "QUIT", msg);
 }
 
+static void sig_silc_channel_joined(SILC_CHANNEL_REC *channel)
+{
+  CHANNEL_SETUP_REC *rec;
+
+  if (!IS_SILC_CHANNEL(channel))
+    return;
+  if (channel->server && channel->server->disconnected)
+    return;
+  if (channel->session_rejoin)
+    return;
+  
+  rec = channel_setup_find(channel->name, channel->server->connrec->chatnet); 
+
+  if (rec == NULL || rec->autosendcmd == NULL || !*rec->autosendcmd)
+    return;
+
+  eval_special_string(rec->autosendcmd, "", (SERVER_REC*)channel->server, (CHANNEL_REC*)channel);
+}
+
 /* Find Irssi channel entry by SILC channel entry */
 
 SILC_CHANNEL_REC *silc_channel_find_entry(SILC_SERVER_REC *server,
@@ -698,7 +718,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
                                            argv[4], argv_lens[4]);
       } else if (type == 2) {
        /* Set private channel key */
-       if (!(channel_entry->mode & SILC_CHANNEL_MODE_PRIVKEY)) {
+       if (!(channel_entry) || !(channel_entry->mode & SILC_CHANNEL_MODE_PRIVKEY)) {
          printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
                             SILCTXT_CH_PRIVATE_KEY_NOMODE,
                             channel_entry->channel_name);
@@ -747,6 +767,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;
@@ -858,12 +879,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++)
@@ -961,6 +983,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))
@@ -1090,6 +1113,8 @@ void silc_list_key(const char *pub_filename, int verbose)
   ident = &silc_pubkey->identifier;
 
   pk = silc_pkcs_public_key_encode(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);
@@ -1256,6 +1281,7 @@ void silc_channels_init(void)
   signal_add("server connected", (SIGNAL_FUNC) sig_connected);
   signal_add("server quit", (SIGNAL_FUNC) sig_server_quit);
   signal_add("mime", (SIGNAL_FUNC) sig_mime);
+  signal_add("channel joined", (SIGNAL_FUNC) sig_silc_channel_joined);
 
   command_bind_silc("part", MODULE_NAME, (SIGNAL_FUNC) command_part);
   command_bind_silc("me", MODULE_NAME, (SIGNAL_FUNC) command_me);
@@ -1278,6 +1304,7 @@ void silc_channels_deinit(void)
   signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
   signal_remove("server quit", (SIGNAL_FUNC) sig_server_quit);
   signal_remove("mime", (SIGNAL_FUNC) sig_mime);
+  signal_remove("channel joined", (SIGNAL_FUNC) sig_silc_channel_joined);
 
   command_unbind("part", (SIGNAL_FUNC) command_part);
   command_unbind("me", (SIGNAL_FUNC) command_me);