updated
authorcras <cras>
Thu, 21 Mar 2002 17:23:14 +0000 (17:23 +0000)
committercras <cras>
Thu, 21 Mar 2002 17:23:14 +0000 (17:23 +0000)
CHANGES
apps/irssi/src/silc/core/client_ops.c
apps/irssi/src/silc/core/clientutil.c
apps/irssi/src/silc/core/silc-channels.c
apps/irssi/src/silc/core/silc-commands.h [new file with mode: 0644]
apps/irssi/src/silc/core/silc-servers.c

diff --git a/CHANGES b/CHANGES
index a5b0b35b318b75a8b08360ccb4b6e3fc3f6a6016..babafe1668a69d3059ea0ae885a8f30f0c226894 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,16 @@
+Thu Mar 21 19:12:22 EET 2002  Timo Sirainen <tss@iki.fi>
+
+       * Changed hardcoded ~/.silc paths to use get_irssi_dir() so you
+          can specify different directory with --home command line
+         parameter. Affected files irssi/src/silc/core/client_ops.c,
+          clientutil.c
+
+        * SILC-specific commands aren't now executed if the active server
+          isn't of SILC-type, so there won't be problems with having
+          IRC and SILC protocol support in same client. Affected files
+          irssi/src/silc/core/silc-channels.c, silc-servers.c,
+         silc-commands.h
+
 Wed Mar 20 11:06:57 CET 2002  Pekka Riikonen <priikone@silcnet.org>
 
        * Improved the signal support in SILC Schedule.  Added new
index c7d769bc0c2a060550251d352daa5fe2ab092e8b..065c980e3264a094aca347d7aadfaffab196bb71 100644 (file)
@@ -38,6 +38,8 @@
 #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, 
@@ -1373,21 +1375,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;
     }
@@ -1399,8 +1401,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;
index 3e3c13c7370c46619d7ed0191de03200493e02c5..cf0604d818cf188e992a348808c48936a002c0da 100644 (file)
@@ -42,6 +42,8 @@
 #include "fe-common/core/printtext.h"
 #include "fe-common/core/keyboard.h"
 
+#include "core.h"
+
 /* Lists supported ciphers */
 
 void silc_client_list_ciphers()
@@ -314,11 +316,11 @@ int silc_client_check_silc_dir()
   }
 
   /* We'll take home path from /etc/passwd file to be sure. */
