summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2007-10-31 18:04:44 +0100
committerSebastien Helleu <flashcode@flashtux.org>2007-10-31 18:04:44 +0100
commitbf40cfbdfd6b196aceb084941589efc364c65944 (patch)
tree5267a97e07091affce65ace90250ddbe3d2b9c00 /src/plugins
parent02c0dec9cbf1d5e211b8c3c3041c0219c2b2b87d (diff)
downloadweechat-bf40cfbdfd6b196aceb084941589efc364c65944.zip
Improved plugin API, most functions rewritten from scratch
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/CMakeLists.txt22
-rw-r--r--src/plugins/Makefile.am31
-rw-r--r--src/plugins/plugin-api.c1106
-rw-r--r--src/plugins/plugin-api.h96
-rw-r--r--src/plugins/plugin-config.c335
-rw-r--r--src/plugins/plugin-config.h47
-rw-r--r--src/plugins/plugin-list.c361
-rw-r--r--src/plugins/plugin-list.h82
-rw-r--r--src/plugins/plugin.c601
-rw-r--r--src/plugins/plugin.h47
-rw-r--r--src/plugins/plugins-config.c388
-rw-r--r--src/plugins/plugins-config.h44
-rw-r--r--src/plugins/plugins-interface.c1508
-rw-r--r--src/plugins/plugins.c1566
-rw-r--r--src/plugins/plugins.h93
-rw-r--r--src/plugins/weechat-plugin.h562
16 files changed, 2870 insertions, 4019 deletions
diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt
index 1a0ada8ea..513706618 100644
--- a/src/plugins/CMakeLists.txt
+++ b/src/plugins/CMakeLists.txt
@@ -14,8 +14,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-SET(LIB_PLUGINS_SRC weechat-plugin.h plugins.h plugins.c plugins-interface.c
-plugins-config.h plugins-config.c)
+SET(LIB_PLUGINS_SRC weechat-plugin.h plugin.c plugin.h plugin-api.c
+plugin-api.h plugin-config.h plugin-config.c plugin-list.c plugin-list.h)
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR})
ADD_LIBRARY(weechat_plugins STATIC ${LIB_PLUGINS_SRC})
@@ -24,6 +24,14 @@ INCLUDE(CheckIncludeFiles)
INCLUDE(CheckFunctionExists)
INCLUDE(CheckLibraryExists)
+IF(NOT DISABLE_IRC)
+ ADD_SUBDIRECTORY( irc )
+ENDIF(NOT DISABLE_IRC)
+
+IF(NOT DISABLE_PERL AND NOT DISABLE_PYTHON AND NOT DISABLE_RUBY AND NOT DISABLE_LUA)
+ ADD_SUBDIRECTORY( scripts )
+ENDIF(NOT DISABLE_PERL AND NOT DISABLE_PYTHON AND NOT DISABLE_RUBY AND NOT DISABLE_LUA)
+
IF(NOT DISABLE_ASPELL)
# Check for aspell libraries
FIND_PACKAGE(Aspell)
@@ -32,11 +40,17 @@ IF(NOT DISABLE_ASPELL)
ENDIF(ASPELL_FOUND)
ENDIF(NOT DISABLE_ASPELL)
-IF (NOT DISABLE_CHARSET)
+IF(NOT DISABLE_CHARSET)
# Check for iconv support.
IF(ICONV_FOUND)
ADD_SUBDIRECTORY( charset )
ENDIF(ICONV_FOUND)
ENDIF(NOT DISABLE_CHARSET)
-ADD_SUBDIRECTORY( scripts )
+IF(NOT DISABLE_FIFO)
+ ADD_SUBDIRECTORY( fifo )
+ENDIF(NOT DISABLE_FIFO)
+
+IF(NOT DISABLE_TRIGGER)
+ ADD_SUBDIRECTORY( trigger )
+ENDIF(NOT DISABLE_TRIGGER)
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 4767328ac..338552c80 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -16,6 +16,22 @@
INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\"
+noinst_LIBRARIES = lib_weechat_plugins.a
+
+lib_weechat_plugins_a_SOURCES = weechat-plugin.h \
+ plugin.c \
+ plugin.h \
+ plugin-api.c \
+ plugin-api.h \
+ plugin-config.c \
+ plugin-config.h \
+ plugin-list.c \
+ plugin-list.h
+
+if PLUGIN_IRC
+irc_dir = irc
+endif
+
if PLUGIN_PERL
script_dir = scripts
endif
@@ -40,13 +56,12 @@ if PLUGIN_CHARSET
charset_dir = charset
endif
-SUBDIRS = $(script_dir) $(aspell_dir) $(charset_dir)
+if PLUGIN_FIFO
+fifo_dir = fifo
+endif
-noinst_LIBRARIES = lib_weechat_plugins.a
+if PLUGIN_TRIGGER
+trigger_dir = trigger
+endif
-lib_weechat_plugins_a_SOURCES = weechat-plugin.h \
- plugins.h \
- plugins.c \
- plugins-interface.c \
- plugins-config.h \
- plugins-config.c
+SUBDIRS = . $(irc_dir) $(script_dir) $(aspell_dir) $(charset_dir) $(fifo_dir) $(trigger_dir)
diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c
new file mode 100644
index 000000000..68566712a
--- /dev/null
+++ b/src/plugins/plugin-api.c
@@ -0,0 +1,1106 @@
+/*
+ * Copyright (c) 2003-2007 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* plugin-api.c: WeeChat <--> plugin API */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "../core/weechat.h"
+#include "../core/wee-command.h"
+#include "../core/wee-config.h"
+#include "../core/wee-hook.h"
+#include "../core/wee-input.h"
+#include "../core/wee-log.h"
+#include "../core/wee-string.h"
+#include "../core/wee-utf8.h"
+#include "../core/wee-util.h"
+#include "../gui/gui-chat.h"
+#include "../gui/gui-infobar.h"
+#include "../gui/gui-input.h"
+#include "../gui/gui-keyboard.h"
+#include "../gui/gui-nicklist.h"
+#include "../gui/gui-status.h"
+#include "../gui/gui-window.h"
+#include "plugin.h"
+#include "plugin-config.h"
+#include "plugin-list.h"
+
+
+/*
+ * plugin_api_charset_set: set plugin charset
+ */
+
+void
+plugin_api_charset_set (struct t_weechat_plugin *plugin, char *charset)
+{
+ if (!plugin || !charset)
+ return;
+
+ if (plugin->charset)
+ free (plugin->charset);
+
+ plugin->charset = (charset) ? strdup (charset) : NULL;
+}
+
+/*
+ * plugin_api_iconv_to_internal: encode string from a charset to WeeChat
+ * internal charset
+ */
+
+char *
+plugin_api_iconv_to_internal (struct t_weechat_plugin *plugin,
+ char *charset, char *string)
+{
+ if (!plugin || !string)
+ return NULL;
+
+ return string_iconv_to_internal (charset, string);
+}
+
+/*
+ * plugin_api_iconv_from_internal: encode string from WeeChat internal
+ * charset to another
+ */
+
+char *
+plugin_api_iconv_from_internal (struct t_weechat_plugin *plugin,
+ char *charset, char *string)
+{
+ if (!plugin || !string)
+ return NULL;
+
+ return string_iconv_from_internal (charset, string);
+}
+
+/*
+ * plugin_api_gettext: translate a string using gettext
+ */
+
+char *
+plugin_api_gettext (struct t_weechat_plugin *plugin, char *string)
+{
+ /* make C compiler happy */
+ (void) plugin;
+
+ return _(string);
+}
+
+/*
+ * plugin_api_ngettext: translate a string using gettext
+ */
+
+char *
+plugin_api_ngettext (struct t_weechat_plugin *plugin, char *single,
+ char *plural, int count)
+{
+ /* make C compiler happy */
+ (void) plugin;
+
+ return NG_(single, plural, count);
+}
+
+/*
+ * plugin_api_strcasecmp: locale and case independent string comparison
+ */
+
+int
+plugin_api_strcasecmp (struct t_weechat_plugin *plugin,
+ char *string1, char *string2)
+{
+ /* make C compiler happy */
+ (void) plugin;
+
+ return string_strcasecmp (string1, string2);
+}
+
+/*
+ * plugin_api_strncasecmp: locale and case independent string comparison
+ * with max length
+ */
+
+int
+plugin_api_strncasecmp (struct t_weechat_plugin *plugin,
+ char *string1, char *string2, int max)
+{
+ /* make C compiler happy */
+ (void) plugin;
+
+ return string_strncasecmp (string1, string2, max);
+}
+
+/*
+ * plugin_api_explode_string: explode a string
+ */
+
+char **
+plugin_api_explode_string (struct t_weechat_plugin *plugin, char *string,
+ char *separators, int num_items_max,
+ int *num_items)
+{
+ /* make C compiler happy */
+ (void) plugin;
+
+ if (!plugin || !string || !separators || !num_items)
+ return NULL;
+
+ return string_explode (string, separators, num_items_max,
+ num_items);
+}
+
+/*
+ * plugin_api_free_exploded_string: free exploded string
+ */
+
+void
+plugin_api_free_exploded_string (struct t_weechat_plugin *plugin,
+ char **exploded_string)
+{
+ /* make C compiler happy */
+ (void) plugin;
+
+ string_free_exploded (exploded_string);
+}
+
+/*
+ * plugin_api_mkdir_home: create a directory in WeeChat home
+ */
+
+int
+plugin_api_mkdir_home (struct t_weechat_plugin *plugin, char *directory)
+{
+ char *dir_name;
+ int dir_length;
+
+ /* make C compiler happy */
+ (void) plugin;
+
+ if (!directory)
+ return 0;
+
+ /* build directory, adding WeeChat home */
+ dir_length = strlen (weechat_home) + strlen (directory) + 2;
+ dir_name =
+ (char *) malloc (dir_length * sizeof (char));
+ if (!dir_name)
+ return 0;
+
+ snprintf (dir_name, dir_length, "%s/%s", weechat_home, directory);
+
+ if (mkdir (dir_name, 0755) < 0)
+ {
+ if (errno != EEXIST)
+ {
+ free (dir_name);
+ return 0;
+ }
+ }
+
+ free (dir_name);
+ return 1;
+}
+
+/*
+ * plugin_api_exec_on_files: find files in a directory and execute a
+ * function on each file
+ */
+
+void
+plugin_api_exec_on_files (struct t_weechat_plugin *plugin, char *directory,
+ int (*callback)(char *))
+{
+ /* make C compiler happy */
+ (void) plugin;
+
+ if (directory && callback)
+ util_exec_on_files (directory, callback);
+}
+
+/*
+ * plugin_api_printf: print a message on a buffer
+ */
+
+void
+plugin_api_printf (struct t_weechat_plugin *plugin,
+ void *buffer, char *format, ...)
+{
+ va_list argptr;
+ char buf[8192];
+
+ if (!plugin || !format)
+ return;
+
+ va_start (argptr, format);
+ vsnprintf (buf, sizeof (buf) - 1, format, argptr);
+ va_end (argptr);
+
+ gui_chat_printf ((struct t_gui_buffer *)buffer, buf);
+}
+
+/*
+ * plugin_api_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_print_infobar: print a message in infobar
+ */
+
+void
+plugin_api_print_infobar (struct t_weechat_plugin *plugin, int time_displayed,
+ char *message, ...)
+{
+ (void) plugin;
+ (void) time_displayed;
+ (void) message;
+
+ /*va_list argptr;
+ static char buf[1024];
+ char *buf2;
+
+ if (!plugin || (time_displayed < 0) || !message)
+ return;
+
+ va_start (argptr, message);
+ vsnprintf (buf, sizeof (buf) - 1, message, argptr);
+ va_end (argptr);
+
+ buf2 = string_iconv_to_internal (plugin->charset, buf);
+ gui_infobar_printf (time_displayed, GUI_COLOR_WIN_INFOBAR, "%s",
+ (buf2) ? buf2 : buf);
+ if (buf2)
+ free (buf2);*/
+}
+
+/*
+ * plugin_api_infobar_remove: remove message(s) in infobar
+ */
+
+void
+plugin_api_infobar_remove (struct t_weechat_plugin *plugin, int how_many)
+{
+ if (!plugin)
+ return;
+
+ if (how_many <= 0)
+ gui_infobar_remove_all ();
+ else
+ {
+ while ((gui_infobar) && (how_many > 0))
+ {
+ gui_infobar_remove ();
+ how_many--;
+ }
+ }
+ gui_infobar_draw (gui_current_window->buffer, 1);
+}
+
+/*
+ * plugin_api_hook_command: hook a command
+ */
+
+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 *, char *), void *data)
+{
+ if (plugin && callback)
+ return hook_command (plugin, command, description, args,
+ args_desc, completion,
+ callback, data);
+
+ return NULL;
+}
+
+/*
+ * plugin_api_hook_message: hook a message
+ */
+
+struct t_hook *
+plugin_api_hook_message (struct t_weechat_plugin *plugin, char *message,
+ int (*callback)(void *, char *), void *data)
+{
+ if (plugin && callback)
+ return hook_message (plugin, message, callback, data);
+
+ return NULL;
+}
+
+/*
+ * plugin_api_hook_config: hook a config option
+ */
+
+struct t_hook *
+plugin_api_hook_config (struct t_weechat_plugin *plugin, char *config_type,
+ char *config_option,
+ int (*callback)(void *, char *, char *, char *),
+ void *data)
+{
+ if (plugin && callback)
+ return hook_config (plugin, config_type, config_option,
+ callback, data);
+
+ return NULL;
+}
+
+/*
+ * plugin_api_hook_timer: hook a timer
+ */
+
+struct t_hook *
+plugin_api_hook_timer (struct t_weechat_plugin *plugin, long interval,
+ int max_calls, int (*callback)(void *), void *data)
+{
+ if (plugin && (interval > 0) && callback)
+ return hook_timer (plugin, interval, max_calls, callback, data);
+
+ return NULL;
+}
+
+/*
+ * plugin_api_hook_fd: hook a file descriptor
+ */
+
+struct t_hook *
+plugin_api_hook_fd (struct t_weechat_plugin *plugin, int fd,
+ int flag_read, int flag_write, int flag_exception,
+ int (*callback)(void *), void *data)
+{
+ int flags;
+
+ if (plugin && (fd >= 0) && callback)
+ {
+ flags = 0;
+ if (flag_read)
+ flags |= HOOK_FD_FLAG_READ;
+ if (flag_write)
+ flags |= HOOK_FD_FLAG_WRITE;
+ if (flag_exception)
+ flags |= HOOK_FD_FLAG_EXCEPTION;
+ return hook_fd (plugin, fd, flags, callback, data);
+ }
+
+ return NULL;
+}
+
+/*
+ * plugin_api_unhook: unhook something
+ */
+
+void
+plugin_api_unhook (struct t_weechat_plugin *plugin, void *hook)
+{
+ if (plugin && hook
+ && (hook_valid_for_plugin (plugin, (struct t_hook *)hook)))
+ unhook ((struct t_hook *)hook);
+}
+
+/*
+ * plugin_api_unhook_all: unhook all for a plugin
+ */
+
+void
+plugin_api_unhook_all (struct t_weechat_plugin *plugin)
+{
+ if (plugin)
+ unhook_all (plugin);
+}
+
+/*
+ * plugin_api_buffer_new: create a new buffer
+ */
+
+struct t_gui_buffer *
+plugin_api_buffer_new (struct t_weechat_plugin *plugin, char *category,
+ char *name)
+{
+ if (plugin && name && name[0])
+ return gui_buffer_new (plugin, category, name);
+
+ return NULL;
+}
+
+/*
+ * plugin_api_buffer_search: search a buffer
+ */
+
+struct t_gui_buffer *
+plugin_api_buffer_search (struct t_weechat_plugin *plugin, char *category,
+ char *name)
+{
+ if (plugin)
+ return gui_buffer_search_by_category_name (category, name);
+
+ return NULL;
+}
+
+/*
+ * plugin_api_buffer_close: close a buffer
+ */
+
+void
+plugin_api_buffer_close (struct t_weechat_plugin *plugin, void *buffer)
+{
+ if (plugin && buffer
+ && gui_buffer_valid ((struct t_gui_buffer *)buffer))
+ gui_buffer_free ((struct t_gui_buffer *)buffer, 1);
+}
+
+/*
+ * plugin_api_buffer_set: set a buffer property
+ */
+
+void
+plugin_api_buffer_set (struct t_weechat_plugin *plugin, void *buffer,
+ char *property, char *value)
+{
+ long number;
+ char *error;
+
+ if (plugin && buffer && property && property[0])
+ {
+ if (string_strcasecmp (property, "display") == 0)
+ {
+ gui_window_switch_to_buffer (gui_current_window,
+ (struct t_gui_buffer *)buffer);
+ gui_window_redraw_buffer ((struct t_gui_buffer *)buffer);
+ }
+ else if (string_strcasecmp (property, "category") == 0)
+ {
+ gui_buffer_set_category ((struct t_gui_buffer *)buffer, value);
+ gui_status_draw ((struct t_gui_buffer *)buffer, 0);
+ }
+ else if (string_strcasecmp (property, "name") == 0)
+ {
+ gui_buffer_set_name ((struct t_gui_buffer *)buffer, value);
+ gui_status_draw ((struct t_gui_buffer *)buffer, 0);
+ }
+ else if (string_strcasecmp (property, "log") == 0)
+ {
+ gui_buffer_set_log ((struct t_gui_buffer *)buffer, value);
+ }
+ else if (string_strcasecmp (property, "title") == 0)
+ {
+ gui_buffer_set_title ((struct t_gui_buffer *)buffer, value);
+ gui_chat_draw_title ((struct t_gui_buffer *)buffer, 0);
+ }
+ else if (string_strcasecmp (property, "nick_case_sensitive") == 0)
+ {
+ error = NULL;
+ number = strtol (value, &error, 10);
+ if (error && (error[0] == '\0'))
+ gui_buffer_set_nick_case_sensitive ((struct t_gui_buffer *)buffer,
+ number);
+ }
+ else if (string_strcasecmp (property, "nick") == 0)
+ {
+ gui_buffer_set_nick ((struct t_gui_buffer *)buffer, value);
+ gui_input_draw ((struct t_gui_buffer *)buffer, 0);
+ }
+ }
+}
+
+/*
+ * plugin_api_buffer_nick_add: add a nick to a buffer nicklist
+ */
+
+void
+plugin_api_buffer_nick_add (struct t_weechat_plugin *plugin, void *buffer,
+ char *nick, int sort_index, char *color_nick,
+ char prefix, char *color_prefix)
+{
+ int num_color_nick, num_color_prefix;
+ struct t_gui_nick *ptr_nick;
+
+ if (plugin && buffer && gui_buffer_valid ((struct t_gui_buffer *)buffer)
+ && nick && nick[0])
+ {
+ num_color_nick = gui_color_search_config (color_nick);
+ if (num_color_nick < 0)
+ num_color_nick = GUI_COLOR_NICKLIST;
+
+ num_color_prefix = gui_color_search_config (color_prefix);
+ if (num_color_prefix < 0)
+ num_color_prefix = GUI_COLOR_NICKLIST;
+
+ ptr_nick = gui_nicklist_search ((struct t_gui_buffer *)buffer, nick);
+ if (ptr_nick)
+ gui_nicklist_update ((struct t_gui_buffer *)buffer,
+ ptr_nick, nick, sort_index, num_color_nick,
+ prefix, num_color_prefix);
+ else
+ gui_nicklist_add ((struct t_gui_buffer *)buffer,
+ nick, sort_index, num_color_nick,
+ prefix, num_color_prefix);
+ }
+}
+
+/*
+ * plugin_api_buffer_nick_remove: remove a nick from a buffer nicklist
+ */
+
+void
+plugin_api_buffer_nick_remove (struct t_weechat_plugin *plugin, void *buffer,
+ char *nick)
+{
+ if (plugin && buffer && gui_buffer_valid ((struct t_gui_buffer *)buffer)
+ && nick && nick[0])
+ {
+ if (gui_nicklist_remove ((struct t_gui_buffer *)buffer, nick))
+ gui_nicklist_draw ((struct t_gui_buffer *)buffer, 0);
+ //gui_nicklist_remove ((struct t_gui_buffer *)buffer, nick);
+ }
+}
+
+/*
+ * plugin_api_command: execute a command (simulate user entry)
+ */
+
+void
+plugin_api_command (struct t_weechat_plugin *plugin, void *buffer,
+ char *command)
+{
+ char *command2;
+
+ if (!plugin || !command)
+ return;
+
+ command2 = string_iconv_to_internal (plugin->charset, command);
+ if (!buffer)
+ buffer = gui_current_window->buffer;
+ input_data (buffer, (command2) ? command2 : command, 0);
+ if (command2)
+ free (command2);
+}
+
+/*
+ * plugin_api_info_get: get info about WeeChat
+ * WARNING: caller has to free string returned
+ * by this function after use
+ */
+
+char *
+plugin_api_info_get (struct t_weechat_plugin *plugin, char *info)
+{
+ //t_irc_server *ptr_server;
+ //t_irc_channel *ptr_channel;
+ time_t inactivity;
+ char *return_str;
+
+ if (!plugin || !info)
+ return NULL;
+
+ /* below are infos that do NOT need server to return info */
+
+ if (string_strcasecmp (info, "version") == 0)
+ {
+ return strdup (PACKAGE_VERSION);
+ }
+ else if (string_strcasecmp (info, "weechat_dir") == 0)
+ {
+ return strdup (weechat_home);
+ }
+ else if (string_strcasecmp (info, "weechat_libdir") == 0)
+ {
+ return strdup (WEECHAT_LIBDIR);
+ }
+ else if (string_strcasecmp (info, "weechat_sharedir") == 0)
+ {
+ return strdup (WEECHAT_SHAREDIR);
+ }
+ else if (string_strcasecmp (info, "charset_terminal") == 0)
+ {
+ return strdup (local_charset);
+ }
+ else if (string_strcasecmp (info, "charset_internal") == 0)
+ {
+ return strdup (WEECHAT_INTERNAL_CHARSET);
+ }
+ else if (string_strcasecmp (info, "inactivity") == 0)
+ {
+ if (gui_keyboard_last_activity_time == 0)
+ inactivity = 0;
+ else
+ inactivity = time (NULL) - gui_keyboard_last_activity_time;
+ return_str = (char *) malloc (32);
+ if (!return_str)
+ return NULL;
+ snprintf (return_str, 32, "%ld", (long int)inactivity);
+ return return_str;
+ }
+ else if (string_strcasecmp (info, "input") == 0)
+ {
+ if (gui_current_window->buffer->input)
+ {
+ return_str = string_iconv_from_internal (plugin->charset,
+ gui_current_window->buffer->input_buffer);
+ return (return_str) ? return_str : strdup ("");
+ }
+ else
+ return strdup ("");
+ }
+ else if (string_strcasecmp (info, "input_mask") == 0)
+ {
+ if (gui_current_window->buffer->input)
+ return strdup (gui_current_window->buffer->input_buffer_color_mask);
+ else
+ return strdup ("");
+ }
+ else if (string_strcasecmp (info, "input_pos") == 0)
+ {
+ if (gui_current_window->buffer->input)
+ {
+ return_str = (char *) malloc (32);
+ if (!return_str)
+ return NULL;
+ snprintf (return_str, 32, "%d",
+ gui_current_window->buffer->input_buffer_pos);
+ return return_str;
+ }
+ else
+ return strdup ("");
+ }
+
+ /* below are infos that need server to return value */
+
+ /*plugin_find_server_channel (server, NULL, &ptr_server, &ptr_channel);
+
+ if (string_strcasecmp (info, "nick") == 0)
+ {
+ if (ptr_server && ptr_server->is_connected && ptr_server->nick)
+ return strdup (ptr_server->nick);
+ }
+ else if (string_strcasecmp (info, "channel") == 0)
+ {
+ if (GUI_BUFFER_IS_CHANNEL(gui_current_window->buffer)
+ || GUI_BUFFER_IS_PRIVATE(gui_current_window->buffer))
+ return strdup (GUI_CHANNEL(gui_current_window->buffer)->name);
+ }
+ else if (string_strcasecmp (info, "server") == 0)
+ {
+ if (ptr_server && ptr_server->is_connected && ptr_server->name)
+ return strdup (ptr_server->name);
+ }
+ else if (string_strcasecmp (info, "type") == 0)
+ {
+ return_str = (char *) malloc (32);
+ if (!return_str)
+ return NULL;
+ snprintf (return_str, 32, "%d",
+ gui_current_window->buffer->type);
+ return return_str;
+ }
+ else if (string_strcasecmp (info, "away") == 0)
+ {
+ if (ptr_server && ptr_server->is_connected && ptr_server->is_away)
+ return strdup ("1");
+ else
+ return strdup ("0");
+ }*/
+
+ /* info not found */
+ return NULL;
+}
+
+/*
+ * plugin_api_list_get_add_buffer: add a buffer in a list
+ * return 1 if ok, 0 if error
+ */
+
+int
+plugin_api_list_get_add_buffer (struct t_plugin_list *list,
+ struct t_gui_buffer *buffer)
+{
+ struct t_plugin_list_item *ptr_item;
+
+ if (!list || !buffer)
+ return 0;
+
+ ptr_item = plugin_list_new_item (list);
+ if (!ptr_item)
+ return 0;
+
+ if (!plugin_list_new_var_pointer (ptr_item, "pointer", buffer))
+ return 0;
+ if (!plugin_list_new_var_int (ptr_item, "number", buffer->number))
+ return 0;
+ if (!plugin_list_new_var_string (ptr_item, "category", buffer->category))
+ return 0;
+ if (!plugin_list_new_var_string (ptr_item, "name", buffer->name))
+ return 0;
+ if (!plugin_list_new_var_int (ptr_item, "type", buffer->type))
+ return 0;
+ if (!plugin_list_new_var_int (ptr_item, "notify_level", buffer->notify_level))
+ return 0;
+ if (!plugin_list_new_var_int (ptr_item, "num_displayed", buffer->num_displayed))
+ return 0;
+ if (!plugin_list_new_var_string (ptr_item, "log_filename", buffer->log_filename))
+ return 0;
+ if (!plugin_list_new_var_string (ptr_item, "title", buffer->title))
+ return 0;
+ if (!plugin_list_new_var_int (ptr_item, "input", buffer->input))
+ return 0;
+ if (!plugin_list_new_var_string (ptr_item, "input_nick", buffer->input_nick))
+ return 0;
+ if (!plugin_list_new_var_string (ptr_item, "input_string", buffer->input_buffer))
+ return 0;
+
+ return 1;
+}
+
+/*
+ * plugin_api_list_get_add_buffer_line: add a buffer line in a list
+ * return 1 if ok, 0 if error
+ */
+
+int
+plugin_api_list_get_add_buffer_line (struct t_plugin_list *list,
+ struct t_gui_line *line)
+{
+ struct t_plugin_list_item *ptr_item;
+
+ if (!list || !line)
+ return 0;
+
+ ptr_item = plugin_list_new_item (list);
+ if (!ptr_item)
+ return 0;
+
+ if (!plugin_list_new_var_time (ptr_item, "date", line->date))
+ return 0;
+ if (!plugin_list_new_var_string (ptr_item, "str_time", line->str_time))
+ return 0;
+ if (!plugin_list_new_var_string (ptr_item, "prefix", line->prefix))
+ return 0;
+ if (!plugin_list_new_var_string (ptr_item, "message", line->message))
+ return 0;
+
+ return 1;
+}
+
+/*
+ * plugin_api_list_get: get list with infos about WeeChat structures
+ * WARNING: caller has to free string returned
+ * by this function after use, with weechat_free()
+ */
+
+struct t_plugin_list *
+plugin_api_list_get (struct t_weechat_plugin *plugin, char *name,
+ void *pointer)
+{
+ struct t_plugin_list *ptr_list;
+ struct t_gui_buffer *ptr_buffer;
+ struct t_gui_line *ptr_line;
+
+ if (!plugin || !name || !name[0])
+ return NULL;
+
+ if (string_strcasecmp (name, "buffer") == 0)
+ {
+ /* invalid buffer pointer ? */
+ if (pointer && (!gui_buffer_valid ((struct t_gui_buffer *)pointer)))
+ return NULL;
+
+ ptr_list = plugin_list_new ();
+ if (ptr_list)
+ {
+ if (pointer)
+ {
+ /* build list with only one buffer */
+ if (!plugin_api_list_get_add_buffer (ptr_list,
+ (struct t_gui_buffer *)pointer))
+ {
+ plugin_list_free (ptr_list);
+ return NULL;
+ }
+ return ptr_list;
+ }
+ else
+ {
+ /* build list with all buffers */
+ for (ptr_buffer = gui_buffers; ptr_buffer;
+ ptr_buffer = ptr_buffer->next_buffer)
+ {
+ if (!plugin_api_list_get_add_buffer (ptr_list,
+ ptr_buffer))
+ {
+ plugin_list_free (ptr_list);
+ return NULL;
+ }
+ }
+ return ptr_list;
+ }
+ }
+ }
+ else if (string_strcasecmp (name, "buffer_lines") == 0)
+ {
+ /* buffer pointer is mandatory for this list */
+ if (!pointer)
+ return NULL;
+
+ /* invalid buffer pointer ? */
+ if (!gui_buffer_valid ((struct t_gui_buffer *)pointer))
+ return NULL;
+
+ ptr_list = plugin_list_new ();
+ if (ptr_list)
+ {
+ for (ptr_line = ((struct t_gui_buffer *)pointer)->lines; ptr_line;
+ ptr_line = ptr_line->next_line)
+ {
+ if (!plugin_api_list_get_add_buffer_line (ptr_list,
+ ptr_line))
+ {
+ plugin_list_free (ptr_list);
+ return NULL;
+ }
+ }
+ return ptr_list;
+ }
+ }
+
+ /* list not found */
+ return NULL;
+}
+
+/*
+ * plugin_api_get_config_str_value: return string value for any option
+ * This function should never be called directly
+ * (only used by weechat_get_config)
+ */
+
+char *
+plugin_api_get_config_str_value (struct t_config_option *option)
+{
+ char buf_temp[1024], *color_name;
+
+ switch (option->type)
+ {
+ case OPTION_TYPE_BOOLEAN:
+ return (*((int *)(option->ptr_int))) ?
+ strdup ("on") : strdup ("off");
+ break;
+ case OPTION_TYPE_INT:
+ snprintf (buf_temp, sizeof (buf_temp), "%d",
+ *((int *)(option->ptr_int)));
+ return strdup (buf_temp);
+ break;
+ case OPTION_TYPE_INT_WITH_STRING:
+ return strdup (option->array_values[*((int *)(option->ptr_int))]);
+ break;
+ case OPTION_TYPE_STRING:
+ return (*((char **)(option->ptr_string))) ?
+ strdup (*((char **)(option->ptr_string))) : strdup ("");
+ break;
+ case OPTION_TYPE_COLOR:
+ color_name = gui_color_get_name (*((int *)(option->ptr_int)));
+ return (color_name) ? strdup (color_name) : strdup ("");
+ break;
+ }
+
+ /* should never be executed! */
+ return NULL;
+}
+
+/*
+ * plugin_api_config_get: get value of a config option
+ */
+
+char *
+plugin_api_config_get (struct t_weechat_plugin *plugin, char *option_name)
+{
+ struct t_config_option *ptr_option;
+
+ /* make C compiler happy */
+ (void) plugin;
+
+ /* search a WeeChat command */
+ ptr_option = config_option_section_option_search (weechat_config_sections,
+ weechat_config_options,
+ option_name);
+ if (ptr_option)
+ return plugin_api_get_config_str_value (ptr_option);
+
+ /* option not found */
+ return NULL;
+}
+
+/*
+ * plugin_api_config_set: set value of a config option
+ */
+
+int
+plugin_api_config_set (struct t_weechat_plugin *plugin, char *option_name,
+ char *value)
+{
+ struct t_config_option *ptr_option;
+
+ /* make C compiler happy */
+ (void) plugin;
+
+ if (!option_name || !value)
+ return 0;
+
+ /* search and set WeeChat option if found */
+ ptr_option = config_option_section_option_search (weechat_config_sections,
+ weechat_config_options,
+ option_name);
+ if (ptr_option)
+ {
+ if (ptr_option->handler_change)
+ {
+ if (config_option_set (ptr_option, value) == 0)
+ {
+ (void) (ptr_option->handler_change());
+ return 1;
+ }
+ }
+ else
+ return 0;
+ }
+
+ /* failed to set config option */
+ return 0;
+}
+
+/*
+ * plugin_api_plugin_config_get: get value of a plugin config option
+ */
+
+char *
+plugin_api_plugin_config_get (struct t_weechat_plugin *plugin, char *option)
+{
+ struct t_plugin_option *ptr_plugin_option;
+
+ if (!option)
+ return NULL;
+
+ ptr_plugin_option = plugin_config_search (plugin->name, option);
+ if (ptr_plugin_option)
+ return (ptr_plugin_option->value) ? strdup (ptr_plugin_option->value) : NULL;
+
+ /* option not found */
+ return NULL;
+}
+
+/*
+ * plugin_api_plugin_config_set: set value of a plugin config option
+ */
+
+int
+plugin_api_plugin_config_set (struct t_weechat_plugin *plugin, char *option,
+ char *value)
+{
+ if (!option)
+ return 0;
+
+ if (plugin_config_set (plugin->name, option, value))
+ {
+ plugin_config_write ();
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * plugin_api_log: add a message in buffer log file
+ */
+
+void
+plugin_api_log (struct t_weechat_plugin *plugin,
+ char *server, char *channel, char *message, ...)
+{
+ (void) plugin;
+ (void) server;
+ (void) channel;
+ (void) message;
+
+ /*t_gui_buffer *ptr_buffer;
+ va_list argptr;
+ static char buf[8192];
+ char *buf2;
+
+ if (!plugin || !message)
+ return;
+
+ ptr_buffer = gui_buffer_search (server, channel);
+ if (ptr_buffer)
+ {
+ va_start (argptr, message);
+ vsnprintf (buf, sizeof (buf) - 1, message, argptr);
+ va_end (argptr);
+
+ buf2 = string_iconv_to_internal (plugin->charset, buf);
+ gui_log_write_line (ptr_buffer, (buf2) ? buf2 : buf);
+ if (buf2)
+ free (buf2);
+ }*/
+}
diff --git a/src/plugins/plugin-api.h b/src/plugins/plugin-api.h
new file mode 100644
index 000000000..aa4664726
--- /dev/null
+++ b/src/plugins/plugin-api.h
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2003-2007 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __WEECHAT_PLUGIN_API_H
+#define __WEECHAT_PLUGIN_API_H 1
+
+/* strings */
+extern void plugin_api_charset_set (struct t_weechat_plugin *, char *);
+extern char *plugin_api_iconv_to_internal (struct t_weechat_plugin *, char *, char *);
+extern char *plugin_api_iconv_from_internal (struct t_weechat_plugin *, char *, char *);
+extern char *plugin_api_gettext (struct t_weechat_plugin *, char *);
+extern char *plugin_api_ngettext (struct t_weechat_plugin *, char *, char *, int);
+extern int plugin_api_strcasecmp (struct t_weechat_plugin *,char *, char *);
+extern int plugin_api_strncasecmp (struct t_weechat_plugin *,char *, char *, int);
+extern char **plugin_api_explode_string (struct t_weechat_plugin *, char *, char *, int, int *);
+extern void plugin_api_free_exploded_string (struct t_weechat_plugin *, char **);
+
+/* directories */
+extern int plugin_api_mkdir_home (struct t_weechat_plugin *, char *);
+extern void plugin_api_exec_on_files (struct t_weechat_plugin *, char *,
+ int (*)(char *));
+
+/* display */
+extern void plugin_api_printf (struct t_weechat_plugin *, void *,
+ 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_print_infobar (struct t_weechat_plugin *, int,
+ char *, ...);
+extern void plugin_api_infobar_remove (struct t_weechat_plugin *, int);
+
+/* hooks */
+extern struct t_hook *plugin_api_hook_command (struct t_weechat_plugin *,
+ char *, char *, char *, char *,
+ char *, int (*)(void *, char *),
+ void *);
+extern struct t_hook *plugin_api_hook_message (struct t_weechat_plugin *,
+ char *, int (*)(void *, char *),
+ void *);
+extern struct t_hook *plugin_api_hook_config (struct t_weechat_plugin *,
+ char *, char *,
+ int (*)(void *, char *, char *, char *),
+ void *);
+extern struct t_hook *plugin_api_hook_timer (struct t_weechat_plugin *,
+ long, int,
+ int (*)(void *), void *);
+extern struct t_hook *plugin_api_hook_fd (struct t_weechat_plugin *,
+ int, int, int, int,
+ int (*)(void *), void *);
+extern void plugin_api_unhook (struct t_weechat_plugin *, void *);
+extern void plugin_api_unhook_all (struct t_weechat_plugin *);
+
+/* buffers */
+extern struct t_gui_buffer *plugin_api_buffer_new (struct t_weechat_plugin *,
+ char *, char *);
+extern struct t_gui_buffer *plugin_api_buffer_search (struct t_weechat_plugin *,
+ char *, char *);
+extern void plugin_api_buffer_close (struct t_weechat_plugin *, void *);
+extern void plugin_api_buffer_set (struct t_weechat_plugin *, void *, char *,
+ char *);
+extern void plugin_api_buffer_nick_add (struct t_weechat_plugin *, void *,
+ char *, int, char *, char, char *);
+extern void plugin_api_buffer_nick_remove (struct t_weechat_plugin *, char *);
+
+/* command */
+extern void plugin_api_command (struct t_weechat_plugin *, void *, char *);
+
+/* infos */
+extern char *plugin_api_info_get (struct t_weechat_plugin *, char *);
+
+/* config */
+extern char *plugin_api_config_get (struct t_weechat_plugin *, char *);
+extern int plugin_api_config_set (struct t_weechat_plugin *, char *, char *);
+extern char *plugin_api_plugin_config_get (struct t_weechat_plugin *, char *);
+extern int plugin_api_plugin_config_set (struct t_weechat_plugin *, char *, char *);
+
+/* log */
+extern void plugin_api_log (struct t_weechat_plugin *, char *, char *, char *, ...);
+
+#endif /* plugin-api.h */
diff --git a/src/plugins/plugin-config.c b/src/plugins/plugin-config.c
new file mode 100644
index 000000000..9c15cd620
--- /dev/null
+++ b/src/plugins/plugin-config.c
@@ -0,0 +1,335 @@
+/*
+ * Copyright (c) 2003-2007 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* plugin-config.c: plugin configuration */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "../core/weechat.h"
+#include "../core/wee-config.h"
+#include "../core/wee-hook.h"
+#include "../core/wee-log.h"
+#include "../core/wee-string.h"
+#include "plugin-config.h"
+
+
+struct t_plugin_option *plugin_options = NULL;
+struct t_plugin_option *last_plugin_option = NULL;
+
+char *plugin_config_sections[] =
+{ "plugin", NULL };
+
+struct t_config_option *plugin_config_options[] =
+{ NULL, NULL };
+
+t_config_func_read_option *plugin_config_read_functions[] =
+{ plugin_config_read_option, NULL };
+
+t_config_func_write_options *plugin_config_write_functions[] =
+{ plugin_config_write_options, NULL };
+
+
+/*
+ * plugin_config_search_internal: search a plugin option (internal function)
+ * This function should not be called directly.
+ */
+
+struct t_plugin_option *
+plugin_config_search_internal (char *option)
+{
+ struct t_plugin_option *ptr_plugin_option;
+
+ for (ptr_plugin_option = plugin_options; ptr_plugin_option;
+ ptr_plugin_option = ptr_plugin_option->next_option)
+ {
+ if (string_strcasecmp (ptr_plugin_option->name, option) == 0)
+ {
+ return ptr_plugin_option;
+ }
+ }
+
+ /* plugin option not found */
+ return NULL;
+}
+
+/*
+ * plugin_config_search: search a plugin option
+ */
+
+struct t_plugin_option *
+plugin_config_search (char *plugin_name, char *option)
+{
+ char *internal_option;
+ struct t_plugin_option *ptr_plugin_option;
+
+ internal_option = (char *)malloc (strlen (plugin_name) +
+ strlen (option) + 2);
+ if (!internal_option)
+ return NULL;
+
+ strcpy (internal_option, plugin_name);
+ strcat (internal_option, ".");
+ strcat (internal_option, option);
+
+ ptr_plugin_option = plugin_config_search_internal (internal_option);
+
+ free (internal_option);
+
+ return ptr_plugin_option;
+}
+
+/*
+ * plugin_config_find_pos: find position for a plugin option (for sorting options)
+ */
+
+struct t_plugin_option *
+plugin_config_find_pos (char *name)
+{
+ struct t_plugin_option *ptr_option;
+
+ for (ptr_option = plugin_options; ptr_option;
+ ptr_option = ptr_option->next_option)
+ {
+ if (string_strcasecmp (name, ptr_option->name) < 0)
+ return ptr_option;
+ }
+ return NULL;
+}
+
+/*
+ * plugin_config_set_internal: set value for a plugin option (internal function)
+ * This function should not be called directly.
+ * Return: 1 if ok, 0 if error
+ */
+
+int
+plugin_config_set_internal (char *option, char *value)
+{
+ struct t_plugin_option *ptr_plugin_option, *pos_option;
+ int rc;
+
+ rc = 0;
+
+ ptr_plugin_option = plugin_config_search_internal (option);
+ if (ptr_plugin_option)
+ {
+ if (!value || !value[0])
+ {
+ /* remove option from list */
+ if (ptr_plugin_option->prev_option)
+ (ptr_plugin_option->prev_option)->next_option =
+ ptr_plugin_option->next_option;
+ else
+ plugin_options = ptr_plugin_option->next_option;
+ if (ptr_plugin_option->next_option)
+ (ptr_plugin_option->next_option)->prev_option =
+ ptr_plugin_option->prev_option;
+ rc = 1;
+ }
+ else
+ {
+ /* replace old value by new one */
+ if (ptr_plugin_option->value)
+ free (ptr_plugin_option->value);
+ ptr_plugin_option->value = strdup (value);
+ rc = 1;
+ }
+ }
+ else
+ {
+ if (value && value[0])
+ {
+ ptr_plugin_option = (struct t_plugin_option *)malloc (sizeof (struct t_plugin_option));
+ if (ptr_plugin_option)
+ {
+ /* create new option */
+ ptr_plugin_option->name = strdup (option);
+ string_tolower (ptr_plugin_option->name);
+ ptr_plugin_option->value = strdup (value);
+
+ if (plugin_options)
+ {
+ pos_option = plugin_config_find_pos (ptr_plugin_option->name);
+ if (pos_option)
+ {
+ /* insert option into the list (before option found) */
+ ptr_plugin_option->prev_option = pos_option->prev_option;
+ ptr_plugin_option->next_option = pos_option;
+ if (pos_option->prev_option)
+ pos_option->prev_option->next_option = ptr_plugin_option;
+ else
+ plugin_options = ptr_plugin_option;
+ pos_option->prev_option = ptr_plugin_option;
+ }
+ else
+ {
+ /* add option to the end */
+ ptr_plugin_option->prev_option = last_plugin_option;
+ ptr_plugin_option->next_option = NULL;
+ last_plugin_option->next_option = ptr_plugin_option;
+ last_plugin_option = ptr_plugin_option;
+ }
+ }
+ else
+ {
+ ptr_plugin_option->prev_option = NULL;
+ ptr_plugin_option->next_option = NULL;
+ plugin_options = ptr_plugin_option;
+ last_plugin_option = ptr_plugin_option;
+ }
+ rc = 1;
+ }
+ }
+ else
+ rc = 0;
+ }
+
+ if (rc)
+ hook_config_exec ("plugin", option, value);
+
+ return rc;
+}
+
+/*
+ * plugin_config_set: set value for a plugin option (create it if not found)
+ * return: 1 if ok, 0 if error
+ */
+
+int
+plugin_config_set (char *plugin_name, char *option, char *value)
+{
+ char *internal_option;
+ int return_code;
+
+ internal_option = (char *)malloc (strlen (plugin_name) +
+ strlen (option) + 2);
+ if (!internal_option)
+ return 0;
+
+ strcpy (internal_option, plugin_name);
+ strcat (internal_option, ".");
+ strcat (internal_option, option);
+
+ return_code = plugin_config_set_internal (internal_option, value);
+ free (internal_option);
+
+ return return_code;
+}
+
+/*
+ * plugin_config_read_option: read an option in config file
+ * Return: 0 = successful
+ * -1 = option not found
+ * -2 = bad format/value
+ */
+
+int
+plugin_config_read_option (struct t_config_option *options,
+ char *option_name, char *value)
+{
+ char *value2;
+
+ /* make C compiler happy */
+ (void) options;
+
+ if (option_name)
+ {
+ value2 = string_iconv_to_internal (NULL, value);
+ plugin_config_set_internal (option_name,
+ (value2) ? value2 : value);
+ if (value2)
+ free (value2);
+ }
+ else
+ {
+ /* does nothing for new [plugin] section */
+ }
+
+ /* all ok */
+ return 0;
+}
+
+/*
+ * plugin_config_read: read WeeChat plugins configuration file
+ * return: 0 = successful
+ * -1 = config file file not found
+ * -2 = error in config file
+ */
+
+int
+plugin_config_read ()
+{
+ return config_file_read (plugin_config_sections, plugin_config_options,
+ plugin_config_read_functions,
+ plugin_config_read_option,
+ NULL,
+ WEECHAT_PLUGIN_CONFIG_NAME);
+}
+
+/*
+ * plugin_config_write_options: write plugin options in configuration file
+ * Return: 0 = successful
+ * -1 = write error
+ */
+
+int
+plugin_config_write_options (FILE *file, char *section_name,
+ struct t_config_option *options)
+{
+ /* make C compiler happy */
+ (void) options;
+
+ struct t_plugin_option *ptr_plugin_option;
+
+ string_iconv_fprintf (file, "\n[%s]\n", section_name);
+
+ for (ptr_plugin_option = plugin_options; ptr_plugin_option;
+ ptr_plugin_option = ptr_plugin_option->next_option)
+ {
+ string_iconv_fprintf (file, "%s = \"%s\"\n",
+ ptr_plugin_option->name,
+ ptr_plugin_option->value);
+ }
+
+ /* all ok */
+ return 0;
+}
+
+/*
+ * plugin_config_write: write WeeChat configuration file
+ * return: 0 if ok
+ * < 0 if error
+ */
+
+int
+plugin_config_write ()
+{
+ weechat_log_printf (_("Saving plugins configuration to disk\n"));
+ return config_file_write (plugin_config_sections, plugin_config_options,
+ plugin_config_write_functions,
+ WEECHAT_PLUGIN_CONFIG_NAME);
+}
diff --git a/src/plugins/plugin-config.h b/src/plugins/plugin-config.h
new file mode 100644
index 000000000..27ce60b4f
--- /dev/null
+++ b/src/plugins/plugin-config.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2003-2007 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __WEECHAT_PLUGIN_CONFIG_H
+#define __WEECHAT_PLUGIN_CONFIG_H 1
+
+#include "../core/wee-config-option.h"
+
+#define WEECHAT_PLUGIN_CONFIG_NAME "plugins.rc"
+
+struct t_plugin_option
+{
+ char *name; /* option name in config file */
+ char *value; /* value of option */
+ struct t_plugin_option *prev_option; /* link to previous option */
+ struct t_plugin_option *next_option; /* link to next option */
+};
+
+extern struct t_plugin_option *plugin_options;
+
+extern struct t_plugin_option *plugin_config_search_internal (char *);
+extern struct t_plugin_option *plugin_config_search (char *, char *);
+extern int plugin_config_set_internal (char *, char *);
+extern int plugin_config_set (char *, char *, char *);
+extern int plugin_config_read_option (struct t_config_option *, char *, char *);
+extern int plugin_config_read ();
+extern int plugin_config_write_options (FILE *, char *,
+ struct t_config_option *);
+extern int plugin_config_write ();
+
+#endif /* plugin-config.h */
diff --git a/src/plugins/plugin-list.c b/src/plugins/plugin-list.c
new file mode 100644
index 000000000..9bcaa301f
--- /dev/null
+++ b/src/plugins/plugin-list.c
@@ -0,0 +1,361 @@
+/*
+ * Copyright (c) 2003-2007 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* plugin-list.c: manages plugin info lists */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "../core/weechat.h"
+#include "../core/wee-log.h"
+#include "plugin-list.h"
+
+
+struct t_plugin_list *plugin_lists = NULL;
+struct t_plugin_list *last_plugin_list = NULL;
+
+
+/*
+ * plugin_list_new: create a new plugin list
+ */
+
+struct t_plugin_list *
+plugin_list_new ()
+{
+ struct t_plugin_list *new_list;
+
+ new_list = (struct t_plugin_list *)malloc (sizeof (struct t_plugin_list));
+ if (new_list)
+ {
+ new_list->items = NULL;
+ new_list->last_item = NULL;
+ new_list->ptr_item = NULL;
+
+ new_list->prev_list = last_plugin_list;
+ new_list->next_list = NULL;
+ if (plugin_lists)
+ last_plugin_list->next_list = new_list;
+ else
+ plugin_lists = new_list;
+ last_plugin_list = new_list;
+ }
+
+ return new_list;
+}
+
+/*
+ * plugin_list_new_item: create a new item in a plugin list
+ */
+
+struct t_plugin_list_item *
+plugin_list_new_item (struct t_plugin_list *list)
+{
+ struct t_plugin_list_item *new_item;
+
+ new_item = (struct t_plugin_list_item *)malloc (sizeof (struct t_plugin_list_item));
+ if (new_item)
+ {
+ new_item->vars = NULL;
+ new_item->last_var = NULL;
+
+ new_item->prev_item = list->last_item;
+ new_item->next_item = NULL;
+ if (list->items)
+ list->last_item->next_item = new_item;
+ else
+ list->items = new_item;
+ list->last_item = new_item;
+ }
+
+ return new_item;
+}
+
+/*
+ * plugin_list_new_var_int: create a new integer variable in an item
+ */
+
+struct t_plugin_list_var *
+plugin_list_new_var_int (struct t_plugin_list_item *item,
+ char *name, int value)
+{
+ struct t_plugin_list_var *new_var;
+
+ new_var = (struct t_plugin_list_var *)malloc (sizeof (struct t_plugin_list_var));
+ if (new_var)
+ {
+ new_var->name = strdup (name);
+ new_var->value_int = value;
+ new_var->value_string = NULL;
+ new_var->value_pointer = NULL;
+ new_var->value_time = 0;
+
+ new_var->prev_var = item->last_var;
+ new_var->next_var = NULL;
+ if (item->vars)
+ item->last_var->next_var = new_var;
+ else
+ item->vars = new_var;
+ item->last_var = new_var;
+ }
+
+ return new_var;
+}
+
+/*
+ * plugin_list_new_var_string: create a new string variable in an item
+ */
+
+struct t_plugin_list_var *
+plugin_list_new_var_string (struct t_plugin_list_item *item,
+ char *name, char *value)
+{
+ struct t_plugin_list_var *new_var;
+
+ new_var = (struct t_plugin_list_var *)malloc (sizeof (struct t_plugin_list_var));
+ if (new_var)
+ {
+ new_var->name = strdup (name);
+ new_var->value_int = 0;
+ new_var->value_string = strdup (value);
+ new_var->value_time = 0;
+
+ new_var->prev_var = item->last_var;
+ new_var->next_var = NULL;
+ if (item->vars)
+ item->last_var->next_var = new_var;
+ else
+ item->vars = new_var;
+ item->last_var = new_var;
+ }
+
+ return new_var;
+}
+
+/*
+ * plugin_list_new_var_pointer: create a new pointer variable in an item
+ */
+
+struct t_plugin_list_var *
+plugin_list_new_var_pointer (struct t_plugin_list_item *item,
+ char *name, void *pointer)
+{
+ struct t_plugin_list_var *new_var;
+
+ new_var = (struct t_plugin_list_var *)malloc (sizeof (struct t_plugin_list_var));
+ if (new_var)
+ {
+ new_var->name = strdup (name);
+ new_var->value_int = 0;
+ new_var->value_string = NULL;
+ new_var->value_pointer = pointer;
+ new_var->value_time = 0;
+
+ new_var->prev_var = item->last_var;
+ new_var->next_var = NULL;
+ if (item->vars)
+ item->last_var->next_var = new_var;
+ else
+ item->vars = new_var;
+ item->last_var = new_var;
+ }
+
+ return new_var;
+}
+
+/*
+ * plugin_list_new_var_time: create a new time variable in an item
+ */
+
+struct t_plugin_list_var *
+plugin_list_new_var_time (struct t_plugin_list_item *item,
+ char *name, time_t time)
+{
+ struct t_plugin_list_var *new_var;
+
+ new_var = (struct t_plugin_list_var *)malloc (sizeof (struct t_plugin_list_var));
+ if (new_var)
+ {
+ new_var->name = strdup (name);
+ new_var->value_int = 0;
+ new_var->value_string = NULL;
+ new_var->value_pointer = NULL;
+ new_var->value_time = time;
+
+ new_var->prev_var = item->last_var;
+ new_var->next_var = NULL;
+ if (item->vars)
+ item->last_var->next_var = new_var;
+ else
+ item->vars = new_var;
+ item->last_var = new_var;
+ }
+
+ return new_var;
+}
+
+/*
+ * plugin_list_var_free: free a plugin list variable
+ */
+
+void
+plugin_list_var_free (struct t_plugin_list_item *item,
+ struct t_plugin_list_var *var)
+{
+ struct t_plugin_list_var *new_vars;
+
+ /* remove var */
+ if (item->last_var == var)
+ item->last_var = var->prev_var;
+ if (var->prev_var)
+ {
+ (var->prev_var)->next_var = var->next_var;
+ new_vars = item->vars;
+ }
+ else
+ new_vars = var->next_var;
+
+ if (var->next_var)
+ (var->next_var)->prev_var = var->prev_var;
+
+ /* free data */
+ if (var->name)
+ free (var->name);
+ if (var->value_string)
+ free (var->value_string);
+
+ item->vars = new_vars;
+}
+
+/*
+ * plugin_list_item_free: free a plugin list item
+ */
+
+void
+plugin_list_item_free (struct t_plugin_list *list,
+ struct t_plugin_list_item *item)
+{
+ struct t_plugin_list_item *new_items;
+
+ /* remove var */
+ if (list->last_item == item)
+ list->last_item = item->prev_item;
+ if (item->prev_item)
+ {
+ (item->prev_item)->next_item = item->next_item;
+ new_items = list->items;
+ }
+ else
+ new_items = item->next_item;
+
+ if (item->next_item)
+ (item->next_item)->prev_item = item->prev_item;
+
+ /* free data */
+ while (item->vars)
+ {
+ plugin_list_var_free (item, item->vars);
+ }
+
+ list->items = new_items;
+}
+
+/*
+ * plugin_list_free: free a plugin list
+ */
+
+void
+plugin_list_free (struct t_plugin_list *list)
+{
+ struct t_plugin_list *new_plugin_lists;
+
+ /* remove list */
+ if (last_plugin_list == list)
+ last_plugin_list = list->prev_list;
+ if (list->prev_list)
+ {
+ (list->prev_list)->next_list = list->next_list;
+ new_plugin_lists = plugin_lists;
+ }
+ else
+ new_plugin_lists = list->next_list;
+
+ if (list->next_list)
+ (list->next_list)->prev_list = list->prev_list;
+
+ /* free data */
+ while (list->items)
+ {
+ plugin_list_item_free (list, list->items);
+ }
+
+ plugin_lists = new_plugin_lists;
+}
+
+/*
+ * plugin_list_print_log: print plugin lists infos in log (usually for crash dump)
+ */
+
+void
+plugin_list_print_log ()
+{
+ struct t_plugin_list *ptr_list;
+ struct t_plugin_list_item *ptr_item;
+ struct t_plugin_list_var *ptr_var;
+
+ for (ptr_list = plugin_lists; ptr_list;
+ ptr_list = ptr_list->next_list)
+ {
+ weechat_log_printf ("\n");
+ weechat_log_printf ("[plugin list (addr:0x%X)]\n", ptr_list);
+ weechat_log_printf (" items. . . . . . . . . : 0x%X\n", ptr_list->items);
+ weechat_log_printf (" last_item. . . . . . . : 0x%X\n", ptr_list->last_item);
+ weechat_log_printf (" ptr_item . . . . . . . : 0x%X\n", ptr_list->ptr_item);
+ weechat_log_printf (" prev_list. . . . . . . : 0x%X\n", ptr_list->prev_list);
+ weechat_log_printf (" next_list. . . . . . . : 0x%X\n", ptr_list->next_list);
+
+ for (ptr_item = ptr_list->items; ptr_item;
+ ptr_item = ptr_item->next_item)
+ {
+ weechat_log_printf ("\n");
+ weechat_log_printf (" [item (addr:0x%X)]\n", ptr_item);
+ weechat_log_printf (" vars . . . . . . . . . : 0x%X\n", ptr_item->vars);
+ weechat_log_printf (" last_var . . . . . . . : 0x%X\n", ptr_item->last_var);
+ weechat_log_printf (" prev_item. . . . . . . : 0x%X\n", ptr_item->prev_item);
+ weechat_log_printf (" next_item. . . . . . . : 0x%X\n", ptr_item->next_item);
+
+ for (ptr_var = ptr_item->vars; ptr_var;
+ ptr_var = ptr_var->next_var)
+ {
+ weechat_log_printf ("\n");
+ weechat_log_printf (" [var (addr:0x%X)]\n", ptr_var);
+ weechat_log_printf (" name . . . . . . . . : '%s'\n", ptr_var->name);
+ weechat_log_printf (" type . . . . . . . . : %d\n", ptr_var->type);
+ weechat_log_printf (" value_int. . . . . . : %d\n", ptr_var->value_int);
+ weechat_log_printf (" value_string . . . . : '%s'\n", ptr_var->value_string);
+ weechat_log_printf (" value_time . . . . . : %ld\n", ptr_var->value_time);
+ weechat_log_printf (" prev_var . . . . . . : 0x%X\n", ptr_var->prev_var);
+ weechat_log_printf (" next_var . . . . . . : 0x%X\n", ptr_var->next_var);
+ }
+ }
+ }
+}
diff --git a/src/plugins/plugin-list.h b/src/plugins/plugin-list.h
new file mode 100644
index 000000000..251a0168b
--- /dev/null
+++ b/src/plugins/plugin-list.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2003-2007 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __WEECHAT_PLUGIN_LIST_H
+#define __WEECHAT_PLUGIN_LIST_H 1
+
+/* list structures */
+
+enum t_plugin_var_type
+{
+ PLUGIN_LIST_VAR_INTEGER = 0,
+ PLUGIN_LIST_VAR_STRING,
+ PLUGIN_LIST_VAR_POINTER,
+ PLUGIN_LIST_VAR_TIME,
+};
+
+struct t_plugin_list_var
+{
+ char *name; /* variable name */
+ enum t_plugin_var_type type; /* type: integer, string, time */
+ int value_int; /* integer value */
+ char *value_string; /* string value */
+ void *value_pointer; /* pointer value */
+ time_t value_time; /* time value */
+ struct t_plugin_list_var *prev_var; /* link to previous variable */
+ struct t_plugin_list_var *next_var; /* link to next variable */
+};
+
+struct t_plugin_list_item
+{
+ struct t_plugin_list_var *vars; /* item variables */
+ struct t_plugin_list_var *last_var; /* last variable */
+ struct t_plugin_list_item *prev_item; /* link to previous item */
+ struct t_plugin_list_item *next_item; /* link to next item */
+};
+
+struct t_plugin_list
+{
+ struct t_plugin_list_item *items; /* link to items */
+ struct t_plugin_list_item *last_item; /* last variable */
+ struct t_plugin_list_item *ptr_item; /* pointer to current item */
+ struct t_plugin_list *prev_list; /* link to previous list */
+ struct t_plugin_list *next_list; /* link to next list */
+};
+
+/* list variables */
+
+extern struct t_plugin_list *plugin_lists;
+extern struct t_plugin_list *last_plugin_list;
+
+/* list functions */
+
+extern struct t_plugin_list *plugin_list_new ();
+extern struct t_plugin_list_item *plugin_list_new_item (struct t_plugin_list *);
+extern struct t_plugin_list_var *plugin_list_new_var_int (struct t_plugin_list_item *,
+ char *, int);
+extern struct t_plugin_list_var *plugin_list_new_var_string (struct t_plugin_list_item *,
+ char *, char *);
+extern struct t_plugin_list_var *plugin_list_new_var_pointer (struct t_plugin_list_item *,
+ char *, void *);
+extern struct t_plugin_list_var *plugin_list_new_var_time (struct t_plugin_list_item *,
+ char *, time_t);
+extern void plugin_list_free (struct t_plugin_list *);
+extern void plugin_list_print_log ();
+
+#endif /* plugin-list.h */
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
new file mode 100644
index 000000000..32bb9d195
--- /dev/null
+++ b/src/plugins/plugin.c
@@ -0,0 +1,601 @@
+/*
+ * Copyright (c) 2003-2007 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* plugin.c: manages WeeChat plugins (dynamic C libraries) */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <dlfcn.h>
+
+#include "../core/weechat.h"
+#include "../core/wee-command.h"
+#include "../core/wee-config.h"
+#include "../core/wee-hook.h"
+#include "../core/wee-log.h"
+#include "../core/wee-string.h"
+#include "../core/wee-util.h"
+#include "../gui/gui-chat.h"
+#include "plugin.h"
+#include "plugin-api.h"
+#include "plugin-config.h"
+#include "plugin-list.h"
+
+
+struct t_weechat_plugin *weechat_plugins = NULL;
+struct t_weechat_plugin *last_weechat_plugin = NULL;
+
+
+/*
+ * plugin_exec_on_files: find files in a directory and execute a
+ * function on each file
+ */
+
+void
+plugin_exec_on_files (struct t_weechat_plugin *plugin, char *directory,
+ int (*callback)(struct t_weechat_plugin *, char *))
+{
+ char complete_filename[1024];
+ DIR *dir;
+ struct dirent *entry;
+ struct stat statbuf;
+
+ dir = opendir (directory);
+ if (dir)
+ {
+ while ((entry = readdir (dir)))
+ {
+ snprintf (complete_filename, sizeof (complete_filename) - 1,
+ "%s/%s", directory, entry->d_name);
+ lstat (complete_filename, &statbuf);
+ if (!S_ISDIR(statbuf.st_mode))
+ {
+ (int) (*callback) (plugin, complete_filename);
+ }
+ }
+ closedir (dir);
+ }
+}
+
+/*
+ * plugin_search: search a plugin by name
+ */
+
+struct t_weechat_plugin *
+plugin_search (char *name)
+{
+ struct t_weechat_plugin *ptr_plugin;
+
+ for (ptr_plugin = weechat_plugins; ptr_plugin;
+ ptr_plugin = ptr_plugin->next_plugin)
+ {
+ if (string_strcasecmp (ptr_plugin->name, name) == 0)
+ return ptr_plugin;
+ }
+
+ /* plugin not found */
+ return NULL;
+}
+
+/*
+ * plugin_load: load a WeeChat plugin (a dynamic library)
+ * return: pointer to new WeeChat plugin, NULL if error
+ */
+
+struct t_weechat_plugin *
+plugin_load (char *filename)
+{
+ char *full_name;
+ void *handle;
+ char *name, *description, *version, *charset;
+ t_weechat_init_func *init_func;
+ struct t_weechat_plugin *new_plugin;
+
+ if (!filename)
+ return NULL;
+
+ full_name = util_search_full_lib_name (filename, "plugins");
+
+ if (!full_name)
+ return NULL;
+
+ handle = dlopen (full_name, RTLD_GLOBAL | RTLD_NOW);
+ if (!handle)
+ {
+ gui_chat_printf (NULL,
+ _("%s%s unable to load plugin \"%s\": %s\n"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ WEECHAT_ERROR, full_name, dlerror());
+ free (full_name);
+ return NULL;
+ }
+
+ /* look for plugin name */
+ name = dlsym (handle, "plugin_name");
+ if (!name)
+ {
+ dlclose (handle);
+ gui_chat_printf (NULL,
+ _("%s%s symbol \"%s\" not found in "
+ "plugin \"%s\", failed to load\n"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ WEECHAT_ERROR, "plugin_name",
+ full_name);
+ free (full_name);
+ return NULL;
+ }
+
+ /* check for plugin with same name */
+ if (plugin_search (name))
+ {
+ dlclose (handle);
+ gui_chat_printf (NULL,
+ _("%s%s unable to load plugin \"%s\": a plugin "
+ "with same name already exists\n"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ WEECHAT_ERROR, full_name);
+ free (full_name);
+ return NULL;
+ }
+
+ /* look for plugin description */
+ description = dlsym (handle, "plugin_description");
+ if (!description)
+ {
+ dlclose (handle);
+ gui_chat_printf (NULL,
+ _("%s%s symbol \"%s\" not found "
+ "in plugin \"%s\", failed to load\n"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ WEECHAT_ERROR, "plugin_description",
+ full_name);
+ free (full_name);
+ return NULL;
+ }
+
+ /* look for plugin version */
+ version = dlsym (handle, "plugin_version");
+ if (!version)
+ {
+ dlclose (handle);
+ gui_chat_printf (NULL,
+ _("%s%s symbol \"%s\" not found in "
+ "plugin \"%s\", failed to load\n"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ WEECHAT_ERROR, "plugin_version",
+ full_name);
+ free (full_name);
+ return NULL;
+ }
+
+ /* look for plugin charset (optional) */
+ charset = dlsym (handle, "plugin_charset");
+
+ /* look for plugin init function */
+ init_func = dlsym (handle, "weechat_plugin_init");
+ if (!init_func)
+ {
+ dlclose (handle);
+ gui_chat_printf (NULL,
+ _("%s%s function \"%s\" not "
+ "found in plugin \"%s\", failed to load\n"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ WEECHAT_ERROR, "weechat_plugin_init",
+ full_name);
+ free (full_name);
+ return NULL;
+ }
+
+ /* create new plugin */
+ new_plugin = (struct t_weechat_plugin *)malloc (sizeof (struct t_weechat_plugin));
+ if (new_plugin)
+ {
+ /* variables */
+ new_plugin->filename = strdup (full_name);
+ new_plugin->handle = handle;
+ new_plugin->name = strdup (name);
+ new_plugin->description = strdup (description);
+ new_plugin->version = strdup (version);
+ new_plugin->charset = (charset) ? strdup (charset) : NULL;
+
+ /* functions */
+ new_plugin->charset_set = &plugin_api_charset_set;
+ new_plugin->iconv_to_internal = &plugin_api_iconv_to_internal;
+ new_plugin->iconv_from_internal = &plugin_api_iconv_from_internal;
+ new_plugin->gettext = &plugin_api_gettext;
+ new_plugin->ngettext = &plugin_api_ngettext;
+ new_plugin->strcasecmp = &plugin_api_strcasecmp;
+ new_plugin->strncasecmp = &plugin_api_strncasecmp;
+ new_plugin->explode_string = &plugin_api_explode_string;
+ new_plugin->free_exploded_string = &plugin_api_free_exploded_string;
+
+ new_plugin->mkdir_home = &plugin_api_mkdir_home;
+ new_plugin->exec_on_files = &plugin_api_exec_on_files;
+
+ new_plugin->printf = &plugin_api_printf;
+ new_plugin->prefix = &plugin_api_prefix;
+ new_plugin->color = &plugin_api_color;
+ new_plugin->print_infobar = &plugin_api_print_infobar;
+ new_plugin->infobar_remove = &plugin_api_infobar_remove;
+
+ new_plugin->hook_command = &plugin_api_hook_command;
+ new_plugin->hook_message = &plugin_api_hook_message;
+ new_plugin->hook_config = &plugin_api_hook_config;
+ new_plugin->hook_timer = &plugin_api_hook_timer;
+ new_plugin->hook_fd = &plugin_api_hook_fd;
+ new_plugin->unhook = &plugin_api_unhook;
+ new_plugin->unhook_all = &plugin_api_unhook_all;
+
+ new_plugin->buffer_new = &plugin_api_buffer_new;
+ new_plugin->buffer_search = &plugin_api_buffer_search;
+ new_plugin->buffer_close = &plugin_api_buffer_close;
+ new_plugin->buffer_set = &plugin_api_buffer_set;
+ new_plugin->buffer_nick_add = &plugin_api_buffer_nick_add;
+ new_plugin->buffer_nick_remove = &plugin_api_buffer_nick_remove;
+
+ new_plugin->command = &plugin_api_command;
+
+ new_plugin->info_get = &plugin_api_info_get;
+
+ new_plugin->config_get = &plugin_api_config_get;
+ new_plugin->config_set = &plugin_api_config_set;
+ new_plugin->plugin_config_get = &plugin_api_plugin_config_get;
+ new_plugin->plugin_config_set = &plugin_api_plugin_config_set;
+
+ new_plugin->log = &plugin_api_log;
+
+ /* add new plugin to list */
+ new_plugin->prev_plugin = last_weechat_plugin;
+ new_plugin->next_plugin = NULL;
+ if (weechat_plugins)
+ last_weechat_plugin->next_plugin = new_plugin;
+ else
+ weechat_plugins = new_plugin;
+ last_weechat_plugin = new_plugin;
+
+ gui_chat_printf (NULL,
+ _("%sInitializing plugin \"%s\" %s\n"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_INFO],
+ new_plugin->name, new_plugin->version);
+
+ /* init plugin */
+ if (((t_weechat_init_func *)init_func) (new_plugin) < 0)
+ {
+ gui_chat_printf (NULL,
+ _("%s%s unable to initialize plugin "
+ "\"%s\"\n"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ WEECHAT_ERROR, full_name);
+ plugin_remove (new_plugin);
+ free (full_name);
+ return NULL;
+ }
+ }
+ else
+ {
+ gui_chat_printf (NULL,
+ _("%s%s unable to load plugin \"%s\" "
+ "(not enough memory)\n"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ WEECHAT_ERROR, full_name);
+ free (full_name);
+ return NULL;
+ }
+
+ gui_chat_printf (NULL,
+ _("%sPlugin \"%s\" (%s) loaded.\n"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_INFO],
+ name, full_name);
+
+ free (full_name);
+
+ return new_plugin;
+}
+
+/*
+ * plugin_auto_load_file: load a file found by plugin_auto_load,
+ * but only it this is really a dynamic library
+ */
+
+int
+plugin_auto_load_file (struct t_weechat_plugin *plugin, char *filename)
+{
+ char *pos;
+
+ /* make C compiler happy */
+ (void) plugin;
+
+ if (cfg_plugins_extension && cfg_plugins_extension[0])
+ {
+ pos = strstr (filename, cfg_plugins_extension);
+ if (pos)
+ {
+ if (string_strcasecmp (pos, cfg_plugins_extension) == 0)
+ plugin_load (filename);
+ }
+ }
+ else
+ plugin_load (filename);
+ return 1;
+}
+
+/*
+ * plugin_auto_load: auto-load WeeChat plugins
+ */
+
+void
+plugin_auto_load ()
+{
+ char *ptr_home, *dir_name, *plugins_path, *plugins_path2;
+ char *list_plugins, *pos, *pos2;
+
+ if (cfg_plugins_autoload && cfg_plugins_autoload[0])
+ {
+ if (string_strcasecmp (cfg_plugins_autoload, "*") == 0)
+ {
+ /* auto-load plugins in WeeChat home dir */
+ if (cfg_plugins_path && cfg_plugins_path[0])
+ {
+ ptr_home = getenv ("HOME");
+ plugins_path = string_replace (cfg_plugins_path, "~", ptr_home);
+ plugins_path2 = string_replace ((plugins_path) ?
+ plugins_path : cfg_plugins_path,
+ "%h", weechat_home);
+ plugin_exec_on_files (NULL,
+ (plugins_path2) ?
+ plugins_path2 : ((plugins_path) ?
+ plugins_path : cfg_plugins_path),
+ &plugin_auto_load_file);
+ if (plugins_path)
+ free (plugins_path);
+ if (plugins_path2)
+ free (plugins_path2);
+ }
+
+ /* auto-load plugins in WeeChat global lib dir */
+ dir_name = (char *)malloc (strlen (WEECHAT_LIBDIR) + 16);
+ if (dir_name)
+ {
+ snprintf (dir_name, strlen (WEECHAT_LIBDIR) + 16,
+ "%s/plugins", WEECHAT_LIBDIR);
+ plugin_exec_on_files (NULL, dir_name, &plugin_auto_load_file);
+ free (dir_name);
+ }
+ }
+ else
+ {
+ list_plugins = strdup (cfg_plugins_autoload);
+ if (list_plugins)
+ {
+ pos = list_plugins;
+ while (pos && pos[0])
+ {
+ pos2 = strchr (pos, ',');
+ if (pos2)
+ pos2[0] = '\0';
+ plugin_load (pos);
+ if (pos2)
+ pos = pos2 + 1;
+ else
+ pos = NULL;
+ }
+ free (list_plugins);
+ }
+ }
+ }
+}
+
+/*
+ * plugin_remove: remove a WeeChat plugin
+ */
+
+void
+plugin_remove (struct t_weechat_plugin *plugin)
+{
+ struct t_weechat_plugin *new_weechat_plugins;
+
+ /* remove plugin from list */
+ if (last_weechat_plugin == plugin)
+ last_weechat_plugin = plugin->prev_plugin;
+ if (plugin->prev_plugin)
+ {
+ (plugin->prev_plugin)->next_plugin = plugin->next_plugin;
+ new_weechat_plugins = weechat_plugins;
+ }
+ else
+ new_weechat_plugins = plugin->next_plugin;
+
+ if (plugin->next_plugin)
+ (plugin->next_plugin)->prev_plugin = plugin->prev_plugin;
+
+ /* remove all hooks */
+ unhook_all_plugin (plugin);
+
+ /* free data */
+ if (plugin->filename)
+ free (plugin->filename);
+ dlclose (plugin->handle);
+ if (plugin->name)
+ free (plugin->name);
+ if (plugin->description)
+ free (plugin->description);
+ if (plugin->version)
+ free (plugin->version);
+ if (plugin->charset)
+ free (plugin->charset);
+ free (plugin);
+
+ weechat_plugins = new_weechat_plugins;
+}
+
+/*
+ * plugin_unload: unload a WeeChat plugin
+ */
+
+void
+plugin_unload (struct t_weechat_plugin *plugin)
+{
+ t_weechat_end_func *end_func;
+ char *name;
+
+ name = (plugin->name) ? strdup (plugin->name) : strdup ("???");
+
+ end_func = dlsym (plugin->handle, "weechat_plugin_end");
+ if (end_func)
+ (void) (end_func) (plugin);
+ plugin_remove (plugin);
+
+ gui_chat_printf (NULL,
+ _("%sPlugin \"%s\" unloaded.\n"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_INFO],
+ (name) ? name : "???");
+ if (name)
+ free (name);
+}
+
+/*
+ * plugin_unload_name: unload a WeeChat plugin by name
+ */
+
+void
+plugin_unload_name (char *name)
+{
+ struct t_weechat_plugin *ptr_plugin;
+
+ ptr_plugin = plugin_search (name);
+ if (ptr_plugin)
+ plugin_unload (ptr_plugin);
+ else
+ {
+ gui_chat_printf (NULL,
+ _("%s%s plugin \"%s\" not found\n"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ WEECHAT_ERROR, name);
+ }
+}
+
+/*
+ * plugin_unload_all: unload all WeeChat plugins
+ */
+
+void
+plugin_unload_all ()
+{
+ while (weechat_plugins)
+ plugin_unload (last_weechat_plugin);
+}
+
+/*
+ * plugin_reload_name: reload a WeeChat plugin by name
+ */
+
+void
+plugin_reload_name (char *name)
+{
+ struct t_weechat_plugin *ptr_plugin;
+ char *filename;
+
+ ptr_plugin = plugin_search (name);
+ if (ptr_plugin)
+ {
+ filename = strdup (ptr_plugin->filename);
+ if (filename)
+ {
+ plugin_unload (ptr_plugin);
+ gui_chat_printf (NULL,
+ _("%sPlugin \"%s\" unloaded.\n"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_INFO],
+ name);
+ plugin_load (filename);
+ free (filename);
+ }
+ }
+ else
+ {
+ gui_chat_printf (NULL,
+ _("%s%s plugin \"%s\" not found\n"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ WEECHAT_ERROR, name);
+ }
+}
+
+/*
+ * plugin_init: init plugin support
+ */
+
+void
+plugin_init (int auto_load)
+{
+ /* read plugins options on disk */
+ plugin_config_read ();
+
+ /* auto-load plugins if asked */
+ if (auto_load)
+ plugin_auto_load ();
+}
+
+/*
+ * plugin_end: end plugin support
+ */
+
+void
+plugin_end ()
+{
+ /* write plugins config options */
+ plugin_config_write ();
+
+ /* unload all plugins */
+ plugin_unload_all ();
+}
+
+/*
+ * plugin_print_log: print plugin infos in log (usually for crash dump)
+ */
+
+void
+plugin_print_log ()
+{
+ struct t_weechat_plugin *ptr_plugin;
+
+ for (ptr_plugin = weechat_plugins; ptr_plugin;
+ ptr_plugin = ptr_plugin->next_plugin)
+ {
+ weechat_log_printf ("\n");
+ weechat_log_printf ("[plugin (addr:0x%X)]\n", ptr_plugin);
+ weechat_log_printf (" filename . . . . . . . : '%s'\n", ptr_plugin->filename);
+ weechat_log_printf (" handle . . . . . . . . : 0x%X\n", ptr_plugin->handle);
+ weechat_log_printf (" name . . . . . . . . . : '%s'\n", ptr_plugin->name);
+ weechat_log_printf (" description. . . . . . : '%s'\n", ptr_plugin->description);
+ weechat_log_printf (" version. . . . . . . . : '%s'\n", ptr_plugin->version);
+ weechat_log_printf (" charset. . . . . . . . : '%s'\n", ptr_plugin->charset);
+ weechat_log_printf (" prev_plugin. . . . . . : 0x%X\n", ptr_plugin->prev_plugin);
+ weechat_log_printf (" next_plugin. . . . . . : 0x%X\n", ptr_plugin->next_plugin);
+ }
+
+ plugin_list_print_log ();
+}
diff --git a/src/plugins/plugin.h b/src/plugins/plugin.h
new file mode 100644
index 000000000..63e725d7c
--- /dev/null
+++ b/src/plugins/plugin.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2003-2007 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __WEECHAT_PLUGIN_H
+#define __WEECHAT_PLUGIN_H 1
+
+#include "weechat-plugin.h"
+
+typedef int (t_weechat_init_func) (struct t_weechat_plugin *);
+typedef void (t_weechat_end_func) (struct t_weechat_plugin *);
+
+extern struct t_weechat_plugin *weechat_plugins;
+extern struct t_weechat_plugin *last_weechat_plugin;
+
+//extern t_plugin_irc_color plugins_irc_colors[GUI_NUM_IRC_COLORS];
+
+extern void plugin_exec_on_files (struct t_weechat_plugin *, char *,
+ int (*)(struct t_weechat_plugin *, char *));
+extern struct t_weechat_plugin *plugin_search (char *);
+extern struct t_weechat_plugin *plugin_load (char *);
+extern void plugin_auto_load ();
+extern void plugin_remove (struct t_weechat_plugin *);
+extern void plugin_unload (struct t_weechat_plugin *);
+extern void plugin_unload_name (char *);
+extern void plugin_unload_all ();
+extern void plugin_reload_name (char *);
+extern void plugin_init (int);
+extern void plugin_end ();
+extern void plugin_print_log ();
+
+#endif /* plugin.h */
diff --git a/src/plugins/plugins-config.c b/src/plugins/plugins-config.c
deleted file mode 100644
index 8eb75e332..000000000
--- a/src/plugins/plugins-config.c
+++ /dev/null
@@ -1,388 +0,0 @@
-/*
- * Copyright (c) 2003-2007 by FlashCode <flashcode@flashtux.org>
- * See README for License detail, AUTHORS for developers list.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* plugins-config.c: plugins configuration */
-
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include "../common/weechat.h"
-#include "weechat-plugin.h"
-#include "plugins-config.h"
-#include "../common/util.h"
-#include "../protocols/irc/irc.h"
-
-
-t_plugin_option *plugin_options = NULL;
-t_plugin_option *last_plugin_option = NULL;
-
-
-/*
- * plugin_config_search_internal: search a plugin option (internal function)
- * This function should not be called directly.
- */
-
-t_plugin_option *
-plugin_config_search_internal (char *option)
-{
- t_plugin_option *ptr_plugin_option;
-
- for (ptr_plugin_option = plugin_options; ptr_plugin_option;
- ptr_plugin_option = ptr_plugin_option->next_option)
- {
- if (ascii_strcasecmp (ptr_plugin_option->name, option) == 0)
- {
- return ptr_plugin_option;
- }
- }
-
- /* plugin option not found */
- return NULL;
-}
-
-/*
- * plugin_config_search: search a plugin option
- */
-
-t_plugin_option *
-plugin_config_search (t_weechat_plugin *plugin, char *option)
-{
- char *internal_option;
- t_plugin_option *ptr_plugin_option;
-
- internal_option = (char *)malloc (strlen (plugin->name) +
- strlen (option) + 2);
- if (!internal_option)
- return NULL;
-
- strcpy (internal_option, plugin->name);
- strcat (internal_option, ".");
- strcat (internal_option, option);
-
- ptr_plugin_option = plugin_config_search_internal (internal_option);
-
- free (internal_option);
-
- return ptr_plugin_option;
-}
-
-/*
- * plugin_config_find_pos: find position for a plugin option (for sorting options)
- */
-
-t_plugin_option *
-plugin_config_find_pos (char *name)
-{
- t_plugin_option *ptr_option;
-
- for (ptr_option = plugin_options; ptr_option;
- ptr_option = ptr_option->next_option)
- {
- if (ascii_strcasecmp (name, ptr_option->name) < 0)
- return ptr_option;
- }
- return NULL;
-}
-
-/*
- * plugin_config_set_internal: set value for a plugin option (internal function)
- * This function should not be called directly.
- */
-
-int
-plugin_config_set_internal (char *option, char *value)
-{
- t_plugin_option *ptr_plugin_option, *pos_option;
-
- ptr_plugin_option = plugin_config_search_internal (option);
- if (ptr_plugin_option)
- {
- if (!value || !value[0])
- {
- /* remove option from list */
- if (ptr_plugin_option->prev_option)
- (ptr_plugin_option->prev_option)->next_option =
- ptr_plugin_option->next_option;
- else
- plugin_options = ptr_plugin_option->next_option;
- if (ptr_plugin_option->next_option)
- (ptr_plugin_option->next_option)->prev_option =
- ptr_plugin_option->prev_option;
- return 1;
- }
- else
- {
- /* replace old value by new one */
- if (ptr_plugin_option->value)
- free (ptr_plugin_option->value);
- ptr_plugin_option->value = strdup (value);
- return 1;
- }
- }
- else
- {
- if (value && value[0])
- {
- ptr_plugin_option = (t_plugin_option *)malloc (sizeof (t_plugin_option));
- if (ptr_plugin_option)
- {
- /* create new option */
- ptr_plugin_option->name = strdup (option);
- ascii_tolower (ptr_plugin_option->name);
- ptr_plugin_option->value = strdup (value);
-
- if (plugin_options)
- {
- pos_option = plugin_config_find_pos (ptr_plugin_option->name);
- if (pos_option)
- {
- /* insert option into the list (before option found) */
- ptr_plugin_option->prev_option = pos_option->prev_option;
- ptr_plugin_option->next_option = pos_option;
- if (pos_option->prev_option)
- pos_option->prev_option->next_option = ptr_plugin_option;
- else
- plugin_options = ptr_plugin_option;
- pos_option->prev_option = ptr_plugin_option;
- }
- else
- {
- /* add option to the end */
- ptr_plugin_option->prev_option = last_plugin_option;
- ptr_plugin_option->next_option = NULL;
- last_plugin_option->next_option = ptr_plugin_option;
- last_plugin_option = ptr_plugin_option;
- }
- }
- else
- {
- ptr_plugin_option->prev_option = NULL;
- ptr_plugin_option->next_option = NULL;
- plugin_options = ptr_plugin_option;
- last_plugin_option = ptr_plugin_option;
- }
- return 1;
- }
- }
- else
- return 1;
- }
-
- /* failed to set plugin option */
- return 0;
-}
-
-/*
- * plugin_config_set: set value for a plugin option (create it if not found)
- */
-
-int
-plugin_config_set (t_weechat_plugin *plugin, char *option, char *value)
-{
- char *internal_option;
- int return_code;
-
- internal_option = (char *)malloc (strlen (plugin->name) +
- strlen (option) + 2);
- if (!internal_option)
- return 0;
-
- strcpy (internal_option, plugin->name);
- strcat (internal_option, ".");
- strcat (internal_option, option);
-
- return_code = plugin_config_set_internal (internal_option, value);
- free (internal_option);
-
- return return_code;
-}
-
-/*
- * plugin_config_read: read WeeChat plugins configuration
- */
-
-void
-plugin_config_read ()
-{
- int filename_length;
- char *filename;
- FILE *file;
- int line_number;
- char line[1024], *ptr_line, *ptr_line2, *pos, *pos2;
-
- filename_length = strlen (weechat_home) +
- strlen (WEECHAT_PLUGINS_CONFIG_NAME) + 2;
- filename =
- (char *) malloc (filename_length * sizeof (char));
- if (!filename)
- return;
- snprintf (filename, filename_length, "%s%s" WEECHAT_PLUGINS_CONFIG_NAME,
- weechat_home, DIR_SEPARATOR);
- if ((file = fopen (filename, "r")) == NULL)
- return;
-
- line_number = 0;
- while (!feof (file))
- {
- ptr_line = fgets (line, sizeof (line) - 1, file);
- line_number++;
- if (ptr_line)
- {
- /* encode line to internal charset */
- ptr_line2 = weechat_iconv_to_internal (NULL, ptr_line);
- if (ptr_line2)
- {
- snprintf (line, sizeof (line) - 1, "%s", ptr_line2);
- free (ptr_line2);
- }
-
- /* skip spaces */
- while (ptr_line[0] == ' ')
- ptr_line++;
- /* not a comment and not an empty line */
- if ((ptr_line[0] != '#') && (ptr_line[0] != '\r')
- && (ptr_line[0] != '\n'))
- {
- pos = strchr (line, '=');
- if (pos == NULL)
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL,
- _("%s %s, line %d: invalid syntax, missing \"=\"\n"),
- WEECHAT_WARNING, filename, line_number);
- }
- else
- {
- pos[0] = '\0';
- pos++;
-
- /* remove spaces before '=' */
- pos2 = pos - 2;
- while ((pos2 > line) && (pos2[0] == ' '))
- {
- pos2[0] = '\0';
- pos2--;
- }
-
- /* skip spaces after '=' */
- while (pos[0] && (pos[0] == ' '))
- {
- pos++;
- }
-
- /* remove CR/LF */
- pos2 = strchr (pos, '\r');
- if (pos2 != NULL)
- pos2[0] = '\0';
- pos2 = strchr (pos, '\n');
- if (pos2 != NULL)
- pos2[0] = '\0';
-
- /* remove simple or double quotes
- and spaces at the end */
- if (strlen(pos) > 1)
- {
- pos2 = pos + strlen (pos) - 1;
- while ((pos2 > pos) && (pos2[0] == ' '))
- {
- pos2[0] = '\0';
- pos2--;
- }
- pos2 = pos + strlen (pos) - 1;
- if (((pos[0] == '\'') &&
- (pos2[0] == '\'')) ||
- ((pos[0] == '"') &&
- (pos2[0] == '"')))
- {
- pos2[0] = '\0';
- pos++;
- }
- }
-
- plugin_config_set_internal (ptr_line, pos);
- }
- }
- }
- }
-
- fclose (file);
- free (filename);
-}
-
-/*
- * plugin_config_write: write WeeChat configurtion
- * return: 0 if ok
- * < 0 if error
- */
-
-int
-plugin_config_write ()
-{
- int filename_length;
- char *filename;
- FILE *file;
- time_t current_time;
- t_plugin_option *ptr_plugin_option;
-
- filename_length = strlen (weechat_home) +
- strlen (WEECHAT_PLUGINS_CONFIG_NAME) + 2;
- filename =
- (char *) malloc (filename_length * sizeof (char));
- if (!filename)
- return -2;
- snprintf (filename, filename_length, "%s%s" WEECHAT_PLUGINS_CONFIG_NAME,
- weechat_home, DIR_SEPARATOR);
-
- if ((file = fopen (filename, "w")) == NULL)
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL, _("%s cannot create file \"%s\"\n"),
- WEECHAT_ERROR, filename);
- free (filename);
- return -1;
- }
-
- current_time = time (NULL);
- weechat_iconv_fprintf (file, _("#\n# %s plugins configuration file, created by "
- "%s v%s on %s"),
- PACKAGE_NAME, PACKAGE_NAME, PACKAGE_VERSION,
- ctime (&current_time));
- weechat_iconv_fprintf (file, _("# WARNING! Be careful when editing this file, "
- "WeeChat writes this file when options are updated.\n#\n"));
-
- for (ptr_plugin_option = plugin_options; ptr_plugin_option;
- ptr_plugin_option = ptr_plugin_option->next_option)
- {
- weechat_iconv_fprintf (file, "%s = \"%s\"\n",
- ptr_plugin_option->name,
- ptr_plugin_option->value);
- }
-
- fclose (file);
- chmod (filename, 0600);
- free (filename);
- return 0;
-}
diff --git a/src/plugins/plugins-config.h b/src/plugins/plugins-config.h
deleted file mode 100644
index c0dcb6403..000000000
--- a/src/plugins/plugins-config.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2003-2007 by FlashCode <flashcode@flashtux.org>
- * See README for License detail, AUTHORS for developers list.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#ifndef __WEECHAT_PLUGINS_CONFIG_H
-#define __WEECHAT_PLUGINS_CONFIG_H 1
-
-#define WEECHAT_PLUGINS_CONFIG_NAME "plugins.rc"
-
-typedef struct t_plugin_option t_plugin_option;
-
-struct t_plugin_option
-{
- char *name; /* option name in config file */
- char *value; /* value of option */
- t_plugin_option *prev_option; /* link to previous option */
- t_plugin_option *next_option; /* link to next option */
-};
-
-extern t_plugin_option *plugin_options;
-
-extern t_plugin_option *plugin_config_search_internal (char *);
-extern t_plugin_option *plugin_config_search (t_weechat_plugin *, char *);
-extern int plugin_config_set_internal (char *, char *);
-extern int plugin_config_set (t_weechat_plugin *, char *, char *);
-extern void plugin_config_read ();
-extern int plugin_config_write ();
-
-#endif /* plugins-config.h */
diff --git a/src/plugins/plugins-interface.c b/src/plugins/plugins-interface.c
deleted file mode 100644
index bbafd9b5c..000000000
--- a/src/plugins/plugins-interface.c
+++ /dev/null
@@ -1,1508 +0,0 @@
-/*
- * Copyright (c) 2003-2007 by FlashCode <flashcode@flashtux.org>
- * See README for License detail, AUTHORS for developers list.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* plugins-interface.c: WeeChat plugins interface */
-
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <errno.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdarg.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include "../common/weechat.h"
-#include "plugins.h"
-#include "plugins-config.h"
-#include "../common/command.h"
-#include "../common/log.h"
-#include "../common/utf8.h"
-#include "../common/util.h"
-#include "../common/weeconfig.h"
-#include "../protocols/irc/irc.h"
-#include "../gui/gui.h"
-
-
-/*
- * weechat_ascii_strcasecmp: locale and case independent string comparison
- */
-
-int
-weechat_ascii_strcasecmp (t_weechat_plugin *plugin,
- char *string1, char *string2)
-{
- /* make C compiler happy */
- (void) plugin;
-
- return ascii_strcasecmp (string1, string2);
-}
-
-/*
- * weechat_ascii_strncasecmp: locale and case independent string comparison
- * with max length
- */
-
-int
-weechat_ascii_strncasecmp (t_weechat_plugin *plugin,
- char *string1, char *string2, int max)
-{
- /* make C compiler happy */
- (void) plugin;
-
- return ascii_strncasecmp (string1, string2, max);
-}
-
-/*
- * weechat_explode_string: explode a string
- */
-
-char **
-weechat_explode_string (t_weechat_plugin *plugin, char *string,
- char *separators, int num_items_max,
- int *num_items)
-{
- /* make C compiler happy */
- (void) plugin;
-
- if (!plugin || !string || !separators || !num_items)
- return NULL;
-
- return explode_string (string, separators, num_items_max, num_items);
-}
-
-/*
- * weechat_free_exploded_string: free exploded string
- */
-
-void
-weechat_free_exploded_string (t_weechat_plugin *plugin, char **exploded_string)
-{
- /* make C compiler happy */
- (void) plugin;
-
- free_exploded_string (exploded_string);
-}
-
-/*
- * weechat_plugin_mkdir_home: create a directory in WeeChat home
- */
-
-int
-weechat_plugin_mkdir_home (t_weechat_plugin *plugin, char *directory)
-{
- char *dir_name;
- int dir_length;
-
- /* make C compiler happy */
- (void) plugin;
-
- if (!directory)
- return 0;
-
- /* build directory, adding WeeChat home */
- dir_length = strlen (weechat_home) + strlen (directory) + 2;
- dir_name =
- (char *) malloc (dir_length * sizeof (char));
- if (!dir_name)
- return 0;
-
- snprintf (dir_name, dir_length, "%s/%s", weechat_home, directory);
-
- if (mkdir (dir_name, 0755) < 0)
- {
- if (errno != EEXIST)
- {
- free (dir_name);
- return 0;
- }
- }
-
- free (dir_name);
- return 1;
-}
-
-/*
- * weechat_plugin_exec_on_files: find files in a directory and execute a
- * function on each file
- */
-
-void
-weechat_plugin_exec_on_files (t_weechat_plugin *plugin, char *directory,
- int (*callback)(t_weechat_plugin *, char *))
-{
- if (directory && callback)
- plugin_exec_on_files (plugin, directory, callback);
-}
-
-/*
- * weechat_plugin_print: print a message on a server or channel buffer
- */
-
-void
-weechat_plugin_print (t_weechat_plugin *plugin,
- char *server, char *channel, char *message, ...)
-{
- t_gui_buffer *ptr_buffer;
- va_list argptr;
- static char buf[8192];
- char *buf2;
-
- if (!plugin || !message)
- return;
-
- ptr_buffer = gui_buffer_search (server, channel);
- va_start (argptr, message);
- vsnprintf (buf, sizeof (buf) - 1, message, argptr);
- va_end (argptr);
-
- buf2 = weechat_iconv_to_internal (plugin->charset, buf);
- irc_display_prefix (NULL, ptr_buffer, GUI_PREFIX_PLUGIN);
- gui_printf_keep_colors (ptr_buffer, "%s\n", (buf2) ? buf2 : buf);
- if (buf2)
- free (buf2);
-}
-
-/*
- * weechat_plugin_print_server: print a message on server buffer
- */
-
-void
-weechat_plugin_print_server (t_weechat_plugin *plugin, char *message, ...)
-{
- va_list argptr;
- static char buf[8192];
- char *buf2;
-
- if (!plugin || !message)
- return;
-
- va_start (argptr, message);
- vsnprintf (buf, sizeof (buf) - 1, message, argptr);
- va_end (argptr);
-
- buf2 = weechat_iconv_to_internal (plugin->charset, buf);
- irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN);
- gui_printf_keep_colors (NULL, "%s\n", (buf2) ? buf2 : buf);
- if (buf2)
- free (buf2);
-}
-
-/*
- * weechat_plugin_print_infobar: print a message in infobar
- */
-
-void
-weechat_plugin_print_infobar (t_weechat_plugin *plugin, int time_displayed, char *message, ...)
-{
- va_list argptr;
- static char buf[1024];
- char *buf2;
-
- if (!plugin || (time_displayed < 0) || !message)
- return;
-
- va_start (argptr, message);
- vsnprintf (buf, sizeof (buf) - 1, message, argptr);
- va_end (argptr);
-
- buf2 = weechat_iconv_to_internal (plugin->charset, buf);
- gui_infobar_printf (time_displayed, GUI_COLOR_WIN_INFOBAR, "%s",
- (buf2) ? buf2 : buf);
- if (buf2)
- free (buf2);
-}
-
-/*
- * weechat_plugin_infobar_remove: remove message(s) in infobar
- */
-
-void
-weechat_plugin_infobar_remove (t_weechat_plugin *plugin, int how_many)
-{
- if (!plugin)
- return;
-
- if (how_many <= 0)
- gui_infobar_remove_all ();
- else
- {
- while ((gui_infobar) && (how_many > 0))
- {
- gui_infobar_remove ();
- how_many--;
- }
- }
- gui_infobar_draw (gui_current_window->buffer, 1);
-}
-
-/*
- * weechat_plugin_log: add a message in buffer log file
- */
-
-void
-weechat_plugin_log (t_weechat_plugin *plugin,
- char *server, char *channel, char *message, ...)
-{
- t_gui_buffer *ptr_buffer;
- va_list argptr;
- static char buf[8192];
- char *buf2;
-
- if (!plugin || !message)
- return;
-
- ptr_buffer = gui_buffer_search (server, channel);
- if (ptr_buffer)
- {
- va_start (argptr, message);
- vsnprintf (buf, sizeof (buf) - 1, message, argptr);
- va_end (argptr);
-
- buf2 = weechat_iconv_to_internal (plugin->charset, buf);
- gui_log_write_line (ptr_buffer, (buf2) ? buf2 : buf);
- if (buf2)
- free (buf2);
- }
-}
-
-/*
- * weechat_plugin_msg_handler_add: add a message handler
- */
-
-t_plugin_handler *
-weechat_plugin_msg_handler_add (t_weechat_plugin *plugin, char *message,
- t_plugin_handler_func *handler_func,
- char *handler_args, void *handler_pointer)
-{
- if (plugin && message && handler_func)
- return plugin_msg_handler_add (plugin, message, handler_func,
- handler_args, handler_pointer);
-
- return NULL;
-}
-
-/*
- * weechat_plugin_cmd_handler_add: add a command handler
- */
-
-t_plugin_handler *
-weechat_plugin_cmd_handler_add (t_weechat_plugin *plugin, char *command,
- char *description, char *arguments,
- char *arguments_description,
- char *completion_template,
- t_plugin_handler_func *handler_func,
- char *handler_args, void *handler_pointer)
-{
- if (plugin && command && handler_func)
- return plugin_cmd_handler_add (plugin, command, description, arguments,
- arguments_description,
- completion_template,
- handler_func,
- handler_args, handler_pointer);
-
- return NULL;
-}
-
-/*
- * weechat_plugin_timer_handler_add: add a timer handler
- */
-
-t_plugin_handler *
-weechat_plugin_timer_handler_add (t_weechat_plugin *plugin, int interval,
- t_plugin_handler_func *handler_func,
- char *handler_args, void *handler_pointer)
-{
- if (plugin && (interval >= 1) && handler_func)
- return plugin_timer_handler_add (plugin, interval, handler_func,
- handler_args, handler_pointer);
-
- return NULL;
-}
-
-/*
- * weechat_plugin_keyboard_handler_add: add a keyboard handler
- */
-
-t_plugin_handler *
-weechat_plugin_keyboard_handler_add (t_weechat_plugin *plugin,
- t_plugin_handler_func *handler_func,
- char *handler_args, void *handler_pointer)
-{
- if (plugin && handler_func)
- return plugin_keyboard_handler_add (plugin, handler_func,
- handler_args, handler_pointer);
-
- return NULL;
-}
-
-/*
- * weechat_plugin_event_handler_add: add an event handler
- */
-
-t_plugin_handler *
-weechat_plugin_event_handler_add (t_weechat_plugin *plugin, char *event,
- t_plugin_handler_func *handler_func,
- char *handler_args, void *handler_pointer)
-{
- if (plugin && event && handler_func)
- return plugin_event_handler_add (plugin, event, handler_func,
- handler_args, handler_pointer);
-
- return NULL;
-}
-
-/*
- * weechat_plugin_handler_remove: remove a WeeChat handler
- */
-
-void
-weechat_plugin_handler_remove (t_weechat_plugin *plugin,
- t_plugin_handler *handler)
-{
- if (plugin && handler)
- plugin_handler_remove (plugin, handler);
-}
-
-/*
- * weechat_plugin_handler_remove_all: remove all WeeChat handlers
- */
-
-void
-weechat_plugin_handler_remove_all (t_weechat_plugin *plugin)
-{
- if (plugin)
- plugin_handler_remove_all (plugin);
-}
-
-/*
- * weechat_plugin_modifier_add: add a IRC message modifier
- */
-
-t_plugin_modifier *
-weechat_plugin_modifier_add (t_weechat_plugin *plugin,
- char *type, char *message,
- t_plugin_modifier_func *modifier_func,
- char *modifier_args, void *modifier_pointer)
-{
- if (plugin && type && modifier_func)
- return plugin_modifier_add (plugin, type, message, modifier_func,
- modifier_args, modifier_pointer);
-
- return NULL;
-}
-
-/*
- * weechat_plugin_modifier_remove: remove a WeeChat modifier
- */
-
-void
-weechat_plugin_modifier_remove (t_weechat_plugin *plugin,
- t_plugin_modifier *modifier)
-{
- if (plugin && modifier)
- plugin_modifier_remove (plugin, modifier);
-}
-
-/*
- * weechat_plugin_modifier_remove_all: remove all WeeChat modifiers
- */
-
-void
-weechat_plugin_modifier_remove_all (t_weechat_plugin *plugin)
-{
- if (plugin)
- plugin_modifier_remove_all (plugin);
-}
-
-/*
- * weechat_plugin_exec_command: execute a command (simulate user entry)
- */
-
-void
-weechat_plugin_exec_command (t_weechat_plugin *plugin,
- char *server, char *channel, char *command)
-{
- t_irc_server *ptr_server;
- t_irc_channel *ptr_channel;
- char *command2;
-
- if (!plugin || !command)
- return;
-
- if (plugin_find_server_channel (server, channel, &ptr_server, &ptr_channel) < 0)
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL,
- _("%s server/channel (%s/%s) not found for plugin "
- "exec command\n"),
- WEECHAT_ERROR,
- (server) ? server : "", (channel) ? channel : "");
- }
- else
- {
- command2 = weechat_iconv_to_internal (plugin->charset, command);
- if (ptr_server && ptr_channel)
- user_command (ptr_server, ptr_channel, (command2) ? command2 : command, 0);
- else if (ptr_server && (ptr_server->buffer))
- user_command (ptr_server, NULL, (command2) ? command2 : command, 0);
- else
- user_command (NULL, NULL, (command2) ? command2 : command, 0);
- if (command2)
- free (command2);
- }
-}
-
-/*
- * weechat_plugin_get_info: get info about WeeChat
- * WARNING: caller has to free string returned
- * by this function after use
- */
-
-char *
-weechat_plugin_get_info (t_weechat_plugin *plugin, char *info, char *server)
-{
- t_irc_server *ptr_server;
- t_irc_channel *ptr_channel;
- time_t inactivity;
- char *return_str;
-
- if (!plugin || !info)
- return NULL;
-
- /* below are infos that do NOT need server to return info */
-
- if (ascii_strcasecmp (info, "version") == 0)
- {
- return strdup (PACKAGE_VERSION);
- }
- else if (ascii_strcasecmp (info, "weechatdir") == 0)
- {
- /* WARNING: deprecated info, you should use "weechat_dir" */
- /* will be removed in a future version */
- return strdup (weechat_home);
- }
- else if (ascii_strcasecmp (info, "weechat_dir") == 0)
- {
- return strdup (weechat_home);
- }
- else if (ascii_strcasecmp (info, "weechat_libdir") == 0)
- {
- return strdup (WEECHAT_LIBDIR);
- }
- else if (ascii_strcasecmp (info, "weechat_sharedir") == 0)
- {
- return strdup (WEECHAT_SHAREDIR);
- }
- else if (ascii_strcasecmp (info, "charset_terminal") == 0)
- {
- return strdup (local_charset);
- }
- else if (ascii_strcasecmp (info, "charset_internal") == 0)
- {
- return strdup (WEECHAT_INTERNAL_CHARSET);
- }
- else if (ascii_strcasecmp (info, "inactivity") == 0)
- {
- if (gui_last_activity_time == 0)
- inactivity = 0;
- else
- inactivity = time (NULL) - gui_last_activity_time;
- return_str = (char *) malloc (32);
- if (!return_str)
- return NULL;
- snprintf (return_str, 32, "%ld", (long int)inactivity);
- return return_str;
- }
- else if (ascii_strcasecmp (info, "input") == 0)
- {
- if (gui_current_window->buffer->has_input)
- {
- return_str = weechat_iconv_from_internal (plugin->charset,
- gui_current_window->buffer->input_buffer);
- return (return_str) ? return_str : strdup ("");
- }
- else
- return strdup ("");
- }
- else if (ascii_strcasecmp (info, "input_mask") == 0)
- {
- if (gui_current_window->buffer->has_input)
- return strdup (gui_current_window->buffer->input_buffer_color_mask);
- else
- return strdup ("");
- }
- else if (ascii_strcasecmp (info, "input_pos") == 0)
- {
- if (gui_current_window->buffer->has_input)
- {
- return_str = (char *) malloc (32);
- if (!return_str)
- return NULL;
- snprintf (return_str, 32, "%d",
- gui_current_window->buffer->input_buffer_pos);
- return return_str;
- }
- else
- return strdup ("");
- }
-
- /* below are infos that need server to return value */
-
- plugin_find_server_channel (server, NULL, &ptr_server, &ptr_channel);
-
- if (ascii_strcasecmp (info, "nick") == 0)
- {
- if (ptr_server && ptr_server->is_connected && ptr_server->nick)
- return strdup (ptr_server->nick);
- }
- else if (ascii_strcasecmp (info, "channel") == 0)
- {
- if (GUI_BUFFER_IS_CHANNEL(gui_current_window->buffer)
- || GUI_BUFFER_IS_PRIVATE(gui_current_window->buffer))
- return strdup (GUI_CHANNEL(gui_current_window->buffer)->name);
- }
- else if (ascii_strcasecmp (info, "server") == 0)
- {
- if (ptr_server && ptr_server->is_connected && ptr_server->name)
- return strdup (ptr_server->name);
- }
- else if (ascii_strcasecmp (info, "type") == 0)
- {
- return_str = (char *) malloc (32);
- if (!return_str)
- return NULL;
- snprintf (return_str, 32, "%d",
- gui_current_window->buffer->type);
- return return_str;
- }
- else if (ascii_strcasecmp (info, "away") == 0)
- {
- if (ptr_server && ptr_server->is_connected && ptr_server->is_away)
- return strdup ("1");
- else
- return strdup ("0");
- }
-
- /* info not found */
- return NULL;
-}
-
-/*
- * weechat_plugin_get_dcc_info: get list of DCC files/chats info
- * WARNING: caller has to free structure returned
- * by this function after use
- */
-
-t_plugin_dcc_info *
-weechat_plugin_get_dcc_info (t_weechat_plugin *plugin)
-{
- t_plugin_dcc_info *dcc_info, *last_dcc_info, *new_dcc_info;
- t_irc_dcc *ptr_dcc;
-
- if (!plugin)
- return NULL;
-
- if (irc_dcc_list)
- {
- dcc_info = NULL;
- last_dcc_info = NULL;
- for (ptr_dcc = irc_dcc_list; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
- {
- new_dcc_info = (t_plugin_dcc_info *)malloc (sizeof (t_plugin_dcc_info));
- if (new_dcc_info)
- {
- new_dcc_info->server = (ptr_dcc->server) ? strdup (ptr_dcc->server->name) : strdup ("");
- new_dcc_info->channel = (ptr_dcc->channel) ? strdup (ptr_dcc->channel->name) : strdup ("");
- new_dcc_info->type = ptr_dcc->type;
- new_dcc_info->status = ptr_dcc->status;
- new_dcc_info->start_time = ptr_dcc->start_time;
- new_dcc_info->start_transfer = ptr_dcc->start_transfer;
- new_dcc_info->addr = ptr_dcc->addr;
- new_dcc_info->port = ptr_dcc->port;
- new_dcc_info->nick = (ptr_dcc->nick) ? strdup (ptr_dcc->nick) : strdup ("");
- new_dcc_info->filename = (ptr_dcc->filename) ? strdup (ptr_dcc->filename) : strdup ("");
- new_dcc_info->local_filename = (ptr_dcc->local_filename) ? strdup (ptr_dcc->local_filename) : strdup ("");
- new_dcc_info->filename_suffix = ptr_dcc->filename_suffix;
- new_dcc_info->size = ptr_dcc->size;
- new_dcc_info->pos = ptr_dcc->pos;
- new_dcc_info->start_resume = ptr_dcc->start_resume;
- new_dcc_info->bytes_per_sec = ptr_dcc->bytes_per_sec;
-
- new_dcc_info->prev_dcc = last_dcc_info;
- new_dcc_info->next_dcc = NULL;
- if (!dcc_info)
- dcc_info = new_dcc_info;
- else
- last_dcc_info->next_dcc = new_dcc_info;
- last_dcc_info = new_dcc_info;
- }
- }
-
- return dcc_info;
- }
-
- return NULL;
-}
-
-/*
- * weechat_plugin_free_dcc_info: free dcc info struct list
- */
-
-void
-weechat_plugin_free_dcc_info (t_weechat_plugin *plugin, t_plugin_dcc_info *dcc_info)
-{
- t_plugin_dcc_info *new_dcc_info;
-
- if (!plugin || !dcc_info)
- return;
-
- while (dcc_info)
- {
- if (dcc_info->server)
- free (dcc_info->server);
- if (dcc_info->channel)
- free (dcc_info->channel);
- if (dcc_info->nick)
- free (dcc_info->nick);
- if (dcc_info->filename)
- free (dcc_info->filename);
- if (dcc_info->local_filename)
- free (dcc_info->local_filename);
- new_dcc_info = dcc_info->next_dcc;
- free (dcc_info);
- dcc_info = new_dcc_info;
- }
-}
-
-/*
- * weechat_plugin_get_config_str_value: return string value for any option
- * This function should never be called directly
- * (only used by weechat_get_config)
- */
-
-char *
-weechat_plugin_get_config_str_value (t_config_option *option, void *value)
-{
- char buf_temp[1024], *color_name;
-
- if (!value)
- {
- if (option->option_type == OPTION_TYPE_STRING)
- value = option->ptr_string;
- else
- value = option->ptr_int;
- }
-
- switch (option->option_type)
- {
- case OPTION_TYPE_BOOLEAN:
- return (*((int *)value)) ?
- strdup ("on") : strdup ("off");
- break;
- case OPTION_TYPE_INT:
- snprintf (buf_temp, sizeof (buf_temp), "%d",
- *((int *)value));
- return strdup (buf_temp);
- break;
- case OPTION_TYPE_INT_WITH_STRING:
- return strdup (option->array_values[*((int *)value)]);
- break;
- case OPTION_TYPE_COLOR:
- color_name = gui_color_get_name (*((int *)value));
- return (color_name) ? strdup (color_name) : strdup ("");
- break;
- case OPTION_TYPE_STRING:
- return (*((char **)value)) ? strdup (*((char **)value)) : strdup ("");
- break;
- }
-
- /* should never be executed! */
- return NULL;
-}
-
-/*
- * weechat_plugin_get_config: get value of a config option
- */
-
-char *
-weechat_plugin_get_config (t_weechat_plugin *plugin, char *option)
-{
- int i, j;
- t_irc_server *ptr_server;
- char option_name[256];
- void *ptr_option_value;
-
- /* make C compiler happy */
- (void) plugin;
-
- for (i = 0; i < CONFIG_NUMBER_SECTIONS; i++)
- {
- if ((i != CONFIG_SECTION_KEYS) && (i != CONFIG_SECTION_ALIAS)
- && (i != CONFIG_SECTION_IGNORE) && (i != CONFIG_SECTION_SERVER))
- {
- for (j = 0; weechat_options[i][j].option_name; j++)
- {
- if ((!option) ||
- ((option) && (option[0])
- && (ascii_strcasecmp (weechat_options[i][j].option_name, option) == 0)))
- {
- return weechat_plugin_get_config_str_value (&weechat_options[i][j], NULL);
- }
- }
- }
- }
- for (ptr_server = irc_servers; ptr_server;
- ptr_server = ptr_server->next_server)
- {
- for (i = 0; weechat_options[CONFIG_SECTION_SERVER][i].option_name; i++)
- {
- snprintf (option_name, sizeof (option_name), "%s.%s",
- ptr_server->name,
- weechat_options[CONFIG_SECTION_SERVER][i].option_name);
- if ((!option) ||
- ((option) && (option[0])
- && (ascii_strcasecmp (option_name, option) == 0)))
- {
- ptr_option_value = config_get_server_option_ptr (ptr_server,
- weechat_options[CONFIG_SECTION_SERVER][i].option_name);
- if (ptr_option_value)
- {
- return weechat_plugin_get_config_str_value (&weechat_options[CONFIG_SECTION_SERVER][i],
- ptr_option_value);
- }
- }
- }
- }
-
- /* option not found */
- return NULL;
-}
-
-/*
- * weechat_plugin_set_config: set value of a config option
- */
-
-int
-weechat_plugin_set_config (t_weechat_plugin *plugin, char *option, char *value)
-{
- char *pos, *server_name;
- t_irc_server *ptr_server;
- t_config_option *ptr_option;
-
- /* make C compiler happy */
- (void) plugin;
-
- if (!option || !value)
- return 0;
-
- pos = strchr (option, '.');
- if (pos)
- {
- /* server config option modification */
- server_name = (char *)malloc (pos - option + 1);
- if (server_name)
- {
- strncpy (server_name, option, pos - option);
- server_name[pos - option] = '\0';
- ptr_server = irc_server_search (server_name);
- free (server_name);
- if (ptr_server)
- return (config_set_server_value (ptr_server, pos + 1, value) == 0);
- }
- }
- else
- {
- ptr_option = config_option_search (option);
- if (ptr_option)
- {
- if (ptr_option->handler_change)
- {
- if (config_option_set_value (ptr_option, value) == 0)
- {
- (void) (ptr_option->handler_change());
- return 1;
- }
- }
- }
- }
-
- /* failed to set config option */
- return 0;
-}
-
-/*
- * weechat_plugin_get_plugin_config: get value of a plugin config option
- */
-
-char *
-weechat_plugin_get_plugin_config (t_weechat_plugin *plugin, char *option)
-{
- t_plugin_option *ptr_plugin_option;
-
- if (!option)
- return NULL;
-
- ptr_plugin_option = plugin_config_search (plugin, option);
- if (ptr_plugin_option)
- return (ptr_plugin_option->value) ? strdup (ptr_plugin_option->value) : NULL;
-
- /* option not found */
- return NULL;
-}
-
-/*
- * weechat_plugin_set_plugin_config: set value of a plugin config option
- */
-
-int
-weechat_plugin_set_plugin_config (t_weechat_plugin *plugin, char *option, char *value)
-{
- if (!option)
- return 0;
-
- if (plugin_config_set (plugin, option, value))
- {
- plugin_config_write ();
- return 1;
- }
- return 0;
-}
-
-/*
- * weechat_plugin_get_server_info: get list of server info
- * WARNING: caller has to free structure returned
- * by this function after use
- */
-
-t_plugin_server_info *
-weechat_plugin_get_server_info (t_weechat_plugin *plugin)
-{
- t_plugin_server_info *server_info, *last_server_info, *new_server_info;
- t_irc_server *ptr_server;
-
- if (!plugin)
- return NULL;
-
- if (irc_servers)
- {
- server_info = NULL;
- last_server_info = NULL;
- for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server)
- {
- new_server_info = (t_plugin_server_info *) malloc (sizeof (t_plugin_server_info));
- if (new_server_info)
- {
- new_server_info->name = (ptr_server->name) ? strdup (ptr_server->name) : strdup ("");
- new_server_info->autoconnect = ptr_server->autoconnect;
- new_server_info->autoreconnect = ptr_server->autoreconnect;
- new_server_info->autoreconnect_delay = ptr_server->autoreconnect_delay;
- new_server_info->temp_server = ptr_server->temp_server;
- new_server_info->address = (ptr_server->address) ? strdup (ptr_server->address) : strdup ("");
- new_server_info->port = ptr_server->port;
- new_server_info->ipv6 = ptr_server->ipv6;
- new_server_info->ssl = ptr_server->ssl;
- new_server_info->password = (ptr_server->password) ? strdup (ptr_server->password) : strdup ("");
- new_server_info->nick1 = (ptr_server->nick1) ? strdup (ptr_server->nick1) : strdup ("");
- new_server_info->nick2 = (ptr_server->nick2) ? strdup (ptr_server->nick2) : strdup ("");
- new_server_info->nick3 = (ptr_server->nick3) ? strdup (ptr_server->nick3) : strdup ("");
- new_server_info->username = (ptr_server->username) ? strdup (ptr_server->username) : strdup ("");
- new_server_info->realname = (ptr_server->realname) ? strdup (ptr_server->realname) : strdup ("");
- new_server_info->command = (ptr_server->command) ? strdup (ptr_server->command) : strdup ("");
- new_server_info->command_delay = ptr_server->command_delay;
- new_server_info->autojoin = (ptr_server->autojoin) ? strdup (ptr_server->autojoin) : strdup ("");
- new_server_info->autorejoin = ptr_server->autorejoin;
- new_server_info->notify_levels = (ptr_server->notify_levels) ? strdup (ptr_server->notify_levels) : strdup ("");
- new_server_info->is_connected = ptr_server->is_connected;
- new_server_info->ssl_connected = ptr_server->ssl_connected;
- new_server_info->nick = (ptr_server->nick) ? strdup (ptr_server->nick) : strdup ("");
- new_server_info->nick_modes = (ptr_server->nick_modes) ? strdup (ptr_server->nick_modes) : strdup ("");
- new_server_info->is_away = ptr_server->is_away;
- new_server_info->away_time = ptr_server->away_time;
- new_server_info->lag = ptr_server->lag;
-
- new_server_info->prev_server = last_server_info;
- new_server_info->next_server = NULL;
- if (!server_info)
- server_info = new_server_info;
- else
- last_server_info->next_server = new_server_info;
- last_server_info = new_server_info;
- }
- }
-
- return server_info;
- }
-
- return NULL;
-}
-
-/*
- * weechat_plugin_free_server_info: free server info struct list
- */
-
-void
-weechat_plugin_free_server_info (t_weechat_plugin *plugin, t_plugin_server_info *server_info)
-{
- t_plugin_server_info *new_server_info;
-
- if (!plugin || !server_info)
- return;
-
- while (server_info)
- {
- if (server_info->name)
- free (server_info->name);
- if (server_info->address)
- free (server_info->address);
- if (server_info->password)
- free (server_info->password);
- if (server_info->nick1)
- free (server_info->nick1);
- if (server_info->nick2)
- free (server_info->nick2);
- if (server_info->nick3)
- free (server_info->nick3);
- if (server_info->username)
- free (server_info->username);
- if (server_info->realname)
- free (server_info->realname);
- if (server_info->command)
- free (server_info->command);
- if (server_info->autojoin)
- free (server_info->autojoin);
- if (server_info->notify_levels)
- free (server_info->notify_levels);
- if (server_info->nick)
- free (server_info->nick);
- if (server_info->nick_modes)
- free (server_info->nick_modes);
- new_server_info = server_info->next_server;
- free (server_info);
- server_info = new_server_info;
- }
-}
-
-/*
- * weechat_plugin_get_channel_info: get list of channel info from a server
- * WARNING: caller has to free structure
- * returned by this function after use
- */
-
-t_plugin_channel_info *
-weechat_plugin_get_channel_info (t_weechat_plugin *plugin, char *server)
-{
- t_plugin_channel_info *channel_info, *last_channel_info, *new_channel_info;
- t_irc_channel *ptr_channel, *ptr_channels;
- t_irc_server *ptr_server;
-
- if (!plugin || !server || !server[0])
- return NULL;
-
- ptr_server = irc_server_search (server);
- if (!ptr_server)
- return NULL;
-
- ptr_channels = ptr_server->channels;
-
- if (ptr_channels)
- {
- channel_info = NULL;
- last_channel_info = NULL;
- for (ptr_channel = ptr_channels; ptr_channel; ptr_channel = ptr_channel->next_channel)
- {
- new_channel_info = (t_plugin_channel_info *) malloc (sizeof (t_plugin_channel_info));
- if (new_channel_info)
- {
- new_channel_info->type = ptr_channel->type;
- new_channel_info->name = (ptr_channel->name) ? strdup (ptr_channel->name) : strdup ("");
- new_channel_info->topic = (ptr_channel->topic) ? strdup (ptr_channel->topic) : strdup ("");
- new_channel_info->modes = (ptr_channel->modes) ? strdup (ptr_channel->modes) : strdup ("");
- new_channel_info->limit = ptr_channel->limit;
- new_channel_info->key = (ptr_channel->key) ? strdup (ptr_channel->key) : strdup ("");
- new_channel_info->nicks_count = ptr_channel->nicks_count;
-
- new_channel_info->prev_channel = last_channel_info;
- new_channel_info->next_channel = NULL;
- if (!channel_info)
- channel_info = new_channel_info;
- else
- last_channel_info->next_channel = new_channel_info;
- last_channel_info = new_channel_info;
- }
- }
-
- return channel_info;
- }
-
- return NULL;
-}
-
-/*
- * weechat_plugin_free_channel_info: free channel info struct list
- */
-
-void
-weechat_plugin_free_channel_info (t_weechat_plugin *plugin, t_plugin_channel_info *channel_info)
-{
- t_plugin_channel_info *new_channel_info;
-
- if (!plugin || !channel_info)
- return;
-
- while (channel_info)
- {
- if (channel_info->name)
- free (channel_info->name);
- if (channel_info->topic)
- free (channel_info->topic);
- if (channel_info->modes)
- free (channel_info->modes);
- if (channel_info->key)
- free (channel_info->key);
- new_channel_info = channel_info->next_channel;
- free (channel_info);
- channel_info = new_channel_info;
- }
-}
-
-/*
- * weechat_plugin_get_nick_info: get list of nick info from a server/channel
- * * WARNING: caller has to free structure
- * returned by this function after use
- */
-
-t_plugin_nick_info *
-weechat_plugin_get_nick_info (t_weechat_plugin *plugin, char *server, char *channel)
-{
- t_plugin_nick_info *nick_info, *last_nick_info, *new_nick_info;
- t_irc_nick *ptr_nick, *ptr_nicks;
- t_irc_channel *ptr_channel;
- t_irc_server *ptr_server;
-
- if (!plugin || !server || !server[0] || !channel || !channel[0])
- return NULL;
-
- ptr_server = irc_server_search (server);
- if (!ptr_server)
- return NULL;
-
- ptr_channel = irc_channel_search (ptr_server, channel);
- if (!ptr_channel)
- return NULL;
-
- ptr_nicks = ptr_channel->nicks;
-
- if (ptr_nicks)
- {
- nick_info = NULL;
- last_nick_info = NULL;
- for (ptr_nick = ptr_nicks; ptr_nick; ptr_nick = ptr_nick->next_nick)
- {
- new_nick_info = (t_plugin_nick_info *) malloc (sizeof (t_plugin_nick_info));
- if (new_nick_info)
- {
- new_nick_info->nick = (ptr_nick->nick) ? strdup (ptr_nick->nick) : strdup ("");
- new_nick_info->flags = ptr_nick->flags;
- new_nick_info->host = ptr_nick->host;
-
- new_nick_info->prev_nick = last_nick_info;
- new_nick_info->next_nick = NULL;
- if (!nick_info)
- nick_info = new_nick_info;
- else
- last_nick_info->next_nick = new_nick_info;
- last_nick_info = new_nick_info;
- }
- }
-
- return nick_info;
- }
-
- return NULL;
-}
-
-/*
- * weechat_plugin_free_nick_info: free nick info struct list
- */
-
-void
-weechat_plugin_free_nick_info (t_weechat_plugin *plugin, t_plugin_nick_info *nick_info)
-{
- t_plugin_nick_info *new_nick_info;
-
- if (!plugin || !nick_info)
- return;
-
- while (nick_info)
- {
- if (nick_info->nick)
- free (nick_info->nick);
- new_nick_info = nick_info->next_nick;
- free (nick_info);
- nick_info = new_nick_info;
- }
-}
-
-/*
- * weechat_plugin_input_color: add color in input buffer
- * if color < 0, input buffer is refresh
- * if start < 0 or length <= 0, color mask is reinit
- * otherwise, color is applied from start to start + length
- */
-
-void
-weechat_plugin_input_color (t_weechat_plugin *plugin, int color, int start, int length)
-{
- int i, begin, end;
- char *pos1, *pos2;
-
- if (!plugin
- || (!gui_current_window->buffer->has_input)
- || (gui_current_window->buffer->input_buffer_size == 0))
- return;
-
- if (color < 0)
- gui_input_draw (gui_current_window->buffer, 0);
- else
- {
- if ((start < 0) || (length <= 0))
- gui_input_init_color_mask (gui_current_window->buffer);
- else
- {
- if (local_utf8)
- {
- begin = start;
- end = start + length - 1;
- }
- else
- {
- pos1 = utf8_add_offset (gui_current_window->buffer->input_buffer,
- start);
- pos2 = pos1;
- for (i = 0; i < length; i++)
- pos2 = utf8_next_char (pos2);
- begin = pos1 - gui_current_window->buffer->input_buffer;
- end = begin + (pos2 - pos1) - 1;
- }
- color %= GUI_NUM_IRC_COLORS;
- for (i = begin; i <= end; i++)
- {
- gui_current_window->buffer->input_buffer_color_mask[i] =
- '0' + color;
- }
- }
- }
-}
-
-/*
- * weechat_plugin_get_irc_color: get number of IRC color with name
- */
-
-int
-weechat_plugin_get_irc_color (t_weechat_plugin *plugin, char *color_name)
-{
- int i;
-
- if (!plugin)
- return -1;
-
- for (i = 0; i < GUI_NUM_IRC_COLORS; i++)
- {
- if (strcasecmp (plugins_irc_colors[i].name, color_name) == 0)
- return i;
- }
-
- /* color not found */
- return -1;
-}
-
-/*
- * weechat_plugin_get_window_info: get list of window info
- * WARNING: caller has to free structure
- * returned by this function after use
- */
-
-t_plugin_window_info *
-weechat_plugin_get_window_info (t_weechat_plugin *plugin)
-{
- t_plugin_window_info *window_info, *last_window_info, *new_window_info;
- t_gui_window *ptr_win;
-
- if (!plugin)
- return NULL;
-
- if (gui_windows)
- {
- window_info = NULL;
- last_window_info = NULL;
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
- {
- new_window_info = (t_plugin_window_info *) malloc (sizeof (t_plugin_window_info));
- if (new_window_info)
- {
- new_window_info->win_x = ptr_win->win_x;
- new_window_info->win_y = ptr_win->win_y;
- new_window_info->win_width = ptr_win->win_width;
- new_window_info->win_height = ptr_win->win_height;
- new_window_info->win_width_pct = ptr_win->win_width_pct;
- new_window_info->win_height_pct = ptr_win->win_height_pct;
- new_window_info->num_buffer = (ptr_win->buffer) ? ptr_win->buffer->number : 0;
-
- new_window_info->prev_window = last_window_info;
- new_window_info->next_window = NULL;
- if (!window_info)
- window_info = new_window_info;
- else
- last_window_info->next_window = new_window_info;
- last_window_info = new_window_info;
- }
- }
-
- return window_info;
- }
-
- return NULL;
-}
-
-/*
- * weechat_plugin_free_window_info: free window info struct list
- */
-
-void
-weechat_plugin_free_window_info (t_weechat_plugin *plugin, t_plugin_window_info *window_info)
-{
- t_plugin_window_info *new_window_info;
-
- if (!plugin || !window_info)
- return;
-
- while (window_info)
- {
- new_window_info = window_info->next_window;
- free (window_info);
- window_info = new_window_info;
- }
-}
-
-/*
- * weechat_plugin_get_buffer_info: get list of buffer info
- * WARNING: caller has to free structure
- * returned by this function after use
- */
-
-t_plugin_buffer_info *
-weechat_plugin_get_buffer_info (t_weechat_plugin *plugin)
-{
- t_plugin_buffer_info *buffer_info, *last_buffer_info, *new_buffer_info;
- t_gui_buffer *ptr_buffer;
-
- if (!plugin)
- return NULL;
-
- if (gui_buffers)
- {
- buffer_info = NULL;
- last_buffer_info = NULL;
- for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer)
- {
- new_buffer_info = (t_plugin_buffer_info *) malloc (sizeof (t_plugin_buffer_info));
- if (new_buffer_info)
- {
- new_buffer_info->type = ptr_buffer->type;
- new_buffer_info->number = ptr_buffer->number;
- new_buffer_info->num_displayed = ptr_buffer->num_displayed;
- new_buffer_info->server_name = (GUI_SERVER(ptr_buffer)) ? strdup (GUI_SERVER(ptr_buffer)->name) : NULL;
- new_buffer_info->channel_name = (GUI_CHANNEL(ptr_buffer)) ? strdup (GUI_CHANNEL(ptr_buffer)->name) : NULL;
- new_buffer_info->notify_level = ptr_buffer->notify_level;
- new_buffer_info->log_filename = (ptr_buffer->log_filename) ? strdup (ptr_buffer->log_filename) : NULL;
-
- new_buffer_info->prev_buffer = last_buffer_info;
- new_buffer_info->next_buffer = NULL;
- if (!buffer_info)
- buffer_info = new_buffer_info;
- else
- last_buffer_info->next_buffer = new_buffer_info;
- last_buffer_info = new_buffer_info;
- }
- }
-
- return buffer_info;
- }
-
- return NULL;
-}
-
-/*
- * weechat_plugin_free_buffer_info: free buffer info struct list
- */
-
-void
-weechat_plugin_free_buffer_info (t_weechat_plugin *plugin, t_plugin_buffer_info *buffer_info)
-{
- t_plugin_buffer_info *new_buffer_info;
-
- if (!plugin || !buffer_info)
- return;
-
- while (buffer_info)
- {
- if (buffer_info->server_name)
- free (buffer_info->server_name);
- if (buffer_info->channel_name)
- free (buffer_info->channel_name);
- if (buffer_info->log_filename)
- free (buffer_info->log_filename);
- new_buffer_info = buffer_info->next_buffer;
- free (buffer_info);
- buffer_info = new_buffer_info;
- }
-}
-
-/*
- * weechat_plugin_get_buffer_data: get buffer content
- * WARNING: caller has to free structure
- * returned by this function after use
- */
-
-t_plugin_buffer_line *
-weechat_plugin_get_buffer_data (t_weechat_plugin *plugin, char *server, char *channel)
-{
- t_gui_buffer *ptr_buffer;
- t_plugin_buffer_line *buffer_line, *last_buffer_line, *new_buffer_line;
- t_gui_line *ptr_line;
- char *data1, *data2;
-
- if (!plugin)
- return NULL;
-
- ptr_buffer = gui_buffer_search (server, channel);
-
- if (!ptr_buffer)
- return NULL;
-
- buffer_line = NULL;
- last_buffer_line = NULL;
- for (ptr_line = ptr_buffer->last_line; ptr_line;
- ptr_line = ptr_line->prev_line)
- {
- new_buffer_line = (t_plugin_buffer_line *) malloc (sizeof (t_plugin_buffer_line));
- if (new_buffer_line)
- {
- new_buffer_line->date = ptr_line->date;
- new_buffer_line->nick = (ptr_line->nick) ? strdup (ptr_line->nick) : NULL;
- if (ptr_line->data)
- {
- data1 = (char *) gui_color_decode ((unsigned char *)(ptr_line->data + ptr_line->ofs_start_message), 0, 0);
- data2 = (data1) ? weechat_iconv_from_internal (plugin->charset, data1) : NULL;
- if (data2)
- new_buffer_line->data = data2;
- else
- new_buffer_line->data = ptr_line->data;
- if (data1)
- free (data1);
- }
- else
- new_buffer_line->data = NULL;
-
- new_buffer_line->prev_line = last_buffer_line;
- new_buffer_line->next_line = NULL;
- if (!buffer_line)
- buffer_line = new_buffer_line;
- else
- last_buffer_line->next_line = new_buffer_line;
- last_buffer_line = new_buffer_line;
- }
- }
-
- return buffer_line;
-}
-
-/*
- * weechat_plugin_free_buffer_data: free buffer data (lines) struct list
- */
-
-void
-weechat_plugin_free_buffer_data (t_weechat_plugin *plugin, t_plugin_buffer_line *buffer_line)
-{
- t_plugin_buffer_line *new_buffer_line;
-
- if (!plugin || !buffer_line)
- return;
-
- while (buffer_line)
- {
- if (buffer_line->nick)
- free (buffer_line->nick);
- if (buffer_line->data)
- free (buffer_line->data);
- new_buffer_line = buffer_line->next_line;
- free (buffer_line);
- buffer_line = new_buffer_line;
- }
-}
-
-/*
- * weechat_plugin_set_charset: set plugin charset
- */
-
-void
-weechat_plugin_set_charset (t_weechat_plugin *plugin, char *charset)
-{
- if (!plugin || !charset)
- return;
-
- if (plugin->charset)
- free (plugin->charset);
-
- plugin->charset = (charset) ? strdup (charset) : NULL;
-}
-
-/*
- * weechat_plugin_iconv_to_internal: encode string from a charset to WeeChat
- * internal charset
- */
-
-char *
-weechat_plugin_iconv_to_internal (t_weechat_plugin *plugin,
- char *charset, char *string)
-{
- if (!plugin || !string)
- return NULL;
-
- return weechat_iconv_to_internal (charset, string);
-}
-
-/*
- * weechat_plugin_iconv_from_internal: encode string from WeeChat internal
- * charset to another
- */
-
-char *
-weechat_plugin_iconv_from_internal (t_weechat_plugin *plugin,
- char *charset, char *string)
-{
- if (!plugin || !string)
- return NULL;
-
- return weechat_iconv_from_internal (charset, string);
-}
diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c
deleted file mode 100644
index 58b5bb39a..000000000
--- a/src/plugins/plugins.c
+++ /dev/null
@@ -1,1566 +0,0 @@
-/*
- * Copyright (c) 2003-2007 by FlashCode <flashcode@flashtux.org>
- * See README for License detail, AUTHORS for developers list.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* plugins.c: manages WeeChat plugins (dynamic C libraries) */
-
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <errno.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdarg.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <dlfcn.h>
-
-#include "../common/weechat.h"
-#include "plugins.h"
-#include "plugins-config.h"
-#include "../common/command.h"
-#include "../common/log.h"
-#include "../common/util.h"
-#include "../common/weeconfig.h"
-#include "../protocols/irc/irc.h"
-#include "../gui/gui.h"
-
-
-t_weechat_plugin *weechat_plugins = NULL;
-t_weechat_plugin *last_weechat_plugin = NULL;
-
-t_plugin_irc_color plugins_irc_colors[GUI_NUM_IRC_COLORS] =
-{ { /* 0 */ WEECHAT_IRC_COLOR_WHITE, "white" },
- { /* 1 */ WEECHAT_IRC_COLOR_BLACK, "black" },
- { /* 2 */ WEECHAT_IRC_COLOR_BLUE, "blue" },
- { /* 3 */ WEECHAT_IRC_COLOR_GREEN, "green" },
- { /* 4 */ WEECHAT_IRC_COLOR_LIGHTRED, "lightred" },
- { /* 5 */ WEECHAT_IRC_COLOR_RED, "red" },
- { /* 6 */ WEECHAT_IRC_COLOR_MAGENTA, "magenta" },
- { /* 7 */ WEECHAT_IRC_COLOR_BROWN, "brown" },
- { /* 8 */ WEECHAT_IRC_COLOR_YELLOW, "yellow" },
- { /* 9 */ WEECHAT_IRC_COLOR_LIGHTGREEN, "lightgreen" },
- { /* 10 */ WEECHAT_IRC_COLOR_CYAN, "cyan" },
- { /* 11 */ WEECHAT_IRC_COLOR_LIGHTCYAN, "lightcyan" },
- { /* 12 */ WEECHAT_IRC_COLOR_LIGHTBLUE, "lightblue" },
- { /* 13 */ WEECHAT_IRC_COLOR_LIGHTMAGENTA, "lightmagenta" },
- { /* 14 */ WEECHAT_IRC_COLOR_GRAY, "gray" },
- { /* 15 */ WEECHAT_IRC_COLOR_LIGHTGRAY, "lightgray" }};
-
-
-/*
- * plugin_find_server_channel: find server/channel for command execution
- */
-
-int
-plugin_find_server_channel (char *server, char *channel,
- t_irc_server **ptr_server,
- t_irc_channel **ptr_channel)
-{
- (*ptr_server) = NULL;
- (*ptr_channel) = NULL;
-
- /* nothing given => return current server/channel */
- if ((!server || !server[0]) && (!channel || !channel[0]))
- {
- (*ptr_server) = GUI_SERVER(gui_current_window->buffer);
- (*ptr_channel) = (GUI_BUFFER_IS_CHANNEL(gui_current_window->buffer) ||
- GUI_BUFFER_IS_PRIVATE(gui_current_window->buffer)) ?
- GUI_CHANNEL(gui_current_window->buffer) : NULL;
- }
- else
- {
- if (server && server[0])
- {
- (*ptr_server) = irc_server_search (server);
- if (!(*ptr_server))
- return -1;
- }
- else
- {
- (*ptr_server) = GUI_SERVER(gui_current_window->buffer);
- if (!(*ptr_server))
- (*ptr_server) = GUI_SERVER(gui_buffers);
- }
-
- if (channel && channel[0])
- {
- if ((*ptr_server))
- (*ptr_channel) = irc_channel_search ((*ptr_server), channel);
- if (!(*ptr_channel))
- return -1;
- }
- }
- return 0;
-}
-
-/*
- * plugin_exec_on_files: find files in a directory and execute a
- * function on each file
- */
-
-void
-plugin_exec_on_files (t_weechat_plugin *plugin, char *directory,
- int (*callback)(t_weechat_plugin *, char *))
-{
- char complete_filename[1024];
- DIR *dir;
- struct dirent *entry;
- struct stat statbuf;
-
- dir = opendir (directory);
- if (dir)
- {
- while ((entry = readdir (dir)))
- {
- snprintf (complete_filename, sizeof (complete_filename) - 1,
- "%s/%s", directory, entry->d_name);
- lstat (complete_filename, &statbuf);
- if (!S_ISDIR(statbuf.st_mode))
- {
- (int) (*callback) (plugin, complete_filename);
- }
- }
- closedir (dir);
- }
-}
-
-/*
- * plugin_search: search a plugin by name
- */
-
-t_weechat_plugin *
-plugin_search (char *name)
-{
- t_weechat_plugin *ptr_plugin;
-
- for (ptr_plugin = weechat_plugins; ptr_plugin;
- ptr_plugin = ptr_plugin->next_plugin)
- {
- if (ascii_strcasecmp (ptr_plugin->name, name) == 0)
- return ptr_plugin;
- }
-
- /* plugin not found */
- return NULL;
-}
-
-/*
- * plugin_cmd_handler_search: search a plugin command handler
- * return: pointer to handler, NULL if not found
- */
-
-t_plugin_handler *
-plugin_cmd_handler_search (char *command)
-{
- t_weechat_plugin *ptr_plugin;
- t_plugin_handler *ptr_handler;
-
- for (ptr_plugin = weechat_plugins; ptr_plugin;
- ptr_plugin = ptr_plugin->next_plugin)
- {
- for (ptr_handler = ptr_plugin->handlers;
- ptr_handler; ptr_handler = ptr_handler->next_handler)
- {
- if ((ptr_handler->type == PLUGIN_HANDLER_COMMAND)
- && (ascii_strcasecmp (ptr_handler->command, command) == 0))
- return ptr_handler;
- }
- }
-
- /* command handler not found */
- return NULL;
-}
-
-/*
- * plugin_msg_handler_add: add a message handler
- * arguments:
- * 1. the plugin pointer
- * 2. the IRC command
- * 3. the handler function
- * 4. handler args: a string given to
- * handler when called (used by scripts)
- * 5. handler pointer: a pointer given to
- * handler when called (used by scripts)
- */
-
-t_plugin_handler *
-plugin_msg_handler_add (t_weechat_plugin *plugin, char *irc_command,
- t_plugin_handler_func *handler_func,
- char *handler_args, void *handler_pointer)
-{
- t_plugin_handler *new_handler;
-
- new_handler = (t_plugin_handler *)malloc (sizeof (t_plugin_handler));
- if (new_handler)
- {
- new_handler->type = PLUGIN_HANDLER_MESSAGE;
- new_handler->irc_command = strdup (irc_command);
- new_handler->command = NULL;
- new_handler->description = NULL;
- new_handler->arguments = NULL;
- new_handler->arguments_description = NULL;
- new_handler->completion_template = NULL;
- new_handler->interval = 0;
- new_handler->remaining = 0;
- new_handler->event = NULL;
- new_handler->handler = handler_func;
- new_handler->handler_args = (handler_args) ? strdup (handler_args) : NULL;
- new_handler->handler_pointer = handler_pointer;
- new_handler->running = 0;
-
- /* add new handler to list */
- new_handler->prev_handler = plugin->last_handler;
- new_handler->next_handler = NULL;
- if (plugin->handlers)
- (plugin->last_handler)->next_handler = new_handler;
- else
- plugin->handlers = new_handler;
- plugin->last_handler = new_handler;
- }
- else
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL,
- _("%s plugin %s: unable to add handler for IRC command \"%s\" (not enough memory)\n"),
- WEECHAT_ERROR, plugin->name, irc_command);
- return NULL;
- }
- return new_handler;
-}
-
-/*
- * plugin_cmd_handler_add: add a command handler
- * arguments:
- * 1. the plugin pointer
- * 2. the WeeChat command
- * 3. command description (for /help)
- * 4. command arguments (for /help)
- * 5. command args description (for /help)
- * 6. completion template
- * 7. the handler function
- * 8. handler args: a string given to
- * handler when called (used by scripts)
- * 9. handler pointer: a pointer given to
- * handler when called (used by scripts)
- */
-
-t_plugin_handler *
-plugin_cmd_handler_add (t_weechat_plugin *plugin, char *command,
- char *description, char *arguments,
- char *arguments_description,
- char *completion_template,
- t_plugin_handler_func *handler_func,
- char *handler_args, void *handler_pointer)
-{
- t_plugin_handler *new_handler;
-
- if (plugin_cmd_handler_search (command))
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL,
- _("%s plugin %s: unable to add handler for \"%s\" command "
- "(already exists)\n"),
- WEECHAT_ERROR, plugin->name, command);
- return NULL;
- }
-
- if (ascii_strcasecmp (command, "builtin") == 0)
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL,
- _("%s plugin %s: unable to add handler for \"%s\" command "
- "(forbidden)\n"),
- WEECHAT_ERROR, plugin->name, command);
- return NULL;
- }
-
- new_handler = (t_plugin_handler *)malloc (sizeof (t_plugin_handler));
- if (new_handler)
- {
- new_handler->type = PLUGIN_HANDLER_COMMAND;
- new_handler->irc_command = NULL;
- new_handler->command = strdup (command);
- new_handler->description = (description) ? strdup (description) : NULL;
- new_handler->arguments = (arguments) ? strdup (arguments) : NULL;
- new_handler->arguments_description = (arguments_description) ? strdup (arguments_description) : NULL;
- new_handler->completion_template = (completion_template) ? strdup (completion_template) : strdup ("");
- new_handler->interval = 0;
- new_handler->remaining = 0;
- new_handler->event = NULL;
- new_handler->handler = handler_func;
- new_handler->handler_args = (handler_args) ? strdup (handler_args) : NULL;
- new_handler->handler_pointer = handler_pointer;
- new_handler->running = 0;
-
- /* add new handler to list */
- new_handler->prev_handler = plugin->last_handler;
- new_handler->next_handler = NULL;
- if (plugin->handlers)
- (plugin->last_handler)->next_handler = new_handler;
- else
- plugin->handlers = new_handler;
- plugin->last_handler = new_handler;
-
- /* add command to WeeChat commands list */
- if (!weelist_search (index_commands, command))
- weelist_add (&index_commands, &last_index_command, command,
- WEELIST_POS_SORT);
- }
- else
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL,
- _("%s plugin %s: unable to add handler for \"%s\" command (not enough memory)\n"),
- WEECHAT_ERROR, plugin->name, command);
- return NULL;
- }
- return new_handler;
-}
-
-/*
- * plugin_timer_handler_add: add a timer handler
- * arguments:
- * 1. the plugin pointer
- * 2. the interval between two calls
- * 3. the handler function
- * 4. handler args: a string given to
- * handler when called (used by scripts)
- * 5. handler pointer: a pointer given to
- * handler when called (used by scripts)
- */
-
-t_plugin_handler *
-plugin_timer_handler_add (t_weechat_plugin *plugin, int interval,
- t_plugin_handler_func *handler_func,
- char *handler_args, void *handler_pointer)
-{
- t_plugin_handler *new_handler;
-
- new_handler = (t_plugin_handler *)malloc (sizeof (t_plugin_handler));
- if (new_handler)
- {
- new_handler->type = PLUGIN_HANDLER_TIMER;
- new_handler->irc_command = NULL;
- new_handler->command = NULL;
- new_handler->description = NULL;
- new_handler->arguments = NULL;
- new_handler->arguments_description = NULL;
- new_handler->completion_template = NULL;
- new_handler->interval = interval;
- new_handler->remaining = interval;
- new_handler->event = NULL;
- new_handler->handler = handler_func;
- new_handler->handler_args = (handler_args) ? strdup (handler_args) : NULL;
- new_handler->handler_pointer = handler_pointer;
- new_handler->running = 0;
-
- /* add new handler to list */
- new_handler->prev_handler = plugin->last_handler;
- new_handler->next_handler = NULL;
- if (plugin->handlers)
- (plugin->last_handler)->next_handler = new_handler;
- else
- plugin->handlers = new_handler;
- plugin->last_handler = new_handler;
- }
- else
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL,
- _("%s plugin %s: unable to add timer handler (not enough memory)\n"),
- WEECHAT_ERROR, plugin->name);
- return NULL;
- }
- return new_handler;
-}
-
-/*
- * plugin_keyboard_handler_add: add a keyboard handler
- * arguments:
- * 1. the plugin pointer
- * 2. the handler function
- * 3. handler args: a string given to
- * handler when called (used by scripts)
- * 4. handler pointer: a pointer given to
- * handler when called (used by scripts)
- */
-
-t_plugin_handler *
-plugin_keyboard_handler_add (t_weechat_plugin *plugin,
- t_plugin_handler_func *handler_func,
- char *handler_args, void *handler_pointer)
-{
- t_plugin_handler *new_handler;
-
- new_handler = (t_plugin_handler *)malloc (sizeof (t_plugin_handler));
- if (new_handler)
- {
- new_handler->type = PLUGIN_HANDLER_KEYBOARD;
- new_handler->irc_command = NULL;
- new_handler->command = NULL;
- new_handler->description = NULL;
- new_handler->arguments = NULL;
- new_handler->arguments_description = NULL;
- new_handler->completion_template = NULL;
- new_handler->interval = 0;
- new_handler->remaining = 0;
- new_handler->event = NULL;
- new_handler->handler = handler_func;
- new_handler->handler_args = (handler_args) ? strdup (handler_args) : NULL;
- new_handler->handler_pointer = handler_pointer;
- new_handler->running = 0;
-
- /* add new handler to list */
- new_handler->prev_handler = plugin->last_handler;
- new_handler->next_handler = NULL;
- if (plugin->handlers)
- (plugin->last_handler)->next_handler = new_handler;
- else
- plugin->handlers = new_handler;
- plugin->last_handler = new_handler;
- }
- else
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL,
- _("%s plugin %s: unable to add keyboard handler (not enough memory)\n"),
- WEECHAT_ERROR, plugin->name);
- return NULL;
- }
- return new_handler;
-}
-
-/*
- * plugin_event_handler_add: add an event handler
- * arguments:
- * 1. the plugin pointer
- * 2. the event to catch
- * 3. the handler function
- * 4. handler args: a string given to
- * handler when called (used by scripts)
- * 5. handler pointer: a pointer given to
- * handler when called (used by scripts)
- */
-
-t_plugin_handler *
-plugin_event_handler_add (t_weechat_plugin *plugin, char *event,
- t_plugin_handler_func *handler_func,
- char *handler_args, void *handler_pointer)
-{
- t_plugin_handler *new_handler;
-
- new_handler = (t_plugin_handler *)malloc (sizeof (t_plugin_handler));
- if (new_handler)
- {
- new_handler->type = PLUGIN_HANDLER_EVENT;
- new_handler->irc_command = NULL;
- new_handler->command = NULL;
- new_handler->description = NULL;
- new_handler->arguments = NULL;
- new_handler->arguments_description = NULL;
- new_handler->completion_template = NULL;
- new_handler->interval = 0;
- new_handler->remaining = 0;
- new_handler->event = strdup (event);
- new_handler->handler = handler_func;
- new_handler->handler_args = (handler_args) ? strdup (handler_args) : NULL;
- new_handler->handler_pointer = handler_pointer;
- new_handler->running = 0;
-
- /* add new handler to list */
- new_handler->prev_handler = plugin->last_handler;
- new_handler->next_handler = NULL;
- if (plugin->handlers)
- (plugin->last_handler)->next_handler = new_handler;
- else
- plugin->handlers = new_handler;
- plugin->last_handler = new_handler;
- }
- else
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL,
- _("%s plugin %s: unable to add event handler (not enough memory)\n"),
- WEECHAT_ERROR, plugin->name);
- return NULL;
- }
- return new_handler;
-}
-
-/*
- * plugin_msg_handler_exec: execute a message handler
- * return: code for informing WeeChat whether message
- * should be ignored or not
- */
-
-int
-plugin_msg_handler_exec (char *server, char *irc_command, char *irc_message)
-{
- t_weechat_plugin *ptr_plugin;
- t_plugin_handler *ptr_handler;
- int return_code, final_return_code;
- char *argv[3] = { NULL, NULL, NULL };
-
- argv[0] = server;
- argv[1] = irc_command;
- argv[2] = irc_message;
-
- final_return_code = PLUGIN_RC_OK;
-
- for (ptr_plugin = weechat_plugins; ptr_plugin;
- ptr_plugin = ptr_plugin->next_plugin)
- {
- for (ptr_handler = ptr_plugin->handlers;
- ptr_handler; ptr_handler = ptr_handler->next_handler)
- {
- if ((ptr_handler->type == PLUGIN_HANDLER_MESSAGE)
- && (((ascii_strcasecmp (ptr_handler->irc_command, "*") == 0)
- && (ascii_strncasecmp (irc_command, "weechat_", 8) != 0))
- || (ascii_strcasecmp (ptr_handler->irc_command, irc_command) == 0)))
- {
- if (ptr_handler->running == 0)
- {
- ptr_handler->running = 1;
- return_code = ((int) (ptr_handler->handler) (ptr_plugin,
- 3, argv,
- ptr_handler->handler_args,
- ptr_handler->handler_pointer));
- ptr_handler->running = 0;
-
- if (return_code >= 0)
- {
- if (return_code & PLUGIN_RC_OK_IGNORE_WEECHAT)
- final_return_code = PLUGIN_RC_OK_IGNORE_WEECHAT;
- if (return_code & PLUGIN_RC_OK_IGNORE_PLUGINS)
- return final_return_code;
- if (return_code & PLUGIN_RC_OK_WITH_HIGHLIGHT)
- final_return_code = PLUGIN_RC_OK_WITH_HIGHLIGHT;
- }
- }
- }
- }
- }
-
- return final_return_code;
-}
-
-/*
- * plugin_cmd_handler_exec: execute a command handler
- * return: 1 if handler executed, 0 if failed,
- * -1 if no handler found
- */
-
-int
-plugin_cmd_handler_exec (char *server, char *command, char *arguments)
-{
- t_weechat_plugin *ptr_plugin;
- t_plugin_handler *ptr_handler;
- int return_code;
- char empty_arg[1] = { '\0' };
- char *argv[3] = { NULL, NULL, NULL };
-
- argv[0] = server;
- argv[1] = command;
- argv[2] = (arguments) ? arguments : empty_arg;
-
- for (ptr_plugin = weechat_plugins; ptr_plugin;
- ptr_plugin = ptr_plugin->next_plugin)
- {
- for (ptr_handler = ptr_plugin->handlers;
- ptr_handler; ptr_handler = ptr_handler->next_handler)
- {
- if ((ptr_handler->type == PLUGIN_HANDLER_COMMAND)
- && (ascii_strcasecmp (ptr_handler->command, command) == 0))
- {
- if (ptr_handler->running == 0)
- {
- ptr_handler->running = 1;
- return_code = (int) (ptr_handler->handler) (ptr_plugin,
- 3, argv,
- ptr_handler->handler_args,
- ptr_handler->handler_pointer);
- ptr_handler->running = 0;
- return (return_code == PLUGIN_RC_KO) ? 0 : 1;
- }
- }
- }
- }
-
- return -1;
-}
-
-/*
- * plugin_timer_handler_exec: check timer handlers and execute functions if needed
- * return: PLUGIN_RC_OK if all ok
- * PLUGIN_RC_KO if at least one handler failed
- */
-
-int
-plugin_timer_handler_exec ()
-{
- t_weechat_plugin *ptr_plugin;
- t_plugin_handler *ptr_handler;
- int return_code, final_return_code;
-
- final_return_code = PLUGIN_RC_OK;
-
- for (ptr_plugin = weechat_plugins; ptr_plugin;
- ptr_plugin = ptr_plugin->next_plugin)
- {
- for (ptr_handler = ptr_plugin->handlers;
- ptr_handler; ptr_handler = ptr_handler->next_handler)
- {
- if (ptr_handler->type == PLUGIN_HANDLER_TIMER)
- {
- ptr_handler->remaining--;
- if (ptr_handler->remaining <= 0)
- {
- return_code = ((int) (ptr_handler->handler) (ptr_plugin,
- 0, NULL,
- ptr_handler->handler_args,
- ptr_handler->handler_pointer));
- ptr_handler->remaining = ptr_handler->interval;
- if (return_code == PLUGIN_RC_KO)
- final_return_code = PLUGIN_RC_KO;
- }
- }
- }
- }
-
- return final_return_code;
-}
-
-/*
- * plugin_keyboard_handler_exec: execute all keyboard handlers
- * return: PLUGIN_RC_OK if all ok
- * PLUGIN_RC_KO if at least one handler failed
- */
-
-int
-plugin_keyboard_handler_exec (char *key, char *input_before, char *input_after)
-{
- t_weechat_plugin *ptr_plugin;
- t_plugin_handler *ptr_handler;
- int return_code, final_return_code;
- char *argv[3] = { NULL, NULL, NULL };
-
- argv[0] = key;
- argv[1] = input_before;
- argv[2] = input_after;
-
- final_return_code = PLUGIN_RC_OK;
-
- for (ptr_plugin = weechat_plugins; ptr_plugin;
- ptr_plugin = ptr_plugin->next_plugin)
- {
- for (ptr_handler = ptr_plugin->handlers;
- ptr_handler; ptr_handler = ptr_handler->next_handler)
- {
- if (ptr_handler->type == PLUGIN_HANDLER_KEYBOARD)
- {
- return_code = ((int) (ptr_handler->handler) (ptr_plugin,
- 3, argv,
- ptr_handler->handler_args,
- ptr_handler->handler_pointer));
- if (return_code == PLUGIN_RC_KO)
- final_return_code = PLUGIN_RC_KO;
- }
- }
- }
-
- return final_return_code;
-}
-
-/*
- * plugin_event_handler_exec: execute an event handler
- * return: PLUGIN_RC_OK if all ok
- * PLUGIN_RC_KO if at least one handler failed
- */
-
-int
-plugin_event_handler_exec (char *event, int argc, char **argv)
-{
- t_weechat_plugin *ptr_plugin;
- t_plugin_handler *ptr_handler;
- int return_code, final_return_code;
-
- final_return_code = PLUGIN_RC_OK;
-
- for (ptr_plugin = weechat_plugins; ptr_plugin;
- ptr_plugin = ptr_plugin->next_plugin)
- {
- for (ptr_handler = ptr_plugin->handlers;
- ptr_handler; ptr_handler = ptr_handler->next_handler)
- {
- if ((ptr_handler->type == PLUGIN_HANDLER_EVENT)
- && (ascii_strcasecmp (ptr_handler->event, event) == 0))
- {
- return_code = ((int) (ptr_handler->handler) (ptr_plugin,
- argc, argv,
- ptr_handler->handler_args,
- ptr_handler->handler_pointer));
- if (return_code == PLUGIN_RC_KO)
- final_return_code = PLUGIN_RC_KO;
- }
- }
- }
-
- return final_return_code;
-}
-
-/*
- * plugin_handler_remove: remove a handler for a plugin
- */
-
-void
-plugin_handler_remove (t_weechat_plugin *plugin,
- t_plugin_handler *handler)
-{
- t_plugin_handler *new_handlers;
-
- /* remove handler from list */
- if (plugin->last_handler == handler)
- plugin->last_handler = handler->prev_handler;
- if (handler->prev_handler)
- {
- (handler->prev_handler)->next_handler = handler->next_handler;
- new_handlers = plugin->handlers;
- }
- else
- new_handlers = handler->next_handler;
-
- if (handler->next_handler)
- (handler->next_handler)->prev_handler = handler->prev_handler;
-
- /* remove command from WeeChat command list, if command handler */
- if ((handler->type == PLUGIN_HANDLER_COMMAND)
- && (!command_used_by_weechat (handler->command)))
- weelist_remove (&index_commands, &last_index_command,
- weelist_search (index_commands, handler->command));
-
- /* free data */
- if (handler->irc_command)
- free (handler->irc_command);
- if (handler->command)
- free (handler->command);
- if (handler->description)
- free (handler->description);
- if (handler->arguments)
- free (handler->arguments);
- if (handler->arguments_description)
- free (handler->arguments_description);
- if (handler->event)
- free (handler->event);
- if (handler->handler_args)
- free (handler->handler_args);
-
- plugin->handlers = new_handlers;
-}
-
-/*
- * plugin_handler_remove_all: remove all handlers for a plugin
- */
-
-void
-plugin_handler_remove_all (t_weechat_plugin *plugin)
-{
- while (plugin->handlers)
- plugin_handler_remove (plugin, plugin->handlers);
-}
-
-/*
- * plugin_modifier_add: add a IRC handler
- * arguments:
- * 1. the plugin pointer
- * 2. type of modifier
- * 3. message ("*" means all)
- * 4. the modifier function
- * 5. modifier args: a string given to
- * modifier when called (used by scripts)
- * 6. modifier pointer: a pointer given to
- * modifier when called (used by scripts)
- */
-
-t_plugin_modifier *
-plugin_modifier_add (t_weechat_plugin *plugin, char *type, char *command,
- t_plugin_modifier_func *modifier_func,
- char *modifier_args, void *modifier_pointer)
-{
- t_plugin_modifier *new_modifier;
- int type_int;
-
- if (ascii_strcasecmp (type, PLUGIN_MODIFIER_IRC_IN_STR) == 0)
- type_int = PLUGIN_MODIFIER_IRC_IN;
- else if (ascii_strcasecmp (type, PLUGIN_MODIFIER_IRC_USER_STR) == 0)
- type_int = PLUGIN_MODIFIER_IRC_USER;
- else if (ascii_strcasecmp (type, PLUGIN_MODIFIER_IRC_OUT_STR) == 0)
- type_int = PLUGIN_MODIFIER_IRC_OUT;
- else
- return NULL;
-
- new_modifier = (t_plugin_modifier *)malloc (sizeof (t_plugin_modifier));
- if (new_modifier)
- {
- new_modifier->type = type_int;
- new_modifier->command = (command && command[0]) ?
- strdup (command) : strdup ("*");
- new_modifier->modifier = modifier_func;
- new_modifier->modifier_args = (modifier_args) ? strdup (modifier_args) : NULL;
- new_modifier->modifier_pointer = modifier_pointer;
- new_modifier->running = 0;
-
- /* add new modifier to list */
- new_modifier->prev_modifier = plugin->last_modifier;
- new_modifier->next_modifier = NULL;
- if (plugin->modifiers)
- (plugin->last_modifier)->next_modifier = new_modifier;
- else
- plugin->modifiers = new_modifier;
- plugin->last_modifier = new_modifier;
- }
- else
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL,
- _("%s plugin %s: unable to add modifier (not enough memory)\n"),
- WEECHAT_ERROR, plugin->name);
- return NULL;
- }
- return new_modifier;
-}
-
-/*
- * plugin_modifier_exec: execute a modifier
- * return: NULL if no modifier was applied on message
- * "" (empty string) if message has been dropped by a modifier
- * other string if message has been modified
- */
-
-char *
-plugin_modifier_exec (t_plugin_modifier_type type,
- char *server, char *message)
-{
- t_weechat_plugin *ptr_plugin;
- t_plugin_modifier *ptr_modifier;
- char *argv[2] = { NULL, NULL };
- char *new_msg, *message_modified, *pos, *command;
- int length_command;
-
- argv[0] = server;
- argv[1] = message;
-
- command = NULL;
- length_command = 0;
- if ((type == PLUGIN_MODIFIER_IRC_IN) || (type == PLUGIN_MODIFIER_IRC_OUT))
- {
- /* look for command in message */
- if (message[0] == ':')
- {
- pos = strchr (message, ' ');
- if (pos)
- {
- while (pos[0] == ' ')
- pos++;
- command = pos;
- }
- }
- else
- command = message;
- if (command)
- {
- pos = strchr (command, ' ');
- if (pos)
- length_command = pos - command;
- else
- length_command = strlen (command);
- }
- }
-
- new_msg = NULL;
- message_modified = NULL;
-
- for (ptr_plugin = weechat_plugins; ptr_plugin;
- ptr_plugin = ptr_plugin->next_plugin)
- {
- for (ptr_modifier = ptr_plugin->modifiers;
- ptr_modifier; ptr_modifier = ptr_modifier->next_modifier)
- {
- if (ptr_modifier->type == type)
- {
- if (ptr_modifier->running == 0)
- {
- if (((type != PLUGIN_MODIFIER_IRC_IN) && (type != PLUGIN_MODIFIER_IRC_OUT))
- || (ascii_strcasecmp (ptr_modifier->command, "*") == 0)
- || (command && (ascii_strncasecmp (ptr_modifier->command, command, length_command) == 0)))
- {
- ptr_modifier->running = 1;
- new_msg = ((char *) (ptr_modifier->modifier) (ptr_plugin,
- 2, argv,
- ptr_modifier->modifier_args,
- ptr_modifier->modifier_pointer));
- ptr_modifier->running = 0;
-
- /* message dropped? */
- if (new_msg && !new_msg[0])
- return new_msg;
-
- /* new message => keep it as base for next modifier */
- if (new_msg)
- {
- /* free any new message allocated before by another modifier */
- if (argv[1] != message)
- free (argv[1]);
- argv[1] = new_msg;
- message_modified = new_msg;
- }
- }
- }
- }
- }
- }
-
- return message_modified;
-}
-
-/*
- * plugin_modifier_remove: remove a modifier for a plugin
- */
-
-void
-plugin_modifier_remove (t_weechat_plugin *plugin,
- t_plugin_modifier *modifier)
-{
- t_plugin_modifier *new_modifiers;
-
- /* remove modifier from list */
- if (plugin->last_modifier == modifier)
- plugin->last_modifier = modifier->prev_modifier;
- if (modifier->prev_modifier)
- {
- (modifier->prev_modifier)->next_modifier = modifier->next_modifier;
- new_modifiers = plugin->modifiers;
- }
- else
- new_modifiers = modifier->next_modifier;
-
- if (modifier->next_modifier)
- (modifier->next_modifier)->prev_modifier = modifier->prev_modifier;
-
- /* free data */
- if (modifier->command)
- free (modifier->command);
-
- plugin->modifiers = new_modifiers;
-}
-
-/*
- * plugin_modifier_remove_all: remove all modifiers for a plugin
- */
-
-void
-plugin_modifier_remove_all (t_weechat_plugin *plugin)
-{
- while (plugin->modifiers)
- plugin_modifier_remove (plugin, plugin->modifiers);
-}
-
-/*
- * plugin_search_full_name: search the full name of a file with a part of name
- * and look in WeeChat user's dir, then WeeChat global lib dir
- */
-
-char *
-plugin_search_full_name (char *filename)
-{
- char *name_with_ext, *final_name;
- int length;
- struct stat st;
-
- /* filename is already a full path */
- if (strchr (filename, '/') || strchr (filename, '\\'))
- return strdup (filename);
-
- length = strlen (filename) + 16;
- if (cfg_plugins_extension && cfg_plugins_extension[0])
- length += strlen (cfg_plugins_extension);
- name_with_ext = (char *)malloc (length);
- if (!name_with_ext)
- return strdup (filename);
- strcpy (name_with_ext, filename);
- if (!strchr (filename, '.')
- && cfg_plugins_extension && cfg_plugins_extension[0])
- strcat (name_with_ext, cfg_plugins_extension);
-
- /* try WeeChat user's dir */
- length = strlen (weechat_home) + strlen (name_with_ext) + 16;
- final_name = (char *)malloc (length);
- if (!final_name)
- {
- free (name_with_ext);
- return strdup (filename);
- }
- snprintf (final_name, length,
- "%s/plugins/%s", weechat_home, name_with_ext);
- if ((stat (final_name, &st) == 0) && (st.st_size > 0))
- {
- free (name_with_ext);
- return final_name;
- }
- free (final_name);
-
- /* try WeeChat global lib dir */
- length = strlen (WEECHAT_LIBDIR) + strlen (name_with_ext) + 16;
- final_name = (char *)malloc (length);
- if (!final_name)
- {
- free (name_with_ext);
- return strdup (filename);
- }
- snprintf (final_name, length,
- "%s/plugins/%s", WEECHAT_LIBDIR, name_with_ext);
- if ((stat (final_name, &st) == 0) && (st.st_size > 0))
- {
- free (name_with_ext);
- return final_name;
- }
- free (final_name);
-
- return name_with_ext;
-}
-
-/*
- * plugin_load: load a WeeChat plugin (a dynamic library)
- * return: pointer to new WeeChat plugin, NULL if error
- */
-
-t_weechat_plugin *
-plugin_load (char *filename)
-{
- char *full_name;
- void *handle;
- char *name, *description, *version, *charset;
- t_weechat_init_func *init_func;
- t_weechat_plugin *new_plugin;
-
- if (!filename)
- return NULL;
-
- full_name = plugin_search_full_name (filename);
-
- if (!full_name)
- return NULL;
-
- handle = dlopen (full_name, RTLD_GLOBAL | RTLD_NOW);
- if (!handle)
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL, _("%s unable to load plugin \"%s\": %s\n"),
- WEECHAT_ERROR, full_name, dlerror());
- free (full_name);
- return NULL;
- }
- /* look for plugin name */
- name = dlsym (handle, "plugin_name");
- if (!name)
- {
- dlclose (handle);
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL, _("%s symbol \"plugin_name\" not found in plugin \"%s\", failed to load\n"),
- WEECHAT_ERROR, full_name);
- free (full_name);
- return NULL;
- }
- /* check for plugin with same name */
- if (plugin_search (name))
- {
- dlclose (handle);
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL,
- _("%s unable to load plugin \"%s\": a plugin with "
- "same name already exists\n"),
- WEECHAT_ERROR, full_name);
- free (full_name);
- return NULL;
- }
- /* look for plugin description */
- description = dlsym (handle, "plugin_description");
- if (!description)
- {
- dlclose (handle);
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL, _("%s symbol \"plugin_description\" not found in plugin \"%s\", failed to load\n"),
- WEECHAT_ERROR, full_name);
- free (full_name);
- return NULL;
- }
- /* look for plugin version */
- version = dlsym (handle, "plugin_version");
- if (!version)
- {
- dlclose (handle);
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL, _("%s symbol \"plugin_version\" not found in plugin \"%s\", failed to load\n"),
- WEECHAT_ERROR, full_name);
- free (full_name);
- return NULL;
- }
- /* look for plugin charset (optional) */
- charset = dlsym (handle, "plugin_charset");
- /* look for plugin init function */
- init_func = dlsym (handle, "weechat_plugin_init");
- if (!init_func)
- {
- dlclose (handle);
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL, _("%s function \"weechat_plugin_init\" not found in plugin \"%s\", failed to load\n"),
- WEECHAT_ERROR, full_name);
- free (full_name);
- return NULL;
- }
-
- /* create new plugin */
- new_plugin = (t_weechat_plugin *)malloc (sizeof (t_weechat_plugin));
- if (new_plugin)
- {
- /* variables */
- new_plugin->filename = strdup (full_name);
- new_plugin->handle = handle;
- new_plugin->name = strdup (name);
- new_plugin->description = strdup (description);
- new_plugin->version = strdup (version);
- new_plugin->charset = (charset) ? strdup (charset) : NULL;
-
- /* functions */
- new_plugin->ascii_strcasecmp = &weechat_ascii_strcasecmp;
- new_plugin->explode_string = &weechat_explode_string;
- new_plugin->free_exploded_string = &weechat_free_exploded_string;
- new_plugin->mkdir_home = &weechat_plugin_mkdir_home;
- new_plugin->exec_on_files = &weechat_plugin_exec_on_files;
- new_plugin->msg_handler_add = &weechat_plugin_msg_handler_add;
- new_plugin->cmd_handler_add = &weechat_plugin_cmd_handler_add;
- new_plugin->timer_handler_add = &weechat_plugin_timer_handler_add;
- new_plugin->keyboard_handler_add = &weechat_plugin_keyboard_handler_add;
- new_plugin->event_handler_add = &weechat_plugin_event_handler_add;
- new_plugin->handler_remove = &weechat_plugin_handler_remove;
- new_plugin->handler_remove_all = &weechat_plugin_handler_remove_all;
- new_plugin->modifier_add = &weechat_plugin_modifier_add;
- new_plugin->modifier_remove = &weechat_plugin_modifier_remove;
- new_plugin->modifier_remove_all = &weechat_plugin_modifier_remove_all;
- new_plugin->print = &weechat_plugin_print;
- new_plugin->print_server = &weechat_plugin_print_server;
- new_plugin->print_infobar = &weechat_plugin_print_infobar;
- new_plugin->infobar_remove = &weechat_plugin_infobar_remove;
- new_plugin->log = &weechat_plugin_log;
- new_plugin->exec_command = &weechat_plugin_exec_command;
- new_plugin->get_info = &weechat_plugin_get_info;
- new_plugin->get_dcc_info = &weechat_plugin_get_dcc_info;
- new_plugin->free_dcc_info = &weechat_plugin_free_dcc_info;
- new_plugin->get_config = &weechat_plugin_get_config;
- new_plugin->set_config = &weechat_plugin_set_config;
- new_plugin->get_plugin_config = &weechat_plugin_get_plugin_config;
- new_plugin->set_plugin_config = &weechat_plugin_set_plugin_config;
- new_plugin->get_server_info = &weechat_plugin_get_server_info;
- new_plugin->free_server_info = &weechat_plugin_free_server_info;
- new_plugin->get_channel_info = &weechat_plugin_get_channel_info;
- new_plugin->free_channel_info = &weechat_plugin_free_channel_info;
- new_plugin->get_nick_info = &weechat_plugin_get_nick_info;
- new_plugin->free_nick_info = &weechat_plugin_free_nick_info;
- new_plugin->input_color = &weechat_plugin_input_color;
- new_plugin->get_irc_color = &weechat_plugin_get_irc_color;
- new_plugin->get_window_info = &weechat_plugin_get_window_info;
- new_plugin->free_window_info = &weechat_plugin_free_window_info;
- new_plugin->get_buffer_info = &weechat_plugin_get_buffer_info;
- new_plugin->free_buffer_info = &weechat_plugin_free_buffer_info;
- new_plugin->get_buffer_data = &weechat_plugin_get_buffer_data;
- new_plugin->free_buffer_data = &weechat_plugin_free_buffer_data;
- new_plugin->set_charset = &weechat_plugin_set_charset;
- new_plugin->iconv_to_internal = &weechat_plugin_iconv_to_internal;
- new_plugin->iconv_from_internal = &weechat_plugin_iconv_from_internal;
-
- /* handlers */
- new_plugin->handlers = NULL;
- new_plugin->last_handler = NULL;
-
- /* modifiers */
- new_plugin->modifiers = NULL;
- new_plugin->last_modifier = NULL;
-
- /* add new plugin to list */
- new_plugin->prev_plugin = last_weechat_plugin;
- new_plugin->next_plugin = NULL;
- if (weechat_plugins)
- last_weechat_plugin->next_plugin = new_plugin;
- else
- weechat_plugins = new_plugin;
- last_weechat_plugin = new_plugin;
-
- irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN);
- gui_printf (NULL,
- _("Initializing plugin \"%s\" %s\n"),
- new_plugin->name, new_plugin->version);
-
- /* init plugin */
- if (((t_weechat_init_func *)init_func) (new_plugin) < 0)
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL,
- _("%s unable to initialize plugin \"%s\"\n"),
- WEECHAT_ERROR, full_name);
- plugin_remove (new_plugin);
- free (full_name);
- return NULL;
- }
- }
- else
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL,
- _("%s unable to load plugin \"%s\" (not enough memory)\n"),
- WEECHAT_ERROR, full_name);
- free (full_name);
- return NULL;
- }
-
- irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN);
- gui_printf (NULL,
- _("Plugin \"%s\" (%s) loaded.\n"),
- name, full_name);
-
- free (full_name);
-
- return new_plugin;
-}
-
-/*
- * plugin_auto_load_file: load a file found by plugin_auto_load,
- * but only it this is really a dynamic library
- */
-
-int
-plugin_auto_load_file (t_weechat_plugin *plugin, char *filename)
-{
- char *pos;
-
- /* make C compiler happy */
- (void) plugin;
-
- if (cfg_plugins_extension && cfg_plugins_extension[0])
- {
- pos = strstr (filename, cfg_plugins_extension);
- if (pos)
- {
- if (ascii_strcasecmp (pos, cfg_plugins_extension) == 0)
- plugin_load (filename);
- }
- }
- else
- plugin_load (filename);
- return 1;
-}
-
-/*
- * plugin_auto_load: auto-load WeeChat plugins
- */
-
-void
-plugin_auto_load ()
-{
- char *ptr_home, *dir_name, *plugins_path, *plugins_path2;
- char *list_plugins, *pos, *pos2;
-
- if (cfg_plugins_autoload && cfg_plugins_autoload[0])
- {
- if (ascii_strcasecmp (cfg_plugins_autoload, "*") == 0)
- {
- /* auto-load plugins in WeeChat home dir */
- if (cfg_plugins_path && cfg_plugins_path[0])
- {
- ptr_home = getenv ("HOME");
- plugins_path = weechat_strreplace (cfg_plugins_path, "~", ptr_home);
- plugins_path2 = weechat_strreplace ((plugins_path) ?
- plugins_path : cfg_plugins_path,
- "%h", weechat_home);
- plugin_exec_on_files (NULL,
- (plugins_path2) ?
- plugins_path2 : ((plugins_path) ?
- plugins_path : cfg_plugins_path),
- &plugin_auto_load_file);
- if (plugins_path)
- free (plugins_path);
- if (plugins_path2)
- free (plugins_path2);
- }
-
- /* auto-load plugins in WeeChat global lib dir */
- dir_name = (char *)malloc (strlen (WEECHAT_LIBDIR) + 16);
- if (dir_name)
- {
- snprintf (dir_name, strlen (WEECHAT_LIBDIR) + 16,
- "%s/plugins", WEECHAT_LIBDIR);
- plugin_exec_on_files (NULL, dir_name, &plugin_auto_load_file);
- free (dir_name);
- }
- }
- else
- {
- list_plugins = strdup (cfg_plugins_autoload);
- if (list_plugins)
- {
- pos = list_plugins;
- while (pos && pos[0])
- {
- pos2 = strchr (pos, ',');
- if (pos2)
- pos2[0] = '\0';
- plugin_load (pos);
- if (pos2)
- pos = pos2 + 1;
- else
- pos = NULL;
- }
- free (list_plugins);
- }
- }
- }
-}
-
-/*
- * plugin_remove: remove a WeeChat plugin
- */
-
-void
-plugin_remove (t_weechat_plugin *plugin)
-{
- t_weechat_plugin *new_weechat_plugins;
-
- /* remove handler from list */
- if (last_weechat_plugin == plugin)
- last_weechat_plugin = plugin->prev_plugin;
- if (plugin->prev_plugin)
- {
- (plugin->prev_plugin)->next_plugin = plugin->next_plugin;
- new_weechat_plugins = weechat_plugins;
- }
- else
- new_weechat_plugins = plugin->next_plugin;
-
- if (plugin->next_plugin)
- (plugin->next_plugin)->prev_plugin = plugin->prev_plugin;
-
- /* remove all handlers and modifiers */
- plugin_handler_remove_all (plugin);
- plugin_modifier_remove_all (plugin);
-
- /* free data */
- if (plugin->filename)
- free (plugin->filename);
- dlclose (plugin->handle);
- if (plugin->name)
- free (plugin->name);
- if (plugin->description)
- free (plugin->description);
- if (plugin->version)
- free (plugin->version);
- if (plugin->charset)
- free (plugin->charset);
- free (plugin);
-
- weechat_plugins = new_weechat_plugins;
-}
-
-/*
- * plugin_unload: unload a WeeChat plugin
- */
-
-void
-plugin_unload (t_weechat_plugin *plugin)
-{
- t_weechat_end_func *end_func;
-
- end_func = dlsym (plugin->handle, "weechat_plugin_end");
- if (end_func)
- (void) (end_func) (plugin);
- plugin_remove (plugin);
-}
-
-/*
- * plugin_unload_name: unload a WeeChat plugin by name
- */
-
-void
-plugin_unload_name (char *name)
-{
- t_weechat_plugin *ptr_plugin;
-
- ptr_plugin = plugin_search (name);
- if (ptr_plugin)
- {
- plugin_unload (ptr_plugin);
- irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN);
- gui_printf (NULL, _("Plugin \"%s\" unloaded.\n"), name);
- }
- else
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL,
- _("%s plugin \"%s\" not found\n"),
- WEECHAT_ERROR, name);
- }
-}
-
-/*
- * plugin_unload_all: unload all WeeChat plugins
- */
-
-void
-plugin_unload_all ()
-{
- while (weechat_plugins)
- plugin_unload (last_weechat_plugin);
-}
-
-/*
- * plugin_reload_name: reload a WeeChat plugin by name
- */
-
-void
-plugin_reload_name (char *name)
-{
- t_weechat_plugin *ptr_plugin;
- char *filename;
-
- ptr_plugin = plugin_search (name);
- if (ptr_plugin)
- {
- filename = strdup (ptr_plugin->filename);
- if (filename)
- {
- plugin_unload (ptr_plugin);
- irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN);
- gui_printf (NULL, _("Plugin \"%s\" unloaded.\n"), name);
- plugin_load (filename);
- free (filename);
- }
- }
- else
- {
- irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
- gui_printf (NULL,
- _("%s plugin \"%s\" not found\n"),
- WEECHAT_ERROR, name);
- }
-}
-
-/*
- * plugin_init: init plugin support
- */
-
-void
-plugin_init (int auto_load)
-{
- /* read plugins options on disk */
- plugin_config_read ();
-
- /* auto-load plugins if asked */
- if (auto_load)
- plugin_auto_load ();
-}
-
-/*
- * plugin_end: end plugin support
- */
-
-void
-plugin_end ()
-{
- /* write plugins config options */
- plugin_config_write ();
-
- /* unload all plugins */
- plugin_unload_all ();
-}
-
-/*
- * plugin_print_log: print plugin infos in log (usually for crash dump)
- */
-
-void
-plugin_print_log (t_weechat_plugin *plugin)
-{
- t_plugin_handler *ptr_handler;
- t_plugin_modifier *ptr_modifier;
-
- weechat_log_printf ("[plugin (addr:0x%X)]\n", plugin);
- weechat_log_printf (" filename . . . . . . . : '%s'\n", plugin->filename);
- weechat_log_printf (" handle . . . . . . . . : 0x%X\n", plugin->handle);
- weechat_log_printf (" name . . . . . . . . . : '%s'\n", plugin->name);
- weechat_log_printf (" description. . . . . . : '%s'\n", plugin->description);
- weechat_log_printf (" version. . . . . . . . : '%s'\n", plugin->version);
- weechat_log_printf (" charset. . . . . . . . : '%s'\n", plugin->charset);
- weechat_log_printf (" handlers . . . . . . . : 0x%X\n", plugin->handlers);
- weechat_log_printf (" last_handler . . . . . : 0x%X\n", plugin->last_handler);
- weechat_log_printf (" modifiers. . . . . . . : 0x%X\n", plugin->modifiers);
- weechat_log_printf (" last_modifier. . . . . : 0x%X\n", plugin->last_modifier);
- weechat_log_printf (" prev_plugin. . . . . . : 0x%X\n", plugin->prev_plugin);
- weechat_log_printf (" next_plugin. . . . . . : 0x%X\n", plugin->next_plugin);
-
- weechat_log_printf ("\n");
- weechat_log_printf (" => handlers:\n");
- for (ptr_handler = plugin->handlers; ptr_handler;
- ptr_handler = ptr_handler->next_handler)
- {
- weechat_log_printf ("\n");
- weechat_log_printf (" [handler (addr:0x%X)]\n", ptr_handler);
- weechat_log_printf (" type . . . . . . . . : %d\n", ptr_handler->type);
- weechat_log_printf (" irc_command. . . . . : '%s'\n", ptr_handler->irc_command);
- weechat_log_printf (" command. . . . . . . : '%s'\n", ptr_handler->command);
- weechat_log_printf (" description. . . . . : '%s'\n", ptr_handler->description);
- weechat_log_printf (" arguments. . . . . . : '%s'\n", ptr_handler->arguments);
- weechat_log_printf (" arguments_description: '%s'\n", ptr_handler->arguments_description);
- weechat_log_printf (" completion_template. : '%s'\n", ptr_handler->completion_template);
- weechat_log_printf (" interval . . . . . . : %d\n", ptr_handler->interval);
- weechat_log_printf (" remaining. . . . . . : %d\n", ptr_handler->remaining);
- weechat_log_printf (" event. . . . . . . . : '%s'\n", ptr_handler->event);
- weechat_log_printf (" handler_args . . . . : '%s'\n", ptr_handler->handler_args);
- weechat_log_printf (" handler_pointer. . . : 0x%X\n", ptr_handler->handler_pointer);
- weechat_log_printf (" running. . . . . . . : %d\n", ptr_handler->running);
- weechat_log_printf (" prev_handler . . . . : 0x%X\n", ptr_handler->prev_handler);
- weechat_log_printf (" next_handler . . . . : 0x%X\n", ptr_handler->next_handler);
- }
-
- weechat_log_printf ("\n");
- weechat_log_printf (" => modifiers:\n");
- for (ptr_modifier = plugin->modifiers; ptr_modifier;
- ptr_modifier = ptr_modifier->next_modifier)
- {
- weechat_log_printf ("\n");
- weechat_log_printf (" [modifier (addr:0x%X)]\n", ptr_modifier);
- weechat_log_printf (" type . . . . . . . . : %d\n", ptr_modifier->type);
- weechat_log_printf (" command. . . . . . . : '%s'\n", ptr_modifier->command);
- weechat_log_printf (" modifier . . . . . . : 0x%X\n", ptr_modifier->modifier);
- weechat_log_printf (" modifier_args. . . . : '%s'\n", ptr_modifier->modifier_args);
- weechat_log_printf (" modifier_pointer . . : 0x%X\n", ptr_modifier->modifier_pointer);
- weechat_log_printf (" running. . . . . . . : %d\n", ptr_modifier->running);
- weechat_log_printf (" prev_modifier. . . . : 0x%X\n", ptr_modifier->prev_modifier);
- weechat_log_printf (" next_modifier. . . . : 0x%X\n", ptr_modifier->next_modifier);
- }
-}
diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h
deleted file mode 100644
index 03d4a4a46..000000000
--- a/src/plugins/plugins.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (c) 2003-2007 by FlashCode <flashcode@flashtux.org>
- * See README for License detail, AUTHORS for developers list.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#ifndef __WEECHAT_PLUGINS_H
-#define __WEECHAT_PLUGINS_H 1
-
-#include "weechat-plugin.h"
-#include "plugins-config.h"
-#include "../protocols/irc/irc.h"
-#include "../gui/gui.h"
-
-typedef struct t_plugin_irc_color t_plugin_irc_color;
-
-struct t_plugin_irc_color
-{
- int number;
- char *name;
-};
-
-typedef int (t_weechat_init_func) (t_weechat_plugin *);
-typedef void (t_weechat_end_func) (t_weechat_plugin *);
-
-extern t_weechat_plugin *weechat_plugins;
-extern t_weechat_plugin *last_weechat_plugin;
-
-extern t_plugin_irc_color plugins_irc_colors[GUI_NUM_IRC_COLORS];
-
-extern int plugin_find_server_channel (char *, char *,
- t_irc_server **, t_irc_channel **);
-extern void plugin_exec_on_files (t_weechat_plugin *, char *,
- int (*)(t_weechat_plugin *, char *));
-extern t_weechat_plugin *plugin_search (char *);
-extern t_plugin_handler *plugin_msg_handler_add (t_weechat_plugin *, char *,
- t_plugin_handler_func *,
- char *, void *);
-extern t_plugin_handler *plugin_cmd_handler_add (t_weechat_plugin *, char *,
- char *, char *, char *,
- char *,
- t_plugin_handler_func *,
- char *, void *);
-extern t_plugin_handler *plugin_timer_handler_add (t_weechat_plugin *, int,
- t_plugin_handler_func *,
- char *, void *);
-extern t_plugin_handler *plugin_keyboard_handler_add (t_weechat_plugin *,
- t_plugin_handler_func *,
- char *, void *);
-extern t_plugin_handler *plugin_event_handler_add (t_weechat_plugin *, char *,
- t_plugin_handler_func *,
- char *, void *);
-extern int plugin_msg_handler_exec (char *, char *, char *);
-extern int plugin_cmd_handler_exec (char *, char *, char *);
-extern int plugin_timer_handler_exec ();
-extern int plugin_keyboard_handler_exec (char *, char *, char *);
-extern int plugin_event_handler_exec (char *, int, char **);
-extern void plugin_handler_remove (t_weechat_plugin *,
- t_plugin_handler *);
-extern void plugin_handler_remove_all (t_weechat_plugin *);
-extern t_plugin_modifier *plugin_modifier_add (t_weechat_plugin *,
- char *, char *,
- t_plugin_modifier_func *,
- char *, void *);
-extern char *plugin_modifier_exec (t_plugin_modifier_type, char *, char *);
-extern void plugin_modifier_remove (t_weechat_plugin *,
- t_plugin_modifier *);
-extern void plugin_modifier_remove_all (t_weechat_plugin *);
-extern t_weechat_plugin *plugin_load (char *);
-extern void plugin_auto_load ();
-extern void plugin_remove (t_weechat_plugin *);
-extern void plugin_unload (t_weechat_plugin *);
-extern void plugin_unload_name (char *);
-extern void plugin_unload_all ();
-extern void plugin_reload_name (char *);
-extern void plugin_init (int);
-extern void plugin_end ();
-extern void plugin_print_log (t_weechat_plugin *);
-
-#endif /* plugins.h */
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index e0ea0c36b..86d9f9a07 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -24,431 +24,177 @@
#include <sys/types.h>
/* return codes for init function and handlers */
-#define PLUGIN_RC_KO -1 /* function/handler failed */
-#define PLUGIN_RC_OK 0 /* function/handler ok */
+#define PLUGIN_RC_FAILED -1 /* function/handler failed */
+#define PLUGIN_RC_SUCCESS 0 /* function/handler ok */
/* return codes specific to message handlers: messages can be discarded for
WeeChat, for plugins, or both */
-#define PLUGIN_RC_OK_IGNORE_WEECHAT 1 /* ignore WeeChat for this message */
-#define PLUGIN_RC_OK_IGNORE_PLUGINS 2 /* ignore other plugins for this msg*/
-#define PLUGIN_RC_OK_IGNORE_ALL (PLUGIN_RC_OK_IGNORE_WEECHAT \
- | PLUGIN_RC_OK_IGNORE_PLUGINS)
- /* ignore WeeChat and other plugins */
-#define PLUGIN_RC_OK_WITH_HIGHLIGHT 4 /* ok and ask for highlight */
- /* (for message handler only) */
-
-#define WEECHAT_IRC_COLOR_WHITE 0
-#define WEECHAT_IRC_COLOR_BLACK 1
-#define WEECHAT_IRC_COLOR_BLUE 2
-#define WEECHAT_IRC_COLOR_GREEN 3
-#define WEECHAT_IRC_COLOR_LIGHTRED 4
-#define WEECHAT_IRC_COLOR_RED 5
-#define WEECHAT_IRC_COLOR_MAGENTA 6
-#define WEECHAT_IRC_COLOR_BROWN 7
-#define WEECHAT_IRC_COLOR_YELLOW 8
-#define WEECHAT_IRC_COLOR_LIGHTGREEN 9
-#define WEECHAT_IRC_COLOR_CYAN 10
-#define WEECHAT_IRC_COLOR_LIGHTCYAN 11
-#define WEECHAT_IRC_COLOR_LIGHTBLUE 12
-#define WEECHAT_IRC_COLOR_LIGHTMAGENTA 13
-#define WEECHAT_IRC_COLOR_GRAY 14
-#define WEECHAT_IRC_COLOR_LIGHTGRAY 15
-
-typedef struct t_plugin_dcc_info t_plugin_dcc_info;
-
-struct t_plugin_dcc_info
-{
- char *server; /* irc server */
- char *channel; /* irc channel (for DCC chat only) */
- int type; /* DCC type (send or receive) */
- int status; /* DCC status (waiting, sending, ..) */
- time_t start_time; /* the time when DCC started */
- time_t start_transfer; /* the time when DCC transfer started */
- unsigned long addr; /* IP address */
- int port; /* port */
- char *nick; /* remote nick */
- char *filename; /* filename (given by sender) */
- char *local_filename; /* local filename (with path) */
- int filename_suffix; /* suffix (.1 for ex) if renaming file */
- unsigned long size; /* file size */
- unsigned long pos; /* number of bytes received/sent */
- unsigned long start_resume; /* start of resume (in bytes) */
- unsigned long bytes_per_sec; /* bytes per second */
- t_plugin_dcc_info *prev_dcc; /* link to previous dcc file/chat */
- t_plugin_dcc_info *next_dcc; /* link to next dcc file/chat */
-};
-
-typedef struct t_plugin_server_info t_plugin_server_info;
-
-struct t_plugin_server_info
-{
- char *name; /* name of server (only for display) */
- int autoconnect; /* = 1 if auto connect at startup */
- int autoreconnect; /* = 1 if auto reco when disconnected */
- int autoreconnect_delay; /* delay before trying again reconnect */
- int temp_server; /* server was given on command line */
- char *address; /* address of server (IP or name) */
- int port; /* port for server (6667 by default) */
- int ipv6; /* use IPv6 protocol */
- int ssl; /* SSL protocol */
- char *password; /* password for server */
- char *nick1; /* first nickname for the server */
- char *nick2; /* alternate nickname */
- char *nick3; /* 2nd alternate nickname */
- char *username; /* user name */
- char *realname; /* real name */
- char *command; /* command to run once connected */
- int command_delay; /* delay after execution of command */
- char *autojoin; /* channels to automatically join */
- int autorejoin; /* auto rejoin channels when kicked */
- char *notify_levels; /* channels notify levels */
- int is_connected; /* 1 if WeeChat is connected to server */
- int ssl_connected; /* = 1 if connected with SSL */
- char *nick; /* current nickname */
- char *nick_modes; /* nick modes */
- int is_away; /* 1 is user is marker as away */
- time_t away_time; /* time() when user marking as away */
- int lag; /* lag (in milliseconds) */
- t_plugin_server_info *prev_server; /* link to previous server info */
- t_plugin_server_info *next_server; /* link to next server info */
-};
-
-typedef struct t_plugin_channel_info t_plugin_channel_info;
-
-struct t_plugin_channel_info
-{
- int type; /* channel type */
- char *name; /* name of channel (exemple: "#abc") */
- char *topic; /* topic of channel (host for private) */
- char *modes; /* channel modes */
- int limit; /* user limit (0 is limit not set) */
- char *key; /* channel key (NULL if no key is set) */
- int nicks_count; /* # nicks on channel (0 if dcc/pv) */
- t_plugin_channel_info *prev_channel; /* link to previous channel info */
- t_plugin_channel_info *next_channel; /* link to next channel info */
-};
-
-typedef struct t_plugin_nick_info t_plugin_nick_info;
-
-struct t_plugin_nick_info
-{
- char *nick; /* nickname */
- int flags; /* chanowner/chanadmin (unrealircd), */
- char *host; /* hostname */
- /* op, halfop, voice, away */
- t_plugin_nick_info *prev_nick; /* link to previous nick */
- t_plugin_nick_info *next_nick; /* link to next nick */
-};
-
-typedef struct t_plugin_window_info t_plugin_window_info;
-
-struct t_plugin_window_info
-{
- int win_x, win_y; /* position of window */
- int win_width, win_height; /* window geometry */
- int win_width_pct; /* % of width (compared to parent win) */
- int win_height_pct; /* % of height (compared to parent win) */
- int num_buffer; /* # of displayed buffer */
- t_plugin_window_info *prev_window; /* link to previous window */
- t_plugin_window_info *next_window; /* link to next window */
-};
-
-typedef struct t_plugin_buffer_info t_plugin_buffer_info;
-
-struct t_plugin_buffer_info
-{
- int type; /* buffer type (0=standard,1=dcc,2=raw) */
- int number; /* buffer number */
- int num_displayed; /* number of windows displaying buffer */
- char *server_name; /* server name for buffer (may be NULL) */
- char *channel_name; /* channel name for buffer (may be NULL)*/
- int notify_level; /* notify level for buffer */
- char *log_filename; /* log filename (NULL is disabled) */
- t_plugin_buffer_info *prev_buffer; /* link to previous buffer */
- t_plugin_buffer_info *next_buffer; /* link to next buffer */
-};
-
-typedef struct t_plugin_buffer_line t_plugin_buffer_line;
-
-struct t_plugin_buffer_line
-{
- time_t date; /* date */
- char *nick; /* nick */
- char *data; /* line data */
- t_plugin_buffer_line *prev_line; /* link to previous line */
- t_plugin_buffer_line *next_line; /* link to next line */
-};
-
-typedef struct t_weechat_plugin t_weechat_plugin;
-
-/* handlers */
-
-typedef int (t_plugin_handler_func) (t_weechat_plugin *, int, char **, char *, void *);
-
-typedef enum t_plugin_handler_type t_plugin_handler_type;
-
-enum t_plugin_handler_type
-{
- PLUGIN_HANDLER_MESSAGE = 0, /* IRC message handler */
- PLUGIN_HANDLER_COMMAND, /* command handler */
- PLUGIN_HANDLER_TIMER, /* timer handler */
- PLUGIN_HANDLER_KEYBOARD, /* keyboard handler */
- PLUGIN_HANDLER_EVENT /* event handler */
-};
-
-typedef struct t_plugin_handler t_plugin_handler;
-
-struct t_plugin_handler
-{
- t_plugin_handler_type type; /* handler type */
-
- /* data for message handler */
- char *irc_command; /* name of IRC command (PRIVMSG, ..) */
-
- /* data for command handler */
- char *command; /* name of command (without first '/') */
- char *description; /* (for /help) short cmd description */
- char *arguments; /* (for /help) command arguments */
- char *arguments_description; /* (for /help) args long description */
- char *completion_template; /* template for completion */
-
- /* data for timer handler */
- int interval; /* interval between two calls to fct */
- int remaining; /* seconds remaining before next call */
-
- /* data for event handler */
- char *event; /* event to catch */
-
- /* data common to all handlers */
- t_plugin_handler_func *handler; /* pointer to handler */
- char *handler_args; /* arguments sent to handler */
- void *handler_pointer; /* pointer sent to handler */
-
- /* for internal use */
- int running; /* 1 if currently running */
- /* (used to prevent circular call) */
- t_plugin_handler *prev_handler; /* link to previous handler */
- t_plugin_handler *next_handler; /* link to next handler */
-};
-
-/* modifiers */
-
-typedef char * (t_plugin_modifier_func) (t_weechat_plugin *, int, char **, char *, void *);
-
-typedef enum t_plugin_modifier_type t_plugin_modifier_type;
-
-enum t_plugin_modifier_type
-{
- PLUGIN_MODIFIER_IRC_IN = 0, /* incoming IRC msg (server > user) */
- PLUGIN_MODIFIER_IRC_USER, /* outgoing IRC msg (user > server) */
- /* after user input (before 'out' mod.) */
- PLUGIN_MODIFIER_IRC_OUT /* outgoing IRC msg (user > server) */
- /* immediately before sending to server */
-};
-
-#define PLUGIN_MODIFIER_IRC_IN_STR "irc_in"
-#define PLUGIN_MODIFIER_IRC_USER_STR "irc_user"
-#define PLUGIN_MODIFIER_IRC_OUT_STR "irc_out"
-
-typedef struct t_plugin_modifier t_plugin_modifier;
-
-struct t_plugin_modifier
-{
- t_plugin_modifier_type type; /* modifier type */
-
- /* data for IRC modifier */
- char *command; /* IRC command */
-
- /* data common to all modifiers */
- t_plugin_modifier_func *modifier; /* pointer to modifier */
- char *modifier_args; /* arguments sent to modifier */
- void *modifier_pointer; /* pointer sent to modifier */
-
- /* for internal use */
- int running; /* 1 if currently running */
- /* (used to prevent circular call) */
- t_plugin_modifier *prev_modifier; /* link to previous modifier */
- t_plugin_modifier *next_modifier; /* link to next modifier */
-};
-
-/* plugin, a WeeChat plugin, which is a dynamic library */
+#define PLUGIN_RC_IGNORE_WEECHAT 1 /* ignore WeeChat for this message */
+#define PLUGIN_RC_IGNORE_PLUGINS 2 /* ignore other plugins for msg */
+#define PLUGIN_RC_IGNORE_ALL (PLUGIN_RC_OK_IGNORE_WEECHAT \
+ | PLUGIN_RC_OK_IGNORE_PLUGINS)
+ /* ignore WeeChat and other plugins*/
+#define PLUGIN_RC_WITH_HIGHLIGHT 4 /* ok and ask for highlight */
+ /* (for message handler only) */
struct t_weechat_plugin
{
/* plugin variables */
- char *filename; /* name of plugin on disk */
- void *handle; /* handle of plugin (given by dlopen) */
- char *name; /* plugin name */
- char *description; /* plugin description */
- char *version; /* plugin version */
- char *charset; /* charset used by plugin */
-
- /* plugin handlers */
- t_plugin_handler *handlers; /* pointer to first handler */
- t_plugin_handler *last_handler; /* pointer to last handler */
-
- /* plugin modifiers */
- t_plugin_modifier *modifiers; /* pointer to first modifier */
- t_plugin_modifier *last_modifier; /* pointer to last modifier */
-
- /* links to previous/next plugins */
- t_weechat_plugin *prev_plugin; /* link to previous plugin */
- t_weechat_plugin *next_plugin; /* link to next plugin */
+ char *filename; /* name of plugin on disk */
+ void *handle; /* handle of plugin (given by dlopen)*/
+ char *name; /* plugin name */
+ char *description; /* plugin description */
+ char *version; /* plugin version */
+ char *charset; /* charset used by plugin */
+ struct t_weechat_plugin *prev_plugin; /* link to previous plugin */
+ struct t_weechat_plugin *next_plugin; /* link to next plugin */
/* plugin functions (interface) */
/* IMPORTANT NOTE for WeeChat developers: always add new interface functions
at the END of functions, for keeping backward compatibility with
existing plugins */
-
- int (*ascii_strcasecmp) (t_weechat_plugin *, char *, char *);
- int (*ascii_strncasecmp) (t_weechat_plugin *, char *, char *, int);
- char **(*explode_string) (t_weechat_plugin *, char *, char *, int, int *);
- void (*free_exploded_string) (t_weechat_plugin *, char **);
- int (*mkdir_home) (t_weechat_plugin *, char *);
- void (*exec_on_files) (t_weechat_plugin *, char *,
- int (*)(t_weechat_plugin *, char *));
-
- void (*print) (t_weechat_plugin *, char *, char *, char *, ...);
- void (*print_server) (t_weechat_plugin *, char *, ...);
- void (*print_infobar) (t_weechat_plugin *, int, char *, ...);
- void (*infobar_remove) (t_weechat_plugin *, int);
-
- t_plugin_handler *(*msg_handler_add) (t_weechat_plugin *, char *,
- t_plugin_handler_func *,
- char *, void *);
- t_plugin_handler *(*cmd_handler_add) (t_weechat_plugin *, char *,
- char *, char *, char *,
- char *,
- t_plugin_handler_func *,
- char *, void *);
- t_plugin_handler *(*timer_handler_add) (t_weechat_plugin *, int,
- t_plugin_handler_func *,
- char *, void *);
- t_plugin_handler *(*keyboard_handler_add) (t_weechat_plugin *,
- t_plugin_handler_func *,
- char *, void *);
- t_plugin_handler *(*event_handler_add) (t_weechat_plugin *, char *,
- t_plugin_handler_func *,
- char *, void *);
- void (*handler_remove) (t_weechat_plugin *, t_plugin_handler *);
- void (*handler_remove_all) (t_weechat_plugin *);
- t_plugin_modifier *(*modifier_add) (t_weechat_plugin *, char *, char *,
- t_plugin_modifier_func *,
- char *, void *);
- void (*modifier_remove) (t_weechat_plugin *, t_plugin_modifier *);
- void (*modifier_remove_all) (t_weechat_plugin *);
-
- void (*exec_command) (t_weechat_plugin *, char *, char *, char *);
- char *(*get_info) (t_weechat_plugin *, char *, char *);
- t_plugin_dcc_info *(*get_dcc_info) (t_weechat_plugin *);
- void (*free_dcc_info) (t_weechat_plugin *, t_plugin_dcc_info *);
- char *(*get_config) (t_weechat_plugin *, char *);
- int (*set_config) (t_weechat_plugin *, char *, char *);
- char *(*get_plugin_config) (t_weechat_plugin *, char *);
- int (*set_plugin_config) (t_weechat_plugin *, char *, char *);
- t_plugin_server_info *(*get_server_info) (t_weechat_plugin *);
- void (*free_server_info) (t_weechat_plugin *, t_plugin_server_info *);
- t_plugin_channel_info *(*get_channel_info) (t_weechat_plugin *, char *);
- void (*free_channel_info) (t_weechat_plugin *, t_plugin_channel_info *);
- t_plugin_nick_info *(*get_nick_info) (t_weechat_plugin *, char*, char*);
- void (*free_nick_info) (t_weechat_plugin *, t_plugin_nick_info *);
-
- void (*log) (t_weechat_plugin *, char *, char *, char *, ...);
-
- void (*input_color) (t_weechat_plugin *, int, int, int);
-
- int (*get_irc_color) (t_weechat_plugin *, char *);
-
- t_plugin_window_info *(*get_window_info) (t_weechat_plugin *);
- void (*free_window_info) (t_weechat_plugin *, t_plugin_window_info *);
- t_plugin_buffer_info *(*get_buffer_info) (t_weechat_plugin *);
- void (*free_buffer_info) (t_weechat_plugin *, t_plugin_buffer_info *);
- t_plugin_buffer_line *(*get_buffer_data) (t_weechat_plugin *, char *, char *);
- void (*free_buffer_data) (t_weechat_plugin *, t_plugin_buffer_line *);
-
- void (*set_charset) (t_weechat_plugin *, char *);
- char *(*iconv_to_internal) (t_weechat_plugin *, char *, char *);
- char *(*iconv_from_internal) (t_weechat_plugin *, char *, char *);
+ /* strings */
+ void (*charset_set) (struct t_weechat_plugin *, char *);
+ char *(*iconv_to_internal) (struct t_weechat_plugin *, char *, char *);
+ char *(*iconv_from_internal) (struct t_weechat_plugin *, char *, char *);
+ char *(*gettext) (struct t_weechat_plugin *, char *);
+ char *(*ngettext) (struct t_weechat_plugin *, char *, char *, int);
+ int (*strcasecmp) (struct t_weechat_plugin *, char *, char *);
+ int (*strncasecmp) (struct t_weechat_plugin *, char *, char *, int);
+ char **(*explode_string) (struct t_weechat_plugin *, char *, char *, int,
+ int *);
+ void (*free_exploded_string) (struct t_weechat_plugin *, char **);
+
+ /* directories */
+ int (*mkdir_home) (struct t_weechat_plugin *, char *);
+ void (*exec_on_files) (struct t_weechat_plugin *, char *,
+ int (*)(char *));
+
+ /* display */
+ void (*printf) (struct t_weechat_plugin *, void *, char *, ...);
+ char *(*prefix) (struct t_weechat_plugin *, char *);
+ char *(*color) (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 *, char *),void *);
+ struct t_hook *(*hook_message) (struct t_weechat_plugin *, char *,
+ int (*)(void *, char *), void *);
+ struct t_hook *(*hook_config) (struct t_weechat_plugin *, char *, char *,
+ int (*)(void *, char *, char *, char *),
+ void *);
+ struct t_hook *(*hook_timer) (struct t_weechat_plugin *, long, int,
+ int (*)(void *), void *);
+ struct t_hook *(*hook_fd) (struct t_weechat_plugin *, int, int, int, int,
+ int (*)(void *), void *);
+ void (*unhook) (struct t_weechat_plugin *, void *);
+ void (*unhook_all) (struct t_weechat_plugin *);
+
+ /* buffers */
+ struct t_gui_buffer *(*buffer_new) (struct t_weechat_plugin *,
+ char *, char *);
+ struct t_gui_buffer *(*buffer_search) (struct t_weechat_plugin *,
+ char *, char *);
+ void (*buffer_close) (struct t_weechat_plugin *, void *);
+ void (*buffer_set) (struct t_weechat_plugin *, void *, char *, char *);
+ void (*buffer_nick_add) (struct t_weechat_plugin *, void *, char *, int,
+ char *, char, char *);
+ void (*buffer_nick_remove) (struct t_weechat_plugin *, char *);
+
+ /* command */
+ void (*command) (struct t_weechat_plugin *, void *, char *);
+
+ /* infos */
+ char *(*info_get) (struct t_weechat_plugin *, char *);
+
+ /* lists */
+ struct t_plugin_list *(*list_get) (struct t_weechat_plugin *, char *,
+ void *);
+ void (*list_free) (struct t_weechat_plugin *, void *);
+
+
+ /* config */
+ char *(*config_get) (struct t_weechat_plugin *, char *);
+ int (*config_set) (struct t_weechat_plugin *, char *, char *);
+ char *(*plugin_config_get) (struct t_weechat_plugin *, char *);
+ int (*plugin_config_set) (struct t_weechat_plugin *, char *, char *);
+
+ /* log */
+ void (*log) (struct t_weechat_plugin *, char *, char *, char *, ...);
/* WeeChat developers: ALWAYS add new functions at the end */
};
-/* general useful functions */
-extern int weechat_ascii_strcasecmp (t_weechat_plugin *,char *, char *);
-extern int weechat_ascii_strncasecmp (t_weechat_plugin *,char *, char *, int);
-extern char **weechat_explode_string (t_weechat_plugin *, char *, char *, int, int *);
-extern void weechat_free_exploded_string (t_weechat_plugin *, char **);
-extern int weechat_plugin_mkdir_home (t_weechat_plugin *, char *);
-extern void weechat_plugin_exec_on_files (t_weechat_plugin *, char *,
- int (*)(t_weechat_plugin *, char *));
-
-/* display functions */
-extern void weechat_plugin_print (t_weechat_plugin *, char *, char *, char *, ...);
-extern void weechat_plugin_print_server (t_weechat_plugin *, char *, ...);
-extern void weechat_plugin_print_infobar (t_weechat_plugin *, int, char *, ...);
-extern void weechat_plugin_infobar_remove (t_weechat_plugin *, int);
-
-/* log functions */
-extern void weechat_plugin_log (t_weechat_plugin *, char *, char *, char *, ...);
-
-/* handler functions */
-extern t_plugin_handler *weechat_plugin_msg_handler_add (t_weechat_plugin *, char *,
- t_plugin_handler_func *,
- char *, void *);
-extern t_plugin_handler *weechat_plugin_cmd_handler_add (t_weechat_plugin *, char *,
- char *, char *, char *,
- char *,
- t_plugin_handler_func *,
- char *, void *);
-extern t_plugin_handler *weechat_plugin_timer_handler_add (t_weechat_plugin *, int,
- t_plugin_handler_func *,
- char *, void *);
-extern t_plugin_handler *weechat_plugin_keyboard_handler_add (t_weechat_plugin *,
- t_plugin_handler_func *,
- char *, void *);
-extern t_plugin_handler *weechat_plugin_event_handler_add (t_weechat_plugin *, char *,
- t_plugin_handler_func *,
- char *, void *);
-extern void weechat_plugin_handler_remove (t_weechat_plugin *, t_plugin_handler *);
-extern void weechat_plugin_handler_remove_all (t_weechat_plugin *);
-
-/* modifier functions */
-extern t_plugin_modifier *weechat_plugin_modifier_add (t_weechat_plugin *,
- char *, char *,
- t_plugin_modifier_func *,
- char *, void *);
-extern void weechat_plugin_modifier_remove (t_weechat_plugin *, t_plugin_modifier *);
-extern void weechat_plugin_modifier_remove_all (t_weechat_plugin *);
-
-/* other functions */
-extern void weechat_plugin_exec_command (t_weechat_plugin *, char *, char *, char *);
-extern char *weechat_plugin_get_info (t_weechat_plugin *, char *, char *);
-extern t_plugin_dcc_info *weechat_plugin_get_dcc_info (t_weechat_plugin *);
-extern void weechat_plugin_free_dcc_info (t_weechat_plugin *, t_plugin_dcc_info *);
-extern char *weechat_plugin_get_config (t_weechat_plugin *, char *);
-extern int weechat_plugin_set_config (t_weechat_plugin *, char *, char *);
-extern char *weechat_plugin_get_plugin_config (t_weechat_plugin *, char *);
-extern int weechat_plugin_set_plugin_config (t_weechat_plugin *, char *, char *);
-extern t_plugin_server_info *weechat_plugin_get_server_info (t_weechat_plugin *);
-extern void weechat_plugin_free_server_info (t_weechat_plugin *, t_plugin_server_info *);
-extern t_plugin_channel_info *weechat_plugin_get_channel_info (t_weechat_plugin *, char *);
-extern void weechat_plugin_free_channel_info (t_weechat_plugin *, t_plugin_channel_info *);
-extern t_plugin_nick_info *weechat_plugin_get_nick_info (t_weechat_plugin *, char *, char *);
-extern void weechat_plugin_free_nick_info (t_weechat_plugin *, t_plugin_nick_info *);
-extern void weechat_plugin_input_color (t_weechat_plugin *, int, int, int);
-extern int weechat_plugin_get_irc_color (t_weechat_plugin *, char *);
-extern t_plugin_window_info *weechat_plugin_get_window_info (t_weechat_plugin *);
-extern void weechat_plugin_free_window_info (t_weechat_plugin *, t_plugin_window_info *);
-extern t_plugin_buffer_info *weechat_plugin_get_buffer_info (t_weechat_plugin *);
-extern void weechat_plugin_free_buffer_info (t_weechat_plugin *, t_plugin_buffer_info *);
-extern t_plugin_buffer_line *weechat_plugin_get_buffer_data (t_weechat_plugin *, char *, char *);
-extern void weechat_plugin_free_buffer_data (t_weechat_plugin *, t_plugin_buffer_line *);
-
-/* iconv functions */
-extern void weechat_plugin_set_charset (t_weechat_plugin *, char *);
-extern char *weechat_plugin_iconv_to_internal (t_weechat_plugin *, char *, char *);
-extern char *weechat_plugin_iconv_from_internal (t_weechat_plugin *, char *, char *);
+/* macros for easy call to plugin API */
+
+#ifndef __WEECHAT_H
+#define _(string) weechat_plugin->gettext(weechat_plugin, string)
+#define N_(string) (string)
+#define NG_(single,plural,number) \
+ weechat_plugin->ngettext(weechat_plugin, single, plural, number)
+#endif
+#define weechat_strcasecmp(string1, string2) \
+ weechat_plugin->strcasecmp(weechat_plugin, string1, string2)
+#define weechat_strncasecmp(string1, string2, max) \
+ weechat_plugin->strncasecmp(weechat_plugin, string1, string2, max)
+
+#define weechat_printf(buffer, argz...) \
+ weechat_plugin->printf(weechat_plugin, buffer, ##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 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)
+#define weechat_hook_message(msg, callback, data) \
+ weechat_plugin->hook_message(weechat_plugin, msg, callback, data)
+#define weechat_hook_config(type, option, callback, data) \
+ weechat_plugin->hook_config(weechat_plugin, type, option, \
+ callback, data)
+#define weechat_hook_timer(interval, max_calls, callback, data) \
+ weechat_plugin->hook_timer(weechat_plugin, interval, max_calls, \
+ callback, data)
+#define weechat_hook_fd(fd, flag_read, flag_write, flag_exception, \
+ callback, data) \
+ weechat_plugin->hook_fd(weechat_plugin, fd, flag_read, flag_write, \
+ flag_exception, callback, data)
+#define weechat_unhook(hook) \
+ weechat_plugin->unhook(weechat_plugin, hook)
+#define weechat_unhook_all() \
+ weechat_plugin->unhook(weechat_plugin)
+
+#define weechat_buffer_new(category, name) \
+ weechat_plugin->buffer_new(weechat_plugin, category, name)
+#define weechat_buffer_search(category, name) \
+ weechat_plugin->buffer_search(weechat_plugin, category, name)
+#define weechat_buffer_close(ptr_buffer) \
+ weechat_plugin->buffer_close(weechat_plugin, ptr_buffer)
+#define weechat_buffer_set(ptr_buffer, property, value) \
+ weechat_plugin->buffer_set(weechat_plugin, ptr_buffer, \
+ property, value)
+
+#define weechat_command(buffer, cmd) \
+ weechat_plugin->command(weechat_plugin, buffer, cmd)
+
+#define weechat_info_get(infoname) \
+ weechat_plugin->info_get(weechat_plugin, infoname)
+
+#define weechat_config_get(option) \
+ weechat_plugin->config_get(weechat_plugin, option)
+#define weechat_config_set(option, value) \
+ weechat_plugin->config_set(weechat_plugin, option, value)
+#define weechat_plugin_config_get(option) \
+ weechat_plugin->plugin_config_get(weechat_plugin, option)
+#define weechat_plugin_config_set(option, value) \
+ weechat_plugin->plugin_config_set(weechat_plugin, option, value)
#endif /* weechat-plugin.h */