summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/irc/CMakeLists.txt9
-rw-r--r--src/plugins/irc/Makefile.am41
-rw-r--r--src/plugins/irc/irc-buffer.c209
-rw-r--r--src/plugins/irc/irc-buffer.h49
-rw-r--r--src/plugins/irc/irc-channel.c83
-rw-r--r--src/plugins/irc/irc-channel.h64
-rw-r--r--src/plugins/irc/irc-color.c359
-rw-r--r--src/plugins/irc/irc-color.h54
-rw-r--r--src/plugins/irc/irc-command.c3897
-rw-r--r--src/plugins/irc/irc-command.h91
-rw-r--r--src/plugins/irc/irc-commands.c514
-rw-r--r--src/plugins/irc/irc-config.c883
-rw-r--r--src/plugins/irc/irc-config.h81
-rw-r--r--src/plugins/irc/irc-core.c181
-rw-r--r--src/plugins/irc/irc-dcc.c576
-rw-r--r--src/plugins/irc/irc-dcc.h112
-rw-r--r--src/plugins/irc/irc-display.c400
-rw-r--r--src/plugins/irc/irc-ignore.c440
-rw-r--r--src/plugins/irc/irc-input.c200
-rw-r--r--src/plugins/irc/irc-log.c139
-rw-r--r--src/plugins/irc/irc-mode.c28
-rw-r--r--src/plugins/irc/irc-nick.c287
-rw-r--r--src/plugins/irc/irc-nick.h52
-rw-r--r--src/plugins/irc/irc-protocol.c5274
-rw-r--r--src/plugins/irc/irc-protocol.h35
-rw-r--r--src/plugins/irc/irc-recv.c5058
-rw-r--r--src/plugins/irc/irc-send.c2281
-rw-r--r--src/plugins/irc/irc-server.c531
-rw-r--r--src/plugins/irc/irc-server.h144
-rw-r--r--src/plugins/irc/irc.h783
30 files changed, 13111 insertions, 9744 deletions
diff --git a/src/plugins/irc/CMakeLists.txt b/src/plugins/irc/CMakeLists.txt
index 1942e6ceb..3331c6819 100644
--- a/src/plugins/irc/CMakeLists.txt
+++ b/src/plugins/irc/CMakeLists.txt
@@ -14,12 +14,15 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-SET(LIB_IRC_SRC irc.h irc-commands.c irc-send.c irc-recv.c irc-server.c
-irc-channel.c irc-nick.c irc-mode.c irc-dcc.c irc-ignore.c irc-display.c)
+SET(LIB_PROTOCOL_IRC_SRC irc.h irc-buffer.c irc-buffer.h irc-channel.c
+irc-channel.h irc-command.c irc-command.h irc-color.c irc-color.h irc-config.c
+irc-config.h irc-core.c irc-dcc.c irc-dcc.h irc-display.c irc-input.c irc-log.c
+irc-mode.c irc-nick.c irc-nick.h irc-protocol.c irc-protocol.h irc-server.c
+irc-server.h)
CHECK_INCLUDE_FILES("regex.h" HAVE_REGEX_H)
CHECK_FUNCTION_EXISTS(regexec HAVE_REGEXEC)
CHECK_FUNCTION_EXISTS(uname HAVE_UNAME)
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR})
-ADD_LIBRARY(weechat_irc STATIC ${LIB_IRC_SRC})
+ADD_LIBRARY(weechat_protocol_irc STATIC ${LIB_PROTOCOL_IRC_SRC})
diff --git a/src/plugins/irc/Makefile.am b/src/plugins/irc/Makefile.am
index 2670aca85..4d63188e7 100644
--- a/src/plugins/irc/Makefile.am
+++ b/src/plugins/irc/Makefile.am
@@ -16,16 +16,33 @@
INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(GNUTLS_CFLAGS)
-noinst_LIBRARIES = lib_weechat_irc.a
+libdir = ${weechat_libdir}/plugins
-lib_weechat_irc_a_SOURCES = irc.h \
- irc-commands.c \
- irc-send.c \
- irc-recv.c \
- irc-server.c \
- irc-channel.c \
- irc-nick.c \
- irc-mode.c \
- irc-dcc.c \
- irc-ignore.c \
- irc-display.c
+lib_LTLIBRARIES = irc.la
+
+irc_la_SOURCES = irc.h \
+ irc-buffer.c \
+ irc-buffer.h \
+ irc-channel.c \
+ irc-channel.h \
+ irc-command.c \
+ irc-command.h \
+ irc-color.c \
+ irc-color.h \
+ irc-config.c \
+ irc-config.h \
+ irc-core.c \
+ irc-dcc.c \
+ irc-dcc.h \
+ irc-display.c \
+ irc-input.c \
+ irc-log.c \
+ irc-mode.c \
+ irc-nick.c \
+ irc-nick.h \
+ irc-protocol.c \
+ irc-protocol.h \
+ irc-server.c \
+ irc-server.h
+irc_la_LDFLAGS = -module
+irc_la_LIBADD = $(GNUTLS_LFLAGS)
diff --git a/src/plugins/irc/irc-buffer.c b/src/plugins/irc/irc-buffer.c
new file mode 100644
index 000000000..2e174ca20
--- /dev/null
+++ b/src/plugins/irc/irc-buffer.c
@@ -0,0 +1,209 @@
+/*
+ * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/* irc-buffer.c: manages buffers for IRC protocol */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "../../core/weechat.h"
+#include "irc.h"
+#include "../../core/utf8.h"
+#include "../../core/weechat-config.h"
+#include "../../gui/gui.h"
+
+
+/*
+ * irc_buffer_data_create: create protocol data (for GUI buffer)
+ */
+
+t_irc_buffer_data *
+irc_buffer_data_create (t_irc_server *server)
+{
+ t_irc_buffer_data *buffer_data;
+
+ buffer_data = (t_irc_buffer_data *)malloc (sizeof (t_irc_buffer_data));
+ if (!buffer_data)
+ return NULL;
+
+ buffer_data->server = server;
+ buffer_data->channel = NULL;
+ buffer_data->all_servers = irc_cfg_irc_one_server_buffer;
+
+ return buffer_data;
+}
+
+/*
+ * irc_buffer_data_free: free protocol data (in GUI buffer)
+ */
+
+void
+irc_buffer_data_free (t_gui_buffer *buffer)
+{
+ free ((t_irc_buffer_data *)buffer->protocol_data);
+}
+
+/*
+ * irc_buffer_servers_search: search servers buffer
+ * (when same buffer is used for all servers)
+ */
+
+t_gui_buffer *
+irc_buffer_servers_search ()
+{
+ t_gui_buffer *ptr_buffer;
+
+ for (ptr_buffer = gui_buffers; ptr_buffer;
+ ptr_buffer = ptr_buffer->next_buffer)
+ {
+ if (IRC_BUFFER_ALL_SERVERS(ptr_buffer))
+ return ptr_buffer;
+
+ }
+
+ /* buffer not found */
+ return NULL;
+}
+
+/*
+ * irc_buffer_merge_servers: merge server buffers in one buffer
+ */
+
+void
+irc_buffer_merge_servers (t_gui_window *window)
+{
+ t_gui_buffer *ptr_buffer_server, *ptr_buffer, *new_ptr_buffer;
+ t_irc_server *ptr_server;
+
+ /* new server buffer is the first server buffer found */
+ for (ptr_buffer_server = gui_buffers; ptr_buffer_server;
+ ptr_buffer_server = ptr_buffer_server->next_buffer)
+ {
+ if ((ptr_buffer_server->protocol == irc_protocol)
+ && (IRC_BUFFER_SERVER(ptr_buffer_server))
+ && (!IRC_BUFFER_CHANNEL(ptr_buffer_server)))
+ break;
+ }
+
+ /* no server buffer found */
+ if (!ptr_buffer_server)
+ return;
+
+ ptr_buffer = gui_buffers;
+ while (ptr_buffer)
+ {
+ if ((ptr_buffer->protocol == irc_protocol)
+ && (ptr_buffer != ptr_buffer_server)
+ && (IRC_BUFFER_SERVER(ptr_buffer))
+ && (!IRC_BUFFER_CHANNEL(ptr_buffer)))
+ {
+ ptr_server = IRC_BUFFER_SERVER(ptr_buffer);
+
+ /* add (by pointer artefact) lines from buffer found to server buffer */
+ if (ptr_buffer->lines)
+ {
+ if (ptr_buffer_server->lines)
+ {
+ ptr_buffer->lines->prev_line =
+ ptr_buffer_server->last_line;
+ ptr_buffer_server->last_line->next_line =
+ ptr_buffer->lines;
+ ptr_buffer_server->last_line =
+ ptr_buffer->last_line;
+ }
+ else
+ {
+ ptr_buffer_server->lines = ptr_buffer->lines;
+ ptr_buffer_server->last_line = ptr_buffer->last_line;
+ }
+ }
+
+ /* free buffer but not lines, because they're now used by
+ our unique server buffer */
+ new_ptr_buffer = ptr_buffer->next_buffer;
+ ptr_buffer->lines = NULL;
+ gui_buffer_free (ptr_buffer, 1);
+ ptr_buffer = new_ptr_buffer;
+
+ /* asociate server with new server buffer */
+ ptr_server->buffer = ptr_buffer_server;
+ }
+ else
+ ptr_buffer = ptr_buffer->next_buffer;
+ }
+
+ IRC_BUFFER_ALL_SERVERS(ptr_buffer_server) = 1;
+ gui_window_redraw_buffer (window->buffer);
+}
+
+/*
+ * irc_buffer_split_server: split the server buffer into many buffers (one by server)
+ */
+
+void
+irc_buffer_split_server (t_gui_window *window)
+{
+ t_gui_buffer *ptr_buffer;
+ t_irc_server *ptr_server;
+ char *log_filename;
+
+ ptr_buffer = gui_buffer_servers_search ();
+
+ if (ptr_buffer)
+ {
+ if (IRC_BUFFER_SERVER(ptr_buffer))
+ {
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ if (ptr_server->buffer
+ && (ptr_server != IRC_BUFFER_SERVER(ptr_buffer))
+ && (ptr_server->buffer == ptr_buffer))
+ {
+ ptr_server->buffer = NULL;
+ log_filename = irc_log_get_filename (ptr_server->name,
+ NULL,
+ 0);
+ gui_buffer_new (window, 0,
+ ptr_server->name,
+ ptr_server->name,
+ GUI_BUFFER_ATTRIB_TEXT |
+ GUI_BUFFER_ATTRIB_INPUT |
+ GUI_BUFFER_ATTRIB_NICKS,
+ irc_protocol,
+ irc_buffer_data_create (ptr_server),
+ &irc_buffer_data_free,
+ GUI_NOTIFY_LEVEL_DEFAULT,
+ NULL, ptr_server->nick,
+ irc_cfg_log_auto_server, log_filename,
+ 0);
+ if (log_filename)
+ free (log_filename);
+ }
+ }
+ }
+ IRC_BUFFER_ALL_SERVERS(ptr_buffer) = 0;
+ gui_status_draw (window->buffer, 1);
+ gui_input_draw (window->buffer, 1);
+ }
+}
diff --git a/src/plugins/irc/irc-buffer.h b/src/plugins/irc/irc-buffer.h
new file mode 100644
index 000000000..d2731b2e3
--- /dev/null
+++ b/src/plugins/irc/irc-buffer.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __WEECHAT_IRC_BUFFER_H
+#define __WEECHAT_IRC_BUFFER_H 1
+
+#include "irc-server.h"
+#include "irc-channel.h"
+
+#define IRC_BUFFER_SERVER(buffer) (((t_irc_buffer_data *)(buffer->protocol_data))->server)
+#define IRC_BUFFER_CHANNEL(buffer) (((t_irc_buffer_data *)(buffer->protocol_data))->channel)
+#define IRC_BUFFER_ALL_SERVERS(buffer) (((t_irc_buffer_data *)(buffer->protocol_data))->all_servers)
+
+#define IRC_BUFFER_GET_SERVER(buffer) \
+ t_irc_server *ptr_server = IRC_BUFFER_SERVER(buffer)
+#define IRC_BUFFER_GET_CHANNEL(buffer) \
+ t_irc_channel *ptr_channel = IRC_BUFFER_CHANNEL(buffer)
+#define IRC_BUFFER_GET_SERVER_CHANNEL(buffer) \
+ t_irc_server *ptr_server = IRC_BUFFER_SERVER(buffer); \
+ t_irc_channel *ptr_channel = IRC_BUFFER_CHANNEL(buffer)
+
+/* protocol data for GUI buffers */
+
+typedef struct t_irc_buffer_data t_irc_buffer_data;
+
+struct t_irc_buffer_data
+{
+ t_irc_server *server;
+ t_irc_channel *channel;
+ int all_servers;
+};
+
+#endif /* irc-buffer.h */
diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c
index ab5dfa63d..262ccd6f3 100644
--- a/src/plugins/irc/irc-channel.c
+++ b/src/plugins/irc/irc-channel.c
@@ -27,24 +27,28 @@
#include <unistd.h>
#include <string.h>
-#include "../../common/weechat.h"
+#include "../../core/weechat.h"
#include "irc.h"
-#include "../../common/log.h"
-#include "../../common/utf8.h"
-#include "../../common/util.h"
-#include "../../common/weeconfig.h"
+#include "../../core/log.h"
+#include "../../core/utf8.h"
+#include "../../core/util.h"
+#include "../../core/weechat-config.h"
#include "../../gui/gui.h"
/*
- * irc_channel_new: allocate a new channel for a server and add it to the
- * server queue
+ * irc_channel_new: allocate a new channel for a server and add it to servers
+ * list
*/
t_irc_channel *
-irc_channel_new (t_irc_server *server, int channel_type, char *channel_name)
+irc_channel_new (t_irc_server *server, int channel_type, char *channel_name,
+ int switch_to_channel)
{
t_irc_channel *new_channel;
+ t_gui_buffer *new_buffer;
+ int attribs, log_buffer;
+ char *log_filename;
/* alloc memory for new channel */
if ((new_channel = (t_irc_channel *) malloc (sizeof (t_irc_channel))) == NULL)
@@ -53,6 +57,40 @@ irc_channel_new (t_irc_server *server, int channel_type, char *channel_name)
return NULL;
}
+ log_buffer = 0;
+ attribs = GUI_BUFFER_ATTRIB_TEXT | GUI_BUFFER_ATTRIB_INPUT |
+ GUI_BUFFER_ATTRIB_NICKS;
+ switch (channel_type)
+ {
+ case IRC_CHANNEL_TYPE_CHANNEL:
+ if (irc_cfg_log_auto_channel)
+ log_buffer = 1;
+ attribs |= GUI_BUFFER_ATTRIB_NICKLIST;
+ break;
+ case IRC_CHANNEL_TYPE_PRIVATE:
+ case IRC_CHANNEL_TYPE_DCC_CHAT:
+ if (irc_cfg_log_auto_private)
+ log_buffer = 1;
+ break;
+ }
+
+ log_filename = irc_log_get_filename (server->name, channel_name,
+ (channel_type == IRC_CHANNEL_TYPE_DCC_CHAT));
+ new_buffer = gui_buffer_new (gui_current_window, 0,
+ server->name, channel_name,
+ attribs,
+ irc_protocol,
+ irc_buffer_data_create (server),
+ &irc_buffer_data_free,
+ GUI_NOTIFY_LEVEL_DEFAULT,
+ channel_name, server->nick,
+ log_buffer, log_filename,
+ switch_to_channel);
+ if (log_filename)
+ free (log_filename);
+ if (!new_buffer)
+ return NULL;
+
/* initialize new channel */
new_channel->type = channel_type;
new_channel->dcc_chat = NULL;
@@ -70,11 +108,14 @@ irc_channel_new (t_irc_server *server, int channel_type, char *channel_name)
new_channel->nick_completion_reset = 0;
new_channel->nicks = NULL;
new_channel->last_nick = NULL;
- new_channel->buffer = NULL;
+ new_channel->buffer = new_buffer;
new_channel->nicks_speaking = NULL;
new_channel->last_nick_speaking = NULL;
- /* add new channel to queue */
+ IRC_BUFFER_CHANNEL(new_buffer) = new_channel;
+ new_buffer->notify_level = irc_channel_get_notify_level (server, new_channel);
+
+ /* add new channel to channels list */
new_channel->prev_channel = server->last_channel;
new_channel->next_channel = NULL;
if (server->channels)
@@ -88,7 +129,7 @@ irc_channel_new (t_irc_server *server, int channel_type, char *channel_name)
}
/*
- * irc_channel_free: free a channel and remove it from channels queue
+ * irc_channel_free: free a channel and remove it from channels list
*/
void
@@ -110,7 +151,7 @@ irc_channel_free (t_irc_server *server, t_irc_channel *channel)
}
}
- /* remove channel from queue */
+ /* remove channel from channels list */
if (server->last_channel == channel)
server->last_channel = channel->prev_channel;
if (channel->prev_channel)
@@ -172,7 +213,7 @@ irc_channel_search (t_irc_server *server, char *channel_name)
ptr_channel = ptr_channel->next_channel)
{
if ((ptr_channel->type != IRC_CHANNEL_TYPE_DCC_CHAT)
- && (ascii_strcasecmp (ptr_channel->name, channel_name) == 0))
+ && (weechat_strcasecmp (ptr_channel->name, channel_name) == 0))
return ptr_channel;
}
return NULL;
@@ -193,7 +234,7 @@ irc_channel_search_any (t_irc_server *server, char *channel_name)
for (ptr_channel = server->channels; ptr_channel;
ptr_channel = ptr_channel->next_channel)
{
- if (ascii_strcasecmp (ptr_channel->name, channel_name) == 0)
+ if (weechat_strcasecmp (ptr_channel->name, channel_name) == 0)
return ptr_channel;
}
return NULL;
@@ -216,7 +257,7 @@ irc_channel_search_any_without_buffer (t_irc_server *server, char *channel_name)
ptr_channel = ptr_channel->next_channel)
{
if (!ptr_channel->buffer
- && (ascii_strcasecmp (ptr_channel->name, channel_name) == 0))
+ && (weechat_strcasecmp (ptr_channel->name, channel_name) == 0))
return ptr_channel;
}
return NULL;
@@ -238,7 +279,7 @@ irc_channel_search_dcc (t_irc_server *server, char *channel_name)
ptr_channel = ptr_channel->next_channel)
{
if ((ptr_channel->type == IRC_CHANNEL_TYPE_DCC_CHAT)
- && (ascii_strcasecmp (ptr_channel->name, channel_name) == 0))
+ && (weechat_strcasecmp (ptr_channel->name, channel_name) == 0))
return ptr_channel;
}
return NULL;
@@ -289,8 +330,8 @@ irc_channel_check_away (t_irc_server *server, t_irc_channel *channel, int force)
{
if (channel->type == IRC_CHANNEL_TYPE_CHANNEL)
{
- if (force || (cfg_irc_away_check_max_nicks == 0) ||
- (channel->nicks_count <= cfg_irc_away_check_max_nicks))
+ if (force || (irc_cfg_irc_away_check_max_nicks == 0) ||
+ (channel->nicks_count <= irc_cfg_irc_away_check_max_nicks))
{
channel->checking_away++;
irc_server_sendf (server, "WHO %s", channel->name);
@@ -331,11 +372,9 @@ irc_channel_create_dcc (t_irc_dcc *ptr_dcc)
{
ptr_channel = irc_channel_new (ptr_dcc->server,
IRC_CHANNEL_TYPE_DCC_CHAT,
- ptr_dcc->nick);
+ ptr_dcc->nick, 0);
if (!ptr_channel)
return 0;
- gui_buffer_new (gui_current_window, ptr_dcc->server, ptr_channel,
- GUI_BUFFER_TYPE_STANDARD, 0);
}
if (ptr_channel->dcc_chat &&
@@ -452,7 +491,7 @@ irc_channel_print_log (t_irc_channel *channel)
weechat_log_printf (" away_message . . . . : '%s'\n", channel->away_message);
weechat_log_printf (" cycle. . . . . . . . : %d\n", channel->cycle);
weechat_log_printf (" close. . . . . . . . : %d\n", channel->close);
- weechat_log_printf (" display_creation_date: %d\n", channel->close);
+ weechat_log_printf (" display_creation_date: %d\n", channel->display_creation_date);
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);
diff --git a/src/plugins/irc/irc-channel.h b/src/plugins/irc/irc-channel.h
new file mode 100644
index 000000000..9849890fc
--- /dev/null
+++ b/src/plugins/irc/irc-channel.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __WEECHAT_IRC_CHANNEL_H
+#define __WEECHAT_IRC_CHANNEL_H 1
+
+#include "irc-nick.h"
+#include "../../gui/gui.h"
+
+#define IRC_CHANNEL_PREFIX "#&+!"
+
+/* channel types */
+#define IRC_CHANNEL_TYPE_UNKNOWN -1
+#define IRC_CHANNEL_TYPE_CHANNEL 0
+#define IRC_CHANNEL_TYPE_PRIVATE 1
+#define IRC_CHANNEL_TYPE_DCC_CHAT 2
+
+#define IRC_CHANNEL_NICKS_SPEAKING_LIMIT 32
+
+typedef struct t_irc_channel t_irc_channel;
+
+struct t_irc_channel
+{
+ int type; /* channel type */
+ 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; /* 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) */
+ int checking_away; /* = 1 if checking away with WHO cmd */
+ char *away_message; /* to display away only once in private */
+ int cycle; /* currently cycling (/part then /join) */
+ int close; /* close request (/buffer close) */
+ int display_creation_date; /* 1 if creation date should be displayed*/
+ int nick_completion_reset; /* 1 if nick completion should be rebuilt*/
+ /* there was some join/part on channel */
+ t_irc_nick *nicks; /* nicks on the channel */
+ t_irc_nick *last_nick; /* last nick on the channel */
+ t_weelist *nicks_speaking; /* nicks speaking (for smart completion) */
+ t_weelist *last_nick_speaking; /* last nick speaking */
+ t_gui_buffer *buffer; /* GUI buffer allocated for channel */
+ t_irc_channel *prev_channel; /* link to previous channel */
+ t_irc_channel *next_channel; /* link to next channel */
+};
+
+#endif /* irc-channel.h */
diff --git a/src/plugins/irc/irc-color.c b/src/plugins/irc/irc-color.c
new file mode 100644
index 000000000..193b4a15f
--- /dev/null
+++ b/src/plugins/irc/irc-color.c
@@ -0,0 +1,359 @@
+/*
+ * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/* irc-color.c: IRC color decoding/encidong in messages */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "../../core/weechat.h"
+#include "irc-color.h"
+#include "../../gui/gui.h"
+
+
+/*
+ * irc_color_decode: parses a message (coming from IRC server),
+ * if keep_colors == 0: remove any color/style in message
+ * otherwise change colors by internal WeeChat color codes
+ * if keep_eechat_attr == 0: remove any weechat color/style attribute
+ * After use, string returned has to be free()
+ */
+
+unsigned char *
+irc_color_decode (unsigned char *string, int keep_irc_colors, int keep_weechat_attr)
+{
+ /*unsigned char *out;
+ int out_length, out_pos, length;
+ char str_fg[3], str_bg[3];
+ int fg, bg, attr;*/
+
+ (void) string;
+ (void) keep_irc_colors;
+ (void) keep_weechat_attr;
+
+ return NULL;
+
+ /*out_length = (strlen ((char *)string) * 2) + 1;
+ out = (unsigned char *)malloc (out_length);
+ if (!out)
+ return NULL;
+
+ out_pos = 0;
+ while (string && string[0] && (out_pos < out_length - 1))
+ {
+ switch (string[0])
+ {
+ case IRC_COLOR_BOLD_CHAR:
+ case IRC_COLOR_RESET_CHAR:
+ case IRC_COLOR_FIXED_CHAR:
+ case IRC_COLOR_REVERSE_CHAR:
+ case IRC_COLOR_REVERSE2_CHAR:
+ case IRC_COLOR_ITALIC_CHAR:
+ case IRC_COLOR_UNDERLINE_CHAR:
+ if (keep_irc_colors)
+ out[out_pos++] = string[0];
+ string++;
+ break;
+ case IRC_COLOR_COLOR_CHAR:
+ string++;
+ str_fg[0] = '\0';
+ str_bg[0] = '\0';
+ if (isdigit (string[0]))
+ {
+ str_fg[0] = string[0];
+ str_fg[1] = '\0';
+ string++;
+ if (isdigit (string[0]))
+ {
+ str_fg[1] = string[0];
+ str_fg[2] = '\0';
+ string++;
+ }
+ }
+ if (string[0] == ',')
+ {
+ string++;
+ if (isdigit (string[0]))
+ {
+ str_bg[0] = string[0];
+ str_bg[1] = '\0';
+ string++;
+ if (isdigit (string[0]))
+ {
+ str_bg[1] = string[0];
+ str_bg[2] = '\0';
+ string++;
+ }
+ }
+ }
+ if (keep_irc_colors)
+ {
+ if (!str_fg[0] && !str_bg[0])
+ out[out_pos++] = IRC_COLOR_COLOR_CHAR;
+ else
+ {
+ attr = 0;
+ if (str_fg[0])
+ {
+ sscanf (str_fg, "%d", &fg);
+ fg %= GUI_NUM_IRC_COLORS;
+ attr |= gui_irc_colors[fg][1];
+ }
+ if (str_bg[0])
+ {
+ sscanf (str_bg, "%d", &bg);
+ bg %= GUI_NUM_IRC_COLORS;
+ attr |= gui_irc_colors[bg][1];
+ }
+ if (attr & A_BOLD)
+ {
+ out[out_pos++] = GUI_ATTR_WEECHAT_SET_CHAR;
+ out[out_pos++] = IRC_COLOR_BOLD_CHAR;
+ }
+ else
+ {
+ out[out_pos++] = GUI_ATTR_WEECHAT_REMOVE_CHAR;
+ out[out_pos++] = IRC_COLOR_BOLD_CHAR;
+ }
+ out[out_pos++] = IRC_COLOR_COLOR_CHAR;
+ if (str_fg[0])
+ {
+ out[out_pos++] = (gui_irc_colors[fg][0] / 10) + '0';
+ out[out_pos++] = (gui_irc_colors[fg][0] % 10) + '0';
+ }
+ if (str_bg[0])
+ {
+ out[out_pos++] = ',';
+ out[out_pos++] = (gui_irc_colors[bg][0] / 10) + '0';
+ out[out_pos++] = (gui_irc_colors[bg][0] % 10) + '0';
+ }
+ }
+ }
+ break;
+ case GUI_ATTR_WEECHAT_COLOR_CHAR:
+ if (keep_weechat_attr)
+ out[out_pos++] = string[0];
+ string++;
+ if (isdigit (string[0]) && isdigit (string[1]))
+ {
+ if (keep_weechat_attr)
+ {
+ out[out_pos++] = string[0];
+ out[out_pos++] = string[1];
+ }
+ string += 2;
+ }
+ break;
+ case GUI_ATTR_WEECHAT_SET_CHAR:
+ case GUI_ATTR_WEECHAT_REMOVE_CHAR:
+ if (keep_weechat_attr)
+ out[out_pos++] = string[0];
+ string++;
+ if (string[0])
+ {
+ if (keep_weechat_attr)
+ out[out_pos++] = string[0];
+ string++;
+ }
+ break;
+ case GUI_ATTR_WEECHAT_RESET_CHAR:
+ if (keep_weechat_attr)
+ out[out_pos++] = string[0];
+ string++;
+ break;
+ default:
+ length = utf8_char_size ((char *)string);
+ if (length == 0)
+ length = 1;
+ memcpy (out + out_pos, string, length);
+ out_pos += length;
+ string += length;
+ }
+ }
+ out[out_pos] = '\0';
+ return out;*/
+}
+
+/*
+ * irc_color_decode_for_user_entry: parses a message (coming from IRC server),
+ * and replaces colors/bold/.. by ^C, ^B, ..
+ * After use, string returned has to be free()
+ */
+
+unsigned char *
+irc_color_decode_for_user_entry (unsigned char *string)
+{
+ /*unsigned char *out;
+ int out_length, out_pos, length;*/
+
+ (void) string;
+
+ return NULL;
+
+ /*out_length = (strlen ((char *)string) * 2) + 1;
+ out = (unsigned char *)malloc (out_length);
+ if (!out)
+ return NULL;
+
+ out_pos = 0;
+ while (string && string[0] && (out_pos < out_length - 1))
+ {
+ switch (string[0])
+ {
+ case IRC_COLOR_BOLD_CHAR:
+ out[out_pos++] = 0x02; // ^B
+ string++;
+ break;
+ case IRC_COLOR_FIXED_CHAR:
+ string++;
+ break;
+ case IRC_COLOR_RESET_CHAR:
+ out[out_pos++] = 0x0F; // ^O
+ string++;
+ break;
+ case IRC_COLOR_REVERSE_CHAR:
+ case IRC_COLOR_REVERSE2_CHAR:
+ out[out_pos++] = 0x12; // ^R
+ string++;
+ break;
+ case IRC_COLOR_ITALIC_CHAR:
+ string++;
+ break;
+ case IRC_COLOR_UNDERLINE_CHAR:
+ out[out_pos++] = 0x15; // ^U
+ string++;
+ break;
+ case IRC_COLOR_COLOR_CHAR:
+ out[out_pos++] = 0x03; // ^C
+ string++;
+ break;
+ default:
+ length = utf8_char_size ((char *)string);
+ if (length == 0)
+ length = 1;
+ memcpy (out + out_pos, string, length);
+ out_pos += length;
+ string += length;
+ }
+ }
+ out[out_pos] = '\0';
+ return out;*/
+}
+
+/*
+ * irc_color_encode: parses a message (entered by user), and
+ * encode special chars (^Cb, ^Cc, ..) in IRC colors
+ * if keep_colors == 0: remove any color/style in message
+ * otherwise: keep colors
+ * After use, string returned has to be free()
+ */
+
+unsigned char *
+irc_color_encode (unsigned char *string, int keep_colors)
+{
+ /*unsigned char *out;
+ int out_length, out_pos, length;*/
+
+ (void) string;
+ (void) keep_colors;
+
+ return NULL;
+
+ /*out_length = (strlen ((char *)string) * 2) + 1;
+ out = (unsigned char *)malloc (out_length);
+ if (!out)
+ return NULL;
+
+ out_pos = 0;
+ while (string && string[0] && (out_pos < out_length - 1))
+ {
+ switch (string[0])
+ {
+ case 0x02: // ^B
+ if (keep_colors)
+ out[out_pos++] = IRC_COLOR_BOLD_CHAR;
+ string++;
+ break;
+ case 0x03: // ^C
+ if (keep_colors)
+ out[out_pos++] = IRC_COLOR_COLOR_CHAR;
+ string++;
+ if (isdigit (string[0]))
+ {
+ if (keep_colors)
+ out[out_pos++] = string[0];
+ string++;
+ if (isdigit (string[0]))
+ {
+ if (keep_colors)
+ out[out_pos++] = string[0];
+ string++;
+ }
+ }
+ if (string[0] == ',')
+ {
+ if (keep_colors)
+ out[out_pos++] = ',';
+ string++;
+ if (isdigit (string[0]))
+ {
+ if (keep_colors)
+ out[out_pos++] = string[0];
+ string++;
+ if (isdigit (string[0]))
+ {
+ if (keep_colors)
+ out[out_pos++] = string[0];
+ string++;
+ }
+ }
+ }
+ break;
+ case 0x0F: // ^O
+ if (keep_colors)
+ out[out_pos++] = IRC_COLOR_RESET_CHAR;
+ string++;
+ break;
+ case 0x12: // ^R
+ if (keep_colors)
+ out[out_pos++] = IRC_COLOR_REVERSE_CHAR;
+ string++;
+ break;
+ case 0x15: // ^U
+ if (keep_colors)
+ out[out_pos++] = IRC_COLOR_UNDERLINE_CHAR;
+ string++;
+ break;
+ default:
+ length = utf8_char_size ((char *)string);
+ if (length == 0)
+ length = 1;
+ memcpy (out + out_pos, string, length);
+ out_pos += length;
+ string += length;
+ }
+ }
+ out[out_pos] = '\0';
+ return out;*/
+}
diff --git a/src/plugins/irc/irc-color.h b/src/plugins/irc/irc-color.h
new file mode 100644
index 000000000..7b153595c
--- /dev/null
+++ b/src/plugins/irc/irc-color.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __WEECHAT_IRC_COLOR_H
+#define __WEECHAT_IRC_COLOR_H 1
+
+/* shift ncurses colors for compatibility with colors
+ in IRC messages (same as other IRC clients) */
+
+#define WEECHAT_COLOR_BLACK COLOR_BLACK
+#define WEECHAT_COLOR_RED COLOR_BLUE
+#define WEECHAT_COLOR_GREEN COLOR_GREEN
+#define WEECHAT_COLOR_YELLOW COLOR_CYAN
+#define WEECHAT_COLOR_BLUE COLOR_RED
+#define WEECHAT_COLOR_MAGENTA COLOR_MAGENTA
+#define WEECHAT_COLOR_CYAN COLOR_YELLOW
+#define WEECHAT_COLOR_WHITE COLOR_WHITE
+
+/* attributes in IRC messages for color & style (bold, ..) */
+
+#define IRC_COLOR_BOLD_CHAR '\x02'
+#define IRC_COLOR_BOLD_STR "\x02"
+#define IRC_COLOR_COLOR_CHAR '\x03'
+#define IRC_COLOR_COLOR_STR "\x03"
+#define IRC_COLOR_RESET_CHAR '\x0F'
+#define IRC_COLOR_RESET_STR "\x0F"
+#define IRC_COLOR_FIXED_CHAR '\x11'
+#define IRC_COLOR_FIXED_STR "\x11"
+#define IRC_COLOR_REVERSE_CHAR '\x12'
+#define IRC_COLOR_REVERSE_STR "\x12"
+#define IRC_COLOR_REVERSE2_CHAR '\x16'
+#define IRC_COLOR_REVERSE2_STR "\x16"
+#define IRC_COLOR_ITALIC_CHAR '\x1D'
+#define IRC_COLOR_ITALIC_STR "\x1D"
+#define IRC_COLOR_UNDERLINE_CHAR '\x1F'
+#define IRC_COLOR_UNDERLINE_STR "\x1F"
+
+#endif /* irc-color.h */
diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c
new file mode 100644
index 000000000..528bdda31
--- /dev/null
+++ b/src/plugins/irc/irc-command.c
@@ -0,0 +1,3897 @@
+/*
+ * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/* irc-command.c: IRC commands managment */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "../../core/weechat.h"
+#include "irc.h"
+#include "../../core/command.h"
+#include "../../core/util.h"
+#include "../../core/weechat-config.h"
+#include "../../gui/gui.h"
+
+
+t_weechat_command irc_commands[] =
+{ { "admin", N_("find information about the administrator of the server"),
+ N_("[target]"),
+ N_("target: server"),
+ NULL, 0, 1, 0, irc_cmd_admin },
+ { "ame", N_("send a CTCP action to all channels of all connected servers"),
+ N_("message"),
+ N_("message: message to send"),
+ "", 1, MAX_ARGS, 1, irc_cmd_ame },
+ { "amsg", N_("send message to all channels of all connected servers"),
+ N_("text"),
+ N_("text: text to send"),
+ "", 1, MAX_ARGS, 1, irc_cmd_amsg },
+ { "away", N_("toggle away status"),
+ N_("[-all] [message]"),
+ N_(" -all: toggle away status on all connected servers\n"
+ "message: message for away (if no message is given, away status is "
+ "removed)"),
+ "-all", 0, MAX_ARGS, 1, irc_cmd_away },
+ { "ban", N_("bans nicks or hosts"),
+ N_("[channel] [nickname [nickname ...]]"),
+ N_(" channel: channel for ban\n"
+ "nickname: user or host to ban"),
+ "%N", 0, MAX_ARGS, 0, irc_cmd_ban },
+ { "connect", N_("connect to server(s)"),
+ N_("[-all [-nojoin] | servername [servername ...] [-nojoin] | hostname "
+ "[-port port] [-ipv6] [-ssl]]"),
+ N_(" -all: connect to all servers\n"
+ "servername: internal server name to connect\n"
+ " -nojoin: do not join any channel (even if autojoin is enabled on "
+ "server)\n"
+ " hostname: hostname to connect, creating temporary server\n"
+ " port: port for server (integer, default is 6667)\n"
+ " ipv6: use IPv6 protocol\n"
+ " ssl: use SSL protocol"),
+ "%S|-all|-nojoin|%*", 0, MAX_ARGS, 0, irc_cmd_connect },
+ { "ctcp", N_("send a CTCP message (Client-To-Client Protocol)"),
+ N_("receiver type [arguments]"),
+ N_(" receiver: nick or channel to send CTCP to\n"
+ " type: CTCP type (examples: \"version\", \"ping\", ..)\n"
+ "arguments: arguments for CTCP"),
+ "%c|%n action|ping|version", 2, MAX_ARGS, 1, irc_cmd_ctcp },
+ { "cycle", N_("leave and rejoin a channel"),
+ N_("[channel[,channel]] [part_message]"),
+ N_(" channel: channel name for cycle\n"
+ "part_message: part message (displayed to other users)"),
+ "%p", 0, MAX_ARGS, 0, irc_cmd_cycle },
+ { "dcc", N_("starts DCC (file or chat) or close chat"),
+ N_("action [nickname [file]]"),
+ N_(" action: 'send' (file) or 'chat' or 'close' (chat)\n"
+ "nickname: nickname to send file or chat\n"
+ " file: filename (on local host)"),
+ "chat|send|close %n %f", 1, MAX_ARGS, 0, irc_cmd_dcc },
+ { "dehalfop", N_("removes half channel operator status from nickname(s)"),
+ N_("[nickname [nickname]]"), "",
+ "", 0, MAX_ARGS, 0, irc_cmd_dehalfop },
+ { "deop", N_("removes channel operator status from nickname(s)"),
+ N_("[nickname [nickname]]"), "",
+ "", 0, MAX_ARGS, 0, irc_cmd_deop },
+ { "devoice", N_("removes voice from nickname(s)"),
+ N_("[nickname [nickname]]"), "",
+ "", 0, MAX_ARGS, 0, irc_cmd_devoice },
+ { "die", N_("shutdown the server"), "", "",
+ NULL, 0, 0, 0, irc_cmd_die },
+ { "disconnect", N_("disconnect from server(s)"),
+ N_("[-all | servername [servername ...]]"),
+ N_(" -all: disconnect from all servers\n"
+ "servername: server name to disconnect"),
+ "%S|-all", 0, MAX_ARGS, 0, irc_cmd_disconnect },
+ { "halfop", N_("gives half channel operator status to nickname(s)"),
+ N_("[nickname [nickname]]"), "",
+ "", 0, MAX_ARGS, 0, irc_cmd_halfop },
+ { "info", N_("get information describing the server"),
+ N_("[target]"),
+ N_("target: server name"),
+ NULL, 0, 1, 0, irc_cmd_info },
+ { "invite", N_("invite a nick on a channel"),
+ N_("nickname channel"),
+ N_("nickname: nick to invite\n"
+ " channel: channel to invite"),
+ "%n %c", 1, 2, 0, irc_cmd_invite },
+ { "ison", N_("check if a nickname is currently on IRC"),
+ N_("nickname [nickname ...]"),
+ N_("nickname: nickname"),
+ "", 1, MAX_ARGS, 0, irc_cmd_ison },
+ { "join", N_("join a channel"),
+ N_("channel[,channel] [key[,key]]"),
+ N_("channel: channel name to join\n"
+ " key: key to join the channel"),
+ "%C", 1, MAX_ARGS, 0, irc_cmd_join },
+ { "kick", N_("forcibly remove a user from a channel"),
+ N_("[channel] nickname [comment]"),
+ N_(" channel: channel where user is\n"
+ "nickname: nickname to kick\n"
+ " comment: comment for kick"),
+ "%n %-", 1, MAX_ARGS, 0, irc_cmd_kick },
+ { "kickban", N_("kicks and bans a nick from a channel"),
+ N_("[channel] nickname [comment]"),
+ N_(" channel: channel where user is\n"
+ "nickname: nickname to kick and ban\n"
+ " comment: comment for kick"),
+ "%n %-", 1, MAX_ARGS, 0, irc_cmd_kickban },
+ { "kill", N_("close client-server connection"),
+ N_("nickname comment"),
+ N_("nickname: nickname\n"
+ " comment: comment for kill"),
+ "%n %-", 2, MAX_ARGS, 0, irc_cmd_kill },
+ { "links",
+ N_("list all servernames which are known by the server answering "
+ "the query"),
+ N_("[[server] server_mask]"),
+ N_(" server: this server should answer the query\n"
+ "server_mask: list of servers must match this mask"),
+ NULL, 0, 2, 0, irc_cmd_links },
+ { "list", N_("list channels and their topic"),
+ N_("[channel[,channel] [server]]"),
+ N_("channel: channel to list (a regexp is allowed)\nserver: server name"),
+ NULL, 0, MAX_ARGS, 0, irc_cmd_list },
+ { "lusers", N_("get statistics about the size of the IRC network"),
+ N_("[mask [target]]"),
+ N_(" mask: servers matching the mask only\n"
+ "target: server for forwarding request"),
+ NULL, 0, 2, 0, irc_cmd_lusers },
+ { "me", N_("send a CTCP action to the current channel"),
+ N_("message"),
+ N_("message: message to send"),
+ "", 0, MAX_ARGS, 1, irc_cmd_me },
+ { "mode", N_("change channel or user mode"),
+ N_("{ channel {[+|-]|o|p|s|i|t|n|b|v} [limit] [user] [ban mask] } | "
+ "{ nickname {[+|-]|i|w|s|o} }"),
+ N_("channel modes:\n"
+ " channel: channel name to modify\n"
+ " o: give/take channel operator privileges\n"
+ " p: private channel flag\n"
+ " s: secret channel flag\n"
+ " i: invite-only channel flag\n"
+ " t: topic settable by channel operator only flag\n"
+ " n: no messages to channel from clients on the outside\n"
+ " m: moderated channel\n"
+ " l: set the user limit to channel\n"
+ " b: set a ban mask to keep users out\n"
+ " e: set exception mask\n"
+ " v: give/take the ability to speak on a moderated channel\n"
+ " k: set a channel key (password)\n"
+ "user modes:\n"
+ " nickname: nickname to modify\n"
+ " i: mark a user as invisible\n"
+ " s: mark a user for receive server notices\n"
+ " w: user receives wallops\n"
+ " o: operator flag"),
+ "%c|%m", 1, MAX_ARGS, 0, irc_cmd_mode },
+ { "motd", N_("get the \"Message Of The Day\""),
+ N_("[target]"),
+ N_("target: server name"),
+ NULL, 0, 1, 0, irc_cmd_motd },
+ { "msg", N_("send message to a nick or channel"),
+ N_("receiver[,receiver] text"),
+ N_("receiver: nick or channel (may be mask, '*' = current channel)\n"
+ "text: text to send"),
+ "", 2, MAX_ARGS, 1, irc_cmd_msg },
+ { "names", N_("list nicknames on channels"),
+ N_("[channel[,channel]]"),
+ N_("channel: channel name"),
+ NULL, 0, 1, 0, irc_cmd_names },
+ { "nick", N_("change current nickname"),
+ N_("[-all] nickname"),
+ N_(" -all: set new nickname for all connected servers\n"
+ "nickname: new nickname"),
+ "-all", 1, 2, 0, irc_cmd_nick },
+ { "notice", N_("send notice message to user"),
+ N_("nickname text"),
+ N_("nickname: user to send notice to\n"
+ " text: text to send"),
+ "%n %-", 2, MAX_ARGS, 1, irc_cmd_notice },
+ { "op", N_("gives channel operator status to nickname(s)"),
+ N_("nickname [nickname]"), "",
+ "", 1, MAX_ARGS, 0, irc_cmd_op },
+ { "oper", N_("get operator privileges"),
+ N_("user password"),
+ N_("user/password: used to get privileges on current IRC server"),
+ NULL, 2, 2, 0, irc_cmd_oper },
+ { "part", N_("leave a channel"),
+ N_("[channel[,channel]] [part_message]"),
+ N_(" channel: channel name to leave\n"
+ "part_message: part message (displayed to other users)"),
+ "%p", 0, MAX_ARGS, 0, irc_cmd_part },
+ { "ping", N_("ping server"),
+ N_("server1 [server2]"),
+ N_("server1: server to ping\nserver2: forward ping to this server"),
+ NULL, 1, 2, 0, irc_cmd_ping },
+ { "pong", N_("answer to a ping message"),
+ N_("daemon [daemon2]"),
+ N_(" daemon: daemon who has responded to Ping message\n"
+ "daemon2: forward message to this daemon"),
+ NULL, 1, 2, 0, irc_cmd_pong },
+ { "query", N_("send a private message to a nick"),
+ N_("nickname [text]"),
+ N_("nickname: nickname for private conversation\n"
+ " text: text to send"),
+ "%n %-", 1, MAX_ARGS, 1, irc_cmd_query },
+ { "quit", N_("close all connections and quit"),
+ N_("[quit_message]"),
+ N_("quit_message: quit message (displayed to other users)"),
+ "%q", 0, MAX_ARGS, 1, irc_cmd_quit },
+ { "quote", N_("send raw data to server without parsing"),
+ N_("data"),
+ N_("data: raw data to send"),
+ "", 1, MAX_ARGS, 1, irc_cmd_quote },
+ { "reconnect", N_("reconnect to server(s)"),
+ N_("[-all [-nojoin] | servername [servername ...] [-nojoin]]"),
+ N_(" -all: reconnect to all servers\n"
+ "servername: server name to reconnect\n"
+ " -nojoin: do not join any channel (even if autojoin is enabled on "
+ "server)"),
+ "%S|-all|-nojoin|%*", 0, MAX_ARGS, 0, irc_cmd_reconnect },
+ { "rehash", N_("tell the server to reload its config file"), "", "",
+ NULL, 0, 0, 0, irc_cmd_rehash },
+ { "restart", N_("tell the server to restart itself"), "", "",
+ NULL, 0, 0, 0, irc_cmd_restart },
+ { "service", N_("register a new service"),
+ N_("nickname reserved distribution type reserved info"),
+ N_("distribution: visibility of service\n"
+ " type: reserved for future usage"),
+ NULL, 6, 6, 0, irc_cmd_service },
+ { "server", N_("list, add or remove servers"),
+ N_("[list [servername]] | [listfull [servername]] | [add servername "
+ "hostname [-port port] [-temp] [-auto | -noauto] [-ipv6] [-ssl] "
+ "[-pwd password] [-nicks nick1 nick2 nick3] [-username username] "
+ "[-realname realname] [-command command] "
+ "[-autojoin channel[,channel]] ] | [copy servername newservername] | "
+ "[rename servername newservername] | [keep servername] | "
+ "[del servername]"),
+ N_(" list: list servers (no parameter implies this list)\n"
+ " listfull: list servers with detailed info for each server\n"
+ " add: create a new server\n"
+ "servername: server name, for internal and display use\n"
+ " hostname: name or IP address of server\n"
+ " port: port for server (integer, default is 6667)\n"
+ " temp: create temporary server (not saved in config file)\n"
+ " auto: automatically connect to server when WeeChat starts\n"
+ " noauto: do not connect to server when WeeChat starts (default)\n"
+ " ipv6: use IPv6 protocol\n"
+ " ssl: use SSL protocol\n"
+ " password: password for server\n"
+ " nick1: first nick for server\n"
+ " nick2: alternate nick for server\n"
+ " nick3: second alternate nick for server\n"
+ " username: user name\n"
+ " realname: real name of user\n"
+ " copy: duplicate a server\n"
+ " rename: rename a server\n"
+ " keep: keep server in config file (for temporary servers only)\n"
+ " del: delete a server\n"
+ " deloutq: delete messages out queue for all servers (all messages "
+ "WeeChat is currently sending)"),
+ "add|copy|rename|keep|del|deloutq|list|listfull %S %S",
+ 0, MAX_ARGS, 0, irc_cmd_server },
+ { "servlist", N_("list services currently connected to the network"),
+ N_("[mask [type]]"),
+ N_("mask: list only services matching this mask\n"
+ "type: list only services of this type"),
+ NULL, 0, 2, 0, irc_cmd_servlist },
+ { "squery", N_("deliver a message to a service"),
+ N_("service text"),
+ N_("service: name of service\ntext: text to send"),
+ NULL, 2, MAX_ARGS, 1, irc_cmd_squery },
+ { "squit", N_("disconnect server links"),
+ N_("server comment"),
+ N_( "server: server name\n"
+ "comment: comment for quit"),
+ NULL, 2, 2, 1, irc_cmd_squit },
+ { "stats", N_("query statistics about server"),
+ N_("[query [server]]"),
+ N_(" query: c/h/i/k/l/m/o/y/u (see RFC1459)\n"
+ "server: server name"),
+ NULL, 0, 2, 0, irc_cmd_stats },
+ { "summon",
+ N_("give users who are on a host running an IRC server a message "
+ "asking them to please join IRC"),
+ N_("user [target [channel]]"),
+ N_(" user: username\ntarget: server name\n"
+ "channel: channel name"),
+ NULL, 1, 3, 0, irc_cmd_summon },
+ { "time", N_("query local time from server"),
+ N_("[target]"),
+ N_("target: query time from specified server"),
+ NULL, 0, 1, 0, irc_cmd_time },
+ { "topic", N_("get/set channel topic"),
+ N_("[channel] [topic]"),
+ N_("channel: channel name\ntopic: new topic for channel "
+ "(if topic is \"-delete\" then topic is deleted)"),
+ "%t|-delete %-", 0, MAX_ARGS, 1, irc_cmd_topic },
+ { "trace", N_("find the route to specific server"),
+ N_("[target]"),
+ N_("target: server"),
+ NULL, 0, 1, 0, irc_cmd_trace },
+ { "unban", N_("unbans nicks or hosts"),
+ N_("[channel] nickname [nickname ...]"),
+ N_(" channel: channel for unban\n"
+ "nickname: user or host to unban"),
+ "", 1, MAX_ARGS, 0, irc_cmd_unban },
+ { "userhost", N_("return a list of information about nicknames"),
+ N_("nickname [nickname ...]"),
+ N_("nickname: nickname"),
+ "%n", 1, MAX_ARGS, 0, irc_cmd_userhost },
+ { "users", N_("list of users logged into the server"),
+ N_("[target]"),
+ N_("target: server"),
+ NULL, 0, 1, 0, irc_cmd_users },
+ { "version",
+ N_("gives the version info of nick or server (current or specified)"),
+ N_("[server | nickname]"),
+ N_(" server: server name\n"
+ "nickname: nickname"),
+ "%n", 0, 1, 0, irc_cmd_version },
+ { "voice", N_("gives voice to nickname(s)"),
+ N_("[nickname [nickname]]"), "",
+ "", 0, MAX_ARGS, 0, irc_cmd_voice },
+ { "wallops", N_("send a message to all currently connected users who have "
+ "set the 'w' user mode for themselves"),
+ N_("text"),
+ N_("text to send"),
+ NULL, 1, MAX_ARGS, 1, irc_cmd_wallops },
+ { "who", N_("generate a query which returns a list of information"),
+ N_("[mask [\"o\"]]"),
+ N_("mask: only information which match this mask\n"
+ " o: only operators are returned according to the mask supplied"),
+ "%C", 0, 2, 0, irc_cmd_who },
+ { "whois", N_("query information about user(s)"),
+ N_("[server] nickname[,nickname]"),
+ N_(" server: server name\n"
+ "nickname: nickname (may be a mask)"),
+ "", 1, MAX_ARGS, 0, irc_cmd_whois },
+ { "whowas",
+ N_("ask for information about a nickname which no longer exists"),
+ N_("nickname [,nickname [,nickname ...]] [count [target]]"),
+ N_("nickname: nickname to search\n"
+ " count: number of replies to return "
+ "(full search if negative number)\n"
+ " target: reply should match this mask"),
+ "", 1, MAX_ARGS, 0, irc_cmd_whowas },
+ { NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL }
+};
+
+
+/*
+ * irc_cmd_admin: find information about the administrator of the server
+ */
+
+int
+irc_cmd_admin (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (arguments)
+ irc_server_sendf (ptr_server, "ADMIN %s", arguments);
+ else
+ irc_server_sendf (ptr_server, "ADMIN");
+ return 0;
+}
+
+/*
+ * irc_cmd_me_channel: send a ctcp action to a channel
+ */
+
+int
+irc_cmd_me_channel (t_irc_server *server, t_irc_channel *channel,
+ char *arguments)
+{
+ char *string;
+
+ irc_server_sendf (server, "PRIVMSG %s :\01ACTION %s\01",
+ channel->name,
+ (arguments && arguments[0]) ? arguments : "");
+ string = (arguments && arguments[0]) ?
+ (char *)irc_color_decode ((unsigned char *)arguments, 1, 0) : NULL;
+ gui_chat_printf_action (channel->buffer,
+ "%s%s %s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ server->nick,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (string) ? string : "");
+ if (string)
+ free (string);
+ return 0;
+}
+
+/*
+ * irc_cmd_me_all_channels: send a ctcp action to all channels of a server
+ */
+
+int
+irc_cmd_me_all_channels (t_irc_server *server, char *arguments)
+{
+ t_irc_channel *ptr_channel;
+
+ for (ptr_channel = server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
+ {
+ if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL)
+ irc_cmd_me_channel (server, ptr_channel, arguments);
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_mode_nicks: send mode change for many nicks on a channel
+ */
+
+void
+irc_cmd_mode_nicks (t_irc_server *server, char *channel,
+ char *set, char *mode, int argc, char **argv)
+{
+ int i, length;
+ char *command;
+
+ length = 0;
+ for (i = 0; i < argc; i++)
+ length += strlen (argv[i]) + 1;
+ length += strlen (channel) + (argc * strlen (mode)) + 32;
+ command = (char *)malloc (length);
+ if (command)
+ {
+ snprintf (command, length, "MODE %s %s", channel, set);
+ for (i = 0; i < argc; i++)
+ strcat (command, mode);
+ for (i = 0; i < argc; i++)
+ {
+ strcat (command, " ");
+ strcat (command, argv[i]);
+ }
+ irc_server_sendf (server, "%s", command);
+ free (command);
+ }
+}
+
+/*
+ * irc_cmd_ame: send a ctcp action to all channels of all connected servers
+ */
+
+int
+irc_cmd_ame (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ t_irc_server *ptr_server;
+ t_irc_channel *ptr_channel;
+
+ /* make C compiler happy */
+ (void) window;
+ (void) argc;
+ (void) argv;
+
+ gui_add_hotlist = 0;
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ if (ptr_server->is_connected)
+ {
+ for (ptr_channel = ptr_server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
+ {
+ if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL)
+ irc_cmd_me_channel (ptr_server, ptr_channel, arguments);
+ }
+ }
+ }
+ gui_add_hotlist = 1;
+ return 0;
+}
+
+/*
+ * irc_cmd_amsg: send message to all channels of all connected servers
+ */
+
+int
+irc_cmd_amsg (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ t_irc_server *ptr_server;
+ t_irc_channel *ptr_channel;
+ t_irc_nick *ptr_nick;
+ char *string;
+
+ /* make C compiler happy */
+ (void) window;
+ (void) argc;
+ (void) argv;
+
+ if (arguments)
+ {
+ gui_add_hotlist = 0;
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ if (ptr_server->is_connected)
+ {
+ for (ptr_channel = ptr_server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
+ {
+ if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL)
+ {
+ irc_server_sendf (ptr_server, "PRIVMSG %s :%s",
+ ptr_channel->name, arguments);
+ ptr_nick = irc_nick_search (ptr_channel,
+ ptr_server->nick);
+ if (ptr_nick)
+ {
+ irc_display_nick (ptr_channel->buffer, ptr_nick,
+ NULL, GUI_MSG_TYPE_NICK, 1,
+ NULL, 0);
+ string = (char *)irc_color_decode (
+ (unsigned char *)arguments, 1, 0);
+ gui_chat_printf (ptr_channel->buffer, "%s\n",
+ (string) ? string : arguments);
+ if (string)
+ free (string);
+ }
+ else
+ {
+ gui_chat_printf_error (ptr_server->buffer,
+ _("%s cannot find nick for "
+ "sending message\n"),
+ WEECHAT_ERROR);
+ }
+ }
+ }
+ }
+ }
+ gui_add_hotlist = 1;
+ }
+ else
+ return -1;
+ return 0;
+}
+
+/*
+ * irc_cmd_away_server: toggle away status for one server
+ */
+
+void
+irc_cmd_away_server (t_irc_server *server, char *arguments)
+{
+ char *string, buffer[4096];
+ t_gui_window *ptr_window;
+ time_t time_now, elapsed;
+
+ if (!server)
+ return;
+
+ if (arguments)
+ {
+ if (server->away_message)
+ free (server->away_message);
+ server->away_message = (char *) malloc (strlen (arguments) + 1);
+ if (server->away_message)
+ strcpy (server->away_message, arguments);
+
+ /* if server is connected, send away command now */
+ if (server->is_connected)
+ {
+ server->is_away = 1;
+ server->away_time = time (NULL);
+ irc_server_sendf (server, "AWAY :%s", arguments);
+ if (irc_cfg_irc_display_away != CFG_IRC_DISPLAY_AWAY_OFF)
+ {
+ string = (char *)irc_color_decode ((unsigned char *)arguments,
+ 1, 0);
+ if (irc_cfg_irc_display_away == CFG_IRC_DISPLAY_AWAY_LOCAL)
+ irc_display_away (server, "away",
+ (string) ? string : arguments);
+ else
+ {
+ snprintf (buffer, sizeof (buffer), "is away: %s",
+ (string) ? string : arguments);
+ irc_cmd_me_all_channels (server, buffer);
+ }
+ if (string)
+ free (string);
+ }
+ irc_server_set_away (server, server->nick, 1);
+ for (ptr_window = gui_windows; ptr_window;
+ ptr_window = ptr_window->next_window)
+ {
+ if (strcmp (ptr_window->buffer->category, server->name) == 0)
+ ptr_window->buffer->last_read_line =
+ ptr_window->buffer->last_line;
+ }
+ }
+ else
+ {
+ /* server not connected, store away for future usage
+ (when connecting to server) */
+ string = (char *)irc_color_decode ((unsigned char *)arguments,
+ 1, 0);
+ gui_chat_printf_info_nolog (server->buffer,
+ _("Future away on %s%s%s: %s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_SERVER),
+ server->name,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (string) ? string : arguments);
+ if (string)
+ free (string);
+ }
+ }
+ else
+ {
+ if (server->away_message)
+ {
+ free (server->away_message);
+ server->away_message = NULL;
+ }
+
+ /* if server is connected, send away command now */
+ if (server->is_connected)
+ {
+ irc_server_sendf (server, "AWAY");
+ server->is_away = 0;
+ if (server->away_time != 0)
+ {
+ time_now = time (NULL);
+ elapsed = (time_now >= server->away_time) ?
+ time_now - server->away_time : 0;
+ server->away_time = 0;
+ if (irc_cfg_irc_display_away != CFG_IRC_DISPLAY_AWAY_OFF)
+ {
+ if (irc_cfg_irc_display_away == CFG_IRC_DISPLAY_AWAY_LOCAL)
+ {
+ snprintf (buffer, sizeof (buffer),
+ "gone %.2ld:%.2ld:%.2ld",
+ (long int)(elapsed / 3600),
+ (long int)((elapsed / 60) % 60),
+ (long int)(elapsed % 60));
+ irc_display_away (server, "back", buffer);
+ }
+ else
+ {
+ snprintf (buffer, sizeof (buffer),
+ "is back (gone %.2ld:%.2ld:%.2ld)",
+ (long int)(elapsed / 3600),
+ (long int)((elapsed / 60) % 60),
+ (long int)(elapsed % 60));
+ irc_cmd_me_all_channels (server, buffer);
+ }
+ }
+ }
+ irc_server_set_away (server, server->nick, 0);
+ }
+ else
+ {
+ /* server not connected, remove away message but do not send
+ anything */
+ gui_chat_printf_info_nolog (server->buffer,
+ _("Future away on %s%s%s removed.\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_SERVER),
+ server->name,
+ GUI_COLOR(GUI_COLOR_CHAT));
+ }
+ }
+}
+
+/*
+ * irc_cmd_away: toggle away status
+ */
+
+int
+irc_cmd_away (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ char *pos;
+
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ gui_add_hotlist = 0;
+ if (arguments && (strncmp (arguments, "-all", 4) == 0))
+ {
+ pos = arguments + 4;
+ while (pos[0] == ' ')
+ pos++;
+ if (!pos[0])
+ pos = NULL;
+
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ if (ptr_server->is_connected)
+ irc_cmd_away_server (ptr_server, pos);
+ }
+ }
+ else
+ irc_cmd_away_server (ptr_server, arguments);
+
+ gui_status_draw (window->buffer, 1);
+ gui_add_hotlist = 1;
+ return 0;
+}
+
+/*
+ * irc_cmd_ban: bans nicks or hosts
+ */
+
+int
+irc_cmd_ban (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ char *pos_channel, *pos, *pos2;
+
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (arguments)
+ {
+ pos_channel = NULL;
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+
+ if (irc_channel_is_channel (arguments))
+ {
+ pos_channel = arguments;
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ }
+ else
+ {
+ pos[0] = ' ';
+ pos = arguments;
+ }
+ }
+ else
+ pos = arguments;
+
+ /* channel not given, use default buffer */
+ if (!pos_channel)
+ {
+ if (!ptr_channel)
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can only "
+ "be executed in a channel "
+ "buffer\n"),
+ WEECHAT_ERROR, "ban");
+ return -1;
+ }
+ pos_channel = ptr_channel->name;
+ }
+
+ /* loop on users */
+ while (pos && pos[0])
+ {
+ pos2 = strchr (pos, ' ');
+ if (pos2)
+ {
+ pos2[0] = '\0';
+ pos2++;
+ while (pos2[0] == ' ')
+ pos2++;
+ }
+ irc_server_sendf (ptr_server, "MODE %s +b %s", pos_channel, pos);
+ pos = pos2;
+ }
+ }
+ else
+ {
+ if (!ptr_channel)
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can only be "
+ "executed in a channel buffer\n"),
+ WEECHAT_ERROR, "ban");
+ return -1;
+ }
+ irc_server_sendf (ptr_server, "MODE %s +b", ptr_channel->name);
+ }
+
+ return 0;
+}
+
+/*
+ * irc_cmd_connect_one_server: connect to one server
+ * return 0 if error, 1 if ok
+ */
+
+int
+irc_cmd_connect_one_server (t_irc_server *server, int no_join)
+{
+ if (!server)
+ return 0;
+
+ if (server->is_connected)
+ {
+ gui_chat_printf_error (NULL,
+ _("%s already connected to server "
+ "\"%s\"!\n"),
+ WEECHAT_ERROR, server->name);
+ return 0;
+ }
+ if (server->child_pid > 0)
+ {
+ gui_chat_printf_error (NULL,
+ _("%s currently connecting to server "
+ "\"%s\"!\n"),
+ WEECHAT_ERROR, server->name);
+ return 0;
+ }
+ if (irc_server_connect (server, no_join))
+ {
+ server->reconnect_start = 0;
+ server->reconnect_join = (server->channels) ? 1 : 0;
+ gui_status_draw (server->buffer, 1);
+ }
+
+ /* connect ok */
+ return 1;
+}
+
+/*
+ * irc_cmd_connect: connect to server(s)
+ */
+
+int
+irc_cmd_connect (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ t_irc_server server_tmp;
+ int i, nb_connect, connect_ok, all_servers, no_join, port, ipv6, ssl;
+ char *error;
+ long number;
+
+ IRC_BUFFER_GET_SERVER(window->buffer);
+
+ /* make C compiler happy */
+ (void) window;
+ (void) arguments;
+
+ nb_connect = 0;
+ connect_ok = 1;
+ port = IRC_SERVER_DEFAULT_PORT;
+ ipv6 = 0;
+ ssl = 0;
+
+ all_servers = 0;
+ no_join = 0;
+ for (i = 0; i < argc; i++)
+ {
+ if (weechat_strcasecmp (argv[i], "-all") == 0)
+ all_servers = 1;
+ if (weechat_strcasecmp (argv[i], "-nojoin") == 0)
+ no_join = 1;
+ if (weechat_strcasecmp (argv[i], "-ipv6") == 0)
+ ipv6 = 1;
+ if (weechat_strcasecmp (argv[i], "-ssl") == 0)
+ ssl = 1;
+ if (weechat_strcasecmp (argv[i], "-port") == 0)
+ {
+ if (i == (argc - 1))
+ {
+ gui_chat_printf_error (NULL,
+ _("%s missing argument for \"%s\" "
+ "option\n"),
+ WEECHAT_ERROR, "-port");
+ return -1;
+ }
+ error = NULL;
+ number = strtol (argv[++i], &error, 10);
+ if (error && (error[0] == '\0'))
+ port = number;
+ }
+ }
+
+ if (all_servers)
+ {
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ nb_connect++;
+ if (!ptr_server->is_connected && (ptr_server->child_pid == 0))
+ {
+ if (!irc_cmd_connect_one_server (ptr_server, no_join))
+ connect_ok = 0;
+ }
+ }
+ }
+ else
+ {
+ for (i = 0; i < argc; i++)
+ {
+ if (argv[i][0] != '-')
+ {
+ nb_connect++;
+ ptr_server = irc_server_search (argv[i]);
+ if (ptr_server)
+ {
+ if (!irc_cmd_connect_one_server (ptr_server, no_join))
+ connect_ok = 0;
+ }
+ else
+ {
+ irc_server_init (&server_tmp);
+ server_tmp.name = strdup (argv[i]);
+ server_tmp.address = strdup (argv[i]);
+ server_tmp.port = port;
+ server_tmp.ipv6 = ipv6;
+ server_tmp.ssl = ssl;
+ ptr_server = irc_server_new (server_tmp.name,
+ server_tmp.autoconnect,
+ server_tmp.autoreconnect,
+ server_tmp.autoreconnect_delay,
+ 1, /* temp server */
+ server_tmp.address,
+ server_tmp.port,
+ server_tmp.ipv6,
+ server_tmp.ssl,
+ server_tmp.password,
+ server_tmp.nick1,
+ server_tmp.nick2,
+ server_tmp.nick3,
+ server_tmp.username,
+ server_tmp.realname,
+ server_tmp.hostname,
+ server_tmp.command,
+ 1, /* command_delay */
+ server_tmp.autojoin,
+ 1, /* autorejoin */
+ NULL);
+ if (ptr_server)
+ {
+ gui_chat_printf_info (NULL,
+ _("Server %s%s%s created "
+ "(temporary server, "
+ "NOT SAVED!)\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_SERVER),
+ server_tmp.name,
+ GUI_COLOR(GUI_COLOR_CHAT));
+ if (!irc_cmd_connect_one_server (ptr_server, 0))
+ connect_ok = 0;
+ }
+ else
+ {
+ gui_chat_printf_error (NULL,
+ _("%s unable to create server "
+ "\"%s\"\n"),
+ WEECHAT_ERROR, argv[i]);
+ }
+ }
+ }
+ else
+ {
+ if (weechat_strcasecmp (argv[i], "-port") == 0)
+ i++;
+ }
+ }
+ }
+
+ if (nb_connect == 0)
+ connect_ok = irc_cmd_connect_one_server (ptr_server, no_join);
+
+ if (!connect_ok)
+ return -1;
+
+ return 0;
+}
+
+/*
+ * irc_cmd_ctcp: send a ctcp message
+ */
+
+int
+irc_cmd_ctcp (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ char *pos_type, *pos_args, *pos;
+ struct timeval tv;
+
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ pos_type = strchr (arguments, ' ');
+ if (pos_type)
+ {
+ pos_type[0] = '\0';
+ pos_type++;
+ while (pos_type[0] == ' ')
+ pos_type++;
+ pos_args = strchr (pos_type, ' ');
+ if (pos_args)
+ {
+ pos_args[0] = '\0';
+ pos_args++;
+ while (pos_args[0] == ' ')
+ pos_args++;
+ }
+ else
+ pos_args = NULL;
+
+ pos = pos_type;
+ while (pos[0])
+ {
+ pos[0] = toupper (pos[0]);
+ pos++;
+ }
+
+ gui_chat_printf_server (ptr_server->buffer,
+ "CTCP%s(%s%s%s)%s: %s%s",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ arguments,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ pos_type);
+
+ if ((weechat_strcasecmp (pos_type, "ping") == 0) && (!pos_args))
+ {
+ gettimeofday (&tv, NULL);
+ irc_server_sendf (ptr_server, "PRIVMSG %s :\01PING %d %d\01",
+ arguments, tv.tv_sec, tv.tv_usec);
+ gui_chat_printf (ptr_server->buffer, " %s%d %d\n",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ tv.tv_sec, tv.tv_usec);
+ }
+ else
+ {
+ if (pos_args)
+ {
+ irc_server_sendf (ptr_server, "PRIVMSG %s :\01%s %s\01",
+ arguments, pos_type, pos_args);
+ gui_chat_printf (ptr_server->buffer, " %s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_args);
+ }
+ else
+ {
+ irc_server_sendf (ptr_server, "PRIVMSG %s :\01%s\01",
+ arguments, pos_type);
+ gui_chat_printf (ptr_server->buffer, "\n");
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_cycle: leave and rejoin a channel
+ */
+
+int
+irc_cmd_cycle (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ char *channel_name, *pos_args, *ptr_arg, *buf;
+ char **channels;
+ int i, num_channels;
+
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (arguments)
+ {
+ if (irc_channel_is_channel (arguments))
+ {
+ channel_name = arguments;
+ pos_args = strchr (arguments, ' ');
+ if (pos_args)
+ {
+ pos_args[0] = '\0';
+ pos_args++;
+ while (pos_args[0] == ' ')
+ pos_args++;
+ }
+ channels = weechat_explode_string (channel_name, ",", 0,
+ &num_channels);
+ if (channels)
+ {
+ for (i = 0; i < num_channels; i++)
+ {
+ ptr_channel = irc_channel_search (ptr_server, channels[i]);
+ /* mark channel as cycling */
+ if (ptr_channel &&
+ (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL))
+ ptr_channel->cycle = 1;
+ }
+ weechat_free_exploded_string (channels);
+ }
+ }
+ else
+ {
+ if (!ptr_channel)
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can not be "
+ "executed on a server "
+ "buffer\n"),
+ WEECHAT_ERROR, "cycle");
+ return -1;
+ }
+
+ /* does nothing on private buffer (cycle has no sense!) */
+ if (ptr_channel->type != IRC_CHANNEL_TYPE_CHANNEL)
+ return 0;
+
+ channel_name = ptr_channel->name;
+ pos_args = arguments;
+ ptr_channel->cycle = 1;
+ }
+ }
+ else
+ {
+ if (!ptr_channel)
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can not be "
+ "executed on a server buffer\n"),
+ WEECHAT_ERROR, "part");
+ return -1;
+ }
+
+ /* does nothing on private buffer (cycle has no sense!) */
+ if (ptr_channel->type != IRC_CHANNEL_TYPE_CHANNEL)
+ return 0;
+
+ channel_name = ptr_channel->name;
+ pos_args = NULL;
+ ptr_channel->cycle = 1;
+ }
+
+ ptr_arg = (pos_args) ? pos_args :
+ (irc_cfg_irc_default_msg_part && irc_cfg_irc_default_msg_part[0]) ?
+ irc_cfg_irc_default_msg_part : NULL;
+
+ if (ptr_arg)
+ {
+ buf = weechat_strreplace (ptr_arg, "%v", PACKAGE_VERSION);
+ irc_server_sendf (ptr_server, "PART %s :%s", channel_name,
+ (buf) ? buf : ptr_arg);
+ if (buf)
+ free (buf);
+ }
+ else
+ irc_server_sendf (ptr_server, "PART %s", channel_name);
+
+ return 0;
+}
+
+/*
+ * irc_cmd_dcc: DCC control (file or chat)
+ */
+
+int
+irc_cmd_dcc (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ char *pos_nick, *pos_file;
+
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make compiler happy */
+ (void) argc;
+ (void) argv;
+
+ /* DCC SEND file */
+ if (strncasecmp (arguments, "send", 4) == 0)
+ {
+ pos_nick = strchr (arguments, ' ');
+ if (!pos_nick)
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s wrong argument count for "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, "dcc send");
+ return -1;
+ }
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+
+ pos_file = strchr (pos_nick, ' ');
+ if (!pos_file)
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s wrong argument count for "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, "dcc send");
+ return -1;
+ }
+ pos_file[0] = '\0';
+ pos_file++;
+ while (pos_file[0] == ' ')
+ pos_file++;
+
+ irc_dcc_send_request (ptr_server, IRC_DCC_FILE_SEND,
+ pos_nick, pos_file);
+ }
+ /* DCC CHAT */
+ else if (strncasecmp (arguments, "chat", 4) == 0)
+ {
+ pos_nick = strchr (arguments, ' ');
+ if (!pos_nick)
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s wrong argument count for "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, "dcc chat");
+ return -1;
+ }
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+
+ irc_dcc_send_request (ptr_server, IRC_DCC_CHAT_SEND,
+ pos_nick, NULL);
+ }
+ /* close DCC CHAT */
+ else if (weechat_strcasecmp (arguments, "close") == 0)
+ {
+ if (ptr_channel && (ptr_channel != IRC_CHANNEL_TYPE_CHANNEL)
+ && (ptr_channel->dcc_chat))
+ {
+ irc_dcc_close ((t_irc_dcc *)(ptr_channel->dcc_chat),
+ IRC_DCC_ABORTED);
+ irc_dcc_redraw (1);
+ }
+ }
+ /* unknown DCC action */
+ else
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s wrong arguments for \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "dcc");
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * irc_cmd_dehalfop: remove half operator privileges from nickname(s)
+ */
+
+int
+irc_cmd_dehalfop (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) arguments;
+
+ if (ptr_channel && (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL))
+ {
+ if (argc == 0)
+ irc_server_sendf (ptr_server, "MODE %s -h %s",
+ ptr_channel->name,
+ ptr_server->nick);
+ else
+ irc_cmd_mode_nicks (ptr_server, ptr_channel->name,
+ "-", "h", argc, argv);
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can only be "
+ "executed in a channel buffer\n"),
+ WEECHAT_ERROR, "dehalfop");
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_deop: remove operator privileges from nickname(s)
+ */
+
+int
+irc_cmd_deop (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) arguments;
+
+ if (ptr_channel && (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL))
+ {
+ if (argc == 0)
+ irc_server_sendf (ptr_server, "MODE %s -o %s",
+ ptr_channel->name,
+ ptr_server->nick);
+ else
+ irc_cmd_mode_nicks (ptr_server, ptr_channel->name,
+ "-", "o", argc, argv);
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can only be "
+ "executed in a channel buffer\n"),
+ WEECHAT_ERROR, "deop");
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_devoice: remove voice from nickname(s)
+ */
+
+int
+irc_cmd_devoice (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) arguments;
+
+ if (ptr_channel && (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL))
+ {
+ if (argc == 0)
+ irc_server_sendf (ptr_server, "MODE %s -v %s",
+ ptr_channel->name,
+ ptr_server->nick);
+ else
+ irc_cmd_mode_nicks (ptr_server, ptr_channel->name,
+ "-", "v", argc, argv);
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can only be "
+ "executed in a channel buffer\n"),
+ WEECHAT_ERROR, "devoice");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_die: shotdown the server
+ */
+
+int
+irc_cmd_die (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) arguments;
+ (void) argc;
+ (void) argv;
+
+ irc_server_sendf (ptr_server, "DIE");
+ return 0;
+}
+
+/*
+ * irc_cmd_quit_server: send QUIT to a server
+ */
+
+void
+irc_cmd_quit_server (t_irc_server *server, char *arguments)
+{
+ char *ptr_arg, *buf;
+
+ if (!server)
+ return;
+
+ if (server->is_connected)
+ {
+ ptr_arg = (arguments) ? arguments :
+ (irc_cfg_irc_default_msg_quit && irc_cfg_irc_default_msg_quit[0]) ?
+ irc_cfg_irc_default_msg_quit : NULL;
+
+ if (ptr_arg)
+ {
+ buf = weechat_strreplace (ptr_arg, "%v", PACKAGE_VERSION);
+ irc_server_sendf (server, "QUIT :%s",
+ (buf) ? buf : ptr_arg);
+ if (buf)
+ free (buf);
+ }
+ else
+ irc_server_sendf (server, "QUIT");
+ }
+}
+
+/*
+ * irc_cmd_disconnect_one_server: disconnect from a server
+ * return 0 if error, 1 if ok
+ */
+
+int
+irc_cmd_disconnect_one_server (t_irc_server *server)
+{
+ if (!server)
+ return 0;
+
+ if ((!server->is_connected) && (server->child_pid == 0)
+ && (server->reconnect_start == 0))
+ {
+ gui_chat_printf_error (server->buffer,
+ _("%s not connected to server \"%s\"!\n"),
+ WEECHAT_ERROR, server->name);
+ return 0;
+ }
+ if (server->reconnect_start > 0)
+ {
+ gui_chat_printf_info (server->buffer,
+ _("Auto-reconnection is cancelled\n"));
+ }
+ irc_cmd_quit_server (server, NULL);
+ irc_server_disconnect (server, 0);
+ gui_status_draw (server->buffer, 1);
+
+ /* disconnect ok */
+ return 1;
+}
+
+/*
+ * irc_cmd_disconnect: disconnect from server(s)
+ */
+
+int
+irc_cmd_disconnect (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ int i, disconnect_ok;
+
+ IRC_BUFFER_GET_SERVER(window->buffer);
+
+ /* make C compiler happy */
+ (void) arguments;
+
+ if (argc == 0)
+ disconnect_ok = irc_cmd_disconnect_one_server (ptr_server);
+ else
+ {
+ disconnect_ok = 1;
+
+ if (weechat_strcasecmp (argv[0], "-all") == 0)
+ {
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ if ((ptr_server->is_connected) || (ptr_server->child_pid != 0)
+ || (ptr_server->reconnect_start != 0))
+ {
+ if (!irc_cmd_disconnect_one_server (ptr_server))
+ disconnect_ok = 0;
+ }
+ }
+ }
+ else
+ {
+ for (i = 0; i < argc; i++)
+ {
+ ptr_server = irc_server_search (argv[i]);
+ if (ptr_server)
+ {
+ if (!irc_cmd_disconnect_one_server (ptr_server))
+ disconnect_ok = 0;
+ }
+ else
+ {
+ gui_chat_printf_error (NULL,
+ _("%s server \"%s\" not found\n"),
+ WEECHAT_ERROR, argv[i]);
+ disconnect_ok = 0;
+ }
+ }
+ }
+ }
+
+ if (!disconnect_ok)
+ return -1;
+
+ return 0;
+}
+
+/*
+ * irc_cmd_halfop: give half operator privileges to nickname(s)
+ */
+
+int
+irc_cmd_halfop (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) arguments;
+
+ if (ptr_channel && (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL))
+ {
+ if (argc == 0)
+ irc_server_sendf (ptr_server, "MODE %s +h %s",
+ ptr_channel->name,
+ ptr_server->nick);
+ else
+ irc_cmd_mode_nicks (ptr_server, ptr_channel->name,
+ "+", "h", argc, argv);
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can only be "
+ "executed in a channel buffer\n"),
+ WEECHAT_ERROR, "halfop");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_info: get information describing the server
+ */
+
+int
+irc_cmd_info (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (arguments)
+ irc_server_sendf (ptr_server, "INFO %s", arguments);
+ else
+ irc_server_sendf (ptr_server, "INFO");
+ return 0;
+}
+
+/*
+ * irc_cmd_invite: invite a nick on a channel
+ */
+
+int
+irc_cmd_invite (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) arguments;
+
+ if (argc == 2)
+ irc_server_sendf (ptr_server, "INVITE %s %s", argv[0], argv[1]);
+ else
+ {
+ if (ptr_channel && (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL))
+ irc_server_sendf (ptr_server, "INVITE %s %s",
+ argv[0], ptr_channel->name);
+ else
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can only be "
+ "executed in a channel buffer\n"),
+ WEECHAT_ERROR, "invite");
+ return -1;
+ }
+
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_ison: check if a nickname is currently on IRC
+ */
+
+int
+irc_cmd_ison (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ irc_server_sendf (ptr_server, "ISON %s", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_join_server: send JOIN command on a server
+ */
+
+void
+irc_cmd_join_server (t_irc_server *server, char *arguments)
+{
+ if (irc_channel_is_channel (arguments))
+ irc_server_sendf (server, "JOIN %s", arguments);
+ else
+ irc_server_sendf (server, "JOIN #%s", arguments);
+}
+
+/*
+ * irc_cmd_join: join a new channel
+ */
+
+int
+irc_cmd_join (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ irc_cmd_join_server (ptr_server, arguments);
+
+ return 0;
+}
+
+/*
+ * irc_cmd_kick: forcibly remove a user from a channel
+ */
+
+int
+irc_cmd_kick (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ char *pos_channel, *pos_nick, *pos_comment;
+
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (irc_channel_is_channel (arguments))
+ {
+ pos_channel = arguments;
+ pos_nick = strchr (arguments, ' ');
+ if (!pos_nick)
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s wrong arguments for \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "kick");
+ return -1;
+ }
+ pos_nick[0] = '\0';
+ pos_nick++;
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ }
+ else
+ {
+ if (ptr_channel && (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL))
+ {
+ pos_channel = ptr_channel->name;
+ pos_nick = arguments;
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can only be "
+ "executed in a channel buffer\n"),
+ WEECHAT_ERROR, "kick");
+ return -1;
+ }
+ }
+
+ pos_comment = strchr (pos_nick, ' ');
+ if (pos_comment)
+ {
+ pos_comment[0] = '\0';
+ pos_comment++;
+ while (pos_comment[0] == ' ')
+ pos_comment++;
+ }
+
+ if (pos_comment)
+ irc_server_sendf (ptr_server, "KICK %s %s :%s",
+ pos_channel, pos_nick, pos_comment);
+ else
+ irc_server_sendf (ptr_server, "KICK %s %s",
+ pos_channel, pos_nick);
+
+ return 0;
+}
+
+/*
+ * irc_cmd_kickban: forcibly remove a user from a channel and ban it
+ */
+
+int
+irc_cmd_kickban (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ char *pos_channel, *pos_nick, *pos_comment;
+
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (irc_channel_is_channel (arguments))
+ {
+ pos_channel = arguments;
+ pos_nick = strchr (arguments, ' ');
+ if (!pos_nick)
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s wrong arguments for \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "kickban");
+ return -1;
+ }
+ pos_nick[0] = '\0';
+ pos_nick++;
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ }
+ else
+ {
+ if (ptr_channel && (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL))
+ {
+ pos_channel = ptr_channel->name;
+ pos_nick = arguments;
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can only be "
+ "executed in a channel buffer\n"),
+ WEECHAT_ERROR, "kickban");
+ return -1;
+ }
+ }
+
+ pos_comment = strchr (pos_nick, ' ');
+ if (pos_comment)
+ {
+ pos_comment[0] = '\0';
+ pos_comment++;
+ while (pos_comment[0] == ' ')
+ pos_comment++;
+ }
+
+ irc_server_sendf (ptr_server, "MODE %s +b %s",
+ pos_channel, pos_nick);
+ if (pos_comment)
+ irc_server_sendf (ptr_server, "KICK %s %s :%s",
+ pos_channel, pos_nick, pos_comment);
+ else
+ irc_server_sendf (ptr_server, "KICK %s %s",
+ pos_channel, pos_nick);
+
+ return 0;
+}
+
+/*
+ * irc_cmd_kill: close client-server connection
+ */
+
+int
+irc_cmd_kill (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ char *pos;
+
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ irc_server_sendf (ptr_server, "KILL %s :%s",
+ arguments, pos);
+ }
+ else
+ irc_server_sendf (ptr_server, "KILL %s",
+ arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_links: list all servernames which are known by the server
+ * answering the query
+ */
+
+int
+irc_cmd_links (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (arguments)
+ irc_server_sendf (ptr_server, "LINKS %s", arguments);
+ else
+ irc_server_sendf (ptr_server, "LINKS");
+ return 0;
+}
+
+/*
+ * irc_cmd_list: close client-server connection
+ */
+
+int
+irc_cmd_list (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ char buf[512];
+ int ret;
+
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (ptr_server->cmd_list_regexp)
+ {
+ regfree (ptr_server->cmd_list_regexp);
+ free (ptr_server->cmd_list_regexp);
+ ptr_server->cmd_list_regexp = NULL;
+ }
+
+ if (arguments)
+ {
+ ptr_server->cmd_list_regexp = (regex_t *) malloc (sizeof (regex_t));
+ if (ptr_server->cmd_list_regexp)
+ {
+ if ((ret = regcomp (ptr_server->cmd_list_regexp,
+ arguments,
+ REG_NOSUB | REG_ICASE)) != 0)
+ {
+ regerror (ret, ptr_server->cmd_list_regexp,
+ buf, sizeof(buf));
+ gui_chat_printf (ptr_server->buffer,
+ _("%s \"%s\" is not a valid regular "
+ "expression (%s)\n"),
+ WEECHAT_ERROR, arguments, buf);
+ }
+ else
+ irc_server_sendf (ptr_server, "LIST");
+ }
+ else
+ {
+ gui_chat_printf (ptr_server->buffer,
+ _("%s not enough memory for regular "
+ "expression\n"),
+ WEECHAT_ERROR);
+ }
+ }
+ else
+ irc_server_sendf (ptr_server, "LIST");
+
+ return 0;
+}
+
+/*
+ * irc_cmd_lusers: get statistics about ths size of the IRC network
+ */
+
+int
+irc_cmd_lusers (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (arguments)
+ irc_server_sendf (ptr_server, "LUSERS %s", arguments);
+ else
+ irc_server_sendf (ptr_server, "LUSERS");
+ return 0;
+}
+
+/*
+ * irc_cmd_me: send a ctcp action to the current channel
+ */
+
+int
+irc_cmd_me (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (!ptr_channel)
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can not be executed "
+ "on a server buffer\n"),
+ WEECHAT_ERROR, "me");
+ return -1;
+ }
+ irc_cmd_me_channel (ptr_server, ptr_channel, arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_mode_server! send MODE command on a server
+ */
+
+void
+irc_cmd_mode_server (t_irc_server *server, char *arguments)
+{
+ irc_server_sendf (server, "MODE %s", arguments);
+}
+
+/*
+ * irc_cmd_mode: change mode for channel/nickname
+ */
+
+int
+irc_cmd_mode (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ irc_cmd_mode_server (ptr_server, arguments);
+
+ return 0;
+}
+
+/*
+ * irc_cmd_motd: get the "Message Of The Day"
+ */
+
+int
+irc_cmd_motd (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (arguments)
+ irc_server_sendf (ptr_server, "MOTD %s", arguments);
+ else
+ irc_server_sendf (ptr_server, "MOTD");
+ return 0;
+}
+
+/*
+ * irc_cmd_msg: send a message to a nick or channel
+ */
+
+int
+irc_cmd_msg (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ char *pos, *pos_comma;
+ char *msg_pwd_hidden;
+ t_irc_nick *ptr_nick;
+ char *string;
+
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+
+ while (arguments && arguments[0])
+ {
+ pos_comma = strchr (arguments, ',');
+ if (pos_comma)
+ {
+ pos_comma[0] = '\0';
+ pos_comma++;
+ }
+ if (strcmp (arguments, "*") == 0)
+ {
+ if (!ptr_channel
+ || ((ptr_channel->type != IRC_CHANNEL_TYPE_CHANNEL)
+ && (ptr_channel->type != IRC_CHANNEL_TYPE_PRIVATE)))
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can "
+ "only be executed in a "
+ "channel or private "
+ "buffer\n"),
+ WEECHAT_ERROR, "msg *");
+ return -1;
+ }
+ if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL)
+ ptr_nick = irc_nick_search (ptr_channel, ptr_server->nick);
+ else
+ ptr_nick = NULL;
+ irc_display_nick (ptr_channel->buffer, ptr_nick,
+ (ptr_nick) ? NULL : ptr_server->nick,
+ GUI_MSG_TYPE_NICK, 1, NULL, 0);
+ string = (char *)irc_color_decode ((unsigned char *)pos, 1, 0);
+ gui_chat_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_MSG,
+ NULL, -1,
+ "%s\n",
+ (string) ? string : "");
+ if (string)
+ free (string);
+
+ irc_server_sendf (ptr_server, "PRIVMSG %s :%s",
+ ptr_channel->name, pos);
+ }
+ else
+ {
+ if (irc_channel_is_channel (arguments))
+ {
+ ptr_channel = irc_channel_search (ptr_server, arguments);
+ if (ptr_channel)
+ {
+ ptr_nick = irc_nick_search (ptr_channel,
+ ptr_server->nick);
+ if (ptr_nick)
+ {
+ irc_display_nick (ptr_channel->buffer, ptr_nick,
+ NULL, GUI_MSG_TYPE_NICK, 1,
+ NULL, 0);
+ string = (char *)irc_color_decode (
+ (unsigned char *)pos, 1, 0);
+ gui_chat_printf_type (ptr_channel->buffer,
+ GUI_MSG_TYPE_MSG,
+ NULL, -1,
+ "%s\n",
+ (string) ? string : "");
+ if (string)
+ free (string);
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s nick \"%s\" "
+ "not found for "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR,
+ ptr_server->nick,
+ "msg");
+ }
+ }
+ irc_server_sendf (ptr_server, "PRIVMSG %s :%s",
+ arguments, pos);
+ }
+ else
+ {
+ /* message to nickserv with identify ? */
+ if (strcmp (arguments, "nickserv") == 0)
+ {
+ msg_pwd_hidden = strdup (pos);
+ if (irc_cfg_log_hide_nickserv_pwd)
+ irc_display_hide_password (msg_pwd_hidden, 0);
+ gui_chat_printf_type (ptr_server->buffer,
+ GUI_MSG_TYPE_NICK,
+ cfg_look_prefix_server,
+ cfg_col_chat_prefix_server,
+ "%s-%s%s%s- ",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ arguments,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
+ string = (char *)irc_color_decode (
+ (unsigned char *)msg_pwd_hidden, 1, 0);
+ gui_chat_printf (ptr_server->buffer,
+ "%s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (string) ? string : "");
+ if (string)
+ free (string);
+ irc_server_sendf (ptr_server, "PRIVMSG %s :%s",
+ arguments, pos);
+ free (msg_pwd_hidden);
+ return 0;
+ }
+
+ string = (char *)irc_color_decode (
+ (unsigned char *)pos, 1, 0);
+ ptr_channel = irc_channel_search (ptr_server, arguments);
+ if (ptr_channel)
+ {
+ irc_display_nick (ptr_channel->buffer, NULL,
+ ptr_server->nick,
+ GUI_MSG_TYPE_NICK, 1,
+ GUI_COLOR(GUI_CHAT_NICK_SELF),
+ 0);
+ gui_chat_printf_type (ptr_channel->buffer,
+ GUI_MSG_TYPE_MSG,
+ NULL, -1,
+ "%s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (string) ? string : "");
+ }
+ else
+ {
+ gui_chat_printf_server (ptr_server->buffer,
+ "MSG%s(%s%s%s)%s: ",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ arguments,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT));
+ gui_chat_printf_type (ptr_server->buffer,
+ GUI_MSG_TYPE_MSG,
+ cfg_look_prefix_server,
+ cfg_col_chat_prefix_server,
+ "%s\n",
+ (string) ? string : pos);
+ }
+ if (string)
+ free (string);
+ irc_server_sendf (ptr_server, "PRIVMSG %s :%s",
+ arguments, pos);
+ }
+ }
+ arguments = pos_comma;
+ }
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s wrong argument count for \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "msg");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_names: list nicknames on channels
+ */
+
+int
+irc_cmd_names (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (arguments)
+ irc_server_sendf (ptr_server, "NAMES %s", arguments);
+ else
+ {
+ if (ptr_channel && (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL))
+ irc_server_sendf (ptr_server, "NAMES %s",
+ ptr_channel->name);
+ else
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can only be "
+ "executed in a channel buffer\n"),
+ WEECHAT_ERROR, "names");
+ return -1;
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_send_nick_server: change nickname on a server
+ */
+
+void
+irc_send_nick_server (t_irc_server *server, char *nickname)
+{
+ t_irc_channel *ptr_channel;
+
+ if (!server)
+ return;
+
+ if (server->is_connected)
+ irc_server_sendf (server, "NICK %s", nickname);
+ else
+ {
+ if (server->nick)
+ free (server->nick);
+ server->nick = strdup (nickname);
+ gui_input_draw (server->buffer, 1);
+ for (ptr_channel = server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
+ {
+ gui_input_draw (ptr_channel->buffer, 1);
+ }
+ }
+}
+
+/*
+ * irc_cmd_nick: change nickname
+ */
+
+int
+irc_cmd_nick (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server)
+ return -1;
+
+ /* make C compiler happy */
+ (void) arguments;
+
+ if (argc == 2)
+ {
+ if (strncmp (argv[0], "-all", 4) != 0)
+ return -1;
+
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ irc_send_nick_server (ptr_server, argv[1]);
+ }
+ }
+ else
+ {
+ if (argc == 1)
+ irc_send_nick_server (ptr_server, argv[0]);
+ else
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * irc_cmd_notice: send notice message
+ */
+
+int
+irc_cmd_notice (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ char *pos, *string;
+
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ string = (char *)irc_color_decode ((unsigned char *)pos, 1, 0);
+ gui_chat_printf_server (ptr_server->buffer,
+ "notice%s(%s%s%s)%s: %s\n",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ arguments,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (string) ? string : "");
+ if (string)
+ free (string);
+ irc_server_sendf (ptr_server, "NOTICE %s :%s",
+ arguments, pos);
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s wrong argument count for \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "notice");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_op: give operator privileges to nickname(s)
+ */
+
+int
+irc_cmd_op (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) arguments;
+
+ if (ptr_channel && (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL))
+ {
+ if (argc == 0)
+ irc_server_sendf (ptr_server, "MODE %s +o %s",
+ ptr_channel->name,
+ ptr_server->nick);
+ else
+ irc_cmd_mode_nicks (ptr_server, ptr_channel->name,
+ "+", "o", argc, argv);
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can only be "
+ "executed in a channel buffer\n"),
+ WEECHAT_ERROR, "op");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_oper: get oper privileges
+ */
+
+int
+irc_cmd_oper (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ irc_server_sendf (ptr_server, "OPER %s", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_part: leave a channel or close a private window
+ */
+
+int
+irc_cmd_part (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ char *channel_name, *pos_args, *ptr_arg, *buf;
+
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (arguments)
+ {
+ if (irc_channel_is_channel (arguments))
+ {
+ channel_name = arguments;
+ pos_args = strchr (arguments, ' ');
+ if (pos_args)
+ {
+ pos_args[0] = '\0';
+ pos_args++;
+ while (pos_args[0] == ' ')
+ pos_args++;
+ }
+ }
+ else
+ {
+ if (!ptr_channel)
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can only be "
+ "executed in a channel or "
+ "private buffer\n"),
+ WEECHAT_ERROR, "part");
+ return -1;
+ }
+ channel_name = ptr_channel->name;
+ pos_args = arguments;
+ }
+ }
+ else
+ {
+ if (!ptr_channel)
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can only be "
+ "executed in a channel or private "
+ "buffer\n"),
+ WEECHAT_ERROR, "part");
+ return -1;
+ }
+ if (!ptr_channel->nicks)
+ {
+ gui_buffer_free (ptr_channel->buffer, 1);
+ irc_channel_free (ptr_server, ptr_channel);
+ gui_status_draw (gui_current_window->buffer, 1);
+ gui_input_draw (gui_current_window->buffer, 1);
+ return 0;
+ }
+ channel_name = ptr_channel->name;
+ pos_args = NULL;
+ }
+
+ ptr_arg = (pos_args) ? pos_args :
+ (irc_cfg_irc_default_msg_part && irc_cfg_irc_default_msg_part[0]) ?
+ irc_cfg_irc_default_msg_part : NULL;
+
+ if (ptr_arg)
+ {
+ buf = weechat_strreplace (ptr_arg, "%v", PACKAGE_VERSION);
+ irc_server_sendf (ptr_server, "PART %s :%s",
+ channel_name,
+ (buf) ? buf : ptr_arg);
+ if (buf)
+ free (buf);
+ }
+ else
+ irc_server_sendf (ptr_server, "PART %s", channel_name);
+
+ return 0;
+}
+
+/*
+ * irc_cmd_ping: ping a server
+ */
+
+int
+irc_cmd_ping (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ irc_server_sendf (ptr_server, "PING %s", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_pong: send pong answer to a daemon
+ */
+
+int
+irc_cmd_pong (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ irc_server_sendf (ptr_server, "PONG %s", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_query: start private conversation with a nick
+ */
+
+int
+irc_cmd_query (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ char *pos, *string;
+
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ if (!pos[0])
+ pos = NULL;
+ }
+
+ /* create private window if not already opened */
+ ptr_channel = irc_channel_search (ptr_server, arguments);
+ if (!ptr_channel)
+ {
+ ptr_channel = irc_channel_new (ptr_server,
+ IRC_CHANNEL_TYPE_PRIVATE,
+ arguments, 1);
+ if (!ptr_channel)
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s cannot create new private "
+ "buffer \"%s\"\n"),
+ WEECHAT_ERROR, arguments);
+ return -1;
+ }
+ gui_chat_draw_title (ptr_channel->buffer, 1);
+ }
+ else
+ {
+ if (window->buffer != ptr_channel->buffer)
+ {
+ gui_window_switch_to_buffer (window, ptr_channel->buffer);
+ gui_window_redraw_buffer (ptr_channel->buffer);
+ }
+ }
+
+ /* display text if given */
+ if (pos)
+ {
+ irc_display_nick (ptr_channel->buffer, NULL, ptr_server->nick,
+ GUI_MSG_TYPE_NICK, 1,
+ GUI_COLOR(GIU_COLOR_CHAT_NICK_SELF), 0);
+ string = (char *)irc_color_decode ((unsigned char *)pos, 1, 0);
+ gui_chat_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_MSG,
+ NULL, -1,
+ "%s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (string) ? string : "");
+ if (string)
+ free (string);
+ irc_server_sendf (ptr_server, "PRIVMSG %s :%s",
+ arguments, pos);
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_quit: disconnect from all servers and quit WeeChat
+ */
+
+int
+irc_cmd_quit (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ t_irc_server *ptr_server;
+
+ /* make C compiler happy */
+ (void) window;
+ (void) argc;
+ (void) argv;
+
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ irc_cmd_quit_server (ptr_server, arguments);
+ }
+ quit_weechat = 1;
+ return 0;
+}
+
+/*
+ * irc_cmd_quote: send raw data to server
+ */
+
+int
+irc_cmd_quote (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (ptr_server->sock < 0)
+ {
+ gui_chat_printf_error_nolog (NULL,
+ _("%s command \"%s\" needs a server "
+ "connection!\n"),
+ WEECHAT_ERROR, "quote");
+ return -1;
+ }
+ irc_server_sendf (ptr_server, "%s", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_reconnect_one_server: reconnect to a server
+ * return 0 if error, 1 if ok
+ */
+
+int
+irc_cmd_reconnect_one_server (t_irc_server *server, int no_join)
+{
+ if (!server)
+ return 0;
+
+ if ((!server->is_connected) && (server->child_pid == 0))
+ {
+ gui_chat_printf_error (server->buffer,
+ _("%s not connected to server \"%s\"!\n"),
+ WEECHAT_ERROR, server->name);
+ return 0;
+ }
+ irc_cmd_quit_server (server, NULL);
+ irc_server_disconnect (server, 0);
+ if (irc_server_connect (server, no_join))
+ {
+ server->reconnect_start = 0;
+ server->reconnect_join = (server->channels) ? 1 : 0;
+ }
+ gui_status_draw (server->buffer, 1);
+
+ /* reconnect ok */
+ return 1;
+}
+
+/*
+ * irc_cmd_reconnect: reconnect to server(s)
+ */
+
+int
+irc_cmd_reconnect (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ int i, nb_reconnect, reconnect_ok, all_servers, no_join;
+
+ IRC_BUFFER_GET_SERVER(window->buffer);
+
+ /* make C compiler happy */
+ (void) arguments;
+
+ nb_reconnect = 0;
+ reconnect_ok = 1;
+
+ all_servers = 0;
+ no_join = 0;
+ for (i = 0; i < argc; i++)
+ {
+ if (weechat_strcasecmp (argv[i], "-all") == 0)
+ all_servers = 1;
+ if (weechat_strcasecmp (argv[i], "-nojoin") == 0)
+ no_join = 1;
+ }
+
+ if (all_servers)
+ {
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ nb_reconnect++;
+ if ((ptr_server->is_connected) || (ptr_server->child_pid != 0))
+ {
+ if (!irc_cmd_reconnect_one_server (ptr_server, no_join))
+ reconnect_ok = 0;
+ }
+ }
+ }
+ else
+ {
+ for (i = 0; i < argc; i++)
+ {
+ if (argv[i][0] != '-')
+ {
+ nb_reconnect++;
+ ptr_server = irc_server_search (argv[i]);
+ if (ptr_server)
+ {
+ if (!irc_cmd_reconnect_one_server (ptr_server, no_join))
+ reconnect_ok = 0;
+ }
+ else
+ {
+ gui_chat_printf_error (NULL,
+ _("%s server \"%s\" not found\n"),
+ WEECHAT_ERROR, argv[i]);
+ reconnect_ok = 0;
+ }
+ }
+ }
+ }
+
+ if (nb_reconnect == 0)
+ reconnect_ok = irc_cmd_reconnect_one_server (ptr_server, no_join);
+
+ if (!reconnect_ok)
+ return -1;
+
+ return 0;
+}
+
+/*
+ * irc_cmd_rehash: tell the server to reload its config file
+ */
+
+int
+irc_cmd_rehash (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) arguments;
+ (void) argc;
+ (void) argv;
+
+ irc_server_sendf (ptr_server, "REHASH");
+ return 0;
+}
+
+/*
+ * irc_cmd_restart: tell the server to restart itself
+ */
+
+int
+irc_cmd_restart (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) arguments;
+ (void) argc;
+ (void) argv;
+
+ irc_server_sendf (ptr_server, "RESTART");
+ return 0;
+}
+
+/*
+ * irc_cmd_server: manage IRC servers
+ */
+
+int
+irc_cmd_server (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ int i, detailed_list, one_server_found;
+ t_irc_server server_tmp, *ptr_server, *server_found, *new_server;
+ char *server_name, *error;
+ long number;
+ t_gui_buffer *ptr_buffer;
+
+ /* make C compiler happy */
+ (void) arguments;
+
+ if ((argc == 0)
+ || (weechat_strcasecmp (argv[0], "list") == 0)
+ || (weechat_strcasecmp (argv[0], "listfull") == 0))
+ {
+ /* list servers */
+ server_name = NULL;
+ detailed_list = 0;
+ for (i = 0; i < argc; i++)
+ {
+ if (weechat_strcasecmp (argv[i], "list") == 0)
+ continue;
+ if (weechat_strcasecmp (argv[i], "listfull") == 0)
+ {
+ detailed_list = 1;
+ continue;
+ }
+ if (!server_name)
+ server_name = argv[i];
+ }
+ if (!server_name)
+ {
+ if (irc_servers)
+ {
+ gui_chat_printf (NULL, "\n");
+ gui_chat_printf (NULL, _("All servers:\n"));
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ irc_display_server (ptr_server, detailed_list);
+ }
+ }
+ else
+ gui_chat_printf_info (NULL, _("No server.\n"));
+ }
+ else
+ {
+ one_server_found = 0;
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ if (weechat_strcasestr (ptr_server->name, server_name))
+ {
+ if (!one_server_found)
+ {
+ gui_chat_printf (NULL, "\n");
+ gui_chat_printf (NULL, _("Servers with '%s':\n"),
+ server_name);
+ }
+ one_server_found = 1;
+ irc_display_server (ptr_server, detailed_list);
+ }
+ }
+ if (!one_server_found)
+ gui_chat_printf_info (NULL,
+ _("No server with '%s' found.\n"),
+ server_name);
+ }
+ }
+ else
+ {
+ if (weechat_strcasecmp (argv[0], "add") == 0)
+ {
+ if (argc < 3)
+ {
+ gui_chat_printf_error (NULL,
+ _("%s missing parameters for \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "server");
+ return -1;
+ }
+
+ if (irc_server_name_already_exists (argv[1]))
+ {
+ gui_chat_printf_error (NULL,
+ _("%s server \"%s\" already exists, "
+ "can't create it!\n"),
+ WEECHAT_ERROR, argv[1]);
+ return -1;
+ }
+
+ /* init server struct */
+ irc_server_init (&server_tmp);
+
+ server_tmp.name = strdup (argv[1]);
+ server_tmp.address = strdup (argv[2]);
+ server_tmp.port = IRC_SERVER_DEFAULT_PORT;
+
+ /* parse arguments */
+ for (i = 3; i < argc; i++)
+ {
+ if (argv[i][0] == '-')
+ {
+ if (weechat_strcasecmp (argv[i], "-temp") == 0)
+ server_tmp.temp_server = 1;
+ if (weechat_strcasecmp (argv[i], "-auto") == 0)
+ server_tmp.autoconnect = 1;
+ if (weechat_strcasecmp (argv[i], "-noauto") == 0)
+ server_tmp.autoconnect = 0;
+ if (weechat_strcasecmp (argv[i], "-ipv6") == 0)
+ server_tmp.ipv6 = 1;
+ if (weechat_strcasecmp (argv[i], "-ssl") == 0)
+ server_tmp.ssl = 1;
+ if (weechat_strcasecmp (argv[i], "-port") == 0)
+ {
+ if (i == (argc - 1))
+ {
+ gui_chat_printf_error (NULL,
+ _("%s missing argument for "
+ "\"%s\" option\n"),
+ WEECHAT_ERROR, "-port");
+ irc_server_destroy (&server_tmp);
+ return -1;
+ }
+ error = NULL;
+ number = strtol (argv[++i], &error, 10);
+ if (error && (error[0] == '\0'))
+ server_tmp.port = number;
+ }
+ if (weechat_strcasecmp (argv[i], "-pwd") == 0)
+ {
+ if (i == (argc - 1))
+ {
+ gui_chat_printf_error (NULL,
+ _("%s missing argument for "
+ "\"%s\" option\n"),
+ WEECHAT_ERROR, "-pwd");
+ irc_server_destroy (&server_tmp);
+ return -1;
+ }
+ server_tmp.password = strdup (argv[++i]);
+ }
+ if (weechat_strcasecmp (argv[i], "-nicks") == 0)
+ {
+ if (i >= (argc - 3))
+ {
+ gui_chat_printf_error (NULL,
+ _("%s missing argument for "
+ "\"%s\" option\n"),
+ WEECHAT_ERROR, "-nicks");
+ irc_server_destroy (&server_tmp);
+ return -1;
+ }
+ server_tmp.nick1 = strdup (argv[++i]);
+ server_tmp.nick2 = strdup (argv[++i]);
+ server_tmp.nick3 = strdup (argv[++i]);
+ }
+ if (weechat_strcasecmp (argv[i], "-username") == 0)
+ {
+ if (i == (argc - 1))
+ {
+ gui_chat_printf_error (NULL,
+ _("%s missing argument for "
+ "\"%s\" option\n"),
+ WEECHAT_ERROR, "-username");
+ irc_server_destroy (&server_tmp);
+ return -1;
+ }
+ server_tmp.username = strdup (argv[++i]);
+ }
+ if (weechat_strcasecmp (argv[i], "-realname") == 0)
+ {
+ if (i == (argc - 1))
+ {
+ gui_chat_printf_error (NULL,
+ _("%s missing argument for "
+ "\"%s\" option\n"),
+ WEECHAT_ERROR, "-realname");
+ irc_server_destroy (&server_tmp);
+ return -1;
+ }
+ server_tmp.realname = strdup (argv[++i]);
+ }
+ if (weechat_strcasecmp (argv[i], "-command") == 0)
+ {
+ if (i == (argc - 1))
+ {
+ gui_chat_printf_error (NULL,
+ _("%s missing argument for "
+ "\"%s\" option\n"),
+ WEECHAT_ERROR, "-command");
+ irc_server_destroy (&server_tmp);
+ return -1;
+ }
+ server_tmp.command = strdup (argv[++i]);
+ }
+ if (weechat_strcasecmp (argv[i], "-autojoin") == 0)
+ {
+ if (i == (argc - 1))
+ {
+ gui_chat_printf_error (NULL,
+ _("%s missing argument for "
+ "\"%s\" option\n"),
+ WEECHAT_ERROR, "-autojoin");
+ irc_server_destroy (&server_tmp);
+ return -1;
+ }
+ server_tmp.autojoin = strdup (argv[++i]);
+ }
+ }
+ }
+
+ /* create new server */
+ new_server = irc_server_new (server_tmp.name,
+ server_tmp.autoconnect,
+ server_tmp.autoreconnect,
+ server_tmp.autoreconnect_delay,
+ server_tmp.temp_server,
+ server_tmp.address,
+ server_tmp.port,
+ server_tmp.ipv6,
+ server_tmp.ssl,
+ server_tmp.password,
+ server_tmp.nick1,
+ server_tmp.nick2,
+ server_tmp.nick3,
+ server_tmp.username,
+ server_tmp.realname,
+ server_tmp.hostname,
+ server_tmp.command,
+ 1, /* command_delay */
+ server_tmp.autojoin,
+ 1, /* autorejoin */
+ NULL);
+ if (new_server)
+ {
+ gui_chat_printf_info (NULL, _("Server %s%s%s created\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_SERVER),
+ server_tmp.name,
+ GUI_COLOR(GUI_COLOR_CHAT));
+ }
+ else
+ {
+ gui_chat_printf_error (NULL,
+ _("%s unable to create server\n"),
+ WEECHAT_ERROR);
+ irc_server_destroy (&server_tmp);
+ return -1;
+ }
+
+ if (new_server->autoconnect)
+ irc_server_connect (new_server, 0);
+
+ irc_server_destroy (&server_tmp);
+ }
+ else if (weechat_strcasecmp (argv[0], "copy") == 0)
+ {
+ if (argc < 3)
+ {
+ gui_chat_printf_error (NULL,
+ _("%s missing server name for \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "server copy");
+ return -1;
+ }
+
+ /* look for server by name */
+ server_found = irc_server_search (argv[1]);
+ if (!server_found)
+ {
+ gui_chat_printf_error (NULL,
+ _("%s server \"%s\" not found for "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, argv[1], "server copy");
+ return -1;
+ }
+
+ /* check if target name already exists */
+ if (irc_server_search (argv[2]))
+ {
+ gui_chat_printf_error (NULL,
+ _("%s server \"%s\" already exists for "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, argv[2], "server copy");
+ return -1;
+ }
+
+ /* duplicate server */
+ new_server = irc_server_duplicate (server_found, argv[2]);
+ if (new_server)
+ {
+ gui_chat_printf_info (NULL,
+ _("Server %s%s%s has been copied to "
+ "%s%s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_SERVER),
+ argv[1],
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_SERVER),
+ argv[2]);
+ gui_window_redraw_all_buffers ();
+ return 0;
+ }
+
+ return -1;
+ }
+ else if (weechat_strcasecmp (argv[0], "rename") == 0)
+ {
+ if (argc < 3)
+ {
+ gui_chat_printf_error (NULL,
+ _("%s missing server name for \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "server rename");
+ return -1;
+ }
+
+ /* look for server by name */
+ server_found = irc_server_search (argv[1]);
+ if (!server_found)
+ {
+ gui_chat_printf_error (NULL,
+ _("%s server \"%s\" not found for "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, argv[1],
+ "server rename");
+ return -1;
+ }
+
+ /* check if target name already exists */
+ if (irc_server_search (argv[2]))
+ {
+ gui_chat_printf_error (NULL,
+ _("%s server \"%s\" already exists for "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, argv[2],
+ "server rename");
+ return -1;
+ }
+
+ /* rename server */
+ if (irc_server_rename (server_found, argv[2]))
+ {
+ gui_chat_printf_info (NULL,
+ _("Server %s%s%s has been renamed to "
+ "%s%s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_SERVER),
+ argv[1],
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_SERVER),
+ argv[2]);
+ gui_window_redraw_all_buffers ();
+ return 0;
+ }
+
+ return -1;
+ }
+ else if (weechat_strcasecmp (argv[0], "keep") == 0)
+ {
+ if (argc < 2)
+ {
+ gui_chat_printf_error (NULL,
+ _("%s missing server name for \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "server keep");
+ return -1;
+ }
+
+ /* look for server by name */
+ server_found = irc_server_search (argv[1]);
+ if (!server_found)
+ {
+ gui_chat_printf_error (NULL,
+ _("%s server \"%s\" not found for "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, argv[1], "server keep");
+ return -1;
+ }
+
+ /* check that it is temporary server */
+ if (!server_found->temp_server)
+ {
+ gui_chat_printf_error (NULL,
+ _("%s server \"%s\" is not a temporary "
+ "server\n"),
+ WEECHAT_ERROR, argv[1]);
+ return -1;
+ }
+
+ /* remove temporary flag on server */
+ server_found->temp_server = 0;
+
+ gui_chat_printf_info (NULL,
+ _("Server %s%s%s is not temporary any "
+ "more\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_SERVER),
+ argv[1],
+ GUI_COLOR(GUI_COLOR_CHAT));
+
+ return 0;
+ }
+ else if (weechat_strcasecmp (argv[0], "del") == 0)
+ {
+ if (argc < 2)
+ {
+ gui_chat_printf_error (NULL,
+ _("%s missing server name for \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "server del");
+ return -1;
+ }
+
+ /* look for server by name */
+ server_found = irc_server_search (argv[1]);
+ if (!server_found)
+ {
+ gui_chat_printf_error (NULL,
+ _("%s server \"%s\" not found for "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, argv[1], "server del");
+ return -1;
+ }
+ if (server_found->is_connected)
+ {
+ gui_chat_printf_error (NULL,
+ _("%s you can not delete server \"%s\" "
+ "because you are connected to. "
+ "Try /disconnect %s before.\n"),
+ WEECHAT_ERROR, argv[1], argv[1]);
+ return -1;
+ }
+
+ for (ptr_buffer = gui_buffers; ptr_buffer;
+ ptr_buffer = ptr_buffer->next_buffer)
+ {
+ if ((ptr_buffer->protocol == irc_protocol)
+ && (IRC_BUFFER_SERVER(ptr_buffer) == server_found))
+ {
+ IRC_BUFFER_SERVER(ptr_buffer) = NULL;
+ IRC_BUFFER_CHANNEL(ptr_buffer) = NULL;
+ }
+ }
+
+ server_name = strdup (server_found->name);
+
+ irc_server_free (server_found);
+
+ gui_chat_printf_info (NULL, _("Server %s%s%s has been deleted\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_SERVER),
+ server_name,
+ GUI_COLOR(GUI_COLOR_CHAT));
+ if (server_name)
+ free (server_name);
+
+ gui_window_redraw_buffer (window->buffer);
+
+ return 0;
+ }
+ else if (weechat_strcasecmp (argv[0], "deloutq") == 0)
+ {
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ irc_server_outqueue_free_all (ptr_server);
+ }
+ gui_chat_printf_info_nolog (NULL,
+ _("Messages outqueue DELETED for all "
+ "servers. Some messages from you or "
+ "WeeChat may have been lost!\n"));
+ return 0;
+ }
+ else
+ {
+ gui_chat_printf_error (NULL,
+ _("%s unknown option for \"%s\" command\n"),
+ WEECHAT_ERROR, "server");
+ return -1;
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_service: register a new service
+ */
+
+int
+irc_cmd_service (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ irc_server_sendf (ptr_server, "SERVICE %s", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_servlist: list services currently connected to the network
+ */
+
+int
+irc_cmd_servlist (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (arguments)
+ irc_server_sendf (ptr_server, "SERVLIST %s", arguments);
+ else
+ irc_server_sendf (ptr_server, "SERVLIST");
+ return 0;
+}
+
+/*
+ * irc_cmd_squery: deliver a message to a service
+ */
+
+int
+irc_cmd_squery (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ char *pos;
+
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ {
+ pos++;
+ }
+ irc_server_sendf (ptr_server, "SQUERY %s :%s", arguments, pos);
+ }
+ else
+ irc_server_sendf (ptr_server, "SQUERY %s", arguments);
+
+ return 0;
+}
+
+/*
+ * irc_cmd_squit: disconnect server links
+ */
+
+int
+irc_cmd_squit (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ irc_server_sendf (ptr_server, "SQUIT %s", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_stats: query statistics about server
+ */
+
+int
+irc_cmd_stats (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (arguments)
+ irc_server_sendf (ptr_server, "STATS %s", arguments);
+ else
+ irc_server_sendf (ptr_server, "STATS");
+ return 0;
+}
+
+/*
+ * irc_cmd_summon: give users who are on a host running an IRC server
+ * a message asking them to please join IRC
+ */
+
+int
+irc_cmd_summon (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ irc_server_sendf (ptr_server, "SUMMON %s", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_time: query local time from server
+ */
+
+int
+irc_cmd_time (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (arguments)
+ irc_server_sendf (ptr_server, "TIME %s", arguments);
+ else
+ irc_server_sendf (ptr_server, "TIME");
+ return 0;
+}
+
+/*
+ * irc_cmd_topic: get/set topic for a channel
+ */
+
+int
+irc_cmd_topic (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ char *channel_name, *new_topic, *pos;
+
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ channel_name = NULL;
+ new_topic = NULL;
+
+ if (arguments)
+ {
+ if (irc_channel_is_channel (arguments))
+ {
+ channel_name = arguments;
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ new_topic = (pos[0]) ? pos : NULL;
+ }
+ }
+ else
+ new_topic = arguments;
+ }
+
+ /* look for current channel if not specified */
+ if (!channel_name)
+ {
+ if (ptr_channel && (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL))
+ channel_name = ptr_channel->name;
+ else
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can only be "
+ "executed in a channel buffer\n"),
+ WEECHAT_ERROR, "topic");
+ return -1;
+ }
+ }
+
+ if (new_topic)
+ {
+ if (strcmp (new_topic, "-delete") == 0)
+ irc_server_sendf (ptr_server, "TOPIC %s :",
+ channel_name);
+ else
+ irc_server_sendf (ptr_server, "TOPIC %s :%s",
+ channel_name, new_topic);
+ }
+ else
+ irc_server_sendf (ptr_server, "TOPIC %s",
+ channel_name);
+
+ return 0;
+}
+
+/*
+ * irc_cmd_trace: find the route to specific server
+ */
+
+int
+irc_cmd_trace (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (arguments)
+ irc_server_sendf (ptr_server, "TRACE %s", arguments);
+ else
+ irc_server_sendf (ptr_server, "TRACE");
+ return 0;
+}
+
+/*
+ * irc_cmd_unban: unbans nicks or hosts
+ */
+
+int
+irc_cmd_unban (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ char *pos_channel, *pos, *pos2;
+
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (arguments)
+ {
+ pos_channel = NULL;
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+
+ if (irc_channel_is_channel (arguments))
+ {
+ pos_channel = arguments;
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ }
+ else
+ {
+ pos[0] = ' ';
+ pos = arguments;
+ }
+ }
+ else
+ pos = arguments;
+
+ /* channel not given, use default buffer */
+ if (!pos_channel)
+ {
+ if (ptr_channel && (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL))
+ pos_channel = ptr_channel->name;
+ else
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can only be "
+ "executed in a channel "
+ "buffer\n"),
+ WEECHAT_ERROR, "unban");
+ return -1;
+ }
+ }
+
+ /* loop on users */
+ while (pos && pos[0])
+ {
+ pos2 = strchr (pos, ' ');
+ if (pos2)
+ {
+ pos2[0] = '\0';
+ pos2++;
+ while (pos2[0] == ' ')
+ pos2++;
+ }
+ irc_server_sendf (ptr_server, "MODE %s -b %s",
+ pos_channel, pos);
+ pos = pos2;
+ }
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s wrong argument count for \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "unban");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_userhost: return a list of information about nicknames
+ */
+
+int
+irc_cmd_userhost (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ irc_server_sendf (ptr_server, "USERHOST %s", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_users: list of users logged into the server
+ */
+
+int
+irc_cmd_users (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (arguments)
+ irc_server_sendf (ptr_server, "USERS %s", arguments);
+ else
+ irc_server_sendf (ptr_server, "USERS");
+ return 0;
+}
+
+/*
+ * irc_cmd_version: gives the version info of nick or server (current or specified)
+ */
+
+int
+irc_cmd_version (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (arguments)
+ {
+ if (ptr_channel && (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL)
+ && irc_nick_search (ptr_channel, arguments))
+ irc_server_sendf (ptr_server, "PRIVMSG %s :\01VERSION\01",
+ arguments);
+ else
+ irc_server_sendf (ptr_server, "VERSION %s",
+ arguments);
+ }
+ else
+ {
+ gui_chat_printf_info (ptr_server->buffer,
+ _("%s, compiled on %s %s\n"),
+ PACKAGE_STRING,
+ __DATE__, __TIME__);
+ irc_server_sendf (ptr_server, "VERSION");
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_voice: give voice to nickname(s)
+ */
+
+int
+irc_cmd_voice (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) arguments;
+
+ if (ptr_channel && (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL))
+ {
+ if (argc == 0)
+ irc_server_sendf (ptr_server, "MODE %s +v %s",
+ ptr_channel->name,
+ ptr_server->nick);
+ else
+ irc_cmd_mode_nicks (ptr_server, ptr_channel->name,
+ "+", "v", argc, argv);
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (ptr_server->buffer,
+ _("%s \"%s\" command can only be "
+ "executed in a channel buffer\n"),
+ WEECHAT_ERROR, "voice");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_wallops: send a message to all currently connected users who
+ * have set the 'w' user mode for themselves
+ */
+
+int
+irc_cmd_wallops (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ irc_server_sendf (ptr_server, "WALLOPS :%s", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_who: generate a query which returns a list of information
+ */
+
+int
+irc_cmd_who (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ if (arguments)
+ irc_server_sendf (ptr_server, "WHO %s", arguments);
+ else
+ irc_server_sendf (ptr_server, "WHO");
+ return 0;
+}
+
+/*
+ * irc_cmd_whois: query information about user(s)
+ */
+
+int
+irc_cmd_whois (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ irc_server_sendf (ptr_server, "WHOIS %s", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_whowas: ask for information about a nickname which no longer exists
+ */
+
+int
+irc_cmd_whowas (t_gui_window *window,
+ char *arguments, int argc, char **argv)
+{
+ IRC_BUFFER_GET_SERVER(window->buffer);
+ if (!ptr_server || !ptr_server->is_connected)
+ return -1;
+
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
+ irc_server_sendf (ptr_server, "WHOWAS %s", arguments);
+ return 0;
+}
diff --git a/src/plugins/irc/irc-command.h b/src/plugins/irc/irc-command.h
new file mode 100644
index 000000000..02d2db87d
--- /dev/null
+++ b/src/plugins/irc/irc-command.h
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __WEECHAT_IRC_COMMAND_H
+#define __WEECHAT_IRC_COMMAND_H 1
+
+#include "../../core/command.h"
+
+extern t_weechat_command irc_commands[];
+
+extern int irc_cmd_admin (t_gui_window *, char *, int, char **);
+extern int irc_cmd_ame (t_gui_window *, char *, int, char **);
+extern int irc_cmd_amsg (t_gui_window *, char *, int, char **);
+extern int irc_cmd_away (t_gui_window *, char *, int, char **);
+extern int irc_cmd_ban (t_gui_window *, char *, int, char **);
+extern int irc_cmd_connect (t_gui_window *, char *, int, char **);
+extern int irc_cmd_ctcp (t_gui_window *, char *, int, char **);
+extern int irc_cmd_cycle (t_gui_window *, char *, int, char **);
+extern int irc_cmd_dcc (t_gui_window *, char *, int, char **);
+extern int irc_cmd_dehalfop (t_gui_window *, char *, int, char **);
+extern int irc_cmd_deop (t_gui_window *, char *, int, char **);
+extern int irc_cmd_devoice (t_gui_window *, char *, int, char **);
+extern int irc_cmd_die (t_gui_window *, char *, int, char **);
+extern int irc_cmd_disconnect (t_gui_window *, char *, int, char **);
+extern int irc_cmd_halfop (t_gui_window *, char *, int, char **);
+extern int irc_cmd_info (t_gui_window *, char *, int, char **);
+extern int irc_cmd_invite (t_gui_window *, char *, int, char **);
+extern int irc_cmd_ison (t_gui_window *, char *, int, char **);
+extern int irc_cmd_join (t_gui_window *, char *, int, char **);
+extern int irc_cmd_kick (t_gui_window *, char *, int, char **);
+extern int irc_cmd_kickban (t_gui_window *, char *, int, char **);
+extern int irc_cmd_kill (t_gui_window *, char *, int, char **);
+extern int irc_cmd_links (t_gui_window *, char *, int, char **);
+extern int irc_cmd_list (t_gui_window *, char *, int, char **);
+extern int irc_cmd_lusers (t_gui_window *, char *, int, char **);
+extern int irc_cmd_me (t_gui_window *, char *, int, char **);
+extern int irc_cmd_mode (t_gui_window *, char *, int, char **);
+extern int irc_cmd_motd (t_gui_window *, char *, int, char **);
+extern int irc_cmd_msg (t_gui_window *, char *, int, char **);
+extern int irc_cmd_msg (t_gui_window *, char *, int, char **);
+extern int irc_cmd_names (t_gui_window *, char *, int, char **);
+extern int irc_cmd_nick (t_gui_window *, char *, int, char **);
+extern int irc_cmd_notice (t_gui_window *, char *, int, char **);
+extern int irc_cmd_op (t_gui_window *, char *, int, char **);
+extern int irc_cmd_oper (t_gui_window *, char *, int, char **);
+extern int irc_cmd_part (t_gui_window *, char *, int, char **);
+extern int irc_cmd_ping (t_gui_window *, char *, int, char **);
+extern int irc_cmd_pong (t_gui_window *, char *, int, char **);
+extern int irc_cmd_query (t_gui_window *, char *, int, char **);
+extern int irc_cmd_quit (t_gui_window *, char *, int, char **);
+extern int irc_cmd_quote (t_gui_window *, char *, int, char **);
+extern int irc_cmd_reconnect (t_gui_window *, char *, int, char **);
+extern int irc_cmd_rehash (t_gui_window *, char *, int, char **);
+extern int irc_cmd_restart (t_gui_window *, char *, int, char **);
+extern int irc_cmd_service (t_gui_window *, char *, int, char **);
+extern int irc_cmd_server (t_gui_window *, char *, int, char **);
+extern int irc_cmd_servlist (t_gui_window *, char *, int, char **);
+extern int irc_cmd_squery (t_gui_window *, char *, int, char **);
+extern int irc_cmd_squit (t_gui_window *, char *, int, char **);
+extern int irc_cmd_stats (t_gui_window *, char *, int, char **);
+extern int irc_cmd_summon (t_gui_window *, char *, int, char **);
+extern int irc_cmd_time (t_gui_window *, char *, int, char **);
+extern int irc_cmd_topic (t_gui_window *, char *, int, char **);
+extern int irc_cmd_trace (t_gui_window *, char *, int, char **);
+extern int irc_cmd_unban (t_gui_window *, char *, int, char **);
+extern int irc_cmd_userhost (t_gui_window *, char *, int, char **);
+extern int irc_cmd_users (t_gui_window *, char *, int, char **);
+extern int irc_cmd_version (t_gui_window *, char *, int, char **);
+extern int irc_cmd_voice (t_gui_window *, char *, int, char **);
+extern int irc_cmd_wallops (t_gui_window *, char *, int, char **);
+extern int irc_cmd_who (t_gui_window *, char *, int, char **);
+extern int irc_cmd_whois (t_gui_window *, char *, int, char **);
+extern int irc_cmd_whowas (t_gui_window *, char *, int, char **);
+
+#endif /* irc-command.h */
diff --git a/src/plugins/irc/irc-commands.c b/src/plugins/irc/irc-commands.c
deleted file mode 100644
index 762008dd8..000000000
--- a/src/plugins/irc/irc-commands.c
+++ /dev/null
@@ -1,514 +0,0 @@
-/*
- * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
- */
-
-/* irc-commands.c: implementation of IRC commands, according to
- RFC 1459,2810,2811,2812 */
-
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "../../common/weechat.h"
-#include "irc.h"
-#include "../../common/command.h"
-
-
-t_irc_command irc_commands[] =
-{ { "admin", N_("find information about the administrator of the server"),
- N_("[target]"),
- N_("target: server"),
- NULL, 0, 1, 0, 1, NULL, irc_send_cmd_admin, NULL },
- { "ame", N_("send a CTCP action to all channels of all connected servers"),
- N_("message"),
- N_("message: message to send"),
- "", 1, MAX_ARGS, 1, 1, NULL, irc_send_cmd_ame, NULL },
- { "amsg", N_("send message to all channels of all connected servers"),
- N_("text"),
- N_("text: text to send"),
- "", 1, MAX_ARGS, 1, 1, NULL, irc_send_cmd_amsg, NULL },
- { "away", N_("toggle away status"),
- N_("[-all] [message]"),
- N_(" -all: toggle away status on all connected servers\n"
- "message: message for away (if no message is given, away status is removed)"),
- "-all", 0, MAX_ARGS, 1, 0, NULL, irc_send_cmd_away, NULL },
- { "ban", N_("bans nicks or hosts"),
- N_("[channel] [nickname [nickname ...]]"),
- N_(" channel: channel for ban\n"
- "nickname: user or host to ban"),
- "%N", 0, MAX_ARGS, 0, 1, NULL, irc_send_cmd_ban, NULL },
- { "ctcp", N_("send a CTCP message (Client-To-Client Protocol)"),
- N_("receiver type [arguments]"),
- N_(" receiver: nick or channel to send CTCP to\n"
- " type: CTCP type (examples: \"version\", \"ping\", ..)\n"
- "arguments: arguments for CTCP"),
- "%c|%n action|ping|version", 2, MAX_ARGS, 1, 1, NULL, irc_send_cmd_ctcp, NULL },
- { "cycle", N_("leave and rejoin a channel"),
- N_("[channel[,channel]] [part_message]"),
- N_(" channel: channel name for cycle\n"
- "part_message: part message (displayed to other users)"),
- "%p", 0, MAX_ARGS, 0, 1, NULL, irc_send_cmd_cycle, NULL },
- { "dehalfop", N_("removes half channel operator status from nickname(s)"),
- N_("[nickname [nickname]]"), "",
- "", 0, MAX_ARGS, 0, 1, irc_send_cmd_dehalfop, NULL, NULL },
- { "deop", N_("removes channel operator status from nickname(s)"),
- N_("[nickname [nickname]]"), "",
- "", 0, MAX_ARGS, 0, 1, irc_send_cmd_deop, NULL, NULL },
- { "devoice", N_("removes voice from nickname(s)"),
- N_("[nickname [nickname]]"), "",
- "", 0, MAX_ARGS, 0, 1, irc_send_cmd_devoice, NULL, NULL },
- { "die", N_("shutdown the server"), "", "",
- NULL, 0, 0, 0, 1, NULL, irc_send_cmd_die, NULL },
- { "error", N_("error received from IRC server"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_error },
- { "halfop", N_("gives half channel operator status to nickname(s)"),
- N_("[nickname [nickname]]"), "",
- "", 0, MAX_ARGS, 0, 1, irc_send_cmd_halfop, NULL, NULL },
- { "info", N_("get information describing the server"),
- N_("[target]"),
- N_("target: server name"),
- NULL, 0, 1, 0, 1, NULL, irc_send_cmd_info, NULL },
- { "invite", N_("invite a nick on a channel"),
- N_("nickname channel"),
- N_("nickname: nick to invite\n"
- " channel: channel to invite"),
- "%n %c", 1, 2, 0, 1, irc_send_cmd_invite, NULL, irc_recv_cmd_invite },
- { "ison", N_("check if a nickname is currently on IRC"),
- N_("nickname [nickname ...]"),
- N_("nickname: nickname"),
- "", 1, MAX_ARGS, 0, 1, NULL, irc_send_cmd_ison, NULL },
- { "join", N_("join a channel"),
- N_("channel[,channel] [key[,key]]"),
- N_("channel: channel name to join\n"
- " key: key to join the channel"),
- "%C", 1, MAX_ARGS, 0, 1, NULL, irc_send_cmd_join, irc_recv_cmd_join },
- { "kick", N_("forcibly remove a user from a channel"),
- N_("[channel] nickname [comment]"),
- N_(" channel: channel where user is\n"
- "nickname: nickname to kick\n"
- " comment: comment for kick"),
- "%n %-", 1, MAX_ARGS, 0, 1, NULL, irc_send_cmd_kick, irc_recv_cmd_kick },
- { "kickban", N_("kicks and bans a nick from a channel"),
- N_("[channel] nickname [comment]"),
- N_(" channel: channel where user is\n"
- "nickname: nickname to kick and ban\n"
- " comment: comment for kick"),
- "%n %-", 1, MAX_ARGS, 0, 1, NULL, irc_send_cmd_kickban, NULL },
- { "kill", N_("close client-server connection"),
- N_("nickname comment"),
- N_("nickname: nickname\n"
- " comment: comment for kill"),
- "%n %-", 2, MAX_ARGS, 0, 1, NULL, irc_send_cmd_kill, irc_recv_cmd_kill },
- { "links", N_("list all servernames which are known by the server answering the query"),
- N_("[[server] server_mask]"),
- N_(" server: this server should answer the query\n"
- "server_mask: list of servers must match this mask"),
- NULL, 0, 2, 0, 1, NULL, irc_send_cmd_links, NULL },
- { "list", N_("list channels and their topic"),
- N_("[channel[,channel] [server]]"),
- N_("channel: channel to list (a regexp is allowed)\nserver: server name"),
- NULL, 0, MAX_ARGS, 0, 1, NULL, irc_send_cmd_list, NULL },
- { "lusers", N_("get statistics about the size of the IRC network"),
- N_("[mask [target]]"),
- N_(" mask: servers matching the mask only\n"
- "target: server for forwarding request"),
- NULL, 0, 2, 0, 1, NULL, irc_send_cmd_lusers, NULL },
- { "me", N_("send a CTCP action to the current channel"),
- N_("message"),
- N_("message: message to send"),
- "", 0, MAX_ARGS, 1, 1, NULL, irc_send_cmd_me, NULL },
- { "mode", N_("change channel or user mode"),
- N_("{ channel {[+|-]|o|p|s|i|t|n|b|v} [limit] [user] [ban mask] } | "
- "{ nickname {[+|-]|i|w|s|o} }"),
- N_("channel modes:\n"
- " channel: channel name to modify\n"
- " o: give/take channel operator privileges\n"
- " p: private channel flag\n"
- " s: secret channel flag\n"
- " i: invite-only channel flag\n"
- " t: topic settable by channel operator only flag\n"
- " n: no messages to channel from clients on the outside\n"
- " m: moderated channel\n"
- " l: set the user limit to channel\n"
- " b: set a ban mask to keep users out\n"
- " e: set exception mask\n"
- " v: give/take the ability to speak on a moderated channel\n"
- " k: set a channel key (password)\n"
- "user modes:\n"
- " nickname: nickname to modify\n"
- " i: mark a user as invisible\n"
- " s: mark a user for receive server notices\n"
- " w: user receives wallops\n"
- " o: operator flag"),
- "%c|%m", 1, MAX_ARGS, 0, 1, NULL, irc_send_cmd_mode, irc_recv_cmd_mode },
- { "motd", N_("get the \"Message Of The Day\""),
- N_("[target]"),
- N_("target: server name"),
- NULL, 0, 1, 0, 1, NULL, irc_send_cmd_motd, NULL },
- { "msg", N_("send message to a nick or channel"),
- N_("receiver[,receiver] text"),
- N_("receiver: nick or channel (may be mask, '*' = current channel)\n"
- "text: text to send"),
- "", 2, MAX_ARGS, 1, 1, NULL, irc_send_cmd_msg, NULL },
- { "names", N_("list nicknames on channels"),
- N_("[channel[,channel]]"),
- N_("channel: channel name"),
- NULL, 0, 1, 0, 1, NULL, irc_send_cmd_names, NULL },
- { "nick", N_("change current nickname"),
- N_("[-all] nickname"),
- N_(" -all: set new nickname for all connected servers\n"
- "nickname: new nickname"),
- "-all", 1, 2, 0, 0, irc_send_cmd_nick, NULL, irc_recv_cmd_nick },
- { "notice", N_("send notice message to user"),
- N_("nickname text"),
- N_("nickname: user to send notice to\n"
- " text: text to send"),
- "%n %-", 2, MAX_ARGS, 1, 1, NULL, irc_send_cmd_notice, irc_recv_cmd_notice },
- { "op", N_("gives channel operator status to nickname(s)"),
- N_("nickname [nickname]"), "",
- "", 1, MAX_ARGS, 0, 1, irc_send_cmd_op, NULL, NULL },
- { "oper", N_("get operator privileges"),
- N_("user password"),
- N_("user/password: used to get privileges on current IRC server"),
- NULL, 2, 2, 0, 1, NULL, irc_send_cmd_oper, NULL },
- { "part", N_("leave a channel"),
- N_("[channel[,channel]] [part_message]"),
- N_(" channel: channel name to leave\n"
- "part_message: part message (displayed to other users)"),
- "%p", 0, MAX_ARGS, 0, 1, NULL, irc_send_cmd_part, irc_recv_cmd_part },
- { "ping", N_("ping server"),
- N_("server1 [server2]"),
- N_("server1: server to ping\nserver2: forward ping to this server"),
- NULL, 1, 2, 0, 1, NULL, irc_send_cmd_ping, irc_recv_cmd_ping },
- { "pong", N_("answer to a ping message"),
- N_("daemon [daemon2]"),
- N_(" daemon: daemon who has responded to Ping message\n"
- "daemon2: forward message to this daemon"),
- NULL, 1, 2, 0, 1, NULL, irc_send_cmd_pong, irc_recv_cmd_pong },
- { "privmsg", N_("message received"), "", "",
- "", 0, 0, 1, 1, NULL, NULL, irc_recv_cmd_privmsg },
- { "query", N_("send a private message to a nick"),
- N_("nickname [text]"),
- N_("nickname: nickname for private conversation\n"
- " text: text to send"),
- "%n %-", 1, MAX_ARGS, 1, 1, NULL, irc_send_cmd_query, NULL },
- { "quit", N_("close all connections and quit"),
- N_("[quit_message]"),
- N_("quit_message: quit message (displayed to other users)"),
- "%q", 0, MAX_ARGS, 1, 0, NULL, irc_send_cmd_quit, irc_recv_cmd_quit },
- { "quote", N_("send raw data to server without parsing"),
- N_("data"),
- N_("data: raw data to send"),
- "", 1, MAX_ARGS, 1, 0, NULL, irc_send_cmd_quote, NULL },
- { "rehash", N_("tell the server to reload its config file"), "", "",
- NULL, 0, 0, 0, 1, NULL, irc_send_cmd_rehash, NULL },
- { "restart", N_("tell the server to restart itself"), "", "",
- NULL, 0, 0, 0, 1, NULL, irc_send_cmd_restart, NULL },
- { "service", N_("register a new service"),
- N_("nickname reserved distribution type reserved info"),
- N_("distribution: visibility of service\n"
- " type: reserved for future usage"),
- NULL, 6, 6, 0, 1, NULL, irc_send_cmd_service, NULL },
- { "servlist", N_("list services currently connected to the network"),
- N_("[mask [type]]"),
- N_("mask: list only services matching this mask\n"
- "type: list only services of this type"),
- NULL, 0, 2, 0, 1, NULL, irc_send_cmd_servlist, NULL },
- { "squery", N_("deliver a message to a service"),
- N_("service text"),
- N_("service: name of service\ntext: text to send"),
- NULL, 2, MAX_ARGS, 1, 1, NULL, irc_send_cmd_squery, NULL },
- { "squit", N_("disconnect server links"),
- N_("server comment"),
- N_( "server: server name\n"
- "comment: comment for quit"),
- NULL, 2, 2, 1, 1, NULL, irc_send_cmd_squit, NULL },
- { "stats", N_("query statistics about server"),
- N_("[query [server]]"),
- N_(" query: c/h/i/k/l/m/o/y/u (see RFC1459)\n"
- "server: server name"),
- NULL, 0, 2, 0, 1, NULL, irc_send_cmd_stats, NULL },
- { "summon", N_("give users who are on a host running an IRC server a message "
- "asking them to please join IRC"),
- N_("user [target [channel]]"),
- N_(" user: username\ntarget: server name\n"
- "channel: channel name"),
- NULL, 1, 3, 0, 1, NULL, irc_send_cmd_summon, NULL },
- { "time", N_("query local time from server"),
- N_("[target]"),
- N_("target: query time from specified server"),
- NULL, 0, 1, 0, 1, NULL, irc_send_cmd_time, NULL },
- { "topic", N_("get/set channel topic"),
- N_("[channel] [topic]"),
- N_("channel: channel name\ntopic: new topic for channel "
- "(if topic is \"-delete\" then topic is deleted)"),
- "%t|-delete %-", 0, MAX_ARGS, 1, 1, NULL, irc_send_cmd_topic, irc_recv_cmd_topic },
- { "trace", N_("find the route to specific server"),
- N_("[target]"),
- N_("target: server"),
- NULL, 0, 1, 0, 1, NULL, irc_send_cmd_trace, NULL },
- { "unban", N_("unbans nicks or hosts"),
- N_("[channel] nickname [nickname ...]"),
- N_(" channel: channel for unban\n"
- "nickname: user or host to unban"),
- "", 1, MAX_ARGS, 0, 1, NULL, irc_send_cmd_unban, NULL },
- { "userhost", N_("return a list of information about nicknames"),
- N_("nickname [nickname ...]"),
- N_("nickname: nickname"),
- "%n", 1, MAX_ARGS, 0, 1, NULL, irc_send_cmd_userhost, NULL },
- { "users", N_("list of users logged into the server"),
- N_("[target]"),
- N_("target: server"),
- NULL, 0, 1, 0, 1, NULL, irc_send_cmd_users, NULL },
- { "version", N_("gives the version info of nick or server (current or specified)"),
- N_("[server | nickname]"),
- N_(" server: server name\n"
- "nickname: nickname"),
- NULL, 0, 1, 0, 1, NULL, irc_send_cmd_version, NULL },
- { "voice", N_("gives voice to nickname(s)"),
- N_("[nickname [nickname]]"), "",
- "", 0, MAX_ARGS, 0, 1, irc_send_cmd_voice, NULL, NULL },
- { "wallops", N_("send a message to all currently connected users who have "
- "set the 'w' user mode for themselves"),
- N_("text"),
- N_("text to send"),
- NULL, 1, MAX_ARGS, 1, 1, NULL, irc_send_cmd_wallops, irc_recv_cmd_wallops },
- { "who", N_("generate a query which returns a list of information"),
- N_("[mask [\"o\"]]"),
- N_("mask: only information which match this mask\n"
- " o: only operators are returned according to the mask supplied"),
- "%C", 0, 2, 0, 1, NULL, irc_send_cmd_who, NULL },
- { "whois", N_("query information about user(s)"),
- N_("[server] nickname[,nickname]"),
- N_(" server: server name\n"
- "nickname: nickname (may be a mask)"),
- "", 1, MAX_ARGS, 0, 1, NULL, irc_send_cmd_whois, NULL },
- { "whowas", N_("ask for information about a nickname which no longer exists"),
- N_("nickname [,nickname [,nickname ...]] [count [target]]"),
- N_("nickname: nickname to search\n"
- " count: number of replies to return (full search if negative number)\n"
- " target: reply should match this mask"),
- "", 1, MAX_ARGS, 0, 1, NULL, irc_send_cmd_whowas, NULL },
- { "001", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_001 },
- { "005", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_005 },
- { "221", N_("user mode string"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_221 },
- { "301", N_("away message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_301 },
- { "302", N_("userhost"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_302 },
- { "303", N_("ison"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_303 },
- { "305", N_("unaway"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_305 },
- { "306", N_("now away"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_306 },
- { "307", N_("whois (registered nick)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_whois_nick_msg },
- { "310", N_("whois (help mode)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_310 },
- { "311", N_("whois (user)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_311 },
- { "312", N_("whois (server)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_312 },
- { "313", N_("whois (operator)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_whois_nick_msg },
- { "314", N_("whowas"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_314 },
- { "315", N_("end of /who list"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_315 },
- { "317", N_("whois (idle)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_317 },
- { "318", N_("whois (end)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_whois_nick_msg },
- { "319", N_("whois (channels)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_319 },
- { "320", N_("whois (identified user)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_whois_nick_msg },
- { "321", N_("/list start"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_321 },
- { "322", N_("channel (for /list)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_322 },
- { "323", N_("/list end"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_323 },
- { "324", N_("channel mode"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_324 },
- { "326", N_("whois (has oper privs)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_whois_nick_msg },
- { "327", N_("whois (host)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_327 },
- { "329", N_("channel creation date"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_329 },
- { "331", N_("no topic for channel"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_331 },
- { "332", N_("topic of channel"),
- N_("channel :topic"),
- N_("channel: name of channel\n"
- " topic: topic of the channel"),
- NULL, 2, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_332 },
- { "333", N_("infos about topic (nick and date changed)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_333 },
- { "338", N_("whois (host)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_338 },
- { "341", N_("inviting"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_341 },
- { "344", N_("channel reop"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_344 },
- { "345", N_("end of channel reop list"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_345 },
- { "348", N_("channel exception list"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_348 },
- { "349", N_("end of channel exception list"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_349 },
- { "351", N_("server version"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_351 },
- { "352", N_("who"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_352 },
- { "353", N_("list of nicks on channel"),
- N_("channel :[[@|+]nick ...]"),
- N_("channel: name of channel\n"
- " nick: nick on the channel"),
- NULL, 2, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_353 },
- { "366", N_("end of /names list"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_366 },
- { "367", N_("banlist"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_367 },
- { "368", N_("end of banlist"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_368 },
- { "378", N_("whois (connecting from)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_whois_nick_msg },
- { "379", N_("whois (using modes)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_whois_nick_msg },
- { "401", N_("no such nick/channel"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "402", N_("no such server"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "403", N_("no such channel"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "404", N_("cannot send to channel"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "405", N_("too many channels"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "406", N_("was no such nick"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "407", N_("was no such nick"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "409", N_("no origin"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "410", N_("no services"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "411", N_("no recipient"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "412", N_("no text to send"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "413", N_("no toplevel"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "414", N_("wilcard in toplevel domain"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "421", N_("unknown command"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "422", N_("MOTD is missing"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "423", N_("no administrative info"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "424", N_("file error"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "431", N_("no nickname given"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "432", N_("erroneous nickname"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_432 },
- { "433", N_("nickname already in use"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_433 },
- { "436", N_("nickname collision"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "437", N_("resource unavailable"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "438", N_("not authorized to change nickname"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_438 },
- { "441", N_("user not in channel"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "442", N_("not on channel"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "443", N_("user already on channel"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "444", N_("user not logged in"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "445", N_("summon has been disabled"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "446", N_("users has been disabled"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "451", N_("you are not registered"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "461", N_("not enough parameters"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "462", N_("you may not register"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "463", N_("your host isn't among the privileged"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "464", N_("password incorrect"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "465", N_("you are banned from this server"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "467", N_("channel key already set"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "470", N_("forwarding to another channel"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "471", N_("channel is already full"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "472", N_("unknown mode char to me"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "473", N_("cannot join channel (invite only)"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "474", N_("cannot join channel (banned from channel)"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "475", N_("cannot join channel (bad channel key)"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "476", N_("bad channel mask"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "477", N_("channel doesn't support modes"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "481", N_("you're not an IRC operator"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "482", N_("you're not channel operator"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "483", N_("you can't kill a server!"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "484", N_("your connection is restricted!"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "485", N_("user is immune from kick/deop"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "487", N_("network split"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "491", N_("no O-lines for your host"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "501", N_("unknown mode flag"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "502", N_("can't change mode for other users"), "", "",
- NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_recv_cmd_error },
- { "671", N_("whois (secure connection)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_671 },
- { "973", N_("whois (secure connection)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_server_mode_reason },
- { "974", N_("whois (secure connection)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_server_mode_reason },
- { "975", N_("whois (secure connection)"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_recv_cmd_server_mode_reason },
- { NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 1, NULL, NULL, NULL }
-};
diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c
new file mode 100644
index 000000000..27819e262
--- /dev/null
+++ b/src/plugins/irc/irc-config.c
@@ -0,0 +1,883 @@
+/*
+ * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/* irc-config.c: IRC configuration options */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <limits.h>
+#include <pwd.h>
+
+#include "../../core/weechat.h"
+#include "irc.h"
+#include "../../core/config-option.h"
+#include "../../core/config-file.h"
+#include "../../core/hook.h"
+#include "../../core/util.h"
+
+
+/* config, irc section */
+
+int irc_cfg_irc_one_server_buffer;
+int irc_cfg_irc_open_near_server;
+char *irc_cfg_irc_nick_prefix;
+char *irc_cfg_irc_nick_suffix;
+int irc_cfg_irc_display_away;
+int irc_cfg_irc_show_away_once;
+char *irc_cfg_irc_display_away_values[] =
+{ "off", "local", "channel", NULL };
+char *irc_cfg_irc_default_msg_part;
+char *irc_cfg_irc_default_msg_quit;
+int irc_cfg_irc_notice_as_pv;
+int irc_cfg_irc_away_check;
+int irc_cfg_irc_away_check_max_nicks;
+int irc_cfg_irc_lag_check;
+int irc_cfg_irc_lag_min_show;
+int irc_cfg_irc_lag_disconnect;
+int irc_cfg_irc_anti_flood;
+char *irc_cfg_irc_highlight;
+int irc_cfg_irc_colors_receive;
+int irc_cfg_irc_colors_send;
+int irc_cfg_irc_send_unknown_commands;
+
+t_config_option irc_options_irc[] =
+{ { "irc_one_server_buffer",
+ N_("use same buffer for all servers"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, NULL, NULL,
+ &irc_cfg_irc_one_server_buffer, NULL, irc_config_change_one_server_buffer },
+ { "irc_open_near_server",
+ N_("open new channels/privates near server"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, NULL, NULL,
+ &irc_cfg_irc_open_near_server, NULL, irc_config_change_noop },
+ { "irc_nick_prefix",
+ N_("text to display before nick in chat window"),
+ OPTION_TYPE_STRING, 0, 0, 0, "", NULL,
+ NULL, &irc_cfg_irc_nick_prefix, irc_config_change_noop },
+ { "irc_nick_suffix",
+ N_("text to display after nick in chat window"),
+ OPTION_TYPE_STRING, 0, 0, 0, " |", NULL,
+ NULL, &irc_cfg_irc_nick_suffix, irc_config_change_noop },
+ { "irc_display_away",
+ N_("display message when (un)marking as away"),
+ OPTION_TYPE_INT_WITH_STRING, 0, 0, 0, "off", irc_cfg_irc_display_away_values,
+ &irc_cfg_irc_display_away, NULL, irc_config_change_noop },
+ { "irc_show_away_once",
+ N_("show remote away message only once in private"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL,
+ &irc_cfg_irc_show_away_once, NULL, irc_config_change_noop },
+ { "irc_default_msg_part",
+ N_("default part message (leaving channel) ('%v' will be replaced by "
+ "WeeChat version in string)"),
+ OPTION_TYPE_STRING, 0, 0, 0, "WeeChat %v", NULL,
+ NULL, &irc_cfg_irc_default_msg_part, irc_config_change_noop },
+ { "irc_default_msg_quit",
+ N_("default quit message ('%v' will be replaced by WeeChat version in "
+ "string)"),
+ OPTION_TYPE_STRING, 0, 0, 0, "WeeChat %v", NULL,
+ NULL, &irc_cfg_irc_default_msg_quit, irc_config_change_noop },
+ { "irc_notice_as_pv",
+ N_("display notices as private messages"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, NULL, NULL,
+ &irc_cfg_irc_notice_as_pv, NULL, irc_config_change_noop },
+ { "irc_away_check",
+ N_("interval between two checks for away (in minutes, 0 = never check)"),
+ OPTION_TYPE_INT, 0, INT_MAX, 0, NULL, NULL,
+ &irc_cfg_irc_away_check, NULL, irc_config_change_away_check },
+ { "irc_away_check_max_nicks",
+ N_("do not check away nicks on channels with high number of nicks (0 = unlimited)"),
+ OPTION_TYPE_INT, 0, INT_MAX, 0, NULL, NULL,
+ &irc_cfg_irc_away_check_max_nicks, NULL, irc_config_change_away_check },
+ { "irc_lag_check",
+ N_("interval between two checks for lag (in seconds)"),
+ OPTION_TYPE_INT, 30, INT_MAX, 60, NULL, NULL,
+ &irc_cfg_irc_lag_check, NULL, irc_config_change_noop },
+ { "irc_lag_min_show",
+ N_("minimum lag to show (in seconds)"),
+ OPTION_TYPE_INT, 0, INT_MAX, 1, NULL, NULL,
+ &irc_cfg_irc_lag_min_show, NULL, irc_config_change_noop },
+ { "irc_lag_disconnect",
+ N_("disconnect after important lag (in minutes, 0 = never disconnect)"),
+ OPTION_TYPE_INT, 0, INT_MAX, 5, NULL, NULL,
+ &irc_cfg_irc_lag_disconnect, NULL, irc_config_change_noop },
+ { "irc_anti_flood",
+ N_("anti-flood: # seconds between two user messages (0 = no anti-flood)"),
+ OPTION_TYPE_INT, 0, 5, 2, NULL, NULL,
+ &irc_cfg_irc_anti_flood, NULL, irc_config_change_noop },
+ { "irc_highlight",
+ N_("comma separated list of words to highlight (case insensitive comparison, "
+ "words may begin or end with \"*\" for partial match)"),
+ OPTION_TYPE_STRING, 0, 0, 0, "", NULL,
+ NULL, &irc_cfg_irc_highlight, irc_config_change_noop },
+ { "irc_colors_receive",
+ N_("when off, colors codes are ignored in incoming messages"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL,
+ &irc_cfg_irc_colors_receive, NULL, irc_config_change_noop },
+ { "irc_colors_send",
+ N_("allow user to send colors with special codes (^Cb=bold, ^Ccxx=color, "
+ "^Ccxx,yy=color+background, ^Cu=underline, ^Cr=reverse)"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL,
+ &irc_cfg_irc_colors_send, NULL, irc_config_change_noop },
+ { "irc_send_unknown_commands",
+ N_("send unknown commands to IRC server"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, NULL, NULL,
+ &irc_cfg_irc_send_unknown_commands, NULL, irc_config_change_noop },
+ { NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
+};
+
+/* config, dcc section */
+
+int irc_cfg_dcc_auto_accept_files;
+int irc_cfg_dcc_auto_accept_chats;
+int irc_cfg_dcc_timeout;
+int irc_cfg_dcc_blocksize;
+int irc_cfg_dcc_fast_send;
+char *irc_cfg_dcc_port_range;
+char *irc_cfg_dcc_own_ip;
+char *irc_cfg_dcc_download_path;
+char *irc_cfg_dcc_upload_path;
+int irc_cfg_dcc_convert_spaces;
+int irc_cfg_dcc_auto_rename;
+int irc_cfg_dcc_auto_resume;
+
+t_config_option irc_options_dcc[] =
+{ { "dcc_auto_accept_files",
+ N_("automatically accept incoming dcc files"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, NULL, NULL,
+ &irc_cfg_dcc_auto_accept_files, NULL, irc_config_change_noop },
+ { "dcc_auto_accept_chats",
+ N_("automatically accept dcc chats (use carefully!)"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, NULL, NULL,
+ &irc_cfg_dcc_auto_accept_chats, NULL, irc_config_change_noop },
+ { "dcc_timeout",
+ N_("timeout for dcc request (in seconds)"),
+ OPTION_TYPE_INT, 5, INT_MAX, 300, NULL, NULL,
+ &irc_cfg_dcc_timeout, NULL, irc_config_change_noop },
+ { "dcc_blocksize",
+ N_("block size for dcc packets in bytes (default: 65536)"),
+ OPTION_TYPE_INT, IRC_DCC_MIN_BLOCKSIZE, IRC_DCC_MAX_BLOCKSIZE, 65536, NULL, NULL,
+ &irc_cfg_dcc_blocksize, NULL, irc_config_change_noop },
+ { "dcc_fast_send",
+ N_("does not wait for ACK when sending file"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL,
+ &irc_cfg_dcc_fast_send, NULL, irc_config_change_noop },
+ { "dcc_port_range",
+ N_("restricts outgoing dcc to use only ports in the given range "
+ "(useful for NAT) (syntax: a single port, ie. 5000 or a port "
+ "range, ie. 5000-5015, empty value means any port)"),
+ OPTION_TYPE_STRING, 0, 0, 0, "", NULL,
+ NULL, &irc_cfg_dcc_port_range, irc_config_change_noop },
+ { "dcc_own_ip",
+ N_("IP or DNS address used for outgoing dcc "
+ "(if empty, local interface IP is used)"),
+ OPTION_TYPE_STRING, 0, 0, 0, "", NULL,
+ NULL, &irc_cfg_dcc_own_ip, irc_config_change_noop },
+ { "dcc_download_path",
+ N_("path for writing incoming files with dcc (default: user home)"),
+ OPTION_TYPE_STRING, 0, 0, 0, "%h/dcc", NULL,
+ NULL, &irc_cfg_dcc_download_path, irc_config_change_noop },
+ { "dcc_upload_path",
+ N_("path for reading files when sending thru dcc (when no path is "
+ "specified)"),
+ OPTION_TYPE_STRING, 0, 0, 0, "~", NULL,
+ NULL, &irc_cfg_dcc_upload_path, irc_config_change_noop },
+ { "dcc_convert_spaces",
+ N_("convert spaces to underscores when sending files"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL,
+ &irc_cfg_dcc_convert_spaces, NULL, irc_config_change_noop },
+ { "dcc_auto_rename",
+ N_("rename incoming files if already exists (add '.1', '.2', ...)"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL,
+ &irc_cfg_dcc_auto_rename, NULL, irc_config_change_noop },
+ { "dcc_auto_resume",
+ N_("automatically resume dcc transfer if connection with remote host is "
+ "loosed"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL,
+ &irc_cfg_dcc_auto_resume, NULL, irc_config_change_noop },
+ { NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
+};
+
+/* config, log section */
+
+int irc_cfg_log_auto_server;
+int irc_cfg_log_auto_channel;
+int irc_cfg_log_auto_private;
+int irc_cfg_log_hide_nickserv_pwd;
+
+t_config_option irc_options_log[] =
+{ { "log_auto_server",
+ N_("automatically log server messages"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, NULL, NULL,
+ &irc_cfg_log_auto_server, NULL, irc_config_change_log },
+ { "log_auto_channel",
+ N_("automatically log channel chats"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, NULL, NULL,
+ &irc_cfg_log_auto_channel, NULL, irc_config_change_log },
+ { "log_auto_private",
+ N_("automatically log private chats"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, NULL, NULL,
+ &irc_cfg_log_auto_private, NULL, irc_config_change_log },
+ { "log_hide_nickserv_pwd",
+ N_("hide password displayed by nickserv"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL,
+ &irc_cfg_log_hide_nickserv_pwd, NULL, irc_config_change_noop },
+ { NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
+};
+
+/* config, server section */
+
+static t_irc_server cfg_server;
+
+t_config_option irc_options_server[] =
+{ { "server_name",
+ N_("name associated to IRC server (for display only)"),
+ OPTION_TYPE_STRING, 0, 0, 0, "", NULL,
+ NULL, &(cfg_server.name), NULL },
+ { "server_autoconnect",
+ N_("automatically connect to server when WeeChat is starting"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL,
+ &(cfg_server.autoconnect), NULL, NULL },
+ { "server_autoreconnect",
+ N_("automatically reconnect to server when disconnected"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL,
+ &(cfg_server.autoreconnect), NULL, NULL },
+ { "server_autoreconnect_delay",
+ N_("delay (in seconds) before trying again to reconnect to server"),
+ OPTION_TYPE_INT, 0, 65535, 30, NULL, NULL,
+ &(cfg_server.autoreconnect_delay), NULL, NULL },
+ { "server_address",
+ N_("IP address or hostname of IRC server"),
+ OPTION_TYPE_STRING, 0, 0, 0, "", NULL,
+ NULL, &(cfg_server.address), NULL },
+ { "server_port",
+ N_("port for connecting to server"),
+ OPTION_TYPE_INT, 0, 65535, 6667, NULL, NULL,
+ &(cfg_server.port), NULL, NULL },
+ { "server_ipv6",
+ N_("use IPv6 protocol for server communication"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, NULL, NULL,
+ &(cfg_server.ipv6), NULL, NULL },
+ { "server_ssl",
+ N_("use SSL for server communication"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, NULL, NULL,
+ &(cfg_server.ssl), NULL, NULL },
+ { "server_password",
+ N_("password for IRC server"),
+ OPTION_TYPE_STRING, 0, 0, 0, "", NULL,
+ NULL, &(cfg_server.password), NULL },
+ { "server_nick1",
+ N_("nickname to use on IRC server"),
+ OPTION_TYPE_STRING, 0, 0, 0, "", NULL,
+ NULL, &(cfg_server.nick1), NULL },
+ { "server_nick2",
+ N_("alternate nickname to use on IRC server (if nickname is already used)"),
+ OPTION_TYPE_STRING, 0, 0, 0, "", NULL,
+ NULL, &(cfg_server.nick2), NULL },
+ { "server_nick3",
+ N_("2nd alternate nickname to use on IRC server (if alternate nickname is "
+ "already used)"),
+ OPTION_TYPE_STRING, 0, 0, 0, "", NULL,
+ NULL, &(cfg_server.nick3), NULL },
+ { "server_username",
+ N_("user name to use on IRC server"),
+ OPTION_TYPE_STRING, 0, 0, 0, "", NULL,
+ NULL, &(cfg_server.username), NULL },
+ { "server_realname",
+ N_("real name to use on IRC server"),
+ OPTION_TYPE_STRING, 0, 0, 0, "", NULL,
+ NULL, &(cfg_server.realname), NULL },
+ { "server_hostname",
+ N_("custom hostname/IP for server (optional, if empty local hostname is "
+ "used)"),
+ OPTION_TYPE_STRING, 0, 0, 0, "", NULL,
+ NULL, &(cfg_server.hostname), NULL },
+ { "server_command",
+ N_("command(s) to run when connected to server (many commands should be "
+ "separated by ';', use '\\;' for a semicolon, special variables $nick, "
+ "$channel and $server are replaced by their value)"),
+ OPTION_TYPE_STRING, 0, 0, 0, "", NULL,
+ NULL, &(cfg_server.command), NULL },
+ { "server_command_delay",
+ N_("delay (in seconds) after command was executed (example: give some time "
+ "for authentication)"),
+ OPTION_TYPE_INT, 0, 3600, 0, NULL, NULL,
+ &(cfg_server.command_delay), NULL, NULL },
+ { "server_autojoin",
+ N_("comma separated list of channels to join when connected to server "
+ "(example: \"#chan1,#chan2,#chan3 key1,key2\")"),
+ OPTION_TYPE_STRING, 0, 0, 0, "", NULL,
+ NULL, &(cfg_server.autojoin), NULL },
+ { "server_autorejoin",
+ N_("automatically rejoin channels when kicked"),
+ OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL,
+ &(cfg_server.autorejoin), NULL, NULL },
+ { "server_notify_levels",
+ N_("comma separated list of notify levels for channels of this server "
+ "(format: #channel:1,..), a channel name '*' is reserved for server "
+ "default notify level"),
+ OPTION_TYPE_STRING, 0, 0, 0, "", NULL,
+ NULL, &(cfg_server.notify_levels), irc_config_change_notify_levels },
+ { NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
+};
+
+char *weechat_protocol_config_sections[] =
+{ "irc", "dcc",
+ "log", "server",
+ NULL
+};
+
+t_config_option *weechat_protocol_config_options[] =
+{ irc_options_irc, irc_options_dcc,
+ irc_options_log, NULL,
+ NULL };
+
+t_config_func_read_option *irc_config_read_functions[] =
+{ config_file_read_option, config_file_read_option,
+ config_file_read_option, irc_config_read_server,
+ NULL
+};
+
+t_config_func_write_options *irc_config_write_functions[] =
+{ config_file_write_options, config_file_write_options,
+ config_file_write_options, irc_config_write_servers,
+ NULL
+};
+
+t_config_func_write_options *irc_config_write_default_functions[] =
+{ config_file_write_options_default_values, config_file_write_options_default_values,
+ config_file_write_options_default_values, irc_config_write_servers_default_values,
+ NULL
+};
+
+
+/*
+ * irc_config_change_noop: called when an option is changed by /set command
+ * and that no special action is needed after that
+ */
+
+void
+irc_config_change_noop ()
+{
+ /* do nothing */
+}
+
+/*
+ * irc_config_change_one_server_buffer: called when the "one server buffer"
+ * setting is changed
+ */
+
+void
+irc_config_change_one_server_buffer ()
+{
+ if (irc_cfg_irc_one_server_buffer)
+ irc_buffer_merge_servers (gui_current_window);
+ else
+ irc_buffer_split_server (gui_current_window);
+}
+
+/*
+ * irc_config_change_away_check: called when away check is changed
+ */
+
+void
+irc_config_change_away_check ()
+{
+ if (irc_hook_timer_check_away)
+ {
+ weechat_hook_remove (irc_hook_timer_check_away);
+ irc_hook_timer_check_away = NULL;
+ }
+ if (irc_cfg_irc_away_check == 0)
+ {
+ /* reset away flag for all nicks/chans/servers */
+ irc_server_remove_away ();
+ }
+ weechat_hook_add_timer (irc_cfg_irc_away_check * 60 * 1000,
+ irc_server_timer_check_away,
+ NULL);
+}
+
+/*
+ * irc_config_change_log: called when log settings are changed
+ * (for server/channel/private logging)
+ */
+
+void
+irc_config_change_log ()
+{
+ t_gui_buffer *ptr_buffer;
+ t_irc_server *ptr_server;
+ t_irc_channel *ptr_channel;
+
+ for (ptr_buffer = gui_buffers; ptr_buffer;
+ ptr_buffer = ptr_buffer->next_buffer)
+ {
+ if (ptr_buffer->protocol == irc_protocol)
+ {
+ ptr_server = irc_server_search (ptr_buffer->category);
+ ptr_channel = irc_channel_search (ptr_server, ptr_buffer->name);
+
+ if (ptr_server && !ptr_channel)
+ {
+ if (irc_cfg_log_auto_server && !ptr_buffer->log_file)
+ gui_log_start (ptr_buffer);
+ else if (!irc_cfg_log_auto_server && ptr_buffer->log_file)
+ gui_log_end (ptr_buffer);
+ }
+ if (ptr_server && ptr_channel)
+ {
+ if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL)
+ {
+ if (irc_cfg_log_auto_channel && !ptr_buffer->log_file)
+ gui_log_start (ptr_buffer);
+ else if (!irc_cfg_log_auto_channel && ptr_buffer->log_file)
+ gui_log_end (ptr_buffer);
+ }
+ else
+ {
+ if (irc_cfg_log_auto_private && !ptr_buffer->log_file)
+ gui_log_start (ptr_buffer);
+ else if (!irc_cfg_log_auto_private && ptr_buffer->log_file)
+ gui_log_end (ptr_buffer);
+ }
+ }
+ }
+ }
+}
+
+/*
+ * irc_config_change_notify_levels: called when notify level is changed
+ */
+
+void
+irc_config_change_notify_levels ()
+{
+}
+
+/*
+ * irc_config_create_dirs: create configuratoin directories (read from configuration file)
+ */
+
+void
+irc_config_create_dirs ()
+{
+ char *dir1, *dir2;
+
+ /* create DCC download directory */
+ dir1 = weechat_strreplace (irc_cfg_dcc_download_path, "~", getenv ("HOME"));
+ dir2 = weechat_strreplace (dir1, "%h", weechat_home);
+ (void) weechat_create_dir (dir2, 0700);
+ if (dir1)
+ free (dir1);
+ if (dir2)
+ free (dir2);
+}
+
+/*
+ * irc_config_get_server_option_ptr: get a pointer to a server configuration option
+ */
+
+void *
+irc_config_get_server_option_ptr (t_irc_server *server, char *option_name)
+{
+ if (weechat_strcasecmp (option_name, "server_name") == 0)
+ return (void *)(&server->name);
+ if (weechat_strcasecmp (option_name, "server_autoconnect") == 0)
+ return (void *)(&server->autoconnect);
+ if (weechat_strcasecmp (option_name, "server_autoreconnect") == 0)
+ return (void *)(&server->autoreconnect);
+ if (weechat_strcasecmp (option_name, "server_autoreconnect_delay") == 0)
+ return (void *)(&server->autoreconnect_delay);
+ if (weechat_strcasecmp (option_name, "server_address") == 0)
+ return (void *)(&server->address);
+ if (weechat_strcasecmp (option_name, "server_port") == 0)
+ return (void *)(&server->port);
+ if (weechat_strcasecmp (option_name, "server_ipv6") == 0)
+ return (void *)(&server->ipv6);
+ if (weechat_strcasecmp (option_name, "server_ssl") == 0)
+ return (void *)(&server->ssl);
+ if (weechat_strcasecmp (option_name, "server_password") == 0)
+ return (void *)(&server->password);
+ if (weechat_strcasecmp (option_name, "server_nick1") == 0)
+ return (void *)(&server->nick1);
+ if (weechat_strcasecmp (option_name, "server_nick2") == 0)
+ return (void *)(&server->nick2);
+ if (weechat_strcasecmp (option_name, "server_nick3") == 0)
+ return (void *)(&server->nick3);
+ if (weechat_strcasecmp (option_name, "server_username") == 0)
+ return (void *)(&server->username);
+ if (weechat_strcasecmp (option_name, "server_realname") == 0)
+ return (void *)(&server->realname);
+ if (weechat_strcasecmp (option_name, "server_hostname") == 0)
+ return (void *)(&server->hostname);
+ if (weechat_strcasecmp (option_name, "server_command") == 0)
+ return (void *)(&server->command);
+ if (weechat_strcasecmp (option_name, "server_command_delay") == 0)
+ return (void *)(&server->command_delay);
+ if (weechat_strcasecmp (option_name, "server_autojoin") == 0)
+ return (void *)(&server->autojoin);
+ if (weechat_strcasecmp (option_name, "server_autorejoin") == 0)
+ return (void *)(&server->autorejoin);
+ if (weechat_strcasecmp (option_name, "server_notify_levels") == 0)
+ return (void *)(&server->notify_levels);
+ /* option not found */
+ return NULL;
+}
+
+/*
+ * irc_config_set_server_value: set new value for an option of a server
+ * return: 0 if success
+ * -1 if option not found
+ * -2 if bad value
+ */
+
+int
+irc_config_set_server_value (t_irc_server *server, char *option_name,
+ char *value)
+{
+ t_config_option *ptr_option;
+ int i;
+ void *ptr_data;
+ int int_value;
+
+ ptr_data = irc_config_get_server_option_ptr (server, option_name);
+ if (!ptr_data)
+ return -1;
+
+ ptr_option = NULL;
+ for (i = 0; irc_options_server[i].name; i++)
+ {
+ /* if option found, return pointer */
+ if (weechat_strcasecmp (irc_options_server[i].name, option_name) == 0)
+ {
+ ptr_option = &irc_options_server[i];
+ break;
+ }
+ }
+ if (!ptr_option)
+ return -1;
+
+ switch (ptr_option->type)
+ {
+ case OPTION_TYPE_BOOLEAN:
+ int_value = config_option_option_get_boolean_value (value);
+ switch (int_value)
+ {
+ case BOOL_TRUE:
+ *((int *)(ptr_data)) = BOOL_TRUE;
+ break;
+ case BOOL_FALSE:
+ *((int *)(ptr_data)) = BOOL_FALSE;
+ break;
+ default:
+ return -2;
+ }
+ break;
+ case OPTION_TYPE_INT:
+ int_value = atoi (value);
+ if ((int_value < ptr_option->min) || (int_value > ptr_option->max))
+ return -2;
+ *((int *)(ptr_data)) = int_value;
+ break;
+ case OPTION_TYPE_INT_WITH_STRING:
+ int_value = config_option_get_pos_array_values (ptr_option->array_values,
+ value);
+ if (int_value < 0)
+ return -2;
+ *((int *)(ptr_data)) = int_value;
+ break;
+ case OPTION_TYPE_COLOR:
+ if (!gui_color_assign ((int *)ptr_data, value))
+ return -2;
+ break;
+ case OPTION_TYPE_STRING:
+ if (*((char **)ptr_data))
+ free (*((char **)ptr_data));
+ *((char **)ptr_data) = strdup (value);
+ break;
+ }
+ if (ptr_option->handler_change != NULL)
+ (void) (ptr_option->handler_change());
+ return 0;
+}
+
+/*
+ * irc_config_allocate_server: allocate a new server
+ */
+
+int
+irc_config_allocate_server (char *filename, int line_number)
+{
+ if (!cfg_server.name
+ || !cfg_server.address
+ || cfg_server.port < 0
+ || !cfg_server.nick1
+ || !cfg_server.nick2
+ || !cfg_server.nick3
+ || !cfg_server.username
+ || !cfg_server.realname)
+ {
+ irc_server_free_all ();
+ gui_chat_printf (NULL,
+ _("%s %s, line %d: new server, but previous was "
+ "incomplete\n"),
+ WEECHAT_WARNING, filename, line_number);
+ return 0;
+
+ }
+ if (irc_server_name_already_exists (cfg_server.name))
+ {
+ irc_server_free_all ();
+ gui_chat_printf (NULL,
+ _("%s %s, line %d: server '%s' already exists\n"),
+ WEECHAT_WARNING, filename, line_number,
+ cfg_server.name);
+ return 0;
+ }
+ if (!irc_server_new (cfg_server.name,
+ cfg_server.autoconnect, cfg_server.autoreconnect,
+ cfg_server.autoreconnect_delay, 0, cfg_server.address,
+ cfg_server.port, cfg_server.ipv6, cfg_server.ssl,
+ cfg_server.password, cfg_server.nick1,
+ cfg_server.nick2, cfg_server.nick3,
+ cfg_server.username, cfg_server.realname,
+ cfg_server.hostname, cfg_server.command,
+ cfg_server.command_delay, cfg_server.autojoin,
+ cfg_server.autorejoin, cfg_server.notify_levels))
+ {
+ irc_server_free_all ();
+ gui_chat_printf (NULL,
+ _("%s %s, line %d: unable to create server\n"),
+ WEECHAT_WARNING, filename, line_number);
+ return 0;
+ }
+
+ irc_server_destroy (&cfg_server);
+ irc_server_init (&cfg_server);
+
+ return 1;
+}
+
+/*
+ * irc_config_read_server: read a server option in configuration file
+ * Return: 0 = successful
+ * -1 = option not found
+ * -2 = bad format/value
+ */
+
+int
+irc_config_read_server (t_config_option *options,
+ char *option_name, char *value)
+{
+ /* make C compiler happy */
+ (void) options;
+
+ if (option_name)
+ {
+ if (value[0])
+ {
+ /* bind key (overwrite any binding with same key) */
+ gui_keyboard_bind (option_name, value);
+ }
+ else
+ {
+ /* unbin key if no value given */
+ gui_keyboard_unbind (option_name);
+ }
+ }
+ else
+ {
+ /* does nothing for new [key] section */
+ }
+
+ /* all ok */
+ return 0;
+}
+
+/*
+ * irc_config_read: read IRC configuration file
+ * return: 0 = successful
+ * -1 = configuration file file not found
+ * -2 = error in configuration file
+ */
+
+int
+irc_config_read ()
+{
+ irc_server_init (&cfg_server);
+
+ return config_file_read (weechat_protocol_config_sections,
+ weechat_protocol_config_options,
+ irc_config_read_functions,
+ irc_config_write_default_functions,
+ IRC_CONFIG_NAME);
+}
+
+/*
+ * irc_config_write_servers: write servers sections in configuration file
+ * Return: 0 = successful
+ * -1 = write error
+ */
+
+int
+irc_config_write_servers (FILE *file, char *section_name,
+ t_config_option *options)
+{
+ t_irc_server *ptr_server;
+
+ /* make C compiler happy */
+ (void) options;
+
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ if (!ptr_server->temp_server)
+ {
+ weechat_iconv_fprintf (file, "\n[%s]\n", section_name);
+ weechat_iconv_fprintf (file, "server_name = \"%s\"\n", ptr_server->name);
+ weechat_iconv_fprintf (file, "server_autoconnect = %s\n",
+ (ptr_server->autoconnect) ? "on" : "off");
+ weechat_iconv_fprintf (file, "server_autoreconnect = %s\n",
+ (ptr_server->autoreconnect) ? "on" : "off");
+ weechat_iconv_fprintf (file, "server_autoreconnect_delay = %d\n",
+ ptr_server->autoreconnect_delay);
+ weechat_iconv_fprintf (file, "server_address = \"%s\"\n", ptr_server->address);
+ weechat_iconv_fprintf (file, "server_port = %d\n", ptr_server->port);
+ weechat_iconv_fprintf (file, "server_ipv6 = %s\n",
+ (ptr_server->ipv6) ? "on" : "off");
+ weechat_iconv_fprintf (file, "server_ssl = %s\n",
+ (ptr_server->ssl) ? "on" : "off");
+ weechat_iconv_fprintf (file, "server_password = \"%s\"\n",
+ (ptr_server->password) ? ptr_server->password : "");
+ weechat_iconv_fprintf (file, "server_nick1 = \"%s\"\n", ptr_server->nick1);
+ weechat_iconv_fprintf (file, "server_nick2 = \"%s\"\n", ptr_server->nick2);
+ weechat_iconv_fprintf (file, "server_nick3 = \"%s\"\n", ptr_server->nick3);
+ weechat_iconv_fprintf (file, "server_username = \"%s\"\n", ptr_server->username);
+ weechat_iconv_fprintf (file, "server_realname = \"%s\"\n", ptr_server->realname);
+ weechat_iconv_fprintf (file, "server_hostname = \"%s\"\n",
+ (ptr_server->hostname) ? ptr_server->hostname : "");
+ weechat_iconv_fprintf (file, "server_command = \"%s\"\n",
+ (ptr_server->command) ? ptr_server->command : "");
+ weechat_iconv_fprintf (file, "server_command_delay = %d\n", ptr_server->command_delay);
+ weechat_iconv_fprintf (file, "server_autojoin = \"%s\"\n",
+ (ptr_server->autojoin) ? ptr_server->autojoin : "");
+ weechat_iconv_fprintf (file, "server_autorejoin = %s\n",
+ (ptr_server->autorejoin) ? "on" : "off");
+ weechat_iconv_fprintf (file, "server_notify_levels = \"%s\"\n",
+ (ptr_server->notify_levels) ? ptr_server->notify_levels : "");
+ }
+ }
+
+ /* all ok */
+ return 0;
+}
+
+/*
+ * irc_config_write_server_default_values: write server section with default values
+ * in configuration file
+ * Return: 0 = successful
+ * -1 = write error
+ */
+
+int
+irc_config_write_server_default_values (FILE *file, char *section_name,
+ t_config_option *options)
+{
+ /* make C compiler happy */
+ (void) options;
+
+ struct passwd *my_passwd;
+ char *realname, *pos;
+
+ weechat_iconv_fprintf (file, "\n[%s]\n", section_name);
+
+ weechat_iconv_fprintf (file, "server_name = \"freenode\"\n");
+ weechat_iconv_fprintf (file, "server_autoconnect = on\n");
+ weechat_iconv_fprintf (file, "server_autoreconnect = on\n");
+ weechat_iconv_fprintf (file, "server_autoreconnect_delay = 30\n");
+ weechat_iconv_fprintf (file, "server_address = \"irc.freenode.net\"\n");
+ weechat_iconv_fprintf (file, "server_port = 6667\n");
+ weechat_iconv_fprintf (file, "server_ipv6 = off\n");
+ weechat_iconv_fprintf (file, "server_ssl = off\n");
+ weechat_iconv_fprintf (file, "server_password = \"\"\n");
+
+ /* Get the user's name from /etc/passwd */
+ if ((my_passwd = getpwuid (geteuid ())) != NULL)
+ {
+ weechat_iconv_fprintf (file, "server_nick1 = \"%s\"\n", my_passwd->pw_name);
+ weechat_iconv_fprintf (file, "server_nick2 = \"%s1\"\n", my_passwd->pw_name);
+ weechat_iconv_fprintf (file, "server_nick3 = \"%s2\"\n", my_passwd->pw_name);
+ weechat_iconv_fprintf (file, "server_username = \"%s\"\n", my_passwd->pw_name);
+ if ((!my_passwd->pw_gecos)
+ || (my_passwd->pw_gecos[0] == '\0')
+ || (my_passwd->pw_gecos[0] == ',')
+ || (my_passwd->pw_gecos[0] == ' '))
+ weechat_iconv_fprintf (file, "server_realname = \"%s\"\n", my_passwd->pw_name);
+ else
+ {
+ realname = strdup (my_passwd->pw_gecos);
+ pos = strchr (realname, ',');
+ if (pos)
+ pos[0] = '\0';
+ weechat_iconv_fprintf (file, "server_realname = \"%s\"\n",
+ realname);
+ if (pos)
+ pos[0] = ',';
+ free (realname);
+ }
+ }
+ else
+ {
+ /* default values if /etc/passwd can't be read */
+ weechat_iconv_fprintf (file, "server_nick1 = \"weechat1\"\n");
+ weechat_iconv_fprintf (file, "server_nick2 = \"weechat2\"\n");
+ weechat_iconv_fprintf (file, "server_nick3 = \"weechat3\"\n");
+ weechat_iconv_fprintf (file, "server_username = \"weechat\"\n");
+ weechat_iconv_fprintf (file, "server_realname = \"weechat\"\n");
+ }
+
+ weechat_iconv_fprintf (file, "server_hostname = \"\"\n");
+ weechat_iconv_fprintf (file, "server_command = \"\"\n");
+ weechat_iconv_fprintf (file, "server_command_delay = 0\n");
+ weechat_iconv_fprintf (file, "server_autojoin = \"\"\n");
+ weechat_iconv_fprintf (file, "server_autorejoin = on\n");
+ weechat_iconv_fprintf (file, "server_notify_levels = \"\"\n");
+
+ /* all ok */
+ return 0;
+}
+
+/*
+ * irc_config_write: write IRC configuration file
+ * return: 0 if ok
+ * < 0 if error
+ */
+
+int
+irc_config_write ()
+{
+ return config_file_write (weechat_protocol_config_sections,
+ weechat_protocol_config_options,
+ irc_config_write_functions,
+ IRC_CONFIG_NAME);
+}
diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h
new file mode 100644
index 000000000..1d3efedb4
--- /dev/null
+++ b/src/plugins/irc/irc-config.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __WEECHAT_IRC_CONFIG_H
+#define __WEECHAT_IRC_CONFIG_H 1
+
+#include "../../core/config-option.h"
+
+#define IRC_CONFIG_NAME "irc.rc"
+
+#define CFG_IRC_DISPLAY_AWAY_OFF 0
+#define CFG_IRC_DISPLAY_AWAY_LOCAL 1
+#define CFG_IRC_DISPLAY_AWAY_CHANNEL 2
+
+extern int irc_cfg_irc_one_server_buffer;
+extern int irc_cfg_irc_open_near_server;
+extern char *irc_cfg_irc_nick_prefix;
+extern char *irc_cfg_irc_nick_suffix;
+extern int irc_cfg_irc_display_away;
+extern int irc_cfg_irc_show_away_once;
+extern char *irc_cfg_irc_default_msg_part;
+extern char *irc_cfg_irc_default_msg_quit;
+extern int irc_cfg_irc_notice_as_pv;
+extern int irc_cfg_irc_away_check;
+extern int irc_cfg_irc_away_check_max_nicks;
+extern int irc_cfg_irc_lag_check;
+extern int irc_cfg_irc_lag_min_show;
+extern int irc_cfg_irc_lag_disconnect;
+extern int irc_cfg_irc_anti_flood;
+extern char *irc_cfg_irc_highlight;
+extern int irc_cfg_irc_colors_receive;
+extern int irc_cfg_irc_colors_send;
+extern int irc_cfg_irc_send_unknown_commands;
+
+extern int irc_cfg_dcc_auto_accept_files;
+extern int irc_cfg_dcc_auto_accept_chats;
+extern int irc_cfg_dcc_timeout;
+extern int irc_cfg_dcc_blocksize;
+extern int irc_cfg_dcc_fast_send;
+extern char *irc_cfg_dcc_port_range;
+extern char *irc_cfg_dcc_own_ip;
+extern char *irc_cfg_dcc_download_path;
+extern char *irc_cfg_dcc_upload_path;
+extern int irc_cfg_dcc_convert_spaces;
+extern int irc_cfg_dcc_auto_rename;
+extern int irc_cfg_dcc_auto_resume;
+
+extern int irc_cfg_log_auto_server;
+extern int irc_cfg_log_auto_channel;
+extern int irc_cfg_log_auto_private;
+extern int irc_cfg_log_hide_nickserv_pwd;
+
+extern void irc_config_change_noop ();
+extern void irc_config_change_one_server_buffer ();
+extern void irc_config_change_away_check ();
+extern void irc_config_change_log ();
+extern void irc_config_change_notify_levels ();
+extern int irc_config_read_server (t_config_option *, char *, char *);
+extern int irc_config_read ();
+extern int irc_config_write_servers (FILE *, char *, t_config_option *);
+extern int irc_config_write_servers_default_values (FILE *, char *,
+ t_config_option *);
+extern int irc_config_write ();
+
+#endif /* irc-config.h */
diff --git a/src/plugins/irc/irc-core.c b/src/plugins/irc/irc-core.c
new file mode 100644
index 000000000..f24c7429f
--- /dev/null
+++ b/src/plugins/irc/irc-core.c
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/* irc-core.c: main IRC functions */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef HAVE_GNUTLS
+#include <gnutls/gnutls.h>
+#endif
+
+#include "../../core/weechat.h"
+#include "irc.h"
+#include "../../core/log.h"
+#include "../../gui/gui.h"
+
+
+char protocol_name[] = _PROTOCOL_NAME;
+char protocol_version[] = _PROTOCOL_VERSION;
+char protocol_description[] = _PROTOCOL_DESC;
+
+t_weechat_protocol *irc_protocol;
+t_weechat_hook *irc_hook_timer = NULL;
+t_weechat_hook *irc_hook_timer_check_away = NULL;
+
+#ifdef HAVE_GNUTLS
+gnutls_certificate_credentials gnutls_xcred; /* gnutls client credentials */
+#endif
+
+
+/*
+ * weechat_protocol_init: initialize IRC protocol
+ */
+
+int
+weechat_protocol_init (t_weechat_protocol *protocol)
+{
+ irc_protocol = protocol;
+
+#ifdef HAVE_GNUTLS
+ /* init GnuTLS */
+ gnutls_global_init ();
+ gnutls_certificate_allocate_credentials (&gnutls_xcred);
+ gnutls_certificate_set_x509_trust_file (gnutls_xcred, "ca.pem", GNUTLS_X509_FMT_PEM);
+#endif
+
+ irc_config_read ();
+
+ return PROTOCOL_RC_OK;
+}
+
+/*
+ * weechat_protocol_run: run IRC protocol: auto-connect to servers
+ * and start timers
+ */
+
+int
+weechat_protocol_run ()
+{
+ irc_server_auto_connect (1, 0);
+
+ irc_hook_timer = weechat_hook_add_timer (1 * 1000,
+ irc_server_timer,
+ NULL);
+ if (irc_cfg_irc_away_check != 0)
+ weechat_hook_add_timer (irc_cfg_irc_away_check * 60 * 1000,
+ irc_server_timer_check_away,
+ NULL);
+
+ return PROTOCOL_RC_OK;
+}
+
+/*
+ * weechat_protocol_input_data: read data from user input
+ */
+
+int
+weechat_protocol_input_data (t_gui_window *window, char *data)
+{
+ return irc_input_data (window, data);
+}
+
+/*
+ * weechat_protocol_config_read: read IRC configuration file
+ */
+
+int
+weechat_protocol_config_read ()
+{
+ return irc_config_read ();
+}
+
+/*
+ * weechat_protocol_config_write: write IRC configuration file
+ */
+
+int
+weechat_protocol_config_write ()
+{
+ return irc_config_write ();
+}
+
+/*
+ * weechat_protocol_dump: dump protocol data in WeeChat log file
+ */
+
+int
+weechat_protocol_dump ()
+{
+ t_irc_server *ptr_server;
+ t_irc_channel *ptr_channel;
+ t_irc_nick *ptr_nick;
+
+ for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server)
+ {
+ weechat_log_printf ("\n");
+ irc_server_print_log (ptr_server);
+
+ for (ptr_channel = ptr_server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
+ {
+ weechat_log_printf ("\n");
+ irc_channel_print_log (ptr_channel);
+
+ for (ptr_nick = ptr_channel->nicks; ptr_nick;
+ ptr_nick = ptr_nick->next_nick)
+ {
+ weechat_log_printf ("\n");
+ irc_nick_print_log (ptr_nick);
+ }
+
+ }
+ }
+
+ irc_dcc_print_log ();
+
+ return PROTOCOL_RC_OK;
+}
+
+/*
+ * weechat_protocol_end: end IRC protocol
+ */
+
+int
+weechat_protocol_end ()
+{
+ if (irc_hook_timer)
+ weechat_hook_remove (irc_hook_timer);
+
+ irc_server_disconnect_all ();
+ irc_dcc_end ();
+ irc_server_free_all ();
+
+ irc_config_write ();
+
+#ifdef HAVE_GNUTLS
+ /* GnuTLS end */
+ gnutls_certificate_free_credentials (gnutls_xcred);
+ gnutls_global_deinit();
+#endif
+
+ return PROTOCOL_RC_OK;
+}
diff --git a/src/plugins/irc/irc-dcc.c b/src/plugins/irc/irc-dcc.c
index 6580b7110..9d5cd76de 100644
--- a/src/plugins/irc/irc-dcc.c
+++ b/src/plugins/irc/irc-dcc.c
@@ -39,12 +39,11 @@
#include <arpa/inet.h>
#include <netdb.h>
-#include "../../common/weechat.h"
+#include "../../core/weechat.h"
#include "irc.h"
-#include "../../common/log.h"
-#include "../../common/hotlist.h"
-#include "../../common/util.h"
-#include "../../common/weeconfig.h"
+#include "../../core/log.h"
+#include "../../core/util.h"
+#include "../../core/weechat-config.h"
#include "../../gui/gui.h"
@@ -68,7 +67,7 @@ irc_dcc_redraw (int highlight)
gui_window_redraw_buffer (ptr_buffer);
if (highlight && gui_add_hotlist && (ptr_buffer->num_displayed == 0))
{
- hotlist_add (highlight, NULL, NULL, ptr_buffer, 0);
+ gui_hotlist_add (highlight, NULL, ptr_buffer, 0);
gui_status_draw (gui_current_window->buffer, 0);
}
}
@@ -125,7 +124,7 @@ irc_dcc_file_is_resumable (t_irc_dcc *ptr_dcc, char *filename)
{
struct stat st;
- if (!cfg_dcc_auto_resume)
+ if (!irc_cfg_dcc_auto_resume)
return 0;
if (access (filename, W_OK) == 0)
@@ -160,7 +159,7 @@ irc_dcc_find_filename (t_irc_dcc *ptr_dcc)
if (!IRC_DCC_IS_FILE(ptr_dcc->type))
return;
- dir1 = weechat_strreplace (cfg_dcc_download_path, "~", getenv ("HOME"));
+ dir1 = weechat_strreplace (irc_cfg_dcc_download_path, "~", getenv ("HOME"));
if (!dir1)
return;
dir2 = weechat_strreplace (dir1, "%h", weechat_home);
@@ -195,10 +194,10 @@ irc_dcc_find_filename (t_irc_dcc *ptr_dcc)
return;
/* if auto rename is not set, then abort DCC */
- if (!cfg_dcc_auto_rename)
+ if (!irc_cfg_dcc_auto_rename)
{
irc_dcc_close (ptr_dcc, IRC_DCC_FAILED);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
return;
}
@@ -206,7 +205,7 @@ irc_dcc_find_filename (t_irc_dcc *ptr_dcc)
if (!filename2)
{
irc_dcc_close (ptr_dcc, IRC_DCC_FAILED);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
return;
}
ptr_dcc->filename_suffix = 0;
@@ -454,32 +453,33 @@ irc_dcc_close (t_irc_dcc *ptr_dcc, int status)
ptr_dcc->status = status;
- if ((status == IRC_DCC_DONE) || (status == IRC_DCC_ABORTED) || (status == IRC_DCC_FAILED))
+ if ((status == IRC_DCC_DONE) || (status == IRC_DCC_ABORTED)
+ || (status == IRC_DCC_FAILED))
{
if (IRC_DCC_IS_FILE(ptr_dcc->type))
{
- irc_display_prefix (ptr_dcc->server, ptr_dcc->server->buffer,
- GUI_PREFIX_INFO);
- gui_printf (ptr_dcc->server->buffer,
- _("DCC: file %s%s%s"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- ptr_dcc->filename,
- GUI_COLOR(GUI_COLOR_WIN_CHAT));
+ gui_chat_printf_info (ptr_dcc->server->buffer,
+ _("DCC: file %s%s%s"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ ptr_dcc->filename,
+ GUI_COLOR(GUI_COLOR_CHAT));
if (ptr_dcc->local_filename)
- gui_printf (ptr_dcc->server->buffer,
- _(" (local filename: %s%s%s)"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- ptr_dcc->local_filename,
- GUI_COLOR(GUI_COLOR_WIN_CHAT));
+ gui_chat_printf (ptr_dcc->server->buffer,
+ _(" (local filename: %s%s%s)"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ ptr_dcc->local_filename,
+ GUI_COLOR(GUI_COLOR_CHAT));
if (ptr_dcc->type == IRC_DCC_FILE_SEND)
- gui_printf (ptr_dcc->server->buffer, _(" sent to "));
+ gui_chat_printf (ptr_dcc->server->buffer,
+ _(" sent to "));
else
- gui_printf (ptr_dcc->server->buffer, _(" received from "));
- gui_printf (ptr_dcc->server->buffer, "%s%s%s: %s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- ptr_dcc->nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (status == IRC_DCC_DONE) ? _("OK") : _("FAILED"));
+ gui_chat_printf (ptr_dcc->server->buffer,
+ _(" received from "));
+ gui_chat_printf (ptr_dcc->server->buffer, "%s%s%s: %s\n",
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ ptr_dcc->nick,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (status == IRC_DCC_DONE) ? _("OK") : _("FAILED"));
irc_dcc_file_child_kill (ptr_dcc);
}
}
@@ -491,18 +491,18 @@ irc_dcc_close (t_irc_dcc *ptr_dcc, int status)
ptr_buffer = ptr_dcc->channel->buffer;
else
ptr_buffer = ptr_dcc->server->buffer;
- irc_display_prefix (ptr_dcc->server, ptr_buffer, GUI_PREFIX_INFO);
- gui_printf (ptr_buffer,
- _("DCC chat closed with %s%s %s(%s%d.%d.%d.%d%s)\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- ptr_dcc->nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- ptr_dcc->addr >> 24,
- (ptr_dcc->addr >> 16) & 0xff,
- (ptr_dcc->addr >> 8) & 0xff,
- ptr_dcc->addr & 0xff,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
+ gui_chat_printf_info (ptr_buffer,
+ _("DCC chat closed with %s%s "
+ "%s(%s%d.%d.%d.%d%s)\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ ptr_dcc->nick,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ ptr_dcc->addr >> 24,
+ (ptr_dcc->addr >> 16) & 0xff,
+ (ptr_dcc->addr >> 8) & 0xff,
+ ptr_dcc->addr & 0xff,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
}
}
@@ -545,31 +545,30 @@ irc_dcc_channel_for_chat (t_irc_dcc *ptr_dcc)
{
if (!irc_channel_create_dcc (ptr_dcc))
{
- irc_display_prefix (ptr_dcc->server, ptr_dcc->server->buffer,
- GUI_PREFIX_ERROR);
- gui_printf (ptr_dcc->server->buffer,
- _("%s can't associate DCC chat with private buffer "
- "(maybe private buffer has already DCC CHAT?)\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (ptr_dcc->server->buffer,
+ _("%s can't associate DCC chat with private "
+ "buffer (maybe private buffer has already "
+ "DCC CHAT?)\n"),
+ WEECHAT_ERROR);
irc_dcc_close (ptr_dcc, IRC_DCC_FAILED);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
return;
}
- irc_display_prefix (ptr_dcc->server, ptr_dcc->channel->buffer,
- GUI_PREFIX_INFO);
- gui_printf_type (ptr_dcc->channel->buffer, GUI_MSG_TYPE_MSG,
- _("Connected to %s%s %s(%s%d.%d.%d.%d%s)%s via DCC chat\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- ptr_dcc->nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- ptr_dcc->addr >> 24,
- (ptr_dcc->addr >> 16) & 0xff,
- (ptr_dcc->addr >> 8) & 0xff,
- ptr_dcc->addr & 0xff,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT));
+ gui_chat_printf_type (ptr_dcc->channel->buffer, GUI_MSG_TYPE_MSG,
+ cfg_look_prefix_info, cfg_col_chat_prefix_info,
+ _("Connected to %s%s %s(%s%d.%d.%d.%d%s)%s via DCC "
+ "chat\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ ptr_dcc->nick,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ ptr_dcc->addr >> 24,
+ (ptr_dcc->addr >> 16) & 0xff,
+ (ptr_dcc->addr >> 8) & 0xff,
+ ptr_dcc->addr & 0xff,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT));
}
/*
@@ -601,7 +600,7 @@ irc_dcc_recv_connect_init (t_irc_dcc *ptr_dcc)
if (!irc_dcc_connect (ptr_dcc))
{
irc_dcc_close (ptr_dcc, IRC_DCC_FAILED);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
}
else
{
@@ -618,7 +617,7 @@ irc_dcc_recv_connect_init (t_irc_dcc *ptr_dcc)
irc_dcc_channel_for_chat (ptr_dcc);
}
}
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
}
/*
@@ -637,7 +636,7 @@ irc_dcc_accept (t_irc_dcc *ptr_dcc)
"PRIVMSG %s :\01DCC RESUME %s %d %u\01",
ptr_dcc->nick, ptr_dcc->filename,
ptr_dcc->port, ptr_dcc->start_resume);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
}
else
irc_dcc_recv_connect_init (ptr_dcc);
@@ -653,7 +652,8 @@ irc_dcc_accept_resume (t_irc_server *server, char *filename, int port,
{
t_irc_dcc *ptr_dcc;
- ptr_dcc = irc_dcc_search (server, IRC_DCC_FILE_SEND, IRC_DCC_CONNECTING, port);
+ ptr_dcc = irc_dcc_search (server, IRC_DCC_FILE_SEND, IRC_DCC_CONNECTING,
+ port);
if (ptr_dcc)
{
ptr_dcc->pos = pos_start;
@@ -667,24 +667,24 @@ irc_dcc_accept_resume (t_irc_server *server, char *filename, int port,
ptr_dcc->nick, ptr_dcc->filename,
ptr_dcc->port, ptr_dcc->start_resume);
- irc_display_prefix (ptr_dcc->server, ptr_dcc->server->buffer,
- GUI_PREFIX_INFO);
- gui_printf (ptr_dcc->server->buffer,
- _("DCC: file %s%s%s resumed at position %u\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- ptr_dcc->filename,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- ptr_dcc->start_resume);
- irc_dcc_redraw (HOTLIST_MSG);
+ gui_chat_printf_info (ptr_dcc->server->buffer,
+ _("DCC: file %s%s%s resumed at position %u\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ ptr_dcc->filename,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ ptr_dcc->start_resume);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
}
else
- gui_printf (server->buffer,
- _("%s can't resume file \"%s\" (port: %d, start position: %u): DCC not found or ended\n"),
- WEECHAT_ERROR, filename, port, pos_start);
+ gui_chat_printf (server->buffer,
+ _("%s can't resume file \"%s\" (port: %d, start "
+ "position: %u): DCC not found or ended\n"),
+ WEECHAT_ERROR, filename, port, pos_start);
}
/*
- * irc_dcc_start_resume: called when "DCC ACCEPT" is received (resume accepted by sender)
+ * irc_dcc_start_resume: called when "DCC ACCEPT" is received
+ * (resume accepted by sender)
*/
void
@@ -693,7 +693,8 @@ irc_dcc_start_resume (t_irc_server *server, char *filename, int port,
{
t_irc_dcc *ptr_dcc;
- ptr_dcc = irc_dcc_search (server, IRC_DCC_FILE_RECV, IRC_DCC_CONNECTING, port);
+ ptr_dcc = irc_dcc_search (server, IRC_DCC_FILE_RECV, IRC_DCC_CONNECTING,
+ port);
if (ptr_dcc)
{
ptr_dcc->pos = pos_start;
@@ -703,9 +704,10 @@ irc_dcc_start_resume (t_irc_server *server, char *filename, int port,
irc_dcc_recv_connect_init (ptr_dcc);
}
else
- gui_printf (server->buffer,
- _("%s can't resume file \"%s\" (port: %d, start position: %u): DCC not found or ended\n"),
- WEECHAT_ERROR, filename, port, pos_start);
+ gui_chat_printf (server->buffer,
+ _("%s can't resume file \"%s\" (port: %d, start "
+ "position: %u): DCC not found or ended\n"),
+ WEECHAT_ERROR, filename, port, pos_start);
}
/*
@@ -736,12 +738,12 @@ irc_dcc_alloc ()
new_dcc->child_read = -1;
new_dcc->child_write = -1;
new_dcc->unterminated_message = NULL;
- new_dcc->fast_send = cfg_dcc_fast_send;
+ new_dcc->fast_send = irc_cfg_dcc_fast_send;
new_dcc->file = -1;
new_dcc->filename = NULL;
new_dcc->local_filename = NULL;
new_dcc->filename_suffix = -1;
- new_dcc->blocksize = cfg_dcc_blocksize;
+ new_dcc->blocksize = irc_cfg_dcc_blocksize;
new_dcc->size = 0;
new_dcc->pos = 0;
new_dcc->ack = 0;
@@ -776,10 +778,9 @@ irc_dcc_add (t_irc_server *server, int type, unsigned long addr, int port, char
new_dcc = irc_dcc_alloc ();
if (!new_dcc)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s not enough memory for new DCC\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ _("%s not enough memory for new DCC\n"),
+ WEECHAT_ERROR);
return NULL;
}
@@ -822,96 +823,92 @@ irc_dcc_add (t_irc_server *server, int type, unsigned long addr, int port, char
/* write info message on server buffer */
if (type == IRC_DCC_FILE_RECV)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_INFO);
- gui_printf (server->buffer,
- _("Incoming DCC file from %s%s%s (%s%d.%d.%d.%d%s)%s: %s%s%s, %s%lu%s bytes\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- addr >> 24,
- (addr >> 16) & 0xff,
- (addr >> 8) & 0xff,
- addr & 0xff,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- filename,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- size,
- GUI_COLOR(GUI_COLOR_WIN_CHAT));
- irc_dcc_redraw (HOTLIST_MSG);
+ gui_chat_printf_info (server->buffer,
+ _("Incoming DCC file from %s%s%s "
+ "(%s%d.%d.%d.%d%s)%s: %s%s%s, "
+ "%s%lu%s bytes\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ addr >> 24,
+ (addr >> 16) & 0xff,
+ (addr >> 8) & 0xff,
+ addr & 0xff,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ filename,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ size,
+ GUI_COLOR(GUI_COLOR_CHAT));
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
}
if (type == IRC_DCC_FILE_SEND)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_INFO);
- gui_printf (server->buffer,
- _("Sending DCC file to %s%s%s: %s%s%s "
- "(local filename: %s%s%s), %s%lu%s bytes\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- filename,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- local_filename,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- size,
- GUI_COLOR(GUI_COLOR_WIN_CHAT));
- irc_dcc_redraw (HOTLIST_MSG);
+ gui_chat_printf_info (server->buffer,
+ _("Sending DCC file to %s%s%s: %s%s%s "
+ "(local filename: %s%s%s), %s%lu%s bytes\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ filename,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ local_filename,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ size,
+ GUI_COLOR(GUI_COLOR_CHAT));
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
}
if (type == IRC_DCC_CHAT_RECV)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_INFO);
- gui_printf (server->buffer,
- _("Incoming DCC chat request from %s%s%s "
- "(%s%d.%d.%d.%d%s)\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- addr >> 24,
- (addr >> 16) & 0xff,
- (addr >> 8) & 0xff,
- addr & 0xff,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
- irc_dcc_redraw (HOTLIST_MSG);
+ gui_chat_printf_info (server->buffer,
+ _("Incoming DCC chat request from %s%s%s "
+ "(%s%d.%d.%d.%d%s)\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ addr >> 24,
+ (addr >> 16) & 0xff,
+ (addr >> 8) & 0xff,
+ addr & 0xff,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
}
if (type == IRC_DCC_CHAT_SEND)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_INFO);
- gui_printf (server->buffer,
- _("Sending DCC chat request to %s%s\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick);
- irc_dcc_redraw (HOTLIST_MSG);
+ gui_chat_printf_info (server->buffer,
+ _("Sending DCC chat request to %s%s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
}
if (IRC_DCC_IS_FILE(type) && (!new_dcc->local_filename))
{
irc_dcc_close (new_dcc, IRC_DCC_FAILED);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
return NULL;
}
if (IRC_DCC_IS_FILE(type) && (new_dcc->start_resume > 0))
{
- irc_display_prefix (new_dcc->server, new_dcc->server->buffer,
- GUI_PREFIX_INFO);
- gui_printf (new_dcc->server->buffer,
- _("DCC: file %s%s%s (local filename: %s%s%s) "
- "will be resumed at position %u\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- new_dcc->filename,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- new_dcc->local_filename,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- new_dcc->start_resume);
- irc_dcc_redraw (HOTLIST_MSG);
+ gui_chat_printf_info (new_dcc->server->buffer,
+ _("DCC: file %s%s%s (local filename: %s%s%s) "
+ "will be resumed at position %u\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ new_dcc->filename,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ new_dcc->local_filename,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ new_dcc->start_resume);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
}
/* connect if needed and redraw DCC buffer */
@@ -920,16 +917,16 @@ irc_dcc_add (t_irc_server *server, int type, unsigned long addr, int port, char
if (!irc_dcc_connect (new_dcc))
{
irc_dcc_close (new_dcc, IRC_DCC_FAILED);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
return NULL;
}
}
- if ( ( (type == IRC_DCC_CHAT_RECV) && (cfg_dcc_auto_accept_chats) )
- || ( (type == IRC_DCC_FILE_RECV) && (cfg_dcc_auto_accept_files) ) )
+ if ( ( (type == IRC_DCC_CHAT_RECV) && (irc_cfg_dcc_auto_accept_chats) )
+ || ( (type == IRC_DCC_FILE_RECV) && (irc_cfg_dcc_auto_accept_files) ) )
irc_dcc_accept (new_dcc);
else
- irc_dcc_redraw (HOTLIST_PRIVATE);
+ irc_dcc_redraw (GUI_HOTLIST_PRIVATE);
gui_status_draw (gui_current_window->buffer, 0);
return new_dcc;
@@ -969,7 +966,8 @@ irc_dcc_send_request (t_irc_server *server, int type, char *nick, char *filename
filename2 = weechat_strreplace (filename, "~", getenv ("HOME"));
else
{
- dir1 = weechat_strreplace (cfg_dcc_upload_path, "~", getenv ("HOME"));
+ dir1 = weechat_strreplace (irc_cfg_dcc_upload_path, "~",
+ getenv ("HOME"));
if (!dir1)
return;
dir2 = weechat_strreplace (dir1, "%h", weechat_home);
@@ -982,10 +980,9 @@ irc_dcc_send_request (t_irc_server *server, int type, char *nick, char *filename
strlen (filename) + 4);
if (!filename2)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s not enough memory for DCC SEND\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ _("%s not enough memory for DCC SEND\n"),
+ WEECHAT_ERROR);
return;
}
strcpy (filename2, dir2);
@@ -1002,10 +999,9 @@ irc_dcc_send_request (t_irc_server *server, int type, char *nick, char *filename
/* check if file exists */
if (stat (filename2, &st) == -1)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s cannot access file \"%s\"\n"),
- WEECHAT_ERROR, filename2);
+ gui_chat_printf_error (server->buffer,
+ _("%s cannot access file \"%s\"\n"),
+ WEECHAT_ERROR, filename2);
if (filename2)
free (filename2);
return;
@@ -1016,18 +1012,19 @@ irc_dcc_send_request (t_irc_server *server, int type, char *nick, char *filename
/* look up the IP address from dcc_own_ip, if set */
local_addr = 0;
- if (cfg_dcc_own_ip && cfg_dcc_own_ip[0])
+ if (irc_cfg_dcc_own_ip && irc_cfg_dcc_own_ip[0])
{
- host = gethostbyname (cfg_dcc_own_ip);
+ host = gethostbyname (irc_cfg_dcc_own_ip);
if (host)
{
memcpy (&tmpaddr, host->h_addr_list[0], sizeof(struct in_addr));
local_addr = ntohl (tmpaddr.s_addr);
}
else
- gui_printf (server->buffer,
- _("%s could not find address for '%s'. Falling back to local IP.\n"),
- WEECHAT_WARNING, cfg_dcc_own_ip);
+ gui_chat_printf (server->buffer,
+ _("%s could not find address for '%s'. Falling "
+ "back to local IP.\n"),
+ WEECHAT_WARNING, irc_cfg_dcc_own_ip);
}
/* use the local interface, from the server socket */
@@ -1044,10 +1041,9 @@ irc_dcc_send_request (t_irc_server *server, int type, char *nick, char *filename
sock = socket (AF_INET, SOCK_STREAM, 0);
if (sock < 0)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s cannot create socket for DCC\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ _("%s cannot create socket for DCC\n"),
+ WEECHAT_ERROR);
if (filename2)
free (filename2);
return;
@@ -1057,10 +1053,10 @@ irc_dcc_send_request (t_irc_server *server, int type, char *nick, char *filename
port = 0;
- if (cfg_dcc_port_range && cfg_dcc_port_range[0])
+ if (irc_cfg_dcc_port_range && irc_cfg_dcc_port_range[0])
{
/* find a free port in the specified range */
- args = sscanf (cfg_dcc_port_range, "%d-%d", &port_start, &port_end);
+ args = sscanf (irc_cfg_dcc_port_range, "%d-%d", &port_start, &port_end);
if (args > 0)
{
port = port_start;
@@ -1102,10 +1098,9 @@ irc_dcc_send_request (t_irc_server *server, int type, char *nick, char *filename
if (port == -1)
{
/* Could not find any port to bind */
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s cannot find available port for DCC\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ _("%s cannot find available port for DCC\n"),
+ WEECHAT_ERROR);
close (sock);
if (filename2)
free (filename2);
@@ -1128,7 +1123,7 @@ irc_dcc_send_request (t_irc_server *server, int type, char *nick, char *filename
{
if (pos[0] == ' ')
{
- if (cfg_dcc_convert_spaces)
+ if (irc_cfg_dcc_convert_spaces)
pos[0] = '_';
else
spaces = 1;
@@ -1139,17 +1134,17 @@ irc_dcc_send_request (t_irc_server *server, int type, char *nick, char *filename
/* add DCC entry and listen to socket */
if (type == IRC_DCC_CHAT_SEND)
- ptr_dcc = irc_dcc_add (server, IRC_DCC_CHAT_SEND, local_addr, port, nick, sock,
- NULL, NULL, 0);
+ ptr_dcc = irc_dcc_add (server, IRC_DCC_CHAT_SEND, local_addr, port,
+ nick, sock, NULL, NULL, 0);
else
- ptr_dcc = irc_dcc_add (server, IRC_DCC_FILE_SEND, local_addr, port, nick, sock,
- short_filename, filename2, st.st_size);
+ ptr_dcc = irc_dcc_add (server, IRC_DCC_FILE_SEND, local_addr, port,
+ nick, sock, short_filename, filename2,
+ st.st_size);
if (!ptr_dcc)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s cannot send DCC\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ _("%s cannot send DCC\n"),
+ WEECHAT_ERROR);
close (sock);
if (short_filename)
free (short_filename);
@@ -1216,16 +1211,17 @@ irc_dcc_chat_sendf (t_irc_dcc *ptr_dcc, char *fmt, ...)
size_buf = strlen (buffer);
#ifdef DEBUG
buffer[size_buf - 2] = '\0';
- gui_printf (ptr_dcc->server->buffer, "[DEBUG] Sending to remote host (DCC CHAT) >>> %s\n", buffer);
+ gui_chat_printf (ptr_dcc->server->buffer,
+ "[DEBUG] Sending to remote host (DCC CHAT) >>> %s\n",
+ buffer);
buffer[size_buf - 2] = '\r';
#endif
if (irc_dcc_chat_send (ptr_dcc, buffer, strlen (buffer)) <= 0)
{
- irc_display_prefix (ptr_dcc->server, ptr_dcc->server->buffer,
- GUI_PREFIX_ERROR);
- gui_printf (ptr_dcc->server->buffer,
- _("%s error sending data to \"%s\" via DCC CHAT\n"),
- WEECHAT_ERROR, ptr_dcc->nick);
+ gui_chat_printf_error (ptr_dcc->server->buffer,
+ _("%s error sending data to \"%s\" via DCC "
+ "CHAT\n"),
+ WEECHAT_ERROR, ptr_dcc->nick);
irc_dcc_close (ptr_dcc, IRC_DCC_FAILED);
}
}
@@ -1304,27 +1300,33 @@ irc_dcc_chat_recv (t_irc_dcc *ptr_dcc)
if (ptr_buf)
{
- if (irc_recv_is_highlight (ptr_buf, ptr_dcc->server->nick))
+ if (irc_protocol_is_highlight (ptr_buf, ptr_dcc->server->nick))
{
- irc_display_nick (ptr_dcc->channel->buffer, NULL, ptr_dcc->nick,
- GUI_MSG_TYPE_NICK | GUI_MSG_TYPE_HIGHLIGHT, 1,
- GUI_COLOR_WIN_CHAT_HIGHLIGHT, 0);
+ irc_display_nick (ptr_dcc->channel->buffer, NULL,
+ ptr_dcc->nick,
+ GUI_MSG_TYPE_NICK | GUI_MSG_TYPE_HIGHLIGHT,
+ 1,
+ GUI_COLOR(GUI_COLOR_CHAT_HIGHLIGHT), 0);
if ((cfg_look_infobar_delay_highlight > 0)
&& (ptr_dcc->channel->buffer != gui_current_window->buffer))
{
gui_infobar_printf (cfg_look_infobar_delay_highlight,
- GUI_COLOR_WIN_INFOBAR_HIGHLIGHT,
+ GUI_COLOR_INFOBAR_HIGHLIGHT,
_("Private %s> %s"),
ptr_dcc->nick, ptr_buf);
}
}
else
- irc_display_nick (ptr_dcc->channel->buffer, NULL, ptr_dcc->nick,
- GUI_MSG_TYPE_NICK, 1, GUI_COLOR_WIN_NICK_PRIVATE, 0);
- gui_printf_type (ptr_dcc->channel->buffer, GUI_MSG_TYPE_MSG,
- "%s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- ptr_buf);
+ irc_display_nick (ptr_dcc->channel->buffer, NULL,
+ ptr_dcc->nick,
+ GUI_MSG_TYPE_NICK, 1,
+ GUI_COLOR(GUI_COLOR_CHAT_NICK_OTHER), 0);
+ gui_chat_printf_type (ptr_dcc->channel->buffer,
+ GUI_MSG_TYPE_MSG,
+ NULL, -1,
+ "%s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ ptr_buf);
}
ptr_buf = next_ptr_buf;
@@ -1336,7 +1338,7 @@ irc_dcc_chat_recv (t_irc_dcc *ptr_dcc)
else
{
irc_dcc_close (ptr_dcc, IRC_DCC_ABORTED);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
}
}
@@ -1352,13 +1354,11 @@ irc_dcc_file_create_pipe (t_irc_dcc *ptr_dcc)
if (pipe (child_pipe) < 0)
{
- irc_display_prefix (ptr_dcc->server, ptr_dcc->server->buffer,
- GUI_PREFIX_ERROR);
- gui_printf (ptr_dcc->server->buffer,
- _("%s DCC: unable to create pipe\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (ptr_dcc->server->buffer,
+ _("%s DCC: unable to create pipe\n"),
+ WEECHAT_ERROR);
irc_dcc_close (ptr_dcc, IRC_DCC_FAILED);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
return 0;
}
@@ -1580,47 +1580,41 @@ irc_dcc_file_child_read (t_irc_dcc *ptr_dcc)
{
/* errors for sender */
case IRC_DCC_ERROR_READ_LOCAL:
- irc_display_prefix (ptr_dcc->server, ptr_dcc->server->buffer,
- GUI_PREFIX_ERROR);
- gui_printf (ptr_dcc->server->buffer,
- _("%s DCC: unable to read local file\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (ptr_dcc->server->buffer,
+ _("%s DCC: unable to read local "
+ "file\n"),
+ WEECHAT_ERROR);
break;
case IRC_DCC_ERROR_SEND_BLOCK:
- irc_display_prefix (ptr_dcc->server, ptr_dcc->server->buffer,
- GUI_PREFIX_ERROR);
- gui_printf (ptr_dcc->server->buffer,
- _("%s DCC: unable to send block to receiver\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (ptr_dcc->server->buffer,
+ _("%s DCC: unable to send block to "
+ "receiver\n"),
+ WEECHAT_ERROR);
break;
case IRC_DCC_ERROR_READ_ACK:
- irc_display_prefix (ptr_dcc->server, ptr_dcc->server->buffer,
- GUI_PREFIX_ERROR);
- gui_printf (ptr_dcc->server->buffer,
- _("%s DCC: unable to read ACK from receiver\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (ptr_dcc->server->buffer,
+ _("%s DCC: unable to read ACK from "
+ "receiver\n"),
+ WEECHAT_ERROR);
break;
/* errors for receiver */
case IRC_DCC_ERROR_CONNECT_SENDER:
- irc_display_prefix (ptr_dcc->server, ptr_dcc->server->buffer,
- GUI_PREFIX_ERROR);
- gui_printf (ptr_dcc->server->buffer,
- _("%s DCC: unable to connect to sender\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (ptr_dcc->server->buffer,
+ _("%s DCC: unable to connect to "
+ "sender\n"),
+ WEECHAT_ERROR);
break;
case IRC_DCC_ERROR_RECV_BLOCK:
- irc_display_prefix (ptr_dcc->server, ptr_dcc->server->buffer,
- GUI_PREFIX_ERROR);
- gui_printf (ptr_dcc->server->buffer,
- _("%s DCC: unable to receive block from sender\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (ptr_dcc->server->buffer,
+ _("%s DCC: unable to receive block "
+ "from sender\n"),
+ WEECHAT_ERROR);
break;
case IRC_DCC_ERROR_WRITE_LOCAL:
- irc_display_prefix (ptr_dcc->server, ptr_dcc->server->buffer,
- GUI_PREFIX_ERROR);
- gui_printf (ptr_dcc->server->buffer,
- _("%s DCC: unable to write local file\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (ptr_dcc->server->buffer,
+ _("%s DCC: unable to write local "
+ "file\n"),
+ WEECHAT_ERROR);
break;
}
@@ -1634,18 +1628,18 @@ irc_dcc_file_child_read (t_irc_dcc *ptr_dcc)
ptr_dcc->status = IRC_DCC_ACTIVE;
ptr_dcc->start_transfer = time (NULL);
ptr_dcc->last_check_time = time (NULL);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
}
else
- irc_dcc_redraw (HOTLIST_LOW);
+ irc_dcc_redraw (GUI_HOTLIST_LOW);
break;
case IRC_DCC_DONE:
irc_dcc_close (ptr_dcc, IRC_DCC_DONE);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
break;
case IRC_DCC_FAILED:
irc_dcc_close (ptr_dcc, IRC_DCC_FAILED);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
break;
}
}
@@ -1669,13 +1663,11 @@ irc_dcc_file_send_fork (t_irc_dcc *ptr_dcc)
{
/* fork failed */
case -1:
- irc_display_prefix (ptr_dcc->server, ptr_dcc->server->buffer,
- GUI_PREFIX_ERROR);
- gui_printf (ptr_dcc->server->buffer,
- _("%s DCC: unable to fork\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (ptr_dcc->server->buffer,
+ _("%s DCC: unable to fork\n"),
+ WEECHAT_ERROR);
irc_dcc_close (ptr_dcc, IRC_DCC_FAILED);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
return;
/* child process */
case 0:
@@ -1712,13 +1704,11 @@ irc_dcc_file_recv_fork (t_irc_dcc *ptr_dcc)
{
/* fork failed */
case -1:
- irc_display_prefix (ptr_dcc->server, ptr_dcc->server->buffer,
- GUI_PREFIX_ERROR);
- gui_printf (ptr_dcc->server->buffer,
- _("%s DCC: unable to fork\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (ptr_dcc->server->buffer,
+ _("%s DCC: unable to fork\n"),
+ WEECHAT_ERROR);
irc_dcc_close (ptr_dcc, IRC_DCC_FAILED);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
return;
/* child process */
case 0:
@@ -1750,15 +1740,14 @@ irc_dcc_handle ()
/* check DCC timeout */
if (IRC_DCC_IS_FILE(ptr_dcc->type) && !IRC_DCC_ENDED(ptr_dcc->status))
{
- if ((cfg_dcc_timeout != 0) && (time (NULL) > ptr_dcc->last_activity + cfg_dcc_timeout))
+ if ((irc_cfg_dcc_timeout != 0)
+ && (time (NULL) > ptr_dcc->last_activity + irc_cfg_dcc_timeout))
{
- irc_display_prefix (ptr_dcc->server, ptr_dcc->server->buffer,
- GUI_PREFIX_ERROR);
- gui_printf (ptr_dcc->server->buffer,
- _("%s DCC: timeout\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (ptr_dcc->server->buffer,
+ _("%s DCC: timeout\n"),
+ WEECHAT_ERROR);
irc_dcc_close (ptr_dcc, IRC_DCC_FAILED);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
continue;
}
}
@@ -1779,36 +1768,37 @@ irc_dcc_handle ()
{
ptr_dcc->last_activity = time (NULL);
length = sizeof (addr);
- sock = accept (ptr_dcc->sock, (struct sockaddr *) &addr, &length);
+ sock = accept (ptr_dcc->sock,
+ (struct sockaddr *) &addr, &length);
close (ptr_dcc->sock);
ptr_dcc->sock = -1;
if (sock < 0)
{
- irc_display_prefix (ptr_dcc->server, ptr_dcc->server->buffer,
- GUI_PREFIX_ERROR);
- gui_printf (ptr_dcc->server->buffer,
- _("%s DCC: unable to create socket for sending file\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (ptr_dcc->server->buffer,
+ _("%s DCC: unable to "
+ "create socket for "
+ "sending file\n"),
+ WEECHAT_ERROR);
irc_dcc_close (ptr_dcc, IRC_DCC_FAILED);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
continue;
}
ptr_dcc->sock = sock;
if (fcntl (ptr_dcc->sock, F_SETFL, O_NONBLOCK) == -1)
{
- irc_display_prefix (ptr_dcc->server, ptr_dcc->server->buffer,
- GUI_PREFIX_ERROR);
- gui_printf (ptr_dcc->server->buffer,
- _("%s DCC: unable to set 'nonblock' option for socket\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (ptr_dcc->server->buffer,
+ _("%s DCC: unable to set "
+ "'nonblock' option for "
+ "socket\n"),
+ WEECHAT_ERROR);
irc_dcc_close (ptr_dcc, IRC_DCC_FAILED);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
continue;
}
ptr_dcc->addr = ntohl (addr.sin_addr.s_addr);
ptr_dcc->status = IRC_DCC_ACTIVE;
ptr_dcc->start_transfer = time (NULL);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
irc_dcc_file_send_fork (ptr_dcc);
}
}
@@ -1841,19 +1831,19 @@ irc_dcc_handle ()
if (sock < 0)
{
irc_dcc_close (ptr_dcc, IRC_DCC_FAILED);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
continue;
}
ptr_dcc->sock = sock;
if (fcntl (ptr_dcc->sock, F_SETFL, O_NONBLOCK) == -1)
{
irc_dcc_close (ptr_dcc, IRC_DCC_FAILED);
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
continue;
}
ptr_dcc->addr = ntohl (addr.sin_addr.s_addr);
ptr_dcc->status = IRC_DCC_ACTIVE;
- irc_dcc_redraw (HOTLIST_MSG);
+ irc_dcc_redraw (GUI_HOTLIST_MSG);
irc_dcc_channel_for_chat (ptr_dcc);
}
}
diff --git a/src/plugins/irc/irc-dcc.h b/src/plugins/irc/irc-dcc.h
new file mode 100644
index 000000000..cfa89be53
--- /dev/null
+++ b/src/plugins/irc/irc-dcc.h
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __WEECHAT_IRC_DCC_H
+#define __WEECHAT_IRC_DCC_H 1
+
+/* DCC types */
+
+#define IRC_DCC_CHAT_RECV 0 /* receiving DCC chat */
+#define IRC_DCC_CHAT_SEND 1 /* sending DCC chat */
+#define IRC_DCC_FILE_RECV 2 /* incoming DCC file */
+#define IRC_DCC_FILE_SEND 3 /* sending DCC file */
+
+/* DCC status */
+
+#define IRC_DCC_WAITING 0 /* waiting for host answer */
+#define IRC_DCC_CONNECTING 1 /* connecting to host */
+#define IRC_DCC_ACTIVE 2 /* sending/receiving data */
+#define IRC_DCC_DONE 3 /* transfer done */
+#define IRC_DCC_FAILED 4 /* DCC failed */
+#define IRC_DCC_ABORTED 5 /* DCC aborted by user */
+
+/* DCC blocksize (for file) */
+
+#define IRC_DCC_MIN_BLOCKSIZE 1024 /* min DCC block size when sending file*/
+#define IRC_DCC_MAX_BLOCKSIZE 102400 /* max DCC block size when sending file*/
+
+/* DCC errors (for file) */
+
+#define IRC_DCC_NO_ERROR 0 /* no error to report, all ok! */
+#define IRC_DCC_ERROR_READ_LOCAL 1 /* unable to read local file */
+#define IRC_DCC_ERROR_SEND_BLOCK 2 /* unable to send block to receiver */
+#define IRC_DCC_ERROR_READ_ACK 3 /* unable to read ACK from receiver */
+#define IRC_DCC_ERROR_CONNECT_SENDER 4 /* unable to connect to sender */
+#define IRC_DCC_ERROR_RECV_BLOCK 5 /* unable to recv block from sender */
+#define IRC_DCC_ERROR_WRITE_LOCAL 6 /* unable to write to local file */
+
+/* DCC macros for type */
+
+#define IRC_DCC_IS_CHAT(type) ((type == IRC_DCC_CHAT_RECV) || \
+ (type == IRC_DCC_CHAT_SEND))
+#define IRC_DCC_IS_FILE(type) ((type == IRC_DCC_FILE_RECV) || \
+ (type == IRC_DCC_FILE_SEND))
+#define IRC_DCC_IS_RECV(type) ((type == IRC_DCC_CHAT_RECV) || \
+ (type == IRC_DCC_FILE_RECV))
+#define IRC_DCC_IS_SEND(type) ((type == IRC_DCC_CHAT_SEND) || \
+ (type == IRC_DCC_FILE_SEND))
+
+/* DCC macro for status */
+
+#define IRC_DCC_ENDED(status) ((status == IRC_DCC_DONE) || \
+ (status == IRC_DCC_FAILED) || \
+ (status == IRC_DCC_ABORTED))
+
+typedef struct t_irc_dcc t_irc_dcc;
+
+struct t_irc_dcc
+{
+ t_irc_server *server; /* irc server */
+ t_irc_channel *channel; /* irc channel (for DCC chat only) */
+ int type; /* DCC type (file/chat, send/receive) */
+ int status; /* DCC status (waiting, sending, ..) */
+ time_t start_time; /* the time when DCC started */
+ time_t start_transfer; /* the time when DCC transfer started */
+ unsigned long addr; /* IP address */
+ int port; /* port */
+ char *nick; /* remote nick */
+ int sock; /* socket for connection */
+ pid_t child_pid; /* pid of child process (sending/recving)*/
+ int child_read; /* to read into child pipe */
+ int child_write; /* to write into child pipe */
+ char *unterminated_message; /* beginning of a message in input buf */
+ int fast_send; /* fase send for files: does not wait ACK*/
+ int file; /* local file (for reading or writing) */
+ char *filename; /* filename (given by sender) */
+ char *local_filename; /* local filename (with path) */
+ int filename_suffix; /* suffix (.1 for ex) if renaming file */
+ int blocksize; /* block size for sending file */
+ unsigned long size; /* file size */
+ unsigned long pos; /* number of bytes received/sent */
+ unsigned long ack; /* number of bytes received OK */
+ unsigned long start_resume; /* start of resume (in bytes) */
+ time_t last_check_time; /* last time we looked at bytes sent/recv*/
+ unsigned long last_check_pos; /* bytes sent/recv at last check */
+ 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 */
+};
+
+extern t_irc_dcc *irc_dcc_list;
+extern t_irc_dcc *irc_last_dcc;
+extern char *irc_dcc_status_string[6];
+
+#endif /* irc-dcc.h */
diff --git a/src/plugins/irc/irc-display.c b/src/plugins/irc/irc-display.c
index f1112eaa8..0f3ebffe2 100644
--- a/src/plugins/irc/irc-display.c
+++ b/src/plugins/irc/irc-display.c
@@ -28,10 +28,10 @@
#include <stdio.h>
#include <string.h>
-#include "../../common/weechat.h"
+#include "../../core/weechat.h"
#include "irc.h"
-#include "../../common/utf8.h"
-#include "../../common/weeconfig.h"
+#include "../../core/utf8.h"
+#include "../../core/weechat-config.h"
#include "../../gui/gui.h"
@@ -88,83 +88,31 @@ irc_display_hide_password (char *string, int look_for_nickserv)
}
/*
- * irc_display_prefix: display a prefix for action/info/error msg
- * prefix must be 3 chars length
- */
-
-void
-irc_display_prefix (t_irc_server *server, t_gui_buffer *buffer, char *prefix)
-{
- int type;
- char format[32];
-
- type = GUI_MSG_TYPE_INFO | GUI_MSG_TYPE_PREFIX;
-
- if (!cfg_log_plugin_msg && (strcmp (prefix, GUI_PREFIX_PLUGIN) == 0))
- type |= GUI_MSG_TYPE_NOLOG;
-
- if (buffer)
- {
- if (cfg_look_align_other
- && (GUI_BUFFER_IS_CHANNEL(buffer) || GUI_BUFFER_IS_PRIVATE(buffer)))
- {
- snprintf (format, 32, "%%-%ds", cfg_look_align_size - 2);
- gui_printf_type (buffer, GUI_MSG_TYPE_NICK, format, " ");
- }
- }
-
- if (prefix[0] == prefix[2])
- {
- gui_printf_type (buffer, type, "%s%c%s%c%s%c ",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_PREFIX1),
- prefix[0],
- GUI_COLOR(GUI_COLOR_WIN_CHAT_PREFIX2),
- prefix[1],
- GUI_COLOR(GUI_COLOR_WIN_CHAT_PREFIX1),
- prefix[2]);
- }
- else
- {
- if (strcmp (prefix, GUI_PREFIX_JOIN) == 0)
- gui_printf_type (buffer, type, "%s%s ",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_JOIN), prefix);
- else if (strcmp (prefix, GUI_PREFIX_PART) == 0)
- gui_printf_type (buffer, type, "%s%s ",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_PART), prefix);
- else
- gui_printf_type (buffer, type, "%s%s ",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_PREFIX1), prefix);
- }
- if (server && (server->buffer == buffer) && buffer->all_servers)
- {
- gui_printf_type (buffer, type, "%s[%s%s%s] ",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), server->name,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
- }
- gui_printf_type (buffer, type, GUI_NO_COLOR);
-}
-
-/*
* irc_display_nick: display nick in chat window
*/
void
irc_display_nick (t_gui_buffer *buffer, t_irc_nick *nick, char *nickname,
- int type, int display_around, int force_color, int no_nickmode)
+ int type, int display_around, char *force_color, int no_nickmode)
{
char format[32], *ptr_nickname;
- int max_align, i, nickname_length, external_nick, length, spaces;
- int disable_prefix_suffix;
-
+ t_irc_server *ptr_server;
+ t_irc_channel *ptr_channel;
+ int is_private, max_align, i, nickname_length, external_nick;
+ int length, spaces, disable_prefix_suffix;
+
max_align = (cfg_look_align_size_max >= cfg_look_align_size) ?
cfg_look_align_size_max : cfg_look_align_size;
+
+ ptr_server = irc_server_search (buffer->category);
+ ptr_channel = irc_channel_search (ptr_server, buffer->name);
+ is_private = (ptr_channel && (ptr_channel->type != IRC_CHANNEL_TYPE_CHANNEL));
ptr_nickname = strdup ((nick) ? nick->nick : nickname);
if (!ptr_nickname)
return;
nickname_length = utf8_width_screen (ptr_nickname);
- external_nick = (!nick && !GUI_BUFFER_IS_PRIVATE(buffer));
+ external_nick = (!nick && !is_private);
disable_prefix_suffix = ((cfg_look_align_nick != CFG_LOOK_ALIGN_NICK_NONE)
&& ((int)strlen (cfg_look_nick_prefix) +
(int)strlen (cfg_look_nick_suffix) > max_align - 4));
@@ -202,9 +150,10 @@ irc_display_nick (t_gui_buffer *buffer, t_irc_nick *nick, char *nickname,
/* display prefix */
if (display_around && !disable_prefix_suffix
&& cfg_look_nick_prefix && cfg_look_nick_prefix[0])
- gui_printf_type (buffer, type, "%s%s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- cfg_look_nick_prefix);
+ gui_chat_printf_type (buffer, type, NULL, -1,
+ "%s%s",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ cfg_look_nick_prefix);
/* display spaces before nick, if needed */
if (display_around
@@ -212,43 +161,43 @@ irc_display_nick (t_gui_buffer *buffer, t_irc_nick *nick, char *nickname,
&& (spaces > 0))
{
snprintf (format, 32, "%%-%ds", spaces);
- gui_printf_type (buffer, type, format, " ");
+ gui_chat_printf_type (buffer, type, NULL, -1, format, " ");
}
/* display nick mode */
if (nick && cfg_look_nickmode)
{
if (nick->flags & IRC_NICK_CHANOWNER)
- gui_printf_type (buffer, type, "%s~",
- GUI_COLOR(GUI_COLOR_WIN_NICK_OP));
+ gui_chat_printf_type (buffer, type, NULL, -1, "%s~",
+ GUI_COLOR(GUI_COLOR_NICKLIST_PREFIX1));
else if (nick->flags & IRC_NICK_CHANADMIN)
- gui_printf_type (buffer, type, "%s&",
- GUI_COLOR(GUI_COLOR_WIN_NICK_OP));
+ gui_chat_printf_type (buffer, type, NULL, -1, "%s&",
+ GUI_COLOR(GUI_COLOR_NICKLIST_PREFIX1));
else if (nick->flags & IRC_NICK_CHANADMIN2)
- gui_printf_type (buffer, type, "%s!",
- GUI_COLOR(GUI_COLOR_WIN_NICK_OP));
+ gui_chat_printf_type (buffer, type, NULL, -1, "%s!",
+ GUI_COLOR(GUI_COLOR_NICKLIST_PREFIX1));
else if (nick->flags & IRC_NICK_OP)
- gui_printf_type (buffer, type, "%s@",
- GUI_COLOR(GUI_COLOR_WIN_NICK_OP));
+ gui_chat_printf_type (buffer, type, NULL, -1, "%s@",
+ GUI_COLOR(GUI_COLOR_NICKLIST_PREFIX1));
else if (nick->flags & IRC_NICK_HALFOP)
- gui_printf_type (buffer, type, "%s%%",
- GUI_COLOR(GUI_COLOR_WIN_NICK_HALFOP));
+ gui_chat_printf_type (buffer, type, NULL, -1, "%s%%",
+ GUI_COLOR(GUI_COLOR_NICKLIST_PREFIX2));
else if (nick->flags & IRC_NICK_VOICE)
- gui_printf_type (buffer, type, "%s+",
- GUI_COLOR(GUI_COLOR_WIN_NICK_VOICE));
+ gui_chat_printf_type (buffer, type, NULL, -1, "%s+",
+ GUI_COLOR(GUI_COLOR_NICKLIST_PREFIX3));
else if (nick->flags & IRC_NICK_CHANUSER)
- gui_printf_type (buffer, type, "%s-",
- GUI_COLOR(GUI_COLOR_WIN_NICK_CHANUSER));
+ gui_chat_printf_type (buffer, type, NULL, -1, "%s-",
+ GUI_COLOR(GUI_COLOR_NICKLIST_PREFIX4));
else if (cfg_look_nickmode_empty && !no_nickmode)
- gui_printf_type (buffer, type, "%s ",
- GUI_COLOR(GUI_COLOR_WIN_CHAT));
+ gui_chat_printf_type (buffer, type, NULL, -1, "%s ",
+ GUI_COLOR(GUI_COLOR_CHAT));
}
/* display nick */
if (external_nick)
- gui_printf_type (buffer, type, "%s%s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- "(");
+ gui_chat_printf_type (buffer, type, NULL, -1, "%s%s",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ "(");
if (display_around && (spaces < 0))
{
i = nickname_length + spaces - 1;
@@ -262,26 +211,26 @@ irc_display_nick (t_gui_buffer *buffer, t_irc_nick *nick, char *nickname,
ptr_nickname[i] = '\0';
}
if (display_around)
- gui_printf_type_nick (buffer, type,
- (nick) ? nick->nick : nickname,
+ gui_chat_printf_type_nick (buffer, type,
+ (nick) ? nick->nick : nickname,
+ NULL, -1,
+ "%s%s",
+ (force_color) ? force_color :
+ GUI_COLOR((nick) ?
+ nick->color : cfg_col_chat),
+ ptr_nickname);
+ else
+ gui_chat_printf_type (buffer, type, NULL, -1,
"%s%s",
- (force_color >= 0) ?
- GUI_COLOR(force_color) :
- GUI_COLOR((nick) ? nick->color : GUI_COLOR_WIN_CHAT),
+ (force_color) ? force_color :
+ GUI_COLOR((nick) ? nick->color : cfg_col_chat),
ptr_nickname);
- else
- gui_printf_type (buffer, type,
- "%s%s",
- (force_color >= 0) ?
- GUI_COLOR(force_color) :
- GUI_COLOR((nick) ? nick->color : GUI_COLOR_WIN_CHAT),
- ptr_nickname);
if (display_around && (spaces < 0))
- gui_printf_type (buffer, type, "%s+",
- GUI_COLOR(GUI_COLOR_WIN_NICK_MORE));
+ gui_chat_printf_type (buffer, type, NULL, -1, "%s+",
+ GUI_COLOR(GUI_COLOR_NICKLIST_MORE));
if (external_nick)
- gui_printf_type (buffer, type, "%s%s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
+ gui_chat_printf_type (buffer, type, NULL, -1, "%s%s",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
")");
/* display spaces after nick, if needed */
@@ -290,19 +239,19 @@ irc_display_nick (t_gui_buffer *buffer, t_irc_nick *nick, char *nickname,
&& (spaces > 0))
{
snprintf (format, 32, "%%-%ds", spaces);
- gui_printf_type (buffer, type, format, " ");
+ gui_chat_printf_type (buffer, type, NULL, -1, format, " ");
}
/* display suffix */
if (display_around && !disable_prefix_suffix
&& cfg_look_nick_suffix && cfg_look_nick_suffix[0])
- gui_printf_type (buffer, type, "%s%s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- cfg_look_nick_suffix);
+ gui_chat_printf_type (buffer, type, NULL, -1, "%s%s",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ cfg_look_nick_suffix);
- gui_printf_type (buffer, type, "%s%s",
- GUI_NO_COLOR,
- (display_around) ? " " : "");
+ gui_chat_printf_type (buffer, type, NULL, -1, "%s%s",
+ GUI_NO_COLOR,
+ (display_around) ? " " : "");
free (ptr_nickname);
}
@@ -324,18 +273,20 @@ irc_display_away (t_irc_server *server, char *string1, char *string2)
if (cfg_look_align_other)
{
snprintf (format, 32, "%%-%ds", cfg_look_align_size + 1);
- gui_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_NICK,
- format, " ");
+ gui_chat_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_NICK,
+ NULL, -1,
+ format, " ");
}
- gui_printf_nolog (ptr_channel->buffer,
- "%s[%s%s%s %s: %s%s]\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- server->nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- string1,
- string2,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
+ gui_chat_printf_nolog (ptr_channel->buffer,
+ NULL, -1,
+ "%s[%s%s%s %s: %s%s]\n",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ server->nick,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ string1,
+ string2,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
}
}
}
@@ -345,34 +296,34 @@ irc_display_away (t_irc_server *server, char *string1, char *string2)
*/
void
-irc_display_mode (t_irc_server *server, t_gui_buffer *buffer,
+irc_display_mode (t_gui_buffer *buffer,
char *channel_name, char *nick_name, char set_flag,
char *symbol, char *nick_host, char *message, char *param)
{
- irc_display_prefix (server, buffer, GUI_PREFIX_INFO);
- gui_printf (buffer, "%s[%s%s%s/%s%c%s%s] %s%s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- (channel_name) ?
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL) :
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- (channel_name) ? channel_name : nick_name,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- set_flag,
- symbol,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick_host);
+ gui_chat_printf_info (buffer,
+ "%s[%s%s%s/%s%c%s%s] %s%s",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ (channel_name) ?
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL) :
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ (channel_name) ? channel_name : nick_name,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ set_flag,
+ symbol,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick_host);
if (param)
- gui_printf (buffer, " %s%s %s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- message,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- param);
+ gui_chat_printf (buffer, " %s%s %s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ message,
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ param);
else
- gui_printf (buffer, " %s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- message);
+ gui_chat_printf (buffer, " %s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ message);
}
/*
@@ -387,101 +338,104 @@ irc_display_server (t_irc_server *server, int with_detail)
if (with_detail)
{
- gui_printf (NULL, "\n");
- gui_printf (NULL, _("%sServer: %s%s %s[%s%s%s]\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER),
- server->name,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (server->is_connected) ?
- _("connected") : _("not connected"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
+ gui_chat_printf (NULL, "\n");
+ gui_chat_printf (NULL, _("%sServer: %s%s %s[%s%s%s]\n"),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_SERVER),
+ server->name,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (server->is_connected) ?
+ _("connected") : _("not connected"),
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
- gui_printf (NULL, " server_autoconnect . . . . : %s%s\n",
- (server->autoconnect) ? _("on") : _("off"),
- (server->temp_server) ?
- _(" (temporary server, will not be saved)") : "");
- gui_printf (NULL, " server_autoreconnect . . . : %s\n",
- (server->autoreconnect) ? _("on") : _("off"));
- gui_printf (NULL, " server_autoreconnect_delay : %d %s\n",
- server->autoreconnect_delay,
- _("seconds"));
- gui_printf (NULL, " server_address . . . . . . : %s\n",
- server->address);
- gui_printf (NULL, " server_port . . . . . . . : %d\n",
- server->port);
- gui_printf (NULL, " server_ipv6 . . . . . . . : %s\n",
- (server->ipv6) ? _("on") : _("off"));
- gui_printf (NULL, " server_ssl . . . . . . . . : %s\n",
- (server->ssl) ? _("on") : _("off"));
- gui_printf (NULL, " server_password . . . . . : %s\n",
- (server->password && server->password[0]) ?
- _("(hidden)") : "");
- gui_printf (NULL, " server_nick1/2/3 . . . . . : %s %s/ %s%s %s/ %s%s\n",
- server->nick1,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- server->nick2,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- server->nick3);
- gui_printf (NULL, " server_username . . . . . : %s\n",
- server->username);
- gui_printf (NULL, " server_realname . . . . . : %s\n",
- server->realname);
- gui_printf (NULL, " server_hostname . . . . . : %s\n",
- (server->hostname) ? server->hostname : "");
+ gui_chat_printf (NULL, " server_autoconnect . . . . : %s%s\n",
+ (server->autoconnect) ? _("on") : _("off"),
+ (server->temp_server) ?
+ _(" (temporary server, will not be saved)") : "");
+ gui_chat_printf (NULL, " server_autoreconnect . . . : %s\n",
+ (server->autoreconnect) ? _("on") : _("off"));
+ gui_chat_printf (NULL, " server_autoreconnect_delay : %d %s\n",
+ server->autoreconnect_delay,
+ _("seconds"));
+ gui_chat_printf (NULL, " server_address . . . . . . : %s\n",
+ server->address);
+ gui_chat_printf (NULL, " server_port . . . . . . . : %d\n",
+ server->port);
+ gui_chat_printf (NULL, " server_ipv6 . . . . . . . : %s\n",
+ (server->ipv6) ? _("on") : _("off"));
+ gui_chat_printf (NULL, " server_ssl . . . . . . . . : %s\n",
+ (server->ssl) ? _("on") : _("off"));
+ gui_chat_printf (NULL, " server_password . . . . . : %s\n",
+ (server->password && server->password[0]) ?
+ _("(hidden)") : "");
+ gui_chat_printf (NULL, " server_nick1/2/3 . . . . . : "
+ "%s %s/ %s%s %s/ %s%s\n",
+ server->nick1,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ server->nick2,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ server->nick3);
+ gui_chat_printf (NULL, " server_username . . . . . : %s\n",
+ server->username);
+ gui_chat_printf (NULL, " server_realname . . . . . : %s\n",
+ server->realname);
+ gui_chat_printf (NULL, " server_hostname . . . . . : %s\n",
+ (server->hostname) ? server->hostname : "");
if (server->command && server->command[0])
string = strdup (server->command);
else
string = NULL;
if (string)
{
- if (cfg_log_hide_nickserv_pwd)
+ if (irc_cfg_log_hide_nickserv_pwd)
irc_display_hide_password (string, 1);
- gui_printf (NULL, " server_command . . . . . . : %s\n",
- string);
+ gui_chat_printf (NULL, " server_command . . . . . . : %s\n",
+ string);
free (string);
}
else
- gui_printf (NULL, " server_command . . . . . . : %s\n",
- (server->command && server->command[0]) ?
- server->command : "");
- gui_printf (NULL, " server_command_delay . . . : %d %s\n",
- server->command_delay,
- _("seconds"));
- gui_printf (NULL, " server_autojoin . . . . . : %s\n",
- (server->autojoin && server->autojoin[0]) ?
- server->autojoin : "");
- gui_printf (NULL, " server_notify_levels . . . : %s\n",
- (server->notify_levels && server->notify_levels[0]) ?
- server->notify_levels : "");
+ gui_chat_printf (NULL, " server_command . . . . . . : %s\n",
+ (server->command && server->command[0]) ?
+ server->command : "");
+ gui_chat_printf (NULL, " server_command_delay . . . : %d %s\n",
+ server->command_delay,
+ _("seconds"));
+ gui_chat_printf (NULL, " server_autojoin . . . . . : %s\n",
+ (server->autojoin && server->autojoin[0]) ?
+ server->autojoin : "");
+ gui_chat_printf (NULL, " server_notify_levels . . . : %s\n",
+ (server->notify_levels && server->notify_levels[0]) ?
+ server->notify_levels : "");
}
else
{
- gui_printf (NULL, " %s %s%s ",
- (server->is_connected) ? "*" : " ",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER),
- server->name);
- gui_printf (NULL, "%s[%s%s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (server->is_connected) ?
- _("connected") : _("not connected"));
+ gui_chat_printf (NULL, " %s %s%s ",
+ (server->is_connected) ? "*" : " ",
+ GUI_COLOR(GUI_COLOR_CHAT_SERVER),
+ server->name);
+ gui_chat_printf (NULL, "%s[%s%s",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (server->is_connected) ?
+ _("connected") : _("not connected"));
if (server->is_connected)
{
num_channels = irc_server_get_channel_count (server);
num_pv = irc_server_get_pv_count (server);
- gui_printf (NULL, ", ");
- gui_printf (NULL, NG_("%d channel", "%d channels", num_channels),
- num_channels);
- gui_printf (NULL, ", ");
- gui_printf (NULL, _("%d pv"), num_pv);
+ gui_chat_printf (NULL, ", ");
+ gui_chat_printf (NULL,
+ NG_("%d channel", "%d channels",
+ num_channels),
+ num_channels);
+ gui_chat_printf (NULL, ", ");
+ gui_chat_printf (NULL, _("%d pv"), num_pv);
}
- gui_printf (NULL, "%s]%s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (server->temp_server) ? _(" (temporary)") : "");
+ gui_chat_printf (NULL, "%s]%s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (server->temp_server) ? _(" (temporary)") : "");
}
}
diff --git a/src/plugins/irc/irc-ignore.c b/src/plugins/irc/irc-ignore.c
deleted file mode 100644
index c7e8b509d..000000000
--- a/src/plugins/irc/irc-ignore.c
+++ /dev/null
@@ -1,440 +0,0 @@
-/*
- * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
- */
-
-/* irc-ignore.c: manages IRC ignore list */
-
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "../../common/weechat.h"
-#include "irc.h"
-#include "../../common/command.h"
-#include "../../common/log.h"
-#include "../../common/util.h"
-
-
-t_irc_ignore *irc_ignore = NULL;
-t_irc_ignore *last_irc_ignore = NULL;
-
-
-/*
- * irc_ignore_check_mask: return 1 is mask1 and mask2 are the same host
- * anyone or both strings may have user and/or host after
- */
-
-int
-irc_ignore_check_mask (char *mask1, char *mask2)
-{
- char *m1, *m2, *pos;
- int match;
-
- if (!mask1 || !mask1[0] || !mask2 || !mask2[0])
- return 0;
-
- m1 = strdup (mask1);
- m2 = strdup (mask2);
-
- pos = strchr (m1, '!');
- if (!pos)
- {
- /* remove '!' from m2 */
- pos = strchr (m2, '!');
- if (pos)
- pos[0] = '\0';
- }
- pos = strchr (m2, '!');
- if (!pos)
- {
- /* remove '!' from m1 */
- pos = strchr (m1, '!');
- if (pos)
- pos[0] = '\0';
- }
-
- /* TODO: use regexp to match both masks */
- match = ascii_strcasecmp (m1, m2);
-
- free (m1);
- free (m2);
-
- return (match == 0);
-}
-
-/*
- * irc_ignore_match: check if pointed ignore matches with arguments
- */
-
-int
-irc_ignore_match (t_irc_ignore *ptr_ignore, char *mask, char *type,
- char *channel_name, char *server_name)
-{
- /* check mask */
- if ((strcmp (mask, "*") != 0) && (strcmp (ptr_ignore->mask, "*") != 0)
- && (!irc_ignore_check_mask (ptr_ignore->mask, mask)))
- return 0;
-
- /* mask is matching, go on with type */
- if ((strcmp (type, "*") != 0) && (strcmp (ptr_ignore->type, "*") != 0)
- && (ascii_strcasecmp (ptr_ignore->type, type) != 0))
- return 0;
-
- /* mask and type matching, go on with server */
- if (server_name && server_name[0])
- {
- if ((strcmp (server_name, "*") != 0) && (strcmp (ptr_ignore->server_name, "*") != 0)
- && (ascii_strcasecmp (ptr_ignore->server_name, server_name) != 0))
- return 0;
- }
- else
- {
- if (strcmp (ptr_ignore->server_name, "*") != 0)
- return 0;
- }
-
- /* mask, type and server matching, go on with channel */
- if (channel_name && channel_name[0])
- {
- if ((strcmp (channel_name, "*") != 0) && (strcmp (ptr_ignore->channel_name, "*") != 0)
- && (ascii_strcasecmp (ptr_ignore->channel_name, channel_name) != 0))
- return 0;
- }
- else
- {
- if (strcmp (ptr_ignore->channel_name, "*") != 0)
- return 0;
- }
-
- /* all is matching => we find a ignore! */
- return 1;
-}
-
-/*
- * irc_ignore_check: check if an ignore is set for arguments
- * return 1 if at least one ignore exists (message should NOT be displayed)
- * 0 if no ignore found (message will be displayed)
- */
-
-int
-irc_ignore_check (char *mask, char *type, char *channel_name, char *server_name)
-{
- t_irc_ignore *ptr_ignore;
-
- if (!mask || !mask[0] || !type || !type[0])
- return 0;
-
- for (ptr_ignore = irc_ignore; ptr_ignore;
- ptr_ignore = ptr_ignore->next_ignore)
- {
- if (irc_ignore_match (ptr_ignore, mask, type, channel_name, server_name))
- return 1;
- }
-
- /* no ignore found */
- return 0;
-}
-
-/*
- * irc_ignore_search: search for an ignore
- */
-
-t_irc_ignore *
-irc_ignore_search (char *mask, char *type, char *channel_name, char *server_name)
-{
- t_irc_ignore *ptr_ignore;
-
- for (ptr_ignore = irc_ignore; ptr_ignore;
- ptr_ignore = ptr_ignore->next_ignore)
- {
- if ((ascii_strcasecmp (ptr_ignore->mask, mask) == 0)
- && (ascii_strcasecmp (ptr_ignore->type, type) == 0)
- && (ascii_strcasecmp (ptr_ignore->channel_name, channel_name) == 0)
- && (ascii_strcasecmp (ptr_ignore->server_name, server_name) == 0))
- return ptr_ignore;
- }
-
- /* ignore not found */
- return NULL;
-}
-
-/*
- * irc_ignore_add: add an ignore in list
- */
-
-t_irc_ignore *
-irc_ignore_add (char *mask, char *type, char *channel_name, char *server_name)
-{
- int type_index;
- t_irc_command *command_ptr;
- t_irc_ignore *new_ignore;
-
- if (!mask || !mask[0] || !type || !type[0] || !channel_name || !channel_name[0]
- || !server_name || !server_name[0])
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL,
- _("%s too few arguments for ignore\n"),
- WEECHAT_ERROR);
- return NULL;
- }
-
-#ifdef DEBUG
- weechat_log_printf ("Adding ignore: mask:'%s', type:'%s', channel:'%s', "
- "server:'%s'\n",
- mask, type, channel_name, server_name);
-#endif
-
- type_index = -1;
- command_ptr = NULL;
-
- if ((strcmp (mask, "*") == 0) && (strcmp (type, "*") == 0))
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL,
- _("%s mask or type/command should be non generic value for ignore\n"),
- WEECHAT_ERROR);
- return NULL;
- }
-
- if (irc_ignore_search (mask, type, channel_name, server_name))
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL,
- _("%s ignore already exists\n"),
- WEECHAT_ERROR);
- return NULL;
- }
-
- /* create new ignore */
- new_ignore = (t_irc_ignore *) malloc (sizeof (t_irc_ignore));
- if (new_ignore)
- {
- new_ignore->mask = strdup (mask);
- new_ignore->type = strdup (type);
- new_ignore->server_name = strdup (server_name);
- new_ignore->channel_name = strdup (channel_name);
-
- /* add new ignore to queue */
- new_ignore->prev_ignore = last_irc_ignore;
- new_ignore->next_ignore = NULL;
- if (irc_ignore)
- last_irc_ignore->next_ignore = new_ignore;
- else
- irc_ignore = new_ignore;
- last_irc_ignore = new_ignore;
- }
- else
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL,
- _("%s not enough memory to create ignore\n"),
- WEECHAT_ERROR);
- return NULL;
- }
-
- return new_ignore;
-}
-
-/*
- * irc_ignore_add_from_config: add an ignore to list, read from config file
- * (comma serparated values)
- */
-
-t_irc_ignore *
-irc_ignore_add_from_config (char *string)
-{
- t_irc_ignore *new_ignore;
- char *string2;
- char *pos_mask, *pos_type, *pos_channel, *pos_server;
-
- if (!string || !string[0])
- return NULL;
-
- new_ignore = NULL;
- string2 = strdup (string);
-
- pos_mask = string2;
- pos_type = strchr (pos_mask, ',');
- if (pos_type)
- {
- pos_type[0] = '\0';
- pos_type++;
- pos_channel = strchr (pos_type, ',');
- if (pos_channel)
- {
- pos_channel[0] = '\0';
- pos_channel++;
- pos_server = strchr (pos_channel, ',');
- if (pos_server)
- {
- pos_server[0] = '\0';
- pos_server++;
- new_ignore = irc_ignore_add (pos_mask, pos_type, pos_channel, pos_server);
- }
- }
- }
-
- free (string2);
- return new_ignore;
-}
-
-/*
- * irc_ignore_free: free an ignore
- */
-
-void
-irc_ignore_free (t_irc_ignore *ptr_ignore)
-{
- t_irc_ignore *new_irc_ignore;
-
- /* free data */
- if (ptr_ignore->mask)
- free (ptr_ignore->mask);
- if (ptr_ignore->type)
- free (ptr_ignore->type);
- if (ptr_ignore->channel_name)
- free (ptr_ignore->channel_name);
- if (ptr_ignore->server_name)
- free (ptr_ignore->server_name);
-
- /* remove ignore from queue */
- if (last_irc_ignore == ptr_ignore)
- last_irc_ignore = ptr_ignore->prev_ignore;
- if (ptr_ignore->prev_ignore)
- {
- (ptr_ignore->prev_ignore)->next_ignore = ptr_ignore->next_ignore;
- new_irc_ignore = irc_ignore;
- }
- else
- new_irc_ignore = ptr_ignore->next_ignore;
-
- if (ptr_ignore->next_ignore)
- (ptr_ignore->next_ignore)->prev_ignore = ptr_ignore->prev_ignore;
-
- free (ptr_ignore);
- irc_ignore = new_irc_ignore;
-}
-
-/*
- * irc_ignore_free_all: free all ignores
- */
-
-void
-irc_ignore_free_all ()
-{
- while (irc_ignore)
- irc_ignore_free (irc_ignore);
-}
-
-/*
- * irc_ignore_search_free: search and free ignore(s)
- * return: number of ignore found and deleted
- * 0 if no ignore found
- */
-
-int
-irc_ignore_search_free (char *mask, char *type,
- char *channel_name, char *server_name)
-{
- int found;
- t_irc_ignore *ptr_ignore, *next_ignore;
-
- found = 0;
- ptr_ignore = irc_ignore;
- while (ptr_ignore)
- {
- if (irc_ignore_match (ptr_ignore, mask, type, channel_name, server_name))
- {
- found++;
- if (found == 1)
- gui_printf (NULL, "\n");
- irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO);
- weechat_cmd_ignore_display (_("Removing ignore:"), ptr_ignore);
- next_ignore = ptr_ignore->next_ignore;
- irc_ignore_free (ptr_ignore);
- ptr_ignore = next_ignore;
- }
- else
- ptr_ignore = ptr_ignore->next_ignore;
- }
-
- return found;
-}
-
-/*
- * irc_ignore_search_free_by_number: search and free ignore(s) by number
- * return: 1 if ignore found and deleted
- * 0 if ignore not found
- */
-
-int
-irc_ignore_search_free_by_number (int number)
-{
- int i;
- t_irc_ignore *ptr_ignore;
-
- if (number < 1)
- return 0;
-
- i = 0;
- for (ptr_ignore = irc_ignore; ptr_ignore;
- ptr_ignore = ptr_ignore->next_ignore)
- {
- i++;
- if (i == number)
- {
- gui_printf (NULL, "\n");
- irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO);
- weechat_cmd_ignore_display (_("Removing ignore:"), ptr_ignore);
- irc_ignore_free (ptr_ignore);
- return 1;
- }
- }
-
- /* ignore number not found */
- return 0;
-}
-
-/*
- * irc_ignore_print_log: print ignore list in log (usually for crash dump)
- */
-
-void
-irc_ignore_print_log ()
-{
- t_irc_ignore *ptr_ignore;
-
- weechat_log_printf ("[ignore list]\n");
-
- for (ptr_ignore = irc_ignore; ptr_ignore;
- ptr_ignore = 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/plugins/irc/irc-input.c b/src/plugins/irc/irc-input.c
new file mode 100644
index 000000000..dc8b71922
--- /dev/null
+++ b/src/plugins/irc/irc-input.c
@@ -0,0 +1,200 @@
+/*
+ * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/* irc-input.c: IRC input data (read from user) */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "../../core/weechat.h"
+#include "irc.h"
+#include "../../core/utf8.h"
+#include "../../core/weechat-config.h"
+#include "../../gui/gui.h"
+
+
+/*
+ * irc_input_user_message_display: display user message
+ */
+
+void
+irc_input_user_message_display (t_gui_window *window, char *text)
+{
+ t_irc_nick *ptr_nick;
+
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+
+ if ((ptr_channel->type == IRC_CHANNEL_TYPE_PRIVATE)
+ || (ptr_channel->type == IRC_CHANNEL_TYPE_DCC_CHAT))
+ {
+ irc_display_nick (window->buffer, NULL, ptr_server->nick,
+ GUI_MSG_TYPE_NICK, 1,
+ GUI_COLOR(GUI_COLOR_CHAT_NICK_SELF), 0);
+ gui_chat_printf_type (window->buffer,
+ GUI_MSG_TYPE_MSG,
+ NULL, -1,
+ "%s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ text);
+ }
+ else
+ {
+ ptr_nick = irc_nick_search (ptr_channel, ptr_server->nick);
+ if (ptr_nick)
+ {
+ irc_display_nick (window->buffer, ptr_nick, NULL,
+ GUI_MSG_TYPE_NICK, 1, NULL, 0);
+ gui_chat_printf_type (window->buffer,
+ GUI_MSG_TYPE_MSG,
+ NULL, -1,
+ "%s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ text);
+ }
+ else
+ {
+ gui_chat_printf_error (ptr_server->buffer,
+ _("%s cannot find nick for sending "
+ "message\n"),
+ WEECHAT_ERROR);
+ }
+ }
+}
+
+/*
+ * irc_input_send_user_message: send a PRIVMSG message, and split it
+ * if > 512 bytes
+ */
+
+void
+irc_input_send_user_message (t_gui_window *window, char *text)
+{
+ int max_length;
+ char *pos, *pos_next, *pos_max, *next, saved_char, *last_space;
+
+ IRC_BUFFER_GET_SERVER_CHANNEL(window->buffer);
+
+ if (!ptr_server || !ptr_channel || !text || !text[0])
+ return;
+
+ if (!ptr_server->is_connected)
+ {
+ gui_chat_printf_error (window->buffer,
+ _("%s you are not connected to server\n"),
+ WEECHAT_ERROR);
+ return;
+ }
+
+ next = NULL;
+ last_space = NULL;
+ saved_char = '\0';
+
+ max_length = 512 - 16 - 65 - 10 - strlen (ptr_server->nick) -
+ strlen (ptr_channel->name);
+
+ if (max_length > 0)
+ {
+ if ((int)strlen (text) > max_length)
+ {
+ pos = text;
+ pos_max = text + max_length;
+ while (pos && pos[0])
+ {
+ if (pos[0] == ' ')
+ last_space = pos;
+ pos_next = utf8_next_char (pos);
+ if (pos_next > pos_max)
+ break;
+ pos = pos_next;
+ }
+ if (last_space && (last_space < pos))
+ pos = last_space + 1;
+ saved_char = pos[0];
+ pos[0] = '\0';
+ next = pos;
+ }
+ }
+
+ irc_server_sendf_queued (ptr_server, "PRIVMSG %s :%s",
+ ptr_channel->name, text);
+ irc_input_user_message_display (window, text);
+
+ if (next)
+ {
+ next[0] = saved_char;
+ irc_input_send_user_message (window, next);
+ }
+}
+
+/*
+ * irc_input_data: read data from user input
+ * Return: PROTOCOL_RC_OK if ok
+ * PROTOCOL_RC_KO if error
+ */
+
+int
+irc_input_data (t_gui_window *window, char *data)
+{
+ char *data_with_colors;
+
+ IRC_BUFFER_GET_CHANNEL(window->buffer);
+
+ if (ptr_channel)
+ {
+ data_with_colors = (char *)irc_color_encode ((unsigned char *)data,
+ irc_cfg_irc_colors_send);
+
+ if (ptr_channel->dcc_chat)
+ {
+ if (((t_irc_dcc *)(ptr_channel->dcc_chat))->sock < 0)
+ {
+ gui_chat_printf_error_nolog (window->buffer,
+ "%s DCC CHAT is closed\n",
+ WEECHAT_ERROR);
+ }
+ else
+ {
+ irc_dcc_chat_sendf ((t_irc_dcc *)(ptr_channel->dcc_chat),
+ "%s\r\n",
+ (data_with_colors) ? data_with_colors : data);
+ irc_input_user_message_display (window,
+ (data_with_colors) ?
+ data_with_colors : data);
+ }
+ }
+ else
+ irc_input_send_user_message (window,
+ (data_with_colors) ? data_with_colors : data);
+
+ if (data_with_colors)
+ free (data_with_colors);
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (window->buffer,
+ _("This buffer is not a channel!\n"));
+ return PROTOCOL_RC_KO;
+ }
+
+ return PROTOCOL_RC_OK;
+}
diff --git a/src/plugins/irc/irc-log.c b/src/plugins/irc/irc-log.c
new file mode 100644
index 000000000..cca8a8ffa
--- /dev/null
+++ b/src/plugins/irc/irc-log.c
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/* irc-log.c: log IRC buffers to files */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "../../core/weechat.h"
+#include "irc.h"
+#include "../../core/log.h"
+#include "../../core/util.h"
+#include "../../core/weechat-config.h"
+
+
+/*
+ * irc_log_get_filename: get filename for an IRC buffer log file
+ * Note: result has to be free() after use
+ */
+
+char *
+irc_log_fet_filename (char *server_name, char *channel_name, int dcc_chat)
+{
+ int length;
+ char *log_path, *log_path2;
+ char *server_name2, *channel_name2;
+ char *log_filename;
+
+ if (!server_name)
+ return NULL;
+
+ log_path = weechat_strreplace (cfg_log_path, "~", getenv ("HOME"));
+ log_path2 = weechat_strreplace (log_path, "%h", weechat_home);
+
+ if (channel_name)
+ {
+ server_name2 = NULL;
+ channel_name2 = weechat_strreplace (channel_name, DIR_SEPARATOR, "_");
+ }
+ else
+ {
+ server_name2 = weechat_strreplace (server_name, DIR_SEPARATOR, "_");
+ channel_name2 = NULL;
+ }
+
+ if (!log_path || !log_path2 || (!channel_name && !server_name2)
+ || (channel_name && !channel_name2))
+ {
+ weechat_log_printf (_("Not enough memory to write log file \"%s\"\n"),
+ (log_path2) ? log_path2 : ((log_path) ? log_path : cfg_log_path));
+ if (log_path)
+ free (log_path);
+ if (log_path2)
+ free (log_path2);
+ if (server_name2)
+ free (server_name2);
+ if (channel_name2)
+ free (channel_name2);
+ return NULL;
+ }
+
+ length = strlen (log_path2) + 128;
+ if (channel_name2)
+ length += strlen (channel_name2);
+ else
+ length += strlen (server_name2);
+
+ log_filename = (char *) malloc (length);
+ if (!log_filename)
+ {
+ weechat_log_printf (_("Not enough memory to write log file \"%s\"\n"),
+ (log_path2) ? log_path2 : ((log_path) ? log_path : cfg_log_path));
+ free (log_path);
+ free (log_path2);
+ if (server_name2)
+ free (server_name2);
+ if (channel_name2)
+ free (channel_name2);
+ return NULL;
+ }
+
+ strcpy (log_filename, log_path2);
+
+ free (log_path);
+ free (log_path2);
+
+ if (log_filename[strlen (log_filename) - 1] != DIR_SEPARATOR_CHAR)
+ strcat (log_filename, DIR_SEPARATOR);
+
+ /* server buffer */
+ if (!channel_name2)
+ {
+ strcat (log_filename, server_name2);
+ strcat (log_filename, ".");
+ }
+
+ /* DCC chat buffer */
+ if (channel_name2 && dcc_chat)
+ {
+ strcat (log_filename, "dcc.");
+ }
+
+ /* channel buffer */
+ if (channel_name2)
+ {
+ strcat (log_filename, channel_name2);
+ strcat (log_filename, ".");
+ }
+
+ /* append WeeChat suffix */
+ strcat (log_filename, "weechatlog");
+
+ if (server_name2)
+ free (server_name2);
+ if (channel_name2)
+ free (channel_name2);
+
+ return log_filename;
+}
diff --git a/src/plugins/irc/irc-mode.c b/src/plugins/irc/irc-mode.c
index 766b91b5d..d7b430d04 100644
--- a/src/plugins/irc/irc-mode.c
+++ b/src/plugins/irc/irc-mode.c
@@ -26,9 +26,9 @@
#include <stdlib.h>
#include <string.h>
-#include "../../common/weechat.h"
+#include "../../core/weechat.h"
#include "irc.h"
-#include "../../common/util.h"
+#include "../../core/util.h"
#include "../../gui/gui.h"
@@ -41,6 +41,9 @@ irc_mode_channel_set_nick (t_irc_channel *channel, char *nick,
char set_flag, int flag)
{
t_irc_nick *ptr_nick;
+ t_gui_nick *ptr_gui_nick;
+ int sort_index, color_prefix;
+ char prefix;
if (nick)
{
@@ -48,8 +51,19 @@ irc_mode_channel_set_nick (t_irc_channel *channel, char *nick,
if (ptr_nick)
{
IRC_NICK_SET_FLAG(ptr_nick, (set_flag == '+'), flag);
- irc_nick_resort (channel, ptr_nick);
- gui_nicklist_draw (channel->buffer, 1, 1);
+ ptr_gui_nick = gui_nicklist_search (channel->buffer,
+ ptr_nick->nick);
+ if (ptr_gui_nick)
+ {
+ irc_nick_get_gui_infos (ptr_nick, &sort_index, &prefix,
+ &color_prefix);
+ gui_nicklist_update (channel->buffer, ptr_gui_nick, NULL,
+ sort_index,
+ ptr_gui_nick->color_nick,
+ prefix,
+ color_prefix);
+ gui_nicklist_draw (channel->buffer, 1, 1);
+ }
}
}
}
@@ -97,7 +111,7 @@ irc_mode_channel_set (t_irc_server *server, t_irc_channel *channel,
pos_args++;
while (pos_args[0] == ' ')
pos_args++;
- argv = explode_string (pos_args, " ", 0, &argc);
+ argv = weechat_explode_string (pos_args, " ", 0, &argc);
if (argc > 0)
current_arg = argc - 1;
}
@@ -198,7 +212,7 @@ irc_mode_channel_set (t_irc_server *server, t_irc_channel *channel,
}
if (argv)
- free_exploded_string (argv);
+ weechat_free_exploded_string (argv);
}
/*
@@ -309,7 +323,7 @@ irc_mode_nick_prefix_allowed (t_irc_server *server, char prefix)
{
str[0] = prefix;
str[1] = '\0';
- return (strpbrk (str, IRC_DEFAULT_PREFIXES_LIST)) ? 1 : 0;
+ return (strpbrk (str, IRC_NICK_DEFAULT_PREFIXES_LIST)) ? 1 : 0;
}
return (strchr (server->prefix, prefix) != NULL);
diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c
index 27e5378a8..2357c8833 100644
--- a/src/plugins/irc/irc-nick.c
+++ b/src/plugins/irc/irc-nick.c
@@ -27,12 +27,12 @@
#include <string.h>
#include <limits.h>
-#include "../../common/weechat.h"
+#include "../../core/weechat.h"
#include "irc.h"
-#include "../../common/log.h"
-#include "../../common/utf8.h"
-#include "../../common/util.h"
-#include "../../common/weeconfig.h"
+#include "../../core/log.h"
+#include "../../core/utf8.h"
+#include "../../core/util.h"
+#include "../../core/weechat-config.h"
/*
@@ -51,143 +51,66 @@ irc_nick_find_color (t_irc_nick *nick)
}
color = (color % cfg_look_color_nicks_number);
- return GUI_COLOR_WIN_NICK_1 + color;
+ return GUI_COLOR_CHAT_NICK1 + color;
}
/*
- * irc_nick_score_for_sort: return score for sorting nick, according to privileges
+ * irc_nick_get_gui_infos: get GUI infos for a nick (sort_index, prefix,
+ * prefix color)
*/
-int
-irc_nick_score_for_sort (t_irc_nick *nick)
+void
+irc_nick_get_gui_infos (t_irc_nick *nick,
+ int *sort_index, char *prefix, int *color_prefix)
{
if (nick->flags & IRC_NICK_CHANOWNER)
- return -128;
- if (nick->flags & IRC_NICK_CHANADMIN)
- return -64;
- if (nick->flags & IRC_NICK_CHANADMIN2)
- return -32;
- if (nick->flags & IRC_NICK_OP)
- return -16;
- if (nick->flags & IRC_NICK_HALFOP)
- return -8;
- if (nick->flags & IRC_NICK_VOICE)
- return -4;
- if (nick->flags & IRC_NICK_CHANUSER)
- return -2;
- return 0;
-}
-
-/*
- * irc_nick_compare: compare two nicks
- * return: -1 is nick1 < nick2
- * 0 if nick1 = nick2
- * +1 if nick1 > nick2
- * status sort: operator > voice > normal nick
- */
-
-int
-irc_nick_compare (t_irc_nick *nick1, t_irc_nick *nick2)
-{
- int score1, score2, comp;
-
- score1 = irc_nick_score_for_sort (nick1);
- score2 = irc_nick_score_for_sort (nick2);
-
- comp = ascii_strcasecmp (nick1->nick, nick2->nick);
- if (comp > 0)
- score1++;
- if (comp < 0)
- score2++;
-
- /* nick1 > nick2 */
- if (score1 > score2)
- return 1;
- /* nick1 < nick2 */
- if (score1 < score2)
- return -1;
- /* nick1 == nick2 */
- return 0;
-}
-
-/*
- * irc_nick_find_pos: find position for a nick (for sorting nick list)
- */
-
-t_irc_nick *
-irc_nick_find_pos (t_irc_channel *channel, t_irc_nick *nick)
-{
- t_irc_nick *ptr_nick;
-
- for (ptr_nick = channel->nicks; ptr_nick; ptr_nick = ptr_nick->next_nick)
{
- if (irc_nick_compare (nick, ptr_nick) < 0)
- return ptr_nick;
+ *sort_index = 1;
+ *prefix = '~';
+ *color_prefix = GUI_COLOR_NICKLIST_PREFIX1;
}
- return NULL;
-}
-
-/*
- * irc_nick_insert_sorted: insert nick into sorted list
- */
-
-void
-irc_nick_insert_sorted (t_irc_channel *channel, t_irc_nick *nick)
-{
- t_irc_nick *pos_nick;
-
- if (channel->nicks)
+ else if (nick->flags & IRC_NICK_CHANADMIN)
{
- pos_nick = irc_nick_find_pos (channel, nick);
-
- if (pos_nick)
- {
- /* insert nick into the list (before nick found) */
- nick->prev_nick = pos_nick->prev_nick;
- nick->next_nick = pos_nick;
- if (pos_nick->prev_nick)
- pos_nick->prev_nick->next_nick = nick;
- else
- channel->nicks = nick;
- pos_nick->prev_nick = nick;
- }
- else
- {
- /* add nick to the end */
- nick->prev_nick = channel->last_nick;
- nick->next_nick = NULL;
- channel->last_nick->next_nick = nick;
- channel->last_nick = nick;
- }
+ *sort_index = 2;
+ *prefix = '&';
+ *color_prefix = GUI_COLOR_NICKLIST_PREFIX1;
}
- else
+ else if (nick->flags & IRC_NICK_CHANADMIN2)
{
- nick->prev_nick = NULL;
- nick->next_nick = NULL;
- channel->nicks = nick;
- channel->last_nick = nick;
+ *sort_index = 3;
+ *prefix = '!';
+ *color_prefix = GUI_COLOR_NICKLIST_PREFIX1;
+ }
+ else if (nick->flags & IRC_NICK_OP)
+ {
+ *sort_index = 4;
+ *prefix = '@';
+ *color_prefix = GUI_COLOR_NICKLIST_PREFIX1;
+ }
+ else if (nick->flags & IRC_NICK_HALFOP)
+ {
+ *sort_index = 5;
+ *prefix = '%';
+ *color_prefix = GUI_COLOR_NICKLIST_PREFIX2;
+ }
+ else if (nick->flags & IRC_NICK_VOICE)
+ {
+ *sort_index = 6;
+ *prefix = '+';
+ *color_prefix = GUI_COLOR_NICKLIST_PREFIX3;
+ }
+ else if (nick->flags & IRC_NICK_CHANUSER)
+ {
+ *sort_index = 7;
+ *prefix = '-';
+ *color_prefix = GUI_COLOR_NICKLIST_PREFIX4;
}
-}
-
-/*
- * irc_nick_resort: resort nick in the list
- */
-
-void
-irc_nick_resort (t_irc_channel *channel, t_irc_nick *nick)
-{
- /* temporarly remove nick from list */
- if (nick == channel->nicks)
- channel->nicks = nick->next_nick;
else
- nick->prev_nick->next_nick = nick->next_nick;
- if (nick->next_nick)
- nick->next_nick->prev_nick = nick->prev_nick;
- if (nick == channel->last_nick)
- channel->last_nick = nick->prev_nick;
-
- /* insert again nick into sorted list */
- irc_nick_insert_sorted (channel, nick);
+ {
+ *sort_index = 8;
+ *prefix = ' ';
+ *color_prefix = GUI_COLOR_NICKLIST;
+ }
}
/*
@@ -200,6 +123,9 @@ irc_nick_new (t_irc_server *server, t_irc_channel *channel, char *nick_name,
int is_halfop, int has_voice, int is_chanuser)
{
t_irc_nick *new_nick;
+ t_gui_nick *ptr_gui_nick;
+ int sort_index, color_prefix;
+ char prefix;
/* nick already exists on this channel? */
if ((new_nick = irc_nick_search (channel, nick_name)))
@@ -212,7 +138,15 @@ irc_nick_new (t_irc_server *server, t_irc_channel *channel, char *nick_name,
IRC_NICK_SET_FLAG(new_nick, is_halfop, IRC_NICK_HALFOP);
IRC_NICK_SET_FLAG(new_nick, has_voice, IRC_NICK_VOICE);
IRC_NICK_SET_FLAG(new_nick, is_chanuser, IRC_NICK_CHANUSER);
- irc_nick_resort (channel, new_nick);
+ irc_nick_get_gui_infos (new_nick, &sort_index, &prefix, &color_prefix);
+ ptr_gui_nick = gui_nicklist_search (channel->buffer, new_nick->nick);
+ if (ptr_gui_nick)
+ gui_nicklist_update (channel->buffer, ptr_gui_nick, NULL,
+ sort_index,
+ ptr_gui_nick->color_nick,
+ prefix,
+ color_prefix);
+
return new_nick;
}
@@ -231,33 +165,56 @@ irc_nick_new (t_irc_server *server, t_irc_channel *channel, char *nick_name,
IRC_NICK_SET_FLAG(new_nick, is_halfop, IRC_NICK_HALFOP);
IRC_NICK_SET_FLAG(new_nick, has_voice, IRC_NICK_VOICE);
IRC_NICK_SET_FLAG(new_nick, is_chanuser, IRC_NICK_CHANUSER);
- if (ascii_strcasecmp (new_nick->nick, server->nick) == 0)
- new_nick->color = GUI_COLOR_WIN_NICK_SELF;
+ if (weechat_strcasecmp (new_nick->nick, server->nick) == 0)
+ new_nick->color = GUI_COLOR_CHAT_NICK_SELF;
else
new_nick->color = irc_nick_find_color (new_nick);
-
- irc_nick_insert_sorted (channel, new_nick);
+
+ /* add nick to end of list */
+ new_nick->prev_nick = channel->last_nick;
+ if (channel->nicks)
+ channel->last_nick->next_nick = new_nick;
+ else
+ channel->nicks = new_nick;
+ channel->last_nick = new_nick;
+ new_nick->next_nick = NULL;
channel->nicks_count++;
-
+
channel->nick_completion_reset = 1;
+ /* add nick to buffer nicklist */
+ irc_nick_get_gui_infos (new_nick, &sort_index, &prefix, &color_prefix);
+ gui_nicklist_add (channel->buffer, new_nick->nick, sort_index,
+ GUI_COLOR_NICKLIST, prefix, color_prefix);
+
/* all is ok, return address of new nick */
return new_nick;
}
/*
- * irc_nick_change: change nickname and move it if necessary (list is sorted)
+ * irc_nick_change: change nickname
*/
void
-irc_nick_change (t_irc_channel *channel, t_irc_nick *nick, char *new_nick)
+irc_nick_change (t_irc_server *server, t_irc_channel *channel,
+ t_irc_nick *nick, char *new_nick)
{
int nick_is_me;
t_weelist *ptr_weelist;
+ t_gui_nick *ptr_nick;
+
+ /* update buffer nick */
+ ptr_nick = gui_nicklist_search (channel->buffer, nick->nick);
+ if (ptr_nick)
+ gui_nicklist_update (channel->buffer, ptr_nick, new_nick,
+ ptr_nick->sort_index,
+ ptr_nick->color_nick,
+ ptr_nick->prefix,
+ ptr_nick->color_prefix);
+
+ nick_is_me = (strcmp (nick->nick, server->nick) == 0) ? 1 : 0;
- nick_is_me = (strcmp (nick->nick, GUI_SERVER(channel->buffer)->nick) == 0) ? 1 : 0;
-
if (!nick_is_me && channel->nicks_speaking)
{
ptr_weelist = weelist_search (channel->nicks_speaking, nick->nick);
@@ -273,16 +230,13 @@ irc_nick_change (t_irc_channel *channel, t_irc_nick *nick, char *new_nick)
free (nick->nick);
nick->nick = strdup (new_nick);
if (nick_is_me)
- nick->color = GUI_COLOR_WIN_NICK_SELF;
+ nick->color = GUI_COLOR_CHAT_NICK_SELF;
else
nick->color = irc_nick_find_color (nick);
-
- /* insert again nick into sorted list */
- irc_nick_resort (channel, nick);
}
/*
- * irc_nick_free: free a nick and remove it from nicks queue
+ * irc_nick_free: free a nick and remove it from nicks list
*/
void
@@ -293,7 +247,10 @@ irc_nick_free (t_irc_channel *channel, t_irc_nick *nick)
if (!channel || !nick)
return;
- /* remove nick from queue */
+ /* remove nick from buffer nicklist */
+ (void) gui_nicklist_remove (channel->buffer, nick->nick);
+
+ /* remove nick from nicks list */
if (channel->last_nick == nick)
channel->last_nick = nick->prev_nick;
if (nick->prev_nick)
@@ -316,7 +273,7 @@ irc_nick_free (t_irc_channel *channel, t_irc_nick *nick)
free (nick->host);
free (nick);
channel->nicks = new_nicks;
-
+
channel->nick_completion_reset = 1;
}
@@ -353,7 +310,7 @@ irc_nick_search (t_irc_channel *channel, char *nickname)
for (ptr_nick = channel->nicks; ptr_nick;
ptr_nick = ptr_nick->next_nick)
{
- if (ascii_strcasecmp (ptr_nick->nick, nickname) == 0)
+ if (weechat_strcasecmp (ptr_nick->nick, nickname) == 0)
return ptr_nick;
}
return NULL;
@@ -399,40 +356,30 @@ irc_nick_count (t_irc_channel *channel, int *total, int *count_op,
}
/*
- * irc_nick_get_max_length: returns longer nickname on a channel
- */
-
-int
-irc_nick_get_max_length (t_irc_channel *channel)
-{
- int length, max_length;
- t_irc_nick *ptr_nick;
-
- max_length = 0;
- for (ptr_nick = channel->nicks; ptr_nick; ptr_nick = ptr_nick->next_nick)
- {
- length = utf8_width_screen (ptr_nick->nick);
- if (length > max_length)
- max_length = length;
- }
- return max_length;
-}
-
-/*
* irc_nick_set_away: set/unset away status for a channel
*/
void
irc_nick_set_away (t_irc_channel *channel, t_irc_nick *nick, int is_away)
{
- if ((cfg_irc_away_check > 0)
- && ((cfg_irc_away_check_max_nicks == 0) ||
- (channel->nicks_count <= cfg_irc_away_check_max_nicks)))
+ t_gui_nick *ptr_nick;
+
+ if ((irc_cfg_irc_away_check > 0)
+ && ((irc_cfg_irc_away_check_max_nicks == 0) ||
+ (channel->nicks_count <= irc_cfg_irc_away_check_max_nicks)))
{
if (((is_away) && (!(nick->flags & IRC_NICK_AWAY))) ||
((!is_away) && (nick->flags & IRC_NICK_AWAY)))
{
IRC_NICK_SET_FLAG(nick, is_away, IRC_NICK_AWAY);
+ ptr_nick = gui_nicklist_search (channel->buffer, nick->nick);
+ if (ptr_nick)
+ gui_nicklist_update (channel->buffer, ptr_nick, NULL,
+ ptr_nick->sort_index,
+ (is_away) ? GUI_COLOR_NICKLIST_AWAY :
+ GUI_COLOR_NICKLIST,
+ ptr_nick->prefix,
+ ptr_nick->color_prefix);
gui_nicklist_draw (channel->buffer, 0, 0);
}
}
@@ -445,7 +392,7 @@ irc_nick_set_away (t_irc_channel *channel, t_irc_nick *nick, int is_away)
void
irc_nick_print_log (t_irc_nick *nick)
{
- weechat_log_printf ("=> nick %s (addr:0x%X)]\n", nick->nick, nick);
+ weechat_log_printf ("=> nick %s (addr:0x%X):\n", nick->nick, nick);
weechat_log_printf (" host . . . . . : %s\n", nick->host);
weechat_log_printf (" flags. . . . . : %d\n", nick->flags);
weechat_log_printf (" color. . . . . : %d\n", nick->color);
diff --git a/src/plugins/irc/irc-nick.h b/src/plugins/irc/irc-nick.h
new file mode 100644
index 000000000..a5cfee1c4
--- /dev/null
+++ b/src/plugins/irc/irc-nick.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __WEECHAT_IRC_NICK_H
+#define __WEECHAT_IRC_NICK_H 1
+
+#define IRC_NICK_DEFAULT_PREFIXES_LIST "@%+~&!-"
+
+#define IRC_NICK_CHANOWNER 1
+#define IRC_NICK_CHANADMIN 2
+#define IRC_NICK_OP 4
+#define IRC_NICK_HALFOP 8
+#define IRC_NICK_VOICE 16
+#define IRC_NICK_AWAY 32
+#define IRC_NICK_CHANADMIN2 64
+#define IRC_NICK_CHANUSER 128
+#define IRC_NICK_SET_FLAG(nick, set, flag) \
+ if (set) \
+ nick->flags |= flag; \
+ else \
+ nick->flags &= 0xFFFF - flag;
+
+typedef struct t_irc_nick t_irc_nick;
+
+struct t_irc_nick
+{
+ char *nick; /* nickname */
+ char *host; /* full hostname */
+ 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 */
+};
+
+#endif /* irc-nick.h */
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
new file mode 100644
index 000000000..da50e4bb3
--- /dev/null
+++ b/src/plugins/irc/irc-protocol.c
@@ -0,0 +1,5274 @@
+/*
+ * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/* irc-protocol.c: description of IRC commands, according to
+ RFC 1459,2810,2811,2812 */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <wctype.h>
+#include <sys/utsname.h>
+
+#include "../../core/weechat.h"
+#include "irc.h"
+#include "../../core/alias.h"
+#include "../../core/command.h"
+#include "../../core/utf8.h"
+#include "../../core/util.h"
+#include "../../core/weechat-config.h"
+
+
+t_irc_protocol_msg irc_protocol_messages[] =
+{ { "error", N_("error received from IRC server"), irc_protocol_cmd_error },
+ { "invite", N_("invite a nick on a channel"), irc_protocol_cmd_invite },
+ { "join", N_("join a channel"), irc_protocol_cmd_join },
+ { "kick", N_("forcibly remove a user from a channel"), irc_protocol_cmd_kick },
+ { "kill", N_("close client-server connection"), irc_protocol_cmd_kill },
+ { "mode", N_("change channel or user mode"), irc_protocol_cmd_mode },
+ { "nick", N_("change current nickname"), irc_protocol_cmd_nick },
+ { "notice", N_("send notice message to user"), irc_protocol_cmd_notice },
+ { "part", N_("leave a channel"), irc_protocol_cmd_part },
+ { "ping", N_("ping server"), irc_protocol_cmd_ping },
+ { "pong", N_("answer to a ping message"), irc_protocol_cmd_pong },
+ { "privmsg", N_("message received"), irc_protocol_cmd_privmsg },
+ { "quit", N_("close all connections and quit"), irc_protocol_cmd_quit },
+ { "topic", N_("get/set channel topic"), irc_protocol_cmd_topic },
+ { "wallops", N_("send a message to all currently connected users who have "
+ "set the 'w' user mode for themselves"), irc_protocol_cmd_wallops },
+ { "001", N_("a server message"), irc_protocol_cmd_001 },
+ { "005", N_("a server message"), irc_protocol_cmd_005 },
+ { "221", N_("user mode string"), irc_protocol_cmd_221 },
+ { "301", N_("away message"), irc_protocol_cmd_301 },
+ { "302", N_("userhost"), irc_protocol_cmd_302 },
+ { "303", N_("ison"), irc_protocol_cmd_303 },
+ { "305", N_("unaway"), irc_protocol_cmd_305 },
+ { "306", N_("now away"), irc_protocol_cmd_306 },
+ { "307", N_("whois (registered nick)"), irc_protocol_cmd_whois_nick_msg },
+ { "310", N_("whois (help mode)"), irc_protocol_cmd_310 },
+ { "311", N_("whois (user)"), irc_protocol_cmd_311 },
+ { "312", N_("whois (server)"), irc_protocol_cmd_312 },
+ { "313", N_("whois (operator)"), irc_protocol_cmd_whois_nick_msg },
+ { "314", N_("whowas"), irc_protocol_cmd_314 },
+ { "315", N_("end of /who list"), irc_protocol_cmd_315 },
+ { "317", N_("whois (idle)"), irc_protocol_cmd_317 },
+ { "318", N_("whois (end)"), irc_protocol_cmd_whois_nick_msg },
+ { "319", N_("whois (channels)"), irc_protocol_cmd_319 },
+ { "320", N_("whois (identified user)"), irc_protocol_cmd_whois_nick_msg },
+ { "321", N_("/list start"), irc_protocol_cmd_321 },
+ { "322", N_("channel (for /list)"), irc_protocol_cmd_322 },
+ { "323", N_("/list end"), irc_protocol_cmd_323 },
+ { "324", N_("channel mode"), irc_protocol_cmd_324 },
+ { "326", N_("whois (has oper privs)"), irc_protocol_cmd_whois_nick_msg },
+ { "327", N_("whois (host)"), irc_protocol_cmd_327 },
+ { "329", N_("channel creation date"), irc_protocol_cmd_329 },
+ { "331", N_("no topic for channel"), irc_protocol_cmd_331 },
+ { "332", N_("topic of channel"), irc_protocol_cmd_332 },
+ { "333", N_("infos about topic (nick and date changed)"), irc_protocol_cmd_333 },
+ { "338", N_("whois (host)"), irc_protocol_cmd_338 },
+ { "341", N_("inviting"), irc_protocol_cmd_341 },
+ { "344", N_("channel reop"), irc_protocol_cmd_344 },
+ { "345", N_("end of channel reop list"), irc_protocol_cmd_345 },
+ { "348", N_("channel exception list"), irc_protocol_cmd_348 },
+ { "349", N_("end of channel exception list"), irc_protocol_cmd_349 },
+ { "351", N_("server version"), irc_protocol_cmd_351 },
+ { "352", N_("who"), irc_protocol_cmd_352 },
+ { "353", N_("list of nicks on channel"), irc_protocol_cmd_353 },
+ { "366", N_("end of /names list"), irc_protocol_cmd_366 },
+ { "367", N_("banlist"), irc_protocol_cmd_367 },
+ { "368", N_("end of banlist"), irc_protocol_cmd_368 },
+ { "378", N_("whois (connecting from)"), irc_protocol_cmd_whois_nick_msg },
+ { "379", N_("whois (using modes)"), irc_protocol_cmd_whois_nick_msg },
+ { "401", N_("no such nick/channel"), irc_protocol_cmd_error },
+ { "402", N_("no such server"), irc_protocol_cmd_error },
+ { "403", N_("no such channel"), irc_protocol_cmd_error },
+ { "404", N_("cannot send to channel"), irc_protocol_cmd_error },
+ { "405", N_("too many channels"), irc_protocol_cmd_error },
+ { "406", N_("was no such nick"), irc_protocol_cmd_error },
+ { "407", N_("was no such nick"), irc_protocol_cmd_error },
+ { "409", N_("no origin"), irc_protocol_cmd_error },
+ { "410", N_("no services"), irc_protocol_cmd_error },
+ { "411", N_("no recipient"), irc_protocol_cmd_error },
+ { "412", N_("no text to send"), irc_protocol_cmd_error },
+ { "413", N_("no toplevel"), irc_protocol_cmd_error },
+ { "414", N_("wilcard in toplevel domain"), irc_protocol_cmd_error },
+ { "421", N_("unknown command"), irc_protocol_cmd_error },
+ { "422", N_("MOTD is missing"), irc_protocol_cmd_error },
+ { "423", N_("no administrative info"), irc_protocol_cmd_error },
+ { "424", N_("file error"), irc_protocol_cmd_error },
+ { "431", N_("no nickname given"), irc_protocol_cmd_error },
+ { "432", N_("erroneous nickname"), irc_protocol_cmd_432 },
+ { "433", N_("nickname already in use"), irc_protocol_cmd_433 },
+ { "436", N_("nickname collision"), irc_protocol_cmd_error },
+ { "437", N_("resource unavailable"), irc_protocol_cmd_error },
+ { "438", N_("not authorized to change nickname"), irc_protocol_cmd_438 },
+ { "441", N_("user not in channel"), irc_protocol_cmd_error },
+ { "442", N_("not on channel"), irc_protocol_cmd_error },
+ { "443", N_("user already on channel"), irc_protocol_cmd_error },
+ { "444", N_("user not logged in"), irc_protocol_cmd_error },
+ { "445", N_("summon has been disabled"), irc_protocol_cmd_error },
+ { "446", N_("users has been disabled"), irc_protocol_cmd_error },
+ { "451", N_("you are not registered"), irc_protocol_cmd_error },
+ { "461", N_("not enough parameters"), irc_protocol_cmd_error },
+ { "462", N_("you may not register"), irc_protocol_cmd_error },
+ { "463", N_("your host isn't among the privileged"), irc_protocol_cmd_error },
+ { "464", N_("password incorrect"), irc_protocol_cmd_error },
+ { "465", N_("you are banned from this server"), irc_protocol_cmd_error },
+ { "467", N_("channel key already set"), irc_protocol_cmd_error },
+ { "470", N_("forwarding to another channel"), irc_protocol_cmd_error },
+ { "471", N_("channel is already full"), irc_protocol_cmd_error },
+ { "472", N_("unknown mode char to me"), irc_protocol_cmd_error },
+ { "473", N_("cannot join channel (invite only)"), irc_protocol_cmd_error },
+ { "474", N_("cannot join channel (banned from channel)"), irc_protocol_cmd_error },
+ { "475", N_("cannot join channel (bad channel key)"), irc_protocol_cmd_error },
+ { "476", N_("bad channel mask"), irc_protocol_cmd_error },
+ { "477", N_("channel doesn't support modes"), irc_protocol_cmd_error },
+ { "481", N_("you're not an IRC operator"), irc_protocol_cmd_error },
+ { "482", N_("you're not channel operator"), irc_protocol_cmd_error },
+ { "483", N_("you can't kill a server!"), irc_protocol_cmd_error },
+ { "484", N_("your connection is restricted!"), irc_protocol_cmd_error },
+ { "485", N_("user is immune from kick/deop"), irc_protocol_cmd_error },
+ { "487", N_("network split"), irc_protocol_cmd_error },
+ { "491", N_("no O-lines for your host"), irc_protocol_cmd_error },
+ { "501", N_("unknown mode flag"), irc_protocol_cmd_error },
+ { "502", N_("can't change mode for other users"), irc_protocol_cmd_error },
+ { "671", N_("whois (secure connection)"), irc_protocol_cmd_671 },
+ { "973", N_("whois (secure connection)"), irc_protocol_cmd_server_mode_reason },
+ { "974", N_("whois (secure connection)"), irc_protocol_cmd_server_mode_reason },
+ { "975", N_("whois (secure connection)"), irc_protocol_cmd_server_mode_reason },
+ { NULL, NULL, NULL }
+};
+
+
+char *irc_message = NULL;
+
+
+/*
+ * irc_protocol_is_word_char: return 1 if given character is a "word character"
+ */
+
+int
+irc_protocol_is_word_char (char *str)
+{
+ wint_t c = utf8_get_wide_char (str);
+
+ if (c == WEOF)
+ return 0;
+
+ if (iswalnum (c))
+ return 1;
+
+ switch (c)
+ {
+ case '-':
+ case '_':
+ case '|':
+ return 1;
+ }
+
+ /* not a 'word char' */
+ return 0;
+}
+
+/*
+ * irc_protocol_is_numeric_command: return 1 if given string is 100% numeric
+ */
+
+int
+irc_protocol_is_numeric_command (char *str)
+{
+ while (str && str[0])
+ {
+ if (!isdigit (str[0]))
+ return 0;
+ str++;
+ }
+ return 1;
+}
+
+/*
+ * irc_protocol_is_highlight: return 1 if given message contains highlight (with given nick
+ * or at least one of string in "irc_higlight" setting)
+ */
+
+int
+irc_protocol_is_highlight (char *message, char *nick)
+{
+ char *msg, *highlight, *match, *match_pre, *match_post, *msg_pos, *pos, *pos_end;
+ int end, length, startswith, endswith, wildcard_start, wildcard_end;
+
+ /* empty message ? */
+ if (!message || !message[0])
+ return 0;
+
+ /* highlight by nickname */
+ match = strstr (message, nick);
+ if (match)
+ {
+ match_pre = utf8_prev_char (message, match);
+ if (!match_pre)
+ match_pre = match - 1;
+ match_post = match + strlen(nick);
+ startswith = ((match == message) || (!irc_protocol_is_word_char (match_pre)));
+ endswith = ((!match_post[0]) || (!irc_protocol_is_word_char (match_post)));
+ if (startswith && endswith)
+ return 1;
+ }
+
+ /* no highlight by nickname and "irc_highlight" is empty */
+ if (!irc_cfg_irc_highlight || !irc_cfg_irc_highlight[0])
+ return 0;
+
+ /* convert both strings to lower case */
+ if ((msg = strdup (message)) == NULL)
+ return 0;
+ if ((highlight = strdup (irc_cfg_irc_highlight)) == NULL)
+ {
+ free (msg);
+ return 0;
+ }
+ pos = msg;
+ while (pos[0])
+ {
+ pos[0] = tolower (pos[0]);
+ pos++;
+ }
+ pos = highlight;
+ while (pos[0])
+ {
+ pos[0] = tolower (pos[0]);
+ pos++;
+ }
+
+ /* look in "irc_highlight" for highlight */
+ pos = highlight;
+ end = 0;
+ while (!end)
+ {
+ pos_end = strchr (pos, ',');
+ if (!pos_end)
+ {
+ pos_end = strchr (pos, '\0');
+ end = 1;
+ }
+ /* error parsing string! */
+ if (!pos_end)
+ {
+ free (msg);
+ free (highlight);
+ return 0;
+ }
+
+ length = pos_end - pos;
+ pos_end[0] = '\0';
+ if (length > 0)
+ {
+ if ((wildcard_start = (pos[0] == '*')))
+ {
+ pos++;
+ length--;
+ }
+ if ((wildcard_end = (*(pos_end - 1) == '*')))
+ {
+ *(pos_end - 1) = '\0';
+ length--;
+ }
+ }
+
+ if (length > 0)
+ {
+ msg_pos = msg;
+ /* highlight found! */
+ while ((match = strstr (msg_pos, pos)) != NULL)
+ {
+ match_pre = match - 1;
+ match_pre = utf8_prev_char (msg, match);
+ if (!match_pre)
+ match_pre = match - 1;
+ match_post = match + length;
+ startswith = ((match == msg) || (!irc_protocol_is_word_char (match_pre)));
+ endswith = ((!match_post[0]) || (!irc_protocol_is_word_char (match_post)));
+ if ((wildcard_start && wildcard_end) ||
+ (!wildcard_start && !wildcard_end &&
+ startswith && endswith) ||
+ (wildcard_start && endswith) ||
+ (wildcard_end && startswith))
+ {
+ free (msg);
+ free (highlight);
+ return 1;
+ }
+ msg_pos = match_post;
+ }
+ }
+
+ if (!end)
+ pos = pos_end + 1;
+ }
+
+ /* no highlight found with "irc_highlight" list */
+ free (msg);
+ free (highlight);
+ return 0;
+}
+
+/*
+ * irc_protocol_replace_vars: replace special IRC vars ($nick, $channel, $server) in a string
+ * Note: result has to be free() after use
+ */
+
+char *
+irc_protocol_replace_vars (t_irc_server *server, t_irc_channel *channel, char *string)
+{
+ char *var_nick, *var_channel, *var_server;
+ char empty_string[1] = { '\0' };
+ char *res, *temp;
+
+ var_nick = (server && server->nick) ? server->nick : empty_string;
+ var_channel = (channel) ? channel->name : empty_string;
+ var_server = (server) ? server->name : empty_string;
+
+ /* replace nick */
+ temp = weechat_strreplace (string, "$nick", var_nick);
+ if (!temp)
+ return NULL;
+ res = temp;
+
+ /* replace channel */
+ temp = weechat_strreplace (res, "$channel", var_channel);
+ free (res);
+ if (!temp)
+ return NULL;
+ res = temp;
+
+ /* replace server */
+ temp = weechat_strreplace (res, "$server", var_server);
+ free (res);
+ if (!temp)
+ return NULL;
+ res = temp;
+
+ /* return result */
+ return res;
+}
+
+/*
+ * irc_protocol_recv_command: executes action when receiving IRC command
+ * return: 0 = all ok, command executed
+ * -1 = command failed
+ * -2 = no command to execute
+ * -3 = command not found
+ */
+
+int
+irc_protocol_recv_command (t_irc_server *server, char *entire_line,
+ char *host, char *command, char *arguments)
+{
+ int i, cmd_found, return_code, ignore, highlight;
+ char *pos, *nick;
+ char *dup_entire_line, *dup_host, *dup_arguments, *irc_message;
+ t_irc_recv_func *cmd_recv_func;
+ char *cmd_name;
+
+ if (!command)
+ return -2;
+
+ /* look for IRC command */
+ cmd_found = -1;
+ for (i = 0; irc_protocol_messages[i].name; i++)
+ {
+ if (weechat_strcasecmp (irc_protocol_messages[i].name, command) == 0)
+ {
+ cmd_found = i;
+ break;
+ }
+ }
+
+ /* command not found */
+ if (cmd_found < 0)
+ {
+ /* for numeric commands, we use default recv function */
+ if (irc_protocol_is_numeric_command (command))
+ {
+ cmd_name = command;
+ cmd_recv_func = irc_protocol_cmd_server_msg;
+ }
+ else
+ return -3;
+ }
+ else
+ {
+ cmd_name = irc_protocol_messages[cmd_found].name;
+ cmd_recv_func = irc_protocol_messages[cmd_found].recv_function;
+ }
+
+ if (cmd_recv_func != NULL)
+ {
+ dup_entire_line = (entire_line) ? strdup (entire_line) : NULL;
+ dup_host = (host) ? strdup (host) : NULL;
+ dup_arguments = (arguments) ? strdup (arguments) : NULL;
+
+ ignore = 0;
+ highlight = 0;
+
+ return_code = plugin_msg_handler_exec (server->name,
+ cmd_name,
+ dup_entire_line);
+ /* plugin handler choosed to discard message for WeeChat,
+ so we ignore this message in standard handler */
+ if (return_code & PLUGIN_RC_OK_IGNORE_WEECHAT)
+ ignore = 1;
+ /* plugin asked for highlight ? */
+ if (return_code & PLUGIN_RC_OK_WITH_HIGHLIGHT)
+ highlight = 1;
+
+ pos = (dup_host) ? strchr (dup_host, '!') : NULL;
+ if (pos)
+ pos[0] = '\0';
+ nick = (dup_host) ? strdup (dup_host) : NULL;
+ if (pos)
+ pos[0] = '!';
+ irc_message = strdup (dup_entire_line);
+ return_code = (int) (cmd_recv_func) (server, irc_message,
+ dup_host, nick,
+ dup_arguments,
+ ignore, highlight);
+ if (irc_message)
+ free (irc_message);
+ if (nick)
+ free (nick);
+ if (dup_entire_line)
+ free (dup_entire_line);
+ if (dup_host)
+ free (dup_host);
+ if (dup_arguments)
+ free (dup_arguments);
+ return return_code;
+ }
+
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_error: error received from server
+ */
+
+int
+irc_protocol_cmd_error (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos;
+ int first;
+ t_gui_buffer *ptr_buffer;
+ t_irc_channel *ptr_channel;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) ignore;
+ (void) highlight;
+
+ first = 1;
+ ptr_buffer = server->buffer;
+
+ while (arguments && arguments[0])
+ {
+ while (arguments[0] == ' ')
+ arguments++;
+
+ if (arguments[0] == ':')
+ {
+ arguments++;
+ if (first)
+ gui_chat_printf_error (ptr_buffer,
+ "%s%s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (first) ? "" : ": ",
+ arguments);
+ else
+ gui_chat_printf (ptr_buffer,
+ "%s%s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (first) ? "" : ": ",
+ arguments);
+ if (strncmp (arguments, "Closing Link", 12) == 0)
+ irc_server_disconnect (server, 1);
+ arguments = NULL;
+ }
+ else
+ {
+ pos = strchr (arguments, ' ');
+ if (pos)
+ pos[0] = '\0';
+ if (strcasecmp (arguments, server->nick) != 0)
+ {
+ if (first)
+ {
+ ptr_channel = irc_channel_search (server, arguments);
+ if (ptr_channel)
+ ptr_buffer = ptr_channel->buffer;
+ gui_chat_printf_error (ptr_buffer,
+ "%s%s%s",
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ (first) ? "" : " ",
+ arguments);
+ }
+ else
+ gui_chat_printf (ptr_buffer,
+ "%s%s%s",
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ (first) ? "" : " ",
+ arguments);
+ first = 0;
+ }
+ if (pos)
+ arguments = pos + 1;
+ else
+ arguments = NULL;
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_invite: 'invite' message received
+ */
+
+int
+irc_protocol_cmd_invite (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_channel;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) highlight;
+
+ pos_channel = strchr (arguments, ' ');
+ if (pos_channel)
+ {
+ pos_channel[0] = '\0';
+ pos_channel++;
+ while (pos_channel[0] == ' ')
+ pos_channel++;
+ if (pos_channel[0] == ':')
+ pos_channel++;
+
+ if (!ignore)
+ {
+ gui_chat_printf_server (server->buffer,
+ _("You have been invited to %s%s%s by "
+ "%s%s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ pos_channel,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick);
+ if (gui_add_hotlist
+ && ((server->buffer->num_displayed == 0)
+ || (gui_buffer_is_scrolled (server->buffer))))
+ {
+ gui_hotlist_add (GUI_HOTLIST_HIGHLIGHT, NULL,
+ server->buffer, 0);
+ gui_status_draw (gui_current_window->buffer, 1);
+ }
+ }
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s channel \"%s\" not found for "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, "", "invite");
+ return -1;
+ }
+ return 0;
+}
+
+
+/*
+ * irc_protocol_cmd_join: 'join' message received
+ */
+
+int
+irc_protocol_cmd_join (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ t_irc_channel *ptr_channel;
+ t_irc_nick *ptr_nick;
+ char *pos;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) highlight;
+
+ /* no host => we can't identify sender of message! */
+ if (!host)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s \"%s\" command received without "
+ "host\n"),
+ WEECHAT_ERROR, "join");
+ return -1;
+ }
+
+ if (arguments[0] == ':')
+ arguments++;
+
+ ptr_channel = irc_channel_search (server, arguments);
+ if (!ptr_channel)
+ {
+ ptr_channel = irc_channel_new (server, IRC_CHANNEL_TYPE_CHANNEL,
+ arguments, 1);
+ if (!ptr_channel)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot create new channel "
+ "\"%s\"\n"),
+ WEECHAT_ERROR, arguments);
+ return -1;
+ }
+ }
+
+ pos = strchr (host, '!');
+ if (!ignore)
+ {
+ gui_chat_printf_join (ptr_channel->buffer,
+ _("%s%s %s(%s%s%s)%s has joined %s%s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ (pos) ? pos + 1 : host,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ arguments);
+ }
+
+ /* remove topic and display channel creation date if joining new channel */
+ if (!ptr_channel->nicks)
+ {
+ if (ptr_channel->topic)
+ {
+ free (ptr_channel->topic);
+ ptr_channel->topic = NULL;
+ gui_chat_draw_title (ptr_channel->buffer, 1);
+ }
+ ptr_channel->display_creation_date = 1;
+ }
+
+ /* add nick in channel */
+ ptr_nick = irc_nick_new (server, ptr_channel, nick, 0, 0, 0, 0, 0, 0, 0);
+ if (ptr_nick)
+ ptr_nick->host = strdup ((pos) ? pos + 1 : host);
+
+ /* redraw nicklist and status bar */
+ gui_nicklist_draw (ptr_channel->buffer, 1, 1);
+ gui_status_draw (ptr_channel->buffer, 1);
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_kick: 'kick' message received
+ */
+
+int
+irc_protocol_cmd_kick (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_nick, *pos_comment;
+ t_irc_channel *ptr_channel;
+ t_irc_nick *ptr_nick;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) highlight;
+
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ pos_nick[0] = '\0';
+ pos_nick++;
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+
+ pos_comment = strchr (pos_nick, ' ');
+ if (pos_comment)
+ {
+ pos_comment[0] = '\0';
+ pos_comment++;
+ while (pos_comment[0] == ' ')
+ pos_comment++;
+ if (pos_comment[0] == ':')
+ pos_comment++;
+ }
+
+ ptr_channel = irc_channel_search (server, arguments);
+ if (!ptr_channel)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s channel \"%s\" not found for "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, arguments, "kick");
+ return -1;
+ }
+
+ if (!ignore)
+ {
+ gui_chat_printf_quit (ptr_channel->buffer,
+ _("%s%s%s has kicked %s%s%s from %s%s"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_nick,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ arguments);
+ if (pos_comment)
+ gui_chat_printf (ptr_channel->buffer, " %s(%s%s%s)\n",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_comment,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
+ else
+ gui_chat_printf (ptr_channel->buffer, "\n");
+ }
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s nick \"%s\" not found for \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "", "kick");
+ return -1;
+ }
+ if (strcmp (pos_nick, server->nick) == 0)
+ {
+ /* my nick was kicked => free all nicks, channel is not active any more */
+ irc_nick_free_all (ptr_channel);
+ gui_nicklist_draw (ptr_channel->buffer, 1, 1);
+ gui_status_draw (ptr_channel->buffer, 1);
+ if (server->autorejoin)
+ irc_cmd_join_server (server, ptr_channel->name);
+ }
+ {
+ /* someone was kicked from channel (but not me) => remove only this nick */
+ ptr_nick = irc_nick_search (ptr_channel, pos_nick);
+ if (ptr_nick)
+ {
+ irc_nick_free (ptr_channel, ptr_nick);
+ gui_nicklist_draw (ptr_channel->buffer, 1, 1);
+ gui_status_draw (ptr_channel->buffer, 1);
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_kill: 'kill' message received
+ */
+
+int
+irc_protocol_cmd_kill (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_host2, *pos_comment;
+ t_irc_channel *ptr_channel;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) highlight;
+
+ pos_host2 = strchr (arguments, ' ');
+ if (pos_host2)
+ {
+ pos_host2[0] = '\0';
+ pos_host2++;
+ while (pos_host2[0] == ' ')
+ pos_host2++;
+
+ if (pos_host2[0] == ':')
+ pos_comment = pos_host2 + 1;
+ else
+ {
+ pos_comment = strchr (pos_host2, ' ');
+ if (pos_comment)
+ {
+ pos_comment[0] = '\0';
+ pos_comment++;
+ while (pos_comment[0] == ' ')
+ pos_comment++;
+ if (pos_comment[0] == ':')
+ pos_comment++;
+ }
+ }
+
+ for (ptr_channel = server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
+ {
+ if (!ignore)
+ {
+ gui_chat_printf_quit (ptr_channel->buffer,
+ _("%s%s%s has killed %s%s%s from "
+ "server"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ arguments,
+ GUI_COLOR(GUI_COLOR_CHAT));
+ if (pos_comment)
+ gui_chat_printf (ptr_channel->buffer, " %s(%s%s%s)\n",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_comment,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
+ else
+ gui_chat_printf (ptr_channel->buffer, "\n");
+ }
+ }
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s host not found for \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "kill");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_mode: 'mode' message received
+ */
+
+int
+irc_protocol_cmd_mode (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_modes, *pos;
+ t_irc_channel *ptr_channel;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) highlight;
+
+ /* no host => we can't identify sender of message! */
+ if (!host)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s \"%s\" command received without "
+ "host\n"),
+ WEECHAT_ERROR, "mode");
+ return -1;
+ }
+
+ pos_modes = strchr (arguments, ' ');
+ if (!pos_modes)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s \"%s\" command received without "
+ "channel or nickname\n"),
+ WEECHAT_ERROR, "mode");
+ return -1;
+ }
+ pos_modes[0] = '\0';
+ pos_modes++;
+ while (pos_modes[0] == ' ')
+ pos_modes++;
+ if (pos_modes[0] == ':')
+ pos_modes++;
+
+ /* remove spaces after modes */
+ pos = pos_modes + strlen (pos_modes) - 1;
+ while ((pos >= pos_modes) && (pos[0] == ' '))
+ {
+ pos[0] = '\0';
+ pos--;
+ }
+
+ if (irc_channel_is_channel (arguments))
+ {
+ ptr_channel = irc_channel_search (server, arguments);
+ if (ptr_channel)
+ {
+ if (!ignore)
+ {
+ gui_chat_printf_info (ptr_channel->buffer,
+ _("Mode %s%s %s[%s%s%s]%s by %s%s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ ptr_channel->name,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_modes,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick);
+ }
+ irc_mode_channel_set (server, ptr_channel, pos_modes);
+ irc_server_sendf (server, "MODE %s", ptr_channel->name);
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s channel \"%s\" not found for "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, arguments, "mode");
+ return -1;
+ }
+ }
+ else
+ {
+ if (!ignore)
+ {
+ gui_chat_printf_info (server->buffer,
+ _("User mode %s[%s%s%s]%s by %s%s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_modes,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick);
+ }
+ irc_mode_user_set (server, pos_modes);
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_nick: 'nick' message received
+ */
+
+int
+irc_protocol_cmd_nick (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ t_irc_channel *ptr_channel;
+ t_irc_nick *ptr_nick;
+ int nick_is_me;
+ t_gui_window *ptr_window;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) highlight;
+
+ /* no host => we can't identify sender of message! */
+ if (!host)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s \"%s\" command received without "
+ "host\n"),
+ WEECHAT_ERROR, "nick");
+ return -1;
+ }
+
+ if (arguments[0] == ':')
+ arguments++;
+
+ for (ptr_channel = server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
+ {
+ switch (ptr_channel->type)
+ {
+ case IRC_CHANNEL_TYPE_PRIVATE:
+ case IRC_CHANNEL_TYPE_DCC_CHAT:
+ /* rename private window if this is with "old nick" */
+ if (weechat_strcasecmp (ptr_channel->name, nick) == 0)
+ {
+ free (ptr_channel->name);
+ ptr_channel->name = strdup (arguments);
+ }
+ break;
+ case IRC_CHANNEL_TYPE_CHANNEL:
+ /* rename nick in nicklist if found */
+ ptr_nick = irc_nick_search (ptr_channel, nick);
+ if (ptr_nick)
+ {
+ nick_is_me = (strcmp (ptr_nick->nick, server->nick) == 0) ? 1 : 0;
+ if (nick_is_me)
+ gui_add_hotlist = 0;
+ irc_nick_change (server, ptr_channel, ptr_nick, arguments);
+ if (!ignore)
+ {
+ if (nick_is_me)
+ gui_chat_printf_info (ptr_channel->buffer,
+ _("You are now known as "
+ "%s%s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ arguments);
+ else
+ gui_chat_printf_info (ptr_channel->buffer,
+ _("%s%s%s is now known as "
+ "%s%s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ arguments);
+ }
+ gui_nicklist_draw (ptr_channel->buffer, 1, 1);
+ gui_add_hotlist = 1;
+ }
+ break;
+ }
+ }
+
+ if (strcmp (server->nick, nick) == 0)
+ {
+ free (server->nick);
+ server->nick = strdup (arguments);
+ gui_status_draw (gui_current_window->buffer, 1);
+ for (ptr_window = gui_windows; ptr_window;
+ ptr_window = ptr_window->next_window)
+ {
+ if ((ptr_window->buffer->protocol == irc_protocol)
+ && (IRC_BUFFER_SERVER(ptr_window->buffer) == server))
+ gui_input_draw (ptr_window->buffer, 1);
+ }
+ }
+ else
+ {
+ gui_status_draw (gui_current_window->buffer, 1);
+ gui_input_draw (gui_current_window->buffer, 1);
+ }
+
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_notice: 'notice' message received
+ */
+
+int
+irc_protocol_cmd_notice (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *host2, *pos, *pos2, *pos_usec;
+ struct timeval tv;
+ long sec1, usec1, sec2, usec2, difftime;
+ t_irc_channel *ptr_channel;
+ int highlight_displayed;
+
+ /* make C compiler happy */
+ (void) irc_message;
+
+ host2 = NULL;
+ if (host)
+ {
+ pos = strchr (host, '!');
+ if (pos)
+ host2 = pos + 1;
+ }
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ if (pos[0] == ':')
+ pos++;
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s nickname not found for \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "notice");
+ return -1;
+ }
+
+ if (!ignore)
+ {
+ if (strncmp (pos, "\01VERSION", 8) == 0)
+ {
+ pos += 9;
+ pos2 = strchr (pos, '\01');
+ if (pos2)
+ pos2[0] = '\0';
+ gui_chat_printf_server (server->buffer,
+ _("CTCP %sVERSION%s reply from %s%s%s: "
+ "%s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos);
+ }
+ else
+ {
+ if (strncmp (pos, "\01PING", 5) == 0)
+ {
+ pos += 5;
+ while (pos[0] == ' ')
+ pos++;
+ pos_usec = strchr (pos, ' ');
+ if (pos_usec)
+ {
+ pos_usec[0] = '\0';
+ pos_usec++;
+ pos2 = strchr (pos_usec, '\01');
+ if (pos2)
+ {
+ pos2[0] = '\0';
+
+ gettimeofday (&tv, NULL);
+ sec1 = atol (pos);
+ usec1 = atol (pos_usec);
+ sec2 = tv.tv_sec;
+ usec2 = tv.tv_usec;
+
+ difftime = ((sec2 * 1000000) + usec2) -
+ ((sec1 * 1000000) + usec1);
+
+ gui_chat_printf_server (server->buffer,
+ _("CTCP %sPING%s reply from "
+ "%s%s%s: %ld.%ld seconds\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ difftime / 1000000,
+ (difftime % 1000000) / 1000);
+ }
+ }
+ }
+ else
+ {
+ if (nick && nick[0] && irc_cfg_irc_notice_as_pv)
+ {
+ ptr_channel = irc_channel_search (server, nick);
+ if (!ptr_channel)
+ {
+ ptr_channel = irc_channel_new (server,
+ IRC_CHANNEL_TYPE_PRIVATE,
+ nick, 0);
+ if (!ptr_channel)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot create "
+ "new private "
+ "window \"%s\"\n"),
+ WEECHAT_ERROR, nick);
+ return -1;
+ }
+ }
+ if (!ptr_channel->topic)
+ {
+ ptr_channel->topic = strdup ((host2) ? host2 : "");
+ gui_chat_draw_title (ptr_channel->buffer, 1);
+ }
+
+ gui_chat_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_NICK,
+ NULL, -1, "%s<",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
+ if (highlight
+ || irc_protocol_is_highlight (pos, server->nick))
+ {
+ gui_chat_printf_type (ptr_channel->buffer,
+ GUI_MSG_TYPE_NICK |
+ GUI_MSG_TYPE_HIGHLIGHT,
+ NULL, -1, "%s%s",
+ GUI_COLOR(GUI_COLOR_CHAT_HIGHLIGHT),
+ nick);
+ if ( (cfg_look_infobar_delay_highlight > 0)
+ && (ptr_channel->buffer != gui_current_window->buffer) )
+ gui_infobar_printf (cfg_look_infobar_delay_highlight,
+ GUI_COLOR_INFOBAR_HIGHLIGHT,
+ _("Private %s> %s"),
+ nick, pos);
+ highlight_displayed = 1;
+ }
+ else
+ {
+ gui_chat_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_NICK,
+ NULL, -1, "%s%s",
+ GUI_COLOR(GUI_COLOR_CHAT_NICK_OTHER),
+ nick);
+ highlight_displayed = 0;
+ }
+ gui_chat_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_NICK,
+ NULL, -1, "%s> ",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
+ gui_chat_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_MSG,
+ NULL, -1, "%s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos);
+ if (highlight_displayed)
+ (void) plugin_msg_handler_exec (server->name,
+ "weechat_highlight",
+ irc_message);
+ }
+ else
+ {
+ if (host)
+ {
+ gui_chat_printf_server (server->buffer, "%s%s",
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick);
+ if (host2)
+ gui_chat_printf (server->buffer, " %s(%s%s%s)",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ host2,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
+ gui_chat_printf (server->buffer, "%s: ",
+ GUI_COLOR(GUI_COLOR_CHAT));
+ gui_chat_printf (server->buffer, "%s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos);
+ }
+ else
+ gui_chat_printf_server (server->buffer, "%s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos);
+
+ if ((nick)
+ && (weechat_strcasecmp (nick, "nickserv") != 0)
+ && (weechat_strcasecmp (nick, "chanserv") != 0)
+ && (weechat_strcasecmp (nick, "memoserv") != 0))
+ {
+ if (gui_add_hotlist
+ && ((server->buffer->num_displayed == 0)
+ || (gui_buffer_is_scrolled (server->buffer))))
+ {
+ gui_hotlist_add (GUI_HOTLIST_PRIVATE, NULL,
+ server->buffer, 0);
+ gui_status_draw (gui_current_window->buffer, 1);
+ }
+ }
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_part: 'part' message received
+ */
+
+int
+irc_protocol_cmd_part (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos, *pos_args, *join_string;
+ int join_length;
+ t_irc_channel *ptr_channel;
+ t_irc_nick *ptr_nick;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) highlight;
+
+ /* no host => we can't identify sender of message! */
+ if (!host || !arguments)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s \"%s\" command received without "
+ "host or channel\n"),
+ WEECHAT_ERROR, "part");
+ return -1;
+ }
+
+ if (arguments[0] == ':')
+ arguments++;
+
+ pos_args = strchr (arguments, ' ');
+ if (pos_args)
+ {
+ pos_args[0] = '\0';
+ pos_args++;
+ while (pos_args[0] == ' ')
+ pos_args++;
+ if (pos_args[0] == ':')
+ pos_args++;
+ }
+
+ ptr_channel = irc_channel_search (server, arguments);
+ if (ptr_channel)
+ {
+ ptr_nick = irc_nick_search (ptr_channel, nick);
+ if (ptr_nick)
+ {
+ /* display part message */
+ if (!ignore)
+ {
+ pos = strchr (host, '!');
+ gui_chat_printf_quit (ptr_channel->buffer,
+ _("%s%s %s(%s%s%s)%s has left %s%s"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ (pos) ? pos + 1 : "",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ ptr_channel->name);
+ if (pos_args && pos_args[0])
+ gui_chat_printf (ptr_channel->buffer, " %s(%s%s%s)\n",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_args,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
+ else
+ gui_chat_printf (ptr_channel->buffer, "\n");
+ }
+
+ /* part request was issued by local client ? */
+ if (strcmp (ptr_nick->nick, server->nick) == 0)
+ {
+ irc_nick_free_all (ptr_channel);
+
+ /* cycling ? => rejoin channel immediately */
+ if (ptr_channel->cycle)
+ {
+ ptr_channel->cycle = 0;
+ if (ptr_channel->key)
+ {
+ join_length = strlen (ptr_channel->name) + 1 +
+ strlen (ptr_channel->key) + 1;
+ join_string = (char *)malloc (join_length);
+ if (join_string)
+ {
+ snprintf (join_string, join_length, "%s %s",
+ ptr_channel->name,
+ ptr_channel->key);
+ irc_cmd_join_server (server, join_string);
+ free (join_string);
+ }
+ else
+ irc_cmd_join_server (server, ptr_channel->name);
+ }
+ else
+ irc_cmd_join_server (server, ptr_channel->name);
+ }
+ if (ptr_channel->close)
+ {
+ gui_buffer_free (ptr_channel->buffer, 1);
+ irc_channel_free (server, ptr_channel);
+ ptr_channel = NULL;
+ }
+ }
+ else
+ irc_nick_free (ptr_channel, ptr_nick);
+
+ if (ptr_channel)
+ {
+ gui_nicklist_draw (ptr_channel->buffer, 1, 1);
+ gui_status_draw (ptr_channel->buffer, 1);
+ }
+ gui_input_draw (gui_current_window->buffer, 1);
+ }
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s channel \"%s\" not found for "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, arguments, "part");
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_ping: 'ping' command received
+ */
+
+int
+irc_protocol_cmd_ping (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) ignore;
+ (void) highlight;
+
+ if (arguments[0] == ':')
+ arguments++;
+
+ pos = strrchr (arguments, ' ');
+ if (pos)
+ pos[0] = '\0';
+
+ irc_server_sendf (server, "PONG :%s", arguments);
+
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_pong: 'pong' command received
+ */
+
+int
+irc_protocol_cmd_pong (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ struct timeval tv;
+ int old_lag;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) arguments;
+ (void) ignore;
+ (void) highlight;
+
+ if (server->lag_check_time.tv_sec != 0)
+ {
+ /* calculate lag (time diff with lag check) */
+ old_lag = server->lag;
+ gettimeofday (&tv, NULL);
+ server->lag = (int) weechat_get_timeval_diff (&(server->lag_check_time), &tv);
+ if (old_lag != server->lag)
+ gui_status_draw (gui_current_window->buffer, 1);
+
+ /* schedule next lag check */
+ server->lag_check_time.tv_sec = 0;
+ server->lag_check_time.tv_usec = 0;
+ server->lag_next_check = time (NULL) + irc_cfg_irc_lag_check;
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_reply_version: send version in reply to "CTCP VERSION" request
+ */
+
+void
+irc_cmd_reply_version (t_irc_server *server, t_irc_channel *channel,
+ char *nick, char *message, int ignore)
+{
+ char *pos;
+ struct utsname *buf;
+ t_gui_buffer *ptr_buffer;
+
+ ptr_buffer = (channel) ? channel->buffer : server->buffer;
+
+ if (!ignore)
+ {
+ pos = strchr (message, ' ');
+ if (pos)
+ {
+ while (pos[0] == ' ')
+ pos++;
+ if (pos[0] == '\01')
+ pos = NULL;
+ else if (!pos[0])
+ pos = NULL;
+ }
+
+ buf = (struct utsname *) malloc (sizeof (struct utsname));
+ if (buf && (uname (buf) >= 0))
+ {
+ irc_server_sendf (server,
+ "NOTICE %s :%sVERSION %s v%s"
+ " compiled on %s, running "
+ "%s %s / %s%s",
+ nick, "\01", PACKAGE_NAME, PACKAGE_VERSION, __DATE__,
+ &buf->sysname,
+ &buf->release, &buf->machine, "\01");
+ free (buf);
+ }
+ else
+ irc_server_sendf (server,
+ "NOTICE %s :%sVERSION %s v%s"
+ " compiled on %s%s",
+ nick, "\01", PACKAGE_NAME, PACKAGE_VERSION, __DATE__,
+ "\01");
+ gui_chat_printf_server (ptr_buffer,
+ _("CTCP %sVERSION%s received from %s%s"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick);
+ if (pos)
+ gui_chat_printf (ptr_buffer, "%s: %s\n",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos);
+ else
+ gui_chat_printf (ptr_buffer, "\n");
+ (void) plugin_msg_handler_exec (server->name,
+ "weechat_ctcp",
+ irc_message);
+ }
+}
+
+/*
+ * irc_protocol_cmd_privmsg: 'privmsg' command received
+ */
+
+int
+irc_protocol_cmd_privmsg (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos, *pos2, *host2;
+ char *pos_file, *pos_addr, *pos_port, *pos_size, *pos_start_resume; /* for DCC */
+ t_irc_channel *ptr_channel;
+ t_irc_nick *ptr_nick;
+ int highlight_displayed;
+
+ /* make C compiler happy */
+ (void) irc_message;
+
+ /* no host => we can't identify sender of message! */
+ if (!host)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s \"%s\" command received without "
+ "host\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+
+ pos = strchr (host, '!');
+ if (pos)
+ host2 = pos + 1;
+ else
+ host2 = host;
+
+ /* receiver is a channel ? */
+ if (irc_channel_is_channel (arguments))
+ {
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ if (pos[0] == ':')
+ pos++;
+
+ ptr_channel = irc_channel_search (server, arguments);
+ if (ptr_channel)
+ {
+ if (strncmp (pos, "\01ACTION ", 8) == 0)
+ {
+ pos += 8;
+ pos2 = strchr (pos, '\01');
+ if (pos2)
+ pos2[0] = '\0';
+ if (!ignore)
+ {
+ if (highlight
+ || irc_protocol_is_highlight (pos, server->nick))
+ {
+ gui_chat_printf_type (ptr_channel->buffer,
+ GUI_MSG_TYPE_MSG |
+ GUI_MSG_TYPE_HIGHLIGHT,
+ cfg_look_prefix_action,
+ cfg_col_chat_prefix_action,
+ "%s%s",
+ GUI_COLOR(GUI_COLOR_CHAT_HIGHLIGHT),
+ nick);
+ if ( (cfg_look_infobar)
+ && (cfg_look_infobar_delay_highlight > 0)
+ && (ptr_channel->buffer != gui_current_window->buffer) )
+ gui_infobar_printf (cfg_look_infobar_delay_highlight,
+ GUI_COLOR_INFOBAR_HIGHLIGHT,
+ _("Channel %s: * %s %s"),
+ ptr_channel->name, nick, pos);
+ gui_chat_printf (ptr_channel->buffer, " %s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT), pos);
+ (void) plugin_msg_handler_exec (server->name,
+ "weechat_highlight",
+ irc_message);
+ }
+ else
+ {
+ gui_chat_printf_type (ptr_channel->buffer,
+ GUI_MSG_TYPE_MSG,
+ NULL, -1,
+ "%s%s",
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ cfg_look_prefix_action,
+ cfg_col_chat_prefix_action,
+ nick);
+ gui_chat_printf (ptr_channel->buffer, " %s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT), pos);
+ }
+ irc_channel_add_nick_speaking (ptr_channel, nick);
+ }
+ return 0;
+ }
+ if (strncmp (pos, "\01SOUND ", 7) == 0)
+ {
+ pos += 7;
+ pos2 = strchr (pos, '\01');
+ if (pos2)
+ pos2[0] = '\0';
+ if (!ignore)
+ {
+ gui_chat_printf_server (ptr_channel->buffer,
+ _("Received a CTCP %sSOUND%s "
+ "\"%s\" from %s%s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos,
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick);
+ }
+ return 0;
+ }
+ if (strncmp (pos, "\01PING", 5) == 0)
+ {
+ pos += 5;
+ while (pos[0] == ' ')
+ pos++;
+ pos2 = strchr (pos, '\01');
+ if (pos2)
+ pos2[0] = '\0';
+ else
+ pos = NULL;
+ if (pos && !pos[0])
+ pos = NULL;
+ if (pos)
+ irc_server_sendf (server, "NOTICE %s :\01PING %s\01",
+ nick, pos);
+ else
+ irc_server_sendf (server, "NOTICE %s :\01PING\01",
+ nick);
+ gui_chat_printf_server (ptr_channel->buffer,
+ _("CTCP %sPING%s received from "
+ "%s%s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick);
+ return 0;
+ }
+ if (strncmp (pos, "\01VERSION", 8) == 0)
+ {
+ irc_cmd_reply_version (server, ptr_channel, nick,
+ pos, ignore);
+ return 0;
+ }
+
+ /* unknown CTCP ? */
+ pos2 = strchr (pos + 1, '\01');
+ if ((pos[0] == '\01') && pos2 && (pos2[1] == '\0'))
+ {
+ pos++;
+ pos2[0] = '\0';
+ pos2 = strchr (pos, ' ');
+ if (pos2)
+ {
+ pos2[0] = '\0';
+ pos2++;
+ while (pos2[0] == ' ')
+ pos2++;
+ if (!pos2[0])
+ pos2 = NULL;
+ }
+ if (!ignore)
+ {
+ gui_chat_printf_server (ptr_channel->buffer,
+ _("Unknown CTCP %s%s%s "
+ "received from %s%s"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ pos,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick);
+ if (pos2)
+ gui_chat_printf (ptr_channel->buffer, "%s: %s\n",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos2);
+ else
+ gui_chat_printf (ptr_channel->buffer, "\n");
+ }
+ return 0;
+ }
+
+ /* other message */
+ if (!ignore)
+ {
+ ptr_nick = irc_nick_search (ptr_channel, nick);
+ if (highlight || irc_protocol_is_highlight (pos, server->nick))
+ {
+ irc_display_nick (ptr_channel->buffer, ptr_nick,
+ (ptr_nick) ? NULL : nick,
+ GUI_MSG_TYPE_NICK | GUI_MSG_TYPE_HIGHLIGHT,
+ 1, GUI_COLOR(GUI_COLOR_CHAT_HIGHLIGHT), 0);
+ if ( (cfg_look_infobar)
+ && (cfg_look_infobar_delay_highlight > 0)
+ && (ptr_channel->buffer != gui_current_window->buffer) )
+ gui_infobar_printf (cfg_look_infobar_delay_highlight,
+ GUI_COLOR_INFOBAR_HIGHLIGHT,
+ _("Channel %s: %s> %s"),
+ ptr_channel->name, nick, pos);
+ gui_chat_printf_type (ptr_channel->buffer,
+ GUI_MSG_TYPE_MSG,
+ NULL, -1,
+ "%s\n", pos);
+ (void) plugin_msg_handler_exec (server->name,
+ "weechat_highlight",
+ irc_message);
+ }
+ else
+ {
+ irc_display_nick (ptr_channel->buffer, ptr_nick,
+ (ptr_nick) ? NULL : nick,
+ GUI_MSG_TYPE_NICK, 1, NULL, 0);
+ gui_chat_printf_type (ptr_channel->buffer,
+ GUI_MSG_TYPE_MSG,
+ NULL, -1,
+ "%s\n", pos);
+ }
+ irc_channel_add_nick_speaking (ptr_channel, nick);
+ }
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s channel \"%s\" not found "
+ "for \"%s\" command\n"),
+ WEECHAT_ERROR, arguments,
+ "privmsg");
+ return -1;
+ }
+ }
+ }
+ else
+ {
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ if (pos[0] == ':')
+ pos++;
+
+ /* version asked by another user => answer with WeeChat version */
+ if (strncmp (pos, "\01VERSION", 8) == 0)
+ {
+ irc_cmd_reply_version (server, NULL, nick, pos, ignore);
+ return 0;
+ }
+
+ /* ping request from another user => answer */
+ if (strncmp (pos, "\01PING", 5) == 0)
+ {
+ if (!ignore)
+ {
+ pos += 5;
+ while (pos[0] == ' ')
+ pos++;
+ pos2 = strchr (pos, '\01');
+ if (pos2)
+ pos2[0] = '\0';
+ else
+ pos = NULL;
+ if (pos && !pos[0])
+ pos = NULL;
+ if (pos)
+ irc_server_sendf (server, "NOTICE %s :\01PING %s\01",
+ nick, pos);
+ else
+ irc_server_sendf (server, "NOTICE %s :\01PING\01",
+ nick);
+ gui_chat_printf_server (server->buffer,
+ _("CTCP %sPING%s received from "
+ "%s%s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick);
+ (void) plugin_msg_handler_exec (server->name,
+ "weechat_ctcp",
+ irc_message);
+ }
+ return 0;
+ }
+
+ /* incoming DCC file */
+ if (strncmp (pos, "\01DCC SEND", 9) == 0)
+ {
+ /* check if DCC SEND is ok, i.e. with 0x01 at end */
+ pos2 = strchr (pos + 1, '\01');
+ if (!pos2)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+ pos2[0] = '\0';
+
+ if (!ignore)
+ {
+ /* DCC filename */
+ pos_file = pos + 9;
+ while (pos_file[0] == ' ')
+ pos_file++;
+
+ /* look for file size */
+ pos_size = strrchr (pos_file, ' ');
+ if (!pos_size)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+ pos2 = pos_size;
+ pos_size++;
+ while (pos2[0] == ' ')
+ pos2--;
+ pos2[1] = '\0';
+
+ /* look for DCC port */
+ pos_port = strrchr (pos_file, ' ');
+ if (!pos_port)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+ pos2 = pos_port;
+ pos_port++;
+ while (pos2[0] == ' ')
+ pos2--;
+ pos2[1] = '\0';
+
+ /* look for DCC IP address */
+ pos_addr = strrchr (pos_file, ' ');
+ if (!pos_addr)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+ pos2 = pos_addr;
+ pos_addr++;
+ while (pos2[0] == ' ')
+ pos2--;
+ pos2[1] = '\0';
+
+ irc_dcc_add (server, IRC_DCC_FILE_RECV,
+ strtoul (pos_addr, NULL, 10),
+ atoi (pos_port), nick, -1, pos_file, NULL,
+ strtoul (pos_size, NULL, 10));
+ (void) plugin_msg_handler_exec (server->name,
+ "weechat_dcc",
+ irc_message);
+ }
+ return 0;
+ }
+
+ /* incoming DCC RESUME (asked by receiver) */
+ if (strncmp (pos, "\01DCC RESUME", 11) == 0)
+ {
+ /* check if DCC RESUME is ok, i.e. with 0x01 at end */
+ pos2 = strchr (pos + 1, '\01');
+ if (!pos2)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+ pos2[0] = '\0';
+
+ if (!ignore)
+ {
+ /* DCC filename */
+ pos_file = pos + 11;
+ while (pos_file[0] == ' ')
+ pos_file++;
+
+ /* look for resume start position */
+ pos_start_resume = strrchr (pos_file, ' ');
+ if (!pos_start_resume)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+ pos2 = pos_start_resume;
+ pos_start_resume++;
+ while (pos2[0] == ' ')
+ pos2--;
+ pos2[1] = '\0';
+
+ /* look for DCC port */
+ pos_port = strrchr (pos_file, ' ');
+ if (!pos_port)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+ pos2 = pos_port;
+ pos_port++;
+ while (pos2[0] == ' ')
+ pos2--;
+ pos2[1] = '\0';
+
+ irc_dcc_accept_resume (server, pos_file, atoi (pos_port),
+ strtoul (pos_start_resume, NULL, 10));
+ (void) plugin_msg_handler_exec (server->name,
+ "weechat_dcc",
+ irc_message);
+ }
+ return 0;
+ }
+
+ /* incoming DCC ACCEPT (resume accepted by sender) */
+ if (strncmp (pos, "\01DCC ACCEPT", 11) == 0)
+ {
+ /* check if DCC ACCEPT is ok, i.e. with 0x01 at end */
+ pos2 = strchr (pos + 1, '\01');
+ if (!pos2)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+ pos2[0] = '\0';
+
+ if (!ignore)
+ {
+ /* DCC filename */
+ pos_file = pos + 11;
+ while (pos_file[0] == ' ')
+ pos_file++;
+
+ /* look for resume start position */
+ pos_start_resume = strrchr (pos_file, ' ');
+ if (!pos_start_resume)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+ pos2 = pos_start_resume;
+ pos_start_resume++;
+ while (pos2[0] == ' ')
+ pos2--;
+ pos2[1] = '\0';
+
+ /* look for DCC port */
+ pos_port = strrchr (pos_file, ' ');
+ if (!pos_port)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+ pos2 = pos_port;
+ pos_port++;
+ while (pos2[0] == ' ')
+ pos2--;
+ pos2[1] = '\0';
+
+ irc_dcc_start_resume (server, pos_file, atoi (pos_port),
+ strtoul (pos_start_resume, NULL, 10));
+ (void) plugin_msg_handler_exec (server->name,
+ "weechat_dcc",
+ irc_message);
+ }
+ return 0;
+ }
+
+ /* incoming DCC CHAT */
+ if (strncmp (pos, "\01DCC CHAT", 9) == 0)
+ {
+ /* check if DCC CHAT is ok, i.e. with 0x01 at end */
+ pos2 = strchr (pos + 1, '\01');
+ if (!pos2)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+ pos2[0] = '\0';
+
+ if (!ignore)
+ {
+ /* CHAT type */
+ pos_file = pos + 9;
+ while (pos_file[0] == ' ')
+ pos_file++;
+
+ /* DCC IP address */
+ pos_addr = strchr (pos_file, ' ');
+ if (!pos_addr)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+ pos_addr[0] = '\0';
+ pos_addr++;
+ while (pos_addr[0] == ' ')
+ pos_addr++;
+
+ /* look for DCC port */
+ pos_port = strchr (pos_addr, ' ');
+ if (!pos_port)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+ pos_port[0] = '\0';
+ pos_port++;
+ while (pos_port[0] == ' ')
+ pos_port++;
+
+ if (weechat_strcasecmp (pos_file, "chat") != 0)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s unknown DCC CHAT "
+ "type received from "),
+ WEECHAT_ERROR);
+ gui_chat_printf (server->buffer, "%s%s%s: \"%s\"\n",
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_file);
+ return -1;
+ }
+
+ irc_dcc_add (server, IRC_DCC_CHAT_RECV,
+ strtoul (pos_addr, NULL, 10),
+ atoi (pos_port), nick, -1, NULL, NULL, 0);
+ (void) plugin_msg_handler_exec (server->name,
+ "weechat_dcc",
+ irc_message);
+ }
+ return 0;
+ }
+
+ /* private message received => display it */
+ ptr_channel = irc_channel_search (server, nick);
+
+ if (strncmp (pos, "\01ACTION ", 8) == 0)
+ {
+ if (!ignore)
+ {
+ if (!ptr_channel)
+ {
+ ptr_channel = irc_channel_new (server,
+ IRC_CHANNEL_TYPE_PRIVATE,
+ nick, 0);
+ if (!ptr_channel)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot create "
+ "new private "
+ "window \"%s\"\n"),
+ WEECHAT_ERROR, nick);
+ return -1;
+ }
+ }
+ if (!ptr_channel->topic)
+ {
+ ptr_channel->topic = strdup (host2);
+ gui_chat_draw_title (ptr_channel->buffer, 1);
+ }
+
+ pos += 8;
+ pos2 = strchr (pos, '\01');
+ if (pos2)
+ pos2[0] = '\0';
+ if (highlight || irc_protocol_is_highlight (pos, server->nick))
+ {
+ gui_chat_printf_type (ptr_channel->buffer,
+ GUI_MSG_TYPE_MSG |
+ GUI_MSG_TYPE_HIGHLIGHT,
+ cfg_look_prefix_action,
+ cfg_col_chat_prefix_action,
+ "%s%s",
+ GUI_COLOR(GUI_COLOR_CHAT_HIGHLIGHT),
+ nick);
+ if ( (cfg_look_infobar)
+ && (cfg_look_infobar_delay_highlight > 0)
+ && (ptr_channel->buffer != gui_current_window->buffer) )
+ gui_infobar_printf (cfg_look_infobar_delay_highlight,
+ GUI_COLOR_INFOBAR_HIGHLIGHT,
+ _("Channel %s: * %s %s"),
+ ptr_channel->name, nick, pos);
+ gui_chat_printf (ptr_channel->buffer, " %s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT), pos);
+ (void) plugin_msg_handler_exec (server->name,
+ "weechat_highlight",
+ irc_message);
+ }
+ else
+ {
+ gui_chat_printf_type (ptr_channel->buffer,
+ GUI_MSG_TYPE_MSG,
+ NULL, -1,
+ "%s%s",
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ cfg_look_prefix_action,
+ cfg_col_chat_prefix_action,
+ nick);
+ gui_chat_printf (ptr_channel->buffer, " %s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT), pos);
+ (void) plugin_msg_handler_exec (server->name,
+ "weechat_pv",
+ irc_message);
+ }
+ }
+ }
+ else
+ {
+ /* unknown CTCP ? */
+ pos2 = strchr (pos + 1, '\01');
+ if ((pos[0] == '\01') && pos2 && (pos2[1] == '\0'))
+ {
+ if (!ignore)
+ {
+ pos++;
+ pos2[0] = '\0';
+ pos2 = strchr (pos, ' ');
+ if (pos2)
+ {
+ pos2[0] = '\0';
+ pos2++;
+ while (pos2[0] == ' ')
+ pos2++;
+ if (!pos2[0])
+ pos2 = NULL;
+ }
+ gui_chat_printf_server (server->buffer,
+ _("Unknown CTCP %s%s%s "
+ "received from %s%s"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ pos,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick);
+ if (pos2)
+ gui_chat_printf (server->buffer, "%s: %s\n",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos2);
+ else
+ gui_chat_printf (server->buffer, "\n");
+ (void) plugin_msg_handler_exec (server->name,
+ "weechat_ctcp",
+ irc_message);
+ }
+ return 0;
+ }
+ else
+ {
+ if (!ignore)
+ {
+ if (!ptr_channel)
+ {
+ ptr_channel = irc_channel_new (server,
+ IRC_CHANNEL_TYPE_PRIVATE,
+ nick, 0);
+ if (!ptr_channel)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot "
+ "create new "
+ "private "
+ "window "
+ "\"%s\"\n"),
+ WEECHAT_ERROR,
+ nick);
+ return -1;
+ }
+ }
+ if (!ptr_channel->topic)
+ {
+ ptr_channel->topic = strdup (host2);
+ gui_chat_draw_title (ptr_channel->buffer, 1);
+ }
+
+ if (highlight || irc_protocol_is_highlight (pos, server->nick))
+ {
+ irc_display_nick (ptr_channel->buffer, NULL, nick,
+ GUI_MSG_TYPE_NICK | GUI_MSG_TYPE_HIGHLIGHT, 1,
+ GUI_COLOR(GUI_COLOR_CHAT_HIGHLIGHT), 0);
+ if ((cfg_look_infobar_delay_highlight > 0)
+ && (ptr_channel->buffer != gui_current_window->buffer))
+ gui_infobar_printf (cfg_look_infobar_delay_highlight,
+ GUI_COLOR_INFOBAR_HIGHLIGHT,
+ _("Private %s> %s"),
+ nick, pos);
+ highlight_displayed = 1;
+ }
+ else
+ {
+ irc_display_nick (ptr_channel->buffer, NULL, nick,
+ GUI_MSG_TYPE_NICK, 1,
+ GUI_COLOR(GUI_COLOR_CHAT_NICK_OTHER), 0);
+ highlight_displayed = 0;
+ }
+ gui_chat_printf_type (ptr_channel->buffer,
+ GUI_MSG_TYPE_MSG,
+ NULL, -1,
+ "%s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos);
+ (void) plugin_msg_handler_exec (server->name,
+ "weechat_pv",
+ irc_message);
+ if (highlight_displayed)
+ (void) plugin_msg_handler_exec (server->name,
+ "weechat_highlight",
+ irc_message);
+ }
+ }
+ }
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse \"%s\" command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_quit: 'quit' command received
+ */
+
+int
+irc_protocol_cmd_quit (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos;
+ t_irc_channel *ptr_channel;
+ t_irc_nick *ptr_nick;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) highlight;
+
+ /* no host => we can't identify sender of message! */
+ if (!host)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s \"%s\" command received without "
+ "host\n"),
+ WEECHAT_ERROR, "quit");
+ return -1;
+ }
+
+ if (arguments[0] == ':')
+ arguments++;
+
+ for (ptr_channel = server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
+ {
+ if ((ptr_channel->type == IRC_CHANNEL_TYPE_PRIVATE)
+ || (ptr_channel->type == IRC_CHANNEL_TYPE_DCC_CHAT))
+ ptr_nick = NULL;
+ else
+ ptr_nick = irc_nick_search (ptr_channel, nick);
+
+ if (ptr_nick || (strcmp (ptr_channel->name, nick) == 0))
+ {
+ if (ptr_nick)
+ irc_nick_free (ptr_channel, ptr_nick);
+ if (!ignore)
+ {
+ pos = strchr (host, '!');
+ gui_chat_printf_quit (ptr_channel->buffer,
+ _("%s%s %s(%s%s%s)%s has quit"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ (pos) ? pos + 1 : "",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT));
+ gui_chat_printf (ptr_channel->buffer,
+ " %s(%s%s%s)\n",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ arguments,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
+ }
+ gui_nicklist_draw (ptr_channel->buffer, 1, 1);
+ gui_status_draw (ptr_channel->buffer, 1);
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_server_mode_reason: command received from server (numeric),
+ * format: "mode :reason"
+ */
+
+int
+irc_protocol_cmd_server_mode_reason (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *ptr_msg;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ /* skip nickname if at beginning of server message */
+ if (strncmp (server->nick, arguments, strlen (server->nick)) == 0)
+ {
+ arguments += strlen (server->nick) + 1;
+ while (arguments[0] == ' ')
+ arguments++;
+ }
+
+ ptr_msg = strchr (arguments, ' ');
+ if (ptr_msg)
+ {
+ ptr_msg[0] = '\0';
+ ptr_msg++;
+ while (ptr_msg[0] == ' ')
+ ptr_msg++;
+ if (ptr_msg[0] == ':')
+ ptr_msg++;
+ }
+
+ gui_chat_printf_server (server->buffer, "%s%s: %s\n",
+ GUI_COLOR(GUI_COLOR_CHAT), arguments,
+ (ptr_msg) ? ptr_msg : "");
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_server_msg: command received from server (numeric)
+ */
+
+int
+irc_protocol_cmd_server_msg (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ while (arguments[0] == ' ')
+ arguments++;
+
+ /* skip nickname if at beginning of server message */
+ if (strncasecmp (server->nick, arguments, strlen (server->nick)) == 0)
+ {
+ arguments += strlen (server->nick) + 1;
+ while (arguments[0] == ' ')
+ arguments++;
+ }
+
+ if (arguments[0] == ':')
+ arguments++;
+
+ gui_chat_printf_server (server->buffer, "%s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT), arguments);
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_topic: 'topic' command received
+ */
+
+int
+irc_protocol_cmd_topic (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos;
+ t_irc_channel *ptr_channel;
+ t_gui_buffer *buffer;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) highlight;
+
+ if (!irc_channel_is_channel (arguments))
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s \"%s\" command received without channel\n"),
+ WEECHAT_ERROR, "topic");
+ return -1;
+ }
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ if (pos[0] == ':')
+ pos++;
+ if (!pos[0])
+ pos = NULL;
+ }
+
+ ptr_channel = irc_channel_search (server, arguments);
+ buffer = (ptr_channel) ? ptr_channel->buffer : server->buffer;
+
+ if (!ignore)
+ {
+ if (pos)
+ {
+ gui_chat_printf_info (buffer,
+ _("%s%s%s has changed topic for %s%s%s to:"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ arguments,
+ GUI_COLOR(GUI_COLOR_CHAT));
+ gui_chat_printf (buffer, " \"%s%s\"\n", pos, GUI_NO_COLOR);
+ }
+ else
+ gui_chat_printf_info (buffer,
+ _("%s%s%s has unset topic for %s%s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ arguments);
+ }
+
+ if (ptr_channel)
+ {
+ if (ptr_channel->topic)
+ free (ptr_channel->topic);
+ if (pos)
+ ptr_channel->topic = strdup (pos);
+ else
+ ptr_channel->topic = strdup ("");
+ gui_chat_draw_title (ptr_channel->buffer, 1);
+ }
+
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_wallops: 'wallops' command received
+ */
+
+int
+irc_protocol_cmd_wallops (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ if (arguments[0] == ':')
+ arguments++;
+ gui_chat_printf_server (server->buffer,
+ _("WALLOPS from %s%s%s: %s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ nick,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ arguments);
+ }
+
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_001: '001' command (connected to irc server)
+ */
+
+int
+irc_protocol_cmd_001 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos;
+ char **commands, **ptr, *vars_replaced;
+ char *away_msg;
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ pos[0] = '\0';
+ if (strcmp (server->nick, arguments) != 0)
+ {
+ free (server->nick);
+ server->nick = strdup (arguments);
+ }
+
+ irc_protocol_cmd_server_msg (server, irc_message, host, nick, arguments,
+ ignore, highlight);
+
+ /* connection to IRC server is ok! */
+ server->is_connected = 1;
+ server->lag_next_check = time (NULL) + irc_cfg_irc_lag_check;
+
+ /* set away message if user was away (before disconnection for example) */
+ if (server->away_message && server->away_message[0])
+ {
+ away_msg = strdup (server->away_message);
+ if (away_msg)
+ {
+ irc_cmd_away_server (server, away_msg);
+ free (away_msg);
+ }
+ }
+
+ /* execute command when connected */
+ if (server->command && server->command[0])
+ {
+ /* splitting command on ';' which can be escaped with '\;' */
+ commands = weechat_split_multi_command (server->command, ';');
+ if (commands)
+ {
+ for (ptr = commands; *ptr; ptr++)
+ {
+ vars_replaced = irc_protocol_replace_vars (server, NULL, *ptr);
+ protocol_input_data (gui_window_search_by_buffer (server->buffer),
+ (vars_replaced) ? vars_replaced : *ptr, 0);
+ if (vars_replaced)
+ free (vars_replaced);
+ }
+ weechat_free_multi_command (commands);
+ }
+
+ if (server->command_delay > 0)
+ server->command_time = time (NULL) + 1;
+ else
+ irc_server_autojoin_channels (server);
+ }
+ else
+ irc_server_autojoin_channels (server);
+
+ gui_status_draw (server->buffer, 1);
+ gui_input_draw (server->buffer, 1);
+
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_005: '005' command (some infos from server)
+ */
+
+int
+irc_protocol_cmd_005 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos, *pos2;
+
+ irc_protocol_cmd_server_msg (server, irc_message, host, nick, arguments,
+ ignore, highlight);
+
+ pos = strstr (arguments, "PREFIX=");
+ if (pos)
+ {
+ pos += 7;
+ if (pos[0] == '(')
+ {
+ pos2 = strchr (pos, ')');
+ if (!pos2)
+ return 0;
+ pos = pos2 + 1;
+ }
+ pos2 = strchr (pos, ' ');
+ if (pos2)
+ pos2[0] = '\0';
+ if (server->prefix)
+ free (server->prefix);
+ server->prefix = strdup (pos);
+ if (pos2)
+ pos2[0] = ' ';
+ }
+
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_221: '221' command (user mode string)
+ */
+
+int
+irc_protocol_cmd_221 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_mode;
+
+ /* make C compiler happy */
+ (void) server;
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ pos_mode = strchr (arguments, ' ');
+ if (pos_mode)
+ {
+ pos_mode[0] = '\0';
+ pos_mode++;
+ while (pos_mode[0] == ' ')
+ pos_mode++;
+
+ if (!ignore)
+ {
+ gui_chat_printf_server (server->buffer,
+ _("User mode for %s%s%s is %s[%s%s%s]\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ arguments,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_mode,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
+ }
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse \"%s\" command\n"),
+ WEECHAT_ERROR, "221");
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_301: '301' command (away message)
+ */
+
+int
+irc_protocol_cmd_301 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_nick, *pos_message;
+ t_irc_channel *ptr_channel;
+ t_gui_buffer *ptr_buffer;
+
+ /* make C compiler happy */
+ (void) server;
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_message = strchr (pos_nick, ' ');
+ if (pos_message)
+ {
+ pos_message[0] = '\0';
+ pos_message++;
+ while (pos_message[0] == ' ')
+ pos_message++;
+ if (pos_message[0] == ':')
+ pos_message++;
+
+ if (!ignore)
+ {
+ /* look for private buffer to display message */
+ ptr_channel = irc_channel_search (server, pos_nick);
+ if (!irc_cfg_irc_show_away_once || !ptr_channel ||
+ !(ptr_channel->away_message) ||
+ (strcmp (ptr_channel->away_message, pos_message) != 0))
+ {
+ ptr_buffer = (ptr_channel) ? ptr_channel->buffer : server->buffer;
+ gui_chat_printf_info (ptr_buffer,
+ _("%s%s%s is away: %s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_nick,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_message);
+ if (ptr_channel)
+ {
+ if (ptr_channel->away_message)
+ free (ptr_channel->away_message);
+ ptr_channel->away_message = strdup (pos_message);
+ }
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_302: '302' command (userhost)
+ */
+
+int
+irc_protocol_cmd_302 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_host, *ptr_next;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ arguments = strchr (arguments, ' ');
+ if (arguments)
+ {
+ while (arguments[0] == ' ')
+ arguments++;
+ if (arguments[0] == ':')
+ arguments++;
+ while (arguments)
+ {
+ pos_host = strchr (arguments, '=');
+ if (pos_host)
+ {
+ pos_host[0] = '\0';
+ pos_host++;
+
+ ptr_next = strchr (pos_host, ' ');
+ if (ptr_next)
+ {
+ ptr_next[0] = '\0';
+ ptr_next++;
+ while (ptr_next[0] == ' ')
+ ptr_next++;
+ }
+
+ gui_chat_printf_server (server->buffer,
+ "%s%s%s=%s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ arguments,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ pos_host);
+ }
+ else
+ ptr_next = NULL;
+ arguments = ptr_next;
+ if (arguments && !arguments[0])
+ arguments = NULL;
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_303: '303' command (ison)
+ */
+
+int
+irc_protocol_cmd_303 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *ptr_next;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ gui_chat_printf_server (server->buffer, _("Users online: "));
+
+ arguments = strchr (arguments, ' ');
+ if (arguments)
+ {
+ while (arguments[0] == ' ')
+ arguments++;
+ if (arguments[0] == ':')
+ arguments++;
+ while (arguments)
+ {
+ ptr_next = strchr (arguments, ' ');
+ if (ptr_next)
+ {
+ ptr_next[0] = '\0';
+ ptr_next++;
+ while (ptr_next[0] == ' ')
+ ptr_next++;
+ }
+ gui_chat_printf (server->buffer, "%s%s ",
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ arguments);
+ arguments = ptr_next;
+ if (arguments && !arguments[0])
+ arguments = NULL;
+ }
+ }
+ gui_chat_printf (server->buffer, "\n");
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_305: '305' command (unaway)
+ */
+
+int
+irc_protocol_cmd_305 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ t_gui_window *ptr_window;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ arguments = strchr (arguments, ' ');
+ if (arguments)
+ {
+ while (arguments[0] == ' ')
+ arguments++;
+ if (arguments[0] == ':')
+ arguments++;
+ gui_chat_printf_server (server->buffer, "%s\n", arguments);
+ }
+ }
+ server->is_away = 0;
+ server->away_time = 0;
+ for (ptr_window = gui_windows; ptr_window;
+ ptr_window = ptr_window->next_window)
+ {
+ if ((ptr_window->buffer->protocol == irc_protocol)
+ && (IRC_BUFFER_SERVER(ptr_window->buffer) == server))
+ gui_status_draw (ptr_window->buffer, 1);
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_306: '306' command (now away)
+ */
+
+int
+irc_protocol_cmd_306 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ t_gui_window *ptr_window;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ arguments = strchr (arguments, ' ');
+ if (arguments)
+ {
+ while (arguments[0] == ' ')
+ arguments++;
+ if (arguments[0] == ':')
+ arguments++;
+ gui_chat_printf_server (server->buffer, "%s\n", arguments);
+ }
+ }
+ server->is_away = 1;
+ server->away_time = time (NULL);
+ for (ptr_window = gui_windows; ptr_window;
+ ptr_window = ptr_window->next_window)
+ {
+ if (ptr_window->buffer->protocol == irc_protocol)
+ {
+ if (IRC_BUFFER_SERVER(ptr_window->buffer) == server)
+ {
+ gui_status_draw (ptr_window->buffer, 1);
+ ptr_window->buffer->last_read_line =
+ ptr_window->buffer->last_line;
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_whois_nick_msg: a whois command with nick and message
+ */
+
+int
+irc_protocol_cmd_whois_nick_msg (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_nick, *pos_msg;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_msg = strchr (pos_nick, ' ');
+ if (pos_msg)
+ {
+ pos_msg[0] = '\0';
+ pos_msg++;
+ while (pos_msg[0] == ' ')
+ pos_msg++;
+ if (pos_msg[0] == ':')
+ pos_msg++;
+
+ gui_chat_printf_server (server->buffer, "%s[%s%s%s] %s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_nick,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_msg);
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_310: '310' command (whois, help mode)
+ */
+
+int
+irc_protocol_cmd_310 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_nick;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+
+ gui_chat_printf_server (server->buffer,
+ _("%s[%s%s%s]%s help mode (+h)\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_nick,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT));
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_311: '311' command (whois, user)
+ */
+
+int
+irc_protocol_cmd_311 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_nick, *pos_user, *pos_host, *pos_realname;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_user = strchr (pos_nick, ' ');
+ if (pos_user)
+ {
+ pos_user[0] = '\0';
+ pos_user++;
+ while (pos_user[0] == ' ')
+ pos_user++;
+ pos_host = strchr (pos_user, ' ');
+ if (pos_host)
+ {
+ pos_host[0] = '\0';
+ pos_host++;
+ while (pos_host[0] == ' ')
+ pos_host++;
+ pos_realname = strchr (pos_host, ' ');
+ if (pos_realname)
+ {
+ pos_realname[0] = '\0';
+ pos_realname++;
+ while (pos_realname[0] == ' ')
+ pos_realname++;
+ if (pos_realname[0] == '*')
+ pos_realname++;
+ while (pos_realname[0] == ' ')
+ pos_realname++;
+ if (pos_realname[0] == ':')
+ pos_realname++;
+
+ gui_chat_printf_server (server->buffer,
+ "%s[%s%s%s] (%s%s@%s%s)%s: %s\n",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_nick,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ pos_user,
+ pos_host,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_realname);
+ }
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_312: '312' command (whois, server)
+ */
+
+int
+irc_protocol_cmd_312 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_nick, *pos_server, *pos_serverinfo;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_server = strchr (pos_nick, ' ');
+ if (pos_server)
+ {
+ pos_server[0] = '\0';
+ pos_server++;
+ while (pos_server[0] == ' ')
+ pos_server++;
+ pos_serverinfo = strchr (pos_server, ' ');
+ if (pos_serverinfo)
+ {
+ pos_serverinfo[0] = '\0';
+ pos_serverinfo++;
+ while (pos_serverinfo[0] == ' ')
+ pos_serverinfo++;
+ if (pos_serverinfo[0] == ':')
+ pos_serverinfo++;
+
+ gui_chat_printf_server (server->buffer,
+ "%s[%s%s%s] %s%s %s(%s%s%s)\n",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_nick,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_server,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_serverinfo,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_314: '314' command (whowas)
+ */
+
+int
+irc_protocol_cmd_314 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_nick, *pos_user, *pos_host, *pos_realname;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_user = strchr (pos_nick, ' ');
+ if (pos_user)
+ {
+ pos_user[0] = '\0';
+ pos_user++;
+ while (pos_user[0] == ' ')
+ pos_user++;
+ pos_host = strchr (pos_user, ' ');
+ if (pos_host)
+ {
+ pos_host[0] = '\0';
+ pos_host++;
+ while (pos_host[0] == ' ')
+ pos_host++;
+ pos_realname = strchr (pos_host, ' ');
+ if (pos_realname)
+ {
+ pos_realname[0] = '\0';
+ pos_realname++;
+ while (pos_realname[0] == ' ')
+ pos_realname++;
+ pos_realname = strchr (pos_realname, ' ');
+ if (pos_realname)
+ {
+ pos_realname[0] = '\0';
+ pos_realname++;
+ while (pos_realname[0] == ' ')
+ pos_realname++;
+ if (pos_realname[0] == ':')
+ pos_realname++;
+
+ gui_chat_printf_server (server->buffer,
+ _("%s%s %s(%s%s@%s%s)%s was %s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_nick,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ pos_user,
+ pos_host,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_realname);
+ }
+ }
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_315: '315' command (end of /who)
+ */
+
+int
+irc_protocol_cmd_315 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos;
+ t_irc_channel *ptr_channel;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ /* skip nickname if at beginning of server message */
+ if (strncmp (server->nick, arguments, strlen (server->nick)) == 0)
+ {
+ arguments += strlen (server->nick) + 1;
+ while (arguments[0] == ' ')
+ arguments++;
+ }
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ ptr_channel = irc_channel_search (server, arguments);
+ if (ptr_channel && (ptr_channel->checking_away > 0))
+ {
+ ptr_channel->checking_away--;
+ return 0;
+ }
+ if (!ignore)
+ {
+ gui_chat_printf_server (server->buffer,
+ "%s%s %s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ arguments,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos);
+ }
+ }
+ else
+ {
+ if (!ignore)
+ gui_chat_printf_server (server->buffer, "%s\n", arguments);
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_317: '317' command (whois, idle)
+ */
+
+int
+irc_protocol_cmd_317 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_nick, *pos_idle, *pos_signon, *pos_message;
+ int idle_time, day, hour, min, sec;
+ time_t datetime;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_idle = strchr (pos_nick, ' ');
+ if (pos_idle)
+ {
+ pos_idle[0] = '\0';
+ pos_idle++;
+ while (pos_idle[0] == ' ')
+ pos_idle++;
+ pos_signon = strchr (pos_idle, ' ');
+ if (pos_signon)
+ {
+ pos_signon[0] = '\0';
+ pos_signon++;
+ while (pos_signon[0] == ' ')
+ pos_signon++;
+ pos_message = strchr (pos_signon, ' ');
+ if (pos_message)
+ {
+ pos_message[0] = '\0';
+
+ idle_time = atoi (pos_idle);
+ day = idle_time / (60 * 60 * 24);
+ hour = (idle_time % (60 * 60 * 24)) / (60 * 60);
+ min = ((idle_time % (60 * 60 * 24)) % (60 * 60)) / 60;
+ sec = ((idle_time % (60 * 60 * 24)) % (60 * 60)) % 60;
+
+ gui_chat_printf_server (server->buffer,
+ _("%s[%s%s%s]%s idle: "),
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_nick,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT));
+
+ if (day > 0)
+ gui_chat_printf (server->buffer, "%s%d %s%s, ",
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ day,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (day > 1) ? _("days") : _("day"));
+
+ datetime = (time_t)(atol (pos_signon));
+ gui_chat_printf (server->buffer,
+ _("%s%02d %s%s %s%02d %s%s %s%02d %s%s, signon at: %s%s"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ hour,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (hour > 1) ? _("hours") : _("hour"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ min,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (min > 1) ? _("minutes") : _("minute"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ sec,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (sec > 1) ? _("seconds") : _("second"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ ctime (&datetime));
+ }
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_319: '319' command (whois, channels)
+ */
+
+int
+irc_protocol_cmd_319 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_nick, *pos_channel, *pos;
+ int color;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_channel = strchr (pos_nick, ' ');
+ if (pos_channel)
+ {
+ pos_channel[0] = '\0';
+ pos_channel++;
+ while (pos_channel[0] == ' ')
+ pos_channel++;
+ if (pos_channel[0] == ':')
+ pos_channel++;
+
+ gui_chat_printf_server (server->buffer,
+ _("%s[%s%s%s]%s Channels: "),
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_nick,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT));
+ while (pos_channel && pos_channel[0])
+ {
+ if (irc_mode_nick_prefix_allowed (server, pos_channel[0]))
+ {
+ switch (pos_channel[0])
+ {
+ case '@': /* op */
+ color = GUI_COLOR_NICKLIST_PREFIX1;
+ break;
+ case '~': /* channel owner */
+ color = GUI_COLOR_NICKLIST_PREFIX1;
+ break;
+ case '&': /* channel admin */
+ color = GUI_COLOR_NICKLIST_PREFIX1;
+ break;
+ case '!': /* channel admin (2) */
+ color = GUI_COLOR_NICKLIST_PREFIX1;
+ break;
+ case '%': /* half-op */
+ color = GUI_COLOR_NICKLIST_PREFIX2;
+ break;
+ case '+': /* voice */
+ color = GUI_COLOR_NICKLIST_PREFIX3;
+ break;
+ case '-': /* channel user */
+ color = GUI_COLOR_NICKLIST_PREFIX4;
+ break;
+ default:
+ color = GUI_COLOR_CHAT;
+ break;
+ }
+ gui_chat_printf (server->buffer, "%s%c",
+ GUI_COLOR(color), pos_channel[0]);
+ pos_channel++;
+ }
+
+ pos = strchr (pos_channel, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ }
+ gui_chat_printf (server->buffer, "%s%s%s",
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ pos_channel,
+ (pos && pos[0]) ? " " : "\n");
+ pos_channel = pos;
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_321: '321' command (/list start)
+ */
+
+int
+irc_protocol_cmd_321 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ }
+ else
+ pos = arguments;
+
+ gui_chat_printf_server (server->buffer, "%s\n", pos);
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_322: '322' command (channel for /list)
+ */
+
+int
+irc_protocol_cmd_322 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ }
+ else
+ pos = arguments;
+
+ if (server->cmd_list_regexp)
+ {
+ if (regexec (server->cmd_list_regexp, pos, 0, NULL, 0) == 0)
+ gui_chat_printf_server (server->buffer, "%s\n", pos);
+ }
+ else
+ gui_chat_printf_server (server->buffer, "%s\n", pos);
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_323: '323' command (/list end)
+ */
+
+int
+irc_protocol_cmd_323 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ }
+ else
+ pos = arguments;
+
+ gui_chat_printf_server (server->buffer, "%s\n", pos);
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_324: '324' command (channel mode)
+ */
+
+int
+irc_protocol_cmd_324 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_channel, *pos_modes, *pos;
+ t_irc_channel *ptr_channel;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) ignore;
+ (void) highlight;
+
+ pos_channel = strchr (arguments, ' ');
+ if (pos_channel)
+ {
+ pos_channel[0] = '\0';
+ pos_channel++;
+ while (pos_channel[0] == ' ')
+ pos_channel++;
+
+ pos_modes = strchr (pos_channel, ' ');
+ if (pos_modes)
+ {
+ pos_modes[0] = '\0';
+ pos_modes++;
+ while (pos_modes[0] == ' ')
+ pos_modes++;
+
+ /* remove spaces after modes */
+ pos = pos_modes + strlen (pos_modes) - 1;
+ while ((pos >= pos_modes) && (pos[0] == ' '))
+ {
+ pos[0] = '\0';
+ pos--;
+ }
+
+ /* search channel */
+ ptr_channel = irc_channel_search (server, pos_channel);
+ if (ptr_channel)
+ {
+ if (pos_modes[0])
+ {
+ if (ptr_channel->modes)
+ ptr_channel->modes = (char *) realloc (ptr_channel->modes,
+ strlen (pos_modes) + 1);
+ else
+ ptr_channel->modes = (char *) malloc (strlen (pos_modes) + 1);
+ strcpy (ptr_channel->modes, pos_modes);
+ irc_mode_channel_set (server, ptr_channel, pos_modes);
+ }
+ else
+ {
+ if (ptr_channel->modes)
+ {
+ free (ptr_channel->modes);
+ ptr_channel->modes = NULL;
+ }
+ }
+ gui_status_draw (ptr_channel->buffer, 1);
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_327: '327' command (whois, host)
+ */
+
+int
+irc_protocol_cmd_327 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_nick, *pos_host1, *pos_host2, *pos_other;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_host1 = strchr (pos_nick, ' ');
+ if (pos_host1)
+ {
+ pos_host1[0] = '\0';
+ pos_host1++;
+ while (pos_host1[0] == ' ')
+ pos_host1++;
+ pos_host2 = strchr (pos_host1, ' ');
+ if (pos_host2)
+ {
+ pos_host2[0] = '\0';
+ pos_host2++;
+ while (pos_host2[0] == ' ')
+ pos_host2++;
+
+ pos_other = strchr (pos_host2, ' ');
+ if (pos_other)
+ {
+ pos_other[0] = '\0';
+ pos_other++;
+ while (pos_other[0] == ' ')
+ pos_other++;
+ }
+
+ gui_chat_printf_server (server->buffer,
+ "%s[%s%s%s] %s%s %s %s%s%s%s%s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_nick,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ pos_host1,
+ pos_host2,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ (pos_other) ? "(" : "",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (pos_other) ? pos_other : "",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ (pos_other) ? ")" : "");
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_329: '329' command received (channel creation date)
+ */
+
+int
+irc_protocol_cmd_329 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_channel, *pos_date;
+ t_irc_channel *ptr_channel;
+ time_t datetime;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ pos_channel = strchr (arguments, ' ');
+ if (pos_channel)
+ {
+ while (pos_channel[0] == ' ')
+ pos_channel++;
+ pos_date = strchr (pos_channel, ' ');
+ if (pos_date)
+ {
+ pos_date[0] = '\0';
+ pos_date++;
+ while (pos_date[0] == ' ')
+ pos_date++;
+
+ ptr_channel = irc_channel_search (server, pos_channel);
+ if (!ptr_channel)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s channel \"%s\" not found for "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, pos_channel, "329");
+ return -1;
+ }
+
+ if (!ignore && (ptr_channel->display_creation_date))
+ {
+ datetime = (time_t)(atol (pos_date));
+ gui_chat_printf_info (ptr_channel->buffer,
+ _("Channel created on %s"),
+ ctime (&datetime));
+ }
+ ptr_channel->display_creation_date = 0;
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot identify date/time for "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, "329");
+ return -1;
+ }
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot identify channel for "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, "329");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_331: '331' command received (no topic for channel)
+ */
+
+int
+irc_protocol_cmd_331 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_channel, *pos;
+ t_irc_channel *ptr_channel;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) server;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ pos_channel = strchr (arguments, ' ');
+ if (pos_channel)
+ {
+ pos_channel++;
+ while (pos_channel[0] == ' ')
+ pos_channel++;
+ pos = strchr (pos_channel, ' ');
+ if (pos)
+ pos[0] = '\0';
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s channel \"%s\" not found for "
+ "\"%s\" command\n"),
+ WEECHAT_ERROR, "", "331");
+ return -1;
+ }
+
+ ptr_channel = irc_channel_search (server, pos_channel);
+ if (!ignore)
+ gui_chat_printf_info ((ptr_channel) ? ptr_channel->buffer : NULL,
+ _("No topic set for %s%s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ pos_channel);
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_332: '332' command received (topic of channel)
+ */
+
+int
+irc_protocol_cmd_332 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos, *pos2;
+ t_irc_channel *ptr_channel;
+ t_gui_buffer *ptr_buffer;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ while (pos[0] == ' ')
+ pos++;
+ pos2 = strchr (pos, ' ');
+ if (pos2)
+ {
+ pos2[0] = '\0';
+ ptr_channel = irc_channel_search (server, pos);
+ ptr_buffer = (ptr_channel) ?
+ ptr_channel->buffer : server->buffer;
+ pos2++;
+ while (pos2[0] == ' ')
+ pos2++;
+ if (pos2[0] == ':')
+ pos2++;
+ if (ptr_channel)
+ {
+ if (ptr_channel->topic)
+ free (ptr_channel->topic);
+ ptr_channel->topic = strdup (pos2);
+ }
+
+ if (!ignore)
+ {
+ gui_chat_printf_info (ptr_buffer, _("Topic for %s%s%s is: "),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ pos,
+ GUI_COLOR(GUI_COLOR_CHAT));
+ gui_chat_printf (ptr_buffer, "\"%s%s\"\n", pos2, GUI_NO_COLOR);
+ }
+
+ if (ptr_channel)
+ gui_chat_draw_title (ptr_buffer, 1);
+ }
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot identify channel for \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "332");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_333: '333' command received (infos about topic (nick / date))
+ */
+
+int
+irc_protocol_cmd_333 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_channel, *pos_nick, *pos_date;
+ t_irc_channel *ptr_channel;
+ t_gui_buffer *ptr_buffer;
+ time_t datetime;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ pos_channel = strchr (arguments, ' ');
+ if (pos_channel)
+ {
+ while (pos_channel[0] == ' ')
+ pos_channel++;
+ pos_nick = strchr (pos_channel, ' ');
+ if (pos_nick)
+ {
+ pos_nick[0] = '\0';
+ pos_nick++;
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_date = strchr (pos_nick, ' ');
+ if (pos_date)
+ {
+ pos_date[0] = '\0';
+ pos_date++;
+ while (pos_date[0] == ' ')
+ pos_date++;
+
+ ptr_channel = irc_channel_search (server, pos_channel);
+ ptr_buffer = (ptr_channel) ?
+ ptr_channel->buffer : server->buffer;
+
+ if (!ignore)
+ {
+ datetime = (time_t)(atol (pos_date));
+ gui_chat_printf_info (ptr_buffer,
+ _("Topic set by %s%s%s, %s"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_nick,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ ctime (&datetime));
+ }
+ }
+ else
+ return 0;
+ }
+ else
+ return 0;
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot identify channel for \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "333");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_338: '338' command (whois, host)
+ */
+
+int
+irc_protocol_cmd_338 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_nick, *pos_host, *pos_message;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_host = strchr (pos_nick, ' ');
+ if (pos_host)
+ {
+ pos_host[0] = '\0';
+ pos_host++;
+ while (pos_host[0] == ' ')
+ pos_host++;
+ pos_message = strchr (pos_host, ' ');
+ if (pos_message)
+ {
+ pos_message[0] = '\0';
+ pos_message++;
+ while (pos_message[0] == ' ')
+ pos_message++;
+ if (pos_message[0] == ':')
+ pos_message++;
+
+ gui_chat_printf_server (server->buffer,
+ "%s[%s%s%s] %s%s %s%s %s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_nick,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_nick,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_message,
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ pos_host);
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_341: '341' command received (inviting)
+ */
+
+int
+irc_protocol_cmd_341 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_nick, *pos_channel;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ pos_nick[0] = '\0';
+ pos_nick++;
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+
+ pos_channel = strchr (pos_nick, ' ');
+ if (pos_channel)
+ {
+ if (!ignore)
+ {
+ pos_channel[0] = '\0';
+ pos_channel++;
+ while (pos_channel[0] == ' ')
+ pos_channel++;
+ if (pos_channel[0] == ':')
+ pos_channel++;
+
+ gui_chat_printf_server (server->buffer,
+ _("%s%s%s has invited %s%s%s on %s%s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ arguments,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_nick,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ pos_channel);
+ gui_status_draw (gui_current_window->buffer, 1);
+ }
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot identify channel for \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "341");
+ return -1;
+ }
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot identify nickname for \"%s\" "
+ "command\n"),
+ WEECHAT_ERROR, "341");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_344: '344' command (channel reop)
+ */
+
+int
+irc_protocol_cmd_344 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_channel, *pos_host;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ pos_channel = strchr (arguments, ' ');
+ if (pos_channel)
+ {
+ while (pos_channel[0] == ' ')
+ pos_channel++;
+ pos_host = strchr (pos_channel, ' ');
+ if (pos_host)
+ {
+ pos_host[0] = '\0';
+ pos_host++;
+ while (pos_host[0] == ' ')
+ pos_host++;
+
+ gui_chat_printf_server (server->buffer,
+ _("Channel reop %s%s%s: %s%s\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ pos_channel,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ pos_host);
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_345: '345' command (end of channel reop)
+ */
+
+int
+irc_protocol_cmd_345 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ /* skip nickname if at beginning of server message */
+ if (strncmp (server->nick, arguments, strlen (server->nick)) == 0)
+ {
+ arguments += strlen (server->nick) + 1;
+ while (arguments[0] == ' ')
+ arguments++;
+ }
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ if (!ignore)
+ gui_chat_printf_server (server->buffer,
+ "%s%s %s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ arguments,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos);
+ }
+ else
+ {
+ if (!ignore)
+ gui_chat_printf_server (server->buffer, "%s\n", arguments);
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_348: '348' command received (channel exception list)
+ */
+
+int
+irc_protocol_cmd_348 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_channel, *pos_exception, *pos_user, *pos_date, *pos;
+ t_irc_channel *ptr_channel;
+ t_gui_buffer *buffer;
+ time_t datetime;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ /* look for channel */
+ pos_channel = strchr (arguments, ' ');
+ if (!pos_channel)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse \"%s\" command\n"),
+ WEECHAT_ERROR, "348");
+ return -1;
+ }
+ pos_channel[0] = '\0';
+ pos_channel++;
+ while (pos_channel[0] == ' ')
+ pos_channel++;
+
+ /* look for exception mask */
+ pos_exception = strchr (pos_channel, ' ');
+ if (!pos_exception)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse \"%s\" command\n"),
+ WEECHAT_ERROR, "348");
+ return -1;
+ }
+ pos_exception[0] = '\0';
+ pos_exception++;
+ while (pos_exception[0] == ' ')
+ pos_exception++;
+
+ /* look for user who set exception */
+ pos_user = strchr (pos_exception, ' ');
+ if (pos_user)
+ {
+ pos_user[0] = '\0';
+ pos_user++;
+ while (pos_user[0] == ' ')
+ pos_user++;
+
+ /* look for date/time */
+ pos_date = strchr (pos_user, ' ');
+ if (pos_date)
+ {
+ pos_date[0] = '\0';
+ pos_date++;
+ while (pos_date[0] == ' ')
+ pos_date++;
+ }
+ }
+ else
+ pos_date = NULL;
+
+ ptr_channel = irc_channel_search (server, pos_channel);
+ buffer = (ptr_channel) ? ptr_channel->buffer : server->buffer;
+
+ if (!ignore)
+ {
+ gui_chat_printf_info (buffer,
+ _("%s[%s%s%s]%s exception %s%s%s"),
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ pos_channel,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ pos_exception,
+ GUI_COLOR(GUI_COLOR_CHAT));
+ if (pos_user)
+ {
+ pos = strchr (pos_user, '!');
+ if (pos)
+ {
+ pos[0] = '\0';
+ gui_chat_printf (buffer,
+ _(" by %s%s %s(%s%s%s)"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_user,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ pos + 1,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
+ }
+ else
+ gui_chat_printf (buffer,
+ _(" by %s%s"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_user);
+ }
+ if (pos_date)
+ {
+ datetime = (time_t)(atol (pos_date));
+ gui_chat_printf_nolog (buffer, NULL, -1,
+ "%s, %s",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ ctime (&datetime));
+ }
+ else
+ gui_chat_printf_nolog (buffer, NULL, -1, "\n");
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_349: '349' command received (end of channel exception list)
+ */
+
+int
+irc_protocol_cmd_349 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_channel, *pos_msg;
+ t_irc_channel *ptr_channel;
+ t_gui_buffer *buffer;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ pos_channel = strchr (arguments, ' ');
+ if (!pos_channel)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse \"%s\" command\n"),
+ WEECHAT_ERROR, "349");
+ return -1;
+ }
+ pos_channel[0] = '\0';
+ pos_channel++;
+ while (pos_channel[0] == ' ')
+ pos_channel++;
+
+ pos_msg = strchr (pos_channel, ' ');
+ if (!pos_msg)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse \"%s\" command\n"),
+ WEECHAT_ERROR, "349");
+ return -1;
+ }
+ pos_msg[0] = '\0';
+ pos_msg++;
+ while (pos_msg[0] == ' ')
+ pos_msg++;
+ if (pos_msg[0] == ':')
+ pos_msg++;
+
+ ptr_channel = irc_channel_search (server, pos_channel);
+ buffer = (ptr_channel) ? ptr_channel->buffer : server->buffer;
+
+ if (!ignore)
+ {
+ gui_chat_printf_info (buffer,
+ "%s[%s%s%s] %s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ pos_channel,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_msg);
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_351: '351' command received (server version)
+ */
+
+int
+irc_protocol_cmd_351 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos, *pos2;
+
+ /* make C compiler happy */
+ (void) server;
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ }
+ else
+ pos = arguments;
+
+ pos2 = strstr (pos, " :");
+ if (pos2)
+ {
+ pos2[0] = '\0';
+ pos2 += 2;
+ }
+
+ if (!ignore)
+ {
+ if (pos2)
+ gui_chat_printf_server (server->buffer, "%s %s\n", pos, pos2);
+ else
+ gui_chat_printf_server (server->buffer, "%s\n", pos);
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_352: '352' command (who)
+ */
+
+int
+irc_protocol_cmd_352 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_channel, *pos_user, *pos_host, *pos_server, *pos_nick;
+ char *pos_attr, *pos_hopcount, *pos_realname;
+ int length;
+ t_irc_channel *ptr_channel;
+ t_irc_nick *ptr_nick;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ pos_channel = strchr (arguments, ' ');
+ if (pos_channel)
+ {
+ while (pos_channel[0] == ' ')
+ pos_channel++;
+ pos_user = strchr (pos_channel, ' ');
+ if (pos_user)
+ {
+ pos_user[0] = '\0';
+ pos_user++;
+ while (pos_user[0] == ' ')
+ pos_user++;
+ pos_host = strchr (pos_user, ' ');
+ if (pos_host)
+ {
+ pos_host[0] = '\0';
+ pos_host++;
+ while (pos_host[0] == ' ')
+ pos_host++;
+ pos_server = strchr (pos_host, ' ');
+ if (pos_server)
+ {
+ pos_server[0] = '\0';
+ pos_server++;
+ while (pos_server[0] == ' ')
+ pos_server++;
+ pos_nick = strchr (pos_server, ' ');
+ if (pos_nick)
+ {
+ pos_nick[0] = '\0';
+ pos_nick++;
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_attr = strchr (pos_nick, ' ');
+ if (pos_attr)
+ {
+ pos_attr[0] = '\0';
+ pos_attr++;
+ while (pos_attr[0] == ' ')
+ pos_attr++;
+ pos_hopcount = strchr (pos_attr, ' ');
+ if (pos_hopcount)
+ {
+ pos_hopcount[0] = '\0';
+ pos_hopcount++;
+ while (pos_hopcount[0] == ' ')
+ pos_hopcount++;
+ if (pos_hopcount[0] == ':')
+ pos_hopcount++;
+ pos_realname = strchr (pos_hopcount, ' ');
+ if (pos_realname)
+ {
+ pos_realname[0] = '\0';
+ pos_realname++;
+ while (pos_realname[0] == ' ')
+ pos_realname++;
+
+ ptr_channel = irc_channel_search (server, pos_channel);
+ if (ptr_channel && (ptr_channel->checking_away > 0))
+ {
+ ptr_nick = irc_nick_search (ptr_channel, pos_nick);
+ if (ptr_nick)
+ {
+ if (ptr_nick->host)
+ free (ptr_nick->host);
+ length = strlen (pos_user) + 1 + strlen (pos_host) + 1;
+ ptr_nick->host = (char *) malloc (length);
+ if (ptr_nick->host)
+ snprintf (ptr_nick->host, length, "%s@%s", pos_user, pos_host);
+ irc_nick_set_away (ptr_channel, ptr_nick,
+ (pos_attr[0] == 'G') ? 1 : 0);
+ }
+ return 0;
+ }
+
+ if (!ignore)
+ {
+ gui_chat_printf_server (server->buffer,
+ _("%s%s%s on %s%s%s "
+ "%s %s %s%s@%s "
+ "%s(%s%s%s)\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_nick,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ pos_channel,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_attr,
+ pos_hopcount,
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ pos_user,
+ pos_host,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_realname,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_353: '353' command received (list of users on a channel)
+ */
+
+int
+irc_protocol_cmd_353 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos, *pos_nick;
+ int is_chanowner, is_chanadmin, is_chanadmin2, is_op, is_halfop;
+ int has_voice, is_chanuser;
+ int prefix_found, color;
+ t_irc_channel *ptr_channel;
+ t_gui_buffer *ptr_buffer;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ pos = strstr (arguments, " = ");
+ if (pos)
+ arguments = pos + 3;
+ else
+ {
+ pos = strstr (arguments, " * ");
+ if (pos)
+ arguments = pos + 3;
+ else
+ {
+ pos = strstr (arguments, " @ ");
+ if (pos)
+ arguments = pos + 3;
+ }
+ }
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+
+ ptr_channel = irc_channel_search (server, arguments);
+ if (ptr_channel)
+ ptr_buffer = ptr_channel->buffer;
+ else
+ ptr_buffer = server->buffer;
+
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ if (pos[0] != ':')
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse \"%s\" command\n"),
+ WEECHAT_ERROR, "353");
+ return -1;
+ }
+
+ /* channel is not joined => display users on server buffer */
+ if (!ignore && !ptr_channel)
+ {
+ /* display users on channel */
+ gui_chat_printf_server (ptr_buffer,
+ _("Nicks %s%s%s: %s["),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ arguments,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
+ }
+
+ pos++;
+ if (pos[0])
+ {
+ while (pos && pos[0])
+ {
+ is_chanowner = 0;
+ is_chanadmin = 0;
+ is_chanadmin2 = 0;
+ is_op = 0;
+ is_halfop = 0;
+ has_voice = 0;
+ is_chanuser = 0;
+ prefix_found = 1;
+
+ while (prefix_found)
+ {
+ prefix_found = 0;
+
+ if (irc_mode_nick_prefix_allowed (server, pos[0]))
+ {
+ prefix_found = 1;
+ switch (pos[0])
+ {
+ case '@': /* op */
+ is_op = 1;
+ color = GUI_COLOR_NICKLIST_PREFIX1;
+ break;
+ case '~': /* channel owner */
+ is_chanowner = 1;
+ color = GUI_COLOR_NICKLIST_PREFIX1;
+ break;
+ case '&': /* channel admin */
+ is_chanadmin = 1;
+ color = GUI_COLOR_NICKLIST_PREFIX1;
+ break;
+ case '!': /* channel admin (2) */
+ is_chanadmin2 = 1;
+ color = GUI_COLOR_NICKLIST_PREFIX1;
+ break;
+ case '%': /* half-op */
+ is_halfop = 1;
+ color = GUI_COLOR_NICKLIST_PREFIX2;
+ break;
+ case '+': /* voice */
+ has_voice = 1;
+ color = GUI_COLOR_NICKLIST_PREFIX3;
+ break;
+ case '-': /* channel user */
+ is_chanuser = 1;
+ color = GUI_COLOR_NICKLIST_PREFIX4;
+ break;
+ default:
+ color = GUI_COLOR_CHAT;
+ break;
+ }
+ if (!ignore && !ptr_channel)
+ gui_chat_printf (ptr_buffer, "%s%c",
+ GUI_COLOR(color), pos[0]);
+ }
+ if (prefix_found)
+ pos++;
+ }
+ pos_nick = pos;
+ pos = strchr (pos, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ }
+ if (ptr_channel)
+ {
+ if (!irc_nick_new (server, ptr_channel, pos_nick,
+ is_chanowner, is_chanadmin, is_chanadmin2,
+ is_op, is_halfop, has_voice, is_chanuser))
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot create nick \"%s\" "
+ "for channel \"%s\"\n"),
+ WEECHAT_ERROR, pos_nick,
+ ptr_channel->name);
+ }
+ }
+ else
+ {
+ if (!ignore)
+ {
+ gui_chat_printf (ptr_buffer, "%s%s",
+ GUI_COLOR(GUI_COLOR_CHAT), pos_nick);
+ if (pos && pos[0])
+ gui_chat_printf (ptr_buffer, " ");
+ }
+ }
+ }
+ }
+ if (ptr_channel)
+ {
+ gui_nicklist_draw (ptr_channel->buffer, 1, 1);
+ gui_status_draw (ptr_channel->buffer, 1);
+ }
+ else
+ {
+ if (!ignore)
+ gui_chat_printf (ptr_buffer, "%s]\n",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
+ }
+ }
+ else
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse \"%s\" command\n"),
+ WEECHAT_ERROR, "353");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_366: '366' command received (end of /names list)
+ */
+
+int
+irc_protocol_cmd_366 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos, *pos2;
+ t_irc_channel *ptr_channel;
+ t_irc_nick *ptr_nick;
+ int num_nicks, num_op, num_halfop, num_voice, num_normal;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ while (pos[0] == ' ')
+ pos++;
+ pos2 = strchr (pos, ' ');
+ if (pos2)
+ {
+ pos2[0] = '\0';
+ pos2++;
+ while (pos2[0] == ' ')
+ pos2++;
+ if (pos2[0] == ':')
+ pos2++;
+
+ ptr_channel = irc_channel_search (server, pos);
+ if (ptr_channel)
+ {
+ if (!ignore)
+ {
+ /* display users on channel */
+ gui_chat_printf_server (ptr_channel->buffer,
+ _("Nicks %s%s%s: %s["),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ ptr_channel->name,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
+
+ for (ptr_nick = ptr_channel->nicks; ptr_nick; ptr_nick = ptr_nick->next_nick)
+ {
+ irc_display_nick (ptr_channel->buffer, ptr_nick, NULL,
+ GUI_MSG_TYPE_MSG, 0,
+ GUI_COLOR(GUI_COLOR_CHAT), 1);
+ if (ptr_nick != ptr_channel->last_nick)
+ gui_chat_printf (ptr_channel->buffer, " ");
+ }
+ gui_chat_printf (ptr_channel->buffer, "%s]\n",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
+
+ /* display number of nicks, ops, halfops & voices on the channel */
+ irc_nick_count (ptr_channel, &num_nicks, &num_op, &num_halfop, &num_voice,
+ &num_normal);
+ gui_chat_printf_info (ptr_channel->buffer,
+ _("Channel %s%s%s: %s%d%s %s %s(%s%d%s %s, "
+ "%s%d%s %s, %s%d%s %s, %s%d%s %s%s)\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ ptr_channel->name,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ num_nicks,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (num_nicks > 1) ? _("nicks") : _("nick"),
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ num_op,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (num_op > 1) ? _("ops") : _("op"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ num_halfop,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (num_halfop > 1) ? _("halfops") : _("halfop"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ num_voice,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (num_voice > 1) ? _("voices") : _("voice"),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ num_normal,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ _("normal"),
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
+ }
+ irc_cmd_mode_server (server, ptr_channel->name);
+ irc_channel_check_away (server, ptr_channel, 1);
+ }
+ else
+ {
+ if (!ignore)
+ {
+ gui_chat_printf_info (gui_current_window->buffer,
+ "%s%s%s: %s\n",
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ pos,
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos2);
+ }
+ return 0;
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_367: '367' command received (banlist)
+ */
+
+int
+irc_protocol_cmd_367 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_channel, *pos_ban, *pos_user, *pos_date, *pos;
+ t_irc_channel *ptr_channel;
+ t_gui_buffer *buffer;
+ time_t datetime;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ /* look for channel */
+ pos_channel = strchr (arguments, ' ');
+ if (!pos_channel)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse \"%s\" command\n"),
+ WEECHAT_ERROR, "367");
+ return -1;
+ }
+ pos_channel[0] = '\0';
+ pos_channel++;
+ while (pos_channel[0] == ' ')
+ pos_channel++;
+
+ /* look for ban mask */
+ pos_ban = strchr (pos_channel, ' ');
+ if (!pos_ban)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse \"%s\" command\n"),
+ WEECHAT_ERROR, "367");
+ return -1;
+ }
+ pos_ban[0] = '\0';
+ pos_ban++;
+ while (pos_ban[0] == ' ')
+ pos_ban++;
+
+ /* look for user who set ban */
+ pos_date = NULL;
+ pos_user = strchr (pos_ban, ' ');
+ if (pos_user)
+ {
+ pos_user[0] = '\0';
+ pos_user++;
+ while (pos_user[0] == ' ')
+ pos_user++;
+
+ /* look for date/time */
+ pos_date = strchr (pos_user, ' ');
+ if (pos_date)
+ {
+ pos_date[0] = '\0';
+ pos_date++;
+ while (pos_date[0] == ' ')
+ pos_date++;
+ }
+ }
+
+ ptr_channel = irc_channel_search (server, pos_channel);
+ buffer = (ptr_channel) ? ptr_channel->buffer : server->buffer;
+
+ if (!ignore)
+ {
+ if (pos_user)
+ {
+ gui_chat_printf_info_nolog (buffer,
+ _("%s[%s%s%s] %s%s%s banned by "),
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ pos_channel,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ pos_ban,
+ GUI_COLOR(GUI_COLOR_CHAT));
+ pos = strchr (pos_user, '!');
+ if (pos)
+ {
+ pos[0] = '\0';
+ gui_chat_printf (buffer,
+ "%s%s %s(%s%s%s)",
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_user,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ pos + 1,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
+ }
+ else
+ gui_chat_printf (buffer,
+ "%s%s",
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_user);
+ if (pos_date)
+ {
+ datetime = (time_t)(atol (pos_date));
+ gui_chat_printf (buffer,
+ "%s, %s",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ ctime (&datetime));
+ }
+ else
+ gui_chat_printf (buffer, "\n");
+ }
+ else
+ gui_chat_printf_info_nolog (buffer,
+ _("%s[%s%s%s] %s%s%s banned\n"),
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ pos_channel,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_HOST),
+ pos_ban,
+ GUI_COLOR(GUI_COLOR_CHAT));
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_368: '368' command received (end of banlist)
+ */
+
+int
+irc_protocol_cmd_368 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_channel, *pos_msg;
+ t_irc_channel *ptr_channel;
+ t_gui_buffer *buffer;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ pos_channel = strchr (arguments, ' ');
+ if (!pos_channel)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse \"%s\" command\n"),
+ WEECHAT_ERROR, "368");
+ return -1;
+ }
+ pos_channel[0] = '\0';
+ pos_channel++;
+ while (pos_channel[0] == ' ')
+ pos_channel++;
+
+ pos_msg = strchr (pos_channel, ' ');
+ if (!pos_msg)
+ {
+ gui_chat_printf_error_nolog (server->buffer,
+ _("%s cannot parse \"%s\" command\n"),
+ WEECHAT_ERROR, "368");
+ return -1;
+ }
+ pos_msg[0] = '\0';
+ pos_msg++;
+ while (pos_msg[0] == ' ')
+ pos_msg++;
+ if (pos_msg[0] == ':')
+ pos_msg++;
+
+ ptr_channel = irc_channel_search (server, pos_channel);
+ buffer = (ptr_channel) ? ptr_channel->buffer : server->buffer;
+
+ if (!ignore)
+ {
+ gui_chat_printf_info_nolog (buffer,
+ "%s[%s%s%s] %s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_CHANNEL),
+ pos_channel,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_msg);
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_432: '432' command received (erroneous nickname)
+ */
+
+int
+irc_protocol_cmd_432 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ /* Note: this IRC command can not be ignored */
+
+ irc_protocol_cmd_error (server, irc_message, host, nick, arguments,
+ ignore, highlight);
+
+ if (!server->is_connected)
+ {
+ if (strcmp (server->nick, server->nick1) == 0)
+ {
+ gui_chat_printf_info (server->buffer,
+ _("%s: trying 2nd nickname \"%s\"\n"),
+ PACKAGE_NAME, server->nick2);
+ free (server->nick);
+ server->nick = strdup (server->nick2);
+ }
+ else
+ {
+ if (strcmp (server->nick, server->nick2) == 0)
+ {
+ gui_chat_printf_info (server->buffer,
+ _("%s: trying 3rd nickname \"%s\"\n"),
+ PACKAGE_NAME, server->nick3);
+ free (server->nick);
+ server->nick = strdup (server->nick3);
+ }
+ else
+ {
+ if (strcmp (server->nick, server->nick3) == 0)
+ {
+ gui_chat_printf_info (server->buffer,
+ _("%s: all declared nicknames are already in "
+ "use or invalid, closing connection with "
+ "server!\n"),
+ PACKAGE_NAME);
+ irc_server_disconnect (server, 1);
+ return 0;
+ }
+ else
+ {
+ gui_chat_printf_info (server->buffer,
+ _("%s: trying 1st nickname \"%s\"\n"),
+ PACKAGE_NAME, server->nick1);
+ free (server->nick);
+ server->nick = strdup (server->nick1);
+ }
+ }
+ }
+ irc_server_sendf (server, "NICK %s", server->nick);
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_433: '433' command received (nickname already in use)
+ */
+
+int
+irc_protocol_cmd_433 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ /* Note: this IRC command can not be ignored */
+
+ if (!server->is_connected)
+ {
+ if (strcmp (server->nick, server->nick1) == 0)
+ {
+ gui_chat_printf_info (server->buffer,
+ _("%s: nickname \"%s\" is already in use, "
+ "trying 2nd nickname \"%s\"\n"),
+ PACKAGE_NAME, server->nick, server->nick2);
+ free (server->nick);
+ server->nick = strdup (server->nick2);
+ }
+ else
+ {
+ if (strcmp (server->nick, server->nick2) == 0)
+ {
+ gui_chat_printf_info (server->buffer,
+ _("%s: nickname \"%s\" is already in use, "
+ "trying 3rd nickname \"%s\"\n"),
+ PACKAGE_NAME, server->nick, server->nick3);
+ free (server->nick);
+ server->nick = strdup (server->nick3);
+ }
+ else
+ {
+ if (strcmp (server->nick, server->nick3) == 0)
+ {
+ gui_chat_printf_error (server->buffer,
+ _("%s: all declared nicknames are already in use, "
+ "closing connection with server!\n"),
+ PACKAGE_NAME);
+ irc_server_disconnect (server, 1);
+ return 0;
+ }
+ else
+ {
+ gui_chat_printf_info (server->buffer,
+ _("%s: nickname \"%s\" is already in use, "
+ "trying 1st nickname \"%s\"\n"),
+ PACKAGE_NAME, server->nick, server->nick1);
+ free (server->nick);
+ server->nick = strdup (server->nick1);
+ }
+ }
+ }
+ irc_server_sendf (server, "NICK %s", server->nick);
+ }
+ else
+ return irc_protocol_cmd_error (server, irc_message, host, nick, arguments,
+ ignore, highlight);
+
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_438: '438' command received (not authorized to change nickname)
+ */
+
+int
+irc_protocol_cmd_438 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos, *pos2;
+
+ /* make C compiler happy */
+ (void) server;
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+
+ pos2 = strstr (pos, " :");
+ if (pos2)
+ {
+ pos2[0] = '\0';
+ pos2 += 2;
+ gui_chat_printf_server (server->buffer,
+ "%s (%s => %s)\n",
+ pos2, arguments, pos);
+ }
+ else
+ gui_chat_printf_server (server->buffer,
+ "%s (%s)\n",
+ pos, arguments);
+ }
+ else
+ gui_chat_printf_server (server->buffer, "%s\n", arguments);
+ }
+ return 0;
+}
+
+/*
+ * irc_protocol_cmd_671: '671' command (whois, secure connection)
+ */
+
+int
+irc_protocol_cmd_671 (t_irc_server *server, char *irc_message, char *host,
+ char *nick, char *arguments, int ignore, int highlight)
+{
+ char *pos_nick, *pos_message;
+
+ /* make C compiler happy */
+ (void) irc_message;
+ (void) host;
+ (void) nick;
+ (void) highlight;
+
+ if (!ignore)
+ {
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_message = strchr (pos_nick, ' ');
+ if (pos_message)
+ {
+ pos_message[0] = '\0';
+ pos_message++;
+ while (pos_message[0] == ' ')
+ pos_message++;
+ if (pos_message[0] == ':')
+ pos_message++;
+
+ gui_chat_printf_server (server->buffer,
+ "%s[%s%s%s] %s%s\n",
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT_NICK),
+ pos_nick,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ pos_message);
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/plugins/irc/irc-protocol.h b/src/plugins/irc/irc-protocol.h
new file mode 100644
index 000000000..3c2a0647c
--- /dev/null
+++ b/src/plugins/irc/irc-protocol.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __WEECHAT_IRC_PROTOCOL_H
+#define __WEECHAT_IRC_PROTOCOL_H 1
+
+typedef int (t_irc_recv_func)(t_irc_server *, char *, char *, char *, char *,
+ int, int);
+
+typedef struct t_irc_protocol_msg t_irc_protocol_msg;
+
+struct t_irc_protocol_msg
+{
+ char *name; /* IRC message name */
+ char *description; /* message description */
+ t_irc_recv_func *recv_function; /* function called when msg is received */
+};
+
+#endif /* irc-protocol.h */
diff --git a/src/plugins/irc/irc-recv.c b/src/plugins/irc/irc-recv.c
deleted file mode 100644
index 4e0d195ad..000000000
--- a/src/plugins/irc/irc-recv.c
+++ /dev/null
@@ -1,5058 +0,0 @@
-/*
- * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
- */
-
-/* irc-recv.c: implementation of IRC commands (server to client),
- according to RFC 1459,2810,2811,2812 */
-
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include <wctype.h>
-#include <sys/time.h>
-#include <time.h>
-#include <sys/utsname.h>
-#include <regex.h>
-
-#include "../../common/weechat.h"
-#include "irc.h"
-#include "../../common/alias.h"
-#include "../../common/command.h"
-#include "../../common/hotlist.h"
-#include "../../common/utf8.h"
-#include "../../common/util.h"
-#include "../../common/weeconfig.h"
-#include "../../gui/gui.h"
-
-#ifdef PLUGINS
-#include "../../plugins/plugins.h"
-#endif
-
-
-char *irc_last_command_received = NULL;
-int command_ignored, command_force_highlight;
-
-
-/*
- * irc_recv_is_word_char: return 1 if given character is a "word character"
- */
-
-int
-irc_recv_is_word_char (char *str)
-{
- wint_t c = utf8_get_wc (str);
-
- if (c == WEOF)
- return 0;
-
- if (iswalnum (c))
- return 1;
-
- switch (c)
- {
- case '-':
- case '_':
- case '|':
- return 1;
- }
-
- /* not a 'word char' */
- return 0;
-}
-
-/*
- * irc_recv_command_is_numeric: return 1 if given string is 100% numeric
- */
-
-int
-irc_recv_command_is_numeric (char *str)
-{
- while (str && str[0])
- {
- if (!isdigit (str[0]))
- return 0;
- str++;
- }
- return 1;
-}
-
-/*
- * irc_recv_is_highlight: return 1 if given message contains highlight (with given nick
- * or at least one of string in "irc_higlight" setting)
- */
-
-int
-irc_recv_is_highlight (char *message, char *nick)
-{
- char *msg, *highlight, *match, *match_pre, *match_post, *msg_pos, *pos, *pos_end;
- int end, length, startswith, endswith, wildcard_start, wildcard_end;
-
- /* empty message ? */
- if (!message || !message[0])
- return 0;
-
- /* highlight asked by a plugin */
- if (command_force_highlight)
- return 1;
-
- /* highlight by nickname */
- match = strstr (message, nick);
- if (match)
- {
- match_pre = utf8_prev_char (message, match);
- if (!match_pre)
- match_pre = match - 1;
- match_post = match + strlen(nick);
- startswith = ((match == message) || (!irc_recv_is_word_char (match_pre)));
- endswith = ((!match_post[0]) || (!irc_recv_is_word_char (match_post)));
- if (startswith && endswith)
- return 1;
- }
-
- /* no highlight by nickname and "irc_highlight" is empty */
- if (!cfg_irc_highlight || !cfg_irc_highlight[0])
- return 0;
-
- /* convert both strings to lower case */
- if ((msg = strdup (message)) == NULL)
- return 0;
- if ((highlight = strdup (cfg_irc_highlight)) == NULL)
- {
- free (msg);
- return 0;
- }
- pos = msg;
- while (pos[0])
- {
- pos[0] = tolower (pos[0]);
- pos++;
- }
- pos = highlight;
- while (pos[0])
- {
- pos[0] = tolower (pos[0]);
- pos++;
- }
-
- /* look in "irc_highlight" for highlight */
- pos = highlight;
- end = 0;
- while (!end)
- {
- pos_end = strchr (pos, ',');
- if (!pos_end)
- {
- pos_end = strchr (pos, '\0');
- end = 1;
- }
- /* error parsing string! */
- if (!pos_end)
- {
- free (msg);
- free (highlight);
- return 0;
- }
-
- length = pos_end - pos;
- pos_end[0] = '\0';
- if (length > 0)
- {
- if ((wildcard_start = (pos[0] == '*')))
- {
- pos++;
- length--;
- }
- if ((wildcard_end = (*(pos_end - 1) == '*')))
- {
- *(pos_end - 1) = '\0';
- length--;
- }
- }
-
- if (length > 0)
- {
- msg_pos = msg;
- /* highlight found! */
- while ((match = strstr (msg_pos, pos)) != NULL)
- {
- match_pre = match - 1;
- match_pre = utf8_prev_char (msg, match);
- if (!match_pre)
- match_pre = match - 1;
- match_post = match + length;
- startswith = ((match == msg) || (!irc_recv_is_word_char (match_pre)));
- endswith = ((!match_post[0]) || (!irc_recv_is_word_char (match_post)));
- if ((wildcard_start && wildcard_end) ||
- (!wildcard_start && !wildcard_end &&
- startswith && endswith) ||
- (wildcard_start && endswith) ||
- (wildcard_end && startswith))
- {
- free (msg);
- free (highlight);
- return 1;
- }
- msg_pos = match_post;
- }
- }
-
- if (!end)
- pos = pos_end + 1;
- }
-
- /* no highlight found with "irc_highlight" list */
- free (msg);
- free (highlight);
- return 0;
-}
-
-/*
- * irc_recv_command: executes action when receiving IRC command
- * returns: 0 = all ok, command executed
- * -1 = command failed
- * -2 = no command to execute
- * -3 = command not found
- */
-
-int
-irc_recv_command (t_irc_server *server, char *entire_line,
- char *host, char *command, char *arguments)
-{
- int i, cmd_found, return_code;
- char *pos, *nick;
- char *dup_entire_line, *dup_host, *dup_arguments;
- t_irc_recv_func *cmd_recv_func;
- char *cmd_name;
-
- if (!command)
- return -2;
-
- /* look for IRC command */
- cmd_found = -1;
- for (i = 0; irc_commands[i].command_name; i++)
- {
- if (ascii_strcasecmp (irc_commands[i].command_name, command) == 0)
- {
- cmd_found = i;
- break;
- }
- }
-
- /* command not found */
- if (cmd_found < 0)
- {
- /* for numeric commands, we use default recv function (irc_recv_server_msg) */
- if (irc_recv_command_is_numeric (command))
- {
- cmd_name = command;
- cmd_recv_func = irc_recv_cmd_server_msg;
- }
- else
- return -3;
- }
- else
- {
- cmd_name = irc_commands[cmd_found].command_name;
- cmd_recv_func = irc_commands[cmd_found].recv_function;
- }
-
- if (cmd_recv_func != NULL)
- {
- dup_entire_line = (entire_line) ? strdup (entire_line) : NULL;
- dup_host = (host) ? strdup (host) : NULL;
- dup_arguments = (arguments) ? strdup (arguments) : NULL;
-
- command_ignored = irc_ignore_check (dup_host,
- cmd_name,
- NULL,
- server->name);
- command_force_highlight = 0;
-#ifdef PLUGINS
- return_code = plugin_msg_handler_exec (server->name,
- cmd_name,
- dup_entire_line);
- /* plugin handler choosed to discard message for WeeChat,
- so we ignore this message in standard handler */
- if (return_code & PLUGIN_RC_OK_IGNORE_WEECHAT)
- command_ignored = 1;
- /* plugin asked for highlight ? */
- if (return_code & PLUGIN_RC_OK_WITH_HIGHLIGHT)
- command_force_highlight = 1;
-#endif
- pos = (dup_host) ? strchr (dup_host, '!') : NULL;
- if (pos)
- pos[0] = '\0';
- nick = (dup_host) ? strdup (dup_host) : NULL;
- if (pos)
- pos[0] = '!';
- irc_last_command_received = strdup (dup_entire_line);
- return_code = (int) (cmd_recv_func) (server, dup_host, nick,
- dup_arguments);
- if (irc_last_command_received)
- free (irc_last_command_received);
- if (nick)
- free (nick);
- if (dup_entire_line)
- free (dup_entire_line);
- if (dup_host)
- free (dup_host);
- if (dup_arguments)
- free (dup_arguments);
- return return_code;
- }
-
- return 0;
-}
-
-/*
- * irc_recv_cmd_error: error received from server
- */
-
-int
-irc_recv_cmd_error (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos;
- int first;
- t_gui_buffer *ptr_buffer;
- t_irc_channel *ptr_channel;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- first = 1;
- ptr_buffer = server->buffer;
-
- while (arguments && arguments[0])
- {
- while (arguments[0] == ' ')
- arguments++;
-
- if (arguments[0] == ':')
- {
- arguments++;
- if (first)
- irc_display_prefix (server, ptr_buffer, GUI_PREFIX_ERROR);
- gui_printf (ptr_buffer, "%s%s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (first) ? "" : ": ",
- arguments);
- if (strncmp (arguments, "Closing Link", 12) == 0)
- irc_server_disconnect (server, 1);
- arguments = NULL;
- }
- else
- {
- pos = strchr (arguments, ' ');
- if (pos)
- pos[0] = '\0';
- if (strcasecmp (arguments, server->nick) != 0)
- {
- if (first)
- {
- ptr_channel = irc_channel_search (server, arguments);
- if (ptr_channel)
- ptr_buffer = ptr_channel->buffer;
- irc_display_prefix (server, ptr_buffer, GUI_PREFIX_ERROR);
- }
- gui_printf (ptr_buffer, "%s%s%s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- (first) ? "" : " ",
- arguments);
- first = 0;
- }
- if (pos)
- arguments = pos + 1;
- else
- arguments = NULL;
- }
- }
-
- return 0;
-}
-
-/*
- * irc_recv_cmd_invite: 'invite' message received
- */
-
-int
-irc_recv_cmd_invite (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_channel;
-
- pos_channel = strchr (arguments, ' ');
- if (pos_channel)
- {
- pos_channel[0] = '\0';
- pos_channel++;
- while (pos_channel[0] == ' ')
- pos_channel++;
- if (pos_channel[0] == ':')
- pos_channel++;
-
- command_ignored |= irc_ignore_check (host, "invite", pos_channel, server->name);
-
- if (!command_ignored)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, _("You have been invited to %s%s%s by %s%s\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- pos_channel,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick);
- if (gui_add_hotlist
- && ((server->buffer->num_displayed == 0) || (gui_buffer_is_scrolled (server->buffer))))
- {
- hotlist_add (HOTLIST_HIGHLIGHT, NULL, server, server->buffer, 0);
- gui_status_draw (gui_current_window->buffer, 1);
- }
- }
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s channel \"%s\" not found for \"%s\" command\n"),
- WEECHAT_ERROR, "", "invite");
- return -1;
- }
- return 0;
-}
-
-
-/*
- * irc_recv_cmd_join: 'join' message received
- */
-
-int
-irc_recv_cmd_join (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- t_irc_channel *ptr_channel;
- t_irc_nick *ptr_nick;
- char *pos;
-
- /* no host => we can't identify sender of message! */
- if (!host)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command received without host\n"),
- WEECHAT_ERROR, "join");
- return -1;
- }
-
- if (arguments[0] == ':')
- arguments++;
-
- command_ignored |= irc_ignore_check (host, "join", arguments, server->name);
-
- ptr_channel = irc_channel_search (server, arguments);
- if (!ptr_channel)
- {
- ptr_channel = irc_channel_new (server, IRC_CHANNEL_TYPE_CHANNEL, arguments);
- if (!ptr_channel)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot create new channel \"%s\"\n"),
- WEECHAT_ERROR, arguments);
- return -1;
- }
- gui_buffer_new (gui_current_window, server, ptr_channel,
- GUI_BUFFER_TYPE_STANDARD, 1);
- }
-
- pos = strchr (host, '!');
- if (!command_ignored)
- {
- irc_display_prefix (server, ptr_channel->buffer, GUI_PREFIX_JOIN);
- gui_printf (ptr_channel->buffer,
- _("%s%s %s(%s%s%s)%s has joined %s%s\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- (pos) ? pos + 1 : host,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- arguments);
- }
-
- /* remove topic and display channel creation date if joining new channel */
- if (!ptr_channel->nicks)
- {
- if (ptr_channel->topic)
- {
- free (ptr_channel->topic);
- ptr_channel->topic = NULL;
- gui_chat_draw_title (ptr_channel->buffer, 1);
- }
- ptr_channel->display_creation_date = 1;
- }
-
- /* add nick in channel */
- ptr_nick = irc_nick_new (server, ptr_channel, nick, 0, 0, 0, 0, 0, 0, 0);
- if (ptr_nick)
- ptr_nick->host = strdup ((pos) ? pos + 1 : host);
-
- /* redraw nicklist and status bar */
- gui_nicklist_draw (ptr_channel->buffer, 1, 1);
- gui_status_draw (ptr_channel->buffer, 1);
- return 0;
-}
-
-/*
- * irc_recv_cmd_kick: 'kick' message received
- */
-
-int
-irc_recv_cmd_kick (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_nick, *pos_comment;
- t_irc_channel *ptr_channel;
- t_irc_nick *ptr_nick;
-
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- pos_nick[0] = '\0';
- pos_nick++;
- while (pos_nick[0] == ' ')
- pos_nick++;
-
- pos_comment = strchr (pos_nick, ' ');
- if (pos_comment)
- {
- pos_comment[0] = '\0';
- pos_comment++;
- while (pos_comment[0] == ' ')
- pos_comment++;
- if (pos_comment[0] == ':')
- pos_comment++;
- }
-
- command_ignored |= irc_ignore_check (host, "kick", arguments, server->name);
-
- ptr_channel = irc_channel_search (server, arguments);
- if (!ptr_channel)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s channel \"%s\" not found for \"%s\" command\n"),
- WEECHAT_ERROR, arguments, "kick");
- return -1;
- }
-
- if (!command_ignored)
- {
- irc_display_prefix (server, ptr_channel->buffer, GUI_PREFIX_PART);
- gui_printf (ptr_channel->buffer, _("%s%s%s has kicked %s%s%s from %s%s"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- arguments);
- if (pos_comment)
- gui_printf (ptr_channel->buffer, " %s(%s%s%s)\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_comment,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
- else
- gui_printf (ptr_channel->buffer, "\n");
- }
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s nick \"%s\" not found for \"%s\" command\n"),
- WEECHAT_ERROR, "", "kick");
- return -1;
- }
- if (strcmp (pos_nick, server->nick) == 0)
- {
- /* my nick was kicked => free all nicks, channel is not active any more */
- irc_nick_free_all (ptr_channel);
- gui_nicklist_draw (ptr_channel->buffer, 1, 1);
- gui_status_draw (ptr_channel->buffer, 1);
- if (server->autorejoin)
- irc_send_cmd_join (server, NULL, ptr_channel->name);
- }
- {
- /* someone was kicked from channel (but not me) => remove only this nick */
- ptr_nick = irc_nick_search (ptr_channel, pos_nick);
- if (ptr_nick)
- {
- irc_nick_free (ptr_channel, ptr_nick);
- gui_nicklist_draw (ptr_channel->buffer, 1, 1);
- gui_status_draw (ptr_channel->buffer, 1);
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_kill: 'kill' message received
- */
-
-int
-irc_recv_cmd_kill (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_host2, *pos_comment;
- t_irc_channel *ptr_channel;
-
- pos_host2 = strchr (arguments, ' ');
- if (pos_host2)
- {
- pos_host2[0] = '\0';
- pos_host2++;
- while (pos_host2[0] == ' ')
- pos_host2++;
-
- if (pos_host2[0] == ':')
- pos_comment = pos_host2 + 1;
- else
- {
- pos_comment = strchr (pos_host2, ' ');
- if (pos_comment)
- {
- pos_comment[0] = '\0';
- pos_comment++;
- while (pos_comment[0] == ' ')
- pos_comment++;
- if (pos_comment[0] == ':')
- pos_comment++;
- }
- }
-
- for (ptr_channel = server->channels; ptr_channel;
- ptr_channel = ptr_channel->next_channel)
- {
- if (!command_ignored
- && !irc_ignore_check (host, "kill", ptr_channel->name, server->name))
- {
- irc_display_prefix (server, ptr_channel->buffer, GUI_PREFIX_PART);
- gui_printf (ptr_channel->buffer, _("%s%s%s has killed %s%s%s from server"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- arguments,
- GUI_COLOR(GUI_COLOR_WIN_CHAT));
- if (pos_comment)
- gui_printf (ptr_channel->buffer, " %s(%s%s%s)\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_comment,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
- else
- gui_printf (ptr_channel->buffer, "\n");
- }
- }
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s host not found for \"%s\" command\n"),
- WEECHAT_ERROR, "kill");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_mode: 'mode' message received
- */
-
-int
-irc_recv_cmd_mode (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_modes, *pos;
- t_irc_channel *ptr_channel;
-
- /* no host => we can't identify sender of message! */
- if (!host)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command received without host\n"),
- WEECHAT_ERROR, "mode");
- return -1;
- }
-
- pos_modes = strchr (arguments, ' ');
- if (!pos_modes)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command received without channel or nickname\n"),
- WEECHAT_ERROR, "mode");
- return -1;
- }
- pos_modes[0] = '\0';
- pos_modes++;
- while (pos_modes[0] == ' ')
- pos_modes++;
- if (pos_modes[0] == ':')
- pos_modes++;
-
- /* remove spaces after modes */
- pos = pos_modes + strlen (pos_modes) - 1;
- while ((pos >= pos_modes) && (pos[0] == ' '))
- {
- pos[0] = '\0';
- pos--;
- }
-
- if (irc_channel_is_channel (arguments))
- {
- ptr_channel = irc_channel_search (server, arguments);
- if (ptr_channel)
- {
- command_ignored |= irc_ignore_check (host, "mode",
- ptr_channel->name, server->name);
- if (!command_ignored)
- {
- irc_display_prefix (server, ptr_channel->buffer, GUI_PREFIX_INFO);
- gui_printf (ptr_channel->buffer,
- _("Mode %s%s %s[%s%s%s]%s by %s%s\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- ptr_channel->name,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_modes,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick);
- }
- irc_mode_channel_set (server, ptr_channel, pos_modes);
- irc_server_sendf (server, "MODE %s", ptr_channel->name);
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s channel \"%s\" not found for \"%s\" command\n"),
- WEECHAT_ERROR, arguments, "mode");
- return -1;
- }
- }
- else
- {
- if (!command_ignored)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_INFO);
- gui_printf (server->buffer,
- _("User mode %s[%s%s%s]%s by %s%s\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_modes,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick);
- }
- irc_mode_user_set (server, pos_modes);
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_nick: 'nick' message received
- */
-
-int
-irc_recv_cmd_nick (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- t_irc_channel *ptr_channel;
- t_irc_nick *ptr_nick;
- int nick_is_me;
- t_gui_window *ptr_win;
- t_gui_buffer *ptr_buffer;
-
- /* no host => we can't identify sender of message! */
- if (!host)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command received without host\n"),
- WEECHAT_ERROR, "nick");
- return -1;
- }
-
- if (arguments[0] == ':')
- arguments++;
-
- /* change nickname in any opened private window */
- for (ptr_buffer = gui_buffers; ptr_buffer;
- ptr_buffer = ptr_buffer->next_buffer)
- {
- if ((GUI_SERVER(ptr_buffer) == server) && GUI_BUFFER_IS_PRIVATE(ptr_buffer))
- {
- if ((GUI_CHANNEL(ptr_buffer)->name)
- && (ascii_strcasecmp (nick, GUI_CHANNEL(ptr_buffer)->name) == 0))
- {
- ptr_channel = irc_channel_search_any (server, arguments);
- if (!ptr_channel)
- {
- free (GUI_CHANNEL(ptr_buffer)->name);
- GUI_CHANNEL(ptr_buffer)->name = strdup (arguments);
- }
- }
- }
- }
-
- for (ptr_channel = server->channels; ptr_channel;
- ptr_channel = ptr_channel->next_channel)
- {
- ptr_nick = irc_nick_search (ptr_channel, nick);
- if (ptr_nick)
- {
- nick_is_me = (strcmp (ptr_nick->nick, server->nick) == 0) ? 1 : 0;
- if (nick_is_me)
- gui_add_hotlist = 0;
- irc_nick_change (ptr_channel, ptr_nick, arguments);
- if (!command_ignored
- && !irc_ignore_check (host, "nick", ptr_channel->name, server->name))
- {
- irc_display_prefix (server, ptr_channel->buffer, GUI_PREFIX_INFO);
- if (nick_is_me)
- gui_printf (ptr_channel->buffer, _("You are now known as %s%s\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- arguments);
- else
- gui_printf (ptr_channel->buffer, _("%s%s%s is now known as %s%s\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- arguments);
- }
- gui_nicklist_draw (ptr_channel->buffer, 1, 1);
- gui_add_hotlist = 1;
- }
- }
-
- if (strcmp (server->nick, nick) == 0)
- {
- free (server->nick);
- server->nick = strdup (arguments);
- gui_status_draw (gui_current_window->buffer, 1);
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
- {
- if (ptr_win->buffer->server == server)
- gui_input_draw (ptr_win->buffer, 1);
- }
- }
- else
- {
- gui_status_draw (gui_current_window->buffer, 1);
- gui_input_draw (gui_current_window->buffer, 1);
- }
-
- return 0;
-}
-
-/*
- * irc_recv_cmd_notice: 'notice' message received
- */
-
-int
-irc_recv_cmd_notice (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *host2, *pos, *pos2, *pos_usec;
- struct timeval tv;
- long sec1, usec1, sec2, usec2, difftime;
- t_irc_channel *ptr_channel;
- int highlight;
-
- host2 = NULL;
- if (host)
- {
- pos = strchr (host, '!');
- if (pos)
- host2 = pos + 1;
- }
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- if (pos[0] == ':')
- pos++;
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s nickname not found for \"%s\" command\n"),
- WEECHAT_ERROR, "notice");
- return -1;
- }
-
- if (!command_ignored)
- {
- if (strncmp (pos, "\01VERSION", 8) == 0)
- {
- pos += 9;
- pos2 = strchr (pos, '\01');
- if (pos2)
- pos2[0] = '\0';
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, _("CTCP %sVERSION%s reply from %s%s%s: %s\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos);
- }
- else
- {
- if (strncmp (pos, "\01PING", 5) == 0)
- {
- pos += 5;
- while (pos[0] == ' ')
- pos++;
- pos_usec = strchr (pos, ' ');
- if (pos_usec)
- {
- pos_usec[0] = '\0';
- pos_usec++;
- pos2 = strchr (pos_usec, '\01');
- if (pos2)
- {
- pos2[0] = '\0';
-
- gettimeofday (&tv, NULL);
- sec1 = atol (pos);
- usec1 = atol (pos_usec);
- sec2 = tv.tv_sec;
- usec2 = tv.tv_usec;
-
- difftime = ((sec2 * 1000000) + usec2) - ((sec1 * 1000000) + usec1);
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, _("CTCP %sPING%s reply from %s%s%s: %ld.%ld seconds\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- difftime / 1000000,
- (difftime % 1000000) / 1000);
- }
- }
- }
- else
- {
- if (nick && nick[0] && cfg_irc_notice_as_pv)
- {
- ptr_channel = irc_channel_search (server, nick);
- if (!ptr_channel)
- {
- ptr_channel = irc_channel_new (server, IRC_CHANNEL_TYPE_PRIVATE, nick);
- if (!ptr_channel)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot create new private window \"%s\"\n"),
- WEECHAT_ERROR, nick);
- return -1;
- }
- gui_buffer_new (gui_current_window, server, ptr_channel,
- GUI_BUFFER_TYPE_STANDARD, 0);
- }
- if (!ptr_channel->topic)
- {
- ptr_channel->topic = strdup ((host2) ? host2 : "");
- gui_chat_draw_title (ptr_channel->buffer, 1);
- }
-
- gui_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_NICK,
- "%s<",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
- if (irc_recv_is_highlight (pos, server->nick))
- {
- gui_printf_type (ptr_channel->buffer,
- GUI_MSG_TYPE_NICK | GUI_MSG_TYPE_HIGHLIGHT,
- "%s%s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HIGHLIGHT),
- nick);
- if ( (cfg_look_infobar_delay_highlight > 0)
- && (ptr_channel->buffer != gui_current_window->buffer) )
- gui_infobar_printf (cfg_look_infobar_delay_highlight,
- GUI_COLOR_WIN_INFOBAR_HIGHLIGHT,
- _("Private %s> %s"),
- nick, pos);
- highlight = 1;
- }
- else
- {
- gui_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_NICK,
- "%s%s",
- GUI_COLOR(GUI_COLOR_WIN_NICK_PRIVATE),
- nick);
- highlight = 0;
- }
- gui_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_NICK,
- "%s> ",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
- gui_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_MSG,
- "%s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos);
-#ifdef PLUGINS
- if (highlight)
- (void) plugin_msg_handler_exec (server->name,
- "weechat_highlight",
- irc_last_command_received);
-#endif
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- if (host)
- {
- gui_printf (server->buffer, "%s%s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK), nick);
- if (host2)
- gui_printf (server->buffer, " %s(%s%s%s)",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- host2,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
- gui_printf (server->buffer, "%s: ",
- GUI_COLOR(GUI_COLOR_WIN_CHAT));
- }
- gui_printf (server->buffer, "%s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos);
- if ((nick) && (ascii_strcasecmp (nick, "nickserv") != 0) &&
- (ascii_strcasecmp (nick, "chanserv") != 0) &&
- (ascii_strcasecmp (nick, "memoserv") != 0))
- {
- if (gui_add_hotlist
- && ((server->buffer->num_displayed == 0) || (gui_buffer_is_scrolled (server->buffer))))
- {
- hotlist_add (HOTLIST_PRIVATE, NULL, server, server->buffer, 0);
- gui_status_draw (gui_current_window->buffer, 1);
- }
- }
- }
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_part: 'part' message received
- */
-
-int
-irc_recv_cmd_part (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos, *pos_args, *join_string;
- int join_length;
- t_irc_channel *ptr_channel;
- t_irc_nick *ptr_nick;
-
- /* no host => we can't identify sender of message! */
- if (!host || !arguments)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command received without host or channel\n"),
- WEECHAT_ERROR, "part");
- return -1;
- }
-
- if (arguments[0] == ':')
- arguments++;
-
- pos_args = strchr (arguments, ' ');
- if (pos_args)
- {
- pos_args[0] = '\0';
- pos_args++;
- while (pos_args[0] == ' ')
- pos_args++;
- if (pos_args[0] == ':')
- pos_args++;
- }
-
- ptr_channel = irc_channel_search (server, arguments);
- if (ptr_channel)
- {
- command_ignored |= irc_ignore_check (host, "part", ptr_channel->name, server->name);
- ptr_nick = irc_nick_search (ptr_channel, nick);
- if (ptr_nick)
- {
- /* display part message */
- if (!command_ignored)
- {
- pos = strchr (host, '!');
- irc_display_prefix (server, ptr_channel->buffer, GUI_PREFIX_PART);
- gui_printf (ptr_channel->buffer, _("%s%s %s(%s%s%s)%s has left %s%s"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- (pos) ? pos + 1 : "",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- ptr_channel->name);
- if (pos_args && pos_args[0])
- gui_printf (ptr_channel->buffer, " %s(%s%s%s)\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_args,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
- else
- gui_printf (ptr_channel->buffer, "\n");
- }
-
- /* part request was issued by local client ? */
- if (strcmp (ptr_nick->nick, server->nick) == 0)
- {
- irc_nick_free_all (ptr_channel);
-
- /* cycling ? => rejoin channel immediately */
- if (ptr_channel->cycle)
- {
- ptr_channel->cycle = 0;
- if (ptr_channel->key)
- {
- join_length = strlen (ptr_channel->name) + 1 +
- strlen (ptr_channel->key) + 1;
- join_string = (char *)malloc (join_length);
- if (join_string)
- {
- snprintf (join_string, join_length, "%s %s",
- ptr_channel->name,
- ptr_channel->key);
- irc_send_cmd_join(server, ptr_channel, join_string);
- free (join_string);
- }
- else
- irc_send_cmd_join(server, ptr_channel, ptr_channel->name);
- }
- else
- irc_send_cmd_join(server, ptr_channel, ptr_channel->name);
- }
- if (ptr_channel->close)
- {
- gui_buffer_free (ptr_channel->buffer, 1);
- irc_channel_free (server, ptr_channel);
- ptr_channel = NULL;
- }
- }
- else
- irc_nick_free (ptr_channel, ptr_nick);
-
- if (ptr_channel)
- {
- gui_nicklist_draw (ptr_channel->buffer, 1, 1);
- gui_status_draw (ptr_channel->buffer, 1);
- }
- gui_input_draw (gui_current_window->buffer, 1);
- }
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s channel \"%s\" not found for \"%s\" command\n"),
- WEECHAT_ERROR, arguments, "part");
- return -1;
- }
-
- return 0;
-}
-
-/*
- * irc_recv_cmd_ping: 'ping' command received
- */
-
-int
-irc_recv_cmd_ping (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (arguments[0] == ':')
- arguments++;
-
- pos = strrchr (arguments, ' ');
- if (pos)
- pos[0] = '\0';
-
- irc_server_sendf (server, "PONG :%s", arguments);
-
- return 0;
-}
-
-/*
- * irc_recv_cmd_pong: 'pong' command received
- */
-
-int
-irc_recv_cmd_pong (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- struct timeval tv;
- int old_lag;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
- (void) arguments;
-
- if (server->lag_check_time.tv_sec != 0)
- {
- /* calculate lag (time diff with lag check) */
- old_lag = server->lag;
- gettimeofday (&tv, NULL);
- server->lag = (int) get_timeval_diff (&(server->lag_check_time), &tv);
- if (old_lag != server->lag)
- gui_status_draw (gui_current_window->buffer, 1);
-
- /* schedule next lag check */
- server->lag_check_time.tv_sec = 0;
- server->lag_check_time.tv_usec = 0;
- server->lag_next_check = time (NULL) + cfg_irc_lag_check;
- }
- return 0;
-}
-
-/*
- * irc_cmd_reply_version: send version in reply to "CTCP VERSION" request
- */
-
-void
-irc_cmd_reply_version (t_irc_server *server, t_irc_channel *channel,
- char *host, char *nick, char *message)
-{
- char *pos;
- struct utsname *buf;
- t_gui_buffer *ptr_buffer;
-
- ptr_buffer = (channel) ? channel->buffer : server->buffer;
-
- command_ignored |= irc_ignore_check (host, "ctcp", NULL, server->name);
- if (!command_ignored)
- {
- pos = strchr (message, ' ');
- if (pos)
- {
- while (pos[0] == ' ')
- pos++;
- if (pos[0] == '\01')
- pos = NULL;
- else if (!pos[0])
- pos = NULL;
- }
-
- buf = (struct utsname *) malloc (sizeof (struct utsname));
- if (buf && (uname (buf) >= 0))
- {
- irc_server_sendf (server,
- "NOTICE %s :%sVERSION %s v%s"
- " compiled on %s, running "
- "%s %s / %s%s",
- nick, "\01", PACKAGE_NAME, PACKAGE_VERSION, __DATE__,
- &buf->sysname,
- &buf->release, &buf->machine, "\01");
- free (buf);
- }
- else
- irc_server_sendf (server,
- "NOTICE %s :%sVERSION %s v%s"
- " compiled on %s%s",
- nick, "\01", PACKAGE_NAME, PACKAGE_VERSION, __DATE__,
- "\01");
- irc_display_prefix (server, ptr_buffer, GUI_PREFIX_SERVER);
- gui_printf (ptr_buffer,
- _("CTCP %sVERSION%s received from %s%s"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick);
- if (pos)
- gui_printf (ptr_buffer, "%s: %s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos);
- else
- gui_printf (ptr_buffer, "\n");
-#ifdef PLUGINS
- (void) plugin_msg_handler_exec (server->name,
- "weechat_ctcp",
- irc_last_command_received);
-#endif
- }
-}
-
-/*
- * irc_recv_cmd_privmsg: 'privmsg' command received
- */
-
-int
-irc_recv_cmd_privmsg (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos, *pos2, *host2;
- char *pos_file, *pos_addr, *pos_port, *pos_size, *pos_start_resume; /* for DCC */
- t_irc_channel *ptr_channel;
- t_irc_nick *ptr_nick;
- int highlight;
-
- /* no host => we can't identify sender of message! */
- if (!host)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command received without host\n"),
- WEECHAT_ERROR, "privmsg");
- return -1;
- }
-
- pos = strchr (host, '!');
- if (pos)
- host2 = pos + 1;
- else
- host2 = host;
-
- /* receiver is a channel ? */
- if (irc_channel_is_channel (arguments))
- {
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- if (pos[0] == ':')
- pos++;
-
- ptr_channel = irc_channel_search (server, arguments);
- if (ptr_channel)
- {
- if (strncmp (pos, "\01ACTION ", 8) == 0)
- {
- command_ignored |= irc_ignore_check (host, "action", ptr_channel->name, server->name);
- pos += 8;
- pos2 = strchr (pos, '\01');
- if (pos2)
- pos2[0] = '\0';
- if (!command_ignored)
- {
- irc_display_prefix (server, ptr_channel->buffer, GUI_PREFIX_ACTION_ME);
- if (irc_recv_is_highlight (pos, server->nick))
- {
- gui_printf_type (ptr_channel->buffer,
- GUI_MSG_TYPE_MSG | GUI_MSG_TYPE_HIGHLIGHT,
- "%s%s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HIGHLIGHT),
- nick);
- if ( (cfg_look_infobar)
- && (cfg_look_infobar_delay_highlight > 0)
- && (ptr_channel->buffer != gui_current_window->buffer) )
- gui_infobar_printf (cfg_look_infobar_delay_highlight,
- GUI_COLOR_WIN_INFOBAR_HIGHLIGHT,
- _("Channel %s: * %s %s"),
- ptr_channel->name, nick, pos);
- gui_printf (ptr_channel->buffer, " %s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT), pos);
-#ifdef PLUGINS
- (void) plugin_msg_handler_exec (server->name,
- "weechat_highlight",
- irc_last_command_received);
-#endif
- }
- else
- {
- gui_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_MSG,
- "%s%s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick);
- gui_printf (ptr_channel->buffer, " %s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT), pos);
- }
- irc_channel_add_nick_speaking (ptr_channel, nick);
- }
- return 0;
- }
- if (strncmp (pos, "\01SOUND ", 7) == 0)
- {
- command_ignored |= irc_ignore_check (host, "ctcp", ptr_channel->name, server->name);
- pos += 7;
- pos2 = strchr (pos, '\01');
- if (pos2)
- pos2[0] = '\0';
- if (!command_ignored)
- {
- irc_display_prefix (server, ptr_channel->buffer, GUI_PREFIX_SERVER);
- gui_printf (ptr_channel->buffer,
- _("Received a CTCP %sSOUND%s \"%s\" from %s%s\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick);
- }
- return 0;
- }
- if (strncmp (pos, "\01PING", 5) == 0)
- {
- command_ignored |= irc_ignore_check (host, "ctcp", ptr_channel->name, server->name);
- pos += 5;
- while (pos[0] == ' ')
- pos++;
- pos2 = strchr (pos, '\01');
- if (pos2)
- pos2[0] = '\0';
- else
- pos = NULL;
- if (pos && !pos[0])
- pos = NULL;
- if (pos)
- irc_server_sendf (server, "NOTICE %s :\01PING %s\01",
- nick, pos);
- else
- irc_server_sendf (server, "NOTICE %s :\01PING\01",
- nick);
- irc_display_prefix (server, ptr_channel->buffer, GUI_PREFIX_SERVER);
- gui_printf (ptr_channel->buffer,
- _("CTCP %sPING%s received from %s%s\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick);
- return 0;
- }
- if (strncmp (pos, "\01VERSION", 8) == 0)
- {
- irc_cmd_reply_version (server, ptr_channel, host, nick, pos);
- return 0;
- }
-
- /* unknown CTCP ? */
- pos2 = strchr (pos + 1, '\01');
- if ((pos[0] == '\01') && pos2 && (pos2[1] == '\0'))
- {
- command_ignored |= irc_ignore_check (host, "ctcp", ptr_channel->name, server->name);
- pos++;
- pos2[0] = '\0';
- pos2 = strchr (pos, ' ');
- if (pos2)
- {
- pos2[0] = '\0';
- pos2++;
- while (pos2[0] == ' ')
- pos2++;
- if (!pos2[0])
- pos2 = NULL;
- }
- if (!command_ignored)
- {
- irc_display_prefix (server, ptr_channel->buffer, GUI_PREFIX_SERVER);
- gui_printf (ptr_channel->buffer,
- _("Unknown CTCP %s%s%s received from %s%s"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- pos,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick);
- if (pos2)
- gui_printf (ptr_channel->buffer, "%s: %s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos2);
- else
- gui_printf (ptr_channel->buffer, "\n");
- }
- return 0;
- }
-
- /* other message */
- command_ignored |= irc_ignore_check (host, "privmsg", ptr_channel->name, server->name);
- if (!command_ignored)
- {
- ptr_nick = irc_nick_search (ptr_channel, nick);
- if (irc_recv_is_highlight (pos, server->nick))
- {
- irc_display_nick (ptr_channel->buffer, ptr_nick,
- (ptr_nick) ? NULL : nick,
- GUI_MSG_TYPE_NICK | GUI_MSG_TYPE_HIGHLIGHT,
- 1, GUI_COLOR_WIN_CHAT_HIGHLIGHT, 0);
- if ( (cfg_look_infobar)
- && (cfg_look_infobar_delay_highlight > 0)
- && (ptr_channel->buffer != gui_current_window->buffer) )
- gui_infobar_printf (cfg_look_infobar_delay_highlight,
- GUI_COLOR_WIN_INFOBAR_HIGHLIGHT,
- _("Channel %s: %s> %s"),
- ptr_channel->name, nick, pos);
- gui_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_MSG,
- "%s\n", pos);
-#ifdef PLUGINS
- (void) plugin_msg_handler_exec (server->name,
- "weechat_highlight",
- irc_last_command_received);
-#endif
- }
- else
- {
- irc_display_nick (ptr_channel->buffer, ptr_nick,
- (ptr_nick) ? NULL : nick,
- GUI_MSG_TYPE_NICK, 1, -1, 0);
- gui_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_MSG,
- "%s\n", pos);
- }
- irc_channel_add_nick_speaking (ptr_channel, nick);
- }
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s channel \"%s\" not found for \"%s\" command\n"),
- WEECHAT_ERROR, arguments, "privmsg");
- return -1;
- }
- }
- }
- else
- {
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- if (pos[0] == ':')
- pos++;
-
- /* version asked by another user => answer with WeeChat version */
- if (strncmp (pos, "\01VERSION", 8) == 0)
- {
- irc_cmd_reply_version (server, NULL, host, nick, pos);
- return 0;
- }
-
- /* ping request from another user => answer */
- if (strncmp (pos, "\01PING", 5) == 0)
- {
- command_ignored |= irc_ignore_check (host, "ctcp", NULL, server->name);
- if (!command_ignored)
- {
- pos += 5;
- while (pos[0] == ' ')
- pos++;
- pos2 = strchr (pos, '\01');
- if (pos2)
- pos2[0] = '\0';
- else
- pos = NULL;
- if (pos && !pos[0])
- pos = NULL;
- if (pos)
- irc_server_sendf (server, "NOTICE %s :\01PING %s\01",
- nick, pos);
- else
- irc_server_sendf (server, "NOTICE %s :\01PING\01",
- nick);
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer,
- _("CTCP %sPING%s received from %s%s\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick);
-#ifdef PLUGINS
- (void) plugin_msg_handler_exec (server->name,
- "weechat_ctcp",
- irc_last_command_received);
-#endif
- }
- return 0;
- }
-
- /* incoming DCC file */
- if (strncmp (pos, "\01DCC SEND", 9) == 0)
- {
- /* check if DCC SEND is ok, i.e. with 0x01 at end */
- pos2 = strchr (pos + 1, '\01');
- if (!pos2)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "privmsg");
- return -1;
- }
- pos2[0] = '\0';
-
- command_ignored |= irc_ignore_check (host, "dcc", NULL, server->name);
-
- if (!command_ignored)
- {
- /* DCC filename */
- pos_file = pos + 9;
- while (pos_file[0] == ' ')
- pos_file++;
-
- /* look for file size */
- pos_size = strrchr (pos_file, ' ');
- if (!pos_size)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "privmsg");
- return -1;
- }
- pos2 = pos_size;
- pos_size++;
- while (pos2[0] == ' ')
- pos2--;
- pos2[1] = '\0';
-
- /* look for DCC port */
- pos_port = strrchr (pos_file, ' ');
- if (!pos_port)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "privmsg");
- return -1;
- }
- pos2 = pos_port;
- pos_port++;
- while (pos2[0] == ' ')
- pos2--;
- pos2[1] = '\0';
-
- /* look for DCC IP address */
- pos_addr = strrchr (pos_file, ' ');
- if (!pos_addr)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "privmsg");
- return -1;
- }
- pos2 = pos_addr;
- pos_addr++;
- while (pos2[0] == ' ')
- pos2--;
- pos2[1] = '\0';
-
- irc_dcc_add (server, IRC_DCC_FILE_RECV,
- strtoul (pos_addr, NULL, 10),
- atoi (pos_port), nick, -1, pos_file, NULL,
- strtoul (pos_size, NULL, 10));
-#ifdef PLUGINS
- (void) plugin_msg_handler_exec (server->name,
- "weechat_dcc",
- irc_last_command_received);
-#endif
- }
- return 0;
- }
-
- /* incoming DCC RESUME (asked by receiver) */
- if (strncmp (pos, "\01DCC RESUME", 11) == 0)
- {
- /* check if DCC RESUME is ok, i.e. with 0x01 at end */
- pos2 = strchr (pos + 1, '\01');
- if (!pos2)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "privmsg");
- return -1;
- }
- pos2[0] = '\0';
-
- command_ignored |= irc_ignore_check (host, "dcc", NULL, server->name);
-
- if (!command_ignored)
- {
- /* DCC filename */
- pos_file = pos + 11;
- while (pos_file[0] == ' ')
- pos_file++;
-
- /* look for resume start position */
- pos_start_resume = strrchr (pos_file, ' ');
- if (!pos_start_resume)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "privmsg");
- return -1;
- }
- pos2 = pos_start_resume;
- pos_start_resume++;
- while (pos2[0] == ' ')
- pos2--;
- pos2[1] = '\0';
-
- /* look for DCC port */
- pos_port = strrchr (pos_file, ' ');
- if (!pos_port)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "privmsg");
- return -1;
- }
- pos2 = pos_port;
- pos_port++;
- while (pos2[0] == ' ')
- pos2--;
- pos2[1] = '\0';
-
- irc_dcc_accept_resume (server, pos_file, atoi (pos_port),
- strtoul (pos_start_resume, NULL, 10));
-#ifdef PLUGINS
- (void) plugin_msg_handler_exec (server->name,
- "weechat_dcc",
- irc_last_command_received);
-#endif
- }
- return 0;
- }
-
- /* incoming DCC ACCEPT (resume accepted by sender) */
- if (strncmp (pos, "\01DCC ACCEPT", 11) == 0)
- {
- /* check if DCC ACCEPT is ok, i.e. with 0x01 at end */
- pos2 = strchr (pos + 1, '\01');
- if (!pos2)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "privmsg");
- return -1;
- }
- pos2[0] = '\0';
-
- command_ignored |= irc_ignore_check (host, "dcc", NULL, server->name);
-
- if (!command_ignored)
- {
- /* DCC filename */
- pos_file = pos + 11;
- while (pos_file[0] == ' ')
- pos_file++;
-
- /* look for resume start position */
- pos_start_resume = strrchr (pos_file, ' ');
- if (!pos_start_resume)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "privmsg");
- return -1;
- }
- pos2 = pos_start_resume;
- pos_start_resume++;
- while (pos2[0] == ' ')
- pos2--;
- pos2[1] = '\0';
-
- /* look for DCC port */
- pos_port = strrchr (pos_file, ' ');
- if (!pos_port)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "privmsg");
- return -1;
- }
- pos2 = pos_port;
- pos_port++;
- while (pos2[0] == ' ')
- pos2--;
- pos2[1] = '\0';
-
- irc_dcc_start_resume (server, pos_file, atoi (pos_port),
- strtoul (pos_start_resume, NULL, 10));
-#ifdef PLUGINS
- (void) plugin_msg_handler_exec (server->name,
- "weechat_dcc",
- irc_last_command_received);
-#endif
- }
- return 0;
- }
-
- /* incoming DCC CHAT */
- if (strncmp (pos, "\01DCC CHAT", 9) == 0)
- {
- /* check if DCC CHAT is ok, i.e. with 0x01 at end */
- pos2 = strchr (pos + 1, '\01');
- if (!pos2)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "privmsg");
- return -1;
- }
- pos2[0] = '\0';
-
- command_ignored |= irc_ignore_check (host, "dcc", NULL, server->name);
-
- if (!command_ignored)
- {
- /* CHAT type */
- pos_file = pos + 9;
- while (pos_file[0] == ' ')
- pos_file++;
-
- /* DCC IP address */
- pos_addr = strchr (pos_file, ' ');
- if (!pos_addr)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "privmsg");
- return -1;
- }
- pos_addr[0] = '\0';
- pos_addr++;
- while (pos_addr[0] == ' ')
- pos_addr++;
-
- /* look for DCC port */
- pos_port = strchr (pos_addr, ' ');
- if (!pos_port)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "privmsg");
- return -1;
- }
- pos_port[0] = '\0';
- pos_port++;
- while (pos_port[0] == ' ')
- pos_port++;
-
- if (ascii_strcasecmp (pos_file, "chat") != 0)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s unknown DCC CHAT type received from "),
- WEECHAT_ERROR);
- gui_printf (server->buffer, "%s%s%s: \"%s\"\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_file);
- return -1;
- }
-
- irc_dcc_add (server, IRC_DCC_CHAT_RECV,
- strtoul (pos_addr, NULL, 10),
- atoi (pos_port), nick, -1, NULL, NULL, 0);
-#ifdef PLUGINS
- (void) plugin_msg_handler_exec (server->name,
- "weechat_dcc",
- irc_last_command_received);
-#endif
- }
- return 0;
- }
-
- /* private message received => display it */
- ptr_channel = irc_channel_search (server, nick);
-
- if (strncmp (pos, "\01ACTION ", 8) == 0)
- {
- command_ignored |= irc_ignore_check (host, "action", NULL, server->name);
- command_ignored |= irc_ignore_check (host, "pv", NULL, server->name);
-
- if (!command_ignored)
- {
- if (!ptr_channel)
- {
- ptr_channel = irc_channel_new (server,
- IRC_CHANNEL_TYPE_PRIVATE,
- nick);
- if (!ptr_channel)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot create new private window \"%s\"\n"),
- WEECHAT_ERROR, nick);
- return -1;
- }
- gui_buffer_new (gui_current_window, server, ptr_channel,
- GUI_BUFFER_TYPE_STANDARD, 0);
- }
- if (!ptr_channel->topic)
- {
- ptr_channel->topic = strdup (host2);
- gui_chat_draw_title (ptr_channel->buffer, 1);
- }
-
- pos += 8;
- pos2 = strchr (pos, '\01');
- if (pos2)
- pos2[0] = '\0';
- irc_display_prefix (server, ptr_channel->buffer, GUI_PREFIX_ACTION_ME);
- if (irc_recv_is_highlight (pos, server->nick))
- {
- gui_printf_type (ptr_channel->buffer,
- GUI_MSG_TYPE_MSG | GUI_MSG_TYPE_HIGHLIGHT,
- "%s%s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HIGHLIGHT),
- nick);
- if ( (cfg_look_infobar)
- && (cfg_look_infobar_delay_highlight > 0)
- && (ptr_channel->buffer != gui_current_window->buffer) )
- gui_infobar_printf (cfg_look_infobar_delay_highlight,
- GUI_COLOR_WIN_INFOBAR_HIGHLIGHT,
- _("Channel %s: * %s %s"),
- ptr_channel->name, nick, pos);
- gui_printf (ptr_channel->buffer, " %s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT), pos);
-#ifdef PLUGINS
- (void) plugin_msg_handler_exec (server->name,
- "weechat_highlight",
- irc_last_command_received);
-#endif
- }
- else
- {
- gui_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_MSG,
- "%s%s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick);
- gui_printf (ptr_channel->buffer, " %s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT), pos);
-#ifdef PLUGINS
- (void) plugin_msg_handler_exec (server->name,
- "weechat_pv",
- irc_last_command_received);
-#endif
- }
- }
- }
- else
- {
- /* unknown CTCP ? */
- pos2 = strchr (pos + 1, '\01');
- if ((pos[0] == '\01') && pos2 && (pos2[1] == '\0'))
- {
- command_ignored |= irc_ignore_check (host, "ctcp", NULL, server->name);
-
- if (!command_ignored)
- {
- pos++;
- pos2[0] = '\0';
- pos2 = strchr (pos, ' ');
- if (pos2)
- {
- pos2[0] = '\0';
- pos2++;
- while (pos2[0] == ' ')
- pos2++;
- if (!pos2[0])
- pos2 = NULL;
- }
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer,
- _("Unknown CTCP %s%s%s received from %s%s"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- pos,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick);
- if (pos2)
- gui_printf (server->buffer, "%s: %s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos2);
- else
- gui_printf (server->buffer, "\n");
-#ifdef PLUGINS
- (void) plugin_msg_handler_exec (server->name,
- "weechat_ctcp",
- irc_last_command_received);
-#endif
- }
- return 0;
- }
- else
- {
- command_ignored |= irc_ignore_check (host, "pv", NULL, server->name);
-
- if (!command_ignored)
- {
- if (!ptr_channel)
- {
- ptr_channel = irc_channel_new (server,
- IRC_CHANNEL_TYPE_PRIVATE,
- nick);
- if (!ptr_channel)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot create new private window \"%s\"\n"),
- WEECHAT_ERROR, nick);
- return -1;
- }
- gui_buffer_new (gui_current_window, server, ptr_channel,
- GUI_BUFFER_TYPE_STANDARD, 0);
- }
- if (!ptr_channel->topic)
- {
- ptr_channel->topic = strdup (host2);
- gui_chat_draw_title (ptr_channel->buffer, 1);
- }
-
- if (irc_recv_is_highlight (pos, server->nick))
- {
- irc_display_nick (ptr_channel->buffer, NULL, nick,
- GUI_MSG_TYPE_NICK | GUI_MSG_TYPE_HIGHLIGHT, 1,
- GUI_COLOR_WIN_CHAT_HIGHLIGHT, 0);
- if ((cfg_look_infobar_delay_highlight > 0)
- && (ptr_channel->buffer != gui_current_window->buffer))
- gui_infobar_printf (cfg_look_infobar_delay_highlight,
- GUI_COLOR_WIN_INFOBAR_HIGHLIGHT,
- _("Private %s> %s"),
- nick, pos);
- highlight = 1;
- }
- else
- {
- irc_display_nick (ptr_channel->buffer, NULL, nick,
- GUI_MSG_TYPE_NICK, 1, GUI_COLOR_WIN_NICK_PRIVATE, 0);
- highlight = 0;
- }
- gui_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_MSG,
- "%s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos);
-#ifdef PLUGINS
- (void) plugin_msg_handler_exec (server->name,
- "weechat_pv",
- irc_last_command_received);
- if (highlight)
- (void) plugin_msg_handler_exec (server->name,
- "weechat_highlight",
- irc_last_command_received);
-#endif
- }
- }
- }
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "privmsg");
- return -1;
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_quit: 'quit' command received
- */
-
-int
-irc_recv_cmd_quit (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos;
- t_irc_channel *ptr_channel;
- t_irc_nick *ptr_nick;
-
- /* no host => we can't identify sender of message! */
- if (!host)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command received without host\n"),
- WEECHAT_ERROR, "quit");
- return -1;
- }
-
- if (arguments[0] == ':')
- arguments++;
-
- for (ptr_channel = server->channels; ptr_channel;
- ptr_channel = ptr_channel->next_channel)
- {
- if ((ptr_channel->type == IRC_CHANNEL_TYPE_PRIVATE)
- || (ptr_channel->type == IRC_CHANNEL_TYPE_DCC_CHAT))
- ptr_nick = NULL;
- else
- ptr_nick = irc_nick_search (ptr_channel, nick);
-
- if (ptr_nick || (strcmp (ptr_channel->name, nick) == 0))
- {
- if (ptr_nick)
- irc_nick_free (ptr_channel, ptr_nick);
- if (!command_ignored
- && !irc_ignore_check (host, "quit", ptr_channel->name, server->name))
- {
- pos = strchr (host, '!');
- irc_display_prefix (server, ptr_channel->buffer, GUI_PREFIX_QUIT);
- gui_printf (ptr_channel->buffer,
- _("%s%s %s(%s%s%s)%s has quit"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- (pos) ? pos + 1 : "",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT));
- gui_printf (ptr_channel->buffer,
- " %s(%s%s%s)\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- arguments,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
- }
- gui_nicklist_draw (ptr_channel->buffer, 1, 1);
- gui_status_draw (ptr_channel->buffer, 1);
- }
- }
-
- return 0;
-}
-
-/*
- * irc_recv_cmd_server_mode_reason: command received from server (numeric),
- * format: "mode :reason"
- */
-
-int
-irc_recv_cmd_server_mode_reason (t_irc_server *server, char *host,
- char *nick, char *arguments)
-{
- char *ptr_msg;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- /* skip nickname if at beginning of server message */
- if (strncmp (server->nick, arguments, strlen (server->nick)) == 0)
- {
- arguments += strlen (server->nick) + 1;
- while (arguments[0] == ' ')
- arguments++;
- }
-
- ptr_msg = strchr (arguments, ' ');
- if (ptr_msg)
- {
- ptr_msg[0] = '\0';
- ptr_msg++;
- while (ptr_msg[0] == ' ')
- ptr_msg++;
- if (ptr_msg[0] == ':')
- ptr_msg++;
- }
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, "%s%s: %s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT), arguments,
- (ptr_msg) ? ptr_msg : "");
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_server_msg: command received from server (numeric)
- */
-
-int
-irc_recv_cmd_server_msg (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- while (arguments[0] == ' ')
- arguments++;
-
- /* skip nickname if at beginning of server message */
- if (strncasecmp (server->nick, arguments, strlen (server->nick)) == 0)
- {
- arguments += strlen (server->nick) + 1;
- while (arguments[0] == ' ')
- arguments++;
- }
-
- if (arguments[0] == ':')
- arguments++;
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, "%s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT), arguments);
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_server_reply: server reply
- */
-
-int
-irc_recv_cmd_server_reply (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos, *pos2;
- int first;
-
- /* make C compiler happy */
- (void) server;
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- }
- else
- pos = arguments;
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- first = 1;
-
- while (pos && pos[0])
- {
- pos2 = strchr (pos, ' ');
- if ((pos[0] == ':') || (!pos2))
- {
- if (pos[0] == ':')
- pos++;
- gui_printf (server->buffer, "%s%s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (first) ? "" : ": ",
- pos);
- pos = NULL;
- }
- else
- {
- pos2[0] = '\0';
- gui_printf (server->buffer, "%s%s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- (first) ? "" : " ",
- pos);
- first = 0;
- pos = pos2 + 1;
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_topic: 'topic' command received
- */
-
-int
-irc_recv_cmd_topic (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos;
- t_irc_channel *ptr_channel;
- t_gui_buffer *buffer;
-
- if (!irc_channel_is_channel (arguments))
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command received without channel\n"),
- WEECHAT_ERROR, "topic");
- return -1;
- }
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- if (pos[0] == ':')
- pos++;
- if (!pos[0])
- pos = NULL;
- }
-
- command_ignored |= irc_ignore_check (host, "topic", arguments, server->name);
-
- ptr_channel = irc_channel_search (server, arguments);
- buffer = (ptr_channel) ? ptr_channel->buffer : server->buffer;
-
- if (!command_ignored)
- {
- irc_display_prefix (server, buffer, GUI_PREFIX_INFO);
- if (pos)
- {
- gui_printf (buffer,
- _("%s%s%s has changed topic for %s%s%s to:"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- arguments,
- GUI_COLOR(GUI_COLOR_WIN_CHAT));
- gui_printf (buffer, " \"%s%s\"\n", pos, GUI_NO_COLOR);
- }
- else
- gui_printf (buffer,
- _("%s%s%s has unset topic for %s%s\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- arguments);
- }
-
- if (ptr_channel)
- {
- if (ptr_channel->topic)
- free (ptr_channel->topic);
- if (pos)
- ptr_channel->topic = strdup (pos);
- else
- ptr_channel->topic = strdup ("");
- gui_chat_draw_title (ptr_channel->buffer, 1);
- }
-
- return 0;
-}
-
-/*
- * irc_recv_cmd_wallops: 'wallops' command received
- */
-
-int
-irc_recv_cmd_wallops (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- command_ignored |= irc_ignore_check (host, "wallops", arguments, server->name);
-
- if (!command_ignored)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- if (arguments[0] == ':')
- arguments++;
- gui_printf (server->buffer,
- _("WALLOPS from %s%s%s: %s\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- arguments);
- }
-
- return 0;
-}
-
-/*
- * irc_recv_cmd_001: '001' command (connected to irc server)
- */
-
-int
-irc_recv_cmd_001 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos;
- char **commands, **ptr, *vars_replaced;
- char *away_msg;
-
- pos = strchr (arguments, ' ');
- if (pos)
- pos[0] = '\0';
- if (strcmp (server->nick, arguments) != 0)
- {
- free (server->nick);
- server->nick = strdup (arguments);
- }
-
- irc_recv_cmd_server_msg (server, host, nick, arguments);
-
- /* connection to IRC server is ok! */
- server->is_connected = 1;
- server->lag_next_check = time (NULL) + cfg_irc_lag_check;
-
- /* set away message if user was away (before disconnection for example) */
- if (server->away_message && server->away_message[0])
- {
- away_msg = strdup (server->away_message);
- if (away_msg)
- {
- irc_send_away (server, away_msg);
- free (away_msg);
- }
- }
-
- /* execute command when connected */
- if (server->command && server->command[0])
- {
- /* splitting command on ';' which can be escaped with '\;' */
- commands = split_multi_command (server->command, ';');
- if (commands)
- {
- for (ptr = commands; *ptr; ptr++)
- {
- vars_replaced = alias_replace_vars (server, NULL, *ptr);
- user_command (server, NULL,
- (vars_replaced) ? vars_replaced : *ptr, 0);
- if (vars_replaced)
- free (vars_replaced);
- }
- free_multi_command (commands);
- }
-
- if (server->command_delay > 0)
- server->command_time = time (NULL) + 1;
- else
- irc_server_autojoin_channels (server);
- }
- else
- irc_server_autojoin_channels (server);
-
- gui_status_draw (server->buffer, 1);
- gui_input_draw (server->buffer, 1);
-
- return 0;
-}
-
-/*
- * irc_recv_cmd_005: '005' command (some infos from server)
- */
-
-int
-irc_recv_cmd_005 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos, *pos2;
-
- irc_recv_cmd_server_msg (server, host, nick, arguments);
-
- pos = strstr (arguments, "PREFIX=");
- if (pos)
- {
- pos += 7;
- if (pos[0] == '(')
- {
- pos2 = strchr (pos, ')');
- if (!pos2)
- return 0;
- pos = pos2 + 1;
- }
- pos2 = strchr (pos, ' ');
- if (pos2)
- pos2[0] = '\0';
- if (server->prefix)
- free (server->prefix);
- server->prefix = strdup (pos);
- if (pos2)
- pos2[0] = ' ';
- }
-
- return 0;
-}
-
-/*
- * irc_recv_cmd_221: '221' command (user mode string)
- */
-
-int
-irc_recv_cmd_221 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_mode;
-
- /* make C compiler happy */
- (void) server;
- (void) host;
- (void) nick;
-
- pos_mode = strchr (arguments, ' ');
- if (pos_mode)
- {
- pos_mode[0] = '\0';
- pos_mode++;
- while (pos_mode[0] == ' ')
- pos_mode++;
-
- if (!command_ignored)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer,
- _("User mode for %s%s%s is %s[%s%s%s]\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- arguments,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_mode,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
- }
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "221");
- return -1;
- }
-
- return 0;
-}
-
-/*
- * irc_recv_cmd_301: '301' command (away message)
- */
-
-int
-irc_recv_cmd_301 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_nick, *pos_message;
- t_irc_channel *ptr_channel;
- t_gui_buffer *ptr_buffer;
-
- /* make C compiler happy */
- (void) server;
- (void) host;
- (void) nick;
-
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_message = strchr (pos_nick, ' ');
- if (pos_message)
- {
- pos_message[0] = '\0';
- pos_message++;
- while (pos_message[0] == ' ')
- pos_message++;
- if (pos_message[0] == ':')
- pos_message++;
-
- if (!command_ignored)
- {
- /* look for private buffer to display message */
- ptr_channel = irc_channel_search (server, pos_nick);
- if (!cfg_irc_show_away_once || !ptr_channel ||
- !(ptr_channel->away_message) ||
- (strcmp (ptr_channel->away_message, pos_message) != 0))
- {
- ptr_buffer = (ptr_channel) ? ptr_channel->buffer : server->buffer;
- irc_display_prefix (server, ptr_buffer, GUI_PREFIX_INFO);
- gui_printf (ptr_buffer,
- _("%s%s%s is away: %s\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_message);
- if (ptr_channel)
- {
- if (ptr_channel->away_message)
- free (ptr_channel->away_message);
- ptr_channel->away_message = strdup (pos_message);
- }
- }
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_302: '302' command (userhost)
- */
-
-int
-irc_recv_cmd_302 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_host, *ptr_next;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- arguments = strchr (arguments, ' ');
- if (arguments)
- {
- while (arguments[0] == ' ')
- arguments++;
- if (arguments[0] == ':')
- arguments++;
- while (arguments)
- {
- pos_host = strchr (arguments, '=');
- if (pos_host)
- {
- pos_host[0] = '\0';
- pos_host++;
-
- ptr_next = strchr (pos_host, ' ');
- if (ptr_next)
- {
- ptr_next[0] = '\0';
- ptr_next++;
- while (ptr_next[0] == ' ')
- ptr_next++;
- }
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, "%s%s%s=%s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- arguments,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- pos_host);
- }
- else
- ptr_next = NULL;
- arguments = ptr_next;
- if (arguments && !arguments[0])
- arguments = NULL;
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_303: '303' command (ison)
- */
-
-int
-irc_recv_cmd_303 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *ptr_next;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, _("Users online: "));
-
- arguments = strchr (arguments, ' ');
- if (arguments)
- {
- while (arguments[0] == ' ')
- arguments++;
- if (arguments[0] == ':')
- arguments++;
- while (arguments)
- {
- ptr_next = strchr (arguments, ' ');
- if (ptr_next)
- {
- ptr_next[0] = '\0';
- ptr_next++;
- while (ptr_next[0] == ' ')
- ptr_next++;
- }
- gui_printf (server->buffer, "%s%s ",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- arguments);
- arguments = ptr_next;
- if (arguments && !arguments[0])
- arguments = NULL;
- }
- }
- gui_printf (server->buffer, "\n");
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_305: '305' command (unaway)
- */
-
-int
-irc_recv_cmd_305 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- t_gui_window *ptr_win;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- arguments = strchr (arguments, ' ');
- if (arguments)
- {
- while (arguments[0] == ' ')
- arguments++;
- if (arguments[0] == ':')
- arguments++;
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, "%s\n", arguments);
- }
- }
- server->is_away = 0;
- server->away_time = 0;
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
- {
- if (GUI_SERVER(ptr_win->buffer) == server)
- gui_status_draw (ptr_win->buffer, 1);
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_306: '306' command (now away)
- */
-
-int
-irc_recv_cmd_306 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- t_gui_window *ptr_win;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- arguments = strchr (arguments, ' ');
- if (arguments)
- {
- while (arguments[0] == ' ')
- arguments++;
- if (arguments[0] == ':')
- arguments++;
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, "%s\n", arguments);
- }
- }
- server->is_away = 1;
- server->away_time = time (NULL);
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
- {
- if (GUI_SERVER(ptr_win->buffer) == server)
- gui_status_draw (ptr_win->buffer, 1);
- if (GUI_SERVER(ptr_win->buffer) == server)
- ptr_win->buffer->last_read_line =
- ptr_win->buffer->last_line;
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_whois_nick_msg: a whois command with nick and message
- */
-
-int
-irc_recv_cmd_whois_nick_msg (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_nick, *pos_msg;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_msg = strchr (pos_nick, ' ');
- if (pos_msg)
- {
- pos_msg[0] = '\0';
- pos_msg++;
- while (pos_msg[0] == ' ')
- pos_msg++;
- if (pos_msg[0] == ':')
- pos_msg++;
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, "%s[%s%s%s] %s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_msg);
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_310: '310' command (whois, help mode)
- */
-
-int
-irc_recv_cmd_310 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_nick;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- while (pos_nick[0] == ' ')
- pos_nick++;
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, _("%s[%s%s%s]%s help mode (+h)\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT));
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_311: '311' command (whois, user)
- */
-
-int
-irc_recv_cmd_311 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_nick, *pos_user, *pos_host, *pos_realname;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_user = strchr (pos_nick, ' ');
- if (pos_user)
- {
- pos_user[0] = '\0';
- pos_user++;
- while (pos_user[0] == ' ')
- pos_user++;
- pos_host = strchr (pos_user, ' ');
- if (pos_host)
- {
- pos_host[0] = '\0';
- pos_host++;
- while (pos_host[0] == ' ')
- pos_host++;
- pos_realname = strchr (pos_host, ' ');
- if (pos_realname)
- {
- pos_realname[0] = '\0';
- pos_realname++;
- while (pos_realname[0] == ' ')
- pos_realname++;
- if (pos_realname[0] == '*')
- pos_realname++;
- while (pos_realname[0] == ' ')
- pos_realname++;
- if (pos_realname[0] == ':')
- pos_realname++;
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer,
- "%s[%s%s%s] (%s%s@%s%s)%s: %s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- pos_user,
- pos_host,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_realname);
- }
- }
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_312: '312' command (whois, server)
- */
-
-int
-irc_recv_cmd_312 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_nick, *pos_server, *pos_serverinfo;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_server = strchr (pos_nick, ' ');
- if (pos_server)
- {
- pos_server[0] = '\0';
- pos_server++;
- while (pos_server[0] == ' ')
- pos_server++;
- pos_serverinfo = strchr (pos_server, ' ');
- if (pos_serverinfo)
- {
- pos_serverinfo[0] = '\0';
- pos_serverinfo++;
- while (pos_serverinfo[0] == ' ')
- pos_serverinfo++;
- if (pos_serverinfo[0] == ':')
- pos_serverinfo++;
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer,
- "%s[%s%s%s] %s%s %s(%s%s%s)\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_server,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_serverinfo,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
- }
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_314: '314' command (whowas)
- */
-
-int
-irc_recv_cmd_314 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_nick, *pos_user, *pos_host, *pos_realname;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_user = strchr (pos_nick, ' ');
- if (pos_user)
- {
- pos_user[0] = '\0';
- pos_user++;
- while (pos_user[0] == ' ')
- pos_user++;
- pos_host = strchr (pos_user, ' ');
- if (pos_host)
- {
- pos_host[0] = '\0';
- pos_host++;
- while (pos_host[0] == ' ')
- pos_host++;
- pos_realname = strchr (pos_host, ' ');
- if (pos_realname)
- {
- pos_realname[0] = '\0';
- pos_realname++;
- while (pos_realname[0] == ' ')
- pos_realname++;
- pos_realname = strchr (pos_realname, ' ');
- if (pos_realname)
- {
- pos_realname[0] = '\0';
- pos_realname++;
- while (pos_realname[0] == ' ')
- pos_realname++;
- if (pos_realname[0] == ':')
- pos_realname++;
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer,
- _("%s%s %s(%s%s@%s%s)%s was %s\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- pos_user,
- pos_host,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_realname);
- }
- }
- }
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_315: '315' command (end of /who)
- */
-
-int
-irc_recv_cmd_315 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos;
- t_irc_channel *ptr_channel;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- /* skip nickname if at beginning of server message */
- if (strncmp (server->nick, arguments, strlen (server->nick)) == 0)
- {
- arguments += strlen (server->nick) + 1;
- while (arguments[0] == ' ')
- arguments++;
- }
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- ptr_channel = irc_channel_search (server, arguments);
- if (ptr_channel && (ptr_channel->checking_away > 0))
- {
- ptr_channel->checking_away--;
- return 0;
- }
- if (!command_ignored)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, "%s%s %s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- arguments,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos);
- }
- }
- else
- {
- if (!command_ignored)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, "%s\n", arguments);
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_317: '317' command (whois, idle)
- */
-
-int
-irc_recv_cmd_317 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_nick, *pos_idle, *pos_signon, *pos_message;
- int idle_time, day, hour, min, sec;
- time_t datetime;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_idle = strchr (pos_nick, ' ');
- if (pos_idle)
- {
- pos_idle[0] = '\0';
- pos_idle++;
- while (pos_idle[0] == ' ')
- pos_idle++;
- pos_signon = strchr (pos_idle, ' ');
- if (pos_signon)
- {
- pos_signon[0] = '\0';
- pos_signon++;
- while (pos_signon[0] == ' ')
- pos_signon++;
- pos_message = strchr (pos_signon, ' ');
- if (pos_message)
- {
- pos_message[0] = '\0';
-
- idle_time = atoi (pos_idle);
- day = idle_time / (60 * 60 * 24);
- hour = (idle_time % (60 * 60 * 24)) / (60 * 60);
- min = ((idle_time % (60 * 60 * 24)) % (60 * 60)) / 60;
- sec = ((idle_time % (60 * 60 * 24)) % (60 * 60)) % 60;
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, _("%s[%s%s%s]%s idle: "),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT));
-
- if (day > 0)
- gui_printf (server->buffer, "%s%d %s%s, ",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- day,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (day > 1) ? _("days") : _("day"));
-
- datetime = (time_t)(atol (pos_signon));
- gui_printf (server->buffer,
- _("%s%02d %s%s %s%02d %s%s %s%02d %s%s, signon at: %s%s"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- hour,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (hour > 1) ? _("hours") : _("hour"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- min,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (min > 1) ? _("minutes") : _("minute"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- sec,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (sec > 1) ? _("seconds") : _("second"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- ctime (&datetime));
- }
- }
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_319: '319' command (whois, channels)
- */
-
-int
-irc_recv_cmd_319 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_nick, *pos_channel, *pos;
- int color;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_channel = strchr (pos_nick, ' ');
- if (pos_channel)
- {
- pos_channel[0] = '\0';
- pos_channel++;
- while (pos_channel[0] == ' ')
- pos_channel++;
- if (pos_channel[0] == ':')
- pos_channel++;
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, "%s[%s%s%s]%s Channels: ",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT));
- while (pos_channel && pos_channel[0])
- {
- if (irc_mode_nick_prefix_allowed (server, pos_channel[0]))
- {
- switch (pos_channel[0])
- {
- case '@': /* op */
- color = GUI_COLOR_WIN_NICK_OP;
- break;
- case '%': /* half-op */
- color = GUI_COLOR_WIN_NICK_HALFOP;
- break;
- case '+': /* voice */
- color = GUI_COLOR_WIN_NICK_VOICE;
- break;
- case '~': /* channel owner */
- color = GUI_COLOR_WIN_NICK_CHANOWNER;
- break;
- case '&': /* channel admin */
- color = GUI_COLOR_WIN_NICK_CHANADMIN;
- break;
- case '!': /* channel admin (2) */
- color = GUI_COLOR_WIN_NICK_CHANADMIN;
- break;
- case '-': /* channel user */
- color = GUI_COLOR_WIN_NICK_CHANUSER;
- break;
- default:
- color = GUI_COLOR_WIN_CHAT;
- break;
- }
- gui_printf (server->buffer, "%s%c",
- GUI_COLOR(GUI_COLOR_WIN_NICK_OP),
- pos_channel[0]);
- pos_channel++;
- }
-
- pos = strchr (pos_channel, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- }
- gui_printf (server->buffer, "%s%s%s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- pos_channel,
- (pos && pos[0]) ? " " : "\n");
- pos_channel = pos;
- }
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_321: '321' command (/list start)
- */
-
-int
-irc_recv_cmd_321 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- }
- else
- pos = arguments;
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, "%s\n", pos);
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_322: '322' command (channel for /list)
- */
-
-int
-irc_recv_cmd_322 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- }
- else
- pos = arguments;
-
- if (server->cmd_list_regexp)
- {
- if (regexec (server->cmd_list_regexp, pos, 0, NULL, 0) == 0) {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, "%s\n", pos);
- }
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, "%s\n", pos);
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_323: '323' command (/list end)
- */
-
-int
-irc_recv_cmd_323 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- }
- else
- pos = arguments;
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, "%s\n", pos);
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_324: '324' command (channel mode)
- */
-
-int
-irc_recv_cmd_324 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_channel, *pos_modes, *pos;
- t_irc_channel *ptr_channel;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- pos_channel = strchr (arguments, ' ');
- if (pos_channel)
- {
- pos_channel[0] = '\0';
- pos_channel++;
- while (pos_channel[0] == ' ')
- pos_channel++;
-
- pos_modes = strchr (pos_channel, ' ');
- if (pos_modes)
- {
- pos_modes[0] = '\0';
- pos_modes++;
- while (pos_modes[0] == ' ')
- pos_modes++;
-
- /* remove spaces after modes */
- pos = pos_modes + strlen (pos_modes) - 1;
- while ((pos >= pos_modes) && (pos[0] == ' '))
- {
- pos[0] = '\0';
- pos--;
- }
-
- /* search channel */
- ptr_channel = irc_channel_search (server, pos_channel);
- if (ptr_channel)
- {
- if (pos_modes[0])
- {
- if (ptr_channel->modes)
- ptr_channel->modes = (char *) realloc (ptr_channel->modes,
- strlen (pos_modes) + 1);
- else
- ptr_channel->modes = (char *) malloc (strlen (pos_modes) + 1);
- strcpy (ptr_channel->modes, pos_modes);
- irc_mode_channel_set (server, ptr_channel, pos_modes);
- }
- else
- {
- if (ptr_channel->modes)
- {
- free (ptr_channel->modes);
- ptr_channel->modes = NULL;
- }
- }
- gui_status_draw (ptr_channel->buffer, 1);
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_327: '327' command (whois, host)
- */
-
-int
-irc_recv_cmd_327 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_nick, *pos_host1, *pos_host2, *pos_other;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_host1 = strchr (pos_nick, ' ');
- if (pos_host1)
- {
- pos_host1[0] = '\0';
- pos_host1++;
- while (pos_host1[0] == ' ')
- pos_host1++;
- pos_host2 = strchr (pos_host1, ' ');
- if (pos_host2)
- {
- pos_host2[0] = '\0';
- pos_host2++;
- while (pos_host2[0] == ' ')
- pos_host2++;
-
- pos_other = strchr (pos_host2, ' ');
- if (pos_other)
- {
- pos_other[0] = '\0';
- pos_other++;
- while (pos_other[0] == ' ')
- pos_other++;
- }
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer,
- "%s[%s%s%s] %s%s %s %s%s%s%s%s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- pos_host1,
- pos_host2,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- (pos_other) ? "(" : "",
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (pos_other) ? pos_other : "",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- (pos_other) ? ")" : "");
- }
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_329: '329' command received (channel creation date)
- */
-
-int
-irc_recv_cmd_329 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_channel, *pos_date;
- t_irc_channel *ptr_channel;
- time_t datetime;
-
- /* make C compiler happy */
- (void) nick;
-
- pos_channel = strchr (arguments, ' ');
- if (pos_channel)
- {
- while (pos_channel[0] == ' ')
- pos_channel++;
- pos_date = strchr (pos_channel, ' ');
- if (pos_date)
- {
- pos_date[0] = '\0';
- pos_date++;
- while (pos_date[0] == ' ')
- pos_date++;
-
- ptr_channel = irc_channel_search (server, pos_channel);
- if (!ptr_channel)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s channel \"%s\" not found for \"%s\" command\n"),
- WEECHAT_ERROR, pos_channel, "329");
- return -1;
- }
-
- command_ignored |= irc_ignore_check (host, "329",
- pos_channel, server->name);
- if (!command_ignored && (ptr_channel->display_creation_date))
- {
- datetime = (time_t)(atol (pos_date));
- irc_display_prefix (server, ptr_channel->buffer, GUI_PREFIX_INFO);
- gui_printf (ptr_channel->buffer, _("Channel created on %s"),
- ctime (&datetime));
- }
- ptr_channel->display_creation_date = 0;
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot identify date/time for \"%s\" command\n"),
- WEECHAT_ERROR, "329");
- return -1;
- }
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot identify channel for \"%s\" command\n"),
- WEECHAT_ERROR, "329");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_331: '331' command received (no topic for channel)
- */
-
-int
-irc_recv_cmd_331 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_channel, *pos;
- t_irc_channel *ptr_channel;
-
- /* make C compiler happy */
- (void) server;
- (void) nick;
-
- if (!command_ignored)
- {
- pos_channel = strchr (arguments, ' ');
- if (pos_channel)
- {
- pos_channel++;
- while (pos_channel[0] == ' ')
- pos_channel++;
- pos = strchr (pos_channel, ' ');
- if (pos)
- pos[0] = '\0';
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s channel \"%s\" not found for \"%s\" command\n"),
- WEECHAT_ERROR, "", "331");
- return -1;
- }
-
- ptr_channel = irc_channel_search (server, pos_channel);
- command_ignored |= irc_ignore_check (host, "331",
- (ptr_channel) ? ptr_channel->name : NULL,
- server->name);
- if (!command_ignored)
- {
- irc_display_prefix (server,
- (ptr_channel) ? ptr_channel->buffer : NULL,
- GUI_PREFIX_INFO);
- gui_printf ((ptr_channel) ? ptr_channel->buffer : NULL,
- _("No topic set for %s%s\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- pos_channel);
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_332: '332' command received (topic of channel)
- */
-
-int
-irc_recv_cmd_332 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos, *pos2;
- t_irc_channel *ptr_channel;
- t_gui_buffer *ptr_buffer;
-
- /* make C compiler happy */
- (void) nick;
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- while (pos[0] == ' ')
- pos++;
- pos2 = strchr (pos, ' ');
- if (pos2)
- {
- pos2[0] = '\0';
- ptr_channel = irc_channel_search (server, pos);
- ptr_buffer = (ptr_channel) ?
- ptr_channel->buffer : server->buffer;
- pos2++;
- while (pos2[0] == ' ')
- pos2++;
- if (pos2[0] == ':')
- pos2++;
- if (ptr_channel)
- {
- if (ptr_channel->topic)
- free (ptr_channel->topic);
- ptr_channel->topic = strdup (pos2);
- }
-
- command_ignored |= irc_ignore_check (host, "332", pos, server->name);
- if (!command_ignored)
- {
- irc_display_prefix (server, ptr_buffer, GUI_PREFIX_INFO);
- gui_printf (ptr_buffer, _("Topic for %s%s%s is: "),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- pos,
- GUI_COLOR(GUI_COLOR_WIN_CHAT));
- gui_printf (ptr_buffer, "\"%s%s\"\n", pos2, GUI_NO_COLOR);
- }
-
- if (ptr_channel)
- gui_chat_draw_title (ptr_buffer, 1);
- }
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot identify channel for \"%s\" command\n"),
- WEECHAT_ERROR, "332");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_333: '333' command received (infos about topic (nick / date))
- */
-
-int
-irc_recv_cmd_333 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_channel, *pos_nick, *pos_date;
- t_irc_channel *ptr_channel;
- t_gui_buffer *ptr_buffer;
- time_t datetime;
-
- /* make C compiler happy */
- (void) nick;
-
- pos_channel = strchr (arguments, ' ');
- if (pos_channel)
- {
- while (pos_channel[0] == ' ')
- pos_channel++;
- pos_nick = strchr (pos_channel, ' ');
- if (pos_nick)
- {
- pos_nick[0] = '\0';
- pos_nick++;
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_date = strchr (pos_nick, ' ');
- if (pos_date)
- {
- pos_date[0] = '\0';
- pos_date++;
- while (pos_date[0] == ' ')
- pos_date++;
-
- ptr_channel = irc_channel_search (server, pos_channel);
- ptr_buffer = (ptr_channel) ?
- ptr_channel->buffer : server->buffer;
-
- command_ignored |= irc_ignore_check (host, "333",
- pos_channel, server->name);
- if (!command_ignored)
- {
- datetime = (time_t)(atol (pos_date));
- irc_display_prefix (server, ptr_buffer, GUI_PREFIX_INFO);
- gui_printf (ptr_buffer, _("Topic set by %s%s%s, %s"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- ctime (&datetime));
- }
- }
- else
- return 0;
- }
- else
- return 0;
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot identify channel for \"%s\" command\n"),
- WEECHAT_ERROR, "333");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_338: '338' command (whois, host)
- */
-
-int
-irc_recv_cmd_338 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_nick, *pos_host, *pos_message;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_host = strchr (pos_nick, ' ');
- if (pos_host)
- {
- pos_host[0] = '\0';
- pos_host++;
- while (pos_host[0] == ' ')
- pos_host++;
- pos_message = strchr (pos_host, ' ');
- if (pos_message)
- {
- pos_message[0] = '\0';
- pos_message++;
- while (pos_message[0] == ' ')
- pos_message++;
- if (pos_message[0] == ':')
- pos_message++;
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, "%s[%s%s%s] %s%s %s%s %s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_message,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- pos_host);
- }
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_341: '341' command received (inviting)
- */
-
-int
-irc_recv_cmd_341 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_nick, *pos_channel;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- pos_nick[0] = '\0';
- pos_nick++;
- while (pos_nick[0] == ' ')
- pos_nick++;
-
- pos_channel = strchr (pos_nick, ' ');
- if (pos_channel)
- {
- pos_channel[0] = '\0';
- pos_channel++;
- while (pos_channel[0] == ' ')
- pos_channel++;
- if (pos_channel[0] == ':')
- pos_channel++;
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer,
- _("%s%s%s has invited %s%s%s on %s%s\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- arguments,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- pos_channel);
- gui_status_draw (gui_current_window->buffer, 1);
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot identify channel for \"%s\" command\n"),
- WEECHAT_ERROR, "341");
- return -1;
- }
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot identify nickname for \"%s\" command\n"),
- WEECHAT_ERROR, "341");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_344: '344' command (channel reop)
- */
-
-int
-irc_recv_cmd_344 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_channel, *pos_host;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- pos_channel = strchr (arguments, ' ');
- if (pos_channel)
- {
- while (pos_channel[0] == ' ')
- pos_channel++;
- pos_host = strchr (pos_channel, ' ');
- if (pos_host)
- {
- pos_host[0] = '\0';
- pos_host++;
- while (pos_host[0] == ' ')
- pos_host++;
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, _("Channel reop %s%s%s: %s%s\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- pos_channel,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- pos_host);
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_345: '345' command (end of channel reop)
- */
-
-int
-irc_recv_cmd_345 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- /* skip nickname if at beginning of server message */
- if (strncmp (server->nick, arguments, strlen (server->nick)) == 0)
- {
- arguments += strlen (server->nick) + 1;
- while (arguments[0] == ' ')
- arguments++;
- }
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- if (!command_ignored)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, "%s%s %s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- arguments,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos);
- }
- }
- else
- {
- if (!command_ignored)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, "%s\n", arguments);
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_348: '348' command received (channel exception list)
- */
-
-int
-irc_recv_cmd_348 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_channel, *pos_exception, *pos_user, *pos_date, *pos;
- t_irc_channel *ptr_channel;
- t_gui_buffer *buffer;
- time_t datetime;
-
- /* make C compiler happy */
- (void) nick;
-
- /* look for channel */
- pos_channel = strchr (arguments, ' ');
- if (!pos_channel)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "348");
- return -1;
- }
- pos_channel[0] = '\0';
- pos_channel++;
- while (pos_channel[0] == ' ')
- pos_channel++;
-
- /* look for exception mask */
- pos_exception = strchr (pos_channel, ' ');
- if (!pos_exception)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "348");
- return -1;
- }
- pos_exception[0] = '\0';
- pos_exception++;
- while (pos_exception[0] == ' ')
- pos_exception++;
-
- /* look for user who set exception */
- pos_user = strchr (pos_exception, ' ');
- if (pos_user)
- {
- pos_user[0] = '\0';
- pos_user++;
- while (pos_user[0] == ' ')
- pos_user++;
-
- /* look for date/time */
- pos_date = strchr (pos_user, ' ');
- if (pos_date)
- {
- pos_date[0] = '\0';
- pos_date++;
- while (pos_date[0] == ' ')
- pos_date++;
- }
- }
- else
- pos_date = NULL;
-
- ptr_channel = irc_channel_search (server, pos_channel);
- buffer = (ptr_channel) ? ptr_channel->buffer : server->buffer;
-
- command_ignored |= irc_ignore_check (host, "348", pos_channel, server->name);
-
- if (!command_ignored)
- {
- irc_display_prefix (server, buffer, GUI_PREFIX_INFO);
- gui_printf (buffer, "%s[%s%s%s]%s exception %s%s%s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- pos_channel,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- pos_exception,
- GUI_COLOR(GUI_COLOR_WIN_CHAT));
- if (pos_user)
- {
- pos = strchr (pos_user, '!');
- if (pos)
- {
- pos[0] = '\0';
- gui_printf (buffer, _(" by %s%s %s(%s%s%s)"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_user,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- pos + 1,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
- }
- else
- gui_printf (buffer, _(" by %s%s"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_user);
- }
- if (pos_date)
- {
- datetime = (time_t)(atol (pos_date));
- gui_printf_nolog (buffer, "%s, %s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- ctime (&datetime));
- }
- else
- gui_printf_nolog (buffer, "\n");
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_349: '349' command received (end of channel exception list)
- */
-
-int
-irc_recv_cmd_349 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_channel, *pos_msg;
- t_irc_channel *ptr_channel;
- t_gui_buffer *buffer;
-
- /* make C compiler happy */
- (void) nick;
-
- pos_channel = strchr (arguments, ' ');
- if (!pos_channel)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "349");
- return -1;
- }
- pos_channel[0] = '\0';
- pos_channel++;
- while (pos_channel[0] == ' ')
- pos_channel++;
-
- pos_msg = strchr (pos_channel, ' ');
- if (!pos_msg)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "349");
- return -1;
- }
- pos_msg[0] = '\0';
- pos_msg++;
- while (pos_msg[0] == ' ')
- pos_msg++;
- if (pos_msg[0] == ':')
- pos_msg++;
-
- ptr_channel = irc_channel_search (server, pos_channel);
- buffer = (ptr_channel) ? ptr_channel->buffer : server->buffer;
-
- command_ignored |= irc_ignore_check (host, "349", pos_channel, server->name);
-
- if (!command_ignored)
- {
- irc_display_prefix (server, buffer, GUI_PREFIX_INFO);
- gui_printf (buffer, "%s[%s%s%s] %s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- pos_channel,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_msg);
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_351: '351' command received (server version)
- */
-
-int
-irc_recv_cmd_351 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos, *pos2;
-
- /* make C compiler happy */
- (void) server;
- (void) host;
- (void) nick;
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- }
- else
- pos = arguments;
-
- pos2 = strstr (pos, " :");
- if (pos2)
- {
- pos2[0] = '\0';
- pos2 += 2;
- }
-
- if (!command_ignored)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- if (pos2)
- gui_printf (server->buffer, "%s %s\n", pos, pos2);
- else
- gui_printf (server->buffer, "%s\n", pos);
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_352: '352' command (who)
- */
-
-int
-irc_recv_cmd_352 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_channel, *pos_user, *pos_host, *pos_server, *pos_nick;
- char *pos_attr, *pos_hopcount, *pos_realname;
- int length;
- t_irc_channel *ptr_channel;
- t_irc_nick *ptr_nick;
-
- /* make C compiler happy */
- (void) nick;
-
- pos_channel = strchr (arguments, ' ');
- if (pos_channel)
- {
- while (pos_channel[0] == ' ')
- pos_channel++;
- pos_user = strchr (pos_channel, ' ');
- if (pos_user)
- {
- pos_user[0] = '\0';
- pos_user++;
- while (pos_user[0] == ' ')
- pos_user++;
- pos_host = strchr (pos_user, ' ');
- if (pos_host)
- {
- pos_host[0] = '\0';
- pos_host++;
- while (pos_host[0] == ' ')
- pos_host++;
- pos_server = strchr (pos_host, ' ');
- if (pos_server)
- {
- pos_server[0] = '\0';
- pos_server++;
- while (pos_server[0] == ' ')
- pos_server++;
- pos_nick = strchr (pos_server, ' ');
- if (pos_nick)
- {
- pos_nick[0] = '\0';
- pos_nick++;
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_attr = strchr (pos_nick, ' ');
- if (pos_attr)
- {
- pos_attr[0] = '\0';
- pos_attr++;
- while (pos_attr[0] == ' ')
- pos_attr++;
- pos_hopcount = strchr (pos_attr, ' ');
- if (pos_hopcount)
- {
- pos_hopcount[0] = '\0';
- pos_hopcount++;
- while (pos_hopcount[0] == ' ')
- pos_hopcount++;
- if (pos_hopcount[0] == ':')
- pos_hopcount++;
- pos_realname = strchr (pos_hopcount, ' ');
- if (pos_realname)
- {
- pos_realname[0] = '\0';
- pos_realname++;
- while (pos_realname[0] == ' ')
- pos_realname++;
-
- command_ignored |= irc_ignore_check (host, "352", pos_channel, server->name);
-
- ptr_channel = irc_channel_search (server, pos_channel);
- if (ptr_channel && (ptr_channel->checking_away > 0))
- {
- ptr_nick = irc_nick_search (ptr_channel, pos_nick);
- if (ptr_nick)
- {
- if (ptr_nick->host)
- free (ptr_nick->host);
- length = strlen (pos_user) + 1 + strlen (pos_host) + 1;
- ptr_nick->host = (char *) malloc (length);
- if (ptr_nick->host)
- snprintf (ptr_nick->host, length, "%s@%s", pos_user, pos_host);
- irc_nick_set_away (ptr_channel, ptr_nick,
- (pos_attr[0] == 'G') ? 1 : 0);
- }
- return 0;
- }
-
- if (!command_ignored)
- {
- irc_display_prefix (server, server->buffer,
- GUI_PREFIX_SERVER);
- gui_printf (server->buffer,
- "%s%s%s on %s%s%s %s %s %s%s@%s %s(%s%s%s)\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- pos_channel,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_attr,
- pos_hopcount,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- pos_user,
- pos_host,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_realname,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_353: '353' command received (list of users on a channel)
- */
-
-int
-irc_recv_cmd_353 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos, *pos_nick;
- int is_chanowner, is_chanadmin, is_chanadmin2, is_op, is_halfop;
- int has_voice, is_chanuser;
- int prefix_found, color;
- t_irc_channel *ptr_channel;
- t_gui_buffer *ptr_buffer;
-
- /* make C compiler happy */
- (void) nick;
-
- pos = strstr (arguments, " = ");
- if (pos)
- arguments = pos + 3;
- else
- {
- pos = strstr (arguments, " * ");
- if (pos)
- arguments = pos + 3;
- else
- {
- pos = strstr (arguments, " @ ");
- if (pos)
- arguments = pos + 3;
- }
- }
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
-
- ptr_channel = irc_channel_search (server, arguments);
- if (ptr_channel)
- ptr_buffer = ptr_channel->buffer;
- else
- ptr_buffer = server->buffer;
-
- pos++;
- while (pos[0] == ' ')
- pos++;
- if (pos[0] != ':')
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "353");
- return -1;
- }
-
- command_ignored |= irc_ignore_check (host, "353",
- (ptr_channel) ? ptr_channel->name : NULL,
- server->name);
-
- /* channel is not joined => display users on server buffer */
- if (!command_ignored && !ptr_channel)
- {
- /* display users on channel */
- irc_display_prefix (server, ptr_buffer, GUI_PREFIX_SERVER);
- gui_printf (ptr_buffer, _("Nicks %s%s%s: %s["),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- arguments,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
- }
-
- pos++;
- if (pos[0])
- {
- while (pos && pos[0])
- {
- is_chanowner = 0;
- is_chanadmin = 0;
- is_chanadmin2 = 0;
- is_op = 0;
- is_halfop = 0;
- has_voice = 0;
- is_chanuser = 0;
- prefix_found = 1;
-
- while (prefix_found)
- {
- prefix_found = 0;
-
- if (irc_mode_nick_prefix_allowed (server, pos[0]))
- {
- prefix_found = 1;
- switch (pos[0])
- {
- case '@': /* op */
- is_op = 1;
- color = GUI_COLOR_WIN_NICK_OP;
- break;
- case '%': /* half-op */
- is_halfop = 1;
- color = GUI_COLOR_WIN_NICK_HALFOP;
- break;
- case '+': /* voice */
- has_voice = 1;
- color = GUI_COLOR_WIN_NICK_VOICE;
- break;
- case '~': /* channel owner */
- is_chanowner = 1;
- color = GUI_COLOR_WIN_NICK_CHANOWNER;
- break;
- case '&': /* channel admin */
- is_chanadmin = 1;
- color = GUI_COLOR_WIN_NICK_CHANADMIN;
- break;
- case '!': /* channel admin (2) */
- is_chanadmin2 = 1;
- color = GUI_COLOR_WIN_NICK_CHANADMIN;
- break;
- case '-': /* channel user */
- is_chanuser = 1;
- color = GUI_COLOR_WIN_NICK_CHANUSER;
- break;
- default:
- color = GUI_COLOR_WIN_CHAT;
- break;
- }
- if (!command_ignored && !ptr_channel)
- gui_printf (ptr_buffer, "%s%c",
- GUI_COLOR(color),
- pos[0]);
- }
- if (prefix_found)
- pos++;
- }
- pos_nick = pos;
- pos = strchr (pos, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- }
- if (ptr_channel)
- {
- if (!irc_nick_new (server, ptr_channel, pos_nick,
- is_chanowner, is_chanadmin, is_chanadmin2,
- is_op, is_halfop, has_voice, is_chanuser))
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot create nick \"%s\" for channel \"%s\"\n"),
- WEECHAT_ERROR, pos_nick, ptr_channel->name);
- }
- }
- else
- {
- if (!command_ignored)
- {
- gui_printf (ptr_buffer, "%s%s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT), pos_nick);
- if (pos && pos[0])
- gui_printf (ptr_buffer, " ");
- }
- }
- }
- }
- if (ptr_channel)
- {
- gui_nicklist_draw (ptr_channel->buffer, 1, 1);
- gui_status_draw (ptr_channel->buffer, 1);
- }
- else
- {
- if (!command_ignored)
- gui_printf (ptr_buffer, "%s]\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
- }
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "353");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_366: '366' command received (end of /names list)
- */
-
-int
-irc_recv_cmd_366 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos, *pos2;
- t_irc_channel *ptr_channel;
- t_irc_nick *ptr_nick;
- int num_nicks, num_op, num_halfop, num_voice, num_normal;
-
- /* make C compiler happy */
- (void) nick;
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- while (pos[0] == ' ')
- pos++;
- pos2 = strchr (pos, ' ');
- if (pos2)
- {
- pos2[0] = '\0';
- pos2++;
- while (pos2[0] == ' ')
- pos2++;
- if (pos2[0] == ':')
- pos2++;
-
- ptr_channel = irc_channel_search (server, pos);
- if (ptr_channel)
- {
- command_ignored |= irc_ignore_check (host, "366", ptr_channel->name, server->name);
-
- if (!command_ignored)
- {
- /* display users on channel */
- irc_display_prefix (server, ptr_channel->buffer, GUI_PREFIX_SERVER);
- gui_printf (ptr_channel->buffer, _("Nicks %s%s%s: %s["),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- ptr_channel->name,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
-
- for (ptr_nick = ptr_channel->nicks; ptr_nick; ptr_nick = ptr_nick->next_nick)
- {
- irc_display_nick (ptr_channel->buffer, ptr_nick, NULL,
- GUI_MSG_TYPE_MSG, 0, GUI_COLOR_WIN_CHAT, 1);
- if (ptr_nick != ptr_channel->last_nick)
- gui_printf (ptr_channel->buffer, " ");
- }
- gui_printf (ptr_channel->buffer, "%s]\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
-
- /* display number of nicks, ops, halfops & voices on the channel */
- irc_nick_count (ptr_channel, &num_nicks, &num_op, &num_halfop, &num_voice,
- &num_normal);
- irc_display_prefix (server, ptr_channel->buffer, GUI_PREFIX_INFO);
- gui_printf (ptr_channel->buffer,
- _("Channel %s%s%s: %s%d%s %s %s(%s%d%s %s, "
- "%s%d%s %s, %s%d%s %s, %s%d%s %s%s)\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- ptr_channel->name,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- num_nicks,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (num_nicks > 1) ? _("nicks") : _("nick"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- num_op,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (num_op > 1) ? _("ops") : _("op"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- num_halfop,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (num_halfop > 1) ? _("halfops") : _("halfop"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- num_voice,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (num_voice > 1) ? _("voices") : _("voice"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- num_normal,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- _("normal"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
- }
- irc_send_cmd_mode (server, NULL, ptr_channel->name);
- irc_channel_check_away (server, ptr_channel, 1);
- }
- else
- {
- if (!command_ignored)
- {
- irc_display_prefix (server, gui_current_window->buffer, GUI_PREFIX_INFO);
- gui_printf (gui_current_window->buffer, "%s%s%s: %s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- pos,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos2);
- }
- return 0;
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_367: '367' command received (banlist)
- */
-
-int
-irc_recv_cmd_367 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_channel, *pos_ban, *pos_user, *pos_date, *pos;
- t_irc_channel *ptr_channel;
- t_gui_buffer *buffer;
- time_t datetime;
-
- /* make C compiler happy */
- (void) nick;
-
- /* look for channel */
- pos_channel = strchr (arguments, ' ');
- if (!pos_channel)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "367");
- return -1;
- }
- pos_channel[0] = '\0';
- pos_channel++;
- while (pos_channel[0] == ' ')
- pos_channel++;
-
- /* look for ban mask */
- pos_ban = strchr (pos_channel, ' ');
- if (!pos_ban)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "367");
- return -1;
- }
- pos_ban[0] = '\0';
- pos_ban++;
- while (pos_ban[0] == ' ')
- pos_ban++;
-
- /* look for user who set ban */
- pos_date = NULL;
- pos_user = strchr (pos_ban, ' ');
- if (pos_user)
- {
- pos_user[0] = '\0';
- pos_user++;
- while (pos_user[0] == ' ')
- pos_user++;
-
- /* look for date/time */
- pos_date = strchr (pos_user, ' ');
- if (pos_date)
- {
- pos_date[0] = '\0';
- pos_date++;
- while (pos_date[0] == ' ')
- pos_date++;
- }
- }
-
- ptr_channel = irc_channel_search (server, pos_channel);
- buffer = (ptr_channel) ? ptr_channel->buffer : server->buffer;
-
- command_ignored |= irc_ignore_check (host, "367", pos_channel, server->name);
-
- if (!command_ignored)
- {
- irc_display_prefix (server, buffer, GUI_PREFIX_INFO);
- if (pos_user)
- {
- gui_printf_nolog (buffer, _("%s[%s%s%s] %s%s%s banned by "),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- pos_channel,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- pos_ban,
- GUI_COLOR(GUI_COLOR_WIN_CHAT));
- pos = strchr (pos_user, '!');
- if (pos)
- {
- pos[0] = '\0';
- gui_printf (buffer, "%s%s %s(%s%s%s)",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_user,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- pos + 1,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
- }
- else
- gui_printf (buffer, "%s%s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_user);
- if (pos_date)
- {
- datetime = (time_t)(atol (pos_date));
- gui_printf (buffer, "%s, %s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- ctime (&datetime));
- }
- else
- gui_printf (buffer, "\n");
- }
- else
- gui_printf_nolog (buffer, _("%s[%s%s%s] %s%s%s banned\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- pos_channel,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST),
- pos_ban,
- GUI_COLOR(GUI_COLOR_WIN_CHAT));
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_368: '368' command received (end of banlist)
- */
-
-int
-irc_recv_cmd_368 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_channel, *pos_msg;
- t_irc_channel *ptr_channel;
- t_gui_buffer *buffer;
-
- /* make C compiler happy */
- (void) nick;
-
- pos_channel = strchr (arguments, ' ');
- if (!pos_channel)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "368");
- return -1;
- }
- pos_channel[0] = '\0';
- pos_channel++;
- while (pos_channel[0] == ' ')
- pos_channel++;
-
- pos_msg = strchr (pos_channel, ' ');
- if (!pos_msg)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "368");
- return -1;
- }
- pos_msg[0] = '\0';
- pos_msg++;
- while (pos_msg[0] == ' ')
- pos_msg++;
- if (pos_msg[0] == ':')
- pos_msg++;
-
- ptr_channel = irc_channel_search (server, pos_channel);
- buffer = (ptr_channel) ? ptr_channel->buffer : server->buffer;
-
- command_ignored |= irc_ignore_check (host, "368", pos_channel, server->name);
-
- if (!command_ignored)
- {
- irc_display_prefix (server, buffer, GUI_PREFIX_INFO);
- gui_printf_nolog (buffer, "%s[%s%s%s] %s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- pos_channel,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_msg);
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_432: '432' command received (erroneous nickname)
- */
-
-int
-irc_recv_cmd_432 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- /* Note: this IRC command can not be ignored */
-
- irc_recv_cmd_error (server, host, nick, arguments);
-
- if (!server->is_connected)
- {
- if (strcmp (server->nick, server->nick1) == 0)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_INFO);
- gui_printf (server->buffer,
- _("%s: trying 2nd nickname \"%s\"\n"),
- PACKAGE_NAME, server->nick2);
- free (server->nick);
- server->nick = strdup (server->nick2);
- }
- else
- {
- if (strcmp (server->nick, server->nick2) == 0)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_INFO);
- gui_printf (server->buffer,
- _("%s: trying 3rd nickname \"%s\"\n"),
- PACKAGE_NAME, server->nick3);
- free (server->nick);
- server->nick = strdup (server->nick3);
- }
- else
- {
- if (strcmp (server->nick, server->nick3) == 0)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_INFO);
- gui_printf (server->buffer,
- _("%s: all declared nicknames are already in "
- "use or invalid, closing connection with "
- "server!\n"),
- PACKAGE_NAME);
- irc_server_disconnect (server, 1);
- return 0;
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_INFO);
- gui_printf (server->buffer,
- _("%s: trying 1st nickname \"%s\"\n"),
- PACKAGE_NAME, server->nick1);
- free (server->nick);
- server->nick = strdup (server->nick1);
- }
- }
- }
- irc_server_sendf (server, "NICK %s", server->nick);
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_433: '433' command received (nickname already in use)
- */
-
-int
-irc_recv_cmd_433 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- /* Note: this IRC command can not be ignored */
-
- if (!server->is_connected)
- {
- if (strcmp (server->nick, server->nick1) == 0)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_INFO);
- gui_printf (server->buffer,
- _("%s: nickname \"%s\" is already in use, "
- "trying 2nd nickname \"%s\"\n"),
- PACKAGE_NAME, server->nick, server->nick2);
- free (server->nick);
- server->nick = strdup (server->nick2);
- }
- else
- {
- if (strcmp (server->nick, server->nick2) == 0)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_INFO);
- gui_printf (server->buffer,
- _("%s: nickname \"%s\" is already in use, "
- "trying 3rd nickname \"%s\"\n"),
- PACKAGE_NAME, server->nick, server->nick3);
- free (server->nick);
- server->nick = strdup (server->nick3);
- }
- else
- {
- if (strcmp (server->nick, server->nick3) == 0)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_INFO);
- gui_printf (server->buffer,
- _("%s: all declared nicknames are already in use, "
- "closing connection with server!\n"),
- PACKAGE_NAME);
- irc_server_disconnect (server, 1);
- return 0;
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_INFO);
- gui_printf (server->buffer,
- _("%s: nickname \"%s\" is already in use, "
- "trying 1st nickname \"%s\"\n"),
- PACKAGE_NAME, server->nick, server->nick1);
- free (server->nick);
- server->nick = strdup (server->nick1);
- }
- }
- }
- irc_server_sendf (server, "NICK %s", server->nick);
- }
- else
- return irc_recv_cmd_error (server, host, nick, arguments);
-
- return 0;
-}
-
-/*
- * irc_recv_cmd_438: '438' command received (not authorized to change nickname)
- */
-
-int
-irc_recv_cmd_438 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos, *pos2;
-
- /* make C compiler happy */
- (void) server;
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- pos = strchr (arguments, ' ');
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- if (pos)
- {
- pos[0] = '\0';
- pos++;
-
- pos2 = strstr (pos, " :");
- if (pos2)
- {
- pos2[0] = '\0';
- pos2 += 2;
- gui_printf (server->buffer, "%s (%s => %s)\n", pos2, arguments, pos);
- }
- else
- gui_printf (server->buffer, "%s (%s)\n", pos, arguments);
- }
- else
- gui_printf (server->buffer, "%s\n", arguments);
- }
- return 0;
-}
-
-/*
- * irc_recv_cmd_671: '671' command (whois, secure connection)
- */
-
-int
-irc_recv_cmd_671 (t_irc_server *server, char *host, char *nick, char *arguments)
-{
- char *pos_nick, *pos_message;
-
- /* make C compiler happy */
- (void) host;
- (void) nick;
-
- if (!command_ignored)
- {
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_message = strchr (pos_nick, ' ');
- if (pos_message)
- {
- pos_message[0] = '\0';
- pos_message++;
- while (pos_message[0] == ' ')
- pos_message++;
- if (pos_message[0] == ':')
- pos_message++;
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, "%s[%s%s%s] %s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- pos_nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_message);
- }
- }
- }
- return 0;
-}
diff --git a/src/plugins/irc/irc-send.c b/src/plugins/irc/irc-send.c
deleted file mode 100644
index a4d71d498..000000000
--- a/src/plugins/irc/irc-send.c
+++ /dev/null
@@ -1,2281 +0,0 @@
-/*
- * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
- */
-
-/* irc-send.c: implementation of IRC commands (client to server),
- according to RFC 1459,2810,2811,2812 */
-
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include <sys/time.h>
-#include <netdb.h>
-#include <time.h>
-#include <sys/utsname.h>
-#include <regex.h>
-
-#include "../../common/weechat.h"
-#include "irc.h"
-#include "../../common/command.h"
-#include "../../common/util.h"
-#include "../../common/weeconfig.h"
-#include "../../gui/gui.h"
-
-
-/*
- * irc_send_login: login to irc server
- */
-
-void
-irc_send_login (t_irc_server *server)
-{
- if ((server->password) && (server->password[0]))
- irc_server_sendf (server, "PASS %s", server->password);
-
- if (!server->nick)
- server->nick = strdup (server->nick1);
- irc_server_sendf (server,
- "NICK %s\n"
- "USER %s %s %s :%s",
- server->nick, server->username, server->username,
- server->address, server->realname);
- gui_input_draw (gui_current_window->buffer, 1);
-}
-
-/*
- * irc_send_cmd_admin: find information about the administrator of the server
- */
-
-int
-irc_send_cmd_admin (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- if (arguments)
- irc_server_sendf (server, "ADMIN %s", arguments);
- else
- irc_server_sendf (server, "ADMIN");
- return 0;
-}
-
-/*
- * irc_send_me: send a ctcp action to a channel
- */
-
-int
-irc_send_me (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- char *string;
-
- irc_server_sendf (server, "PRIVMSG %s :\01ACTION %s\01",
- channel->name,
- (arguments && arguments[0]) ? arguments : "");
- irc_display_prefix (NULL, channel->buffer, GUI_PREFIX_ACTION_ME);
- string = (arguments && arguments[0]) ?
- (char *)gui_color_decode ((unsigned char *)arguments, 1, 0) : NULL;
- gui_printf (channel->buffer, "%s%s %s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- server->nick,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (string) ? string : "");
- if (string)
- free (string);
- return 0;
-}
-
-/*
- * irc_send_me_all_channels: send a ctcp action to all channels of a server
- */
-
-int
-irc_send_me_all_channels (t_irc_server *server, char *arguments)
-{
- t_irc_channel *ptr_channel;
-
- for (ptr_channel = server->channels; ptr_channel;
- ptr_channel = ptr_channel->next_channel)
- {
- if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL)
- irc_send_me (server, ptr_channel, arguments);
- }
- return 0;
-}
-
-/*
- * irc_send_cmd_ame: send a ctcp action to all channels of all connected servers
- */
-
-int
-irc_send_cmd_ame (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- t_irc_server *ptr_server;
- t_irc_channel *ptr_channel;
-
- /* make C compiler happy */
- (void) server;
- (void) channel;
-
- gui_add_hotlist = 0;
- for (ptr_server = irc_servers; ptr_server;
- ptr_server = ptr_server->next_server)
- {
- if (ptr_server->is_connected)
- {
- for (ptr_channel = ptr_server->channels; ptr_channel;
- ptr_channel = ptr_channel->next_channel)
- {
- if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL)
- irc_send_me (ptr_server, ptr_channel, arguments);
- }
- }
- }
- gui_add_hotlist = 1;
- return 0;
-}
-
-/*
- * irc_send_cmd_amsg: send message to all channels of all connected servers
- */
-
-int
-irc_send_cmd_amsg (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- t_irc_server *ptr_server;
- t_irc_channel *ptr_channel;
- t_irc_nick *ptr_nick;
- char *string;
-
- /* make C compiler happy */
- (void) server;
- (void) channel;
-
- if (arguments)
- {
- gui_add_hotlist = 0;
- for (ptr_server = irc_servers; ptr_server;
- ptr_server = ptr_server->next_server)
- {
- if (ptr_server->is_connected)
- {
- for (ptr_channel = ptr_server->channels; ptr_channel;
- ptr_channel = ptr_channel->next_channel)
- {
- if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL)
- {
- irc_server_sendf (ptr_server, "PRIVMSG %s :%s",
- ptr_channel->name, arguments);
- ptr_nick = irc_nick_search (ptr_channel, ptr_server->nick);
- if (ptr_nick)
- {
- irc_display_nick (ptr_channel->buffer, ptr_nick, NULL,
- GUI_MSG_TYPE_NICK, 1, -1, 0);
- string = (char *)gui_color_decode ((unsigned char *)arguments, 1, 0);
- gui_printf (ptr_channel->buffer, "%s\n", (string) ? string : arguments);
- if (string)
- free (string);
- }
- else
- {
- irc_display_prefix (ptr_server, ptr_server->buffer, GUI_PREFIX_ERROR);
- gui_printf (ptr_server->buffer,
- _("%s cannot find nick for sending message\n"),
- WEECHAT_ERROR);
- }
- }
- }
- }
- }
- gui_add_hotlist = 1;
- }
- else
- return -1;
- return 0;
-}
-
-/*
- * irc_send_away: toggle away status for one server
- */
-
-void
-irc_send_away (t_irc_server *server, char *arguments)
-{
- char *string, buffer[4096];
- t_gui_window *ptr_window;
- time_t time_now, elapsed;
-
- if (!server)
- return;
-
- if (arguments)
- {
- if (server->away_message)
- free (server->away_message);
- server->away_message = (char *) malloc (strlen (arguments) + 1);
- if (server->away_message)
- strcpy (server->away_message, arguments);
-
- /* if server is connected, send away command now */
- if (server->is_connected)
- {
- server->is_away = 1;
- server->away_time = time (NULL);
- irc_server_sendf (server, "AWAY :%s", arguments);
- if (cfg_irc_display_away != CFG_IRC_DISPLAY_AWAY_OFF)
- {
- string = (char *)gui_color_decode ((unsigned char *)arguments, 1, 0);
- if (cfg_irc_display_away == CFG_IRC_DISPLAY_AWAY_LOCAL)
- irc_display_away (server, "away", (string) ? string : arguments);
- else
- {
- snprintf (buffer, sizeof (buffer), "is away: %s", (string) ? string : arguments);
- irc_send_me_all_channels (server, buffer);
- }
- if (string)
- free (string);
- }
- irc_server_set_away (server, server->nick, 1);
- for (ptr_window = gui_windows; ptr_window;
- ptr_window = ptr_window->next_window)
- {
- if (GUI_SERVER(ptr_window->buffer) == server)
- ptr_window->buffer->last_read_line =
- ptr_window->buffer->last_line;
- }
- }
- else
- {
- /* server not connected, store away for future usage
- (when connecting to server) */
- string = (char *)gui_color_decode ((unsigned char *)arguments, 1, 0);
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_INFO);
- gui_printf_nolog (server->buffer,
- _("Future away on %s%s%s: %s\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER),
- server->name,
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (string) ? string : arguments);
- if (string)
- free (string);
- }
- }
- else
- {
- if (server->away_message)
- {
- free (server->away_message);
- server->away_message = NULL;
- }
-
- /* if server is connected, send away command now */
- if (server->is_connected)
- {
- irc_server_sendf (server, "AWAY");
- server->is_away = 0;
- if (server->away_time != 0)
- {
- time_now = time (NULL);
- elapsed = (time_now >= server->away_time) ?
- time_now - server->away_time : 0;
- server->away_time = 0;
- if (cfg_irc_display_away != CFG_IRC_DISPLAY_AWAY_OFF)
- {
- if (cfg_irc_display_away == CFG_IRC_DISPLAY_AWAY_LOCAL)
- {
- snprintf (buffer, sizeof (buffer),
- "gone %.2ld:%.2ld:%.2ld",
- (long int)(elapsed / 3600),
- (long int)((elapsed / 60) % 60),
- (long int)(elapsed % 60));
- irc_display_away (server, "back", buffer);
- }
- else
- {
- snprintf (buffer, sizeof (buffer),
- "is back (gone %.2ld:%.2ld:%.2ld)",
- (long int)(elapsed / 3600),
- (long int)((elapsed / 60) % 60),
- (long int)(elapsed % 60));
- irc_send_me_all_channels (server, buffer);
- }
- }
- }
- irc_server_set_away (server, server->nick, 0);
- }
- else
- {
- /* server not connected, remove away message but do not send anything */
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_INFO);
- gui_printf_nolog (server->buffer,
- _("Future away on %s%s%s removed.\n"),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER),
- server->name,
- GUI_COLOR(GUI_COLOR_WIN_CHAT));
- }
- }
-}
-
-/*
- * irc_send_cmd_away: toggle away status
- */
-
-int
-irc_send_cmd_away (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- t_gui_buffer *buffer;
- char *pos;
- t_irc_server *ptr_server;
-
- gui_buffer_find_context (server, channel, NULL, &buffer);
-
- /* make C compiler happy */
- (void) channel;
-
- gui_add_hotlist = 0;
- if (arguments && (strncmp (arguments, "-all", 4) == 0))
- {
- pos = arguments + 4;
- while (pos[0] == ' ')
- pos++;
- if (!pos[0])
- pos = NULL;
-
- for (ptr_server = irc_servers; ptr_server;
- ptr_server = ptr_server->next_server)
- {
- if (ptr_server->is_connected)
- irc_send_away (ptr_server, pos);
- }
- }
- else
- irc_send_away (server, arguments);
-
- gui_status_draw (buffer, 1);
- gui_add_hotlist = 1;
- return 0;
-}
-
-/*
- * irc_send_cmd_ban: bans nicks or hosts
- */
-
-int
-irc_send_cmd_ban (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- t_gui_buffer *buffer;
- char *pos_channel, *pos, *pos2;
-
- gui_buffer_find_context (server, channel, NULL, &buffer);
-
- if (arguments)
- {
- pos_channel = NULL;
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
-
- if (irc_channel_is_channel (arguments))
- {
- pos_channel = arguments;
- pos++;
- while (pos[0] == ' ')
- pos++;
- }
- else
- {
- pos[0] = ' ';
- pos = arguments;
- }
- }
- else
- pos = arguments;
-
- /* channel not given, use default buffer */
- if (!pos_channel)
- {
- if (!GUI_BUFFER_IS_CHANNEL(buffer))
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can only be executed in a channel buffer\n"),
- WEECHAT_ERROR, "ban");
- return -1;
- }
- pos_channel = GUI_CHANNEL(buffer)->name;
- }
-
- /* loop on users */
- while (pos && pos[0])
- {
- pos2 = strchr (pos, ' ');
- if (pos2)
- {
- pos2[0] = '\0';
- pos2++;
- while (pos2[0] == ' ')
- pos2++;
- }
- irc_server_sendf (server, "MODE %s +b %s", pos_channel, pos);
- pos = pos2;
- }
- }
- else
- {
- if (!GUI_BUFFER_IS_CHANNEL(buffer))
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can only be executed in a channel buffer\n"),
- WEECHAT_ERROR, "ban");
- return -1;
- }
- irc_server_sendf (server, "MODE %s +b", GUI_CHANNEL(buffer)->name);
- }
-
- return 0;
-}
-
-/*
- * irc_send_cmd_ctcp: send a ctcp message
- */
-
-int
-irc_send_cmd_ctcp (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- char *pos_type, *pos_args, *pos;
- struct timeval tv;
-
- /* make C compiler happy */
- (void) channel;
-
- pos_type = strchr (arguments, ' ');
- if (pos_type)
- {
- pos_type[0] = '\0';
- pos_type++;
- while (pos_type[0] == ' ')
- pos_type++;
- pos_args = strchr (pos_type, ' ');
- if (pos_args)
- {
- pos_args[0] = '\0';
- pos_args++;
- while (pos_args[0] == ' ')
- pos_args++;
- }
- else
- pos_args = NULL;
-
- pos = pos_type;
- while (pos[0])
- {
- pos[0] = toupper (pos[0]);
- pos++;
- }
-
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, "CTCP%s(%s%s%s)%s: %s%s",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- arguments,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
- pos_type);
-
- if ((ascii_strcasecmp (pos_type, "ping") == 0) && (!pos_args))
- {
- gettimeofday (&tv, NULL);
- irc_server_sendf (server, "PRIVMSG %s :\01PING %d %d\01",
- arguments, tv.tv_sec, tv.tv_usec);
- gui_printf (server->buffer, " %s%d %d\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- tv.tv_sec, tv.tv_usec);
- }
- else
- {
- if (pos_args)
- {
- irc_server_sendf (server, "PRIVMSG %s :\01%s %s\01",
- arguments, pos_type, pos_args);
- gui_printf (server->buffer, " %s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- pos_args);
- }
- else
- {
- irc_server_sendf (server, "PRIVMSG %s :\01%s\01",
- arguments, pos_type);
- gui_printf (server->buffer, "\n");
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_send_cmd_cycle: leave and rejoin a channel
- */
-
-int
-irc_send_cmd_cycle (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- t_gui_buffer *buffer;
- char *channel_name, *pos_args, *ptr_arg, *buf;
- t_irc_channel *ptr_channel;
- char **channels;
- int i, argc;
-
- gui_buffer_find_context (server, channel, NULL, &buffer);
-
- if (arguments)
- {
- if (irc_channel_is_channel (arguments))
- {
- channel_name = arguments;
- pos_args = strchr (arguments, ' ');
- if (pos_args)
- {
- pos_args[0] = '\0';
- pos_args++;
- while (pos_args[0] == ' ')
- pos_args++;
- }
- channels = explode_string (channel_name, ",", 0, &argc);
- if (channels)
- {
- for (i = 0; i < argc; i++)
- {
- ptr_channel = irc_channel_search (server, channels[i]);
- /* mark channal as cycling */
- if (ptr_channel &&
- (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL))
- ptr_channel->cycle = 1;
- }
- free_exploded_string (channels);
- }
- }
- else
- {
- if (GUI_BUFFER_IS_SERVER(buffer))
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can not be executed on a server buffer\n"),
- WEECHAT_ERROR, "cycle");
- return -1;
- }
-
- /* does nothing on private buffer (cycle has no sense!) */
- if (GUI_BUFFER_IS_PRIVATE(buffer))
- return 0;
-
- channel_name = GUI_CHANNEL(buffer)->name;
- pos_args = arguments;
- GUI_CHANNEL(buffer)->cycle = 1;
- }
- }
- else
- {
- if (GUI_BUFFER_IS_SERVER(buffer))
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can not be executed on a server buffer\n"),
- WEECHAT_ERROR, "part");
- return -1;
- }
-
- /* does nothing on private buffer (cycle has no sense!) */
- if (GUI_BUFFER_IS_PRIVATE(buffer))
- return 0;
-
- channel_name = GUI_CHANNEL(buffer)->name;
- pos_args = NULL;
- GUI_CHANNEL(buffer)->cycle = 1;
- }
-
- ptr_arg = (pos_args) ? pos_args :
- (cfg_irc_default_msg_part && cfg_irc_default_msg_part[0]) ?
- cfg_irc_default_msg_part : NULL;
-
- if (ptr_arg)
- {
- buf = weechat_strreplace (ptr_arg, "%v", PACKAGE_VERSION);
- irc_server_sendf (server, "PART %s :%s", channel_name,
- (buf) ? buf : ptr_arg);
- if (buf)
- free (buf);
- }
- else
- irc_server_sendf (server, "PART %s", channel_name);
-
- return 0;
-}
-
-/*
- * irc_send_cmd_dehalfop: remove half operator privileges from nickname(s)
- */
-
-int
-irc_send_cmd_dehalfop (t_irc_server *server, t_irc_channel *channel,
- int argc, char **argv)
-{
- t_gui_buffer *buffer;
-
- gui_buffer_find_context (server, channel, NULL, &buffer);
-
- if (GUI_BUFFER_IS_CHANNEL(buffer))
- {
- if (argc == 0)
- irc_server_sendf (server, "MODE %s -h %s",
- GUI_CHANNEL(buffer)->name,
- server->nick);
- else
- irc_send_mode_nicks (server, GUI_CHANNEL(buffer)->name,
- "-", "h", argc, argv);
- }
- else
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can only be executed in a channel buffer\n"),
- WEECHAT_ERROR, "dehalfop");
- }
- return 0;
-}
-
-/*
- * irc_send_cmd_deop: remove operator privileges from nickname(s)
- */
-
-int
-irc_send_cmd_deop (t_irc_server *server, t_irc_channel *channel,
- int argc, char **argv)
-{
- t_gui_buffer *buffer;
-
- gui_buffer_find_context (server, channel, NULL, &buffer);
-
- if (GUI_BUFFER_IS_CHANNEL(buffer))
- {
- if (argc == 0)
- irc_server_sendf (server, "MODE %s -o %s",
- GUI_CHANNEL(buffer)->name,
- server->nick);
- else
- irc_send_mode_nicks (server, GUI_CHANNEL(buffer)->name,
- "-", "o", argc, argv);
- }
- else
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can only be executed in a channel buffer\n"),
- WEECHAT_ERROR, "deop");
- }
- return 0;
-}
-
-/*
- * irc_send_cmd_devoice: remove voice from nickname(s)
- */
-
-int
-irc_send_cmd_devoice (t_irc_server *server, t_irc_channel *channel,
- int argc, char **argv)
-{
- t_gui_buffer *buffer;
-
- gui_buffer_find_context (server, channel, NULL, &buffer);
-
- if (GUI_BUFFER_IS_CHANNEL(buffer))
- {
- if (argc == 0)
- irc_server_sendf (server, "MODE %s -v %s",
- GUI_CHANNEL(buffer)->name,
- server->nick);
- else
- irc_send_mode_nicks (server, GUI_CHANNEL(buffer)->name,
- "-", "v", argc, argv);
- }
- else
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can only be executed in a channel buffer\n"),
- WEECHAT_ERROR, "devoice");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_send_cmd_die: shotdown the server
- */
-
-int
-irc_send_cmd_die (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
- (void) arguments;
-
- irc_server_sendf (server, "DIE");
- return 0;
-}
-
-/*
- * irc_send_cmd_halfop: give half operator privileges to nickname(s)
- */
-
-int
-irc_send_cmd_halfop (t_irc_server *server, t_irc_channel *channel,
- int argc, char **argv)
-{
- t_gui_buffer *buffer;
-
- gui_buffer_find_context (server, channel, NULL, &buffer);
-
- if (GUI_BUFFER_IS_CHANNEL(buffer))
- {
- if (argc == 0)
- irc_server_sendf (server, "MODE %s +h %s",
- GUI_CHANNEL(buffer)->name,
- server->nick);
- else
- irc_send_mode_nicks (server, GUI_CHANNEL(buffer)->name,
- "+", "h", argc, argv);
- }
- else
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can only be executed in a channel buffer\n"),
- WEECHAT_ERROR, "halfop");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_send_cmd_info: get information describing the server
- */
-
-int
-irc_send_cmd_info (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- if (arguments)
- irc_server_sendf (server, "INFO %s", arguments);
- else
- irc_server_sendf (server, "INFO");
- return 0;
-}
-
-/*
- * irc_send_cmd_invite: invite a nick on a channel
- */
-
-int
-irc_send_cmd_invite (t_irc_server *server, t_irc_channel *channel,
- int argc, char **argv)
-{
- t_gui_buffer *buffer;
-
- gui_buffer_find_context (server, channel, NULL, &buffer);
-
- if (argc == 2)
- irc_server_sendf (server, "INVITE %s %s", argv[0], argv[1]);
- else
- {
- if (!GUI_BUFFER_IS_CHANNEL(buffer))
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can only be executed in a channel buffer\n"),
- WEECHAT_ERROR, "invite");
- return -1;
- }
- irc_server_sendf (server, "INVITE %s %s",
- argv[0], GUI_CHANNEL(buffer)->name);
- }
- return 0;
-}
-
-/*
- * irc_send_cmd_ison: check if a nickname is currently on IRC
- */
-
-int
-irc_send_cmd_ison (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- irc_server_sendf (server, "ISON %s", arguments);
- return 0;
-}
-
-/*
- * irc_send_cmd_join: join a new channel
- */
-
-int
-irc_send_cmd_join (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- if (irc_channel_is_channel (arguments))
- irc_server_sendf (server, "JOIN %s", arguments);
- else
- irc_server_sendf (server, "JOIN #%s", arguments);
- return 0;
-}
-
-/*
- * irc_send_cmd_kick: forcibly remove a user from a channel
- */
-
-int
-irc_send_cmd_kick (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- t_gui_buffer *buffer;
- char *pos_channel, *pos_nick, *pos_comment;
-
- gui_buffer_find_context (server, channel, NULL, &buffer);
-
- if (irc_channel_is_channel (arguments))
- {
- pos_channel = arguments;
- pos_nick = strchr (arguments, ' ');
- if (!pos_nick)
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s wrong arguments for \"%s\" command\n"),
- WEECHAT_ERROR, "kick");
- return -1;
- }
- pos_nick[0] = '\0';
- pos_nick++;
- while (pos_nick[0] == ' ')
- pos_nick++;
- }
- else
- {
- if (!GUI_BUFFER_IS_CHANNEL(buffer))
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can only be executed in a channel buffer\n"),
- WEECHAT_ERROR, "kick");
- return -1;
- }
- pos_channel = GUI_CHANNEL(buffer)->name;
- pos_nick = arguments;
- }
-
- pos_comment = strchr (pos_nick, ' ');
- if (pos_comment)
- {
- pos_comment[0] = '\0';
- pos_comment++;
- while (pos_comment[0] == ' ')
- pos_comment++;
- }
-
- if (pos_comment)
- irc_server_sendf (server, "KICK %s %s :%s", pos_channel, pos_nick, pos_comment);
- else
- irc_server_sendf (server, "KICK %s %s", pos_channel, pos_nick);
-
- return 0;
-}
-
-/*
- * irc_send_cmd_kickban: forcibly remove a user from a channel and ban it
- */
-
-int
-irc_send_cmd_kickban (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- t_gui_buffer *buffer;
- char *pos_channel, *pos_nick, *pos_comment;
-
- gui_buffer_find_context (server, channel, NULL, &buffer);
-
- if (irc_channel_is_channel (arguments))
- {
- pos_channel = arguments;
- pos_nick = strchr (arguments, ' ');
- if (!pos_nick)
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s wrong arguments for \"%s\" command\n"),
- WEECHAT_ERROR, "kickban");
- return -1;
- }
- pos_nick[0] = '\0';
- pos_nick++;
- while (pos_nick[0] == ' ')
- pos_nick++;
- }
- else
- {
- if (!GUI_BUFFER_IS_CHANNEL(buffer))
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can only be executed in a channel buffer\n"),
- WEECHAT_ERROR, "kickban");
- return -1;
- }
- pos_channel = GUI_CHANNEL(buffer)->name;
- pos_nick = arguments;
- }
-
- pos_comment = strchr (pos_nick, ' ');
- if (pos_comment)
- {
- pos_comment[0] = '\0';
- pos_comment++;
- while (pos_comment[0] == ' ')
- pos_comment++;
- }
-
- irc_server_sendf (server, "MODE %s +b %s", pos_channel, pos_nick);
- if (pos_comment)
- irc_server_sendf (server, "KICK %s %s :%s", pos_channel, pos_nick, pos_comment);
- else
- irc_server_sendf (server, "KICK %s %s", pos_channel, pos_nick);
-
- return 0;
-}
-
-/*
- * irc_send_cmd_kill: close client-server connection
- */
-
-int
-irc_send_cmd_kill (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- char *pos;
-
- /* make C compiler happy */
- (void) channel;
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- irc_server_sendf (server, "KILL %s :%s", arguments, pos);
- }
- else
- irc_server_sendf (server, "KILL %s", arguments);
- return 0;
-}
-
-/*
- * irc_send_cmd_links: list all servernames which are known by the server
- * answering the query
- */
-
-int
-irc_send_cmd_links (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- if (arguments)
- irc_server_sendf (server, "LINKS %s", arguments);
- else
- irc_server_sendf (server, "LINKS");
- return 0;
-}
-
-/*
- * irc_send_cmd_list: close client-server connection
- */
-
-int
-irc_send_cmd_list (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- char buffer[512];
- int ret;
- /* make C compiler happy */
- (void) channel;
-
- if (server->cmd_list_regexp)
- {
- regfree (server->cmd_list_regexp);
- free (server->cmd_list_regexp);
- server->cmd_list_regexp = NULL;
- }
-
- if (arguments)
- {
- server->cmd_list_regexp = (regex_t *) malloc (sizeof (regex_t));
- if (server->cmd_list_regexp)
- {
- if ((ret = regcomp (server->cmd_list_regexp, arguments, REG_NOSUB | REG_ICASE)) != 0)
- {
- regerror (ret, server->cmd_list_regexp, buffer, sizeof(buffer));
- gui_printf (server->buffer,
- _("%s \"%s\" is not a valid regular expression (%s)\n"),
- WEECHAT_ERROR, arguments, buffer);
- }
- else
- irc_server_sendf (server, "LIST");
- }
- else
- {
- gui_printf (server->buffer,
- _("%s not enough memory for regular expression\n"),
- WEECHAT_ERROR);
- }
- }
- else
- irc_server_sendf (server, "LIST");
-
- return 0;
-}
-
-/*
- * irc_send_cmd_lusers: get statistics about ths size of the IRC network
- */
-
-int
-irc_send_cmd_lusers (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- if (arguments)
- irc_server_sendf (server, "LUSERS %s", arguments);
- else
- irc_server_sendf (server, "LUSERS");
- return 0;
-}
-
-/*
- * irc_send_cmd_me: send a ctcp action to the current channel
- */
-
-int
-irc_send_cmd_me (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- t_gui_buffer *buffer;
-
- gui_buffer_find_context (server, channel, NULL, &buffer);
-
- if (GUI_BUFFER_IS_SERVER(buffer))
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can not be executed on a server buffer\n"),
- WEECHAT_ERROR, "me");
- return -1;
- }
- irc_send_me (server, GUI_CHANNEL(buffer), arguments);
- return 0;
-}
-
-/*
- * irc_send_cmd_mode: change mode for channel/nickname
- */
-
-int
-irc_send_cmd_mode (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- irc_server_sendf (server, "MODE %s", arguments);
- return 0;
-}
-
-/*
- * irc_send_mode_nicks: send mode change for many nicks on a channel
- */
-
-void
-irc_send_mode_nicks (t_irc_server *server, char *channel,
- char *set, char *mode, int argc, char **argv)
-{
- int i, length;
- char *command;
-
- length = 0;
- for (i = 0; i < argc; i++)
- length += strlen (argv[i]) + 1;
- length += strlen (channel) + (argc * strlen (mode)) + 32;
- command = (char *)malloc (length);
- if (command)
- {
- snprintf (command, length, "MODE %s %s", channel, set);
- for (i = 0; i < argc; i++)
- strcat (command, mode);
- for (i = 0; i < argc; i++)
- {
- strcat (command, " ");
- strcat (command, argv[i]);
- }
- irc_server_sendf (server, "%s", command);
- free (command);
- }
-}
-
-/*
- * irc_send_cmd_motd: get the "Message Of The Day"
- */
-
-int
-irc_send_cmd_motd (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- if (arguments)
- irc_server_sendf (server, "MOTD %s", arguments);
- else
- irc_server_sendf (server, "MOTD");
- return 0;
-}
-
-/*
- * irc_send_cmd_msg: send a message to a nick or channel
- */
-
-int
-irc_send_cmd_msg (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- t_gui_window *window;
- t_gui_buffer *buffer;
- char *pos, *pos_comma;
- char *msg_pwd_hidden;
- t_irc_channel *ptr_channel;
- t_irc_nick *ptr_nick;
- char *string;
-
- gui_buffer_find_context (server, channel, &window, &buffer);
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
-
- while (arguments && arguments[0])
- {
- pos_comma = strchr (arguments, ',');
- if (pos_comma)
- {
- pos_comma[0] = '\0';
- pos_comma++;
- }
- if (strcmp (arguments, "*") == 0)
- {
- if (!GUI_BUFFER_IS_CHANNEL(buffer) &&
- !GUI_BUFFER_IS_PRIVATE(buffer))
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can only be executed in a channel or private buffer\n"),
- WEECHAT_ERROR, "msg *");
- return -1;
- }
- ptr_channel = GUI_CHANNEL(buffer);
- if (GUI_BUFFER_IS_CHANNEL(buffer))
- ptr_nick = irc_nick_search (ptr_channel, server->nick);
- else
- ptr_nick = NULL;
- irc_display_nick (buffer, ptr_nick,
- (ptr_nick) ? NULL : server->nick,
- GUI_MSG_TYPE_NICK, 1, -1, 0);
- string = (char *)gui_color_decode ((unsigned char *)pos, 1, 0);
- gui_printf_type (buffer, GUI_MSG_TYPE_MSG, "%s\n",
- (string) ? string : "");
- if (string)
- free (string);
-
- irc_server_sendf (server, "PRIVMSG %s :%s", ptr_channel->name, pos);
- }
- else
- {
- if (irc_channel_is_channel (arguments))
- {
- ptr_channel = irc_channel_search (server, arguments);
- if (ptr_channel)
- {
- ptr_nick = irc_nick_search (ptr_channel, server->nick);
- if (ptr_nick)
- {
- irc_display_nick (ptr_channel->buffer, ptr_nick, NULL,
- GUI_MSG_TYPE_NICK, 1, -1, 0);
- string = (char *)gui_color_decode ((unsigned char *)pos, 1, 0);
- gui_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_MSG, "%s\n",
- (string) ? string : "");
- if (string)
- free (string);
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s nick \"%s\" not found for \"%s\" command\n"),
- WEECHAT_ERROR, server->nick, "msg");
- }
- }
- irc_server_sendf (server, "PRIVMSG %s :%s", arguments, pos);
- }
- else
- {
- /* message to nickserv with identify ? */
- if (strcmp (arguments, "nickserv") == 0)
- {
- msg_pwd_hidden = strdup (pos);
- if (cfg_log_hide_nickserv_pwd)
- irc_display_hide_password (msg_pwd_hidden, 0);
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf_type (server->buffer, GUI_MSG_TYPE_NICK,
- "%s-%s%s%s- ",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- arguments,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK));
- string = (char *)gui_color_decode ((unsigned char *)msg_pwd_hidden, 1, 0);
- gui_printf (server->buffer, "%s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (string) ? string : "");
- if (string)
- free (string);
- irc_server_sendf (server, "PRIVMSG %s :%s", arguments, pos);
- free (msg_pwd_hidden);
- return 0;
- }
-
- string = (char *)gui_color_decode ((unsigned char *)pos, 1, 0);
- ptr_channel = irc_channel_search (server, arguments);
- if (ptr_channel)
- {
- irc_display_nick (ptr_channel->buffer, NULL, server->nick,
- GUI_MSG_TYPE_NICK, 1, GUI_COLOR_WIN_NICK_SELF, 0);
- gui_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_MSG,
- "%s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (string) ? string : "");
- }
- else
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- gui_printf (server->buffer, "MSG%s(%s%s%s)%s: ",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- arguments,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT));
- gui_printf_type (server->buffer, GUI_MSG_TYPE_MSG,
- "%s\n",
- (string) ? string : pos);
- }
- if (string)
- free (string);
- irc_server_sendf (server, "PRIVMSG %s :%s", arguments, pos);
- }
- }
- arguments = pos_comma;
- }
- }
- else
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s wrong argument count for \"%s\" command\n"),
- WEECHAT_ERROR, "msg");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_send_cmd_names: list nicknames on channels
- */
-
-int
-irc_send_cmd_names (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- t_gui_buffer *buffer;
-
- gui_buffer_find_context (server, channel, NULL, &buffer);
-
- if (arguments)
- irc_server_sendf (server, "NAMES %s", arguments);
- else
- {
- if (!GUI_BUFFER_IS_CHANNEL(buffer))
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can only be executed in a channel buffer\n"),
- WEECHAT_ERROR, "names");
- return -1;
- }
- else
- irc_server_sendf (server, "NAMES %s",
- GUI_CHANNEL(buffer)->name);
- }
- return 0;
-}
-
-/*
- * irc_send_cmd_nick_server: change nickname on a server
- */
-
-void
-irc_send_cmd_nick_server (t_irc_server *server, char *nickname)
-{
- t_irc_channel *ptr_channel;
-
- if (server->is_connected)
- irc_server_sendf (server, "NICK %s", nickname);
- else
- {
- if (server->nick)
- free (server->nick);
- server->nick = strdup (nickname);
- gui_input_draw (server->buffer, 1);
- for (ptr_channel = server->channels; ptr_channel;
- ptr_channel = ptr_channel->next_channel)
- {
- gui_input_draw (ptr_channel->buffer, 1);
- }
- }
-}
-
-/*
- * irc_send_cmd_nick: change nickname
- */
-
-int
-irc_send_cmd_nick (t_irc_server *server, t_irc_channel *channel,
- int argc, char **argv)
-{
- t_irc_server *ptr_server;
-
- /* make C compiler happy */
- (void) channel;
-
- if (!server)
- return 0;
-
- if (argc == 2)
- {
- if (strncmp (argv[0], "-all", 4) != 0)
- return -1;
-
- for (ptr_server = irc_servers; ptr_server;
- ptr_server = ptr_server->next_server)
- {
- irc_send_cmd_nick_server (ptr_server, argv[1]);
- }
- }
- else
- {
- if (argc == 1)
- irc_send_cmd_nick_server (server, argv[0]);
- else
- return -1;
- }
-
- return 0;
-}
-
-/*
- * irc_send_cmd_notice: send notice message
- */
-
-int
-irc_send_cmd_notice (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- char *pos, *string;
-
- /* make C compiler happy */
- (void) channel;
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- irc_display_prefix (server, server->buffer, GUI_PREFIX_SERVER);
- string = (char *)gui_color_decode ((unsigned char *)pos, 1, 0);
- gui_printf (server->buffer, "notice%s(%s%s%s)%s: %s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
- arguments,
- GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK),
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (string) ? string : "");
- if (string)
- free (string);
- irc_server_sendf (server, "NOTICE %s :%s", arguments, pos);
- }
- else
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s wrong argument count for \"%s\" command\n"),
- WEECHAT_ERROR, "notice");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_send_cmd_op: give operator privileges to nickname(s)
- */
-
-int
-irc_send_cmd_op (t_irc_server *server, t_irc_channel *channel,
- int argc, char **argv)
-{
- t_gui_buffer *buffer;
-
- gui_buffer_find_context (server, channel, NULL, &buffer);
-
- if (GUI_BUFFER_IS_CHANNEL(buffer))
- {
- if (argc == 0)
- irc_server_sendf (server, "MODE %s +o %s",
- GUI_CHANNEL(buffer)->name,
- server->nick);
- else
- irc_send_mode_nicks (server, GUI_CHANNEL(buffer)->name,
- "+", "o", argc, argv);
- }
- else
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can only be executed in a channel buffer\n"),
- WEECHAT_ERROR, "op");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_send_cmd_oper: get oper privileges
- */
-
-int
-irc_send_cmd_oper (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- irc_server_sendf (server, "OPER %s", arguments);
- return 0;
-}
-
-/*
- * irc_send_cmd_part: leave a channel or close a private window
- */
-
-int
-irc_send_cmd_part (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- t_gui_buffer *buffer;
- char *channel_name, *pos_args, *ptr_arg, *buf;
- t_irc_channel *ptr_channel;
-
- gui_buffer_find_context (server, channel, NULL, &buffer);
-
- if (arguments)
- {
- if (irc_channel_is_channel (arguments))
- {
- channel_name = arguments;
- pos_args = strchr (arguments, ' ');
- if (pos_args)
- {
- pos_args[0] = '\0';
- pos_args++;
- while (pos_args[0] == ' ')
- pos_args++;
- }
- }
- else
- {
- if (!GUI_CHANNEL(buffer))
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can only be executed in a channel or private buffer\n"),
- WEECHAT_ERROR, "part");
- return -1;
- }
- channel_name = GUI_CHANNEL(buffer)->name;
- pos_args = arguments;
- }
- }
- else
- {
- if (!GUI_CHANNEL(buffer))
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can only be executed in a channel or private buffer\n"),
- WEECHAT_ERROR, "part");
- return -1;
- }
- if (GUI_BUFFER_IS_PRIVATE(buffer))
- {
- ptr_channel = GUI_CHANNEL(buffer);
- gui_buffer_free (ptr_channel->buffer, 1);
- irc_channel_free (server, ptr_channel);
- gui_status_draw (buffer, 1);
- gui_input_draw (buffer, 1);
- return 0;
- }
- channel_name = GUI_CHANNEL(buffer)->name;
- pos_args = NULL;
- }
-
- ptr_arg = (pos_args) ? pos_args :
- (cfg_irc_default_msg_part && cfg_irc_default_msg_part[0]) ?
- cfg_irc_default_msg_part : NULL;
-
- if (ptr_arg)
- {
- buf = weechat_strreplace (ptr_arg, "%v", PACKAGE_VERSION);
- irc_server_sendf (server, "PART %s :%s", channel_name,
- (buf) ? buf : ptr_arg);
- if (buf)
- free (buf);
- }
- else
- irc_server_sendf (server, "PART %s", channel_name);
-
- return 0;
-}
-
-/*
- * irc_send_cmd_ping: ping a server
- */
-
-int
-irc_send_cmd_ping (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- irc_server_sendf (server, "PING %s", arguments);
- return 0;
-}
-
-/*
- * irc_send_cmd_pong: send pong answer to a daemon
- */
-
-int
-irc_send_cmd_pong (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- irc_server_sendf (server, "PONG %s", arguments);
- return 0;
-}
-
-/*
- * irc_send_cmd_query: start private conversation with a nick
- */
-
-int
-irc_send_cmd_query (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- t_gui_window *window;
- t_gui_buffer *buffer;
- char *pos, *string;
- t_irc_channel *ptr_channel;
- t_gui_buffer *ptr_buffer;
-
- gui_buffer_find_context (server, channel, &window, &buffer);
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- if (!pos[0])
- pos = NULL;
- }
-
- /* create private window if not already opened */
- ptr_channel = irc_channel_search (server, arguments);
- if (!ptr_channel)
- {
- ptr_channel = irc_channel_new (server, IRC_CHANNEL_TYPE_PRIVATE, arguments);
- if (!ptr_channel)
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s cannot create new private buffer \"%s\"\n"),
- WEECHAT_ERROR, arguments);
- return -1;
- }
- gui_buffer_new (window, server, ptr_channel,
- GUI_BUFFER_TYPE_STANDARD, 1);
- gui_chat_draw_title (ptr_channel->buffer, 1);
- }
- else
- {
- for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer)
- {
- if (ptr_buffer->channel == ptr_channel)
- {
- gui_window_switch_to_buffer (window, ptr_buffer);
- gui_window_redraw_buffer (ptr_buffer);
- break;
- }
- }
- }
-
- /* display text if given */
- if (pos)
- {
- irc_display_nick (ptr_channel->buffer, NULL, server->nick,
- GUI_MSG_TYPE_NICK, 1, GUI_COLOR_WIN_NICK_SELF, 0);
- string = (char *)gui_color_decode ((unsigned char *)pos, 1, 0);
- gui_printf_type (ptr_channel->buffer, GUI_MSG_TYPE_MSG,
- "%s%s\n",
- GUI_COLOR(GUI_COLOR_WIN_CHAT),
- (string) ? string : "");
- if (string)
- free (string);
- irc_server_sendf (server, "PRIVMSG %s :%s", arguments, pos);
- }
- return 0;
-}
-
-/*
- * irc_send_quit_server: send QUIT to a server
- */
-
-void
-irc_send_quit_server (t_irc_server *server, char *arguments)
-{
- char *ptr_arg, *buf;
-
- if (server->is_connected)
- {
- ptr_arg = (arguments) ? arguments :
- (cfg_irc_default_msg_quit && cfg_irc_default_msg_quit[0]) ?
- cfg_irc_default_msg_quit : NULL;
-
- if (ptr_arg)
- {
- buf = weechat_strreplace (ptr_arg, "%v", PACKAGE_VERSION);
- irc_server_sendf (server, "QUIT :%s",
- (buf) ? buf : ptr_arg);
- if (buf)
- free (buf);
- }
- else
- irc_server_sendf (server, "QUIT");
- }
-}
-
-/*
- * irc_send_cmd_quit: disconnect from all servers and quit WeeChat
- */
-
-int
-irc_send_cmd_quit (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- t_irc_server *ptr_server;
-
- /* make C compiler happy */
- (void) server;
- (void) channel;
-
- for (ptr_server = irc_servers; ptr_server;
- ptr_server = ptr_server->next_server)
- {
- irc_send_quit_server (ptr_server, arguments);
- }
- quit_weechat = 1;
- return 0;
-}
-
-/*
- * irc_send_cmd_quote: send raw data to server
- */
-
-int
-irc_send_cmd_quote (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- if (!server || server->sock < 0)
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf_nolog (NULL,
- _("%s command \"%s\" needs a server connection!\n"),
- WEECHAT_ERROR, "quote");
- return -1;
- }
- irc_server_sendf (server, "%s", arguments);
- return 0;
-}
-
-/*
- * irc_send_cmd_rehash: tell the server to reload its config file
- */
-
-int
-irc_send_cmd_rehash (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
- (void) arguments;
-
- irc_server_sendf (server, "REHASH");
- return 0;
-}
-
-/*
- * irc_send_cmd_restart: tell the server to restart itself
- */
-
-int
-irc_send_cmd_restart (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
- (void) arguments;
-
- irc_server_sendf (server, "RESTART");
- return 0;
-}
-
-/*
- * irc_send_cmd_service: register a new service
- */
-
-int
-irc_send_cmd_service (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- irc_server_sendf (server, "SERVICE %s", arguments);
- return 0;
-}
-
-/*
- * irc_send_cmd_servlist: list services currently connected to the network
- */
-
-int
-irc_send_cmd_servlist (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- if (arguments)
- irc_server_sendf (server, "SERVLIST %s", arguments);
- else
- irc_server_sendf (server, "SERVLIST");
- return 0;
-}
-
-/*
- * irc_send_cmd_squery: deliver a message to a service
- */
-
-int
-irc_send_cmd_squery (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- char *pos;
-
- /* make C compiler happy */
- (void) channel;
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- {
- pos++;
- }
- irc_server_sendf (server, "SQUERY %s :%s", arguments, pos);
- }
- else
- irc_server_sendf (server, "SQUERY %s", arguments);
-
- return 0;
-}
-
-/*
- * irc_send_cmd_squit: disconnect server links
- */
-
-int
-irc_send_cmd_squit (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- irc_server_sendf (server, "SQUIT %s", arguments);
- return 0;
-}
-
-/*
- * irc_send_cmd_stats: query statistics about server
- */
-
-int
-irc_send_cmd_stats (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- if (arguments)
- irc_server_sendf (server, "STATS %s", arguments);
- else
- irc_server_sendf (server, "STATS");
- return 0;
-}
-
-/*
- * irc_send_cmd_summon: give users who are on a host running an IRC server
- * a message asking them to please join IRC
- */
-
-int
-irc_send_cmd_summon (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- irc_server_sendf (server, "SUMMON %s", arguments);
- return 0;
-}
-
-/*
- * irc_send_cmd_time: query local time from server
- */
-
-int
-irc_send_cmd_time (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- if (arguments)
- irc_server_sendf (server, "TIME %s", arguments);
- else
- irc_server_sendf (server, "TIME");
- return 0;
-}
-
-/*
- * irc_send_cmd_topic: get/set topic for a channel
- */
-
-int
-irc_send_cmd_topic (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- t_gui_buffer *buffer;
- char *channel_name, *new_topic, *pos;
-
- gui_buffer_find_context (server, channel, NULL, &buffer);
-
- channel_name = NULL;
- new_topic = NULL;
-
- if (arguments)
- {
- if (irc_channel_is_channel (arguments))
- {
- channel_name = arguments;
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- new_topic = (pos[0]) ? pos : NULL;
- }
- }
- else
- new_topic = arguments;
- }
-
- /* look for current channel if not specified */
- if (!channel_name)
- {
- if (GUI_BUFFER_IS_SERVER(buffer))
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can not be executed on a server buffer\n"),
- WEECHAT_ERROR, "topic");
- return -1;
- }
- channel_name = GUI_CHANNEL(buffer)->name;
- }
-
- if (new_topic)
- {
- if (strcmp (new_topic, "-delete") == 0)
- irc_server_sendf (server, "TOPIC %s :", channel_name);
- else
- irc_server_sendf (server, "TOPIC %s :%s", channel_name, new_topic);
- }
- else
- irc_server_sendf (server, "TOPIC %s", channel_name);
-
- return 0;
-}
-
-/*
- * irc_send_cmd_trace: find the route to specific server
- */
-
-int
-irc_send_cmd_trace (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- if (arguments)
- irc_server_sendf (server, "TRACE %s", arguments);
- else
- irc_server_sendf (server, "TRACE");
- return 0;
-}
-
-/*
- * irc_send_cmd_unban: unbans nicks or hosts
- */
-
-int
-irc_send_cmd_unban (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- t_gui_buffer *buffer;
- char *pos_channel, *pos, *pos2;
-
- gui_buffer_find_context (server, channel, NULL, &buffer);
-
- if (arguments)
- {
- pos_channel = NULL;
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
-
- if (irc_channel_is_channel (arguments))
- {
- pos_channel = arguments;
- pos++;
- while (pos[0] == ' ')
- pos++;
- }
- else
- {
- pos[0] = ' ';
- pos = arguments;
- }
- }
- else
- pos = arguments;
-
- /* channel not given, use default buffer */
- if (!pos_channel)
- {
- if (!GUI_BUFFER_IS_CHANNEL(buffer))
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can only be executed in a channel buffer\n"),
- WEECHAT_ERROR, "unban");
- return -1;
- }
- pos_channel = GUI_CHANNEL(buffer)->name;
- }
-
- /* loop on users */
- while (pos && pos[0])
- {
- pos2 = strchr (pos, ' ');
- if (pos2)
- {
- pos2[0] = '\0';
- pos2++;
- while (pos2[0] == ' ')
- pos2++;
- }
- irc_server_sendf (server, "MODE %s -b %s", pos_channel, pos);
- pos = pos2;
- }
- }
- else
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s wrong argument count for \"%s\" command\n"),
- WEECHAT_ERROR, "unban");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_send_cmd_userhost: return a list of information about nicknames
- */
-
-int
-irc_send_cmd_userhost (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- irc_server_sendf (server, "USERHOST %s", arguments);
- return 0;
-}
-
-/*
- * irc_send_cmd_users: list of users logged into the server
- */
-
-int
-irc_send_cmd_users (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- if (arguments)
- irc_server_sendf (server, "USERS %s", arguments);
- else
- irc_server_sendf (server, "USERS");
- return 0;
-}
-
-/*
- * irc_send_cmd_version: gives the version info of nick or server (current or specified)
- */
-
-int
-irc_send_cmd_version (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- t_gui_buffer *buffer;
-
- gui_buffer_find_context (server, channel, NULL, &buffer);
-
- if (arguments)
- {
- if (GUI_BUFFER_IS_CHANNEL(buffer) &&
- irc_nick_search (GUI_CHANNEL(buffer), arguments))
- irc_server_sendf (server, "PRIVMSG %s :\01VERSION\01",
- arguments);
- else
- irc_server_sendf (server, "VERSION %s",
- arguments);
- }
- else
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_INFO);
- gui_printf (server->buffer, _("%s, compiled on %s %s\n"),
- PACKAGE_STRING,
- __DATE__, __TIME__);
- irc_server_sendf (server, "VERSION");
- }
- return 0;
-}
-
-/*
- * irc_send_cmd_voice: give voice to nickname(s)
- */
-
-int
-irc_send_cmd_voice (t_irc_server *server, t_irc_channel *channel,
- int argc, char **argv)
-{
- t_gui_buffer *buffer;
-
- gui_buffer_find_context (server, channel, NULL, &buffer);
-
- if (GUI_BUFFER_IS_CHANNEL(buffer))
- {
- if (argc == 0)
- irc_server_sendf (server, "MODE %s +v %s",
- GUI_CHANNEL(buffer)->name,
- server->nick);
- else
- irc_send_mode_nicks (server, GUI_CHANNEL(buffer)->name,
- "+", "v", argc, argv);
- }
- else
- {
- irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR);
- gui_printf_nolog (server->buffer,
- _("%s \"%s\" command can only be executed in a channel buffer\n"),
- WEECHAT_ERROR, "voice");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_send_cmd_wallops: send a message to all currently connected users who
- * have set the 'w' user mode for themselves
- */
-
-int
-irc_send_cmd_wallops (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- irc_server_sendf (server, "WALLOPS :%s", arguments);
- return 0;
-}
-
-/*
- * irc_send_cmd_who: generate a query which returns a list of information
- */
-
-int
-irc_send_cmd_who (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- if (arguments)
- irc_server_sendf (server, "WHO %s", arguments);
- else
- irc_server_sendf (server, "WHO");
- return 0;
-}
-
-/*
- * irc_send_cmd_whois: query information about user(s)
- */
-
-int
-irc_send_cmd_whois (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- irc_server_sendf (server, "WHOIS %s", arguments);
- return 0;
-}
-
-/*
- * irc_send_cmd_whowas: ask for information about a nickname which no longer exists
- */
-
-int
-irc_send_cmd_whowas (t_irc_server *server, t_irc_channel *channel,
- char *arguments)
-{
- /* make C compiler happy */
- (void) channel;
-
- irc_server_sendf (server, "WHOWAS %s", arguments);
- return 0;
-}
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index 0c119ceb1..2e751eb95 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -42,16 +42,14 @@
#include <gnutls/gnutls.h>
#endif
-#include "../../common/weechat.h"
+#include "../../core/weechat.h"
#include "irc.h"
-#include "../../common/log.h"
-#include "../../common/util.h"
-#include "../../common/weeconfig.h"
+#include "../../core/hook.h"
+#include "../../core/log.h"
+#include "../../core/util.h"
+#include "../../core/weechat-config.h"
#include "../../gui/gui.h"
-
-#ifdef PLUGINS
#include "../../plugins/plugins.h"
-#endif
t_irc_server *irc_servers = NULL;
@@ -60,8 +58,6 @@ t_irc_server *last_irc_server = NULL;
t_irc_message *irc_recv_msgq = NULL;
t_irc_message *irc_msgq_last_msg = NULL;
-int irc_check_away = 0;
-
#ifdef HAVE_GNUTLS
const int gnutls_cert_type_prio[] = { GNUTLS_CRT_X509, GNUTLS_CRT_OPENPGP, 0 };
#if LIBGNUTLS_VERSION_NUMBER >= 0x010700
@@ -109,6 +105,7 @@ irc_server_init (t_irc_server *server)
server->child_read = -1;
server->child_write = -1;
server->sock = -1;
+ server->hook_fd = NULL;
server->is_connected = 0;
server->ssl_connected = 0;
server->unterminated_message = NULL;
@@ -125,14 +122,13 @@ irc_server_init (t_irc_server *server)
server->lag = 0;
server->lag_check_time.tv_sec = 0;
server->lag_check_time.tv_usec = 0;
- server->lag_next_check = time (NULL) + cfg_irc_lag_check;
+ server->lag_next_check = time (NULL) + irc_cfg_irc_lag_check;
server->cmd_list_regexp = NULL;
server->queue_msg = 0;
server->last_user_message = 0;
server->outqueue = NULL;
server->last_outqueue = NULL;
server->buffer = NULL;
- server->saved_buffer = NULL;
server->channels = NULL;
server->last_channel = NULL;
}
@@ -250,7 +246,7 @@ irc_server_init_with_url (char *irc_url, t_irc_server *server)
/* some default values */
if (server->port < 0)
- server->port = IRC_DEFAULT_PORT;
+ server->port = IRC_SERVER_DEFAULT_PORT;
server->nick2 = (char *) malloc (strlen (server->nick1) + 2);
strcpy (server->nick2, server->nick1);
server->nick2 = strcat (server->nick2, "1");
@@ -601,15 +597,43 @@ irc_server_rename (t_irc_server *server, char *new_name)
int
irc_server_send (t_irc_server *server, char *buffer, int size_buf)
{
+ int rc;
+
if (!server)
- return -1;
+ {
+ gui_chat_printf_error (NULL,
+ _("%s error sending data to IRC server: null "
+ "pointer (please report problem to "
+ "developers)"),
+ WEECHAT_ERROR);
+ return 0;
+ }
+
+ if (size_buf <= 0)
+ {
+ gui_chat_printf_error (server->buffer,
+ _("%s error sending data to IRC server: empty "
+ "buffer (please report problem to "
+ "developers)"),
+ WEECHAT_ERROR);
+ return 0;
+ }
#ifdef HAVE_GNUTLS
if (server->ssl_connected)
- return gnutls_record_send (server->gnutls_sess, buffer, size_buf);
+ rc = gnutls_record_send (server->gnutls_sess, buffer, size_buf);
else
#endif
- return send (server->sock, buffer, size_buf, 0);
+ rc = send (server->sock, buffer, size_buf, 0);
+
+ if (rc < 0)
+ {
+ gui_chat_printf_error (server->buffer,
+ _("%s error sending data to IRC server (%s)"),
+ WEECHAT_ERROR, strerror (errno));
+ }
+
+ return rc;
}
/*
@@ -625,15 +649,15 @@ irc_server_outqueue_send (t_irc_server *server)
if (server->outqueue)
{
time_now = time (NULL);
- if (time_now >= server->last_user_message + cfg_irc_anti_flood)
+ if (time_now >= server->last_user_message + irc_cfg_irc_anti_flood)
{
if (server->outqueue->message_before_mod)
{
pos = strchr (server->outqueue->message_before_mod, '\r');
if (pos)
pos[0] = '\0';
- gui_printf_raw_data (server, 1, 0,
- server->outqueue->message_before_mod);
+ gui_chat_printf_raw_data (server, 1, 0,
+ server->outqueue->message_before_mod);
if (pos)
pos[0] = '\r';
}
@@ -642,17 +666,18 @@ irc_server_outqueue_send (t_irc_server *server)
pos = strchr (server->outqueue->message_after_mod, '\r');
if (pos)
pos[0] = '\0';
- gui_printf_raw_data (server, 1, server->outqueue->modified,
- server->outqueue->message_after_mod);
+ gui_chat_printf_raw_data (server, 1, server->outqueue->modified,
+ server->outqueue->message_after_mod);
if (pos)
pos[0] = '\r';
}
if (irc_server_send (server, server->outqueue->message_after_mod,
- strlen (server->outqueue->message_after_mod)) <= 0)
+ strlen (server->outqueue->message_after_mod)) < 0)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer, _("%s error sending data to IRC server\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ _("%s error sending data to IRC "
+ "server\n"),
+ WEECHAT_ERROR);
}
server->last_user_message = time_now;
irc_server_outqueue_free (server, server->outqueue);
@@ -675,15 +700,12 @@ irc_server_send_one_msg (t_irc_server *server, char *message)
rc = 1;
#ifdef DEBUG
- gui_printf (server->buffer, "[DEBUG] Sending to server >>> %s\n", message);
+ gui_chat_printf (server->buffer, "[DEBUG] Sending to server >>> %s\n",
+ message);
#endif
-#ifdef PLUGINS
new_msg = plugin_modifier_exec (PLUGIN_MODIFIER_IRC_OUT,
server->name,
message);
-#else
- new_msg = NULL;
-#endif
/* no changes in new message */
if (new_msg && (strcmp (buffer, new_msg) == 0))
@@ -711,8 +733,8 @@ irc_server_send_one_msg (t_irc_server *server, char *message)
queue = 0;
if ((server->queue_msg)
&& ((server->outqueue)
- || ((cfg_irc_anti_flood > 0)
- && (time_now - server->last_user_message < cfg_irc_anti_flood))))
+ || ((irc_cfg_irc_anti_flood > 0)
+ && (time_now - server->last_user_message < irc_cfg_irc_anti_flood))))
queue = 1;
/* if queue, then only queue message and send nothing now */
@@ -726,14 +748,15 @@ irc_server_send_one_msg (t_irc_server *server, char *message)
else
{
if (first_message)
- gui_printf_raw_data (server, 1, 0, message);
+ gui_chat_printf_raw_data (server, 1, 0, message);
if (new_msg)
- gui_printf_raw_data (server, 1, 1, ptr_msg);
+ gui_chat_printf_raw_data (server, 1, 1, ptr_msg);
if (irc_server_send (server, buffer, strlen (buffer)) <= 0)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer, _("%s error sending data to IRC server\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ _("%s error sending data to IRC "
+ "server\n"),
+ WEECHAT_ERROR);
rc = 0;
}
else
@@ -754,7 +777,7 @@ irc_server_send_one_msg (t_irc_server *server, char *message)
}
}
else
- gui_printf_raw_data (server, 1, 1, _("(message dropped)"));
+ gui_chat_printf_raw_data (server, 1, 1, _("(message dropped)"));
if (new_msg)
free (new_msg);
@@ -862,10 +885,10 @@ irc_server_msgq_add_msg (t_irc_server *server, char *msg)
message = (t_irc_message *) malloc (sizeof (t_irc_message));
if (!message)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s not enough memory for received IRC message\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ _("%s not enough memory for received IRC "
+ "message\n"),
+ WEECHAT_ERROR);
return;
}
message->server = server;
@@ -875,10 +898,10 @@ irc_server_msgq_add_msg (t_irc_server *server, char *msg)
strlen (msg) + 1);
if (!message->data)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s not enough memory for received IRC message\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ _("%s not enough memory for received IRC "
+ "message\n"),
+ WEECHAT_ERROR);
}
else
{
@@ -922,10 +945,10 @@ irc_server_msgq_add_unterminated (t_irc_server *server, char *string)
strlen (string) + 1);
if (!server->unterminated_message)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s not enough memory for received IRC message\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ _("%s not enough memory for received IRC "
+ "message\n"),
+ WEECHAT_ERROR);
}
else
strcat (server->unterminated_message, string);
@@ -935,10 +958,10 @@ irc_server_msgq_add_unterminated (t_irc_server *server, char *string)
server->unterminated_message = strdup (string);
if (!server->unterminated_message)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s not enough memory for received IRC message\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ _("%s not enough memory for received IRC "
+ "message\n"),
+ WEECHAT_ERROR);
}
}
}
@@ -997,7 +1020,9 @@ irc_server_msgq_flush ()
if (irc_recv_msgq->data)
{
#ifdef DEBUG
- gui_printf (gui_current_window->buffer, "[DEBUG] %s\n", irc_recv_msgq->data);
+ gui_chat_printf (gui_current_window->buffer,
+ "[DEBUG] %s\n",
+ irc_recv_msgq->data);
#endif
ptr_data = irc_recv_msgq->data;
while (ptr_data[0] == ' ')
@@ -1005,17 +1030,16 @@ irc_server_msgq_flush ()
if (ptr_data[0])
{
- gui_printf_raw_data (irc_recv_msgq->server, 0, 0, ptr_data);
+ gui_chat_printf_raw_data (irc_recv_msgq->server, 0, 0,
+ ptr_data);
#ifdef DEBUG
- gui_printf (NULL, "[DEBUG] data received from server: %s\n", ptr_data);
+ gui_chat_printf (NULL,
+ "[DEBUG] data received from server: %s\n",
+ ptr_data);
#endif
-#ifdef PLUGINS
new_msg = plugin_modifier_exec (PLUGIN_MODIFIER_IRC_IN,
irc_recv_msgq->server->name,
ptr_data);
-#else
- new_msg = NULL;
-#endif
/* no changes in new message */
if (new_msg && (strcmp (ptr_data, new_msg) == 0))
{
@@ -1036,30 +1060,36 @@ irc_server_msgq_flush ()
pos[0] = '\0';
if (new_msg)
- gui_printf_raw_data (irc_recv_msgq->server, 0, 1, ptr_msg);
+ gui_chat_printf_raw_data (irc_recv_msgq->server,
+ 0, 1, ptr_msg);
- irc_server_parse_message (ptr_msg, &host, &command, &args);
+ irc_server_parse_message (ptr_msg, &host,
+ &command, &args);
- switch (irc_recv_command (irc_recv_msgq->server, ptr_msg, host, command, args))
+ switch (irc_protocol_recv_command (irc_recv_msgq->server,
+ ptr_msg,
+ host, command, args))
{
case -1:
- irc_display_prefix (irc_recv_msgq->server,
- irc_recv_msgq->server->buffer, GUI_PREFIX_ERROR);
- gui_printf (irc_recv_msgq->server->buffer,
- _("%s Command \"%s\" failed!\n"), WEECHAT_ERROR, command);
+ gui_chat_printf_error (irc_recv_msgq->server->buffer,
+ _("%s Command \"%s\" "
+ "failed!\n"),
+ WEECHAT_ERROR, command);
break;
case -2:
- irc_display_prefix (irc_recv_msgq->server,
- irc_recv_msgq->server->buffer, GUI_PREFIX_ERROR);
- gui_printf (irc_recv_msgq->server->buffer,
- _("%s No command to execute!\n"), WEECHAT_ERROR);
+ gui_chat_printf_error (irc_recv_msgq->server->buffer,
+ _("%s No command to "
+ "execute!\n"),
+ WEECHAT_ERROR);
break;
case -3:
- irc_display_prefix (irc_recv_msgq->server,
- irc_recv_msgq->server->buffer, GUI_PREFIX_ERROR);
- gui_printf (irc_recv_msgq->server->buffer,
- _("%s Unknown command: cmd=\"%s\", host=\"%s\", args=\"%s\"\n"),
- WEECHAT_WARNING, command, host, args);
+ gui_chat_printf_error (irc_recv_msgq->server->buffer,
+ _("%s Unknown command: "
+ "cmd=\"%s\", "
+ "host=\"%s\", "
+ "args=\"%s\"\n"),
+ WEECHAT_WARNING,
+ command, host, args);
break;
}
if (host)
@@ -1079,7 +1109,8 @@ irc_server_msgq_flush ()
}
}
else
- gui_printf_raw_data (irc_recv_msgq->server, 0, 1, _("(message dropped)"));
+ gui_chat_printf_raw_data (irc_recv_msgq->server, 0, 1,
+ _("(message dropped)"));
if (new_msg)
free (new_msg);
}
@@ -1099,8 +1130,12 @@ irc_server_msgq_flush ()
*/
void
-irc_server_recv (t_irc_server *server)
+irc_server_recv (void *arg_server)
{
+ t_irc_server *server;
+
+ server = (t_irc_server *)arg_server;
+
static char buffer[4096 + 2];
int num_read;
@@ -1109,7 +1144,8 @@ irc_server_recv (t_irc_server *server)
#ifdef HAVE_GNUTLS
if (server->ssl_connected)
- num_read = gnutls_record_recv (server->gnutls_sess, buffer, sizeof (buffer) - 2);
+ num_read = gnutls_record_recv (server->gnutls_sess, buffer,
+ sizeof (buffer) - 2);
else
#endif
num_read = recv (server->sock, buffer, sizeof (buffer) - 2, 0);
@@ -1122,15 +1158,99 @@ irc_server_recv (t_irc_server *server)
}
else
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s cannot read data from socket, disconnecting from server...\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ _("%s cannot read data from socket, "
+ "disconnecting from server...\n"),
+ WEECHAT_ERROR);
irc_server_disconnect (server, 1);
}
}
/*
+ * irc_server_timer: timer called each second to perform some operations
+ * on servers
+ */
+
+void
+irc_server_timer (void *empty)
+{
+ t_irc_server *ptr_server;
+ time_t new_time;
+ static struct timeval tv;
+ int diff;
+
+ (void) empty;
+
+ new_time = time (NULL);
+
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ /* check if reconnection is pending */
+ if ((!ptr_server->is_connected)
+ && (ptr_server->reconnect_start > 0)
+ && (new_time >= (ptr_server->reconnect_start + ptr_server->autoreconnect_delay)))
+ irc_server_reconnect (ptr_server);
+ else
+ {
+ if (ptr_server->is_connected)
+ {
+ /* send queued messages */
+ irc_server_outqueue_send (ptr_server);
+
+ /* check for lag */
+ if ((ptr_server->lag_check_time.tv_sec == 0)
+ && (new_time >= ptr_server->lag_next_check))
+ {
+ irc_server_sendf (ptr_server, "PING %s", ptr_server->address);
+ gettimeofday (&(ptr_server->lag_check_time), NULL);
+ }
+
+ /* check if it's time to autojoin channels (after command delay) */
+ if ((ptr_server->command_time != 0)
+ && (new_time >= ptr_server->command_time + ptr_server->command_delay))
+ {
+ irc_server_autojoin_channels (ptr_server);
+ ptr_server->command_time = 0;
+ }
+
+ /* lag timeout => disconnect */
+ if ((ptr_server->lag_check_time.tv_sec != 0)
+ && (irc_cfg_irc_lag_disconnect > 0))
+ {
+ gettimeofday (&tv, NULL);
+ diff = (int) weechat_get_timeval_diff (&(ptr_server->lag_check_time),
+ &tv);
+ if (diff / 1000 > irc_cfg_irc_lag_disconnect * 60)
+ {
+ gui_chat_printf_error (ptr_server->buffer,
+ _("%s lag is high, "
+ "disconnecting from "
+ "server...\n"),
+ WEECHAT_WARNING);
+ irc_server_disconnect (ptr_server, 1);
+ }
+ }
+ }
+ }
+ }
+}
+
+/*
+ * irc_server_timer_check_away: timer called to check away on servers
+ * (according to option "irc_check_away")
+ */
+
+void
+irc_server_timer_check_away (void *empty)
+{
+ (void) empty;
+
+ if (irc_cfg_irc_away_check > 0)
+ irc_server_check_away ();
+}
+
+/*
* irc_server_child_kill: kill child process and close pipe
*/
@@ -1206,24 +1326,47 @@ irc_server_reconnect_schedule (t_irc_server *server)
if (server->autoreconnect)
{
server->reconnect_start = time (NULL);
- irc_display_prefix (server, server->buffer, GUI_PREFIX_INFO);
- gui_printf (server->buffer, _("%s: Reconnecting to server in %d seconds\n"),
- PACKAGE_NAME, server->autoreconnect_delay);
+ gui_chat_printf_info (server->buffer,
+ _("%s: Reconnecting to server in %d seconds\n"),
+ PACKAGE_NAME, server->autoreconnect_delay);
}
else
server->reconnect_start = 0;
}
/*
+ * irc_server_login: login to IRC server
+ */
+
+void
+irc_server_login (t_irc_server *server)
+{
+ if ((server->password) && (server->password[0]))
+ irc_server_sendf (server, "PASS %s", server->password);
+
+ if (!server->nick)
+ server->nick = strdup (server->nick1);
+ irc_server_sendf (server,
+ "NICK %s\n"
+ "USER %s %s %s :%s",
+ server->nick, server->username, server->username,
+ server->address, server->realname);
+ gui_input_draw (gui_current_window->buffer, 1);
+}
+
+/*
* irc_server_child_read: read connection progress from child process
*/
void
-irc_server_child_read (t_irc_server *server)
+irc_server_child_read (void *arg_server)
{
+ t_irc_server *server;
char buffer[1];
int num_read;
+ server = (t_irc_server *)arg_server;
+
num_read = read (server->child_read, buffer, sizeof (buffer));
if (num_read > 0)
{
@@ -1239,10 +1382,10 @@ irc_server_child_read (t_irc_server *server)
(gnutls_transport_ptr) ((unsigned long) server->sock));
if (gnutls_handshake (server->gnutls_sess) < 0)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s gnutls handshake failed\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ _("%s GnuTLS handshake "
+ "failed\n"),
+ WEECHAT_ERROR);
irc_server_close_connection (server);
irc_server_reconnect_schedule (server);
return;
@@ -1251,62 +1394,61 @@ irc_server_child_read (t_irc_server *server)
#endif
/* kill child and login to server */
irc_server_child_kill (server);
- irc_send_login (server);
+ irc_server_login (server);
+ weechat_hook_remove (server->hook_fd);
+ server->hook_fd = weechat_hook_add_fd (server->sock,
+ WEECHAT_HOOK_FD_READ,
+ irc_server_recv,
+ server);
break;
/* adress not found */
case '1':
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- if (cfg_proxy_use)
- gui_printf (server->buffer,
- _("%s proxy address \"%s\" not found\n"),
- WEECHAT_ERROR, server->address);
- else
- gui_printf (server->buffer,
- _("%s address \"%s\" not found\n"),
- WEECHAT_ERROR, server->address);
+ gui_chat_printf_error (server->buffer,
+ (cfg_proxy_use) ?
+ _("%s proxy address \"%s\" not "
+ "found\n") :
+ _("%s address \"%s\" not found\n"),
+ WEECHAT_ERROR, server->address);
irc_server_close_connection (server);
irc_server_reconnect_schedule (server);
break;
/* IP address not found */
case '2':
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- if (cfg_proxy_use)
- gui_printf (server->buffer,
- _("%s proxy IP address not found\n"), WEECHAT_ERROR);
- else
- gui_printf (server->buffer,
- _("%s IP address not found\n"), WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ (cfg_proxy_use) ?
+ _("%s proxy IP address not found\n") :
+ _("%s IP address not found\n"),
+ WEECHAT_ERROR);
irc_server_close_connection (server);
irc_server_reconnect_schedule (server);
break;
/* connection refused */
case '3':
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- if (cfg_proxy_use)
- gui_printf (server->buffer,
- _("%s proxy connection refused\n"), WEECHAT_ERROR);
- else
- gui_printf (server->buffer,
- _("%s connection refused\n"), WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ (cfg_proxy_use) ?
+ _("%s proxy connection refused\n") :
+ _("%s connection refused\n"),
+ WEECHAT_ERROR);
irc_server_close_connection (server);
irc_server_reconnect_schedule (server);
break;
/* proxy fails to connect to server */
case '4':
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s proxy fails to establish connection to "
- "server (check username/password if used)\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ _("%s proxy fails to establish "
+ "connection to "
+ "server (check username/password if "
+ "used)\n"),
+ WEECHAT_ERROR);
irc_server_close_connection (server);
irc_server_reconnect_schedule (server);
break;
/* fails to set local hostname/IP */
case '5':
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s unable to set local hostname/IP\n"),
- WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ _("%s unable to set local "
+ "hostname/IP\n"),
+ WEECHAT_ERROR);
irc_server_close_connection (server);
irc_server_reconnect_schedule (server);
break;
@@ -1808,6 +1950,8 @@ irc_server_child (t_irc_server *server)
/*
* irc_server_connect: connect to an IRC server
+ * Return: 1 if ok
+ * 0 if error
*/
int
@@ -1817,46 +1961,70 @@ irc_server_connect (t_irc_server *server, int disable_autojoin)
#ifndef __CYGWIN__
pid_t pid;
#endif
+ char *log_filename;
+
+ if (!server->buffer)
+ {
+ log_filename = irc_log_get_filename (server->name, NULL, 0);
+ server->buffer = gui_buffer_new (gui_current_window, 0,
+ server->name, server->name,
+ GUI_BUFFER_ATTRIB_TEXT | GUI_BUFFER_ATTRIB_INPUT |
+ GUI_BUFFER_ATTRIB_NICKS,
+ irc_protocol,
+ irc_buffer_data_create (server),
+ &irc_buffer_data_free,
+ GUI_NOTIFY_LEVEL_DEFAULT,
+ NULL, server->nick,
+ irc_cfg_log_auto_server, log_filename,
+ 1);
+ if (log_filename)
+ free (log_filename);
+ if (!server->buffer)
+ return 0;
+ }
#ifndef HAVE_GNUTLS
if (server->ssl)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s cannot connect with SSL since WeeChat was not built "
- "with GNUtls support\n"), WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ _("%s cannot connect with SSL since WeeChat "
+ "was not built with GnuTLS support\n"),
+ WEECHAT_ERROR);
return 0;
}
#endif
- irc_display_prefix (server, server->buffer, GUI_PREFIX_INFO);
if (cfg_proxy_use)
- {
- gui_printf (server->buffer,
- _("%s: connecting to server %s:%d%s%s via %s proxy %s:%d%s...\n"),
- PACKAGE_NAME, 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"),
+ {
+ gui_chat_printf_info (server->buffer,
+ _("%s: connecting to server %s:%d%s%s via %s "
+ "proxy %s:%d%s...\n"),
+ PACKAGE_NAME, 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_type_values[cfg_proxy_type],
+ cfg_proxy_address, cfg_proxy_port,
(cfg_proxy_ipv6) ? " (IPv6)" : "");
- }
+ }
else
- {
- gui_printf (server->buffer,
- _("%s: connecting to server %s:%d%s%s...\n"),
- PACKAGE_NAME, server->address, server->port,
- (server->ipv6) ? " (IPv6)" : "",
- (server->ssl) ? " (SSL)" : "");
- weechat_log_printf (_("Connecting to server %s:%d%s%s...\n"),
+ {
+ gui_chat_printf_info (server->buffer,
+ _("%s: connecting to server %s:%d%s%s...\n"),
+ PACKAGE_NAME, 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 */
irc_server_close_connection (server);
@@ -1868,15 +2036,17 @@ irc_server_connect (t_irc_server *server, int disable_autojoin)
{
if (gnutls_init (&server->gnutls_sess, GNUTLS_CLIENT) != 0)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s gnutls init error\n"), WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ _("%s GnuTLS init error\n"),
+ WEECHAT_ERROR);
return 0;
}
gnutls_set_default_priority (server->gnutls_sess);
- gnutls_certificate_type_set_priority (server->gnutls_sess, gnutls_cert_type_prio);
+ gnutls_certificate_type_set_priority (server->gnutls_sess,
+ gnutls_cert_type_prio);
gnutls_protocol_set_priority (server->gnutls_sess, gnutls_prot_prio);
- gnutls_credentials_set (server->gnutls_sess, GNUTLS_CRD_CERTIFICATE, gnutls_xcred);
+ gnutls_credentials_set (server->gnutls_sess, GNUTLS_CRD_CERTIFICATE,
+ gnutls_xcred);
server->ssl_connected = 1;
}
#endif
@@ -1884,9 +2054,9 @@ irc_server_connect (t_irc_server *server, int disable_autojoin)
/* create pipe for child process */
if (pipe (child_pipe) < 0)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s cannot create pipe\n"), WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ _("%s cannot create pipe\n"),
+ WEECHAT_ERROR);
return 0;
}
server->child_read = child_pipe[0];
@@ -1899,9 +2069,9 @@ irc_server_connect (t_irc_server *server, int disable_autojoin)
server->sock = socket ((server->ipv6) ? AF_INET6 : AF_INET, SOCK_STREAM, 0);
if (server->sock == -1)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s cannot create socket\n"), WEECHAT_ERROR);
+ gui_chat_printf_error (server->buffer,
+ _("%s cannot create socket\n"),
+ WEECHAT_ERROR);
return 0;
}
@@ -1910,10 +2080,10 @@ irc_server_connect (t_irc_server *server, int disable_autojoin)
if (setsockopt (server->sock, SOL_SOCKET, SO_REUSEADDR,
(void *) &set, sizeof (set)) == -1)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s cannot set socket option \"SO_REUSEADDR\"\n"),
- WEECHAT_WARNING);
+ gui_chat_printf_error (server->buffer,
+ _("%s cannot set socket option "
+ "\"SO_REUSEADDR\"\n"),
+ WEECHAT_WARNING);
}
/* set SO_KEEPALIVE option for socket */
@@ -1921,10 +2091,10 @@ irc_server_connect (t_irc_server *server, int disable_autojoin)
if (setsockopt (server->sock, SOL_SOCKET, SO_KEEPALIVE,
(void *) &set, sizeof (set)) == -1)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR);
- gui_printf (server->buffer,
- _("%s cannot set socket option \"SO_KEEPALIVE\"\n"),
- WEECHAT_WARNING);
+ gui_chat_printf_error (server->buffer,
+ _("%s cannot set socket option "
+ "\"SO_KEEPALIVE\"\n"),
+ WEECHAT_WARNING);
}
#ifdef __CYGWIN__
@@ -1950,6 +2120,10 @@ irc_server_connect (t_irc_server *server, int disable_autojoin)
}
/* parent process */
server->child_pid = pid;
+ server->hook_fd = weechat_hook_add_fd (server->child_read,
+ WEECHAT_HOOK_FD_READ,
+ irc_server_child_read,
+ server);
#endif
server->disable_autojoin = disable_autojoin;
@@ -1964,9 +2138,8 @@ irc_server_connect (t_irc_server *server, int disable_autojoin)
void
irc_server_reconnect (t_irc_server *server)
{
- irc_display_prefix (server, server->buffer, GUI_PREFIX_INFO);
- gui_printf (server->buffer, _("%s: Reconnecting to server...\n"),
- PACKAGE_NAME);
+ gui_chat_printf_info (server->buffer,
+ _("Reconnecting to server...\n"));
server->reconnect_start = 0;
if (irc_server_connect (server, 0))
@@ -1990,9 +2163,6 @@ irc_server_auto_connect (int auto_connect, int temp_server)
if ( ((temp_server) && (ptr_server->temp_server))
|| ((!temp_server) && (auto_connect) && (ptr_server->autoconnect)) )
{
- (void) gui_buffer_new (gui_current_window, ptr_server, NULL,
- GUI_BUFFER_TYPE_STANDARD, 1);
- gui_window_redraw_buffer (gui_current_window->buffer);
if (!irc_server_connect (ptr_server, 0))
irc_server_reconnect_schedule (ptr_server);
}
@@ -2015,8 +2185,8 @@ irc_server_disconnect (t_irc_server *server, int reconnect)
ptr_channel = ptr_channel->next_channel)
{
irc_nick_free_all (ptr_channel);
- irc_display_prefix (NULL, ptr_channel->buffer, GUI_PREFIX_INFO);
- gui_printf (ptr_channel->buffer, _("Disconnected from server!\n"));
+ gui_chat_printf_info (ptr_channel->buffer,
+ _("Disconnected from server!\n"));
gui_nicklist_draw (ptr_channel->buffer, 1, 1);
gui_status_draw (ptr_channel->buffer, 1);
}
@@ -2025,10 +2195,8 @@ irc_server_disconnect (t_irc_server *server, int reconnect)
irc_server_close_connection (server);
if (server->buffer)
- {
- irc_display_prefix (server, server->buffer, GUI_PREFIX_INFO);
- gui_printf (server->buffer, _("Disconnected from server!\n"));
- }
+ gui_chat_printf_info (server->buffer,
+ _("Disconnected from server!\n"));
if (server->nick_modes)
{
@@ -2045,7 +2213,7 @@ irc_server_disconnect (t_irc_server *server, int reconnect)
server->lag = 0;
server->lag_check_time.tv_sec = 0;
server->lag_check_time.tv_usec = 0;
- server->lag_next_check = time (NULL) + cfg_irc_lag_check;
+ server->lag_next_check = time (NULL) + irc_cfg_irc_lag_check;
if ((reconnect) && (server->autoreconnect))
irc_server_reconnect_schedule (server);
@@ -2106,7 +2274,7 @@ irc_server_autojoin_channels (t_irc_server *server)
{
/* auto-join when connecting to server for first time */
if (!server->disable_autojoin && server->autojoin && server->autojoin[0])
- irc_send_cmd_join (server, NULL, server->autojoin);
+ irc_cmd_join_server (server, server->autojoin);
}
server->disable_autojoin = 0;
@@ -2386,6 +2554,7 @@ irc_server_print_log (t_irc_server *server)
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 (" hook_fd . . . . . . : 0x%X\n", server->hook_fd);
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);
diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h
new file mode 100644
index 000000000..2513d77e9
--- /dev/null
+++ b/src/plugins/irc/irc-server.h
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __WEECHAT_IRC_SERVER_H
+#define __WEECHAT_IRC_SERVER_H 1
+
+#include <regex.h>
+
+#ifdef HAVE_GNUTLS
+#include <gnutls/gnutls.h>
+#endif
+
+#include "irc-channel.h"
+#include "../../core/hook.h"
+#include "../../gui/gui.h"
+
+#ifndef NI_MAXHOST
+#define NI_MAXHOST 256
+#endif
+
+#define IRC_SERVER_DEFAULT_PORT 6667
+#define IRC_SERVER_DEFAULT_PREFIXES_LIST "@%+~&!-"
+
+#define irc_server_sendf_queued(server, fmt, argz...) \
+ if (server) \
+ { \
+ server->queue_msg = 1; \
+ irc_server_sendf (server, fmt, ##argz); \
+ server->queue_msg = 0; \
+ }
+
+/* output queue of messages to server (for sending slowly to server) */
+
+typedef struct t_irc_outqueue t_irc_outqueue;
+
+struct t_irc_outqueue
+{
+ char *message_before_mod; /* message before any modifier */
+ char *message_after_mod; /* message after modifier(s) */
+ int modified; /* message was modified by modifier(s) */
+ t_irc_outqueue *next_outqueue; /* pointer to next message in queue */
+ t_irc_outqueue *prev_outqueue; /* pointer to previous message in queue */
+};
+
+typedef struct t_irc_server t_irc_server;
+
+struct t_irc_server
+{
+ /* user choices */
+ char *name; /* internal name of server */
+ int autoconnect; /* = 1 if auto connect at startup */
+ int autoreconnect; /* = 1 if auto reco when disconnected */
+ int autoreconnect_delay; /* delay before trying again reconnect */
+ int temp_server; /* server is temporary (not saved!) */
+ char *address; /* address of server (IP or name) */
+ int port; /* port for server (6667 by default) */
+ int ipv6; /* use IPv6 protocol */
+ int ssl; /* SSL protocol */
+ char *password; /* password for server */
+ char *nick1; /* first nickname for the server */
+ char *nick2; /* alternate nickname */
+ char *nick3; /* 2nd alternate nickname */
+ char *username; /* user name */
+ char *realname; /* real name */
+ char *hostname; /* custom hostname */
+ char *command; /* command to run once connected */
+ int command_delay; /* delay after execution of command */
+ char *autojoin; /* channels to automatically join */
+ int autorejoin; /* auto rejoin channels when kicked */
+ char *notify_levels; /* channels notify levels */
+
+ /* internal vars */
+ pid_t child_pid; /* pid of child process (connecting) */
+ int child_read; /* to read into child pipe */
+ int child_write; /* to write into child pipe */
+ int sock; /* socket for server (IPv4 or IPv6) */
+ t_weechat_hook *hook_fd; /* hook for server socket or child pipe */
+ int is_connected; /* 1 if WeeChat is connected to server */
+ 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 */
+ char *nick_modes; /* nick modes */
+ char *prefix; /* nick prefix allowed (from msg 005) */
+ time_t reconnect_start; /* this time + delay = reconnect time */
+ time_t command_time; /* this time + command_delay = time to */
+ /* autojoin channels */
+ int reconnect_join; /* 1 if channels opened to rejoin */
+ int disable_autojoin; /* 1 if user asked to not autojoin chans */
+ int is_away; /* 1 is user is marked as away */
+ char *away_message; /* away message, NULL if not away */
+ time_t away_time; /* time() when user marking as away */
+ int lag; /* lag (in milliseconds) */
+ struct timeval lag_check_time; /* last time lag was checked (ping sent) */
+ time_t lag_next_check; /* time for next check */
+ regex_t *cmd_list_regexp; /* compiled Regular Expression for /list */
+ int queue_msg; /* set to 1 when queue (out) is required */
+ time_t last_user_message; /* time of last user message (anti flood)*/
+ t_irc_outqueue *outqueue; /* queue for outgoing user messages */
+ t_irc_outqueue *last_outqueue; /* last outgoing user message */
+ t_gui_buffer *buffer; /* GUI buffer allocated for server */
+ t_irc_channel *channels; /* opened channels on server */
+ t_irc_channel *last_channel; /* last opened channal on server */
+ t_irc_server *prev_server; /* link to previous server */
+ t_irc_server *next_server; /* link to next server */
+};
+
+/* IRC messages */
+
+typedef struct t_irc_message t_irc_message;
+
+struct t_irc_message
+{
+ t_irc_server *server; /* server pointer for received msg */
+ char *data; /* message content */
+ t_irc_message *next_message; /* link to next message */
+};
+
+extern t_irc_server *irc_servers;
+#ifdef HAVE_GNUTLS
+extern const int gnutls_cert_type_prio[];
+extern const int gnutls_prot_prio[];
+#endif
+extern t_irc_message *irc_recv_msgq, *irc_msgq_last_msg;
+
+#endif /* irc-server.h */
diff --git a/src/plugins/irc/irc.h b/src/plugins/irc/irc.h
index 9a94570c3..aa03107c6 100644
--- a/src/plugins/irc/irc.h
+++ b/src/plugins/irc/irc.h
@@ -20,389 +20,35 @@
#ifndef __WEECHAT_IRC_H
#define __WEECHAT_IRC_H 1
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <time.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <regex.h>
-
-#ifdef HAVE_GNUTLS
-#include <gnutls/gnutls.h>
-#endif
-
-#include "../../gui/gui.h"
-
-#ifndef NI_MAXHOST
-#define NI_MAXHOST 256
-#endif
-
-#define IRC_DEFAULT_PORT 6667
-#define IRC_DEFAULT_PREFIXES_LIST "@%+~&!-"
-
-/* nick types */
-
-#define IRC_NICK_CHANOWNER 1
-#define IRC_NICK_CHANADMIN 2
-#define IRC_NICK_OP 4
-#define IRC_NICK_HALFOP 8
-#define IRC_NICK_VOICE 16
-#define IRC_NICK_AWAY 32
-#define IRC_NICK_CHANADMIN2 64
-#define IRC_NICK_CHANUSER 128
-#define IRC_NICK_SET_FLAG(nick, set, flag) \
- if (set) \
- nick->flags |= flag; \
- else \
- nick->flags &= 0xFFFF - flag;
-
-#define irc_server_sendf_queued(server, fmt, argz...) \
- if (server) \
- { \
- server->queue_msg = 1; \
- irc_server_sendf (server, fmt, ##argz); \
- server->queue_msg = 0; \
- }
-
-typedef struct t_irc_nick t_irc_nick;
-
-struct t_irc_nick
-{
- char *nick; /* nickname */
- char *host; /* full hostname */
- 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 */
-};
-
-#define IRC_CHANNEL_PREFIX "#&+!"
-
-/* channel types */
-#define IRC_CHANNEL_TYPE_UNKNOWN -1
-#define IRC_CHANNEL_TYPE_CHANNEL 0
-#define IRC_CHANNEL_TYPE_PRIVATE 1
-#define IRC_CHANNEL_TYPE_DCC_CHAT 2
-
-#define IRC_CHANNEL_NICKS_SPEAKING_LIMIT 32
-
-typedef struct t_irc_channel t_irc_channel;
-
-struct t_irc_channel
-{
- int type; /* channel type */
- 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; /* 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) */
- int checking_away; /* = 1 if checking away with WHO cmd */
- char *away_message; /* to display away only once in private */
- int cycle; /* currently cycling (/part then /join) */
- int close; /* close request (/buffer close) */
- int display_creation_date; /* 1 if creation date should be displayed */
- int nick_completion_reset; /* 1 if nick completion should be rebuilt */
- /* there was some join/part on channel */
- t_irc_nick *nicks; /* nicks on the channel */
- t_irc_nick *last_nick; /* last nick on the channel */
- t_weelist *nicks_speaking; /* nicks speaking (for smart completion) */
- t_weelist *last_nick_speaking; /* last nick speaking */
- t_gui_buffer *buffer; /* GUI buffer allocated for channel */
- t_irc_channel *prev_channel; /* link to previous channel */
- t_irc_channel *next_channel; /* link to next channel */
-};
-
-/* server types */
-
-typedef struct t_irc_outqueue t_irc_outqueue;
-
-struct t_irc_outqueue
-{
- char *message_before_mod; /* message before any modifier */
- char *message_after_mod; /* message after modifier(s) */
- int modified; /* message was modified by modifier(s) */
- t_irc_outqueue *next_outqueue; /* pointer to next message in queue */
- t_irc_outqueue *prev_outqueue; /* pointer to previous message in queue */
-};
-
-typedef struct t_irc_server t_irc_server;
-
-struct t_irc_server
-{
- /* user choices */
- char *name; /* internal name of server */
- int autoconnect; /* = 1 if auto connect at startup */
- int autoreconnect; /* = 1 if auto reco when disconnected */
- int autoreconnect_delay; /* delay before trying again reconnect */
- int temp_server; /* server is temporary (will not be saved)*/
- char *address; /* address of server (IP or name) */
- int port; /* port for server (6667 by default) */
- int ipv6; /* use IPv6 protocol */
- int ssl; /* SSL protocol */
- char *password; /* password for server */
- char *nick1; /* first nickname for the server */
- char *nick2; /* alternate nickname */
- char *nick3; /* 2nd alternate nickname */
- char *username; /* user name */
- char *realname; /* real name */
- char *hostname; /* custom hostname */
- char *command; /* command to run once connected */
- int command_delay; /* delay after execution of command */
- char *autojoin; /* channels to automatically join */
- int autorejoin; /* auto rejoin channels when kicked */
- char *notify_levels; /* channels notify levels */
-
- /* internal vars */
- pid_t child_pid; /* pid of child process (connecting) */
- int child_read; /* to read into child pipe */
- 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 */
- 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 */
- char *nick_modes; /* nick modes */
- char *prefix; /* nick prefix allowed (from msg 005) */
- time_t reconnect_start; /* this time + delay = reconnect time */
- time_t command_time; /* this time + command_delay = time to */
- /* autojoin channels */
- int reconnect_join; /* 1 if channels opened to rejoin */
- int disable_autojoin; /* 1 if user asked to not autojoin chans */
- int is_away; /* 1 is user is marked as away */
- char *away_message; /* away message, NULL if not away */
- time_t away_time; /* time() when user marking as away */
- int lag; /* lag (in milliseconds) */
- struct timeval lag_check_time; /* last time lag was checked (ping sent) */
- time_t lag_next_check; /* time for next check */
- regex_t *cmd_list_regexp; /* compiled Regular Expression for /list */
- int queue_msg; /* set to 1 when queue (out) is required */
- time_t last_user_message; /* time of last user message (anti flood) */
- t_irc_outqueue *outqueue; /* queue for outgoing user messages */
- t_irc_outqueue *last_outqueue; /* last outgoing user message */
- t_gui_buffer *buffer; /* GUI buffer allocated for server */
- t_gui_buffer *saved_buffer; /* channel before jumping to next server */
- t_irc_channel *channels; /* opened channels on server */
- t_irc_channel *last_channel; /* last opened channal on server */
- t_irc_server *prev_server; /* link to previous server */
- t_irc_server *next_server; /* link to next server */
-};
-
-/* irc commands */
-
-typedef int (t_irc_recv_func)(t_irc_server *, char *, char *, char *);
-
-typedef struct t_irc_command t_irc_command;
-
-struct t_irc_command
-{
- char *command_name; /* IRC command name */
- char *command_description; /* command description (for /help) */
- char *arguments; /* command arguments (for /help) */
- char *arguments_description; /* arguments description (for /help) */
- char *completion_template; /* template for completion */
- /* NULL=no completion, ""=default (nick) */
- int min_arg, max_arg; /* min & max number of arguments */
- int conversion; /* = 1 if cmd args are converted (charset */
- /* and color) before sending to server */
- int needs_connection; /* = 1 if cmd needs server connection */
- int (*cmd_function_args)(t_irc_server *, t_irc_channel *, int, char **);
- /* function called when user enters cmd */
- int (*cmd_function_1arg)(t_irc_server *, t_irc_channel *, char *);
- /* function called when user enters cmd */
- t_irc_recv_func *recv_function; /* function called when cmd is received */
-};
-
-/* irc messages */
-
-typedef struct t_irc_message t_irc_message;
-
-struct t_irc_message
-{
- t_irc_server *server; /* server pointer for received msg */
- char *data; /* message content */
- t_irc_message *next_message; /* link to next message */
-};
-
-/* DCC types */
-
-#define IRC_DCC_CHAT_RECV 0 /* receiving DCC chat */
-#define IRC_DCC_CHAT_SEND 1 /* sending DCC chat */
-#define IRC_DCC_FILE_RECV 2 /* incoming DCC file */
-#define IRC_DCC_FILE_SEND 3 /* sending DCC file */
-
-/* DCC status */
-
-#define IRC_DCC_WAITING 0 /* waiting for host answer */
-#define IRC_DCC_CONNECTING 1 /* connecting to host */
-#define IRC_DCC_ACTIVE 2 /* sending/receiving data */
-#define IRC_DCC_DONE 3 /* transfer done */
-#define IRC_DCC_FAILED 4 /* DCC failed */
-#define IRC_DCC_ABORTED 5 /* DCC aborted by user */
-
-/* DCC blocksize (for file) */
-
-#define IRC_DCC_MIN_BLOCKSIZE 1024 /* min DCC block size when sending file */
-#define IRC_DCC_MAX_BLOCKSIZE 102400 /* max DCC block size when sending file */
-
-/* DCC errors (for file) */
-
-#define IRC_DCC_NO_ERROR 0 /* no error to report, all ok! */
-#define IRC_DCC_ERROR_READ_LOCAL 1 /* unable to read local file */
-#define IRC_DCC_ERROR_SEND_BLOCK 2 /* unable to send block to receiver */
-#define IRC_DCC_ERROR_READ_ACK 3 /* unable to read ACK from receiver */
-#define IRC_DCC_ERROR_CONNECT_SENDER 4 /* unable to connect to sender */
-#define IRC_DCC_ERROR_RECV_BLOCK 5 /* unable to recv block from sender */
-#define IRC_DCC_ERROR_WRITE_LOCAL 6 /* unable to write to local file */
-
-/* DCC macros for type */
-
-#define IRC_DCC_IS_CHAT(type) ((type == IRC_DCC_CHAT_RECV) || \
- (type == IRC_DCC_CHAT_SEND))
-#define IRC_DCC_IS_FILE(type) ((type == IRC_DCC_FILE_RECV) || \
- (type == IRC_DCC_FILE_SEND))
-#define IRC_DCC_IS_RECV(type) ((type == IRC_DCC_CHAT_RECV) || \
- (type == IRC_DCC_FILE_RECV))
-#define IRC_DCC_IS_SEND(type) ((type == IRC_DCC_CHAT_SEND) || \
- (type == IRC_DCC_FILE_SEND))
-
-/* DCC macro for status */
-
-#define IRC_DCC_ENDED(status) ((status == IRC_DCC_DONE) || \
- (status == IRC_DCC_FAILED) || \
- (status == IRC_DCC_ABORTED))
-
-typedef struct t_irc_dcc t_irc_dcc;
-
-struct t_irc_dcc
-{
- t_irc_server *server; /* irc server */
- t_irc_channel *channel; /* irc channel (for DCC chat only) */
- int type; /* DCC type (file/chat, send/receive) */
- int status; /* DCC status (waiting, sending, ..) */
- time_t start_time; /* the time when DCC started */
- time_t start_transfer; /* the time when DCC transfer started */
- unsigned long addr; /* IP address */
- int port; /* port */
- char *nick; /* remote nick */
- int sock; /* socket for connection */
- pid_t child_pid; /* pid of child process (sending/recving) */
- int child_read; /* to read into child pipe */
- int child_write; /* to write into child pipe */
- char *unterminated_message; /* beginning of a message in input buf */
- int fast_send; /* fase send for files: does not wait ACK */
- int file; /* local file (for reading or writing) */
- char *filename; /* filename (given by sender) */
- char *local_filename; /* local filename (with path) */
- int filename_suffix; /* suffix (.1 for ex) if renaming file */
- int blocksize; /* block size for sending file */
- unsigned long size; /* file size */
- unsigned long pos; /* number of bytes received/sent */
- unsigned long ack; /* number of bytes received OK */
- unsigned long start_resume; /* start of resume (in bytes) */
- time_t last_check_time; /* last time we looked at bytes sent/recv */
- unsigned long last_check_pos; /* bytes sent/recv at last check */
- 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 */
-};
-
-/* ignore types */
-
-/* pre-defined ignore types, all other types are made with IRC commands */
-/* for example: part join quit notice invite ... */
-
-#define IRC_IGNORE_ACTION "action"
-#define IRC_IGNORE_CTCP "ctcp"
-#define IRC_IGNORE_DCC "dcc"
-#define IRC_IGNORE_PRIVATE "pv"
-
-typedef struct t_irc_ignore t_irc_ignore;
-
-struct t_irc_ignore
-{
- char *mask; /* nickname or mask */
- char *type; /* type of ignore */
- char *channel_name; /* name of channel, "*" == all */
- char *server_name; /* name of server, "*" == all */
- t_irc_ignore *prev_ignore; /* pointer to previous ignore */
- t_irc_ignore *next_ignore; /* pointer to next ignore */
-};
-
-/* variables */
-
-extern t_irc_command irc_commands[];
-extern t_irc_server *irc_servers;
-#ifdef HAVE_GNUTLS
-extern const int gnutls_cert_type_prio[];
-extern const int gnutls_prot_prio[];
-#endif
-extern t_irc_message *irc_recv_msgq, *irc_msgq_last_msg;
-extern int irc_check_away;
-extern t_irc_dcc *irc_dcc_list;
-extern t_irc_dcc *irc_last_dcc;
-extern char *irc_dcc_status_string[6];
-extern t_irc_ignore *irc_ignore;
-extern t_irc_ignore *irc_last_ignore;
+#include "irc-buffer.h"
+#include "irc-color.h"
+#include "irc-command.h"
+#include "irc-config.h"
+#include "irc-server.h"
+#include "irc-channel.h"
+#include "irc-nick.h"
+#include "irc-dcc.h"
+#include "irc-protocol.h"
-/* server functions (irc-server.c) */
+#include "../protocol.h"
-extern void irc_server_init (t_irc_server *);
-extern int irc_server_init_with_url (char *, t_irc_server *);
-extern t_irc_server *irc_server_alloc ();
-extern void irc_server_outqueue_free_all (t_irc_server *);
-extern void irc_server_destroy (t_irc_server *);
-extern void irc_server_free (t_irc_server *);
-extern void irc_server_free_all ();
-extern t_irc_server *irc_server_new (char *, int, int, int, int, char *, int, int, int,
- char *, char *, char *, char *, char *, char *,
- char *, char *, int, char *, int, char *);
-extern t_irc_server *irc_server_duplicate (t_irc_server *, char *);
-extern int irc_server_rename (t_irc_server *, char *);
-extern int irc_server_send (t_irc_server *, char *, int);
-extern void irc_server_outqueue_send (t_irc_server *);
-extern void irc_server_sendf (t_irc_server *, char *, ...);
-extern void irc_server_parse_message (char *, char **, char **, char **);
-extern void irc_server_recv (t_irc_server *);
-extern void irc_server_child_read (t_irc_server *);
-extern void irc_server_convbase64_8x3_to_6x4 (char *, char*);
-extern void irc_server_base64encode (char *, char *);
-extern int irc_server_pass_httpproxy (int, char*, int);
-extern int irc_server_resolve (char *, char *, int *);
-extern int irc_server_pass_socks4proxy (int, char*, int, char*);
-extern int irc_server_pass_socks5proxy (int, char*, int);
-extern int irc_server_pass_proxy (int, char*, int, char*);
-extern int irc_server_connect (t_irc_server *, int);
-extern void irc_server_reconnect (t_irc_server *);
-extern void irc_server_auto_connect (int, int);
-extern void irc_server_disconnect (t_irc_server *, int);
-extern void irc_server_disconnect_all ();
-extern void irc_server_autojoin_channels ();
-extern t_irc_server *irc_server_search (char *);
-extern int irc_server_get_number_connected ();
-extern void irc_server_get_number_buffer (t_irc_server *, int *, int *);
-extern int irc_server_name_already_exists (char *);
-extern int irc_server_get_channel_count (t_irc_server *);
-extern int irc_server_get_pv_count (t_irc_server *);
-extern void irc_server_remove_away ();
-extern void irc_server_check_away ();
-extern void irc_server_set_away (t_irc_server *, char *, int);
-extern int irc_server_get_default_notify_level (t_irc_server *);
-extern void irc_server_set_default_notify_level (t_irc_server *, int);
-extern void irc_server_print_log (t_irc_server *);
+#define _PROTOCOL_NAME "irc"
+#define _PROTOCOL_VERSION "0.1"
+#define _PROTOCOL_DESC "IRC (Internet Relay Chat)"
+
+extern t_weechat_protocol *irc_protocol;
+extern t_weechat_hook *irc_hook_timer, *irc_hook_timer_check_away;
+
+/* buffer functions (irc-buffer.c) */
+
+extern t_irc_buffer_data *irc_buffer_data_create (t_irc_server *);
+extern void irc_buffer_data_free (t_gui_buffer *);
+extern void irc_buffer_merge_servers (t_gui_window *);
+extern void irc_buffer_split_server (t_gui_window *);
/* channel functions (irc-channel.c) */
-extern t_irc_channel *irc_channel_new (t_irc_server *, int, char *);
+extern t_irc_channel *irc_channel_new (t_irc_server *, int, char *, int);
extern void irc_channel_free (t_irc_server *, t_irc_channel *);
extern void irc_channel_free_all (t_irc_server *);
extern t_irc_channel *irc_channel_search (t_irc_server *, char *);
@@ -419,26 +65,83 @@ extern void irc_channel_set_notify_level (t_irc_server *, t_irc_channel *, int);
extern void irc_channel_add_nick_speaking (t_irc_channel *, char *);
extern void irc_channel_print_log (t_irc_channel *);
-/* nick functions (irc-nick.c) */
-
-extern int irc_nick_find_color (t_irc_nick *);
-extern t_irc_nick *irc_nick_new (t_irc_server *, t_irc_channel *, char *,
- int, int, int, int, int, int, int);
-extern void irc_nick_resort (t_irc_channel *, t_irc_nick *);
-extern void irc_nick_change (t_irc_channel *, t_irc_nick *, char *);
-extern void irc_nick_free (t_irc_channel *, t_irc_nick *);
-extern void irc_nick_free_all (t_irc_channel *);
-extern t_irc_nick *irc_nick_search (t_irc_channel *, char *);
-extern void irc_nick_count (t_irc_channel *, int *, int *, int *, int *, int *);
-extern int irc_nick_get_max_length (t_irc_channel *);
-extern void irc_nick_set_away (t_irc_channel *, t_irc_nick *, int);
-extern void irc_nick_print_log (t_irc_nick *);
-
-/* mode functions (irc-mode.c) */
-
-extern void irc_mode_channel_set (t_irc_server *, t_irc_channel *, char *);
-extern void irc_mode_user_set (t_irc_server *, char *);
-extern int irc_mode_nick_prefix_allowed (t_irc_server *, char);
+/* color functions (irc-color.c) */
+
+extern unsigned char *irc_color_decode (unsigned char *, int, int);
+extern unsigned char *irc_color_decode_for_user_entry (unsigned char *);
+extern unsigned char *irc_color_encode (unsigned char *, int);
+
+/* IRC commands (irc-command.c) */
+
+extern int irc_cmd_admin (t_gui_window *, char *, int, char **);
+extern void irc_cmd_mode_nicks (t_irc_server *, char *, char *, char *, int, char **);
+extern int irc_cmd_ame (t_gui_window *, char *, int, char **);
+extern int irc_cmd_amsg (t_gui_window *, char *, int, char **);
+extern void irc_cmd_away_server (t_irc_server *, char *);
+extern int irc_cmd_away (t_gui_window *, char *, int, char **);
+extern int irc_cmd_ban (t_gui_window *, char *, int, char **);
+extern int irc_cmd_ctcp (t_gui_window *, char *, int, char **);
+extern int irc_cmd_cycle (t_gui_window *, char *, int, char **);
+extern int irc_cmd_dehalfop (t_gui_window *, char *, int, char **);
+extern int irc_cmd_deop (t_gui_window *, char *, int, char **);
+extern int irc_cmd_devoice (t_gui_window *, char *, int, char **);
+extern int irc_cmd_die (t_gui_window *, char *, int, char **);
+extern int irc_cmd_halfop (t_gui_window *, char *, int, char **);
+extern int irc_cmd_info (t_gui_window *, char *, int, char **);
+extern int irc_cmd_invite (t_gui_window *, char *, int, char **);
+extern int irc_cmd_ison (t_gui_window *, char *, int, char **);
+extern void irc_cmd_join_server (t_irc_server *, char *);
+extern int irc_cmd_join (t_gui_window *, char *, int, char **);
+extern int irc_cmd_kick (t_gui_window *, char *, int, char **);
+extern int irc_cmd_kickban (t_gui_window *, char *, int, char **);
+extern int irc_cmd_kill (t_gui_window *, char *, int, char **);
+extern int irc_cmd_links (t_gui_window *, char *, int, char **);
+extern int irc_cmd_list (t_gui_window *, char *, int, char **);
+extern int irc_cmd_lusers (t_gui_window *, char *, int, char **);
+extern int irc_cmd_me (t_gui_window *, char *, int, char **);
+extern void irc_cmd_mode_server (t_irc_server *, char *);
+extern int irc_cmd_mode (t_gui_window *, char *, int, char **);
+extern int irc_cmd_motd (t_gui_window *, char *, int, char **);
+extern int irc_cmd_msg (t_gui_window *, char *, int, char **);
+extern int irc_cmd_names (t_gui_window *, char *, int, char **);
+extern int irc_cmd_nick (t_gui_window *, char *, int, char **);
+extern int irc_cmd_notice (t_gui_window *, char *, int, char **);
+extern int irc_cmd_op (t_gui_window *, char *, int, char **);
+extern int irc_cmd_oper (t_gui_window *, char *, int, char **);
+extern int irc_cmd_part (t_gui_window *, char *, int, char **);
+extern int irc_cmd_ping (t_gui_window *, char *, int, char **);
+extern int irc_cmd_pong (t_gui_window *, char *, int, char **);
+extern int irc_cmd_query (t_gui_window *, char *, int, char **);
+extern int irc_cmd_quit (t_gui_window *, char *, int, char **);
+extern int irc_cmd_quote (t_gui_window *, char *, int, char **);
+extern int irc_cmd_rehash (t_gui_window *, char *, int, char **);
+extern int irc_cmd_restart (t_gui_window *, char *, int, char **);
+extern int irc_cmd_service (t_gui_window *, char *, int, char **);
+extern int irc_cmd_servlist (t_gui_window *, char *, int, char **);
+extern int irc_cmd_squery (t_gui_window *, char *, int, char **);
+extern int irc_cmd_squit (t_gui_window *, char *, int, char **);
+extern int irc_cmd_stats (t_gui_window *, char *, int, char **);
+extern int irc_cmd_summon (t_gui_window *, char *, int, char **);
+extern int irc_cmd_time (t_gui_window *, char *, int, char **);
+extern int irc_cmd_topic (t_gui_window *, char *, int, char **);
+extern int irc_cmd_trace (t_gui_window *, char *, int, char **);
+extern int irc_cmd_unban (t_gui_window *, char *, int, char **);
+extern int irc_cmd_userhost (t_gui_window *, char *, int, char **);
+extern int irc_cmd_users (t_gui_window *, char *, int, char **);
+extern int irc_cmd_version (t_gui_window *, char *, int, char **);
+extern int irc_cmd_voice (t_gui_window *, char *, int, char **);
+extern int irc_cmd_wallops (t_gui_window *, char *, int, char **);
+extern int irc_cmd_who (t_gui_window *, char *, int, char **);
+extern int irc_cmd_whois (t_gui_window *, char *, int, char **);
+extern int irc_cmd_whowas (t_gui_window *, char *, int, char **);
+
+/* config functions (irc-config.c) */
+
+extern void irc_config_create_dirs ();
+extern void *irc_config_get_server_option_ptr (t_irc_server *, char *);
+extern int irc_config_set_server_value (t_irc_server *, char *, char *);
+extern int irc_config_read ();
+extern int irc_config_write ();
/* DCC functions (irc-dcc.c) */
@@ -460,154 +163,154 @@ extern void irc_dcc_handle ();
extern void irc_dcc_end ();
extern void irc_dcc_print_log ();
-/* IRC display (irc-diplay.c) */
+/* display functions (irc-diplay.c) */
extern void irc_display_hide_password (char *, int);
-extern void irc_display_prefix (t_irc_server *, t_gui_buffer *, char *);
extern void irc_display_nick (t_gui_buffer *, t_irc_nick *, char *, int,
- int, int, int);
+ int, char *, int);
extern void irc_display_away (t_irc_server *, char *, char *);
-extern void irc_display_mode (t_irc_server *, t_gui_buffer *, char *, char *,
+extern void irc_display_mode (t_gui_buffer *, char *, char *,
char, char *, char *, char *, char *);
extern void irc_display_server (t_irc_server *ptr_server, int);
-/* IRC commands issued by user (irc-send.c) */
-
-extern void irc_send_login (t_irc_server *);
-extern int irc_send_cmd_admin (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_ame (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_amsg (t_irc_server *, t_irc_channel *, char *);
-extern void irc_send_away (t_irc_server *, char *);
-extern int irc_send_cmd_away (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_ban (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_ctcp (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_cycle (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_dehalfop (t_irc_server *, t_irc_channel *, int, char **);
-extern int irc_send_cmd_deop (t_irc_server *, t_irc_channel *, int, char **);
-extern int irc_send_cmd_devoice (t_irc_server *, t_irc_channel *, int, char **);
-extern int irc_send_cmd_die (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_halfop (t_irc_server *, t_irc_channel *, int, char **);
-extern int irc_send_cmd_info (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_invite (t_irc_server *, t_irc_channel *, int, char **);
-extern int irc_send_cmd_ison (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_join (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_kick (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_kickban (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_kill (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_links (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_list (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_lusers (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_me (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_mode (t_irc_server *, t_irc_channel *, char *);
-extern void irc_send_mode_nicks (t_irc_server *, char *, char *, char *, int, char **);
-extern int irc_send_cmd_motd (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_msg (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_names (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_nick (t_irc_server *, t_irc_channel *, int, char **);
-extern int irc_send_cmd_notice (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_op (t_irc_server *, t_irc_channel *, int, char **);
-extern int irc_send_cmd_oper (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_part (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_ping (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_pong (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_query (t_irc_server *, t_irc_channel *, char *);
-extern void irc_send_quit_server (t_irc_server *, char *);
-extern int irc_send_cmd_quit (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_quote (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_rehash (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_restart (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_service (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_servlist (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_squery (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_squit (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_stats (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_summon (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_time (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_topic (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_trace (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_unban (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_userhost (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_users (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_version (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_voice (t_irc_server *, t_irc_channel *, int, char **);
-extern int irc_send_cmd_wallops (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_who (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_whois (t_irc_server *, t_irc_channel *, char *);
-extern int irc_send_cmd_whowas (t_irc_server *, t_irc_channel *, char *);
-
-/* IRC commands executed when received from server (irc-recv.c) */
-
-extern int irc_recv_is_highlight (char *, char *);
-extern int irc_recv_command (t_irc_server *, char *, char *, char *, char *);
-extern int irc_recv_cmd_error (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_invite (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_join (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_kick (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_kill (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_mode (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_nick (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_notice (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_part (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_ping (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_pong (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_privmsg (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_quit (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_server_mode_reason (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_server_msg (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_server_reply (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_topic (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_wallops (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_001 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_005 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_221 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_301 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_302 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_303 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_305 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_306 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_whois_nick_msg (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_310 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_311 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_312 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_314 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_315 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_317 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_319 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_321 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_322 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_323 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_324 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_327 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_329 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_331 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_332 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_333 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_338 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_341 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_344 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_345 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_348 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_349 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_351 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_352 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_353 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_365 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_366 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_367 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_368 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_432 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_433 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_438 (t_irc_server *, char *, char *, char *);
-extern int irc_recv_cmd_671 (t_irc_server *, char *, char *, char *);
-
-/* ignore functions (irc-ignore.c) */
-
-extern int irc_ignore_check (char *, char *, char *, char *);
-extern t_irc_ignore *irc_ignore_add (char *, char *, char *, char *);
-extern t_irc_ignore *irc_ignore_add_from_config (char *);
-extern void irc_ignore_free_all ();
-extern int irc_ignore_search_free (char *, char *, char *, char *);
-extern int irc_ignore_search_free_by_number (int);
-extern void irc_ignore_print_log ();
+/* input functions (irc-input.c) */
+
+extern int irc_input_data (t_gui_window *, char *);
+
+/* log functions (irc-log.c) */
+extern char *irc_log_get_filename (char *, char *, int);
+
+/* mode functions (irc-mode.c) */
+
+extern void irc_mode_channel_set (t_irc_server *, t_irc_channel *, char *);
+extern void irc_mode_user_set (t_irc_server *, char *);
+extern int irc_mode_nick_prefix_allowed (t_irc_server *, char);
+
+/* nick functions (irc-nick.c) */
+
+extern int irc_nick_find_color (t_irc_nick *);
+extern void irc_nick_get_gui_infos (t_irc_nick *, int *, char *, int *);
+extern t_irc_nick *irc_nick_new (t_irc_server *, t_irc_channel *, char *,
+ int, int, int, int, int, int, int);
+extern void irc_nick_change (t_irc_server *, t_irc_channel *, t_irc_nick *, char *);
+extern void irc_nick_free (t_irc_channel *, t_irc_nick *);
+extern void irc_nick_free_all (t_irc_channel *);
+extern t_irc_nick *irc_nick_search (t_irc_channel *, char *);
+extern void irc_nick_count (t_irc_channel *, int *, int *, int *, int *, int *);
+extern void irc_nick_set_away (t_irc_channel *, t_irc_nick *, int);
+extern void irc_nick_print_log (t_irc_nick *);
+
+/* IRC protocol (irc-protocol.c) */
+
+extern int irc_protocol_is_highlight (char *, char *);
+extern int irc_protocol_recv_command (t_irc_server *, char *, char *, char *, char *);
+extern int irc_protocol_cmd_error (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_invite (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_join (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_kick (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_kill (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_mode (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_nick (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_notice (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_part (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_ping (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_pong (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_privmsg (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_quit (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_server_mode_reason (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_server_msg (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_server_reply (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_topic (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_wallops (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_001 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_005 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_221 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_301 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_302 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_303 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_305 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_306 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_whois_nick_msg (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_310 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_311 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_312 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_314 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_315 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_317 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_319 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_321 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_322 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_323 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_324 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_327 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_329 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_331 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_332 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_333 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_338 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_341 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_344 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_345 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_348 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_349 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_351 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_352 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_353 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_365 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_366 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_367 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_368 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_432 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_433 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_438 (t_irc_server *, char *, char *, char *, char *, int, int);
+extern int irc_protocol_cmd_671 (t_irc_server *, char *, char *, char *, char *, int, int);
+
+/* server functions (irc-server.c) */
+
+extern void irc_server_init (t_irc_server *);
+extern int irc_server_init_with_url (char *, t_irc_server *);
+extern t_irc_server *irc_server_alloc ();
+extern void irc_server_outqueue_free_all (t_irc_server *);
+extern void irc_server_destroy (t_irc_server *);
+extern void irc_server_free (t_irc_server *);
+extern void irc_server_free_all ();
+extern t_irc_server *irc_server_new (char *, int, int, int, int, char *, int, int, int,
+ char *, char *, char *, char *, char *, char *,
+ char *, char *, int, char *, int, char *);
+extern t_irc_server *irc_server_duplicate (t_irc_server *, char *);
+extern int irc_server_rename (t_irc_server *, char *);
+extern int irc_server_send (t_irc_server *, char *, int);
+extern void irc_server_outqueue_send (t_irc_server *);
+extern void irc_server_sendf (t_irc_server *, char *, ...);
+extern void irc_server_parse_message (char *, char **, char **, char **);
+extern void irc_server_recv (void *);
+extern void irc_server_timer (void *);
+extern void irc_server_timer_check_away (void *);
+extern void irc_server_child_read (void *);
+extern void irc_server_convbase64_8x3_to_6x4 (char *, char*);
+extern void irc_server_base64encode (char *, char *);
+extern int irc_server_pass_httpproxy (int, char*, int);
+extern int irc_server_resolve (char *, char *, int *);
+extern int irc_server_pass_socks4proxy (int, char*, int, char*);
+extern int irc_server_pass_socks5proxy (int, char*, int);
+extern int irc_server_pass_proxy (int, char*, int, char*);
+extern int irc_server_connect (t_irc_server *, int);
+extern void irc_server_reconnect (t_irc_server *);
+extern void irc_server_auto_connect (int, int);
+extern void irc_server_disconnect (t_irc_server *, int);
+extern void irc_server_disconnect_all ();
+extern void irc_server_autojoin_channels ();
+extern t_irc_server *irc_server_search (char *);
+extern int irc_server_get_number_connected ();
+extern void irc_server_get_number_buffer (t_irc_server *, int *, int *);
+extern int irc_server_name_already_exists (char *);
+extern int irc_server_get_channel_count (t_irc_server *);
+extern int irc_server_get_pv_count (t_irc_server *);
+extern void irc_server_remove_away ();
+extern void irc_server_check_away ();
+extern void irc_server_set_away (t_irc_server *, char *, int);
+extern int irc_server_get_default_notify_level (t_irc_server *);
+extern void irc_server_set_default_notify_level (t_irc_server *, int);
+extern void irc_server_print_log (t_irc_server *);
#endif /* irc.h */