-  snprintf(filename, sizeof(filename) - 1, "%s/.silc/", pw->pw_dir);
-  snprintf(servfilename, sizeof(servfilename) - 1, "%s/.silc/serverkeys", 
-          pw->pw_dir);
-  snprintf(clientfilename, sizeof(clientfilename) - 1, "%s/.silc/clientkeys", 
-          pw->pw_dir);
+  snprintf(filename, sizeof(filename) - 1, "%s/", get_irssi_dir());
+  snprintf(servfilename, sizeof(servfilename) - 1, "%s/serverkeys", 
+          get_irssi_dir());
+  snprintf(clientfilename, sizeof(clientfilename) - 1, "%s/clientkeys", 
+          get_irssi_dir());
 
   /*
    * Check ~/.silc directory
@@ -519,8 +521,8 @@ int silc_client_load_keys(SilcClient client)
     return FALSE;
 
   memset(filename, 0, sizeof(filename));
-  snprintf(filename, sizeof(filename) - 1, "%s/.silc/%s", 
-          pw->pw_dir, SILC_CLIENT_PRIVATE_KEY_NAME);
+  snprintf(filename, sizeof(filename) - 1, "%s/%s", 
+          get_irssi_dir(), SILC_CLIENT_PRIVATE_KEY_NAME);
 
   if (silc_pkcs_load_private_key(filename, &client->private_key,
                                 SILC_PKCS_FILE_BIN) == FALSE)
@@ -529,8 +531,8 @@ int silc_client_load_keys(SilcClient client)
       return FALSE;
 
   memset(filename, 0, sizeof(filename));
-  snprintf(filename, sizeof(filename) - 1, "%s/.silc/%s", 
-          pw->pw_dir, SILC_CLIENT_PUBLIC_KEY_NAME);
+  snprintf(filename, sizeof(filename) - 1, "%s/%s", 
+          get_irssi_dir(), SILC_CLIENT_PUBLIC_KEY_NAME);
 
   if (silc_pkcs_load_public_key(filename, &client->public_key,
                                SILC_PKCS_FILE_PEM) == FALSE)
index a0c98fffe1c92f4c2f46345ef147b9168b53dae9..02c3b8ec3d16fdd8831f7b6f518ef33748edae8d 100644 (file)
@@ -43,6 +43,8 @@
 #include "fe-common/core/printtext.h"
 #include "fe-common/silc/module-formats.h"
 
+#include "silc-commands.h"
+
 SILC_CHANNEL_REC *silc_channel_create(SILC_SERVER_REC *server,
                                      const char *name, int automatic)
 {
@@ -132,6 +134,8 @@ static void command_part(const char *data, SILC_SERVER_REC *server,
   SILC_CHANNEL_REC *chanrec;
   char userhost[256];
   
+  CMD_SILC_SERVER(server);
+
   if (!IS_SILC_SERVER(server) || !server->connected)
     cmd_return_error(CMDERR_NOT_CONNECTED);
 
@@ -170,6 +174,8 @@ static void command_me(const char *data, SILC_SERVER_REC *server,
   SilcUInt32 *argv_lens, *argv_types;
   int i;
  
+  CMD_SILC_SERVER(server);
+
   if (!IS_SILC_SERVER(server) || !server->connected)
     cmd_return_error(CMDERR_NOT_CONNECTED);
 
@@ -218,6 +224,7 @@ static void command_action(const char *data, SILC_SERVER_REC *server,
   SilcUInt32 *argv_lens, *argv_types;
   int i;
  
+  CMD_SILC_SERVER(server);
   if (!IS_SILC_SERVER(server) || !server->connected)
     cmd_return_error(CMDERR_NOT_CONNECTED);
 
@@ -265,6 +272,7 @@ static void command_notice(const char *data, SILC_SERVER_REC *server,
   SilcUInt32 *argv_lens, *argv_types;
   int i;
  
+  CMD_SILC_SERVER(server);
   if (!IS_SILC_SERVER(server) || !server->connected)
     cmd_return_error(CMDERR_NOT_CONNECTED);
 
@@ -308,6 +316,8 @@ static void command_away(const char *data, SILC_SERVER_REC *server,
 {
   bool set;
 
+  CMD_SILC_SERVER(server);
+
   if (!IS_SILC_SERVER(server) || !server->connected)
     cmd_return_error(CMDERR_NOT_CONNECTED);
 
@@ -461,6 +471,8 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
   SilcUInt32 *argv_lens, *argv_types;
   char *bindhost = NULL;
  
+  CMD_SILC_SERVER(server);
+
   if (!server || !IS_SILC_SERVER(server) || !server->connected)
     cmd_return_error(CMDERR_NOT_CONNECTED);
 
@@ -901,13 +913,13 @@ void silc_channels_init(void)
   signal_add("server connected", (SIGNAL_FUNC) sig_connected);
   signal_add("server quit", (SIGNAL_FUNC) sig_server_quit);
 
-  command_bind("part", MODULE_NAME, (SIGNAL_FUNC) command_part);
-  command_bind("me", MODULE_NAME, (SIGNAL_FUNC) command_me);
-  command_bind("action", MODULE_NAME, (SIGNAL_FUNC) command_action);
-  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);
+  command_bind_silc("part", MODULE_NAME, (SIGNAL_FUNC) command_part);
+  command_bind_silc("me", MODULE_NAME, (SIGNAL_FUNC) command_me);
+  command_bind_silc("action", MODULE_NAME, (SIGNAL_FUNC) command_action);
+  command_bind_silc("notice", MODULE_NAME, (SIGNAL_FUNC) command_notice);
+  command_bind_silc("away", MODULE_NAME, (SIGNAL_FUNC) command_away);
+  command_bind_silc("key", MODULE_NAME, (SIGNAL_FUNC) command_key);
+  command_bind_silc("listkeys", MODULE_NAME, (SIGNAL_FUNC) command_listkeys);
 
   silc_nicklist_init();
 }
diff --git a/apps/irssi/src/silc/core/silc-commands.h b/apps/irssi/src/silc/core/silc-commands.h
new file mode 100644 (file)
index 0000000..d2ba836
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef SILC_COMMANDS_H
+#define SILC_COMMANDS_H
+
+#define command_bind_silc(cmd, section, signal) \
+        command_bind_proto(cmd, SILC_PROTOCOL, section, signal)
+#define command_bind_silc_first(cmd, section, signal) \
+        command_bind_proto_first(cmd, SILC_PROTOCOL, section, signal)
+#define command_bind_silc_last(cmd, section, signal) \
+        command_bind_proto_last(cmd, SILC_PROTOCOL, section, signal)
+
+/* Simply returns if server isn't for SILC protocol. Prints ERR_NOT_CONNECTED
+   error if there's no server or server isn't connected yet */
+#define CMD_SILC_SERVER(server) \
+       G_STMT_START { \
+          if (server != NULL && !IS_SILC_SERVER(server)) \
+            return; \
+          if (server == NULL || !(server)->connected) \
+            cmd_return_error(CMDERR_NOT_CONNECTED); \
+       } G_STMT_END
+
+#endif
index dcd9bb34ff94856cd113f9cecf96ee1f1ef890ca..7c3a69184d55f2e87f06a363bb0b7a7277491eca 100644 (file)
@@ -43,6 +43,8 @@
 #include "fe-common/core/printtext.h"
 #include "fe-common/silc/module-formats.h"
 
