summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/session.c50
-rw-r--r--src/irc/core/irc-session.c43
2 files changed, 78 insertions, 15 deletions
diff --git a/src/core/session.c b/src/core/session.c
index fc5daa18..217b44f8 100644
--- a/src/core/session.c
+++ b/src/core/session.c
@@ -28,6 +28,7 @@
#include "chat-protocols.h"
#include "servers.h"
#include "servers-setup.h"
+#include "channels.h"
static char *session_file;
static char *irssi_binary;
@@ -83,7 +84,7 @@ static void cmd_upgrade(const char *data)
cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
/* save the session */
- session_file = g_strdup_printf("%s/session.%d", get_irssi_dir(), getpid());
+ session_file = g_strdup_printf("%s/session", get_irssi_dir());
session = config_open(session_file, 0600);
unlink(session_file);
@@ -102,7 +103,7 @@ static void cmd_upgrade(const char *data)
}
g_slist_free(file_handles),
- /* irssi -! --session ~/.irssi/session.<pid>
+ /* irssi -! --session ~/.irssi/session
data may contain some other program as well, like
/UPGRADE /usr/bin/screen irssi */
str = g_strdup_printf("%s -! --session %s", data, session_file);
@@ -115,9 +116,39 @@ static void cmd_upgrade(const char *data)
_exit(-1);
}
+static void session_save_channel(CHANNEL_REC *channel, CONFIG_REC *config,
+ CONFIG_NODE *node)
+{
+ node = config_node_section(node, NULL, NODE_TYPE_BLOCK);
+
+ config_node_set_str(config, node, "name", channel->name);
+ config_node_set_str(config, node, "topic", channel->topic);
+ config_node_set_str(config, node, "key", channel->key);
+
+ signal_emit("session save channel", 3, channel, config, node);
+}
+
+static void session_restore_channel(SERVER_REC *server, CONFIG_NODE *node)
+{
+ CHANNEL_REC *channel;
+ const char *name;
+
+ name = config_node_get_str(node, "name", NULL);
+ if (name == NULL)
+ return;
+
+ channel = CHAT_PROTOCOL(server)->channel_create(server, name, TRUE);
+ channel->topic = g_strdup(config_node_get_str(node, "topic", NULL));
+ channel->key = g_strdup(config_node_get_str(node, "key", NULL));
+ channel->session_rejoin = TRUE;
+
+ signal_emit("session restore channel", 2, channel, node);
+}
+
static void session_save_server(SERVER_REC *server, CONFIG_REC *config,
CONFIG_NODE *node, GSList **file_handles)
{
+ GSList *tmp;
int handle;
node = config_node_section(node, NULL, NODE_TYPE_BLOCK);
@@ -136,13 +167,19 @@ static void session_save_server(SERVER_REC *server, CONFIG_REC *config,
signal_emit("session save server", 4,
server, config, node, file_handles);
+
+ /* save channels */
+ node = config_node_section(node, "channels", NODE_TYPE_LIST);
+ for (tmp = server->channels; tmp != NULL; tmp = tmp->next)
+ session_save_channel(tmp->data, config, node);
}
static void session_restore_server(CONFIG_NODE *node)
{
CHAT_PROTOCOL_REC *proto;
SERVER_CONNECT_REC *conn;
- SERVER_REC *server;
+ SERVER_REC *server;
+ GSList *tmp;
const char *chat_type, *address, *chatnet, *password, *nick;
int port, handle;
@@ -171,6 +208,13 @@ static void session_restore_server(CONFIG_NODE *node)
server->session_reconnect = TRUE;
signal_emit("session restore server", 2, server, node);
+
+ /* restore channels */
+ node = config_node_section(node, "channels", -1);
+ if (node != NULL || node->type != NODE_TYPE_LIST) {
+ for (tmp = node->value; tmp != NULL; tmp = tmp->next)
+ session_restore_channel(server, tmp->data);
+ }
}
}
diff --git a/src/irc/core/irc-session.c b/src/irc/core/irc-session.c
index dcb7d5d3..4831a75f 100644
--- a/src/irc/core/irc-session.c
+++ b/src/irc/core/irc-session.c
@@ -20,6 +20,7 @@
#include "module.h"
#include "signals.h"
+#include "net-sendbuffer.h"
#include "lib-config/iconfig.h"
#include "irc-servers.h"
@@ -28,18 +29,29 @@
static void sig_session_save_server(IRC_SERVER_REC *server, CONFIG_REC *config,
CONFIG_NODE *node)
{
- char *chans;
+ GSList *tmp;
if (!IS_IRC_SERVER(server))
return;
+ /* send all non-redirected commands to server immediately */
+ for (tmp = server->cmdqueue; tmp != NULL; tmp = tmp->next->next) {
+ const char *cmd = tmp->data;
+ void *redirect = tmp->next->data;
+
+ if (redirect == NULL) {
+ if (net_sendbuffer_send(server->handle, cmd,
+ strlen(cmd)) == -1)
+ break;
+ }
+ }
+ net_sendbuffer_flush(server->handle);
+
config_node_set_str(config, node, "real_address", server->real_address);
config_node_set_str(config, node, "userhost", server->userhost);
config_node_set_str(config, node, "usermode", server->usermode);
-
- chans = irc_server_get_channels(server);
- config_node_set_str(config, node, "channels", chans);
- g_free(chans);
+ config_node_set_bool(config, node, "usermode_away", server->usermode_away);
+ config_node_set_str(config, node, "away_reason", server->away_reason);
}
static void sig_session_restore_server(IRC_SERVER_REC *server,
@@ -52,11 +64,21 @@ static void sig_session_restore_server(IRC_SERVER_REC *server,
server->real_address = g_strdup(config_node_get_str(node, "real_address", NULL));
server->userhost = g_strdup(config_node_get_str(node, "userhost", NULL));
server->usermode = g_strdup(config_node_get_str(node, "usermode", NULL));
+ server->usermode_away = config_node_get_bool(node, "usermode_away", FALSE);
+ server->away_reason = g_strdup(config_node_get_str(node, "away_reason", NULL));
+ /* FIXME: remove before .99 */
g_free_not_null(server->connrec->channels);
server->connrec->channels = g_strdup(config_node_get_str(node, "channels", NULL));
}
+static void session_restore_channel(IRC_CHANNEL_REC *channel)
+{
+ signal_emit("event join", 4, channel->server, channel->name,
+ channel->server->nick, channel->server->userhost);
+ irc_send_cmdv(channel->server, "NAMES %s", channel->name);
+}
+
static void sig_connected(IRC_SERVER_REC *server)
{
GSList *tmp;
@@ -70,15 +92,12 @@ static void sig_connected(IRC_SERVER_REC *server)
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;
+ IRC_CHANNEL_REC *rec = tmp->data;
- rec->session_rejoin = TRUE;
- signal_emit("event join", 4, server, rec->name,
- server->nick, server->userhost);
- irc_send_cmdv(server, "TOPIC %s", rec->name);
- irc_send_cmdv(server, "NAMES %s", rec->name);
+ rec->session_rejoin = TRUE; /* FIXME: remove after .99 */
+ if (rec->session_rejoin)
+ session_restore_channel(rec);
}
}