From c17a4d5c768d8e23e2c4b329eec264f1038967dc Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sat, 12 Jan 2008 15:25:38 +0100 Subject: Migration of Python plugin to new API, bugs fixed in Perl/Python plugins --- src/core/wee-command.c | 2 +- src/plugins/plugin-api.c | 2 + src/plugins/scripts/perl/Makefile.am | 3 +- src/plugins/scripts/perl/weechat-perl-api.c | 662 +++--- src/plugins/scripts/perl/weechat-perl-api.h | 4 - src/plugins/scripts/perl/weechat-perl.c | 256 +-- src/plugins/scripts/perl/weechat-perl.h | 1 - src/plugins/scripts/python/Makefile.am | 5 +- src/plugins/scripts/python/python.c | 2731 ----------------------- src/plugins/scripts/python/weechat-python-api.c | 2712 ++++++++++++++++++++++ src/plugins/scripts/python/weechat-python-api.h | 25 + src/plugins/scripts/python/weechat-python.c | 792 +++++++ src/plugins/scripts/python/weechat-python.h | 36 + src/plugins/scripts/script-api.c | 78 +- src/plugins/scripts/script-api.h | 115 +- src/plugins/scripts/script.c | 2 - 16 files changed, 4098 insertions(+), 3328 deletions(-) delete mode 100644 src/plugins/scripts/python/python.c create mode 100644 src/plugins/scripts/python/weechat-python-api.c create mode 100644 src/plugins/scripts/python/weechat-python-api.h create mode 100644 src/plugins/scripts/python/weechat-python.c create mode 100644 src/plugins/scripts/python/weechat-python.h diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 993b4ea07..836757b72 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -60,7 +60,7 @@ command_buffer (void *data, struct t_gui_buffer *buffer, { struct t_gui_buffer *ptr_buffer; long number; - char *error ,*value; + char *error, *value; int target_buffer; /* make C compiler happy */ diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index 74bb9fbd7..56a9bb46a 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -84,6 +84,7 @@ plugin_api_ngettext (char *single, char *plural, int count) /* * plugin_api_mkdir_home: create a directory in WeeChat home + * return 1 if ok, 0 if error */ int @@ -119,6 +120,7 @@ plugin_api_mkdir_home (char *directory, int mode) /* * plugin_api_mkdir: create a directory + * return 1 if ok, 0 if error */ int diff --git a/src/plugins/scripts/perl/Makefile.am b/src/plugins/scripts/perl/Makefile.am index a064a3a1f..d140f1174 100644 --- a/src/plugins/scripts/perl/Makefile.am +++ b/src/plugins/scripts/perl/Makefile.am @@ -22,6 +22,7 @@ lib_LTLIBRARIES = perl.la perl_la_SOURCES = weechat-perl.c \ weechat-perl.h \ - weechat-perl-api.c + weechat-perl-api.c \ + weechat-perl-api.h perl_la_LDFLAGS = -module perl_la_LIBADD = ../lib_weechat_plugins_scripts.la $(PERL_LFLAGS) diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c index b532a44fc..3534347be 100644 --- a/src/plugins/scripts/perl/weechat-perl-api.c +++ b/src/plugins/scripts/perl/weechat-perl-api.c @@ -35,6 +35,27 @@ #include "weechat-perl.h" +#define PERL_RETURN_OK XSRETURN_YES +#define PERL_RETURN_ERROR XSRETURN_NO +#define PERL_RETURN_EMPTY XSRETURN_EMPTY +#define PERL_RETURN_STRING(string) \ + if (string) \ + { \ + XST_mPV (0, string); \ + XSRETURN (1); \ + } \ + XST_mPV (0, ""); \ + XSRETURN (1); +#define PERL_RETURN_STRING_FREE(string) \ + if (string) \ + { \ + XST_mPV (0, string); \ + free (string); \ + XSRETURN (1); \ + } \ + XST_mPV (0, ""); \ + XSRETURN (1); + extern void boot_DynaLoader (pTHX_ CV* cv); @@ -57,7 +78,7 @@ static XS (XS_weechat_register) if (items < 5) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("register"); - XSRETURN_NO; + PERL_RETURN_ERROR; } name = SvPV (ST (0), PL_na); @@ -82,7 +103,7 @@ static XS (XS_weechat_register) "\"%s\" (another script already " "exists with this name)"), weechat_prefix ("error"), "perl", name); - XSRETURN_NO; + PERL_RETURN_ERROR; } /* register script */ @@ -102,10 +123,10 @@ static XS (XS_weechat_register) } else { - XSRETURN_NO; + PERL_RETURN_ERROR; } - XSRETURN_YES; + PERL_RETURN_OK; } /* @@ -122,19 +143,19 @@ static XS (XS_weechat_charset_set) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("charset_set"); - XSRETURN_NO; + PERL_RETURN_ERROR; } if (items < 1) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("charset_set"); - XSRETURN_NO; + PERL_RETURN_ERROR; } script_api_charset_set (perl_current_script, - SvPV (ST (0), PL_na)); + SvPV (ST (0), PL_na)); /* charset */ - XSRETURN_YES; + PERL_RETURN_OK; } /* @@ -143,7 +164,7 @@ static XS (XS_weechat_charset_set) static XS (XS_weechat_iconv_to_internal) { - char *charset, *string, *result; + char *result; dXSARGS; /* make C compiler happy */ @@ -152,46 +173,28 @@ static XS (XS_weechat_iconv_to_internal) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("iconv_to_internal"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } - if (items < 1) + if (items < 2) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("iconv_to_internal"); - XSRETURN_EMPTY; - } - - if (items > 1) - { - charset = SvPV (ST (0), PL_na); - string = SvPV (ST (1), PL_na); - } - else - { - charset = (perl_current_script->charset) ? - perl_current_script->charset : weechat_perl_plugin->charset; - string = SvPV (ST (0), PL_na); + PERL_RETURN_EMPTY; } - result = weechat_iconv_to_internal (charset, string); - if (result) - { - XST_mPV (0, result); - free (result); - XSRETURN (1); - } - - XST_mPV (0, ""); - XSRETURN (1); + result = weechat_iconv_to_internal (SvPV (ST (0), PL_na), /* charset */ + SvPV (ST (1), PL_na)); /* string */ + PERL_RETURN_STRING_FREE(result); } /* - * weechat::iconv_from_internal: convert string from WeeChat inernal to other + * weechat::iconv_from_internal: convert string from WeeChat inernal charset + * to another one */ static XS (XS_weechat_iconv_from_internal) { - char *charset, *string, *result; + char *result; dXSARGS; /* make C compiler happy */ @@ -200,28 +203,18 @@ static XS (XS_weechat_iconv_from_internal) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("iconv_from_internal"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } if (items < 2) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("iconv_from_internal"); - XSRETURN_EMPTY; - } - - charset = SvPV (ST (0), PL_na); - string = SvPV (ST (1), PL_na); - - result = weechat_iconv_from_internal (charset, string); - if (result) - { - XST_mPV (0, result); - free (result); - XSRETURN (1); + PERL_RETURN_EMPTY; } - XST_mPV (0, ""); - XSRETURN (1); + result = weechat_iconv_from_internal (SvPV (ST (0), PL_na), /* charset */ + SvPV (ST (1), PL_na)); /* string */ + PERL_RETURN_STRING_FREE(result); } /* @@ -238,18 +231,20 @@ static XS (XS_weechat_mkdir_home) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("mkdir_home"); - XSRETURN_NO; + PERL_RETURN_ERROR; } if (items < 2) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("mkdir_home"); - XSRETURN_NO; + PERL_RETURN_ERROR; } - weechat_mkdir_home (SvPV (ST (0), PL_na), /* directory */ - SvIV (ST (1))); /* mode */ - XSRETURN_YES; + if (weechat_mkdir_home (SvPV (ST (0), PL_na), /* directory */ + SvIV (ST (1)))) /* mode */ + PERL_RETURN_OK; + + PERL_RETURN_ERROR; } /* @@ -266,19 +261,20 @@ static XS (XS_weechat_mkdir) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("mkdir"); - XSRETURN_NO; + PERL_RETURN_ERROR; } if (items < 2) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("mkdir"); - XSRETURN_NO; + PERL_RETURN_ERROR; } - weechat_mkdir (SvPV (ST (0), PL_na), /* directory */ - SvIV (ST (1))); /* mode */ + if (weechat_mkdir (SvPV (ST (0), PL_na), /* directory */ + SvIV (ST (1)))) /* mode */ + PERL_RETURN_OK; - XSRETURN_YES; + PERL_RETURN_ERROR; } /* @@ -296,24 +292,17 @@ static XS (XS_weechat_prefix) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("prefix"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } if (items < 1) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("prefix"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } result = weechat_prefix (SvPV (ST (0), PL_na)); - if (result) - { - XST_mPV (0, result); - XSRETURN (1); - } - - XST_mPV (0, ""); - XSRETURN (1); + PERL_RETURN_STRING(result); } /* @@ -331,24 +320,17 @@ static XS (XS_weechat_color) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("color"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } if (items < 1) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("color"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } result = weechat_color (SvPV (ST (0), PL_na)); - if (result) - { - XST_mPV (0, result); - XSRETURN (1); - } - - XST_mPV (0, ""); - XSRETURN (1); + PERL_RETURN_STRING(result); } /* @@ -357,7 +339,6 @@ static XS (XS_weechat_color) static XS (XS_weechat_print) { - char *buffer, *message; dXSARGS; /* make C compiler happy */ @@ -366,31 +347,20 @@ static XS (XS_weechat_print) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("print"); - XSRETURN_NO; + PERL_RETURN_ERROR; } - if (items < 1) + if (items < 2) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("print"); - XSRETURN_NO; - } - - if (items > 1) - { - buffer = SvPV (ST (0), PL_na); - message = SvPV (ST (1), PL_na); - } - else - { - buffer = NULL; - message = SvPV (ST (0), PL_na); + PERL_RETURN_ERROR; } script_api_printf (weechat_perl_plugin, perl_current_script, - script_string_to_pointer (buffer), - "%s", message); + script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */ + "%s", SvPV (ST (1), PL_na)); /* message */ - XSRETURN_YES; + PERL_RETURN_OK; } /* @@ -407,13 +377,13 @@ static XS (XS_weechat_infobar_print) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print"); - XSRETURN_NO; + PERL_RETURN_ERROR; } if (items < 3) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print"); - XSRETURN_NO; + PERL_RETURN_ERROR; } script_api_infobar_printf (weechat_perl_plugin, perl_current_script, @@ -422,7 +392,7 @@ static XS (XS_weechat_infobar_print) "%s", SvPV (ST (1), PL_na)); /* message */ - XSRETURN_YES; + PERL_RETURN_OK; } /* @@ -439,16 +409,16 @@ static XS (XS_weechat_infobar_remove) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_remove"); - XSRETURN_NO; + PERL_RETURN_ERROR; } weechat_infobar_remove ((items >= 1) ? SvIV (ST (0)) : 0); - XSRETURN_YES; + PERL_RETURN_OK; } /* - * weechat::log_print: log message in server/channel (current or specified ones) + * weechat::log_print: print message in WeeChat log file */ static XS (XS_weechat_log_print) @@ -461,19 +431,19 @@ static XS (XS_weechat_log_print) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("log_print"); - XSRETURN_NO; + PERL_RETURN_ERROR; } if (items < 1) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("log_print"); - XSRETURN_NO; + PERL_RETURN_ERROR; } script_api_log_printf (weechat_perl_plugin, perl_current_script, - "%s", SvPV (ST (0), PL_na)); + "%s", SvPV (ST (0), PL_na)); /* message */ - XSRETURN_YES; + PERL_RETURN_OK; } /* @@ -485,7 +455,7 @@ weechat_perl_api_hook_command_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { struct t_script_callback *script_callback; - char *perl_argv[3]; + char *perl_argv[3], empty_arg[1] = { '\0' }; int *r, ret; /* make C compiler happy */ @@ -494,15 +464,9 @@ weechat_perl_api_hook_command_cb (void *data, struct t_gui_buffer *buffer, script_callback = (struct t_script_callback *)data; perl_argv[0] = script_pointer_to_string (buffer); - if (argc > 1) - { - perl_argv[1] = argv_eol[1]; - perl_argv[2] = NULL; - } - else - { - perl_argv[1] = NULL; - } + perl_argv[1] = (argc > 1) ? argv_eol[1] : empty_arg; + perl_argv[2] = NULL; + r = (int *) weechat_perl_exec (script_callback->script, WEECHAT_SCRIPT_EXEC_INT, script_callback->function, @@ -526,6 +490,8 @@ weechat_perl_api_hook_command_cb (void *data, struct t_gui_buffer *buffer, static XS (XS_weechat_hook_command) { + struct t_hook *new_hook; + char *result; dXSARGS; /* make C compiler happy */ @@ -534,27 +500,27 @@ static XS (XS_weechat_hook_command) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_command"); - XSRETURN_NO; + PERL_RETURN_EMPTY; } if (items < 6) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_command"); - XSRETURN_NO; + PERL_RETURN_EMPTY; } - if (script_api_hook_command (weechat_perl_plugin, - perl_current_script, - SvPV (ST (0), PL_na), /* command */ - SvPV (ST (1), PL_na), /* description */ - SvPV (ST (2), PL_na), /* args */ - SvPV (ST (3), PL_na), /* args_description */ - SvPV (ST (4), PL_na), /* completion */ - &weechat_perl_api_hook_command_cb, - SvPV (ST (5), PL_na))) /* perl function */ - XSRETURN_YES; - - XSRETURN_NO; + new_hook = script_api_hook_command (weechat_perl_plugin, + perl_current_script, + SvPV (ST (0), PL_na), /* command */ + SvPV (ST (1), PL_na), /* description */ + SvPV (ST (2), PL_na), /* args */ + SvPV (ST (3), PL_na), /* args_description */ + SvPV (ST (4), PL_na), /* completion */ + &weechat_perl_api_hook_command_cb, + SvPV (ST (5), PL_na)); /* perl function */ + + result = script_pointer_to_string (new_hook); + PERL_RETURN_STRING_FREE(result);; } /* @@ -591,6 +557,8 @@ weechat_perl_api_hook_timer_cb (void *data) static XS (XS_weechat_hook_timer) { + struct t_hook *new_hook; + char *result; dXSARGS; /* make C compiler happy */ @@ -599,25 +567,25 @@ static XS (XS_weechat_hook_timer) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_timer"); - XSRETURN_NO; + PERL_RETURN_EMPTY; } if (items < 4) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_timer"); - XSRETURN_NO; + PERL_RETURN_EMPTY; } - if (script_api_hook_timer (weechat_perl_plugin, - perl_current_script, - SvIV (ST (0)), /* interval */ - SvIV (ST (1)), /* align_second */ - SvIV (ST (2)), /* max_calls */ - &weechat_perl_api_hook_timer_cb, - SvPV (ST (3), PL_na))) /* perl function */ - XSRETURN_YES; + new_hook = script_api_hook_timer (weechat_perl_plugin, + perl_current_script, + SvIV (ST (0)), /* interval */ + SvIV (ST (1)), /* align_second */ + SvIV (ST (2)), /* max_calls */ + &weechat_perl_api_hook_timer_cb, + SvPV (ST (3), PL_na)); /* perl function */ - XSRETURN_NO; + result = script_pointer_to_string (new_hook); + PERL_RETURN_STRING_FREE(result); } /* @@ -655,6 +623,8 @@ weechat_perl_api_hook_fd_cb (void *data) static XS (XS_weechat_hook_fd) { + struct t_hook *new_hook; + char *result; dXSARGS; /* make C compiler happy */ @@ -663,26 +633,26 @@ static XS (XS_weechat_hook_fd) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_fd"); - XSRETURN_NO; + PERL_RETURN_EMPTY; } if (items < 5) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_fd"); - XSRETURN_NO; + PERL_RETURN_EMPTY; } - if (script_api_hook_fd (weechat_perl_plugin, - perl_current_script, - SvIV (ST (0)), /* fd */ - SvIV (ST (1)), /* read */ - SvIV (ST (2)), /* write */ - SvIV (ST (3)), /* exception */ - &weechat_perl_api_hook_fd_cb, - SvPV (ST (4), PL_na))) /* perl function */ - XSRETURN_YES; + new_hook = script_api_hook_fd (weechat_perl_plugin, + perl_current_script, + SvIV (ST (0)), /* fd */ + SvIV (ST (1)), /* read */ + SvIV (ST (2)), /* write */ + SvIV (ST (3)), /* exception */ + &weechat_perl_api_hook_fd_cb, + SvPV (ST (4), PL_na)); /* perl function */ - XSRETURN_NO; + result = script_pointer_to_string (new_hook); + PERL_RETURN_STRING_FREE(result); } /* @@ -731,6 +701,8 @@ weechat_perl_api_hook_print_cb (void *data, struct t_gui_buffer *buffer, static XS (XS_weechat_hook_print) { + struct t_hook *new_hook; + char *result; dXSARGS; /* make C compiler happy */ @@ -739,25 +711,25 @@ static XS (XS_weechat_hook_print) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_print"); - XSRETURN_NO; + PERL_RETURN_EMPTY; } if (items < 4) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_print"); - XSRETURN_NO; + PERL_RETURN_EMPTY; } - if (script_api_hook_print (weechat_perl_plugin, - perl_current_script, - script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */ - SvPV (ST (1), PL_na), /* message */ - SvIV (ST (2)), /* strip_colors */ - &weechat_perl_api_hook_print_cb, - SvPV (ST (3), PL_na))) /* perl function */ - XSRETURN_YES; + new_hook = script_api_hook_print (weechat_perl_plugin, + perl_current_script, + script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */ + SvPV (ST (1), PL_na), /* message */ + SvIV (ST (2)), /* strip_colors */ + &weechat_perl_api_hook_print_cb, + SvPV (ST (3), PL_na)); /* perl function */ - XSRETURN_NO; + result = script_pointer_to_string (new_hook); + PERL_RETURN_STRING_FREE(result); } /* @@ -819,6 +791,8 @@ weechat_perl_api_hook_signal_cb (void *data, char *signal, char *type_data, static XS (XS_weechat_hook_signal) { + struct t_hook *new_hook; + char *result; dXSARGS; /* make C compiler happy */ @@ -827,23 +801,23 @@ static XS (XS_weechat_hook_signal) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_signal"); - XSRETURN_NO; + PERL_RETURN_ERROR; } if (items < 2) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_signal"); - XSRETURN_NO; + PERL_RETURN_ERROR; } - if (script_api_hook_signal (weechat_perl_plugin, - perl_current_script, - SvPV (ST (0), PL_na), /* signal */ - &weechat_perl_api_hook_signal_cb, - SvPV (ST (1), PL_na))) /* perl function */ - XSRETURN_YES; + new_hook = script_api_hook_signal (weechat_perl_plugin, + perl_current_script, + SvPV (ST (0), PL_na), /* signal */ + &weechat_perl_api_hook_signal_cb, + SvPV (ST (1), PL_na)); /* perl function */ - XSRETURN_NO; + result = script_pointer_to_string (new_hook); + PERL_RETURN_STRING_FREE(result); } /* @@ -852,6 +826,8 @@ static XS (XS_weechat_hook_signal) static XS (XS_weechat_hook_signal_send) { + char *type_data; + int int_value; dXSARGS; /* make C compiler happy */ @@ -860,20 +836,40 @@ static XS (XS_weechat_hook_signal_send) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_signal_send"); - XSRETURN_NO; + PERL_RETURN_ERROR; } if (items < 3) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_signal_send"); - XSRETURN_NO; + PERL_RETURN_ERROR; } - weechat_hook_signal_send (SvPV (ST (0), PL_na), /* signal */ - SvPV (ST (1), PL_na), /* type_data */ - SvPV (ST (2), PL_na)); /* signal_data */ + type_data = SvPV (ST (1), PL_na); + if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) + { + weechat_hook_signal_send (SvPV (ST (0), PL_na), /* signal */ + type_data, + SvPV (ST (2), PL_na)); /* signal_data */ + PERL_RETURN_OK; + } + else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0) + { + int_value = SvIV(ST (2)); + weechat_hook_signal_send (SvPV (ST (0), PL_na), /* signal */ + type_data, + &int_value); /* signal_data */ + PERL_RETURN_OK; + } + else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0) + { + weechat_hook_signal_send (SvPV (ST (0), PL_na), /* signal */ + type_data, + script_string_to_pointer (SvPV (ST (2), PL_na))); /* signal_data */ + PERL_RETURN_OK; + } - XSRETURN_YES; + PERL_RETURN_ERROR; } /* @@ -916,6 +912,8 @@ weechat_perl_api_hook_config_cb (void *data, char *type, char *option, static XS (XS_weechat_hook_config) { + struct t_hook *new_hook; + char *result; dXSARGS; /* make C compiler happy */ @@ -924,24 +922,24 @@ static XS (XS_weechat_hook_config) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_config"); - XSRETURN_NO; + PERL_RETURN_EMPTY; } if (items < 3) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_config"); - XSRETURN_NO; + PERL_RETURN_EMPTY; } - if (script_api_hook_config (weechat_perl_plugin, - perl_current_script, - SvPV (ST (0), PL_na), /* type */ - SvPV (ST (1), PL_na), /* option */ - &weechat_perl_api_hook_config_cb, - SvPV (ST (2), PL_na))) /* perl function */ - XSRETURN_YES; + new_hook = script_api_hook_config (weechat_perl_plugin, + perl_current_script, + SvPV (ST (0), PL_na), /* type */ + SvPV (ST (1), PL_na), /* option */ + &weechat_perl_api_hook_config_cb, + SvPV (ST (2), PL_na)); /* perl function */ - XSRETURN_NO; + result = script_pointer_to_string (new_hook); + PERL_RETURN_STRING_FREE(result); } /* @@ -989,6 +987,8 @@ weechat_perl_api_hook_completion_cb (void *data, char *completion, static XS (XS_weechat_hook_completion) { + struct t_hook *new_hook; + char *result; dXSARGS; /* make C compiler happy */ @@ -997,23 +997,23 @@ static XS (XS_weechat_hook_completion) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_completion"); - XSRETURN_NO; + PERL_RETURN_EMPTY; } if (items < 2) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_completion"); - XSRETURN_NO; + PERL_RETURN_EMPTY; } - if (script_api_hook_completion (weechat_perl_plugin, - perl_current_script, - SvPV (ST (0), PL_na), /* completion */ - &weechat_perl_api_hook_completion_cb, - SvPV (ST (1), PL_na))) /* perl function */ - XSRETURN_YES; + new_hook = script_api_hook_completion (weechat_perl_plugin, + perl_current_script, + SvPV (ST (0), PL_na), /* completion */ + &weechat_perl_api_hook_completion_cb, + SvPV (ST (1), PL_na)); /* perl function */ - XSRETURN_NO; + result = script_pointer_to_string (new_hook); + PERL_RETURN_STRING_FREE(result); } /* @@ -1030,19 +1030,20 @@ static XS (XS_weechat_unhook) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("unhook"); - XSRETURN_NO; + PERL_RETURN_ERROR; } if (items < 1) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("unhook"); - XSRETURN_NO; + PERL_RETURN_ERROR; } - script_api_unhook (weechat_perl_plugin, perl_current_script, - script_string_to_pointer (SvPV (ST (0), PL_na))); + if (script_api_unhook (weechat_perl_plugin, perl_current_script, + script_string_to_pointer (SvPV (ST (0), PL_na)))) + PERL_RETURN_OK; - XSRETURN_YES; + PERL_RETURN_ERROR; } /* @@ -1060,12 +1061,12 @@ static XS (XS_weechat_unhook_all) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("unhook_all"); - XSRETURN_NO; + PERL_RETURN_ERROR; } script_api_unhook_all (weechat_perl_plugin, perl_current_script); - XSRETURN_YES; + PERL_RETURN_OK; } /* @@ -1119,13 +1120,13 @@ static XS (XS_weechat_buffer_new) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_new"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } if (items < 3) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_new"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } new_buffer = script_api_buffer_new (weechat_perl_plugin, @@ -1136,15 +1137,7 @@ static XS (XS_weechat_buffer_new) SvPV (ST (2), PL_na)); /* perl function */ result = script_pointer_to_string (new_buffer); - if (result) - { - XST_mPV (0, result); - free (result); - XSRETURN (1); - } - - XST_mPV (0, ""); - XSRETURN (1); + PERL_RETURN_STRING_FREE(result); } /* @@ -1163,28 +1156,20 @@ static XS (XS_weechat_buffer_search) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_search"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } if (items < 2) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_search"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } ptr_buffer = weechat_buffer_search (SvPV (ST (0), PL_na), /* category */ SvPV (ST (1), PL_na)); /* name */ result = script_pointer_to_string (ptr_buffer); - if (result) - { - XST_mPV (0, result); - free (result); - XSRETURN (1); - } - - XST_mPV (0, ""); - XSRETURN (1); + PERL_RETURN_STRING_FREE(result); } /* @@ -1201,13 +1186,13 @@ static XS (XS_weechat_buffer_close) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_close"); - XSRETURN_NO; + PERL_RETURN_ERROR; } if (items < 2) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_close"); - XSRETURN_NO; + PERL_RETURN_ERROR; } script_api_buffer_close (weechat_perl_plugin, @@ -1215,7 +1200,7 @@ static XS (XS_weechat_buffer_close) script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */ SvIV (ST (1))); /* switch_to_another */ - XSRETURN_YES; + PERL_RETURN_OK; } /* @@ -1233,25 +1218,18 @@ static XS (XS_weechat_buffer_get) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_get"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } if (items < 2) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_get"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } value = weechat_buffer_get (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */ SvPV (ST (1), PL_na)); /* property */ - if (value) - { - XST_mPV (0, value); - XSRETURN (1); - } - - XST_mPV (0, ""); - XSRETURN (1); + PERL_RETURN_STRING(value); } /* @@ -1268,20 +1246,20 @@ static XS (XS_weechat_buffer_set) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_set"); - XSRETURN_NO; + PERL_RETURN_ERROR; } if (items < 3) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_set"); - XSRETURN_NO; + PERL_RETURN_ERROR; } weechat_buffer_set (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */ SvPV (ST (1), PL_na), /* property */ SvPV (ST (2), PL_na)); /* value */ - XSRETURN_YES; + PERL_RETURN_OK; } /* @@ -1300,13 +1278,13 @@ static XS (XS_weechat_nicklist_add_group) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("nicklist_add_group"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } if (items < 5) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("nicklist_add_group"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } new_group = weechat_nicklist_add_group (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */ @@ -1316,15 +1294,7 @@ static XS (XS_weechat_nicklist_add_group) SvIV (ST (4))); /* visible */ result = script_pointer_to_string (new_group); - if (result) - { - XST_mPV (0, result); - free (result); - XSRETURN (1); - } - - XST_mPV (0, ""); - XSRETURN (1); + PERL_RETURN_STRING_FREE(result); } /* @@ -1343,13 +1313,13 @@ static XS (XS_weechat_nicklist_search_group) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("nicklist_search_group"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } if (items < 3) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("nicklist_search_group"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } ptr_group = weechat_nicklist_search_group (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */ @@ -1357,15 +1327,7 @@ static XS (XS_weechat_nicklist_search_group) SvPV (ST (2), PL_na)); /* name */ result = script_pointer_to_string (ptr_group); - if (result) - { - XST_mPV (0, result); - free (result); - XSRETURN (1); - } - - XST_mPV (0, ""); - XSRETURN (1); + PERL_RETURN_STRING_FREE(result); } /* @@ -1384,20 +1346,21 @@ static XS (XS_weechat_nicklist_add_nick) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("nicklist_add_nick"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } if (items < 7) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("nicklist_add_nick"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } - + str_prefix = SvPV(ST (4), PL_na); if (str_prefix && str_prefix[0]) prefix = str_prefix[0]; else prefix = ' '; + new_nick = weechat_nicklist_add_nick (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */ script_string_to_pointer (SvPV (ST (1), PL_na)), /* group */ SvPV (ST (2), PL_na), /* name */ @@ -1407,15 +1370,7 @@ static XS (XS_weechat_nicklist_add_nick) SvIV (ST (6))); /* visible */ result = script_pointer_to_string (new_nick); - if (result) - { - XST_mPV (0, result); - free (result); - XSRETURN (1); - } - - XST_mPV (0, ""); - XSRETURN (1); + PERL_RETURN_STRING_FREE(result); } /* @@ -1434,13 +1389,13 @@ static XS (XS_weechat_nicklist_search_nick) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("nicklist_search_nick"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } if (items < 3) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("nicklist_search_nick"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } ptr_nick = weechat_nicklist_search_nick (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */ @@ -1448,15 +1403,7 @@ static XS (XS_weechat_nicklist_search_nick) SvPV (ST (2), PL_na)); /* name */ result = script_pointer_to_string (ptr_nick); - if (result) - { - XST_mPV (0, result); - free (result); - XSRETURN (1); - } - - XST_mPV (0, ""); - XSRETURN (1); + PERL_RETURN_STRING_FREE(result); } /* @@ -1473,19 +1420,19 @@ static XS (XS_weechat_nicklist_remove_group) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("nicklist_remove_group"); - XSRETURN_NO; + PERL_RETURN_ERROR; } if (items < 2) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("nicklist_remove_group"); - XSRETURN_NO; + PERL_RETURN_ERROR; } weechat_nicklist_remove_group (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */ script_string_to_pointer (SvPV (ST (1), PL_na))); /* group */ - XSRETURN_YES; + PERL_RETURN_OK; } /* @@ -1502,19 +1449,19 @@ static XS (XS_weechat_nicklist_remove_nick) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("nicklist_remove_nick"); - XSRETURN_NO; + PERL_RETURN_ERROR; } if (items < 2) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("nicklist_remove_nick"); - XSRETURN_NO; + PERL_RETURN_ERROR; } weechat_nicklist_remove_nick (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */ script_string_to_pointer (SvPV (ST (1), PL_na))); /* nick */ - XSRETURN_YES; + PERL_RETURN_OK; } /* @@ -1531,18 +1478,18 @@ static XS (XS_weechat_nicklist_remove_all) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("nicklist_remove_all"); - XSRETURN_NO; + PERL_RETURN_ERROR; } if (items < 2) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("nicklist_remove_all"); - XSRETURN_NO; + PERL_RETURN_ERROR; } weechat_nicklist_remove_all (script_string_to_pointer (SvPV (ST (0), PL_na))); /* buffer */ - XSRETURN_YES; + PERL_RETURN_OK; } /* @@ -1551,7 +1498,6 @@ static XS (XS_weechat_nicklist_remove_all) static XS (XS_weechat_command) { - char *buffer, *command; dXSARGS; /* make C compiler happy */ @@ -1560,31 +1506,20 @@ static XS (XS_weechat_command) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("command"); - XSRETURN_NO; + PERL_RETURN_ERROR; } - if (items < 1) + if (items < 2) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("command"); - XSRETURN_NO; - } - - if (items > 1) - { - buffer = SvPV (ST (0), PL_na); - command = SvPV (ST (1), PL_na); - } - else - { - buffer = NULL; - command = SvPV (ST (0), PL_na); + PERL_RETURN_ERROR; } script_api_command (weechat_perl_plugin, perl_current_script, - script_string_to_pointer (buffer), - command); + script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */ + SvPV (ST (1), PL_na)); /* command */ - XSRETURN_YES; + PERL_RETURN_OK; } /* @@ -1602,24 +1537,17 @@ static XS (XS_weechat_info_get) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("info_get"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } if (items < 1) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("info_get"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } value = weechat_info_get (SvPV (ST (0), PL_na)); - if (value) - { - XST_mPV (0, value); - XSRETURN (1); - } - - XST_mPV (0, ""); - XSRETURN (1); + PERL_RETURN_STRING(value); } /* @@ -1646,13 +1574,13 @@ static XS (XS_weechat_get_dcc_info) weechat_perl_plugin->print_server (weechat_perl_plugin, "Perl error: unable to get DCC info, " "script not initialized"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } dcc_info = weechat_perl_plugin->get_dcc_info (weechat_perl_plugin); count = 0; if (!dcc_info) - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; for (ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc) { @@ -1707,13 +1635,13 @@ static XS (XS_weechat_config_get_weechat) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_get_weechat"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } if (items < 1) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_get_weechat"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } option = SvPV (ST (0), PL_na); @@ -1753,7 +1681,7 @@ static XS (XS_weechat_set_config) weechat_perl_plugin->print_server (weechat_perl_plugin, "Perl error: unable to set config option, " "script not initialized"); - XSRETURN_NO; + PERL_RETURN_ERROR; } if (items < 2) @@ -1761,7 +1689,7 @@ static XS (XS_weechat_set_config) weechat_perl_plugin->print_server (weechat_perl_plugin, "Perl error: wrong parameters for " "\"set_config\" function"); - XSRETURN_NO; + PERL_RETURN_ERROR; } option = SvPV (ST (0), PL_na); @@ -1770,10 +1698,10 @@ static XS (XS_weechat_set_config) if (option && value) { if (weechat_perl_plugin->set_config (weechat_perl_plugin, option, value)) - XSRETURN_YES; + PERL_RETURN_OK; } - XSRETURN_NO; + PERL_RETURN_ERROR; } */ @@ -1795,7 +1723,7 @@ static XS (XS_weechat_get_plugin_config) weechat_perl_plugin->print_server (weechat_perl_plugin, "Perl error: unable to get plugin config option, " "script not initialized"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } if (items < 1) @@ -1803,7 +1731,7 @@ static XS (XS_weechat_get_plugin_config) weechat_perl_plugin->print_server (weechat_perl_plugin, "Perl error: wrong parameters for " "\"get_plugin_config\" function"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } option = SvPV (ST (0), PL_na); @@ -1845,7 +1773,7 @@ static XS (XS_weechat_set_plugin_config) weechat_perl_plugin->print_server (weechat_perl_plugin, "Perl error: unable to set plugin config option, " "script not initialized"); - XSRETURN_NO; + PERL_RETURN_ERROR; } if (items < 2) @@ -1853,7 +1781,7 @@ static XS (XS_weechat_set_plugin_config) weechat_perl_plugin->print_server (weechat_perl_plugin, "Perl error: wrong parameters for " "\"set_plugin_config\" function"); - XSRETURN_NO; + PERL_RETURN_ERROR; } option = SvPV (ST (0), PL_na); @@ -1864,10 +1792,10 @@ static XS (XS_weechat_set_plugin_config) if (weechat_script_set_plugin_config (weechat_perl_plugin, perl_current_script, option, value)) - XSRETURN_YES; + PERL_RETURN_OK; } - XSRETURN_NO; + PERL_RETURN_ERROR; } */ @@ -1892,20 +1820,20 @@ static XS (XS_weechat_get_server_info) weechat_perl_plugin->print_server (weechat_perl_plugin, "Perl error: unable to get server info, " "script not initialized"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } server_info = weechat_perl_plugin->get_server_info (weechat_perl_plugin); if (!server_info) { - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } server_hash = (HV *) sv_2mortal((SV *) newHV()); if (!server_hash) { weechat_perl_plugin->free_server_info (weechat_perl_plugin, server_info); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } for (ptr_server = server_info; ptr_server; ptr_server = ptr_server->next_server) @@ -1972,7 +1900,7 @@ static XS (XS_weechat_get_channel_info) weechat_perl_plugin->print_server (weechat_perl_plugin, "Perl error: unable to get channel info, " "script not initialized"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } if (items != 1) @@ -1980,24 +1908,24 @@ static XS (XS_weechat_get_channel_info) weechat_perl_plugin->print_server (weechat_perl_plugin, "Perl error: wrong parameters for " "\"get_channel_info\" function"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } server = SvPV (ST (0), PL_na); if (!server) - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; channel_info = weechat_perl_plugin->get_channel_info (weechat_perl_plugin, server); if (!channel_info) { - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } channel_hash = (HV *) sv_2mortal((SV *) newHV()); if (!channel_hash) { weechat_perl_plugin->free_channel_info (weechat_perl_plugin, channel_info); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } for (ptr_channel = channel_info; ptr_channel; ptr_channel = ptr_channel->next_channel) @@ -2042,7 +1970,7 @@ static XS (XS_weechat_get_nick_info) weechat_perl_plugin->print_server (weechat_perl_plugin, "Perl error: unable to get nick info, " "script not initialized"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } if (items != 2) @@ -2050,25 +1978,25 @@ static XS (XS_weechat_get_nick_info) weechat_perl_plugin->print_server (weechat_perl_plugin, "Perl error: wrong parameters for " "\"get_nick_info\" function"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } server = SvPV (ST (0), PL_na); channel = SvPV (ST (1), PL_na); if (!server || !channel) - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; nick_info = weechat_perl_plugin->get_nick_info (weechat_perl_plugin, server, channel); if (!nick_info) { - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } nick_hash = (HV *) sv_2mortal((SV *) newHV()); if (!nick_hash) { weechat_perl_plugin->free_nick_info (weechat_perl_plugin, nick_info); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } for (ptr_nick = nick_info; ptr_nick; ptr_nick = ptr_nick->next_nick) @@ -2108,7 +2036,7 @@ static XS (XS_weechat_input_color) weechat_perl_plugin->print_server (weechat_perl_plugin, "Perl error: unable to colorize input, " "script not initialized"); - XSRETURN_NO; + PERL_RETURN_ERROR; } if (items < 3) @@ -2116,7 +2044,7 @@ static XS (XS_weechat_input_color) weechat_perl_plugin->print_server (weechat_perl_plugin, "Perl error: wrong parameters for " "\"color_input\" function"); - XSRETURN_NO; + PERL_RETURN_ERROR; } color = SvIV (ST (0)); @@ -2125,7 +2053,7 @@ static XS (XS_weechat_input_color) weechat_perl_plugin->input_color (weechat_perl_plugin, color, start, length); - XSRETURN_YES; + PERL_RETURN_OK; } */ @@ -2194,13 +2122,13 @@ static XS (XS_weechat_get_window_info) weechat_perl_plugin->print_server (weechat_perl_plugin, "Perl error: unable to get window info, " "script not initialized"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } window_info = weechat_perl_plugin->get_window_info (weechat_perl_plugin); count = 0; if (!window_info) - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; for (ptr_win = window_info; ptr_win; ptr_win = ptr_win->next_window) { @@ -2244,20 +2172,20 @@ static XS (XS_weechat_get_buffer_info) weechat_perl_plugin->print_server (weechat_perl_plugin, "Perl error: unable to get buffer info, " "script not initialized"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } buffer_info = weechat_perl_plugin->get_buffer_info (weechat_perl_plugin); if (!buffer_info) { - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } buffer_hash = (HV *) sv_2mortal((SV *) newHV()); if (!buffer_hash) { weechat_perl_plugin->free_buffer_info (weechat_perl_plugin, buffer_info); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } for (ptr_buffer = buffer_info; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) @@ -2309,7 +2237,7 @@ static XS (XS_weechat_get_buffer_data) weechat_perl_plugin->print_server (weechat_perl_plugin, "Perl error: unable to get buffer data, " "script not initialized"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } if (items != 2) @@ -2317,7 +2245,7 @@ static XS (XS_weechat_get_buffer_data) weechat_perl_plugin->print_server (weechat_perl_plugin, "Perl error: wrong parameters for " "\"get_buffer_data\" function"); - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; } channel = NULL; @@ -2333,7 +2261,7 @@ static XS (XS_weechat_get_buffer_data) buffer_data = weechat_perl_plugin->get_buffer_data (weechat_perl_plugin, server, channel); count = 0; if (!buffer_data) - XSRETURN_EMPTY; + PERL_RETURN_EMPTY; for (ptr_data = buffer_data; ptr_data; ptr_data = ptr_data->next_line) { @@ -2421,8 +2349,8 @@ weechat_perl_xs_init (pTHX) /* interface constants */ stash = gv_stashpv ("weechat", TRUE); - newCONSTSUB (stash, "weechat::WEECHAT_RC_ERROR", newSViv (WEECHAT_RC_ERROR)); newCONSTSUB (stash, "weechat::WEECHAT_RC_OK", newSViv (WEECHAT_RC_OK)); + newCONSTSUB (stash, "weechat::WEECHAT_RC_ERROR", newSViv (WEECHAT_RC_ERROR)); newCONSTSUB (stash, "weechat::WEECHAT_RC_OK_IGNORE_WEECHAT", newSViv (WEECHAT_RC_OK_IGNORE_WEECHAT)); newCONSTSUB (stash, "weechat::WEECHAT_RC_OK_IGNORE_PLUGINS", newSViv (WEECHAT_RC_OK_IGNORE_PLUGINS)); newCONSTSUB (stash, "weechat::WEECHAT_RC_OK_IGNORE_ALL", newSViv (WEECHAT_RC_OK_IGNORE_ALL)); diff --git a/src/plugins/scripts/perl/weechat-perl-api.h b/src/plugins/scripts/perl/weechat-perl-api.h index 90a9b3777..5aedc0723 100644 --- a/src/plugins/scripts/perl/weechat-perl-api.h +++ b/src/plugins/scripts/perl/weechat-perl-api.h @@ -20,10 +20,6 @@ #ifndef __WEECHAT_PERL_API_H #define __WEECHAT_PERL_API_H 1 -#define weechat_plugin weechat_perl_plugin - -extern struct t_weechat_plugin *weechat_perl_plugin; - extern void weechat_perl_xs_init (pTHX); #endif /* weechat-perl.h */ diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c index 90b074e7d..f452a58cd 100644 --- a/src/plugins/scripts/perl/weechat-perl.c +++ b/src/plugins/scripts/perl/weechat-perl.c @@ -230,7 +230,7 @@ weechat_perl_load (char *filename) #endif weechat_printf (NULL, - weechat_gettext ("%s%s: loading Perl script \"%s\""), + weechat_gettext ("%s%s: loading script \"%s\""), weechat_prefix ("info"), "perl", filename); if (stat (filename, &buf) != 0) @@ -476,7 +476,9 @@ weechat_perl_command_cb (void *data, struct t_gui_buffer *buffer, { /* list registered Perl scripts */ weechat_printf (NULL, ""); - weechat_printf (NULL, weechat_gettext ("Registered Perl scripts:")); + weechat_printf (NULL, + weechat_gettext ("Registered %s scripts:"), + "perl"); if (perl_scripts) { for (ptr_script = perl_scripts; ptr_script; @@ -493,127 +495,128 @@ weechat_perl_command_cb (void *data, struct t_gui_buffer *buffer, } } else - weechat_printf (NULL, " (none)"); + weechat_printf (NULL, weechat_gettext (" (none)")); + + /* + // List Perl message handlers + plugin->print_server (plugin, ""); + plugin->print_server (plugin, "Perl message handlers:"); + handler_found = 0; + for (ptr_handler = plugin->handlers; + ptr_handler; ptr_handler = ptr_handler->next_handler) + { + if ((ptr_handler->type == PLUGIN_HANDLER_MESSAGE) + && (ptr_handler->handler_args)) + { + handler_found = 1; + plugin->print_server (plugin, " IRC(%s) => Perl(%s)", + ptr_handler->irc_command, + ptr_handler->handler_args); + } + } + if (!handler_found) + plugin->print_server (plugin, " (none)"); - /* list Perl message handlers */ - /*plugin->print_server (plugin, ""); - plugin->print_server (plugin, "Perl message handlers:"); - handler_found = 0; - for (ptr_handler = plugin->handlers; - ptr_handler; ptr_handler = ptr_handler->next_handler) - { - if ((ptr_handler->type == PLUGIN_HANDLER_MESSAGE) - && (ptr_handler->handler_args)) - { - handler_found = 1; - plugin->print_server (plugin, " IRC(%s) => Perl(%s)", - ptr_handler->irc_command, - ptr_handler->handler_args); - } - } - if (!handler_found) - plugin->print_server (plugin, " (none)"); - */ - /* list Perl command handlers */ - /*plugin->print_server (plugin, ""); - plugin->print_server (plugin, "Perl command handlers:"); - handler_found = 0; - for (ptr_handler = plugin->handlers; - ptr_handler; ptr_handler = ptr_handler->next_handler) - { - if ((ptr_handler->type == PLUGIN_HANDLER_COMMAND) - && (ptr_handler->handler_args)) - { - handler_found = 1; - plugin->print_server (plugin, " /%s => Perl(%s)", - ptr_handler->command, - ptr_handler->handler_args); - } - } - if (!handler_found) - plugin->print_server (plugin, " (none)"); - */ - /* list Perl timer handlers */ - /*plugin->print_server (plugin, ""); - plugin->print_server (plugin, "Perl timer handlers:"); - handler_found = 0; - for (ptr_handler = plugin->handlers; - ptr_handler; ptr_handler = ptr_handler->next_handler) - { - if ((ptr_handler->type == PLUGIN_HANDLER_TIMER) - && (ptr_handler->handler_args)) - { - handler_found = 1; - plugin->print_server (plugin, " %d seconds => Perl(%s)", - ptr_handler->interval, - ptr_handler->handler_args); - } - } - if (!handler_found) - plugin->print_server (plugin, " (none)"); - */ - /* list Perl keyboard handlers */ - /*plugin->print_server (plugin, ""); - plugin->print_server (plugin, "Perl keyboard handlers:"); - handler_found = 0; - for (ptr_handler = plugin->handlers; - ptr_handler; ptr_handler = ptr_handler->next_handler) - { - if ((ptr_handler->type == PLUGIN_HANDLER_KEYBOARD) - && (ptr_handler->handler_args)) - { - handler_found = 1; - plugin->print_server (plugin, " Perl(%s)", - ptr_handler->handler_args); - } - } - if (!handler_found) - plugin->print_server (plugin, " (none)"); - */ - /* list Perl event handlers */ - /*plugin->print_server (plugin, ""); - plugin->print_server (plugin, "Perl event handlers:"); - handler_found = 0; - for (ptr_handler = plugin->handlers; - ptr_handler; ptr_handler = ptr_handler->next_handler) - { - if ((ptr_handler->type == PLUGIN_HANDLER_EVENT) - && (ptr_handler->handler_args)) - { - handler_found = 1; - plugin->print_server (plugin, " %s => Perl(%s)", - ptr_handler->event, - ptr_handler->handler_args); - } - } - if (!handler_found) - plugin->print_server (plugin, " (none)"); - */ - /* List Perl modifiers */ - /*plugin->print_server (plugin, ""); - plugin->print_server (plugin, "Perl modifiers:"); - modifier_found = 0; - for (ptr_modifier = plugin->modifiers; - ptr_modifier; ptr_modifier = ptr_modifier->next_modifier) - { - modifier_found = 1; - if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_IN) - plugin->print_server (plugin, " IRC(%s, %s) => Perl(%s)", - ptr_modifier->command, - PLUGIN_MODIFIER_IRC_IN_STR, - ptr_modifier->modifier_args); - else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_USER) - plugin->print_server (plugin, " IRC(%s, %s) => Perl(%s)", - ptr_modifier->command, - PLUGIN_MODIFIER_IRC_USER_STR, - ptr_modifier->modifier_args); - else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_OUT) - plugin->print_server (plugin, " IRC(%s, %s) => Perl(%s)", - ptr_modifier->command, - PLUGIN_MODIFIER_IRC_OUT_STR, - ptr_modifier->modifier_args); - } - if (!modifier_found) + // List Perl command handlers + plugin->print_server (plugin, ""); + plugin->print_server (plugin, "Perl command handlers:"); + handler_found = 0; + for (ptr_handler = plugin->handlers; + ptr_handler; ptr_handler = ptr_handler->next_handler) + { + if ((ptr_handler->type == PLUGIN_HANDLER_COMMAND) + && (ptr_handler->handler_args)) + { + handler_found = 1; + plugin->print_server (plugin, " /%s => Perl(%s)", + ptr_handler->command, + ptr_handler->handler_args); + } + } + if (!handler_found) + plugin->print_server (plugin, " (none)"); + + // List Perl timer handlers + plugin->print_server (plugin, ""); + plugin->print_server (plugin, "Perl timer handlers:"); + handler_found = 0; + for (ptr_handler = plugin->handlers; + ptr_handler; ptr_handler = ptr_handler->next_handler) + { + if ((ptr_handler->type == PLUGIN_HANDLER_TIMER) + && (ptr_handler->handler_args)) + { + handler_found = 1; + plugin->print_server (plugin, " %d seconds => Perl(%s)", + ptr_handler->interval, + ptr_handler->handler_args); + } + } + if (!handler_found) + plugin->print_server (plugin, " (none)"); + + // List Perl keyboard handlers + plugin->print_server (plugin, ""); + plugin->print_server (plugin, "Perl keyboard handlers:"); + handler_found = 0; + for (ptr_handler = plugin->handlers; + ptr_handler; ptr_handler = ptr_handler->next_handler) + { + if ((ptr_handler->type == PLUGIN_HANDLER_KEYBOARD) + && (ptr_handler->handler_args)) + { + handler_found = 1; + plugin->print_server (plugin, " Perl(%s)", + ptr_handler->handler_args); + } + } + if (!handler_found) + plugin->print_server (plugin, " (none)"); + + // List Perl event handlers + plugin->print_server (plugin, ""); + plugin->print_server (plugin, "Perl event handlers:"); + handler_found = 0; + for (ptr_handler = plugin->handlers; + ptr_handler; ptr_handler = ptr_handler->next_handler) + { + if ((ptr_handler->type == PLUGIN_HANDLER_EVENT) + && (ptr_handler->handler_args)) + { + handler_found = 1; + plugin->print_server (plugin, " %s => Perl(%s)", + ptr_handler->event, + ptr_handler->handler_args); + } + } + if (!handler_found) + plugin->print_server (plugin, " (none)"); + + // List Perl modifiers + plugin->print_server (plugin, ""); + plugin->print_server (plugin, "Perl modifiers:"); + modifier_found = 0; + for (ptr_modifier = plugin->modifiers; + ptr_modifier; ptr_modifier = ptr_modifier->next_modifier) + { + modifier_found = 1; + if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_IN) + plugin->print_server (plugin, " IRC(%s, %s) => Perl(%s)", + ptr_modifier->command, + PLUGIN_MODIFIER_IRC_IN_STR, + ptr_modifier->modifier_args); + else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_USER) + plugin->print_server (plugin, " IRC(%s, %s) => Perl(%s)", + ptr_modifier->command, + PLUGIN_MODIFIER_IRC_USER_STR, + ptr_modifier->modifier_args); + else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_OUT) + plugin->print_server (plugin, " IRC(%s, %s) => Perl(%s)", + ptr_modifier->command, + PLUGIN_MODIFIER_IRC_OUT_STR, + ptr_modifier->modifier_args); + } + if (!modifier_found) plugin->print_server (plugin, " (none)"); */ } @@ -680,8 +683,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin) if (!perl_main) { weechat_printf (NULL, - weechat_gettext ("%s%s: unable to initialize Perl"), - weechat_prefix ("error"), "perl"); + weechat_gettext ("%s%s: unable to initialize %s"), + weechat_prefix ("error"), "perl", "perl"); return WEECHAT_RC_ERROR; } @@ -706,7 +709,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin) weechat_mkdir_home ("perl/autoload", 0644); script_init (weechat_perl_plugin); - script_auto_load (weechat_perl_plugin, "perl", &weechat_perl_load_cb); + script_auto_load (weechat_perl_plugin, "perl", + &weechat_perl_load_cb); /* init ok */ return WEECHAT_RC_OK; @@ -723,7 +727,7 @@ weechat_plugin_end (struct t_weechat_plugin *plugin) (void) plugin; /* unload all scripts */ - weechat_perl_unload_all (weechat_perl_plugin); + weechat_perl_unload_all (); #ifndef MULTIPLICITY /* free perl intepreter */ diff --git a/src/plugins/scripts/perl/weechat-perl.h b/src/plugins/scripts/perl/weechat-perl.h index 3aab01578..cdeb25a69 100644 --- a/src/plugins/scripts/perl/weechat-perl.h +++ b/src/plugins/scripts/perl/weechat-perl.h @@ -21,7 +21,6 @@ #define __WEECHAT_PERL_H 1 #include "../../weechat-plugin.h" -#include "../script.h" #define weechat_plugin weechat_perl_plugin diff --git a/src/plugins/scripts/python/Makefile.am b/src/plugins/scripts/python/Makefile.am index 853803a12..a63fabb2c 100644 --- a/src/plugins/scripts/python/Makefile.am +++ b/src/plugins/scripts/python/Makefile.am @@ -20,6 +20,9 @@ libdir = ${weechat_libdir}/plugins lib_LTLIBRARIES = python.la -python_la_SOURCES = python.c +python_la_SOURCES = weechat-python.c \ + weechat-python.h \ + weechat-python-api.c \ + weechat-python-api.h python_la_LDFLAGS = -module python_la_LIBADD = ../lib_weechat_plugins_scripts.la $(PYTHON_LFLAGS) diff --git a/src/plugins/scripts/python/python.c b/src/plugins/scripts/python/python.c deleted file mode 100644 index 6a243243e..000000000 --- a/src/plugins/scripts/python/python.c +++ /dev/null @@ -1,2731 +0,0 @@ -/* - * Copyright (c) 2003-2008 by FlashCode - * See README for License detail, AUTHORS for developers list. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/* weechat-python.c: Python plugin support for WeeChat */ - -#undef _ - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "../../weechat-plugin.h" -#include "../weechat-script.h" - - -WEECHAT_PLUGIN_NAME("python"); -WEECHAT_PLUGIN_DESCRIPTION("Python plugin for WeeChat"); -WEECHAT_PLUGIN_AUTHOR("FlashCode "); -WEECHAT_PLUGIN_VERSION("0.1"); -WEECHAT_PLUGIN_LICENSE("GPL"); - -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; - -char python_buffer_output[128]; - -/* - * weechat_python_exec: execute a Python script - */ - -void * -weechat_python_exec (t_weechat_plugin *plugin, - t_plugin_script *script, - int ret_type, - char *function, char *arg1, char *arg2, char *arg3) -{ - PyObject *evMain; - PyObject *evDict; - PyObject *evFunc; - PyObject *rc; - void *ret_value; - int *ret_i; - - /* 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->print_server (plugin, - "Python error: unable to run function \"%s\"", - function); - /* PyEval_ReleaseThread (python_current_script->interpreter); */ - return NULL; - } - - python_current_script = script; - - if (arg1) - { - if (arg2) - { - if (arg3) - rc = PyObject_CallFunction (evFunc, "sss", arg1, arg2, arg3); - else - rc = PyObject_CallFunction (evFunc, "ss", arg1, arg2); - } - else - rc = PyObject_CallFunction (evFunc, "s", arg1); - } - else - rc = PyObject_CallFunction (evFunc, NULL); - - - ret_value = NULL; - - /* - ugly hack : rc = NULL while 'return weechat.PLUGIN_RC_OK .... - because of '#define PLUGIN_RC_OK 0' - */ - if (rc == NULL) - rc = PyInt_FromLong (0); - - if (PyString_Check (rc) && (ret_type == SCRIPT_EXEC_STRING)) - { - if (PyString_AsString (rc)) - ret_value = strdup (PyString_AsString(rc)); - else - ret_value = NULL; - - Py_XDECREF(rc); - } - else if (PyInt_Check (rc) && (ret_type == SCRIPT_EXEC_INT)) - { - - ret_i = (int *)malloc (sizeof(int)); - if (ret_i) - *ret_i = (int) PyInt_AsLong(rc); - ret_value = ret_i; - - Py_XDECREF(rc); - } - else - { - python_plugin->print_server (python_plugin, - "Python error: function \"%s\" must return a valid value", - function); - /* PyEval_ReleaseThread (python_current_script->interpreter); */ - return NULL; - } - - if (ret_value == NULL) - { - plugin->print_server (plugin, - "Python error: unable to alloc memory in function \"%s\"", - function); - /* PyEval_ReleaseThread (python_current_script->interpreter); */ - return NULL; - } - - if (PyErr_Occurred ()) PyErr_Print (); - - /* PyEval_ReleaseThread (python_current_script->interpreter); */ - - return ret_value; -} - -/* - * weechat_python_cmd_msg_handler: general command/message handler for Python - */ - -int -weechat_python_cmd_msg_handler (t_weechat_plugin *plugin, - int argc, char **argv, - char *handler_args, void *handler_pointer) -{ - int *r; - int ret; - - if (argc >= 3) - { - r = (int *) weechat_python_exec (plugin, (t_plugin_script *)handler_pointer, - SCRIPT_EXEC_INT, - handler_args, argv[0], argv[2], NULL); - if (r == NULL) - ret = PLUGIN_RC_KO; - else - { - ret = *r; - free (r); - } - return ret; - } - else - return PLUGIN_RC_KO; -} - -/* - * weechat_python_timer_handler: general timer handler for Python - */ - -int -weechat_python_timer_handler (t_weechat_plugin *plugin, - int argc, char **argv, - char *handler_args, void *handler_pointer) -{ - /* make C compiler happy */ - (void) argc; - (void) argv; - int *r; - int ret; - - r = (int *) weechat_python_exec (plugin, (t_plugin_script *)handler_pointer, - SCRIPT_EXEC_INT, - handler_args, NULL, NULL, NULL); - if (r == NULL) - ret = PLUGIN_RC_KO; - else - { - ret = *r; - free (r); - } - return ret; -} - -/* - * weechat_python_keyboard_handler: general keyboard handler for Python - */ - -int -weechat_python_keyboard_handler (t_weechat_plugin *plugin, - int argc, char **argv, - char *handler_args, void *handler_pointer) -{ - int *r; - int ret; - - if (argc >= 3) - { - r = (int *) weechat_python_exec (plugin, (t_plugin_script *)handler_pointer, - SCRIPT_EXEC_INT, - handler_args, argv[0], argv[1], argv[2]); - if (r == NULL) - ret = PLUGIN_RC_KO; - else - { - ret = *r; - free (r); - } - return ret; - } - else - return PLUGIN_RC_KO; -} - -/* - * weechat_python_event_handler: general event handler for Python - */ - -int -weechat_python_event_handler (t_weechat_plugin *plugin, - int argc, char **argv, - char *handler_args, void *handler_pointer) -{ - int *r; - int ret; - - if (argc >= 1) - { - r = (int *) weechat_python_exec (plugin, (t_plugin_script *)handler_pointer, - SCRIPT_EXEC_INT, - handler_args, - argv[0], - (argc >= 2) ? argv[1] : NULL, - (argc >= 3) ? argv[2] : NULL); - if (r == NULL) - ret = PLUGIN_RC_KO; - else - { - ret = *r; - free (r); - } - return ret; - } - else - return PLUGIN_RC_KO; -} - -/* - * weechat_python_modifier: general modifier for Python - */ - -char * -weechat_python_modifier (t_weechat_plugin *plugin, - int argc, char **argv, - char *modifier_args, void *modifier_pointer) -{ - if (argc >= 2) - return (char *) weechat_python_exec (plugin, (t_plugin_script *)modifier_pointer, - SCRIPT_EXEC_STRING, - modifier_args, argv[0], argv[1], NULL); - else - return NULL; -} - -/* - * weechat_python_register: startup function for all WeeChat Python scripts - */ - -static PyObject * -weechat_python_register (PyObject *self, PyObject *args) -{ - char *name, *version, *shutdown_func, *description, *charset; - - /* make C compiler happy */ - (void) self; - - python_current_script = NULL; - - name = NULL; - version = NULL; - shutdown_func = NULL; - description = NULL; - charset = NULL; - - if (!PyArg_ParseTuple (args, "ssss|s", &name, &version, &shutdown_func, - &description, &charset)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"register\" function"); - return Py_BuildValue ("i", 0); - } - - if (weechat_script_search (python_plugin, &python_scripts, name)) - { - /* error: another scripts already exists with this name! */ - python_plugin->print_server (python_plugin, - "Python error: unable to register " - "\"%s\" script (another script " - "already exists with this name)", - name); - return Py_BuildValue ("i", 0); - } - - /* 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, charset); - if (python_current_script) - { - python_plugin->print_server (python_plugin, - "Python: registered script \"%s\", " - "version %s (%s)", - name, version, description); - } - else - return Py_BuildValue ("i", 0); - - return Py_BuildValue ("i", 1); -} - -/* - * weechat_python_set_charset: set script charset - */ - -static PyObject * -weechat_python_set_charset (PyObject *self, PyObject *args) -{ - char *charset; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to set charset, " - "script not initialized"); - Py_INCREF(Py_None); - return Py_None; - } - - charset = NULL; - - if (!PyArg_ParseTuple (args, "s", &charset)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"set_charset\" function"); - Py_INCREF(Py_None); - return Py_None; - } - - if (charset) - weechat_script_set_charset (python_plugin, - python_current_script, - charset); - - return Py_BuildValue ("i", 1); -} - -/* - * weechat_python_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 C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to print message, " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - message = NULL; - channel_name = NULL; - server_name = NULL; - - if (!PyArg_ParseTuple (args, "s|ss", &message, &channel_name, &server_name)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"print\" function"); - return Py_BuildValue ("i", 0); - } - - python_plugin->print (python_plugin, - server_name, channel_name, - "%s", message); - - return Py_BuildValue ("i", 1); -} - -/* - * weechat_python_print_server: print message into a buffer server - */ - -static PyObject * -weechat_python_print_server (PyObject *self, PyObject *args) -{ - char *message; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to print message (server), " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - message = NULL; - - if (!PyArg_ParseTuple (args, "s", &message)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"print_server\" function"); - return Py_BuildValue ("i", 0); - } - - python_plugin->print_server (python_plugin, "%s", message); - - return Py_BuildValue ("i", 1); -} - -/* - * weechat_python_print_infobar: print message to infobar - */ - -static PyObject * -weechat_python_print_infobar (PyObject *self, PyObject *args) -{ - int delay; - char *message; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to print infobar message, " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - delay = 1; - message = NULL; - - if (!PyArg_ParseTuple (args, "is", &delay, &message)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"print_infobar\" function"); - return Py_BuildValue ("i", 0); - } - - python_plugin->print_infobar (python_plugin, delay, "%s", message); - - return Py_BuildValue ("i", 1); -} - -/* - * weechat_python_remove_infobar: remove message(s) from infobar - */ - -static PyObject * -weechat_python_remove_infobar (PyObject *self, PyObject *args) -{ - int how_many; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to remove infobar message(s), " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - how_many = 0; - - if (!PyArg_ParseTuple (args, "|i", &how_many)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"infobar_remove\" function"); - return Py_BuildValue ("i", 0); - } - - python_plugin->infobar_remove (python_plugin, how_many); - - return Py_BuildValue ("i", 1); -} - -/* - * weechat_python_log: log message in server/channel (current or specified ones) - */ - -static PyObject * -weechat_python_log (PyObject *self, PyObject *args) -{ - char *message, *channel_name, *server_name; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to log message, " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - message = NULL; - channel_name = NULL; - server_name = NULL; - - if (!PyArg_ParseTuple (args, "s|ss", &message, &channel_name, &server_name)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"log\" function"); - return Py_BuildValue ("i", 0); - } - - python_plugin->log (python_plugin, - server_name, channel_name, - "%s", message); - - return Py_BuildValue ("i", 1); -} - -/* - * weechat_python_command: send command to server - */ - -static PyObject * -weechat_python_command (PyObject *self, PyObject *args) -{ - char *command, *channel_name, *server_name; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to run command, " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - command = NULL; - channel_name = NULL; - server_name = NULL; - - if (!PyArg_ParseTuple (args, "s|ss", &command, &channel_name, &server_name)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"command\" function"); - return Py_BuildValue ("i", 0); - } - - python_plugin->exec_command (python_plugin, - server_name, channel_name, - command); - - return Py_BuildValue ("i", 1); -} - -/* - * weechat_python_add_message_handler: add handler for messages - */ - -static PyObject * -weechat_python_add_message_handler (PyObject *self, PyObject *args) -{ - char *irc_command, *function; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to add message handler, " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - irc_command = NULL; - function = NULL; - - if (!PyArg_ParseTuple (args, "ss", &irc_command, &function)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"add_message_handler\" function"); - return Py_BuildValue ("i", 0); - } - - if (python_plugin->msg_handler_add (python_plugin, irc_command, - weechat_python_cmd_msg_handler, - function, - (void *)python_current_script)) - return Py_BuildValue ("i", 1); - - return Py_BuildValue ("i", 0); -} - -/* - * weechat_python_add_command_handler: define/redefines commands - */ - -static PyObject * -weechat_python_add_command_handler (PyObject *self, PyObject *args) -{ - char *command, *function, *description, *arguments, *arguments_description; - char *completion_template; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to add command handler, " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - command = NULL; - function = NULL; - description = NULL; - arguments = NULL; - arguments_description = NULL; - completion_template = NULL; - - if (!PyArg_ParseTuple (args, "ss|ssss", &command, &function, - &description, &arguments, &arguments_description, - &completion_template)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"add_command_handler\" function"); - return Py_BuildValue ("i", 0); - } - - if (python_plugin->cmd_handler_add (python_plugin, - command, - description, - arguments, - arguments_description, - completion_template, - weechat_python_cmd_msg_handler, - function, - (void *)python_current_script)) - return Py_BuildValue ("i", 1); - - return Py_BuildValue ("i", 0); -} - -/* - * weechat_python_add_timer_handler: add a timer handler - */ - -static PyObject * -weechat_python_add_timer_handler (PyObject *self, PyObject *args) -{ - int interval; - char *function; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to add timer handler, " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - interval = 10; - function = NULL; - - if (!PyArg_ParseTuple (args, "is", &interval, &function)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"add_timer_handler\" function"); - return Py_BuildValue ("i", 0); - } - - if (python_plugin->timer_handler_add (python_plugin, interval, - weechat_python_timer_handler, - function, - (void *)python_current_script)) - return Py_BuildValue ("i", 1); - - return Py_BuildValue ("i", 0); -} - -/* - * weechat_python_add_keyboard_handler: add a keyboard handler - */ - -static PyObject * -weechat_python_add_keyboard_handler (PyObject *self, PyObject *args) -{ - char *function; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to add keyboard handler, " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - function = NULL; - - if (!PyArg_ParseTuple (args, "s", &function)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"add_keyboard_handler\" function"); - return Py_BuildValue ("i", 0); - } - - if (python_plugin->keyboard_handler_add (python_plugin, - weechat_python_keyboard_handler, - function, - (void *)python_current_script)) - return Py_BuildValue ("i", 1); - - return Py_BuildValue ("i", 0); -} - -/* - * weechat_python_add_event_handler: add handler for events - */ - -static PyObject * -weechat_python_add_event_handler (PyObject *self, PyObject *args) -{ - char *event, *function; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to add event handler, " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - event = NULL; - function = NULL; - - if (!PyArg_ParseTuple (args, "ss", &event, &function)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"add_event_handler\" function"); - return Py_BuildValue ("i", 0); - } - - if (python_plugin->event_handler_add (python_plugin, event, - weechat_python_event_handler, - function, - (void *)python_current_script)) - return Py_BuildValue ("i", 1); - - return Py_BuildValue ("i", 0); -} - -/* - * weechat_python_remove_handler: remove a handler - */ - -static PyObject * -weechat_python_remove_handler (PyObject *self, PyObject *args) -{ - char *command, *function; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to remove handler, " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - command = NULL; - function = NULL; - - if (!PyArg_ParseTuple (args, "ss", &command, &function)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"remove_handler\" function"); - return Py_BuildValue ("i", 0); - } - - weechat_script_remove_handler (python_plugin, python_current_script, - command, function); - - return Py_BuildValue ("i", 1); -} - -/* - * weechat_python_remove_timer_handler: remove a timer handler - */ - -static PyObject * -weechat_python_remove_timer_handler (PyObject *self, PyObject *args) -{ - char *function; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to remove timer handler, " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - function = NULL; - - if (!PyArg_ParseTuple (args, "s", &function)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"remove_timer_handler\" function"); - return Py_BuildValue ("i", 0); - } - - weechat_script_remove_timer_handler (python_plugin, python_current_script, - function); - - return Py_BuildValue ("i", 1); -} - -/* - * weechat_python_remove_keyboard_handler: remove a keyboard handler - */ - -static PyObject * -weechat_python_remove_keyboard_handler (PyObject *self, PyObject *args) -{ - char *function; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to remove keyboard handler, " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - function = NULL; - - if (!PyArg_ParseTuple (args, "s", &function)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"remove_keyboard_handler\" function"); - return Py_BuildValue ("i", 0); - } - - weechat_script_remove_keyboard_handler (python_plugin, python_current_script, - function); - - return Py_BuildValue ("i", 1); -} - -/* - * weechat_python_remove_event_handler: remove an event handler - */ - -static PyObject * -weechat_python_remove_event_handler (PyObject *self, PyObject *args) -{ - char *function; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to remove event handler, " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - function = NULL; - - if (!PyArg_ParseTuple (args, "s", &function)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"remove_event_handler\" function"); - return Py_BuildValue ("i", 0); - } - - weechat_script_remove_event_handler (python_plugin, python_current_script, - function); - - return Py_BuildValue ("i", 1); -} - -/* - * weechat_python_add_modifier: add a modifier - */ - -static PyObject * -weechat_python_add_modifier (PyObject *self, PyObject *args) -{ - char *type, *command, *function; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to add modifier, " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - type = NULL; - command = NULL; - function = NULL; - - if (!PyArg_ParseTuple (args, "sss", &type, &command, &function)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"add_modifier\" function"); - return Py_BuildValue ("i", 0); - } - - if (python_plugin->modifier_add (python_plugin, type, command, - weechat_python_modifier, - function, - (void *)python_current_script)) - return Py_BuildValue ("i", 1); - - return Py_BuildValue ("i", 0); -} - -/* - * weechat_python_remove_modifier: remove a modifier - */ - -static PyObject * -weechat_python_remove_modifier (PyObject *self, PyObject *args) -{ - char *type, *command, *function; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to remove modifier, " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - type = NULL; - command = NULL; - function = NULL; - - if (!PyArg_ParseTuple (args, "sss", &type, &command, &function)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"remove_modifier\" function"); - return Py_BuildValue ("i", 0); - } - - weechat_script_remove_modifier (python_plugin, python_current_script, - type, command, function); - - return Py_BuildValue ("i", 1); -} - -/* - * weechat_python_get_info: get various infos - */ - -static PyObject * -weechat_python_get_info (PyObject *self, PyObject *args) -{ - char *arg, *server_name, *info; - PyObject *object; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to get info, " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - arg = NULL; - server_name = NULL; - - if (!PyArg_ParseTuple (args, "s|s", &arg, &server_name)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"get_info\" function"); - return Py_BuildValue ("i", 0); - } - - if (arg) - { - info = python_plugin->get_info (python_plugin, arg, server_name); - - if (info) - { - object = Py_BuildValue ("s", info); - free (info); - return object; - } - } - - return Py_BuildValue ("s", ""); -} - -/* - * weechat_python_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; - PyObject *dcc_list, *dcc_list_member, *key, *value; - char timebuffer1[64]; - char timebuffer2[64]; - struct in_addr in; - - /* make C compiler happy */ - (void) self; - (void) args; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to get DCC info, " - "script not initialized"); - Py_INCREF(Py_None); - return Py_None; - } - - dcc_list = PyList_New (0); - if (!dcc_list) - { - Py_INCREF(Py_None); - return Py_None; - } - - dcc_info = python_plugin->get_dcc_info (python_plugin); - if (!dcc_info) - return dcc_list; - - for(ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc) - { - strftime(timebuffer1, sizeof(timebuffer1), "%F %T", - localtime(&ptr_dcc->start_time)); - strftime(timebuffer2, sizeof(timebuffer2), "%F %T", - localtime(&ptr_dcc->start_transfer)); - in.s_addr = htonl(ptr_dcc->addr); - - dcc_list_member= PyDict_New(); - - if (dcc_list_member) - { - key = Py_BuildValue("s", "server"); - value = Py_BuildValue("s", ptr_dcc->server); - PyDict_SetItem(dcc_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "channel"); - value = Py_BuildValue("s", ptr_dcc->channel); - PyDict_SetItem(dcc_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "type"); - value = Py_BuildValue("i", ptr_dcc->type); - PyDict_SetItem(dcc_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "status"); - value = Py_BuildValue("i", ptr_dcc->status); - PyDict_SetItem(dcc_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "start_time"); - value = Py_BuildValue("s", timebuffer1); - PyDict_SetItem(dcc_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "start_transfer"); - value = Py_BuildValue("s", timebuffer2); - PyDict_SetItem(dcc_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "address"); - value = Py_BuildValue("s", inet_ntoa(in)); - PyDict_SetItem(dcc_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "port"); - value = Py_BuildValue("i", ptr_dcc->port); - PyDict_SetItem(dcc_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "nick"); - value = Py_BuildValue("s", ptr_dcc->nick); - PyDict_SetItem(dcc_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "remote_file"); - value = Py_BuildValue("s", ptr_dcc->filename); - PyDict_SetItem(dcc_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "local_file"); - value = Py_BuildValue("s", ptr_dcc->local_filename); - PyDict_SetItem(dcc_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "filename_suffix"); - value = Py_BuildValue("i", ptr_dcc->filename_suffix); - PyDict_SetItem(dcc_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "size"); - value = Py_BuildValue("k", ptr_dcc->size); - PyDict_SetItem(dcc_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "pos"); - value = Py_BuildValue("k", ptr_dcc->pos); - PyDict_SetItem(dcc_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "start_resume"); - value = Py_BuildValue("k", ptr_dcc->start_resume); - PyDict_SetItem(dcc_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "cps"); - value = Py_BuildValue("k", ptr_dcc->bytes_per_sec); - PyDict_SetItem(dcc_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - PyList_Append(dcc_list, dcc_list_member); - Py_DECREF (dcc_list_member); - } - } - - python_plugin->free_dcc_info (python_plugin, dcc_info); - - return dcc_list; -} - -/* - * weechat_python_get_config: get value of a WeeChat config option - */ - -static PyObject * -weechat_python_get_config (PyObject *self, PyObject *args) -{ - char *option, *return_value; - PyObject *python_return_value; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to get config option, " - "script not initialized"); - Py_INCREF(Py_None); - return Py_None; - } - - option = NULL; - - if (!PyArg_ParseTuple (args, "s", &option)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"get_config\" function"); - Py_INCREF(Py_None); - return Py_None; - } - - if (option) - { - return_value = python_plugin->get_config (python_plugin, option); - - if (return_value) - { - python_return_value = Py_BuildValue ("s", return_value); - free (return_value); - return python_return_value; - } - } - - return Py_BuildValue ("s", ""); -} - -/* - * weechat_python_set_config: set value of a WeeChat config option - */ - -static PyObject * -weechat_python_set_config (PyObject *self, PyObject *args) -{ - char *option, *value; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to set config option, " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - option = NULL; - value = NULL; - - if (!PyArg_ParseTuple (args, "ss", &option, &value)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"set_config\" function"); - return Py_BuildValue ("i", 0); - } - - if (option && value) - { - if (python_plugin->set_config (python_plugin, option, value)) - return Py_BuildValue ("i", 1); - } - - return Py_BuildValue ("i", 0); -} - -/* - * weechat_python_get_plugin_config: get value of a plugin config option - */ - -static PyObject * -weechat_python_get_plugin_config (PyObject *self, PyObject *args) -{ - char *option, *return_value; - PyObject *python_return_value; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to get plugin config option, " - "script not initialized"); - Py_INCREF(Py_None); - return Py_None; - } - - option = NULL; - - if (!PyArg_ParseTuple (args, "s", &option)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"get_plugin_config\" function"); - Py_INCREF(Py_None); - return Py_None; - } - - if (option) - { - return_value = weechat_script_get_plugin_config (python_plugin, - python_current_script, - option); - - if (return_value) - { - python_return_value = Py_BuildValue ("s", return_value); - free (return_value); - return python_return_value; - } - } - - return Py_BuildValue ("s", ""); -} - -/* - * weechat_python_set_plugin_config: set value of a plugin config option - */ - -static PyObject * -weechat_python_set_plugin_config (PyObject *self, PyObject *args) -{ - char *option, *value; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to set plugin config option, " - "script not initialized"); - return Py_BuildValue ("i", 0); - } - - option = NULL; - value = NULL; - - if (!PyArg_ParseTuple (args, "ss", &option, &value)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"set_plugin_config\" function"); - return Py_BuildValue ("i", 0); - } - - if (option && value) - { - if (weechat_script_set_plugin_config (python_plugin, - python_current_script, - option, value)) - return Py_BuildValue ("i", 1); - } - - return Py_BuildValue ("i", 0); -} - -/* - * weechat_python_get_server_info: get infos about servers - */ - -static PyObject * -weechat_python_get_server_info (PyObject *self, PyObject *args) -{ - t_plugin_server_info *server_info, *ptr_server; - PyObject *server_hash, *server_hash_member, *key, *value; - char timebuffer[64]; - - /* make C compiler happy */ - (void) self; - (void) args; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to get server infos, " - "script not initialized"); - Py_INCREF(Py_None); - return Py_None; - } - - server_hash = PyDict_New (); - if (!server_hash) - { - Py_INCREF(Py_None); - return Py_None; - } - - server_info = python_plugin->get_server_info (python_plugin); - if (!server_info) - return server_hash; - - for(ptr_server = server_info; ptr_server; ptr_server = ptr_server->next_server) - { - strftime(timebuffer, sizeof(timebuffer), "%F %T", - localtime(&ptr_server->away_time)); - - server_hash_member = PyDict_New(); - - if (server_hash_member) - { - key = Py_BuildValue("s", "autoconnect"); - value = Py_BuildValue("i", ptr_server->autoconnect); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "autoreconnect"); - value = Py_BuildValue("i", ptr_server->autoreconnect); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "autoreconnect_delay"); - value = Py_BuildValue("i", ptr_server->autoreconnect_delay); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "temp_server"); - value = Py_BuildValue("i", ptr_server->temp_server); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "address"); - value = Py_BuildValue("s", ptr_server->address); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "port"); - value = Py_BuildValue("i", ptr_server->port); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "ipv6"); - value = Py_BuildValue("i", ptr_server->ipv6); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "ssl"); - value = Py_BuildValue("i", ptr_server->ssl); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "password"); - value = Py_BuildValue("s", ptr_server->password); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "nick1"); - value = Py_BuildValue("s", ptr_server->nick1); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "nick2"); - value = Py_BuildValue("s", ptr_server->nick2); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "nick3"); - value = Py_BuildValue("s", ptr_server->nick3); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "username"); - value = Py_BuildValue("s", ptr_server->username); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "realname"); - value = Py_BuildValue("s", ptr_server->realname); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "command"); - value = Py_BuildValue("s", ptr_server->command); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "command_delay"); - value = Py_BuildValue("i", ptr_server->command_delay); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "autojoin"); - value = Py_BuildValue("s", ptr_server->autojoin); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "autorejoin"); - value = Py_BuildValue("i", ptr_server->autorejoin); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "notify_levels"); - value = Py_BuildValue("s", ptr_server->notify_levels); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "is_connected"); - value = Py_BuildValue("i", ptr_server->is_connected); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "ssl_connected"); - value = Py_BuildValue("i", ptr_server->ssl_connected); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "nick"); - value = Py_BuildValue("s", ptr_server->nick); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "nick_modes"); - value = Py_BuildValue("s", ptr_server->nick_modes); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "away_time"); - value = Py_BuildValue("s", timebuffer); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "lag"); - value = Py_BuildValue("i", ptr_server->lag); - PyDict_SetItem(server_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", ptr_server->name); - PyDict_SetItem(server_hash, key, server_hash_member); - Py_DECREF (key); - Py_DECREF (server_hash_member); - } - } - - python_plugin->free_server_info(python_plugin, server_info); - - return server_hash; -} - -/* - * weechat_python_get_channel_info: get infos about channels - */ - -static PyObject * -weechat_python_get_channel_info (PyObject *self, PyObject *args) -{ - t_plugin_channel_info *channel_info, *ptr_channel; - PyObject *channel_hash, *channel_hash_member, *key, *value; - char *server; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to get channel infos, " - "script not initialized"); - Py_INCREF(Py_None); - return Py_None; - } - - server = NULL; - if (!PyArg_ParseTuple (args, "s", &server)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"get_channel_info\" function"); - Py_INCREF(Py_None); - return Py_None; - } - - channel_hash = PyDict_New (); - if (!channel_hash) - { - Py_INCREF(Py_None); - return Py_None; - } - - channel_info = python_plugin->get_channel_info (python_plugin, server); - if (!channel_info) - return channel_hash; - - for(ptr_channel = channel_info; ptr_channel; ptr_channel = ptr_channel->next_channel) - { - channel_hash_member = PyDict_New(); - - if (channel_hash_member) - { - key = Py_BuildValue("s", "type"); - value = Py_BuildValue("i", ptr_channel->type); - PyDict_SetItem(channel_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "topic"); - value = Py_BuildValue("s", ptr_channel->topic); - PyDict_SetItem(channel_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "modes"); - value = Py_BuildValue("s", ptr_channel->modes); - PyDict_SetItem(channel_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "limit"); - value = Py_BuildValue("i", ptr_channel->limit); - PyDict_SetItem(channel_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "key"); - value = Py_BuildValue("s", ptr_channel->key); - PyDict_SetItem(channel_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "nicks_count"); - value = Py_BuildValue("i", ptr_channel->nicks_count); - PyDict_SetItem(channel_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", ptr_channel->name); - PyDict_SetItem(channel_hash, key, channel_hash_member); - Py_DECREF (key); - Py_DECREF (channel_hash_member); - } - } - - python_plugin->free_channel_info(python_plugin, channel_info); - - return channel_hash; -} - -/* - * weechat_python_get_nick_info: get infos about nicks - */ - -static PyObject * -weechat_python_get_nick_info (PyObject *self, PyObject *args) -{ - t_plugin_nick_info *nick_info, *ptr_nick; - PyObject *nick_hash, *nick_hash_member, *key, *value; - char *server, *channel; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to get nick infos, " - "script not initialized"); - Py_INCREF(Py_None); - return Py_None; - } - - server = NULL; - channel = NULL; - if (!PyArg_ParseTuple (args, "ss", &server, &channel)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"get_nick_info\" function"); - Py_INCREF(Py_None); - return Py_None; - } - - nick_hash = PyDict_New (); - if (!nick_hash) - { - Py_INCREF(Py_None); - return Py_None; - } - - nick_info = python_plugin->get_nick_info (python_plugin, server, channel); - if (!nick_info) - return nick_hash; - - for(ptr_nick = nick_info; ptr_nick; ptr_nick = ptr_nick->next_nick) - { - nick_hash_member = PyDict_New(); - - if (nick_hash_member) - { - key = Py_BuildValue("s", "flags"); - value = Py_BuildValue("i", ptr_nick->flags); - PyDict_SetItem(nick_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "host"); - value = Py_BuildValue("s", ptr_nick->host ? ptr_nick->host : ""); - PyDict_SetItem(nick_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", ptr_nick->nick); - PyDict_SetItem(nick_hash, key, nick_hash_member); - Py_DECREF (key); - Py_DECREF (nick_hash_member); - } - } - - python_plugin->free_nick_info(python_plugin, nick_info); - - return nick_hash; -} - -/* - * weechat_python_get_irc_color: - * get the numeric value which identify an irc color by its name - */ - -static PyObject * -weechat_python_get_irc_color (PyObject *self, PyObject *args) -{ - char *color; - - /* make C compiler happy */ - (void) self; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to get irc color, " - "script not initialized"); - return Py_BuildValue ("i", -1); - } - - color = NULL; - - if (!PyArg_ParseTuple (args, "s", &color)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"get_irc_color\" function"); - return Py_BuildValue ("i", -1); - } - - if (color) - return Py_BuildValue ("i", python_plugin->get_irc_color (python_plugin, color)); - - return Py_BuildValue ("i", -1); -} - -/* - * weechat_python_get_window_info: get infos about windows - */ - -static PyObject * -weechat_python_get_window_info (PyObject *self, PyObject *args) -{ - t_plugin_window_info *window_info, *ptr_win; - PyObject *window_list, *window_list_member, *key, *value; - - /* make C compiler happy */ - (void) self; - (void) args; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to get window info, " - "script not initialized"); - Py_INCREF(Py_None); - return Py_None; - } - - window_list = PyList_New (0); - if (!window_list) { - Py_INCREF(Py_None); - return Py_None; - } - - window_info = python_plugin->get_window_info (python_plugin); - if (!window_info) - return window_list; - - for (ptr_win = window_info; ptr_win; ptr_win = ptr_win->next_window) - { - window_list_member = PyDict_New(); - - if (window_list_member) - { - key = Py_BuildValue("s", "num_buffer"); - value = Py_BuildValue("i", ptr_win->num_buffer); - PyDict_SetItem(window_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "win_x"); - value = Py_BuildValue("i", ptr_win->win_x); - PyDict_SetItem(window_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "win_y"); - value = Py_BuildValue("i", ptr_win->win_y); - PyDict_SetItem(window_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "win_width"); - value = Py_BuildValue("i", ptr_win->win_width); - PyDict_SetItem(window_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "win_height"); - value = Py_BuildValue("i", ptr_win->win_height); - PyDict_SetItem(window_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "win_width_pct"); - value = Py_BuildValue("i", ptr_win->win_width_pct); - PyDict_SetItem(window_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "win_height_pct"); - value = Py_BuildValue("i", ptr_win->win_height_pct); - PyDict_SetItem(window_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - PyList_Append(window_list, window_list_member); - Py_DECREF (window_list_member); - } - } - - python_plugin->free_window_info(python_plugin, window_info); - - return window_list; -} - -/* - * weechat_python_get_buffer_info: get infos about buffers - */ - -static PyObject * -weechat_python_get_buffer_info (PyObject *self, PyObject *args) -{ - t_plugin_buffer_info *buffer_info, *ptr_buffer; - PyObject *buffer_hash, *buffer_hash_member, *key, *value; - - /* make C compiler happy */ - (void) self; - (void) args; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to get buffer info, " - "script not initialized"); - Py_INCREF(Py_None); - return Py_None; - } - - buffer_hash = PyDict_New (); - if (!buffer_hash) - { - Py_INCREF(Py_None); - return Py_None; - } - - buffer_info = python_plugin->get_buffer_info (python_plugin); - if (!buffer_info) - return buffer_hash; - - for(ptr_buffer = buffer_info; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - buffer_hash_member = PyDict_New(); - - if (buffer_hash_member) - { - - key = Py_BuildValue("s", "type"); - value = Py_BuildValue("i", ptr_buffer->type); - PyDict_SetItem(buffer_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "num_displayed"); - value = Py_BuildValue("i", ptr_buffer->num_displayed); - PyDict_SetItem(buffer_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "server"); - value = Py_BuildValue("s", ptr_buffer->server_name == NULL ? "" : ptr_buffer->server_name); - PyDict_SetItem(buffer_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "channel"); - value = Py_BuildValue("s", ptr_buffer->channel_name == NULL ? "" : ptr_buffer->channel_name); - PyDict_SetItem(buffer_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "notify_level"); - value = Py_BuildValue("i", ptr_buffer->notify_level); - PyDict_SetItem(buffer_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "log_filename"); - value = Py_BuildValue("s", ptr_buffer->log_filename == NULL ? "" : ptr_buffer->log_filename); - PyDict_SetItem(buffer_hash_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("i", ptr_buffer->number); - PyDict_SetItem(buffer_hash, key, buffer_hash_member); - Py_DECREF (key); - Py_DECREF (buffer_hash_member); - } - } - python_plugin->free_buffer_info(python_plugin, buffer_info); - - return buffer_hash; -} - -/* - * weechat_python_get_buffer_data: get buffer content - */ - -static PyObject * -weechat_python_get_buffer_data (PyObject *self, PyObject *args) -{ - t_plugin_buffer_line *buffer_data, *ptr_data; - PyObject *data_list, *data_list_member, *key, *value; - char *server, *channel; - char timebuffer[64]; - - /* make C compiler happy */ - (void) self; - (void) args; - - if (!python_current_script) - { - python_plugin->print_server (python_plugin, - "Python error: unable to get buffer data, " - "script not initialized"); - Py_INCREF(Py_None); - return Py_None; - } - - server = NULL; - channel = NULL; - - if (!PyArg_ParseTuple (args, "ss|", &server, &channel)) - { - python_plugin->print_server (python_plugin, - "Python error: wrong parameters for " - "\"get_buffer_data\" function"); - Py_INCREF(Py_None); - return Py_None; - } - - data_list = PyList_New (0); - if (!data_list) - { - Py_INCREF(Py_None); - return Py_None; - } - - buffer_data = python_plugin->get_buffer_data (python_plugin, server, channel); - if (!buffer_data) - return data_list; - - for(ptr_data = buffer_data; ptr_data; ptr_data = ptr_data->next_line) - { - data_list_member= PyDict_New(); - - if (data_list_member) - { - strftime(timebuffer, sizeof(timebuffer), "%F %T", - localtime(&ptr_data->date)); - - key = Py_BuildValue("s", "date"); - value = Py_BuildValue("s", timebuffer); - PyDict_SetItem(data_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "nick"); - value = Py_BuildValue("s", ptr_data->nick == NULL ? "" : ptr_data->nick); - PyDict_SetItem(data_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - key = Py_BuildValue("s", "data"); - value = Py_BuildValue("s", ptr_data->data == NULL ? "" : ptr_data->data); - PyDict_SetItem(data_list_member, key, value); - Py_DECREF (key); - Py_DECREF (value); - - PyList_Append(data_list, data_list_member); - Py_DECREF (data_list_member); - } - } - - python_plugin->free_buffer_data (python_plugin, buffer_data); - - return data_list; -} - -/* - * Python subroutines - */ - -static -PyMethodDef weechat_python_funcs[] = { - { "register", weechat_python_register, METH_VARARGS, "" }, - { "set_charset", weechat_python_set_charset, METH_VARARGS, "" }, - { "prnt", weechat_python_print, METH_VARARGS, "" }, - { "print_server", weechat_python_print_server, METH_VARARGS, "" }, - { "print_infobar", weechat_python_print_infobar, METH_VARARGS, "" }, - { "remove_infobar", weechat_python_remove_infobar, METH_VARARGS, "" }, - { "log", weechat_python_log, 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, "" }, - { "add_timer_handler", weechat_python_add_timer_handler, METH_VARARGS, "" }, - { "add_keyboard_handler", weechat_python_add_keyboard_handler, METH_VARARGS, "" }, - { "add_event_handler", weechat_python_add_event_handler, METH_VARARGS, "" }, - { "remove_handler", weechat_python_remove_handler, METH_VARARGS, "" }, - { "remove_timer_handler", weechat_python_remove_timer_handler, METH_VARARGS, "" }, - { "remove_keyboard_handler", weechat_python_remove_keyboard_handler, METH_VARARGS, "" }, - { "remove_event_handler", weechat_python_remove_event_handler, METH_VARARGS, "" }, - { "add_modifier", weechat_python_add_modifier, METH_VARARGS, "" }, - { "remove_modifier", weechat_python_remove_modifier, METH_VARARGS, "" }, - { "get_info", weechat_python_get_info, METH_VARARGS, "" }, - { "get_dcc_info", weechat_python_get_dcc_info, METH_VARARGS, "" }, - { "get_config", weechat_python_get_config, METH_VARARGS, "" }, - { "set_config", weechat_python_set_config, METH_VARARGS, "" }, - { "get_plugin_config", weechat_python_get_plugin_config, METH_VARARGS, "" }, - { "set_plugin_config", weechat_python_set_plugin_config, METH_VARARGS, "" }, - { "get_server_info", weechat_python_get_server_info, METH_VARARGS, "" }, - { "get_channel_info", weechat_python_get_channel_info, METH_VARARGS, "" }, - { "get_nick_info", weechat_python_get_nick_info, METH_VARARGS, "" }, - { "get_irc_color", weechat_python_get_irc_color, METH_VARARGS, "" }, - { "get_window_info", weechat_python_get_window_info, METH_VARARGS, "" }, - { "get_buffer_info", weechat_python_get_buffer_info, METH_VARARGS, "" }, - { "get_buffer_data", weechat_python_get_buffer_data, METH_VARARGS, "" }, - { NULL, NULL, 0, NULL } -}; - -/* - * weechat_python_output : redirection for stdout and stderr - */ - -static PyObject * -weechat_python_output (PyObject *self, PyObject *args) -{ - char *msg, *m, *p; - - /* make C compiler happy */ - (void) self; - - msg = NULL; - - if (!PyArg_ParseTuple (args, "s", &msg)) - { - if (strlen(python_buffer_output) > 0) - { - python_plugin->print_server (python_plugin, - "Python stdout/stderr : %s", - python_buffer_output); - python_buffer_output[0] = '\0'; - } - } - else - { - m = msg; - while ((p = strchr (m, '\n')) != NULL) - { - *p = '\0'; - if (strlen (m) + strlen (python_buffer_output) > 0) - python_plugin->print_server (python_plugin, - "Python stdout/stderr : %s%s", - python_buffer_output, m); - *p = '\n'; - python_buffer_output[0] = '\0'; - m = ++p; - } - - if (strlen(m) + strlen(python_buffer_output) > sizeof(python_buffer_output)) - { - python_plugin->print_server (python_plugin, - "Python stdout/stderr : %s%s", - python_buffer_output, m); - python_buffer_output[0] = '\0'; - } - else - strcat (python_buffer_output, m); - } - - Py_INCREF(Py_None); - return Py_None; -} - -/* - * Outputs subroutines - */ - -static -PyMethodDef weechat_python_output_funcs[] = { - { "write", weechat_python_output, METH_VARARGS, "" }, - { NULL, NULL, 0, NULL } -}; - -/* - * weechat_python_load: load a Python script - */ - -int -weechat_python_load (t_weechat_plugin *plugin, char *filename) -{ - char *argv[] = { "__weechat_plugin__" , NULL }; - FILE *fp; - PyThreadState *python_current_interpreter; - PyObject *weechat_module, *weechat_outputs, *weechat_dict; - PyObject *python_path, *path; - char *w_home, *p_home; - int len; - - plugin->print_server (plugin, "Loading Python script \"%s\"", filename); - - if ((fp = fopen (filename, "r")) == NULL) - { - plugin->print_server (plugin, "Python error: script \"%s\" not found", - filename); - return 0; - } - - python_current_script = NULL; - - /* PyEval_AcquireLock (); */ - python_current_interpreter = Py_NewInterpreter (); - PySys_SetArgv(1, argv); - - if (python_current_interpreter == NULL) - { - plugin->print_server (plugin, - "Python error: unable to create new sub-interpreter"); - fclose (fp); - /* PyEval_ReleaseLock (); */ - return 0; - } - - /* PyThreadState_Swap (python_current_interpreter); */ - - weechat_module = Py_InitModule ("weechat", weechat_python_funcs); - - if ( weechat_module == NULL) - { - plugin->print_server (plugin, - "Python error: unable to initialize WeeChat module"); - fclose (fp); - - Py_EndInterpreter (python_current_interpreter); - /* PyEval_ReleaseLock (); */ - - return 0; - } - - /* adding $weechat_dir/python in $PYTHONPATH */ - python_path = PySys_GetObject ("path"); - w_home = plugin->get_info (plugin, "weechat_dir", NULL); - if (w_home) - { - len = strlen (w_home) + 1 + strlen("python") + 1; - p_home = (char *)malloc (len * sizeof(char)); - if (p_home) - { - snprintf (p_home, len, "%s/python", w_home); - path = PyString_FromString (p_home); - if (path != NULL) - { - PyList_Insert (python_path, 0, path); - Py_DECREF (path); - } - free (p_home); - } - free (w_home); - } - - /* define some constants */ - weechat_dict = PyModule_GetDict(weechat_module); - PyDict_SetItemString(weechat_dict, "PLUGIN_RC_OK", PyInt_FromLong((long) PLUGIN_RC_OK)); - PyDict_SetItemString(weechat_dict, "PLUGIN_RC_KO", PyInt_FromLong((long) PLUGIN_RC_KO)); - PyDict_SetItemString(weechat_dict, "PLUGIN_RC_OK_IGNORE_WEECHAT", PyInt_FromLong((long) PLUGIN_RC_OK_IGNORE_WEECHAT)); - PyDict_SetItemString(weechat_dict, "PLUGIN_RC_OK_IGNORE_PLUGINS", PyInt_FromLong((long) PLUGIN_RC_OK_IGNORE_PLUGINS)); - PyDict_SetItemString(weechat_dict, "PLUGIN_RC_OK_IGNORE_ALL", PyInt_FromLong((long) PLUGIN_RC_OK_IGNORE_ALL)); - PyDict_SetItemString(weechat_dict, "PLUGIN_RC_OK_WITH_HIGHLIGHT", PyInt_FromLong((long) PLUGIN_RC_OK_WITH_HIGHLIGHT)); - - weechat_outputs = Py_InitModule("weechatOutputs", weechat_python_output_funcs); - if (weechat_outputs == NULL) - { - plugin->print_server (plugin, - "Python warning: unable to redirect stdout and stderr"); - } - else - { - if (PySys_SetObject("stdout", weechat_outputs) == -1) - plugin->print_server (plugin, - "Python warning: unable to redirect stdout"); - if (PySys_SetObject("stderr", weechat_outputs) == -1) - plugin->print_server (plugin, - "Python warning: unable to redirect stderr"); - } - - python_current_script_filename = filename; - - if (PyRun_SimpleFile (fp, filename) != 0) - { - plugin->print_server (plugin, - "Python error: unable to parse file \"%s\"", - filename); - fclose (fp); - - if (PyErr_Occurred ()) PyErr_Print (); - Py_EndInterpreter (python_current_interpreter); - /* PyEval_ReleaseLock (); */ - - /* if script was registered, removing from list */ - if (python_current_script != NULL) - weechat_script_remove (plugin, &python_scripts, python_current_script); - return 0; - } - - if (PyErr_Occurred ()) PyErr_Print (); - - fclose (fp); - - if (python_current_script == NULL) - { - plugin->print_server (plugin, - "Python error: function \"register\" not found " - "(or failed) in file \"%s\"", - filename); - - if (PyErr_Occurred ()) PyErr_Print (); - Py_EndInterpreter (python_current_interpreter); - /* PyEval_ReleaseLock (); */ - - return 0; - } - - python_current_script->interpreter = (PyThreadState *) python_current_interpreter; - /* PyEval_ReleaseThread (python_current_script->interpreter); */ - - return 1; -} - -/* - * weechat_python_unload: unload a Python script - */ - -void -weechat_python_unload (t_weechat_plugin *plugin, t_plugin_script *script) -{ - int *r; - - plugin->print_server (plugin, - "Unloading Python script \"%s\"", - script->name); - - if (script->shutdown_func && script->shutdown_func[0]) - { - r = (int *) weechat_python_exec (plugin, script, SCRIPT_EXEC_INT, - script->shutdown_func, NULL, NULL, NULL); - if (r) - free (r); - } - - PyThreadState_Swap (script->interpreter); - Py_EndInterpreter (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->print_server (plugin, - "Python script \"%s\" unloaded", - name); - } - else - { - plugin->print_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->print_server (plugin, - "Unloading all Python scripts"); - while (python_scripts) - weechat_python_unload (plugin, python_scripts); - - plugin->print_server (plugin, - "Python scripts unloaded"); -} - -/* - * weechat_python_cmd: /python command handler - */ - -int -weechat_python_cmd (t_weechat_plugin *plugin, - int cmd_argc, char **cmd_argv, - char *handler_args, void *handler_pointer) -{ - int argc, handler_found, modifier_found; - char **argv, *path_script; - t_plugin_script *ptr_script; - t_plugin_handler *ptr_handler; - t_plugin_modifier *ptr_modifier; - - /* make C compiler happy */ - (void) handler_args; - (void) handler_pointer; - - if (cmd_argc < 3) - return PLUGIN_RC_KO; - - if (cmd_argv[2]) - argv = plugin->explode_string (plugin, cmd_argv[2], " ", 0, &argc); - else - { - argv = NULL; - argc = 0; - } - - switch (argc) - { - case 0: - /* list registered Python scripts */ - plugin->print_server (plugin, ""); - plugin->print_server (plugin, "Registered Python scripts:"); - if (python_scripts) - { - for (ptr_script = python_scripts; - ptr_script; ptr_script = ptr_script->next_script) - { - plugin->print_server (plugin, " %s v%s%s%s", - ptr_script->name, - ptr_script->version, - (ptr_script->description[0]) ? " - " : "", - ptr_script->description); - } - } - else - plugin->print_server (plugin, " (none)"); - - /* list Python message handlers */ - plugin->print_server (plugin, ""); - plugin->print_server (plugin, "Python message handlers:"); - handler_found = 0; - for (ptr_handler = plugin->handlers; - ptr_handler; ptr_handler = ptr_handler->next_handler) - { - if ((ptr_handler->type == PLUGIN_HANDLER_MESSAGE) - && (ptr_handler->handler_args)) - { - handler_found = 1; - plugin->print_server (plugin, " IRC(%s) => Python(%s)", - ptr_handler->irc_command, - ptr_handler->handler_args); - } - } - if (!handler_found) - plugin->print_server (plugin, " (none)"); - - /* list Python command handlers */ - plugin->print_server (plugin, ""); - plugin->print_server (plugin, "Python command handlers:"); - handler_found = 0; - for (ptr_handler = plugin->handlers; - ptr_handler; ptr_handler = ptr_handler->next_handler) - { - if ((ptr_handler->type == PLUGIN_HANDLER_COMMAND) - && (ptr_handler->handler_args)) - { - handler_found = 1; - plugin->print_server (plugin, " /%s => Python(%s)", - ptr_handler->command, - ptr_handler->handler_args); - } - } - if (!handler_found) - plugin->print_server (plugin, " (none)"); - - /* list Python timer handlers */ - plugin->print_server (plugin, ""); - plugin->print_server (plugin, "Python timer handlers:"); - handler_found = 0; - for (ptr_handler = plugin->handlers; - ptr_handler; ptr_handler = ptr_handler->next_handler) - { - if ((ptr_handler->type == PLUGIN_HANDLER_TIMER) - && (ptr_handler->handler_args)) - { - handler_found = 1; - plugin->print_server (plugin, " %d seconds => Python(%s)", - ptr_handler->interval, - ptr_handler->handler_args); - } - } - if (!handler_found) - plugin->print_server (plugin, " (none)"); - - /* list Python keyboard handlers */ - plugin->print_server (plugin, ""); - plugin->print_server (plugin, "Python keyboard handlers:"); - handler_found = 0; - for (ptr_handler = plugin->handlers; - ptr_handler; ptr_handler = ptr_handler->next_handler) - { - if ((ptr_handler->type == PLUGIN_HANDLER_KEYBOARD) - && (ptr_handler->handler_args)) - { - handler_found = 1; - plugin->print_server (plugin, " Python(%s)", - ptr_handler->handler_args); - } - } - if (!handler_found) - plugin->print_server (plugin, " (none)"); - - /* list Python event handlers */ - plugin->print_server (plugin, ""); - plugin->print_server (plugin, "Python event handlers:"); - handler_found = 0; - for (ptr_handler = plugin->handlers; - ptr_handler; ptr_handler = ptr_handler->next_handler) - { - if ((ptr_handler->type == PLUGIN_HANDLER_EVENT) - && (ptr_handler->handler_args)) - { - handler_found = 1; - plugin->print_server (plugin, " %s => Python(%s)", - ptr_handler->event, - ptr_handler->handler_args); - } - } - if (!handler_found) - plugin->print_server (plugin, " (none)"); - - /* list Python modifiers */ - plugin->print_server (plugin, ""); - plugin->print_server (plugin, "Python modifiers:"); - modifier_found = 0; - for (ptr_modifier = plugin->modifiers; - ptr_modifier; ptr_modifier = ptr_modifier->next_modifier) - { - modifier_found = 1; - if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_IN) - plugin->print_server (plugin, " IRC(%s, %s) => Python(%s)", - ptr_modifier->command, - PLUGIN_MODIFIER_IRC_IN_STR, - ptr_modifier->modifier_args); - else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_USER) - plugin->print_server (plugin, " IRC(%s, %s) => Python(%s)", - ptr_modifier->command, - PLUGIN_MODIFIER_IRC_USER_STR, - ptr_modifier->modifier_args); - else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_OUT) - plugin->print_server (plugin, " IRC(%s, %s) => Python(%s)", - ptr_modifier->command, - PLUGIN_MODIFIER_IRC_OUT_STR, - ptr_modifier->modifier_args); - } - if (!modifier_found) - plugin->print_server (plugin, " (none)"); - break; - - case 1: - if (plugin->strcasecmp (plugin, argv[0], "autoload") == 0) - weechat_script_auto_load (plugin, "python", weechat_python_load); - else if (plugin->strcasecmp (plugin, argv[0], "reload") == 0) - { - weechat_python_unload_all (plugin); - weechat_script_auto_load (plugin, "python", weechat_python_load); - } - else if (plugin->strcasecmp (plugin, argv[0], "unload") == 0) - weechat_python_unload_all (plugin); - break; - case 2: - if (plugin->strcasecmp (plugin, argv[0], "load") == 0) - { - /* load Python script */ - path_script = weechat_script_search_full_name (plugin, "python", argv[1]); - weechat_python_load (plugin, (path_script) ? path_script : argv[1]); - if (path_script) - free (path_script); - } - else if (plugin->strcasecmp (plugin, argv[0], "unload") == 0) - { - /* unload Python script */ - weechat_python_unload_name (plugin, argv[1]); - } - else - { - plugin->print_server (plugin, - "Python error: unknown option for " - "\"python\" command"); - } - break; - default: - plugin->print_server (plugin, - "Python error: wrong argument count for \"python\" command"); - } - - if (argv) - plugin->free_exploded_string (plugin, argv); - - return PLUGIN_RC_OK; -} - -/* - * weechat_plugin_init: initialize Python plugin - */ - -int -weechat_plugin_init (t_weechat_plugin *plugin) -{ - - python_plugin = plugin; - - plugin->print_server (plugin, "Loading Python module \"weechat\""); - - /* init stdout/stderr buffer */ - python_buffer_output[0] = '\0'; - - Py_Initialize (); - if (Py_IsInitialized () == 0) - { - plugin->print_server (plugin, - "Python error: unable to launch global interpreter"); - return PLUGIN_RC_KO; - } - - PyEval_InitThreads(); - /* python_mainThreadState = PyThreadState_Swap(NULL); */ - python_mainThreadState = PyEval_SaveThread(); - /* PyEval_ReleaseLock (); */ - - if (python_mainThreadState == NULL) - { - plugin->print_server (plugin, - "Python error: unable to get current interpreter state"); - return PLUGIN_RC_KO; - } - - plugin->cmd_handler_add (plugin, "python", - "list/load/unload Python scripts", - "[load filename] | [autoload] | [reload] | [unload [script]]", - "filename: Python script (file) to load\n" - "script: script name to unload\n\n" - "Without argument, /python command lists all loaded Python scripts.", - "load|autoload|reload|unload %f", - weechat_python_cmd, NULL, NULL); - - plugin->mkdir_home (plugin, "python"); - plugin->mkdir_home (plugin, "python/autoload"); - - script_init (weechat_python_plugin); - weechat_script_auto_load (plugin, "python", weechat_python_load); - - /* init ok */ - return PLUGIN_RC_OK; -} - -/* - * 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 */ - if (python_mainThreadState != NULL) - { - /* PyEval_AcquireLock (); */ - PyThreadState_Swap (python_mainThreadState); - /* PyEval_ReleaseLock (); */ - python_mainThreadState = NULL; - } - - Py_Finalize (); - if (Py_IsInitialized () != 0) - python_plugin->print_server (python_plugin, - "Python error: unable to free interpreter"); - - python_plugin->print_server (python_plugin, - "Python plugin ended"); -} diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c new file mode 100644 index 000000000..125bc573d --- /dev/null +++ b/src/plugins/scripts/python/weechat-python-api.c @@ -0,0 +1,2712 @@ +/* + * Copyright (c) 2003-2008 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* weechat-python-api.c: Python API functions */ + +#undef _ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "../../weechat-plugin.h" +#include "../script.h" +#include "../script-api.h" +#include "../script-callback.h" +#include "weechat-python.h" + + +#define PYTHON_RETURN_OK return Py_BuildValue ("i", 1); +#define PYTHON_RETURN_ERROR return Py_BuildValue ("i", 0); +#define PYTHON_RETURN_EMPTY \ + Py_INCREF(Py_None); \ + return Py_None; +#define PYTHON_RETURN_STRING(string) \ + if (string) \ + return Py_BuildValue ("s", string); \ + return Py_BuildValue ("s", ""); +#define PYTHON_RETURN_STRING_FREE(string) \ + if (string) \ + { \ + object = Py_BuildValue ("s", string); \ + free (string); \ + return object; \ + } \ + return Py_BuildValue ("s", ""); + + +/* + * weechat_python_api_register: startup function for all WeeChat Python scripts + */ + +static PyObject * +weechat_python_api_register (PyObject *self, PyObject *args) +{ + char *name, *author, *version, *license, *shutdown_func, *description; + char *charset; + + /* make C compiler happy */ + (void) self; + + python_current_script = NULL; + + name = NULL; + author = NULL; + version = NULL; + license = NULL; + shutdown_func = NULL; + description = NULL; + charset = NULL; + + if (!PyArg_ParseTuple (args, "ssssss|s", &name, &author, &version, + &license, &shutdown_func, &description, &charset)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("register"); + PYTHON_RETURN_ERROR; + } + + if (script_search (weechat_python_plugin, &python_scripts, name)) + { + /* error: another scripts already exists with this name! */ + weechat_printf (NULL, + weechat_gettext ("%s%s: unable to register script " + "\"%s\" (another script already " + "exists with this name)"), + weechat_prefix ("error"), "python", name); + PYTHON_RETURN_ERROR; + } + + /* register script */ + python_current_script = script_add (weechat_python_plugin, + &python_scripts, + (python_current_script_filename) ? + python_current_script_filename : "", + name, author, version, license, + shutdown_func, description, charset); + if (python_current_script) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: registered script \"%s\", " + "version %s (%s)"), + weechat_prefix ("info"), "python", + name, version, description); + } + else + PYTHON_RETURN_ERROR; + + PYTHON_RETURN_OK; +} + +/* + * weechat_python_api_charset_set: set script charset + */ + +static PyObject * +weechat_python_api_charset_set (PyObject *self, PyObject *args) +{ + char *charset; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("charset_set"); + PYTHON_RETURN_ERROR; + } + + charset = NULL; + + if (!PyArg_ParseTuple (args, "s", &charset)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("charset_set"); + PYTHON_RETURN_ERROR; + } + + script_api_charset_set (python_current_script, + charset); + + PYTHON_RETURN_OK; +} + +/* + * weechat_python_api_iconv_to_internal: convert string to internal WeeChat charset + */ + +static PyObject * +weechat_python_api_iconv_to_internal (PyObject *self, PyObject *args) +{ + char *charset, *string, *result; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("iconv_to_internal"); + PYTHON_RETURN_EMPTY; + } + + charset = NULL; + string = NULL; + + if (!PyArg_ParseTuple (args, "ss", &charset, &string)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("iconv_to_internal"); + PYTHON_RETURN_EMPTY; + } + + result = weechat_iconv_to_internal (charset, string); + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_iconv_from_internal: convert string from WeeChat internal + * charset to another one + */ + +static PyObject * +weechat_python_api_iconv_from_internal (PyObject *self, PyObject *args) +{ + char *charset, *string, *result; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("iconv_from_internal"); + PYTHON_RETURN_EMPTY; + } + + charset = NULL; + string = NULL; + + if (!PyArg_ParseTuple (args, "ss", &charset, &string)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("iconv_from_internal"); + PYTHON_RETURN_EMPTY; + } + + result = weechat_iconv_from_internal (charset, string); + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_mkdir_home: create a directory in WeeChat home + */ + +static PyObject * +weechat_python_api_mkdir_home (PyObject *self, PyObject *args) +{ + char *directory; + int mode; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("mkdir_home"); + PYTHON_RETURN_ERROR; + } + + directory = NULL; + mode = 0; + + if (!PyArg_ParseTuple (args, "si", &directory, &mode)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("mkdir_home"); + PYTHON_RETURN_ERROR; + } + + if (weechat_mkdir_home (directory, mode)) + PYTHON_RETURN_OK; + + PYTHON_RETURN_ERROR; +} + +/* + * weechat_python_api_mkdir: create a directory + */ + +static PyObject * +weechat_python_api_mkdir (PyObject *self, PyObject *args) +{ + char *directory; + int mode; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("mkdir"); + PYTHON_RETURN_ERROR; + } + + directory = NULL; + mode = 0; + + if (!PyArg_ParseTuple (args, "si", &directory, &mode)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("mkdir"); + PYTHON_RETURN_ERROR; + } + + if (weechat_mkdir (directory, mode)) + PYTHON_RETURN_OK; + + PYTHON_RETURN_ERROR; +} + +/* + * weechat_python_api_prefix: get a prefix, used for display + */ + +static PyObject * +weechat_python_api_prefix (PyObject *self, PyObject *args) +{ + char *prefix, *result; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("prefix"); + PYTHON_RETURN_EMPTY; + } + + prefix = NULL; + + if (!PyArg_ParseTuple (args, "s", &prefix)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("prefix"); + PYTHON_RETURN_EMPTY; + } + + result = weechat_prefix (prefix); + PYTHON_RETURN_STRING(result); +} + +/* + * weechat_python_api_color: get a color code, used for display + */ + +static PyObject * +weechat_python_api_color (PyObject *self, PyObject *args) +{ + char *color, *result; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("color"); + PYTHON_RETURN_EMPTY; + } + + color = NULL; + + if (!PyArg_ParseTuple (args, "s", &color)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("color"); + PYTHON_RETURN_EMPTY; + } + + result = weechat_prefix (color); + PYTHON_RETURN_STRING(result); +} + +/* + * weechat_python_api_prnt: print message into a buffer (current or specified one) + */ + +static PyObject * +weechat_python_api_prnt (PyObject *self, PyObject *args) +{ + char *buffer, *message; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("prnt"); + PYTHON_RETURN_ERROR; + } + + buffer = NULL; + message = NULL; + + if (!PyArg_ParseTuple (args, "ss", &buffer, &message)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("prnt"); + PYTHON_RETURN_ERROR; + } + + script_api_printf (weechat_python_plugin, python_current_script, + script_string_to_pointer (buffer), + "%s", message); + + PYTHON_RETURN_OK; +} + +/* + * weechat_python_api_infobar_print: print message to infobar + */ + +static PyObject * +weechat_python_api_infobar_print (PyObject *self, PyObject *args) +{ + int delay; + char *color, *message; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print"); + PYTHON_RETURN_ERROR; + } + + delay = 1; + message = NULL; + + if (!PyArg_ParseTuple (args, "iss", &delay, &color, &message)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print"); + PYTHON_RETURN_ERROR; + } + + script_api_infobar_printf (weechat_python_plugin, python_current_script, + delay, color, "%s", message); + + PYTHON_RETURN_OK; +} + +/* + * weechat_python_api_infobar_remove: remove message(s) from infobar + */ + +static PyObject * +weechat_python_api_infobar_remove (PyObject *self, PyObject *args) +{ + int how_many; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print"); + PYTHON_RETURN_ERROR; + } + + how_many = 0; + + if (!PyArg_ParseTuple (args, "|i", &how_many)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print"); + PYTHON_RETURN_ERROR; + } + + weechat_infobar_remove (how_many); + + PYTHON_RETURN_OK; +} + +/* + * weechat_python_api_log_print: print message in WeeChat log file + */ + +static PyObject * +weechat_python_api_log_print (PyObject *self, PyObject *args) +{ + char *message; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("log_print"); + PYTHON_RETURN_ERROR; + } + + message = NULL; + + if (!PyArg_ParseTuple (args, "s", &message)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("log_print"); + PYTHON_RETURN_ERROR; + } + + script_api_log_printf (weechat_python_plugin, python_current_script, + "%s", message); + + PYTHON_RETURN_OK; +} + +/* + * weechat_python_api_hook_command_cb: callback for command hooked + */ + +int +weechat_python_api_hook_command_cb (void *data, struct t_gui_buffer *buffer, + int argc, char **argv, char **argv_eol) +{ + struct t_script_callback *script_callback; + char *python_argv[3], empty_arg[1] = { '\0' }; + int *r, ret; + + /* make C compiler happy */ + (void) argv; + + script_callback = (struct t_script_callback *)data; + + python_argv[0] = script_pointer_to_string (buffer); + python_argv[1] = (argc > 1) ? argv_eol[1] : empty_arg; + python_argv[2] = NULL; + + r = (int *) weechat_python_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + python_argv); + if (!r) + ret = WEECHAT_RC_ERROR; + else + { + ret = *r; + free (r); + } + if (python_argv[0]) + free (python_argv[0]); + + return ret; +} + +/* + * weechat_python_api_hook_command: hook a command + */ + +static PyObject * +weechat_python_api_hook_command (PyObject *self, PyObject *args) +{ + char *command, *description, *arguments, *args_description, *completion; + char *function, *result; + struct t_hook *new_hook; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_command"); + PYTHON_RETURN_EMPTY; + } + + command = NULL; + description = NULL; + arguments = NULL; + args_description = NULL; + completion = NULL; + function = NULL; + + if (!PyArg_ParseTuple (args, "ssssss", &command, &description, &arguments, + &args_description, &completion, &function)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_command"); + PYTHON_RETURN_ERROR; + } + + new_hook = script_api_hook_command (weechat_python_plugin, python_current_script, + command, + description, + arguments, + args_description, + completion, + &weechat_python_api_hook_command_cb, + function); + + result = script_pointer_to_string (new_hook); + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_hook_timer_cb: callback for timer hooked + */ + +int +weechat_python_api_hook_timer_cb (void *data) +{ + struct t_script_callback *script_callback; + char *python_argv[1] = { NULL }; + int *r, ret; + + script_callback = (struct t_script_callback *)data; + + r = (int *) weechat_python_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + python_argv); + if (!r) + ret = WEECHAT_RC_ERROR; + else + { + ret = *r; + free (r); + } + + return ret; +} + +/* + * weechat_python_api_hook_timer: hook a timer + */ + +static PyObject * +weechat_python_api_hook_timer (PyObject *self, PyObject *args) +{ + int interval, align_second, max_calls; + char *function, *result; + struct t_hook *new_hook; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_timer"); + PYTHON_RETURN_ERROR; + } + + interval = 10; + align_second = 0; + max_calls = 0; + function = NULL; + + if (!PyArg_ParseTuple (args, "iiis", &interval, &align_second, &max_calls, + &function)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_timer"); + PYTHON_RETURN_ERROR; + } + + new_hook = script_api_hook_timer (weechat_python_plugin, python_current_script, + interval, + align_second, + max_calls, + &weechat_python_api_hook_timer_cb, + function); + + result = script_pointer_to_string (new_hook); + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_hook_fd_cb: callback for fd hooked + */ + +int +weechat_python_api_hook_fd_cb (void *data) +{ + struct t_script_callback *script_callback; + char *python_argv[1] = { NULL }; + int *r, ret; + + script_callback = (struct t_script_callback *)data; + + r = (int *) weechat_python_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + python_argv); + if (!r) + ret = WEECHAT_RC_ERROR; + else + { + ret = *r; + free (r); + } + + return ret; +} + +/* + * weechat_python_api_hook_fd: hook a fd + */ + +static PyObject * +weechat_python_api_hook_fd (PyObject *self, PyObject *args) +{ + int fd, read, write, exception; + char *function, *result; + struct t_hook *new_hook; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_fd"); + PYTHON_RETURN_ERROR; + } + + fd = 0; + read = 0; + write = 0; + exception = 0; + function = NULL; + + if (!PyArg_ParseTuple (args, "iiiis", &fd, &read, &write, &exception, + &function)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_fd"); + PYTHON_RETURN_ERROR; + } + + new_hook = script_api_hook_fd (weechat_python_plugin, python_current_script, + fd, + read, + write, + exception, + &weechat_python_api_hook_fd_cb, + function); + + result = script_pointer_to_string (new_hook); + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_hook_print_cb: callback for print hooked + */ + +int +weechat_python_api_hook_print_cb (void *data, struct t_gui_buffer *buffer, + time_t date, char *prefix, char *message) +{ + struct t_script_callback *script_callback; + char *python_argv[5]; + static char timebuffer[64]; + int *r, ret; + + script_callback = (struct t_script_callback *)data; + + snprintf (timebuffer, sizeof (timebuffer) - 1, "%ld", date); + + python_argv[0] = script_pointer_to_string (buffer); + python_argv[1] = timebuffer; + python_argv[2] = prefix; + python_argv[3] = message; + python_argv[4] = NULL; + + r = (int *) weechat_python_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + python_argv); + if (!r) + ret = WEECHAT_RC_ERROR; + else + { + ret = *r; + free (r); + } + if (python_argv[0]) + free (python_argv[0]); + + return ret; +} + +/* + * weechat_python_api_hook_print: hook a print + */ + +static PyObject * +weechat_python_api_hook_print (PyObject *self, PyObject *args) +{ + char *buffer, *message, *function, *result; + int strip_colors; + struct t_hook *new_hook; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_print"); + PYTHON_RETURN_ERROR; + } + + buffer = NULL; + message = NULL; + strip_colors = 0; + function = NULL; + + if (!PyArg_ParseTuple (args, "ssis", &buffer, &message, &strip_colors, + &function)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_print"); + PYTHON_RETURN_ERROR; + } + + new_hook = script_api_hook_print (weechat_python_plugin, python_current_script, + script_string_to_pointer (buffer), + message, + strip_colors, + &weechat_python_api_hook_print_cb, + function); + + result = script_pointer_to_string(new_hook); + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_hook_signal_cb: callback for signal hooked + */ + +int +weechat_python_api_hook_signal_cb (void *data, char *signal, char *type_data, + void *signal_data) +{ + struct t_script_callback *script_callback; + char *python_argv[3]; + static char value_str[64]; + int *r, ret, free_needed; + + script_callback = (struct t_script_callback *)data; + + python_argv[0] = signal; + free_needed = 0; + if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) + { + python_argv[1] = (char *)signal_data; + } + else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0) + { + snprintf (value_str, sizeof (value_str) - 1, + "%d", *((int *)signal_data)); + python_argv[1] = value_str; + } + else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0) + { + python_argv[1] = script_pointer_to_string (signal_data); + free_needed = 1; + } + else + python_argv[1] = NULL; + python_argv[2] = NULL; + + r = (int *) weechat_python_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + python_argv); + if (!r) + ret = WEECHAT_RC_ERROR; + else + { + ret = *r; + free (r); + } + if (free_needed && python_argv[1]) + free (python_argv[1]); + + return ret; +} + +/* + * weechat_python_api_hook_signal: hook a signal + */ + +static PyObject * +weechat_python_api_hook_signal (PyObject *self, PyObject *args) +{ + char *signal, *function, *result; + struct t_hook *new_hook; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_signal"); + PYTHON_RETURN_ERROR; + } + + signal = NULL; + function = NULL; + + if (!PyArg_ParseTuple (args, "ss", &signal, &function)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_signal"); + PYTHON_RETURN_ERROR; + } + + new_hook = script_api_hook_signal (weechat_python_plugin, python_current_script, + signal, + &weechat_python_api_hook_signal_cb, + function); + + result = script_pointer_to_string (new_hook); + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_hook_signal_send: send a signal + */ + +static PyObject * +weechat_python_api_hook_signal_send (PyObject *self, PyObject *args) +{ + char *signal, *type_data, *signal_data, *error; + long number; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_signal_send"); + PYTHON_RETURN_ERROR; + } + + signal = NULL; + type_data = NULL; + signal_data = NULL; + + if (!PyArg_ParseTuple (args, "sss", &signal, &type_data, &signal_data)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_signal_send"); + PYTHON_RETURN_ERROR; + } + + if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) + { + weechat_hook_signal_send (signal, type_data, signal_data); + } + else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0) + { + error = NULL; + number = (int)strtol (signal_data, &error, 10); + if (error && (error[0] == '\0')) + { + weechat_hook_signal_send (signal, type_data, &number); + } + } + else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0) + { + weechat_hook_signal_send (signal, type_data, + script_string_to_pointer (signal_data)); + } + PYTHON_RETURN_OK; +} + +/* + * weechat_python_api_hook_config_cb: callback for config option hooked + */ + +int +weechat_python_api_hook_config_cb (void *data, char *type, char *option, + char *value) +{ + struct t_script_callback *script_callback; + char *python_argv[4]; + int *r, ret; + + script_callback = (struct t_script_callback *)data; + + python_argv[0] = type; + python_argv[1] = option; + python_argv[2] = value; + python_argv[3] = NULL; + + r = (int *) weechat_python_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + python_argv); + if (!r) + ret = WEECHAT_RC_ERROR; + else + { + ret = *r; + free (r); + } + + return ret; +} + +/* + * weechat_python_api_hook_config: hook a config option + */ + +static PyObject * +weechat_python_api_hook_config (PyObject *self, PyObject *args) +{ + char *type, *option, *function, *result; + struct t_hook *new_hook; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_config"); + PYTHON_RETURN_ERROR; + } + + type = NULL; + option = NULL; + function = NULL; + + if (!PyArg_ParseTuple (args, "sss", &type, &option, &function)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_config"); + PYTHON_RETURN_ERROR; + } + + new_hook = script_api_hook_config (weechat_python_plugin, python_current_script, + type, + option, + &weechat_python_api_hook_config_cb, + function); + + result = script_pointer_to_string(new_hook); + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_hook_completion_cb: callback for completion hooked + */ + +int +weechat_python_api_hook_completion_cb (void *data, char *completion, + struct t_gui_buffer *buffer, + struct t_weelist *list) +{ + struct t_script_callback *script_callback; + char *python_argv[4]; + int *r, ret; + + script_callback = (struct t_script_callback *)data; + + python_argv[0] = completion; + python_argv[1] = script_pointer_to_string (buffer); + python_argv[2] = script_pointer_to_string (list); + python_argv[3] = NULL; + + r = (int *) weechat_python_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + python_argv); + if (!r) + ret = WEECHAT_RC_ERROR; + else + { + ret = *r; + free (r); + } + if (python_argv[1]) + free (python_argv[1]); + if (python_argv[2]) + free (python_argv[2]); + + return ret; +} + +/* + * weechat_python_api_hook_completion: hook a completion + */ + +static PyObject * +weechat_python_api_hook_completion (PyObject *self, PyObject *args) +{ + char *completion, *function, *result; + struct t_hook *new_hook; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_completion"); + PYTHON_RETURN_ERROR; + } + + completion = NULL; + function = NULL; + + if (!PyArg_ParseTuple (args, "ss", &completion, &function)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_completion"); + PYTHON_RETURN_ERROR; + } + + new_hook = script_api_hook_completion (weechat_python_plugin, + python_current_script, + completion, + &weechat_python_api_hook_completion_cb, + function); + + result = script_pointer_to_string(new_hook); + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_unhook: unhook something + */ + +static PyObject * +weechat_python_api_unhook (PyObject *self, PyObject *args) +{ + char *hook; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("unhook"); + PYTHON_RETURN_ERROR; + } + + hook = NULL; + + if (!PyArg_ParseTuple (args, "s", &hook)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("unhook"); + PYTHON_RETURN_ERROR; + } + + if (script_api_unhook (weechat_python_plugin, python_current_script, + script_string_to_pointer (hook))) + PYTHON_RETURN_OK; + + PYTHON_RETURN_ERROR; +} + +/* + * weechat_python_api_unhook_all: unhook all for script + */ + +static PyObject * +weechat_python_api_unhook_all (PyObject *self, PyObject *args) +{ + /* make C compiler happy */ + (void) self; + (void) args; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("unhook_all"); + PYTHON_RETURN_ERROR; + } + + script_api_unhook_all (weechat_python_plugin, python_current_script); + + PYTHON_RETURN_OK; +} + +/* + * weechat_python_api_input_data_cb: callback for input data in a buffer + */ + +int +weechat_python_api_input_data_cb (void *data, struct t_gui_buffer *buffer, + char *input_data) +{ + struct t_script_callback *script_callback; + char *python_argv[3]; + int *r, ret; + + script_callback = (struct t_script_callback *)data; + + python_argv[0] = script_pointer_to_string (buffer); + python_argv[1] = input_data; + python_argv[2] = NULL; + + r = (int *) weechat_python_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + python_argv); + if (!r) + ret = WEECHAT_RC_ERROR; + else + { + ret = *r; + free (r); + } + if (python_argv[0]) + free (python_argv[0]); + + return ret; +} + +/* + * weechat_python_api_buffer_new: create a new buffer + */ + +static PyObject * +weechat_python_api_buffer_new (PyObject *self, PyObject *args) +{ + struct t_gui_buffer *new_buffer; + char *category, *name, *function, *result; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_new"); + PYTHON_RETURN_EMPTY; + } + + category = NULL; + name = NULL; + function = NULL; + + if (!PyArg_ParseTuple (args, "sss", &category, &name, &function)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_new"); + PYTHON_RETURN_EMPTY; + } + + new_buffer = script_api_buffer_new (weechat_python_plugin, + python_current_script, + category, name, + &weechat_python_api_input_data_cb, + function); + + result = script_pointer_to_string (new_buffer); + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_buffer_search: search a buffer + */ + +static PyObject * +weechat_python_api_buffer_search (PyObject *self, PyObject *args) +{ + char *category, *name; + struct t_gui_buffer *ptr_buffer; + char *result; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_search"); + PYTHON_RETURN_EMPTY; + } + + category = NULL; + name = NULL; + + if (!PyArg_ParseTuple (args, "ss", &category, &name)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_search"); + PYTHON_RETURN_EMPTY; + } + + ptr_buffer = weechat_buffer_search (category, name); + + result = script_pointer_to_string (ptr_buffer); + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_buffer_close: close a buffer + */ + +static PyObject * +weechat_python_api_buffer_close (PyObject *self, PyObject *args) +{ + char *buffer; + int switch_to_another; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_close"); + PYTHON_RETURN_ERROR; + } + + buffer = NULL; + switch_to_another = 0; + + if (!PyArg_ParseTuple (args, "si", &buffer, &switch_to_another)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_close"); + PYTHON_RETURN_ERROR; + } + + script_api_buffer_close (weechat_python_plugin, python_current_script, + script_string_to_pointer (buffer), + switch_to_another); + + PYTHON_RETURN_OK; +} + +/* + * weechat_python_api_buffer_get: get a buffer property + */ + +static PyObject * +weechat_python_api_buffer_get (PyObject *self, PyObject *args) +{ + char *buffer, *property, *value; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_get"); + PYTHON_RETURN_ERROR; + } + + buffer = NULL; + property = NULL; + + if (!PyArg_ParseTuple (args, "ss", &buffer, &property)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_get"); + PYTHON_RETURN_ERROR; + } + + value = weechat_buffer_get (script_string_to_pointer (buffer), property); + PYTHON_RETURN_STRING(value); +} + +/* + * weechat_python_api_buffer_set: set a buffer property + */ + +static PyObject * +weechat_python_api_buffer_set (PyObject *self, PyObject *args) +{ + char *buffer, *property, *value; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_set"); + PYTHON_RETURN_ERROR; + } + + buffer = NULL; + property = NULL; + value = NULL; + + if (!PyArg_ParseTuple (args, "sss", &buffer, &property, &value)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_set"); + PYTHON_RETURN_ERROR; + } + + weechat_buffer_set (script_string_to_pointer (buffer), property, value); + + PYTHON_RETURN_OK; +} + +/* + * weechat_python_api_nicklist_add_group: add a group in nicklist + */ + +static PyObject * +weechat_python_api_nicklist_add_group (PyObject *self, PyObject *args) +{ + struct t_gui_nick_group *new_group; + char *buffer, *parent_group, *name, *color, *result; + int visible; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("nicklist_add_group"); + PYTHON_RETURN_EMPTY; + } + + buffer = NULL; + parent_group = NULL; + name = NULL; + color = NULL; + visible = 0; + + if (!PyArg_ParseTuple (args, "ssssi", &buffer, &parent_group, &name, + &color, &visible)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("nicklist_add_group"); + PYTHON_RETURN_EMPTY; + } + + new_group = weechat_nicklist_add_group (script_string_to_pointer (buffer), + script_string_to_pointer (parent_group), + name, color, visible); + + result = script_pointer_to_string (new_group); + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_nicklist_search_group: search a group in nicklist + */ + +static PyObject * +weechat_python_api_nicklist_search_group (PyObject *self, PyObject *args) +{ + struct t_gui_nick_group *ptr_group; + char *buffer, *from_group, *name, *result; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("nicklist_search_group"); + PYTHON_RETURN_EMPTY; + } + + buffer = NULL; + from_group = NULL; + name = NULL; + + if (!PyArg_ParseTuple (args, "sss", &buffer, &from_group, &name)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("nicklist_search_group"); + PYTHON_RETURN_EMPTY; + } + + ptr_group = weechat_nicklist_search_group (script_string_to_pointer (buffer), + script_string_to_pointer (from_group), + name); + + result = script_pointer_to_string (ptr_group); + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_nicklist_add_nick: add a nick in nicklist + */ + +static PyObject * +weechat_python_api_nicklist_add_nick (PyObject *self, PyObject *args) +{ + struct t_gui_nick *new_nick; + char *buffer, *group, *name, *color, *str_prefix, *prefix_color, *result; + char prefix; + int visible; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("nicklist_add_nick"); + PYTHON_RETURN_EMPTY; + } + + buffer = NULL; + group = NULL; + name = NULL; + color = NULL; + str_prefix = NULL; + prefix_color = NULL; + visible = 0; + + if (!PyArg_ParseTuple (args, "ssssssi", &buffer, &group, &name, &color, + &str_prefix, &prefix_color, &visible)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("nicklist_add_nick"); + PYTHON_RETURN_EMPTY; + } + + if (str_prefix && str_prefix[0]) + prefix = str_prefix[0]; + else + prefix = ' '; + + new_nick = weechat_nicklist_add_nick (script_string_to_pointer (buffer), + script_string_to_pointer (group), + name, color, prefix, prefix_color, + visible); + + result = script_pointer_to_string (new_nick); + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_nicklist_search_nick: search a nick in nicklist + */ + +static PyObject * +weechat_python_api_nicklist_search_nick (PyObject *self, PyObject *args) +{ + struct t_gui_nick *ptr_nick; + char *buffer, *from_group, *name, *result; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("nicklist_search_nick"); + PYTHON_RETURN_EMPTY; + } + + buffer = NULL; + from_group = NULL; + name = NULL; + + if (!PyArg_ParseTuple (args, "sss", &buffer, &from_group, &name)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("nicklist_search_nick"); + PYTHON_RETURN_EMPTY; + } + + ptr_nick = weechat_nicklist_search_nick (script_string_to_pointer (buffer), + script_string_to_pointer (from_group), + name); + + result = script_pointer_to_string (ptr_nick); + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_nicklist_remove_group: remove a group from nicklist + */ + +static PyObject * +weechat_python_api_nicklist_remove_group (PyObject *self, PyObject *args) +{ + char *buffer, *group; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("nicklist_remove_group"); + PYTHON_RETURN_ERROR; + } + + buffer = NULL; + group = NULL; + + if (!PyArg_ParseTuple (args, "ss", &buffer, &group)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("nicklist_remove_group"); + PYTHON_RETURN_ERROR; + } + + weechat_nicklist_remove_group (script_string_to_pointer (buffer), + script_string_to_pointer (group)); + + PYTHON_RETURN_OK; +} + +/* + * weechat_python_api_nicklist_remove_nick: remove a nick from nicklist + */ + +static PyObject * +weechat_python_api_nicklist_remove_nick (PyObject *self, PyObject *args) +{ + char *buffer, *nick; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("nicklist_remove_nick"); + PYTHON_RETURN_ERROR; + } + + buffer = NULL; + nick = NULL; + + if (!PyArg_ParseTuple (args, "ss", &buffer, &nick)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("nicklist_remove_nick"); + PYTHON_RETURN_ERROR; + } + + weechat_nicklist_remove_group (script_string_to_pointer (buffer), + script_string_to_pointer (nick)); + + PYTHON_RETURN_OK; +} + +/* + * weechat_python_api_nicklist_remove_all: remove all groups/nicks from nicklist + */ + +static PyObject * +weechat_python_api_nicklist_remove_all (PyObject *self, PyObject *args) +{ + char *buffer; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("nicklist_remove_all"); + PYTHON_RETURN_ERROR; + } + + buffer = NULL; + + if (!PyArg_ParseTuple (args, "s", &buffer)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("nicklist_remove_all"); + PYTHON_RETURN_ERROR; + } + + weechat_nicklist_remove_all (script_string_to_pointer (buffer)); + + PYTHON_RETURN_OK; +} + +/* + * weechat_python_api_command: send command to server + */ + +static PyObject * +weechat_python_api_command (PyObject *self, PyObject *args) +{ + char *buffer, *command; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("command"); + PYTHON_RETURN_ERROR; + } + + buffer = NULL; + command = NULL; + + if (!PyArg_ParseTuple (args, "ss", &buffer, &command)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("command"); + PYTHON_RETURN_ERROR; + } + + script_api_command (weechat_python_plugin, python_current_script, + script_string_to_pointer (buffer), command); + + PYTHON_RETURN_OK; +} + +/* + * weechat_python_api_info_get: get info about WeeChat + */ + +static PyObject * +weechat_python_api_info_get (PyObject *self, PyObject *args) +{ + char *info, *value; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("info_get"); + PYTHON_RETURN_EMPTY; + } + + info = NULL; + + if (!PyArg_ParseTuple (args, "s", &info)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("info_get"); + PYTHON_RETURN_EMPTY; + } + + value = weechat_info_get (info); + PYTHON_RETURN_STRING(value); +} + +/* + * weechat_python_api_get_dcc_info: get infos about DCC + */ + +/* +static PyObject * +weechat_python_api_get_dcc_info (PyObject *self, PyObject *args) +{ + t_plugin_dcc_info *dcc_info, *ptr_dcc; + PyObject *dcc_list, *dcc_list_member, *key, *value; + char timebuffer1[64]; + char timebuffer2[64]; + struct in_addr in; + + // make C compiler happy + (void) self; + (void) args; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print"); + PYTHON_RETURN_EMPTY; + } + + dcc_list = PyList_New (0); + if (!dcc_list) + { + PYTHON_RETURN_EMPTY; + } + + dcc_info = python_plugin->get_dcc_info (python_plugin); + if (!dcc_info) + return dcc_list; + + for(ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc) + { + strftime(timebuffer1, sizeof(timebuffer1), "%F %T", + localtime(&ptr_dcc->start_time)); + strftime(timebuffer2, sizeof(timebuffer2), "%F %T", + localtime(&ptr_dcc->start_transfer)); + in.s_addr = htonl(ptr_dcc->addr); + + dcc_list_member= PyDict_New(); + + if (dcc_list_member) + { + key = Py_BuildValue("s", "server"); + value = Py_BuildValue("s", ptr_dcc->server); + PyDict_SetItem(dcc_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "channel"); + value = Py_BuildValue("s", ptr_dcc->channel); + PyDict_SetItem(dcc_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "type"); + value = Py_BuildValue("i", ptr_dcc->type); + PyDict_SetItem(dcc_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "status"); + value = Py_BuildValue("i", ptr_dcc->status); + PyDict_SetItem(dcc_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "start_time"); + value = Py_BuildValue("s", timebuffer1); + PyDict_SetItem(dcc_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "start_transfer"); + value = Py_BuildValue("s", timebuffer2); + PyDict_SetItem(dcc_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "address"); + value = Py_BuildValue("s", inet_ntoa(in)); + PyDict_SetItem(dcc_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "port"); + value = Py_BuildValue("i", ptr_dcc->port); + PyDict_SetItem(dcc_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "nick"); + value = Py_BuildValue("s", ptr_dcc->nick); + PyDict_SetItem(dcc_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "remote_file"); + value = Py_BuildValue("s", ptr_dcc->filename); + PyDict_SetItem(dcc_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "local_file"); + value = Py_BuildValue("s", ptr_dcc->local_filename); + PyDict_SetItem(dcc_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "filename_suffix"); + value = Py_BuildValue("i", ptr_dcc->filename_suffix); + PyDict_SetItem(dcc_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "size"); + value = Py_BuildValue("k", ptr_dcc->size); + PyDict_SetItem(dcc_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "pos"); + value = Py_BuildValue("k", ptr_dcc->pos); + PyDict_SetItem(dcc_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "start_resume"); + value = Py_BuildValue("k", ptr_dcc->start_resume); + PyDict_SetItem(dcc_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "cps"); + value = Py_BuildValue("k", ptr_dcc->bytes_per_sec); + PyDict_SetItem(dcc_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + PyList_Append(dcc_list, dcc_list_member); + Py_DECREF (dcc_list_member); + } + } + + python_plugin->free_dcc_info (python_plugin, dcc_info); + + return dcc_list; +} +*/ + +/* + * weechat_python_api_get_config: get value of a WeeChat config option + */ + +/* +static PyObject * +weechat_python_api_get_config (PyObject *self, PyObject *args) +{ + char *option, *return_value; + PyObject *python_return_value; + + // make C compiler happy + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print"); + PYTHON_RETURN_EMPTY; + } + + option = NULL; + + if (!PyArg_ParseTuple (args, "s", &option)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print"); + PYTHON_RETURN_EMPTY; + } + + if (option) + { + return_value = python_plugin->get_config (python_plugin, option); + + if (return_value) + { + python_return_value = Py_BuildValue ("s", return_value); + free (return_value); + return python_return_value; + } + } + + return Py_BuildValue ("s", ""); +} +*/ + +/* + * weechat_python_api_set_config: set value of a WeeChat config option + */ + +/* +static PyObject * +weechat_python_api_set_config (PyObject *self, PyObject *args) +{ + char *option, *value; + + // make C compiler happy + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print"); + PYTHON_RETURN_ERROR; + } + + option = NULL; + value = NULL; + + if (!PyArg_ParseTuple (args, "ss", &option, &value)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print"); + PYTHON_RETURN_ERROR; + } + + if (option && value) + { + if (python_plugin->set_config (python_plugin, option, value)) + PYTHON_RETURN_OK; + } + + PYTHON_RETURN_ERROR; +} +*/ + +/* + * weechat_python_api_get_plugin_config: get value of a plugin config option + */ + +/* +static PyObject * +weechat_python_api_get_plugin_config (PyObject *self, PyObject *args) +{ + char *option, *return_value; + PyObject *python_return_value; + + // make C compiler happy + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print"); + PYTHON_RETURN_EMPTY; + } + + option = NULL; + + if (!PyArg_ParseTuple (args, "s", &option)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print"); + PYTHON_RETURN_EMPTY; + } + + if (option) + { + return_value = weechat_script_get_plugin_config (python_plugin, + python_current_script, + option); + + if (return_value) + { + python_return_value = Py_BuildValue ("s", return_value); + free (return_value); + return python_return_value; + } + } + + return Py_BuildValue ("s", ""); +} +*/ + +/* + * weechat_python_api_set_plugin_config: set value of a plugin config option + */ + + /* +static PyObject * +weechat_python_api_set_plugin_config (PyObject *self, PyObject *args) +{ + char *option, *value; + + // make C compiler happy + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print"); + PYTHON_RETURN_ERROR; + } + + option = NULL; + value = NULL; + + if (!PyArg_ParseTuple (args, "ss", &option, &value)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print"); + PYTHON_RETURN_ERROR; + } + + if (option && value) + { + if (weechat_script_set_plugin_config (python_plugin, + python_current_script, + option, value)) + PYTHON_RETURN_OK; + } + + PYTHON_RETURN_ERROR; +} +*/ + +/* + * weechat_python_api_get_server_info: get infos about servers + */ + +/* +static PyObject * +weechat_python_api_get_server_info (PyObject *self, PyObject *args) +{ + t_plugin_server_info *server_info, *ptr_server; + PyObject *server_hash, *server_hash_member, *key, *value; + char timebuffer[64]; + + // make C compiler happy + (void) self; + (void) args; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print"); + PYTHON_RETURN_EMPTY; + } + + server_hash = PyDict_New (); + if (!server_hash) + { + PYTHON_RETURN_EMPTY; + } + + server_info = python_plugin->get_server_info (python_plugin); + if (!server_info) + return server_hash; + + for(ptr_server = server_info; ptr_server; ptr_server = ptr_server->next_server) + { + strftime(timebuffer, sizeof(timebuffer), "%F %T", + localtime(&ptr_server->away_time)); + + server_hash_member = PyDict_New(); + + if (server_hash_member) + { + key = Py_BuildValue("s", "autoconnect"); + value = Py_BuildValue("i", ptr_server->autoconnect); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "autoreconnect"); + value = Py_BuildValue("i", ptr_server->autoreconnect); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "autoreconnect_delay"); + value = Py_BuildValue("i", ptr_server->autoreconnect_delay); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "temp_server"); + value = Py_BuildValue("i", ptr_server->temp_server); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "address"); + value = Py_BuildValue("s", ptr_server->address); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "port"); + value = Py_BuildValue("i", ptr_server->port); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "ipv6"); + value = Py_BuildValue("i", ptr_server->ipv6); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "ssl"); + value = Py_BuildValue("i", ptr_server->ssl); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "password"); + value = Py_BuildValue("s", ptr_server->password); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "nick1"); + value = Py_BuildValue("s", ptr_server->nick1); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "nick2"); + value = Py_BuildValue("s", ptr_server->nick2); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "nick3"); + value = Py_BuildValue("s", ptr_server->nick3); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "username"); + value = Py_BuildValue("s", ptr_server->username); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "realname"); + value = Py_BuildValue("s", ptr_server->realname); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "command"); + value = Py_BuildValue("s", ptr_server->command); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "command_delay"); + value = Py_BuildValue("i", ptr_server->command_delay); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "autojoin"); + value = Py_BuildValue("s", ptr_server->autojoin); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "autorejoin"); + value = Py_BuildValue("i", ptr_server->autorejoin); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "notify_levels"); + value = Py_BuildValue("s", ptr_server->notify_levels); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "is_connected"); + value = Py_BuildValue("i", ptr_server->is_connected); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "ssl_connected"); + value = Py_BuildValue("i", ptr_server->ssl_connected); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "nick"); + value = Py_BuildValue("s", ptr_server->nick); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "nick_modes"); + value = Py_BuildValue("s", ptr_server->nick_modes); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "away_time"); + value = Py_BuildValue("s", timebuffer); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "lag"); + value = Py_BuildValue("i", ptr_server->lag); + PyDict_SetItem(server_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", ptr_server->name); + PyDict_SetItem(server_hash, key, server_hash_member); + Py_DECREF (key); + Py_DECREF (server_hash_member); + } + } + + python_plugin->free_server_info(python_plugin, server_info); + + return server_hash; +} +*/ + +/* + * weechat_python_api_get_channel_info: get infos about channels + */ + +/* +static PyObject * +weechat_python_api_get_channel_info (PyObject *self, PyObject *args) +{ + t_plugin_channel_info *channel_info, *ptr_channel; + PyObject *channel_hash, *channel_hash_member, *key, *value; + char *server; + + // make C compiler happy + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print"); + PYTHON_RETURN_EMPTY; + } + + server = NULL; + if (!PyArg_ParseTuple (args, "s", &server)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print"); + PYTHON_RETURN_EMPTY; + } + + channel_hash = PyDict_New (); + if (!channel_hash) + { + PYTHON_RETURN_EMPTY; + } + + channel_info = python_plugin->get_channel_info (python_plugin, server); + if (!channel_info) + return channel_hash; + + for(ptr_channel = channel_info; ptr_channel; ptr_channel = ptr_channel->next_channel) + { + channel_hash_member = PyDict_New(); + + if (channel_hash_member) + { + key = Py_BuildValue("s", "type"); + value = Py_BuildValue("i", ptr_channel->type); + PyDict_SetItem(channel_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "topic"); + value = Py_BuildValue("s", ptr_channel->topic); + PyDict_SetItem(channel_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "modes"); + value = Py_BuildValue("s", ptr_channel->modes); + PyDict_SetItem(channel_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "limit"); + value = Py_BuildValue("i", ptr_channel->limit); + PyDict_SetItem(channel_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "key"); + value = Py_BuildValue("s", ptr_channel->key); + PyDict_SetItem(channel_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "nicks_count"); + value = Py_BuildValue("i", ptr_channel->nicks_count); + PyDict_SetItem(channel_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", ptr_channel->name); + PyDict_SetItem(channel_hash, key, channel_hash_member); + Py_DECREF (key); + Py_DECREF (channel_hash_member); + } + } + + python_plugin->free_channel_info(python_plugin, channel_info); + + return channel_hash; +} +*/ + +/* + * weechat_python_api_get_nick_info: get infos about nicks + */ + +/* +static PyObject * +weechat_python_api_get_nick_info (PyObject *self, PyObject *args) +{ + t_plugin_nick_info *nick_info, *ptr_nick; + PyObject *nick_hash, *nick_hash_member, *key, *value; + char *server, *channel; + + // make C compiler happy + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print"); + PYTHON_RETURN_EMPTY; + } + + server = NULL; + channel = NULL; + if (!PyArg_ParseTuple (args, "ss", &server, &channel)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print"); + PYTHON_RETURN_EMPTY; + } + + nick_hash = PyDict_New (); + if (!nick_hash) + { + PYTHON_RETURN_EMPTY; + } + + nick_info = python_plugin->get_nick_info (python_plugin, server, channel); + if (!nick_info) + return nick_hash; + + for(ptr_nick = nick_info; ptr_nick; ptr_nick = ptr_nick->next_nick) + { + nick_hash_member = PyDict_New(); + + if (nick_hash_member) + { + key = Py_BuildValue("s", "flags"); + value = Py_BuildValue("i", ptr_nick->flags); + PyDict_SetItem(nick_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "host"); + value = Py_BuildValue("s", ptr_nick->host ? ptr_nick->host : ""); + PyDict_SetItem(nick_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", ptr_nick->nick); + PyDict_SetItem(nick_hash, key, nick_hash_member); + Py_DECREF (key); + Py_DECREF (nick_hash_member); + } + } + + python_plugin->free_nick_info(python_plugin, nick_info); + + return nick_hash; +} +*/ + +/* + * weechat_python_api_get_irc_color: get the numeric value which identify an + * irc color by its name + */ + +/* +static PyObject * +weechat_python_api_get_irc_color (PyObject *self, PyObject *args) +{ + char *color; + + // make C compiler happy + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print"); + return Py_BuildValue ("i", -1); + } + + color = NULL; + + if (!PyArg_ParseTuple (args, "s", &color)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print"); + return Py_BuildValue ("i", -1); + } + + if (color) + return Py_BuildValue ("i", python_plugin->get_irc_color (python_plugin, color)); + + return Py_BuildValue ("i", -1); +} +*/ + +/* + * weechat_python_api_get_window_info: get infos about windows + */ + +/* +static PyObject * +weechat_python_api_get_window_info (PyObject *self, PyObject *args) +{ + t_plugin_window_info *window_info, *ptr_win; + PyObject *window_list, *window_list_member, *key, *value; + + // make C compiler happy + (void) self; + (void) args; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print"); + PYTHON_RETURN_EMPTY; + } + + window_list = PyList_New (0); + if (!window_list) + { + PYTHON_RETURN_EMPTY; + } + + window_info = python_plugin->get_window_info (python_plugin); + if (!window_info) + return window_list; + + for (ptr_win = window_info; ptr_win; ptr_win = ptr_win->next_window) + { + window_list_member = PyDict_New(); + + if (window_list_member) + { + key = Py_BuildValue("s", "num_buffer"); + value = Py_BuildValue("i", ptr_win->num_buffer); + PyDict_SetItem(window_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "win_x"); + value = Py_BuildValue("i", ptr_win->win_x); + PyDict_SetItem(window_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "win_y"); + value = Py_BuildValue("i", ptr_win->win_y); + PyDict_SetItem(window_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "win_width"); + value = Py_BuildValue("i", ptr_win->win_width); + PyDict_SetItem(window_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "win_height"); + value = Py_BuildValue("i", ptr_win->win_height); + PyDict_SetItem(window_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "win_width_pct"); + value = Py_BuildValue("i", ptr_win->win_width_pct); + PyDict_SetItem(window_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "win_height_pct"); + value = Py_BuildValue("i", ptr_win->win_height_pct); + PyDict_SetItem(window_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + PyList_Append(window_list, window_list_member); + Py_DECREF (window_list_member); + } + } + + python_plugin->free_window_info(python_plugin, window_info); + + return window_list; +} +*/ + +/* + * weechat_python_api_get_buffer_info: get infos about buffers + */ + +/* +static PyObject * +weechat_python_api_get_buffer_info (PyObject *self, PyObject *args) +{ + t_plugin_buffer_info *buffer_info, *ptr_buffer; + PyObject *buffer_hash, *buffer_hash_member, *key, *value; + + // make C compiler happy + (void) self; + (void) args; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print"); + PYTHON_RETURN_EMPTY; + } + + buffer_hash = PyDict_New (); + if (!buffer_hash) + { + PYTHON_RETURN_EMPTY; + } + + buffer_info = python_plugin->get_buffer_info (python_plugin); + if (!buffer_info) + return buffer_hash; + + for(ptr_buffer = buffer_info; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + buffer_hash_member = PyDict_New(); + + if (buffer_hash_member) + { + + key = Py_BuildValue("s", "type"); + value = Py_BuildValue("i", ptr_buffer->type); + PyDict_SetItem(buffer_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "num_displayed"); + value = Py_BuildValue("i", ptr_buffer->num_displayed); + PyDict_SetItem(buffer_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "server"); + value = Py_BuildValue("s", ptr_buffer->server_name == NULL ? "" : ptr_buffer->server_name); + PyDict_SetItem(buffer_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "channel"); + value = Py_BuildValue("s", ptr_buffer->channel_name == NULL ? "" : ptr_buffer->channel_name); + PyDict_SetItem(buffer_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "notify_level"); + value = Py_BuildValue("i", ptr_buffer->notify_level); + PyDict_SetItem(buffer_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "log_filename"); + value = Py_BuildValue("s", ptr_buffer->log_filename == NULL ? "" : ptr_buffer->log_filename); + PyDict_SetItem(buffer_hash_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("i", ptr_buffer->number); + PyDict_SetItem(buffer_hash, key, buffer_hash_member); + Py_DECREF (key); + Py_DECREF (buffer_hash_member); + } + } + python_plugin->free_buffer_info(python_plugin, buffer_info); + + return buffer_hash; +} +*/ + +/* + * weechat_python_api_get_buffer_data: get buffer content + */ + +/* +static PyObject * +weechat_python_api_get_buffer_data (PyObject *self, PyObject *args) +{ + t_plugin_buffer_line *buffer_data, *ptr_data; + PyObject *data_list, *data_list_member, *key, *value; + char *server, *channel; + char timebuffer[64]; + + // make C compiler happy + (void) self; + (void) args; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print"); + PYTHON_RETURN_EMPTY; + } + + server = NULL; + channel = NULL; + + if (!PyArg_ParseTuple (args, "ss|", &server, &channel)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print"); + PYTHON_RETURN_EMPTY; + } + + data_list = PyList_New (0); + if (!data_list) + { + PYTHON_RETURN_EMPTY; + } + + buffer_data = python_plugin->get_buffer_data (python_plugin, server, channel); + if (!buffer_data) + return data_list; + + for(ptr_data = buffer_data; ptr_data; ptr_data = ptr_data->next_line) + { + data_list_member= PyDict_New(); + + if (data_list_member) + { + strftime(timebuffer, sizeof(timebuffer), "%F %T", + localtime(&ptr_data->date)); + + key = Py_BuildValue("s", "date"); + value = Py_BuildValue("s", timebuffer); + PyDict_SetItem(data_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "nick"); + value = Py_BuildValue("s", ptr_data->nick == NULL ? "" : ptr_data->nick); + PyDict_SetItem(data_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + key = Py_BuildValue("s", "data"); + value = Py_BuildValue("s", ptr_data->data == NULL ? "" : ptr_data->data); + PyDict_SetItem(data_list_member, key, value); + Py_DECREF (key); + Py_DECREF (value); + + PyList_Append(data_list, data_list_member); + Py_DECREF (data_list_member); + } + } + + python_plugin->free_buffer_data (python_plugin, buffer_data); + + return data_list; +} +*/ + +/* + * Python subroutines + */ + +PyMethodDef weechat_python_funcs[] = +{ + { "register", weechat_python_api_register, METH_VARARGS, "" }, + { "charset_set", weechat_python_api_charset_set, METH_VARARGS, "" }, + { "iconv_to_internal", weechat_python_api_iconv_to_internal, METH_VARARGS, "" }, + { "iconv_from_internal", weechat_python_api_iconv_from_internal, METH_VARARGS, "" }, + { "mkdir_home", weechat_python_api_mkdir_home, METH_VARARGS, "" }, + { "mkdir", weechat_python_api_mkdir, METH_VARARGS, "" }, + { "prefix", weechat_python_api_prefix, METH_VARARGS, "" }, + { "color", weechat_python_api_color, METH_VARARGS, "" }, + { "prnt", weechat_python_api_prnt, METH_VARARGS, "" }, + { "infobar_print", weechat_python_api_infobar_print, METH_VARARGS, "" }, + { "infobar_remove", weechat_python_api_infobar_remove, METH_VARARGS, "" }, + { "log_print", weechat_python_api_log_print, METH_VARARGS, "" }, + { "hook_command", weechat_python_api_hook_command, METH_VARARGS, "" }, + { "hook_timer", weechat_python_api_hook_timer, METH_VARARGS, "" }, + { "hook_fd", weechat_python_api_hook_fd, METH_VARARGS, "" }, + { "hook_print", weechat_python_api_hook_print, METH_VARARGS, "" }, + { "hook_signal", weechat_python_api_hook_signal, METH_VARARGS, "" }, + { "hook_signal_send", weechat_python_api_hook_signal_send, METH_VARARGS, "" }, + { "hook_config", weechat_python_api_hook_config, METH_VARARGS, "" }, + { "hook_completion", weechat_python_api_hook_completion, METH_VARARGS, "" }, + { "unhook", weechat_python_api_unhook, METH_VARARGS, "" }, + { "unhook_all", weechat_python_api_unhook_all, METH_VARARGS, "" }, + { "buffer_new", weechat_python_api_buffer_new, METH_VARARGS, "" }, + { "buffer_search", weechat_python_api_buffer_search, METH_VARARGS, "" }, + { "buffer_close", weechat_python_api_buffer_close, METH_VARARGS, "" }, + { "buffer_get", weechat_python_api_buffer_get, METH_VARARGS, "" }, + { "buffer_set", weechat_python_api_buffer_set, METH_VARARGS, "" }, + { "nicklist_add_group", weechat_python_api_nicklist_add_group, METH_VARARGS, "" }, + { "nicklist_search_group", weechat_python_api_nicklist_search_group, METH_VARARGS, "" }, + { "nicklist_add_nick", weechat_python_api_nicklist_add_nick, METH_VARARGS, "" }, + { "nicklist_search_nick", weechat_python_api_nicklist_search_nick, METH_VARARGS, "" }, + { "nicklist_remove_group", weechat_python_api_nicklist_remove_group, METH_VARARGS, "" }, + { "nicklist_remove_nick", weechat_python_api_nicklist_remove_nick, METH_VARARGS, "" }, + { "nicklist_remove_all", weechat_python_api_nicklist_remove_all, METH_VARARGS, "" }, + { "command", weechat_python_api_command, METH_VARARGS, "" }, + { "info_get", weechat_python_api_info_get, METH_VARARGS, "" }, + /* + { "get_dcc_info", weechat_python_get_dcc_info, METH_VARARGS, "" }, + { "get_config", weechat_python_get_config, METH_VARARGS, "" }, + { "set_config", weechat_python_set_config, METH_VARARGS, "" }, + { "get_plugin_config", weechat_python_get_plugin_config, METH_VARARGS, "" }, + { "set_plugin_config", weechat_python_set_plugin_config, METH_VARARGS, "" }, + { "get_server_info", weechat_python_get_server_info, METH_VARARGS, "" }, + { "get_channel_info", weechat_python_get_channel_info, METH_VARARGS, "" }, + { "get_nick_info", weechat_python_get_nick_info, METH_VARARGS, "" }, + { "get_irc_color", weechat_python_get_irc_color, METH_VARARGS, "" }, + { "get_window_info", weechat_python_get_window_info, METH_VARARGS, "" }, + { "get_buffer_info", weechat_python_get_buffer_info, METH_VARARGS, "" }, + { "get_buffer_data", weechat_python_get_buffer_data, METH_VARARGS, "" }, + */ + { NULL, NULL, 0, NULL } +}; diff --git a/src/plugins/scripts/python/weechat-python-api.h b/src/plugins/scripts/python/weechat-python-api.h new file mode 100644 index 000000000..404a92182 --- /dev/null +++ b/src/plugins/scripts/python/weechat-python-api.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2003-2008 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#ifndef __WEECHAT_PYTHON_API_H +#define __WEECHAT_PYTHON_API_H 1 + +extern PyMethodDef weechat_python_funcs[]; + +#endif /* weechat-python.h */ diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c new file mode 100644 index 000000000..ec7590f79 --- /dev/null +++ b/src/plugins/scripts/python/weechat-python.c @@ -0,0 +1,792 @@ +/* + * Copyright (c) 2003-2008 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* weechat-python.c: Python plugin for WeeChat */ + +#undef _ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include + +#include "../../weechat-plugin.h" +#include "../script.h" +#include "weechat-python.h" +#include "weechat-python-api.h" + + +WEECHAT_PLUGIN_NAME("python"); +WEECHAT_PLUGIN_DESCRIPTION("Python plugin for WeeChat"); +WEECHAT_PLUGIN_AUTHOR("FlashCode "); +WEECHAT_PLUGIN_VERSION("0.1"); +WEECHAT_PLUGIN_LICENSE("GPL"); + +struct t_weechat_plugin *weechat_python_plugin; + +struct t_plugin_script *python_scripts = NULL; +struct t_plugin_script *python_current_script = NULL; +char *python_current_script_filename = NULL; +PyThreadState *python_mainThreadState = NULL; + +char python_buffer_output[128]; + + +/* + * weechat_python_exec: execute a Python script + */ + +void * +weechat_python_exec (struct t_plugin_script *script, + int ret_type, char *function, char **argv) +{ + PyObject *evMain; + PyObject *evDict; + PyObject *evFunc; + PyObject *rc; + void *ret_value; + int *ret_i; + + /* 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)) ) + { + weechat_printf (NULL, + weechat_gettext ("%s%s unable to run function \"%s\""), + weechat_prefix ("error"), "python", function); + /* PyEval_ReleaseThread (python_current_script->interpreter); */ + return NULL; + } + + python_current_script = script; + + if (argv && argv[0]) + { + if (argv[1]) + { + if (argv[2]) + { + if (argv[3]) + { + if (argv[4]) + { + rc = PyObject_CallFunction (evFunc, "sssss", argv[0], + argv[1], argv[2], argv[3], + argv[4]); + } + else + rc = PyObject_CallFunction (evFunc, "ssss", argv[0], + argv[1], argv[2], argv[3]); + } + else + rc = PyObject_CallFunction (evFunc, "sss", argv[0], + argv[1], argv[2]); + } + else + rc = PyObject_CallFunction (evFunc, "ss", argv[0], argv[1]); + } + else + rc = PyObject_CallFunction (evFunc, "s", argv[0]); + } + else + rc = PyObject_CallFunction (evFunc, NULL); + + ret_value = NULL; + + /* + ugly hack : rc = NULL while 'return weechat.PLUGIN_RC_OK .... + because of '#define PLUGIN_RC_OK 0' + */ + if (rc == NULL) + rc = PyInt_FromLong (0); + + if (PyString_Check (rc) && (ret_type == WEECHAT_SCRIPT_EXEC_STRING)) + { + if (PyString_AsString (rc)) + ret_value = strdup (PyString_AsString(rc)); + else + ret_value = NULL; + + Py_XDECREF(rc); + } + else if (PyInt_Check (rc) && (ret_type == WEECHAT_SCRIPT_EXEC_INT)) + { + + ret_i = (int *)malloc (sizeof(int)); + if (ret_i) + *ret_i = (int) PyInt_AsLong(rc); + ret_value = ret_i; + + Py_XDECREF(rc); + } + else + { + weechat_printf (NULL, + weechat_gettext ("%s%s: function \"%s\" must return " + "a valid value"), + weechat_prefix ("error"), "python", function); + /* PyEval_ReleaseThread (python_current_script->interpreter); */ + return NULL; + } + + if (ret_value == NULL) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: not enough memory for " + "function \"%s\""), + weechat_prefix ("error"), "python", function); + /* PyEval_ReleaseThread (python_current_script->interpreter); */ + return NULL; + } + + if (PyErr_Occurred ()) PyErr_Print (); + + /* PyEval_ReleaseThread (python_current_script->interpreter); */ + + return ret_value; +} + +/* + * weechat_python_output : redirection for stdout and stderr + */ + +static PyObject * +weechat_python_output (PyObject *self, PyObject *args) +{ + char *msg, *m, *p; + + /* make C compiler happy */ + (void) self; + + msg = NULL; + + if (!PyArg_ParseTuple (args, "s", &msg)) + { + if (strlen(python_buffer_output) > 0) + { + weechat_printf (NULL, + weechat_gettext ("%s: stdout/stderr: %s%s"), + "python", python_buffer_output, ""); + python_buffer_output[0] = '\0'; + } + } + else + { + m = msg; + while ((p = strchr (m, '\n')) != NULL) + { + *p = '\0'; + if (strlen (m) + strlen (python_buffer_output) > 0) + { + weechat_printf (NULL, + weechat_gettext ("%s: stdout/stderr: %s%s"), + "python", python_buffer_output, m); + } + *p = '\n'; + python_buffer_output[0] = '\0'; + m = ++p; + } + + if (strlen(m) + strlen(python_buffer_output) > sizeof(python_buffer_output)) + { + weechat_printf (NULL, + weechat_gettext ("%s: stdout/stderr : %s%s"), + "python", python_buffer_output, m); + python_buffer_output[0] = '\0'; + } + else + strcat (python_buffer_output, m); + } + + Py_INCREF(Py_None); + return Py_None; +} + +/* + * Outputs subroutines + */ + +static +PyMethodDef weechat_python_output_funcs[] = { + { "write", weechat_python_output, METH_VARARGS, "" }, + { NULL, NULL, 0, NULL } +}; + +/* + * weechat_python_load: load a Python script + */ + +int +weechat_python_load (char *filename) +{ + char *argv[] = { "__weechat_plugin__" , NULL }; + FILE *fp; + PyThreadState *python_current_interpreter; + PyObject *weechat_module, *weechat_outputs, *weechat_dict; + PyObject *python_path, *path; + char *w_home, *p_home; + int len; + + weechat_printf (NULL, + weechat_gettext ("%s%s: loading script \"%s\""), + weechat_prefix ("info"), "python", filename); + if ((fp = fopen (filename, "r")) == NULL) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: script \"%s\" not found"), + weechat_prefix ("error"), "python", filename); + return 0; + } + + python_current_script = NULL; + + /* PyEval_AcquireLock (); */ + python_current_interpreter = Py_NewInterpreter (); + PySys_SetArgv(1, argv); + + if (python_current_interpreter == NULL) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: unable to create new " + "sub-interpreter"), + weechat_prefix ("error"), "python"); + fclose (fp); + /* PyEval_ReleaseLock (); */ + return 0; + } + + /* PyThreadState_Swap (python_current_interpreter); */ + + weechat_module = Py_InitModule ("weechat", weechat_python_funcs); + + if ( weechat_module == NULL) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: unable to initialize WeeChat " + "module"), + weechat_prefix ("error"), "python"); + fclose (fp); + + Py_EndInterpreter (python_current_interpreter); + /* PyEval_ReleaseLock (); */ + + return 0; + } + + /* adding $weechat_dir/python in $PYTHONPATH */ + python_path = PySys_GetObject ("path"); + w_home = weechat_info_get ("weechat_dir"); + if (w_home) + { + len = strlen (w_home) + 1 + strlen("python") + 1; + p_home = (char *)malloc (len * sizeof(char)); + if (p_home) + { + snprintf (p_home, len, "%s/python", w_home); + path = PyString_FromString (p_home); + if (path != NULL) + { + PyList_Insert (python_path, 0, path); + Py_DECREF (path); + } + free (p_home); + } + } + + /* define some constants */ + weechat_dict = PyModule_GetDict(weechat_module); + PyDict_SetItemString(weechat_dict, "WEECHAT_RC_OK", PyInt_FromLong((long) WEECHAT_RC_OK)); + PyDict_SetItemString(weechat_dict, "WEECHAT_RC_ERROR", PyInt_FromLong((long) WEECHAT_RC_ERROR)); + PyDict_SetItemString(weechat_dict, "WEECHAT_RC_OK_IGNORE_WEECHAT", PyInt_FromLong((long) WEECHAT_RC_OK_IGNORE_WEECHAT)); + PyDict_SetItemString(weechat_dict, "WEECHAT_RC_OK_IGNORE_PLUGINS", PyInt_FromLong((long) WEECHAT_RC_OK_IGNORE_PLUGINS)); + PyDict_SetItemString(weechat_dict, "WEECHAT_RC_OK_IGNORE_ALL", PyInt_FromLong((long) WEECHAT_RC_OK_IGNORE_ALL)); + PyDict_SetItemString(weechat_dict, "WEECHAT_RC_OK_WITH_HIGHLIGHT", PyInt_FromLong((long) WEECHAT_RC_OK_WITH_HIGHLIGHT)); + PyDict_SetItemString(weechat_dict, "WEECHAT_LIST_POS_SORT", PyString_FromString(WEECHAT_LIST_POS_SORT)); + PyDict_SetItemString(weechat_dict, "WEECHAT_LIST_POS_BEGINNING", PyString_FromString(WEECHAT_LIST_POS_BEGINNING)); + PyDict_SetItemString(weechat_dict, "WEECHAT_LIST_POS_END", PyString_FromString(WEECHAT_LIST_POS_END)); + PyDict_SetItemString(weechat_dict, "WEECHAT_HOTLIST_LOW", PyString_FromString(WEECHAT_HOTLIST_LOW)); + PyDict_SetItemString(weechat_dict, "WEECHAT_HOTLIST_MESSAGE", PyString_FromString(WEECHAT_HOTLIST_MESSAGE)); + PyDict_SetItemString(weechat_dict, "WEECHAT_HOTLIST_PRIVATE", PyString_FromString(WEECHAT_HOTLIST_PRIVATE)); + PyDict_SetItemString(weechat_dict, "WEECHAT_HOTLIST_HIGHLIGHT", PyString_FromString(WEECHAT_HOTLIST_HIGHLIGHT)); + PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_SIGNAL_STRING", PyString_FromString(WEECHAT_HOOK_SIGNAL_STRING)); + PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_SIGNAL_INT", PyString_FromString(WEECHAT_HOOK_SIGNAL_INT)); + PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_SIGNAL_POINTER", PyString_FromString(WEECHAT_HOOK_SIGNAL_POINTER)); + + weechat_outputs = Py_InitModule("weechatOutputs", weechat_python_output_funcs); + if (weechat_outputs == NULL) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: unable to redirect stdout and " + "stderr"), + weechat_prefix ("error"), "python"); + } + else + { + if (PySys_SetObject("stdout", weechat_outputs) == -1) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: unable to redirect stdout"), + weechat_prefix ("error"), "python"); + } + if (PySys_SetObject("stderr", weechat_outputs) == -1) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: unable to redirect stderr"), + weechat_prefix ("error"), "python"); + } + } + + python_current_script_filename = filename; + + if (PyRun_SimpleFile (fp, filename) != 0) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: unable to parse file \"%s\""), + weechat_prefix ("error"), "python", filename); + fclose (fp); + + if (PyErr_Occurred ()) PyErr_Print (); + Py_EndInterpreter (python_current_interpreter); + /* PyEval_ReleaseLock (); */ + + /* if script was registered, removing from list */ + if (python_current_script != NULL) + { + script_remove (weechat_python_plugin, + &python_scripts, python_current_script); + } + return 0; + } + + if (PyErr_Occurred ()) PyErr_Print (); + + fclose (fp); + + if (python_current_script == NULL) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: function \"register\" not " + "found (or failed) in file \"%s\""), + weechat_prefix ("error"), "python", filename); + + if (PyErr_Occurred ()) PyErr_Print (); + Py_EndInterpreter (python_current_interpreter); + /* PyEval_ReleaseLock (); */ + + return 0; + } + + python_current_script->interpreter = (PyThreadState *) python_current_interpreter; + /* PyEval_ReleaseThread (python_current_script->interpreter); */ + + return 1; +} + +/* + * weechat_python_load_cb: callback for script_auto_load() function + */ + +int +weechat_python_load_cb (void *data, char *filename) +{ + /* make C compiler happy */ + (void) data; + + return weechat_python_load (filename); +} + +/* + * weechat_python_unload: unload a Python script + */ + +void +weechat_python_unload (struct t_plugin_script *script) +{ + int *r; + + weechat_printf (NULL, + weechat_gettext ("%s%s: unloading script \"%s\""), + weechat_prefix ("info"), "python", script->name); + + if (script->shutdown_func && script->shutdown_func[0]) + { + r = (int *) weechat_python_exec (script, WEECHAT_SCRIPT_EXEC_INT, + script->shutdown_func, NULL); + if (r) + free (r); + } + + PyThreadState_Swap (script->interpreter); + Py_EndInterpreter (script->interpreter); + + script_remove (weechat_python_plugin, &python_scripts, script); +} + +/* + * weechat_python_unload_name: unload a Python script by name + */ + +void +weechat_python_unload_name (char *name) +{ + struct t_plugin_script *ptr_script; + + ptr_script = script_search (weechat_python_plugin, &python_scripts, name); + if (ptr_script) + { + weechat_python_unload (ptr_script); + weechat_printf (NULL, + weechat_gettext ("%s%s: script \"%s\" unloaded"), + weechat_prefix ("info"), "python", name); + } + else + { + weechat_printf (NULL, + weechat_gettext ("%s%s: script \"%s\" not loaded"), + weechat_prefix ("error"), "python", name); + } +} + +/* + * weechat_python_unload_all: unload all Python scripts + */ + +void +weechat_python_unload_all () +{ + while (python_scripts) + { + weechat_python_unload (python_scripts); + } +} + +/* + * weechat_python_cmd: /python command handler + */ + +int +weechat_python_command_cb (void *data, struct t_gui_buffer *buffer, + int argc, char **argv, char **argv_eol) +{ + //int handler_found, modifier_found; + char *path_script; + struct t_plugin_script *ptr_script; + //struct t_plugin_handler *ptr_handler; + //struct t_plugin_modifier *ptr_modifier; + + /* make C compiler happy */ + (void) data; + (void) buffer; + + if (argc == 1) + { + /* list registered Python scripts */ + weechat_printf (NULL, ""); + weechat_printf (NULL, + weechat_gettext ("Registered %s scripts:"), + "python"); + if (python_scripts) + { + for (ptr_script = python_scripts; ptr_script; + ptr_script = ptr_script->next_script) + { + weechat_printf (NULL, + weechat_gettext (" %s v%s (%s), by %s, " + "license %s"), + ptr_script->name, + ptr_script->version, + ptr_script->description, + ptr_script->author, + ptr_script->license); + } + } + else + weechat_printf (NULL, weechat_gettext (" (none)")); + + /* + // List Python message handlers + plugin->print_server (plugin, ""); + plugin->print_server (plugin, "Python message handlers:"); + handler_found = 0; + for (ptr_handler = plugin->handlers; + ptr_handler; ptr_handler = ptr_handler->next_handler) + { + if ((ptr_handler->type == PLUGIN_HANDLER_MESSAGE) + && (ptr_handler->handler_args)) + { + handler_found = 1; + plugin->print_server (plugin, " IRC(%s) => Python(%s)", + ptr_handler->irc_command, + ptr_handler->handler_args); + } + } + if (!handler_found) + plugin->print_server (plugin, " (none)"); + + // List Python command handlers + plugin->print_server (plugin, ""); + plugin->print_server (plugin, "Python command handlers:"); + handler_found = 0; + for (ptr_handler = plugin->handlers; + ptr_handler; ptr_handler = ptr_handler->next_handler) + { + if ((ptr_handler->type == PLUGIN_HANDLER_COMMAND) + && (ptr_handler->handler_args)) + { + handler_found = 1; + plugin->print_server (plugin, " /%s => Python(%s)", + ptr_handler->command, + ptr_handler->handler_args); + } + } + if (!handler_found) + plugin->print_server (plugin, " (none)"); + + // List Python timer handlers + plugin->print_server (plugin, ""); + plugin->print_server (plugin, "Python timer handlers:"); + handler_found = 0; + for (ptr_handler = plugin->handlers; + ptr_handler; ptr_handler = ptr_handler->next_handler) + { + if ((ptr_handler->type == PLUGIN_HANDLER_TIMER) + && (ptr_handler->handler_args)) + { + handler_found = 1; + plugin->print_server (plugin, " %d seconds => Python(%s)", + ptr_handler->interval, + ptr_handler->handler_args); + } + } + if (!handler_found) + plugin->print_server (plugin, " (none)"); + + // List Python keyboard handlers + plugin->print_server (plugin, ""); + plugin->print_server (plugin, "Python keyboard handlers:"); + handler_found = 0; + for (ptr_handler = plugin->handlers; + ptr_handler; ptr_handler = ptr_handler->next_handler) + { + if ((ptr_handler->type == PLUGIN_HANDLER_KEYBOARD) + && (ptr_handler->handler_args)) + { + handler_found = 1; + plugin->print_server (plugin, " Python(%s)", + ptr_handler->handler_args); + } + } + if (!handler_found) + plugin->print_server (plugin, " (none)"); + + // List Python event handlers + plugin->print_server (plugin, ""); + plugin->print_server (plugin, "Python event handlers:"); + handler_found = 0; + for (ptr_handler = plugin->handlers; + ptr_handler; ptr_handler = ptr_handler->next_handler) + { + if ((ptr_handler->type == PLUGIN_HANDLER_EVENT) + && (ptr_handler->handler_args)) + { + handler_found = 1; + plugin->print_server (plugin, " %s => Python(%s)", + ptr_handler->event, + ptr_handler->handler_args); + } + } + if (!handler_found) + plugin->print_server (plugin, " (none)"); + + // List Python modifiers + plugin->print_server (plugin, ""); + plugin->print_server (plugin, "Python modifiers:"); + modifier_found = 0; + for (ptr_modifier = plugin->modifiers; + ptr_modifier; ptr_modifier = ptr_modifier->next_modifier) + { + modifier_found = 1; + if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_IN) + plugin->print_server (plugin, " IRC(%s, %s) => Python(%s)", + ptr_modifier->command, + PLUGIN_MODIFIER_IRC_IN_STR, + ptr_modifier->modifier_args); + else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_USER) + plugin->print_server (plugin, " IRC(%s, %s) => Python(%s)", + ptr_modifier->command, + PLUGIN_MODIFIER_IRC_USER_STR, + ptr_modifier->modifier_args); + else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_OUT) + plugin->print_server (plugin, " IRC(%s, %s) => Python(%s)", + ptr_modifier->command, + PLUGIN_MODIFIER_IRC_OUT_STR, + ptr_modifier->modifier_args); + } + if (!modifier_found) + plugin->print_server (plugin, " (none)"); + */ + } + else if (argc == 2) + { + if (weechat_strcasecmp (argv[1], "autoload") == 0) + { + script_auto_load (weechat_python_plugin, "python", + &weechat_python_load_cb); + } + else if (weechat_strcasecmp (argv[1], "reload") == 0) + { + weechat_python_unload_all (); + script_auto_load (weechat_python_plugin, "python", + &weechat_python_load_cb); + } + else if (weechat_strcasecmp (argv[1], "unload") == 0) + { + weechat_python_unload_all (); + } + } + else + { + if (weechat_strcasecmp (argv[1], "load") == 0) + { + /* load Python script */ + path_script = script_search_full_name (weechat_python_plugin, + "python", argv_eol[2]); + weechat_python_load ((path_script) ? path_script : argv_eol[2]); + if (path_script) + free (path_script); + } + else if (weechat_strcasecmp (argv[1], "unload") == 0) + { + /* unload Python script */ + weechat_python_unload_name (argv_eol[2]); + } + else + { + weechat_printf (NULL, + weechat_gettext ("%s%s: unknown option for " + "command \"%s\""), + weechat_prefix ("error"), "python", "python"); + } + } + + return WEECHAT_RC_OK; +} + +/* + * weechat_plugin_init: initialize Python plugin + */ + +int +weechat_plugin_init (struct t_weechat_plugin *plugin) +{ + weechat_python_plugin = plugin; + + /* init stdout/stderr buffer */ + python_buffer_output[0] = '\0'; + + Py_Initialize (); + if (Py_IsInitialized () == 0) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: unable to launch global " + "interpreter"), + weechat_prefix ("error"), "python"); + return WEECHAT_RC_ERROR; + } + + PyEval_InitThreads(); + /* python_mainThreadState = PyThreadState_Swap(NULL); */ + python_mainThreadState = PyEval_SaveThread(); + /* PyEval_ReleaseLock (); */ + + if (python_mainThreadState == NULL) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: unable to get current " + "interpreter state"), + weechat_prefix ("error"), "python"); + return WEECHAT_RC_ERROR; + } + + weechat_hook_command ("python", + weechat_gettext ("list/load/unload Python scripts"), + weechat_gettext ("[load filename] | [autoload] | " + "[reload] | [unload [script]]"), + weechat_gettext ("filename: Python script (file) to " + "load\n" + "script: script name to unload\n\n" + "Without argument, /python command " + "lists all loaded Python scripts."), + "load|autoload|reload|unload %f", + &weechat_python_command_cb, NULL); + + weechat_mkdir_home ("python", 0644); + weechat_mkdir_home ("python/autoload", 0644); + + script_init (weechat_python_plugin); + script_auto_load (weechat_python_plugin, "python", + &weechat_python_load_cb); + + /* init ok */ + return WEECHAT_RC_OK; +} + +/* + * weechat_plugin_end: shutdown Python interface + */ + +void +weechat_plugin_end (struct t_weechat_plugin *plugin) +{ + /* make C compiler happy */ + (void) plugin; + + /* unload all scripts */ + weechat_python_unload_all (); + + /* free Python interpreter */ + if (python_mainThreadState != NULL) + { + /* PyEval_AcquireLock (); */ + PyThreadState_Swap (python_mainThreadState); + /* PyEval_ReleaseLock (); */ + python_mainThreadState = NULL; + } + + Py_Finalize (); + if (Py_IsInitialized () != 0) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: unable to free interpreter"), + weechat_prefix ("error"), "python"); + } +} diff --git a/src/plugins/scripts/python/weechat-python.h b/src/plugins/scripts/python/weechat-python.h new file mode 100644 index 000000000..6c7deebe4 --- /dev/null +++ b/src/plugins/scripts/python/weechat-python.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2003-2008 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#ifndef __WEECHAT_PYTHON_H +#define __WEECHAT_PYTHON_H 1 + +#include "../../weechat-plugin.h" + +#define weechat_plugin weechat_python_plugin + +extern struct t_weechat_plugin *weechat_python_plugin; + +extern struct t_plugin_script *python_scripts; +extern struct t_plugin_script *python_current_script; +extern char *python_current_script_filename; + +extern void * weechat_python_exec (struct t_plugin_script *script, + int ret_type, char *function, char **argv); + +#endif /* weechat-perl.h */ diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c index e85793f2b..4ea484310 100644 --- a/src/plugins/scripts/script-api.c +++ b/src/plugins/scripts/script-api.c @@ -118,10 +118,10 @@ script_api_log_printf (struct t_weechat_plugin *weechat_plugin, /* * script_api_hook_command: hook a command - * return 1 if ok, 0 if error + * return new hook, NULL if error */ -int +struct t_hook * script_api_hook_command (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, char *command, char *description, @@ -138,7 +138,7 @@ script_api_hook_command (struct t_weechat_plugin *weechat_plugin, new_script_callback = script_callback_alloc (); if (!new_script_callback) - return 0; + return NULL; new_script_callback->script = NULL; new_script_callback->function = NULL; @@ -150,7 +150,7 @@ script_api_hook_command (struct t_weechat_plugin *weechat_plugin, if (!new_hook) { free (new_script_callback); - return 0; + return NULL; } new_script_callback->script = script; @@ -159,15 +159,15 @@ script_api_hook_command (struct t_weechat_plugin *weechat_plugin, script_callback_add (script, new_script_callback); - return 1; + return new_hook; } /* * script_api_hook_timer: hook a timer - * return 1 if ok, 0 if error + * return new hook, NULL if error */ -int +struct t_hook * script_api_hook_timer (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, int interval, int align_second, int max_calls, @@ -179,14 +179,14 @@ script_api_hook_timer (struct t_weechat_plugin *weechat_plugin, new_script_callback = script_callback_alloc (); if (!new_script_callback) - return 0; + return NULL; new_hook = weechat_hook_timer (interval, align_second, max_calls, callback, new_script_callback); if (!new_hook) { free (new_script_callback); - return 0; + return NULL; } new_script_callback->script = script; @@ -195,15 +195,15 @@ script_api_hook_timer (struct t_weechat_plugin *weechat_plugin, script_callback_add (script, new_script_callback); - return 1; + return new_hook; } /* * script_api_hook_fd: hook a fd - * return 1 if ok, 0 if error + * return new hook, NULL if error */ -int +struct t_hook * script_api_hook_fd (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, int fd, int flag_read, int flag_write, @@ -216,14 +216,14 @@ script_api_hook_fd (struct t_weechat_plugin *weechat_plugin, new_script_callback = script_callback_alloc (); if (!new_script_callback) - return 0; + return NULL; new_hook = weechat_hook_fd (fd, flag_read, flag_write, flag_exception, callback, new_script_callback); if (!new_hook) { free (new_script_callback); - return 0; + return NULL; } new_script_callback->script = script; @@ -232,15 +232,15 @@ script_api_hook_fd (struct t_weechat_plugin *weechat_plugin, script_callback_add (script, new_script_callback); - return 1; + return new_hook; } /* * script_api_hook_print: hook a print - * return 1 if ok, 0 if error + * return new hook, NULL if error */ -int +struct t_hook * script_api_hook_print (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, struct t_gui_buffer *buffer, @@ -256,14 +256,14 @@ script_api_hook_print (struct t_weechat_plugin *weechat_plugin, new_script_callback = script_callback_alloc (); if (!new_script_callback) - return 0; + return NULL; new_hook = weechat_hook_print (buffer, message, strip_colors, callback, new_script_callback); if (!new_hook) { free (new_script_callback); - return 0; + return NULL; } new_script_callback->script = script; @@ -272,15 +272,15 @@ script_api_hook_print (struct t_weechat_plugin *weechat_plugin, script_callback_add (script, new_script_callback); - return 1; + return new_hook; } /* * script_api_hook_signal: hook a signal - * return 1 if ok, 0 if error + * return new hook, NULL if error */ -int +struct t_hook * script_api_hook_signal (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, char *signal, @@ -294,13 +294,13 @@ script_api_hook_signal (struct t_weechat_plugin *weechat_plugin, new_script_callback = script_callback_alloc (); if (!new_script_callback) - return 0; + return NULL; new_hook = weechat_hook_signal (signal, callback, new_script_callback); if (!new_hook) { free (new_script_callback); - return 0; + return NULL; } new_script_callback->script = script; @@ -309,15 +309,15 @@ script_api_hook_signal (struct t_weechat_plugin *weechat_plugin, script_callback_add (script, new_script_callback); - return 1; + return new_hook; } /* * script_api_hook_config: hook a config option - * return 1 if ok, 0 if error + * return new hook, NULL if error */ -int +struct t_hook * script_api_hook_config (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, char *type, char *option, @@ -330,13 +330,13 @@ script_api_hook_config (struct t_weechat_plugin *weechat_plugin, new_script_callback = script_callback_alloc (); if (!new_script_callback) - return 0; + return NULL; new_hook = weechat_hook_config (type, option, callback, new_script_callback); if (!new_hook) { free (new_script_callback); - return 0; + return NULL; } new_script_callback->script = script; @@ -345,15 +345,15 @@ script_api_hook_config (struct t_weechat_plugin *weechat_plugin, script_callback_add (script, new_script_callback); - return 1; + return new_hook; } /* * script_api_hook_completion: hook a completion - * return 1 if ok, 0 if error + * return new hook, NULL if error */ -int +struct t_hook * script_api_hook_completion (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, char *completion, @@ -367,13 +367,13 @@ script_api_hook_completion (struct t_weechat_plugin *weechat_plugin, new_script_callback = script_callback_alloc (); if (!new_script_callback) - return 0; + return NULL; new_hook = weechat_hook_completion (completion, callback, new_script_callback); if (!new_hook) { free (new_script_callback); - return 0; + return NULL; } new_script_callback->script = script; @@ -382,14 +382,15 @@ script_api_hook_completion (struct t_weechat_plugin *weechat_plugin, script_callback_add (script, new_script_callback); - return 1; + return new_hook; } /* * script_api_unhook: unhook something + * return 1 if ok, 0 if error */ -void +int script_api_unhook (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, struct t_hook *hook) @@ -397,7 +398,7 @@ script_api_unhook (struct t_weechat_plugin *weechat_plugin, struct t_script_callback *ptr_script_callback; if (!weechat_plugin || !script || !hook) - return; + return 0; for (ptr_script_callback = script->callbacks; ptr_script_callback; ptr_script_callback = ptr_script_callback->next_callback) @@ -409,7 +410,10 @@ script_api_unhook (struct t_weechat_plugin *weechat_plugin, if (ptr_script_callback) { script_callback_remove (weechat_plugin, script, ptr_script_callback); + return 1; } + + return 0; } /* diff --git a/src/plugins/scripts/script-api.h b/src/plugins/scripts/script-api.h index 68c898c9b..0483a4635 100644 --- a/src/plugins/scripts/script-api.h +++ b/src/plugins/scripts/script-api.h @@ -32,63 +32,64 @@ extern void script_api_infobar_printf (struct t_weechat_plugin *weechat_plugin, extern void script_api_log_printf (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, char *format, ...); -extern int script_api_hook_command (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - char *command, char *description, - char *args, char *args_description, - char *completion, - int (*callback)(void *data, - struct t_gui_buffer *buffer, - int argc, char **argv, - char **argv_eol), - char *function); -extern int script_api_hook_timer (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - int interval, int align_second, - int max_calls, - int (*callback)(void *data), - char *function); -extern int script_api_hook_fd (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - int fd, int flag_read, int flag_write, - int flag_exception, - int (*callback)(void *data), - char *function); -extern int script_api_hook_print (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_gui_buffer *buffer, - char *message, int strip_colors, - int (*callback)(void *data, - struct t_gui_buffer *buffer, - time_t date, char *prefix, - char *message), - char *function); -extern int script_api_hook_signal (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - char *signal, - int (*callback)(void *data, - char *signal, - char *type_data, - void *signal_data), - char *function); -extern int script_api_hook_config (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - char *type, char *option, - int (*callback)(void *data, char *type, - char *option, - char *value), - char *function); -extern int script_api_hook_completion (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - char *completion, - int (*callback)(void *data, - char *completion, - struct t_gui_buffer *buffer, - struct t_weelist *list), - char *function); -extern void script_api_unhook (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_hook *hook); +extern struct t_hook *script_api_hook_command (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + char *command, char *description, + char *args, char *args_description, + char *completion, + int (*callback)(void *data, + struct t_gui_buffer *buffer, + int argc, char **argv, + char **argv_eol), + char *function); +extern struct t_hook *script_api_hook_timer (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + int interval, int align_second, + int max_calls, + int (*callback)(void *data), + char *function); +extern struct t_hook *script_api_hook_fd (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + int fd, int flag_read, + int flag_write, int flag_exception, + int (*callback)(void *data), + char *function); +extern struct t_hook *script_api_hook_print (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + struct t_gui_buffer *buffer, + char *message, int strip_colors, + int (*callback)(void *data, + struct t_gui_buffer *buffer, + time_t date, + char *prefix, + char *message), + char *function); +extern struct t_hook *script_api_hook_signal (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + char *signal, + int (*callback)(void *data, + char *signal, + char *type_data, + void *signal_data), + char *function); +extern struct t_hook *script_api_hook_config (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + char *type, char *option, + int (*callback)(void *data, char *type, + char *option, + char *value), + char *function); +extern struct t_hook *script_api_hook_completion (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + char *completion, + int (*callback)(void *data, + char *completion, + struct t_gui_buffer *buffer, + struct t_weelist *list), + char *function); +extern int script_api_unhook (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + struct t_hook *hook); extern void script_api_unhook_all (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script); struct t_gui_buffer *script_api_buffer_new (struct t_weechat_plugin *weechat_plugin, diff --git a/src/plugins/scripts/script.c b/src/plugins/scripts/script.c index dfdb6acd4..01a5e0dfa 100644 --- a/src/plugins/scripts/script.c +++ b/src/plugins/scripts/script.c @@ -46,8 +46,6 @@ script_config_read (struct t_weechat_plugin *weechat_plugin) { char *string; - weechat_printf (NULL, "script_config_read"); - string = weechat_config_get_plugin (SCRIPT_OPTION_CHECK_LICENSE); if (!string) { -- cgit v1.2.3