+#include "silc-commands.h"
+
 void silc_servers_reconnect_init(void);
 void silc_servers_reconnect_deinit(void);
 
@@ -369,6 +371,8 @@ void silc_command_exec(SILC_SERVER_REC *server,
 static void command_self(const char *data, SILC_SERVER_REC *server,
                         WI_ITEM_REC *item)
 {
+  CMD_SILC_SERVER(server);
+
   if (!IS_SILC_SERVER(server) || !server->connected) {
     printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Not connected to server");
     return;
@@ -390,6 +394,7 @@ static void command_self(const char *data, SILC_SERVER_REC *server,
 
 static void command_sconnect(const char *data, SILC_SERVER_REC *server)
 {
+  CMD_SILC_SERVER(server);
   if (!IS_SILC_SERVER(server) || !server->connected) {
     printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Not connected to server");
     return;
@@ -571,6 +576,7 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
   SilcUInt32 local_port = 0;
   SilcUInt32 session_id;
 
+  CMD_SILC_SERVER(server);
   if (!server || !IS_SILC_SERVER(server) || !server->connected)
     cmd_return_error(CMDERR_NOT_CONNECTED);
 
@@ -845,29 +851,29 @@ void silc_server_init(void)
 
   signal_add_first("server connected", (SIGNAL_FUNC) sig_connected);
   signal_add("server disconnected", (SIGNAL_FUNC) sig_disconnected);
-  command_bind("whois", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("whowas", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("nick", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("topic", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("cmode", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("cumode", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("users", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("list", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("ban", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("oper", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("silcoper", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("umode", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("invite", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("kill", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("kick", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("info", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("ping", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("motd", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("close", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("shutdown", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("getkey", MODULE_NAME, (SIGNAL_FUNC) command_self);
-  command_bind("sconnect", MODULE_NAME, (SIGNAL_FUNC) command_sconnect);
-  command_bind("file", MODULE_NAME, (SIGNAL_FUNC) command_file);
+  command_bind_silc("whois", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("whowas", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("nick", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("topic", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("cmode", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("cumode", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("users", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("list", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("ban", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("oper", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("silcoper", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("umode", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("invite", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("kill", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("kick", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("info", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("ping", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("motd", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("close", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("shutdown", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("getkey", MODULE_NAME, (SIGNAL_FUNC) command_self);
+  command_bind_silc("sconnect", MODULE_NAME, (SIGNAL_FUNC) command_sconnect);
+  command_bind_silc("file", MODULE_NAME, (SIGNAL_FUNC) command_file);
 
   command_set_options("connect", "+silcnet");
 }