diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/demo/demo.c | 31 | ||||
-rw-r--r-- | src/plugins/fifo/fifo.c | 2 | ||||
-rw-r--r-- | src/plugins/irc/CMakeLists.txt | 7 | ||||
-rw-r--r-- | src/plugins/irc/Makefile.am | 4 | ||||
-rw-r--r-- | src/plugins/irc/irc-buffer.h | 6 | ||||
-rw-r--r-- | src/plugins/irc/irc-channel.h | 19 | ||||
-rw-r--r-- | src/plugins/irc/irc-command.h | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-dcc.h | 14 | ||||
-rw-r--r-- | src/plugins/irc/irc-nick.h | 6 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.h | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.h | 46 | ||||
-rw-r--r-- | src/plugins/irc/irc.c (renamed from src/plugins/irc/irc-core.c) | 147 | ||||
-rw-r--r-- | src/plugins/irc/irc.h | 10 | ||||
-rw-r--r-- | src/plugins/logger/logger.c | 2 | ||||
-rw-r--r-- | src/plugins/plugin-api.c | 100 | ||||
-rw-r--r-- | src/plugins/plugin-api.h | 7 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 17 |
17 files changed, 197 insertions, 225 deletions
diff --git a/src/plugins/demo/demo.c b/src/plugins/demo/demo.c index fed51f515..d25e7d304 100644 --- a/src/plugins/demo/demo.c +++ b/src/plugins/demo/demo.c @@ -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 diff --git a/src/plugins/fifo/fifo.c b/src/plugins/fifo/fifo.c index a82ae86ab..032c18a44 100644 --- a/src/plugins/fifo/fifo.c +++ b/src/plugins/fifo/fifo.c @@ -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 diff --git a/src/plugins/irc/CMakeLists.txt b/src/plugins/irc/CMakeLists.txt index 3331c6819..8292edcc6 100644 --- a/src/plugins/irc/CMakeLists.txt +++ b/src/plugins/irc/CMakeLists.txt @@ -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) diff --git a/src/plugins/irc/Makefile.am b/src/plugins/irc/Makefile.am index 4d63188e7..0f6864e2f 100644 --- a/src/plugins/irc/Makefile.am +++ b/src/plugins/irc/Makefile.am @@ -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 \ diff --git a/src/plugins/irc/irc-buffer.h b/src/plugins/irc/irc-buffer.h index d2731b2e3..6b527005c 100644 --- a/src/plugins/irc/irc-buffer.h +++ b/src/plugins/irc/irc-buffer.h @@ -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; }; diff --git a/src/plugins/irc/irc-channel.h b/src/plugins/irc/irc-channel.h index 9849890fc..673a60379 100644 --- a/src/plugins/irc/irc-channel.h +++ b/src/plugins/irc/irc-channel.h @@ -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 */ diff --git a/src/plugins/irc/irc-command.h b/src/plugins/irc/irc-command.h index 02d2db87d..f73f2e74f 100644 --- a/src/plugins/irc/irc-command.h +++ b/src/plugins/irc/irc-command.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 **); diff --git a/src/plugins/irc/irc-dcc.h b/src/plugins/irc/irc-dcc.h index cfa89be53..27cab49bb 100644 --- a/src/plugins/irc/irc-dcc.h +++ b/src/plugins/irc/irc-dcc.h @@ -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 */ diff --git a/src/plugins/irc/irc-nick.h b/src/plugins/irc/irc-nick.h index a5cfee1c4..230f49503 100644 --- a/src/plugins/irc/irc-nick.h +++ b/src/plugins/irc/irc-nick.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 */ diff --git a/src/plugins/irc/irc-protocol.h b/src/plugins/irc/irc-protocol.h index 3c2a0647c..4c1e324f8 100644 --- a/src/plugins/irc/irc-protocol.h +++ b/src/plugins/irc/irc-protocol.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 */ diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h index 2513d77e9..e759877a9 100644 --- a/src/plugins/irc/irc-server.h +++ b/src/plugins/irc/irc-server.h @@ -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 */ diff --git a/src/plugins/irc/irc-core.c b/src/plugins/irc/irc.c index f24c7429f..e2cae9b9d 100644 --- a/src/plugins/irc/irc-core.c +++ b/src/plugins/irc/irc.c @@ -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 - */ - -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 + * irc_dump: dump IRC data in WeeChat log file */ -int -weechat_protocol_config_write () +static int +irc_dump () { - 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; + struct t_irc_server *ptr_server; + struct t_irc_channel *ptr_channel; + struct 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_plugin_init: initialize IRC plugin + */ + +int +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_protocol_end: end IRC protocol + * weechat_plugin_end: end IRC plugin */ int -weechat_protocol_end () +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; } diff --git a/src/plugins/irc/irc.h b/src/plugins/irc/irc.h index aa03107c6..7d29c71e5 100644 --- a/src/plugins/irc/irc.h +++ b/src/plugins/irc/irc.h @@ -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) */ diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c index 1cdeed850..1efd8a803 100644 --- a/src/plugins/logger/logger.c +++ b/src/plugins/logger/logger.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 diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index 1b26bea60..610855f7e 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -253,6 +253,53 @@ plugin_api_exec_on_files (struct t_weechat_plugin *plugin, char *directory, } /* + * plugin_api_prefix: return a prefix for display with printf + */ + +char * +plugin_api_prefix (struct t_weechat_plugin *plugin, char *prefix) +{ + static char empty_prefix[] = ""; + + if (!plugin || !prefix) + return empty_prefix; + + if (string_strcasecmp (prefix, "info") == 0) + return gui_chat_prefix[GUI_CHAT_PREFIX_INFO]; + if (string_strcasecmp (prefix, "error") == 0) + return gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]; + if (string_strcasecmp (prefix, "network") == 0) + return gui_chat_prefix[GUI_CHAT_PREFIX_NETWORK]; + if (string_strcasecmp (prefix, "action") == 0) + return gui_chat_prefix[GUI_CHAT_PREFIX_ACTION]; + if (string_strcasecmp (prefix, "join") == 0) + return gui_chat_prefix[GUI_CHAT_PREFIX_JOIN]; + if (string_strcasecmp (prefix, "quit") == 0) + return gui_chat_prefix[GUI_CHAT_PREFIX_QUIT]; + + return empty_prefix; +} + +/* + * plugin_api_color: return a WeeChat color for display with printf + */ + +char * +plugin_api_color (struct t_weechat_plugin *plugin, char *color_name) +{ + int num_color; + + if (!plugin || !color_name) + return GUI_NO_COLOR; + + num_color = gui_color_search_config (color_name); + if (num_color >= 0) + return GUI_COLOR(num_color); + + return GUI_NO_COLOR; +} + +/* * plugin_api_printf: print a message on a buffer */ @@ -271,7 +318,7 @@ plugin_api_printf (struct t_weechat_plugin *plugin, vsnprintf (buf, sizeof (buf) - 1, format, argptr); va_end (argptr); - gui_chat_printf ((struct t_gui_buffer *)buffer, buf); + gui_chat_printf ((struct t_gui_buffer *)buffer, "%s", buf); } /* @@ -297,50 +344,23 @@ plugin_api_printf_date (struct t_weechat_plugin *plugin, } /* - * plugin_api_prefix: return a prefix for display with printf + * plugin_api_log_printf: print a message in WeeChat log file */ -char * -plugin_api_prefix (struct t_weechat_plugin *plugin, char *prefix) +void +plugin_api_log_printf (struct t_weechat_plugin *plugin, char *format, ...) { - static char empty_prefix[] = ""; - - if (!plugin || !prefix) - return empty_prefix; - - if (string_strcasecmp (prefix, "info") == 0) - return gui_chat_prefix[GUI_CHAT_PREFIX_INFO]; - if (string_strcasecmp (prefix, "error") == 0) - return gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]; - if (string_strcasecmp (prefix, "network") == 0) - return gui_chat_prefix[GUI_CHAT_PREFIX_NETWORK]; - if (string_strcasecmp (prefix, "action") == 0) - return gui_chat_prefix[GUI_CHAT_PREFIX_ACTION]; - if (string_strcasecmp (prefix, "join") == 0) - return gui_chat_prefix[GUI_CHAT_PREFIX_JOIN]; - if (string_strcasecmp (prefix, "quit") == 0) - return gui_chat_prefix[GUI_CHAT_PREFIX_QUIT]; + va_list argptr; + char buf[8192]; - return empty_prefix; -} - -/* - * plugin_api_color: return a WeeChat color for display with printf - */ - -char * -plugin_api_color (struct t_weechat_plugin *plugin, char *color_name) -{ - int num_color; + if (!plugin || !format) + return; - if (!plugin || !color_name) - return GUI_NO_COLOR; - - num_color = gui_color_search_config (color_name); - if (num_color >= 0) - return GUI_COLOR(num_color); + va_start (argptr, format); + vsnprintf (buf, sizeof (buf) - 1, format, argptr); + va_end (argptr); - return GUI_NO_COLOR; + log_printf ("%s", buf); } /* @@ -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) diff --git a/src/plugins/plugin-api.h b/src/plugins/plugin-api.h index 6cb555cdf..076003913 100644 --- a/src/plugins/plugin-api.h +++ b/src/plugins/plugin-api.h @@ -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, diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 3fcbf7dd7..d94b6748b 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -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) \ |