mirror of
https://github.com/weechat/weechat.git
synced 2026-07-03 08:13:14 +02:00
Added buffer argument in command hooks, code cleanup in IRC plugin
This commit is contained in:
+6
-5
@@ -173,13 +173,13 @@ hook_command (void *plugin, char *command, char *description,
|
||||
*/
|
||||
|
||||
int
|
||||
hook_command_exec (void *plugin, char *string)
|
||||
hook_command_exec (void *buffer, char *string)
|
||||
{
|
||||
struct t_hook *ptr_hook, *next_hook;
|
||||
char **argv, **argv_eol;
|
||||
int argc, rc;
|
||||
|
||||
if (!string || !string[0])
|
||||
|
||||
if (!buffer || !string || !string[0])
|
||||
return -1;
|
||||
|
||||
argv = string_explode (string, " ", 0, 0, &argc);
|
||||
@@ -197,13 +197,14 @@ hook_command_exec (void *plugin, char *string)
|
||||
|
||||
if ((ptr_hook->type == HOOK_TYPE_COMMAND)
|
||||
&& (!ptr_hook->running)
|
||||
&& (!plugin || (plugin == ptr_hook->plugin))
|
||||
&& (!((struct t_gui_buffer *)buffer)->plugin
|
||||
|| (((struct t_gui_buffer *)buffer)->plugin == ptr_hook->plugin))
|
||||
&& (string_strcasecmp (argv[0] + 1,
|
||||
HOOK_COMMAND(ptr_hook, command)) == 0))
|
||||
{
|
||||
ptr_hook->running = 1;
|
||||
rc = (int) (HOOK_COMMAND(ptr_hook, callback))
|
||||
(ptr_hook->callback_data, argc, argv, argv_eol);
|
||||
(ptr_hook->callback_data, buffer, argc, argv, argv_eol);
|
||||
if (hook_valid (ptr_hook))
|
||||
ptr_hook->running = 0;
|
||||
if (rc == PLUGIN_RC_FAILED)
|
||||
|
||||
+3
-3
@@ -55,11 +55,11 @@ struct t_hook
|
||||
void *hook_data; /* hook specific data */
|
||||
|
||||
int running; /* 1 if hook is currently running */
|
||||
struct t_hook *prev_hook; /* pointer to previous hook */
|
||||
struct t_hook *next_hook; /* pointer to next hook */
|
||||
struct t_hook *prev_hook; /* link to previous hook */
|
||||
struct t_hook *next_hook; /* link to next hook */
|
||||
};
|
||||
|
||||
typedef int (t_hook_callback_command)(void *, int, char **, char **);
|
||||
typedef int (t_hook_callback_command)(void *, void *, int, char **, char **);
|
||||
|
||||
struct t_hook_command
|
||||
{
|
||||
|
||||
@@ -76,7 +76,7 @@ input_exec_command (struct t_gui_buffer *buffer, char *string,
|
||||
rc = -1;
|
||||
if (!only_builtin)
|
||||
{
|
||||
rc = hook_command_exec (buffer->plugin, command);
|
||||
rc = hook_command_exec (buffer, command);
|
||||
/*vars_replaced = alias_replace_vars (window, ptr_args);
|
||||
rc = plugin_cmd_handler_exec (window->buffer->protocol, command + 1,
|
||||
(vars_replaced) ? vars_replaced : ptr_args);
|
||||
@@ -375,7 +375,7 @@ input_data (struct t_gui_buffer *buffer, char *data, int only_builtin)
|
||||
|
||||
if (command_is_command (ptr_data))
|
||||
{
|
||||
/* WeeChat or protocol command */
|
||||
/* WeeChat or plugin command */
|
||||
(void) input_exec_command (buffer, ptr_data,
|
||||
only_builtin);
|
||||
}
|
||||
@@ -384,7 +384,7 @@ input_data (struct t_gui_buffer *buffer, char *data, int only_builtin)
|
||||
if ((ptr_data[0] == '/') && (ptr_data[1] == '/'))
|
||||
ptr_data++;
|
||||
|
||||
hook_command_exec (buffer->plugin, ptr_data);
|
||||
hook_command_exec (buffer, ptr_data);
|
||||
|
||||
if (buffer->input_data_cb)
|
||||
{
|
||||
|
||||
+21
-10
@@ -44,9 +44,12 @@ static struct t_weechat_plugin *weechat_plugin = NULL;
|
||||
*/
|
||||
|
||||
static int
|
||||
demo_printf_command_cb (void *data, int argc, char **argv, char **argv_eol)
|
||||
demo_printf_command_cb (void *data, void *buffer, int argc, char **argv,
|
||||
char **argv_eol)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) buffer;
|
||||
(void) argv;
|
||||
|
||||
if (argc > 1)
|
||||
@@ -80,18 +83,21 @@ demo_printf_command_cb (void *data, int argc, char **argv, char **argv_eol)
|
||||
*/
|
||||
|
||||
static int
|
||||
demo_buffer_command_cb (void *data, int argc, char **argv, char **argv_eol)
|
||||
demo_buffer_command_cb (void *data, void *buffer, int argc, char **argv,
|
||||
char **argv_eol)
|
||||
{
|
||||
struct t_gui_buffer *buffer;
|
||||
|
||||
struct t_gui_buffer *new_buffer;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) buffer;
|
||||
(void) argv_eol;
|
||||
|
||||
if (argc > 2)
|
||||
{
|
||||
buffer = weechat_buffer_new (argv[1], argv[2]);
|
||||
if (buffer)
|
||||
weechat_buffer_set (buffer, "display", "1");
|
||||
new_buffer = weechat_buffer_new (argv[1], argv[2]);
|
||||
if (new_buffer)
|
||||
weechat_buffer_set (new_buffer, "display", "1");
|
||||
}
|
||||
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
@@ -162,12 +168,14 @@ demo_print_list (void *list, char *item_name)
|
||||
*/
|
||||
|
||||
static int
|
||||
demo_list_command_cb (void *data, int argc, char **argv, char **argv_eol)
|
||||
demo_list_command_cb (void *data, void *buffer, int argc, char **argv,
|
||||
char **argv_eol)
|
||||
{
|
||||
struct t_plugin_list *list;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) buffer;
|
||||
(void) argv_eol;
|
||||
|
||||
if (argc > 1)
|
||||
@@ -206,10 +214,12 @@ demo_list_command_cb (void *data, int argc, char **argv, char **argv_eol)
|
||||
*/
|
||||
|
||||
static int
|
||||
demo_info_command_cb (void *data, int argc, char **argv, char **argv_eol)
|
||||
demo_info_command_cb (void *data, void *buffer, int argc, char **argv,
|
||||
char **argv_eol)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) buffer;
|
||||
(void) argv_eol;
|
||||
|
||||
if (argc > 1)
|
||||
@@ -232,6 +242,7 @@ demo_info_command_cb (void *data, int argc, char **argv, char **argv_eol)
|
||||
static int
|
||||
demo_event_cb (void *data, char *event, void *pointer)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
|
||||
weechat_printf (NULL, "demo_event: event: %s, pointer: %X",
|
||||
@@ -241,7 +252,7 @@ demo_event_cb (void *data, char *event, void *pointer)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_init: init demo plugin
|
||||
* weechat_plugin_init: initialize demo plugin
|
||||
*/
|
||||
|
||||
int
|
||||
|
||||
@@ -321,7 +321,7 @@ fifo_config_cb (void *data, char *type, char *option, char *value)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_init: init fifo plugin
|
||||
* weechat_plugin_init: initialize fifo plugin
|
||||
*/
|
||||
|
||||
int
|
||||
|
||||
@@ -14,11 +14,10 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
SET(LIB_PROTOCOL_IRC_SRC irc.h irc-buffer.c irc-buffer.h irc-channel.c
|
||||
SET(LIB_PROTOCOL_IRC_SRC irc.c 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-config.h 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)
|
||||
|
||||
@@ -20,7 +20,8 @@ libdir = ${weechat_libdir}/plugins
|
||||
|
||||
lib_LTLIBRARIES = irc.la
|
||||
|
||||
irc_la_SOURCES = irc.h \
|
||||
irc_la_SOURCES = irc.c \
|
||||
irc.h \
|
||||
irc-buffer.c \
|
||||
irc-buffer.h \
|
||||
irc-channel.c \
|
||||
@@ -31,7 +32,6 @@ irc_la_SOURCES = irc.h \
|
||||
irc-color.h \
|
||||
irc-config.c \
|
||||
irc-config.h \
|
||||
irc-core.c \
|
||||
irc-dcc.c \
|
||||
irc-dcc.h \
|
||||
irc-display.c \
|
||||
|
||||
@@ -37,12 +37,10 @@
|
||||
|
||||
/* 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;
|
||||
struct t_irc_server *server;
|
||||
struct t_irc_channel *channel;
|
||||
int all_servers;
|
||||
};
|
||||
|
||||
|
||||
@@ -20,9 +20,6 @@
|
||||
#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 */
|
||||
@@ -33,8 +30,6 @@
|
||||
|
||||
#define IRC_CHANNEL_NICKS_SPEAKING_LIMIT 32
|
||||
|
||||
typedef struct t_irc_channel t_irc_channel;
|
||||
|
||||
struct t_irc_channel
|
||||
{
|
||||
int type; /* channel type */
|
||||
@@ -52,13 +47,13 @@ struct t_irc_channel
|
||||
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 */
|
||||
struct t_irc_nick *nicks; /* nicks on the channel */
|
||||
struct t_irc_nick *last_nick; /* last nick on the channel */
|
||||
struct t_weelist *nicks_speaking; /* for smart completion */
|
||||
struct t_weelist *last_nick_speaking; /* last nick speaking */
|
||||
struct t_gui_buffer *buffer; /* buffer allocated for channel */
|
||||
struct t_irc_channel *prev_channel; /* link to previous channel */
|
||||
struct t_irc_channel *next_channel; /* link to next channel */
|
||||
};
|
||||
|
||||
#endif /* irc-channel.h */
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
#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 **);
|
||||
|
||||
@@ -68,12 +68,10 @@
|
||||
(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) */
|
||||
struct t_irc_server *server; /* irc server */
|
||||
struct 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 */
|
||||
@@ -101,12 +99,12 @@ struct t_irc_dcc
|
||||
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 */
|
||||
struct t_irc_dcc *prev_dcc; /* link to previous dcc file/chat */
|
||||
struct 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 struct t_irc_dcc *irc_dcc_list;
|
||||
extern struct t_irc_dcc *irc_last_dcc;
|
||||
extern char *irc_dcc_status_string[6];
|
||||
|
||||
#endif /* irc-dcc.h */
|
||||
|
||||
@@ -36,8 +36,6 @@
|
||||
else \
|
||||
nick->flags &= 0xFFFF - flag;
|
||||
|
||||
typedef struct t_irc_nick t_irc_nick;
|
||||
|
||||
struct t_irc_nick
|
||||
{
|
||||
char *nick; /* nickname */
|
||||
@@ -45,8 +43,8 @@ struct t_irc_nick
|
||||
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 */
|
||||
struct t_irc_nick *prev_nick; /* link to previous nick on channel */
|
||||
struct t_irc_nick *next_nick; /* link to next nick on channel */
|
||||
};
|
||||
|
||||
#endif /* irc-nick.h */
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
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 */
|
||||
|
||||
@@ -26,10 +26,6 @@
|
||||
#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
|
||||
@@ -47,19 +43,15 @@
|
||||
|
||||
/* 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 */
|
||||
char *message_before_mod; /* msg before any modifier */
|
||||
char *message_after_mod; /* msg after modifier(s) */
|
||||
int modified; /* msg was modified by modifier(s) */
|
||||
struct t_irc_outqueue *next_outqueue; /* link to next msg in queue */
|
||||
struct t_irc_outqueue *prev_outqueue; /* link to prev msg in queue */
|
||||
};
|
||||
|
||||
typedef struct t_irc_server t_irc_server;
|
||||
|
||||
struct t_irc_server
|
||||
{
|
||||
/* user choices */
|
||||
@@ -90,7 +82,7 @@ struct t_irc_server
|
||||
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 */
|
||||
struct t_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
|
||||
@@ -114,31 +106,29 @@ struct t_irc_server
|
||||
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 */
|
||||
struct t_irc_outqueue *outqueue; /* queue for outgoing user msgs */
|
||||
struct t_irc_outqueue *last_outqueue; /* last outgoing user message */
|
||||
struct t_gui_buffer *buffer; /* GUI buffer allocated for server */
|
||||
struct t_irc_channel *channels; /* opened channels on server */
|
||||
struct t_irc_channel *last_channel; /* last opened channal on server */
|
||||
struct t_irc_server *prev_server; /* link to previous server */
|
||||
struct 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 */
|
||||
struct t_irc_server *server; /* server pointer for received msg */
|
||||
char *data; /* message content */
|
||||
struct t_irc_message *next_message; /* link to next message */
|
||||
};
|
||||
|
||||
extern t_irc_server *irc_servers;
|
||||
extern struct 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 struct t_irc_message *irc_recv_msgq, *irc_msgq_last_msg;
|
||||
|
||||
#endif /* irc-server.h */
|
||||
|
||||
@@ -33,13 +33,9 @@
|
||||
#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;
|
||||
static struct t_weechat_plugin *weechat_plugin = NULL;
|
||||
static struct t_hook *irc_hook_timer = NULL;
|
||||
static struct t_hook *irc_hook_timer_check_away = NULL;
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
gnutls_certificate_credentials gnutls_xcred; /* gnutls client credentials */
|
||||
@@ -47,89 +43,18 @@ gnutls_certificate_credentials gnutls_xcred; /* gnutls client credentials */
|
||||
|
||||
|
||||
/*
|
||||
* weechat_protocol_init: initialize IRC protocol
|
||||
* irc_dump: dump IRC data in WeeChat log file
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_protocol_init (t_weechat_protocol *protocol)
|
||||
static int
|
||||
irc_dump ()
|
||||
{
|
||||
irc_protocol = protocol;
|
||||
struct t_irc_server *ptr_server;
|
||||
struct t_irc_channel *ptr_channel;
|
||||
struct t_irc_nick *ptr_nick;
|
||||
|
||||
#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)
|
||||
for (ptr_server = irc_servers; ptr_server;
|
||||
ptr_server = ptr_server->next_server)
|
||||
{
|
||||
weechat_log_printf ("\n");
|
||||
irc_server_print_log (ptr_server);
|
||||
@@ -146,24 +71,62 @@ weechat_protocol_dump ()
|
||||
weechat_log_printf ("\n");
|
||||
irc_nick_print_log (ptr_nick);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
irc_dcc_print_log ();
|
||||
|
||||
return PROTOCOL_RC_OK;
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* weechat_protocol_end: end IRC protocol
|
||||
* weechat_plugin_init: initialize IRC plugin
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_protocol_end ()
|
||||
weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
{
|
||||
weechat_plugin = plugin;
|
||||
|
||||
#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 ();
|
||||
|
||||
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_timer (irc_cfg_irc_away_check * 60 * 1000,
|
||||
irc_server_timer_check_away,
|
||||
NULL);
|
||||
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_end: end IRC plugin
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_plugin_end ()
|
||||
{
|
||||
if (irc_hook_timer)
|
||||
weechat_hook_remove (irc_hook_timer);
|
||||
{
|
||||
weechat_unhook (irc_hook_timer);
|
||||
irc_hook_timer = NULL;
|
||||
}
|
||||
if (irc_hook_timer_check_away)
|
||||
{
|
||||
weechat_unhook (irc_hook_timer_check_away);
|
||||
irc_hook_timer_check_away = NULL;
|
||||
}
|
||||
|
||||
irc_server_disconnect_all ();
|
||||
irc_dcc_end ();
|
||||
@@ -177,5 +140,5 @@ weechat_protocol_end ()
|
||||
gnutls_global_deinit();
|
||||
#endif
|
||||
|
||||
return PROTOCOL_RC_OK;
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
||||
@@ -32,12 +32,12 @@
|
||||
|
||||
#include "../protocol.h"
|
||||
|
||||
#define _PROTOCOL_NAME "irc"
|
||||
#define _PROTOCOL_VERSION "0.1"
|
||||
#define _PROTOCOL_DESC "IRC (Internet Relay Chat)"
|
||||
char plugin_name[] = "irc";
|
||||
char plugin_version[] = "0.1";
|
||||
char plugin_description[] = "IRC (Internet Relay Chat)";
|
||||
|
||||
extern t_weechat_protocol *irc_protocol;
|
||||
extern t_weechat_hook *irc_hook_timer, *irc_hook_timer_check_away;
|
||||
extern struct t_weechat_plugin *weechat_plugin;
|
||||
extern struct t_hook *irc_hook_timer, *irc_hook_timer_check_away;
|
||||
|
||||
/* buffer functions (irc-buffer.c) */
|
||||
|
||||
|
||||
@@ -419,7 +419,7 @@ logger_print_cb (void *data, void *buffer, time_t date, char *prefix,
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_init: init logger plugin
|
||||
* weechat_plugin_init: initialize logger plugin
|
||||
*/
|
||||
|
||||
int
|
||||
|
||||
+65
-45
@@ -252,50 +252,6 @@ plugin_api_exec_on_files (struct t_weechat_plugin *plugin, char *directory,
|
||||
util_exec_on_files (directory, callback);
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_printf: print a message on a buffer
|
||||
*/
|
||||
|
||||
void
|
||||
plugin_api_printf (struct t_weechat_plugin *plugin,
|
||||
void *buffer, char *format, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
char buf[8192];
|
||||
|
||||
if (!plugin || !format
|
||||
|| !gui_buffer_valid ((struct t_gui_buffer *)buffer))
|
||||
return;
|
||||
|
||||
va_start (argptr, format);
|
||||
vsnprintf (buf, sizeof (buf) - 1, format, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
gui_chat_printf ((struct t_gui_buffer *)buffer, buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_printf_date: print a message on a buffer with a specific date
|
||||
*/
|
||||
|
||||
void
|
||||
plugin_api_printf_date (struct t_weechat_plugin *plugin,
|
||||
void *buffer, time_t date, char *format, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
char buf[8192];
|
||||
|
||||
if (!plugin || !format
|
||||
|| !gui_buffer_valid ((struct t_gui_buffer *)buffer))
|
||||
return;
|
||||
|
||||
va_start (argptr, format);
|
||||
vsnprintf (buf, sizeof (buf) - 1, format, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
gui_chat_printf_date ((struct t_gui_buffer *)buffer, date, buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_prefix: return a prefix for display with printf
|
||||
*/
|
||||
@@ -343,6 +299,70 @@ plugin_api_color (struct t_weechat_plugin *plugin, char *color_name)
|
||||
return GUI_NO_COLOR;
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_printf: print a message on a buffer
|
||||
*/
|
||||
|
||||
void
|
||||
plugin_api_printf (struct t_weechat_plugin *plugin,
|
||||
void *buffer, char *format, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
char buf[8192];
|
||||
|
||||
if (!plugin || !format
|
||||
|| !gui_buffer_valid ((struct t_gui_buffer *)buffer))
|
||||
return;
|
||||
|
||||
va_start (argptr, format);
|
||||
vsnprintf (buf, sizeof (buf) - 1, format, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
gui_chat_printf ((struct t_gui_buffer *)buffer, "%s", buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_printf_date: print a message on a buffer with a specific date
|
||||
*/
|
||||
|
||||
void
|
||||
plugin_api_printf_date (struct t_weechat_plugin *plugin,
|
||||
void *buffer, time_t date, char *format, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
char buf[8192];
|
||||
|
||||
if (!plugin || !format
|
||||
|| !gui_buffer_valid ((struct t_gui_buffer *)buffer))
|
||||
return;
|
||||
|
||||
va_start (argptr, format);
|
||||
vsnprintf (buf, sizeof (buf) - 1, format, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
gui_chat_printf_date ((struct t_gui_buffer *)buffer, date, buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_log_printf: print a message in WeeChat log file
|
||||
*/
|
||||
|
||||
void
|
||||
plugin_api_log_printf (struct t_weechat_plugin *plugin, char *format, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
char buf[8192];
|
||||
|
||||
if (!plugin || !format)
|
||||
return;
|
||||
|
||||
va_start (argptr, format);
|
||||
vsnprintf (buf, sizeof (buf) - 1, format, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
log_printf ("%s", buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_print_infobar: print a message in infobar
|
||||
*/
|
||||
@@ -404,7 +424,7 @@ struct t_hook *
|
||||
plugin_api_hook_command (struct t_weechat_plugin *plugin, char *command,
|
||||
char *description, char *args,
|
||||
char *args_desc, char *completion,
|
||||
int (*callback)(void *, int, char **, char **),
|
||||
int (*callback)(void *, void *, int, char **, char **),
|
||||
void *data)
|
||||
{
|
||||
if (plugin && callback)
|
||||
|
||||
@@ -45,12 +45,13 @@ extern void plugin_api_exec_on_files (struct t_weechat_plugin *, char *,
|
||||
int (*)(char *));
|
||||
|
||||
/* display */
|
||||
extern char *plugin_api_prefix (struct t_weechat_plugin *, char *);
|
||||
extern char *plugin_api_color (struct t_weechat_plugin *, char *);
|
||||
extern void plugin_api_printf (struct t_weechat_plugin *, void *,
|
||||
char *, ...);
|
||||
extern void plugin_api_printf_date (struct t_weechat_plugin *, void *,
|
||||
time_t, char *, ...);
|
||||
extern char *plugin_api_prefix (struct t_weechat_plugin *, char *);
|
||||
extern char *plugin_api_color (struct t_weechat_plugin *, char *);
|
||||
extern void plugin_api_log_printf (struct t_weechat_plugin *, char *, ...);
|
||||
extern void plugin_api_print_infobar (struct t_weechat_plugin *, int,
|
||||
char *, ...);
|
||||
extern void plugin_api_infobar_remove (struct t_weechat_plugin *, int);
|
||||
@@ -59,7 +60,7 @@ extern void plugin_api_infobar_remove (struct t_weechat_plugin *, int);
|
||||
extern struct t_hook *plugin_api_hook_command (struct t_weechat_plugin *,
|
||||
char *, char *, char *, char *,
|
||||
char *,
|
||||
int (*)(void *, int, char **, char **),
|
||||
int (*)(void *, void *, int, char **, char **),
|
||||
void *);
|
||||
extern struct t_hook *plugin_api_hook_timer (struct t_weechat_plugin *,
|
||||
long, int,
|
||||
|
||||
@@ -74,18 +74,19 @@ struct t_weechat_plugin
|
||||
int (*)(char *));
|
||||
|
||||
/* display */
|
||||
char *(*prefix) (struct t_weechat_plugin *, char *);
|
||||
char *(*color) (struct t_weechat_plugin *, char *);
|
||||
void (*printf) (struct t_weechat_plugin *, void *, char *, ...);
|
||||
void (*printf_date) (struct t_weechat_plugin *, void *, time_t,
|
||||
char *, ...);
|
||||
char *(*prefix) (struct t_weechat_plugin *, char *);
|
||||
char *(*color) (struct t_weechat_plugin *, char *);
|
||||
void (*log_printf) (struct t_weechat_plugin *, char *, ...);
|
||||
void (*print_infobar) (struct t_weechat_plugin *, int, char *, ...);
|
||||
void (*infobar_remove) (struct t_weechat_plugin *, int);
|
||||
|
||||
/* hooks */
|
||||
struct t_hook *(*hook_command) (struct t_weechat_plugin *, char *, char *,
|
||||
char *, char *, char *,
|
||||
int (*)(void *, int, char **, char **),
|
||||
int (*)(void *, void *, int, char **, char **),
|
||||
void *);
|
||||
struct t_hook *(*hook_timer) (struct t_weechat_plugin *, long, int,
|
||||
int (*)(void *), void *);
|
||||
@@ -172,15 +173,17 @@ struct t_weechat_plugin
|
||||
#define weechat_string_free_exploded(array_str) \
|
||||
weechat_plugin->string_free_exploded(weechat_plugin, array_str)
|
||||
|
||||
#define weechat_prefix(prefix_name) \
|
||||
weechat_plugin->prefix(weechat_plugin, prefix_name)
|
||||
#define weechat_color(color_name) \
|
||||
weechat_plugin->color(weechat_plugin, color_name)
|
||||
#define weechat_printf(buffer, argz...) \
|
||||
weechat_plugin->printf(weechat_plugin, buffer, ##argz)
|
||||
#define weechat_printf_date(buffer, datetime, argz...) \
|
||||
weechat_plugin->printf_date(weechat_plugin, buffer, datetime, \
|
||||
##argz)
|
||||
#define weechat_prefix(prefix_name) \
|
||||
weechat_plugin->prefix(weechat_plugin, prefix_name)
|
||||
#define weechat_color(color_name) \
|
||||
weechat_plugin->color(weechat_plugin, color_name)
|
||||
#define weechat2_log_printf(argz...) \
|
||||
weechat_plugin->log_printf(weechat_plugin, ##argz)
|
||||
|
||||
#define weechat_hook_command(command, description, args, args_desc, \
|
||||
completion, callback, data) \
|
||||
|
||||
Reference in New Issue
Block a user