Protocol version 1.2 integrations
[silc.git] / apps / irssi / src / silc / core / silc-channels.c
index 38cd2bcc448069101d0dd6dcde65406ffe982053..a720ecdb88e427bc4151fe484fdd36ab6735abae 100644 (file)
@@ -46,7 +46,9 @@
 #include "silc-commands.h"
 
 SILC_CHANNEL_REC *silc_channel_create(SILC_SERVER_REC *server,
-                                     const char *name, int automatic)
+                                     const char *name,
+                                     const char *visible_name,
+                                     int automatic)
 {
   SILC_CHANNEL_REC *rec;
 
@@ -55,10 +57,8 @@ SILC_CHANNEL_REC *silc_channel_create(SILC_SERVER_REC *server,
 
   rec = g_new0(SILC_CHANNEL_REC, 1);
   rec->chat_type = SILC_PROTOCOL;
-  rec->name = g_strdup(name);
-  rec->server = server;
-
-  channel_init((CHANNEL_REC *) rec, automatic);
+  channel_init((CHANNEL_REC *)rec, (SERVER_REC *)server, name, name,
+              automatic);
   return rec;
 }
 
@@ -144,7 +144,7 @@ static void command_part(const char *data, SILC_SERVER_REC *server,
   if (!strcmp(data, "*") || *data == '\0') {
     if (!IS_SILC_CHANNEL(item))
       cmd_return_error(CMDERR_NOT_JOINED);
-    data = item->name;
+    data = item->visible_name;
   }
 
   chanrec = silc_channel_find(server, data);
@@ -161,7 +161,7 @@ static void command_part(const char *data, SILC_SERVER_REC *server,
   chanrec->left = TRUE;
   silc_command_exec(server, "LEAVE", chanrec->name);
   signal_stop();
-  
+
   channel_destroy(CHANNEL(chanrec));
 }
 
@@ -195,15 +195,17 @@ static void command_me(const char *data, SILC_SERVER_REC *server,
   if (argc < 2)
     cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
 
-  chanrec = silc_channel_find(server, item->name);
+  chanrec = silc_channel_find(server, item->visible_name);
   if (chanrec == NULL) 
     cmd_return_error(CMDERR_CHAN_NOT_FOUND);
 
   if (!silc_term_utf8()) {
-    int len = silc_utf8_encoded_len(argv[1], argv_lens[1], SILC_STRING_ASCII);
+    int len = silc_utf8_encoded_len(argv[1], argv_lens[1],
+                                   SILC_STRING_LANGUAGE);
     message = silc_calloc(len + 1, sizeof(*message));
     g_return_if_fail(message != NULL);
-    silc_utf8_encode(argv[1], argv_lens[1], SILC_STRING_ASCII, message, len);
+    silc_utf8_encode(argv[1], argv_lens[1], SILC_STRING_LANGUAGE,
+                    message, len);
   }
 
   /* Send the action message */
@@ -261,10 +263,12 @@ static void command_action(const char *data, SILC_SERVER_REC *server,
     cmd_return_error(CMDERR_CHAN_NOT_FOUND);
 
   if (!silc_term_utf8()) {
-    int len = silc_utf8_encoded_len(argv[2], argv_lens[2], SILC_STRING_ASCII);
+    int len = silc_utf8_encoded_len(argv[2], argv_lens[2],
+                                   SILC_STRING_LANGUAGE);
     message = silc_calloc(len + 1, sizeof(*message));
     g_return_if_fail(message != NULL);
-    silc_utf8_encode(argv[2], argv_lens[2], SILC_STRING_ASCII, message, len);
+    silc_utf8_encode(argv[2], argv_lens[2], SILC_STRING_LANGUAGE,
+                    message, len);
   }
 
   /* Send the action message */
@@ -316,15 +320,17 @@ static void command_notice(const char *data, SILC_SERVER_REC *server,
   if (argc < 2)
     cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
 
-  chanrec = silc_channel_find(server, item->name);
+  chanrec = silc_channel_find(server, item->visible_name);
   if (chanrec == NULL) 
     cmd_return_error(CMDERR_CHAN_NOT_FOUND);
 
   if (!silc_term_utf8()) {
-    int len = silc_utf8_encoded_len(argv[1], argv_lens[1], SILC_STRING_ASCII);
+    int len = silc_utf8_encoded_len(argv[1], argv_lens[1],
+                                   SILC_STRING_LANGUAGE);
     message = silc_calloc(len + 1, sizeof(*message));
     g_return_if_fail(message != NULL);
-    silc_utf8_encode(argv[1], argv_lens[1], SILC_STRING_ASCII, message, len);
+    silc_utf8_encode(argv[1], argv_lens[1], SILC_STRING_LANGUAGE,
+                    message, len);
   }
 
   /* Send the action message */
@@ -377,8 +383,10 @@ static void command_away(const char *data, SILC_SERVER_REC *server,
   }
 
   server->usermode_away = set;
+  g_free_and_null(server->away_reason);
   if (set)
     server->away_reason = g_strdup((char *)data);
+
   signal_emit("away mode changed", 1, server);
 
   silc_command_exec(server, "UMODE", set ? "+g" : "-g");
@@ -416,7 +424,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);
@@ -604,32 +612,46 @@ 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. */
+       /* XXX for now we don't do this.  This feature is pretty stupid
+          and should perhaps be removed altogether from SILC.
        silc_client_send_private_message_key(silc_client, conn, 
                                             client_entry, TRUE);
+       */
       } 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, 
@@ -800,8 +822,9 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
        memset(buf, 0, sizeof(buf));
        strncat(buf, "  ", 2);
 
-       len = strlen(keys[k]->cipher->cipher->name);
-       strncat(buf, keys[k]->cipher->cipher->name, len > 16 ? 16 : len);
+       len = strlen(silc_cipher_get_name(keys[k]->cipher));
+       strncat(buf, silc_cipher_get_name(keys[k]->cipher),
+               len > 16 ? 16 : len);
        if (len < 16)
          for (i = 0; i < 16 - len; i++)
            strcat(buf, " ");