From bbbb36cf1974ec63375915c081998cdd2ad881b0 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 19 Nov 2001 01:48:58 +0000 Subject: /UPGRADE - upgrade-on-the-fly feature. Currently only moves the active server connections to the new irssi process, but that should be enough to never quit from IRC again :) git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2070 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/irc/core/Makefile.am | 1 + src/irc/core/irc-core.c | 5 +++ src/irc/core/irc-servers.c | 4 +- src/irc/core/irc-session.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 src/irc/core/irc-session.c (limited to 'src/irc/core') diff --git a/src/irc/core/Makefile.am b/src/irc/core/Makefile.am index 9a12b7f4..fb84a0b5 100644 --- a/src/irc/core/Makefile.am +++ b/src/irc/core/Makefile.am @@ -25,6 +25,7 @@ libirc_core_a_SOURCES = \ irc-servers.c \ irc-servers-reconnect.c \ irc-servers-setup.c \ + irc-session.c \ lag.c \ massjoin.c \ modes.c \ diff --git a/src/irc/core/irc-core.c b/src/irc/core/irc-core.c index 8906efbe..efede641 100644 --- a/src/irc/core/irc-core.c +++ b/src/irc/core/irc-core.c @@ -36,6 +36,9 @@ void irc_expandos_init(void); void irc_expandos_deinit(void); +void irc_session_init(void); +void irc_session_deinit(void); + void lag_init(void); void lag_deinit(void); @@ -100,6 +103,7 @@ void irc_core_init(void) chat_protocol_register(rec); g_free(rec); + irc_session_init(); irc_chatnets_init(); irc_servers_init(); irc_channels_init(); @@ -130,6 +134,7 @@ void irc_core_deinit(void) irc_irc_deinit(); irc_servers_deinit(); irc_chatnets_deinit(); + irc_session_deinit(); chat_protocol_unregister("IRC"); } diff --git a/src/irc/core/irc-servers.c b/src/irc/core/irc-servers.c index 3314aa24..1a082e82 100644 --- a/src/irc/core/irc-servers.c +++ b/src/irc/core/irc-servers.c @@ -249,7 +249,9 @@ static void sig_connected(IRC_SERVER_REC *server) return; server->splits = g_hash_table_new((GHashFunc) g_istr_hash, (GCompareFunc) g_istr_equal); - server_init(server); + + if (!server->session_reconnect) + server_init(server); } static void sig_disconnected(IRC_SERVER_REC *server) diff --git a/src/irc/core/irc-session.c b/src/irc/core/irc-session.c new file mode 100644 index 00000000..226a7489 --- /dev/null +++ b/src/irc/core/irc-session.c @@ -0,0 +1,95 @@ +/* + irc-session.c : irssi + + Copyright (C) 2001 Timo Sirainen + + 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 "irc-servers.h" +#include "irc-channels.h" + +static void sig_session_save_server(IRC_SERVER_REC *server, CONFIG_REC *config, + CONFIG_NODE *node) +{ + char *chans; + + if (!IS_IRC_SERVER(server)) + return; + + config_node_set_str(config, node, "real_address", server->real_address); + config_node_set_str(config, node, "userhost", server->userhost); + + chans = irc_server_get_channels(server); + config_node_set_str(config, node, "channels", chans); + g_free(chans); +} + +static void sig_session_restore_server(IRC_SERVER_REC *server, + CONFIG_NODE *node) +{ + if (!IS_IRC_SERVER(server)) + return; + + if (server->real_address == NULL) + server->real_address = g_strdup(config_node_get_str(node, "real_address", NULL)); + server->userhost = g_strdup(config_node_get_str(node, "userhost", NULL)); + + g_free_not_null(server->connrec->channels); + server->connrec->channels = g_strdup(config_node_get_str(node, "channels", NULL)); +} + +static void sig_connected(IRC_SERVER_REC *server) +{ + GSList *tmp; + char *str; + + if (!IS_IRC_SERVER(server) || !server->session_reconnect) + return; + + str = g_strdup_printf("%s :Restoring connection to %s", + server->nick, server->connrec->address); + signal_emit("event 001", 3, server, str, server->real_address); + g_free(str); + + /* send join events for each channel and ask names list for them */ + for (tmp = server->channels; tmp != NULL; tmp = tmp->next) { + CHANNEL_REC *rec = tmp->data; + + signal_emit("event join", 4, server, rec->name, + server->nick, server->userhost); + irc_send_cmdv(server, "NAMES %s", rec->name); + } +} + +void irc_session_init(void) +{ + signal_add("session save server", (SIGNAL_FUNC) sig_session_save_server); + signal_add("session restore server", (SIGNAL_FUNC) sig_session_restore_server); + + signal_add("server connected", (SIGNAL_FUNC) sig_connected); +} + +void irc_session_deinit(void) +{ + signal_remove("session save server", (SIGNAL_FUNC) sig_session_save_server); + signal_remove("session restore server", (SIGNAL_FUNC) sig_session_restore_server); + + signal_remove("server connected", (SIGNAL_FUNC) sig_connected); +} -- cgit v1.2.3