diff options
Diffstat (limited to 'src/plugins')
32 files changed, 1422 insertions, 244 deletions
diff --git a/src/plugins/charset/charset.c b/src/plugins/charset/charset.c index e49ead786..7f54471f4 100644 --- a/src/plugins/charset/charset.c +++ b/src/plugins/charset/charset.c @@ -526,8 +526,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) charset_debug = weechat_config_boolean (weechat_config_get ("weechat.plugin.debug")); /* get terminal & internal charsets */ - charset_terminal = weechat_info_get ("charset_terminal"); - charset_internal = weechat_info_get ("charset_internal"); + charset_terminal = weechat_info_get ("charset_terminal", ""); + charset_internal = weechat_info_get ("charset_internal", ""); /* display message */ weechat_printf (NULL, diff --git a/src/plugins/demo/demo.c b/src/plugins/demo/demo.c index 7f61244ed..334797816 100644 --- a/src/plugins/demo/demo.c +++ b/src/plugins/demo/demo.c @@ -210,6 +210,9 @@ demo_infolist_print (struct t_infolist *infolist, const char *item_name) int i, j, argc, size; time_t time; + if (!infolist) + return; + i = 1; while (weechat_infolist_next (infolist)) { @@ -268,76 +271,84 @@ demo_infolist_print (struct t_infolist *infolist, const char *item_name) } /* - * demo_infolist_command_cb: demo command for list + * demo_info_command_cb: demo command for info_get */ int -demo_infolist_command_cb (void *data, struct t_gui_buffer *buffer, int argc, - char **argv, char **argv_eol) +demo_info_command_cb (void *data, struct t_gui_buffer *buffer, int argc, + char **argv, char **argv_eol) { struct t_infolist *infolist; /* make C compiler happy */ (void) data; (void) buffer; - (void) argv_eol; if (argc > 1) + weechat_printf (NULL, "info \"%s\" = \"%s\"", + argv[1], + weechat_info_get (argv[1], + (argc > 2) ? argv_eol[2] : NULL)); + else { - if (weechat_strcasecmp (argv[1], "buffer") == 0) - { - infolist = weechat_infolist_get ("buffer", NULL, NULL); - if (infolist) - { - demo_infolist_print (infolist, "buffer"); - weechat_infolist_free (infolist); - } - return WEECHAT_RC_OK; - } - if (weechat_strcasecmp (argv[1], "buffer_lines") == 0) + infolist = weechat_infolist_get ("hook", NULL, "info"); + if (infolist) { - infolist = weechat_infolist_get ("buffer_lines", NULL, NULL); - if (infolist) + weechat_printf (NULL, ""); + weechat_printf (NULL, _("Available infos:")); + while (weechat_infolist_next (infolist)) { - demo_infolist_print (infolist, "buffer_line"); - weechat_infolist_free (infolist); + weechat_printf (NULL, + " %s", + weechat_infolist_string (infolist, "info_name")); } - return WEECHAT_RC_OK; + weechat_infolist_free (infolist); } } - weechat_printf (NULL, - _("%s%s: missing argument for \"%s\" command " - "(try /help %s)"), - weechat_prefix ("error"), "demo", - "demo_infolist", "demo_infolist"); - return WEECHAT_RC_OK; } /* - * demo_info_command_cb: demo command for info_get + * demo_infolist_command_cb: demo command for list */ int -demo_info_command_cb (void *data, struct t_gui_buffer *buffer, int argc, - char **argv, char **argv_eol) +demo_infolist_command_cb (void *data, struct t_gui_buffer *buffer, int argc, + char **argv, char **argv_eol) { + struct t_infolist *infolist; + /* make C compiler happy */ (void) data; (void) buffer; - (void) argv_eol; if (argc > 1) - weechat_printf (NULL, "info \"%s\" = \"%s\"", - argv[1], - weechat_info_get (argv[1])); + { + infolist = weechat_infolist_get (argv[1], NULL, + (argc > 2) ? argv_eol[2] : NULL); + if (infolist) + { + demo_infolist_print (infolist, argv[1]); + weechat_infolist_free (infolist); + } + } else - weechat_printf (NULL, - _("%s%s: missing argument for \"%s\" command " - "(try /help %s)"), - weechat_prefix ("error"), "demo", - "demo_info", "demo_info"); + { + infolist = weechat_infolist_get ("hook", NULL, "infolist"); + if (infolist) + { + weechat_printf (NULL, ""); + weechat_printf (NULL, _("Available infolists:")); + while (weechat_infolist_next (infolist)) + { + weechat_printf (NULL, + " %s", + weechat_infolist_string (infolist, "infolist_name")); + } + weechat_infolist_free (infolist); + } + } return WEECHAT_RC_OK; } @@ -416,7 +427,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) "", "", &demo_buffer_command_cb, NULL); - + weechat_hook_command ("demo_buffer_set", N_("set a buffer property"), N_("property value"), @@ -424,26 +435,25 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) "", &demo_buffer_set_command_cb, NULL); - weechat_hook_command ("demo_infolist", - N_("get and display an infolist"), - N_("infolist"), - N_("infolist: infolist to display (values: buffer, " - "buffer_lines)"), - "buffer|buffer_lines", - &demo_infolist_command_cb, NULL); - weechat_hook_command ("demo_info", N_("get and display an info"), - N_("info"), - N_("info: info to display (values: version, " - "weechat_dir, weechat_libdir, weechat_sharedir, " - "charset_terminal, charset_internal, inactivity, " - "input, input_mask, input_pos)"), - "version|weechat_dir|weechat_libdir|" - "weechat_sharedir|charset_terminal|charset_internal|" - "inactivity|input|input_mask|input_pos", + N_("[info [arguments]]"), + N_(" info: info to display\n" + "arguments: optional arguments for info\n\n" + "Without argument, this command displays list " + "of available infos"), + "%i", &demo_info_command_cb, NULL); + weechat_hook_command ("demo_infolist", + N_("get and display an infolist"), + N_("[infolist]"), + N_("infolist: infolist to display\n\n" + "Without argument, this command displays list " + "of available infolists"), + "%i", + &demo_infolist_command_cb, NULL); + weechat_hook_signal ("debug", &demo_debug_signal_debug_cb, NULL); weechat_hook_signal ("*", &demo_signal_cb, NULL); diff --git a/src/plugins/fifo/fifo.c b/src/plugins/fifo/fifo.c index e493a1dad..7d2c8f5e1 100644 --- a/src/plugins/fifo/fifo.c +++ b/src/plugins/fifo/fifo.c @@ -67,7 +67,7 @@ fifo_create () fifo_option = weechat_config_get_plugin ("fifo"); } - weechat_home = weechat_info_get ("weechat_dir"); + weechat_home = weechat_info_get ("weechat_dir", ""); if (fifo_option && weechat_home) { diff --git a/src/plugins/irc/CMakeLists.txt b/src/plugins/irc/CMakeLists.txt index aa3242a11..05eb00665 100644 --- a/src/plugins/irc/CMakeLists.txt +++ b/src/plugins/irc/CMakeLists.txt @@ -24,6 +24,7 @@ irc-completion.c irc-completion.h irc-config.c irc-config.h irc-debug.c irc-debug.h irc-display.c irc-display.h +irc-info.c irc-info.h irc-input.c irc-input.h irc-mode.c irc-mode.h irc-nick.c irc-nick.h diff --git a/src/plugins/irc/Makefile.am b/src/plugins/irc/Makefile.am index 714c12e47..9adf6056b 100644 --- a/src/plugins/irc/Makefile.am +++ b/src/plugins/irc/Makefile.am @@ -38,6 +38,8 @@ irc_la_SOURCES = irc.c \ irc-debug.h \ irc-display.c \ irc-display.h \ + irc-info.c \ + irc-info.h \ irc-input.c \ irc-input.h \ irc-mode.c \ diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index ac92d2af6..e309b1d12 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -34,6 +34,31 @@ /* + * irc_channel_valid: check if a channel pointer exists for a server + * return 1 if channel exists + * 0 if channel is not found + */ + +int +irc_channel_valid (struct t_irc_server *server, struct t_irc_channel *channel) +{ + struct t_irc_channel *ptr_channel; + + if (!server) + return 0; + + for (ptr_channel = server->channels; ptr_channel; + ptr_channel = ptr_channel->next_channel) + { + if (ptr_channel == channel) + return 1; + } + + /* channel not found */ + return 0; +} + +/* * irc_channel_new: allocate a new channel for a server and add it to servers * list */ @@ -114,6 +139,7 @@ irc_channel_new (struct t_irc_server *server, int channel_type, new_channel->last_nick = NULL; new_channel->buffer = new_buffer; new_channel->nicks_speaking = NULL; + new_channel->buffer_as_string = NULL; /* add new channel to channels list */ new_channel->prev_channel = server->last_channel; @@ -185,6 +211,8 @@ irc_channel_free (struct t_irc_server *server, struct t_irc_channel *channel) free (channel->away_message); if (channel->nicks_speaking) weechat_list_free (channel->nicks_speaking); + if (channel->buffer_as_string) + free (channel->buffer_as_string); free (channel); diff --git a/src/plugins/irc/irc-channel.h b/src/plugins/irc/irc-channel.h index 523f6a1d1..4d40ec72c 100644 --- a/src/plugins/irc/irc-channel.h +++ b/src/plugins/irc/irc-channel.h @@ -50,10 +50,13 @@ struct t_irc_channel struct t_irc_nick *last_nick; /* last nick on the channel */ struct t_weelist *nicks_speaking; /* for smart completion */ struct t_gui_buffer *buffer; /* buffer allocated for channel */ + char *buffer_as_string; /* used to return buffer info */ struct t_irc_channel *prev_channel; /* link to previous channel */ struct t_irc_channel *next_channel; /* link to next channel */ }; +extern int irc_channel_valid (struct t_irc_server *server, + struct t_irc_channel *channel); extern struct t_irc_channel *irc_channel_new (struct t_irc_server *server, int channel_type, const char *channel_name, diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index 5b06cc56f..3343ad18e 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -863,7 +863,7 @@ irc_command_cycle (void *data, struct t_gui_buffer *buffer, int argc, if (ptr_arg) { - version = weechat_info_get ("version"); + version = weechat_info_get ("version", ""); buf = weechat_string_replace (ptr_arg, "%v", (version) ? version : ""); irc_server_sendf (ptr_server, "PART %s :%s", channel_name, (buf) ? buf : ptr_arg); @@ -1141,7 +1141,7 @@ irc_command_quit_server (struct t_irc_server *server, const char *arguments) if (ptr_arg) { - version = weechat_info_get ("version"); + version = weechat_info_get ("version", ""); buf = weechat_string_replace (ptr_arg, "%v", (version) ? version : ""); irc_server_sendf (server, "QUIT :%s", @@ -2169,7 +2169,7 @@ irc_command_part_channel (struct t_irc_server *server, const char *channel_name, if (ptr_arg) { - version = weechat_info_get ("version"); + version = weechat_info_get ("version", ""); buf = weechat_string_replace (ptr_arg, "%v", (version) ? version : ""); irc_server_sendf (server, "PART %s :%s", channel_name, diff --git a/src/plugins/irc/irc-info.c b/src/plugins/irc/irc-info.c new file mode 100644 index 000000000..85014c9b1 --- /dev/null +++ b/src/plugins/irc/irc-info.c @@ -0,0 +1,339 @@ +/* + * Copyright (c) 2003-2008 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-info.c: info and infolist hooks for IRC plugin */ + + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "../weechat-plugin.h" +#include "irc.h" +#include "irc-info.h" +#include "irc-channel.h" +#include "irc-nick.h" +#include "irc-protocol.h" +#include "irc-server.h" + + +/* + * irc_info_create_string_with_pointer: create a string with a pointer inside + * an IRC structure + */ + +void +irc_info_create_string_with_pointer (char **string, void *pointer) +{ + if (*string) + { + free (*string); + *string = NULL; + } + if (pointer) + { + *string = malloc (64); + if (*string) + { + snprintf (*string, 64 - 1, "0x%x", (unsigned int)pointer); + } + } +} + +/* + * irc_info_get_info_cb: callback called when IRC info is asked + */ + +char * +irc_info_get_info_cb (void *data, const char *info_name, + const char *arguments) +{ + char *pos_comma, *pos_comma2, *server, *channel, *host, *nick; + static char str_true[2] = "1"; + struct t_irc_server *ptr_server; + struct t_irc_channel *ptr_channel; + + /* make C compiler happy */ + (void) data; + + if (weechat_strcasecmp (info_name, "irc_is_channel") == 0) + { + if (irc_channel_is_channel (arguments)) + return str_true; + return NULL; + } + else if (weechat_strcasecmp (info_name, "irc_nick_from_host") == 0) + { + return irc_protocol_get_nick_from_host (arguments); + } + else if (weechat_strcasecmp (info_name, "irc_buffer") == 0) + { + if (arguments && arguments[0]) + { + server = NULL; + channel = NULL; + host = NULL; + ptr_server = NULL; + ptr_channel = NULL; + + pos_comma = strchr (arguments, ','); + if (pos_comma) + { + server = weechat_strndup (arguments, pos_comma - arguments); + pos_comma2 = strchr (pos_comma + 1, ','); + if (pos_comma2) + { + channel = weechat_strndup (pos_comma + 1, + pos_comma2 - pos_comma - 1); + host = strdup (pos_comma2 + 1); + } + else + channel = strdup (pos_comma + 1); + } + else + { + if (irc_channel_is_channel (arguments)) + channel = strdup (arguments); + else + server = strdup (arguments); + } + + /* replace channel by nick in host if channel is not a channel + (private ?) */ + if (channel && host) + { + if (!irc_channel_is_channel (channel)) + { + free (channel); + channel = NULL; + nick = irc_protocol_get_nick_from_host (host); + if (nick) + channel = strdup (nick); + + } + } + + /* search for server or channel buffer */ + if (server) + { + ptr_server = irc_server_search (server); + if (ptr_server && channel) + ptr_channel = irc_channel_search (ptr_server, channel); + } + + if (server) + free (server); + if (channel) + free (channel); + if (host) + free (host); + + if (ptr_channel) + { + irc_info_create_string_with_pointer (&ptr_channel->buffer_as_string, + ptr_channel->buffer); + return ptr_channel->buffer_as_string; + } + if (ptr_server) + { + irc_info_create_string_with_pointer (&ptr_server->buffer_as_string, + ptr_server->buffer); + return ptr_server->buffer_as_string; + } + } + } + + return NULL; +} + +/* + * irc_info_get_infolist_cb: callback called when IRC infolist is asked + */ + +struct t_infolist * +irc_info_get_infolist_cb (void *data, const char *infolist_name, + void *pointer, const char *arguments) +{ + struct t_infolist *ptr_infolist; + struct t_irc_server *ptr_server; + struct t_irc_channel *ptr_channel; + struct t_irc_nick *ptr_nick; + char *pos_comma, *server_name; + + /* make C compiler happy */ + (void) data; + (void) arguments; + + if (!infolist_name || !infolist_name[0]) + return NULL; + + if (weechat_strcasecmp (infolist_name, "irc_server") == 0) + { + if (pointer && !irc_server_valid (pointer)) + return NULL; + + ptr_infolist = weechat_infolist_new (); + if (ptr_infolist) + { + if (pointer) + { + /* build list with only one server */ + if (!irc_server_add_to_infolist (ptr_infolist, pointer)) + { + weechat_infolist_free (ptr_infolist); + return NULL; + } + return ptr_infolist; + } + else + { + /* build list with all servers */ + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + if (!irc_server_add_to_infolist (ptr_infolist, ptr_server)) + { + weechat_infolist_free (ptr_infolist); + return NULL; + } + } + return ptr_infolist; + } + } + } + else if (weechat_strcasecmp (infolist_name, "irc_channel") == 0) + { + if (arguments && arguments[0]) + { + ptr_server = irc_server_search (arguments); + if (ptr_server) + { + if (pointer && !irc_channel_valid (ptr_server, pointer)) + return NULL; + + ptr_infolist = weechat_infolist_new (); + if (ptr_infolist) + { + if (pointer) + { + /* build list with only one channel */ + if (!irc_channel_add_to_infolist (ptr_infolist, pointer)) + { + weechat_infolist_free (ptr_infolist); + return NULL; + } + return ptr_infolist; + } + else + { + /* build list with all channels of server */ + for (ptr_channel = ptr_server->channels; ptr_channel; + ptr_channel = ptr_channel->next_channel) + { + if (!irc_channel_add_to_infolist (ptr_infolist, + ptr_channel)) + { + weechat_infolist_free (ptr_infolist); + return NULL; + } + } + return ptr_infolist; + } + } + } + } + } + else if (weechat_strcasecmp (infolist_name, "irc_nick") == 0) + { + if (arguments && arguments[0]) + { + ptr_server = NULL; + ptr_channel = NULL; + pos_comma = strchr (arguments, ','); + if (pos_comma) + { + server_name = weechat_strndup (arguments, pos_comma - arguments); + if (server_name) + { + ptr_server = irc_server_search (server_name); + if (ptr_server) + { + ptr_channel = irc_channel_search (ptr_server, + pos_comma + 1); + } + free (server_name); + } + } + if (ptr_server && ptr_channel) + { + if (pointer && !irc_nick_valid (ptr_channel, pointer)) + return NULL; + + ptr_infolist = weechat_infolist_new (); + if (ptr_infolist) + { + if (pointer) + { + /* build list with only one nick */ + if (!irc_nick_add_to_infolist (ptr_infolist, pointer)) + { + weechat_infolist_free (ptr_infolist); + return NULL; + } + return ptr_infolist; + } + else + { + /* build list with all nicks of channel */ + for (ptr_nick = ptr_channel->nicks; ptr_nick; + ptr_nick = ptr_nick->next_nick) + { + if (!irc_nick_add_to_infolist (ptr_infolist, + ptr_nick)) + { + weechat_infolist_free (ptr_infolist); + return NULL; + } + } + return ptr_infolist; + } + } + } + } + } + + return NULL; +} + +/* + * irc_info_init: initialize info and infolist hooks for IRC plugin + */ + +void +irc_info_init () +{ + /* irc info hooks */ + weechat_hook_info ("irc_is_channel", &irc_info_get_info_cb, NULL); + weechat_hook_info ("irc_nick_from_host", &irc_info_get_info_cb, NULL); + weechat_hook_info ("irc_buffer", &irc_info_get_info_cb, NULL); + + /* irc infolist hooks */ + weechat_hook_infolist ("irc_server", &irc_info_get_infolist_cb, NULL); + weechat_hook_infolist ("irc_channel", &irc_info_get_infolist_cb, NULL); + weechat_hook_infolist ("irc_nick", &irc_info_get_infolist_cb, NULL); +} diff --git a/src/plugins/irc/irc-info.h b/src/plugins/irc/irc-info.h new file mode 100644 index 000000000..aca465c61 --- /dev/null +++ b/src/plugins/irc/irc-info.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2003-2008 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_INFO_H +#define __WEECHAT_IRC_INFO_H 1 + +extern void irc_info_init (); + +#endif /* irc-info.h */ diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c index 2b3f28094..fb68993ec 100644 --- a/src/plugins/irc/irc-nick.c +++ b/src/plugins/irc/irc-nick.c @@ -33,6 +33,30 @@ /* + * irc_nick_valid: check if a nick pointer exists for a channel + * return 1 if nick exists + * 0 if nick is not found + */ + +int +irc_nick_valid (struct t_irc_channel *channel, struct t_irc_nick *nick) +{ + struct t_irc_nick *ptr_nick; + + if (!channel) + return 0; + + for (ptr_nick = channel->nicks; ptr_nick; ptr_nick = ptr_nick->next_nick) + { + if (ptr_nick == nick) + return 1; + } + + /* nick not found */ + return 0; +} + +/* * irc_nick_find_color: find a color for a nick (according to nick letters) */ diff --git a/src/plugins/irc/irc-nick.h b/src/plugins/irc/irc-nick.h index b503bb799..1e3ec41a2 100644 --- a/src/plugins/irc/irc-nick.h +++ b/src/plugins/irc/irc-nick.h @@ -56,6 +56,8 @@ struct t_irc_nick struct t_irc_nick *next_nick; /* link to next nick on channel */ }; +extern int irc_nick_valid (struct t_irc_channel *channel, + struct t_irc_nick *nick); extern struct t_irc_nick *irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel, const char *nick_name, int is_chanowner, diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index f75fba255..4e9a6bfd2 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -52,7 +52,10 @@ irc_protocol_get_nick_from_host (const char *host) { static char nick[128]; char *pos; - + + if (!host) + return NULL; + nick[0] = '\0'; if (host) { @@ -1004,8 +1007,8 @@ irc_protocol_reply_version (struct t_irc_server *server, pos = NULL; } - version = weechat_info_get ("version"); - date = weechat_info_get ("date"); + version = weechat_info_get ("version", ""); + date = weechat_info_get ("date", ""); if (version && date) { irc_server_sendf (server, @@ -4168,6 +4171,9 @@ irc_protocol_recv_command (struct t_irc_server *server, const char *entire_line, weechat_prefix ("error"), entire_line); } + /* send signal with received command */ + irc_server_send_signal (server, "irc_in2", command, entire_line); + if (irc_message) free (irc_message); if (nick) diff --git a/src/plugins/irc/irc-protocol.h b/src/plugins/irc/irc-protocol.h index 28f3e45e6..49e68196e 100644 --- a/src/plugins/irc/irc-protocol.h +++ b/src/plugins/irc/irc-protocol.h @@ -55,6 +55,7 @@ struct t_irc_protocol_msg t_irc_recv_func *recv_function; /* function called when msg is received */ }; +extern char *irc_protocol_get_nick_from_host (const char *host); extern void irc_protocol_recv_command (struct t_irc_server *server, const char *entire_line, const char *host, const char *command, diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index c094d85f9..244a30b20 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -49,6 +49,31 @@ struct t_irc_message *irc_msgq_last_msg = NULL; /* + * irc_server_valid: check if a server pointer exists + * return 1 if server exists + * 0 if server is not found + */ + +int +irc_server_valid (struct t_irc_server *server) +{ + struct t_irc_server *ptr_server; + + if (!server) + return 0; + + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + if (ptr_server == server) + return 1; + } + + /* server not found */ + return 0; +} + +/* * irc_server_get_name_without_port: get name of server without port * (ends before first '/' if found) */ @@ -351,6 +376,7 @@ irc_server_init (struct t_irc_server *server) server->outqueue = NULL; server->last_outqueue = NULL; server->buffer = NULL; + server->buffer_as_string = NULL; server->channels = NULL; server->last_channel = NULL; @@ -727,6 +753,8 @@ irc_server_free_data (struct t_irc_server *server) irc_server_outqueue_free_all (server); if (server->channels) irc_channel_free_all (server); + if (server->buffer_as_string) + free (server->buffer_as_string); } /* diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h index de19a7b42..1d861c168 100644 --- a/src/plugins/irc/irc-server.h +++ b/src/plugins/irc/irc-server.h @@ -112,6 +112,7 @@ struct t_irc_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 */ + char *buffer_as_string; /* used to return buffer info */ 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 */ @@ -135,6 +136,7 @@ extern const int gnutls_prot_prio[]; extern struct t_irc_message *irc_recv_msgq, *irc_msgq_last_msg; +extern int irc_server_valid (struct t_irc_server *server); extern char *irc_server_get_name_without_port (const char *name); extern void irc_server_new_option (struct t_irc_server *server, int index_option, diff --git a/src/plugins/irc/irc.c b/src/plugins/irc/irc.c index 0a6d67326..82f5d3db0 100644 --- a/src/plugins/irc/irc.c +++ b/src/plugins/irc/irc.c @@ -28,6 +28,7 @@ #include "irc-completion.h" #include "irc-config.h" #include "irc-debug.h" +#include "irc-info.h" #include "irc-server.h" #include "irc-channel.h" #include "irc-nick.h" @@ -114,6 +115,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) irc_command_init (); + irc_info_init (); + /* hook some signals */ irc_debug_init (); weechat_hook_signal ("quit", &irc_signal_quit_cb, NULL); diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c index 92fe91f66..dac2f267c 100644 --- a/src/plugins/logger/logger.c +++ b/src/plugins/logger/logger.c @@ -200,7 +200,7 @@ logger_create_directory () dir1 = weechat_string_replace (logger_option_path, "~", getenv ("HOME")); if (dir1) { - weechat_dir = weechat_info_get ("weechat_dir"); + weechat_dir = weechat_info_get ("weechat_dir", ""); if (weechat_dir) { dir2 = weechat_string_replace (dir1, "%h", weechat_dir); @@ -243,8 +243,8 @@ logger_get_filename (struct t_gui_buffer *buffer) res = NULL; - dir_separator = weechat_info_get ("dir_separator"); - weechat_dir = weechat_info_get ("weechat_dir"); + dir_separator = weechat_info_get ("dir_separator", ""); + weechat_dir = weechat_info_get ("weechat_dir", ""); log_path = weechat_string_replace (logger_option_path, "~", getenv ("HOME")); log_path2 = weechat_string_replace (log_path, "%h", weechat_dir); @@ -340,7 +340,7 @@ logger_write_line (struct t_logger_buffer *logger_buffer, if (logger_buffer->log_filename) { - charset = weechat_info_get ("charset_terminal"); + charset = weechat_info_get ("charset_terminal", ""); if (!logger_buffer->log_file) { diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index 87cedb9e0..02978fc2f 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -258,55 +258,60 @@ plugin_api_command (struct t_weechat_plugin *plugin, } /* - * plugin_api_info_get: get info about WeeChat + * plugin_api_info_get_inernal: get info about WeeChat */ char * -plugin_api_info_get (struct t_weechat_plugin *plugin, const char *info) +plugin_api_info_get_internal (void *data, const char *info_name, + const char *arguments) { time_t inactivity; static char value[32]; - if (!plugin || !info) + /* make C compiler happy */ + (void) data; + (void) arguments; + + if (!info_name) return NULL; - if (string_strcasecmp (info, "version") == 0) + if (string_strcasecmp (info_name, "version") == 0) { return PACKAGE_VERSION; } - if (string_strcasecmp (info, "date") == 0) + if (string_strcasecmp (info_name, "date") == 0) { return __DATE__; } - else if (string_strcasecmp (info, "dir_separator") == 0) + else if (string_strcasecmp (info_name, "dir_separator") == 0) { return DIR_SEPARATOR; } - else if (string_strcasecmp (info, "weechat_dir") == 0) + else if (string_strcasecmp (info_name, "weechat_dir") == 0) { return weechat_home; } - else if (string_strcasecmp (info, "weechat_libdir") == 0) + else if (string_strcasecmp (info_name, "weechat_libdir") == 0) { return WEECHAT_LIBDIR; } - else if (string_strcasecmp (info, "weechat_sharedir") == 0) + else if (string_strcasecmp (info_name, "weechat_sharedir") == 0) { return WEECHAT_SHAREDIR; } - else if (string_strcasecmp (info, "weechat_localedir") == 0) + else if (string_strcasecmp (info_name, "weechat_localedir") == 0) { return LOCALEDIR; } - else if (string_strcasecmp (info, "charset_terminal") == 0) + else if (string_strcasecmp (info_name, "charset_terminal") == 0) { return weechat_local_charset; } - else if (string_strcasecmp (info, "charset_internal") == 0) + else if (string_strcasecmp (info_name, "charset_internal") == 0) { return WEECHAT_INTERNAL_CHARSET; } - else if (string_strcasecmp (info, "inactivity") == 0) + else if (string_strcasecmp (info_name, "inactivity") == 0) { if (gui_keyboard_last_activity_time == 0) inactivity = 0; @@ -315,7 +320,7 @@ plugin_api_info_get (struct t_weechat_plugin *plugin, const char *info) snprintf (value, sizeof (value), "%ld", (long int)inactivity); return value; } - else if (string_strcasecmp (info, "filters_enabled") == 0) + else if (string_strcasecmp (info_name, "filters_enabled") == 0) { snprintf (value, sizeof (value), "%d", gui_filters_enabled); return value; @@ -326,23 +331,28 @@ plugin_api_info_get (struct t_weechat_plugin *plugin, const char *info) } /* - * plugin_api_infolist_get: get list with infos about WeeChat structures - * WARNING: caller has to free string returned - * by this function after use, with weechat_infolist_free() + * plugin_api_infolist_get_internal: get list with infos about WeeChat structures + * WARNING: caller has to free string returned + * by this function after use, with + * weechat_infolist_free() */ struct t_infolist * -plugin_api_infolist_get (const char *name, void *pointer, const char *arguments) +plugin_api_infolist_get_internal (void *data, const char *infolist_name, + void *pointer, const char *arguments) { struct t_infolist *ptr_infolist; struct t_gui_buffer *ptr_buffer; struct t_gui_line *ptr_line; struct t_gui_window *ptr_window; - if (!name || !name[0]) + /* make C compiler happy */ + (void) data; + + if (!infolist_name || !infolist_name[0]) return NULL; - if (string_strcasecmp (name, "buffer") == 0) + if (string_strcasecmp (infolist_name, "buffer") == 0) { /* invalid buffer pointer ? */ if (pointer && (!gui_buffer_valid (pointer))) @@ -377,7 +387,7 @@ plugin_api_infolist_get (const char *name, void *pointer, const char *arguments) } } } - else if (string_strcasecmp (name, "buffer_lines") == 0) + else if (string_strcasecmp (infolist_name, "buffer_lines") == 0) { if (!pointer) pointer = gui_buffers; @@ -403,7 +413,7 @@ plugin_api_infolist_get (const char *name, void *pointer, const char *arguments) return ptr_infolist; } } - else if (string_strcasecmp (name, "nicklist") == 0) + else if (string_strcasecmp (infolist_name, "nicklist") == 0) { /* invalid buffer pointer ? */ if (!pointer || (!gui_buffer_valid (pointer))) @@ -420,7 +430,7 @@ plugin_api_infolist_get (const char *name, void *pointer, const char *arguments) return ptr_infolist; } } - else if (string_strcasecmp (name, "window") == 0) + else if (string_strcasecmp (infolist_name, "window") == 0) { /* invalid window pointer ? */ if (pointer && (!gui_window_valid (pointer))) @@ -474,7 +484,7 @@ plugin_api_infolist_get (const char *name, void *pointer, const char *arguments) } } } - else if (string_strcasecmp (name, "option") == 0) + else if (string_strcasecmp (infolist_name, "option") == 0) { ptr_infolist = infolist_new (); if (ptr_infolist) @@ -487,7 +497,7 @@ plugin_api_infolist_get (const char *name, void *pointer, const char *arguments) return ptr_infolist; } } - else if (string_strcasecmp (name, "hook") == 0) + else if (string_strcasecmp (infolist_name, "hook") == 0) { ptr_infolist = infolist_new (); if (ptr_infolist) @@ -637,3 +647,33 @@ plugin_api_infolist_free (struct t_infolist *infolist) if (infolist && infolist_valid (infolist)) infolist_free (infolist); } + +/* + * plugin_api_init: init plugin API + */ + +void +plugin_api_init () +{ + /* WeeChat core info hooks */ + hook_info (NULL, "version", &plugin_api_info_get_internal, NULL); + hook_info (NULL, "date", &plugin_api_info_get_internal, NULL); + hook_info (NULL, "dir_separator", &plugin_api_info_get_internal, NULL); + hook_info (NULL, "weechat_dir", &plugin_api_info_get_internal, NULL); + hook_info (NULL, "weechat_libdir", &plugin_api_info_get_internal, NULL); + hook_info (NULL, "weechat_sharedir", &plugin_api_info_get_internal, NULL); + hook_info (NULL, "weechat_localedir", &plugin_api_info_get_internal, NULL); + hook_info (NULL, "charset_terminal", &plugin_api_info_get_internal, NULL); + hook_info (NULL, "charset_internal", &plugin_api_info_get_internal, NULL); + hook_info (NULL, "inactivity", &plugin_api_info_get_internal, NULL); + hook_info (NULL, "filters_enabled", &plugin_api_info_get_internal, NULL); + + /* WeeChat core infolist hooks */ + hook_infolist (NULL, "buffer", &plugin_api_infolist_get_internal, NULL); + hook_infolist (NULL, "buffer_lines", &plugin_api_infolist_get_internal, NULL); + hook_infolist (NULL, "buffer", &plugin_api_infolist_get_internal, NULL); + hook_infolist (NULL, "nicklist", &plugin_api_infolist_get_internal, NULL); + hook_infolist (NULL, "window", &plugin_api_infolist_get_internal, NULL); + hook_infolist (NULL, "option", &plugin_api_infolist_get_internal, NULL); + hook_infolist (NULL, "hook", &plugin_api_infolist_get_internal, NULL); +} diff --git a/src/plugins/plugin-api.h b/src/plugins/plugin-api.h index bfa77b4d7..21f23a54a 100644 --- a/src/plugins/plugin-api.h +++ b/src/plugins/plugin-api.h @@ -68,5 +68,6 @@ extern void *plugin_api_infolist_buffer (struct t_infolist *infolist, extern time_t plugin_api_infolist_time (struct t_infolist *infolist, const char *var); extern void plugin_api_infolist_free (struct t_infolist *infolist); +extern void plugin_api_init (); #endif /* plugin-api.h */ diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index b5334ce05..865dfd1f6 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -386,6 +386,8 @@ plugin_load (const char *filename) new_plugin->hook_completion_list_add = &hook_completion_list_add; new_plugin->hook_modifier = &hook_modifier; new_plugin->hook_modifier_exec = &hook_modifier_exec; + new_plugin->hook_info = &hook_info; + new_plugin->hook_infolist = &hook_infolist; new_plugin->unhook = &unhook; new_plugin->unhook_all = &unhook_all_plugin; @@ -421,7 +423,7 @@ plugin_load (const char *filename) new_plugin->network_pass_proxy = &network_pass_proxy; new_plugin->network_connect_to = &network_connect_to; - new_plugin->info_get = &plugin_api_info_get; + new_plugin->info_get = &hook_info_get; new_plugin->infolist_new = &infolist_new; new_plugin->infolist_new_item = &infolist_new_item; @@ -430,7 +432,7 @@ plugin_load (const char *filename) new_plugin->infolist_new_var_pointer = &infolist_new_var_pointer; new_plugin->infolist_new_var_buffer = &infolist_new_var_buffer; new_plugin->infolist_new_var_time = &infolist_new_var_time; - new_plugin->infolist_get = &plugin_api_infolist_get; + new_plugin->infolist_get = &hook_infolist_get; new_plugin->infolist_next = &plugin_api_infolist_next; new_plugin->infolist_prev = &plugin_api_infolist_prev; new_plugin->infolist_reset_item_cursor = &plugin_api_infolist_reset_item_cursor; @@ -441,7 +443,7 @@ plugin_load (const char *filename) new_plugin->infolist_buffer = &plugin_api_infolist_buffer; new_plugin->infolist_time = &plugin_api_infolist_time; new_plugin->infolist_free = &plugin_api_infolist_free; - + new_plugin->upgrade_create = &upgrade_file_create; new_plugin->upgrade_write_object = &upgrade_file_write_object; new_plugin->upgrade_read = &upgrade_file_read; @@ -805,6 +807,9 @@ plugin_init (int auto_load, int argc, char *argv[]) { plugin_argc = argc; plugin_argv = argv; + + /* init plugin API (create some hooks) */ + plugin_api_init (); /* read plugins options on disk */ plugin_config_init (); diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c index b117a4d52..3b6c05323 100644 --- a/src/plugins/scripts/lua/weechat-lua-api.c +++ b/src/plugins/scripts/lua/weechat-lua-api.c @@ -3076,6 +3076,145 @@ weechat_lua_api_hook_modifier_exec (lua_State *L) } /* + * weechat_lua_api_hook_info_cb: callback for info hooked + */ + +char * +weechat_lua_api_hook_info_cb (void *data, const char *info_name, + const char *arguments) +{ + struct t_script_callback *script_callback; + char *lua_argv[3]; + + script_callback = (struct t_script_callback *)data; + + lua_argv[0] = (char *)info_name; + lua_argv[1] = (char *)arguments; + lua_argv[2] = NULL; + + return (char *)weechat_lua_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_STRING, + script_callback->function, + lua_argv); +} + +/* + * weechat_lua_api_hook_info: hook an info + */ + +static int +weechat_lua_api_hook_info (lua_State *L) +{ + const char *info_name, *function; + char *result; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_info"); + LUA_RETURN_EMPTY; + } + + info_name = NULL; + function = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_info"); + LUA_RETURN_EMPTY; + } + + info_name = lua_tostring (lua_current_interpreter, -2); + function = lua_tostring (lua_current_interpreter, -1); + + result = script_ptr2str (script_api_hook_info (weechat_lua_plugin, + lua_current_script, + info_name, + &weechat_lua_api_hook_info_cb, + function)); + + LUA_RETURN_STRING_FREE(result); +} + +/* + * weechat_lua_api_hook_infolist_cb: callback for infolist hooked + */ + +struct t_infolist * +weechat_lua_api_hook_infolist_cb (void *data, const char *info_name, + void *pointer, const char *arguments) +{ + struct t_script_callback *script_callback; + char *lua_argv[4]; + struct t_infolist *value; + + script_callback = (struct t_script_callback *)data; + + lua_argv[0] = (char *)info_name; + lua_argv[1] = script_ptr2str (pointer); + lua_argv[2] = (char *)arguments; + lua_argv[3] = NULL; + + value = (struct t_infolist *)weechat_lua_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_STRING, + script_callback->function, + lua_argv); + + if (lua_argv[1]) + free (lua_argv[1]); + + return value; +} + +/* + * weechat_lua_api_hook_infolist: hook an infolist + */ + +static int +weechat_lua_api_hook_infolist (lua_State *L) +{ + const char *infolist_name, *function; + char *result; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_infolist"); + LUA_RETURN_EMPTY; + } + + infolist_name = NULL; + function = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_infolist"); + LUA_RETURN_EMPTY; + } + + infolist_name = lua_tostring (lua_current_interpreter, -2); + function = lua_tostring (lua_current_interpreter, -1); + + result = script_ptr2str (script_api_hook_infolist (weechat_lua_plugin, + lua_current_script, + infolist_name, + &weechat_lua_api_hook_infolist_cb, + function)); + + LUA_RETURN_STRING_FREE(result); +} + +/* * weechat_lua_api_unhook: unhook something */ @@ -4308,7 +4447,7 @@ weechat_lua_api_command (lua_State *L) static int weechat_lua_api_info_get (lua_State *L) { - const char *info; + const char *info_name, *arguments; char *value; int n; @@ -4321,19 +4460,21 @@ weechat_lua_api_info_get (lua_State *L) LUA_RETURN_EMPTY; } - info = NULL; + info_name = NULL; + arguments = NULL; n = lua_gettop (lua_current_interpreter); - - if (n < 1) + + if (n < 2) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("info_get"); LUA_RETURN_EMPTY; } - - info = lua_tostring (lua_current_interpreter, -1); - value = weechat_info_get (info); + info_name = lua_tostring (lua_current_interpreter, -2); + arguments = lua_tostring (lua_current_interpreter, -1); + + value = weechat_info_get (info_name, arguments); LUA_RETURN_STRING(value); } @@ -5017,6 +5158,8 @@ const struct luaL_reg weechat_lua_api_funcs[] = { { "hook_completion_list_add", &weechat_lua_api_hook_completion_list_add }, { "hook_modifier", &weechat_lua_api_hook_modifier }, { "hook_modifier_exec", &weechat_lua_api_hook_modifier_exec }, + { "hook_info", &weechat_lua_api_hook_info }, + { "hook_infolist", &weechat_lua_api_hook_infolist }, { "unhook", &weechat_lua_api_unhook }, { "unhook_all", &weechat_lua_api_unhook_all }, { "buffer_new", &weechat_lua_api_buffer_new }, diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c index 0926e4653..d5257267e 100644 --- a/src/plugins/scripts/perl/weechat-perl-api.c +++ b/src/plugins/scripts/perl/weechat-perl-api.c @@ -2569,6 +2569,129 @@ static XS (XS_weechat_hook_modifier_exec) } /* + * weechat_perl_api_hook_info_cb: callback for info hooked + */ + +char * +weechat_perl_api_hook_info_cb (void *data, const char *info_name, + const char *arguments) +{ + struct t_script_callback *script_callback; + char *perl_argv[3]; + + script_callback = (struct t_script_callback *)data; + + perl_argv[0] = (char *)info_name; + perl_argv[1] = (char *)arguments; + perl_argv[2] = NULL; + + return (char *)weechat_perl_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_STRING, + script_callback->function, + perl_argv); +} + +/* + * weechat::hook_info: hook an info + */ + +static XS (XS_weechat_hook_info) +{ + char *result, *info_name, *perl_fn; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_info"); + PERL_RETURN_EMPTY; + } + + if (items < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_info"); + PERL_RETURN_EMPTY; + } + + info_name = SvPV (ST (0), PL_na); + perl_fn = SvPV (ST (1), PL_na); + result = script_ptr2str (script_api_hook_info (weechat_perl_plugin, + perl_current_script, + info_name, + &weechat_perl_api_hook_info_cb, + perl_fn)); + + PERL_RETURN_STRING_FREE(result); +} + +/* + * weechat_perl_api_hook_infolist_cb: callback for infolist hooked + */ + +struct t_infolist * +weechat_perl_api_hook_infolist_cb (void *data, const char *infolist_name, + void *pointer, const char *arguments) +{ + struct t_script_callback *script_callback; + char *perl_argv[4]; + struct t_infolist *value; + + script_callback = (struct t_script_callback *)data; + + perl_argv[0] = (char *)infolist_name; + perl_argv[1] = script_ptr2str (pointer); + perl_argv[2] = (char *)arguments; + perl_argv[3] = NULL; + + value = (struct t_infolist *)weechat_perl_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_STRING, + script_callback->function, + perl_argv); + + if (perl_argv[1]) + free (perl_argv[1]); + + return value; +} + +/* + * weechat::hook_infolist: hook an infolist + */ + +static XS (XS_weechat_hook_infolist) +{ + char *result, *infolist_name, *perl_fn; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_infolist"); + PERL_RETURN_EMPTY; + } + + if (items < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_infolist"); + PERL_RETURN_EMPTY; + } + + infolist_name = SvPV (ST (0), PL_na); + perl_fn = SvPV (ST (1), PL_na); + result = script_ptr2str (script_api_hook_infolist (weechat_perl_plugin, + perl_current_script, + infolist_name, + &weechat_perl_api_hook_infolist_cb, + perl_fn)); + + PERL_RETURN_STRING_FREE(result); +} + +/* * weechat::unhook: unhook something */ @@ -3578,13 +3701,14 @@ static XS (XS_weechat_info_get) PERL_RETURN_EMPTY; } - if (items < 1) + if (items < 2) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("info_get"); PERL_RETURN_EMPTY; } - value = weechat_info_get (SvPV (ST (0), PL_na)); + value = weechat_info_get (SvPV (ST (0), PL_na), + SvPV (ST (1), PL_na)); PERL_RETURN_STRING(value); } @@ -3940,6 +4064,8 @@ weechat_perl_api_init (pTHX) newXS ("weechat::hook_completion_list_add", XS_weechat_hook_completion_list_add, "weechat"); newXS ("weechat::hook_modifier", XS_weechat_hook_modifier, "weechat"); newXS ("weechat::hook_modifier_exec", XS_weechat_hook_modifier_exec, "weechat"); + newXS ("weechat::hook_info", XS_weechat_hook_info, "weechat"); + newXS ("weechat::hook_infolist", XS_weechat_hook_infolist, "weechat"); newXS ("weechat::unhook", XS_weechat_unhook, "weechat"); newXS ("weechat::unhook_all", XS_weechat_unhook_all, "weechat"); newXS ("weechat::buffer_new", XS_weechat_buffer_new, "weechat"); diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c index 5adc196e1..2ff23794c 100644 --- a/src/plugins/scripts/python/weechat-python-api.c +++ b/src/plugins/scripts/python/weechat-python-api.c @@ -2725,6 +2725,133 @@ weechat_python_api_hook_modifier_exec (PyObject *self, PyObject *args) } /* + * weechat_python_api_hook_info_cb: callback for info hooked + */ + +char * +weechat_python_api_hook_info_cb (void *data, const char *info_name, + const char *arguments) +{ + struct t_script_callback *script_callback; + char *python_argv[3]; + + script_callback = (struct t_script_callback *)data; + + python_argv[0] = (char *)info_name; + python_argv[1] = (char *)arguments; + python_argv[2] = NULL; + + return (char *)weechat_python_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_STRING, + script_callback->function, + python_argv); +} + +/* + * weechat_python_api_hook_info: hook an info + */ + +static PyObject * +weechat_python_api_hook_info (PyObject *self, PyObject *args) +{ + char *info_name, *function, *result; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_info"); + PYTHON_RETURN_EMPTY; + } + + info_name = NULL; + function = NULL; + + if (!PyArg_ParseTuple (args, "ss", &info_name, &function)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_info"); + PYTHON_RETURN_EMPTY; + } + + result = script_ptr2str(script_api_hook_info (weechat_python_plugin, + python_current_script, + info_name, + &weechat_python_api_hook_info_cb, + function)); + + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_hook_infolist_cb: callback for infolist hooked + */ + +struct t_infolist * +weechat_python_api_hook_infolist_cb (void *data, const char *infolist_name, + void *pointer, const char *arguments) +{ + struct t_script_callback *script_callback; + char *python_argv[4]; + struct t_infolist *value; + + script_callback = (struct t_script_callback *)data; + + python_argv[0] = (char *)infolist_name; + python_argv[1] = script_ptr2str (pointer); + python_argv[2] = (char *)arguments; + python_argv[3] = NULL; + + value = (struct t_infolist *)weechat_python_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_STRING, + script_callback->function, + python_argv); + + if (python_argv[1]) + free (python_argv[1]); + + return value; +} + +/* + * weechat_python_api_hook_infolist: hook an infolist + */ + +static PyObject * +weechat_python_api_hook_infolist (PyObject *self, PyObject *args) +{ + char *infolist_name, *function, *result; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_infolist"); + PYTHON_RETURN_EMPTY; + } + + infolist_name = NULL; + function = NULL; + + if (!PyArg_ParseTuple (args, "ss", &infolist_name, &function)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_infolist"); + PYTHON_RETURN_EMPTY; + } + + result = script_ptr2str(script_api_hook_infolist (weechat_python_plugin, + python_current_script, + infolist_name, + &weechat_python_api_hook_infolist_cb, + function)); + + PYTHON_RETURN_STRING_FREE(result); +} + +/* * weechat_python_api_unhook: unhook something */ @@ -3794,7 +3921,7 @@ weechat_python_api_command (PyObject *self, PyObject *args) static PyObject * weechat_python_api_info_get (PyObject *self, PyObject *args) { - char *info, *value; + char *info_name, *arguments, *value; /* make C compiler happy */ (void) self; @@ -3805,15 +3932,15 @@ weechat_python_api_info_get (PyObject *self, PyObject *args) PYTHON_RETURN_EMPTY; } - info = NULL; + info_name = NULL; - if (!PyArg_ParseTuple (args, "s", &info)) + if (!PyArg_ParseTuple (args, "ss", &info_name, &arguments)) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("info_get"); PYTHON_RETURN_EMPTY; } - value = weechat_info_get (info); + value = weechat_info_get (info_name, arguments); PYTHON_RETURN_STRING(value); } @@ -4184,6 +4311,8 @@ PyMethodDef weechat_python_funcs[] = { "hook_completion_list_add", &weechat_python_api_hook_completion_list_add, METH_VARARGS, "" }, { "hook_modifier", &weechat_python_api_hook_modifier, METH_VARARGS, "" }, { "hook_modifier_exec", &weechat_python_api_hook_modifier_exec, METH_VARARGS, "" }, + { "hook_info", &weechat_python_api_hook_info, METH_VARARGS, "" }, + { "hook_infolist", &weechat_python_api_hook_infolist, METH_VARARGS, "" }, { "unhook", &weechat_python_api_unhook, METH_VARARGS, "" }, { "unhook_all", &weechat_python_api_unhook_all, METH_VARARGS, "" }, { "buffer_new", &weechat_python_api_buffer_new, METH_VARARGS, "" }, diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c index 9755e9532..62ffa25a8 100644 --- a/src/plugins/scripts/python/weechat-python.c +++ b/src/plugins/scripts/python/weechat-python.c @@ -314,7 +314,7 @@ weechat_python_load (const char *filename) /* adding $weechat_dir/python in $PYTHONPATH */ python_path = PySys_GetObject ("path"); - w_home = weechat_info_get ("weechat_dir"); + w_home = weechat_info_get ("weechat_dir", ""); if (w_home) { len = strlen (w_home) + 1 + strlen("python") + 1; diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c index 3a876e349..25a1e2cb4 100644 --- a/src/plugins/scripts/ruby/weechat-ruby-api.c +++ b/src/plugins/scripts/ruby/weechat-ruby-api.c @@ -3135,6 +3135,145 @@ weechat_ruby_api_hook_modifier_exec (VALUE class, VALUE modifier, } /* + * weechat_ruby_api_hook_info_cb: callback for info hooked + */ + +char * +weechat_ruby_api_hook_info_cb (void *data, const char *info_name, + const char *arguments) +{ + struct t_script_callback *script_callback; + char *ruby_argv[3]; + + script_callback = (struct t_script_callback *)data; + + ruby_argv[0] = (char *)info_name; + ruby_argv[1] = (char *)arguments; + ruby_argv[2] = NULL; + + return (char *)weechat_ruby_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_STRING, + script_callback->function, + ruby_argv); +} + +/* + * weechat_ruby_api_hook_info: hook an info + */ + +static VALUE +weechat_ruby_api_hook_info (VALUE class, VALUE info_name, VALUE function) +{ + char *c_info_name, *c_function, *result; + VALUE return_value; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_info"); + RUBY_RETURN_EMPTY; + } + + c_info_name = NULL; + c_function = NULL; + + if (NIL_P (info_name) || NIL_P (function)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_info"); + RUBY_RETURN_EMPTY; + } + + Check_Type (info_name, T_STRING); + Check_Type (function, T_STRING); + + c_info_name = STR2CSTR (info_name); + c_function = STR2CSTR (function); + + result = script_ptr2str (script_api_hook_info (weechat_ruby_plugin, + ruby_current_script, + c_info_name, + &weechat_ruby_api_hook_info_cb, + c_function)); + + RUBY_RETURN_STRING_FREE(result); +} + +/* + * weechat_ruby_api_hook_infolist_cb: callback for infolist hooked + */ + +struct t_infolist * +weechat_ruby_api_hook_infolist_cb (void *data, const char *infolist_name, + void *pointer, const char *arguments) +{ + struct t_script_callback *script_callback; + char *ruby_argv[4]; + struct t_infolist *value; + + script_callback = (struct t_script_callback *)data; + + ruby_argv[0] = (char *)infolist_name; + ruby_argv[1] = script_ptr2str (pointer); + ruby_argv[2] = (char *)arguments; + ruby_argv[3] = NULL; + + value = (struct t_infolist *)weechat_ruby_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_STRING, + script_callback->function, + ruby_argv); + + if (ruby_argv[1]) + free (ruby_argv[1]); + + return value; +} + +/* + * weechat_ruby_api_hook_infolist: hook an infolist + */ + +static VALUE +weechat_ruby_api_hook_infolist (VALUE class, VALUE infolist_name, VALUE function) +{ + char *c_infolist_name, *c_function, *result; + VALUE return_value; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_infolist"); + RUBY_RETURN_EMPTY; + } + + c_infolist_name = NULL; + c_function = NULL; + + if (NIL_P (infolist_name) || NIL_P (function)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_infolist"); + RUBY_RETURN_EMPTY; + } + + Check_Type (infolist_name, T_STRING); + Check_Type (function, T_STRING); + + c_infolist_name = STR2CSTR (infolist_name); + c_function = STR2CSTR (function); + + result = script_ptr2str (script_api_hook_infolist (weechat_ruby_plugin, + ruby_current_script, + c_infolist_name, + &weechat_ruby_api_hook_infolist_cb, + c_function)); + + RUBY_RETURN_STRING_FREE(result); +} + +/* * weechat_ruby_api_unhook: unhook something */ @@ -4376,9 +4515,9 @@ weechat_ruby_api_command (VALUE class, VALUE buffer, VALUE command) */ static VALUE -weechat_ruby_api_info_get (VALUE class, VALUE info) +weechat_ruby_api_info_get (VALUE class, VALUE info_name, VALUE arguments) { - char *c_info, *value; + char *c_info_name, *c_arguments, *value; /* make C compiler happy */ (void) class; @@ -4389,17 +4528,19 @@ weechat_ruby_api_info_get (VALUE class, VALUE info) RUBY_RETURN_EMPTY; } - if (NIL_P (info)) + if (NIL_P (info_name) || NIL_P (arguments)) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("info_get"); RUBY_RETURN_EMPTY; } - Check_Type (info, T_STRING); + Check_Type (info_name, T_STRING); + Check_Type (arguments, T_STRING); + + c_info_name = STR2CSTR (info_name); + c_arguments = STR2CSTR (arguments); - c_info = STR2CSTR (info); - - value = weechat_info_get (c_info); + value = weechat_info_get (c_info_name, c_arguments); RUBY_RETURN_STRING(value); } @@ -4823,6 +4964,8 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) rb_define_module_function (ruby_mWeechat, "hook_completion_list_add", &weechat_ruby_api_hook_completion_list_add, 4); rb_define_module_function (ruby_mWeechat, "hook_modifier", &weechat_ruby_api_hook_modifier, 2); rb_define_module_function (ruby_mWeechat, "hook_modifier_exec", &weechat_ruby_api_hook_modifier_exec, 3); + rb_define_module_function (ruby_mWeechat, "hook_info", &weechat_ruby_api_hook_info, 2); + rb_define_module_function (ruby_mWeechat, "hook_infolist", &weechat_ruby_api_hook_infolist, 2); rb_define_module_function (ruby_mWeechat, "unhook", &weechat_ruby_api_unhook, 1); rb_define_module_function (ruby_mWeechat, "unhook_all", &weechat_ruby_api_unhook_all, 0); rb_define_module_function (ruby_mWeechat, "buffer_new", &weechat_ruby_api_buffer_new, 4); @@ -4850,7 +4993,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) rb_define_module_function (ruby_mWeechat, "bar_update", &weechat_ruby_api_bar_update, 1); rb_define_module_function (ruby_mWeechat, "bar_remove", &weechat_ruby_api_bar_remove, 1); rb_define_module_function (ruby_mWeechat, "command", &weechat_ruby_api_command, 2); - rb_define_module_function (ruby_mWeechat, "info_get", &weechat_ruby_api_info_get, 1); + rb_define_module_function (ruby_mWeechat, "info_get", &weechat_ruby_api_info_get, 2); rb_define_module_function (ruby_mWeechat, "infolist_get", &weechat_ruby_api_infolist_get, 3); rb_define_module_function (ruby_mWeechat, "infolist_next", &weechat_ruby_api_infolist_next, 1); rb_define_module_function (ruby_mWeechat, "infolist_prev", &weechat_ruby_api_infolist_prev, 1); diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c index 6c2d5a743..baeab5559 100644 --- a/src/plugins/scripts/script-api.c +++ b/src/plugins/scripts/script-api.c @@ -876,6 +876,84 @@ script_api_hook_modifier (struct t_weechat_plugin *weechat_plugin, } /* + * script_api_hook_info: hook an info + * return new hook, NULL if error + */ + +struct t_hook * +script_api_hook_info (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + const char *info_name, + char *(*callback)(void *data, + const char *info_name, + const char *arguments), + const char *function) +{ + struct t_script_callback *new_script_callback; + struct t_hook *new_hook; + + new_script_callback = script_callback_alloc (); + if (!new_script_callback) + return NULL; + + new_hook = weechat_hook_info (info_name, callback, new_script_callback); + if (!new_hook) + { + script_callback_free_data (new_script_callback); + free (new_script_callback); + return NULL; + } + + new_script_callback->script = script; + new_script_callback->function = strdup (function); + new_script_callback->hook = new_hook; + + script_callback_add (script, new_script_callback); + + return new_hook; +} + +/* + * script_api_hook_infolist: hook an infolist + * return new hook, NULL if error + */ + +struct t_hook * +script_api_hook_infolist (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + const char *infolist_name, + struct t_infolist *(*callback)(void *data, + const char *infolist_name, + void *pointer, + const char *arguments), + const char *function) +{ + struct t_script_callback *new_script_callback; + struct t_hook *new_hook; + + new_script_callback = script_callback_alloc (); + if (!new_script_callback) + return NULL; + + new_hook = weechat_hook_infolist (infolist_name, + callback, new_script_callback); + if (!new_hook) + { + script_callback_free_data (new_script_callback); + free (new_script_callback); + return NULL; + } + + new_script_callback->script = script; + new_script_callback->function = strdup (function); + new_script_callback->hook = new_hook; + + script_callback_add (script, new_script_callback); + + return new_hook; +} + +/* * script_api_unhook: unhook something */ diff --git a/src/plugins/scripts/script-api.h b/src/plugins/scripts/script-api.h index 573fab44f..f437275b5 100644 --- a/src/plugins/scripts/script-api.h +++ b/src/plugins/scripts/script-api.h @@ -150,6 +150,21 @@ extern struct t_hook *script_api_hook_modifier (struct t_weechat_plugin *weechat const char *modifier_data, const char *string), const char *function); +extern struct t_hook *script_api_hook_info (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + const char *info_name, + char *(*callback)(void *data, + const char *info_name, + const char *arguments), + const char *function); +extern struct t_hook *script_api_hook_infolist (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + const char *infolist_name, + struct t_infolist *(*callback)(void *data, + const char *infolist_name, + void *pointer, + const char *arguments), + const char *function); extern void script_api_unhook (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, struct t_hook *hook); diff --git a/src/plugins/scripts/script.c b/src/plugins/scripts/script.c index d24136d19..5e5d28a27 100644 --- a/src/plugins/scripts/script.c +++ b/src/plugins/scripts/script.c @@ -214,7 +214,7 @@ script_auto_load (struct t_weechat_plugin *weechat_plugin, int dir_length; /* build directory, adding WeeChat home */ - dir_home = weechat_info_get ("weechat_dir"); + dir_home = weechat_info_get ("weechat_dir", ""); if (!dir_home) return; dir_length = strlen (dir_home) + strlen (weechat_plugin->name) + 16; @@ -277,7 +277,7 @@ script_search_full_name (struct t_weechat_plugin *weechat_plugin, return NULL; } - dir_home = weechat_info_get ("weechat_dir"); + dir_home = weechat_info_get ("weechat_dir", ""); if (dir_home) { /* try WeeChat user's autoload dir */ @@ -321,7 +321,7 @@ script_search_full_name (struct t_weechat_plugin *weechat_plugin, } /* try WeeChat system dir */ - dir_system = weechat_info_get ("weechat_sharedir"); + dir_system = weechat_info_get ("weechat_sharedir", ""); if (dir_system) { length = strlen (dir_system) + strlen (weechat_plugin->name) + diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 0a3526ad6..058ff2e02 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -28,6 +28,7 @@ struct t_gui_buffer; struct t_gui_bar; struct t_gui_bar_item; struct t_gui_completion; +struct t_infolist; struct t_weelist; /* macros for defining plugin infos */ @@ -367,6 +368,19 @@ struct t_weechat_plugin char *(*hook_modifier_exec) (struct t_weechat_plugin *plugin, const char *modifier, const char *modifier_data, const char *string); + struct t_hook *(*hook_info) (struct t_weechat_plugin *plugin, + const char *info_name, + char *(*callback)(void *data, + const char *info_name, + const char *arguments), + void *callback_data); + struct t_hook *(*hook_infolist) (struct t_weechat_plugin *plugin, + const char *infolist_name, + struct t_infolist *(*callback)(void *data, + const char *infolist_name, + void *pointer, + const char *arguments), + void *callback_data); void (*unhook) (struct t_hook *hook); void (*unhook_all) (struct t_weechat_plugin *plugin); @@ -453,7 +467,8 @@ struct t_weechat_plugin int (*network_connect_to) (int sock, unsigned long address, int port); /* infos */ - char *(*info_get) (struct t_weechat_plugin *plugin, const char *info); + char *(*info_get) (struct t_weechat_plugin *plugin, const char *info_name, + const char *arguments); /* infolists */ struct t_infolist *(*infolist_new) (); @@ -474,7 +489,9 @@ struct t_weechat_plugin struct t_infolist_var *(*infolist_new_var_time) (struct t_infolist_item *item, const char *name, time_t time); - struct t_infolist *(*infolist_get) (const char *name, void *pointer, + struct t_infolist *(*infolist_get) (struct t_weechat_plugin *plugin, + const char *infolist_name, + void *pointer, const char *arguments); int (*infolist_next) (struct t_infolist *infolist); int (*infolist_prev) (struct t_infolist *infolist); @@ -509,45 +526,45 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); /* macros for easy call to plugin API */ /* strings */ -#define weechat_charset_set(__charset) \ +#define weechat_charset_set(__charset) \ weechat_plugin->charset_set(weechat_plugin, __charset) -#define weechat_iconv_to_internal(__charset, __string) \ +#define weechat_iconv_to_internal(__charset, __string) \ weechat_plugin->iconv_to_internal(__charset, __string) -#define weechat_iconv_from_internal(__charset, __string) \ +#define weechat_iconv_from_internal(__charset, __string) \ weechat_plugin->iconv_from_internal(__charset, __string) #ifndef __WEECHAT_H #ifndef _ #define _(string) weechat_plugin->gettext(string) #define N_(string) (string) -#define NG_(single,plural,number) \ +#define NG_(single,plural,number) \ weechat_plugin->ngettext(single, plural, number) #endif #endif #define weechat_gettext(string) weechat_plugin->gettext(string) -#define weechat_ngettext(single,plural,number) \ +#define weechat_ngettext(single,plural,number) \ weechat_plugin->ngettext(single, plural, number) -#define weechat_strndup(__string, __length) \ +#define weechat_strndup(__string, __length) \ weechat_plugin->strndup(__string, __length) -#define weechat_string_tolower(__string) \ +#define weechat_string_tolower(__string) \ weechat_plugin->string_tolower(__string) -#define weechat_string_toupper(__string) \ +#define weechat_string_toupper(__string) \ weechat_plugin->string_toupper(__string) -#define weechat_strcasecmp(__string1, __string2) \ +#define weechat_strcasecmp(__string1, __string2) \ weechat_plugin->strcasecmp(__string1, __string2) -#define weechat_strncasecmp(__string1, __string2, __max) \ +#define weechat_strncasecmp(__string1, __string2, __max) \ weechat_plugin->strncasecmp(__string1, __string2, __max) #define weechat_strcmp_ignore_chars(__string1, __string2, \ __chars_ignored, __case_sensitive) \ weechat_plugin->strcmp_ignore_chars(__string1, __string2, \ __chars_ignored, \ __case_sensitive) -#define weechat_strcasestr(__string1, __string2) \ +#define weechat_strcasestr(__string1, __string2) \ weechat_plugin->strcasestr(__string1, __string2) #define weechat_string_match(__string, __mask, __case_sensitive) \ weechat_plugin->string_match(__string, __mask, __case_sensitive) #define weechat_string_replace(__string, __search, __replace) \ weechat_plugin->string_replace(__string, __search, __replace) -#define weechat_string_remove_quotes(__string, __quotes) \ +#define weechat_string_remove_quotes(__string, __quotes) \ weechat_plugin->string_remove_quotes(__string, __quotes) #define weechat_string_strip(__string, __left, __right, __chars) \ weechat_plugin->string_strip(__string, __left, __right, __chars) @@ -557,7 +574,7 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); __num_items) \ weechat_plugin->string_explode(__string, __separator, __eol, \ __max, __num_items) -#define weechat_string_free_exploded(__exploded_string) \ +#define weechat_string_free_exploded(__exploded_string) \ weechat_plugin->string_free_exploded(__exploded_string) #define weechat_string_build_with_exploded(__exploded_string, \ __separator) \ @@ -569,77 +586,77 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); weechat_plugin->string_free_splitted_command(__splitted_command) /* UTF-8 strings */ -#define weechat_utf8_has_8bits(__string) \ +#define weechat_utf8_has_8bits(__string) \ weechat_plugin->utf8_has_8bits(__string) -#define weechat_utf8_is_valid(__string, __error) \ +#define weechat_utf8_is_valid(__string, __error) \ weechat_plugin->utf8_is_valid(__string, __error) -#define weechat_utf8_normalize(__string, __char) \ +#define weechat_utf8_normalize(__string, __char) \ weechat_plugin->utf8_normalize(__string, __char) -#define weechat_utf8_prev_char(__start, __string) \ +#define weechat_utf8_prev_char(__start, __string) \ weechat_plugin->utf8_prev_char(__start, __string) -#define weechat_utf8_next_char(__string) \ +#define weechat_utf8_next_char(__string) \ weechat_plugin->utf8_next_char(__string) -#define weechat_utf8_char_size(__string) \ +#define weechat_utf8_char_size(__string) \ weechat_plugin->utf8_char_size(__string) -#define weechat_utf8_strlen(__string) \ +#define weechat_utf8_strlen(__string) \ weechat_plugin->utf8_strlen(__string) -#define weechat_utf8_strnlen(__string, __bytes) \ +#define weechat_utf8_strnlen(__string, __bytes) \ weechat_plugin->utf8_strnlen(__string, __bytes) -#define weechat_utf8_strlen_screen(__string) \ +#define weechat_utf8_strlen_screen(__string) \ weechat_plugin->utf8_strlen_screen(__string) -#define weechat_utf8_charcasecmp(__string1, __string2) \ +#define weechat_utf8_charcasecmp(__string1, __string2) \ weechat_plugin->utf8_charcasecmp(__string1, __string2) -#define weechat_utf8_char_size_screen(__string) \ +#define weechat_utf8_char_size_screen(__string) \ weechat_plugin->utf8_char_size_screen(__string) -#define weechat_utf8_add_offset(__string, __offset) \ +#define weechat_utf8_add_offset(__string, __offset) \ weechat_plugin->utf8_add_offset(__string, __offset) -#define weechat_utf8_real_pos(__string, __pos) \ +#define weechat_utf8_real_pos(__string, __pos) \ weechat_plugin->utf8_real_pos(__string, __pos) -#define weechat_utf8_pos(__string, __real_pos) \ +#define weechat_utf8_pos(__string, __real_pos) \ weechat_plugin->utf8_pos(__string, __real_pos) /* directories */ -#define weechat_mkdir_home(__directory, __mode) \ +#define weechat_mkdir_home(__directory, __mode) \ weechat_plugin->mkdir_home(__directory, __mode) -#define weechat_mkdir(__directory, __mode) \ +#define weechat_mkdir(__directory, __mode) \ weechat_plugin->mkdir(__directory, __mode) #define weechat_exec_on_files(__directory, __data, __callback) \ weechat_plugin->exec_on_files(__directory, __data, __callback) /* util */ -#define weechat_timeval_cmp(__time1, __time2) \ +#define weechat_timeval_cmp(__time1, __time2) \ weechat_plugin->timeval_cmp(__time1, __time2) -#define weechat_timeval_diff(__time1, __time2) \ +#define weechat_timeval_diff(__time1, __time2) \ weechat_plugin->timeval_diff(__time1, __time2) -#define weechat_timeval_add(__time, __interval) \ +#define weechat_timeval_add(__time, __interval) \ weechat_plugin->timeval_add(__time, __interval) /* sorted list */ -#define weechat_list_new() \ +#define weechat_list_new() \ weechat_plugin->list_new() -#define weechat_list_add(__list, __string, __where) \ +#define weechat_list_add(__list, __string, __where) \ weechat_plugin->list_add(__list, __string, __where) -#define weechat_list_search(__list, __string) \ +#define weechat_list_search(__list, __string) \ weechat_plugin->list_search(__list, __string) -#define weechat_list_casesearch(__list, __string) \ +#define weechat_list_casesearch(__list, __string) \ weechat_plugin->list_casesearch(__list, __string) -#define weechat_list_get(__list, __index) \ +#define weechat_list_get(__list, __index) \ weechat_plugin->list_get(__list, __index) -#define weechat_list_set(__item, __value) \ +#define weechat_list_set(__item, __value) \ weechat_plugin->list_set(__item, __value) -#define weechat_list_next(__item) \ +#define weechat_list_next(__item) \ weechat_plugin->list_next(__item) -#define weechat_list_prev(__item) \ +#define weechat_list_prev(__item) \ weechat_plugin->list_prev(__item) -#define weechat_list_string(__item) \ +#define weechat_list_string(__item) \ weechat_plugin->list_string(__item) -#define weechat_list_size(__list) \ +#define weechat_list_size(__list) \ weechat_plugin->list_size(__list) -#define weechat_list_remove(__list, __item) \ +#define weechat_list_remove(__list, __item) \ weechat_plugin->list_remove(__list, __item) -#define weechat_list_remove_all(__list) \ +#define weechat_list_remove_all(__list) \ weechat_plugin->list_remove_all(__list) -#define weechat_list_free(__list) \ +#define weechat_list_free(__list) \ weechat_plugin->list_free(__list) /* config files */ @@ -666,7 +683,7 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); __cb_write_def_data, \ __cb_create_option, \ __cb_create_option_data) -#define weechat_config_search_section(__config, __name) \ +#define weechat_config_search_section(__config, __name) \ weechat_plugin->config_search_section(__config, __name) #define weechat_config_new_option(__config, __section, __name, __type, \ __desc, __string_values, __min, \ @@ -699,7 +716,7 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); weechat_plugin->config_search_with_string(__name, __config, \ __section, __option, \ __pos_option); -#define weechat_config_string_to_boolean(__string) \ +#define weechat_config_string_to_boolean(__string) \ weechat_plugin->config_string_to_boolean(__string) #define weechat_config_option_reset(__option, __run_callback) \ weechat_plugin->config_option_reset(__option, __run_callback) @@ -708,52 +725,51 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); __run_callback) #define weechat_config_option_unset(__option) \ weechat_plugin->config_option_unset(__option) -#define weechat_config_option_rename(__option, __new_name) \ +#define weechat_config_option_rename(__option, __new_name) \ weechat_plugin->config_option_rename(__option, __new_name) #define weechat_config_option_get_pointer(__option, __property) \ weechat_plugin->config_option_get_pointer(__option, __property) -#define weechat_config_boolean(__option) \ +#define weechat_config_boolean(__option) \ weechat_plugin->config_boolean(__option) -#define weechat_config_integer(__option) \ +#define weechat_config_integer(__option) \ weechat_plugin->config_integer(__option) -#define weechat_config_string(__option) \ +#define weechat_config_string(__option) \ weechat_plugin->config_string(__option) -#define weechat_config_color(__option) \ +#define weechat_config_color(__option) \ weechat_plugin->config_color(__option) -#define weechat_config_write_line(__config, __option, \ - __value...) \ - weechat_plugin->config_write_line(__config, __option, \ - ##__value) -#define weechat_config_write(__config) \ +#define weechat_config_write_line(__config, __option, __value...) \ + weechat_plugin->config_write_line(__config, __option, ##__value) +#define weechat_config_write(__config) \ weechat_plugin->config_write(__config) -#define weechat_config_read(__config) \ +#define weechat_config_read(__config) \ weechat_plugin->config_read(__config) -#define weechat_config_reload(__config) \ +#define weechat_config_reload(__config) \ weechat_plugin->config_reload(__config) -#define weechat_config_option_free(__option) \ +#define weechat_config_option_free(__option) \ weechat_plugin->config_option_free(__option) -#define weechat_config_section_free_options(__section) \ +#define weechat_config_section_free_options(__section) \ weechat_plugin->config_section_free_options(__section) -#define weechat_config_section_free(__config, __section) \ +#define weechat_config_section_free(__config, __section) \ weechat_plugin->config_section_free(__config, __section) -#define weechat_config_free(__config) \ +#define weechat_config_free(__config) \ weechat_plugin->config_free(__config) -#define weechat_config_get(__option) \ +#define weechat_config_get(__option) \ weechat_plugin->config_get(__option) -#define weechat_config_get_plugin(__option) \ +#define weechat_config_get_plugin(__option) \ weechat_plugin->config_get_plugin(weechat_plugin, __option) #define weechat_config_set_plugin(__option, __value) \ - weechat_plugin->config_set_plugin(weechat_plugin, __option, __value) + weechat_plugin->config_set_plugin(weechat_plugin, __option, \ + __value) /* display */ -#define weechat_prefix(__prefix) \ +#define weechat_prefix(__prefix) \ weechat_plugin->prefix(__prefix) -#define weechat_color(__color_name) \ +#define weechat_color(__color_name) \ weechat_plugin->color(__color_name) #define weechat_printf(__buffer, __message, __argz...) \ weechat_plugin->printf_date_tags(__buffer, 0, NULL, __message, \ ##__argz) -#define weechat_printf_y(__buffer, __y, __message, __argz...) \ +#define weechat_printf_y(__buffer, __y, __message, __argz...) \ weechat_plugin->printf_y(__buffer, __y, __message, ##__argz) #define weechat_printf_date(__buffer, __date, __message, __argz...) \ weechat_plugin->printf_date_tags(__buffer, __date, NULL, \ @@ -765,16 +781,16 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); __argz...) \ weechat_plugin->printf_date_tags(__buffer, __date, __tags, \ __message, ##__argz) -#define weechat_log_printf(__message, __argz...) \ +#define weechat_log_printf(__message, __argz...) \ weechat_plugin->log_printf(__message, ##__argz) /* hooks */ #define weechat_hook_command(__command, __description, __args, \ __args_desc, __completion, __callback, \ __data) \ - weechat_plugin->hook_command(weechat_plugin, __command, __description, \ - __args, __args_desc, __completion, \ - __callback, __data) + weechat_plugin->hook_command(weechat_plugin, __command, \ + __description, __args, __args_desc, \ + __completion, __callback, __data) #define weechat_hook_timer(__interval, __align_second, __max_calls, \ __callback, __data) \ weechat_plugin->hook_timer(weechat_plugin, __interval, \ @@ -813,16 +829,22 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); weechat_plugin->hook_completion_list_add(__completion, __word, \ __nick_completion, \ __where) -#define weechat_hook_modifier(__modifier, __callback, __data) \ - weechat_plugin->hook_modifier(weechat_plugin, __modifier, \ +#define weechat_hook_modifier(__modifier, __callback, __data) \ + weechat_plugin->hook_modifier(weechat_plugin, __modifier, \ __callback, __data) #define weechat_hook_modifier_exec(__modifier, __modifier_data, \ __string) \ weechat_plugin->hook_modifier_exec(weechat_plugin, __modifier, \ __modifier_data, __string) -#define weechat_unhook(__hook) \ +#define weechat_hook_info(__info_name, __callback, __data) \ + weechat_plugin->hook_info(weechat_plugin, __info_name, \ + __callback, __data) +#define weechat_hook_infolist(__infolist_name, __callback, __data) \ + weechat_plugin->hook_infolist(weechat_plugin, __infolist_name, \ + __callback, __data) +#define weechat_unhook(__hook) \ weechat_plugin->unhook( __hook) -#define weechat_unhook_all() \ +#define weechat_unhook_all() \ weechat_plugin->unhook_all_plugin(weechat_plugin) /* buffers */ @@ -832,27 +854,27 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); weechat_plugin->buffer_new(weechat_plugin, __category, __name, \ __input_callback, __input_callback_data, \ __close_callback, __close_callback_data) -#define weechat_buffer_search(__category, __name) \ +#define weechat_buffer_search(__category, __name) \ weechat_plugin->buffer_search(__category, __name) -#define weechat_current_buffer \ +#define weechat_current_buffer \ weechat_plugin->buffer_search(NULL, NULL) -#define weechat_buffer_clear(__buffer) \ +#define weechat_buffer_clear(__buffer) \ weechat_plugin->buffer_clear(__buffer) -#define weechat_buffer_close(__buffer, __switch_to_another) \ +#define weechat_buffer_close(__buffer, __switch_to_another) \ weechat_plugin->buffer_close(__buffer, __switch_to_another) -#define weechat_buffer_get_integer(__buffer, __property) \ +#define weechat_buffer_get_integer(__buffer, __property) \ weechat_plugin->buffer_get_integer(__buffer, __property) -#define weechat_buffer_get_string(__buffer, __property) \ +#define weechat_buffer_get_string(__buffer, __property) \ weechat_plugin->buffer_get_string(__buffer, __property) -#define weechat_buffer_get_pointer(__buffer, __property) \ +#define weechat_buffer_get_pointer(__buffer, __property) \ weechat_plugin->buffer_get_pointer(__buffer, __property) -#define weechat_buffer_set(__buffer, __property, __value) \ +#define weechat_buffer_set(__buffer, __property, __value) \ weechat_plugin->buffer_set(__buffer, __property, __value) /* nicklist */ -#define weechat_nicklist_add_group(__buffer, __parent_group, __name, \ - __color, __visible) \ - weechat_plugin->nicklist_add_group(__buffer, __parent_group, \ +#define weechat_nicklist_add_group(__buffer, __parent_group, __name, \ + __color, __visible) \ + weechat_plugin->nicklist_add_group(__buffer, __parent_group, \ __name, __color, __visible) #define weechat_nicklist_search_group(__buffer, __from_group, __name) \ weechat_plugin->nicklist_search_group(__buffer, __from_group, \ @@ -860,45 +882,46 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); #define weechat_nicklist_add_nick(__buffer, __group, __name, __color, \ __prefix, __prefix_color, __visible) \ weechat_plugin->nicklist_add_nick(__buffer, __group, __name, \ - __color, __prefix, __prefix_color, \ - __visible) + __color, __prefix, \ + __prefix_color, __visible) #define weechat_nicklist_search_nick(__buffer, __from_group, __name) \ - weechat_plugin->nicklist_search_nick(__buffer, __from_group, __name) -#define weechat_nicklist_remove_group(__buffer, __group) \ + weechat_plugin->nicklist_search_nick(__buffer, __from_group, \ + __name) +#define weechat_nicklist_remove_group(__buffer, __group) \ weechat_plugin->nicklist_remove_group(__buffer, __group) -#define weechat_nicklist_remove_nick(__buffer, __nick) \ +#define weechat_nicklist_remove_nick(__buffer, __nick) \ weechat_plugin->nicklist_remove_nick(__buffer, __nick) -#define weechat_nicklist_remove_all(__buffer) \ +#define weechat_nicklist_remove_all(__buffer) \ weechat_plugin->nicklist_remove_all(__buffer) /* bars */ -#define weechat_bar_item_search(__name) \ +#define weechat_bar_item_search(__name) \ weechat_plugin->bar_item_search(__name) #define weechat_bar_item_new(__name, __build_callback, __data) \ weechat_plugin->bar_item_new(weechat_plugin, __name, \ __build_callback, __data) -#define weechat_bar_item_update(__name) \ +#define weechat_bar_item_update(__name) \ weechat_plugin->bar_item_update(__name) -#define weechat_bar_item_remove(__item) \ +#define weechat_bar_item_remove(__item) \ weechat_plugin->bar_item_remove(__item) -#define weechat_bar_search(__name) \ +#define weechat_bar_search(__name) \ weechat_plugin->bar_search(__name) -#define weechat_bar_new(__name, __hidden, __priority, __type, \ - __condition, __position, __filling_top_bottom, \ - __filling_left_right, __size, __size_max, \ - __color_fg, __color_delim, __color_bg, \ - __separator, __items) \ - weechat_plugin->bar_new(weechat_plugin, __name, __hidden, \ - __priority, __type, __condition, \ - __position, __filling_top_bottom, \ - __filling_left_right, __size, __size_max, \ - __color_fg, __color_delim, __color_bg, \ +#define weechat_bar_new(__name, __hidden, __priority, __type, \ + __condition, __position, __filling_top_bottom, \ + __filling_left_right, __size, __size_max, \ + __color_fg, __color_delim, __color_bg, \ + __separator, __items) \ + weechat_plugin->bar_new(weechat_plugin, __name, __hidden, \ + __priority, __type, __condition, \ + __position, __filling_top_bottom, \ + __filling_left_right, __size, __size_max, \ + __color_fg, __color_delim, __color_bg, \ __separator, __items) -#define weechat_bar_set(__bar, __property, __value) \ +#define weechat_bar_set(__bar, __property, __value) \ weechat_plugin->bar_set(__bar, __property, __value) -#define weechat_bar_update(__name) \ +#define weechat_bar_update(__name) \ weechat_plugin->bar_update(__name) -#define weechat_bar_remove(__bar) \ +#define weechat_bar_remove(__bar) \ weechat_plugin->bar_remove(__bar) /* command */ @@ -912,13 +935,13 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); weechat_plugin->network_connect_to(__sock, __address, __port) /* infos */ -#define weechat_info_get(__name) \ - weechat_plugin->info_get(weechat_plugin, __name) +#define weechat_info_get(__info_name, __arguments) \ + weechat_plugin->info_get(weechat_plugin, __info_name, __arguments) /* infolists */ -#define weechat_infolist_new() \ +#define weechat_infolist_new() \ weechat_plugin->infolist_new() -#define weechat_infolist_new_item(__list) \ +#define weechat_infolist_new_item(__list) \ weechat_plugin->infolist_new_item(__list) #define weechat_infolist_new_var_integer(__item, __name, __value) \ weechat_plugin->infolist_new_var_integer(__item, __name, __value) @@ -932,8 +955,9 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); __size) #define weechat_infolist_new_var_time(__item, __name, __time) \ weechat_plugin->infolist_new_var_time(__item, __name, __time) -#define weechat_infolist_get(__name, __pointer, __arguments) \ - weechat_plugin->infolist_get(__name, __pointer, __arguments) +#define weechat_infolist_get(__infolist_name, __pointer, __arguments) \ + weechat_plugin->infolist_get(weechat_plugin, __infolist_name, \ + __pointer, __arguments) #define weechat_infolist_next(__list) \ weechat_plugin->infolist_next(__list) #define weechat_infolist_prev(__list) \ diff --git a/src/plugins/xfer/xfer-file.c b/src/plugins/xfer/xfer-file.c index 625013e94..20e2983d5 100644 --- a/src/plugins/xfer/xfer-file.c +++ b/src/plugins/xfer/xfer-file.c @@ -87,7 +87,7 @@ xfer_file_find_filename (struct t_xfer *xfer) if (!dir1) return; - weechat_home = weechat_info_get ("weechat_dir"); + weechat_home = weechat_info_get ("weechat_dir", ""); if (!weechat_home) { free (dir1); @@ -107,7 +107,7 @@ xfer_file_find_filename (struct t_xfer *xfer) return; strcpy (xfer->local_filename, dir2); - dir_separator = weechat_info_get("dir_separator"); + dir_separator = weechat_info_get("dir_separator", ""); if (dir_separator && (xfer->local_filename[strlen (xfer->local_filename) - 1] != dir_separator[0])) strcat (xfer->local_filename, dir_separator); diff --git a/src/plugins/xfer/xfer.c b/src/plugins/xfer/xfer.c index 81ff81198..e93af86bb 100644 --- a/src/plugins/xfer/xfer.c +++ b/src/plugins/xfer/xfer.c @@ -104,7 +104,7 @@ xfer_create_directories () char *weechat_dir, *dir1, *dir2; /* create download directory */ - weechat_dir = weechat_info_get ("weechat_dir"); + weechat_dir = weechat_info_get ("weechat_dir", ""); if (weechat_dir) { dir1 = weechat_string_replace (weechat_config_string (xfer_config_file_download_path), @@ -754,7 +754,7 @@ xfer_add_cb (void *data, const char *signal, const char *type_data, void *signal return WEECHAT_RC_ERROR; } - weechat_dir = weechat_info_get ("weechat_dir"); + weechat_dir = weechat_info_get ("weechat_dir", ""); dir2 = weechat_string_replace (dir1, "%h", weechat_dir); if (!dir2) { |