mirror of
https://github.com/weechat/weechat.git
synced 2026-06-28 22:06:38 +02:00
New plugin interface (loads dynamic C libraries)
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
WeeChat - Wee Enhanced Environment for Chat
|
||||
===========================================
|
||||
|
||||
ChangeLog - 2005-10-03
|
||||
ChangeLog - 2005-10-15
|
||||
|
||||
|
||||
Version 0.1.6 (under dev!):
|
||||
* new plugin interface, rewritten from scratch: now loads dynamic C
|
||||
library, and perl/python are plugin scripts
|
||||
* added some missing IRC commands
|
||||
* added colors for input buffer and current channel of status bar
|
||||
* added online help for config options (with /set full_option_name)
|
||||
|
||||
@@ -6,6 +6,7 @@ cp Makefile.am Makefile.am.old
|
||||
gettextize --copy --force --intl --no-changelog &&
|
||||
mv Makefile.am.old Makefile.am
|
||||
mv configure.in.old configure.in
|
||||
libtoolize --force &&
|
||||
aclocal &&
|
||||
# autoheader creates config.h.in needed by autoconf
|
||||
autoheader &&
|
||||
|
||||
+94
-37
@@ -24,23 +24,23 @@ AC_CONFIG_SRCDIR([src/common/weechat.c])
|
||||
AM_CONFIG_HEADER(config.h)
|
||||
AM_INIT_AUTOMAKE([weechat], [0.1.6-cvs])
|
||||
|
||||
# Checks for programs.
|
||||
# Checks for programs
|
||||
AC_PROG_CC
|
||||
AC_PROG_MAKE_SET
|
||||
AC_PROG_RANLIB
|
||||
AM_PROG_LIBTOOL
|
||||
|
||||
# Gettext
|
||||
ALL_LINGUAS="fr es cs"
|
||||
AM_GNU_GETTEXT
|
||||
|
||||
# Checks for libraries.
|
||||
AC_CHECK_LIB([ncurses], [initscr], LIBNCURSES_FOUND=1, LIBNCURSES_FOUND=0)
|
||||
# Checks for libraries
|
||||
AC_CHECK_LIB(ncurses, initscr, LIBNCURSES_FOUND=1, LIBNCURSES_FOUND=0)
|
||||
|
||||
# Checks for header files.
|
||||
# Checks for header files
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS([arpa/inet.h libintl.h limits.h locale.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h sys/time.h sys/types.h unistd.h pwd.h errno.h])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
# Checks for typedefs, structures, and compiler characteristics
|
||||
AC_HEADER_TIME
|
||||
AC_STRUCT_TM
|
||||
|
||||
@@ -63,6 +63,11 @@ AC_FUNC_SELECT_ARGTYPES
|
||||
AC_TYPE_SIGNAL
|
||||
AC_CHECK_FUNCS([gethostbyname gethostname getsockname gettimeofday inet_ntoa memset mkdir select setlocale socket strcasecmp strchr strdup strncasecmp strpbrk strrchr strstr uname])
|
||||
|
||||
# Variables in config.h
|
||||
|
||||
AH_VERBATIM([PREFIX], [#undef PREFIX])
|
||||
AH_VERBATIM([WEECHAT_LIBDIR], [#undef WEECHAT_LIBDIR])
|
||||
AH_VERBATIM([WEECHAT_SHAREDIR], [#undef WEECHAT_SHAREDIR])
|
||||
AH_VERBATIM([PLUGINS], [#undef PLUGINS])
|
||||
AH_VERBATIM([PLUGIN_PERL], [#undef PLUGIN_PERL])
|
||||
AH_VERBATIM([PLUGIN_PYTHON], [#undef PLUGIN_PYTHON])
|
||||
@@ -70,27 +75,33 @@ AH_VERBATIM([PLUGIN_RUBY], [#undef PLUGIN_RUBY])
|
||||
AH_VERBATIM([HAVE_GNUTLS], [#undef HAVE_GNUTLS])
|
||||
AH_VERBATIM([DEBUG], [#undef DEBUG])
|
||||
|
||||
# Arguments for ./configure
|
||||
|
||||
AC_ARG_ENABLE(ncurses, [ --disable-ncurses Turn off ncurses interface (default=auto)],enable_ncurses=$enableval,enable_ncurses=yes)
|
||||
AC_ARG_ENABLE(wxwidgets,[ --enable-wxwidgets Turn on WxWidgets interface (default=no)],enable_wxwidgets=$enableval,enable_wxwidgets=no)
|
||||
AC_ARG_ENABLE(gtk, [ --enable-gtk Turn on Gtk+ interface (default=no)],enable_gtk=$enableval,enable_gtk=no)
|
||||
AC_ARG_ENABLE(qt, [ --enable-qt Turn on Qt interface (default=no)],enable_qt=$enableval,enable_qt=no)
|
||||
AC_ARG_ENABLE(perl, [ --enable-perl Turn on Perl plugins (default=no)],enable_perl=$enableval,enable_perl=no)
|
||||
AC_ARG_ENABLE(python, [ --enable-python Turn on Python plugins (default=no)],enable_python=$enableval,enable_python=no)
|
||||
AC_ARG_ENABLE(ruby, [ --enable-ruby Turn on Ruby plugins (default=no)],enable_ruby=$enableval,enable_ruby=no)
|
||||
AC_ARG_ENABLE(plugins, [ --disable-plugins Turn off plugins support (default=yes)],enable_plugins=$enableval,enable_plugins=yes)
|
||||
AC_ARG_ENABLE(perl, [ --enable-perl Turn on Perl script plugin (default=no)],enable_perl=$enableval,enable_perl=no)
|
||||
AC_ARG_ENABLE(python, [ --enable-python Turn on Python script plugin (default=no)],enable_python=$enableval,enable_python=no)
|
||||
AC_ARG_ENABLE(ruby, [ --enable-ruby Turn on Ruby script plugin (default=no)],enable_ruby=$enableval,enable_ruby=no)
|
||||
AC_ARG_ENABLE(gnutls, [ --disable-gnutls Turn off gnutls support (default=auto)],enable_gnutls=$enableval,enable_gnutls=yes)
|
||||
AC_ARG_WITH(debug, [ --with-debug Debugging: 0=no debug, 1=debug compilation, 2=debug compilation + verbose msgs (default=0)],debug=$withval,debug=0)
|
||||
|
||||
enable_plugins="no"
|
||||
|
||||
AM_CONDITIONAL(GUI_NCURSES, test "$enable_ncurses" = "yes")
|
||||
AM_CONDITIONAL(GUI_WXWIDGETS, test "$enable_wxwidgets" = "yes")
|
||||
AM_CONDITIONAL(GUI_GTK, test "$enable_gtk" = "yes")
|
||||
AM_CONDITIONAL(GUI_QT, test "$enable_qt" = "yes")
|
||||
AM_CONDITIONAL(PLUGINS, test "$enable_plugins" = "yes")
|
||||
AM_CONDITIONAL(PLUGIN_PERL, test "$enable_perl" = "yes")
|
||||
AM_CONDITIONAL(PLUGIN_PYTHON, test "$enable_python" = "yes")
|
||||
AM_CONDITIONAL(PLUGIN_RUBY, test "$enable_ruby" = "yes")
|
||||
AM_CONDITIONAL(HAVE_GNUTLS, test "$enable_gnutls" = "yes")
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# GUI
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
if test "x$enable_ncurses" = "xyes" ; then
|
||||
if test "$LIBNCURSES_FOUND" = "0" ; then
|
||||
AC_MSG_ERROR([
|
||||
@@ -136,6 +147,10 @@ if test "x$enable_gtk" = "xyes" ; then
|
||||
AC_SUBST(GTK_LIBS)
|
||||
fi
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# plugins
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
PLUGINS_LIBS=
|
||||
|
||||
if test "x$enable_perl" = "xyes" ; then
|
||||
@@ -169,7 +184,7 @@ it with your software package manager.])
|
||||
PERL_LIB_TEST=`PT=perltest.c ; echo "int main() { return 0; }" > $PT ; $CC -Wall $PT -o $PT.out $($PERL -MExtUtils::Embed -e ldopts) 1>/dev/null 2>&1; echo $?; rm -f $PT $PT.out 1>/dev/null 2>&1`
|
||||
|
||||
if test "x$PERL_LIB_TEST" = "x0" ; then
|
||||
PLUGINS_LIBS="$PLUGINS_LIBS ../../plugins/perl/lib_weechat_perl.a `$PERL -MExtUtils::Embed -e ldopts`"
|
||||
PERL_LFLAGS=`$PERL -MExtUtils::Embed -e ldopts`
|
||||
else
|
||||
AC_MSG_ERROR([
|
||||
*** Perl library couldn't be found in your system.
|
||||
@@ -178,6 +193,7 @@ it with your software package manager.])
|
||||
AC_MSG_RESULT(found)
|
||||
|
||||
AC_SUBST(PERL_CFLAGS)
|
||||
AC_SUBST(PERL_LFLAGS)
|
||||
AC_DEFINE(PLUGIN_PERL)
|
||||
fi
|
||||
|
||||
@@ -220,8 +236,8 @@ if test "x$enable_python" = "xyes" ; then
|
||||
fi
|
||||
AC_MSG_RESULT(found)
|
||||
|
||||
PLUGINS_LIBS="$PLUGINS_LIBS ../../plugins/python/lib_weechat_python.a $PYTHON_LFLAGS"
|
||||
AC_SUBST(PYTHON_CFLAGS)
|
||||
AC_SUBST(PYTHON_LFLAGS)
|
||||
AC_DEFINE(PLUGIN_PYTHON)
|
||||
fi
|
||||
|
||||
@@ -232,17 +248,32 @@ if test "x$enable_ruby" = "xyes" ; then
|
||||
|
||||
RUBY_CFLAGS=-I`ruby -rrbconfig -e "puts Config::CONFIG[['archdir']]"`
|
||||
RUBY_LFLAGS=`ruby -rrbconfig -e "puts Config::CONFIG[['LIBRUBYARG_SHARED']]"`
|
||||
PLUGINS_LIBS="$PLUGINS_LIBS ../../plugins/ruby/lib_weechat_ruby.a $RUBY_LFLAGS"
|
||||
AC_SUBST(RUBY_CFLAGS)
|
||||
AC_SUBST(RUBY_LFLAGS)
|
||||
AC_DEFINE(PLUGIN_RUBY)
|
||||
fi
|
||||
|
||||
if test "x$enable_plugins" = "xyes" ; then
|
||||
AC_DEFINE(PLUGINS)
|
||||
AC_CHECK_FUNCS(dlopen, LIBDL_FOUND=yes, LIBDL_FOUND=no)
|
||||
if test "$LIBDL_FOUND" != "yes"; then
|
||||
AC_CHECK_LIB(dl, dlopen, LIBDL_FOUND=yes, LIBDL_FOUND=no)
|
||||
fi
|
||||
if test "$LIBDL_FOUND" = "yes"; then
|
||||
PLUGINS_LIBS="../../plugins/lib_weechat_plugins.a -ldl"
|
||||
AC_DEFINE(PLUGINS)
|
||||
else
|
||||
AC_MSG_ERROR([
|
||||
*** "dl" library (dynamic library loader) couldn't be found in your system.
|
||||
*** Try to install it with your software package manager or disable plugins.])
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_SUBST(PLUGINS_LIBS)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# gnutls
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
if test "x$enable_gnutls" = "xyes" ; then
|
||||
found_gnutls="no"
|
||||
AM_PATH_LIBGNUTLS( 1.0.0, found_gnutls=yes, AC_MSG_WARN([[
|
||||
@@ -257,6 +288,29 @@ if test "x$enable_gnutls" = "xyes" ; then
|
||||
enable_gnutls="no"
|
||||
fi
|
||||
fi
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# general vars
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
if test "x$prefix" = "xNONE" ; then
|
||||
prefix="$ac_default_prefix"
|
||||
fi
|
||||
|
||||
if test "x$exec_prefix" = "xNONE" ; then
|
||||
exec_prefix="$prefix"
|
||||
fi
|
||||
|
||||
AC_DEFINE_UNQUOTED(PREFIX, "${prefix}")
|
||||
|
||||
WEECHAT_LIBDIR=`eval echo ${libdir}/weechat`
|
||||
AC_DEFINE_UNQUOTED(WEECHAT_LIBDIR, "$WEECHAT_LIBDIR")
|
||||
|
||||
WEECHAT_SHAREDIR=`eval echo ${datadir}/weechat`
|
||||
AC_DEFINE_UNQUOTED(WEECHAT_SHAREDIR, "$WEECHAT_SHAREDIR")
|
||||
|
||||
weechat_libdir=${libdir}/weechat
|
||||
AC_SUBST(weechat_libdir)
|
||||
|
||||
CFLAGS=`echo $CFLAGS | sed s/-g//g`
|
||||
if test "x$CFLAGS" = "x" ; then
|
||||
@@ -272,19 +326,23 @@ if test "x$debug" = "x2" ; then
|
||||
AC_DEFINE(DEBUG)
|
||||
fi
|
||||
|
||||
dnl For FreeBSD
|
||||
# for FreeBSD
|
||||
LIBS="$LIBS $INTLLIBS"
|
||||
CFLAGS="$CFLAGS $CPPFLAGS"
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# output Makefiles
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
AC_OUTPUT([Makefile
|
||||
doc/Makefile
|
||||
src/Makefile
|
||||
src/common/Makefile
|
||||
src/irc/Makefile
|
||||
src/plugins/Makefile
|
||||
src/plugins/perl/Makefile
|
||||
src/plugins/python/Makefile
|
||||
src/plugins/ruby/Makefile
|
||||
src/plugins/scripts/Makefile
|
||||
src/plugins/scripts/perl/Makefile
|
||||
src/plugins/scripts/python/Makefile
|
||||
src/gui/Makefile
|
||||
src/gui/curses/Makefile
|
||||
src/gui/wxwidgets/Makefile
|
||||
@@ -293,8 +351,9 @@ AC_OUTPUT([Makefile
|
||||
intl/Makefile
|
||||
po/Makefile.in])
|
||||
|
||||
echo
|
||||
echo $PACKAGE $VERSION
|
||||
# ------------------------------------------------------------------------------
|
||||
# end message
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
listgui=
|
||||
if test "x$enable_ncurses" = "xyes" ; then
|
||||
@@ -325,19 +384,17 @@ if test "x$debug" = "x2" ; then
|
||||
msg_debug_verbose="yes"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo Interfaces.................... :$listgui
|
||||
echo
|
||||
echo Build with Plugin support..... : $enable_plugins
|
||||
echo Build with Perl support....... : $enable_perl
|
||||
echo Build with Python support..... : $enable_python
|
||||
echo Build with Ruby support....... : $enable_ruby
|
||||
echo Build with GNUtls support..... : $enable_gnutls
|
||||
echo
|
||||
echo Compile with debug info....... : $msg_debug_compiler
|
||||
echo Print debugging messages...... : $msg_debug_verbose
|
||||
echo
|
||||
eval eval echo WeeChat will be installed in $bindir.
|
||||
echo
|
||||
echo configure complete, now type \'make\' to build WeeChat
|
||||
echo
|
||||
echo ""
|
||||
echo "Interfaces.................... :$listgui"
|
||||
echo "Build with GNUtls support..... : $enable_gnutls"
|
||||
echo "Build with Plugin support..... : $enable_plugins"
|
||||
echo " Perl plugin..... : $enable_perl"
|
||||
echo " Python plugin... : $enable_python"
|
||||
echo " Ruby plugin..... : $enable_ruby"
|
||||
echo "Compile with debug info....... : $msg_debug_compiler"
|
||||
echo "Print debugging messages...... : $msg_debug_verbose"
|
||||
echo ""
|
||||
eval echo "WeeChat will be installed in $bindir."
|
||||
echo ""
|
||||
echo "configure complete, now type 'make' to build WeeChat $VERSION"
|
||||
echo ""
|
||||
|
||||
+1
-6
@@ -8,14 +8,9 @@
|
||||
./src/irc/irc-dcc.c
|
||||
./src/irc/irc-ignore.c
|
||||
./src/irc/irc.h
|
||||
./src/plugins/perl/wee-perl.c
|
||||
./src/plugins/perl/wee-perl.h
|
||||
./src/plugins/python/wee-python.c
|
||||
./src/plugins/python/wee-python.h
|
||||
./src/plugins/ruby/wee-ruby.c
|
||||
./src/plugins/ruby/wee-ruby.h
|
||||
./src/plugins/plugins.c
|
||||
./src/plugins/plugins.h
|
||||
./src/plugins/weechat-plugin.h
|
||||
./src/gui/curses/gui-input.c
|
||||
./src/gui/curses/gui-display.c
|
||||
./src/gui/gtk/gui-display.c
|
||||
|
||||
+609
-669
File diff suppressed because it is too large
Load Diff
+224
-480
@@ -89,21 +89,11 @@ t_weechat_command weechat_commands[] =
|
||||
"functions: list internal functions for key bindings\n"
|
||||
"reset: restore bindings to the default values and delete ALL personal binding (use carefully!)"),
|
||||
0, MAX_ARGS, NULL, weechat_cmd_key },
|
||||
{ "perl", N_("list/load/unload Perl scripts"),
|
||||
{ "plugin", N_("list/load/unload plugins"),
|
||||
N_("[load filename] | [autoload] | [reload] | [unload]"),
|
||||
N_("filename: Perl script (file) to load\n\n"
|
||||
"Without argument, /perl command lists all loaded Perl scripts."),
|
||||
0, 2, weechat_cmd_perl, NULL },
|
||||
{ "python", N_("list/load/unload Python scripts"),
|
||||
N_("[load filename] | [autoload] | [reload] | [unload]"),
|
||||
N_("filename: Python script (file) to load\n\n"
|
||||
"Without argument, /python command lists all loaded Python scripts."),
|
||||
0, 2, weechat_cmd_python, NULL },
|
||||
{ "ruby", N_("list/load/unload Ruby scripts"),
|
||||
N_("[load filename] | [autoload] | [reload] | [unload]"),
|
||||
N_("filename: Ruby script (file) to load\n\n"
|
||||
"Without argument, /ruby command lists all loaded Ruby scripts."),
|
||||
0, 2, weechat_cmd_ruby, NULL },
|
||||
N_("filename: WeeChat plugin (file) to load\n\n"
|
||||
"Without argument, /plugin command lists all loaded plugins."),
|
||||
0, 2, weechat_cmd_plugin, NULL },
|
||||
{ "server", N_("list, add or remove servers"),
|
||||
N_("[servername] | "
|
||||
"[servername hostname port [-auto | -noauto] [-ipv6] [-ssl] [-pwd password] [-nicks nick1 "
|
||||
@@ -381,7 +371,7 @@ alias_free_all ()
|
||||
*/
|
||||
|
||||
char **
|
||||
explode_string (/*@null@*/ char *string, char *separators, int num_items_max,
|
||||
explode_string (char *string, char *separators, int num_items_max,
|
||||
int *num_items)
|
||||
{
|
||||
int i, n_items;
|
||||
@@ -461,6 +451,23 @@ explode_string (/*@null@*/ char *string, char *separators, int num_items_max,
|
||||
return array;
|
||||
}
|
||||
|
||||
/*
|
||||
* free_exploded_string: free an exploded string
|
||||
*/
|
||||
|
||||
void
|
||||
free_exploded_string (char **exploded_string)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (exploded_string)
|
||||
{
|
||||
for (i = 0; exploded_string[i]; i++)
|
||||
free (exploded_string[i]);
|
||||
free (exploded_string);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* exec_weechat_command: executes a command (WeeChat internal or IRC)
|
||||
* returns: 1 if command was executed succesfully
|
||||
@@ -470,7 +477,7 @@ explode_string (/*@null@*/ char *string, char *separators, int num_items_max,
|
||||
int
|
||||
exec_weechat_command (t_irc_server *server, char *string)
|
||||
{
|
||||
int i, j, argc, return_code, length1, length2;
|
||||
int i, argc, return_code, length1, length2;
|
||||
char *command, *pos, *ptr_args, **argv, *alias_command;
|
||||
t_weechat_alias *ptr_alias;
|
||||
|
||||
@@ -502,7 +509,11 @@ exec_weechat_command (t_irc_server *server, char *string)
|
||||
ptr_args = NULL;
|
||||
}
|
||||
|
||||
if (!plugin_exec_command (command + 1, (server) ? server->name : "", ptr_args))
|
||||
#ifdef PLUGINS
|
||||
if (!plugin_cmd_handler_exec ((server) ? server->name : "", command + 1, ptr_args))
|
||||
#else
|
||||
if (1)
|
||||
#endif
|
||||
{
|
||||
argv = explode_string (ptr_args, " ", 0, &argc);
|
||||
|
||||
@@ -556,12 +567,7 @@ exec_weechat_command (t_irc_server *server, char *string)
|
||||
WEECHAT_ERROR, command + 1);
|
||||
}
|
||||
}
|
||||
if (argv)
|
||||
{
|
||||
for (j = 0; argv[j]; j++)
|
||||
free (argv[j]);
|
||||
free (argv);
|
||||
}
|
||||
free_exploded_string (argv);
|
||||
free (command);
|
||||
return 1;
|
||||
}
|
||||
@@ -626,12 +632,7 @@ exec_weechat_command (t_irc_server *server, char *string)
|
||||
WEECHAT_ERROR, command + 1);
|
||||
}
|
||||
}
|
||||
if (argv)
|
||||
{
|
||||
for (j = 0; argv[j]; j++)
|
||||
free (argv[j]);
|
||||
free (argv);
|
||||
}
|
||||
free_exploded_string (argv);
|
||||
free (command);
|
||||
return 1;
|
||||
}
|
||||
@@ -659,12 +660,7 @@ exec_weechat_command (t_irc_server *server, char *string)
|
||||
else
|
||||
(void) exec_weechat_command (server, ptr_alias->alias_command);
|
||||
|
||||
if (argv)
|
||||
{
|
||||
for (j = 0; argv[j]; j++)
|
||||
free (argv[j]);
|
||||
free (argv);
|
||||
}
|
||||
free_exploded_string (argv);
|
||||
free (command);
|
||||
return 1;
|
||||
}
|
||||
@@ -674,12 +670,7 @@ exec_weechat_command (t_irc_server *server, char *string)
|
||||
_("%s unknown command \"%s\" (type /help for help)\n"),
|
||||
WEECHAT_ERROR,
|
||||
command + 1);
|
||||
if (argv)
|
||||
{
|
||||
for (j = 0; argv[j]; j++)
|
||||
free (argv[j]);
|
||||
free (argv);
|
||||
}
|
||||
free_exploded_string (argv);
|
||||
}
|
||||
free (command);
|
||||
return 0;
|
||||
@@ -767,7 +758,9 @@ user_command (t_irc_server *server, t_gui_buffer *buffer, char *command)
|
||||
snprintf (plugin_args, plugin_args_length,
|
||||
"localhost PRIVMSG %s :%s",
|
||||
CHANNEL(buffer)->name, command);
|
||||
plugin_event_msg ("privmsg", server->name, plugin_args);
|
||||
#ifdef PLUGINS
|
||||
plugin_msg_handler_exec (server->name, "privmsg", plugin_args);
|
||||
#endif
|
||||
free (plugin_args);
|
||||
}
|
||||
else
|
||||
@@ -1294,88 +1287,144 @@ int
|
||||
weechat_cmd_help (int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
#ifdef PLUGINS
|
||||
t_weechat_plugin *ptr_plugin;
|
||||
t_plugin_cmd_handler *ptr_cmd_handler;
|
||||
#endif
|
||||
|
||||
if (argc == 0)
|
||||
switch (argc)
|
||||
{
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("%s internal commands:\n"), PACKAGE_NAME);
|
||||
for (i = 0; weechat_commands[i].command_name; i++)
|
||||
{
|
||||
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " %s",
|
||||
weechat_commands[i].command_name);
|
||||
gui_printf (NULL, " - %s\n",
|
||||
_(weechat_commands[i].command_description));
|
||||
}
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("IRC commands:\n"));
|
||||
for (i = 0; irc_commands[i].command_name; i++)
|
||||
{
|
||||
if (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg)
|
||||
case 0:
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("%s internal commands:\n"), PACKAGE_NAME);
|
||||
for (i = 0; weechat_commands[i].command_name; i++)
|
||||
{
|
||||
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " %s",
|
||||
irc_commands[i].command_name);
|
||||
gui_printf (NULL, " - %s\n",
|
||||
_(irc_commands[i].command_description));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (argc == 1)
|
||||
{
|
||||
for (i = 0; weechat_commands[i].command_name; i++)
|
||||
{
|
||||
if (ascii_strcasecmp (weechat_commands[i].command_name, argv[0]) == 0)
|
||||
{
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, "[w]");
|
||||
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " /%s",
|
||||
weechat_commands[i].command_name);
|
||||
if (weechat_commands[i].arguments &&
|
||||
weechat_commands[i].arguments[0])
|
||||
gui_printf (NULL, " %s\n",
|
||||
_(weechat_commands[i].arguments));
|
||||
else
|
||||
gui_printf (NULL, "\n");
|
||||
if (weechat_commands[i].command_description &&
|
||||
weechat_commands[i].command_description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
_(weechat_commands[i].command_description));
|
||||
if (weechat_commands[i].arguments_description &&
|
||||
weechat_commands[i].arguments_description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
_(weechat_commands[i].arguments_description));
|
||||
return 0;
|
||||
gui_printf (NULL, " - %s\n",
|
||||
_(weechat_commands[i].command_description));
|
||||
}
|
||||
}
|
||||
for (i = 0; irc_commands[i].command_name; i++)
|
||||
{
|
||||
if ((ascii_strcasecmp (irc_commands[i].command_name, argv[0]) == 0)
|
||||
&& (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg))
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("IRC commands:\n"));
|
||||
for (i = 0; irc_commands[i].command_name; i++)
|
||||
{
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, "[i]");
|
||||
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " /%s",
|
||||
irc_commands[i].command_name);
|
||||
if (irc_commands[i].arguments &&
|
||||
irc_commands[i].arguments[0])
|
||||
gui_printf (NULL, " %s\n",
|
||||
_(irc_commands[i].arguments));
|
||||
else
|
||||
gui_printf (NULL, "\n");
|
||||
if (irc_commands[i].command_description &&
|
||||
irc_commands[i].command_description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
if (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg)
|
||||
{
|
||||
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " %s",
|
||||
irc_commands[i].command_name);
|
||||
gui_printf (NULL, " - %s\n",
|
||||
_(irc_commands[i].command_description));
|
||||
if (irc_commands[i].arguments_description &&
|
||||
irc_commands[i].arguments_description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
_(irc_commands[i].arguments_description));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("No help available, \"%s\" is an unknown command\n"),
|
||||
argv[0]);
|
||||
#ifdef PLUGINS
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("Plugin commands:\n"));
|
||||
for (ptr_plugin = weechat_plugins; ptr_plugin;
|
||||
ptr_plugin = ptr_plugin->next_plugin)
|
||||
{
|
||||
for (ptr_cmd_handler = ptr_plugin->cmd_handlers; ptr_cmd_handler;
|
||||
ptr_cmd_handler = ptr_cmd_handler->next_handler)
|
||||
{
|
||||
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " %s",
|
||||
ptr_cmd_handler->command);
|
||||
if (ptr_cmd_handler->description
|
||||
&& ptr_cmd_handler->description[0])
|
||||
gui_printf (NULL, " - %s",
|
||||
ptr_cmd_handler->description);
|
||||
gui_printf (NULL, "\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case 1:
|
||||
for (i = 0; weechat_commands[i].command_name; i++)
|
||||
{
|
||||
if (ascii_strcasecmp (weechat_commands[i].command_name, argv[0]) == 0)
|
||||
{
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, "[w]");
|
||||
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " /%s",
|
||||
weechat_commands[i].command_name);
|
||||
if (weechat_commands[i].arguments &&
|
||||
weechat_commands[i].arguments[0])
|
||||
gui_printf (NULL, " %s\n",
|
||||
_(weechat_commands[i].arguments));
|
||||
else
|
||||
gui_printf (NULL, "\n");
|
||||
if (weechat_commands[i].command_description &&
|
||||
weechat_commands[i].command_description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
_(weechat_commands[i].command_description));
|
||||
if (weechat_commands[i].arguments_description &&
|
||||
weechat_commands[i].arguments_description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
_(weechat_commands[i].arguments_description));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
for (i = 0; irc_commands[i].command_name; i++)
|
||||
{
|
||||
if ((ascii_strcasecmp (irc_commands[i].command_name, argv[0]) == 0)
|
||||
&& (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg))
|
||||
{
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, "[i]");
|
||||
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " /%s",
|
||||
irc_commands[i].command_name);
|
||||
if (irc_commands[i].arguments &&
|
||||
irc_commands[i].arguments[0])
|
||||
gui_printf (NULL, " %s\n",
|
||||
_(irc_commands[i].arguments));
|
||||
else
|
||||
gui_printf (NULL, "\n");
|
||||
if (irc_commands[i].command_description &&
|
||||
irc_commands[i].command_description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
_(irc_commands[i].command_description));
|
||||
if (irc_commands[i].arguments_description &&
|
||||
irc_commands[i].arguments_description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
_(irc_commands[i].arguments_description));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#ifdef PLUGINS
|
||||
for (ptr_plugin = weechat_plugins; ptr_plugin;
|
||||
ptr_plugin = ptr_plugin->next_plugin)
|
||||
{
|
||||
for (ptr_cmd_handler = ptr_plugin->cmd_handlers; ptr_cmd_handler;
|
||||
ptr_cmd_handler = ptr_cmd_handler->next_handler)
|
||||
{
|
||||
if (ascii_strcasecmp (ptr_cmd_handler->command, argv[0]) == 0)
|
||||
{
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, "[p]");
|
||||
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " /%s",
|
||||
ptr_cmd_handler->command);
|
||||
if (ptr_cmd_handler->arguments &&
|
||||
ptr_cmd_handler->arguments[0])
|
||||
gui_printf (NULL, " %s\n",
|
||||
ptr_cmd_handler->arguments);
|
||||
else
|
||||
gui_printf (NULL, "\n");
|
||||
if (ptr_cmd_handler->description &&
|
||||
ptr_cmd_handler->description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
ptr_cmd_handler->description);
|
||||
if (ptr_cmd_handler->arguments_description &&
|
||||
ptr_cmd_handler->arguments_description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
ptr_cmd_handler->arguments_description);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("No help available, \"%s\" is an unknown command\n"),
|
||||
argv[0]);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1601,92 +1650,82 @@ weechat_cmd_key (char *arguments)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_cmd_perl: list/load/unload Perl scripts
|
||||
* weechat_cmd_plugin: list/load/unload WeeChat plugins
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_cmd_perl (int argc, char **argv)
|
||||
weechat_cmd_plugin (int argc, char **argv)
|
||||
{
|
||||
#ifdef PLUGIN_PERL
|
||||
t_plugin_script *ptr_plugin_script;
|
||||
t_plugin_handler *ptr_plugin_handler;
|
||||
int handler_found, path_length;
|
||||
char *path_script;
|
||||
#ifdef PLUGINS
|
||||
t_weechat_plugin *ptr_plugin;
|
||||
t_plugin_msg_handler *ptr_msg_handler;
|
||||
t_plugin_cmd_handler *ptr_cmd_handler;
|
||||
|
||||
switch (argc)
|
||||
{
|
||||
case 0:
|
||||
/* list registered Perl scripts */
|
||||
/* list plugins */
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("Registered %s scripts:\n"), "Perl");
|
||||
if (perl_scripts)
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _("Plugins loaded:\n"));
|
||||
for (ptr_plugin = weechat_plugins; ptr_plugin;
|
||||
ptr_plugin = ptr_plugin->next_plugin)
|
||||
{
|
||||
for (ptr_plugin_script = perl_scripts; ptr_plugin_script;
|
||||
ptr_plugin_script = ptr_plugin_script->next_script)
|
||||
/* plugin info */
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, " %s v%s - %s (%s)\n",
|
||||
ptr_plugin->name,
|
||||
ptr_plugin->version,
|
||||
ptr_plugin->description,
|
||||
ptr_plugin->filename);
|
||||
|
||||
/* message handlers */
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" message handlers:\n"));
|
||||
for (ptr_msg_handler = ptr_plugin->msg_handlers;
|
||||
ptr_msg_handler;
|
||||
ptr_msg_handler = ptr_msg_handler->next_handler)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, " %s v%s%s%s\n",
|
||||
ptr_plugin_script->name,
|
||||
ptr_plugin_script->version,
|
||||
(ptr_plugin_script->description[0]) ? " - " : "",
|
||||
ptr_plugin_script->description);
|
||||
gui_printf (NULL, _(" IRC(%s)\n"),
|
||||
ptr_msg_handler->irc_command);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (none)\n"));
|
||||
}
|
||||
|
||||
/* list Perl message handlers */
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("%s message handlers:\n"), "Perl");
|
||||
handler_found = 0;
|
||||
for (ptr_plugin_handler = plugin_msg_handlers; ptr_plugin_handler;
|
||||
ptr_plugin_handler = ptr_plugin_handler->next_handler)
|
||||
{
|
||||
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PERL)
|
||||
if (!ptr_plugin->msg_handlers)
|
||||
{
|
||||
handler_found = 1;
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" IRC(%s) => %s(%s)\n"),
|
||||
ptr_plugin_handler->name,
|
||||
"Perl",
|
||||
ptr_plugin_handler->function_name);
|
||||
gui_printf (NULL, _(" (no message handler)\n"));
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
{
|
||||
|
||||
/* command handlers */
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (none)\n"));
|
||||
}
|
||||
|
||||
/* list Perl command handlers */
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("%s command handlers:\n"), "Perl");
|
||||
handler_found = 0;
|
||||
for (ptr_plugin_handler = plugin_cmd_handlers; ptr_plugin_handler;
|
||||
ptr_plugin_handler = ptr_plugin_handler->next_handler)
|
||||
{
|
||||
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PERL)
|
||||
gui_printf (NULL, _(" command handlers:\n"));
|
||||
for (ptr_cmd_handler = ptr_plugin->cmd_handlers;
|
||||
ptr_cmd_handler;
|
||||
ptr_cmd_handler = ptr_cmd_handler->next_handler)
|
||||
{
|
||||
handler_found = 1;
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" Command /%s => %s(%s)\n"),
|
||||
ptr_plugin_handler->name,
|
||||
"Perl",
|
||||
ptr_plugin_handler->function_name);
|
||||
gui_printf (NULL, " /%s",
|
||||
ptr_cmd_handler->command);
|
||||
if (ptr_cmd_handler->description
|
||||
&& ptr_cmd_handler->description[0])
|
||||
gui_printf (NULL, " (%s)",
|
||||
ptr_cmd_handler->description);
|
||||
gui_printf (NULL, "\n");
|
||||
}
|
||||
if (!ptr_plugin->cmd_handlers)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (no command handler)\n"));
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
if (!weechat_plugins)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (none)\n"));
|
||||
gui_printf (NULL, _(" (no plugin)\n"));
|
||||
}
|
||||
|
||||
break;
|
||||
case 1:
|
||||
if (ascii_strcasecmp (argv[0], "autoload") == 0)
|
||||
/*if (ascii_strcasecmp (argv[0], "autoload") == 0)
|
||||
plugin_auto_load (PLUGIN_TYPE_PERL, "perl/autoload");
|
||||
else if (ascii_strcasecmp (argv[0], "reload") == 0)
|
||||
{
|
||||
@@ -1694,337 +1733,42 @@ weechat_cmd_perl (int argc, char **argv)
|
||||
plugin_auto_load (PLUGIN_TYPE_PERL, "perl/autoload");
|
||||
}
|
||||
else if (ascii_strcasecmp (argv[0], "unload") == 0)
|
||||
plugin_unload (PLUGIN_TYPE_PERL, NULL);
|
||||
plugin_unload (PLUGIN_TYPE_PERL, NULL);*/
|
||||
break;
|
||||
case 2:
|
||||
if (ascii_strcasecmp (argv[0], "load") == 0)
|
||||
{
|
||||
/* load Perl script */
|
||||
if (strstr(argv[1], DIR_SEPARATOR))
|
||||
path_script = NULL;
|
||||
else
|
||||
{
|
||||
path_length = strlen (weechat_home) + strlen (argv[1]) + 7;
|
||||
path_script = (char *) malloc (path_length * sizeof (char));
|
||||
snprintf (path_script, path_length, "%s%s%s%s%s",
|
||||
weechat_home, DIR_SEPARATOR, "perl",
|
||||
DIR_SEPARATOR, argv[1]);
|
||||
}
|
||||
plugin_load (PLUGIN_TYPE_PERL,
|
||||
(path_script) ? path_script : argv[1]);
|
||||
if (path_script)
|
||||
free (path_script);
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s unknown option for \"%s\" command\n"),
|
||||
WEECHAT_ERROR, "perl");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s wrong argument count for \"%s\" command\n"),
|
||||
WEECHAT_ERROR, "perl");
|
||||
}
|
||||
#else
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("WeeChat was build without Perl support.\n"
|
||||
"Please rebuild WeeChat with "
|
||||
"\"--enable-perl\" option for ./configure script\n"));
|
||||
/* make gcc happy */
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
#endif /* PLUGIN_PERL */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_cmd_python: list/load/unload Python scripts
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_cmd_python (int argc, char **argv)
|
||||
{
|
||||
#ifdef PLUGIN_PYTHON
|
||||
t_plugin_script *ptr_plugin_script;
|
||||
t_plugin_handler *ptr_plugin_handler;
|
||||
int handler_found, path_length;
|
||||
char *path_script;
|
||||
|
||||
switch (argc)
|
||||
{
|
||||
case 0:
|
||||
/* list registered Python scripts */
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("Registered %s scripts:\n"), "Python");
|
||||
if (python_scripts)
|
||||
{
|
||||
for (ptr_plugin_script = python_scripts; ptr_plugin_script;
|
||||
ptr_plugin_script = ptr_plugin_script->next_script)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, " %s v%s%s%s\n",
|
||||
ptr_plugin_script->name,
|
||||
ptr_plugin_script->version,
|
||||
(ptr_plugin_script->description[0]) ? " - " : "",
|
||||
ptr_plugin_script->description);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (none)\n"));
|
||||
}
|
||||
|
||||
/* list Python message handlers */
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("%s message handlers:\n"), "Python");
|
||||
handler_found = 0;
|
||||
for (ptr_plugin_handler = plugin_msg_handlers; ptr_plugin_handler;
|
||||
ptr_plugin_handler = ptr_plugin_handler->next_handler)
|
||||
{
|
||||
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PYTHON)
|
||||
{
|
||||
handler_found = 1;
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" IRC(%s) => %s(%s)\n"),
|
||||
ptr_plugin_handler->name,
|
||||
"Python",
|
||||
ptr_plugin_handler->function_name);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (none)\n"));
|
||||
}
|
||||
|
||||
/* list Python command handlers */
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("%s command handlers:\n"), "Python");
|
||||
handler_found = 0;
|
||||
for (ptr_plugin_handler = plugin_cmd_handlers; ptr_plugin_handler;
|
||||
ptr_plugin_handler = ptr_plugin_handler->next_handler)
|
||||
{
|
||||
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PYTHON)
|
||||
{
|
||||
handler_found = 1;
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" Command /%s => %s(%s)\n"),
|
||||
ptr_plugin_handler->name,
|
||||
"Python",
|
||||
ptr_plugin_handler->function_name);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (none)\n"));
|
||||
}
|
||||
|
||||
break;
|
||||
case 1:
|
||||
if (ascii_strcasecmp (argv[0], "autoload") == 0)
|
||||
plugin_auto_load (PLUGIN_TYPE_PYTHON, "python/autoload");
|
||||
else if (ascii_strcasecmp (argv[0], "reload") == 0)
|
||||
{
|
||||
plugin_unload (PLUGIN_TYPE_PYTHON, NULL);
|
||||
plugin_auto_load (PLUGIN_TYPE_PYTHON, "python/autoload");
|
||||
/* load plugin */
|
||||
plugin_load (argv[1]);
|
||||
}
|
||||
else if (ascii_strcasecmp (argv[0], "unload") == 0)
|
||||
plugin_unload (PLUGIN_TYPE_PYTHON, NULL);
|
||||
break;
|
||||
case 2:
|
||||
if (ascii_strcasecmp (argv[0], "load") == 0)
|
||||
{
|
||||
/* load Python script */
|
||||
if (strstr(argv[1], DIR_SEPARATOR))
|
||||
path_script = NULL;
|
||||
else
|
||||
{
|
||||
path_length = strlen (weechat_home) + strlen (argv[1]) + 9;
|
||||
path_script = (char *) malloc (path_length * sizeof (char));
|
||||
snprintf (path_script, path_length, "%s%s%s%s%s",
|
||||
weechat_home, DIR_SEPARATOR, "python",
|
||||
DIR_SEPARATOR, argv[1]);
|
||||
}
|
||||
plugin_load (PLUGIN_TYPE_PYTHON,
|
||||
(path_script) ? path_script : argv[1]);
|
||||
if (path_script)
|
||||
free (path_script);
|
||||
/* unload plugin */
|
||||
plugin_unload_name (argv[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s unknown option for \"%s\" command\n"),
|
||||
WEECHAT_ERROR, "python");
|
||||
WEECHAT_ERROR, "plugin");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s wrong argument count for \"%s\" command\n"),
|
||||
WEECHAT_ERROR, "python");
|
||||
WEECHAT_ERROR, "plugin");
|
||||
}
|
||||
#else
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("WeeChat was build without Python support.\n"
|
||||
"Please rebuild WeeChat with "
|
||||
"\"--enable-python\" option for ./configure script\n"));
|
||||
_("Command \"plugin\" is not available, WeeChat was built "
|
||||
"without plugins support.\n"));
|
||||
/* make gcc happy */
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
#endif /* PLUGIN_PYTHON */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_cmd_ruby: list/load/unload Ruby scripts
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_cmd_ruby (int argc, char **argv)
|
||||
{
|
||||
#ifdef PLUGIN_RUBY
|
||||
t_plugin_script *ptr_plugin_script;
|
||||
t_plugin_handler *ptr_plugin_handler;
|
||||
int handler_found, path_length;
|
||||
char *path_script;
|
||||
|
||||
switch (argc)
|
||||
{
|
||||
case 0:
|
||||
/* list registered Ruby scripts */
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("Registered %s scripts:\n"), "Ruby");
|
||||
if (ruby_scripts)
|
||||
{
|
||||
for (ptr_plugin_script = ruby_scripts; ptr_plugin_script;
|
||||
ptr_plugin_script = ptr_plugin_script->next_script)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, " %s v%s%s%s\n",
|
||||
ptr_plugin_script->name,
|
||||
ptr_plugin_script->version,
|
||||
(ptr_plugin_script->description[0]) ? " - " : "",
|
||||
ptr_plugin_script->description);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (none)\n"));
|
||||
}
|
||||
|
||||
/* list Ruby message handlers */
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("%s message handlers:\n"), "Ruby");
|
||||
handler_found = 0;
|
||||
for (ptr_plugin_handler = plugin_msg_handlers; ptr_plugin_handler;
|
||||
ptr_plugin_handler = ptr_plugin_handler->next_handler)
|
||||
{
|
||||
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_RUBY)
|
||||
{
|
||||
handler_found = 1;
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" IRC(%s) => %s(%s)\n"),
|
||||
ptr_plugin_handler->name,
|
||||
"Ruby",
|
||||
ptr_plugin_handler->function_name);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (none)\n"));
|
||||
}
|
||||
|
||||
/* list Ruby command handlers */
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("%s command handlers:\n"), "Ruby");
|
||||
handler_found = 0;
|
||||
for (ptr_plugin_handler = plugin_cmd_handlers; ptr_plugin_handler;
|
||||
ptr_plugin_handler = ptr_plugin_handler->next_handler)
|
||||
{
|
||||
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_RUBY)
|
||||
{
|
||||
handler_found = 1;
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" Command /%s => %s(%s)\n"),
|
||||
ptr_plugin_handler->name,
|
||||
"Ruby",
|
||||
ptr_plugin_handler->function_name);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (none)\n"));
|
||||
}
|
||||
|
||||
break;
|
||||
case 1:
|
||||
if (ascii_strcasecmp (argv[0], "autoload") == 0)
|
||||
plugin_auto_load (PLUGIN_TYPE_RUBY, "ruby/autoload");
|
||||
else if (ascii_strcasecmp (argv[0], "reload") == 0)
|
||||
{
|
||||
plugin_unload (PLUGIN_TYPE_RUBY, NULL);
|
||||
plugin_auto_load (PLUGIN_TYPE_RUBY, "ruby/autoload");
|
||||
}
|
||||
else if (ascii_strcasecmp (argv[0], "unload") == 0)
|
||||
plugin_unload (PLUGIN_TYPE_RUBY, NULL);
|
||||
break;
|
||||
case 2:
|
||||
if (ascii_strcasecmp (argv[0], "load") == 0)
|
||||
{
|
||||
/* load Ruby script */
|
||||
if (strstr(argv[1], DIR_SEPARATOR))
|
||||
path_script = NULL;
|
||||
else
|
||||
{
|
||||
path_length = strlen (weechat_home) + strlen (argv[1]) + 9;
|
||||
path_script = (char *) malloc (path_length * sizeof (char));
|
||||
snprintf (path_script, path_length, "%s%s%s%s%s",
|
||||
weechat_home, DIR_SEPARATOR, "ruby",
|
||||
DIR_SEPARATOR, argv[1]);
|
||||
}
|
||||
plugin_load (PLUGIN_TYPE_RUBY,
|
||||
(path_script) ? path_script : argv[1]);
|
||||
if (path_script)
|
||||
free (path_script);
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s unknown option for \"%s\" command\n"),
|
||||
WEECHAT_ERROR, "ruby");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s wrong argument count for \"%s\" command\n"),
|
||||
WEECHAT_ERROR, "ruby");
|
||||
}
|
||||
#else
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("WeeChat was build without Ruby support.\n"
|
||||
"Please rebuild WeeChat with "
|
||||
"\"--enable-ruby\" option for ./configure script\n"));
|
||||
/* make gcc happy */
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
#endif /* PLUGIN_RUBY */
|
||||
#endif /* PLUGINS */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -60,6 +60,8 @@ extern void command_index_build ();
|
||||
extern void command_index_free ();
|
||||
extern t_weechat_alias *alias_new (char *, char *);
|
||||
extern void alias_free_all ();
|
||||
extern char **explode_string (char *, char *, int, int *);
|
||||
extern void free_exploded_string (char **);
|
||||
extern int exec_weechat_command (t_irc_server *, char *);
|
||||
extern void user_command (t_irc_server *, t_gui_buffer *, char *);
|
||||
extern int weechat_cmd_alias (char *);
|
||||
@@ -72,9 +74,7 @@ extern int weechat_cmd_help (int, char **);
|
||||
extern void weechat_cmd_ignore_display (char *, t_irc_ignore *);
|
||||
extern int weechat_cmd_ignore (int, char **);
|
||||
extern int weechat_cmd_key (char *);
|
||||
extern int weechat_cmd_perl (int, char **);
|
||||
extern int weechat_cmd_python (int, char **);
|
||||
extern int weechat_cmd_ruby (int, char **);
|
||||
extern int weechat_cmd_plugin (int, char **);
|
||||
extern int weechat_cmd_save (int, char **);
|
||||
extern int weechat_cmd_server (int, char **);
|
||||
extern int weechat_cmd_set (char *);
|
||||
|
||||
+23
-2
@@ -34,6 +34,10 @@
|
||||
#include "weeconfig.h"
|
||||
#include "../irc/irc.h"
|
||||
|
||||
#ifdef PLUGINS
|
||||
#include "../plugins/plugins.h"
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* completion_init: init completion
|
||||
@@ -108,6 +112,10 @@ completion_build_list (t_completion *completion, void *channel)
|
||||
t_config_option *option;
|
||||
void *option_value;
|
||||
char option_string[2048];
|
||||
#ifdef PLUGINS
|
||||
t_weechat_plugin *ptr_plugin;
|
||||
t_plugin_cmd_handler *ptr_cmd_handler;
|
||||
#endif
|
||||
|
||||
/* WeeChat internal commands */
|
||||
|
||||
@@ -200,6 +208,20 @@ completion_build_list (t_completion *completion, void *channel)
|
||||
&completion->last_completion,
|
||||
irc_commands[i].command_name);
|
||||
}
|
||||
#ifdef PLUGINS
|
||||
for (ptr_plugin = weechat_plugins; ptr_plugin;
|
||||
ptr_plugin = ptr_plugin->next_plugin)
|
||||
{
|
||||
for (ptr_cmd_handler = ptr_plugin->cmd_handlers;
|
||||
ptr_cmd_handler;
|
||||
ptr_cmd_handler = ptr_cmd_handler->next_handler)
|
||||
{
|
||||
weelist_add (&completion->completion_list,
|
||||
&completion->last_completion,
|
||||
ptr_cmd_handler->command);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
if (ascii_strcasecmp (completion->base_command, "ignore") == 0)
|
||||
@@ -312,8 +334,7 @@ completion_build_list (t_completion *completion, void *channel)
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (((ascii_strcasecmp (completion->base_command, "perl") == 0)
|
||||
|| (ascii_strcasecmp (completion->base_command, "python") == 0))
|
||||
if ((ascii_strcasecmp (completion->base_command, "plugin") == 0)
|
||||
&& (completion->base_command_arg == 1))
|
||||
{
|
||||
weelist_add (&completion->completion_list,
|
||||
|
||||
+9
-49
@@ -9,7 +9,7 @@
|
||||
* ### Fast & light environment for Chat ###
|
||||
* ### ###
|
||||
* ### By FlashCode <flashcode@flashtux.org> ###
|
||||
### ###
|
||||
* ### ###
|
||||
* ### http://weechat.flashtux.org ###
|
||||
* ### ###
|
||||
* ############################################################################
|
||||
@@ -66,7 +66,10 @@
|
||||
#include "fifo.h"
|
||||
#include "../irc/irc.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
#ifdef PLUGINS
|
||||
#include "../plugins/plugins.h"
|
||||
#endif
|
||||
|
||||
|
||||
int quit_weechat; /* = 1 if quit request from user... why ? :'( */
|
||||
@@ -590,53 +593,6 @@ wee_create_home_dirs ()
|
||||
dir_length = strlen (weechat_home) + 64;
|
||||
dir_name = (char *) malloc (dir_length * sizeof (char));
|
||||
|
||||
#ifdef PLUGIN_PERL
|
||||
/* create "~/.weechat/perl" */
|
||||
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
|
||||
"perl");
|
||||
if (wee_create_dir (dir_name))
|
||||
{
|
||||
/* create "~/.weechat/perl/autoload" */
|
||||
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
|
||||
DIR_SEPARATOR, "perl", DIR_SEPARATOR, "autoload");
|
||||
wee_create_dir (dir_name);
|
||||
/* create "~/.weechat/perl/config" */
|
||||
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
|
||||
DIR_SEPARATOR, "perl", DIR_SEPARATOR, "config");
|
||||
wee_create_dir (dir_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_PYTHON
|
||||
/* create "~/.weechat/python" */
|
||||
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
|
||||
"python");
|
||||
if (wee_create_dir (dir_name))
|
||||
{
|
||||
/* create "~/.weechat/python/autoload" */
|
||||
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
|
||||
DIR_SEPARATOR, "python", DIR_SEPARATOR, "autoload");
|
||||
wee_create_dir (dir_name);
|
||||
/* create "~/.weechat/python/config" */
|
||||
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
|
||||
DIR_SEPARATOR, "python", DIR_SEPARATOR, "config");
|
||||
wee_create_dir (dir_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_RUBY
|
||||
/* create "~/.weechat/ruby" */
|
||||
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
|
||||
"ruby");
|
||||
if (wee_create_dir (dir_name))
|
||||
{
|
||||
/* create "~/.weechat/ruby/autoload" */
|
||||
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
|
||||
DIR_SEPARATOR, "ruby", DIR_SEPARATOR, "autoload");
|
||||
wee_create_dir (dir_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* create "~/.weechat/logs" */
|
||||
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
|
||||
"logs");
|
||||
@@ -925,14 +881,18 @@ main (int argc, char *argv[])
|
||||
|
||||
gui_init (); /* init WeeChat interface */
|
||||
weechat_welcome_message (); /* display WeeChat welcome message */
|
||||
plugin_init (); /* init plugin interface(s) */
|
||||
#ifdef PLUGINS
|
||||
plugin_init (); /* init plugin interface(s) */
|
||||
#endif
|
||||
/* auto-connect to servers */
|
||||
server_auto_connect (server_cmd_line);
|
||||
fifo_create (); /* create FIFO pipe for remote control */
|
||||
|
||||
gui_main_loop (); /* WeeChat main loop */
|
||||
|
||||
#ifdef PLUGINS
|
||||
plugin_end (); /* end plugin interface(s) */
|
||||
#endif
|
||||
server_disconnect_all (); /* disconnect from all servers */
|
||||
(void) config_write (NULL); /* save config file */
|
||||
command_index_free (); /* free commands index */
|
||||
|
||||
+33
-1
@@ -53,6 +53,7 @@ t_config_section config_sections[CONFIG_NUMBER_SECTIONS] =
|
||||
{ CONFIG_SECTION_IRC, "irc" },
|
||||
{ CONFIG_SECTION_DCC, "dcc" },
|
||||
{ CONFIG_SECTION_PROXY, "proxy" },
|
||||
{ CONFIG_SECTION_PLUGINS, "plugins" },
|
||||
{ CONFIG_SECTION_KEYS, "keys" },
|
||||
{ CONFIG_SECTION_ALIAS, "alias" },
|
||||
{ CONFIG_SECTION_IGNORE, "ignore" },
|
||||
@@ -747,6 +748,36 @@ t_config_option weechat_options_proxy[] =
|
||||
{ NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
/* config, plugins section */
|
||||
|
||||
char *cfg_plugins_path;
|
||||
char *cfg_plugins_autoload;
|
||||
char *cfg_plugins_extension;
|
||||
|
||||
t_config_option weechat_options_plugins[] =
|
||||
{ { "plugins_path", N_("path for searching plugins"),
|
||||
N_("path for searching plugins"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0,
|
||||
"~/.weechat/plugins", NULL, NULL, &cfg_plugins_path, config_change_noop },
|
||||
{ "plugins_autoload", N_("list of plugins to load automatically"),
|
||||
N_("comma separated list of plugins to load automatically at startup, "
|
||||
"\"*\" means all plugins found "
|
||||
"(names may be partial, for example \"perl\" is ok for \"libperl.so\")"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0,
|
||||
"*", NULL, NULL, &cfg_plugins_autoload, config_change_noop },
|
||||
{ "plugins_extension", N_("standard plugins extension in filename"),
|
||||
N_("standard plugins extension in filename, used for autoload "
|
||||
"(if empty, then all files are loaded when autoload is \"*\")"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0,
|
||||
#ifdef WIN32
|
||||
".dll",
|
||||
#else
|
||||
".so",
|
||||
#endif
|
||||
NULL, NULL, &cfg_plugins_extension, config_change_noop },
|
||||
{ NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
/* config, server section */
|
||||
|
||||
static t_irc_server cfg_server;
|
||||
@@ -836,7 +867,8 @@ t_config_option weechat_options_server[] =
|
||||
t_config_option *weechat_options[CONFIG_NUMBER_SECTIONS] =
|
||||
{ weechat_options_look, weechat_options_colors, weechat_options_history,
|
||||
weechat_options_log, weechat_options_irc, weechat_options_dcc,
|
||||
weechat_options_proxy, NULL, NULL, NULL, weechat_options_server
|
||||
weechat_options_proxy, weechat_options_plugins, NULL, NULL, NULL,
|
||||
weechat_options_server
|
||||
};
|
||||
|
||||
|
||||
|
||||
+10
-5
@@ -33,11 +33,12 @@
|
||||
#define CONFIG_SECTION_IRC 4
|
||||
#define CONFIG_SECTION_DCC 5
|
||||
#define CONFIG_SECTION_PROXY 6
|
||||
#define CONFIG_SECTION_KEYS 7
|
||||
#define CONFIG_SECTION_ALIAS 8
|
||||
#define CONFIG_SECTION_IGNORE 9
|
||||
#define CONFIG_SECTION_SERVER 10
|
||||
#define CONFIG_NUMBER_SECTIONS 11
|
||||
#define CONFIG_SECTION_PLUGINS 7
|
||||
#define CONFIG_SECTION_KEYS 8
|
||||
#define CONFIG_SECTION_ALIAS 9
|
||||
#define CONFIG_SECTION_IGNORE 10
|
||||
#define CONFIG_SECTION_SERVER 11
|
||||
#define CONFIG_NUMBER_SECTIONS 12
|
||||
|
||||
#define OPTION_TYPE_BOOLEAN 1 /* values: on/off */
|
||||
#define OPTION_TYPE_INT 2 /* values: from min to max */
|
||||
@@ -202,6 +203,10 @@ extern int cfg_proxy_port;
|
||||
extern char *cfg_proxy_username;
|
||||
extern char *cfg_proxy_password;
|
||||
|
||||
extern char *cfg_plugins_path;
|
||||
extern char *cfg_plugins_autoload;
|
||||
extern char *cfg_plugins_extension;
|
||||
|
||||
extern t_config_section config_sections [CONFIG_NUMBER_SECTIONS];
|
||||
extern t_config_option * weechat_options [CONFIG_NUMBER_SECTIONS];
|
||||
|
||||
|
||||
@@ -140,6 +140,9 @@ weelist_remove (t_weelist **weelist, t_weelist **last_weelist, t_weelist *elemen
|
||||
{
|
||||
t_weelist *new_weelist;
|
||||
|
||||
if (!element)
|
||||
return;
|
||||
|
||||
/* remove element from list */
|
||||
if (*last_weelist == element)
|
||||
*last_weelist = element->prev_weelist;
|
||||
|
||||
@@ -22,8 +22,8 @@ bin_PROGRAMS = weechat-curses
|
||||
weechat_curses_LDADD = ../gui-common.o ../gui-keyboard.o \
|
||||
../../common/lib_weechat_main.a \
|
||||
../../irc/lib_weechat_irc.a \
|
||||
$(PLUGINS_LIBS) \
|
||||
$(NCURSES_LIBS) \
|
||||
../../plugins/lib_weechat_plugins.a $(PLUGINS_LIBS) \
|
||||
$(GNUTLS_LIBS)
|
||||
|
||||
weechat_curses_SOURCES = gui-display.c \
|
||||
|
||||
+6
-1
@@ -179,8 +179,13 @@ irc_recv_command (t_irc_server *server, char *entire_line,
|
||||
return_code = (int) (irc_commands[i].recv_function) (server, host, nick, arguments);
|
||||
if (nick)
|
||||
free (nick);
|
||||
#ifdef PLUGINS
|
||||
if (!command_ignored)
|
||||
plugin_event_msg (irc_commands[i].command_name, server->name, entire_line);
|
||||
plugin_msg_handler_exec (server->name, irc_commands[i].command_name, entire_line);
|
||||
#else
|
||||
/* make gcc happy */
|
||||
(void) entire_line;
|
||||
#endif
|
||||
return return_code;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,20 +18,21 @@
|
||||
INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\"
|
||||
|
||||
if PLUGIN_PERL
|
||||
perl_dir = perl
|
||||
script_dir = scripts
|
||||
endif
|
||||
|
||||
if PLUGIN_PYTHON
|
||||
python_dir = python
|
||||
script_dir = scripts
|
||||
endif
|
||||
|
||||
if PLUGIN_RUBY
|
||||
ruby_dir = ruby
|
||||
script_dir = scripts
|
||||
endif
|
||||
|
||||
SUBDIRS = $(perl_dir) $(python_dir) $(ruby_dir)
|
||||
SUBDIRS = $(script_dir)
|
||||
|
||||
noinst_LIBRARIES = lib_weechat_plugins.a
|
||||
|
||||
lib_weechat_plugins_a_SOURCES = plugins.h \
|
||||
lib_weechat_plugins_a_SOURCES = weechat-plugin.h \
|
||||
plugins.h \
|
||||
plugins.c
|
||||
|
||||
+1196
-425
File diff suppressed because it is too large
Load Diff
+13
-57
@@ -21,68 +21,24 @@
|
||||
#ifndef __WEECHAT_PLUGINS_H
|
||||
#define __WEECHAT_PLUGINS_H 1
|
||||
|
||||
#include "weechat-plugin.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
#define PLUGIN_TYPE_PERL 0
|
||||
#define PLUGIN_TYPE_PYTHON 1
|
||||
#define PLUGIN_TYPE_RUBY 2
|
||||
typedef int (t_weechat_init_func) (t_weechat_plugin *);
|
||||
typedef void (t_weechat_end_func) (t_weechat_plugin *);
|
||||
|
||||
typedef struct t_plugin_script t_plugin_script;
|
||||
extern t_weechat_plugin *weechat_plugins;
|
||||
extern t_weechat_plugin *last_weechat_plugin;
|
||||
|
||||
struct t_plugin_script
|
||||
{
|
||||
char *name; /* name of script */
|
||||
char *version; /* version of script */
|
||||
char *shutdown_func; /* function when script ends */
|
||||
char *description; /* description of script */
|
||||
t_plugin_script *prev_script; /* link to previous Perl script */
|
||||
t_plugin_script *next_script; /* link to next Perl script */
|
||||
};
|
||||
|
||||
typedef struct t_plugin_handler t_plugin_handler;
|
||||
|
||||
struct t_plugin_handler
|
||||
{
|
||||
int plugin_type; /* plugin type (Perl, Python, Ruby) */
|
||||
char *name; /* name of IRC command (PRIVMSG, ..)
|
||||
or command (without first '/') */
|
||||
char *function_name; /* name of function (handler) */
|
||||
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 */
|
||||
};
|
||||
|
||||
extern t_plugin_handler *plugin_msg_handlers;
|
||||
extern t_plugin_handler *last_plugin_msg_handler;
|
||||
|
||||
extern t_plugin_handler *plugin_cmd_handlers;
|
||||
extern t_plugin_handler *last_plugin_cmd_handler;
|
||||
|
||||
#ifdef PLUGIN_PERL
|
||||
extern t_plugin_script *perl_scripts;
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_PYTHON
|
||||
extern t_plugin_script *python_scripts;
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_RUBY
|
||||
extern t_plugin_script *ruby_scripts;
|
||||
#endif
|
||||
|
||||
extern void plugin_auto_load (int, char *);
|
||||
extern t_weechat_plugin *plugin_search (char *);
|
||||
extern int plugin_msg_handler_exec (char *, char *, char *);
|
||||
extern int plugin_cmd_handler_exec (char *, char *, char *);
|
||||
extern t_weechat_plugin *plugin_load (char *);
|
||||
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_init ();
|
||||
extern void plugin_load (int, char *);
|
||||
extern void plugin_unload (int, char *);
|
||||
extern t_plugin_handler *plugin_handler_search (t_plugin_handler *, char *);
|
||||
extern void plugin_handler_add (t_plugin_handler **, t_plugin_handler **,
|
||||
int, char *, char *);
|
||||
extern void plugin_handler_free_all_type (t_plugin_handler **,
|
||||
t_plugin_handler **, int);
|
||||
extern void plugin_event_msg (char *, char *, char *);
|
||||
extern int plugin_exec_command (char *, char *, char *);
|
||||
extern t_gui_buffer *plugin_find_buffer (char *, char *);
|
||||
extern void plugin_end ();
|
||||
|
||||
#endif /* plugins.h */
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
# Copyright (c) 2003-2005 FlashCode <flashcode@flashtux.org>
|
||||
#
|
||||
# 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 2 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, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\"
|
||||
|
||||
noinst_LTLIBRARIES = lib_weechat_plugins_scripts.la
|
||||
|
||||
lib_weechat_plugins_scripts_la_SOURCES = weechat-script.h \
|
||||
weechat-script.c
|
||||
|
||||
if PLUGIN_PERL
|
||||
perl_dir = perl
|
||||
endif
|
||||
|
||||
if PLUGIN_PYTHON
|
||||
python_dir = python
|
||||
endif
|
||||
|
||||
if PLUGIN_RUBY
|
||||
#ruby_dir = ruby
|
||||
endif
|
||||
|
||||
SUBDIRS = . $(perl_dir) $(python_dir) $(ruby_dir)
|
||||
@@ -0,0 +1,26 @@
|
||||
# Copyright (c) 2003-2005 FlashCode <flashcode@flashtux.org>
|
||||
#
|
||||
# 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 2 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, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(PERL_CFLAGS)
|
||||
|
||||
libdir = ${weechat_libdir}/plugins
|
||||
|
||||
lib_LTLIBRARIES = libperl.la
|
||||
|
||||
libperl_la_SOURCES = weechat-perl.c
|
||||
libperl_la_LDFLAGS = -module
|
||||
libperl_la_LIBADD = ../lib_weechat_plugins_scripts.la $(PERL_LFLAGS)
|
||||
@@ -0,0 +1,739 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* weechat-perl.c: Perl plugin support for WeeChat */
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <EXTERN.h>
|
||||
#include <perl.h>
|
||||
#include <XSUB.h>
|
||||
#undef _
|
||||
#include "../../weechat-plugin.h"
|
||||
#include "../weechat-script.h"
|
||||
|
||||
|
||||
char plugin_name[] = "Perl";
|
||||
char plugin_version[] = "0.1";
|
||||
char plugin_description[] = "Perl scripts support";
|
||||
|
||||
t_weechat_plugin *perl_plugin;
|
||||
|
||||
t_plugin_script *perl_scripts = NULL;
|
||||
t_plugin_script *current_perl_script = NULL;
|
||||
|
||||
static PerlInterpreter *my_perl = NULL;
|
||||
|
||||
extern void boot_DynaLoader (pTHX_ CV* cv);
|
||||
|
||||
|
||||
/*
|
||||
* weechat_perl_exec: execute a Perl script
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_perl_exec (t_weechat_plugin *plugin,
|
||||
t_plugin_script *script,
|
||||
char *function, char *server, char *arguments)
|
||||
{
|
||||
char empty_server[1] = { '\0' };
|
||||
char *argv[3];
|
||||
unsigned int count;
|
||||
int return_code;
|
||||
SV *sv;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) script;
|
||||
|
||||
dSP;
|
||||
ENTER;
|
||||
SAVETMPS;
|
||||
PUSHMARK(sp);
|
||||
if (!server)
|
||||
argv[0] = empty_server;
|
||||
else
|
||||
argv[0] = server;
|
||||
argv[1] = arguments;
|
||||
argv[2] = NULL;
|
||||
count = perl_call_argv (function, G_EVAL | G_SCALAR, argv);
|
||||
SPAGAIN;
|
||||
|
||||
sv = GvSV (gv_fetchpv ("@", TRUE, SVt_PV));
|
||||
return_code = 1;
|
||||
if (SvTRUE (sv))
|
||||
{
|
||||
plugin->printf_server (plugin, "Perl error: %s", SvPV (sv, count));
|
||||
POPs;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (count != 1)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Perl error: too much values from \"%s\" (%d). Expected: 1.",
|
||||
function, count);
|
||||
}
|
||||
else
|
||||
return_code = POPi;
|
||||
}
|
||||
|
||||
PUTBACK;
|
||||
FREETMPS;
|
||||
LEAVE;
|
||||
|
||||
return return_code;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_handler: general message and command handler for Perl
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_perl_handler (t_weechat_plugin *plugin,
|
||||
char *server, char *command, char *arguments,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
/* make gcc happy */
|
||||
(void) command;
|
||||
|
||||
weechat_perl_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
handler_args, server, arguments);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::register: startup function for all WeeChat Perl scripts
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_register)
|
||||
{
|
||||
char *name, *version, *shutdown_func, *description;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) items;
|
||||
(void) cv;
|
||||
|
||||
if (items != 4)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"register\" function");
|
||||
XSRETURN (0);
|
||||
return;
|
||||
}
|
||||
|
||||
name = SvPV (ST (0), integer);
|
||||
version = SvPV (ST (1), integer);
|
||||
shutdown_func = SvPV (ST (2), integer);
|
||||
description = SvPV (ST (3), integer);
|
||||
|
||||
if (weechat_script_search (perl_plugin, &perl_scripts, name))
|
||||
{
|
||||
/* error: another script already exists with this name! */
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: unable to register "
|
||||
"\"%s\" script (another script "
|
||||
"already exists with this name)",
|
||||
name);
|
||||
XSRETURN (0);
|
||||
return;
|
||||
}
|
||||
|
||||
/* register script */
|
||||
current_perl_script = weechat_script_add (perl_plugin,
|
||||
&perl_scripts,
|
||||
"",
|
||||
name, version, shutdown_func,
|
||||
description);
|
||||
if (current_perl_script)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl: registered script \"%s\", "
|
||||
"version %s (%s)",
|
||||
name, version, description);
|
||||
}
|
||||
else
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: unable to load script "
|
||||
"\"%s\" (not enough memory)",
|
||||
name);
|
||||
XSRETURN (0);
|
||||
return;
|
||||
}
|
||||
XSRETURN (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::print: print message into a buffer (current or specified one)
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_print)
|
||||
{
|
||||
unsigned int integer;
|
||||
char *message, *channel_name, *server_name;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if ((items < 1) || (items > 3))
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"print\" function");
|
||||
XSRETURN_NO;
|
||||
return;
|
||||
}
|
||||
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
|
||||
if (items > 1)
|
||||
{
|
||||
channel_name = SvPV (ST (1), integer);
|
||||
if (items > 2)
|
||||
server_name = SvPV (ST (2), integer);
|
||||
}
|
||||
|
||||
message = SvPV (ST (0), integer);
|
||||
perl_plugin->printf (perl_plugin,
|
||||
server_name, channel_name,
|
||||
"%s", message);
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::print_infobar: print message to infobar
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_print_infobar)
|
||||
{
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (items != 2)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"print_infobar\" function");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
perl_plugin->infobar_printf (perl_plugin,
|
||||
SvIV (ST (0)),
|
||||
SvPV (ST (1), integer));
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::command: send command to server
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_command)
|
||||
{
|
||||
unsigned int integer;
|
||||
char *channel_name, *server_name;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if ((items < 1) || (items > 3))
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"command\" function");
|
||||
XSRETURN_NO;
|
||||
return;
|
||||
}
|
||||
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
|
||||
if (items > 1)
|
||||
{
|
||||
channel_name = SvPV (ST (1), integer);
|
||||
if (items > 2)
|
||||
server_name = SvPV (ST (2), integer);
|
||||
}
|
||||
|
||||
perl_plugin->exec_command (perl_plugin,
|
||||
server_name, channel_name,
|
||||
SvPV (ST (0), integer));
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::add_message_handler: add handler for messages (privmsg, ...)
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_add_message_handler)
|
||||
{
|
||||
char *name, *function;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (items != 2)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"add_message_handler\" function");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
name = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (1), integer);
|
||||
perl_plugin->msg_handler_add (perl_plugin, name,
|
||||
weechat_perl_handler, function,
|
||||
(void *)current_perl_script);
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::add_command_handler: add command handler (define/redefine commands)
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_add_command_handler)
|
||||
{
|
||||
char *command, *function, *description, *arguments, *arguments_description;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (items < 2)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"add_command_handler\" function");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
command = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (1), integer);
|
||||
description = (items >= 3) ? SvPV (ST (2), integer) : NULL;
|
||||
arguments = (items >= 4) ? SvPV (ST (3), integer) : NULL;
|
||||
arguments_description = (items >= 5) ? SvPV (ST (4), integer) : NULL;
|
||||
|
||||
perl_plugin->cmd_handler_add (perl_plugin,
|
||||
command,
|
||||
description,
|
||||
arguments,
|
||||
arguments_description,
|
||||
weechat_perl_handler,
|
||||
function,
|
||||
(void *)current_perl_script);
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::get_info: get various infos
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_get_info)
|
||||
{
|
||||
char *arg, *info, *server_name, *channel_name;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if ((items < 1) || (items > 3))
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"get_info\" function");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
server_name = NULL;
|
||||
channel_name = NULL;
|
||||
|
||||
if (items >= 2)
|
||||
server_name = SvPV (ST (1), integer);
|
||||
if (items == 3)
|
||||
channel_name = SvPV (ST (2), integer);
|
||||
|
||||
arg = SvPV (ST (0), integer);
|
||||
if (arg)
|
||||
{
|
||||
info = perl_plugin->get_info (perl_plugin, arg, server_name, channel_name);
|
||||
|
||||
if (info)
|
||||
{
|
||||
XST_mPV (0, info);
|
||||
free (info);
|
||||
}
|
||||
else
|
||||
XST_mPV (0, "");
|
||||
}
|
||||
|
||||
XSRETURN (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::get_dcc_info: get infos about DCC
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_get_dcc_info)
|
||||
{
|
||||
t_plugin_dcc_info *dcc_info, *ptr_dcc;
|
||||
int dcc_count;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
(void) items;
|
||||
|
||||
dcc_info = perl_plugin->get_dcc_info (perl_plugin);
|
||||
dcc_count = 0;
|
||||
|
||||
if (!dcc_info)
|
||||
{
|
||||
XSRETURN (0);
|
||||
return;
|
||||
}
|
||||
|
||||
for (ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
|
||||
{
|
||||
HV *infohash = (HV *) sv_2mortal((SV *) newHV());
|
||||
|
||||
hv_store (infohash, "server", 6, newSVpv (ptr_dcc->server, 0), 0);
|
||||
hv_store (infohash, "channel", 7, newSVpv (ptr_dcc->channel, 0), 0);
|
||||
hv_store (infohash, "type", 4, newSViv (ptr_dcc->type), 0);
|
||||
hv_store (infohash, "status", 6, newSViv (ptr_dcc->status), 0);
|
||||
hv_store (infohash, "start_time", 10, newSViv (ptr_dcc->start_time), 0);
|
||||
hv_store (infohash, "start_transfer", 14, newSViv (ptr_dcc->start_transfer), 0);
|
||||
hv_store (infohash, "address", 7, newSViv (ptr_dcc->addr), 0);
|
||||
hv_store (infohash, "port", 4, newSViv (ptr_dcc->port), 0);
|
||||
hv_store (infohash, "nick", 4, newSVpv (ptr_dcc->nick, 0), 0);
|
||||
hv_store (infohash, "remote_file", 11, newSVpv (ptr_dcc->filename, 0), 0);
|
||||
hv_store (infohash, "local_file", 10, newSVpv (ptr_dcc->local_filename, 0), 0);
|
||||
hv_store (infohash, "filename_suffix", 15, newSViv (ptr_dcc->filename_suffix), 0);
|
||||
hv_store (infohash, "size", 4, newSVnv (ptr_dcc->size), 0);
|
||||
hv_store (infohash, "pos", 3, newSVnv (ptr_dcc->pos), 0);
|
||||
hv_store (infohash, "start_resume", 12, newSVnv (ptr_dcc->start_resume), 0);
|
||||
hv_store (infohash, "cps", 3, newSViv (ptr_dcc->bytes_per_sec), 0);
|
||||
|
||||
XPUSHs(newRV((SV *) infohash));
|
||||
dcc_count++;
|
||||
}
|
||||
|
||||
perl_plugin->free_dcc_info (perl_plugin, dcc_info);
|
||||
|
||||
XSRETURN (dcc_count);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_xs_init: initialize subroutines
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_perl_xs_init (pTHX)
|
||||
{
|
||||
newXS ("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__);
|
||||
|
||||
newXS ("weechat::register", XS_weechat_register, "weechat");
|
||||
newXS ("weechat::print", XS_weechat_print, "weechat");
|
||||
newXS ("weechat::print_infobar", XS_weechat_print_infobar, "weechat");
|
||||
newXS ("weechat::command", XS_weechat_command, "weechat");
|
||||
newXS ("weechat::add_message_handler", XS_weechat_add_message_handler, "weechat");
|
||||
newXS ("weechat::add_command_handler", XS_weechat_add_command_handler, "weechat");
|
||||
newXS ("weechat::get_info", XS_weechat_get_info, "weechat");
|
||||
newXS ("weechat::get_dcc_info", XS_weechat_get_dcc_info, "weechat");
|
||||
}
|
||||
|
||||
/*
|
||||
* wee_perl_load: load a Perl script
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_perl_load (t_weechat_plugin *plugin, char *filename)
|
||||
{
|
||||
plugin->printf_server (plugin, "Loading Perl script \"%s\"", filename);
|
||||
return weechat_perl_exec (plugin, NULL, "wee_perl_load_eval_file", filename, "");
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_unload: unload a Perl script
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_perl_unload (t_weechat_plugin *plugin, t_plugin_script *script)
|
||||
{
|
||||
if (script->shutdown_func && script->shutdown_func[0])
|
||||
weechat_perl_exec (plugin, script, script->shutdown_func, "", "");
|
||||
|
||||
weechat_script_remove (plugin, &perl_scripts, script);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_unload_all: unload all Perl scripts
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_perl_unload_all (t_weechat_plugin *plugin)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Unloading all Perl scripts");
|
||||
while (perl_scripts)
|
||||
weechat_perl_unload (plugin, perl_scripts);
|
||||
|
||||
plugin->printf_server (plugin,
|
||||
"Perl scripts unloaded");
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_cmd: /perl command handler
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_perl_cmd (t_weechat_plugin *plugin,
|
||||
char *server, char *command, char *arguments,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
int argc, path_length, handler_found;
|
||||
char **argv, *path_script, *dir_home;
|
||||
t_plugin_script *ptr_plugin_script;
|
||||
t_plugin_msg_handler *ptr_msg_handler;
|
||||
t_plugin_cmd_handler *ptr_cmd_handler;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) server;
|
||||
(void) command;
|
||||
(void) handler_args;
|
||||
(void) handler_pointer;
|
||||
|
||||
argv = plugin->explode_string (plugin, arguments, " ", 0, &argc);
|
||||
|
||||
switch (argc)
|
||||
{
|
||||
case 0:
|
||||
/* list registered Perl scripts */
|
||||
plugin->printf_server (plugin, "");
|
||||
plugin->printf_server (plugin, "Registered Perl scripts:");
|
||||
if (perl_scripts)
|
||||
{
|
||||
for (ptr_plugin_script = perl_scripts; ptr_plugin_script;
|
||||
ptr_plugin_script = ptr_plugin_script->next_script)
|
||||
{
|
||||
plugin->printf_server (plugin, " %s v%s%s%s",
|
||||
ptr_plugin_script->name,
|
||||
ptr_plugin_script->version,
|
||||
(ptr_plugin_script->description[0]) ? " - " : "",
|
||||
ptr_plugin_script->description);
|
||||
}
|
||||
}
|
||||
else
|
||||
plugin->printf_server (plugin, " (none)");
|
||||
|
||||
/* list Perl message handlers */
|
||||
plugin->printf_server (plugin, "");
|
||||
plugin->printf_server (plugin, "Perl message handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_msg_handler = plugin->msg_handlers; ptr_msg_handler;
|
||||
ptr_msg_handler = ptr_msg_handler->next_handler)
|
||||
{
|
||||
if (ptr_msg_handler->msg_handler_args)
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->printf_server (plugin, " IRC(%s) => Perl(%s)",
|
||||
ptr_msg_handler->irc_command,
|
||||
ptr_msg_handler->msg_handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->printf_server (plugin, " (none)");
|
||||
|
||||
/* list Perl command handlers */
|
||||
plugin->printf_server (plugin, "");
|
||||
plugin->printf_server (plugin, "Perl command handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_cmd_handler = plugin->cmd_handlers; ptr_cmd_handler;
|
||||
ptr_cmd_handler = ptr_cmd_handler->next_handler)
|
||||
{
|
||||
if (ptr_cmd_handler->cmd_handler_args)
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->printf_server (plugin, " /%s => Perl(%s)",
|
||||
ptr_cmd_handler->command,
|
||||
ptr_cmd_handler->cmd_handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->printf_server (plugin, " (none)");
|
||||
break;
|
||||
case 1:
|
||||
if (plugin->ascii_strcasecmp (plugin, argv[0], "autoload") == 0)
|
||||
weechat_script_auto_load (plugin, "perl", weechat_perl_load);
|
||||
else if (plugin->ascii_strcasecmp (plugin, argv[0], "reload") == 0)
|
||||
{
|
||||
weechat_perl_unload_all (plugin);
|
||||
weechat_script_auto_load (plugin, "perl", weechat_perl_load);
|
||||
}
|
||||
else if (plugin->ascii_strcasecmp (plugin, argv[0], "unload") == 0)
|
||||
weechat_perl_unload_all (plugin);
|
||||
break;
|
||||
case 2:
|
||||
if (plugin->ascii_strcasecmp (plugin, argv[0], "load") == 0)
|
||||
{
|
||||
/* load Perl script */
|
||||
if ((strstr (argv[1], "/")) || (strstr (argv[1], "\\")))
|
||||
path_script = NULL;
|
||||
else
|
||||
{
|
||||
dir_home = plugin->get_info (plugin, "weechat_dir", NULL, NULL);
|
||||
if (dir_home)
|
||||
{
|
||||
path_length = strlen (dir_home) + strlen (argv[1]) + 16;
|
||||
path_script = (char *) malloc (path_length * sizeof (char));
|
||||
if (path_script)
|
||||
snprintf (path_script, path_length, "%s/perl/%s",
|
||||
dir_home, argv[1]);
|
||||
else
|
||||
path_script = NULL;
|
||||
free (dir_home);
|
||||
}
|
||||
else
|
||||
path_script = NULL;
|
||||
}
|
||||
weechat_perl_load (plugin, (path_script) ? path_script : argv[1]);
|
||||
if (path_script)
|
||||
free (path_script);
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Perl error: unknown option for "
|
||||
"\"perl\" command");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
plugin->printf_server (plugin,
|
||||
"Perl error: wrong argument count for \"perl\" command");
|
||||
}
|
||||
plugin->free_exploded_string (plugin, argv);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_init: initialize Perl plugin
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_plugin_init (t_weechat_plugin *plugin)
|
||||
{
|
||||
char *perl_args[] = { "", "-e", "0" };
|
||||
/* Following Perl code is extracted/modified from X-Chat IRC client */
|
||||
/* X-Chat is (c) 1998-2005 Peter Zelezny */
|
||||
char *weechat_perl_func =
|
||||
{
|
||||
"sub wee_perl_load_file"
|
||||
"{"
|
||||
" my $filename = shift;"
|
||||
" local $/ = undef;"
|
||||
" open FILE, $filename or return \"__WEECHAT_ERROR__\";"
|
||||
" $_ = <FILE>;"
|
||||
" close FILE;"
|
||||
" return $_;"
|
||||
"}"
|
||||
"sub wee_perl_load_eval_file"
|
||||
"{"
|
||||
" my $filename = shift;"
|
||||
" my $content = wee_perl_load_file ($filename);"
|
||||
" if ($content eq \"__WEECHAT_ERROR__\")"
|
||||
" {"
|
||||
" weechat::print \"Perl error: script '$filename' not found.\", \"\";"
|
||||
" return 1;"
|
||||
" }"
|
||||
" eval $content;"
|
||||
" if ($@)"
|
||||
" {"
|
||||
" weechat::print \"Perl error: unable to load script '$filename':\", \"\";"
|
||||
" weechat::print \"$@\";"
|
||||
" return 2;"
|
||||
" }"
|
||||
" return 0;"
|
||||
"}"
|
||||
"$SIG{__WARN__} = sub { weechat::print \"$_[0]\", \"\"; };"
|
||||
};
|
||||
|
||||
perl_plugin = plugin;
|
||||
|
||||
plugin->printf_server (plugin, "Loading Perl module \"weechat\"");
|
||||
|
||||
my_perl = perl_alloc ();
|
||||
if (!my_perl)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Perl error: unable to initialize Perl");
|
||||
return 0;
|
||||
}
|
||||
perl_construct (my_perl);
|
||||
perl_parse (my_perl, weechat_perl_xs_init, 3, perl_args, NULL);
|
||||
eval_pv (weechat_perl_func, TRUE);
|
||||
|
||||
plugin->cmd_handler_add (plugin, "perl",
|
||||
"list/load/unload Perl scripts",
|
||||
"[load filename] | [autoload] | [reload] | [unload]",
|
||||
"filename: Perl script (file) to load\n\n"
|
||||
"Without argument, /perl command lists all loaded Perl scripts.",
|
||||
weechat_perl_cmd, NULL, NULL);
|
||||
|
||||
plugin->mkdir_home (plugin, "perl");
|
||||
plugin->mkdir_home (plugin, "perl/autoload");
|
||||
|
||||
weechat_script_auto_load (plugin, "perl", weechat_perl_load);
|
||||
|
||||
/* init ok */
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_end: shutdown Perl interface
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_plugin_end (t_weechat_plugin *plugin)
|
||||
{
|
||||
/* unload all scripts */
|
||||
weechat_perl_unload_all (plugin);
|
||||
|
||||
/* free Perl interpreter */
|
||||
if (my_perl)
|
||||
{
|
||||
perl_destruct (my_perl);
|
||||
perl_free (my_perl);
|
||||
my_perl = NULL;
|
||||
}
|
||||
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl plugin ended");
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
# Copyright (c) 2003-2005 FlashCode <flashcode@flashtux.org>
|
||||
#
|
||||
# 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 2 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, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(PYTHON_CFLAGS)
|
||||
|
||||
libdir = ${weechat_libdir}/plugins
|
||||
|
||||
lib_LTLIBRARIES = libpython.la
|
||||
|
||||
libpython_la_SOURCES = weechat-python.c
|
||||
libpython_la_LDFLAGS = -module
|
||||
libpython_la_LIBADD = ../lib_weechat_plugins_scripts.la $(PYTHON_LFLAGS)
|
||||
@@ -0,0 +1,855 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* weechat-python.c: Python plugin support for WeeChat */
|
||||
|
||||
|
||||
#include <Python.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#undef _
|
||||
#include "../../weechat-plugin.h"
|
||||
#include "../weechat-script.h"
|
||||
|
||||
|
||||
char plugin_name[] = "Python";
|
||||
char plugin_version[] = "0.1";
|
||||
char plugin_description[] = "Python scripts support";
|
||||
|
||||
t_weechat_plugin *python_plugin;
|
||||
|
||||
t_plugin_script *python_scripts = NULL;
|
||||
t_plugin_script *python_current_script = NULL;
|
||||
char *python_current_script_filename = NULL;
|
||||
PyThreadState *python_mainThreadState = NULL;
|
||||
|
||||
|
||||
/*
|
||||
* weechat_python_exec: execute a Python script
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_python_exec (t_weechat_plugin *plugin,
|
||||
t_plugin_script *script,
|
||||
char *function, char *server, char *arguments)
|
||||
{
|
||||
PyObject *evMain;
|
||||
PyObject *evDict;
|
||||
PyObject *evFunc;
|
||||
|
||||
PyThreadState_Swap (NULL);
|
||||
|
||||
PyEval_AcquireLock ();
|
||||
|
||||
PyThreadState_Swap (script->interpreter);
|
||||
|
||||
evMain = PyImport_AddModule ((char *) "__main__");
|
||||
evDict = PyModule_GetDict (evMain);
|
||||
evFunc = PyDict_GetItemString (evDict, function);
|
||||
|
||||
if ( !(evFunc && PyCallable_Check (evFunc)) )
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: unable to run function \"%s\"",
|
||||
function);
|
||||
PyEval_ReleaseLock();
|
||||
return 1;
|
||||
}
|
||||
|
||||
PyObject_CallFunction(evFunc, "ss", server == NULL ? "" : server, arguments == NULL ? "" : arguments);
|
||||
|
||||
PyEval_ReleaseLock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_handler: general message and command handler for Python
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_python_handler (t_weechat_plugin *plugin,
|
||||
char *server, char *command, char *arguments,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
/* make gcc happy */
|
||||
(void) command;
|
||||
|
||||
weechat_python_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
handler_args, server, arguments);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.register: startup function for all WeeChat Python scripts
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_register (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *name, *version, *shutdown_func, *description;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
name = NULL;
|
||||
version = NULL;
|
||||
shutdown_func = NULL;
|
||||
description = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ssss", &name, &version, &shutdown_func, &description))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"register\" function");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (weechat_script_search (python_plugin, &python_scripts, name))
|
||||
{
|
||||
/* error: another scripts already exists with this name! */
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to register "
|
||||
"\"%s\" script (another script "
|
||||
"already exists with this name)",
|
||||
name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* register script */
|
||||
python_current_script = weechat_script_add (python_plugin,
|
||||
&python_scripts,
|
||||
(python_current_script_filename) ?
|
||||
python_current_script_filename : "",
|
||||
name, version, shutdown_func,
|
||||
description);
|
||||
if (python_current_script)
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python: registered script \"%s\", "
|
||||
"version %s (%s)",
|
||||
name, version, description);
|
||||
}
|
||||
else
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to load script "
|
||||
"\"%s\" (not enough memory)",
|
||||
name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.print: print message into a buffer (current or specified one)
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_print (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *message, *channel_name, *server_name;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
message = NULL;
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s|ss", &message, &channel_name, &server_name))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"print\" function");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
python_plugin->printf (python_plugin,
|
||||
server_name, channel_name,
|
||||
"%s", message);
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.print_infobar: print message to infobar
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_print_infobar (PyObject *self, PyObject *args)
|
||||
{
|
||||
int delay;
|
||||
char *message;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
delay = 1;
|
||||
message = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "is", &delay, &message))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"print_infobar\" function");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
python_plugin->infobar_printf (python_plugin, delay, message);
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.command: send command to server
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_command (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *command, *channel_name, *server_name;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
command = NULL;
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s|ss", &command, &channel_name, &server_name))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"command\" function");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
python_plugin->exec_command (python_plugin,
|
||||
server_name, channel_name,
|
||||
command);
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.add_message_handler: add handler for messages
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_add_message_handler (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *message, *function;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
message = NULL;
|
||||
function = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ss", &message, &function))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"add_message_handler\" function");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (python_current_script)
|
||||
python_plugin->msg_handler_add (python_plugin, message,
|
||||
weechat_python_handler, function,
|
||||
(void *)python_current_script);
|
||||
else
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to add message handler, "
|
||||
"script not initialized");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.add_command_handler: define/redefines commands
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_add_command_handler (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *command, *function, *description, *arguments, *arguments_description;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
command = NULL;
|
||||
function = NULL;
|
||||
description = NULL;
|
||||
arguments = NULL;
|
||||
arguments_description = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ss|sss", &command, &function,
|
||||
&description, &arguments, &arguments_description))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"add_command_handler\" function");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (python_current_script)
|
||||
python_plugin->cmd_handler_add (python_plugin,
|
||||
command,
|
||||
description,
|
||||
arguments,
|
||||
arguments_description,
|
||||
weechat_python_handler,
|
||||
function,
|
||||
(void *)python_current_script);
|
||||
else
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to add command handler, "
|
||||
"script not initialized");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.get_info: get various infos
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_get_info (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *arg, *server_name, *channel_name, *info;
|
||||
PyObject *object;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
arg = NULL;
|
||||
server_name = NULL;
|
||||
channel_name = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s|ss", &arg, &server_name, &channel_name))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"get_info\" function");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (arg)
|
||||
{
|
||||
info = python_plugin->get_info (python_plugin, arg, server_name, channel_name);
|
||||
|
||||
if (info)
|
||||
{
|
||||
object = Py_BuildValue ("s", info);
|
||||
free (info);
|
||||
return object;
|
||||
}
|
||||
else
|
||||
return Py_BuildValue ("s", "");
|
||||
}
|
||||
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.get_dcc_info: get infos about DCC
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_get_dcc_info (PyObject *self, PyObject *args)
|
||||
{
|
||||
t_plugin_dcc_info *dcc_info, *ptr_dcc;
|
||||
int dcc_count;
|
||||
PyObject *list, *listvalue;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
(void) args;
|
||||
|
||||
dcc_info = python_plugin->get_dcc_info (python_plugin);
|
||||
dcc_count = 0;
|
||||
|
||||
if (!dcc_info)
|
||||
return Py_None;
|
||||
|
||||
for (ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
|
||||
{
|
||||
dcc_count++;
|
||||
}
|
||||
|
||||
list = PyList_New (dcc_count);
|
||||
|
||||
if (!list)
|
||||
{
|
||||
python_plugin->free_dcc_info (python_plugin, dcc_info);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
dcc_count = 0;
|
||||
for(ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
|
||||
{
|
||||
listvalue = Py_BuildValue ("{s:s,s:s,s:i,s:i,s:k,s:k,s:k,s:i,s:s,s:s,"
|
||||
"s:s,s:s,s:k,s:k,s:k,s:k}",
|
||||
"server", ptr_dcc->server,
|
||||
"channel", ptr_dcc->channel,
|
||||
"type", ptr_dcc->type,
|
||||
"status", ptr_dcc->status,
|
||||
"start_time", ptr_dcc->start_time,
|
||||
"start_transfer", ptr_dcc->start_transfer,
|
||||
"address", ptr_dcc->addr,
|
||||
"port", ptr_dcc->port,
|
||||
"nick", ptr_dcc->nick,
|
||||
"remote_file", ptr_dcc->filename,
|
||||
"local_file", ptr_dcc->local_filename,
|
||||
"filename_suffix", ptr_dcc->filename_suffix,
|
||||
"size", ptr_dcc->size,
|
||||
"pos", ptr_dcc->pos,
|
||||
"start_resume", ptr_dcc->start_resume,
|
||||
"cps", ptr_dcc->bytes_per_sec);
|
||||
if (listvalue)
|
||||
{
|
||||
if (PyList_SetItem (list, dcc_count, listvalue) != 0)
|
||||
{
|
||||
PyMem_Free (listvalue);
|
||||
PyMem_Free (list);
|
||||
python_plugin->free_dcc_info (python_plugin, dcc_info);
|
||||
return Py_None;
|
||||
}
|
||||
PyMem_Free (listvalue);
|
||||
}
|
||||
else
|
||||
{
|
||||
python_plugin->free_dcc_info (python_plugin, dcc_info);
|
||||
return Py_None;
|
||||
}
|
||||
dcc_count++;
|
||||
}
|
||||
|
||||
python_plugin->free_dcc_info (python_plugin, dcc_info);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/*
|
||||
* Python subroutines
|
||||
*/
|
||||
|
||||
static
|
||||
PyMethodDef weechat_funcs[] = {
|
||||
{ "register", weechat_python_register, METH_VARARGS, "" },
|
||||
{ "prnt", weechat_python_print, METH_VARARGS, "" },
|
||||
{ "print_infobar", weechat_python_print_infobar, METH_VARARGS, "" },
|
||||
{ "command", weechat_python_command, METH_VARARGS, "" },
|
||||
{ "add_message_handler", weechat_python_add_message_handler, METH_VARARGS, "" },
|
||||
{ "add_command_handler", weechat_python_add_command_handler, METH_VARARGS, "" },
|
||||
{ "get_info", weechat_python_get_info, METH_VARARGS, "" },
|
||||
{ "get_dcc_info", weechat_python_get_dcc_info, METH_VARARGS, "" },
|
||||
{ NULL, NULL, 0, NULL }
|
||||
};
|
||||
|
||||
/*
|
||||
* weechat_python_load: load a Python script
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_python_load (t_weechat_plugin *plugin, char *filename)
|
||||
{
|
||||
FILE *fp;
|
||||
PyThreadState *python_current_interpreter;
|
||||
|
||||
plugin->printf_server (plugin, "Loading Python script \"%s\"", filename);
|
||||
|
||||
if ((fp = fopen (filename, "r")) == NULL)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: unable to open file \"%s\"",
|
||||
filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
python_current_script = NULL;
|
||||
|
||||
PyThreadState_Swap(NULL);
|
||||
|
||||
PyEval_AcquireLock();
|
||||
|
||||
python_current_interpreter = PyThreadState_New (python_mainThreadState->interp);
|
||||
|
||||
if (python_current_interpreter == NULL)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: unable to create new sub-interpreter");
|
||||
PyEval_ReleaseLock();
|
||||
fclose (fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyThreadState_Swap (python_current_interpreter);
|
||||
|
||||
if (Py_InitModule ("weechat", weechat_funcs) == NULL)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: unable to initialize WeeChat module");
|
||||
PyThreadState_Swap (NULL);
|
||||
PyThreadState_Clear (python_current_interpreter);
|
||||
PyThreadState_Delete (python_current_interpreter);
|
||||
PyEval_ReleaseLock ();
|
||||
fclose (fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (PyRun_SimpleString (
|
||||
"import weechat, sys, string\n"
|
||||
|
||||
"class weechatStdout:\n"
|
||||
"\tdef write(self, str):\n"
|
||||
"\t\tstr = string.strip(str)\n"
|
||||
"\t\tif str != \"\":\n"
|
||||
"\t\t\tweechat.prnt(\"Python stdout : \" + str, \"\")\n"
|
||||
|
||||
"class weechatStderr:\n"
|
||||
"\tdef write(self, str):\n"
|
||||
"\t\tstr = string.strip(str)\n"
|
||||
"\t\tif str != \"\":\n"
|
||||
"\t\t\tweechat.prnt(\"Python stderr : \" + str, \"\")\n"
|
||||
|
||||
"sys.stdout = weechatStdout()\n"
|
||||
"sys.stderr = weechatStderr()\n"
|
||||
) != 0)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python warning: unable to redirect stdout and stderr");
|
||||
}
|
||||
|
||||
python_current_script_filename = strdup (filename);
|
||||
|
||||
if (PyRun_SimpleFile (fp, filename) != 0)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: unable to parse file \"%s\"",
|
||||
filename);
|
||||
free (python_current_script_filename);
|
||||
PyThreadState_Swap (NULL);
|
||||
PyThreadState_Clear (python_current_interpreter);
|
||||
PyThreadState_Delete (python_current_interpreter);
|
||||
PyEval_ReleaseLock ();
|
||||
fclose (fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fclose (fp);
|
||||
free (python_current_script_filename);
|
||||
|
||||
if (python_current_script == NULL)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: function \"register\" not found "
|
||||
"in file \"%s\"",
|
||||
filename);
|
||||
PyThreadState_Swap (NULL);
|
||||
PyThreadState_Clear (python_current_interpreter);
|
||||
PyThreadState_Delete (python_current_interpreter);
|
||||
PyEval_ReleaseLock ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
python_current_script->interpreter = (PyThreadState *) python_current_interpreter;
|
||||
PyThreadState_Swap (NULL);
|
||||
PyEval_ReleaseLock ();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_unload: unload a Python script
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_python_unload (t_weechat_plugin *plugin, t_plugin_script *script)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Unloading Python script \"%s\"",
|
||||
script->name);
|
||||
|
||||
if (script->shutdown_func[0])
|
||||
weechat_python_exec (plugin, script, script->shutdown_func, "", "");
|
||||
|
||||
PyThreadState_Swap (NULL);
|
||||
PyThreadState_Clear (script->interpreter);
|
||||
PyThreadState_Delete (script->interpreter);
|
||||
|
||||
weechat_script_remove (plugin, &python_scripts, script);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_unload_name: unload a Python script by name
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_python_unload_name (t_weechat_plugin *plugin, char *name)
|
||||
{
|
||||
t_plugin_script *ptr_script;
|
||||
|
||||
ptr_script = weechat_script_search (plugin, &python_scripts, name);
|
||||
if (ptr_script)
|
||||
{
|
||||
weechat_python_unload (plugin, ptr_script);
|
||||
plugin->printf_server (plugin,
|
||||
"Python script \"%s\" unloaded",
|
||||
name);
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: script \"%s\" not loaded",
|
||||
name);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_unload_all: unload all Python scripts
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_python_unload_all (t_weechat_plugin *plugin)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Unloading all Python scripts");
|
||||
while (python_scripts)
|
||||
weechat_python_unload (plugin, python_scripts);
|
||||
|
||||
plugin->printf_server (plugin,
|
||||
"Python scripts unloaded");
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_cmd: /python command handler
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_python_cmd (t_weechat_plugin *plugin,
|
||||
char *server, char *command, char *arguments,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
int argc, path_length, handler_found;
|
||||
char **argv, *path_script, *dir_home;
|
||||
t_plugin_script *ptr_plugin_script;
|
||||
t_plugin_msg_handler *ptr_msg_handler;
|
||||
t_plugin_cmd_handler *ptr_cmd_handler;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) server;
|
||||
(void) command;
|
||||
(void) handler_args;
|
||||
(void) handler_pointer;
|
||||
|
||||
argv = plugin->explode_string (plugin, arguments, " ", 0, &argc);
|
||||
|
||||
switch (argc)
|
||||
{
|
||||
case 0:
|
||||
/* list registered Python scripts */
|
||||
plugin->printf_server (plugin, "");
|
||||
plugin->printf_server (plugin, "Registered Python scripts:");
|
||||
if (python_scripts)
|
||||
{
|
||||
for (ptr_plugin_script = python_scripts; ptr_plugin_script;
|
||||
ptr_plugin_script = ptr_plugin_script->next_script)
|
||||
{
|
||||
plugin->printf_server (plugin, " %s v%s%s%s",
|
||||
ptr_plugin_script->name,
|
||||
ptr_plugin_script->version,
|
||||
(ptr_plugin_script->description[0]) ? " - " : "",
|
||||
ptr_plugin_script->description);
|
||||
}
|
||||
}
|
||||
else
|
||||
plugin->printf_server (plugin, " (none)");
|
||||
|
||||
/* list Python message handlers */
|
||||
plugin->printf_server (plugin, "");
|
||||
plugin->printf_server (plugin, "Python message handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_msg_handler = plugin->msg_handlers; ptr_msg_handler;
|
||||
ptr_msg_handler = ptr_msg_handler->next_handler)
|
||||
{
|
||||
if (ptr_msg_handler->msg_handler_args)
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->printf_server (plugin, " IRC(%s) => Python(%s)",
|
||||
ptr_msg_handler->irc_command,
|
||||
ptr_msg_handler->msg_handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->printf_server (plugin, " (none)");
|
||||
|
||||
/* list Python command handlers */
|
||||
plugin->printf_server (plugin, "");
|
||||
plugin->printf_server (plugin, "Python command handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_cmd_handler = plugin->cmd_handlers; ptr_cmd_handler;
|
||||
ptr_cmd_handler = ptr_cmd_handler->next_handler)
|
||||
{
|
||||
if (ptr_cmd_handler->cmd_handler_args)
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->printf_server (plugin, " /%s => Python(%s)",
|
||||
ptr_cmd_handler->command,
|
||||
ptr_cmd_handler->cmd_handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->printf_server (plugin, " (none)");
|
||||
break;
|
||||
case 1:
|
||||
if (plugin->ascii_strcasecmp (plugin, argv[0], "autoload") == 0)
|
||||
weechat_script_auto_load (plugin, "python", weechat_python_load);
|
||||
else if (plugin->ascii_strcasecmp (plugin, argv[0], "reload") == 0)
|
||||
{
|
||||
weechat_python_unload_all (plugin);
|
||||
weechat_script_auto_load (plugin, "python", weechat_python_load);
|
||||
}
|
||||
else if (plugin->ascii_strcasecmp (plugin, argv[0], "unload") == 0)
|
||||
weechat_python_unload_all (plugin);
|
||||
break;
|
||||
case 2:
|
||||
if (plugin->ascii_strcasecmp (plugin, argv[0], "load") == 0)
|
||||
{
|
||||
/* load Python script */
|
||||
if ((strstr (argv[1], "/")) || (strstr (argv[1], "\\")))
|
||||
path_script = NULL;
|
||||
else
|
||||
{
|
||||
dir_home = plugin->get_info (plugin, "weechat_dir", NULL, NULL);
|
||||
if (dir_home)
|
||||
{
|
||||
path_length = strlen (dir_home) + strlen (argv[1]) + 16;
|
||||
path_script = (char *) malloc (path_length * sizeof (char));
|
||||
if (path_script)
|
||||
snprintf (path_script, path_length, "%s/python/%s",
|
||||
dir_home, argv[1]);
|
||||
else
|
||||
path_script = NULL;
|
||||
free (dir_home);
|
||||
}
|
||||
else
|
||||
path_script = NULL;
|
||||
}
|
||||
weechat_python_load (plugin, (path_script) ? path_script : argv[1]);
|
||||
if (path_script)
|
||||
free (path_script);
|
||||
}
|
||||
else if (plugin->ascii_strcasecmp (plugin, argv[0], "unload") == 0)
|
||||
{
|
||||
/* unload Python script */
|
||||
weechat_python_unload_name (plugin, argv[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: unknown option for "
|
||||
"\"python\" command");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: wrong argument count for \"python\" command");
|
||||
}
|
||||
plugin->free_exploded_string (plugin, argv);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_init: initialize Python plugin
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_plugin_init (t_weechat_plugin *plugin)
|
||||
{
|
||||
python_plugin = plugin;
|
||||
|
||||
plugin->printf_server (plugin, "Loading Python module \"weechat\"");
|
||||
|
||||
Py_Initialize ();
|
||||
if (Py_IsInitialized () == 0)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: unable to launch global interpreter");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyEval_InitThreads();
|
||||
|
||||
python_mainThreadState = PyThreadState_Get();
|
||||
|
||||
if (python_mainThreadState == NULL)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: unable to get current interpreter state");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyEval_ReleaseLock ();
|
||||
|
||||
plugin->cmd_handler_add (plugin, "python",
|
||||
"list/load/unload Python scripts",
|
||||
"[load filename] | [autoload] | [reload] | [unload]",
|
||||
"filename: Python script (file) to load\n\n"
|
||||
"Without argument, /python command lists all loaded Python scripts.",
|
||||
weechat_python_cmd, NULL, NULL);
|
||||
|
||||
plugin->mkdir_home (plugin, "python");
|
||||
plugin->mkdir_home (plugin, "python/autoload");
|
||||
|
||||
weechat_script_auto_load (plugin, "python", weechat_python_load);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_end: shutdown Python interface
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_plugin_end (t_weechat_plugin *plugin)
|
||||
{
|
||||
/* unload all scripts */
|
||||
weechat_python_unload_all (plugin);
|
||||
|
||||
/* free Python interpreter */
|
||||
/*Py_Finalize ();
|
||||
if (Py_IsInitialized () != 0)
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to free interpreter");
|
||||
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python plugin ended");*/
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
# Copyright (c) 2003-2005 FlashCode <flashcode@flashtux.org>
|
||||
#
|
||||
# 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 2 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, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(RUBY_CFLAGS)
|
||||
|
||||
libdir = ${weechat_libdir}/plugins
|
||||
|
||||
lib_LTLIBRARIES = libruby.la
|
||||
|
||||
libruby_la_SOURCES = weechat-ruby.c
|
||||
libruby_la_LDFLAGS = -module
|
||||
libruby_la_LIBADD = ../lib_weechat_plugins_scripts.la $(RUBY_LFLAGS)
|
||||
@@ -0,0 +1,599 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* wee-ruby.c: Ruby plugin support for WeeChat */
|
||||
|
||||
|
||||
#include <ruby.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#undef _
|
||||
#include "../../weechat-plugin.h"
|
||||
#include "../weechat-script.h"
|
||||
|
||||
|
||||
t_plugin_script *ruby_scripts = NULL;
|
||||
t_plugin_script *last_ruby_script = NULL;
|
||||
|
||||
|
||||
/*
|
||||
* register: startup function for all WeeChat Ruby scripts
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
wee_ruby_register (VALUE class, VALUE name, VALUE version, VALUE shutdown_func, VALUE description)
|
||||
{
|
||||
char *c_name, *c_version, *c_shutdown_func, *c_description;
|
||||
t_plugin_script *ptr_ruby_script, *ruby_script_found, *new_ruby_script;
|
||||
|
||||
if (NIL_P (name) || NIL_P (version) || NIL_P (shutdown_func) || NIL_P (description))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Ruby", "register");
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
Check_Type (name, T_STRING);
|
||||
Check_Type (version, T_STRING);
|
||||
Check_Type (shutdown_func, T_STRING);
|
||||
Check_Type (description, T_STRING);
|
||||
|
||||
c_name = STR2CSTR (name);
|
||||
c_version = STR2CSTR (version);
|
||||
c_shutdown_func = STR2CSTR (shutdown_func);
|
||||
c_description = STR2CSTR (description);
|
||||
|
||||
ruby_script_found = NULL;
|
||||
for (ptr_ruby_script = ruby_scripts; ptr_ruby_script;
|
||||
ptr_ruby_script = ptr_ruby_script->next_script)
|
||||
{
|
||||
if (ascii_strcasecmp (ptr_ruby_script->name, c_name) == 0)
|
||||
{
|
||||
ruby_script_found = ptr_ruby_script;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ruby_script_found)
|
||||
{
|
||||
/* error: another script already exists with this name! */
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: unable to register \"%s\" script (another script "
|
||||
"already exists with this name)\n"),
|
||||
"Ruby", name);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* registering script */
|
||||
new_ruby_script = (t_plugin_script *)malloc (sizeof (t_plugin_script));
|
||||
if (new_ruby_script)
|
||||
{
|
||||
new_ruby_script->name = strdup (c_name);
|
||||
new_ruby_script->version = strdup (c_version);
|
||||
new_ruby_script->shutdown_func = strdup (c_shutdown_func);
|
||||
new_ruby_script->description = strdup (c_description);
|
||||
|
||||
/* add new script to list */
|
||||
new_ruby_script->prev_script = last_ruby_script;
|
||||
new_ruby_script->next_script = NULL;
|
||||
if (ruby_scripts)
|
||||
last_ruby_script->next_script = new_ruby_script;
|
||||
else
|
||||
ruby_scripts = new_ruby_script;
|
||||
last_ruby_script = new_ruby_script;
|
||||
|
||||
wee_log_printf (_("Registered %s script: \"%s\", version %s (%s)\n"),
|
||||
"Ruby", c_name, c_version, c_description);
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: unable to load script \"%s\" (not enough memory)\n"),
|
||||
"Ruby", c_name);
|
||||
}
|
||||
}
|
||||
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
/*
|
||||
* print: print message into a buffer (current or specified one)
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
wee_ruby_print (VALUE class, VALUE message, VALUE channel_name, VALUE server_name)
|
||||
{
|
||||
char *c_message, *c_channel_name, *c_server_name;
|
||||
t_gui_buffer *ptr_buffer;
|
||||
|
||||
c_message = NULL;
|
||||
c_channel_name = NULL;
|
||||
c_server_name = NULL;
|
||||
|
||||
if (NIL_P (message))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Ruby", "print");
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
Check_Type (message, T_STRING);
|
||||
if (!NIL_P (channel_name))
|
||||
Check_Type (channel_name, T_STRING);
|
||||
if (!NIL_P (server_name))
|
||||
Check_Type (server_name, T_STRING);
|
||||
|
||||
c_message = STR2CSTR (message);
|
||||
if (!NIL_P (channel_name))
|
||||
c_channel_name = STR2CSTR (channel_name);
|
||||
if (!NIL_P (server_name))
|
||||
c_server_name = STR2CSTR (server_name);
|
||||
|
||||
ptr_buffer = plugin_find_buffer (c_server_name, c_channel_name);
|
||||
if (ptr_buffer)
|
||||
{
|
||||
irc_display_prefix (ptr_buffer, PREFIX_PLUGIN);
|
||||
gui_printf (ptr_buffer, "%s\n", c_message);
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
/* buffer not found */
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* print_infobar: print message to infobar
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
wee_ruby_print_infobar (VALUE class, VALUE delay, VALUE message)
|
||||
{
|
||||
int c_delay;
|
||||
char *c_message;
|
||||
|
||||
c_delay = 1;
|
||||
c_message = NULL;
|
||||
|
||||
if (NIL_P (delay) || NIL_P (message))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Ruby", "print_infobar");
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
Check_Type (delay, T_FIXNUM);
|
||||
Check_Type (message, T_STRING);
|
||||
|
||||
c_delay = FIX2INT (delay);
|
||||
c_message = STR2CSTR (message);
|
||||
|
||||
gui_infobar_printf (delay, COLOR_WIN_INFOBAR, c_message);
|
||||
|
||||
return Qtrue;
|
||||
}
|
||||
|
||||
/*
|
||||
* command: send command to server
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
wee_ruby_command (VALUE class, VALUE command, VALUE channel_name, VALUE server_name)
|
||||
{
|
||||
char *c_command, *c_channel_name, *c_server_name;
|
||||
t_gui_buffer *ptr_buffer;
|
||||
|
||||
c_command = NULL;
|
||||
c_channel_name = NULL;
|
||||
c_server_name = NULL;
|
||||
|
||||
if (NIL_P (command))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Ruby", "command");
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
Check_Type (command, T_STRING);
|
||||
if (!NIL_P (channel_name))
|
||||
Check_Type (channel_name, T_STRING);
|
||||
if (!NIL_P (server_name))
|
||||
Check_Type (server_name, T_STRING);
|
||||
|
||||
c_command = STR2CSTR (command);
|
||||
if (!NIL_P (channel_name))
|
||||
c_channel_name = STR2CSTR (channel_name);
|
||||
if (!NIL_P (server_name))
|
||||
c_server_name = STR2CSTR (server_name);
|
||||
|
||||
ptr_buffer = plugin_find_buffer (c_server_name, c_channel_name);
|
||||
if (ptr_buffer)
|
||||
{
|
||||
user_command (SERVER(ptr_buffer), ptr_buffer, c_command);
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
/* buffer not found */
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* add_message_handler: add handler for messages
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
wee_ruby_add_message_handler (VALUE class, VALUE message, VALUE function)
|
||||
{
|
||||
char *c_message, *c_function;
|
||||
|
||||
if (NIL_P (message) || NIL_P (function))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Ruby", "add_message_handler");
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
Check_Type (message, T_STRING);
|
||||
Check_Type (function, T_STRING);
|
||||
|
||||
c_message = STR2CSTR (message);
|
||||
c_function = STR2CSTR (function);
|
||||
|
||||
plugin_handler_add (&plugin_msg_handlers, &last_plugin_msg_handler,
|
||||
PLUGIN_TYPE_RUBY, c_message, c_function);
|
||||
|
||||
return Qtrue;
|
||||
}
|
||||
|
||||
/*
|
||||
* add_command_handler: define/redefines commands
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
wee_ruby_add_command_handler (VALUE class, VALUE name, VALUE function)
|
||||
{
|
||||
char *c_name, *c_function;
|
||||
t_plugin_handler *ptr_plugin_handler;
|
||||
|
||||
if (NIL_P (name) || NIL_P (function))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Ruby", "add_command_handler");
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
Check_Type (name, T_STRING);
|
||||
Check_Type (function, T_STRING);
|
||||
|
||||
c_name = STR2CSTR (name);
|
||||
c_function = STR2CSTR (function);
|
||||
|
||||
if (!weelist_search (index_commands, c_name))
|
||||
weelist_add (&index_commands, &last_index_command, c_name);
|
||||
|
||||
ptr_plugin_handler = plugin_handler_search (plugin_cmd_handlers, c_name);
|
||||
if (ptr_plugin_handler)
|
||||
{
|
||||
free (ptr_plugin_handler->function_name);
|
||||
ptr_plugin_handler->function_name = strdup (c_function);
|
||||
}
|
||||
else
|
||||
plugin_handler_add (&plugin_cmd_handlers, &last_plugin_cmd_handler,
|
||||
PLUGIN_TYPE_PYTHON, c_name, c_function);
|
||||
|
||||
return Qtrue;
|
||||
}
|
||||
|
||||
/*
|
||||
* get_info: get various infos
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
wee_ruby_get_info (VALUE class, VALUE arg, VALUE server_name)
|
||||
{
|
||||
char *c_arg, *info, *c_server_name;
|
||||
t_irc_server *ptr_server;
|
||||
|
||||
if (NIL_P (arg))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Ruby", "get_info");
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
Check_Type (arg, T_STRING);
|
||||
if (!NIL_P (server_name))
|
||||
Check_Type (server_name, T_STRING);
|
||||
|
||||
c_arg = STR2CSTR (arg);
|
||||
if (!NIL_P (server_name))
|
||||
c_server_name = STR2CSTR (server_name);
|
||||
|
||||
if (c_server_name == NULL)
|
||||
{
|
||||
ptr_server = SERVER(gui_current_window->buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server)
|
||||
{
|
||||
if (ascii_strcasecmp (ptr_server->name, c_server_name) == 0)
|
||||
break;
|
||||
}
|
||||
if (!ptr_server)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: server not found for \"%s\" function\n"),
|
||||
"Ruby", "get_info");
|
||||
return Qnil;
|
||||
}
|
||||
}
|
||||
|
||||
if (ptr_server && c_arg)
|
||||
{
|
||||
if ( (ascii_strcasecmp (c_arg, "0") == 0) || (ascii_strcasecmp (c_arg, "version") == 0) )
|
||||
{
|
||||
info = PACKAGE_STRING;
|
||||
}
|
||||
else if ( (ascii_strcasecmp (c_arg, "1") == 0) || (ascii_strcasecmp (c_arg, "nick") == 0) )
|
||||
{
|
||||
if (ptr_server->nick)
|
||||
info = ptr_server->nick;
|
||||
}
|
||||
else if ( (ascii_strcasecmp (c_arg, "2") == 0) || (ascii_strcasecmp (c_arg, "channel") == 0) )
|
||||
{
|
||||
if (BUFFER_IS_CHANNEL (gui_current_window->buffer))
|
||||
info = CHANNEL (gui_current_window->buffer)->name;
|
||||
}
|
||||
else if ( (ascii_strcasecmp (c_arg, "3") == 0) || (ascii_strcasecmp (c_arg, "server") == 0) )
|
||||
{
|
||||
if (ptr_server->name)
|
||||
info = ptr_server->name;
|
||||
}
|
||||
else if ( (ascii_strcasecmp (c_arg, "4") == 0) || (ascii_strcasecmp (c_arg, "weechatdir") == 0) )
|
||||
{
|
||||
info = weechat_home;
|
||||
}
|
||||
else if ( (ascii_strcasecmp (c_arg, "5") == 0) || (ascii_strcasecmp (c_arg, "away") == 0) )
|
||||
{
|
||||
return INT2FIX (SERVER(gui_current_window->buffer)->is_away);
|
||||
}
|
||||
else if ( (ascii_strcasecmp (c_arg, "100") == 0) || (ascii_strcasecmp (c_arg, "dccs") == 0) )
|
||||
{
|
||||
/* TODO: build dcc list */
|
||||
}
|
||||
|
||||
if (info)
|
||||
return rb_str_new2 (info);
|
||||
else
|
||||
return rb_str_new2 ("");
|
||||
}
|
||||
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Ruby subroutines
|
||||
*/
|
||||
|
||||
/*
|
||||
* wee_ruby_init: initialize Ruby interface for WeeChat
|
||||
*/
|
||||
|
||||
void
|
||||
wee_ruby_init ()
|
||||
{
|
||||
|
||||
/* TODO: init Ruby environment */
|
||||
/* ruby_init ();
|
||||
if ()
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _("%s error: error while launching interpreter\n"),
|
||||
"Ruby");
|
||||
}
|
||||
else
|
||||
{
|
||||
wee_log_printf (_("Loading %s module \"weechat\"\n"), "Ruby");
|
||||
}*/
|
||||
}
|
||||
|
||||
/*
|
||||
* wee_ruby_search: search a (loaded) Ruby script by name
|
||||
*/
|
||||
|
||||
t_plugin_script *
|
||||
wee_ruby_search (char *name)
|
||||
{
|
||||
t_plugin_script *ptr_ruby_script;
|
||||
|
||||
for (ptr_ruby_script = ruby_scripts; ptr_ruby_script;
|
||||
ptr_ruby_script = ptr_ruby_script->next_script)
|
||||
{
|
||||
if (strcmp (ptr_ruby_script->name, name) == 0)
|
||||
return ptr_ruby_script;
|
||||
}
|
||||
|
||||
/* script not found */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* wee_ruby_exec: execute a Ruby script
|
||||
*/
|
||||
|
||||
int
|
||||
wee_ruby_exec (char *function, char *server, char *arguments)
|
||||
{
|
||||
/* TODO: exec Ruby script */
|
||||
}
|
||||
|
||||
/*
|
||||
* wee_ruby_load: load a Ruby script
|
||||
*/
|
||||
|
||||
int
|
||||
wee_ruby_load (char *filename)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
/* TODO: load & exec Ruby script */
|
||||
gui_printf (NULL, "Ruby scripts not developed!\n");
|
||||
/* execute Ruby script */
|
||||
/*wee_log_printf (_("Loading %s script \"%s\"\n"), "Ruby", filename);
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _("Loading %s script \"%s\"\n"), "Ruby", filename);
|
||||
|
||||
if ((fp = fopen (filename, "r")) == NULL)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: error while opening file \"%s\"\n"),
|
||||
"Ruby", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (xxxxxxx (fp, filename) != 0)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: error while parsing file \"%s\"\n"),
|
||||
"Ruby", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fclose (fp);
|
||||
return 0;*/
|
||||
}
|
||||
|
||||
/*
|
||||
* wee_ruby_script_free: free a Ruby script
|
||||
*/
|
||||
|
||||
void
|
||||
wee_ruby_script_free (t_plugin_script *ptr_ruby_script)
|
||||
{
|
||||
t_plugin_script *new_ruby_scripts;
|
||||
|
||||
/* remove script from list */
|
||||
if (last_ruby_script == ptr_ruby_script)
|
||||
last_ruby_script = ptr_ruby_script->prev_script;
|
||||
if (ptr_ruby_script->prev_script)
|
||||
{
|
||||
(ptr_ruby_script->prev_script)->next_script = ptr_ruby_script->next_script;
|
||||
new_ruby_scripts = ruby_scripts;
|
||||
}
|
||||
else
|
||||
new_ruby_scripts = ptr_ruby_script->next_script;
|
||||
|
||||
if (ptr_ruby_script->next_script)
|
||||
(ptr_ruby_script->next_script)->prev_script = ptr_ruby_script->prev_script;
|
||||
|
||||
/* free data */
|
||||
if (ptr_ruby_script->name)
|
||||
free (ptr_ruby_script->name);
|
||||
if (ptr_ruby_script->version)
|
||||
free (ptr_ruby_script->version);
|
||||
if (ptr_ruby_script->shutdown_func)
|
||||
free (ptr_ruby_script->shutdown_func);
|
||||
if (ptr_ruby_script->description)
|
||||
free (ptr_ruby_script->description);
|
||||
free (ptr_ruby_script);
|
||||
ruby_scripts = new_ruby_scripts;
|
||||
}
|
||||
|
||||
/*
|
||||
* wee_ruby_unload: unload a Ruby script
|
||||
*/
|
||||
|
||||
void
|
||||
wee_ruby_unload (t_plugin_script *ptr_ruby_script)
|
||||
{
|
||||
if (ptr_ruby_script)
|
||||
{
|
||||
wee_log_printf (_("Unloading %s script \"%s\"\n"),
|
||||
"Ruby", ptr_ruby_script->name);
|
||||
|
||||
/* call shutdown callback function */
|
||||
if (ptr_ruby_script->shutdown_func[0])
|
||||
wee_ruby_exec (ptr_ruby_script->shutdown_func, "", "");
|
||||
wee_ruby_script_free (ptr_ruby_script);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* wee_ruby_unload_all: unload all Ruby scripts
|
||||
*/
|
||||
|
||||
void
|
||||
wee_ruby_unload_all ()
|
||||
{
|
||||
wee_log_printf (_("Unloading all %s scripts...\n"), "Ruby");
|
||||
while (ruby_scripts)
|
||||
wee_ruby_unload (ruby_scripts);
|
||||
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _("%s scripts unloaded\n"), "Ruby");
|
||||
}
|
||||
|
||||
/*
|
||||
* wee_ruby_end: shutdown Ruby interface
|
||||
*/
|
||||
|
||||
void
|
||||
wee_ruby_end ()
|
||||
{
|
||||
/* unload all scripts */
|
||||
wee_ruby_unload_all ();
|
||||
|
||||
/* free all handlers */
|
||||
plugin_handler_free_all_type (&plugin_msg_handlers,
|
||||
&last_plugin_msg_handler,
|
||||
PLUGIN_TYPE_RUBY);
|
||||
plugin_handler_free_all_type (&plugin_cmd_handlers,
|
||||
&last_plugin_cmd_handler,
|
||||
PLUGIN_TYPE_RUBY);
|
||||
|
||||
/* TODO: free Ruby interpreter */
|
||||
/* free Ruby interpreter */
|
||||
/* xxxxx ();
|
||||
if ()
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _("%s error: error while freeing interpreter\n"),
|
||||
"Ruby");
|
||||
}*/
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* scripts.c: script interface for WeeChat plugins */
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "../weechat-plugin.h"
|
||||
#include "weechat-script.h"
|
||||
|
||||
|
||||
/*
|
||||
* weechat_script_auto_load: auto-load all scripts in a directory
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_script_auto_load (t_weechat_plugin *plugin, char *language,
|
||||
int (*callback)(t_weechat_plugin *, char *))
|
||||
{
|
||||
char *dir_home, *dir_name;
|
||||
int dir_length;
|
||||
|
||||
/* build directory, adding WeeChat home */
|
||||
dir_home = plugin->get_info (plugin, "weechat_dir", NULL, NULL);
|
||||
if (!dir_home)
|
||||
return;
|
||||
dir_length = strlen (dir_home) + strlen (language) + 16;
|
||||
dir_name =
|
||||
(char *) malloc (dir_length * sizeof (char));
|
||||
if (!dir_name)
|
||||
{
|
||||
free (dir_home);
|
||||
return;
|
||||
}
|
||||
snprintf (dir_name, dir_length, "%s/%s/autoload", dir_home, language);
|
||||
|
||||
plugin->exec_on_files (plugin, dir_name, callback);
|
||||
|
||||
free (dir_name);
|
||||
free (dir_home);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_script_search: search a script in list
|
||||
*/
|
||||
|
||||
t_plugin_script *
|
||||
weechat_script_search (t_weechat_plugin *plugin,
|
||||
t_plugin_script **list, char *name)
|
||||
{
|
||||
t_plugin_script *ptr_script;
|
||||
|
||||
for (ptr_script = *list; ptr_script;
|
||||
ptr_script = ptr_script->next_script)
|
||||
{
|
||||
if (plugin->ascii_strcasecmp (plugin, ptr_script->name, name) == 0)
|
||||
return ptr_script;
|
||||
}
|
||||
|
||||
/* script not found */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_script_add: add a script to list of scripts
|
||||
*/
|
||||
|
||||
t_plugin_script *
|
||||
weechat_script_add (t_weechat_plugin *plugin,
|
||||
t_plugin_script **script_list,
|
||||
char *filename,
|
||||
char *name, char *version,
|
||||
char *shutdown_func, char *description)
|
||||
{
|
||||
t_plugin_script *new_script;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) plugin;
|
||||
|
||||
new_script = (t_plugin_script *)malloc (sizeof (t_plugin_script));
|
||||
if (new_script)
|
||||
{
|
||||
new_script->filename = strdup (filename);
|
||||
new_script->interpreter = NULL;
|
||||
new_script->name = strdup (name);
|
||||
new_script->version = strdup (version);
|
||||
new_script->shutdown_func = strdup (shutdown_func);
|
||||
new_script->description = strdup (description);
|
||||
|
||||
/* add new script to list */
|
||||
if ((*script_list))
|
||||
(*script_list)->prev_script = new_script;
|
||||
new_script->prev_script = NULL;
|
||||
new_script->next_script = (*script_list);
|
||||
(*script_list) = new_script;
|
||||
return new_script;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_script_remove: remove a script from list of scripts
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_script_remove (t_weechat_plugin *plugin,
|
||||
t_plugin_script **script_list, t_plugin_script *script)
|
||||
{
|
||||
t_plugin_msg_handler *ptr_msg_handler, *next_msg_handler;
|
||||
t_plugin_cmd_handler *ptr_cmd_handler, *next_cmd_handler;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) plugin;
|
||||
|
||||
/* remove message handlers */
|
||||
ptr_msg_handler = plugin->msg_handlers;
|
||||
while (ptr_msg_handler)
|
||||
{
|
||||
if ((t_plugin_script *)ptr_msg_handler->msg_handler_pointer == script)
|
||||
{
|
||||
next_msg_handler = ptr_msg_handler->next_handler;
|
||||
plugin->msg_handler_remove (plugin, ptr_msg_handler);
|
||||
ptr_msg_handler = next_msg_handler;
|
||||
}
|
||||
else
|
||||
ptr_msg_handler = ptr_msg_handler->next_handler;
|
||||
}
|
||||
|
||||
/* remove command handlers */
|
||||
ptr_cmd_handler = plugin->cmd_handlers;
|
||||
while (ptr_cmd_handler)
|
||||
{
|
||||
if ((t_plugin_script *)ptr_cmd_handler->cmd_handler_pointer == script)
|
||||
{
|
||||
next_cmd_handler = ptr_cmd_handler->next_handler;
|
||||
plugin->cmd_handler_remove (plugin, ptr_cmd_handler);
|
||||
ptr_cmd_handler = next_cmd_handler;
|
||||
}
|
||||
else
|
||||
ptr_cmd_handler = ptr_cmd_handler->next_handler;
|
||||
}
|
||||
|
||||
/* free data */
|
||||
if (script->filename)
|
||||
free (script->filename);
|
||||
if (script->name)
|
||||
free (script->name);
|
||||
if (script->description)
|
||||
free (script->description);
|
||||
if (script->version)
|
||||
free (script->version);
|
||||
if (script->shutdown_func)
|
||||
free (script->shutdown_func);
|
||||
|
||||
/* remove script from list */
|
||||
if (script->prev_script)
|
||||
(script->prev_script)->next_script = script->next_script;
|
||||
else
|
||||
(*script_list) = script->next_script;
|
||||
if (script->next_script)
|
||||
(script->next_script)->prev_script = script->prev_script;
|
||||
|
||||
/* free script */
|
||||
free (script);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* This header is designed to be distributed with WeeChat plugins, if scripts
|
||||
management is needed */
|
||||
|
||||
#ifndef __WEECHAT_WEECHAT_SCRIPT_H
|
||||
#define __WEECHAT_WEECHAT_SCRIPT_H 1
|
||||
|
||||
typedef struct t_plugin_script t_plugin_script;
|
||||
|
||||
struct t_plugin_script
|
||||
{
|
||||
/* script variables */
|
||||
char *filename; /* name of script on disk */
|
||||
void *interpreter; /* interpreter for script */
|
||||
char *name; /* script name */
|
||||
char *description; /* plugin description */
|
||||
char *version; /* plugin version */
|
||||
char *shutdown_func; /* function when script is unloaded */
|
||||
|
||||
t_plugin_script *prev_script; /* link to previous script */
|
||||
t_plugin_script *next_script; /* link to next script */
|
||||
};
|
||||
|
||||
extern void weechat_script_auto_load (t_weechat_plugin *, char *,
|
||||
int (*)(t_weechat_plugin *, char *));
|
||||
extern t_plugin_script *weechat_script_search (t_weechat_plugin *,
|
||||
t_plugin_script **, char *);
|
||||
extern t_plugin_script *weechat_script_add (t_weechat_plugin *,
|
||||
t_plugin_script **, char *, char *,
|
||||
char *, char *, char *);
|
||||
extern void weechat_script_remove (t_weechat_plugin *,
|
||||
t_plugin_script **, t_plugin_script *);
|
||||
|
||||
#endif /* weechat-script.h */
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* This header is designed to be distributed with WeeChat plugins */
|
||||
|
||||
#ifndef __WEECHAT_WEECHAT_PLUGIN_H
|
||||
#define __WEECHAT_WEECHAT_PLUGIN_H 1
|
||||
|
||||
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_weechat_plugin t_weechat_plugin;
|
||||
|
||||
typedef int (t_plugin_handler_func) (t_weechat_plugin *, char *, char *, char *, char *, void *);
|
||||
|
||||
/* message handler, called when an IRC messages is received */
|
||||
|
||||
typedef struct t_plugin_msg_handler t_plugin_msg_handler;
|
||||
|
||||
struct t_plugin_msg_handler
|
||||
{
|
||||
char *irc_command; /* name of IRC command (PRIVMSG, ..) */
|
||||
t_plugin_handler_func *msg_handler; /* pointer to message handler */
|
||||
char *msg_handler_args; /* arguments sent to message handler */
|
||||
void *msg_handler_pointer; /* pointer sent to message handler */
|
||||
|
||||
int running; /* 1 if currently running */
|
||||
/* (used to prevent circular call) */
|
||||
t_plugin_msg_handler *prev_handler; /* link to previous handler */
|
||||
t_plugin_msg_handler *next_handler; /* link to next handler */
|
||||
};
|
||||
|
||||
/* command handler, to add new commands to WeeChat */
|
||||
|
||||
typedef struct t_plugin_cmd_handler t_plugin_cmd_handler;
|
||||
|
||||
struct t_plugin_cmd_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 */
|
||||
/* command handler */
|
||||
t_plugin_handler_func *cmd_handler; /* pointer to command handler */
|
||||
char *cmd_handler_args; /* arguments sent to command handler */
|
||||
void *cmd_handler_pointer; /* pointer sent to command handler */
|
||||
|
||||
int running; /* 1 if currently running */
|
||||
/* (used to prevent circular call) */
|
||||
t_plugin_cmd_handler *prev_handler; /* link to previous handler */
|
||||
t_plugin_cmd_handler *next_handler; /* link to next handler */
|
||||
};
|
||||
|
||||
/* plugin, a WeeChat plugin, which is a dynamic library */
|
||||
|
||||
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 */
|
||||
|
||||
/* plugin functions (interface) */
|
||||
int (*mkdir_home) (t_weechat_plugin *, char *);
|
||||
void (*exec_on_files) (t_weechat_plugin *, char *,
|
||||
int (*)(t_weechat_plugin *, char *));
|
||||
t_plugin_msg_handler *(*msg_handler_add) (t_weechat_plugin *, char *,
|
||||
t_plugin_handler_func *,
|
||||
char *, void *);
|
||||
void (*msg_handler_remove) (t_weechat_plugin *, t_plugin_msg_handler *);
|
||||
void (*msg_handler_remove_all) (t_weechat_plugin *);
|
||||
t_plugin_cmd_handler *(*cmd_handler_add) (t_weechat_plugin *, char *,
|
||||
char *, char *, char *,
|
||||
t_plugin_handler_func *,
|
||||
char *, void *);
|
||||
void (*cmd_handler_remove) (t_weechat_plugin *, t_plugin_cmd_handler *);
|
||||
void (*cmd_handler_remove_all) (t_weechat_plugin *);
|
||||
void (*printf) (t_weechat_plugin *, char *, char *, char *, ...);
|
||||
void (*printf_server) (t_weechat_plugin *, char *, ...);
|
||||
void (*infobar_printf) (t_weechat_plugin *, int, char *, ...);
|
||||
void (*exec_command) (t_weechat_plugin *, char *, char *, char *);
|
||||
char *(*get_info) (t_weechat_plugin *, char *, char *, char *);
|
||||
t_plugin_dcc_info *(*get_dcc_info) (t_weechat_plugin *);
|
||||
void (*free_dcc_info) (t_weechat_plugin *, t_plugin_dcc_info *);
|
||||
char **(*explode_string) (t_weechat_plugin *, char *, char *, int, int *);
|
||||
void (*free_exploded_string) (t_weechat_plugin *, char **);
|
||||
int (*ascii_strcasecmp) (t_weechat_plugin *, char *, char *);
|
||||
|
||||
/* plugin handlers */
|
||||
t_plugin_msg_handler *msg_handlers; /* IRC message handlers */
|
||||
t_plugin_msg_handler *last_msg_handler;
|
||||
t_plugin_cmd_handler *cmd_handlers; /* command handlers */
|
||||
t_plugin_cmd_handler *last_cmd_handler;
|
||||
|
||||
/* links to previous/next plugins */
|
||||
t_weechat_plugin *prev_plugin; /* link to previous plugin */
|
||||
t_weechat_plugin *next_plugin; /* link to next plugin */
|
||||
};
|
||||
|
||||
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 *));
|
||||
extern t_plugin_msg_handler *weechat_plugin_msg_handler_add (t_weechat_plugin *, char *,
|
||||
t_plugin_handler_func *,
|
||||
char *, void *);
|
||||
extern void weechat_plugin_msg_handler_remove (t_weechat_plugin *, t_plugin_msg_handler *);
|
||||
extern void weechat_plugin_msg_handler_remove_all (t_weechat_plugin *);
|
||||
extern t_plugin_cmd_handler *weechat_plugin_cmd_handler_add (t_weechat_plugin *, char *,
|
||||
char *, char *, char *,
|
||||
t_plugin_handler_func *,
|
||||
char *, void *);
|
||||
extern void weechat_plugin_cmd_handler_remove (t_weechat_plugin *, t_plugin_cmd_handler *);
|
||||
extern void weechat_plugin_cmd_handler_remove_all (t_weechat_plugin *);
|
||||
extern void weechat_plugin_printf (t_weechat_plugin *, char *, char *, char *, ...);
|
||||
extern void weechat_plugin_printf_server (t_weechat_plugin *, char *, ...);
|
||||
extern void weechat_plugin_infobar_printf (t_weechat_plugin *, int, char *, ...);
|
||||
extern void weechat_plugin_exec_command (t_weechat_plugin *, char *, char *, char *);
|
||||
extern char *weechat_plugin_get_info (t_weechat_plugin *, char *, 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_explode_string (t_weechat_plugin *, char *, char *, int, int *);
|
||||
extern void weechat_free_exploded_string (t_weechat_plugin *, char **);
|
||||
extern int weechat_ascii_strcasecmp (t_weechat_plugin *,char *, char *);
|
||||
|
||||
#endif /* weechat-plugin.h */
|
||||
+3
-1
@@ -1,10 +1,12 @@
|
||||
WeeChat - Wee Enhanced Environment for Chat
|
||||
===========================================
|
||||
|
||||
ChangeLog - 2005-10-03
|
||||
ChangeLog - 2005-10-15
|
||||
|
||||
|
||||
Version 0.1.6 (under dev!):
|
||||
* new plugin interface, rewritten from scratch: now loads dynamic C
|
||||
library, and perl/python are plugin scripts
|
||||
* added some missing IRC commands
|
||||
* added colors for input buffer and current channel of status bar
|
||||
* added online help for config options (with /set full_option_name)
|
||||
|
||||
@@ -6,6 +6,7 @@ cp Makefile.am Makefile.am.old
|
||||
gettextize --copy --force --intl --no-changelog &&
|
||||
mv Makefile.am.old Makefile.am
|
||||
mv configure.in.old configure.in
|
||||
libtoolize --force &&
|
||||
aclocal &&
|
||||
# autoheader creates config.h.in needed by autoconf
|
||||
autoheader &&
|
||||
|
||||
+94
-37
@@ -24,23 +24,23 @@ AC_CONFIG_SRCDIR([src/common/weechat.c])
|
||||
AM_CONFIG_HEADER(config.h)
|
||||
AM_INIT_AUTOMAKE([weechat], [0.1.6-cvs])
|
||||
|
||||
# Checks for programs.
|
||||
# Checks for programs
|
||||
AC_PROG_CC
|
||||
AC_PROG_MAKE_SET
|
||||
AC_PROG_RANLIB
|
||||
AM_PROG_LIBTOOL
|
||||
|
||||
# Gettext
|
||||
ALL_LINGUAS="fr es cs"
|
||||
AM_GNU_GETTEXT
|
||||
|
||||
# Checks for libraries.
|
||||
AC_CHECK_LIB([ncurses], [initscr], LIBNCURSES_FOUND=1, LIBNCURSES_FOUND=0)
|
||||
# Checks for libraries
|
||||
AC_CHECK_LIB(ncurses, initscr, LIBNCURSES_FOUND=1, LIBNCURSES_FOUND=0)
|
||||
|
||||
# Checks for header files.
|
||||
# Checks for header files
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS([arpa/inet.h libintl.h limits.h locale.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h sys/time.h sys/types.h unistd.h pwd.h errno.h])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
# Checks for typedefs, structures, and compiler characteristics
|
||||
AC_HEADER_TIME
|
||||
AC_STRUCT_TM
|
||||
|
||||
@@ -63,6 +63,11 @@ AC_FUNC_SELECT_ARGTYPES
|
||||
AC_TYPE_SIGNAL
|
||||
AC_CHECK_FUNCS([gethostbyname gethostname getsockname gettimeofday inet_ntoa memset mkdir select setlocale socket strcasecmp strchr strdup strncasecmp strpbrk strrchr strstr uname])
|
||||
|
||||
# Variables in config.h
|
||||
|
||||
AH_VERBATIM([PREFIX], [#undef PREFIX])
|
||||
AH_VERBATIM([WEECHAT_LIBDIR], [#undef WEECHAT_LIBDIR])
|
||||
AH_VERBATIM([WEECHAT_SHAREDIR], [#undef WEECHAT_SHAREDIR])
|
||||
AH_VERBATIM([PLUGINS], [#undef PLUGINS])
|
||||
AH_VERBATIM([PLUGIN_PERL], [#undef PLUGIN_PERL])
|
||||
AH_VERBATIM([PLUGIN_PYTHON], [#undef PLUGIN_PYTHON])
|
||||
@@ -70,27 +75,33 @@ AH_VERBATIM([PLUGIN_RUBY], [#undef PLUGIN_RUBY])
|
||||
AH_VERBATIM([HAVE_GNUTLS], [#undef HAVE_GNUTLS])
|
||||
AH_VERBATIM([DEBUG], [#undef DEBUG])
|
||||
|
||||
# Arguments for ./configure
|
||||
|
||||
AC_ARG_ENABLE(ncurses, [ --disable-ncurses Turn off ncurses interface (default=auto)],enable_ncurses=$enableval,enable_ncurses=yes)
|
||||
AC_ARG_ENABLE(wxwidgets,[ --enable-wxwidgets Turn on WxWidgets interface (default=no)],enable_wxwidgets=$enableval,enable_wxwidgets=no)
|
||||
AC_ARG_ENABLE(gtk, [ --enable-gtk Turn on Gtk+ interface (default=no)],enable_gtk=$enableval,enable_gtk=no)
|
||||
AC_ARG_ENABLE(qt, [ --enable-qt Turn on Qt interface (default=no)],enable_qt=$enableval,enable_qt=no)
|
||||
AC_ARG_ENABLE(perl, [ --enable-perl Turn on Perl plugins (default=no)],enable_perl=$enableval,enable_perl=no)
|
||||
AC_ARG_ENABLE(python, [ --enable-python Turn on Python plugins (default=no)],enable_python=$enableval,enable_python=no)
|
||||
AC_ARG_ENABLE(ruby, [ --enable-ruby Turn on Ruby plugins (default=no)],enable_ruby=$enableval,enable_ruby=no)
|
||||
AC_ARG_ENABLE(plugins, [ --disable-plugins Turn off plugins support (default=yes)],enable_plugins=$enableval,enable_plugins=yes)
|
||||
AC_ARG_ENABLE(perl, [ --enable-perl Turn on Perl script plugin (default=no)],enable_perl=$enableval,enable_perl=no)
|
||||
AC_ARG_ENABLE(python, [ --enable-python Turn on Python script plugin (default=no)],enable_python=$enableval,enable_python=no)
|
||||
AC_ARG_ENABLE(ruby, [ --enable-ruby Turn on Ruby script plugin (default=no)],enable_ruby=$enableval,enable_ruby=no)
|
||||
AC_ARG_ENABLE(gnutls, [ --disable-gnutls Turn off gnutls support (default=auto)],enable_gnutls=$enableval,enable_gnutls=yes)
|
||||
AC_ARG_WITH(debug, [ --with-debug Debugging: 0=no debug, 1=debug compilation, 2=debug compilation + verbose msgs (default=0)],debug=$withval,debug=0)
|
||||
|
||||
enable_plugins="no"
|
||||
|
||||
AM_CONDITIONAL(GUI_NCURSES, test "$enable_ncurses" = "yes")
|
||||
AM_CONDITIONAL(GUI_WXWIDGETS, test "$enable_wxwidgets" = "yes")
|
||||
AM_CONDITIONAL(GUI_GTK, test "$enable_gtk" = "yes")
|
||||
AM_CONDITIONAL(GUI_QT, test "$enable_qt" = "yes")
|
||||
AM_CONDITIONAL(PLUGINS, test "$enable_plugins" = "yes")
|
||||
AM_CONDITIONAL(PLUGIN_PERL, test "$enable_perl" = "yes")
|
||||
AM_CONDITIONAL(PLUGIN_PYTHON, test "$enable_python" = "yes")
|
||||
AM_CONDITIONAL(PLUGIN_RUBY, test "$enable_ruby" = "yes")
|
||||
AM_CONDITIONAL(HAVE_GNUTLS, test "$enable_gnutls" = "yes")
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# GUI
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
if test "x$enable_ncurses" = "xyes" ; then
|
||||
if test "$LIBNCURSES_FOUND" = "0" ; then
|
||||
AC_MSG_ERROR([
|
||||
@@ -136,6 +147,10 @@ if test "x$enable_gtk" = "xyes" ; then
|
||||
AC_SUBST(GTK_LIBS)
|
||||
fi
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# plugins
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
PLUGINS_LIBS=
|
||||
|
||||
if test "x$enable_perl" = "xyes" ; then
|
||||
@@ -169,7 +184,7 @@ it with your software package manager.])
|
||||
PERL_LIB_TEST=`PT=perltest.c ; echo "int main() { return 0; }" > $PT ; $CC -Wall $PT -o $PT.out $($PERL -MExtUtils::Embed -e ldopts) 1>/dev/null 2>&1; echo $?; rm -f $PT $PT.out 1>/dev/null 2>&1`
|
||||
|
||||
if test "x$PERL_LIB_TEST" = "x0" ; then
|
||||
PLUGINS_LIBS="$PLUGINS_LIBS ../../plugins/perl/lib_weechat_perl.a `$PERL -MExtUtils::Embed -e ldopts`"
|
||||
PERL_LFLAGS=`$PERL -MExtUtils::Embed -e ldopts`
|
||||
else
|
||||
AC_MSG_ERROR([
|
||||
*** Perl library couldn't be found in your system.
|
||||
@@ -178,6 +193,7 @@ it with your software package manager.])
|
||||
AC_MSG_RESULT(found)
|
||||
|
||||
AC_SUBST(PERL_CFLAGS)
|
||||
AC_SUBST(PERL_LFLAGS)
|
||||
AC_DEFINE(PLUGIN_PERL)
|
||||
fi
|
||||
|
||||
@@ -220,8 +236,8 @@ if test "x$enable_python" = "xyes" ; then
|
||||
fi
|
||||
AC_MSG_RESULT(found)
|
||||
|
||||
PLUGINS_LIBS="$PLUGINS_LIBS ../../plugins/python/lib_weechat_python.a $PYTHON_LFLAGS"
|
||||
AC_SUBST(PYTHON_CFLAGS)
|
||||
AC_SUBST(PYTHON_LFLAGS)
|
||||
AC_DEFINE(PLUGIN_PYTHON)
|
||||
fi
|
||||
|
||||
@@ -232,17 +248,32 @@ if test "x$enable_ruby" = "xyes" ; then
|
||||
|
||||
RUBY_CFLAGS=-I`ruby -rrbconfig -e "puts Config::CONFIG[['archdir']]"`
|
||||
RUBY_LFLAGS=`ruby -rrbconfig -e "puts Config::CONFIG[['LIBRUBYARG_SHARED']]"`
|
||||
PLUGINS_LIBS="$PLUGINS_LIBS ../../plugins/ruby/lib_weechat_ruby.a $RUBY_LFLAGS"
|
||||
AC_SUBST(RUBY_CFLAGS)
|
||||
AC_SUBST(RUBY_LFLAGS)
|
||||
AC_DEFINE(PLUGIN_RUBY)
|
||||
fi
|
||||
|
||||
if test "x$enable_plugins" = "xyes" ; then
|
||||
AC_DEFINE(PLUGINS)
|
||||
AC_CHECK_FUNCS(dlopen, LIBDL_FOUND=yes, LIBDL_FOUND=no)
|
||||
if test "$LIBDL_FOUND" != "yes"; then
|
||||
AC_CHECK_LIB(dl, dlopen, LIBDL_FOUND=yes, LIBDL_FOUND=no)
|
||||
fi
|
||||
if test "$LIBDL_FOUND" = "yes"; then
|
||||
PLUGINS_LIBS="../../plugins/lib_weechat_plugins.a -ldl"
|
||||
AC_DEFINE(PLUGINS)
|
||||
else
|
||||
AC_MSG_ERROR([
|
||||
*** "dl" library (dynamic library loader) couldn't be found in your system.
|
||||
*** Try to install it with your software package manager or disable plugins.])
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_SUBST(PLUGINS_LIBS)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# gnutls
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
if test "x$enable_gnutls" = "xyes" ; then
|
||||
found_gnutls="no"
|
||||
AM_PATH_LIBGNUTLS( 1.0.0, found_gnutls=yes, AC_MSG_WARN([[
|
||||
@@ -257,6 +288,29 @@ if test "x$enable_gnutls" = "xyes" ; then
|
||||
enable_gnutls="no"
|
||||
fi
|
||||
fi
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# general vars
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
if test "x$prefix" = "xNONE" ; then
|
||||
prefix="$ac_default_prefix"
|
||||
fi
|
||||
|
||||
if test "x$exec_prefix" = "xNONE" ; then
|
||||
exec_prefix="$prefix"
|
||||
fi
|
||||
|
||||
AC_DEFINE_UNQUOTED(PREFIX, "${prefix}")
|
||||
|
||||
WEECHAT_LIBDIR=`eval echo ${libdir}/weechat`
|
||||
AC_DEFINE_UNQUOTED(WEECHAT_LIBDIR, "$WEECHAT_LIBDIR")
|
||||
|
||||
WEECHAT_SHAREDIR=`eval echo ${datadir}/weechat`
|
||||
AC_DEFINE_UNQUOTED(WEECHAT_SHAREDIR, "$WEECHAT_SHAREDIR")
|
||||
|
||||
weechat_libdir=${libdir}/weechat
|
||||
AC_SUBST(weechat_libdir)
|
||||
|
||||
CFLAGS=`echo $CFLAGS | sed s/-g//g`
|
||||
if test "x$CFLAGS" = "x" ; then
|
||||
@@ -272,19 +326,23 @@ if test "x$debug" = "x2" ; then
|
||||
AC_DEFINE(DEBUG)
|
||||
fi
|
||||
|
||||
dnl For FreeBSD
|
||||
# for FreeBSD
|
||||
LIBS="$LIBS $INTLLIBS"
|
||||
CFLAGS="$CFLAGS $CPPFLAGS"
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# output Makefiles
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
AC_OUTPUT([Makefile
|
||||
doc/Makefile
|
||||
src/Makefile
|
||||
src/common/Makefile
|
||||
src/irc/Makefile
|
||||
src/plugins/Makefile
|
||||
src/plugins/perl/Makefile
|
||||
src/plugins/python/Makefile
|
||||
src/plugins/ruby/Makefile
|
||||
src/plugins/scripts/Makefile
|
||||
src/plugins/scripts/perl/Makefile
|
||||
src/plugins/scripts/python/Makefile
|
||||
src/gui/Makefile
|
||||
src/gui/curses/Makefile
|
||||
src/gui/wxwidgets/Makefile
|
||||
@@ -293,8 +351,9 @@ AC_OUTPUT([Makefile
|
||||
intl/Makefile
|
||||
po/Makefile.in])
|
||||
|
||||
echo
|
||||
echo $PACKAGE $VERSION
|
||||
# ------------------------------------------------------------------------------
|
||||
# end message
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
listgui=
|
||||
if test "x$enable_ncurses" = "xyes" ; then
|
||||
@@ -325,19 +384,17 @@ if test "x$debug" = "x2" ; then
|
||||
msg_debug_verbose="yes"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo Interfaces.................... :$listgui
|
||||
echo
|
||||
echo Build with Plugin support..... : $enable_plugins
|
||||
echo Build with Perl support....... : $enable_perl
|
||||
echo Build with Python support..... : $enable_python
|
||||
echo Build with Ruby support....... : $enable_ruby
|
||||
echo Build with GNUtls support..... : $enable_gnutls
|
||||
echo
|
||||
echo Compile with debug info....... : $msg_debug_compiler
|
||||
echo Print debugging messages...... : $msg_debug_verbose
|
||||
echo
|
||||
eval eval echo WeeChat will be installed in $bindir.
|
||||
echo
|
||||
echo configure complete, now type \'make\' to build WeeChat
|
||||
echo
|
||||
echo ""
|
||||
echo "Interfaces.................... :$listgui"
|
||||
echo "Build with GNUtls support..... : $enable_gnutls"
|
||||
echo "Build with Plugin support..... : $enable_plugins"
|
||||
echo " Perl plugin..... : $enable_perl"
|
||||
echo " Python plugin... : $enable_python"
|
||||
echo " Ruby plugin..... : $enable_ruby"
|
||||
echo "Compile with debug info....... : $msg_debug_compiler"
|
||||
echo "Print debugging messages...... : $msg_debug_verbose"
|
||||
echo ""
|
||||
eval echo "WeeChat will be installed in $bindir."
|
||||
echo ""
|
||||
echo "configure complete, now type 'make' to build WeeChat $VERSION"
|
||||
echo ""
|
||||
|
||||
@@ -8,14 +8,9 @@
|
||||
./src/irc/irc-dcc.c
|
||||
./src/irc/irc-ignore.c
|
||||
./src/irc/irc.h
|
||||
./src/plugins/perl/wee-perl.c
|
||||
./src/plugins/perl/wee-perl.h
|
||||
./src/plugins/python/wee-python.c
|
||||
./src/plugins/python/wee-python.h
|
||||
./src/plugins/ruby/wee-ruby.c
|
||||
./src/plugins/ruby/wee-ruby.h
|
||||
./src/plugins/plugins.c
|
||||
./src/plugins/plugins.h
|
||||
./src/plugins/weechat-plugin.h
|
||||
./src/gui/curses/gui-input.c
|
||||
./src/gui/curses/gui-display.c
|
||||
./src/gui/gtk/gui-display.c
|
||||
|
||||
+603
-691
File diff suppressed because it is too large
Load Diff
+622
-721
File diff suppressed because it is too large
Load Diff
+645
-716
File diff suppressed because it is too large
Load Diff
+609
-669
File diff suppressed because it is too large
Load Diff
+224
-480
@@ -89,21 +89,11 @@ t_weechat_command weechat_commands[] =
|
||||
"functions: list internal functions for key bindings\n"
|
||||
"reset: restore bindings to the default values and delete ALL personal binding (use carefully!)"),
|
||||
0, MAX_ARGS, NULL, weechat_cmd_key },
|
||||
{ "perl", N_("list/load/unload Perl scripts"),
|
||||
{ "plugin", N_("list/load/unload plugins"),
|
||||
N_("[load filename] | [autoload] | [reload] | [unload]"),
|
||||
N_("filename: Perl script (file) to load\n\n"
|
||||
"Without argument, /perl command lists all loaded Perl scripts."),
|
||||
0, 2, weechat_cmd_perl, NULL },
|
||||
{ "python", N_("list/load/unload Python scripts"),
|
||||
N_("[load filename] | [autoload] | [reload] | [unload]"),
|
||||
N_("filename: Python script (file) to load\n\n"
|
||||
"Without argument, /python command lists all loaded Python scripts."),
|
||||
0, 2, weechat_cmd_python, NULL },
|
||||
{ "ruby", N_("list/load/unload Ruby scripts"),
|
||||
N_("[load filename] | [autoload] | [reload] | [unload]"),
|
||||
N_("filename: Ruby script (file) to load\n\n"
|
||||
"Without argument, /ruby command lists all loaded Ruby scripts."),
|
||||
0, 2, weechat_cmd_ruby, NULL },
|
||||
N_("filename: WeeChat plugin (file) to load\n\n"
|
||||
"Without argument, /plugin command lists all loaded plugins."),
|
||||
0, 2, weechat_cmd_plugin, NULL },
|
||||
{ "server", N_("list, add or remove servers"),
|
||||
N_("[servername] | "
|
||||
"[servername hostname port [-auto | -noauto] [-ipv6] [-ssl] [-pwd password] [-nicks nick1 "
|
||||
@@ -381,7 +371,7 @@ alias_free_all ()
|
||||
*/
|
||||
|
||||
char **
|
||||
explode_string (/*@null@*/ char *string, char *separators, int num_items_max,
|
||||
explode_string (char *string, char *separators, int num_items_max,
|
||||
int *num_items)
|
||||
{
|
||||
int i, n_items;
|
||||
@@ -461,6 +451,23 @@ explode_string (/*@null@*/ char *string, char *separators, int num_items_max,
|
||||
return array;
|
||||
}
|
||||
|
||||
/*
|
||||
* free_exploded_string: free an exploded string
|
||||
*/
|
||||
|
||||
void
|
||||
free_exploded_string (char **exploded_string)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (exploded_string)
|
||||
{
|
||||
for (i = 0; exploded_string[i]; i++)
|
||||
free (exploded_string[i]);
|
||||
free (exploded_string);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* exec_weechat_command: executes a command (WeeChat internal or IRC)
|
||||
* returns: 1 if command was executed succesfully
|
||||
@@ -470,7 +477,7 @@ explode_string (/*@null@*/ char *string, char *separators, int num_items_max,
|
||||
int
|
||||
exec_weechat_command (t_irc_server *server, char *string)
|
||||
{
|
||||
int i, j, argc, return_code, length1, length2;
|
||||
int i, argc, return_code, length1, length2;
|
||||
char *command, *pos, *ptr_args, **argv, *alias_command;
|
||||
t_weechat_alias *ptr_alias;
|
||||
|
||||
@@ -502,7 +509,11 @@ exec_weechat_command (t_irc_server *server, char *string)
|
||||
ptr_args = NULL;
|
||||
}
|
||||
|
||||
if (!plugin_exec_command (command + 1, (server) ? server->name : "", ptr_args))
|
||||
#ifdef PLUGINS
|
||||
if (!plugin_cmd_handler_exec ((server) ? server->name : "", command + 1, ptr_args))
|
||||
#else
|
||||
if (1)
|
||||
#endif
|
||||
{
|
||||
argv = explode_string (ptr_args, " ", 0, &argc);
|
||||
|
||||
@@ -556,12 +567,7 @@ exec_weechat_command (t_irc_server *server, char *string)
|
||||
WEECHAT_ERROR, command + 1);
|
||||
}
|
||||
}
|
||||
if (argv)
|
||||
{
|
||||
for (j = 0; argv[j]; j++)
|
||||
free (argv[j]);
|
||||
free (argv);
|
||||
}
|
||||
free_exploded_string (argv);
|
||||
free (command);
|
||||
return 1;
|
||||
}
|
||||
@@ -626,12 +632,7 @@ exec_weechat_command (t_irc_server *server, char *string)
|
||||
WEECHAT_ERROR, command + 1);
|
||||
}
|
||||
}
|
||||
if (argv)
|
||||
{
|
||||
for (j = 0; argv[j]; j++)
|
||||
free (argv[j]);
|
||||
free (argv);
|
||||
}
|
||||
free_exploded_string (argv);
|
||||
free (command);
|
||||
return 1;
|
||||
}
|
||||
@@ -659,12 +660,7 @@ exec_weechat_command (t_irc_server *server, char *string)
|
||||
else
|
||||
(void) exec_weechat_command (server, ptr_alias->alias_command);
|
||||
|
||||
if (argv)
|
||||
{
|
||||
for (j = 0; argv[j]; j++)
|
||||
free (argv[j]);
|
||||
free (argv);
|
||||
}
|
||||
free_exploded_string (argv);
|
||||
free (command);
|
||||
return 1;
|
||||
}
|
||||
@@ -674,12 +670,7 @@ exec_weechat_command (t_irc_server *server, char *string)
|
||||
_("%s unknown command \"%s\" (type /help for help)\n"),
|
||||
WEECHAT_ERROR,
|
||||
command + 1);
|
||||
if (argv)
|
||||
{
|
||||
for (j = 0; argv[j]; j++)
|
||||
free (argv[j]);
|
||||
free (argv);
|
||||
}
|
||||
free_exploded_string (argv);
|
||||
}
|
||||
free (command);
|
||||
return 0;
|
||||
@@ -767,7 +758,9 @@ user_command (t_irc_server *server, t_gui_buffer *buffer, char *command)
|
||||
snprintf (plugin_args, plugin_args_length,
|
||||
"localhost PRIVMSG %s :%s",
|
||||
CHANNEL(buffer)->name, command);
|
||||
plugin_event_msg ("privmsg", server->name, plugin_args);
|
||||
#ifdef PLUGINS
|
||||
plugin_msg_handler_exec (server->name, "privmsg", plugin_args);
|
||||
#endif
|
||||
free (plugin_args);
|
||||
}
|
||||
else
|
||||
@@ -1294,88 +1287,144 @@ int
|
||||
weechat_cmd_help (int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
#ifdef PLUGINS
|
||||
t_weechat_plugin *ptr_plugin;
|
||||
t_plugin_cmd_handler *ptr_cmd_handler;
|
||||
#endif
|
||||
|
||||
if (argc == 0)
|
||||
switch (argc)
|
||||
{
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("%s internal commands:\n"), PACKAGE_NAME);
|
||||
for (i = 0; weechat_commands[i].command_name; i++)
|
||||
{
|
||||
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " %s",
|
||||
weechat_commands[i].command_name);
|
||||
gui_printf (NULL, " - %s\n",
|
||||
_(weechat_commands[i].command_description));
|
||||
}
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("IRC commands:\n"));
|
||||
for (i = 0; irc_commands[i].command_name; i++)
|
||||
{
|
||||
if (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg)
|
||||
case 0:
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("%s internal commands:\n"), PACKAGE_NAME);
|
||||
for (i = 0; weechat_commands[i].command_name; i++)
|
||||
{
|
||||
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " %s",
|
||||
irc_commands[i].command_name);
|
||||
gui_printf (NULL, " - %s\n",
|
||||
_(irc_commands[i].command_description));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (argc == 1)
|
||||
{
|
||||
for (i = 0; weechat_commands[i].command_name; i++)
|
||||
{
|
||||
if (ascii_strcasecmp (weechat_commands[i].command_name, argv[0]) == 0)
|
||||
{
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, "[w]");
|
||||
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " /%s",
|
||||
weechat_commands[i].command_name);
|
||||
if (weechat_commands[i].arguments &&
|
||||
weechat_commands[i].arguments[0])
|
||||
gui_printf (NULL, " %s\n",
|
||||
_(weechat_commands[i].arguments));
|
||||
else
|
||||
gui_printf (NULL, "\n");
|
||||
if (weechat_commands[i].command_description &&
|
||||
weechat_commands[i].command_description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
_(weechat_commands[i].command_description));
|
||||
if (weechat_commands[i].arguments_description &&
|
||||
weechat_commands[i].arguments_description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
_(weechat_commands[i].arguments_description));
|
||||
return 0;
|
||||
gui_printf (NULL, " - %s\n",
|
||||
_(weechat_commands[i].command_description));
|
||||
}
|
||||
}
|
||||
for (i = 0; irc_commands[i].command_name; i++)
|
||||
{
|
||||
if ((ascii_strcasecmp (irc_commands[i].command_name, argv[0]) == 0)
|
||||
&& (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg))
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("IRC commands:\n"));
|
||||
for (i = 0; irc_commands[i].command_name; i++)
|
||||
{
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, "[i]");
|
||||
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " /%s",
|
||||
irc_commands[i].command_name);
|
||||
if (irc_commands[i].arguments &&
|
||||
irc_commands[i].arguments[0])
|
||||
gui_printf (NULL, " %s\n",
|
||||
_(irc_commands[i].arguments));
|
||||
else
|
||||
gui_printf (NULL, "\n");
|
||||
if (irc_commands[i].command_description &&
|
||||
irc_commands[i].command_description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
if (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg)
|
||||
{
|
||||
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " %s",
|
||||
irc_commands[i].command_name);
|
||||
gui_printf (NULL, " - %s\n",
|
||||
_(irc_commands[i].command_description));
|
||||
if (irc_commands[i].arguments_description &&
|
||||
irc_commands[i].arguments_description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
_(irc_commands[i].arguments_description));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("No help available, \"%s\" is an unknown command\n"),
|
||||
argv[0]);
|
||||
#ifdef PLUGINS
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("Plugin commands:\n"));
|
||||
for (ptr_plugin = weechat_plugins; ptr_plugin;
|
||||
ptr_plugin = ptr_plugin->next_plugin)
|
||||
{
|
||||
for (ptr_cmd_handler = ptr_plugin->cmd_handlers; ptr_cmd_handler;
|
||||
ptr_cmd_handler = ptr_cmd_handler->next_handler)
|
||||
{
|
||||
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " %s",
|
||||
ptr_cmd_handler->command);
|
||||
if (ptr_cmd_handler->description
|
||||
&& ptr_cmd_handler->description[0])
|
||||
gui_printf (NULL, " - %s",
|
||||
ptr_cmd_handler->description);
|
||||
gui_printf (NULL, "\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case 1:
|
||||
for (i = 0; weechat_commands[i].command_name; i++)
|
||||
{
|
||||
if (ascii_strcasecmp (weechat_commands[i].command_name, argv[0]) == 0)
|
||||
{
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, "[w]");
|
||||
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " /%s",
|
||||
weechat_commands[i].command_name);
|
||||
if (weechat_commands[i].arguments &&
|
||||
weechat_commands[i].arguments[0])
|
||||
gui_printf (NULL, " %s\n",
|
||||
_(weechat_commands[i].arguments));
|
||||
else
|
||||
gui_printf (NULL, "\n");
|
||||
if (weechat_commands[i].command_description &&
|
||||
weechat_commands[i].command_description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
_(weechat_commands[i].command_description));
|
||||
if (weechat_commands[i].arguments_description &&
|
||||
weechat_commands[i].arguments_description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
_(weechat_commands[i].arguments_description));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
for (i = 0; irc_commands[i].command_name; i++)
|
||||
{
|
||||
if ((ascii_strcasecmp (irc_commands[i].command_name, argv[0]) == 0)
|
||||
&& (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg))
|
||||
{
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, "[i]");
|
||||
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " /%s",
|
||||
irc_commands[i].command_name);
|
||||
if (irc_commands[i].arguments &&
|
||||
irc_commands[i].arguments[0])
|
||||
gui_printf (NULL, " %s\n",
|
||||
_(irc_commands[i].arguments));
|
||||
else
|
||||
gui_printf (NULL, "\n");
|
||||
if (irc_commands[i].command_description &&
|
||||
irc_commands[i].command_description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
_(irc_commands[i].command_description));
|
||||
if (irc_commands[i].arguments_description &&
|
||||
irc_commands[i].arguments_description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
_(irc_commands[i].arguments_description));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#ifdef PLUGINS
|
||||
for (ptr_plugin = weechat_plugins; ptr_plugin;
|
||||
ptr_plugin = ptr_plugin->next_plugin)
|
||||
{
|
||||
for (ptr_cmd_handler = ptr_plugin->cmd_handlers; ptr_cmd_handler;
|
||||
ptr_cmd_handler = ptr_cmd_handler->next_handler)
|
||||
{
|
||||
if (ascii_strcasecmp (ptr_cmd_handler->command, argv[0]) == 0)
|
||||
{
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, "[p]");
|
||||
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " /%s",
|
||||
ptr_cmd_handler->command);
|
||||
if (ptr_cmd_handler->arguments &&
|
||||
ptr_cmd_handler->arguments[0])
|
||||
gui_printf (NULL, " %s\n",
|
||||
ptr_cmd_handler->arguments);
|
||||
else
|
||||
gui_printf (NULL, "\n");
|
||||
if (ptr_cmd_handler->description &&
|
||||
ptr_cmd_handler->description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
ptr_cmd_handler->description);
|
||||
if (ptr_cmd_handler->arguments_description &&
|
||||
ptr_cmd_handler->arguments_description[0])
|
||||
gui_printf (NULL, "\n%s\n",
|
||||
ptr_cmd_handler->arguments_description);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("No help available, \"%s\" is an unknown command\n"),
|
||||
argv[0]);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1601,92 +1650,82 @@ weechat_cmd_key (char *arguments)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_cmd_perl: list/load/unload Perl scripts
|
||||
* weechat_cmd_plugin: list/load/unload WeeChat plugins
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_cmd_perl (int argc, char **argv)
|
||||
weechat_cmd_plugin (int argc, char **argv)
|
||||
{
|
||||
#ifdef PLUGIN_PERL
|
||||
t_plugin_script *ptr_plugin_script;
|
||||
t_plugin_handler *ptr_plugin_handler;
|
||||
int handler_found, path_length;
|
||||
char *path_script;
|
||||
#ifdef PLUGINS
|
||||
t_weechat_plugin *ptr_plugin;
|
||||
t_plugin_msg_handler *ptr_msg_handler;
|
||||
t_plugin_cmd_handler *ptr_cmd_handler;
|
||||
|
||||
switch (argc)
|
||||
{
|
||||
case 0:
|
||||
/* list registered Perl scripts */
|
||||
/* list plugins */
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("Registered %s scripts:\n"), "Perl");
|
||||
if (perl_scripts)
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _("Plugins loaded:\n"));
|
||||
for (ptr_plugin = weechat_plugins; ptr_plugin;
|
||||
ptr_plugin = ptr_plugin->next_plugin)
|
||||
{
|
||||
for (ptr_plugin_script = perl_scripts; ptr_plugin_script;
|
||||
ptr_plugin_script = ptr_plugin_script->next_script)
|
||||
/* plugin info */
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, " %s v%s - %s (%s)\n",
|
||||
ptr_plugin->name,
|
||||
ptr_plugin->version,
|
||||
ptr_plugin->description,
|
||||
ptr_plugin->filename);
|
||||
|
||||
/* message handlers */
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" message handlers:\n"));
|
||||
for (ptr_msg_handler = ptr_plugin->msg_handlers;
|
||||
ptr_msg_handler;
|
||||
ptr_msg_handler = ptr_msg_handler->next_handler)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, " %s v%s%s%s\n",
|
||||
ptr_plugin_script->name,
|
||||
ptr_plugin_script->version,
|
||||
(ptr_plugin_script->description[0]) ? " - " : "",
|
||||
ptr_plugin_script->description);
|
||||
gui_printf (NULL, _(" IRC(%s)\n"),
|
||||
ptr_msg_handler->irc_command);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (none)\n"));
|
||||
}
|
||||
|
||||
/* list Perl message handlers */
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("%s message handlers:\n"), "Perl");
|
||||
handler_found = 0;
|
||||
for (ptr_plugin_handler = plugin_msg_handlers; ptr_plugin_handler;
|
||||
ptr_plugin_handler = ptr_plugin_handler->next_handler)
|
||||
{
|
||||
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PERL)
|
||||
if (!ptr_plugin->msg_handlers)
|
||||
{
|
||||
handler_found = 1;
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" IRC(%s) => %s(%s)\n"),
|
||||
ptr_plugin_handler->name,
|
||||
"Perl",
|
||||
ptr_plugin_handler->function_name);
|
||||
gui_printf (NULL, _(" (no message handler)\n"));
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
{
|
||||
|
||||
/* command handlers */
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (none)\n"));
|
||||
}
|
||||
|
||||
/* list Perl command handlers */
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("%s command handlers:\n"), "Perl");
|
||||
handler_found = 0;
|
||||
for (ptr_plugin_handler = plugin_cmd_handlers; ptr_plugin_handler;
|
||||
ptr_plugin_handler = ptr_plugin_handler->next_handler)
|
||||
{
|
||||
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PERL)
|
||||
gui_printf (NULL, _(" command handlers:\n"));
|
||||
for (ptr_cmd_handler = ptr_plugin->cmd_handlers;
|
||||
ptr_cmd_handler;
|
||||
ptr_cmd_handler = ptr_cmd_handler->next_handler)
|
||||
{
|
||||
handler_found = 1;
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" Command /%s => %s(%s)\n"),
|
||||
ptr_plugin_handler->name,
|
||||
"Perl",
|
||||
ptr_plugin_handler->function_name);
|
||||
gui_printf (NULL, " /%s",
|
||||
ptr_cmd_handler->command);
|
||||
if (ptr_cmd_handler->description
|
||||
&& ptr_cmd_handler->description[0])
|
||||
gui_printf (NULL, " (%s)",
|
||||
ptr_cmd_handler->description);
|
||||
gui_printf (NULL, "\n");
|
||||
}
|
||||
if (!ptr_plugin->cmd_handlers)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (no command handler)\n"));
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
if (!weechat_plugins)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (none)\n"));
|
||||
gui_printf (NULL, _(" (no plugin)\n"));
|
||||
}
|
||||
|
||||
break;
|
||||
case 1:
|
||||
if (ascii_strcasecmp (argv[0], "autoload") == 0)
|
||||
/*if (ascii_strcasecmp (argv[0], "autoload") == 0)
|
||||
plugin_auto_load (PLUGIN_TYPE_PERL, "perl/autoload");
|
||||
else if (ascii_strcasecmp (argv[0], "reload") == 0)
|
||||
{
|
||||
@@ -1694,337 +1733,42 @@ weechat_cmd_perl (int argc, char **argv)
|
||||
plugin_auto_load (PLUGIN_TYPE_PERL, "perl/autoload");
|
||||
}
|
||||
else if (ascii_strcasecmp (argv[0], "unload") == 0)
|
||||
plugin_unload (PLUGIN_TYPE_PERL, NULL);
|
||||
plugin_unload (PLUGIN_TYPE_PERL, NULL);*/
|
||||
break;
|
||||
case 2:
|
||||
if (ascii_strcasecmp (argv[0], "load") == 0)
|
||||
{
|
||||
/* load Perl script */
|
||||
if (strstr(argv[1], DIR_SEPARATOR))
|
||||
path_script = NULL;
|
||||
else
|
||||
{
|
||||
path_length = strlen (weechat_home) + strlen (argv[1]) + 7;
|
||||
path_script = (char *) malloc (path_length * sizeof (char));
|
||||
snprintf (path_script, path_length, "%s%s%s%s%s",
|
||||
weechat_home, DIR_SEPARATOR, "perl",
|
||||
DIR_SEPARATOR, argv[1]);
|
||||
}
|
||||
plugin_load (PLUGIN_TYPE_PERL,
|
||||
(path_script) ? path_script : argv[1]);
|
||||
if (path_script)
|
||||
free (path_script);
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s unknown option for \"%s\" command\n"),
|
||||
WEECHAT_ERROR, "perl");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s wrong argument count for \"%s\" command\n"),
|
||||
WEECHAT_ERROR, "perl");
|
||||
}
|
||||
#else
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("WeeChat was build without Perl support.\n"
|
||||
"Please rebuild WeeChat with "
|
||||
"\"--enable-perl\" option for ./configure script\n"));
|
||||
/* make gcc happy */
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
#endif /* PLUGIN_PERL */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_cmd_python: list/load/unload Python scripts
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_cmd_python (int argc, char **argv)
|
||||
{
|
||||
#ifdef PLUGIN_PYTHON
|
||||
t_plugin_script *ptr_plugin_script;
|
||||
t_plugin_handler *ptr_plugin_handler;
|
||||
int handler_found, path_length;
|
||||
char *path_script;
|
||||
|
||||
switch (argc)
|
||||
{
|
||||
case 0:
|
||||
/* list registered Python scripts */
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("Registered %s scripts:\n"), "Python");
|
||||
if (python_scripts)
|
||||
{
|
||||
for (ptr_plugin_script = python_scripts; ptr_plugin_script;
|
||||
ptr_plugin_script = ptr_plugin_script->next_script)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, " %s v%s%s%s\n",
|
||||
ptr_plugin_script->name,
|
||||
ptr_plugin_script->version,
|
||||
(ptr_plugin_script->description[0]) ? " - " : "",
|
||||
ptr_plugin_script->description);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (none)\n"));
|
||||
}
|
||||
|
||||
/* list Python message handlers */
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("%s message handlers:\n"), "Python");
|
||||
handler_found = 0;
|
||||
for (ptr_plugin_handler = plugin_msg_handlers; ptr_plugin_handler;
|
||||
ptr_plugin_handler = ptr_plugin_handler->next_handler)
|
||||
{
|
||||
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PYTHON)
|
||||
{
|
||||
handler_found = 1;
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" IRC(%s) => %s(%s)\n"),
|
||||
ptr_plugin_handler->name,
|
||||
"Python",
|
||||
ptr_plugin_handler->function_name);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (none)\n"));
|
||||
}
|
||||
|
||||
/* list Python command handlers */
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("%s command handlers:\n"), "Python");
|
||||
handler_found = 0;
|
||||
for (ptr_plugin_handler = plugin_cmd_handlers; ptr_plugin_handler;
|
||||
ptr_plugin_handler = ptr_plugin_handler->next_handler)
|
||||
{
|
||||
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PYTHON)
|
||||
{
|
||||
handler_found = 1;
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" Command /%s => %s(%s)\n"),
|
||||
ptr_plugin_handler->name,
|
||||
"Python",
|
||||
ptr_plugin_handler->function_name);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (none)\n"));
|
||||
}
|
||||
|
||||
break;
|
||||
case 1:
|
||||
if (ascii_strcasecmp (argv[0], "autoload") == 0)
|
||||
plugin_auto_load (PLUGIN_TYPE_PYTHON, "python/autoload");
|
||||
else if (ascii_strcasecmp (argv[0], "reload") == 0)
|
||||
{
|
||||
plugin_unload (PLUGIN_TYPE_PYTHON, NULL);
|
||||
plugin_auto_load (PLUGIN_TYPE_PYTHON, "python/autoload");
|
||||
/* load plugin */
|
||||
plugin_load (argv[1]);
|
||||
}
|
||||
else if (ascii_strcasecmp (argv[0], "unload") == 0)
|
||||
plugin_unload (PLUGIN_TYPE_PYTHON, NULL);
|
||||
break;
|
||||
case 2:
|
||||
if (ascii_strcasecmp (argv[0], "load") == 0)
|
||||
{
|
||||
/* load Python script */
|
||||
if (strstr(argv[1], DIR_SEPARATOR))
|
||||
path_script = NULL;
|
||||
else
|
||||
{
|
||||
path_length = strlen (weechat_home) + strlen (argv[1]) + 9;
|
||||
path_script = (char *) malloc (path_length * sizeof (char));
|
||||
snprintf (path_script, path_length, "%s%s%s%s%s",
|
||||
weechat_home, DIR_SEPARATOR, "python",
|
||||
DIR_SEPARATOR, argv[1]);
|
||||
}
|
||||
plugin_load (PLUGIN_TYPE_PYTHON,
|
||||
(path_script) ? path_script : argv[1]);
|
||||
if (path_script)
|
||||
free (path_script);
|
||||
/* unload plugin */
|
||||
plugin_unload_name (argv[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s unknown option for \"%s\" command\n"),
|
||||
WEECHAT_ERROR, "python");
|
||||
WEECHAT_ERROR, "plugin");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s wrong argument count for \"%s\" command\n"),
|
||||
WEECHAT_ERROR, "python");
|
||||
WEECHAT_ERROR, "plugin");
|
||||
}
|
||||
#else
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("WeeChat was build without Python support.\n"
|
||||
"Please rebuild WeeChat with "
|
||||
"\"--enable-python\" option for ./configure script\n"));
|
||||
_("Command \"plugin\" is not available, WeeChat was built "
|
||||
"without plugins support.\n"));
|
||||
/* make gcc happy */
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
#endif /* PLUGIN_PYTHON */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_cmd_ruby: list/load/unload Ruby scripts
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_cmd_ruby (int argc, char **argv)
|
||||
{
|
||||
#ifdef PLUGIN_RUBY
|
||||
t_plugin_script *ptr_plugin_script;
|
||||
t_plugin_handler *ptr_plugin_handler;
|
||||
int handler_found, path_length;
|
||||
char *path_script;
|
||||
|
||||
switch (argc)
|
||||
{
|
||||
case 0:
|
||||
/* list registered Ruby scripts */
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("Registered %s scripts:\n"), "Ruby");
|
||||
if (ruby_scripts)
|
||||
{
|
||||
for (ptr_plugin_script = ruby_scripts; ptr_plugin_script;
|
||||
ptr_plugin_script = ptr_plugin_script->next_script)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, " %s v%s%s%s\n",
|
||||
ptr_plugin_script->name,
|
||||
ptr_plugin_script->version,
|
||||
(ptr_plugin_script->description[0]) ? " - " : "",
|
||||
ptr_plugin_script->description);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (none)\n"));
|
||||
}
|
||||
|
||||
/* list Ruby message handlers */
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("%s message handlers:\n"), "Ruby");
|
||||
handler_found = 0;
|
||||
for (ptr_plugin_handler = plugin_msg_handlers; ptr_plugin_handler;
|
||||
ptr_plugin_handler = ptr_plugin_handler->next_handler)
|
||||
{
|
||||
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_RUBY)
|
||||
{
|
||||
handler_found = 1;
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" IRC(%s) => %s(%s)\n"),
|
||||
ptr_plugin_handler->name,
|
||||
"Ruby",
|
||||
ptr_plugin_handler->function_name);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (none)\n"));
|
||||
}
|
||||
|
||||
/* list Ruby command handlers */
|
||||
gui_printf (NULL, "\n");
|
||||
gui_printf (NULL, _("%s command handlers:\n"), "Ruby");
|
||||
handler_found = 0;
|
||||
for (ptr_plugin_handler = plugin_cmd_handlers; ptr_plugin_handler;
|
||||
ptr_plugin_handler = ptr_plugin_handler->next_handler)
|
||||
{
|
||||
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_RUBY)
|
||||
{
|
||||
handler_found = 1;
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" Command /%s => %s(%s)\n"),
|
||||
ptr_plugin_handler->name,
|
||||
"Ruby",
|
||||
ptr_plugin_handler->function_name);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _(" (none)\n"));
|
||||
}
|
||||
|
||||
break;
|
||||
case 1:
|
||||
if (ascii_strcasecmp (argv[0], "autoload") == 0)
|
||||
plugin_auto_load (PLUGIN_TYPE_RUBY, "ruby/autoload");
|
||||
else if (ascii_strcasecmp (argv[0], "reload") == 0)
|
||||
{
|
||||
plugin_unload (PLUGIN_TYPE_RUBY, NULL);
|
||||
plugin_auto_load (PLUGIN_TYPE_RUBY, "ruby/autoload");
|
||||
}
|
||||
else if (ascii_strcasecmp (argv[0], "unload") == 0)
|
||||
plugin_unload (PLUGIN_TYPE_RUBY, NULL);
|
||||
break;
|
||||
case 2:
|
||||
if (ascii_strcasecmp (argv[0], "load") == 0)
|
||||
{
|
||||
/* load Ruby script */
|
||||
if (strstr(argv[1], DIR_SEPARATOR))
|
||||
path_script = NULL;
|
||||
else
|
||||
{
|
||||
path_length = strlen (weechat_home) + strlen (argv[1]) + 9;
|
||||
path_script = (char *) malloc (path_length * sizeof (char));
|
||||
snprintf (path_script, path_length, "%s%s%s%s%s",
|
||||
weechat_home, DIR_SEPARATOR, "ruby",
|
||||
DIR_SEPARATOR, argv[1]);
|
||||
}
|
||||
plugin_load (PLUGIN_TYPE_RUBY,
|
||||
(path_script) ? path_script : argv[1]);
|
||||
if (path_script)
|
||||
free (path_script);
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s unknown option for \"%s\" command\n"),
|
||||
WEECHAT_ERROR, "ruby");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s wrong argument count for \"%s\" command\n"),
|
||||
WEECHAT_ERROR, "ruby");
|
||||
}
|
||||
#else
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("WeeChat was build without Ruby support.\n"
|
||||
"Please rebuild WeeChat with "
|
||||
"\"--enable-ruby\" option for ./configure script\n"));
|
||||
/* make gcc happy */
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
#endif /* PLUGIN_RUBY */
|
||||
#endif /* PLUGINS */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -60,6 +60,8 @@ extern void command_index_build ();
|
||||
extern void command_index_free ();
|
||||
extern t_weechat_alias *alias_new (char *, char *);
|
||||
extern void alias_free_all ();
|
||||
extern char **explode_string (char *, char *, int, int *);
|
||||
extern void free_exploded_string (char **);
|
||||
extern int exec_weechat_command (t_irc_server *, char *);
|
||||
extern void user_command (t_irc_server *, t_gui_buffer *, char *);
|
||||
extern int weechat_cmd_alias (char *);
|
||||
@@ -72,9 +74,7 @@ extern int weechat_cmd_help (int, char **);
|
||||
extern void weechat_cmd_ignore_display (char *, t_irc_ignore *);
|
||||
extern int weechat_cmd_ignore (int, char **);
|
||||
extern int weechat_cmd_key (char *);
|
||||
extern int weechat_cmd_perl (int, char **);
|
||||
extern int weechat_cmd_python (int, char **);
|
||||
extern int weechat_cmd_ruby (int, char **);
|
||||
extern int weechat_cmd_plugin (int, char **);
|
||||
extern int weechat_cmd_save (int, char **);
|
||||
extern int weechat_cmd_server (int, char **);
|
||||
extern int weechat_cmd_set (char *);
|
||||
|
||||
@@ -34,6 +34,10 @@
|
||||
#include "weeconfig.h"
|
||||
#include "../irc/irc.h"
|
||||
|
||||
#ifdef PLUGINS
|
||||
#include "../plugins/plugins.h"
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* completion_init: init completion
|
||||
@@ -108,6 +112,10 @@ completion_build_list (t_completion *completion, void *channel)
|
||||
t_config_option *option;
|
||||
void *option_value;
|
||||
char option_string[2048];
|
||||
#ifdef PLUGINS
|
||||
t_weechat_plugin *ptr_plugin;
|
||||
t_plugin_cmd_handler *ptr_cmd_handler;
|
||||
#endif
|
||||
|
||||
/* WeeChat internal commands */
|
||||
|
||||
@@ -200,6 +208,20 @@ completion_build_list (t_completion *completion, void *channel)
|
||||
&completion->last_completion,
|
||||
irc_commands[i].command_name);
|
||||
}
|
||||
#ifdef PLUGINS
|
||||
for (ptr_plugin = weechat_plugins; ptr_plugin;
|
||||
ptr_plugin = ptr_plugin->next_plugin)
|
||||
{
|
||||
for (ptr_cmd_handler = ptr_plugin->cmd_handlers;
|
||||
ptr_cmd_handler;
|
||||
ptr_cmd_handler = ptr_cmd_handler->next_handler)
|
||||
{
|
||||
weelist_add (&completion->completion_list,
|
||||
&completion->last_completion,
|
||||
ptr_cmd_handler->command);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
if (ascii_strcasecmp (completion->base_command, "ignore") == 0)
|
||||
@@ -312,8 +334,7 @@ completion_build_list (t_completion *completion, void *channel)
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (((ascii_strcasecmp (completion->base_command, "perl") == 0)
|
||||
|| (ascii_strcasecmp (completion->base_command, "python") == 0))
|
||||
if ((ascii_strcasecmp (completion->base_command, "plugin") == 0)
|
||||
&& (completion->base_command_arg == 1))
|
||||
{
|
||||
weelist_add (&completion->completion_list,
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
* ### Fast & light environment for Chat ###
|
||||
* ### ###
|
||||
* ### By FlashCode <flashcode@flashtux.org> ###
|
||||
### ###
|
||||
* ### ###
|
||||
* ### http://weechat.flashtux.org ###
|
||||
* ### ###
|
||||
* ############################################################################
|
||||
@@ -66,7 +66,10 @@
|
||||
#include "fifo.h"
|
||||
#include "../irc/irc.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
#ifdef PLUGINS
|
||||
#include "../plugins/plugins.h"
|
||||
#endif
|
||||
|
||||
|
||||
int quit_weechat; /* = 1 if quit request from user... why ? :'( */
|
||||
@@ -590,53 +593,6 @@ wee_create_home_dirs ()
|
||||
dir_length = strlen (weechat_home) + 64;
|
||||
dir_name = (char *) malloc (dir_length * sizeof (char));
|
||||
|
||||
#ifdef PLUGIN_PERL
|
||||
/* create "~/.weechat/perl" */
|
||||
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
|
||||
"perl");
|
||||
if (wee_create_dir (dir_name))
|
||||
{
|
||||
/* create "~/.weechat/perl/autoload" */
|
||||
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
|
||||
DIR_SEPARATOR, "perl", DIR_SEPARATOR, "autoload");
|
||||
wee_create_dir (dir_name);
|
||||
/* create "~/.weechat/perl/config" */
|
||||
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
|
||||
DIR_SEPARATOR, "perl", DIR_SEPARATOR, "config");
|
||||
wee_create_dir (dir_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_PYTHON
|
||||
/* create "~/.weechat/python" */
|
||||
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
|
||||
"python");
|
||||
if (wee_create_dir (dir_name))
|
||||
{
|
||||
/* create "~/.weechat/python/autoload" */
|
||||
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
|
||||
DIR_SEPARATOR, "python", DIR_SEPARATOR, "autoload");
|
||||
wee_create_dir (dir_name);
|
||||
/* create "~/.weechat/python/config" */
|
||||
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
|
||||
DIR_SEPARATOR, "python", DIR_SEPARATOR, "config");
|
||||
wee_create_dir (dir_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_RUBY
|
||||
/* create "~/.weechat/ruby" */
|
||||
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
|
||||
"ruby");
|
||||
if (wee_create_dir (dir_name))
|
||||
{
|
||||
/* create "~/.weechat/ruby/autoload" */
|
||||
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
|
||||
DIR_SEPARATOR, "ruby", DIR_SEPARATOR, "autoload");
|
||||
wee_create_dir (dir_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* create "~/.weechat/logs" */
|
||||
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
|
||||
"logs");
|
||||
@@ -925,14 +881,18 @@ main (int argc, char *argv[])
|
||||
|
||||
gui_init (); /* init WeeChat interface */
|
||||
weechat_welcome_message (); /* display WeeChat welcome message */
|
||||
plugin_init (); /* init plugin interface(s) */
|
||||
#ifdef PLUGINS
|
||||
plugin_init (); /* init plugin interface(s) */
|
||||
#endif
|
||||
/* auto-connect to servers */
|
||||
server_auto_connect (server_cmd_line);
|
||||
fifo_create (); /* create FIFO pipe for remote control */
|
||||
|
||||
gui_main_loop (); /* WeeChat main loop */
|
||||
|
||||
#ifdef PLUGINS
|
||||
plugin_end (); /* end plugin interface(s) */
|
||||
#endif
|
||||
server_disconnect_all (); /* disconnect from all servers */
|
||||
(void) config_write (NULL); /* save config file */
|
||||
command_index_free (); /* free commands index */
|
||||
|
||||
@@ -53,6 +53,7 @@ t_config_section config_sections[CONFIG_NUMBER_SECTIONS] =
|
||||
{ CONFIG_SECTION_IRC, "irc" },
|
||||
{ CONFIG_SECTION_DCC, "dcc" },
|
||||
{ CONFIG_SECTION_PROXY, "proxy" },
|
||||
{ CONFIG_SECTION_PLUGINS, "plugins" },
|
||||
{ CONFIG_SECTION_KEYS, "keys" },
|
||||
{ CONFIG_SECTION_ALIAS, "alias" },
|
||||
{ CONFIG_SECTION_IGNORE, "ignore" },
|
||||
@@ -747,6 +748,36 @@ t_config_option weechat_options_proxy[] =
|
||||
{ NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
/* config, plugins section */
|
||||
|
||||
char *cfg_plugins_path;
|
||||
char *cfg_plugins_autoload;
|
||||
char *cfg_plugins_extension;
|
||||
|
||||
t_config_option weechat_options_plugins[] =
|
||||
{ { "plugins_path", N_("path for searching plugins"),
|
||||
N_("path for searching plugins"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0,
|
||||
"~/.weechat/plugins", NULL, NULL, &cfg_plugins_path, config_change_noop },
|
||||
{ "plugins_autoload", N_("list of plugins to load automatically"),
|
||||
N_("comma separated list of plugins to load automatically at startup, "
|
||||
"\"*\" means all plugins found "
|
||||
"(names may be partial, for example \"perl\" is ok for \"libperl.so\")"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0,
|
||||
"*", NULL, NULL, &cfg_plugins_autoload, config_change_noop },
|
||||
{ "plugins_extension", N_("standard plugins extension in filename"),
|
||||
N_("standard plugins extension in filename, used for autoload "
|
||||
"(if empty, then all files are loaded when autoload is \"*\")"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0,
|
||||
#ifdef WIN32
|
||||
".dll",
|
||||
#else
|
||||
".so",
|
||||
#endif
|
||||
NULL, NULL, &cfg_plugins_extension, config_change_noop },
|
||||
{ NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
/* config, server section */
|
||||
|
||||
static t_irc_server cfg_server;
|
||||
@@ -836,7 +867,8 @@ t_config_option weechat_options_server[] =
|
||||
t_config_option *weechat_options[CONFIG_NUMBER_SECTIONS] =
|
||||
{ weechat_options_look, weechat_options_colors, weechat_options_history,
|
||||
weechat_options_log, weechat_options_irc, weechat_options_dcc,
|
||||
weechat_options_proxy, NULL, NULL, NULL, weechat_options_server
|
||||
weechat_options_proxy, weechat_options_plugins, NULL, NULL, NULL,
|
||||
weechat_options_server
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -33,11 +33,12 @@
|
||||
#define CONFIG_SECTION_IRC 4
|
||||
#define CONFIG_SECTION_DCC 5
|
||||
#define CONFIG_SECTION_PROXY 6
|
||||
#define CONFIG_SECTION_KEYS 7
|
||||
#define CONFIG_SECTION_ALIAS 8
|
||||
#define CONFIG_SECTION_IGNORE 9
|
||||
#define CONFIG_SECTION_SERVER 10
|
||||
#define CONFIG_NUMBER_SECTIONS 11
|
||||
#define CONFIG_SECTION_PLUGINS 7
|
||||
#define CONFIG_SECTION_KEYS 8
|
||||
#define CONFIG_SECTION_ALIAS 9
|
||||
#define CONFIG_SECTION_IGNORE 10
|
||||
#define CONFIG_SECTION_SERVER 11
|
||||
#define CONFIG_NUMBER_SECTIONS 12
|
||||
|
||||
#define OPTION_TYPE_BOOLEAN 1 /* values: on/off */
|
||||
#define OPTION_TYPE_INT 2 /* values: from min to max */
|
||||
@@ -202,6 +203,10 @@ extern int cfg_proxy_port;
|
||||
extern char *cfg_proxy_username;
|
||||
extern char *cfg_proxy_password;
|
||||
|
||||
extern char *cfg_plugins_path;
|
||||
extern char *cfg_plugins_autoload;
|
||||
extern char *cfg_plugins_extension;
|
||||
|
||||
extern t_config_section config_sections [CONFIG_NUMBER_SECTIONS];
|
||||
extern t_config_option * weechat_options [CONFIG_NUMBER_SECTIONS];
|
||||
|
||||
|
||||
@@ -140,6 +140,9 @@ weelist_remove (t_weelist **weelist, t_weelist **last_weelist, t_weelist *elemen
|
||||
{
|
||||
t_weelist *new_weelist;
|
||||
|
||||
if (!element)
|
||||
return;
|
||||
|
||||
/* remove element from list */
|
||||
if (*last_weelist == element)
|
||||
*last_weelist = element->prev_weelist;
|
||||
|
||||
@@ -22,8 +22,8 @@ bin_PROGRAMS = weechat-curses
|
||||
weechat_curses_LDADD = ../gui-common.o ../gui-keyboard.o \
|
||||
../../common/lib_weechat_main.a \
|
||||
../../irc/lib_weechat_irc.a \
|
||||
$(PLUGINS_LIBS) \
|
||||
$(NCURSES_LIBS) \
|
||||
../../plugins/lib_weechat_plugins.a $(PLUGINS_LIBS) \
|
||||
$(GNUTLS_LIBS)
|
||||
|
||||
weechat_curses_SOURCES = gui-display.c \
|
||||
|
||||
@@ -179,8 +179,13 @@ irc_recv_command (t_irc_server *server, char *entire_line,
|
||||
return_code = (int) (irc_commands[i].recv_function) (server, host, nick, arguments);
|
||||
if (nick)
|
||||
free (nick);
|
||||
#ifdef PLUGINS
|
||||
if (!command_ignored)
|
||||
plugin_event_msg (irc_commands[i].command_name, server->name, entire_line);
|
||||
plugin_msg_handler_exec (server->name, irc_commands[i].command_name, entire_line);
|
||||
#else
|
||||
/* make gcc happy */
|
||||
(void) entire_line;
|
||||
#endif
|
||||
return return_code;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,20 +18,21 @@
|
||||
INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\"
|
||||
|
||||
if PLUGIN_PERL
|
||||
perl_dir = perl
|
||||
script_dir = scripts
|
||||
endif
|
||||
|
||||
if PLUGIN_PYTHON
|
||||
python_dir = python
|
||||
script_dir = scripts
|
||||
endif
|
||||
|
||||
if PLUGIN_RUBY
|
||||
ruby_dir = ruby
|
||||
script_dir = scripts
|
||||
endif
|
||||
|
||||
SUBDIRS = $(perl_dir) $(python_dir) $(ruby_dir)
|
||||
SUBDIRS = $(script_dir)
|
||||
|
||||
noinst_LIBRARIES = lib_weechat_plugins.a
|
||||
|
||||
lib_weechat_plugins_a_SOURCES = plugins.h \
|
||||
lib_weechat_plugins_a_SOURCES = weechat-plugin.h \
|
||||
plugins.h \
|
||||
plugins.c
|
||||
|
||||
+1196
-425
File diff suppressed because it is too large
Load Diff
@@ -21,68 +21,24 @@
|
||||
#ifndef __WEECHAT_PLUGINS_H
|
||||
#define __WEECHAT_PLUGINS_H 1
|
||||
|
||||
#include "weechat-plugin.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
#define PLUGIN_TYPE_PERL 0
|
||||
#define PLUGIN_TYPE_PYTHON 1
|
||||
#define PLUGIN_TYPE_RUBY 2
|
||||
typedef int (t_weechat_init_func) (t_weechat_plugin *);
|
||||
typedef void (t_weechat_end_func) (t_weechat_plugin *);
|
||||
|
||||
typedef struct t_plugin_script t_plugin_script;
|
||||
extern t_weechat_plugin *weechat_plugins;
|
||||
extern t_weechat_plugin *last_weechat_plugin;
|
||||
|
||||
struct t_plugin_script
|
||||
{
|
||||
char *name; /* name of script */
|
||||
char *version; /* version of script */
|
||||
char *shutdown_func; /* function when script ends */
|
||||
char *description; /* description of script */
|
||||
t_plugin_script *prev_script; /* link to previous Perl script */
|
||||
t_plugin_script *next_script; /* link to next Perl script */
|
||||
};
|
||||
|
||||
typedef struct t_plugin_handler t_plugin_handler;
|
||||
|
||||
struct t_plugin_handler
|
||||
{
|
||||
int plugin_type; /* plugin type (Perl, Python, Ruby) */
|
||||
char *name; /* name of IRC command (PRIVMSG, ..)
|
||||
or command (without first '/') */
|
||||
char *function_name; /* name of function (handler) */
|
||||
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 */
|
||||
};
|
||||
|
||||
extern t_plugin_handler *plugin_msg_handlers;
|
||||
extern t_plugin_handler *last_plugin_msg_handler;
|
||||
|
||||
extern t_plugin_handler *plugin_cmd_handlers;
|
||||
extern t_plugin_handler *last_plugin_cmd_handler;
|
||||
|
||||
#ifdef PLUGIN_PERL
|
||||
extern t_plugin_script *perl_scripts;
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_PYTHON
|
||||
extern t_plugin_script *python_scripts;
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_RUBY
|
||||
extern t_plugin_script *ruby_scripts;
|
||||
#endif
|
||||
|
||||
extern void plugin_auto_load (int, char *);
|
||||
extern t_weechat_plugin *plugin_search (char *);
|
||||
extern int plugin_msg_handler_exec (char *, char *, char *);
|
||||
extern int plugin_cmd_handler_exec (char *, char *, char *);
|
||||
extern t_weechat_plugin *plugin_load (char *);
|
||||
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_init ();
|
||||
extern void plugin_load (int, char *);
|
||||
extern void plugin_unload (int, char *);
|
||||
extern t_plugin_handler *plugin_handler_search (t_plugin_handler *, char *);
|
||||
extern void plugin_handler_add (t_plugin_handler **, t_plugin_handler **,
|
||||
int, char *, char *);
|
||||
extern void plugin_handler_free_all_type (t_plugin_handler **,
|
||||
t_plugin_handler **, int);
|
||||
extern void plugin_event_msg (char *, char *, char *);
|
||||
extern int plugin_exec_command (char *, char *, char *);
|
||||
extern t_gui_buffer *plugin_find_buffer (char *, char *);
|
||||
extern void plugin_end ();
|
||||
|
||||
#endif /* plugins.h */
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
# Copyright (c) 2003-2005 FlashCode <flashcode@flashtux.org>
|
||||
#
|
||||
# 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 2 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, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\"
|
||||
|
||||
noinst_LTLIBRARIES = lib_weechat_plugins_scripts.la
|
||||
|
||||
lib_weechat_plugins_scripts_la_SOURCES = weechat-script.h \
|
||||
weechat-script.c
|
||||
|
||||
if PLUGIN_PERL
|
||||
perl_dir = perl
|
||||
endif
|
||||
|
||||
if PLUGIN_PYTHON
|
||||
python_dir = python
|
||||
endif
|
||||
|
||||
if PLUGIN_RUBY
|
||||
#ruby_dir = ruby
|
||||
endif
|
||||
|
||||
SUBDIRS = . $(perl_dir) $(python_dir) $(ruby_dir)
|
||||
@@ -0,0 +1,26 @@
|
||||
# Copyright (c) 2003-2005 FlashCode <flashcode@flashtux.org>
|
||||
#
|
||||
# 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 2 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, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(PERL_CFLAGS)
|
||||
|
||||
libdir = ${weechat_libdir}/plugins
|
||||
|
||||
lib_LTLIBRARIES = libperl.la
|
||||
|
||||
libperl_la_SOURCES = weechat-perl.c
|
||||
libperl_la_LDFLAGS = -module
|
||||
libperl_la_LIBADD = ../lib_weechat_plugins_scripts.la $(PERL_LFLAGS)
|
||||
@@ -0,0 +1,739 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* weechat-perl.c: Perl plugin support for WeeChat */
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <EXTERN.h>
|
||||
#include <perl.h>
|
||||
#include <XSUB.h>
|
||||
#undef _
|
||||
#include "../../weechat-plugin.h"
|
||||
#include "../weechat-script.h"
|
||||
|
||||
|
||||
char plugin_name[] = "Perl";
|
||||
char plugin_version[] = "0.1";
|
||||
char plugin_description[] = "Perl scripts support";
|
||||
|
||||
t_weechat_plugin *perl_plugin;
|
||||
|
||||
t_plugin_script *perl_scripts = NULL;
|
||||
t_plugin_script *current_perl_script = NULL;
|
||||
|
||||
static PerlInterpreter *my_perl = NULL;
|
||||
|
||||
extern void boot_DynaLoader (pTHX_ CV* cv);
|
||||
|
||||
|
||||
/*
|
||||
* weechat_perl_exec: execute a Perl script
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_perl_exec (t_weechat_plugin *plugin,
|
||||
t_plugin_script *script,
|
||||
char *function, char *server, char *arguments)
|
||||
{
|
||||
char empty_server[1] = { '\0' };
|
||||
char *argv[3];
|
||||
unsigned int count;
|
||||
int return_code;
|
||||
SV *sv;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) script;
|
||||
|
||||
dSP;
|
||||
ENTER;
|
||||
SAVETMPS;
|
||||
PUSHMARK(sp);
|
||||
if (!server)
|
||||
argv[0] = empty_server;
|
||||
else
|
||||
argv[0] = server;
|
||||
argv[1] = arguments;
|
||||
argv[2] = NULL;
|
||||
count = perl_call_argv (function, G_EVAL | G_SCALAR, argv);
|
||||
SPAGAIN;
|
||||
|
||||
sv = GvSV (gv_fetchpv ("@", TRUE, SVt_PV));
|
||||
return_code = 1;
|
||||
if (SvTRUE (sv))
|
||||
{
|
||||
plugin->printf_server (plugin, "Perl error: %s", SvPV (sv, count));
|
||||
POPs;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (count != 1)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Perl error: too much values from \"%s\" (%d). Expected: 1.",
|
||||
function, count);
|
||||
}
|
||||
else
|
||||
return_code = POPi;
|
||||
}
|
||||
|
||||
PUTBACK;
|
||||
FREETMPS;
|
||||
LEAVE;
|
||||
|
||||
return return_code;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_handler: general message and command handler for Perl
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_perl_handler (t_weechat_plugin *plugin,
|
||||
char *server, char *command, char *arguments,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
/* make gcc happy */
|
||||
(void) command;
|
||||
|
||||
weechat_perl_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
handler_args, server, arguments);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::register: startup function for all WeeChat Perl scripts
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_register)
|
||||
{
|
||||
char *name, *version, *shutdown_func, *description;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) items;
|
||||
(void) cv;
|
||||
|
||||
if (items != 4)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"register\" function");
|
||||
XSRETURN (0);
|
||||
return;
|
||||
}
|
||||
|
||||
name = SvPV (ST (0), integer);
|
||||
version = SvPV (ST (1), integer);
|
||||
shutdown_func = SvPV (ST (2), integer);
|
||||
description = SvPV (ST (3), integer);
|
||||
|
||||
if (weechat_script_search (perl_plugin, &perl_scripts, name))
|
||||
{
|
||||
/* error: another script already exists with this name! */
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: unable to register "
|
||||
"\"%s\" script (another script "
|
||||
"already exists with this name)",
|
||||
name);
|
||||
XSRETURN (0);
|
||||
return;
|
||||
}
|
||||
|
||||
/* register script */
|
||||
current_perl_script = weechat_script_add (perl_plugin,
|
||||
&perl_scripts,
|
||||
"",
|
||||
name, version, shutdown_func,
|
||||
description);
|
||||
if (current_perl_script)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl: registered script \"%s\", "
|
||||
"version %s (%s)",
|
||||
name, version, description);
|
||||
}
|
||||
else
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: unable to load script "
|
||||
"\"%s\" (not enough memory)",
|
||||
name);
|
||||
XSRETURN (0);
|
||||
return;
|
||||
}
|
||||
XSRETURN (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::print: print message into a buffer (current or specified one)
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_print)
|
||||
{
|
||||
unsigned int integer;
|
||||
char *message, *channel_name, *server_name;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if ((items < 1) || (items > 3))
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"print\" function");
|
||||
XSRETURN_NO;
|
||||
return;
|
||||
}
|
||||
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
|
||||
if (items > 1)
|
||||
{
|
||||
channel_name = SvPV (ST (1), integer);
|
||||
if (items > 2)
|
||||
server_name = SvPV (ST (2), integer);
|
||||
}
|
||||
|
||||
message = SvPV (ST (0), integer);
|
||||
perl_plugin->printf (perl_plugin,
|
||||
server_name, channel_name,
|
||||
"%s", message);
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::print_infobar: print message to infobar
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_print_infobar)
|
||||
{
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (items != 2)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"print_infobar\" function");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
perl_plugin->infobar_printf (perl_plugin,
|
||||
SvIV (ST (0)),
|
||||
SvPV (ST (1), integer));
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::command: send command to server
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_command)
|
||||
{
|
||||
unsigned int integer;
|
||||
char *channel_name, *server_name;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if ((items < 1) || (items > 3))
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"command\" function");
|
||||
XSRETURN_NO;
|
||||
return;
|
||||
}
|
||||
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
|
||||
if (items > 1)
|
||||
{
|
||||
channel_name = SvPV (ST (1), integer);
|
||||
if (items > 2)
|
||||
server_name = SvPV (ST (2), integer);
|
||||
}
|
||||
|
||||
perl_plugin->exec_command (perl_plugin,
|
||||
server_name, channel_name,
|
||||
SvPV (ST (0), integer));
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::add_message_handler: add handler for messages (privmsg, ...)
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_add_message_handler)
|
||||
{
|
||||
char *name, *function;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (items != 2)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"add_message_handler\" function");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
name = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (1), integer);
|
||||
perl_plugin->msg_handler_add (perl_plugin, name,
|
||||
weechat_perl_handler, function,
|
||||
(void *)current_perl_script);
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::add_command_handler: add command handler (define/redefine commands)
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_add_command_handler)
|
||||
{
|
||||
char *command, *function, *description, *arguments, *arguments_description;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (items < 2)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"add_command_handler\" function");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
command = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (1), integer);
|
||||
description = (items >= 3) ? SvPV (ST (2), integer) : NULL;
|
||||
arguments = (items >= 4) ? SvPV (ST (3), integer) : NULL;
|
||||
arguments_description = (items >= 5) ? SvPV (ST (4), integer) : NULL;
|
||||
|
||||
perl_plugin->cmd_handler_add (perl_plugin,
|
||||
command,
|
||||
description,
|
||||
arguments,
|
||||
arguments_description,
|
||||
weechat_perl_handler,
|
||||
function,
|
||||
(void *)current_perl_script);
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::get_info: get various infos
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_get_info)
|
||||
{
|
||||
char *arg, *info, *server_name, *channel_name;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if ((items < 1) || (items > 3))
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"get_info\" function");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
server_name = NULL;
|
||||
channel_name = NULL;
|
||||
|
||||
if (items >= 2)
|
||||
server_name = SvPV (ST (1), integer);
|
||||
if (items == 3)
|
||||
channel_name = SvPV (ST (2), integer);
|
||||
|
||||
arg = SvPV (ST (0), integer);
|
||||
if (arg)
|
||||
{
|
||||
info = perl_plugin->get_info (perl_plugin, arg, server_name, channel_name);
|
||||
|
||||
if (info)
|
||||
{
|
||||
XST_mPV (0, info);
|
||||
free (info);
|
||||
}
|
||||
else
|
||||
XST_mPV (0, "");
|
||||
}
|
||||
|
||||
XSRETURN (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::get_dcc_info: get infos about DCC
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_get_dcc_info)
|
||||
{
|
||||
t_plugin_dcc_info *dcc_info, *ptr_dcc;
|
||||
int dcc_count;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
(void) items;
|
||||
|
||||
dcc_info = perl_plugin->get_dcc_info (perl_plugin);
|
||||
dcc_count = 0;
|
||||
|
||||
if (!dcc_info)
|
||||
{
|
||||
XSRETURN (0);
|
||||
return;
|
||||
}
|
||||
|
||||
for (ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
|
||||
{
|
||||
HV *infohash = (HV *) sv_2mortal((SV *) newHV());
|
||||
|
||||
hv_store (infohash, "server", 6, newSVpv (ptr_dcc->server, 0), 0);
|
||||
hv_store (infohash, "channel", 7, newSVpv (ptr_dcc->channel, 0), 0);
|
||||
hv_store (infohash, "type", 4, newSViv (ptr_dcc->type), 0);
|
||||
hv_store (infohash, "status", 6, newSViv (ptr_dcc->status), 0);
|
||||
hv_store (infohash, "start_time", 10, newSViv (ptr_dcc->start_time), 0);
|
||||
hv_store (infohash, "start_transfer", 14, newSViv (ptr_dcc->start_transfer), 0);
|
||||
hv_store (infohash, "address", 7, newSViv (ptr_dcc->addr), 0);
|
||||
hv_store (infohash, "port", 4, newSViv (ptr_dcc->port), 0);
|
||||
hv_store (infohash, "nick", 4, newSVpv (ptr_dcc->nick, 0), 0);
|
||||
hv_store (infohash, "remote_file", 11, newSVpv (ptr_dcc->filename, 0), 0);
|
||||
hv_store (infohash, "local_file", 10, newSVpv (ptr_dcc->local_filename, 0), 0);
|
||||
hv_store (infohash, "filename_suffix", 15, newSViv (ptr_dcc->filename_suffix), 0);
|
||||
hv_store (infohash, "size", 4, newSVnv (ptr_dcc->size), 0);
|
||||
hv_store (infohash, "pos", 3, newSVnv (ptr_dcc->pos), 0);
|
||||
hv_store (infohash, "start_resume", 12, newSVnv (ptr_dcc->start_resume), 0);
|
||||
hv_store (infohash, "cps", 3, newSViv (ptr_dcc->bytes_per_sec), 0);
|
||||
|
||||
XPUSHs(newRV((SV *) infohash));
|
||||
dcc_count++;
|
||||
}
|
||||
|
||||
perl_plugin->free_dcc_info (perl_plugin, dcc_info);
|
||||
|
||||
XSRETURN (dcc_count);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_xs_init: initialize subroutines
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_perl_xs_init (pTHX)
|
||||
{
|
||||
newXS ("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__);
|
||||
|
||||
newXS ("weechat::register", XS_weechat_register, "weechat");
|
||||
newXS ("weechat::print", XS_weechat_print, "weechat");
|
||||
newXS ("weechat::print_infobar", XS_weechat_print_infobar, "weechat");
|
||||
newXS ("weechat::command", XS_weechat_command, "weechat");
|
||||
newXS ("weechat::add_message_handler", XS_weechat_add_message_handler, "weechat");
|
||||
newXS ("weechat::add_command_handler", XS_weechat_add_command_handler, "weechat");
|
||||
newXS ("weechat::get_info", XS_weechat_get_info, "weechat");
|
||||
newXS ("weechat::get_dcc_info", XS_weechat_get_dcc_info, "weechat");
|
||||
}
|
||||
|
||||
/*
|
||||
* wee_perl_load: load a Perl script
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_perl_load (t_weechat_plugin *plugin, char *filename)
|
||||
{
|
||||
plugin->printf_server (plugin, "Loading Perl script \"%s\"", filename);
|
||||
return weechat_perl_exec (plugin, NULL, "wee_perl_load_eval_file", filename, "");
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_unload: unload a Perl script
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_perl_unload (t_weechat_plugin *plugin, t_plugin_script *script)
|
||||
{
|
||||
if (script->shutdown_func && script->shutdown_func[0])
|
||||
weechat_perl_exec (plugin, script, script->shutdown_func, "", "");
|
||||
|
||||
weechat_script_remove (plugin, &perl_scripts, script);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_unload_all: unload all Perl scripts
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_perl_unload_all (t_weechat_plugin *plugin)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Unloading all Perl scripts");
|
||||
while (perl_scripts)
|
||||
weechat_perl_unload (plugin, perl_scripts);
|
||||
|
||||
plugin->printf_server (plugin,
|
||||
"Perl scripts unloaded");
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_cmd: /perl command handler
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_perl_cmd (t_weechat_plugin *plugin,
|
||||
char *server, char *command, char *arguments,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
int argc, path_length, handler_found;
|
||||
char **argv, *path_script, *dir_home;
|
||||
t_plugin_script *ptr_plugin_script;
|
||||
t_plugin_msg_handler *ptr_msg_handler;
|
||||
t_plugin_cmd_handler *ptr_cmd_handler;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) server;
|
||||
(void) command;
|
||||
(void) handler_args;
|
||||
(void) handler_pointer;
|
||||
|
||||
argv = plugin->explode_string (plugin, arguments, " ", 0, &argc);
|
||||
|
||||
switch (argc)
|
||||
{
|
||||
case 0:
|
||||
/* list registered Perl scripts */
|
||||
plugin->printf_server (plugin, "");
|
||||
plugin->printf_server (plugin, "Registered Perl scripts:");
|
||||
if (perl_scripts)
|
||||
{
|
||||
for (ptr_plugin_script = perl_scripts; ptr_plugin_script;
|
||||
ptr_plugin_script = ptr_plugin_script->next_script)
|
||||
{
|
||||
plugin->printf_server (plugin, " %s v%s%s%s",
|
||||
ptr_plugin_script->name,
|
||||
ptr_plugin_script->version,
|
||||
(ptr_plugin_script->description[0]) ? " - " : "",
|
||||
ptr_plugin_script->description);
|
||||
}
|
||||
}
|
||||
else
|
||||
plugin->printf_server (plugin, " (none)");
|
||||
|
||||
/* list Perl message handlers */
|
||||
plugin->printf_server (plugin, "");
|
||||
plugin->printf_server (plugin, "Perl message handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_msg_handler = plugin->msg_handlers; ptr_msg_handler;
|
||||
ptr_msg_handler = ptr_msg_handler->next_handler)
|
||||
{
|
||||
if (ptr_msg_handler->msg_handler_args)
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->printf_server (plugin, " IRC(%s) => Perl(%s)",
|
||||
ptr_msg_handler->irc_command,
|
||||
ptr_msg_handler->msg_handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->printf_server (plugin, " (none)");
|
||||
|
||||
/* list Perl command handlers */
|
||||
plugin->printf_server (plugin, "");
|
||||
plugin->printf_server (plugin, "Perl command handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_cmd_handler = plugin->cmd_handlers; ptr_cmd_handler;
|
||||
ptr_cmd_handler = ptr_cmd_handler->next_handler)
|
||||
{
|
||||
if (ptr_cmd_handler->cmd_handler_args)
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->printf_server (plugin, " /%s => Perl(%s)",
|
||||
ptr_cmd_handler->command,
|
||||
ptr_cmd_handler->cmd_handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->printf_server (plugin, " (none)");
|
||||
break;
|
||||
case 1:
|
||||
if (plugin->ascii_strcasecmp (plugin, argv[0], "autoload") == 0)
|
||||
weechat_script_auto_load (plugin, "perl", weechat_perl_load);
|
||||
else if (plugin->ascii_strcasecmp (plugin, argv[0], "reload") == 0)
|
||||
{
|
||||
weechat_perl_unload_all (plugin);
|
||||
weechat_script_auto_load (plugin, "perl", weechat_perl_load);
|
||||
}
|
||||
else if (plugin->ascii_strcasecmp (plugin, argv[0], "unload") == 0)
|
||||
weechat_perl_unload_all (plugin);
|
||||
break;
|
||||
case 2:
|
||||
if (plugin->ascii_strcasecmp (plugin, argv[0], "load") == 0)
|
||||
{
|
||||
/* load Perl script */
|
||||
if ((strstr (argv[1], "/")) || (strstr (argv[1], "\\")))
|
||||
path_script = NULL;
|
||||
else
|
||||
{
|
||||
dir_home = plugin->get_info (plugin, "weechat_dir", NULL, NULL);
|
||||
if (dir_home)
|
||||
{
|
||||
path_length = strlen (dir_home) + strlen (argv[1]) + 16;
|
||||
path_script = (char *) malloc (path_length * sizeof (char));
|
||||
if (path_script)
|
||||
snprintf (path_script, path_length, "%s/perl/%s",
|
||||
dir_home, argv[1]);
|
||||
else
|
||||
path_script = NULL;
|
||||
free (dir_home);
|
||||
}
|
||||
else
|
||||
path_script = NULL;
|
||||
}
|
||||
weechat_perl_load (plugin, (path_script) ? path_script : argv[1]);
|
||||
if (path_script)
|
||||
free (path_script);
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Perl error: unknown option for "
|
||||
"\"perl\" command");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
plugin->printf_server (plugin,
|
||||
"Perl error: wrong argument count for \"perl\" command");
|
||||
}
|
||||
plugin->free_exploded_string (plugin, argv);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_init: initialize Perl plugin
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_plugin_init (t_weechat_plugin *plugin)
|
||||
{
|
||||
char *perl_args[] = { "", "-e", "0" };
|
||||
/* Following Perl code is extracted/modified from X-Chat IRC client */
|
||||
/* X-Chat is (c) 1998-2005 Peter Zelezny */
|
||||
char *weechat_perl_func =
|
||||
{
|
||||
"sub wee_perl_load_file"
|
||||
"{"
|
||||
" my $filename = shift;"
|
||||
" local $/ = undef;"
|
||||
" open FILE, $filename or return \"__WEECHAT_ERROR__\";"
|
||||
" $_ = <FILE>;"
|
||||
" close FILE;"
|
||||
" return $_;"
|
||||
"}"
|
||||
"sub wee_perl_load_eval_file"
|
||||
"{"
|
||||
" my $filename = shift;"
|
||||
" my $content = wee_perl_load_file ($filename);"
|
||||
" if ($content eq \"__WEECHAT_ERROR__\")"
|
||||
" {"
|
||||
" weechat::print \"Perl error: script '$filename' not found.\", \"\";"
|
||||
" return 1;"
|
||||
" }"
|
||||
" eval $content;"
|
||||
" if ($@)"
|
||||
" {"
|
||||
" weechat::print \"Perl error: unable to load script '$filename':\", \"\";"
|
||||
" weechat::print \"$@\";"
|
||||
" return 2;"
|
||||
" }"
|
||||
" return 0;"
|
||||
"}"
|
||||
"$SIG{__WARN__} = sub { weechat::print \"$_[0]\", \"\"; };"
|
||||
};
|
||||
|
||||
perl_plugin = plugin;
|
||||
|
||||
plugin->printf_server (plugin, "Loading Perl module \"weechat\"");
|
||||
|
||||
my_perl = perl_alloc ();
|
||||
if (!my_perl)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Perl error: unable to initialize Perl");
|
||||
return 0;
|
||||
}
|
||||
perl_construct (my_perl);
|
||||
perl_parse (my_perl, weechat_perl_xs_init, 3, perl_args, NULL);
|
||||
eval_pv (weechat_perl_func, TRUE);
|
||||
|
||||
plugin->cmd_handler_add (plugin, "perl",
|
||||
"list/load/unload Perl scripts",
|
||||
"[load filename] | [autoload] | [reload] | [unload]",
|
||||
"filename: Perl script (file) to load\n\n"
|
||||
"Without argument, /perl command lists all loaded Perl scripts.",
|
||||
weechat_perl_cmd, NULL, NULL);
|
||||
|
||||
plugin->mkdir_home (plugin, "perl");
|
||||
plugin->mkdir_home (plugin, "perl/autoload");
|
||||
|
||||
weechat_script_auto_load (plugin, "perl", weechat_perl_load);
|
||||
|
||||
/* init ok */
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_end: shutdown Perl interface
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_plugin_end (t_weechat_plugin *plugin)
|
||||
{
|
||||
/* unload all scripts */
|
||||
weechat_perl_unload_all (plugin);
|
||||
|
||||
/* free Perl interpreter */
|
||||
if (my_perl)
|
||||
{
|
||||
perl_destruct (my_perl);
|
||||
perl_free (my_perl);
|
||||
my_perl = NULL;
|
||||
}
|
||||
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl plugin ended");
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
# Copyright (c) 2003-2005 FlashCode <flashcode@flashtux.org>
|
||||
#
|
||||
# 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 2 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, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(PYTHON_CFLAGS)
|
||||
|
||||
libdir = ${weechat_libdir}/plugins
|
||||
|
||||
lib_LTLIBRARIES = libpython.la
|
||||
|
||||
libpython_la_SOURCES = weechat-python.c
|
||||
libpython_la_LDFLAGS = -module
|
||||
libpython_la_LIBADD = ../lib_weechat_plugins_scripts.la $(PYTHON_LFLAGS)
|
||||
@@ -0,0 +1,855 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* weechat-python.c: Python plugin support for WeeChat */
|
||||
|
||||
|
||||
#include <Python.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#undef _
|
||||
#include "../../weechat-plugin.h"
|
||||
#include "../weechat-script.h"
|
||||
|
||||
|
||||
char plugin_name[] = "Python";
|
||||
char plugin_version[] = "0.1";
|
||||
char plugin_description[] = "Python scripts support";
|
||||
|
||||
t_weechat_plugin *python_plugin;
|
||||
|
||||
t_plugin_script *python_scripts = NULL;
|
||||
t_plugin_script *python_current_script = NULL;
|
||||
char *python_current_script_filename = NULL;
|
||||
PyThreadState *python_mainThreadState = NULL;
|
||||
|
||||
|
||||
/*
|
||||
* weechat_python_exec: execute a Python script
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_python_exec (t_weechat_plugin *plugin,
|
||||
t_plugin_script *script,
|
||||
char *function, char *server, char *arguments)
|
||||
{
|
||||
PyObject *evMain;
|
||||
PyObject *evDict;
|
||||
PyObject *evFunc;
|
||||
|
||||
PyThreadState_Swap (NULL);
|
||||
|
||||
PyEval_AcquireLock ();
|
||||
|
||||
PyThreadState_Swap (script->interpreter);
|
||||
|
||||
evMain = PyImport_AddModule ((char *) "__main__");
|
||||
evDict = PyModule_GetDict (evMain);
|
||||
evFunc = PyDict_GetItemString (evDict, function);
|
||||
|
||||
if ( !(evFunc && PyCallable_Check (evFunc)) )
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: unable to run function \"%s\"",
|
||||
function);
|
||||
PyEval_ReleaseLock();
|
||||
return 1;
|
||||
}
|
||||
|
||||
PyObject_CallFunction(evFunc, "ss", server == NULL ? "" : server, arguments == NULL ? "" : arguments);
|
||||
|
||||
PyEval_ReleaseLock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_handler: general message and command handler for Python
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_python_handler (t_weechat_plugin *plugin,
|
||||
char *server, char *command, char *arguments,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
/* make gcc happy */
|
||||
(void) command;
|
||||
|
||||
weechat_python_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
handler_args, server, arguments);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.register: startup function for all WeeChat Python scripts
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_register (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *name, *version, *shutdown_func, *description;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
name = NULL;
|
||||
version = NULL;
|
||||
shutdown_func = NULL;
|
||||
description = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ssss", &name, &version, &shutdown_func, &description))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"register\" function");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (weechat_script_search (python_plugin, &python_scripts, name))
|
||||
{
|
||||
/* error: another scripts already exists with this name! */
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to register "
|
||||
"\"%s\" script (another script "
|
||||
"already exists with this name)",
|
||||
name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* register script */
|
||||
python_current_script = weechat_script_add (python_plugin,
|
||||
&python_scripts,
|
||||
(python_current_script_filename) ?
|
||||
python_current_script_filename : "",
|
||||
name, version, shutdown_func,
|
||||
description);
|
||||
if (python_current_script)
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python: registered script \"%s\", "
|
||||
"version %s (%s)",
|
||||
name, version, description);
|
||||
}
|
||||
else
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to load script "
|
||||
"\"%s\" (not enough memory)",
|
||||
name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.print: print message into a buffer (current or specified one)
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_print (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *message, *channel_name, *server_name;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
message = NULL;
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s|ss", &message, &channel_name, &server_name))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"print\" function");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
python_plugin->printf (python_plugin,
|
||||
server_name, channel_name,
|
||||
"%s", message);
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.print_infobar: print message to infobar
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_print_infobar (PyObject *self, PyObject *args)
|
||||
{
|
||||
int delay;
|
||||
char *message;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
delay = 1;
|
||||
message = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "is", &delay, &message))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"print_infobar\" function");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
python_plugin->infobar_printf (python_plugin, delay, message);
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.command: send command to server
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_command (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *command, *channel_name, *server_name;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
command = NULL;
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s|ss", &command, &channel_name, &server_name))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"command\" function");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
python_plugin->exec_command (python_plugin,
|
||||
server_name, channel_name,
|
||||
command);
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.add_message_handler: add handler for messages
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_add_message_handler (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *message, *function;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
message = NULL;
|
||||
function = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ss", &message, &function))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"add_message_handler\" function");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (python_current_script)
|
||||
python_plugin->msg_handler_add (python_plugin, message,
|
||||
weechat_python_handler, function,
|
||||
(void *)python_current_script);
|
||||
else
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to add message handler, "
|
||||
"script not initialized");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.add_command_handler: define/redefines commands
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_add_command_handler (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *command, *function, *description, *arguments, *arguments_description;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
command = NULL;
|
||||
function = NULL;
|
||||
description = NULL;
|
||||
arguments = NULL;
|
||||
arguments_description = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ss|sss", &command, &function,
|
||||
&description, &arguments, &arguments_description))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"add_command_handler\" function");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (python_current_script)
|
||||
python_plugin->cmd_handler_add (python_plugin,
|
||||
command,
|
||||
description,
|
||||
arguments,
|
||||
arguments_description,
|
||||
weechat_python_handler,
|
||||
function,
|
||||
(void *)python_current_script);
|
||||
else
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to add command handler, "
|
||||
"script not initialized");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.get_info: get various infos
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_get_info (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *arg, *server_name, *channel_name, *info;
|
||||
PyObject *object;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
arg = NULL;
|
||||
server_name = NULL;
|
||||
channel_name = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s|ss", &arg, &server_name, &channel_name))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"get_info\" function");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (arg)
|
||||
{
|
||||
info = python_plugin->get_info (python_plugin, arg, server_name, channel_name);
|
||||
|
||||
if (info)
|
||||
{
|
||||
object = Py_BuildValue ("s", info);
|
||||
free (info);
|
||||
return object;
|
||||
}
|
||||
else
|
||||
return Py_BuildValue ("s", "");
|
||||
}
|
||||
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.get_dcc_info: get infos about DCC
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_get_dcc_info (PyObject *self, PyObject *args)
|
||||
{
|
||||
t_plugin_dcc_info *dcc_info, *ptr_dcc;
|
||||
int dcc_count;
|
||||
PyObject *list, *listvalue;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
(void) args;
|
||||
|
||||
dcc_info = python_plugin->get_dcc_info (python_plugin);
|
||||
dcc_count = 0;
|
||||
|
||||
if (!dcc_info)
|
||||
return Py_None;
|
||||
|
||||
for (ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
|
||||
{
|
||||
dcc_count++;
|
||||
}
|
||||
|
||||
list = PyList_New (dcc_count);
|
||||
|
||||
if (!list)
|
||||
{
|
||||
python_plugin->free_dcc_info (python_plugin, dcc_info);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
dcc_count = 0;
|
||||
for(ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
|
||||
{
|
||||
listvalue = Py_BuildValue ("{s:s,s:s,s:i,s:i,s:k,s:k,s:k,s:i,s:s,s:s,"
|
||||
"s:s,s:s,s:k,s:k,s:k,s:k}",
|
||||
"server", ptr_dcc->server,
|
||||
"channel", ptr_dcc->channel,
|
||||
"type", ptr_dcc->type,
|
||||
"status", ptr_dcc->status,
|
||||
"start_time", ptr_dcc->start_time,
|
||||
"start_transfer", ptr_dcc->start_transfer,
|
||||
"address", ptr_dcc->addr,
|
||||
"port", ptr_dcc->port,
|
||||
"nick", ptr_dcc->nick,
|
||||
"remote_file", ptr_dcc->filename,
|
||||
"local_file", ptr_dcc->local_filename,
|
||||
"filename_suffix", ptr_dcc->filename_suffix,
|
||||
"size", ptr_dcc->size,
|
||||
"pos", ptr_dcc->pos,
|
||||
"start_resume", ptr_dcc->start_resume,
|
||||
"cps", ptr_dcc->bytes_per_sec);
|
||||
if (listvalue)
|
||||
{
|
||||
if (PyList_SetItem (list, dcc_count, listvalue) != 0)
|
||||
{
|
||||
PyMem_Free (listvalue);
|
||||
PyMem_Free (list);
|
||||
python_plugin->free_dcc_info (python_plugin, dcc_info);
|
||||
return Py_None;
|
||||
}
|
||||
PyMem_Free (listvalue);
|
||||
}
|
||||
else
|
||||
{
|
||||
python_plugin->free_dcc_info (python_plugin, dcc_info);
|
||||
return Py_None;
|
||||
}
|
||||
dcc_count++;
|
||||
}
|
||||
|
||||
python_plugin->free_dcc_info (python_plugin, dcc_info);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/*
|
||||
* Python subroutines
|
||||
*/
|
||||
|
||||
static
|
||||
PyMethodDef weechat_funcs[] = {
|
||||
{ "register", weechat_python_register, METH_VARARGS, "" },
|
||||
{ "prnt", weechat_python_print, METH_VARARGS, "" },
|
||||
{ "print_infobar", weechat_python_print_infobar, METH_VARARGS, "" },
|
||||
{ "command", weechat_python_command, METH_VARARGS, "" },
|
||||
{ "add_message_handler", weechat_python_add_message_handler, METH_VARARGS, "" },
|
||||
{ "add_command_handler", weechat_python_add_command_handler, METH_VARARGS, "" },
|
||||
{ "get_info", weechat_python_get_info, METH_VARARGS, "" },
|
||||
{ "get_dcc_info", weechat_python_get_dcc_info, METH_VARARGS, "" },
|
||||
{ NULL, NULL, 0, NULL }
|
||||
};
|
||||
|
||||
/*
|
||||
* weechat_python_load: load a Python script
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_python_load (t_weechat_plugin *plugin, char *filename)
|
||||
{
|
||||
FILE *fp;
|
||||
PyThreadState *python_current_interpreter;
|
||||
|
||||
plugin->printf_server (plugin, "Loading Python script \"%s\"", filename);
|
||||
|
||||
if ((fp = fopen (filename, "r")) == NULL)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: unable to open file \"%s\"",
|
||||
filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
python_current_script = NULL;
|
||||
|
||||
PyThreadState_Swap(NULL);
|
||||
|
||||
PyEval_AcquireLock();
|
||||
|
||||
python_current_interpreter = PyThreadState_New (python_mainThreadState->interp);
|
||||
|
||||
if (python_current_interpreter == NULL)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: unable to create new sub-interpreter");
|
||||
PyEval_ReleaseLock();
|
||||
fclose (fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyThreadState_Swap (python_current_interpreter);
|
||||
|
||||
if (Py_InitModule ("weechat", weechat_funcs) == NULL)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: unable to initialize WeeChat module");
|
||||
PyThreadState_Swap (NULL);
|
||||
PyThreadState_Clear (python_current_interpreter);
|
||||
PyThreadState_Delete (python_current_interpreter);
|
||||
PyEval_ReleaseLock ();
|
||||
fclose (fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (PyRun_SimpleString (
|
||||
"import weechat, sys, string\n"
|
||||
|
||||
"class weechatStdout:\n"
|
||||
"\tdef write(self, str):\n"
|
||||
"\t\tstr = string.strip(str)\n"
|
||||
"\t\tif str != \"\":\n"
|
||||
"\t\t\tweechat.prnt(\"Python stdout : \" + str, \"\")\n"
|
||||
|
||||
"class weechatStderr:\n"
|
||||
"\tdef write(self, str):\n"
|
||||
"\t\tstr = string.strip(str)\n"
|
||||
"\t\tif str != \"\":\n"
|
||||
"\t\t\tweechat.prnt(\"Python stderr : \" + str, \"\")\n"
|
||||
|
||||
"sys.stdout = weechatStdout()\n"
|
||||
"sys.stderr = weechatStderr()\n"
|
||||
) != 0)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python warning: unable to redirect stdout and stderr");
|
||||
}
|
||||
|
||||
python_current_script_filename = strdup (filename);
|
||||
|
||||
if (PyRun_SimpleFile (fp, filename) != 0)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: unable to parse file \"%s\"",
|
||||
filename);
|
||||
free (python_current_script_filename);
|
||||
PyThreadState_Swap (NULL);
|
||||
PyThreadState_Clear (python_current_interpreter);
|
||||
PyThreadState_Delete (python_current_interpreter);
|
||||
PyEval_ReleaseLock ();
|
||||
fclose (fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fclose (fp);
|
||||
free (python_current_script_filename);
|
||||
|
||||
if (python_current_script == NULL)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: function \"register\" not found "
|
||||
"in file \"%s\"",
|
||||
filename);
|
||||
PyThreadState_Swap (NULL);
|
||||
PyThreadState_Clear (python_current_interpreter);
|
||||
PyThreadState_Delete (python_current_interpreter);
|
||||
PyEval_ReleaseLock ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
python_current_script->interpreter = (PyThreadState *) python_current_interpreter;
|
||||
PyThreadState_Swap (NULL);
|
||||
PyEval_ReleaseLock ();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_unload: unload a Python script
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_python_unload (t_weechat_plugin *plugin, t_plugin_script *script)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Unloading Python script \"%s\"",
|
||||
script->name);
|
||||
|
||||
if (script->shutdown_func[0])
|
||||
weechat_python_exec (plugin, script, script->shutdown_func, "", "");
|
||||
|
||||
PyThreadState_Swap (NULL);
|
||||
PyThreadState_Clear (script->interpreter);
|
||||
PyThreadState_Delete (script->interpreter);
|
||||
|
||||
weechat_script_remove (plugin, &python_scripts, script);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_unload_name: unload a Python script by name
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_python_unload_name (t_weechat_plugin *plugin, char *name)
|
||||
{
|
||||
t_plugin_script *ptr_script;
|
||||
|
||||
ptr_script = weechat_script_search (plugin, &python_scripts, name);
|
||||
if (ptr_script)
|
||||
{
|
||||
weechat_python_unload (plugin, ptr_script);
|
||||
plugin->printf_server (plugin,
|
||||
"Python script \"%s\" unloaded",
|
||||
name);
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: script \"%s\" not loaded",
|
||||
name);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_unload_all: unload all Python scripts
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_python_unload_all (t_weechat_plugin *plugin)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Unloading all Python scripts");
|
||||
while (python_scripts)
|
||||
weechat_python_unload (plugin, python_scripts);
|
||||
|
||||
plugin->printf_server (plugin,
|
||||
"Python scripts unloaded");
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_cmd: /python command handler
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_python_cmd (t_weechat_plugin *plugin,
|
||||
char *server, char *command, char *arguments,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
int argc, path_length, handler_found;
|
||||
char **argv, *path_script, *dir_home;
|
||||
t_plugin_script *ptr_plugin_script;
|
||||
t_plugin_msg_handler *ptr_msg_handler;
|
||||
t_plugin_cmd_handler *ptr_cmd_handler;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) server;
|
||||
(void) command;
|
||||
(void) handler_args;
|
||||
(void) handler_pointer;
|
||||
|
||||
argv = plugin->explode_string (plugin, arguments, " ", 0, &argc);
|
||||
|
||||
switch (argc)
|
||||
{
|
||||
case 0:
|
||||
/* list registered Python scripts */
|
||||
plugin->printf_server (plugin, "");
|
||||
plugin->printf_server (plugin, "Registered Python scripts:");
|
||||
if (python_scripts)
|
||||
{
|
||||
for (ptr_plugin_script = python_scripts; ptr_plugin_script;
|
||||
ptr_plugin_script = ptr_plugin_script->next_script)
|
||||
{
|
||||
plugin->printf_server (plugin, " %s v%s%s%s",
|
||||
ptr_plugin_script->name,
|
||||
ptr_plugin_script->version,
|
||||
(ptr_plugin_script->description[0]) ? " - " : "",
|
||||
ptr_plugin_script->description);
|
||||
}
|
||||
}
|
||||
else
|
||||
plugin->printf_server (plugin, " (none)");
|
||||
|
||||
/* list Python message handlers */
|
||||
plugin->printf_server (plugin, "");
|
||||
plugin->printf_server (plugin, "Python message handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_msg_handler = plugin->msg_handlers; ptr_msg_handler;
|
||||
ptr_msg_handler = ptr_msg_handler->next_handler)
|
||||
{
|
||||
if (ptr_msg_handler->msg_handler_args)
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->printf_server (plugin, " IRC(%s) => Python(%s)",
|
||||
ptr_msg_handler->irc_command,
|
||||
ptr_msg_handler->msg_handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->printf_server (plugin, " (none)");
|
||||
|
||||
/* list Python command handlers */
|
||||
plugin->printf_server (plugin, "");
|
||||
plugin->printf_server (plugin, "Python command handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_cmd_handler = plugin->cmd_handlers; ptr_cmd_handler;
|
||||
ptr_cmd_handler = ptr_cmd_handler->next_handler)
|
||||
{
|
||||
if (ptr_cmd_handler->cmd_handler_args)
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->printf_server (plugin, " /%s => Python(%s)",
|
||||
ptr_cmd_handler->command,
|
||||
ptr_cmd_handler->cmd_handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->printf_server (plugin, " (none)");
|
||||
break;
|
||||
case 1:
|
||||
if (plugin->ascii_strcasecmp (plugin, argv[0], "autoload") == 0)
|
||||
weechat_script_auto_load (plugin, "python", weechat_python_load);
|
||||
else if (plugin->ascii_strcasecmp (plugin, argv[0], "reload") == 0)
|
||||
{
|
||||
weechat_python_unload_all (plugin);
|
||||
weechat_script_auto_load (plugin, "python", weechat_python_load);
|
||||
}
|
||||
else if (plugin->ascii_strcasecmp (plugin, argv[0], "unload") == 0)
|
||||
weechat_python_unload_all (plugin);
|
||||
break;
|
||||
case 2:
|
||||
if (plugin->ascii_strcasecmp (plugin, argv[0], "load") == 0)
|
||||
{
|
||||
/* load Python script */
|
||||
if ((strstr (argv[1], "/")) || (strstr (argv[1], "\\")))
|
||||
path_script = NULL;
|
||||
else
|
||||
{
|
||||
dir_home = plugin->get_info (plugin, "weechat_dir", NULL, NULL);
|
||||
if (dir_home)
|
||||
{
|
||||
path_length = strlen (dir_home) + strlen (argv[1]) + 16;
|
||||
path_script = (char *) malloc (path_length * sizeof (char));
|
||||
if (path_script)
|
||||
snprintf (path_script, path_length, "%s/python/%s",
|
||||
dir_home, argv[1]);
|
||||
else
|
||||
path_script = NULL;
|
||||
free (dir_home);
|
||||
}
|
||||
else
|
||||
path_script = NULL;
|
||||
}
|
||||
weechat_python_load (plugin, (path_script) ? path_script : argv[1]);
|
||||
if (path_script)
|
||||
free (path_script);
|
||||
}
|
||||
else if (plugin->ascii_strcasecmp (plugin, argv[0], "unload") == 0)
|
||||
{
|
||||
/* unload Python script */
|
||||
weechat_python_unload_name (plugin, argv[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: unknown option for "
|
||||
"\"python\" command");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: wrong argument count for \"python\" command");
|
||||
}
|
||||
plugin->free_exploded_string (plugin, argv);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_init: initialize Python plugin
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_plugin_init (t_weechat_plugin *plugin)
|
||||
{
|
||||
python_plugin = plugin;
|
||||
|
||||
plugin->printf_server (plugin, "Loading Python module \"weechat\"");
|
||||
|
||||
Py_Initialize ();
|
||||
if (Py_IsInitialized () == 0)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: unable to launch global interpreter");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyEval_InitThreads();
|
||||
|
||||
python_mainThreadState = PyThreadState_Get();
|
||||
|
||||
if (python_mainThreadState == NULL)
|
||||
{
|
||||
plugin->printf_server (plugin,
|
||||
"Python error: unable to get current interpreter state");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyEval_ReleaseLock ();
|
||||
|
||||
plugin->cmd_handler_add (plugin, "python",
|
||||
"list/load/unload Python scripts",
|
||||
"[load filename] | [autoload] | [reload] | [unload]",
|
||||
"filename: Python script (file) to load\n\n"
|
||||
"Without argument, /python command lists all loaded Python scripts.",
|
||||
weechat_python_cmd, NULL, NULL);
|
||||
|
||||
plugin->mkdir_home (plugin, "python");
|
||||
plugin->mkdir_home (plugin, "python/autoload");
|
||||
|
||||
weechat_script_auto_load (plugin, "python", weechat_python_load);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_end: shutdown Python interface
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_plugin_end (t_weechat_plugin *plugin)
|
||||
{
|
||||
/* unload all scripts */
|
||||
weechat_python_unload_all (plugin);
|
||||
|
||||
/* free Python interpreter */
|
||||
/*Py_Finalize ();
|
||||
if (Py_IsInitialized () != 0)
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to free interpreter");
|
||||
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python plugin ended");*/
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
# Copyright (c) 2003-2005 FlashCode <flashcode@flashtux.org>
|
||||
#
|
||||
# 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 2 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, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(RUBY_CFLAGS)
|
||||
|
||||
libdir = ${weechat_libdir}/plugins
|
||||
|
||||
lib_LTLIBRARIES = libruby.la
|
||||
|
||||
libruby_la_SOURCES = weechat-ruby.c
|
||||
libruby_la_LDFLAGS = -module
|
||||
libruby_la_LIBADD = ../lib_weechat_plugins_scripts.la $(RUBY_LFLAGS)
|
||||
@@ -0,0 +1,599 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* wee-ruby.c: Ruby plugin support for WeeChat */
|
||||
|
||||
|
||||
#include <ruby.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#undef _
|
||||
#include "../../weechat-plugin.h"
|
||||
#include "../weechat-script.h"
|
||||
|
||||
|
||||
t_plugin_script *ruby_scripts = NULL;
|
||||
t_plugin_script *last_ruby_script = NULL;
|
||||
|
||||
|
||||
/*
|
||||
* register: startup function for all WeeChat Ruby scripts
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
wee_ruby_register (VALUE class, VALUE name, VALUE version, VALUE shutdown_func, VALUE description)
|
||||
{
|
||||
char *c_name, *c_version, *c_shutdown_func, *c_description;
|
||||
t_plugin_script *ptr_ruby_script, *ruby_script_found, *new_ruby_script;
|
||||
|
||||
if (NIL_P (name) || NIL_P (version) || NIL_P (shutdown_func) || NIL_P (description))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Ruby", "register");
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
Check_Type (name, T_STRING);
|
||||
Check_Type (version, T_STRING);
|
||||
Check_Type (shutdown_func, T_STRING);
|
||||
Check_Type (description, T_STRING);
|
||||
|
||||
c_name = STR2CSTR (name);
|
||||
c_version = STR2CSTR (version);
|
||||
c_shutdown_func = STR2CSTR (shutdown_func);
|
||||
c_description = STR2CSTR (description);
|
||||
|
||||
ruby_script_found = NULL;
|
||||
for (ptr_ruby_script = ruby_scripts; ptr_ruby_script;
|
||||
ptr_ruby_script = ptr_ruby_script->next_script)
|
||||
{
|
||||
if (ascii_strcasecmp (ptr_ruby_script->name, c_name) == 0)
|
||||
{
|
||||
ruby_script_found = ptr_ruby_script;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ruby_script_found)
|
||||
{
|
||||
/* error: another script already exists with this name! */
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: unable to register \"%s\" script (another script "
|
||||
"already exists with this name)\n"),
|
||||
"Ruby", name);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* registering script */
|
||||
new_ruby_script = (t_plugin_script *)malloc (sizeof (t_plugin_script));
|
||||
if (new_ruby_script)
|
||||
{
|
||||
new_ruby_script->name = strdup (c_name);
|
||||
new_ruby_script->version = strdup (c_version);
|
||||
new_ruby_script->shutdown_func = strdup (c_shutdown_func);
|
||||
new_ruby_script->description = strdup (c_description);
|
||||
|
||||
/* add new script to list */
|
||||
new_ruby_script->prev_script = last_ruby_script;
|
||||
new_ruby_script->next_script = NULL;
|
||||
if (ruby_scripts)
|
||||
last_ruby_script->next_script = new_ruby_script;
|
||||
else
|
||||
ruby_scripts = new_ruby_script;
|
||||
last_ruby_script = new_ruby_script;
|
||||
|
||||
wee_log_printf (_("Registered %s script: \"%s\", version %s (%s)\n"),
|
||||
"Ruby", c_name, c_version, c_description);
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: unable to load script \"%s\" (not enough memory)\n"),
|
||||
"Ruby", c_name);
|
||||
}
|
||||
}
|
||||
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
/*
|
||||
* print: print message into a buffer (current or specified one)
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
wee_ruby_print (VALUE class, VALUE message, VALUE channel_name, VALUE server_name)
|
||||
{
|
||||
char *c_message, *c_channel_name, *c_server_name;
|
||||
t_gui_buffer *ptr_buffer;
|
||||
|
||||
c_message = NULL;
|
||||
c_channel_name = NULL;
|
||||
c_server_name = NULL;
|
||||
|
||||
if (NIL_P (message))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Ruby", "print");
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
Check_Type (message, T_STRING);
|
||||
if (!NIL_P (channel_name))
|
||||
Check_Type (channel_name, T_STRING);
|
||||
if (!NIL_P (server_name))
|
||||
Check_Type (server_name, T_STRING);
|
||||
|
||||
c_message = STR2CSTR (message);
|
||||
if (!NIL_P (channel_name))
|
||||
c_channel_name = STR2CSTR (channel_name);
|
||||
if (!NIL_P (server_name))
|
||||
c_server_name = STR2CSTR (server_name);
|
||||
|
||||
ptr_buffer = plugin_find_buffer (c_server_name, c_channel_name);
|
||||
if (ptr_buffer)
|
||||
{
|
||||
irc_display_prefix (ptr_buffer, PREFIX_PLUGIN);
|
||||
gui_printf (ptr_buffer, "%s\n", c_message);
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
/* buffer not found */
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* print_infobar: print message to infobar
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
wee_ruby_print_infobar (VALUE class, VALUE delay, VALUE message)
|
||||
{
|
||||
int c_delay;
|
||||
char *c_message;
|
||||
|
||||
c_delay = 1;
|
||||
c_message = NULL;
|
||||
|
||||
if (NIL_P (delay) || NIL_P (message))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Ruby", "print_infobar");
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
Check_Type (delay, T_FIXNUM);
|
||||
Check_Type (message, T_STRING);
|
||||
|
||||
c_delay = FIX2INT (delay);
|
||||
c_message = STR2CSTR (message);
|
||||
|
||||
gui_infobar_printf (delay, COLOR_WIN_INFOBAR, c_message);
|
||||
|
||||
return Qtrue;
|
||||
}
|
||||
|
||||
/*
|
||||
* command: send command to server
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
wee_ruby_command (VALUE class, VALUE command, VALUE channel_name, VALUE server_name)
|
||||
{
|
||||
char *c_command, *c_channel_name, *c_server_name;
|
||||
t_gui_buffer *ptr_buffer;
|
||||
|
||||
c_command = NULL;
|
||||
c_channel_name = NULL;
|
||||
c_server_name = NULL;
|
||||
|
||||
if (NIL_P (command))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Ruby", "command");
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
Check_Type (command, T_STRING);
|
||||
if (!NIL_P (channel_name))
|
||||
Check_Type (channel_name, T_STRING);
|
||||
if (!NIL_P (server_name))
|
||||
Check_Type (server_name, T_STRING);
|
||||
|
||||
c_command = STR2CSTR (command);
|
||||
if (!NIL_P (channel_name))
|
||||
c_channel_name = STR2CSTR (channel_name);
|
||||
if (!NIL_P (server_name))
|
||||
c_server_name = STR2CSTR (server_name);
|
||||
|
||||
ptr_buffer = plugin_find_buffer (c_server_name, c_channel_name);
|
||||
if (ptr_buffer)
|
||||
{
|
||||
user_command (SERVER(ptr_buffer), ptr_buffer, c_command);
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
/* buffer not found */
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* add_message_handler: add handler for messages
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
wee_ruby_add_message_handler (VALUE class, VALUE message, VALUE function)
|
||||
{
|
||||
char *c_message, *c_function;
|
||||
|
||||
if (NIL_P (message) || NIL_P (function))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Ruby", "add_message_handler");
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
Check_Type (message, T_STRING);
|
||||
Check_Type (function, T_STRING);
|
||||
|
||||
c_message = STR2CSTR (message);
|
||||
c_function = STR2CSTR (function);
|
||||
|
||||
plugin_handler_add (&plugin_msg_handlers, &last_plugin_msg_handler,
|
||||
PLUGIN_TYPE_RUBY, c_message, c_function);
|
||||
|
||||
return Qtrue;
|
||||
}
|
||||
|
||||
/*
|
||||
* add_command_handler: define/redefines commands
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
wee_ruby_add_command_handler (VALUE class, VALUE name, VALUE function)
|
||||
{
|
||||
char *c_name, *c_function;
|
||||
t_plugin_handler *ptr_plugin_handler;
|
||||
|
||||
if (NIL_P (name) || NIL_P (function))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Ruby", "add_command_handler");
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
Check_Type (name, T_STRING);
|
||||
Check_Type (function, T_STRING);
|
||||
|
||||
c_name = STR2CSTR (name);
|
||||
c_function = STR2CSTR (function);
|
||||
|
||||
if (!weelist_search (index_commands, c_name))
|
||||
weelist_add (&index_commands, &last_index_command, c_name);
|
||||
|
||||
ptr_plugin_handler = plugin_handler_search (plugin_cmd_handlers, c_name);
|
||||
if (ptr_plugin_handler)
|
||||
{
|
||||
free (ptr_plugin_handler->function_name);
|
||||
ptr_plugin_handler->function_name = strdup (c_function);
|
||||
}
|
||||
else
|
||||
plugin_handler_add (&plugin_cmd_handlers, &last_plugin_cmd_handler,
|
||||
PLUGIN_TYPE_PYTHON, c_name, c_function);
|
||||
|
||||
return Qtrue;
|
||||
}
|
||||
|
||||
/*
|
||||
* get_info: get various infos
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
wee_ruby_get_info (VALUE class, VALUE arg, VALUE server_name)
|
||||
{
|
||||
char *c_arg, *info, *c_server_name;
|
||||
t_irc_server *ptr_server;
|
||||
|
||||
if (NIL_P (arg))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Ruby", "get_info");
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
Check_Type (arg, T_STRING);
|
||||
if (!NIL_P (server_name))
|
||||
Check_Type (server_name, T_STRING);
|
||||
|
||||
c_arg = STR2CSTR (arg);
|
||||
if (!NIL_P (server_name))
|
||||
c_server_name = STR2CSTR (server_name);
|
||||
|
||||
if (c_server_name == NULL)
|
||||
{
|
||||
ptr_server = SERVER(gui_current_window->buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server)
|
||||
{
|
||||
if (ascii_strcasecmp (ptr_server->name, c_server_name) == 0)
|
||||
break;
|
||||
}
|
||||
if (!ptr_server)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: server not found for \"%s\" function\n"),
|
||||
"Ruby", "get_info");
|
||||
return Qnil;
|
||||
}
|
||||
}
|
||||
|
||||
if (ptr_server && c_arg)
|
||||
{
|
||||
if ( (ascii_strcasecmp (c_arg, "0") == 0) || (ascii_strcasecmp (c_arg, "version") == 0) )
|
||||
{
|
||||
info = PACKAGE_STRING;
|
||||
}
|
||||
else if ( (ascii_strcasecmp (c_arg, "1") == 0) || (ascii_strcasecmp (c_arg, "nick") == 0) )
|
||||
{
|
||||
if (ptr_server->nick)
|
||||
info = ptr_server->nick;
|
||||
}
|
||||
else if ( (ascii_strcasecmp (c_arg, "2") == 0) || (ascii_strcasecmp (c_arg, "channel") == 0) )
|
||||
{
|
||||
if (BUFFER_IS_CHANNEL (gui_current_window->buffer))
|
||||
info = CHANNEL (gui_current_window->buffer)->name;
|
||||
}
|
||||
else if ( (ascii_strcasecmp (c_arg, "3") == 0) || (ascii_strcasecmp (c_arg, "server") == 0) )
|
||||
{
|
||||
if (ptr_server->name)
|
||||
info = ptr_server->name;
|
||||
}
|
||||
else if ( (ascii_strcasecmp (c_arg, "4") == 0) || (ascii_strcasecmp (c_arg, "weechatdir") == 0) )
|
||||
{
|
||||
info = weechat_home;
|
||||
}
|
||||
else if ( (ascii_strcasecmp (c_arg, "5") == 0) || (ascii_strcasecmp (c_arg, "away") == 0) )
|
||||
{
|
||||
return INT2FIX (SERVER(gui_current_window->buffer)->is_away);
|
||||
}
|
||||
else if ( (ascii_strcasecmp (c_arg, "100") == 0) || (ascii_strcasecmp (c_arg, "dccs") == 0) )
|
||||
{
|
||||
/* TODO: build dcc list */
|
||||
}
|
||||
|
||||
if (info)
|
||||
return rb_str_new2 (info);
|
||||
else
|
||||
return rb_str_new2 ("");
|
||||
}
|
||||
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Ruby subroutines
|
||||
*/
|
||||
|
||||
/*
|
||||
* wee_ruby_init: initialize Ruby interface for WeeChat
|
||||
*/
|
||||
|
||||
void
|
||||
wee_ruby_init ()
|
||||
{
|
||||
|
||||
/* TODO: init Ruby environment */
|
||||
/* ruby_init ();
|
||||
if ()
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _("%s error: error while launching interpreter\n"),
|
||||
"Ruby");
|
||||
}
|
||||
else
|
||||
{
|
||||
wee_log_printf (_("Loading %s module \"weechat\"\n"), "Ruby");
|
||||
}*/
|
||||
}
|
||||
|
||||
/*
|
||||
* wee_ruby_search: search a (loaded) Ruby script by name
|
||||
*/
|
||||
|
||||
t_plugin_script *
|
||||
wee_ruby_search (char *name)
|
||||
{
|
||||
t_plugin_script *ptr_ruby_script;
|
||||
|
||||
for (ptr_ruby_script = ruby_scripts; ptr_ruby_script;
|
||||
ptr_ruby_script = ptr_ruby_script->next_script)
|
||||
{
|
||||
if (strcmp (ptr_ruby_script->name, name) == 0)
|
||||
return ptr_ruby_script;
|
||||
}
|
||||
|
||||
/* script not found */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* wee_ruby_exec: execute a Ruby script
|
||||
*/
|
||||
|
||||
int
|
||||
wee_ruby_exec (char *function, char *server, char *arguments)
|
||||
{
|
||||
/* TODO: exec Ruby script */
|
||||
}
|
||||
|
||||
/*
|
||||
* wee_ruby_load: load a Ruby script
|
||||
*/
|
||||
|
||||
int
|
||||
wee_ruby_load (char *filename)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
/* TODO: load & exec Ruby script */
|
||||
gui_printf (NULL, "Ruby scripts not developed!\n");
|
||||
/* execute Ruby script */
|
||||
/*wee_log_printf (_("Loading %s script \"%s\"\n"), "Ruby", filename);
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _("Loading %s script \"%s\"\n"), "Ruby", filename);
|
||||
|
||||
if ((fp = fopen (filename, "r")) == NULL)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: error while opening file \"%s\"\n"),
|
||||
"Ruby", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (xxxxxxx (fp, filename) != 0)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: error while parsing file \"%s\"\n"),
|
||||
"Ruby", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fclose (fp);
|
||||
return 0;*/
|
||||
}
|
||||
|
||||
/*
|
||||
* wee_ruby_script_free: free a Ruby script
|
||||
*/
|
||||
|
||||
void
|
||||
wee_ruby_script_free (t_plugin_script *ptr_ruby_script)
|
||||
{
|
||||
t_plugin_script *new_ruby_scripts;
|
||||
|
||||
/* remove script from list */
|
||||
if (last_ruby_script == ptr_ruby_script)
|
||||
last_ruby_script = ptr_ruby_script->prev_script;
|
||||
if (ptr_ruby_script->prev_script)
|
||||
{
|
||||
(ptr_ruby_script->prev_script)->next_script = ptr_ruby_script->next_script;
|
||||
new_ruby_scripts = ruby_scripts;
|
||||
}
|
||||
else
|
||||
new_ruby_scripts = ptr_ruby_script->next_script;
|
||||
|
||||
if (ptr_ruby_script->next_script)
|
||||
(ptr_ruby_script->next_script)->prev_script = ptr_ruby_script->prev_script;
|
||||
|
||||
/* free data */
|
||||
if (ptr_ruby_script->name)
|
||||
free (ptr_ruby_script->name);
|
||||
if (ptr_ruby_script->version)
|
||||
free (ptr_ruby_script->version);
|
||||
if (ptr_ruby_script->shutdown_func)
|
||||
free (ptr_ruby_script->shutdown_func);
|
||||
if (ptr_ruby_script->description)
|
||||
free (ptr_ruby_script->description);
|
||||
free (ptr_ruby_script);
|
||||
ruby_scripts = new_ruby_scripts;
|
||||
}
|
||||
|
||||
/*
|
||||
* wee_ruby_unload: unload a Ruby script
|
||||
*/
|
||||
|
||||
void
|
||||
wee_ruby_unload (t_plugin_script *ptr_ruby_script)
|
||||
{
|
||||
if (ptr_ruby_script)
|
||||
{
|
||||
wee_log_printf (_("Unloading %s script \"%s\"\n"),
|
||||
"Ruby", ptr_ruby_script->name);
|
||||
|
||||
/* call shutdown callback function */
|
||||
if (ptr_ruby_script->shutdown_func[0])
|
||||
wee_ruby_exec (ptr_ruby_script->shutdown_func, "", "");
|
||||
wee_ruby_script_free (ptr_ruby_script);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* wee_ruby_unload_all: unload all Ruby scripts
|
||||
*/
|
||||
|
||||
void
|
||||
wee_ruby_unload_all ()
|
||||
{
|
||||
wee_log_printf (_("Unloading all %s scripts...\n"), "Ruby");
|
||||
while (ruby_scripts)
|
||||
wee_ruby_unload (ruby_scripts);
|
||||
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _("%s scripts unloaded\n"), "Ruby");
|
||||
}
|
||||
|
||||
/*
|
||||
* wee_ruby_end: shutdown Ruby interface
|
||||
*/
|
||||
|
||||
void
|
||||
wee_ruby_end ()
|
||||
{
|
||||
/* unload all scripts */
|
||||
wee_ruby_unload_all ();
|
||||
|
||||
/* free all handlers */
|
||||
plugin_handler_free_all_type (&plugin_msg_handlers,
|
||||
&last_plugin_msg_handler,
|
||||
PLUGIN_TYPE_RUBY);
|
||||
plugin_handler_free_all_type (&plugin_cmd_handlers,
|
||||
&last_plugin_cmd_handler,
|
||||
PLUGIN_TYPE_RUBY);
|
||||
|
||||
/* TODO: free Ruby interpreter */
|
||||
/* free Ruby interpreter */
|
||||
/* xxxxx ();
|
||||
if ()
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _("%s error: error while freeing interpreter\n"),
|
||||
"Ruby");
|
||||
}*/
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* scripts.c: script interface for WeeChat plugins */
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "../weechat-plugin.h"
|
||||
#include "weechat-script.h"
|
||||
|
||||
|
||||
/*
|
||||
* weechat_script_auto_load: auto-load all scripts in a directory
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_script_auto_load (t_weechat_plugin *plugin, char *language,
|
||||
int (*callback)(t_weechat_plugin *, char *))
|
||||
{
|
||||
char *dir_home, *dir_name;
|
||||
int dir_length;
|
||||
|
||||
/* build directory, adding WeeChat home */
|
||||
dir_home = plugin->get_info (plugin, "weechat_dir", NULL, NULL);
|
||||
if (!dir_home)
|
||||
return;
|
||||
dir_length = strlen (dir_home) + strlen (language) + 16;
|
||||
dir_name =
|
||||
(char *) malloc (dir_length * sizeof (char));
|
||||
if (!dir_name)
|
||||
{
|
||||
free (dir_home);
|
||||
return;
|
||||
}
|
||||
snprintf (dir_name, dir_length, "%s/%s/autoload", dir_home, language);
|
||||
|
||||
plugin->exec_on_files (plugin, dir_name, callback);
|
||||
|
||||
free (dir_name);
|
||||
free (dir_home);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_script_search: search a script in list
|
||||
*/
|
||||
|
||||
t_plugin_script *
|
||||
weechat_script_search (t_weechat_plugin *plugin,
|
||||
t_plugin_script **list, char *name)
|
||||
{
|
||||
t_plugin_script *ptr_script;
|
||||
|
||||
for (ptr_script = *list; ptr_script;
|
||||
ptr_script = ptr_script->next_script)
|
||||
{
|
||||
if (plugin->ascii_strcasecmp (plugin, ptr_script->name, name) == 0)
|
||||
return ptr_script;
|
||||
}
|
||||
|
||||
/* script not found */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_script_add: add a script to list of scripts
|
||||
*/
|
||||
|
||||
t_plugin_script *
|
||||
weechat_script_add (t_weechat_plugin *plugin,
|
||||
t_plugin_script **script_list,
|
||||
char *filename,
|
||||
char *name, char *version,
|
||||
char *shutdown_func, char *description)
|
||||
{
|
||||
t_plugin_script *new_script;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) plugin;
|
||||
|
||||
new_script = (t_plugin_script *)malloc (sizeof (t_plugin_script));
|
||||
if (new_script)
|
||||
{
|
||||
new_script->filename = strdup (filename);
|
||||
new_script->interpreter = NULL;
|
||||
new_script->name = strdup (name);
|
||||
new_script->version = strdup (version);
|
||||
new_script->shutdown_func = strdup (shutdown_func);
|
||||
new_script->description = strdup (description);
|
||||
|
||||
/* add new script to list */
|
||||
if ((*script_list))
|
||||
(*script_list)->prev_script = new_script;
|
||||
new_script->prev_script = NULL;
|
||||
new_script->next_script = (*script_list);
|
||||
(*script_list) = new_script;
|
||||
return new_script;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_script_remove: remove a script from list of scripts
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_script_remove (t_weechat_plugin *plugin,
|
||||
t_plugin_script **script_list, t_plugin_script *script)
|
||||
{
|
||||
t_plugin_msg_handler *ptr_msg_handler, *next_msg_handler;
|
||||
t_plugin_cmd_handler *ptr_cmd_handler, *next_cmd_handler;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) plugin;
|
||||
|
||||
/* remove message handlers */
|
||||
ptr_msg_handler = plugin->msg_handlers;
|
||||
while (ptr_msg_handler)
|
||||
{
|
||||
if ((t_plugin_script *)ptr_msg_handler->msg_handler_pointer == script)
|
||||
{
|
||||
next_msg_handler = ptr_msg_handler->next_handler;
|
||||
plugin->msg_handler_remove (plugin, ptr_msg_handler);
|
||||
ptr_msg_handler = next_msg_handler;
|
||||
}
|
||||
else
|
||||
ptr_msg_handler = ptr_msg_handler->next_handler;
|
||||
}
|
||||
|
||||
/* remove command handlers */
|
||||
ptr_cmd_handler = plugin->cmd_handlers;
|
||||
while (ptr_cmd_handler)
|
||||
{
|
||||
if ((t_plugin_script *)ptr_cmd_handler->cmd_handler_pointer == script)
|
||||
{
|
||||
next_cmd_handler = ptr_cmd_handler->next_handler;
|
||||
plugin->cmd_handler_remove (plugin, ptr_cmd_handler);
|
||||
ptr_cmd_handler = next_cmd_handler;
|
||||
}
|
||||
else
|
||||
ptr_cmd_handler = ptr_cmd_handler->next_handler;
|
||||
}
|
||||
|
||||
/* free data */
|
||||
if (script->filename)
|
||||
free (script->filename);
|
||||
if (script->name)
|
||||
free (script->name);
|
||||
if (script->description)
|
||||
free (script->description);
|
||||
if (script->version)
|
||||
free (script->version);
|
||||
if (script->shutdown_func)
|
||||
free (script->shutdown_func);
|
||||
|
||||
/* remove script from list */
|
||||
if (script->prev_script)
|
||||
(script->prev_script)->next_script = script->next_script;
|
||||
else
|
||||
(*script_list) = script->next_script;
|
||||
if (script->next_script)
|
||||
(script->next_script)->prev_script = script->prev_script;
|
||||
|
||||
/* free script */
|
||||
free (script);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* This header is designed to be distributed with WeeChat plugins, if scripts
|
||||
management is needed */
|
||||
|
||||
#ifndef __WEECHAT_WEECHAT_SCRIPT_H
|
||||
#define __WEECHAT_WEECHAT_SCRIPT_H 1
|
||||
|
||||
typedef struct t_plugin_script t_plugin_script;
|
||||
|
||||
struct t_plugin_script
|
||||
{
|
||||
/* script variables */
|
||||
char *filename; /* name of script on disk */
|
||||
void *interpreter; /* interpreter for script */
|
||||
char *name; /* script name */
|
||||
char *description; /* plugin description */
|
||||
char *version; /* plugin version */
|
||||
char *shutdown_func; /* function when script is unloaded */
|
||||
|
||||
t_plugin_script *prev_script; /* link to previous script */
|
||||
t_plugin_script *next_script; /* link to next script */
|
||||
};
|
||||
|
||||
extern void weechat_script_auto_load (t_weechat_plugin *, char *,
|
||||
int (*)(t_weechat_plugin *, char *));
|
||||
extern t_plugin_script *weechat_script_search (t_weechat_plugin *,
|
||||
t_plugin_script **, char *);
|
||||
extern t_plugin_script *weechat_script_add (t_weechat_plugin *,
|
||||
t_plugin_script **, char *, char *,
|
||||
char *, char *, char *);
|
||||
extern void weechat_script_remove (t_weechat_plugin *,
|
||||
t_plugin_script **, t_plugin_script *);
|
||||
|
||||
#endif /* weechat-script.h */
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* This header is designed to be distributed with WeeChat plugins */
|
||||
|
||||
#ifndef __WEECHAT_WEECHAT_PLUGIN_H
|
||||
#define __WEECHAT_WEECHAT_PLUGIN_H 1
|
||||
|
||||
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_weechat_plugin t_weechat_plugin;
|
||||
|
||||
typedef int (t_plugin_handler_func) (t_weechat_plugin *, char *, char *, char *, char *, void *);
|
||||
|
||||
/* message handler, called when an IRC messages is received */
|
||||
|
||||
typedef struct t_plugin_msg_handler t_plugin_msg_handler;
|
||||
|
||||
struct t_plugin_msg_handler
|
||||
{
|
||||
char *irc_command; /* name of IRC command (PRIVMSG, ..) */
|
||||
t_plugin_handler_func *msg_handler; /* pointer to message handler */
|
||||
char *msg_handler_args; /* arguments sent to message handler */
|
||||
void *msg_handler_pointer; /* pointer sent to message handler */
|
||||
|
||||
int running; /* 1 if currently running */
|
||||
/* (used to prevent circular call) */
|
||||
t_plugin_msg_handler *prev_handler; /* link to previous handler */
|
||||
t_plugin_msg_handler *next_handler; /* link to next handler */
|
||||
};
|
||||
|
||||
/* command handler, to add new commands to WeeChat */
|
||||
|
||||
typedef struct t_plugin_cmd_handler t_plugin_cmd_handler;
|
||||
|
||||
struct t_plugin_cmd_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 */
|
||||
/* command handler */
|
||||
t_plugin_handler_func *cmd_handler; /* pointer to command handler */
|
||||
char *cmd_handler_args; /* arguments sent to command handler */
|
||||
void *cmd_handler_pointer; /* pointer sent to command handler */
|
||||
|
||||
int running; /* 1 if currently running */
|
||||
/* (used to prevent circular call) */
|
||||
t_plugin_cmd_handler *prev_handler; /* link to previous handler */
|
||||
t_plugin_cmd_handler *next_handler; /* link to next handler */
|
||||
};
|
||||
|
||||
/* plugin, a WeeChat plugin, which is a dynamic library */
|
||||
|
||||
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 */
|
||||
|
||||
/* plugin functions (interface) */
|
||||
int (*mkdir_home) (t_weechat_plugin *, char *);
|
||||
void (*exec_on_files) (t_weechat_plugin *, char *,
|
||||
int (*)(t_weechat_plugin *, char *));
|
||||
t_plugin_msg_handler *(*msg_handler_add) (t_weechat_plugin *, char *,
|
||||
t_plugin_handler_func *,
|
||||
char *, void *);
|
||||
void (*msg_handler_remove) (t_weechat_plugin *, t_plugin_msg_handler *);
|
||||
void (*msg_handler_remove_all) (t_weechat_plugin *);
|
||||
t_plugin_cmd_handler *(*cmd_handler_add) (t_weechat_plugin *, char *,
|
||||
char *, char *, char *,
|
||||
t_plugin_handler_func *,
|
||||
char *, void *);
|
||||
void (*cmd_handler_remove) (t_weechat_plugin *, t_plugin_cmd_handler *);
|
||||
void (*cmd_handler_remove_all) (t_weechat_plugin *);
|
||||
void (*printf) (t_weechat_plugin *, char *, char *, char *, ...);
|
||||
void (*printf_server) (t_weechat_plugin *, char *, ...);
|
||||
void (*infobar_printf) (t_weechat_plugin *, int, char *, ...);
|
||||
void (*exec_command) (t_weechat_plugin *, char *, char *, char *);
|
||||
char *(*get_info) (t_weechat_plugin *, char *, char *, char *);
|
||||
t_plugin_dcc_info *(*get_dcc_info) (t_weechat_plugin *);
|
||||
void (*free_dcc_info) (t_weechat_plugin *, t_plugin_dcc_info *);
|
||||
char **(*explode_string) (t_weechat_plugin *, char *, char *, int, int *);
|
||||
void (*free_exploded_string) (t_weechat_plugin *, char **);
|
||||
int (*ascii_strcasecmp) (t_weechat_plugin *, char *, char *);
|
||||
|
||||
/* plugin handlers */
|
||||
t_plugin_msg_handler *msg_handlers; /* IRC message handlers */
|
||||
t_plugin_msg_handler *last_msg_handler;
|
||||
t_plugin_cmd_handler *cmd_handlers; /* command handlers */
|
||||
t_plugin_cmd_handler *last_cmd_handler;
|
||||
|
||||
/* links to previous/next plugins */
|
||||
t_weechat_plugin *prev_plugin; /* link to previous plugin */
|
||||
t_weechat_plugin *next_plugin; /* link to next plugin */
|
||||
};
|
||||
|
||||
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 *));
|
||||
extern t_plugin_msg_handler *weechat_plugin_msg_handler_add (t_weechat_plugin *, char *,
|
||||
t_plugin_handler_func *,
|
||||
char *, void *);
|
||||
extern void weechat_plugin_msg_handler_remove (t_weechat_plugin *, t_plugin_msg_handler *);
|
||||
extern void weechat_plugin_msg_handler_remove_all (t_weechat_plugin *);
|
||||
extern t_plugin_cmd_handler *weechat_plugin_cmd_handler_add (t_weechat_plugin *, char *,
|
||||
char *, char *, char *,
|
||||
t_plugin_handler_func *,
|
||||
char *, void *);
|
||||
extern void weechat_plugin_cmd_handler_remove (t_weechat_plugin *, t_plugin_cmd_handler *);
|
||||
extern void weechat_plugin_cmd_handler_remove_all (t_weechat_plugin *);
|
||||
extern void weechat_plugin_printf (t_weechat_plugin *, char *, char *, char *, ...);
|
||||
extern void weechat_plugin_printf_server (t_weechat_plugin *, char *, ...);
|
||||
extern void weechat_plugin_infobar_printf (t_weechat_plugin *, int, char *, ...);
|
||||
extern void weechat_plugin_exec_command (t_weechat_plugin *, char *, char *, char *);
|
||||
extern char *weechat_plugin_get_info (t_weechat_plugin *, char *, 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_explode_string (t_weechat_plugin *, char *, char *, int, int *);
|
||||
extern void weechat_free_exploded_string (t_weechat_plugin *, char **);
|
||||
extern int weechat_ascii_strcasecmp (t_weechat_plugin *,char *, char *);
|
||||
|
||||
#endif /* weechat-plugin.h */
|
||||
Reference in New Issue
Block a user