Fri Jan 02 10:28:15 CET 2004 Jochen Eisinger <jochen@penguin-breeder.org>
authorJochen Eisinger <coffee@silcnet.org>
Fri, 2 Jan 2004 09:31:58 +0000 (09:31 +0000)
committerJochen Eisinger <coffee@silcnet.org>
Fri, 2 Jan 2004 09:31:58 +0000 (09:31 +0000)
* Add /SILCNET [ADD|REMOVE|LIST] command to manage different SILC
  networks.  This is the first step in solving the bug about
  /SERVER ADD -silcnet <silcnet>.  Affected files
  irssi/docs/in/silcnet.in; irssi/src/fe-common/silc/Makefile.am,
  fe-silcnet.c, fe-common-silc.c;
  irssi/src/silc/core/silc-chatnets.[ch], silc-core.c, Makefile.am

CHANGES
apps/irssi/src/fe-common/silc/Makefile.am
apps/irssi/src/fe-common/silc/fe-common-silc.c
apps/irssi/src/fe-common/silc/fe-silcnet.c [new file with mode: 0644]
apps/irssi/src/fe-common/silc/module-formats.c
apps/irssi/src/fe-common/silc/module-formats.h
apps/irssi/src/silc/core/Makefile.am
apps/irssi/src/silc/core/silc-chatnets.c [new file with mode: 0644]
apps/irssi/src/silc/core/silc-chatnets.h [new file with mode: 0644]
apps/irssi/src/silc/core/silc-core.c

diff --git a/CHANGES b/CHANGES
index 6a7be0b5a1e294dda429bac05a04ca895a6790ea..0b1591efcffb042468fa917fe6d087a9c17287d1 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,12 @@
+Fri Jan 02 10:28:15 CET 2004  Jochen Eisinger <jochen@penguin-breeder.org>
+
+       * Add /SILCNET [ADD|REMOVE|LIST] command to manage different SILC
+         networks.  This is the first step in solving the bug about
+         /SERVER ADD -silcnet <silcnet>.  Affected files 
+         irssi/docs/in/silcnet.in; irssi/src/fe-common/silc/Makefile.am,
+         fe-silcnet.c, fe-common-silc.c;
+         irssi/src/silc/core/silc-chatnets.[ch], silc-core.c, Makefile.am
+
 Thu Jan 01 20:11:32 CET 2004  Jochen Eisinger <jochen@penguin-breeder.org>
 
        * /SMSG and /MMSG now correctly create new queries. Affected files
index 1a89f348df3e661239671ec37969380e6dc0e8cd..3306d04bc37e431bcd076410126cf8c781497879 100644 (file)
@@ -28,7 +28,8 @@ libfe_common_silc_a_SOURCES = \
        fe-common-silc.c \
        module-formats.c \
        silc-modules.c \
-       fe-messages.c
+       fe-messages.c \
+       fe-silcnet.c
 
 noinst_HEADERS = \
        module-formats.h \
index 51047a005396ddf52936115d787c034e88d34a7f..21f1a38880c6dee3dd67d99cd54704da50c9df43 100644 (file)
@@ -33,6 +33,9 @@ void fe_silc_modules_deinit(void);
 void fe_silc_messages_init(void);
 void fe_silc_messages_deinit(void);
 
+void fe_silcnet_init(void);
+void fe_silcnet_deinit(void);
+
 void fe_silc_init(void)
 {
   theme_register(fecommon_silc_formats);
@@ -40,6 +43,7 @@ void fe_silc_init(void)
   fe_silc_channels_init();
   fe_silc_modules_init();
   fe_silc_messages_init();
+  fe_silcnet_init();
 
   module_register("silc", "fe");
 }
@@ -49,6 +53,7 @@ void fe_silc_deinit(void)
   fe_silc_messages_deinit();
   fe_silc_modules_deinit();
   fe_silc_channels_deinit();
+  fe_silcnet_deinit();
 
   theme_unregister();
 }
