mirror of
https://github.com/weechat/weechat.git
synced 2026-07-10 03:33:12 +02:00
Added buffer argument in command hooks, code cleanup in IRC plugin
This commit is contained in:
@@ -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) */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user