summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2005-12-06 18:20:59 +0000
committerSebastien Helleu <flashcode@flashtux.org>2005-12-06 18:20:59 +0000
commit0ef010d21121365ca901881de40d5daf6bf4f07a (patch)
tree55dcbfebd572e165ed3cf16838015c2ce0519101 /src
parent6c7a71976b61c6a703d09d1de9db1f4b2496e738 (diff)
downloadweechat-0ef010d21121365ca901881de40d5daf6bf4f07a.zip
added /upgrade command, added ETA for DCC files
Diffstat (limited to 'src')
-rw-r--r--src/common/Makefile.am2
-rw-r--r--src/common/command.c113
-rw-r--r--src/common/command.h1
-rw-r--r--src/common/completion.c10
-rw-r--r--src/common/fifo.c17
-rw-r--r--src/common/history.c88
-rw-r--r--src/common/history.h3
-rw-r--r--src/common/log.c4
-rw-r--r--src/common/session.c1509
-rw-r--r--src/common/session.h169
-rw-r--r--src/common/weechat.c347
-rw-r--r--src/common/weechat.h25
-rw-r--r--src/common/weeconfig.c10
-rw-r--r--src/gui/curses/gui-display.c29
-rw-r--r--src/gui/gui-action.c22
-rw-r--r--src/gui/gui-common.c163
-rw-r--r--src/gui/gui-keyboard.c12
-rw-r--r--src/gui/gui.h6
-rw-r--r--src/irc/irc-channel.c49
-rw-r--r--src/irc/irc-dcc.c117
-rw-r--r--src/irc/irc-display.c10
-rw-r--r--src/irc/irc-ignore.c18
-rw-r--r--src/irc/irc-nick.c72
-rw-r--r--src/irc/irc-recv.c60
-rw-r--r--src/irc/irc-send.c12
-rw-r--r--src/irc/irc-server.c139
-rw-r--r--src/irc/irc.h117
27 files changed, 2527 insertions, 597 deletions
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index e7d9ebb45..0b7be5122 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -37,5 +37,7 @@ lib_weechat_main_a_SOURCES = weechat.c \
log.h \
fifo.c \
fifo.h \
+ session.c \
+ session.h \
utf8.c \
utf8.h
diff --git a/src/common/command.c b/src/common/command.c
index e726e0b06..0e29f676f 100644
--- a/src/common/command.c
+++ b/src/common/command.c
@@ -24,6 +24,7 @@
#include "config.h"
#endif
+#include <unistd.h>
#include <stdlib.h>
#include <string.h>
@@ -31,6 +32,7 @@
#include "command.h"
#include "weelist.h"
#include "weeconfig.h"
+#include "session.h"
#include "../irc/irc.h"
#include "../gui/gui.h"
#include "../plugins/plugins.h"
@@ -77,8 +79,7 @@ t_weechat_command weechat_commands[] =
{ "history", N_("show buffer command history"),
N_("[clear | value]"),
N_("clear: clear history\n"
- "value: number of history entries to show"
- ),
+ "value: number of history entries to show"),
0, 1, weechat_cmd_history, NULL },
{ "ignore", N_("ignore IRC messages and/or hosts"),
N_("[mask [[type | command] [channel [server]]]]"),
@@ -143,6 +144,10 @@ t_weechat_command weechat_commands[] =
"For each argument, '*' means all.\n"
"Without argument, /unignore command lists all defined ignore."),
0, 4, weechat_cmd_unignore, NULL },
+ { "upgrade", N_("upgrade WeeChat without disconnecting from servers"),
+ "",
+ "",
+ 0, 0, weechat_cmd_upgrade, NULL },
{ "uptime", N_("show WeeChat uptime"),
N_("[-o]"),
N_("-o: send uptime on current channel as an IRC message"),
@@ -760,7 +765,7 @@ user_command (t_irc_server *server, t_gui_buffer *buffer, char *command)
command_with_colors2 = (command_with_colors) ?
(char *)gui_color_decode ((unsigned char *)command_with_colors, 1) : NULL;
- if (CHANNEL(buffer)->type == CHAT_PRIVATE)
+ if (CHANNEL(buffer)->type == CHANNEL_TYPE_PRIVATE)
{
gui_printf_type (CHANNEL(buffer)->buffer,
MSG_TYPE_NICK,
@@ -937,11 +942,17 @@ weechat_cmd_buffer_display_info (t_gui_buffer *buffer)
if (buffer->dcc)
gui_printf (NULL, "%sDCC\n",
GUI_COLOR(COLOR_WIN_CHAT_CHANNEL));
- else if (BUFFER_IS_SERVER (buffer))
- gui_printf (NULL, _("%sServer: %s%s\n"),
- GUI_COLOR(COLOR_WIN_CHAT),
- GUI_COLOR(COLOR_WIN_CHAT_SERVER),
- SERVER(buffer)->name);
+ else if (BUFFER_IS_SERVER(buffer))
+ {
+ if (SERVER(buffer))
+ gui_printf (NULL, _("%sServer: %s%s\n"),
+ GUI_COLOR(COLOR_WIN_CHAT),
+ GUI_COLOR(COLOR_WIN_CHAT_SERVER),
+ SERVER(buffer)->name);
+ else
+ gui_printf (NULL, _("%snot connected\n"),
+ GUI_COLOR(COLOR_WIN_CHAT));
+ }
else if (BUFFER_IS_CHANNEL (buffer))
gui_printf (NULL, _("%sChannel: %s%s %s(server: %s%s%s)\n"),
GUI_COLOR(COLOR_WIN_CHAT),
@@ -961,7 +972,8 @@ weechat_cmd_buffer_display_info (t_gui_buffer *buffer)
SERVER(buffer)->name,
GUI_COLOR(COLOR_WIN_CHAT));
else
- gui_printf (NULL, _("not connected\n"));
+ gui_printf (NULL, _("%sunknown\n"),
+ GUI_COLOR(COLOR_WIN_CHAT));
}
/*
@@ -1384,7 +1396,7 @@ weechat_cmd_debug (int argc, char **argv)
if (ascii_strcasecmp (argv[0], "dump") == 0)
{
- wee_dump (0);
+ weechat_dump (0);
}
else if (ascii_strcasecmp (argv[0], "windows") == 0)
{
@@ -2795,6 +2807,87 @@ weechat_cmd_unignore (int argc, char **argv)
}
/*
+ * weechat_cmd_upgrade: upgrade WeeChat
+ */
+
+int
+weechat_cmd_upgrade (int argc, char **argv)
+{
+ t_irc_server *ptr_server;
+ int filename_length;
+ char *filename;
+ char *exec_args[5] = { NULL, "-a", "--session", NULL, NULL };
+
+ /* make gcc happy */
+ (void) argc;
+ (void) argv;
+
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ if (ptr_server->child_pid != 0)
+ {
+ irc_display_prefix (NULL, gui_current_window->buffer, PREFIX_ERROR);
+ gui_printf_nolog (NULL,
+ _("%s can't upgrade: connection to at least "
+ "one server is pending"),
+ WEECHAT_ERROR);
+ return -1;
+ }
+ }
+
+ filename_length = strlen (weechat_home) + strlen (WEECHAT_SESSION_NAME) + 2;
+ filename = (char *) malloc (filename_length * sizeof (char));
+ if (!filename)
+ return -2;
+ snprintf (filename, filename_length, "%s%s" WEECHAT_SESSION_NAME,
+ weechat_home, DIR_SEPARATOR);
+
+ irc_display_prefix (NULL, NULL, PREFIX_INFO);
+ gui_printf_nolog (NULL, _("Upgrading WeeChat...\n"));
+
+ if (!session_save (filename))
+ {
+ free (filename);
+ irc_display_prefix (NULL, NULL, PREFIX_ERROR);
+ gui_printf_nolog (NULL,
+ _("%s unable to save session in file\n"),
+ WEECHAT_ERROR);
+ return -1;
+ }
+
+ exec_args[0] = strdup (weechat_argv0);
+ exec_args[3] = strdup (filename);
+
+ /* unload plugins, save config, then upgrade */
+#ifdef PLUGINS
+ plugin_end ();
+#endif
+ (void) config_write (NULL);
+ gui_end ();
+
+ execvp (exec_args[0], exec_args);
+
+ /* this code should not be reached if execvp is ok */
+#ifdef PLUGINS
+ plugin_init (1);
+#endif
+
+ fprintf (stderr, _("%s exec failed (program: \"%s\"), exiting WeeChat\n"),
+ WEECHAT_ERROR,
+ exec_args[0]);
+
+ free (exec_args[0]);
+ free (exec_args[3]);
+ free (filename);
+
+ weechat_shutdown (EXIT_FAILURE, 0);
+
+ /* never executed */
+ return -1;
+}
+
+/*
* weechat_cmd_uptime: display WeeChat uptime
*/
diff --git a/src/common/command.h b/src/common/command.h
index 4369a4251..3cbd599a5 100644
--- a/src/common/command.h
+++ b/src/common/command.h
@@ -81,6 +81,7 @@ extern int weechat_cmd_server (int, char **);
extern int weechat_cmd_set (char *);
extern int weechat_cmd_unalias (char *);
extern int weechat_cmd_unignore (int, char **);
+extern int weechat_cmd_upgrade (int, char **);
extern int weechat_cmd_uptime (int, char **);
extern int weechat_cmd_window (int, char **);
diff --git a/src/common/completion.c b/src/common/completion.c
index e7f1dc624..8cf2a81b0 100644
--- a/src/common/completion.c
+++ b/src/common/completion.c
@@ -250,7 +250,7 @@ completion_build_list (t_completion *completion, void *channel)
"*");
if (channel)
{
- if (((t_irc_channel *)channel)->type == CHAT_CHANNEL)
+ if (((t_irc_channel *)channel)->type == CHANNEL_TYPE_CHANNEL)
{
for (ptr_nick = ((t_irc_channel *)channel)->nicks; ptr_nick;
ptr_nick = ptr_nick->next_nick)
@@ -260,7 +260,7 @@ completion_build_list (t_completion *completion, void *channel)
ptr_nick->nick);
}
}
- if (((t_irc_channel *)channel)->type == CHAT_PRIVATE)
+ if (((t_irc_channel *)channel)->type == CHANNEL_TYPE_PRIVATE)
{
weelist_add (&completion->completion_list,
&completion->last_completion,
@@ -302,7 +302,7 @@ completion_build_list (t_completion *completion, void *channel)
weelist_add(&completion->completion_list,
&completion->last_completion,
"*");
- if (((t_irc_channel *)channel)->type == CHAT_CHANNEL)
+ if (((t_irc_channel *)channel)->type == CHANNEL_TYPE_CHANNEL)
weelist_add(&completion->completion_list,
&completion->last_completion,
((t_irc_channel *)channel)->name);
@@ -822,7 +822,7 @@ completion_find_context (t_completion *completion, void *channel, char *buffer,
}
if (!completion->completion_list && channel &&
- (((t_irc_channel *)channel)->type == CHAT_PRIVATE)
+ (((t_irc_channel *)channel)->type == CHANNEL_TYPE_PRIVATE)
&& (completion->context == COMPLETION_NICK))
{
/* nick completion in private (only other nick and self) */
@@ -1017,7 +1017,7 @@ completion_nick (t_completion *completion, t_irc_channel *channel)
if (!channel)
return;
- if (((t_irc_channel *)channel)->type == CHAT_PRIVATE)
+ if (((t_irc_channel *)channel)->type == CHANNEL_TYPE_PRIVATE)
{
completion_command_arg (completion, channel, 1);
return;
diff --git a/src/common/fifo.c b/src/common/fifo.c
index 807922363..b4a690446 100644
--- a/src/common/fifo.c
+++ b/src/common/fifo.c
@@ -70,8 +70,9 @@ fifo_create ()
gui_printf (NULL,
_("%s unable to create FIFO pipe for remote control (%s)\n"),
WEECHAT_ERROR, weechat_fifo_filename);
- wee_log_printf (_("%s unable to create FIFO pipe for remote control (%s)\n"),
- WEECHAT_ERROR, weechat_fifo_filename);
+ weechat_log_printf (_("%s unable to create FIFO pipe for "
+ "remote control (%s)\n"),
+ WEECHAT_ERROR, weechat_fifo_filename);
return;
}
@@ -81,12 +82,12 @@ fifo_create ()
gui_printf (NULL,
_("%s unable to open FIFO pipe (%s) for reading\n"),
WEECHAT_ERROR, weechat_fifo_filename);
- wee_log_printf (_("%s unable to open FIFO pipe (%s) for reading\n"),
- WEECHAT_ERROR, weechat_fifo_filename);
+ weechat_log_printf (_("%s unable to open FIFO pipe (%s) for reading\n"),
+ WEECHAT_ERROR, weechat_fifo_filename);
return;
}
- wee_log_printf (_("FIFO pipe is open\n"));
+ weechat_log_printf (_("FIFO pipe is open\n"));
}
}
@@ -249,8 +250,8 @@ fifo_read ()
gui_printf (NULL,
_("%s error reading FIFO pipe, closing it\n"),
WEECHAT_ERROR);
- wee_log_printf (_("%s error reading FIFO pipe, closing it\n"),
- WEECHAT_ERROR);
+ weechat_log_printf (_("%s error reading FIFO pipe, closing it\n"),
+ WEECHAT_ERROR);
fifo_remove ();
}
else
@@ -291,5 +292,5 @@ fifo_remove ()
weechat_fifo_filename = NULL;
}
- wee_log_printf (_("FIFO pipe is closed\n"));
+ weechat_log_printf (_("FIFO pipe is closed\n"));
}
diff --git a/src/common/history.c b/src/common/history.c
index 4f1113eec..266ab0a06 100644
--- a/src/common/history.c
+++ b/src/common/history.c
@@ -66,55 +66,18 @@ history_hide_password (char *string)
}
/*
- * history_add: add a text/command to history
+ * history_buffer_add: add a text/command to buffer's history
*/
void
-history_add (void *buffer, char *string)
+history_buffer_add (void *buffer, char *string)
{
t_history *new_history, *ptr_history;
-
- if ( !history_global
- || ( history_global
- && ascii_strcasecmp (history_global->text, string) != 0))
- {
- /* add history to global history */
- new_history = (t_history *)malloc (sizeof (t_history));
- if (new_history)
- {
- new_history->text = strdup (string);
- if (cfg_log_hide_nickserv_pwd)
- history_hide_password (new_history->text);
-
- if (history_global)
- history_global->prev_history = new_history;
- else
- history_global_last = new_history;
- new_history->next_history = history_global;
- new_history->prev_history = NULL;
- history_global = new_history;
- num_history_global++;
-
- /* remove one command if necessary */
- if ((cfg_history_max_commands > 0)
- && (num_history_global > cfg_history_max_commands))
- {
- ptr_history = history_global_last->prev_history;
- history_global_last->prev_history->next_history = NULL;
- if (history_global_last->text)
- free (history_global_last->text);
- free (history_global_last);
- history_global_last = ptr_history;
- num_history_global--;
- }
- }
- }
if ( !((t_gui_buffer *)(buffer))->history
|| ( ((t_gui_buffer *)(buffer))->history
&& ascii_strcasecmp (((t_gui_buffer *)(buffer))->history->text, string) != 0))
{
- /* add history to local history */
new_history = (t_history *)malloc (sizeof (t_history));
if (new_history)
{
@@ -129,7 +92,7 @@ history_add (void *buffer, char *string)
new_history->next_history = ((t_gui_buffer *)(buffer))->history;
new_history->prev_history = NULL;
((t_gui_buffer *)buffer)->history = new_history;
- ((t_gui_buffer *)(buffer))->num_history++;
+ ((t_gui_buffer *)buffer)->num_history++;
/* remove one command if necessary */
if ((cfg_history_max_commands > 0)
@@ -148,6 +111,51 @@ history_add (void *buffer, char *string)
}
/*
+ * history_global_add: add a text/command to buffer's history
+ */
+
+void
+history_global_add (char *string)
+{
+ t_history *new_history, *ptr_history;
+
+ if (!history_global
+ || (history_global
+ && ascii_strcasecmp (history_global->text, string) != 0))
+ {
+ new_history = (t_history *)malloc (sizeof (t_history));
+ if (new_history)
+ {
+ new_history->text = strdup (string);
+ if (cfg_log_hide_nickserv_pwd)
+ history_hide_password (new_history->text);
+
+ if (history_global)
+ history_global->prev_history = new_history;
+ else
+ history_global_last = new_history;
+ new_history->next_history = history_global;
+ new_history->prev_history = NULL;
+ history_global = new_history;
+ num_history_global++;
+
+ /* remove one command if necessary */
+ if ((cfg_history_max_commands > 0)
+ && (num_history_global > cfg_history_max_commands))
+ {
+ ptr_history = history_global_last->prev_history;
+ history_global_last->prev_history->next_history = NULL;
+ if (history_global_last->text)
+ free (history_global_last->text);
+ free (history_global_last);
+ history_global_last = ptr_history;
+ num_history_global--;
+ }
+ }
+ }
+}
+
+/*
* history_global_free: free global history
*/
diff --git a/src/common/history.h b/src/common/history.h
index 9928e0787..1759aba62 100644
--- a/src/common/history.h
+++ b/src/common/history.h
@@ -34,7 +34,8 @@ extern t_history *history_global;
extern t_history *history_global_last;
extern t_history *history_global_ptr;
-extern void history_add (void *, char *);
+extern void history_buffer_add (void *, char *);
+extern void history_global_add (char *);
extern void history_global_free ();
extern void history_buffer_free (void *);
diff --git a/src/common/log.c b/src/common/log.c
index cc76a2d5e..cfd3cca44 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -120,7 +120,7 @@ log_start (t_gui_buffer *buffer)
buffer->log_filename = (char *) malloc (length);
if (!buffer->log_filename)
{
- wee_log_printf (_("Not enough memory to write log file for a buffer\n"));
+ weechat_log_printf (_("Not enough memory to write log file for a buffer\n"));
return;
}
if (cfg_log_path[0] == '~')
@@ -148,7 +148,7 @@ log_start (t_gui_buffer *buffer)
buffer->log_file = fopen (buffer->log_filename, "a");
if (!buffer->log_file)
{
- wee_log_printf (_("Unable to write log file for a buffer\n"));
+ weechat_log_printf (_("Unable to write log file for a buffer\n"));
free (buffer->log_filename);
return;
}
diff --git a/src/common/session.c b/src/common/session.c
new file mode 100644
index 000000000..0ac84d817
--- /dev/null
+++ b/src/common/session.c
@@ -0,0 +1,1509 @@
+/*
+ * Copyright (c) 2003-2005 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * 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
+ */
+
+/* session.c: save/restore session data */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+
+#include "weechat.h"
+#include "session.h"
+#include "../irc/irc.h"
+#include "../gui/gui.h"
+
+
+/* current server/channel (used when loading session) */
+t_irc_server *session_current_server = NULL;
+t_irc_channel *session_current_channel = NULL;
+t_gui_buffer *session_current_buffer = NULL;
+
+long session_last_read_pos = 0;
+int session_last_read_length = 0;
+
+
+/*
+ * session_write_id: write object ID to file
+ */
+
+int
+session_write_id (FILE *file, int id)
+{
+ return (fwrite ((void *)(&id), sizeof (int), 1, file) > 0);
+}
+
+/*
+ * session_write_int: write an integer to file
+ */
+
+int
+session_write_int (FILE *file, int id, int value)
+{
+ char type;
+
+ if (id >= 0)
+ {
+ if (!session_write_id (file, id))
+ return 0;
+ }
+ type = SESSION_TYPE_INT;
+ if (fwrite ((void *)(&type), sizeof (char), 1, file) == 0)
+ return 0;
+ return (fwrite ((void *)(&value), sizeof (int), 1, file) > 0);
+}
+
+/*
+ * session_write_str: write a string to file
+ */
+
+int
+session_write_str (FILE *file, int id, char *string)
+{
+ char type;
+ int length;
+
+ if (id >= 0)
+ {
+ if (!session_write_id (file, id))
+ return 0;
+ }
+ type = SESSION_TYPE_STR;
+ if (fwrite ((void *)(&type), sizeof (char), 1, file) == 0)
+ return 0;
+ if (string && string[0])
+ {
+ length = strlen (string);
+ if (fwrite ((void *)(&length), sizeof (int), 1, file) == 0)
+ return 0;
+ return (fwrite ((void *)string, length, 1, file) > 0);
+ }
+ else
+ {
+ length = 0;
+ return (fwrite ((void *)(&length), sizeof (int), 1, file) > 0);
+ }
+}
+
+/*
+ * session_write_buf: write a buffer to file
+ */
+
+int
+session_write_buf (FILE *file, int id, void *buffer, int size)
+{
+ char type;
+
+ if (id >= 0)
+ {
+ if (!session_write_id (file, id))
+ return 0;
+ }
+ type = SESSION_TYPE_BUF;
+ if (fwrite ((void *)(&type), sizeof (char), 1, file) == 0)
+ return 0;
+ if (fwrite ((void *)(&size), sizeof (int), 1, file) == 0)
+ return 0;
+ return (fwrite (buffer, size, 1, file) > 0);
+}
+
+/*
+ * session_save_nick: save a nick into session file
+ */
+
+int
+session_save_nick (FILE *file, t_irc_nick *nick)
+{
+ int rc;
+
+ rc = 1;
+ rc = rc && (session_write_id (file, SESSION_OBJ_NICK));
+ rc = rc && (session_write_str (file, SESSION_NICK_NICK, nick->nick));
+ rc = rc && (session_write_int (file, SESSION_NICK_FLAGS, nick->flags));
+ rc = rc && (session_write_int (file, SESSION_NICK_COLOR, nick->color));
+ rc = rc && (session_write_id (file, SESSION_NICK_END));
+ return rc;
+}
+
+/*
+ * session_save_channel: save a channel into session file
+ */
+
+int
+session_save_channel (FILE *file, t_irc_channel *channel)
+{
+ int rc;
+ t_irc_nick *ptr_nick;
+
+ rc = 1;
+ rc = rc && (session_write_id (file, SESSION_OBJ_CHANNEL));
+ rc = rc && (session_write_int (file, SESSION_CHAN_TYPE, channel->type));
+ rc = rc && (session_write_str (file, SESSION_CHAN_NAME, channel->name));
+ rc = rc && (session_write_str (file, SESSION_CHAN_TOPIC, channel->topic));
+ rc = rc && (session_write_str (file, SESSION_CHAN_MODES, channel->modes));
+ rc = rc && (session_write_int (file, SESSION_CHAN_LIMIT, channel->limit));
+ rc = rc && (session_write_str (file, SESSION_CHAN_KEY, channel->key));
+ rc = rc && (session_write_int (file, SESSION_CHAN_NICKS_COUNT, channel->nicks_count));
+ rc = rc && (session_write_int (file, SESSION_CHAN_CHECKING_AWAY, channel->checking_away));
+ rc = rc && (session_write_id (file, SESSION_CHAN_END));
+
+ if (!rc)
+ return 0;
+
+ for (ptr_nick = channel->nicks; ptr_nick;
+ ptr_nick = ptr_nick->next_nick)
+ {
+ if (!session_save_nick (file, ptr_nick))
+ return 0;
+ }
+
+ return 1;
+}
+
+/*
+ * session_save_servers: save all servers into session file
+ */
+
+int
+session_save_servers (FILE *file)
+{
+ int rc;
+ t_irc_server *ptr_server;
+ t_irc_channel *ptr_channel;
+
+ rc = 1;
+
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ rc = rc && (session_write_id (file, SESSION_OBJ_SERVER));
+ rc = rc && (session_write_str (file, SESSION_SERV_NAME, ptr_server->name));
+ rc = rc && (session_write_int (file, SESSION_SERV_AUTOCONNECT, ptr_server->autoconnect));
+ rc = rc && (session_write_int (file, SESSION_SERV_AUTORECONNECT, ptr_server->autoreconnect));
+ rc = rc && (session_write_int (file, SESSION_SERV_AUTORECONNECT_DELAY, ptr_server->autoreconnect_delay));
+ rc = rc && (session_write_int (file, SESSION_SERV_COMMAND_LINE, ptr_server->command_line));
+ rc = rc && (session_write_str (file, SESSION_SERV_ADDRESS, ptr_server->address));
+ rc = rc && (session_write_int (file, SESSION_SERV_PORT, ptr_server->port));
+ rc = rc && (session_write_int (file, SESSION_SERV_IPV6, ptr_server->ipv6));
+ rc = rc && (session_write_int (file, SESSION_SERV_SSL, ptr_server->ssl));
+ rc = rc && (session_write_str (file, SESSION_SERV_PASSWORD, ptr_server->password));
+ rc = rc && (session_write_str (file, SESSION_SERV_NICK1, ptr_server->nick1));
+ rc = rc && (session_write_str (file, SESSION_SERV_NICK2, ptr_server->nick2));
+ rc = rc && (session_write_str (file, SESSION_SERV_NICK3, ptr_server->nick3));
+ rc = rc && (session_write_str (file, SESSION_SERV_USERNAME, ptr_server->username));
+ rc = rc && (session_write_str (file, SESSION_SERV_REALNAME, ptr_server->realname));
+ rc = rc && (session_write_str (file, SESSION_SERV_COMMAND, ptr_server->command));
+ rc = rc && (session_write_int (file, SESSION_SERV_COMMAND_DELAY, ptr_server->command_delay));
+ rc = rc && (session_write_str (file, SESSION_SERV_AUTOJOIN, ptr_server->autojoin));
+ rc = rc && (session_write_int (file, SESSION_SERV_AUTOREJOIN, ptr_server->autorejoin));
+ rc = rc && (session_write_str (file, SESSION_SERV_NOTIFY_LEVELS, ptr_server->notify_levels));
+ rc = rc && (session_write_int (file, SESSION_SERV_CHILD_PID, ptr_server->child_pid));
+ rc = rc && (session_write_int (file, SESSION_SERV_CHILD_READ, ptr_server->child_read));
+ rc = rc && (session_write_int (file, SESSION_SERV_CHILD_WRITE, ptr_server->child_write));
+ rc = rc && (session_write_int (file, SESSION_SERV_SOCK, ptr_server->sock));
+ rc = rc && (session_write_int (file, SESSION_SERV_IS_CONNECTED, ptr_server->is_connected));
+ rc = rc && (session_write_int (file, SESSION_SERV_SSL_CONNECTED, ptr_server->ssl_connected));
+#ifdef HAVE_GNUTLS
+ rc = rc && (session_write_buf (file, SESSION_SERV_GNUTLS_SESS, &(ptr_server->gnutls_sess), sizeof (gnutls_session)));
+#endif
+ rc = rc && (session_write_str (file, SESSION_SERV_UNTERMINATED_MESSAGE, ptr_server->unterminated_message));
+ rc = rc && (session_write_str (file, SESSION_SERV_NICK, ptr_server->nick));
+ rc = rc && (session_write_buf (file, SESSION_SERV_RECONNECT_START, &(ptr_server->reconnect_start), sizeof (time_t)));
+ rc = rc && (session_write_int (file, SESSION_SERV_RECONNECT_JOIN, ptr_server->reconnect_join));
+ rc = rc && (session_write_int (file, SESSION_SERV_IS_AWAY, ptr_server->is_away));
+ rc = rc && (session_write_buf (file, SESSION_SERV_AWAY_TIME, &(ptr_server->away_time), sizeof (time_t)));
+ rc = rc && (session_write_int (file, SESSION_SERV_LAG, ptr_server->lag));
+ rc = rc && (session_write_buf (file, SESSION_SERV_LAG_CHECK_TIME, &(ptr_server->lag_check_time), sizeof (struct timeval)));
+ rc = rc && (session_write_buf (file, SESSION_SERV_LAG_NEXT_CHECK, &(ptr_server->lag_next_check), sizeof (time_t)));
+ rc = rc && (session_write_id (file, SESSION_SERV_END));
+
+ if (!rc)
+ return 0;
+
+ for (ptr_channel = ptr_server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
+ {
+ if (!session_save_channel (file, ptr_channel))
+ return 0;
+ }
+ }
+ return 1;
+}
+
+/*
+ * session_save_dcc: save all DCC into session file
+ */
+
+int
+session_save_dcc (FILE *file)
+{
+ int rc;
+ t_irc_dcc *ptr_dcc;
+
+ rc = 1;
+
+ for (ptr_dcc = dcc_list; ptr_dcc;
+ ptr_dcc = ptr_dcc->next_dcc)
+ {
+ rc = rc && (session_write_id (file, SESSION_OBJ_DCC));
+ rc = rc && (session_write_str (file, SESSION_DCC_SERVER, (ptr_dcc->server) ? ptr_dcc->server->name : NULL));
+ rc = rc && (session_write_str (file, SESSION_DCC_CHANNEL, (ptr_dcc->channel) ? ptr_dcc->channel->name : NULL));
+ rc = rc && (session_write_int (file, SESSION_DCC_TYPE, ptr_dcc->type));
+ rc = rc && (session_write_int (file, SESSION_DCC_STATUS, ptr_dcc->status));
+ rc = rc && (session_write_buf (file, SESSION_DCC_START_TIME, &(ptr_dcc->start_time), sizeof (time_t)));
+ rc = rc && (session_write_buf (file, SESSION_DCC_START_TRANSFER, &(ptr_dcc->start_transfer), sizeof (time_t)));
+ rc = rc && (session_write_buf (file, SESSION_DCC_ADDR, &(ptr_dcc->addr), sizeof (unsigned long)));
+ rc = rc && (session_write_int (file, SESSION_DCC_PORT, ptr_dcc->port));
+ rc = rc && (session_write_str (file, SESSION_DCC_NICK, ptr_dcc->nick));
+ rc = rc && (session_write_int (file, SESSION_DCC_SOCK, ptr_dcc->sock));
+ rc = rc && (session_write_str (file, SESSION_DCC_UNTERMINATED_MESSAGE, ptr_dcc->unterminated_message));
+ rc = rc && (session_write_int (file, SESSION_DCC_FILE, ptr_dcc->file));
+ rc = rc && (session_write_str (file, SESSION_DCC_FILENAME, ptr_dcc->filename));
+ rc = rc && (session_write_str (file, SESSION_DCC_LOCAL_FILENAME, ptr_dcc->local_filename));
+ rc = rc && (session_write_int (file, SESSION_DCC_FILENAME_SUFFIX, ptr_dcc->filename_suffix));
+ rc = rc && (session_write_buf (file, SESSION_DCC_SIZE, &(ptr_dcc->size), sizeof (unsigned long)));
+ rc = rc && (session_write_buf (file, SESSION_DCC_POS, &(ptr_dcc->pos), sizeof (unsigned long)));
+ rc = rc && (session_write_buf (file, SESSION_DCC_ACK, &(ptr_dcc->ack), sizeof (unsigned long)));
+ rc = rc && (session_write_buf (file, SESSION_DCC_START_RESUME, &(ptr_dcc->start_resume), sizeof (unsigned long)));
+ rc = rc && (session_write_buf (file, SESSION_DCC_LAST_CHECK_TIME, &(ptr_dcc->last_check_time), sizeof (time_t)));
+ rc = rc && (session_write_buf (file, SESSION_DCC_LAST_CHECK_POS, &(ptr_dcc->last_check_pos), sizeof (unsigned long)));
+ rc = rc && (session_write_buf (file, SESSION_DCC_LAST_ACTIVITY, &(ptr_dcc->last_activity), sizeof (time_t)));
+ rc = rc && (session_write_buf (file, SESSION_DCC_BYTES_PER_SEC, &(ptr_dcc->bytes_per_sec), sizeof (unsigned long)));
+ rc = rc && (session_write_buf (file, SESSION_DCC_ETA, &(ptr_dcc->eta), sizeof (unsigned long)));
+ rc = rc && (session_write_id (file, SESSION_DCC_END));
+
+ if (!rc)
+ return 0;
+ }
+ return 1;
+}
+
+/*
+ * session_save_history: save history into session file
+ * (from last to first, to restore it in good order)
+ */
+
+int
+session_save_history (FILE *file, t_history *last_history)
+{
+ int rc;
+ t_history *ptr_history;
+
+ rc = 1;
+ rc = rc && (session_write_id (file, SESSION_OBJ_HISTORY));
+ ptr_history = last_history;
+ while (ptr_history)
+ {
+ rc = rc && (session_write_str (file, SESSION_HIST_TEXT, ptr_history->text));
+ ptr_history = ptr_history->prev_history;
+ }
+ rc = rc && (session_write_id (file, SESSION_HIST_END));
+ return rc;
+}
+
+/*
+ * session_save_line: save a buffer line into session file
+ */
+
+int
+session_save_line (FILE *file, t_gui_line *line)
+{
+ int rc;
+
+ rc = 1;
+ rc = rc && (session_write_id (file, SESSION_OBJ_LINE));
+ rc = rc && (session_write_int (file, SESSION_LINE_LENGTH, line->length));
+ rc = rc && (session_write_int (file, SESSION_LINE_LENGTH_ALIGN, line->length_align));
+ rc = rc && (session_write_int (file, SESSION_LINE_LOG_WRITE, line->log_write));
+ rc = rc && (session_write_int (file, SESSION_LINE_WITH_MESSAGE, line->line_with_message));
+ rc = rc && (session_write_int (file, SESSION_LINE_WITH_HIGHLIGHT, line->line_with_highlight));
+ rc = rc && (session_write_str (file, SESSION_LINE_DATA, line->data));
+ rc = rc && (session_write_int (file, SESSION_LINE_OFS_AFTER_DATE, line->ofs_after_date));
+ rc = rc && (session_write_id (file, SESSION_LINE_END));
+ return rc;
+}
+
+/*
+ * session_save_buffers: save all buffers into session file
+ */
+
+int
+session_save_buffers (FILE *file)
+{
+ int rc;
+ t_gui_buffer *ptr_buffer;
+ t_gui_line *ptr_line;
+
+ rc = 1;
+
+ for (ptr_buffer = gui_buffers; ptr_buffer;
+ ptr_buffer = ptr_buffer->next_buffer)
+ {
+ rc = rc && (session_write_id (file, SESSION_OBJ_BUFFER));
+ rc = rc && (session_write_str (file, SESSION_BUFF_SERVER, SERVER(ptr_buffer) ? SERVER(ptr_buffer)->name : NULL));
+ rc = rc && (session_write_str (file, SESSION_BUFF_CHANNEL, CHANNEL(ptr_buffer) ? CHANNEL(ptr_buffer)->name : NULL));
+ rc = rc && (session_write_int (file, SESSION_BUFF_DCC, ptr_buffer->dcc));
+ rc = rc && (session_write_id (file, SESSION_BUFF_END));
+
+ if (!rc)
+ return 0;
+
+ for (ptr_line = ptr_buffer->lines; ptr_line;
+ ptr_line = ptr_line->next_line)
+ {
+ if (!session_save_line (file, ptr_line))
+ return 0;
+ }
+
+ if (!session_save_history (file, ptr_buffer->last_history))
+ return 0;
+ }
+ return 1;
+}
+
+/*
+ * session_save: save current session
+ */
+
+int
+session_save (char *filename)
+{
+ FILE *file;
+ int rc;
+
+ if ((file = fopen (filename, "wb")) == NULL)
+ return 0;
+
+ rc = 1;
+ rc = rc && (session_write_str (file, -1, SESSION_SIGNATURE));
+ rc = rc && (session_save_servers (file));
+ rc = rc && (session_save_dcc (file));
+ rc = rc && (session_save_history (file, history_global_last));
+ rc = rc && (session_save_buffers (file));
+
+ fclose (file);
+
+ return rc;
+}
+
+/* ========================================================================== */
+
+/*
+ * session_crash: stop WeeChat if problem during session loading
+ */
+
+void
+session_crash (FILE *file, char *message, ...)
+{
+ char buffer[4096];
+ va_list argptr;
+
+ va_start (argptr, message);
+ vsnprintf (buffer, sizeof (buffer) - 1, message, argptr);
+ va_end (argptr);
+
+ fclose (file);
+ gui_end ();
+ fprintf (stderr, "%s %s\n",
+ WEECHAT_ERROR, buffer);
+ fprintf (stderr,
+ _("Last operation with session file was at position %ld, "
+ "read of %d bytes\n"),
+ session_last_read_pos,
+ session_last_read_length);
+ fprintf (stderr,
+ _("Please send ~/.weechat/%s, ~/.weechat/%s and "
+ "above messages to WeeChat developers for support.\n"
+ "Be careful, private info may be in these files.\n"),
+ WEECHAT_LOG_NAME,
+ WEECHAT_SESSION_NAME);
+ exit (EXIT_FAILURE);
+}
+
+/*
+ * session_read_int: read integer from file
+ */
+
+int
+session_read_int (FILE *file, int *value)
+{
+ char type;
+
+ session_last_read_pos = ftell (file);
+ session_last_read_length = sizeof (char);
+
+ if (fread ((void *)(&type), sizeof (char), 1, file) == 0)
+ return 0;
+ if (type != SESSION_TYPE_INT)
+ {
+ session_crash (file, _("wrong type in file (expected: %d, read: %d)"),
+ SESSION_TYPE_INT, type);
+ return 0;
+ }
+
+ session_last_read_pos = ftell (file);
+ session_last_read_length = sizeof (int);
+
+ if (value)
+ return (fread ((void *)value, sizeof (int), 1, file) > 0);
+ else
+ return (fseek (file, sizeof (int), SEEK_CUR) >= 0);
+}
+
+/*
+ * session_read_str: read string from file
+ */
+
+int
+session_read_str (FILE *file, char **string)
+{
+ char type;
+ int length;
+
+ if (string && *string)
+ free (*string);
+
+ session_last_read_pos = ftell (file);
+ session_last_read_length = sizeof (char);
+
+ if (fread ((void *)(&type), sizeof (char), 1, file) == 0)
+ return 0;
+ if (type != SESSION_TYPE_STR)
+ {
+ session_crash (file, _("wrong type in file (expected: %d, read: %d)"),
+ SESSION_TYPE_STR, type);
+ return 0;
+ }
+
+ session_last_read_pos = ftell (file);
+ session_last_read_length = sizeof (int);
+
+ if (fread ((void *)(&length), sizeof (int), 1, file) == 0)
+ return 0;
+
+ if (length == 0)
+ {
+ if (string)
+ (*string) = NULL;
+ return 1;
+ }
+
+ session_last_read_pos = ftell (file);
+ session_last_read_length = length;
+
+ if (string)
+ {
+ (*string) = (char *) malloc (length + 1);
+ if (!(*string))
+ return 0;
+
+ if (fread ((void *)(*string), length, 1, file) == 0)
+ {
+ free (*string);
+ return 0;
+ }
+ (*string)[length] = '\0';
+ }
+ else
+ return (fseek (file, length, SEEK_CUR) >= 0);
+
+ return 1;
+}
+
+/*
+ * session_read_buf: read buffer from file
+ */
+
+int
+session_read_buf (FILE *file, void *buffer, int length_expected)
+{
+ char type;
+ int length;
+
+ session_last_read_pos = ftell (file);
+ session_last_read_length = sizeof (char);
+
+ if (fread ((void *)(&type), sizeof (char), 1, file) == 0)
+ return 0;
+ if (type != SESSION_TYPE_BUF)
+ {
+ session_crash (file, _("wrong type in file (expected: %d, read: %d)"),
+ SESSION_TYPE_BUF, type);
+ return 0;
+ }
+
+ session_last_read_pos = ftell (file);
+ session_last_read_length = sizeof (int);
+
+ if (fread ((void *)(&length), sizeof (int), 1, file) == 0)
+ return 0;
+ if ((length_expected > 0) && (length != length_expected))
+ {
+ session_crash (file, _("invalid length for a buffer"));
+ return 0;
+ }
+
+ session_last_read_pos = ftell (file);
+ session_last_read_length = length;
+
+ if (buffer)
+ return (fread (buffer, length, 1, file) > 0);
+ else
+ return (fseek (file, length, SEEK_CUR) >= 0);
+}
+
+/*
+ * session_read_object: read an object in file
+ */
+
+int
+session_read_object (FILE *file, int object_id, int type, void *target, int max_buf_length)
+{
+ int object_id_read;
+ char type_read;
+
+ if (fread ((void *)(&object_id_read), sizeof (int), 1, file) == 0)
+ {
+ session_crash (file, _("object read error"));
+ return 0;
+ }
+ if (object_id_read != object_id)
+ {
+ session_crash (file, _("wrong object (expected: %d, read: %d)"),
+ object_id, object_id_read);
+ return 0;
+ }
+
+ session_last_read_pos = ftell (file);
+ session_last_read_length = sizeof (char);
+
+ if (fread ((void *)(&type_read), sizeof (char), 1, file) == 0)
+ {
+ session_crash (file, _("type read error"));
+ return 0;
+ }
+ if (type_read != type)
+ {
+ session_crash (file, _("wrong type (expected: %d, read: %d)"),
+ type, type_read);
+ return 0;
+ }
+ if (fseek (file, sizeof (char) * (-1), SEEK_CUR) < 0)
+ return 0;
+ switch (type)
+ {
+ case SESSION_TYPE_INT:
+ return session_read_int (file, (int *)target);
+ case SESSION_TYPE_STR:
+ return session_read_str (file, (char **)target);
+ case SESSION_TYPE_BUF:
+ return session_read_buf (file, target, max_buf_length);
+ }
+ return 0;
+}
+
+/*
+ * session_read_ignore_value: ignore a value from file
+ */
+
+int
+session_read_ignore_value (FILE *file)
+{
+ char type;
+
+ if (fread ((void *)(&type), sizeof (char), 1, file) == 0)
+ return 0;
+ if (fseek (file, sizeof (char) * (-1), SEEK_CUR) < 0)
+ return 0;
+ switch (type)
+ {
+ case SESSION_TYPE_INT:
+ return session_read_int (file, NULL);
+ case SESSION_TYPE_STR:
+ return session_read_str (file, NULL);
+ case SESSION_TYPE_BUF:
+ return session_read_buf (file, NULL, 0);
+ }
+ return 0;
+}
+
+/*
+ * session_read_ignore_object: ignore an object from file
+ */
+
+int
+session_read_ignore_object (FILE *file)
+{
+ int object_id;
+
+ while (1)
+ {
+ if (fread ((void *)(&object_id), sizeof (int), 1, file) == 0)
+ return 0;
+ if (feof (file))
+ return 0;
+ if (object_id == SESSION_OBJ_END)
+ return 1;
+ if (!session_read_ignore_value (file))
+ return 0;
+ }
+}
+
+/*
+ * session_load_server: load server from file
+ */
+
+int
+session_load_server (FILE *file)
+{
+ int object_id, rc;
+ char *server_name;
+
+ /* read server name */
+ server_name = NULL;
+ if (!session_read_object (file, SESSION_SERV_NAME, SESSION_TYPE_STR, &server_name, 0))
+ {
+ session_crash (file, _("server name not found"));
+ return 0;
+ }
+
+ /* use or allocate server */
+ weechat_log_printf (_("session: loading server \"%s\"\n"),
+ server_name);
+ session_current_server = server_search (server_name);
+ if (session_current_server)
+ weechat_log_printf (_("server found, updating values\n"));
+ else
+ {
+ weechat_log_printf (_("server not found, creating new one\n"));
+ session_current_server = server_alloc ();
+ if (!session_current_server)
+ {
+ free (server_name);
+ session_crash (file, _("can't create new server"));
+ return 0;
+ }
+ server_init (session_current_server);
+ session_current_server->name = strdup (server_name);
+ }
+ free (server_name);
+
+ /* read server values */
+ rc = 1;
+ while (rc)
+ {
+ if (feof (file))
+ {
+ session_crash (file, _("unexpected end of file (reading server)"));
+ return 0;
+ }
+ if (fread ((void *)(&object_id), sizeof (int), 1, file) == 0)
+ return 0;
+ switch (object_id)
+ {
+ case SESSION_SERV_END:
+ return 1;
+ case SESSION_SERV_AUTOCONNECT:
+ rc = rc && (session_read_int (file, &(session_current_server->autoconnect)));
+ break;
+ case SESSION_SERV_AUTORECONNECT:
+ rc = rc && (session_read_int (file, &(session_current_server->autoreconnect)));
+ break;
+ case SESSION_SERV_AUTORECONNECT_DELAY:
+ rc = rc && (session_read_int (file, &(session_current_server->autoreconnect_delay)));
+ break;
+ case SESSION_SERV_COMMAND_LINE:
+ rc = rc && (session_read_int (file, &(session_current_server->command_line)));
+ break;
+ case SESSION_SERV_ADDRESS:
+ rc = rc && (session_read_str (file, &(session_current_server->address)));
+ break;
+ case SESSION_SERV_PORT:
+ rc = rc && (session_read_int (file, &(session_current_server->port)));
+ break;
+ case SESSION_SERV_IPV6:
+ rc = rc && (session_read_int (file, &(session_current_server->ipv6)));
+ break;
+ case SESSION_SERV_SSL:
+ rc = rc && (session_read_int (file, &(session_current_server->ssl)));
+ break;
+ case SESSION_SERV_PASSWORD:
+ rc = rc && (session_read_str (file, &(session_current_server->password)));
+ break;
+ case SESSION_SERV_NICK1:
+ rc = rc && (session_read_str (file, &(session_current_server->nick1)));
+ break;
+ case SESSION_SERV_NICK2:
+ rc = rc && (session_read_str (file, &(session_current_server->nick2)));
+ break;
+ case SESSION_SERV_NICK3:
+ rc = rc && (session_read_str (file, &(session_current_server->nick3)));
+ break;
+ case SESSION_SERV_USERNAME:
+ rc = rc && (session_read_str (file, &(session_current_server->username)));
+ break;
+ case SESSION_SERV_REALNAME:
+ rc = rc && (session_read_str (file, &(session_current_server->realname)));
+ break;
+ case SESSION_SERV_COMMAND:
+ rc = rc && (session_read_str (file, &(session_current_server->command)));
+ break;
+ case SESSION_SERV_COMMAND_DELAY:
+ rc = rc && (session_read_int (file, &(session_current_server->command_delay)));
+ break;
+ case SESSION_SERV_AUTOJOIN:
+ rc = rc && (session_read_str (file, &(session_current_server->autojoin)));
+ break;
+ case SESSION_SERV_AUTOREJOIN:
+ rc = rc && (session_read_int (file, &(session_current_server->autorejoin)));
+ break;
+ case SESSION_SERV_NOTIFY_LEVELS:
+ rc = rc && (session_read_str (file, &(session_current_server->notify_levels)));
+ break;
+ case SESSION_SERV_CHILD_PID:
+ rc = rc && (session_read_int (file, &(session_current_server->child_pid)));
+ break;
+ case SESSION_SERV_CHILD_READ:
+ rc = rc && (session_read_int (file, &(session_current_server->child_read)));
+ break;
+ case SESSION_SERV_CHILD_WRITE:
+ rc = rc && (session_read_int (file, &(session_current_server->child_write)));
+ break;
+ case SESSION_SERV_SOCK:
+ rc = rc && (session_read_int (file, &(session_current_server->sock)));
+ break;
+ case SESSION_SERV_IS_CONNECTED:
+ rc = rc && (session_read_int (file, &(session_current_server->is_connected)));
+ break;
+ case SESSION_SERV_SSL_CONNECTED:
+ rc = rc && (session_read_int (file, &(session_current_server->ssl_connected)));
+ break;
+#ifdef HAVE_GNUTLS
+ case SESSION_SERV_GNUTLS_SESS:
+ rc = rc && (session_read_buf (file, &(session_current_server->gnutls_sess), sizeof (gnutls_session)));
+ break;
+#endif
+ case SESSION_SERV_UNTERMINATED_MESSAGE:
+ rc = rc && (session_read_str (file, &(session_current_server->unterminated_message)));
+ break;
+ case SESSION_SERV_NICK:
+ rc = rc && (session_read_str (file, &(session_current_server->nick)));
+ break;
+ case SESSION_SERV_RECONNECT_START:
+ rc = rc && (session_read_buf (file, &(session_current_server->reconnect_start), sizeof (time_t)));
+ break;
+ case SESSION_SERV_RECONNECT_JOIN:
+ rc = rc && (session_read_int (file, &(session_current_server->reconnect_join)));
+ break;
+ case SESSION_SERV_IS_AWAY:
+ rc = rc && (session_read_int (file, &(session_current_server->is_away)));
+ break;
+ case SESSION_SERV_AWAY_TIME:
+ rc = rc && (session_read_buf (file, &(session_current_server->away_time), sizeof (time_t)));
+ break;
+ case SESSION_SERV_LAG:
+ rc = rc && (session_read_int (file, &(session_current_server->lag)));
+ break;
+ case SESSION_SERV_LAG_CHECK_TIME:
+ rc = rc && (session_read_buf (file, &(session_current_server->lag_check_time), sizeof (struct timeval)));
+ break;
+ case SESSION_SERV_LAG_NEXT_CHECK:
+ rc = rc && (session_read_buf (file, &(session_current_server->lag_next_check), sizeof (time_t)));
+ break;
+ default:
+ weechat_log_printf (_("session: warning: ignoring value from "
+ "server (object id: %d)\n"));
+ rc = rc && (session_read_ignore_value (file));
+ break;
+ }
+ }
+ return 0;
+}
+
+/*
+ * session_load_channel: load channel from file
+ */
+
+int
+session_load_channel (FILE *file)
+{
+ int object_id, rc, channel_type;
+ char *channel_name;
+
+ /* check if server is allocated for this channel */
+ if (!session_current_server)
+ {
+ session_crash (file, _("channel found without server"));
+ return 0;
+ }
+
+ /* read channel type */
+ if (!session_read_object (file, SESSION_CHAN_TYPE, SESSION_TYPE_INT, &channel_type, 0))
+ {
+ session_crash (file, _("channel type not found"));
+ return 0;
+ }
+
+ /* read channel name */
+ channel_name = NULL;
+ if (!session_read_object (file, SESSION_CHAN_NAME, SESSION_TYPE_STR, &channel_name, 0))
+ {
+ session_crash (file, _("channel name not found"));
+ return 0;
+ }
+
+ /* allocate channel */
+ weechat_log_printf (_("session: loading channel \"%s\"\n"),
+ channel_name);
+ session_current_channel = channel_new (session_current_server,
+ channel_type,
+ channel_name);
+ free (channel_name);
+ if (!session_current_channel)
+ {
+ session_crash (file, _("can't create new channel"));
+ return 0;
+ }
+
+ /* read channel values */
+ rc = 1;
+ while (rc)
+ {
+ if (feof (file))
+ {
+ session_crash (file, _("unexpected end of file (reading channel)"));
+ return 0;
+ }
+ if (fread ((void *)(&object_id), sizeof (int), 1, file) == 0)
+ return 0;
+ switch (object_id)
+ {
+ case SESSION_CHAN_END:
+ return 1;
+ case SESSION_CHAN_TOPIC:
+ rc = rc && (session_read_str (file, &(session_current_channel->topic)));
+ break;
+ case SESSION_CHAN_MODES:
+ rc = rc && (session_read_str (file, (char **)(&(session_current_channel->modes))));
+ break;
+ case SESSION_CHAN_LIMIT:
+ rc = rc && (session_read_int (file, &(session_current_channel->limit)));
+ break;
+ case SESSION_CHAN_KEY:
+ rc = rc && (session_read_str (file, &(session_current_channel->key)));
+ break;
+ case SESSION_CHAN_NICKS_COUNT:
+ rc = rc && (session_read_int (file, &(session_current_channel->nicks_count)));
+ break;
+ case SESSION_CHAN_CHECKING_AWAY:
+ rc = rc && (session_read_int (file, &(session_current_channel->checking_away)));
+ break;
+ default:
+ weechat_log_printf (_("session: warning: ignoring value from "
+ "channel (object id: %d)\n"));
+ rc = rc && (session_read_ignore_value (file));
+ break;
+ }
+ }
+ return 0;
+}
+
+/*
+ * session_load_nick: load nick from file
+ */
+
+int
+session_load_nick (FILE *file)
+{
+ int rc, object_id;
+ char *nick_name;
+ t_irc_nick *nick;
+
+ /* check if channel is allocated for this nick */
+ if (!session_current_channel)
+ {
+ session_crash (file, _("nick found without channel"));
+ return 0;
+ }
+
+ /* read nick name */
+ nick_name = NULL;
+ if (!session_read_object (file, SESSION_NICK_NICK, SESSION_TYPE_STR, &nick_name, 0))
+ {
+ session_crash (file, _("nick name not found"));
+ return 0;
+ }
+
+ /* allocate nick */
+ nick = nick_new (session_current_server, session_current_channel,
+ nick_name, 0, 0, 0, 0, 0);
+ free (nick_name);
+ if (!nick)
+ {
+ session_crash (file, _("can't create new nick"));
+ return 0;
+ }
+
+ /* read nick values */
+ rc = 1;
+ while (rc)
+ {
+ if (feof (file))
+ {
+ session_crash (file, _("unexpected end of file (reading nick)"));
+ return 0;
+ }
+ if (fread ((void *)(&object_id), sizeof (int), 1, file) == 0)
+ return 0;
+ switch (object_id)
+ {
+ case SESSION_NICK_END:
+ return 1;
+ case SESSION_NICK_FLAGS:
+ rc = rc && (session_read_int (file, &(nick->flags)));
+ break;
+ case SESSION_NICK_COLOR:
+ rc = rc && (session_read_int (file, &(nick->color)));
+ break;
+ default:
+ weechat_log_printf (_("session: warning: ignoring value from "
+ "nick (object id: %d)\n"));
+ rc = rc && (session_read_ignore_value (file));
+ break;
+ }
+ }
+ return 0;
+}
+
+/*
+ * session_load_dcc: load DCC from file
+ */
+
+int
+session_load_dcc (FILE *file)
+{
+ int object_id, rc;
+ t_irc_dcc *dcc;
+ char *string;
+ t_irc_server *ptr_server;
+ t_irc_channel *ptr_channel;
+
+ /* allocate DCC */
+ dcc = dcc_alloc ();
+ if (!dcc)
+ {
+ session_crash (file, _("can't create new DCC"));
+ return 0;
+ }
+
+ weechat_log_printf (_("session: loading DCC\n"));
+
+ /* read DCC values */
+ ptr_server = NULL;
+ ptr_channel = NULL;
+ rc = 1;
+ while (rc)
+ {
+ if (feof (file))
+ {
+ session_crash (file, _("unexpected end of file (reading DCC)"));
+ return 0;
+ }
+ if (fread ((void *)(&object_id), sizeof (int), 1, file) == 0)
+ return 0;
+ switch (object_id)
+ {
+ case SESSION_DCC_END:
+ return 1;
+ case SESSION_DCC_SERVER:
+ string = NULL;
+ rc = rc && (session_read_str (file, &string));
+ if (!rc)
+ return 0;
+ if (string && string[0])
+ {
+ ptr_server = server_search (string);
+ if (!ptr_server)
+ {
+ session_crash (file, _("server not found for DCC"));
+ return 0;
+ }
+ dcc->server = ptr_server;
+ }
+ break;
+ case SESSION_DCC_CHANNEL:
+ if (!ptr_server)
+ {
+ session_crash (file, _("DCC with channel but without server"));
+ return 0;
+ }
+ string = NULL;
+ rc = rc && (session_read_str (file, &string));
+ if (!rc)
+ return 0;
+ if (string && string[0])
+ {
+ ptr_channel = channel_search (ptr_server, string);
+ if (!ptr_channel)
+ {
+ session_crash (file, _("channel not found for DCC"));
+ return 0;
+ }
+ dcc->channel = ptr_channel;
+ ptr_channel->dcc_chat = dcc;
+ }
+ break;
+ case SESSION_DCC_TYPE:
+ rc = rc && (session_read_int (file, &(dcc->type)));
+ break;
+ case SESSION_DCC_STATUS:
+ rc = rc && (session_read_int (file, &(dcc->status)));
+ break;
+ case SESSION_DCC_START_TIME:
+ rc = rc && (session_read_buf (file, &(dcc->start_time), sizeof (time_t)));
+ break;
+ case SESSION_DCC_START_TRANSFER:
+ rc = rc && (session_read_buf (file, &(dcc->start_transfer), sizeof (time_t)));
+ break;
+ case SESSION_DCC_ADDR:
+ rc = rc && (session_read_buf (file, &(dcc->addr), sizeof (unsigned long)));
+ break;
+ case SESSION_DCC_PORT:
+ rc = rc && (session_read_int (file, &(dcc->port)));
+ break;
+ case SESSION_DCC_NICK:
+ rc = rc && (session_read_str (file, &(dcc->nick)));
+ break;
+ case SESSION_DCC_SOCK:
+ rc = rc && (session_read_int (file, &(dcc->sock)));
+ break;
+ case SESSION_DCC_UNTERMINATED_MESSAGE:
+ rc = rc && (session_read_str (file, &(dcc->unterminated_message)));
+ break;
+ case SESSION_DCC_FILE:
+ rc = rc && (session_read_int (file, &(dcc->file)));
+ break;
+ case SESSION_DCC_FILENAME:
+ rc = rc && (session_read_str (file, &(dcc->filename)));
+ break;
+ case SESSION_DCC_LOCAL_FILENAME:
+ rc = rc && (session_read_str (file, &(dcc->local_filename)));
+ break;
+ case SESSION_DCC_FILENAME_SUFFIX:
+ rc = rc && (session_read_int (file, &(dcc->filename_suffix)));
+ break;
+ case SESSION_DCC_SIZE:
+ rc = rc && (session_read_buf (file, &(dcc->size), sizeof (unsigned long)));
+ break;
+ case SESSION_DCC_POS:
+ rc = rc && (session_read_buf (file, &(dcc->pos), sizeof (unsigned long)));
+ break;
+ case SESSION_DCC_ACK:
+ rc = rc && (session_read_buf (file, &(dcc->ack), sizeof (unsigned long)));
+ break;
+ case SESSION_DCC_START_RESUME:
+ rc = rc && (session_read_buf (file, &(dcc->start_resume), sizeof (unsigned long)));
+ break;
+ case SESSION_DCC_LAST_CHECK_TIME:
+ rc = rc && (session_read_buf (file, &(dcc->last_check_time), sizeof (time_t)));
+ break;
+ case SESSION_DCC_LAST_CHECK_POS:
+ rc = rc && (session_read_buf (file, &(dcc->last_check_pos), sizeof (unsigned long)));
+ break;
+ case SESSION_DCC_LAST_ACTIVITY:
+ rc = rc && (session_read_buf (file, &(dcc->last_activity), sizeof (time_t)));
+ break;
+ case SESSION_DCC_BYTES_PER_SEC:
+ rc = rc && (session_read_buf (file, &(dcc->bytes_per_sec), sizeof (unsigned long)));
+ break;
+ case SESSION_DCC_ETA:
+ rc = rc && (session_read_buf (file, &(dcc->eta), sizeof (unsigned long)));
+ break;
+ default:
+ weechat_log_printf (_("session: warning: ignoring value from "
+ "DCC (object id: %d)\n"));
+ rc = rc && (session_read_ignore_value (file));
+ break;
+ }
+ }
+ return 0;
+}
+
+/*
+ * session_load_history: load history from file (global or for a buffer)
+ */
+
+int
+session_load_history (FILE *file)
+{
+ int object_id, rc;
+ char *text;
+
+ if (session_current_buffer)
+ weechat_log_printf (_("session: loading buffer history\n"));
+ else
+ weechat_log_printf (_("session: loading global history\n"));
+
+ /* read history values */
+ rc = 1;
+ while (rc)
+ {
+ if (feof (file))
+ {
+ session_crash (file, _("unexpected end of file (reading history)"));
+ return 0;
+ }
+ if (fread ((void *)(&object_id), sizeof (int), 1, file) == 0)
+ return 0;
+ switch (object_id)
+ {
+ case SESSION_HIST_END:
+ return 1;
+ case SESSION_HIST_TEXT:
+ text = NULL;
+ if (!session_read_str (file, &text))
+ return 0;
+ if (session_current_buffer)
+ history_buffer_add (session_current_buffer, text);
+ else
+ history_global_add (text);
+ free (text);
+ break;
+ default:
+ weechat_log_printf (_("session: warning: ignoring value from "
+ "history (object id: %d)\n"));
+ rc = rc && (session_read_ignore_value (file));
+ break;
+ }
+ }
+ return 0;
+}
+
+/*
+ * session_load_buffer: load buffer from file
+ */
+
+int
+session_load_buffer (FILE *file)
+{
+ int object_id, rc;
+ char *server_name, *channel_name;
+ int dcc;
+ t_irc_server *ptr_server;
+ t_irc_channel *ptr_channel;
+
+ /* read server name */
+ server_name = NULL;
+ if (!session_read_object (file, SESSION_BUFF_SERVER, SESSION_TYPE_STR, &server_name, 0))
+ {
+ session_crash (file, _("server name not found for buffer"));
+ return 0;
+ }
+
+ /* read channel name */
+ channel_name = NULL;
+ if (!session_read_object (file, SESSION_BUFF_CHANNEL, SESSION_TYPE_STR, &channel_name, 0))
+ {
+ session_crash (file, _("channel name not found for buffer"));
+ return 0;
+ }
+
+ /* read dcc */
+ if (!session_read_object (file, SESSION_BUFF_DCC, SESSION_TYPE_INT, &dcc, 0))
+ {
+ session_crash (file, _("dcc flag not found for buffer"));
+ return 0;
+ }
+
+ /* allocate buffer */
+ weechat_log_printf (_("session: loading buffer (server: %s, channel: %s, dcc: %d)\n"),
+ (server_name) ? server_name : "-",
+ (channel_name) ? channel_name : "-",
+ dcc);
+ ptr_server = NULL;
+ ptr_channel = NULL;
+ if (server_name)
+ {
+ ptr_server = server_search (server_name);
+ if (!ptr_server)
+ {
+ session_crash (file, _("server not found for buffer"));
+ return 0;
+ }
+ }
+
+ if (channel_name)
+ {
+ ptr_channel = channel_search (ptr_server, channel_name);
+ if (!ptr_channel)
+ {
+ session_crash (file, _("channel not found for buffer"));
+ return 0;
+ }
+ }
+
+ session_current_buffer = gui_buffer_new (gui_windows, ptr_server, ptr_channel, dcc, 1);
+ if (!session_current_buffer)
+ {
+ session_crash (file, _("can't create new buffer"));
+ return 0;
+ }
+
+ free (server_name);
+ free (channel_name);
+
+ /* read buffer values */
+ rc = 1;
+ while (rc)
+ {
+ if (feof (file))
+ {
+ session_crash (file, _("unexpected end of file (reading buffer)"));
+ return 0;
+ }
+ if (fread ((void *)(&object_id), sizeof (int), 1, file) == 0)
+ return 0;
+ switch (object_id)
+ {
+ case SESSION_BUFF_END:
+ return 1;
+ default:
+ weechat_log_printf (_("session: warning: ignoring value from "
+ "buffer (object id: %d)\n"));
+ rc = rc && (session_read_ignore_value (file));
+ break;
+ }
+ }
+ return 0;
+}
+
+/*
+ * session_load_line: load buffer line from file
+ */
+
+int
+session_load_line (FILE *file)
+{
+ int object_id, rc;
+ t_gui_line *line;
+
+ /* check if buffer is allocated for this line */
+ if (!session_current_buffer)
+ {
+ session_crash (file, _("line found without buffer"));
+ return 0;
+ }
+
+ /* allocate line */
+ line = gui_line_new (session_current_buffer);
+ if (!line)
+ {
+ session_crash (file, _("can't create new line"));
+ return 0;
+ }
+
+ /* read line values */
+ rc = 1;
+ while (rc)
+ {
+ if (feof (file))
+ {
+ session_crash (file, _("unexpected end of file (reading line)"));
+ return 0;
+ }
+ if (fread ((void *)(&object_id), sizeof (int), 1, file) == 0)
+ return 0;
+ switch (object_id)
+ {
+ case SESSION_LINE_END:
+ return 1;
+ case SESSION_LINE_LENGTH:
+ rc = rc && (session_read_int (file, &(line->length)));
+ break;
+ case SESSION_LINE_LENGTH_ALIGN:
+ rc = rc && (session_read_int (file, &(line->length_align)));
+ break;
+ case SESSION_LINE_LOG_WRITE:
+ rc = rc && (session_read_int (file, &(line->log_write)));
+ break;
+ case SESSION_LINE_WITH_MESSAGE:
+ rc = rc && (session_read_int (file, &(line->line_with_message)));
+ break;
+ case SESSION_LINE_WITH_HIGHLIGHT:
+ rc = rc && (session_read_int (file, &(line->line_with_highlight)));
+ break;
+ case SESSION_LINE_DATA:
+ rc = rc && (session_read_str (file, &(line->data)));
+ break;
+ case SESSION_LINE_OFS_AFTER_DATE:
+ rc = rc && (session_read_int (file, &(line->ofs_after_date)));
+ break;
+ default:
+ weechat_log_printf (_("session: warning: ignoring value from "
+ "line (object id: %d)\n"));
+ rc = rc && (session_read_ignore_value (file));
+ break;
+ }
+ }
+ return 0;
+}
+
+/*
+ * session_load: load session from file
+ */
+
+int
+session_load (char *filename)
+{
+ FILE *file;
+ char *signature;
+ int object_id;
+ t_irc_server *ptr_server;
+
+ session_current_server = NULL;
+ session_current_channel = NULL;
+ session_current_buffer = NULL;
+
+ session_last_read_pos = -1;
+ session_last_read_length = -1;
+
+ if ((file = fopen (filename, "rb")) == NULL)
+ {
+ session_crash (file, _("session file not found"));
+ return 0;
+ }
+
+ signature = NULL;
+ if (!session_read_str (file, &signature))
+ {
+ session_crash (file, _("signature not found"));
+ return 0;
+ }
+ if (!signature || (strcmp (signature, SESSION_SIGNATURE) != 0))
+ {
+ session_crash (file, _("bad session signature"));
+ return 0;
+ }
+ free (signature);
+
+ while (!feof (file))
+ {
+ if (fread ((void *)(&object_id), sizeof (int), 1, file) == 0)
+ {
+ if (feof (file))
+ break;
+ session_crash (file, _("object id not found"));
+ return 0;
+ }
+ switch (object_id)
+ {
+ case SESSION_OBJ_SERVER:
+ if (!session_load_server (file))
+ {
+ session_crash (file, _("failed to load server"));
+ return 0;
+ }
+ break;
+ case SESSION_OBJ_CHANNEL:
+ if (!session_load_channel (file))
+ {
+ session_crash (file, _("failed to load channel"));
+ return 0;
+ }
+ break;
+ case SESSION_OBJ_NICK:
+ if (!session_load_nick (file))
+ {
+ session_crash (file, _("failed to load nick"));
+ return 0;
+ }
+ break;
+ case SESSION_OBJ_DCC:
+ if (!session_load_dcc (file))
+ {
+ session_crash (file, _("failed to load DCC"));
+ return 0;
+ }
+ break;
+ case SESSION_OBJ_HISTORY:
+ if (!session_load_history (file))
+ {
+ session_crash (file, _("failed to load history"));
+ return 0;
+ }
+ break;
+ case SESSION_OBJ_BUFFER:
+ if (!session_load_buffer (file))
+ {
+ session_crash (file, _("failed to load buffer"));
+ return 0;
+ }
+ break;
+ case SESSION_OBJ_LINE:
+ if (!session_load_line (file))
+ {
+ session_crash (file, _("failed to load line"));
+ return 0;
+ }
+ break;
+ default:
+ weechat_log_printf (_("ignoring object (id: %d)\n"),
+ object_id);
+ if (!session_read_ignore_object (file))
+ {
+ session_crash (file, _("failed to ignore object (id: %d)"),
+ object_id);
+ return 0;
+ }
+ }
+ }
+
+ /* assign a buffer to all connected servers */
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ if ((ptr_server->is_connected) && (!ptr_server->buffer))
+ ptr_server->buffer = gui_buffers;
+ }
+
+ gui_switch_to_buffer (gui_windows, gui_buffers);
+ gui_redraw_buffer (gui_current_window->buffer);
+
+ fclose (file);
+
+ if (unlink (filename) < 0)
+ {
+ irc_display_prefix (NULL, gui_current_window->buffer, PREFIX_ERROR);
+ gui_printf_nolog (gui_current_window->buffer,
+ _("%s can't delete session file (%s)\n"),
+ WEECHAT_ERROR);
+ }
+
+ irc_display_prefix (NULL, gui_current_window->buffer, PREFIX_INFO);
+ gui_printf_nolog (gui_current_window->buffer,
+ _("Upgrade completed successfully\n"));
+
+ return 1;
+}
diff --git a/src/common/session.h b/src/common/session.h
new file mode 100644
index 000000000..666b7aca9
--- /dev/null
+++ b/src/common/session.h
@@ -0,0 +1,169 @@
+/*
+ * Copyright (c) 2003-2005 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * 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
+ */
+
+
+#ifndef __WEECHAT_SESSION_H
+#define __WEECHAT_SESSION_H 1
+
+#define WEECHAT_SESSION_NAME "weechat_session.bin"
+
+#define SESSION_SIGNATURE "== WeeChat Upgrade file v1.0 - binary, do not edit! =="
+
+/* For developers: please add new values ONLY AT THE END of enums */
+
+enum t_session_type
+{
+ SESSION_TYPE_INT = 0,
+ SESSION_TYPE_STR,
+ SESSION_TYPE_BUF
+};
+
+enum t_session_object
+{
+ SESSION_OBJ_END = 0,
+ SESSION_OBJ_SERVER,
+ SESSION_OBJ_CHANNEL,
+ SESSION_OBJ_NICK,
+ SESSION_OBJ_DCC,
+ SESSION_OBJ_HISTORY,
+ SESSION_OBJ_BUFFER,
+ SESSION_OBJ_LINE,
+};
+
+enum t_session_server
+{
+ SESSION_SERV_END = 0,
+ SESSION_SERV_NAME,
+ SESSION_SERV_AUTOCONNECT,
+ SESSION_SERV_AUTORECONNECT,
+ SESSION_SERV_AUTORECONNECT_DELAY,
+ SESSION_SERV_COMMAND_LINE,
+ SESSION_SERV_ADDRESS,
+ SESSION_SERV_PORT,
+ SESSION_SERV_IPV6,
+ SESSION_SERV_SSL,
+ SESSION_SERV_PASSWORD,
+ SESSION_SERV_NICK1,
+ SESSION_SERV_NICK2,
+ SESSION_SERV_NICK3,
+ SESSION_SERV_USERNAME,
+ SESSION_SERV_REALNAME,
+ SESSION_SERV_COMMAND,
+ SESSION_SERV_COMMAND_DELAY,
+ SESSION_SERV_AUTOJOIN,
+ SESSION_SERV_AUTOREJOIN,
+ SESSION_SERV_NOTIFY_LEVELS,
+ SESSION_SERV_CHILD_PID,
+ SESSION_SERV_CHILD_READ,
+ SESSION_SERV_CHILD_WRITE,
+ SESSION_SERV_SOCK,
+ SESSION_SERV_IS_CONNECTED,
+ SESSION_SERV_SSL_CONNECTED,
+ SESSION_SERV_GNUTLS_SESS,
+ SESSION_SERV_UNTERMINATED_MESSAGE,
+ SESSION_SERV_NICK,
+ SESSION_SERV_RECONNECT_START,
+ SESSION_SERV_RECONNECT_JOIN,
+ SESSION_SERV_IS_AWAY,
+ SESSION_SERV_AWAY_TIME,
+ SESSION_SERV_LAG,
+ SESSION_SERV_LAG_CHECK_TIME,
+ SESSION_SERV_LAG_NEXT_CHECK
+};
+
+enum t_session_channel
+{
+ SESSION_CHAN_END = 0,
+ SESSION_CHAN_TYPE,
+ SESSION_CHAN_NAME,
+ SESSION_CHAN_TOPIC,
+ SESSION_CHAN_MODES,
+ SESSION_CHAN_LIMIT,
+ SESSION_CHAN_KEY,
+ SESSION_CHAN_NICKS_COUNT,
+ SESSION_CHAN_CHECKING_AWAY
+};
+
+enum t_session_nick
+{
+ SESSION_NICK_END = 0,
+ SESSION_NICK_NICK,
+ SESSION_NICK_FLAGS,
+ SESSION_NICK_COLOR
+};
+
+enum t_session_dcc
+{
+ SESSION_DCC_END = 0,
+ SESSION_DCC_SERVER,
+ SESSION_DCC_CHANNEL,
+ SESSION_DCC_TYPE,
+ SESSION_DCC_STATUS,
+ SESSION_DCC_START_TIME,
+ SESSION_DCC_START_TRANSFER,
+ SESSION_DCC_ADDR,
+ SESSION_DCC_PORT,
+ SESSION_DCC_NICK,
+ SESSION_DCC_SOCK,
+ SESSION_DCC_UNTERMINATED_MESSAGE,
+ SESSION_DCC_FILE,
+ SESSION_DCC_FILENAME,
+ SESSION_DCC_LOCAL_FILENAME,
+ SESSION_DCC_FILENAME_SUFFIX,
+ SESSION_DCC_SIZE,
+ SESSION_DCC_POS,
+ SESSION_DCC_ACK,
+ SESSION_DCC_START_RESUME,
+ SESSION_DCC_LAST_CHECK_TIME,
+ SESSION_DCC_LAST_CHECK_POS,
+ SESSION_DCC_LAST_ACTIVITY,
+ SESSION_DCC_BYTES_PER_SEC,
+ SESSION_DCC_ETA
+};
+
+enum t_session_history
+{
+ SESSION_HIST_END = 0,
+ SESSION_HIST_TEXT
+};
+
+enum t_session_buffer
+{
+ SESSION_BUFF_END = 0,
+ SESSION_BUFF_SERVER,
+ SESSION_BUFF_CHANNEL,
+ SESSION_BUFF_DCC
+};
+
+enum t_session_line
+{
+ SESSION_LINE_END = 0,
+ SESSION_LINE_LENGTH,
+ SESSION_LINE_LENGTH_ALIGN,
+ SESSION_LINE_LOG_WRITE,
+ SESSION_LINE_WITH_MESSAGE,
+ SESSION_LINE_WITH_HIGHLIGHT,
+ SESSION_LINE_DATA,
+ SESSION_LINE_OFS_AFTER_DATE
+};
+
+int session_save (char *filename);
+int session_load (char *filename);
+
+#endif /* session.h */
diff --git a/src/common/weechat.c b/src/common/weechat.c
index 3bf9d4a75..e076b4da3 100644
--- a/src/common/weechat.c
+++ b/src/common/weechat.c
@@ -65,6 +65,7 @@
#include "command.h"
#include "fifo.h"
#include "utf8.h"
+#include "session.h"
#include "../irc/irc.h"
#include "../gui/gui.h"
@@ -73,6 +74,8 @@
#endif
+char *weechat_argv0 = NULL; /* WeeChat binary file name (argv[0]) */
+char *weechat_session = NULL; /* WeeChat session file (for /upgrade command) */
time_t weechat_start_time; /* WeeChat start time (used by /uptime command) */
int quit_weechat; /* = 1 if quit request from user... why ? :'( */
int sigsegv = 0; /* SIGSEGV received? */
@@ -163,11 +166,11 @@ ascii_strncasecmp (char *string1, char *string2, int max)
}
/*
- * wee_log_printf: displays a message in WeeChat log (~/.weechat/weechat.log)
+ * weechat_log_printf: displays a message in WeeChat log (~/.weechat/weechat.log)
*/
void
-wee_log_printf (char *message, ...)
+weechat_log_printf (char *message, ...)
{
static char buffer[4096];
char *ptr_buffer;
@@ -214,7 +217,7 @@ weechat_convert_encoding (char *from_code, char *to_code, char *string)
{
char *outbuf;
- #ifdef HAVE_ICONV
+#ifdef HAVE_ICONV
iconv_t cd;
char *inbuf;
ICONV_CONST char *ptr_inbuf;
@@ -249,12 +252,12 @@ weechat_convert_encoding (char *from_code, char *to_code, char *string)
}
else
outbuf = strdup (string);
- #else
+#else
/* make gcc happy */
(void) from_code;
(void) to_code;
outbuf = strdup (string);
- #endif /* HAVE_ICONV */
+#endif /* HAVE_ICONV */
return outbuf;
}
@@ -263,7 +266,8 @@ weechat_convert_encoding (char *from_code, char *to_code, char *string)
* get_timeval_diff: calculates difference between two times (return in milliseconds)
*/
-long get_timeval_diff(struct timeval *tv1, struct timeval *tv2)
+long
+get_timeval_diff (struct timeval *tv1, struct timeval *tv2)
{
long diff_sec, diff_usec;
@@ -279,10 +283,40 @@ long get_timeval_diff(struct timeval *tv1, struct timeval *tv2)
}
/*
- * wee_display_config_options: display config options
+ * weechat_display_usage: display WeeChat usage
+ */
+
+void
+weechat_display_usage (char *exec_name)
+{
+ printf ("\n");
+ printf (_("%s (c) Copyright 2003-2005, compiled on %s %s\n"
+ "Developed by FlashCode <flashcode@flashtux.org> - %s"),
+ PACKAGE_STRING, __DATE__, __TIME__, WEECHAT_WEBSITE);
+ printf ("\n\n");
+ printf (_("Usage: %s [options ...]\n" \
+ " or: %s [irc[6][s]://[nickname[:password]@]irc.example.org[:port][/channel][,channel[...]]"),
+ exec_name, exec_name);
+ printf ("\n\n");
+ printf (_(" -a, --no-connect disable auto-connect to servers at startup\n"
+ " -c, --config display config file options\n"
+ " -f, --key-functions display WeeChat internal functions for keys\n"
+ " -h, --help this help\n"
+ " -i, --irc-commands display IRC commands\n"
+ " -k, --keys display WeeChat default keys\n"
+ " -l, --license display WeeChat license\n"
+ " -p, --no-plugin don't load any plugin at startup\n"
+ " -v, --version display WeeChat version\n"
+ " -w, --weechat-commands display WeeChat commands\n"));
+ printf("\n");
+}
+
+/*
+ * weechat_display_config_options: display config options
*/
-void wee_display_config_options ()
+void
+weechat_display_config_options ()
{
int i, j, k;
@@ -353,10 +387,11 @@ void wee_display_config_options ()
}
/*
- * wee_display_commands: display WeeChat and/or IRC commands
+ * weechat_display_commands: display WeeChat and/or IRC commands
*/
-void wee_display_commands (int weechat_cmd, int irc_cmd)
+void
+weechat_display_commands (int weechat_cmd, int irc_cmd)
{
int i;
@@ -406,10 +441,11 @@ void wee_display_commands (int weechat_cmd, int irc_cmd)
}
/*
- * wee_display_key_functions: display WeeChat key functions
+ * weechat_display_key_functions: display WeeChat key functions
*/
-void wee_display_key_functions ()
+void
+weechat_display_key_functions ()
{
int i;
@@ -426,11 +462,11 @@ void wee_display_key_functions ()
}
/*
- * wee_display_keys: display WeeChat default keys
+ * weechat_display_keys: display WeeChat default keys
*/
void
-wee_display_keys ()
+weechat_display_keys ()
{
t_gui_key *ptr_key;
char *expanded_name;
@@ -449,15 +485,17 @@ wee_display_keys ()
}
/*
- * wee_parse_args: parse command line args
+ * weechat_parse_args: parse command line args
*/
void
-wee_parse_args (int argc, char *argv[])
+weechat_parse_args (int argc, char *argv[])
{
int i;
t_irc_server server_tmp;
+ weechat_argv0 = strdup (argv[0]);
+ weechat_session = NULL;
server_cmd_line = 0;
auto_connect = 1;
auto_load_plugins = 1;
@@ -470,54 +508,65 @@ wee_parse_args (int argc, char *argv[])
else if ((strcmp (argv[i], "-c") == 0)
|| (strcmp (argv[i], "--config") == 0))
{
- wee_display_config_options ();
- wee_shutdown (EXIT_SUCCESS, 0);
+ weechat_display_config_options ();
+ weechat_shutdown (EXIT_SUCCESS, 0);
}
else if ((strcmp (argv[i], "-f") == 0)
|| (strcmp (argv[i], "--key-functions") == 0))
{
- wee_display_key_functions ();
- wee_shutdown (EXIT_SUCCESS, 0);
+ weechat_display_key_functions ();
+ weechat_shutdown (EXIT_SUCCESS, 0);
}
else if ((strcmp (argv[i], "-h") == 0)
|| (strcmp (argv[i], "--help") == 0))
{
- printf ("\n" WEE_USAGE1, argv[0], argv[0]);
- printf ("%s", WEE_USAGE2);
- wee_shutdown (EXIT_SUCCESS, 0);
+ weechat_display_usage (argv[0]);
+ weechat_shutdown (EXIT_SUCCESS, 0);
}
else if ((strcmp (argv[i], "-i") == 0)
|| (strcmp (argv[i], "--irc-commands") == 0))
{
- wee_display_commands (0, 1);
- wee_shutdown (EXIT_SUCCESS, 0);
+ weechat_display_commands (0, 1);
+ weechat_shutdown (EXIT_SUCCESS, 0);
}
else if ((strcmp (argv[i], "-k") == 0)
|| (strcmp (argv[i], "--keys") == 0))
{
- wee_display_keys ();
- wee_shutdown (EXIT_SUCCESS, 0);
+ weechat_display_keys ();
+ weechat_shutdown (EXIT_SUCCESS, 0);
}
else if ((strcmp (argv[i], "-l") == 0)
|| (strcmp (argv[i], "--license") == 0))
{
printf ("\n%s%s", WEE_LICENSE);
- wee_shutdown (EXIT_SUCCESS, 0);
+ weechat_shutdown (EXIT_SUCCESS, 0);
}
else if ((strcmp (argv[i], "-p") == 0)
|| (strcmp (argv[i], "--no-plugin") == 0))
auto_load_plugins = 0;
+ else if (strcmp (argv[i], "--session") == 0)
+ {
+ if (i + 1 < argc)
+ weechat_session = strdup (argv[++i]);
+ else
+ {
+ fprintf (stderr,
+ _("%s missing argument for --session option\n"),
+ WEECHAT_ERROR);
+ weechat_shutdown (EXIT_FAILURE, 0);
+ }
+ }
else if ((strcmp (argv[i], "-v") == 0)
|| (strcmp (argv[i], "--version") == 0))
{
printf (PACKAGE_VERSION "\n");
- wee_shutdown (EXIT_SUCCESS, 0);
+ weechat_shutdown (EXIT_SUCCESS, 0);
}
else if ((strcmp (argv[i], "-w") == 0)
|| (strcmp (argv[i], "--weechat-commands") == 0))
{
- wee_display_commands (1, 0);
- wee_shutdown (EXIT_SUCCESS, 0);
+ weechat_display_commands (1, 0);
+ weechat_shutdown (EXIT_SUCCESS, 0);
}
else if ((ascii_strncasecmp (argv[i], "irc", 3) == 0))
{
@@ -552,13 +601,13 @@ wee_parse_args (int argc, char *argv[])
}
/*
- * wee_create_dir: create a directory
- * return: 1 if ok (or directory already exists)
- * 0 if error
+ * weechat_create_dir: create a directory
+ * return: 1 if ok (or directory already exists)
+ * 0 if error
*/
int
-wee_create_dir (char *directory)
+weechat_create_dir (char *directory)
{
if (mkdir (directory, 0755) < 0)
{
@@ -574,26 +623,21 @@ wee_create_dir (char *directory)
}
/*
- * wee_create_home_dirs: create (if not found):
- * - WeeChat home directory ("~/.weechat")
- * - "perl" directory (and "autoload")
- * - "ruby" directory (and "autoload")
- * - "python" directory (and "autoload")
+ * weechat_create_home_dirs: create WeeChat directories (if not found)
*/
void
-wee_create_home_dirs ()
+weechat_create_home_dirs ()
{
char *ptr_home, *dir_name;
int dir_length;
-
- /* TODO: rewrite this code for Windows version */
+
ptr_home = getenv ("HOME");
if (!ptr_home)
{
fprintf (stderr, _("%s unable to get HOME directory\n"),
WEECHAT_ERROR);
- wee_shutdown (EXIT_FAILURE, 0);
+ weechat_shutdown (EXIT_FAILURE, 0);
}
dir_length = strlen (ptr_home) + 10;
weechat_home =
@@ -602,17 +646,17 @@ wee_create_home_dirs ()
{
fprintf (stderr, _("%s not enough memory for home directory\n"),
WEECHAT_ERROR);
- wee_shutdown (EXIT_FAILURE, 0);
+ weechat_shutdown (EXIT_FAILURE, 0);
}
snprintf (weechat_home, dir_length, "%s%s.weechat", ptr_home,
DIR_SEPARATOR);
/* create home directory "~/.weechat" ; error is fatal */
- if (!wee_create_dir (weechat_home))
+ if (!weechat_create_dir (weechat_home))
{
fprintf (stderr, _("%s unable to create ~/.weechat directory\n"),
WEECHAT_ERROR);
- wee_shutdown (EXIT_FAILURE, 0);
+ weechat_shutdown (EXIT_FAILURE, 0);
}
dir_length = strlen (weechat_home) + 64;
@@ -621,7 +665,7 @@ wee_create_home_dirs ()
/* create "~/.weechat/logs" */
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
"logs");
- if (!wee_create_dir (dir_name))
+ if (!weechat_create_dir (dir_name))
{
fprintf (stderr, _("%s unable to create ~/.weechat/logs directory\n"),
WEECHAT_WARNING);
@@ -632,11 +676,11 @@ wee_create_home_dirs ()
}
/*
- * wee_init_vars: initialize some variables
+ * weechat_init_vars: initialize some variables
*/
void
-wee_init_vars ()
+weechat_init_vars ()
{
/* start time, used by /uptime command */
weechat_start_time = time (NULL);
@@ -654,11 +698,11 @@ wee_init_vars ()
}
/*
- * wee_init_log: initialize log file
+ * weechat_init_log: initialize log file
*/
void
-wee_init_log ()
+weechat_init_log ()
{
int filename_length;
char *filename;
@@ -675,6 +719,29 @@ wee_init_log ()
}
/*
+ * weechat_config_read: read WeeChat config file
+ */
+
+void
+weechat_config_read ()
+{
+ switch (config_read ())
+ {
+ case 0: /* read ok */
+ break;
+ case -1: /* config file not found */
+ if (config_create_default () < 0)
+ exit (EXIT_FAILURE);
+ if (config_read () != 0)
+ exit (EXIT_FAILURE);
+ break;
+ default: /* other error (fatal) */
+ server_free_all ();
+ exit (EXIT_FAILURE);
+ }
+}
+
+/*
* weechat_welcome_message: display WeeChat welcome message - yeah!
*/
@@ -720,29 +787,19 @@ weechat_welcome_message ()
"%s-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n",
GUI_COLOR(COLOR_WIN_CHAT_NICK));
- wee_log_printf ("%s (%s %s %s)\n",
- PACKAGE_STRING, _("compiled on"), __DATE__, __TIME__);
-}
-
-/*
- * wee_gui_shutdown: shutdown WeeChat GUI
- */
-
-void
-wee_gui_shutdown ()
-{
- dcc_end ();
- server_free_all ();
- gui_end ();
+ weechat_log_printf ("%s (%s %s %s)\n",
+ PACKAGE_STRING, _("compiled on"), __DATE__, __TIME__);
}
/*
- * wee_shutdown: shutdown WeeChat
+ * weechat_shutdown: shutdown WeeChat
*/
void
-wee_shutdown (int return_code, int crash)
+weechat_shutdown (int return_code, int crash)
{
+ if (weechat_argv0)
+ free (weechat_argv0);
fifo_remove ();
if (weechat_home)
free (weechat_home);
@@ -764,15 +821,16 @@ wee_shutdown (int return_code, int crash)
}
/*
- * wee_dump writes dump to WeeChat log file
+ * weechat_dump writes dump to WeeChat log file
*/
void
-wee_dump (int crash)
+weechat_dump (int crash)
{
t_irc_server *ptr_server;
t_irc_channel *ptr_channel;
t_irc_nick *ptr_nick;
+ t_irc_dcc *ptr_dcc;
t_gui_window *ptr_window;
t_gui_buffer *ptr_buffer;
@@ -783,92 +841,100 @@ wee_dump (int crash)
if (crash)
{
sigsegv = 1;
- wee_log_printf ("Very bad, WeeChat is crashing (SIGSEGV received)...\n");
+ weechat_log_printf ("Very bad, WeeChat is crashing (SIGSEGV received)...\n");
}
- wee_log_printf ("\n");
+ weechat_log_printf ("\n");
if (crash)
{
- wee_log_printf ("****** WeeChat CRASH DUMP ******\n");
- wee_log_printf ("****** Please send this file to WeeChat developers ******\n");
- wee_log_printf ("****** and explain when this crash happened ******\n");
+ weechat_log_printf ("****** WeeChat CRASH DUMP ******\n");
+ weechat_log_printf ("****** Please send this file to WeeChat developers ******\n");
+ weechat_log_printf ("****** and explain when this crash happened ******\n");
}
else
{
- wee_log_printf ("****** WeeChat dump request ******\n");
+ weechat_log_printf ("****** WeeChat dump request ******\n");
}
for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server)
{
- wee_log_printf ("\n");
+ weechat_log_printf ("\n");
server_print_log (ptr_server);
for (ptr_channel = ptr_server->channels; ptr_channel;
ptr_channel = ptr_channel->next_channel)
{
- wee_log_printf ("\n");
+ weechat_log_printf ("\n");
channel_print_log (ptr_channel);
for (ptr_nick = ptr_channel->nicks; ptr_nick;
ptr_nick = ptr_nick->next_nick)
{
- wee_log_printf ("\n");
+ weechat_log_printf ("\n");
nick_print_log (ptr_nick);
}
}
}
- wee_log_printf ("\n");
- wee_log_printf ("[windows/buffers]\n");
- wee_log_printf (" => windows:\n");
+ weechat_log_printf ("\n");
+ for (ptr_dcc = dcc_list; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
+ {
+ dcc_print_log (ptr_dcc);
+ }
+
+ weechat_log_printf ("\n");
+ weechat_log_printf ("[windows/buffers]\n");
+ weechat_log_printf (" => windows:\n");
for (ptr_window = gui_windows; ptr_window; ptr_window = ptr_window->next_window)
{
- wee_log_printf (" 0x%X\n", ptr_window);
+ weechat_log_printf (" 0x%X\n", ptr_window);
}
- wee_log_printf (" => buffers:\n");
+ weechat_log_printf (" => buffers:\n");
for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer)
{
- wee_log_printf (" 0x%X\n", ptr_buffer);
+ weechat_log_printf (" 0x%X\n", ptr_buffer);
}
- wee_log_printf (" => current window = 0x%X\n", gui_current_window);
+ weechat_log_printf (" => current window = 0x%X\n", gui_current_window);
for (ptr_window = gui_windows; ptr_window; ptr_window = ptr_window->next_window)
{
- wee_log_printf ("\n");
+ weechat_log_printf ("\n");
gui_window_print_log (ptr_window);
}
for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer)
{
- wee_log_printf ("\n");
+ weechat_log_printf ("\n");
gui_buffer_print_log (ptr_buffer);
}
- wee_log_printf ("\n");
+ weechat_log_printf ("\n");
ignore_print_log ();
- wee_log_printf ("\n");
- wee_log_printf ("****** End of dump ******\n");
- wee_log_printf ("\n");
+ weechat_log_printf ("\n");
+ weechat_log_printf ("****** End of dump ******\n");
+ weechat_log_printf ("\n");
}
/*
- * my_sigsegv: SIGSEGV handler: save crash log to ~/.weechat/weechat.log and exit
+ * weechat_sigsegv: SIGSEGV handler: save crash log to ~/.weechat/weechat.log and exit
*/
void
-my_sigsegv ()
+weechat_sigsegv ()
{
- wee_dump (1);
- wee_gui_shutdown ();
+ weechat_dump (1);
+ dcc_end ();
+ server_free_all ();
+ gui_end ();
fprintf (stderr, "\n");
fprintf (stderr, "*** Very bad! WeeChat has crashed (SIGSEGV received)\n");
fprintf (stderr, "*** Full crash dump was saved to ~/.weechat/weechat.log file\n");
fprintf (stderr, "*** Please send this file to WeeChat developers.\n");
fprintf (stderr, "*** (be careful, private info may be in this file since\n");
fprintf (stderr, "*** part of chats are displayed, so remove lines if needed)\n\n");
- wee_shutdown (EXIT_FAILURE, 1);
+ weechat_shutdown (EXIT_FAILURE, 1);
}
/*
@@ -878,63 +944,54 @@ my_sigsegv ()
int
main (int argc, char *argv[])
{
- #ifdef ENABLE_NLS
- setlocale (LC_ALL, ""); /* initialize gettext */
+#ifdef ENABLE_NLS
+ setlocale (LC_ALL, ""); /* initialize gettext */
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
- #endif
+#endif
- #ifdef HAVE_LANGINFO_CODESET
+#ifdef HAVE_LANGINFO_CODESET
local_charset = strdup (nl_langinfo (CODESET));
- #endif
-
- signal (SIGINT, SIG_IGN); /* ignore SIGINT signal */
- signal (SIGQUIT, SIG_IGN); /* ignore SIGQUIT signal */
- signal (SIGPIPE, SIG_IGN); /* ignore SIGPIPE signal */
- signal (SIGSEGV, my_sigsegv); /* crash dump when SIGSEGV is received */
- gui_pre_init (&argc, &argv); /* pre-initiliaze interface */
- wee_init_vars (); /* initialize some variables */
- gui_key_init (); /* init keyboard (default key bindings) */
- wee_parse_args (argc, argv); /* parse command line args */
- wee_create_home_dirs (); /* create WeeChat directories */
- wee_init_log (); /* init log file */
- command_index_build (); /* build commands index for completion */
-
- switch (config_read ()) /* read configuration */
- {
- case 0: /* config file OK */
- break;
- case -1: /* config file not found */
- if (config_create_default () < 0)
- return EXIT_FAILURE;
- if (config_read () != 0)
- return EXIT_FAILURE;
- break;
- default: /* other error (fatal) */
- server_free_all ();
- return EXIT_FAILURE;
- }
+#endif
- utf8_init (); /* init UTF-8 in WeeChat */
- gui_init (); /* init WeeChat interface */
- weechat_welcome_message (); /* display WeeChat welcome message */
+ signal (SIGINT, SIG_IGN); /* ignore SIGINT signal */
+ signal (SIGQUIT, SIG_IGN); /* ignore SIGQUIT signal */
+ signal (SIGPIPE, SIG_IGN); /* ignore SIGPIPE signal */
+ signal (SIGSEGV, weechat_sigsegv); /* crash dump when SIGSEGV received */
+ gui_pre_init (&argc, &argv); /* pre-initiliaze interface */
+ weechat_init_vars (); /* initialize some variables */
+ gui_key_init (); /* init keyb. (default key bindings)*/
+ weechat_parse_args (argc, argv); /* parse command line args */
+ weechat_create_home_dirs (); /* create WeeChat directories */
+ weechat_init_log (); /* init log file */
+ command_index_build (); /* build cmd index for completion */
+ weechat_config_read (); /* read configuration */
+ utf8_init (); /* init UTF-8 in WeeChat */
+ gui_init (); /* init WeeChat interface */
+ weechat_welcome_message (); /* display WeeChat welcome message */
#ifdef PLUGINS
- plugin_init (auto_load_plugins);/* init plugin interface(s) */
+ plugin_init (auto_load_plugins); /* init plugin interface(s) */
#endif
- /* auto-connect to servers */
- server_auto_connect (auto_connect, server_cmd_line);
- fifo_create (); /* create FIFO pipe for remote control */
- gui_main_loop (); /* WeeChat main loop */
+ server_auto_connect (auto_connect, /* auto-connect to servers */
+ server_cmd_line);
+ fifo_create (); /* FIFO pipe for remote control */
+
+ if (weechat_session)
+ session_load (weechat_session); /* load previous session if asked */
+
+ gui_main_loop (); /* WeeChat main loop */
#ifdef PLUGINS
- plugin_end (); /* end plugin interface(s) */
+ plugin_end (); /* end plugin interface(s) */
#endif
- server_disconnect_all (); /* disconnect from all servers */
- (void) config_write (NULL); /* save config file */
- command_index_free (); /* free commands index */
- wee_gui_shutdown (); /* shut down WeeChat GUI */
- wee_shutdown (EXIT_SUCCESS, 0); /* quit WeeChat (oh no, why?) */
-
- return EXIT_SUCCESS; /* make gcc happy (never executed) */
+ server_disconnect_all (); /* disconnect from all servers */
+ (void) config_write (NULL); /* save config file */
+ command_index_free (); /* free commands index */
+ dcc_end (); /* remove all DCC */
+ server_free_all (); /* free all servers */
+ gui_end (); /* shut down WeeChat GUI */
+ weechat_shutdown (EXIT_SUCCESS, 0); /* quit WeeChat (oh no, why?) */
+
+ return EXIT_SUCCESS; /* make gcc happy (never executed) */
}
diff --git a/src/common/weechat.h b/src/common/weechat.h
index 7b3ea307f..e5847fcd5 100644
--- a/src/common/weechat.h
+++ b/src/common/weechat.h
@@ -82,24 +82,6 @@
"along with this program; if not, write to the Free Software\n" \
"Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n\n"
-#define WEE_USAGE1 \
- PACKAGE_STRING " (c) Copyright 2003-2005, compiled on " __DATE__ " " __TIME__ \
- "\nDeveloped by FlashCode <flashcode@flashtux.org> - " WEECHAT_WEBSITE "\n\n" \
- "Usage: %s [options ...]\n" \
- " or: %s [irc[6][s]://[nickname[:password]@]irc.example.org[:port][/channel][,channel[...]]\n\n"
-
-#define WEE_USAGE2 \
- " -a, --no-connect disable auto-connect to servers at startup\n" \
- " -c, --config display config file options\n" \
- " -f, --key-functions display WeeChat internal functions for keys\n" \
- " -h, --help this help\n" \
- " -i, --irc-commands display IRC commands\n" \
- " -k, --keys display WeeChat default keys\n" \
- " -l, --license display WeeChat license\n" \
- " -p, --no-plugin don't load any plugin at startup\n" \
- " -v, --version display WeeChat version\n" \
- " -w, --weechat-commands display WeeChat commands\n\n"
-
/* directory separator, depending on OS */
#ifdef _WIN32
@@ -112,6 +94,7 @@
/* global variables and functions */
+extern char *weechat_argv0;
extern time_t weechat_start_time;
extern int quit_weechat;
extern char *weechat_home;
@@ -123,10 +106,10 @@ extern gnutls_certificate_credentials gnutls_xcred;
extern int ascii_strcasecmp (char *, char *);
extern int ascii_strncasecmp (char *, char *, int);
-extern void wee_log_printf (char *, ...);
-extern void wee_dump (int);
+extern void weechat_log_printf (char *, ...);
+extern void weechat_dump (int);
extern char *weechat_convert_encoding (char *, char *, char *);
extern long get_timeval_diff (struct timeval *, struct timeval *);
-extern void wee_shutdown (int, int);
+extern void weechat_shutdown (int, int);
#endif /* weechat.h */
diff --git a/src/common/weeconfig.c b/src/common/weeconfig.c
index 380957f1a..bc86c20c5 100644
--- a/src/common/weeconfig.c
+++ b/src/common/weeconfig.c
@@ -1612,10 +1612,8 @@ config_read ()
int server_found;
char line[1024], *ptr_line, *pos, *pos2;
- filename_length = strlen (weechat_home) +
- strlen (WEECHAT_CONFIG_NAME) + 2;
- filename =
- (char *) malloc (filename_length * sizeof (char));
+ filename_length = strlen (weechat_home) + strlen (WEECHAT_CONFIG_NAME) + 2;
+ filename = (char *) malloc (filename_length * sizeof (char));
if (!filename)
return -2;
snprintf (filename, filename_length, "%s%s" WEECHAT_CONFIG_NAME,
@@ -1914,7 +1912,7 @@ config_create_default ()
}
printf (_("%s: creating default config file...\n"), PACKAGE_NAME);
- wee_log_printf (_("Creating default config file\n"));
+ weechat_log_printf (_("Creating default config file\n"));
current_time = time (NULL);
fprintf (file, _("#\n# %s configuration file, created by "
@@ -2115,7 +2113,7 @@ config_write (char *config_name)
return -1;
}
- wee_log_printf (_("Saving config to disk\n"));
+ weechat_log_printf (_("Saving config to disk\n"));
current_time = time (NULL);
fprintf (file, _("#\n# %s configuration file, created by "
diff --git a/src/gui/curses/gui-display.c b/src/gui/curses/gui-display.c
index 4f8ece500..651d6a3e1 100644
--- a/src/gui/curses/gui-display.c
+++ b/src/gui/curses/gui-display.c
@@ -1594,7 +1594,16 @@ gui_draw_buffer_chat (t_gui_buffer *buffer, int erase)
num_unit = 2;
else
num_unit = 3;
- sprintf (format, " (%s %%s/s)", unit_format[num_unit]);
+ wprintw (ptr_win->win_chat, " (");
+ if (ptr_dcc->status == DCC_ACTIVE)
+ {
+ wprintw (ptr_win->win_chat, _("ETA"));
+ wprintw (ptr_win->win_chat, ": %.2lu:%.2lu:%.2lu - ",
+ ptr_dcc->eta / 3600,
+ (ptr_dcc->eta / 60) % 60,
+ ptr_dcc->eta % 60);
+ }
+ sprintf (format, "%s %%s/s)", unit_format[num_unit]);
buf = weechat_convert_encoding ((local_utf8) ?
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
@@ -1824,31 +1833,31 @@ gui_draw_buffer_nick (t_gui_buffer *buffer, int erase)
}
else
{
- if (ptr_nick->is_chanowner)
+ if (ptr_nick->flags & NICK_CHANOWNER)
{
gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK_CHANOWNER);
mvwprintw (ptr_win->win_nick, y, x, "~");
x++;
}
- else if (ptr_nick->is_chanadmin)
+ else if (ptr_nick->flags & NICK_CHANADMIN)
{
gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK_CHANADMIN);
mvwprintw (ptr_win->win_nick, y, x, "&");
x++;
}
- else if (ptr_nick->is_op)
+ else if (ptr_nick->flags & NICK_OP)
{
gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK_OP);
mvwprintw (ptr_win->win_nick, y, x, "@");
x++;
}
- else if (ptr_nick->is_halfop)
+ else if (ptr_nick->flags & NICK_HALFOP)
{
gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK_HALFOP);
mvwprintw (ptr_win->win_nick, y, x, "%%");
x++;
}
- else if (ptr_nick->has_voice)
+ else if (ptr_nick->flags & NICK_VOICE)
{
gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK_VOICE);
mvwprintw (ptr_win->win_nick, y, x, "+");
@@ -1861,7 +1870,7 @@ gui_draw_buffer_nick (t_gui_buffer *buffer, int erase)
x++;
}
gui_window_set_weechat_color (ptr_win->win_nick,
- ((cfg_irc_away_check > 0) && (ptr_nick->is_away)) ?
+ ((cfg_irc_away_check > 0) && (ptr_nick->flags & NICK_AWAY)) ?
COLOR_WIN_NICK_AWAY : COLOR_WIN_NICK);
mvwprintw (ptr_win->win_nick, y, x, format, ptr_nick->nick);
@@ -2004,7 +2013,7 @@ gui_draw_buffer_status (t_gui_buffer *buffer, int erase)
gui_window_set_weechat_color (ptr_win->win_status,
COLOR_WIN_STATUS_CHANNEL);
if ((!CHANNEL(ptr_win->buffer)->nicks)
- && (CHANNEL(ptr_win->buffer)->type != CHAT_PRIVATE))
+ && (CHANNEL(ptr_win->buffer)->type != CHANNEL_TYPE_PRIVATE))
wprintw (ptr_win->win_status, "(%s)",
CHANNEL(ptr_win->buffer)->name);
else
@@ -2013,7 +2022,7 @@ gui_draw_buffer_status (t_gui_buffer *buffer, int erase)
if (ptr_win->buffer == CHANNEL(ptr_win->buffer)->buffer)
{
/* display channel modes */
- if (CHANNEL(ptr_win->buffer)->type == CHAT_CHANNEL)
+ if (CHANNEL(ptr_win->buffer)->type == CHANNEL_TYPE_CHANNEL)
{
gui_window_set_weechat_color (ptr_win->win_status,
COLOR_WIN_STATUS_DELIMITERS);
@@ -2050,7 +2059,7 @@ gui_draw_buffer_status (t_gui_buffer *buffer, int erase)
}
/* display DCC if private is DCC CHAT */
- if ((CHANNEL(ptr_win->buffer)->type == CHAT_PRIVATE)
+ if ((CHANNEL(ptr_win->buffer)->type == CHANNEL_TYPE_PRIVATE)
&& (CHANNEL(ptr_win->buffer)->dcc_chat))
{
gui_window_set_weechat_color (ptr_win->win_status,
diff --git a/src/gui/gui-action.c b/src/gui/gui-action.c
index dc3bb404e..ddfc8def8 100644
--- a/src/gui/gui-action.c
+++ b/src/gui/gui-action.c
@@ -88,29 +88,30 @@ gui_action_clipboard_paste (t_gui_window *window)
void
gui_action_return (t_gui_window *window)
{
- t_gui_buffer *ptr_buffer;
+ char *command;
if (window->buffer->has_input)
{
if (window->buffer->input_buffer_size > 0)
{
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
- history_add (window->buffer, window->buffer->input_buffer);
+ command = strdup (window->buffer->input_buffer);
+ if (!command)
+ return;
+ history_buffer_add (window->buffer, window->buffer->input_buffer);
+ history_global_add (window->buffer->input_buffer);
+ window->buffer->input_buffer[0] = '\0';
window->buffer->input_buffer_size = 0;
window->buffer->input_buffer_length = 0;
window->buffer->input_buffer_pos = 0;
window->buffer->input_buffer_1st_display = 0;
window->buffer->completion.position = -1;
window->buffer->ptr_history = NULL;
- ptr_buffer = window->buffer;
+ gui_draw_buffer_input (window->buffer, 0);
user_command (SERVER(window->buffer),
window->buffer,
- window->buffer->input_buffer);
- if (ptr_buffer == window->buffer)
- {
- ptr_buffer->input_buffer[0] = '\0';
- gui_draw_buffer_input (ptr_buffer, 0);
- }
+ command);
+ free (command);
}
}
}
@@ -694,7 +695,8 @@ gui_action_up (t_gui_window *window)
if (window->buffer->input_buffer_size > 0)
{
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
- history_add (window->buffer, window->buffer->input_buffer);
+ history_buffer_add (window->buffer, window->buffer->input_buffer);
+ history_global_add (window->buffer->input_buffer);
}
}
else
diff --git a/src/gui/gui-common.c b/src/gui/gui-common.c
index b486c6769..af1e0f86b 100644
--- a/src/gui/gui-common.c
+++ b/src/gui/gui-common.c
@@ -137,8 +137,8 @@ gui_window_new (t_gui_window *parent, int x, int y, int width, int height,
t_gui_window_tree *ptr_tree, *child1, *child2, *ptr_leaf;
#ifdef DEBUG
- wee_log_printf ("Creating new window (x:%d, y:%d, width:%d, height:%d)\n",
- x, y, width, height);
+ weechat_log_printf ("Creating new window (x:%d, y:%d, width:%d, height:%d)\n",
+ x, y, width, height);
#endif
if (parent)
@@ -353,7 +353,7 @@ gui_buffer_new (t_gui_window *window, void *server, void *channel, int dcc,
t_gui_buffer *new_buffer, *ptr_buffer;
#ifdef DEBUG
- wee_log_printf ("Creating new buffer\n");
+ weechat_log_printf ("Creating new buffer\n");
#endif
/* use first buffer if no server was assigned to this buffer */
@@ -665,11 +665,11 @@ gui_buffer_free (t_gui_buffer *buffer, int switch_to_another)
}
/*
- * gui_new_line: create new line for a buffer
+ * gui_line_new: create new line for a buffer
*/
t_gui_line *
-gui_new_line (t_gui_buffer *buffer)
+gui_line_new (t_gui_buffer *buffer)
{
t_gui_line *new_line, *ptr_line;
@@ -693,7 +693,7 @@ gui_new_line (t_gui_buffer *buffer)
}
else
{
- wee_log_printf (_("Not enough memory for new line\n"));
+ weechat_log_printf (_("Not enough memory for new line\n"));
return NULL;
}
@@ -708,7 +708,6 @@ gui_new_line (t_gui_buffer *buffer)
buffer->lines = ptr_line;
ptr_line->prev_line = NULL;
buffer->num_lines--;
- //if (buffer->first_line_displayed)
gui_draw_buffer_chat (buffer, 1);
}
@@ -774,7 +773,7 @@ gui_add_to_line (t_gui_buffer *buffer, int type, char *message)
if (buffer->line_complete)
{
buffer->line_complete = 0;
- if (!gui_new_line (buffer))
+ if (!gui_line_new (buffer))
return;
}
@@ -880,8 +879,8 @@ gui_printf_internal (t_gui_buffer *buffer, int display_time, int type, char *mes
if (buffer == NULL)
{
- wee_log_printf ("WARNING: gui_printf_internal without buffer! This is a bug, "
- "please send to developers - thanks\n");
+ weechat_log_printf ("WARNING: gui_printf_internal without buffer! This is a bug, "
+ "please send to developers - thanks\n");
return;
}
@@ -1045,7 +1044,7 @@ gui_infobar_printf (int time_displayed, int color, char *message, ...)
gui_draw_buffer_infobar (gui_current_window->buffer, 1);
}
else
- wee_log_printf (_("Not enough memory for infobar message\n"));
+ weechat_log_printf (_("Not enough memory for infobar message\n"));
}
if (buf2)
@@ -1616,45 +1615,45 @@ gui_buffer_move_to_number (t_gui_window *window, int number)
void
gui_window_print_log (t_gui_window *window)
{
- wee_log_printf ("[window (addr:0x%X)]\n", window);
- wee_log_printf (" win_x . . . . . . . : %d\n", window->win_x);
- wee_log_printf (" win_y . . . . . . . : %d\n", window->win_y);
- wee_log_printf (" win_width . . . . . : %d\n", window->win_width);
- wee_log_printf (" win_height. . . . . : %d\n", window->win_height);
- wee_log_printf (" win_width_pct . . . : %d\n", window->win_width_pct);
- wee_log_printf (" win_height_pct. . . : %d\n", window->win_height_pct);
- wee_log_printf (" win_chat_x. . . . . : %d\n", window->win_chat_x);
- wee_log_printf (" win_chat_y. . . . . : %d\n", window->win_chat_y);
- wee_log_printf (" win_chat_width. . . : %d\n", window->win_chat_width);
- wee_log_printf (" win_chat_height . . : %d\n", window->win_chat_height);
- wee_log_printf (" win_chat_cursor_x . : %d\n", window->win_chat_cursor_x);
- wee_log_printf (" win_chat_cursor_y . : %d\n", window->win_chat_cursor_y);
- wee_log_printf (" win_nick_x. . . . . : %d\n", window->win_nick_x);
- wee_log_printf (" win_nick_y. . . . . : %d\n", window->win_nick_y);
- wee_log_printf (" win_nick_width. . . : %d\n", window->win_nick_width);
- wee_log_printf (" win_nick_height . . : %d\n", window->win_nick_height);
- wee_log_printf (" win_nick_start. . . : %d\n", window->win_nick_start);
- wee_log_printf (" win_title . . . . . : 0x%X\n", window->win_title);
- wee_log_printf (" win_chat. . . . . . : 0x%X\n", window->win_chat);
- wee_log_printf (" win_nick. . . . . . : 0x%X\n", window->win_nick);
- wee_log_printf (" win_status. . . . . : 0x%X\n", window->win_status);
- wee_log_printf (" win_infobar . . . . : 0x%X\n", window->win_infobar);
- wee_log_printf (" win_input . . . . . : 0x%X\n", window->win_input);
- wee_log_printf (" win_separator . . . : 0x%X\n", window->win_separator);
- wee_log_printf (" textview_chat . . . : 0x%X\n", window->textview_chat);
- wee_log_printf (" textbuffer_chat . . : 0x%X\n", window->textbuffer_chat);
- wee_log_printf (" texttag_chat. . . . : 0x%X\n", window->texttag_chat);
- wee_log_printf (" textview_nicklist . : 0x%X\n", window->textview_nicklist);
- wee_log_printf (" textbuffer_nicklist : 0x%X\n", window->textbuffer_nicklist);
- wee_log_printf (" dcc_first . . . . . : 0x%X\n", window->dcc_first);
- wee_log_printf (" dcc_selected. . . . : 0x%X\n", window->dcc_selected);
- wee_log_printf (" dcc_last_displayed. : 0x%X\n", window->dcc_last_displayed);
- wee_log_printf (" buffer. . . . . . . : 0x%X\n", window->buffer);
- wee_log_printf (" first_line_displayed: %d\n", window->first_line_displayed);
- wee_log_printf (" start_line. . . . . : 0x%X\n", window->start_line);
- wee_log_printf (" start_line_pos. . . : %d\n", window->start_line_pos);
- wee_log_printf (" prev_window . . . . : 0x%X\n", window->prev_window);
- wee_log_printf (" next_window . . . . : 0x%X\n", window->next_window);
+ weechat_log_printf ("[window (addr:0x%X)]\n", window);
+ weechat_log_printf (" win_x . . . . . . . : %d\n", window->win_x);
+ weechat_log_printf (" win_y . . . . . . . : %d\n", window->win_y);
+ weechat_log_printf (" win_width . . . . . : %d\n", window->win_width);
+ weechat_log_printf (" win_height. . . . . : %d\n", window->win_height);
+ weechat_log_printf (" win_width_pct . . . : %d\n", window->win_width_pct);
+ weechat_log_printf (" win_height_pct. . . : %d\n", window->win_height_pct);
+ weechat_log_printf (" win_chat_x. . . . . : %d\n", window->win_chat_x);
+ weechat_log_printf (" win_chat_y. . . . . : %d\n", window->win_chat_y);
+ weechat_log_printf (" win_chat_width. . . : %d\n", window->win_chat_width);
+ weechat_log_printf (" win_chat_height . . : %d\n", window->win_chat_height);
+ weechat_log_printf (" win_chat_cursor_x . : %d\n", window->win_chat_cursor_x);
+ weechat_log_printf (" win_chat_cursor_y . : %d\n", window->win_chat_cursor_y);
+ weechat_log_printf (" win_nick_x. . . . . : %d\n", window->win_nick_x);
+ weechat_log_printf (" win_nick_y. . . . . : %d\n", window->win_nick_y);
+ weechat_log_printf (" win_nick_width. . . : %d\n", window->win_nick_width);
+ weechat_log_printf (" win_nick_height . . : %d\n", window->win_nick_height);
+ weechat_log_printf (" win_nick_start. . . : %d\n", window->win_nick_start);
+ weechat_log_printf (" win_title . . . . . : 0x%X\n", window->win_title);
+ weechat_log_printf (" win_chat. . . . . . : 0x%X\n", window->win_chat);
+ weechat_log_printf (" win_nick. . . . . . : 0x%X\n", window->win_nick);
+ weechat_log_printf (" win_status. . . . . : 0x%X\n", window->win_status);
+ weechat_log_printf (" win_infobar . . . . : 0x%X\n", window->win_infobar);
+ weechat_log_printf (" win_input . . . . . : 0x%X\n", window->win_input);
+ weechat_log_printf (" win_separator . . . : 0x%X\n", window->win_separator);
+ weechat_log_printf (" textview_chat . . . : 0x%X\n", window->textview_chat);
+ weechat_log_printf (" textbuffer_chat . . : 0x%X\n", window->textbuffer_chat);
+ weechat_log_printf (" texttag_chat. . . . : 0x%X\n", window->texttag_chat);
+ weechat_log_printf (" textview_nicklist . : 0x%X\n", window->textview_nicklist);
+ weechat_log_printf (" textbuffer_nicklist : 0x%X\n", window->textbuffer_nicklist);
+ weechat_log_printf (" dcc_first . . . . . : 0x%X\n", window->dcc_first);
+ weechat_log_printf (" dcc_selected. . . . : 0x%X\n", window->dcc_selected);
+ weechat_log_printf (" dcc_last_displayed. : 0x%X\n", window->dcc_last_displayed);
+ weechat_log_printf (" buffer. . . . . . . : 0x%X\n", window->buffer);
+ weechat_log_printf (" first_line_displayed: %d\n", window->first_line_displayed);
+ weechat_log_printf (" start_line. . . . . : 0x%X\n", window->start_line);
+ weechat_log_printf (" start_line_pos. . . : %d\n", window->start_line_pos);
+ weechat_log_printf (" prev_window . . . . : 0x%X\n", window->prev_window);
+ weechat_log_printf (" next_window . . . . : 0x%X\n", window->next_window);
}
@@ -1668,35 +1667,35 @@ gui_buffer_print_log (t_gui_buffer *buffer)
t_gui_line *ptr_line;
int num;
- wee_log_printf ("[buffer (addr:0x%X)]\n", buffer);
- wee_log_printf (" num_displayed. . . . : %d\n", buffer->num_displayed);
- wee_log_printf (" number . . . . . . . : %d\n", buffer->number);
- wee_log_printf (" server . . . . . . . : 0x%X\n", buffer->server);
- wee_log_printf (" all_servers. . . . . : %d\n", buffer->all_servers);
- wee_log_printf (" channel. . . . . . . : 0x%X\n", buffer->channel);
- wee_log_printf (" dcc. . . . . . . . . : %d\n", buffer->dcc);
- wee_log_printf (" lines. . . . . . . . : 0x%X\n", buffer->lines);
- wee_log_printf (" last_line. . . . . . : 0x%X\n", buffer->last_line);
- wee_log_printf (" last_read_line . . . : 0x%X\n", buffer->last_read_line);
- wee_log_printf (" num_lines. . . . . . : %d\n", buffer->num_lines);
- wee_log_printf (" line_complete. . . . : %d\n", buffer->line_complete);
- wee_log_printf (" notify_level . . . . : %d\n", buffer->notify_level);
- wee_log_printf (" log_filename . . . . : '%s'\n", buffer->log_filename);
- wee_log_printf (" log_file . . . . . . : 0x%X\n", buffer->log_file);
- wee_log_printf (" has_input. . . . . . : %d\n", buffer->has_input);
- wee_log_printf (" input_buffer . . . . : '%s'\n", buffer->input_buffer);
- wee_log_printf (" input_buffer_alloc . : %d\n", buffer->input_buffer_alloc);
- wee_log_printf (" input_buffer_size. . : %d\n", buffer->input_buffer_size);
- wee_log_printf (" input_buffer_length. : %d\n", buffer->input_buffer_length);
- wee_log_printf (" input_buffer_pos . . : %d\n", buffer->input_buffer_pos);
- wee_log_printf (" input_buffer_1st_disp: %d\n", buffer->input_buffer_1st_display);
- wee_log_printf (" history. . . . . . . : 0x%X\n", buffer->history);
- wee_log_printf (" last_history . . . . : 0x%X\n", buffer->last_history);
- wee_log_printf (" ptr_history. . . . . : 0x%X\n", buffer->ptr_history);
- wee_log_printf (" prev_buffer. . . . . : 0x%X\n", buffer->prev_buffer);
- wee_log_printf (" next_buffer. . . . . : 0x%X\n", buffer->next_buffer);
- wee_log_printf ("\n");
- wee_log_printf (" => last 100 lines:\n");
+ weechat_log_printf ("[buffer (addr:0x%X)]\n", buffer);
+ weechat_log_printf (" num_displayed. . . . : %d\n", buffer->num_displayed);
+ weechat_log_printf (" number . . . . . . . : %d\n", buffer->number);
+ weechat_log_printf (" server . . . . . . . : 0x%X\n", buffer->server);
+ weechat_log_printf (" all_servers. . . . . : %d\n", buffer->all_servers);
+ weechat_log_printf (" channel. . . . . . . : 0x%X\n", buffer->channel);
+ weechat_log_printf (" dcc. . . . . . . . . : %d\n", buffer->dcc);
+ weechat_log_printf (" lines. . . . . . . . : 0x%X\n", buffer->lines);
+ weechat_log_printf (" last_line. . . . . . : 0x%X\n", buffer->last_line);
+ weechat_log_printf (" last_read_line . . . : 0x%X\n", buffer->last_read_line);
+ weechat_log_printf (" num_lines. . . . . . : %d\n", buffer->num_lines);
+ weechat_log_printf (" line_complete. . . . : %d\n", buffer->line_complete);
+ weechat_log_printf (" notify_level . . . . : %d\n", buffer->notify_level);
+ weechat_log_printf (" log_filename . . . . : '%s'\n", buffer->log_filename);
+ weechat_log_printf (" log_file . . . . . . : 0x%X\n", buffer->log_file);
+ weechat_log_printf (" has_input. . . . . . : %d\n", buffer->has_input);
+ weechat_log_printf (" input_buffer . . . . : '%s'\n", buffer->input_buffer);
+ weechat_log_printf (" input_buffer_alloc . : %d\n", buffer->input_buffer_alloc);
+ weechat_log_printf (" input_buffer_size. . : %d\n", buffer->input_buffer_size);
+ weechat_log_printf (" input_buffer_length. : %d\n", buffer->input_buffer_length);
+ weechat_log_printf (" input_buffer_pos . . : %d\n", buffer->input_buffer_pos);
+ weechat_log_printf (" input_buffer_1st_disp: %d\n", buffer->input_buffer_1st_display);
+ weechat_log_printf (" history. . . . . . . : 0x%X\n", buffer->history);
+ weechat_log_printf (" last_history . . . . : 0x%X\n", buffer->last_history);
+ weechat_log_printf (" ptr_history. . . . . : 0x%X\n", buffer->ptr_history);
+ weechat_log_printf (" prev_buffer. . . . . : 0x%X\n", buffer->prev_buffer);
+ weechat_log_printf (" next_buffer. . . . . : 0x%X\n", buffer->next_buffer);
+ weechat_log_printf ("\n");
+ weechat_log_printf (" => last 100 lines:\n");
num = 0;
ptr_line = buffer->last_line;
@@ -1713,9 +1712,9 @@ gui_buffer_print_log (t_gui_buffer *buffer)
while (ptr_line)
{
num--;
- wee_log_printf (" line N-%05d: %s\n",
- num,
- (ptr_line->data) ? ptr_line->data : "(empty)");
+ weechat_log_printf (" line N-%05d: %s\n",
+ num,
+ (ptr_line->data) ? ptr_line->data : "(empty)");
ptr_line = ptr_line->next_line;
}
diff --git a/src/gui/gui-keyboard.c b/src/gui/gui-keyboard.c
index a3c5c3329..60d06e9db 100644
--- a/src/gui/gui-keyboard.c
+++ b/src/gui/gui-keyboard.c
@@ -431,8 +431,8 @@ gui_key_bind (char *key, char *command)
if (!key || !command)
{
- wee_log_printf (_("%s unable to bind key \"%s\"\n"),
- WEECHAT_ERROR, key);
+ weechat_log_printf (_("%s unable to bind key \"%s\"\n"),
+ WEECHAT_ERROR, key);
return NULL;
}
@@ -442,8 +442,8 @@ gui_key_bind (char *key, char *command)
ptr_function = gui_key_function_search_by_name (command);
if (!ptr_function)
{
- wee_log_printf (_("%s unable to bind key \"%s\" (invalid function name: \"%s\")\n"),
- WEECHAT_ERROR, key, command);
+ weechat_log_printf (_("%s unable to bind key \"%s\" (invalid function name: \"%s\")\n"),
+ WEECHAT_ERROR, key, command);
return NULL;
}
}
@@ -455,8 +455,8 @@ gui_key_bind (char *key, char *command)
ptr_function);
if (!new_key)
{
- wee_log_printf (_("%s not enough memory for key binding\n"),
- WEECHAT_ERROR);
+ weechat_log_printf (_("%s not enough memory for key binding\n"),
+ WEECHAT_ERROR);
return NULL;
}
diff --git a/src/gui/gui.h b/src/gui/gui.h
index 410af2f95..b19b82237 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -140,8 +140,8 @@ enum t_weechat_color
#define CHANNEL(buffer) ((t_irc_channel *)(buffer->channel))
#define BUFFER_IS_SERVER(buffer) ((SERVER(buffer) || (buffer->all_servers)) && !CHANNEL(buffer))
-#define BUFFER_IS_CHANNEL(buffer) (CHANNEL(buffer) && (CHANNEL(buffer)->type == CHAT_CHANNEL))
-#define BUFFER_IS_PRIVATE(buffer) (CHANNEL(buffer) && (CHANNEL(buffer)->type == CHAT_PRIVATE))
+#define BUFFER_IS_CHANNEL(buffer) (CHANNEL(buffer) && (CHANNEL(buffer)->type == CHANNEL_TYPE_CHANNEL))
+#define BUFFER_IS_PRIVATE(buffer) (CHANNEL(buffer) && (CHANNEL(buffer)->type == CHANNEL_TYPE_PRIVATE))
#define BUFFER_HAS_NICKLIST(buffer) (BUFFER_IS_CHANNEL(buffer))
@@ -409,7 +409,7 @@ extern void gui_infobar_printf (int, int, char *, ...);
extern void gui_window_free (t_gui_window *);
extern void gui_infobar_remove ();
extern void gui_buffer_free (t_gui_buffer *, int);
-extern t_gui_line *gui_new_line (t_gui_buffer *);
+extern t_gui_line *gui_line_new (t_gui_buffer *);
extern int gui_word_strlen (t_gui_window *, char *);
extern int gui_word_real_pos (t_gui_window *, char *, int);
extern void gui_printf_internal (t_gui_buffer *, int, int, char *, ...);
diff --git a/src/irc/irc-channel.c b/src/irc/irc-channel.c
index 86028f952..761e64fc7 100644
--- a/src/irc/irc-channel.c
+++ b/src/irc/irc-channel.c
@@ -41,8 +41,7 @@ char *channel_modes = "iklmnst";
*/
t_irc_channel *
-channel_new (t_irc_server *server, int channel_type, char *channel_name,
- int switch_to_buffer)
+channel_new (t_irc_server *server, int channel_type, char *channel_name)
{
t_irc_channel *new_channel;
@@ -58,8 +57,9 @@ channel_new (t_irc_server *server, int channel_type, char *channel_name,
new_channel->dcc_chat = NULL;
new_channel->name = strdup (channel_name);
new_channel->topic = NULL;
- memset (new_channel->modes, ' ', sizeof (new_channel->modes));
- new_channel->modes[sizeof (new_channel->modes) - 1] = '\0';
+ new_channel->modes = (char *) malloc (NUM_CHANNEL_MODES + 1);
+ memset (new_channel->modes, ' ', NUM_CHANNEL_MODES);
+ new_channel->modes[NUM_CHANNEL_MODES] = '\0';
new_channel->limit = 0;
new_channel->key = NULL;
new_channel->nicks_count = 0;
@@ -75,8 +75,6 @@ channel_new (t_irc_server *server, int channel_type, char *channel_name,
else
server->channels = new_channel;
server->last_channel = new_channel;
-
- gui_buffer_new (gui_current_window, server, new_channel, 0, switch_to_buffer);
/* all is ok, return address of new channel */
return new_channel;
@@ -182,11 +180,11 @@ channel_remove_away (t_irc_channel *channel)
{
t_irc_nick *ptr_nick;
- if (channel->type == CHAT_CHANNEL)
+ if (channel->type == CHANNEL_TYPE_CHANNEL)
{
for (ptr_nick = channel->nicks; ptr_nick; ptr_nick = ptr_nick->next_nick)
{
- ptr_nick->is_away = 0;
+ NICK_SET_FLAG(ptr_nick, 0, NICK_AWAY);
}
gui_draw_buffer_nick (channel->buffer, 0);
}
@@ -199,7 +197,7 @@ channel_remove_away (t_irc_channel *channel)
void
channel_check_away (t_irc_server *server, t_irc_channel *channel)
{
- if (channel->type == CHAT_CHANNEL)
+ if (channel->type == CHANNEL_TYPE_CHANNEL)
{
channel->checking_away++;
server_sendf (server, "WHO %s\r\n", channel->name);
@@ -215,7 +213,7 @@ channel_set_away (t_irc_channel *channel, char *nick, int is_away)
{
t_irc_nick *ptr_nick;
- if (channel->type == CHAT_CHANNEL)
+ if (channel->type == CHANNEL_TYPE_CHANNEL)
{
ptr_nick = nick_search (channel, nick);
if (ptr_nick)
@@ -234,10 +232,11 @@ channel_create_dcc (t_irc_dcc *ptr_dcc)
ptr_channel = channel_search (ptr_dcc->server, ptr_dcc->nick);
if (!ptr_channel)
- ptr_channel = channel_new (ptr_dcc->server, CHAT_PRIVATE,
- ptr_dcc->nick, 0);
+ ptr_channel = channel_new (ptr_dcc->server, CHANNEL_TYPE_PRIVATE,
+ ptr_dcc->nick);
if (!ptr_channel)
return 0;
+ gui_buffer_new (gui_current_window, ptr_dcc->server, ptr_channel, 0, 0);
if (ptr_channel->dcc_chat &&
(!DCC_ENDED(((t_irc_dcc *)(ptr_channel->dcc_chat))->status)))
@@ -406,17 +405,17 @@ channel_set_notify_level (t_irc_server *server, t_irc_channel *channel, int noti
void
channel_print_log (t_irc_channel *channel)
{
- wee_log_printf ("=> channel %s (addr:0x%X)]\n", channel->name, channel);
- wee_log_printf (" type . . . . : %d\n", channel->type);
- wee_log_printf (" dcc_chat . . : 0x%X\n", channel->dcc_chat);
- wee_log_printf (" topic. . . . : '%s'\n", channel->topic);
- wee_log_printf (" modes. . . . : '%s'\n", channel->modes);
- wee_log_printf (" limit. . . . : %d\n", channel->limit);
- wee_log_printf (" key. . . . . : '%s'\n", channel->key);
- wee_log_printf (" checking_away: %d\n", channel->checking_away);
- wee_log_printf (" nicks. . . . : 0x%X\n", channel->nicks);
- wee_log_printf (" last_nick. . : 0x%X\n", channel->last_nick);
- wee_log_printf (" buffer . . . : 0x%X\n", channel->buffer);
- wee_log_printf (" prev_channel : 0x%X\n", channel->prev_channel);
- wee_log_printf (" next_channel : 0x%X\n", channel->next_channel);
+ weechat_log_printf ("=> channel %s (addr:0x%X)]\n", channel->name, channel);
+ weechat_log_printf (" type . . . . : %d\n", channel->type);
+ weechat_log_printf (" dcc_chat . . : 0x%X\n", channel->dcc_chat);
+ weechat_log_printf (" topic. . . . : '%s'\n", channel->topic);
+ weechat_log_printf (" modes. . . . : '%s'\n", channel->modes);
+ weechat_log_printf (" limit. . . . : %d\n", channel->limit);
+ weechat_log_printf (" key. . . . . : '%s'\n", channel->key);
+ weechat_log_printf (" checking_away: %d\n", channel->checking_away);
+ weechat_log_printf (" nicks. . . . : 0x%X\n", channel->nicks);
+ weechat_log_printf (" last_nick. . : 0x%X\n", channel->last_nick);
+ weechat_log_printf (" buffer . . . : 0x%X\n", channel->buffer);
+ weechat_log_printf (" prev_channel : 0x%X\n", channel->prev_channel);
+ weechat_log_printf (" next_channel : 0x%X\n", channel->next_channel);
}
diff --git a/src/irc/irc-dcc.c b/src/irc/irc-dcc.c
index 83cb66450..cdf7d08b1 100644
--- a/src/irc/irc-dcc.c
+++ b/src/irc/irc-dcc.c
@@ -148,6 +148,9 @@ dcc_find_filename (t_irc_dcc *ptr_dcc)
{
char *ptr_home, *filename2;
+ if (!DCC_IS_FILE(ptr_dcc->type))
+ return;
+
ptr_home = getenv ("HOME");
ptr_dcc->local_filename = (char *) malloc (strlen (cfg_dcc_download_path) +
strlen (ptr_dcc->nick) +
@@ -223,20 +226,32 @@ void
dcc_calculate_speed (t_irc_dcc *ptr_dcc, int ended)
{
time_t local_time, elapsed;
+ unsigned long bytes_per_sec_total;
local_time = time (NULL);
if (ended || local_time > ptr_dcc->last_check_time)
{
-
if (ended)
{
+ /* calculate bytes per second (global) */
elapsed = local_time - ptr_dcc->start_transfer;
if (elapsed == 0)
elapsed = 1;
ptr_dcc->bytes_per_sec = (ptr_dcc->pos - ptr_dcc->start_resume) / elapsed;
+ ptr_dcc->eta = 0;
}
else
{
+ /* calculate ETA */
+ elapsed = local_time - ptr_dcc->start_transfer;
+ if (elapsed == 0)
+ elapsed = 1;
+ bytes_per_sec_total = (ptr_dcc->pos - ptr_dcc->start_resume) / elapsed;
+ if (bytes_per_sec_total == 0)
+ bytes_per_sec_total = 1;
+ ptr_dcc->eta = (ptr_dcc->size - ptr_dcc->pos) / bytes_per_sec_total;
+
+ /* calculate bytes per second (since last check time) */
elapsed = local_time - ptr_dcc->last_check_time;
if (elapsed == 0)
elapsed = 1;
@@ -606,6 +621,54 @@ dcc_start_resume (t_irc_server *server, char *filename, int port,
}
/*
+ * dcc_alloc: allocate a new DCC file
+ */
+
+t_irc_dcc *
+dcc_alloc ()
+{
+ t_irc_dcc *new_dcc;
+
+ /* create new DCC struct */
+ if ((new_dcc = (t_irc_dcc *) malloc (sizeof (t_irc_dcc))) == NULL)
+ return NULL;
+
+ /* default values */
+ new_dcc->server = NULL;
+ new_dcc->channel = NULL;
+ new_dcc->type = 0;
+ new_dcc->status = 0;
+ new_dcc->start_time = 0;
+ new_dcc->start_transfer = 0;
+ new_dcc->addr = 0;
+ new_dcc->port = 0;
+ new_dcc->nick = NULL;
+ new_dcc->sock = -1;
+ new_dcc->unterminated_message = NULL;
+ new_dcc->file = -1;
+ new_dcc->filename = NULL;
+ new_dcc->local_filename = NULL;
+ new_dcc->filename_suffix = -1;
+ new_dcc->size = 0;
+ new_dcc->pos = 0;
+ new_dcc->ack = 0;
+ new_dcc->start_resume = 0;
+ new_dcc->last_check_time = 0;
+ new_dcc->last_check_pos = 0;
+ new_dcc->last_activity = 0;
+ new_dcc->bytes_per_sec = 0;
+ new_dcc->eta = 0;
+
+ new_dcc->prev_dcc = NULL;
+ new_dcc->next_dcc = dcc_list;
+ if (dcc_list)
+ dcc_list->prev_dcc = new_dcc;
+ dcc_list = new_dcc;
+
+ return new_dcc;
+}
+
+/*
* dcc_add: add a DCC file to queue
*/
@@ -615,8 +678,8 @@ dcc_add (t_irc_server *server, int type, unsigned long addr, int port, char *nic
{
t_irc_dcc *new_dcc;
- /* create new DCC struct */
- if ((new_dcc = (t_irc_dcc *) malloc (sizeof (t_irc_dcc))) == NULL)
+ new_dcc = dcc_alloc ();
+ if (!new_dcc)
{
irc_display_prefix (server, server->buffer, PREFIX_ERROR);
gui_printf (server->buffer,
@@ -650,17 +713,13 @@ dcc_add (t_irc_server *server, int type, unsigned long addr, int port, char *nic
new_dcc->start_resume = 0;
new_dcc->last_check_time = time (NULL);
new_dcc->last_check_pos = 0;
- new_dcc->bytes_per_sec = 0;
new_dcc->last_activity = time (NULL);
+ new_dcc->bytes_per_sec = 0;
+ new_dcc->eta = 0;
if (local_filename)
new_dcc->local_filename = strdup (local_filename);
else
dcc_find_filename (new_dcc);
- new_dcc->prev_dcc = NULL;
- new_dcc->next_dcc = dcc_list;
- if (dcc_list)
- dcc_list->prev_dcc = new_dcc;
- dcc_list = new_dcc;
gui_current_window->dcc_first = NULL;
gui_current_window->dcc_selected = NULL;
@@ -1424,9 +1483,45 @@ dcc_end ()
if (ptr_dcc->sock != -1)
{
if (ptr_dcc->status == DCC_ACTIVE)
- wee_log_printf (_("Aborting active DCC: \"%s\" from %s\n"),
- ptr_dcc->filename, ptr_dcc->nick);
+ weechat_log_printf (_("Aborting active DCC: \"%s\" from %s\n"),
+ ptr_dcc->filename, ptr_dcc->nick);
dcc_close (ptr_dcc, DCC_FAILED);
}
}
}
+
+/*
+ * dcc_print_log: print DCC infos in log (usually for crash dump)
+ */
+
+void
+dcc_print_log (t_irc_dcc *dcc)
+{
+ weechat_log_printf ("[DCC (addr:0x%X)]\n", dcc);
+ weechat_log_printf (" server. . . . . . . : 0x%X\n", dcc->server);
+ weechat_log_printf (" channel . . . . . . : 0x%X\n", dcc->channel);
+ weechat_log_printf (" type. . . . . . . . : %d\n", dcc->type);
+ weechat_log_printf (" status. . . . . . . : %d\n", dcc->status);
+ weechat_log_printf (" start_time. . . . . : %ld\n", dcc->start_time);
+ weechat_log_printf (" start_transfer. . . : %ld\n", dcc->start_transfer);
+ weechat_log_printf (" addr. . . . . . . . : %lu\n", dcc->addr);
+ weechat_log_printf (" port. . . . . . . . : %d\n", dcc->port);
+ weechat_log_printf (" nick. . . . . . . . : '%s'\n", dcc->nick);
+ weechat_log_printf (" sock. . . . . . . . : %d\n", dcc->sock);
+ weechat_log_printf (" unterminated_message: '%s'\n", dcc->unterminated_message);
+ weechat_log_printf (" file. . . . . . . . : %d\n", dcc->file);
+ weechat_log_printf (" filename. . . . . . : '%s'\n", dcc->filename);
+ weechat_log_printf (" local_filename. . . : '%s'\n", dcc->local_filename);
+ weechat_log_printf (" filename_suffix . . : %d\n", dcc->filename_suffix);
+ weechat_log_printf (" size. . . . . . . . : %lu\n", dcc->size);
+ weechat_log_printf (" pos . . . . . . . . : %lu\n", dcc->pos);
+ weechat_log_printf (" ack . . . . . . . . : %lu\n", dcc->ack);
+ weechat_log_printf (" start_resume. . . . : %lu\n", dcc->start_resume);
+ weechat_log_printf (" last_check_time . . : %ld\n", dcc->last_check_time);
+ weechat_log_printf (" last_check_pos. . . : %lu\n", dcc->last_check_pos);
+ weechat_log_printf (" last_activity . . . : %ld\n", dcc->last_activity);
+ weechat_log_printf (" bytes_per_sec . . . : %lu\n", dcc->bytes_per_sec);
+ weechat_log_printf (" eta . . . . . . . . : %lu\n", dcc->eta);
+ weechat_log_printf (" prev_dcc. . . . . . : 0x%X\n", dcc->prev_dcc);
+ weechat_log_printf (" next_dcc. . . . . . : 0x%X\n", dcc->next_dcc);
+}
diff --git a/src/irc/irc-display.c b/src/irc/irc-display.c
index 97272c09d..b8be20219 100644
--- a/src/irc/irc-display.c
+++ b/src/irc/irc-display.c
@@ -97,19 +97,19 @@ irc_display_nick (t_gui_buffer *buffer, t_irc_nick *nick, char *nickname,
(nick) ? "<" : ">");
if (nick && cfg_look_nickmode)
{
- if (nick->is_chanowner)
+ if (nick->flags & NICK_CHANOWNER)
gui_printf_type (buffer, type, "%s~",
GUI_COLOR(COLOR_WIN_NICK_OP));
- else if (nick->is_chanadmin)
+ else if (nick->flags & NICK_CHANADMIN)
gui_printf_type (buffer, type, "%s&",
GUI_COLOR(COLOR_WIN_NICK_OP));
- else if (nick->is_op)
+ else if (nick->flags & NICK_OP)
gui_printf_type (buffer, type, "%s@",
GUI_COLOR(COLOR_WIN_NICK_OP));
- else if (nick->is_halfop)
+ else if (nick->flags & NICK_HALFOP)
gui_printf_type (buffer, type, "%s%%",
GUI_COLOR(COLOR_WIN_NICK_HALFOP));
- else if (nick->has_voice)
+ else if (nick->flags & NICK_VOICE)
gui_printf_type (buffer, type, "%s+",
GUI_COLOR(COLOR_WIN_NICK_VOICE));
else
diff --git a/src/irc/irc-ignore.c b/src/irc/irc-ignore.c
index a039bb846..d81453a8d 100644
--- a/src/irc/irc-ignore.c
+++ b/src/irc/irc-ignore.c
@@ -459,18 +459,18 @@ ignore_print_log ()
{
t_irc_ignore *ptr_ignore;
- wee_log_printf ("[ignore list]\n");
+ weechat_log_printf ("[ignore list]\n");
for (ptr_ignore = irc_ignore; ptr_ignore;
ptr_ignore = ptr_ignore->next_ignore)
{
- wee_log_printf ("\n");
- wee_log_printf (" -> ignore at 0x%X:\n", ptr_ignore);
- wee_log_printf (" mask. . . . . . . : %s\n", ptr_ignore->mask);
- wee_log_printf (" type. . . . . . . : %s\n", ptr_ignore->type);
- wee_log_printf (" channel_name. . . : %s\n", ptr_ignore->channel_name);
- wee_log_printf (" server_name . . . : %s\n", ptr_ignore->server_name);
- wee_log_printf (" prev_ignore . . . : 0x%X\n", ptr_ignore->prev_ignore);
- wee_log_printf (" next_ignore . . . : 0x%X\n", ptr_ignore->next_ignore);
+ weechat_log_printf ("\n");
+ weechat_log_printf (" -> ignore at 0x%X:\n", ptr_ignore);
+ weechat_log_printf (" mask. . . . . . . : %s\n", ptr_ignore->mask);
+ weechat_log_printf (" type. . . . . . . : %s\n", ptr_ignore->type);
+ weechat_log_printf (" channel_name. . . : %s\n", ptr_ignore->channel_name);
+ weechat_log_printf (" server_name . . . : %s\n", ptr_ignore->server_name);
+ weechat_log_printf (" prev_ignore . . . : 0x%X\n", ptr_ignore->prev_ignore);
+ weechat_log_printf (" next_ignore . . . : 0x%X\n", ptr_ignore->next_ignore);
}
}
diff --git a/src/irc/irc-nick.c b/src/irc/irc-nick.c
index a91fcd7af..ae6dbc3bc 100644
--- a/src/irc/irc-nick.c
+++ b/src/irc/irc-nick.c
@@ -59,15 +59,15 @@ nick_find_color (t_irc_nick *nick)
int
nick_score_for_sort (t_irc_nick *nick)
{
- if (nick->is_chanowner)
+ if (nick->flags & NICK_CHANOWNER)
return -32;
- if (nick->is_chanadmin)
+ if (nick->flags & NICK_CHANADMIN)
return -16;
- if (nick->is_op)
+ if (nick->flags & NICK_OP)
return -8;
- if (nick->is_halfop)
+ if (nick->flags & NICK_HALFOP)
return -4;
- if (nick->has_voice)
+ if (nick->flags & NICK_VOICE)
return -2;
return 0;
}
@@ -168,7 +168,7 @@ nick_insert_sorted (t_irc_channel *channel, t_irc_nick *nick)
*/
t_irc_nick *
-nick_new (t_irc_channel *channel, char *nick_name,
+nick_new (t_irc_server *server, t_irc_channel *channel, char *nick_name,
int is_chanowner, int is_chanadmin, int is_op, int is_halfop,
int has_voice)
{
@@ -178,35 +178,31 @@ nick_new (t_irc_channel *channel, char *nick_name,
if ((new_nick = nick_search (channel, nick_name)))
{
/* update nick */
- new_nick->is_chanowner = is_chanowner;
- new_nick->is_chanadmin = is_chanadmin;
- new_nick->is_op = is_op;
- new_nick->is_halfop = is_halfop;
- new_nick->has_voice = has_voice;
+ NICK_SET_FLAG(new_nick, is_chanowner, NICK_CHANOWNER);
+ NICK_SET_FLAG(new_nick, is_chanadmin, NICK_CHANADMIN);
+ NICK_SET_FLAG(new_nick, is_op, NICK_OP);
+ NICK_SET_FLAG(new_nick, is_halfop, NICK_HALFOP);
+ NICK_SET_FLAG(new_nick, has_voice, NICK_VOICE);
return new_nick;
}
/* alloc memory for new nick */
if ((new_nick = (t_irc_nick *) malloc (sizeof (t_irc_nick))) == NULL)
- {
- gui_printf (channel->buffer,
- _("%s cannot allocate new nick\n"), WEECHAT_ERROR);
return NULL;
- }
-
+
/* initialize new nick */
new_nick->nick = strdup (nick_name);
- new_nick->is_chanowner = is_chanowner;
- new_nick->is_chanadmin = is_chanadmin;
- new_nick->is_op = is_op;
- new_nick->is_halfop = is_halfop;
- new_nick->has_voice = has_voice;
- new_nick->is_away = 0;
- if (ascii_strcasecmp (new_nick->nick, SERVER(channel->buffer)->nick) == 0)
+ new_nick->flags = 0;
+ NICK_SET_FLAG(new_nick, is_chanowner, NICK_CHANOWNER);
+ NICK_SET_FLAG(new_nick, is_chanadmin, NICK_CHANADMIN);
+ NICK_SET_FLAG(new_nick, is_op, NICK_OP);
+ NICK_SET_FLAG(new_nick, is_halfop, NICK_HALFOP);
+ NICK_SET_FLAG(new_nick, has_voice, NICK_VOICE);
+ if (ascii_strcasecmp (new_nick->nick, server->nick) == 0)
new_nick->color = COLOR_WIN_NICK_SELF;
else
new_nick->color = nick_find_color (new_nick);
-
+
nick_insert_sorted (channel, new_nick);
channel->nicks_count++;
@@ -347,15 +343,17 @@ nick_count (t_irc_channel *channel, int *total, int *count_op,
ptr_nick = ptr_nick->next_nick)
{
(*total)++;
- if ((ptr_nick->is_chanowner) || (ptr_nick->is_chanadmin) || (ptr_nick->is_op))
+ if ((ptr_nick->flags & NICK_CHANOWNER) ||
+ (ptr_nick->flags & NICK_CHANADMIN) ||
+ (ptr_nick->flags & NICK_OP))
(*count_op)++;
else
{
- if (ptr_nick->is_halfop)
+ if (ptr_nick->flags & NICK_HALFOP)
(*count_halfop)++;
else
{
- if (ptr_nick->has_voice)
+ if (ptr_nick->flags & NICK_VOICE)
(*count_voice)++;
else
(*count_normal)++;
@@ -391,9 +389,10 @@ nick_get_max_length (t_irc_channel *channel)
void
nick_set_away (t_irc_channel *channel, t_irc_nick *nick, int is_away)
{
- if (nick->is_away != is_away)
+ if (((is_away) && (!(nick->flags & NICK_AWAY))) ||
+ ((!is_away) && (nick->flags & NICK_AWAY)))
{
- nick->is_away = is_away;
+ NICK_SET_FLAG(nick, is_away, NICK_AWAY);
gui_draw_buffer_nick (channel->buffer, 0);
}
}
@@ -405,14 +404,9 @@ nick_set_away (t_irc_channel *channel, t_irc_nick *nick, int is_away)
void
nick_print_log (t_irc_nick *nick)
{
- wee_log_printf ("=> nick %s (addr:0x%X)]\n", nick->nick, nick);
- wee_log_printf (" is_chanowner . : %d\n", nick->is_chanowner);
- wee_log_printf (" is_chanadmin . : %d\n", nick->is_chanadmin);
- wee_log_printf (" is_op. . . . . : %d\n", nick->is_op);
- wee_log_printf (" is_halfop. . . : %d\n", nick->is_halfop);
- wee_log_printf (" has_voice. . . : %d\n", nick->has_voice);
- wee_log_printf (" is_away. . . . : %d\n", nick->is_away);
- wee_log_printf (" color. . . . . : %d\n", nick->color);
- wee_log_printf (" prev_nick. . . : 0x%X\n", nick->prev_nick);
- wee_log_printf (" next_nick. . . : 0x%X\n", nick->next_nick);
+ weechat_log_printf ("=> nick %s (addr:0x%X)]\n", nick->nick, nick);
+ weechat_log_printf (" flags. . . . . : %d\n", nick->flags);
+ weechat_log_printf (" color. . . . . : %d\n", nick->color);
+ weechat_log_printf (" prev_nick. . . : 0x%X\n", nick->prev_nick);
+ weechat_log_printf (" next_nick. . . : 0x%X\n", nick->next_nick);
}
diff --git a/src/irc/irc-recv.c b/src/irc/irc-recv.c
index 55c203194..a19196315 100644
--- a/src/irc/irc-recv.c
+++ b/src/irc/irc-recv.c
@@ -396,7 +396,7 @@ irc_cmd_recv_join (t_irc_server *server, char *host, char *nick, char *arguments
ptr_channel = channel_search (server, arguments);
if (!ptr_channel)
{
- ptr_channel = channel_new (server, CHAT_CHANNEL, arguments, 1);
+ ptr_channel = channel_new (server, CHANNEL_TYPE_CHANNEL, arguments);
if (!ptr_channel)
{
irc_display_prefix (server, server->buffer, PREFIX_ERROR);
@@ -405,6 +405,7 @@ irc_cmd_recv_join (t_irc_server *server, char *host, char *nick, char *arguments
WEECHAT_ERROR, arguments);
return -1;
}
+ gui_buffer_new (gui_current_window, server, ptr_channel, 0, 1);
}
if (!command_ignored)
@@ -423,7 +424,7 @@ irc_cmd_recv_join (t_irc_server *server, char *host, char *nick, char *arguments
GUI_COLOR(COLOR_WIN_CHAT_CHANNEL),
arguments);
}
- (void) nick_new (ptr_channel, nick, 0, 0, 0, 0, 0);
+ (void) nick_new (server, ptr_channel, nick, 0, 0, 0, 0, 0);
gui_draw_buffer_nick (ptr_channel->buffer, 1);
gui_draw_buffer_status (ptr_channel->buffer, 1);
return 0;
@@ -705,7 +706,7 @@ void irc_get_channel_modes (t_irc_server *server, t_irc_channel *ptr_channel,
ptr_nick = nick_search (ptr_channel, parm);
if (ptr_nick)
{
- ptr_nick->is_halfop = (set_flag == '+') ? 1 : 0;
+ NICK_SET_FLAG(ptr_nick, (set_flag == '+'), NICK_HALFOP);
nick_resort (ptr_channel, ptr_nick);
gui_draw_buffer_nick (ptr_channel->buffer, 1);
}
@@ -728,8 +729,8 @@ void irc_get_channel_modes (t_irc_server *server, t_irc_channel *ptr_channel,
_("sets invite-only channel flag") :
_("removes invite-only channel flag"),
NULL);
- SET_CHANNEL_MODE(ptr_channel, (set_flag == '+'),
- CHANNEL_MODE_INVITE);
+ CHANNEL_SET_MODE(ptr_channel, (set_flag == '+'),
+ CHANNEL_MODE_INVITE);
break;
case 'k':
pos = NULL;
@@ -748,8 +749,8 @@ void irc_get_channel_modes (t_irc_server *server, t_irc_channel *ptr_channel,
(set_flag == '+') ?
((parm) ? parm : NULL) :
NULL);
- SET_CHANNEL_MODE(ptr_channel, (set_flag == '+'),
- CHANNEL_MODE_KEY);
+ CHANNEL_SET_MODE(ptr_channel, (set_flag == '+'),
+ CHANNEL_MODE_KEY);
if (ptr_channel->key)
free (ptr_channel->key);
ptr_channel->key = strdup (parm);
@@ -780,8 +781,8 @@ void irc_get_channel_modes (t_irc_server *server, t_irc_channel *ptr_channel,
(set_flag == '+') ?
((parm) ? parm : NULL) :
NULL);
- SET_CHANNEL_MODE(ptr_channel, (set_flag == '+'),
- CHANNEL_MODE_LIMIT);
+ CHANNEL_SET_MODE(ptr_channel, (set_flag == '+'),
+ CHANNEL_MODE_LIMIT);
ptr_channel->limit = atoi (parm);
/* look for next parameter */
@@ -801,8 +802,8 @@ void irc_get_channel_modes (t_irc_server *server, t_irc_channel *ptr_channel,
_("sets moderated channel flag") :
_("removes moderated channel flag"),
NULL);
- SET_CHANNEL_MODE(ptr_channel, (set_flag == '+'),
- CHANNEL_MODE_MODERATED);
+ CHANNEL_SET_MODE(ptr_channel, (set_flag == '+'),
+ CHANNEL_MODE_MODERATED);
break;
case 'n':
if (nick_host)
@@ -812,8 +813,8 @@ void irc_get_channel_modes (t_irc_server *server, t_irc_channel *ptr_channel,
_("sets messages from channel only flag") :
_("removes messages from channel only flag"),
NULL);
- SET_CHANNEL_MODE(ptr_channel, (set_flag == '+'),
- CHANNEL_MODE_NO_MSG_OUT);
+ CHANNEL_SET_MODE(ptr_channel, (set_flag == '+'),
+ CHANNEL_MODE_NO_MSG_OUT);
break;
case 'o':
pos = NULL;
@@ -835,7 +836,7 @@ void irc_get_channel_modes (t_irc_server *server, t_irc_channel *ptr_channel,
ptr_nick = nick_search (ptr_channel, parm);
if (ptr_nick)
{
- ptr_nick->is_op = (set_flag == '+') ? 1 : 0;
+ NICK_SET_FLAG(ptr_nick, (set_flag == '+'), NICK_OP);
nick_resort (ptr_channel, ptr_nick);
gui_draw_buffer_nick (ptr_channel->buffer, 1);
}
@@ -858,8 +859,8 @@ void irc_get_channel_modes (t_irc_server *server, t_irc_channel *ptr_channel,
_("sets private channel flag") :
_("removes private channel flag"),
NULL);
- SET_CHANNEL_MODE(ptr_channel, (set_flag == '+'),
- CHANNEL_MODE_SECRET);
+ CHANNEL_SET_MODE(ptr_channel, (set_flag == '+'),
+ CHANNEL_MODE_SECRET);
break;
case 'q':
pos = NULL;
@@ -894,8 +895,8 @@ void irc_get_channel_modes (t_irc_server *server, t_irc_channel *ptr_channel,
_("sets secret channel flag") :
_("removes secret channel flag"),
NULL);
- SET_CHANNEL_MODE(ptr_channel, (set_flag == '+'),
- CHANNEL_MODE_SECRET);
+ CHANNEL_SET_MODE(ptr_channel, (set_flag == '+'),
+ CHANNEL_MODE_SECRET);
break;
case 't':
if (nick_host)
@@ -905,8 +906,8 @@ void irc_get_channel_modes (t_irc_server *server, t_irc_channel *ptr_channel,
_("sets topic protection") :
_("removes topic protection"),
NULL);
- SET_CHANNEL_MODE(ptr_channel, (set_flag == '+'),
- CHANNEL_MODE_TOPIC);
+ CHANNEL_SET_MODE(ptr_channel, (set_flag == '+'),
+ CHANNEL_MODE_TOPIC);
break;
case 'v':
pos = NULL;
@@ -929,7 +930,7 @@ void irc_get_channel_modes (t_irc_server *server, t_irc_channel *ptr_channel,
ptr_nick = nick_search (ptr_channel, parm);
if (ptr_nick)
{
- ptr_nick->has_voice = (set_flag == '+') ? 1 : 0;
+ NICK_SET_FLAG(ptr_nick, (set_flag == '+'), NICK_VOICE);
nick_resort (ptr_channel, ptr_nick);
gui_draw_buffer_nick (ptr_channel->buffer, 1);
}
@@ -1222,7 +1223,7 @@ irc_cmd_recv_notice (t_irc_server *server, char *host, char *nick, char *argumen
ptr_channel = channel_search (server, nick);
if (!ptr_channel)
{
- ptr_channel = channel_new (server, CHAT_PRIVATE, nick, 0);
+ ptr_channel = channel_new (server, CHANNEL_TYPE_PRIVATE, nick);
if (!ptr_channel)
{
irc_display_prefix (server, server->buffer, PREFIX_ERROR);
@@ -1231,6 +1232,7 @@ irc_cmd_recv_notice (t_irc_server *server, char *host, char *nick, char *argumen
WEECHAT_ERROR, nick);
return -1;
}
+ gui_buffer_new (gui_current_window, server, ptr_channel, 0, 0);
}
if (!ptr_channel->topic)
ptr_channel->topic = strdup ((host2) ? host2 : "");
@@ -2034,7 +2036,7 @@ irc_cmd_recv_privmsg (t_irc_server *server, char *host, char *nick, char *argume
{
if (!ptr_channel)
{
- ptr_channel = channel_new (server, CHAT_PRIVATE, nick, 0);
+ ptr_channel = channel_new (server, CHANNEL_TYPE_PRIVATE, nick);
if (!ptr_channel)
{
irc_display_prefix (server, server->buffer, PREFIX_ERROR);
@@ -2043,6 +2045,7 @@ irc_cmd_recv_privmsg (t_irc_server *server, char *host, char *nick, char *argume
WEECHAT_ERROR, nick);
return -1;
}
+ gui_buffer_new (gui_current_window, server, ptr_channel, 0, 0);
}
if (!ptr_channel->topic)
ptr_channel->topic = strdup (host2);
@@ -2124,7 +2127,7 @@ irc_cmd_recv_privmsg (t_irc_server *server, char *host, char *nick, char *argume
{
if (!ptr_channel)
{
- ptr_channel = channel_new (server, CHAT_PRIVATE, nick, 0);
+ ptr_channel = channel_new (server, CHANNEL_TYPE_PRIVATE, nick);
if (!ptr_channel)
{
irc_display_prefix (server, server->buffer, PREFIX_ERROR);
@@ -2133,6 +2136,7 @@ irc_cmd_recv_privmsg (t_irc_server *server, char *host, char *nick, char *argume
WEECHAT_ERROR, nick);
return -1;
}
+ gui_buffer_new (gui_current_window, server, ptr_channel, 0, 0);
}
if (!ptr_channel->topic)
ptr_channel->topic = strdup (host2);
@@ -2206,7 +2210,7 @@ irc_cmd_recv_quit (t_irc_server *server, char *host, char *nick, char *arguments
for (ptr_channel = server->channels; ptr_channel;
ptr_channel = ptr_channel->next_channel)
{
- if (ptr_channel->type == CHAT_PRIVATE)
+ if (ptr_channel->type == CHANNEL_TYPE_PRIVATE)
ptr_nick = NULL;
else
ptr_nick = nick_search (ptr_channel, nick);
@@ -2454,7 +2458,7 @@ irc_cmd_recv_004 (t_irc_server *server, char *host, char *nick, char *arguments)
for (ptr_channel = server->channels; ptr_channel;
ptr_channel = ptr_channel->next_channel)
{
- if (ptr_channel->type == CHAT_CHANNEL)
+ if (ptr_channel->type == CHANNEL_TYPE_CHANNEL)
{
if (ptr_channel->key)
server_sendf (server, "JOIN %s %s\r\n",
@@ -4309,8 +4313,8 @@ irc_cmd_recv_353 (t_irc_server *server, char *host, char *nick, char *arguments)
pos[0] = '\0';
pos++;
}
- if (!nick_new (ptr_channel, pos_nick, is_chanowner, is_chanadmin,
- is_op, is_halfop, has_voice))
+ if (!nick_new (server, ptr_channel, pos_nick, is_chanowner,
+ is_chanadmin, is_op, is_halfop, has_voice))
{
irc_display_prefix (server, server->buffer, PREFIX_ERROR);
gui_printf_nolog (server->buffer,
diff --git a/src/irc/irc-send.c b/src/irc/irc-send.c
index a0bee886b..84da65271 100644
--- a/src/irc/irc-send.c
+++ b/src/irc/irc-send.c
@@ -107,7 +107,7 @@ irc_cmd_send_ame (t_irc_server *server, char *arguments)
for (ptr_channel = ptr_server->channels; ptr_channel;
ptr_channel = ptr_channel->next_channel)
{
- if (ptr_channel->type == CHAT_CHANNEL)
+ if (ptr_channel->type == CHANNEL_TYPE_CHANNEL)
{
server_sendf (ptr_server, "PRIVMSG %s :\01ACTION %s\01\r\n",
ptr_channel->name,
@@ -156,7 +156,7 @@ irc_cmd_send_amsg (t_irc_server *server, char *arguments)
for (ptr_channel = ptr_server->channels; ptr_channel;
ptr_channel = ptr_channel->next_channel)
{
- if (ptr_channel->type == CHAT_CHANNEL)
+ if (ptr_channel->type == CHANNEL_TYPE_CHANNEL)
{
server_sendf (ptr_server, "PRIVMSG %s :%s\r\n",
ptr_channel->name, arguments);
@@ -965,7 +965,7 @@ irc_send_me_all_channels (t_irc_server *server, char *arguments)
for (ptr_channel = server->channels; ptr_channel;
ptr_channel = ptr_channel->next_channel)
{
- if (ptr_channel->type == CHAT_CHANNEL)
+ if (ptr_channel->type == CHANNEL_TYPE_CHANNEL)
irc_send_me (server, ptr_channel, arguments);
}
return 0;
@@ -1145,7 +1145,7 @@ irc_cmd_send_msg (t_irc_server *server, char *arguments)
ptr_channel = channel_search (server, arguments);
if (!ptr_channel)
{
- ptr_channel = channel_new (server, CHAT_PRIVATE, arguments, 1);
+ ptr_channel = channel_new (server, CHANNEL_TYPE_PRIVATE, arguments);
if (!ptr_channel)
{
irc_display_prefix (NULL, server->buffer, PREFIX_ERROR);
@@ -1154,6 +1154,7 @@ irc_cmd_send_msg (t_irc_server *server, char *arguments)
WEECHAT_ERROR, arguments);
return -1;
}
+ gui_buffer_new (gui_current_window, server, ptr_channel, 0, 1);
gui_draw_buffer_title (ptr_channel->buffer, 1);
}
@@ -1485,7 +1486,7 @@ irc_cmd_send_query (t_irc_server *server, char *arguments)
ptr_channel = channel_search (server, arguments);
if (!ptr_channel)
{
- ptr_channel = channel_new (server, CHAT_PRIVATE, arguments, 1);
+ ptr_channel = channel_new (server, CHANNEL_TYPE_PRIVATE, arguments);
if (!ptr_channel)
{
irc_display_prefix (NULL, server->buffer, PREFIX_ERROR);
@@ -1494,6 +1495,7 @@ irc_cmd_send_query (t_irc_server *server, char *arguments)
WEECHAT_ERROR, arguments);
return -1;
}
+ gui_buffer_new (gui_current_window, server, ptr_channel, 0, 1);
gui_draw_buffer_title (ptr_channel->buffer, 1);
}
else
diff --git a/src/irc/irc-server.c b/src/irc/irc-server.c
index d877bd15f..2a4b6107e 100644
--- a/src/irc/irc-server.c
+++ b/src/irc/irc-server.c
@@ -91,9 +91,7 @@ server_init (t_irc_server *server)
server->child_write = -1;
server->sock = -1;
server->is_connected = 0;
-#ifdef HAVE_GNUTLS
server->ssl_connected = 0;
-#endif
server->unterminated_message = NULL;
server->nick = NULL;
server->reconnect_start = 0;
@@ -365,14 +363,14 @@ server_new (char *name, int autoconnect, int autoreconnect, int autoreconnect_de
return NULL;
#ifdef DEBUG
- wee_log_printf ("Creating new server (name:%s, address:%s, port:%d, pwd:%s, "
- "nick1:%s, nick2:%s, nick3:%s, username:%s, realname:%s, "
- "command:%s, autojoin:%s, autorejoin:%s, notify_levels:%s)\n",
- name, address, port, (password) ? password : "",
- (nick1) ? nick1 : "", (nick2) ? nick2 : "", (nick3) ? nick3 : "",
- (username) ? username : "", (realname) ? realname : "",
- (command) ? command : "", (autojoin) ? autojoin : "",
- (autorejoin) ? "on" : "off", (notify_levels) ? notify_levels : "");
+ weechat_log_printf ("Creating new server (name:%s, address:%s, port:%d, pwd:%s, "
+ "nick1:%s, nick2:%s, nick3:%s, username:%s, realname:%s, "
+ "command:%s, autojoin:%s, autorejoin:%s, notify_levels:%s)\n",
+ name, address, port, (password) ? password : "",
+ (nick1) ? nick1 : "", (nick2) ? nick2 : "", (nick3) ? nick3 : "",
+ (username) ? username : "", (realname) ? realname : "",
+ (command) ? command : "", (autojoin) ? autojoin : "",
+ (autorejoin) ? "on" : "off", (notify_levels) ? notify_levels : "");
#endif
if ((new_server = server_alloc ()))
@@ -801,9 +799,7 @@ server_close_connection (t_irc_server *server)
/* server is now disconnected */
server->is_connected = 0;
-#ifdef HAVE_GNUTLS
server->ssl_connected = 0;
-#endif
}
/*
@@ -1399,12 +1395,12 @@ server_connect (t_irc_server *server)
(server->ssl) ? " (SSL)" : "",
cfg_proxy_type_values[cfg_proxy_type], cfg_proxy_address, cfg_proxy_port,
(cfg_proxy_ipv6) ? " (IPv6)" : "");
- wee_log_printf (_("Connecting to server %s:%d%s%s via %s proxy %s:%d%s...\n"),
- server->address, server->port,
- (server->ipv6) ? " (IPv6)" : "",
- (server->ssl) ? " (SSL)" : "",
- cfg_proxy_type_values[cfg_proxy_type], cfg_proxy_address, cfg_proxy_port,
- (cfg_proxy_ipv6) ? " (IPv6)" : "");
+ weechat_log_printf (_("Connecting to server %s:%d%s%s via %s proxy %s:%d%s...\n"),
+ server->address, server->port,
+ (server->ipv6) ? " (IPv6)" : "",
+ (server->ssl) ? " (SSL)" : "",
+ cfg_proxy_type_values[cfg_proxy_type], cfg_proxy_address, cfg_proxy_port,
+ (cfg_proxy_ipv6) ? " (IPv6)" : "");
}
else
{
@@ -1413,18 +1409,18 @@ server_connect (t_irc_server *server)
PACKAGE_NAME, server->address, server->port,
(server->ipv6) ? " (IPv6)" : "",
(server->ssl) ? " (SSL)" : "");
- wee_log_printf (_("Connecting to server %s:%d%s%s...\n"),
- server->address, server->port,
- (server->ipv6) ? " (IPv6)" : "",
- (server->ssl) ? " (SSL)" : "");
+ weechat_log_printf (_("Connecting to server %s:%d%s%s...\n"),
+ server->address, server->port,
+ (server->ipv6) ? " (IPv6)" : "",
+ (server->ssl) ? " (SSL)" : "");
}
/* close any opened connection and kill child process if running */
server_close_connection (server);
/* init SSL if asked */
-#ifdef HAVE_GNUTLS
server->ssl_connected = 0;
+#ifdef HAVE_GNUTLS
if (server->ssl)
{
if (gnutls_init (&server->gnutls_sess, GNUTLS_CLIENT) != 0)
@@ -1706,7 +1702,7 @@ server_remove_away ()
{
for (ptr_channel = ptr_server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel)
{
- if (ptr_channel->type == CHAT_CHANNEL)
+ if (ptr_channel->type == CHANNEL_TYPE_CHANNEL)
channel_remove_away (ptr_channel);
}
}
@@ -1729,7 +1725,7 @@ server_check_away ()
{
for (ptr_channel = ptr_server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel)
{
- if (ptr_channel->type == CHAT_CHANNEL)
+ if (ptr_channel->type == CHANNEL_TYPE_CHANNEL)
channel_check_away (ptr_server, ptr_channel);
}
}
@@ -1749,7 +1745,7 @@ server_set_away (t_irc_server *server, char *nick, int is_away)
{
if (server->is_connected)
{
- if (ptr_channel->type == CHAT_CHANNEL)
+ if (ptr_channel->type == CHANNEL_TYPE_CHANNEL)
channel_set_away (ptr_channel, nick, is_away);
}
}
@@ -1762,49 +1758,50 @@ server_set_away (t_irc_server *server, char *nick, int is_away)
void
server_print_log (t_irc_server *server)
{
- wee_log_printf ("[server %s (addr:0x%X)]\n", server->name, server);
- wee_log_printf (" autoconnect . . . . : %d\n", server->autoconnect);
- wee_log_printf (" autoreconnect . . . : %d\n", server->autoreconnect);
- wee_log_printf (" autoreconnect_delay : %d\n", server->autoreconnect_delay);
- wee_log_printf (" command_line. . . . : %d\n", server->command_line);
- wee_log_printf (" address . . . . . . : '%s'\n", server->address);
- wee_log_printf (" port. . . . . . . . : %d\n", server->port);
- wee_log_printf (" ipv6. . . . . . . . : %d\n", server->ipv6);
- wee_log_printf (" ssl . . . . . . . . : %d\n", server->ssl);
- wee_log_printf (" password. . . . . . : '%s'\n",
- (server->password && server->password[0]) ? "(hidden)" : server->password);
- wee_log_printf (" nick1 . . . . . . . : '%s'\n", server->nick1);
- wee_log_printf (" nick2 . . . . . . . : '%s'\n", server->nick2);
- wee_log_printf (" nick3 . . . . . . . : '%s'\n", server->nick3);
- wee_log_printf (" username. . . . . . : '%s'\n", server->username);
- wee_log_printf (" realname. . . . . . : '%s'\n", server->realname);
- wee_log_printf (" command . . . . . . : '%s'\n",
- (server->command && server->command[0]) ? "(hidden)" : server->command);
- wee_log_printf (" command_delay . . . : %d\n", server->command_delay);
- wee_log_printf (" autojoin. . . . . . : '%s'\n", server->autojoin);
- wee_log_printf (" autorejoin. . . . . : %d\n", server->autorejoin);
- wee_log_printf (" notify_levels . . . : %s\n", server->notify_levels);
- wee_log_printf (" child_pid . . . . . : %d\n", server->child_pid);
- wee_log_printf (" child_read . . . . : %d\n", server->child_read);
- wee_log_printf (" child_write . . . . : %d\n", server->child_write);
- wee_log_printf (" sock. . . . . . . . : %d\n", server->sock);
- wee_log_printf (" is_connected. . . . : %d\n", server->is_connected);
-#ifdef HAVE_GNUTLS
- wee_log_printf(" ssl_connected . . . : %d\n", server->ssl_connected);
-#endif
- wee_log_printf (" unterminated_message: '%s'\n", server->unterminated_message);
- wee_log_printf (" nick. . . . . . . . : '%s'\n", server->nick);
- wee_log_printf (" reconnect_start . . : %ld\n", server->reconnect_start);
- wee_log_printf (" reconnect_join. . . : %d\n", server->reconnect_join);
- wee_log_printf (" is_away . . . . . . : %d\n", server->is_away);
- wee_log_printf (" away_time . . . . . : %ld\n", server->away_time);
- wee_log_printf (" lag . . . . . . . . : %d\n", server->lag);
- wee_log_printf (" lag_check_time. . . : tv_sec:%d, tv_usec:%d\n",
- server->lag_check_time.tv_sec, server->lag_check_time.tv_usec);
- wee_log_printf (" lag_next_check. . . : %ld\n", server->lag_next_check);
- wee_log_printf (" buffer. . . . . . . : 0x%X\n", server->buffer);
- wee_log_printf (" channels. . . . . . : 0x%X\n", server->channels);
- wee_log_printf (" last_channel. . . . : 0x%X\n", server->last_channel);
- wee_log_printf (" prev_server . . . . : 0x%X\n", server->prev_server);
- wee_log_printf (" next_server . . . . : 0x%X\n", server->next_server);
+ weechat_log_printf ("[server %s (addr:0x%X)]\n", server->name, server);
+ weechat_log_printf (" autoconnect . . . . : %d\n", server->autoconnect);
+ weechat_log_printf (" autoreconnect . . . : %d\n", server->autoreconnect);
+ weechat_log_printf (" autoreconnect_delay : %d\n", server->autoreconnect_delay);
+ weechat_log_printf (" command_line. . . . : %d\n", server->command_line);
+ weechat_log_printf (" address . . . . . . : '%s'\n", server->address);
+ weechat_log_printf (" port. . . . . . . . : %d\n", server->port);
+ weechat_log_printf (" ipv6. . . . . . . . : %d\n", server->ipv6);
+ weechat_log_printf (" ssl . . . . . . . . : %d\n", server->ssl);
+ weechat_log_printf (" password. . . . . . : '%s'\n",
+ (server->password && server->password[0]) ?
+ "(hidden)" : server->password);
+ weechat_log_printf (" nick1 . . . . . . . : '%s'\n", server->nick1);
+ weechat_log_printf (" nick2 . . . . . . . : '%s'\n", server->nick2);
+ weechat_log_printf (" nick3 . . . . . . . : '%s'\n", server->nick3);
+ weechat_log_printf (" username. . . . . . : '%s'\n", server->username);
+ weechat_log_printf (" realname. . . . . . : '%s'\n", server->realname);
+ weechat_log_printf (" command . . . . . . : '%s'\n",
+ (server->command && server->command[0]) ?
+ "(hidden)" : server->command);
+ weechat_log_printf (" command_delay . . . : %d\n", server->command_delay);
+ weechat_log_printf (" autojoin. . . . . . : '%s'\n", server->autojoin);
+ weechat_log_printf (" autorejoin. . . . . : %d\n", server->autorejoin);
+ weechat_log_printf (" notify_levels . . . : %s\n", server->notify_levels);
+ weechat_log_printf (" child_pid . . . . . : %d\n", server->child_pid);
+ weechat_log_printf (" child_read . . . . : %d\n", server->child_read);
+ weechat_log_printf (" child_write . . . . : %d\n", server->child_write);
+ weechat_log_printf (" sock. . . . . . . . : %d\n", server->sock);
+ weechat_log_printf (" is_connected. . . . : %d\n", server->is_connected);
+ weechat_log_printf (" ssl_connected . . . : %d\n", server->ssl_connected);
+ weechat_log_printf (" unterminated_message: '%s'\n", server->unterminated_message);
+ weechat_log_printf (" nick. . . . . . . . : '%s'\n", server->nick);
+ weechat_log_printf (" reconnect_start . . : %ld\n", server->reconnect_start);
+ weechat_log_printf (" reconnect_join. . . : %d\n", server->reconnect_join);
+ weechat_log_printf (" is_away . . . . . . : %d\n", server->is_away);
+ weechat_log_printf (" away_time . . . . . : %ld\n", server->away_time);
+ weechat_log_printf (" lag . . . . . . . . : %d\n", server->lag);
+ weechat_log_printf (" lag_check_time. . . : tv_sec:%d, tv_usec:%d\n",
+ server->lag_check_time.tv_sec,
+ server->lag_check_time.tv_usec);
+ weechat_log_printf (" lag_next_check. . . : %ld\n", server->lag_next_check);
+ weechat_log_printf (" buffer. . . . . . . : 0x%X\n", server->buffer);
+ weechat_log_printf (" channels. . . . . . : 0x%X\n", server->channels);
+ weechat_log_printf (" last_channel. . . . : 0x%X\n", server->last_channel);
+ weechat_log_printf (" prev_server . . . . : 0x%X\n", server->prev_server);
+ weechat_log_printf (" next_server . . . . : 0x%X\n", server->next_server);
}
diff --git a/src/irc/irc.h b/src/irc/irc.h
index 236353b8f..e2fdc00fb 100644
--- a/src/irc/irc.h
+++ b/src/irc/irc.h
@@ -46,61 +46,29 @@
#define PREFIX_ERROR "=!="
#define PREFIX_PLUGIN "-P-"
-#define CHANNEL_PREFIX "#&+!"
+#define DEFAULT_IRC_PORT 6667
-/* channel modes */
+/* nick types */
-#define NUM_CHANNEL_MODES 7
-#define CHANNEL_MODE_INVITE 0
-#define CHANNEL_MODE_KEY 1
-#define CHANNEL_MODE_LIMIT 2
-#define CHANNEL_MODE_MODERATED 3
-#define CHANNEL_MODE_NO_MSG_OUT 4
-#define CHANNEL_MODE_SECRET 5
-#define CHANNEL_MODE_TOPIC 6
-#define SET_CHANNEL_MODE(channel, set, mode) \
+#define NICK_CHANOWNER 1
+#define NICK_CHANADMIN 2
+#define NICK_OP 4
+#define NICK_HALFOP 8
+#define NICK_VOICE 16
+#define NICK_AWAY 32
+#define NICK_SET_FLAG(nick, set, flag) \
if (set) \
- channel->modes[mode] = channel_modes[mode]; \
+ nick->flags |= flag; \
else \
- channel->modes[mode] = ' ';
-
-#define DEFAULT_IRC_PORT 6667
-
-/* DCC types & status */
-
-#define DCC_CHAT_RECV 0 /* receiving DCC chat */
-#define DCC_CHAT_SEND 1 /* sending DCC chat */
-#define DCC_FILE_RECV 2 /* incoming DCC file */
-#define DCC_FILE_SEND 3 /* sending DCC file */
-
-#define DCC_WAITING 0 /* waiting for host answer */
-#define DCC_CONNECTING 1 /* connecting to host */
-#define DCC_ACTIVE 2 /* sending/receiving data */
-#define DCC_DONE 3 /* transfer done */
-#define DCC_FAILED 4 /* DCC failed */
-#define DCC_ABORTED 5 /* DCC aborted by user */
-
-#define DCC_IS_CHAT(type) ((type == DCC_CHAT_RECV) || (type == DCC_CHAT_SEND))
-#define DCC_IS_FILE(type) ((type == DCC_FILE_RECV) || (type == DCC_FILE_SEND))
-#define DCC_IS_RECV(type) ((type == DCC_CHAT_RECV) || (type == DCC_FILE_RECV))
-#define DCC_IS_SEND(type) ((type == DCC_CHAT_SEND) || (type == DCC_FILE_SEND))
-
-#define DCC_ENDED(status) ((status == DCC_DONE) || (status == DCC_FAILED) || \
- (status == DCC_ABORTED))
-
-/* nick types */
+ nick->flags &= 0xFFFF - flag;
typedef struct t_irc_nick t_irc_nick;
struct t_irc_nick
{
char *nick; /* nickname */
- int is_chanowner; /* chan owner? (specific to unrealircd) */
- int is_chanadmin; /* chan admin? (specific to unrealircd) */
- int is_op; /* operator privileges? */
- int is_halfop; /* half operator privileges? */
- int has_voice; /* nick has voice? */
- int is_away; /* = 1 if nick is away, otherwise 0 */
+ int flags; /* chanowner/chanadmin (unrealircd), */
+ /* op, halfop, voice, away */
int color; /* color for nickname in chat window */
t_irc_nick *prev_nick; /* link to previous nick on the channel */
t_irc_nick *next_nick; /* link to next nick on the channel */
@@ -108,11 +76,27 @@ struct t_irc_nick
/* channel types */
-typedef struct t_irc_channel t_irc_channel;
+#define CHANNEL_PREFIX "#&+!"
-#define CHAT_UNKNOWN -1
-#define CHAT_CHANNEL 0
-#define CHAT_PRIVATE 1
+#define CHANNEL_TYPE_UNKNOWN -1
+#define CHANNEL_TYPE_CHANNEL 0
+#define CHANNEL_TYPE_PRIVATE 1
+
+#define NUM_CHANNEL_MODES 7
+#define CHANNEL_MODE_INVITE 0
+#define CHANNEL_MODE_KEY 1
+#define CHANNEL_MODE_LIMIT 2
+#define CHANNEL_MODE_MODERATED 3
+#define CHANNEL_MODE_NO_MSG_OUT 4
+#define CHANNEL_MODE_SECRET 5
+#define CHANNEL_MODE_TOPIC 6
+#define CHANNEL_SET_MODE(channel, set, mode) \
+ if (set) \
+ channel->modes[mode] = channel_modes[mode]; \
+ else \
+ channel->modes[mode] = ' ';
+
+typedef struct t_irc_channel t_irc_channel;
struct t_irc_channel
{
@@ -120,7 +104,7 @@ struct t_irc_channel
void *dcc_chat; /* DCC CHAT pointer (NULL if not DCC) */
char *name; /* name of channel (exemple: "#abc") */
char *topic; /* topic of channel (host for private) */
- char modes[NUM_CHANNEL_MODES+1];/* channel modes */
+ char *modes; /* channel modes */
int limit; /* user limit (0 is limit not set) */
char *key; /* channel key (NULL if no key is set) */
int nicks_count; /* # nicks on channel (0 if dcc/pv) */
@@ -166,11 +150,10 @@ struct t_irc_server
int child_write; /* to write into child pipe */
int sock; /* socket for server (IPv4 or IPv6) */
int is_connected; /* 1 if WeeChat is connected to server */
-#ifdef HAVE_GNUTLS
int ssl_connected; /* = 1 if connected with SSL */
+#ifdef HAVE_GNUTLS
gnutls_session gnutls_sess; /* gnutls session (only if SSL is used) */
#endif
-
char *unterminated_message; /* beginning of a message in input buf */
char *nick; /* current nickname */
time_t reconnect_start; /* this time + delay = reconnect time */
@@ -221,6 +204,26 @@ struct t_irc_message
/* DCC types */
+#define DCC_CHAT_RECV 0 /* receiving DCC chat */
+#define DCC_CHAT_SEND 1 /* sending DCC chat */
+#define DCC_FILE_RECV 2 /* incoming DCC file */
+#define DCC_FILE_SEND 3 /* sending DCC file */
+
+#define DCC_WAITING 0 /* waiting for host answer */
+#define DCC_CONNECTING 1 /* connecting to host */
+#define DCC_ACTIVE 2 /* sending/receiving data */
+#define DCC_DONE 3 /* transfer done */
+#define DCC_FAILED 4 /* DCC failed */
+#define DCC_ABORTED 5 /* DCC aborted by user */
+
+#define DCC_IS_CHAT(type) ((type == DCC_CHAT_RECV) || (type == DCC_CHAT_SEND))
+#define DCC_IS_FILE(type) ((type == DCC_FILE_RECV) || (type == DCC_FILE_SEND))
+#define DCC_IS_RECV(type) ((type == DCC_CHAT_RECV) || (type == DCC_FILE_RECV))
+#define DCC_IS_SEND(type) ((type == DCC_CHAT_SEND) || (type == DCC_FILE_SEND))
+
+#define DCC_ENDED(status) ((status == DCC_DONE) || (status == DCC_FAILED) || \
+ (status == DCC_ABORTED))
+
typedef struct t_irc_dcc t_irc_dcc;
struct t_irc_dcc
@@ -246,8 +249,9 @@ struct t_irc_dcc
unsigned long start_resume; /* start of resume (in bytes) */
time_t last_check_time; /* last time we looked at bytes sent/rcv*/
unsigned long last_check_pos; /* bytes sent/recv at last check */
- unsigned long bytes_per_sec; /* bytes per second */
time_t last_activity; /* time of last byte received/sent */
+ unsigned long bytes_per_sec; /* bytes per second */
+ unsigned long eta; /* estimated time of arrival */
t_irc_dcc *prev_dcc; /* link to previous dcc file/chat */
t_irc_dcc *next_dcc; /* link to next dcc file/chat */
};
@@ -327,7 +331,7 @@ extern int pass_proxy(int, char*, int, char*);
/* channel functions (irc-channel.c) */
-extern t_irc_channel *channel_new (t_irc_server *, int, char *, int);
+extern t_irc_channel *channel_new (t_irc_server *, int, char *);
extern void channel_free (t_irc_server *, t_irc_channel *);
extern void channel_free_all (t_irc_server *);
extern t_irc_channel *channel_search (t_irc_server *, char *);
@@ -345,7 +349,8 @@ extern void channel_print_log (t_irc_channel *);
/* nick functions (irc-nick.c) */
extern int nick_find_color (t_irc_nick *);
-extern t_irc_nick *nick_new (t_irc_channel *, char *, int, int, int, int, int);
+extern t_irc_nick *nick_new (t_irc_server *, t_irc_channel *, char *,
+ int, int, int, int, int);
extern void nick_resort (t_irc_channel *, t_irc_nick *);
extern void nick_change (t_irc_channel *, t_irc_nick *, char *);
extern void nick_free (t_irc_channel *, t_irc_nick *);
@@ -364,12 +369,14 @@ extern void dcc_close (t_irc_dcc *, int);
extern void dcc_accept (t_irc_dcc *);
extern void dcc_accept_resume (t_irc_server *, char *, int, unsigned long);
extern void dcc_start_resume (t_irc_server *, char *, int, unsigned long);
+extern t_irc_dcc *dcc_alloc ();
extern t_irc_dcc *dcc_add (t_irc_server *, int, unsigned long, int, char *, int,
char *, char *, unsigned long);
extern void dcc_send_request (t_irc_server *, int, char *, char *);
extern void dcc_chat_sendf (t_irc_dcc *, char *, ...);
extern void dcc_handle ();
extern void dcc_end ();
+extern void dcc_print_log (t_irc_dcc *);
/* IRC display (irc-diplay.c) */