diff --git a/apps/irssi/src/fe-common/silc/fe-silcnet.c b/apps/irssi/src/fe-common/silc/fe-silcnet.c
new file mode 100644 (file)
index 0000000..2ab14d3
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ fe-silcnet.c : irssi
+
+    Copyright (C) 2000 Timo Sirainen
+    Copyright (C) 2003 Jochen Eisinger
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include "module.h"
+#include "module-formats.h"
+#include "signals.h"
+#include "commands.h"
+#include "levels.h"
+#include "misc.h"
+#include "chatnets.h"
+
+#include "silc-servers.h"
+#include "silc-chatnets.h"
+#include "printtext.h"
+
+static void cmd_silcnet_list(void)
+{
+       GString *str;
+       GSList *tmp;
+
+       str = g_string_new(NULL);
+       printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, SILCTXT_SILCNET_HEADER);
+       for (tmp = chatnets; tmp != NULL; tmp = tmp->next) {
+               SILC_CHATNET_REC *rec = tmp->data;
+
+               if (!IS_SILCNET(rec))
+                        continue;
+
+               g_string_truncate(str, 0);
+               if (rec->nick != NULL)
+                       g_string_sprintfa(str, "nick: %s, ", rec->nick);
+               if (rec->username != NULL)
+                       g_string_sprintfa(str, "username: %s, ", rec->username);
+               if (rec->realname != NULL)
+                       g_string_sprintfa(str, "realname: %s, ", rec->realname);
+               if (rec->own_host != NULL)
+                       g_string_sprintfa(str, "host: %s, ", rec->own_host);
+
+               if (str->len > 1) g_string_truncate(str, str->len-2);
+               printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
+                           SILCTXT_SILCNET_LINE, rec->name, str->str);
+       }
+       g_string_free(str, TRUE);
+       printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, SILCTXT_SILCNET_FOOTER);
+}
+
+/* SYNTAX: SILCNET ADD [-nick <nick>] [-user <user>] [-realname <name>]
+                       [-host <host>] <name> */
+static void cmd_silcnet_add(const char *data)
+{
+       GHashTable *optlist;
+       char *name, *value;
+       void *free_arg;
+       SILC_CHATNET_REC *rec;
+
+       if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS,
+                           "silcnet add", &optlist, &name))
+               return;
+       if (*name == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
+
+       rec = silcnet_find(name);
+       if (rec == NULL) {
+               rec = g_new0(SILC_CHATNET_REC, 1);
+               rec->name = g_strdup(name);
+       } else {
+               if (g_hash_table_lookup(optlist, "nick")) g_free_and_null(rec->nick);
+               if (g_hash_table_lookup(optlist, "user")) g_free_and_null(rec->username);
+               if (g_hash_table_lookup(optlist, "realname")) g_free_and_null(rec->realname);
+               if (g_hash_table_lookup(optlist, "host")) {
+                       g_free_and_null(rec->own_host);
+                        rec->own_ip4 = rec->own_ip6 = NULL;
+               }
+       }
+
+
+       value = g_hash_table_lookup(optlist, "nick");
+       if (value != NULL && *value != '\0') rec->nick = g_strdup(value);
+       value = g_hash_table_lookup(optlist, "user");
+       if (value != NULL && *value != '\0') rec->username = g_strdup(value);
+       value = g_hash_table_lookup(optlist, "realname");
+       if (value != NULL && *value != '\0') rec->realname = g_strdup(value);
+
+       value = g_hash_table_lookup(optlist, "host");
+       if (value != NULL && *value != '\0') {
+               rec->own_host = g_strdup(value);
+               rec->own_ip4 = rec->own_ip6 = NULL;
+       }
+
+       silcnet_create(rec);
+       printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, SILCTXT_SILCNET_ADDED, name);
+
+       cmd_params_free(free_arg);
+}
+
+/* SYNTAX: SILCNET REMOVE <silcnet> */
+static void cmd_silcnet_remove(const char *data)
+{
+       SILC_CHATNET_REC *rec;
+
+       if (*data == '\0') cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
+
+       rec = silcnet_find(data);
+       if (rec == NULL)
+               printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, SILCTXT_SILCNET_NOT_FOUND, data);
+       else {
+               printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, SILCTXT_SILCNET_REMOVED, data);
+               chatnet_remove(CHATNET(rec));
+       }
+}
+
+static void cmd_silcnet(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
+{
+       if (*data == '\0')
+               cmd_silcnet_list();
+       else
+               command_runsub("silcnet", data, server, item);
+}
+
+void fe_silcnet_init(void)
+{
+       command_bind("silcnet", NULL, (SIGNAL_FUNC) cmd_silcnet);
+       command_bind("silcnet list", NULL, (SIGNAL_FUNC) cmd_silcnet_list);
+       command_bind("silcnet add", NULL, (SIGNAL_FUNC) cmd_silcnet_add);
+       command_bind("silcnet remove", NULL, (SIGNAL_FUNC) cmd_silcnet_remove);
+
+       command_set_options("silcnet add", "-nick -user -realname -host");
+}
+
+void fe_silcnet_deinit(void)
+{
+       command_unbind("silcnet", (SIGNAL_FUNC) cmd_silcnet);
+       command_unbind("silcnet list", (SIGNAL_FUNC) cmd_silcnet_list);
+       command_unbind("silcnet add", (SIGNAL_FUNC) cmd_silcnet_add);
+       command_unbind("silcnet remove", (SIGNAL_FUNC) cmd_silcnet_remove);
+}
index d63f971620f30e48d0829c5a872a39fe2dab4e32..d492d3f6136974f7477a84b69a2de8e80a404b5a 100644 (file)
@@ -231,5 +231,15 @@ FORMAT_REC fecommon_silc_formats[] = {
         { "lstkey_loadpub", "Could not load public key file `$0'", 1, { 0 } },
        { "lstkey_list", "Stored {hilight $0} public keys:", 1, { 0 } },
 
+       /* Network */
+       { NULL, "Network", 0},
+
+       { "silcnet_added", "SILCNet $0 saved", 1, { 0 } },
+       { "silcnet_removed", "SILCNet $0 removed", 1, { 0 } },
+       { "silcnet_not_found", "SILCNet $0 not found", 1, { 0 } },
+       { "silcnet_header", "%#SILCNets:", 0 },
+       { "silcnet_line", "%#$0: $1", 2, { 0, 0 } },
+       { "silcnet_footer", "", 0 },
+
        { NULL, NULL, 0 }
 };
index 4e7c1ae398946cb51024d22c3778ff68cbc61311..0d9277a00afbe8c8f1fe4a8ab99d9e9138a895c9 100644 (file)
@@ -208,6 +208,7 @@ enum {
   SILCTXT_ATTR_SAVED,
 
   SILCTXT_FILL_7,
+  
   SILCTXT_LISTKEY_PUB_FILE,
   SILCTXT_LISTKEY_PUB_ALG,
   SILCTXT_LISTKEY_PUB_BITS,
@@ -222,6 +223,15 @@ enum {
   SILCTXT_LISTKEY_LOADPUB,
   SILCTXT_LISTKEY_LIST,
 
+  SILCTXT_FILL_8,
+
+  SILCTXT_SILCNET_ADDED,
+  SILCTXT_SILCNET_REMOVED,
+  SILCTXT_SILCNET_NOT_FOUND,
+  SILCTXT_SILCNET_HEADER,
+  SILCTXT_SILCNET_LINE,
+  SILCTXT_SILCNET_FOOTER
+
 };
 
 extern FORMAT_REC fecommon_silc_formats[];
index 98f3398f0b3c3f717bfdc9b85ee67b8e290132dc..04e3a8edb90eb8404874058d9af308d7071d81cc 100644 (file)
@@ -23,7 +23,8 @@ libsilc_core_a_SOURCES = \
        silc-servers.c \
        silc-expandos.c \
        silc-servers-reconnect.c \
-       silc-lag.c
+       silc-lag.c \
+       silc-chatnets.c
 
 noinst_HEADERS = \
        module.h \
@@ -34,5 +35,6 @@ noinst_HEADERS = \
        silc-nicklist.h \
        silc-commands.h \
        silc-queries.h \
-       silc-servers.h 
+       silc-servers.h \
+       silc-chatnets.h
 
diff --git a/apps/irssi/src/silc/core/silc-chatnets.c b/apps/irssi/src/silc/core/silc-chatnets.c
new file mode 100644 (file)
index 0000000..8fbaf2d
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ silc-chatnets.c : irssi
+
+    Copyright (C) 1999-2000 Timo Sirainen
+    Copyright (C) 2003 Jochen Eisinger
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include "module.h"
+#include "signals.h"
+#include "lib-config/iconfig.h"
+#include "settings.h"
+
+#include "silc-chatnets.h"
+
+void silcnet_create(SILC_CHATNET_REC *rec)
+{
+       g_return_if_fail(rec != NULL);
+
+       rec->chat_type = SILC_PROTOCOL;
+        chatnet_create((CHATNET_REC *) rec);
+}
+
+static void sig_chatnet_read(SILC_CHATNET_REC *rec, CONFIG_NODE *node)
+{
+       if (!IS_SILC_CHATNET(rec))
+               return;
+       
+       /* read settings */
+}
+
+static void sig_chatnet_saved(SILC_CHATNET_REC *rec, CONFIG_NODE *node)
+{
+       if (!IS_SILC_CHATNET(rec))
+               return;
+
+       /* save settings */
+}
+
+static void sig_chatnet_destroyed(SILC_CHATNET_REC *rec)
+{
+       if (!IS_SILC_CHATNET(rec))
+               return;
+
+       /* free eventually allocated memory */
+}
+
+
+void silc_chatnets_init(void)
+{
+       signal_add("chatnet read", (SIGNAL_FUNC) sig_chatnet_read);
+       signal_add("chatnet saved", (SIGNAL_FUNC) sig_chatnet_saved);
+       signal_add("chatnet destroyed", (SIGNAL_FUNC) sig_chatnet_destroyed);
+}
+
+void silc_chatnets_deinit(void)
+{
+       GSList *tmp, *next;
+
+       for (tmp = chatnets; tmp != NULL; tmp = next) {
+               CHATNET_REC *rec = tmp->data;
+
+               next = tmp->next;
+               if (IS_SILC_CHATNET(rec))
+                        chatnet_destroy(rec);
+       }
+
+       signal_remove("chatnet read", (SIGNAL_FUNC) sig_chatnet_read);
+       signal_remove("chatnet saved", (SIGNAL_FUNC) sig_chatnet_saved);
+       signal_remove("chatnet destroyed", (SIGNAL_FUNC) sig_chatnet_destroyed);
+}
diff --git a/apps/irssi/src/silc/core/silc-chatnets.h b/apps/irssi/src/silc/core/silc-chatnets.h
new file mode 100644 (file)
index 0000000..e9a1f67
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef __SILC_CHATNETS_H
+#define __SILC_CHATNETS_H
+
+#include "chat-protocols.h"
+#include "chatnets.h"
+
+/* returns SILC_CHATNET_REC if it's SILC network, NULL if it isn't */
+#define SILC_CHATNET(chatnet) \
+       PROTO_CHECK_CAST(CHATNET(chatnet), SILC_CHATNET_REC, chat_type, "SILC")
+
+#define IS_SILC_CHATNET(chatnet) \
+       (SILC_CHATNET(chatnet) ? TRUE : FALSE)
+
+#define IS_SILCNET(silcnet) IS_SILC_CHATNET(silcnet)
+#define SILCNET(silcnet) SILC_CHATNET(silcnet)
+
+struct _SILC_CHATNET_REC {
+#include "chatnet-rec.h"
+};
+
+typedef struct _SILC_CHATNET_REC SILC_CHATNET_REC;
+
+void silcnet_create(SILC_CHATNET_REC *rec);
+
+#define silc_chatnet_find(name) \
+       SILC_CHATNET(chatnet_find(name))
+#define silcnet_find(name) silc_chatnet_find(name)
+
+void silc_chatnets_init(void);
+void silc_chatnets_deinit(void);
+
+#endif
index 7de591f318daec933edc126bb1eb7038480e98f7..6d826f944b792853d18e2260e797585daac95541 100644 (file)
@@ -29,6 +29,7 @@
 #include "silc-channels.h"
 #include "silc-queries.h"
 #include "silc-nicklist.h"
+#include "silc-chatnets.h"
 
 #include "signals.h"
 #include "levels.h"
@@ -480,6 +481,7 @@ void silc_core_init(void)
   silc_queries_init();
   silc_expandos_init();
   silc_lag_init();
+  silc_chatnets_init();
 
   module_register("silc", "core");
 }
@@ -501,6 +503,7 @@ void silc_core_deinit(void)
   silc_queries_deinit();
   silc_expandos_deinit();
   silc_lag_deinit();
+  silc_chatnets_deinit();
   
   chat_protocol_unregister("SILC");