updates.
[silc.git] / apps / irssi / src / silc / core / client_ops.c
index 7f968a6fb75d61e5792ab94a77d0277f319e93c4..16415900889e9d758e0eb05ad89f1f77f0ee7bfd 100644 (file)
 #include "fe-common/core/keyboard.h"
 #include "fe-common/silc/module-formats.h"
 
+#include "core.h"
+
 static void 
 silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
                                const char *name, SilcSocketType conn_type, 
-                               unsigned char *pk, uint32 pk_len, 
+                               unsigned char *pk, SilcUInt32 pk_len, 
                                SilcSKEPKType pk_type,
                                SilcVerifyPublicKey completion, void *context);
 
@@ -156,11 +158,11 @@ void silc_notify(SilcClient client, SilcClientConnection conn,
   SILC_CHANNEL_REC *chanrec;
   SILC_NICK_REC *nickrec;
   SilcClientEntry client_entry, client_entry2;
-  SilcChannelEntry channel;
+  SilcChannelEntry channel, channel2;
   SilcServerEntry server_entry;
   SilcIdType idtype;
   void *entry;
-  uint32 mode;
+  SilcUInt32 mode;
   char userhost[512];
   char *name, *tmp;
   GSList *list1, *list_tmp;
@@ -351,7 +353,7 @@ void silc_notify(SilcClient client, SilcClientConnection conn,
 
     idtype = va_arg(va, int);
     entry = va_arg(va, void *);
-    mode = va_arg(va, uint32);
+    mode = va_arg(va, SilcUInt32);
     (void)va_arg(va, char *);
     (void)va_arg(va, char *);
     channel = va_arg(va, SilcChannelEntry);
@@ -381,6 +383,12 @@ void silc_notify(SilcClient client, SilcClientConnection conn,
                         MSGLEVEL_MODES, SILCTXT_CHANNEL_CMODE,
                         channel->channel_name, tmp ? tmp : "removed all",
                         server_entry->server_name);
+    } else {
+      channel2 = (SilcChannelEntry)entry;
+      printformat_module("fe-common/silc", server, channel->channel_name,
+                        MSGLEVEL_MODES, SILCTXT_CHANNEL_CMODE,
+                        channel->channel_name, tmp ? tmp : "removed all",
+                        channel2->channel_name);
     }
 
     silc_free(tmp);
@@ -393,16 +401,17 @@ void silc_notify(SilcClient client, SilcClientConnection conn,
 
     SILC_LOG_DEBUG(("Notify: CUMODE_CHANGE"));
 
-    client_entry = va_arg(va, SilcClientEntry);
-    mode = va_arg(va, uint32);
+    idtype = va_arg(va, int);
+    entry = va_arg(va, void *);
+    mode = va_arg(va, SilcUInt32);
     client_entry2 = va_arg(va, SilcClientEntry);
     channel = va_arg(va, SilcChannelEntry);
-    
+
     tmp = silc_client_chumode(mode);
     chanrec = silc_channel_find_entry(server, channel);
     if (chanrec != NULL) {
       SILC_NICK_REC *nick;
-      
+
       if (client_entry2 == server->conn->local_entry)
        chanrec->chanop = (mode & SILC_CHANNEL_UMODE_CHANOP) != 0;
       
@@ -413,19 +422,36 @@ void silc_notify(SilcClient client, SilcClientConnection conn,
        signal_emit("nick mode changed", 2, chanrec, nick);
       }
     }
-  
-    printformat_module("fe-common/silc", server, channel->channel_name,
-                      MSGLEVEL_MODES, SILCTXT_CHANNEL_CUMODE,
-                      channel->channel_name, client_entry2->nickname, 
-                      tmp ? tmp : "removed all",
-                      client_entry->nickname);
+
+    if (idtype == SILC_ID_CLIENT) {
+      client_entry = (SilcClientEntry)entry;
+      printformat_module("fe-common/silc", server, channel->channel_name,
+                        MSGLEVEL_MODES, SILCTXT_CHANNEL_CUMODE,
+                        channel->channel_name, client_entry2->nickname, 
+                        tmp ? tmp : "removed all",
+                        client_entry->nickname);
+    } else if (idtype == SILC_ID_SERVER) {
+      server_entry = (SilcServerEntry)entry;
+      printformat_module("fe-common/silc", server, channel->channel_name,
+                        MSGLEVEL_MODES, SILCTXT_CHANNEL_CUMODE,
+                        channel->channel_name, client_entry2->nickname, 
+                        tmp ? tmp : "removed all",
+                        server_entry->server_name);
+    } else {
+      channel2 = (SilcChannelEntry)entry;
+      printformat_module("fe-common/silc", server, channel->channel_name,
+                        MSGLEVEL_MODES, SILCTXT_CHANNEL_CUMODE,
+                        channel->channel_name, client_entry2->nickname, 
+                        tmp ? tmp : "removed all",
+                        channel2->channel_name);
+    }
 
     if (mode & SILC_CHANNEL_UMODE_CHANFO)
       printformat_module("fe-common/silc", 
                         server, channel->channel_name, MSGLEVEL_CRAP,
                         SILCTXT_CHANNEL_FOUNDER,
                         channel->channel_name, client_entry2->nickname);
-    
+
     silc_free(tmp);
     break;
 
@@ -459,7 +485,8 @@ void silc_notify(SilcClient client, SilcClientConnection conn,
     if (client_entry == conn->local_entry) {
       printformat_module("fe-common/silc", server, channel->channel_name,
                         MSGLEVEL_CRAP, SILCTXT_CHANNEL_KICKED_YOU, 
-                        channel->channel_name, client_entry2->nickname,
+                        channel->channel_name, 
+                        client_entry ? client_entry2->nickname : "",
                         tmp ? tmp : "");
       if (chanrec) {
        chanrec->kicked = TRUE;
@@ -469,7 +496,8 @@ void silc_notify(SilcClient client, SilcClientConnection conn,
       printformat_module("fe-common/silc", server, channel->channel_name,
                         MSGLEVEL_CRAP, SILCTXT_CHANNEL_KICKED, 
                         client_entry->nickname, channel->channel_name, 
-                        client_entry2->nickname, tmp ? tmp : "");
+                        client_entry2 ? client_entry2->nickname : "", 
+                        tmp ? tmp : "");
 
       if (chanrec) {
        SILC_NICK_REC *nickrec = silc_nicklist_find(chanrec, client_entry);
@@ -509,6 +537,9 @@ void silc_notify(SilcClient client, SilcClientConnection conn,
     }
     break;
 
+  case SILC_NOTIFY_TYPE_CHANNEL_CHANGE:
+    break;
+
   case SILC_NOTIFY_TYPE_SERVER_SIGNOFF:
     {
       /*
@@ -516,13 +547,13 @@ void silc_notify(SilcClient client, SilcClientConnection conn,
        */
       int i;
       SilcClientEntry *clients;
-      uint32 clients_count;
+      SilcUInt32 clients_count;
 
       SILC_LOG_DEBUG(("Notify: SIGNOFF"));
       
       (void)va_arg(va, void *);
       clients = va_arg(va, SilcClientEntry *);
-      clients_count = va_arg(va, uint32);
+      clients_count = va_arg(va, SilcUInt32);
   
       for (i = 0; i < clients_count; i++) {
        memset(userhost, 0, sizeof(userhost));
@@ -642,7 +673,7 @@ void silc_command(SilcClient client, SilcClientConnection conn,
 static void silc_client_join_get_users(SilcClient client,
                                       SilcClientConnection conn,
                                       SilcClientEntry *clients,
-                                      uint32 clients_count,
+                                      SilcUInt32 clients_count,
                                       void *context)
 {
   SilcChannelEntry channel = (SilcChannelEntry)context;
@@ -758,7 +789,7 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
     {
       char buf[1024], *nickname, *username, *realname, *nick;
       unsigned char *fingerprint;
-      uint32 idle, mode;
+      SilcUInt32 idle, mode;
       SilcBuffer channels;
       SilcClientEntry client_entry;
       
@@ -774,12 +805,13 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
       } else if (status == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID) {
        /* Try to find the entry for the unknown client ID, since we
           might have, and print the nickname of it for user. */
-       uint32 tmp_len;
+       SilcUInt32 tmp_len;
        unsigned char *tmp =
          silc_argument_get_arg_type(silc_command_get_args(cmd_payload),
                                     2, &tmp_len);
        if (tmp) {
-         SilcClientID *client_id = silc_id_payload_parse_id(tmp, tmp_len);
+         SilcClientID *client_id = silc_id_payload_parse_id(tmp, tmp_len, 
+                                                            NULL);
          if (client_id) {
            client_entry = silc_client_get_client_by_id(client, conn,
                                                        client_id);
@@ -800,8 +832,8 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
       username = va_arg(vp, char *);
       realname = va_arg(vp, char *);
       channels = va_arg(vp, SilcBuffer);
-      mode = va_arg(vp, uint32);
-      idle = va_arg(vp, uint32);
+      mode = va_arg(vp, SilcUInt32);
+      idle = va_arg(vp, SilcUInt32);
       fingerprint = va_arg(vp, unsigned char *);
       
       silc_parse_userfqdn(nickname, &nick, NULL);
@@ -822,7 +854,7 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
          silc_dlist_start(list);
          while ((entry = silc_dlist_get(list)) != SILC_LIST_END) {
            char *m = silc_client_chumode_char(silc_channel_get_mode(entry));
-           uint32 name_len;
+           SilcUInt32 name_len;
            char *name = silc_channel_get_name(entry, &name_len);
            
            if (m)
@@ -890,12 +922,13 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
       } else if (status == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID) {
        /* Try to find the entry for the unknown client ID, since we
           might have, and print the nickname of it for user. */
-       uint32 tmp_len;
+       SilcUInt32 tmp_len;
        unsigned char *tmp =
          silc_argument_get_arg_type(silc_command_get_args(cmd_payload),
                                     2, &tmp_len);
        if (tmp) {
-         SilcClientID *client_id = silc_id_payload_parse_id(tmp, tmp_len);
+         SilcClientID *client_id = silc_id_payload_parse_id(tmp, tmp_len,
+                                                            NULL);
          if (client_id) {
            client_entry = silc_client_get_client_by_id(client, conn,
                                                        client_id);
@@ -971,24 +1004,24 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
   case SILC_COMMAND_JOIN: 
     {
       char *channel, *mode, *topic;
-      uint32 modei;
+      SilcUInt32 modei;
       SilcChannelEntry channel_entry;
       SilcBuffer client_id_list;
-      uint32 list_count;
+      SilcUInt32 list_count;
 
       if (!success)
        return;
 
       channel = va_arg(vp, char *);
       channel_entry = va_arg(vp, SilcChannelEntry);
-      modei = va_arg(vp, uint32);
-      (void)va_arg(vp, uint32);
+      modei = va_arg(vp, SilcUInt32);
+      (void)va_arg(vp, SilcUInt32);
       (void)va_arg(vp, unsigned char *);
       (void)va_arg(vp, unsigned char *);
       (void)va_arg(vp, unsigned char *);
       topic = va_arg(vp, char *);
       (void)va_arg(vp, unsigned char *);
-      list_count = va_arg(vp, uint32);
+      list_count = va_arg(vp, SilcUInt32);
       client_id_list = va_arg(vp, SilcBuffer);
 
       chanrec = silc_channel_find(server, channel);
@@ -1067,12 +1100,12 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
     
   case SILC_COMMAND_UMODE:
     {
-      uint32 mode;
+      SilcUInt32 mode;
       
       if (!success)
        return;
       
-      mode = va_arg(vp, uint32);
+      mode = va_arg(vp, SilcUInt32);
       
       if (mode & SILC_UMODE_SERVER_OPERATOR &&
          !(server->umode & SILC_UMODE_SERVER_OPERATOR))
@@ -1085,6 +1118,7 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
                           MSGLEVEL_CRAP, SILCTXT_ROUTER_OPER);
 
       server->umode = mode;
+      signal_emit("user mode changed", 2, server, NULL);
     }
     break;
     
@@ -1092,6 +1126,9 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
     if (!success)
       return;
 
+    server->umode |= SILC_UMODE_SERVER_OPERATOR;
+    signal_emit("user mode changed", 2, server, NULL);
+
     printformat_module("fe-common/silc", server, NULL,
                       MSGLEVEL_CRAP, SILCTXT_SERVER_OPER);
     break;
@@ -1100,6 +1137,9 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
     if (!success)
       return;
 
+    server->umode |= SILC_UMODE_ROUTER_OPERATOR;
+    signal_emit("user mode changed", 2, server, NULL);
+
     printformat_module("fe-common/silc", server, NULL,
                       MSGLEVEL_CRAP, SILCTXT_ROUTER_OPER);
     break;
@@ -1177,14 +1217,14 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
       void *entry;
       SilcPublicKey public_key;
       unsigned char *pk;
-      uint32 pk_len;
+      SilcUInt32 pk_len;
       GetkeyContext getkey;
       char *name;
       
       if (!success)
        return;
       
-      id_type = va_arg(vp, uint32);
+      id_type = va_arg(vp, SilcUInt32);
       entry = va_arg(vp, void *);
       public_key = va_arg(vp, SilcPublicKey);
 
@@ -1278,7 +1318,7 @@ typedef struct {
   char *entity;
   char *entity_name;
   unsigned char *pk;
-  uint32 pk_len;
+  SilcUInt32 pk_len;
   SilcSKEPKType pk_type;
   SilcVerifyPublicKey completion;
   void *context;
@@ -1322,7 +1362,7 @@ static void verify_public_key_completion(const char *line, void *context)
 static void 
 silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
                                const char *name, SilcSocketType conn_type, 
-                               unsigned char *pk, uint32 pk_len, 
+                               unsigned char *pk, SilcUInt32 pk_len, 
                                SilcSKEPKType pk_type,
                                SilcVerifyPublicKey completion, void *context)
 {
@@ -1361,21 +1401,21 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
     if (!name) {
       snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity, 
               conn->sock->ip, conn->sock->port);
-      snprintf(filename, sizeof(filename) - 1, "%s/.silc/%skeys/%s", 
-              pw->pw_dir, entity, file);
+      snprintf(filename, sizeof(filename) - 1, "%s/%skeys/%s", 
+              get_irssi_dir(), entity, file);
       
       snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity, 
               conn->sock->hostname, conn->sock->port);
-      snprintf(filename2, sizeof(filename2) - 1, "%s/.silc/%skeys/%s", 
-              pw->pw_dir, entity, file);
+      snprintf(filename2, sizeof(filename2) - 1, "%s/%skeys/%s", 
+              get_irssi_dir(), entity, file);
       
       ipf = filename;
       hostf = filename2;
     } else {
       snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity, 
               name, conn->sock->port);
-      snprintf(filename, sizeof(filename) - 1, "%s/.silc/%skeys/%s", 
-              pw->pw_dir, entity, file);
+      snprintf(filename, sizeof(filename) - 1, "%s/%skeys/%s", 
+              get_irssi_dir(), entity, file);
       
       ipf = filename;
     }
@@ -1387,8 +1427,8 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
        fingerprint[i] = '_';
     
     snprintf(file, sizeof(file) - 1, "%skey_%s.pub", entity, fingerprint);
-    snprintf(filename, sizeof(filename) - 1, "%s/.silc/%skeys/%s", 
-            pw->pw_dir, entity, file);
+    snprintf(filename, sizeof(filename) - 1, "%s/%skeys/%s", 
+            get_irssi_dir(), entity, file);
     silc_free(fingerprint);
 
     ipf = filename;
@@ -1435,7 +1475,7 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
     /* The key already exists, verify it. */
     SilcPublicKey public_key;
     unsigned char *encpk;
-    uint32 encpk_len;
+    SilcUInt32 encpk_len;
 
     /* Load the key file, try for both IP filename and hostname filename */
     if (!silc_pkcs_load_public_key(ipf, &public_key, 
@@ -1526,7 +1566,7 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
 void 
 silc_verify_public_key(SilcClient client, SilcClientConnection conn,
                       SilcSocketType conn_type, unsigned char *pk, 
-                      uint32 pk_len, SilcSKEPKType pk_type,
+                      SilcUInt32 pk_len, SilcSKEPKType pk_type,
                       SilcVerifyPublicKey completion, void *context)
 {
   silc_verify_public_key_internal(client, conn, NULL, conn_type, pk,
@@ -1607,7 +1647,7 @@ static void silc_get_auth_method_callback(SilcClient client,
    is found and FALSE if not. `conn' may be NULL. */
 
 void silc_get_auth_method(SilcClient client, SilcClientConnection conn,
-                         char *hostname, uint16 port,
+                         char *hostname, SilcUInt16 port,
                          SilcGetAuthMeth completion, void *context)
 {
   InternalGetAuthMethod internal;
@@ -1674,7 +1714,7 @@ void silc_failure(SilcClient client, SilcClientConnection conn,
   }
 
   if (protocol->protocol->type == SILC_PROTOCOL_CLIENT_CONNECTION_AUTH) {
-    uint32 err = (uint32)failure;
+    SilcUInt32 err = (SilcUInt32)failure;
 
     if (err == SILC_AUTH_FAILED)
       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP, 
@@ -1691,7 +1731,7 @@ void silc_failure(SilcClient client, SilcClientConnection conn,
 
 int silc_key_agreement(SilcClient client, SilcClientConnection conn,
                       SilcClientEntry client_entry, const char *hostname,
-                      uint16 port, SilcKeyAgreementCallback *completion,
+                      SilcUInt16 port, SilcKeyAgreementCallback *completion,
                       void **context)
 {
   char portstr[12];
@@ -1719,8 +1759,8 @@ int silc_key_agreement(SilcClient client, SilcClientConnection conn,
 }
 
 void silc_ftp(SilcClient client, SilcClientConnection conn,
-             SilcClientEntry client_entry, uint32 session_id,
-             const char *hostname, uint16 port)
+             SilcClientEntry client_entry, SilcUInt32 session_id,
+             const char *hostname, SilcUInt16 port)
 {
   SILC_SERVER_REC *server;
   char portstr[12];