diff options
Diffstat (limited to 'src')
41 files changed, 3536 insertions, 3005 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 5c515d161..993b4ea07 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -475,7 +475,8 @@ command_debug (void *data, struct t_gui_buffer *buffer, } else { - hook_signal_send ("debug", argv_eol[1]); + hook_signal_send ("debug", + WEECHAT_HOOK_SIGNAL_STRING, argv_eol[1]); } } @@ -1142,6 +1143,7 @@ command_quit (void *data, struct t_gui_buffer *buffer, (void) argv; hook_signal_send ("quit", + WEECHAT_HOOK_SIGNAL_STRING, (argc > 1) ? argv_eol[1] : CONFIG_STRING(config_look_default_msg_quit)); @@ -1186,7 +1188,7 @@ command_reload (void *data, struct t_gui_buffer *buffer, gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); /* tell to plugins to reload their configuration */ - hook_signal_send ("config_reload", NULL); + hook_signal_send ("config_reload", WEECHAT_HOOK_SIGNAL_STRING, NULL); return WEECHAT_RC_OK; } diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index cc5ea3693..ec7b5ce8f 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -1399,38 +1399,38 @@ config_file_print_log () ptr_config_file = ptr_config_file->next_config) { log_printf (""); - log_printf ("[config (addr:0x%X)]", ptr_config_file); - log_printf (" plugin . . . . . . . . : 0x%X", ptr_config_file->plugin); + log_printf ("[config (addr:0x%x)]", ptr_config_file); + log_printf (" plugin . . . . . . . . : 0x%x", ptr_config_file->plugin); log_printf (" filename . . . . . . . : '%s'", ptr_config_file->filename); - log_printf (" file . . . . . . . . . : 0x%X", ptr_config_file->file); - log_printf (" sections . . . . . . . : 0x%X", ptr_config_file->sections); - log_printf (" last_section . . . . . : 0x%X", ptr_config_file->last_section); - log_printf (" prev_config. . . . . . : 0x%X", ptr_config_file->prev_config); - log_printf (" next_config. . . . . . : 0x%X", ptr_config_file->next_config); + log_printf (" file . . . . . . . . . : 0x%x", ptr_config_file->file); + log_printf (" sections . . . . . . . : 0x%x", ptr_config_file->sections); + log_printf (" last_section . . . . . : 0x%x", ptr_config_file->last_section); + log_printf (" prev_config. . . . . . : 0x%x", ptr_config_file->prev_config); + log_printf (" next_config. . . . . . : 0x%x", ptr_config_file->next_config); for (ptr_section = ptr_config_file->sections; ptr_section; ptr_section = ptr_section->next_section) { log_printf (""); - log_printf (" [section (addr:0x%X)]", ptr_section); + log_printf (" [section (addr:0x%x)]", ptr_section); log_printf (" name . . . . . . . . . : '%s'", ptr_section->name); - log_printf (" callback_read. . . . . : 0x%X", ptr_section->callback_read); - log_printf (" callback_write . . . . : 0x%X", ptr_section->callback_write); - log_printf (" callback_write_default : 0x%X", ptr_section->callback_write_default); - log_printf (" options. . . . . . . . : 0x%X", ptr_section->options); - log_printf (" last_option. . . . . . : 0x%X", ptr_section->last_option); - log_printf (" prev_section . . . . . : 0x%X", ptr_section->prev_section); - log_printf (" next_section . . . . . : 0x%X", ptr_section->next_section); + log_printf (" callback_read. . . . . : 0x%x", ptr_section->callback_read); + log_printf (" callback_write . . . . : 0x%x", ptr_section->callback_write); + log_printf (" callback_write_default : 0x%x", ptr_section->callback_write_default); + log_printf (" options. . . . . . . . : 0x%x", ptr_section->options); + log_printf (" last_option. . . . . . : 0x%x", ptr_section->last_option); + log_printf (" prev_section . . . . . : 0x%x", ptr_section->prev_section); + log_printf (" next_section . . . . . : 0x%x", ptr_section->next_section); for (ptr_option = ptr_section->options; ptr_option; ptr_option = ptr_option->next_option) { log_printf (""); - log_printf (" [option (addr:0x%X)]", ptr_option); + log_printf (" [option (addr:0x%x)]", ptr_option); log_printf (" name . . . . . . . . : '%s'", ptr_option->name); log_printf (" type . . . . . . . . : %d", ptr_option->type); log_printf (" description. . . . . : '%s'", ptr_option->description); - log_printf (" string_values. . . . : 0x%X", ptr_option->string_values); + log_printf (" string_values. . . . : 0x%x", ptr_option->string_values); log_printf (" min. . . . . . . . . : %d", ptr_option->min); log_printf (" max. . . . . . . . . : %d", ptr_option->max); switch (ptr_option->type) @@ -1470,10 +1470,10 @@ config_file_print_log () gui_color_get_name (CONFIG_COLOR(ptr_option))); break; } - log_printf (" callback_change. . . : 0x%X", ptr_option->callback_change); + log_printf (" callback_change. . . : 0x%x", ptr_option->callback_change); log_printf (" loaded . . . . . . . : %d", ptr_option->loaded); - log_printf (" prev_option. . . . . : 0x%X", ptr_option->prev_option); - log_printf (" next_option. . . . . : 0x%X", ptr_option->next_option); + log_printf (" prev_option. . . . . : 0x%x", ptr_option->prev_option); + log_printf (" next_option. . . . . : 0x%x", ptr_option->next_option); } } } diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index 0bec00964..02e92de78 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -849,7 +849,7 @@ hook_signal (struct t_weechat_plugin *plugin, char *signal, */ void -hook_signal_send (char *signal, void *signal_data) +hook_signal_send (char *signal, char *type_data, void *signal_data) { struct t_hook *ptr_hook, *next_hook; @@ -867,7 +867,7 @@ hook_signal_send (char *signal, void *signal_data) { ptr_hook->running = 1; (void) (HOOK_SIGNAL(ptr_hook, callback)) - (ptr_hook->callback_data, signal, signal_data); + (ptr_hook->callback_data, signal, type_data, signal_data); ptr_hook->running = 0; } @@ -1188,8 +1188,8 @@ hook_print_log () ptr_hook = ptr_hook->next_hook) { log_printf (""); - log_printf ("[hook (addr:0x%X)]", ptr_hook); - log_printf (" plugin . . . . . . . . : 0x%X ('%s')", + log_printf ("[hook (addr:0x%x)]", ptr_hook); + log_printf (" plugin . . . . . . . . : 0x%x ('%s')", ptr_hook->plugin, (ptr_hook->plugin) ? ptr_hook->plugin->name : ""); log_printf (" deleted. . . . . . . . : %d", ptr_hook->deleted); @@ -1198,11 +1198,11 @@ hook_print_log () { case HOOK_TYPE_COMMAND: log_printf (" type . . . . . . . . . : %d (command)", ptr_hook->type); - log_printf (" callback_data. . . . . : 0x%X", ptr_hook->callback_data); + log_printf (" callback_data. . . . . : 0x%x", ptr_hook->callback_data); if (!ptr_hook->deleted) { log_printf (" command data:"); - log_printf (" callback . . . . . . : 0x%X", HOOK_COMMAND(ptr_hook, callback)); + log_printf (" callback . . . . . . : 0x%x", HOOK_COMMAND(ptr_hook, callback)); log_printf (" command. . . . . . . : '%s'", HOOK_COMMAND(ptr_hook, command)); log_printf (" level. . . . . . . . : %d", HOOK_COMMAND(ptr_hook, level)); log_printf (" command_desc . . . . : '%s'", HOOK_COMMAND(ptr_hook, description)); @@ -1213,11 +1213,11 @@ hook_print_log () break; case HOOK_TYPE_TIMER: log_printf (" type . . . . . . . . . : %d (timer)", ptr_hook->type); - log_printf (" callback_data. . . . . : 0x%X", ptr_hook->callback_data); + log_printf (" callback_data. . . . . : 0x%x", ptr_hook->callback_data); if (!ptr_hook->deleted) { log_printf (" timer data:"); - log_printf (" callback . . . . . . : 0x%X", HOOK_TIMER(ptr_hook, callback)); + log_printf (" callback . . . . . . : 0x%x", HOOK_TIMER(ptr_hook, callback)); log_printf (" interval . . . . . . : %ld", HOOK_TIMER(ptr_hook, interval)); local_time = localtime (&HOOK_TIMER(ptr_hook, last_exec).tv_sec); strftime (text_time, sizeof (text_time), @@ -1237,54 +1237,54 @@ hook_print_log () break; case HOOK_TYPE_FD: log_printf (" type . . . . . . . . . : %d (fd)", ptr_hook->type); - log_printf (" callback_data. . . . . : 0x%X", ptr_hook->callback_data); + log_printf (" callback_data. . . . . : 0x%x", ptr_hook->callback_data); if (!ptr_hook->deleted) { log_printf (" fd data:"); - log_printf (" callback . . . . . . : 0x%X", HOOK_FD(ptr_hook, callback)); + log_printf (" callback . . . . . . : 0x%x", HOOK_FD(ptr_hook, callback)); log_printf (" fd . . . . . . . . . : %ld", HOOK_FD(ptr_hook, fd)); log_printf (" flags. . . . . . . . : %ld", HOOK_FD(ptr_hook, flags)); } break; case HOOK_TYPE_PRINT: log_printf (" type . . . . . . . . . : %d (print)", ptr_hook->type); - log_printf (" callback_data. . . . . : 0x%X", ptr_hook->callback_data); + log_printf (" callback_data. . . . . : 0x%x", ptr_hook->callback_data); if (!ptr_hook->deleted) { log_printf (" print data:"); - log_printf (" callback . . . . . . : 0x%X", HOOK_PRINT(ptr_hook, callback)); - log_printf (" buffer . . . . . . . : 0x%X", HOOK_PRINT(ptr_hook, buffer)); + log_printf (" callback . . . . . . : 0x%x", HOOK_PRINT(ptr_hook, callback)); + log_printf (" buffer . . . . . . . : 0x%x", HOOK_PRINT(ptr_hook, buffer)); log_printf (" message. . . . . . . : '%s'", HOOK_PRINT(ptr_hook, message)); } break; case HOOK_TYPE_SIGNAL: log_printf (" type . . . . . . . . . : %d (signal)", ptr_hook->type); - log_printf (" callback_data. . . . . : 0x%X", ptr_hook->callback_data); + log_printf (" callback_data. . . . . : 0x%x", ptr_hook->callback_data); if (!ptr_hook->deleted) { log_printf (" signal data:"); - log_printf (" callback . . . . . . : 0x%X", HOOK_SIGNAL(ptr_hook, callback)); + log_printf (" callback . . . . . . : 0x%x", HOOK_SIGNAL(ptr_hook, callback)); log_printf (" signal . . . . . . . : '%s'", HOOK_SIGNAL(ptr_hook, signal)); } break; case HOOK_TYPE_CONFIG: log_printf (" type . . . . . . . . . : %d (config)", ptr_hook->type); - log_printf (" callback_data. . . . . : 0x%X", ptr_hook->callback_data); + log_printf (" callback_data. . . . . : 0x%x", ptr_hook->callback_data); if (!ptr_hook->deleted) { log_printf (" config data:"); - log_printf (" callback . . . . . . : 0x%X", HOOK_CONFIG(ptr_hook, callback)); + log_printf (" callback . . . . . . : 0x%x", HOOK_CONFIG(ptr_hook, callback)); log_printf (" type . . . . . . . . : '%s'", HOOK_CONFIG(ptr_hook, type)); log_printf (" option . . . . . . . : '%s'", HOOK_CONFIG(ptr_hook, option)); } break; case HOOK_TYPE_COMPLETION: log_printf (" type . . . . . . . . . : %d (completion)", ptr_hook->type); - log_printf (" callback_data. . . . . : 0x%X", ptr_hook->callback_data); + log_printf (" callback_data. . . . . : 0x%x", ptr_hook->callback_data); if (!ptr_hook->deleted) { log_printf (" completion data:"); - log_printf (" callback . . . . . . : 0x%X", HOOK_COMPLETION(ptr_hook, callback)); + log_printf (" callback . . . . . . : 0x%x", HOOK_COMPLETION(ptr_hook, callback)); log_printf (" completion . . . . . : '%s'", HOOK_COMPLETION(ptr_hook, completion)); } break; @@ -1293,8 +1293,8 @@ hook_print_log () it is never used as type */ break; } - log_printf (" prev_hook. . . . . . . : 0x%X", ptr_hook->prev_hook); - log_printf (" next_hook. . . . . . . : 0x%X", ptr_hook->next_hook); + log_printf (" prev_hook. . . . . . . : 0x%x", ptr_hook->prev_hook); + log_printf (" next_hook. . . . . . . : 0x%x", ptr_hook->next_hook); } } } diff --git a/src/core/wee-hook.h b/src/core/wee-hook.h index dfa293b83..0975aef37 100644 --- a/src/core/wee-hook.h +++ b/src/core/wee-hook.h @@ -113,7 +113,7 @@ struct t_hook_print }; typedef int (t_hook_callback_signal)(void *data, char *signal, - void *signal_data); + char *type_data, void *signal_data); struct t_hook_signal { @@ -188,7 +188,8 @@ extern struct t_hook *hook_signal (struct t_weechat_plugin *plugin, char *signal, t_hook_callback_signal *callback, void *callback_data); -extern void hook_signal_send (char *signal, void *signal_data); +extern void hook_signal_send (char *signal, char *type_data, + void *signal_data); extern struct t_hook *hook_config (struct t_weechat_plugin *, char *type, char *option, t_hook_callback_config *callback, diff --git a/src/core/wee-list.c b/src/core/wee-list.c index c92fcdac8..8f5e23262 100644 --- a/src/core/wee-list.c +++ b/src/core/wee-list.c @@ -30,6 +30,7 @@ #include "wee-list.h" #include "wee-log.h" #include "wee-string.h" +#include "../plugins/weechat-plugin.h" /* @@ -97,9 +98,9 @@ weelist_insert (struct t_weelist *weelist, struct t_weelist_item *item, { /* search position for new element, according to pos asked */ pos_item = NULL; - if (string_strcasecmp (where, WEELIST_POS_BEGINNING) == 0) + if (string_strcasecmp (where, WEECHAT_LIST_POS_BEGINNING) == 0) pos_item = weelist->items; - else if (string_strcasecmp (where, WEELIST_POS_END) == 0) + else if (string_strcasecmp (where, WEECHAT_LIST_POS_END) == 0) pos_item = NULL; else pos_item = weelist_find_pos (weelist, item->data); @@ -353,13 +354,13 @@ weelist_print_log (struct t_weelist *weelist, char *name) { struct t_weelist_item *ptr_item; - log_printf ("[%s (addr:0x%X)]", name, weelist); + log_printf ("[%s (addr:0x%x)]", name, weelist); for (ptr_item = weelist->items; ptr_item; ptr_item = ptr_item->next_item) { log_printf (" data . . . . . . . . . : '%s'", ptr_item->data); - log_printf (" prev_item. . . . . . . : 0x%X", ptr_item->prev_item); - log_printf (" next_item. . . . . . . : 0x%X", ptr_item->next_item); + log_printf (" prev_item. . . . . . . : 0x%x", ptr_item->prev_item); + log_printf (" next_item. . . . . . . : 0x%x", ptr_item->next_item); } } diff --git a/src/core/wee-list.h b/src/core/wee-list.h index 857bdeadd..3562217fe 100644 --- a/src/core/wee-list.h +++ b/src/core/wee-list.h @@ -20,10 +20,6 @@ #ifndef __WEECHAT_LIST_H #define __WEECHAT_LIST_H 1 -#define WEELIST_POS_SORT "sort" -#define WEELIST_POS_BEGINNING "beginning" -#define WEELIST_POS_END "end" - struct t_weelist_item { char *data; /* item data */ diff --git a/src/core/weechat.c b/src/core/weechat.c index d2119745b..d2121a71a 100644 --- a/src/core/weechat.c +++ b/src/core/weechat.c @@ -521,7 +521,7 @@ weechat_dump (int crash) plugin_print_log (); - hook_signal_send ("dump_data", NULL); + hook_signal_send ("dump_data", WEECHAT_HOOK_SIGNAL_STRING, NULL); log_printf (""); log_printf ("****** End of WeeChat dump ******"); diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index 951de91db..3742a857f 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -1426,11 +1426,11 @@ gui_window_title_reset () void gui_window_objects_print_log (struct t_gui_window *window) { - log_printf (" win_title . . . . . : 0x%X", GUI_CURSES(window)->win_title); - log_printf (" win_chat. . . . . . : 0x%X", GUI_CURSES(window)->win_chat); - log_printf (" win_nick. . . . . . : 0x%X", GUI_CURSES(window)->win_nick); - log_printf (" win_status. . . . . : 0x%X", GUI_CURSES(window)->win_status); - log_printf (" win_infobar . . . . : 0x%X", GUI_CURSES(window)->win_infobar); - log_printf (" win_input . . . . . : 0x%X", GUI_CURSES(window)->win_input); - log_printf (" win_separator . . . : 0x%X", GUI_CURSES(window)->win_separator); + log_printf (" win_title . . . . . : 0x%x", GUI_CURSES(window)->win_title); + log_printf (" win_chat. . . . . . : 0x%x", GUI_CURSES(window)->win_chat); + log_printf (" win_nick. . . . . . : 0x%x", GUI_CURSES(window)->win_nick); + log_printf (" win_status. . . . . : 0x%x", GUI_CURSES(window)->win_status); + log_printf (" win_infobar . . . . : 0x%x", GUI_CURSES(window)->win_infobar); + log_printf (" win_input . . . . . : 0x%x", GUI_CURSES(window)->win_input); + log_printf (" win_separator . . . : 0x%x", GUI_CURSES(window)->win_separator); } diff --git a/src/gui/gtk/gui-gtk-window.c b/src/gui/gtk/gui-gtk-window.c index f59021ba2..12526333c 100644 --- a/src/gui/gtk/gui-gtk-window.c +++ b/src/gui/gtk/gui-gtk-window.c @@ -919,9 +919,9 @@ gui_window_title_reset () void gui_window_objects_print_log (struct t_gui_window *window) { - log_printf (" textview_chat . . . : 0x%X", GUI_GTK(window)->textview_chat); - log_printf (" textbuffer_chat . . : 0x%X", GUI_GTK(window)->textbuffer_chat); - log_printf (" texttag_chat. . . . : 0x%X", GUI_GTK(window)->texttag_chat); - log_printf (" textview_nicklist . : 0x%X", GUI_GTK(window)->textview_nicklist); - log_printf (" textbuffer_nicklist : 0x%X", GUI_GTK(window)->textbuffer_nicklist); + log_printf (" textview_chat . . . : 0x%x", GUI_GTK(window)->textview_chat); + log_printf (" textbuffer_chat . . : 0x%x", GUI_GTK(window)->textbuffer_chat); + log_printf (" texttag_chat. . . . : 0x%x", GUI_GTK(window)->texttag_chat); + log_printf (" textview_nicklist . : 0x%x", GUI_GTK(window)->textview_nicklist); + log_printf (" textbuffer_nicklist : 0x%x", GUI_GTK(window)->textbuffer_nicklist); } diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 4423c67bb..444bf3f46 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -178,7 +178,8 @@ gui_buffer_new (struct t_weechat_plugin *plugin, char *category, char *name, gui_window_redraw_buffer (new_buffer); } - hook_signal_send ("buffer_open", new_buffer); + hook_signal_send ("buffer_open", + WEECHAT_HOOK_SIGNAL_POINTER, new_buffer); } else return NULL; @@ -619,7 +620,8 @@ gui_buffer_close (struct t_gui_buffer *buffer, int switch_to_another) struct t_gui_buffer *ptr_buffer; struct t_gui_line *ptr_line; - hook_signal_send ("buffer_close", buffer); + hook_signal_send ("buffer_close", + WEECHAT_HOOK_SIGNAL_POINTER, buffer); if (switch_to_another) { @@ -942,7 +944,7 @@ gui_buffer_dump_hexa (struct t_gui_buffer *buffer) char hexa[(16 * 3) + 1], ascii[(16 * 2) + 1]; int hexa_pos, ascii_pos; - log_printf ("[buffer dump hexa (addr:0x%X)]", buffer); + log_printf ("[buffer dump hexa (addr:0x%x)]", buffer); num_line = 1; for (ptr_line = buffer->lines; ptr_line; ptr_line = ptr_line->next_line) { @@ -1007,8 +1009,8 @@ gui_buffer_print_log () ptr_buffer = ptr_buffer->next_buffer) { log_printf (""); - log_printf ("[buffer (addr:0x%X)]", ptr_buffer); - log_printf (" plugin . . . . . . . . : 0x%X", ptr_buffer->plugin); + log_printf ("[buffer (addr:0x%x)]", ptr_buffer); + log_printf (" plugin . . . . . . . . : 0x%x", ptr_buffer->plugin); log_printf (" number . . . . . . . . : %d", ptr_buffer->number); log_printf (" category . . . . . . . : '%s'", ptr_buffer->category); log_printf (" name . . . . . . . . . : '%s'", ptr_buffer->name); @@ -1016,21 +1018,21 @@ gui_buffer_print_log () log_printf (" notify_level . . . . . : %d", ptr_buffer->notify_level); log_printf (" num_displayed. . . . . : %d", ptr_buffer->num_displayed); log_printf (" title. . . . . . . . . : '%s'", ptr_buffer->title); - log_printf (" lines. . . . . . . . . : 0x%X", ptr_buffer->lines); - log_printf (" last_line. . . . . . . : 0x%X", ptr_buffer->last_line); - log_printf (" last_read_line . . . . : 0x%X", ptr_buffer->last_read_line); + log_printf (" lines. . . . . . . . . : 0x%x", ptr_buffer->lines); + log_printf (" last_line. . . . . . . : 0x%x", ptr_buffer->last_line); + log_printf (" last_read_line . . . . : 0x%x", ptr_buffer->last_read_line); log_printf (" lines_count. . . . . . : %d", ptr_buffer->lines_count); log_printf (" prefix_max_length. . . : %d", ptr_buffer->prefix_max_length); log_printf (" chat_refresh_needed. . : %d", ptr_buffer->chat_refresh_needed); log_printf (" nicklist . . . . . . . : %d", ptr_buffer->nicklist); log_printf (" nicklist_case_sensitive: %d", ptr_buffer->nicklist_case_sensitive); - log_printf (" nicklist_root. . . . . : 0x%X", ptr_buffer->nicklist_root); + log_printf (" nicklist_root. . . . . : 0x%x", ptr_buffer->nicklist_root); log_printf (" nicklist_max_length. . : %d", ptr_buffer->nicklist_max_length); log_printf (" nicklist_display_groups: %d", ptr_buffer->nicklist_display_groups); log_printf (" nicklist_visible_count.: %d", ptr_buffer->nicklist_visible_count); log_printf (" nicklist_refresh_needed: %d", ptr_buffer->nicklist_refresh_needed); log_printf (" input. . . . . . . . . : %d", ptr_buffer->input); - log_printf (" input_data_cb. . . . . : 0x%X", ptr_buffer->input_data_cb); + log_printf (" input_data_cb. . . . . : 0x%x", ptr_buffer->input_data_cb); log_printf (" input_nick . . . . . . : '%s'", ptr_buffer->input_nick); log_printf (" input_buffer . . . . . : '%s'", ptr_buffer->input_buffer); log_printf (" input_buffer_color_mask: '%s'", ptr_buffer->input_buffer_color_mask); @@ -1039,20 +1041,20 @@ gui_buffer_print_log () log_printf (" input_buffer_length. . : %d", ptr_buffer->input_buffer_length); log_printf (" input_buffer_pos . . . : %d", ptr_buffer->input_buffer_pos); log_printf (" input_buffer_1st_disp. : %d", ptr_buffer->input_buffer_1st_display); - log_printf (" completion . . . . . . : 0x%X", ptr_buffer->completion); - log_printf (" history. . . . . . . . : 0x%X", ptr_buffer->history); - log_printf (" last_history . . . . . : 0x%X", ptr_buffer->last_history); - log_printf (" ptr_history. . . . . . : 0x%X", ptr_buffer->ptr_history); + log_printf (" completion . . . . . . : 0x%x", ptr_buffer->completion); + log_printf (" history. . . . . . . . : 0x%x", ptr_buffer->history); + log_printf (" last_history . . . . . : 0x%x", ptr_buffer->last_history); + log_printf (" ptr_history. . . . . . : 0x%x", ptr_buffer->ptr_history); log_printf (" num_history. . . . . . : %d", ptr_buffer->num_history); log_printf (" text_search. . . . . . : %d", ptr_buffer->text_search); log_printf (" text_search_exact. . . : %d", ptr_buffer->text_search_exact); log_printf (" text_search_found. . . : %d", ptr_buffer->text_search_found); log_printf (" text_search_input. . . : '%s'", ptr_buffer->text_search_input); - log_printf (" prev_buffer. . . . . . : 0x%X", ptr_buffer->prev_buffer); - log_printf (" next_buffer. . . . . . : 0x%X", ptr_buffer->next_buffer); + log_printf (" prev_buffer. . . . . . : 0x%x", ptr_buffer->prev_buffer); + log_printf (" next_buffer. . . . . . : 0x%x", ptr_buffer->next_buffer); log_printf (""); - log_printf (" => nicklist_root (addr:0x%X):", ptr_buffer->nicklist_root); + log_printf (" => nicklist_root (addr:0x%x):", ptr_buffer->nicklist_root); gui_nicklist_print_log (ptr_buffer->nicklist_root, 0); log_printf (""); diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c index bef3970c7..fde152aef 100644 --- a/src/gui/gui-completion.c +++ b/src/gui/gui-completion.c @@ -256,7 +256,7 @@ gui_completion_list_add_buffers_names (struct t_gui_completion *completion) ptr_buffer = ptr_buffer->next_buffer) { gui_completion_list_add (completion, ptr_buffer->name, - 0, WEELIST_POS_SORT); + 0, WEECHAT_LIST_POS_SORT); } } @@ -274,7 +274,7 @@ gui_completion_list_add_buffers_categories (struct t_gui_completion *completion) ptr_buffer = ptr_buffer->next_buffer) { gui_completion_list_add (completion, ptr_buffer->category, - 0, WEELIST_POS_SORT); + 0, WEECHAT_LIST_POS_SORT); } } @@ -359,7 +359,7 @@ gui_completion_list_add_filename (struct t_gui_completion *completion) S_ISDIR(statbuf.st_mode) ? DIR_SEPARATOR : ""); gui_completion_list_add (completion, buffer, - 0, WEELIST_POS_SORT); + 0, WEECHAT_LIST_POS_SORT); } } } @@ -389,7 +389,7 @@ gui_completion_list_add_command_hooks (struct t_gui_completion *completion) && (HOOK_COMMAND(ptr_hook, command)[0])) gui_completion_list_add (completion, HOOK_COMMAND(ptr_hook, command), - 0, WEELIST_POS_SORT); + 0, WEECHAT_LIST_POS_SORT); } } @@ -406,7 +406,7 @@ gui_completion_list_add_key_cmd (struct t_gui_completion *completion) for (i = 0; gui_key_functions[i].function_name; i++) { gui_completion_list_add (completion, gui_key_functions[i].function_name, - 0, WEELIST_POS_SORT); + 0, WEECHAT_LIST_POS_SORT); } } @@ -420,7 +420,7 @@ gui_completion_list_add_self_nick (struct t_gui_completion *completion) if (completion->buffer->input_nick) gui_completion_list_add (completion, completion->buffer->input_nick, - 0, WEELIST_POS_SORT); + 0, WEECHAT_LIST_POS_SORT); } /* @@ -441,7 +441,7 @@ gui_completion_list_add_option (struct t_gui_completion *completion) { gui_completion_list_add (completion, ptr_option->name, - 0, WEELIST_POS_SORT); + 0, WEECHAT_LIST_POS_SORT); } } } @@ -459,7 +459,7 @@ gui_completion_list_add_plugin_option (struct t_gui_completion *completion) ptr_option = ptr_option->next_option) { gui_completion_list_add (completion, ptr_option->name, - 0, WEELIST_POS_SORT); + 0, WEECHAT_LIST_POS_SORT); } } @@ -476,7 +476,7 @@ gui_completion_list_add_plugin (struct t_gui_completion *completion) ptr_plugin = ptr_plugin->next_plugin) { gui_completion_list_add (completion, ptr_plugin->name, - 0, WEELIST_POS_SORT); + 0, WEECHAT_LIST_POS_SORT); } } @@ -491,7 +491,7 @@ gui_completion_list_add_quit (struct t_gui_completion *completion) && CONFIG_STRING(config_look_default_msg_quit)[0]) gui_completion_list_add (completion, CONFIG_STRING(config_look_default_msg_quit), - 0, WEELIST_POS_SORT); + 0, WEECHAT_LIST_POS_SORT); } /* @@ -519,10 +519,10 @@ gui_completion_list_add_option_value (struct t_gui_completion *completion) case CONFIG_OPTION_BOOLEAN: if (CONFIG_BOOLEAN(ptr_option) == CONFIG_BOOLEAN_TRUE) gui_completion_list_add (completion, "on", - 0, WEELIST_POS_SORT); + 0, WEECHAT_LIST_POS_SORT); else gui_completion_list_add (completion, "off", - 0, WEELIST_POS_SORT); + 0, WEECHAT_LIST_POS_SORT); break; case CONFIG_OPTION_INTEGER: if (ptr_option->string_values) @@ -533,21 +533,21 @@ gui_completion_list_add_option_value (struct t_gui_completion *completion) snprintf (option_string, sizeof (option_string) - 1, "%d", CONFIG_INTEGER(ptr_option)); gui_completion_list_add (completion, option_string, - 0, WEELIST_POS_SORT); + 0, WEECHAT_LIST_POS_SORT); break; case CONFIG_OPTION_STRING: snprintf (option_string, sizeof (option_string) - 1, "\"%s\"", CONFIG_STRING(ptr_option)); gui_completion_list_add (completion, option_string, - 0, WEELIST_POS_SORT); + 0, WEECHAT_LIST_POS_SORT); break; case CONFIG_OPTION_COLOR: color_name = gui_color_get_name (CONFIG_INTEGER(ptr_option)); if (color_name) gui_completion_list_add (completion, color_name, - 0, WEELIST_POS_SORT); + 0, WEECHAT_LIST_POS_SORT); break; } } @@ -575,7 +575,7 @@ gui_completion_list_add_plugin_option_value (struct t_gui_completion *completion ptr_option = plugin_config_search_internal (completion->args); if (ptr_option) gui_completion_list_add (completion, ptr_option->value, - 0, WEELIST_POS_SORT); + 0, WEECHAT_LIST_POS_SORT); if (pos) pos[0] = ' '; @@ -601,7 +601,7 @@ gui_completion_list_add_weechat_cmd (struct t_gui_completion *completion) { gui_completion_list_add (completion, HOOK_COMMAND(ptr_hook, command), - 0, WEELIST_POS_SORT); + 0, WEECHAT_LIST_POS_SORT); } } } @@ -647,7 +647,7 @@ gui_completion_build_list_template (struct t_gui_completion *completion, { word[word_offset] = '\0'; weelist_add (completion->completion_list, - word, WEELIST_POS_SORT); + word, WEECHAT_LIST_POS_SORT); } word_offset = 0; break; @@ -948,7 +948,7 @@ gui_completion_command (struct t_gui_completion *completion) { gui_completion_list_add (completion, HOOK_COMMAND(ptr_hook, command), - 0, WEELIST_POS_SORT); + 0, WEECHAT_LIST_POS_SORT); } } } @@ -1108,10 +1108,10 @@ gui_completion_nick (struct t_gui_completion *completion) { weelist_add (completion->completion_list, ((t_irc_channel *)(completion->channel))->name, - WEELIST_POS_SORT); + WEECHAT_LIST_POS_SORT); weelist_add (completion->completion_list, ((t_irc_server *)(completion->server))->nick, - WEELIST_POS_SORT); + WEECHAT_LIST_POS_SORT); } gui_completion_command_arg (completion, 1); return; @@ -1135,7 +1135,7 @@ gui_completion_nick (struct t_gui_completion *completion) { weelist_add (completion->completion_list, ptr_nick->nick, - WEELIST_POS_SORT); + WEECHAT_LIST_POS_SORT); } // add nicks speaking recently on this channel @@ -1148,7 +1148,7 @@ gui_completion_nick (struct t_gui_completion *completion) ptr_item->data)) weelist_add (completion->completion_list, ptr_item->data, - WEELIST_POS_BEGINNING); + WEECHAT_LIST_POS_BEGINNING); } } @@ -1156,7 +1156,7 @@ gui_completion_nick (struct t_gui_completion *completion) if (completion->server) weelist_add (completion->completion_list, ((t_irc_server *)(completion->server))->nick, - WEELIST_POS_END); + WEECHAT_LIST_POS_END); ((t_irc_channel *)(completion->channel))->nick_completion_reset = 0; } @@ -1343,8 +1343,8 @@ gui_completion_search (struct t_gui_completion *completion, int direction, void gui_completion_print_log (struct t_gui_completion *completion) { - log_printf ("[completion (addr:0x%X)]", completion); - log_printf (" buffer . . . . . . . . : 0x%X", completion->buffer); + log_printf ("[completion (addr:0x%x)]", completion); + log_printf (" buffer . . . . . . . . : 0x%x", completion->buffer); log_printf (" context. . . . . . . . : %d", completion->context); log_printf (" base_command . . . . . : '%s'", completion->base_command); log_printf (" base_command_arg . . . : %d", completion->base_command_arg); @@ -1355,7 +1355,7 @@ gui_completion_print_log (struct t_gui_completion *completion) log_printf (" args . . . . . . . . . : '%s'", completion->args); log_printf (" direction. . . . . . . : %d", completion->direction); log_printf (" add_space. . . . . . . : %d", completion->add_space); - log_printf (" completion_list. . . . : 0x%X", completion->completion_list); + log_printf (" completion_list. . . . : 0x%x", completion->completion_list); log_printf (" word_found . . . . . . : '%s'", completion->word_found); log_printf (" position_replace . . . : %d", completion->position_replace); log_printf (" diff_size. . . . . . . : %d", completion->diff_size); diff --git a/src/gui/gui-hotlist.c b/src/gui/gui-hotlist.c index 5843236e2..a24adec88 100644 --- a/src/gui/gui-hotlist.c +++ b/src/gui/gui-hotlist.c @@ -355,13 +355,13 @@ gui_hotlist_print_log () for (ptr_hotlist = gui_hotlist; ptr_hotlist; ptr_hotlist = ptr_hotlist->next_hotlist) { - log_printf ("[hotlist (addr:0x%X)]", ptr_hotlist); + log_printf ("[hotlist (addr:0x%x)]", ptr_hotlist); log_printf (" priority . . . . . . . : %d", ptr_hotlist->priority); log_printf (" creation_time. . . . . : tv_sec:%d, tv_usec:%d", ptr_hotlist->creation_time.tv_sec, ptr_hotlist->creation_time.tv_usec); - log_printf (" buffer . . . . . . . . : 0x%X", ptr_hotlist->buffer); - log_printf (" prev_hotlist . . . . . : 0x%X", ptr_hotlist->prev_hotlist); - log_printf (" next_hotlist . . . . . : 0x%X", ptr_hotlist->next_hotlist); + log_printf (" buffer . . . . . . . . : 0x%x", ptr_hotlist->buffer); + log_printf (" prev_hotlist . . . . . : 0x%x", ptr_hotlist->prev_hotlist); + log_printf (" next_hotlist . . . . . : 0x%x", ptr_hotlist->next_hotlist); } } diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c index 33f8edb66..a07329d82 100644 --- a/src/gui/gui-window.c +++ b/src/gui/gui-window.c @@ -772,12 +772,12 @@ gui_window_print_log () struct t_gui_window *ptr_window; log_printf (""); - log_printf ("current window = 0x%X", gui_current_window); + log_printf ("current window = 0x%x", gui_current_window); for (ptr_window = gui_windows; ptr_window; ptr_window = ptr_window->next_window) { log_printf (""); - log_printf ("[window (addr:0x%X)]", ptr_window); + log_printf ("[window (addr:0x%x)]", ptr_window); log_printf (" win_x . . . . . . . : %d", ptr_window->win_x); log_printf (" win_y . . . . . . . : %d", ptr_window->win_y); log_printf (" win_width . . . . . : %d", ptr_window->win_width); @@ -814,14 +814,14 @@ gui_window_print_log () log_printf (" win_input_height. . : %d", ptr_window->win_input_height); log_printf (" win_input_cursor_x. : %d", ptr_window->win_input_cursor_x); gui_window_objects_print_log (ptr_window); - log_printf (" dcc_first . . . . . : 0x%X", ptr_window->dcc_first); - log_printf (" dcc_selected. . . . : 0x%X", ptr_window->dcc_selected); - log_printf (" dcc_last_displayed. : 0x%X", ptr_window->dcc_last_displayed); - log_printf (" buffer. . . . . . . : 0x%X", ptr_window->buffer); + log_printf (" dcc_first . . . . . : 0x%x", ptr_window->dcc_first); + log_printf (" dcc_selected. . . . : 0x%x", ptr_window->dcc_selected); + log_printf (" dcc_last_displayed. : 0x%x", ptr_window->dcc_last_displayed); + log_printf (" buffer. . . . . . . : 0x%x", ptr_window->buffer); log_printf (" first_line_displayed: %d", ptr_window->first_line_displayed); - log_printf (" start_line. . . . . : 0x%X", ptr_window->start_line); + log_printf (" start_line. . . . . : 0x%x", ptr_window->start_line); log_printf (" start_line_pos. . . : %d", ptr_window->start_line_pos); - log_printf (" prev_window . . . . : 0x%X", ptr_window->prev_window); - log_printf (" next_window . . . . : 0x%X", ptr_window->next_window); + log_printf (" prev_window . . . . : 0x%x", ptr_window->prev_window); + log_printf (" next_window . . . . : 0x%x", ptr_window->next_window); } } diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c index 128df444c..bce60d65f 100644 --- a/src/plugins/alias/alias.c +++ b/src/plugins/alias/alias.c @@ -542,11 +542,13 @@ alias_config_read () */ int -alias_config_reload_signal_cb (void *data, char *signal, void *signal_data) +alias_config_reload_signal_cb (void *data, char *signal, char *type_data, + void *signal_data) { /* make C compiler happy */ (void) data; (void) signal; + (void) type_data; (void) signal_data; alias_free_all (); diff --git a/src/plugins/demo/demo.c b/src/plugins/demo/demo.c index e65bfd533..fb99f86b1 100644 --- a/src/plugins/demo/demo.c +++ b/src/plugins/demo/demo.c @@ -134,7 +134,8 @@ demo_buffer_command_cb (void *data, struct t_gui_buffer *buffer, int argc, demo_buffer_input_data_cb); if (new_buffer) weechat_buffer_set (new_buffer, "display", "1"); - weechat_hook_signal_send ("logger_backlog", new_buffer); + weechat_hook_signal_send ("logger_backlog", + WEECHAT_HOOK_SIGNAL_POINTER, new_buffer); } return WEECHAT_RC_OK; @@ -281,14 +282,39 @@ demo_info_command_cb (void *data, struct t_gui_buffer *buffer, int argc, */ int -demo_signal_cb (void *data, char *signal, void *signal_data) +demo_signal_cb (void *data, char *signal, char *type_data, void *signal_data) { /* make C compiler happy */ (void) data; - weechat_printf (NULL, - _("demo_signal: signal: %s, signal_data: %X"), - signal, signal_data); + if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) + { + weechat_printf (NULL, + _("demo_signal: signal: %s, type_data: %s, " + "signal_data: '%s'"), + signal, type_data, (char *)signal_data); + } + else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0) + { + weechat_printf (NULL, + _("demo_signal: signal: %s, type_data: %s, " + "signal_data: %d"), + signal, type_data, *((int *)signal_data)); + } + else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0) + { + weechat_printf (NULL, + _("demo_signal: signal: %s, type_data: %s, " + "signal_data: 0x%x"), + signal, type_data, signal_data); + } + else + { + weechat_printf (NULL, + _("demo_signal: signal: %s, type_data: %s, " + "signal_data: 0x%x (unknown type)"), + signal, type_data, signal_data); + } return WEECHAT_RC_OK; } diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index d501aa8d5..b75e9102a 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -27,6 +27,7 @@ #include <unistd.h> #include <string.h> +#include "../weechat-plugin.h" #include "irc.h" #include "irc-channel.h" #include "irc-config.h" @@ -495,9 +496,9 @@ irc_channel_print_log (struct t_irc_channel *channel) struct t_irc_nick *ptr_nick; weechat_log_printf (""); - weechat_log_printf (" => channel %s (addr:0x%X)]", channel->name, channel); + weechat_log_printf (" => channel %s (addr:0x%x)]", channel->name, channel); weechat_log_printf (" type . . . . . . . . : %d", channel->type); - weechat_log_printf (" dcc_chat . . . . . . : 0x%X", channel->dcc_chat); + weechat_log_printf (" dcc_chat . . . . . . : 0x%x", channel->dcc_chat); weechat_log_printf (" topic. . . . . . . . : '%s'", channel->topic); weechat_log_printf (" modes. . . . . . . . : '%s'", channel->modes); weechat_log_printf (" limit. . . . . . . . : %d", channel->limit); @@ -507,12 +508,12 @@ irc_channel_print_log (struct t_irc_channel *channel) weechat_log_printf (" cycle. . . . . . . . : %d", channel->cycle); weechat_log_printf (" close. . . . . . . . : %d", channel->close); weechat_log_printf (" display_creation_date: %d", channel->display_creation_date); - weechat_log_printf (" nicks. . . . . . . . : 0x%X", channel->nicks); - weechat_log_printf (" last_nick. . . . . . : 0x%X", channel->last_nick); - weechat_log_printf (" buffer . . . . . . . : 0x%X", channel->buffer); - weechat_log_printf (" nicks_speaking . . . : 0x%X", channel->nicks_speaking); - weechat_log_printf (" prev_channel . . . . : 0x%X", channel->prev_channel); - weechat_log_printf (" next_channel . . . . : 0x%X", channel->next_channel); + weechat_log_printf (" nicks. . . . . . . . : 0x%x", channel->nicks); + weechat_log_printf (" last_nick. . . . . . : 0x%x", channel->last_nick); + weechat_log_printf (" buffer . . . . . . . : 0x%x", channel->buffer); + weechat_log_printf (" nicks_speaking . . . : 0x%x", channel->nicks_speaking); + weechat_log_printf (" prev_channel . . . . : 0x%x", channel->prev_channel); + weechat_log_printf (" next_channel . . . . : 0x%x", channel->next_channel); if (channel->nicks_speaking) { weechat_log_printf (""); diff --git a/src/plugins/irc/irc-color.c b/src/plugins/irc/irc-color.c index 947b056fd..b8912edb6 100644 --- a/src/plugins/irc/irc-color.c +++ b/src/plugins/irc/irc-color.c @@ -27,6 +27,7 @@ #include <string.h> #include <ctype.h> +#include "../weechat-plugin.h" #include "irc.h" #include "irc-color.h" diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index 0bb4ad114..859c180c5 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -30,6 +30,7 @@ #include <sys/time.h> #include <time.h> +#include "../weechat-plugin.h" #include "irc.h" #include "irc-command.h" #include "irc-color.h" diff --git a/src/plugins/irc/irc-completion.c b/src/plugins/irc/irc-completion.c index b86cc6440..773a4f2f8 100644 --- a/src/plugins/irc/irc-completion.c +++ b/src/plugins/irc/irc-completion.c @@ -27,6 +27,7 @@ #include <stdio.h> #include <string.h> +#include "../weechat-plugin.h" #include "irc.h" #include "irc-completion.h" #include "irc-config.h" diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index 3c25788d8..f163e84a9 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -29,6 +29,7 @@ #include <limits.h> #include <pwd.h> +#include "../weechat-plugin.h" #include "irc.h" #include "irc-config.h" #include "irc-dcc.h" diff --git a/src/plugins/irc/irc-dcc.c b/src/plugins/irc/irc-dcc.c index e8157ae18..020e1be30 100644 --- a/src/plugins/irc/irc-dcc.c +++ b/src/plugins/irc/irc-dcc.c @@ -39,6 +39,7 @@ #include <arpa/inet.h> #include <netdb.h> +#include "../weechat-plugin.h" #include "irc.h" #include "irc-dcc.h" #include "irc-config.h" @@ -1899,9 +1900,9 @@ irc_dcc_print_log () for (ptr_dcc = irc_dcc_list; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc) { weechat_log_printf (""); - weechat_log_printf ("[DCC (addr:0x%X)]", ptr_dcc); - weechat_log_printf (" server. . . . . . . : 0x%X", ptr_dcc->server); - weechat_log_printf (" channel . . . . . . : 0x%X", ptr_dcc->channel); + weechat_log_printf ("[DCC (addr:0x%x)]", ptr_dcc); + weechat_log_printf (" server. . . . . . . : 0x%x", ptr_dcc->server); + weechat_log_printf (" channel . . . . . . : 0x%x", ptr_dcc->channel); weechat_log_printf (" type. . . . . . . . : %d", ptr_dcc->type); weechat_log_printf (" status. . . . . . . : %d", ptr_dcc->status); weechat_log_printf (" start_time. . . . . : %ld", ptr_dcc->start_time); @@ -1929,7 +1930,7 @@ irc_dcc_print_log () weechat_log_printf (" last_activity . . . : %ld", ptr_dcc->last_activity); weechat_log_printf (" bytes_per_sec . . . : %lu", ptr_dcc->bytes_per_sec); weechat_log_printf (" eta . . . . . . . . : %lu", ptr_dcc->eta); - weechat_log_printf (" prev_dcc. . . . . . : 0x%X", ptr_dcc->prev_dcc); - weechat_log_printf (" next_dcc. . . . . . : 0x%X", ptr_dcc->next_dcc); + weechat_log_printf (" prev_dcc. . . . . . : 0x%x", ptr_dcc->prev_dcc); + weechat_log_printf (" next_dcc. . . . . . : 0x%x", ptr_dcc->next_dcc); } } diff --git a/src/plugins/irc/irc-display.c b/src/plugins/irc/irc-display.c index 9378136fe..fd869b009 100644 --- a/src/plugins/irc/irc-display.c +++ b/src/plugins/irc/irc-display.c @@ -28,6 +28,7 @@ #include <stdio.h> #include <string.h> +#include "../weechat-plugin.h" #include "irc.h" #include "irc-channel.h" #include "irc-command.h" diff --git a/src/plugins/irc/irc-input.c b/src/plugins/irc/irc-input.c index bf3e40b8e..72e37a6f6 100644 --- a/src/plugins/irc/irc-input.c +++ b/src/plugins/irc/irc-input.c @@ -26,6 +26,7 @@ #include <stdlib.h> #include <string.h> +#include "../weechat-plugin.h" #include "irc.h" #include "irc-server.h" #include "irc-channel.h" diff --git a/src/plugins/irc/irc-mode.c b/src/plugins/irc/irc-mode.c index 1d6f66eb3..34c17d1e8 100644 --- a/src/plugins/irc/irc-mode.c +++ b/src/plugins/irc/irc-mode.c @@ -26,6 +26,7 @@ #include <stdlib.h> #include <string.h> +#include "../weechat-plugin.h" #include "irc.h" #include "irc-mode.h" #include "irc-server.h" diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c index e24ab7aaa..6cf854ea4 100644 --- a/src/plugins/irc/irc-nick.c +++ b/src/plugins/irc/irc-nick.c @@ -28,6 +28,7 @@ #include <string.h> #include <limits.h> +#include "../weechat-plugin.h" #include "irc.h" #include "irc-nick.h" #include "irc-config.h" @@ -470,10 +471,10 @@ void irc_nick_print_log (struct t_irc_nick *nick) { weechat_log_printf (""); - weechat_log_printf (" => nick %s (addr:0x%X):", nick->name, nick); + weechat_log_printf (" => nick %s (addr:0x%x):", nick->name, nick); weechat_log_printf (" host . . . . . : %s", nick->host); weechat_log_printf (" flags. . . . . : %d", nick->flags); weechat_log_printf (" color. . . . . : '%s'", nick->color); - weechat_log_printf (" prev_nick. . . : 0x%X", nick->prev_nick); - weechat_log_printf (" next_nick. . . : 0x%X", nick->next_nick); + weechat_log_printf (" prev_nick. . . : 0x%x", nick->prev_nick); + weechat_log_printf (" next_nick. . . : 0x%x", nick->next_nick); } diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 424b3c0d2..07c3f0f46 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -43,6 +43,7 @@ #include <sys/time.h> #include <time.h> +#include "../weechat-plugin.h" #include "irc.h" #include "irc-protocol.h" #include "irc-command.h" diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index 9ac403326..953e650f7 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -44,6 +44,7 @@ #include <gnutls/gnutls.h> #endif +#include "../weechat-plugin.h" #include "irc.h" #include "irc-server.h" #include "irc-channel.h" @@ -2187,7 +2188,8 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin) if (!server->buffer) return 0; weechat_buffer_set (server->buffer, "display", "1"); - weechat_hook_signal_send ("logger_backlog", server->buffer); + weechat_hook_signal_send ("logger_backlog", + WEECHAT_HOOK_SIGNAL_POINTER, server->buffer); } #ifndef HAVE_GNUTLS @@ -2733,7 +2735,7 @@ irc_server_print_log () ptr_server = ptr_server->next_server) { weechat_log_printf (""); - weechat_log_printf ("[server %s (addr:0x%X)]", ptr_server->name, ptr_server); + weechat_log_printf ("[server %s (addr:0x%x)]", ptr_server->name, ptr_server); weechat_log_printf (" autoconnect . . . . : %d", ptr_server->autoconnect); weechat_log_printf (" autoreconnect . . . : %d", ptr_server->autoreconnect); weechat_log_printf (" autoreconnect_delay : %d", ptr_server->autoreconnect_delay); @@ -2762,7 +2764,7 @@ irc_server_print_log () weechat_log_printf (" child_read . . . . : %d", ptr_server->child_read); weechat_log_printf (" child_write . . . . : %d", ptr_server->child_write); weechat_log_printf (" sock. . . . . . . . : %d", ptr_server->sock); - weechat_log_printf (" hook_fd . . . . . . : 0x%X", ptr_server->hook_fd); + weechat_log_printf (" hook_fd . . . . . . : 0x%x", ptr_server->hook_fd); weechat_log_printf (" is_connected. . . . : %d", ptr_server->is_connected); weechat_log_printf (" ssl_connected . . . : %d", ptr_server->ssl_connected); weechat_log_printf (" unterminated_message: '%s'", ptr_server->unterminated_message); @@ -2782,13 +2784,13 @@ irc_server_print_log () ptr_server->lag_check_time.tv_usec); weechat_log_printf (" lag_next_check. . . : %ld", ptr_server->lag_next_check); weechat_log_printf (" last_user_message . : %ld", ptr_server->last_user_message); - weechat_log_printf (" outqueue. . . . . . : 0x%X", ptr_server->outqueue); - weechat_log_printf (" last_outqueue . . . : 0x%X", ptr_server->last_outqueue); - weechat_log_printf (" buffer. . . . . . . : 0x%X", ptr_server->buffer); - weechat_log_printf (" channels. . . . . . : 0x%X", ptr_server->channels); - weechat_log_printf (" last_channel. . . . : 0x%X", ptr_server->last_channel); - weechat_log_printf (" prev_server . . . . : 0x%X", ptr_server->prev_server); - weechat_log_printf (" next_server . . . . : 0x%X", ptr_server->next_server); + weechat_log_printf (" outqueue. . . . . . : 0x%x", ptr_server->outqueue); + weechat_log_printf (" last_outqueue . . . : 0x%x", ptr_server->last_outqueue); + weechat_log_printf (" buffer. . . . . . . : 0x%x", ptr_server->buffer); + weechat_log_printf (" channels. . . . . . : 0x%x", ptr_server->channels); + weechat_log_printf (" last_channel. . . . : 0x%x", ptr_server->last_channel); + weechat_log_printf (" prev_server . . . . : 0x%x", ptr_server->prev_server); + weechat_log_printf (" next_server . . . . : 0x%x", ptr_server->next_server); for (ptr_channel = ptr_server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) diff --git a/src/plugins/irc/irc.c b/src/plugins/irc/irc.c index 31cec28a2..d04bd7a03 100644 --- a/src/plugins/irc/irc.c +++ b/src/plugins/irc/irc.c @@ -24,11 +24,13 @@ #endif #include <stdlib.h> +#include <string.h> #ifdef HAVE_GNUTLS #include <gnutls/gnutls.h> #endif +#include "../weechat-plugin.h" #include "irc.h" #include "irc-command.h" #include "irc-completion.h" @@ -62,12 +64,13 @@ gnutls_certificate_credentials gnutls_xcred; /* gnutls client credentials */ */ int -irc_dump_data_cb (void *data, char *signal, void *pointer) +irc_dump_data_cb (void *data, char *signal, char *type_data, void *signal_data) { /* make C compiler happy */ (void) data; (void) signal; - (void) pointer; + (void) type_data; + (void) signal_data; weechat_log_printf (""); weechat_log_printf ("***** IRC plugin dump *****"); @@ -112,19 +115,21 @@ irc_create_directories () */ int -irc_quit_cb (void *data, char *signal, void *pointer) +irc_quit_cb (void *data, char *signal, char *type_data, void *signal_data) { struct t_irc_server *ptr_server; /* make C compiler happy */ (void) data; (void) signal; - (void) pointer; - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) + if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) { - irc_command_quit_server (ptr_server, (char *)pointer); + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + irc_command_quit_server (ptr_server, (char *)signal_data); + } } return WEECHAT_RC_OK; @@ -135,14 +140,17 @@ irc_quit_cb (void *data, char *signal, void *pointer) */ int -irc_debug_cb (void *data, char *signal, void *pointer) +irc_debug_cb (void *data, char *signal, char *type_data, void *signal_data) { /* make C compiler happy */ (void) data; (void) signal; - - if (weechat_strcasecmp ((char *)pointer, "irc") == 0) - irc_debug ^= 1; + + if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) + { + if (weechat_strcasecmp ((char *)signal_data, "irc") == 0) + irc_debug ^= 1; + } return WEECHAT_RC_OK; } diff --git a/src/plugins/irc/irc.h b/src/plugins/irc/irc.h index 1c5effa4f..3c458fd3c 100644 --- a/src/plugins/irc/irc.h +++ b/src/plugins/irc/irc.h @@ -24,8 +24,6 @@ #include <gnutls/gnutls.h> #endif -#include "../weechat-plugin.h" - #define weechat_plugin weechat_irc_plugin #define IRC_GET_SERVER(__buffer) \ diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c index 379c0482a..3c82642ce 100644 --- a/src/plugins/logger/logger.c +++ b/src/plugins/logger/logger.c @@ -409,14 +409,15 @@ logger_stop_all () */ int -logger_buffer_open_signal_cb (void *data, char *signal, void *pointer) +logger_buffer_open_signal_cb (void *data, char *signal, char *type_data, + void *signal_data) { /* make C compiler happy */ (void) data; (void) signal; - (void) pointer; + (void) type_data; - logger_start_buffer (pointer); + logger_start_buffer (signal_data); return WEECHAT_RC_OK; } @@ -426,14 +427,15 @@ logger_buffer_open_signal_cb (void *data, char *signal, void *pointer) */ int -logger_buffer_close_signal_cb (void *data, char *signal, void *pointer) +logger_buffer_close_signal_cb (void *data, char *signal, char *type_data, + void *signal_data) { /* make C compiler happy */ (void) data; (void) signal; - (void) pointer; + (void) type_data; - logger_stop (logger_buffer_search (pointer), 1); + logger_stop (logger_buffer_search (signal_data), 1); return WEECHAT_RC_OK; } @@ -494,23 +496,25 @@ logger_backlog (struct t_gui_buffer *buffer, char *filename, int lines) */ int -logger_backlog_signal_cb (void *data, char *signal, void *pointer) +logger_backlog_signal_cb (void *data, char *signal, char *type_data, + void *signal_data) { struct t_logger_buffer *ptr_logger_buffer; /* make C compiler happy */ (void) data; (void) signal; + (void) type_data; if (logger_option_backlog >= 0) { - ptr_logger_buffer = logger_buffer_search (pointer); + ptr_logger_buffer = logger_buffer_search (signal_data); if (ptr_logger_buffer && ptr_logger_buffer->log_filename && ptr_logger_buffer->log_enabled) { ptr_logger_buffer->log_enabled = 0; - logger_backlog (pointer, + logger_backlog (signal_data, ptr_logger_buffer->log_filename, logger_option_backlog); @@ -526,13 +530,15 @@ logger_backlog_signal_cb (void *data, char *signal, void *pointer) */ int -logger_start_signal_cb (void *data, char *signal, void *pointer) +logger_start_signal_cb (void *data, char *signal, char *type_data, + void *signal_data) { /* make C compiler happy */ (void) data; (void) signal; + (void) type_data; - logger_start_buffer (pointer); + logger_start_buffer (signal_data); return WEECHAT_RC_OK; } @@ -542,15 +548,17 @@ logger_start_signal_cb (void *data, char *signal, void *pointer) */ int -logger_stop_signal_cb (void *data, char *signal, void *pointer) +logger_stop_signal_cb (void *data, char *signal, char *type_data, + void *signal_data) { struct t_logger_buffer *ptr_logger_buffer; /* make C compiler happy */ (void) data; (void) signal; + (void) type_data; - ptr_logger_buffer = logger_buffer_search (pointer); + ptr_logger_buffer = logger_buffer_search (signal_data); if (ptr_logger_buffer) logger_stop (ptr_logger_buffer, 0); diff --git a/src/plugins/plugin-infolist.c b/src/plugins/plugin-infolist.c index 36d34b4bb..cebdc6e87 100644 --- a/src/plugins/plugin-infolist.c +++ b/src/plugins/plugin-infolist.c @@ -561,28 +561,28 @@ plugin_infolist_print_log () ptr_infolist = ptr_infolist->next_infolist) { log_printf (""); - log_printf ("[plugin infolist (addr:0x%X)]", ptr_infolist); - log_printf (" items. . . . . . . . . : 0x%X", ptr_infolist->items); - log_printf (" last_item. . . . . . . : 0x%X", ptr_infolist->last_item); - log_printf (" ptr_item . . . . . . . : 0x%X", ptr_infolist->ptr_item); - log_printf (" prev_infolist. . . . . : 0x%X", ptr_infolist->prev_infolist); - log_printf (" next_infolist. . . . . : 0x%X", ptr_infolist->next_infolist); + log_printf ("[plugin infolist (addr:0x%x)]", ptr_infolist); + log_printf (" items. . . . . . . . . : 0x%x", ptr_infolist->items); + log_printf (" last_item. . . . . . . : 0x%x", ptr_infolist->last_item); + log_printf (" ptr_item . . . . . . . : 0x%x", ptr_infolist->ptr_item); + log_printf (" prev_infolist. . . . . : 0x%x", ptr_infolist->prev_infolist); + log_printf (" next_infolist. . . . . : 0x%x", ptr_infolist->next_infolist); for (ptr_item = ptr_infolist->items; ptr_item; ptr_item = ptr_item->next_item) { log_printf (""); - log_printf (" [item (addr:0x%X)]", ptr_item); - log_printf (" vars . . . . . . . . . : 0x%X", ptr_item->vars); - log_printf (" last_var . . . . . . . : 0x%X", ptr_item->last_var); - log_printf (" prev_item. . . . . . . : 0x%X", ptr_item->prev_item); - log_printf (" next_item. . . . . . . : 0x%X", ptr_item->next_item); + log_printf (" [item (addr:0x%x)]", ptr_item); + log_printf (" vars . . . . . . . . . : 0x%x", ptr_item->vars); + log_printf (" last_var . . . . . . . : 0x%x", ptr_item->last_var); + log_printf (" prev_item. . . . . . . : 0x%x", ptr_item->prev_item); + log_printf (" next_item. . . . . . . : 0x%x", ptr_item->next_item); for (ptr_var = ptr_item->vars; ptr_var; ptr_var = ptr_var->next_var) { log_printf (""); - log_printf (" [var (addr:0x%X)]", ptr_var); + log_printf (" [var (addr:0x%x)]", ptr_var); log_printf (" name . . . . . . . . : '%s'", ptr_var->name); log_printf (" type . . . . . . . . : %d", ptr_var->type); switch (ptr_var->type) @@ -594,14 +594,14 @@ plugin_infolist_print_log () log_printf (" value (string) . . . : '%s'", (char *)ptr_var->value); break; case PLUGIN_INFOLIST_POINTER: - log_printf (" value (pointer). . . : 0x%X", ptr_var->value); + log_printf (" value (pointer). . . : 0x%x", ptr_var->value); break; case PLUGIN_INFOLIST_TIME: log_printf (" value (time) . . . . : %ld", *((time_t *)ptr_var->value)); break; } - log_printf (" prev_var . . . . . . : 0x%X", ptr_var->prev_var); - log_printf (" next_var . . . . . . : 0x%X", ptr_var->next_var); + log_printf (" prev_var . . . . . . : 0x%x", ptr_var->prev_var); + log_printf (" next_var . . . . . . : 0x%x", ptr_var->next_var); } } } diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 3661b4fea..6405c3da9 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -302,9 +302,9 @@ plugin_load (char *filename) new_plugin->prefix = &plugin_api_prefix; new_plugin->color = &plugin_api_color; new_plugin->printf_date = &gui_chat_printf_date; - new_plugin->log_printf = &log_printf; new_plugin->infobar_printf = &plugin_api_infobar_printf; new_plugin->infobar_remove = &plugin_api_infobar_remove; + new_plugin->log_printf = &log_printf; new_plugin->hook_command = &hook_command; new_plugin->hook_timer = &hook_timer; @@ -676,15 +676,15 @@ plugin_print_log () ptr_plugin = ptr_plugin->next_plugin) { log_printf (""); - log_printf ("[plugin (addr:0x%X)]", ptr_plugin); + log_printf ("[plugin (addr:0x%x)]", ptr_plugin); log_printf (" filename . . . . . . . : '%s'", ptr_plugin->filename); - log_printf (" handle . . . . . . . . : 0x%X", ptr_plugin->handle); + log_printf (" handle . . . . . . . . : 0x%x", ptr_plugin->handle); log_printf (" name . . . . . . . . . : '%s'", ptr_plugin->name); log_printf (" description. . . . . . : '%s'", ptr_plugin->description); log_printf (" version. . . . . . . . : '%s'", ptr_plugin->version); log_printf (" charset. . . . . . . . : '%s'", ptr_plugin->charset); - log_printf (" prev_plugin. . . . . . : 0x%X", ptr_plugin->prev_plugin); - log_printf (" next_plugin. . . . . . : 0x%X", ptr_plugin->next_plugin); + log_printf (" prev_plugin. . . . . . : 0x%x", ptr_plugin->prev_plugin); + log_printf (" next_plugin. . . . . . : 0x%x", ptr_plugin->next_plugin); } plugin_infolist_print_log (); diff --git a/src/plugins/scripts/perl/Makefile.am b/src/plugins/scripts/perl/Makefile.am index 1d88ce204..a064a3a1f 100644 --- a/src/plugins/scripts/perl/Makefile.am +++ b/src/plugins/scripts/perl/Makefile.am @@ -20,6 +20,8 @@ libdir = ${weechat_libdir}/plugins lib_LTLIBRARIES = perl.la -perl_la_SOURCES = perl.c +perl_la_SOURCES = weechat-perl.c \ + weechat-perl.h \ + weechat-perl-api.c perl_la_LDFLAGS = -module perl_la_LIBADD = ../lib_weechat_plugins_scripts.la $(PERL_LFLAGS) diff --git a/src/plugins/scripts/perl/perl.c b/src/plugins/scripts/perl/perl.c deleted file mode 100644 index a1eeef6ae..000000000 --- a/src/plugins/scripts/perl/perl.c +++ /dev/null @@ -1,2444 +0,0 @@ -/* - * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org> - * See README for License detail, AUTHORS for developers list. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* weechat-perl.c: Perl plugin support for WeeChat */ - -#undef _ - -#include <EXTERN.h> -#include <perl.h> -#include <XSUB.h> - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdarg.h> -#include <time.h> - -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <sys/types.h> -#include <sys/stat.h> - -#include "../../weechat-plugin.h" -#include "../weechat-script.h" - -WEECHAT_PLUGIN_NAME("perl"); -WEECHAT_PLUGIN_DESCRIPTION("Perl plugin for WeeChat"); -WEECHAT_PLUGIN_AUTHOR("FlashCode <flashcode@flashtux.org>"); -WEECHAT_PLUGIN_VERSION("0.1"); -WEECHAT_PLUGIN_LICENSE("GPL"); - -t_weechat_plugin *perl_plugin; - -t_plugin_script *perl_scripts = NULL; -t_plugin_script *perl_current_script = NULL; -char *perl_current_script_filename = NULL; - -extern void boot_DynaLoader (pTHX_ CV* cv); - -#ifdef NO_PERL_MULTIPLICITY -#undef MULTIPLICITY -#endif - -#ifndef MULTIPLICITY -#define PKG_NAME_PREFIX "WeechatPerlPackage" -static PerlInterpreter *perl_main = NULL; -int perl_num = 0; -#endif - -char *perl_weechat_code = -{ -#ifndef MULTIPLICITY - "package WeechatPerlScriptLoader;" -#endif - "$weechat_perl_load_eval_file_error = \"\";" - "sub weechat_perl_load_file" - "{" - " my $filename = shift;" - " local $/ = undef;" - " open FILE, $filename or return \"__WEECHAT_PERL_ERROR__\";" - " $_ = <FILE>;" - " close FILE;" - " return $_;" - "}" - "sub weechat_perl_load_eval_file" - "{" -#ifndef MULTIPLICITY - " my ($filename, $package) = @_;" -#else - " my $filename = shift;" -#endif - " my $content = weechat_perl_load_file ($filename);" - " if ($content eq \"__WEECHAT_PERL_ERROR__\")" - " {" - " return 1;" - " }" -#ifndef MULTIPLICITY - " my $eval = qq{package $package; $content;};" -#else - " my $eval = $content;" -#endif - " {" - " eval $eval;" - " }" - " if ($@)" - " {" - " $weechat_perl_load_eval_file_error = $@;" - " return 2;" - " }" - " return 0;" - "}" - "$SIG{__WARN__} = sub { weechat::print \"Perl error: $_[0]\", \"\"; };" - "$SIG{__DIE__} = sub { weechat::print \"Perl error: $_[0]\", \"\"; };" -}; - -/* - * weechat_perl_exec: execute a Perl script - */ - -void * -weechat_perl_exec (t_weechat_plugin *plugin, - t_plugin_script *script, - int ret_type, - char *function, char *arg1, char *arg2, char *arg3) -{ - char empty_arg[1] = { '\0' }; - char *func; - char *argv[4]; - unsigned int count; - void *ret_value; - int *ret_i; - SV *ret_s; - int mem_err; - - /* this code is placed here to conform ISO C90 */ - dSP; - -#ifndef MULTIPLICITY - int size = strlen (script->interpreter) + strlen(function) + 3; - func = (char *)malloc (size * sizeof(char)); - if (!func) - return NULL; - snprintf (func, size, "%s::%s", (char *) script->interpreter, function); -#else - func = function; - PERL_SET_CONTEXT (script->interpreter); -#endif - - ENTER; - SAVETMPS; - PUSHMARK(sp); - - /* are we loading the script file ? */ - if (strcmp (function, "weechat_perl_load_eval_file") != 0) - perl_current_script = script; - - if (arg1) - { - argv[0] = (arg1) ? arg1 : empty_arg; - if (arg2) - { - argv[1] = (arg2) ? arg2 : empty_arg; - if (arg3) - { - argv[2] = (arg3) ? arg3 : empty_arg; - argv[3] = NULL; - } - else - argv[2] = NULL; - } - else - argv[1] = NULL; - } - else - argv[0] = NULL; - - count = perl_call_argv (func, G_EVAL | G_SCALAR, argv); - ret_value = NULL; - mem_err = 1; - - SPAGAIN; - - if (SvTRUE (ERRSV)) - { - plugin->print_server (plugin, "Perl error: %s", SvPV_nolen (ERRSV)); - (void) POPs; /* poping the 'undef' */ - mem_err = 0; - } - else - { - if (count != 1) - { - plugin->print_server (plugin, - "Perl error: function \"%s\" must return 1 valid value (%d)", - function, count); - mem_err = 0; - } - else - { - if (ret_type == SCRIPT_EXEC_STRING) - { - ret_s = newSVsv(POPs); - ret_value = strdup (SvPV_nolen (ret_s)); - SvREFCNT_dec (ret_s); - } - else if (ret_type == SCRIPT_EXEC_INT) - { - ret_i = (int *)malloc (sizeof(int)); - if (ret_i) - *ret_i = POPi; - ret_value = ret_i; - } - else - { - plugin->print_server (plugin, - "Perl error: function \"%s\" is internally misused.", - function); - mem_err = 0; - } - } - } - - PUTBACK; - FREETMPS; - LEAVE; - -#ifndef MULTIPLICITY - free (func); -#endif - - if (ret_value == NULL && mem_err == 1) - { - plugin->print_server (plugin, - "Perl error: unable to alloc memory in function \"%s\"", - function); - return NULL; - } - - return ret_value; -} - -/* - * weechat_perl_cmd_msg_handler: general command/message handler for Perl - */ - -int -weechat_perl_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_perl_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_perl_timer_handler: general timer handler for Perl - */ - -int -weechat_perl_timer_handler (t_weechat_plugin *plugin, - int argc, char **argv, - char *handler_args, void *handler_pointer) -{ - int *r, ret; - - /* make C compiler happy */ - (void) argc; - (void) argv; - - r = (int *) weechat_perl_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_perl_keyboard_handler: general keyboard handler for Perl - */ - -int -weechat_perl_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_perl_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_perl_event_handler: general event handler for Perl - */ - -int -weechat_perl_event_handler (t_weechat_plugin *plugin, - int argc, char **argv, - char *handler_args, void *handler_pointer) -{ - int *r, ret; - - if (argc >= 1) - { - r = (int *) weechat_perl_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_perl_modifier: general modifier for Perl - */ - -char * -weechat_perl_modifier (t_weechat_plugin *plugin, - int argc, char **argv, - char *modifier_args, void *modifier_pointer) -{ - if (argc >= 2) - return (char *) weechat_perl_exec (plugin, (t_plugin_script *)modifier_pointer, - SCRIPT_EXEC_STRING, - modifier_args, argv[0], argv[1], NULL); - else - return NULL; -} - -/* - * weechat::register: startup function for all WeeChat Perl scripts - */ - -static XS (XS_weechat_register) -{ - char *name, *version, *shutdown_func, *description, *charset; - dXSARGS; - - /* make C compiler happy */ - (void) items; - (void) cv; - - perl_current_script = NULL; - - if ((items < 4) || (items > 5)) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"register\" function"); - XSRETURN_NO; - } - - name = SvPV (ST (0), PL_na); - version = SvPV (ST (1), PL_na); - shutdown_func = SvPV (ST (2), PL_na); - description = SvPV (ST (3), PL_na); - charset = (items == 5) ? SvPV (ST (4), PL_na) : NULL; - - if (weechat_script_search (perl_plugin, &perl_scripts, name)) - { - /* error: another script already exists with this name! */ - perl_plugin->print_server (perl_plugin, - "Perl error: unable to register " - "\"%s\" script (another script " - "already exists with this name)", - name); - XSRETURN_NO; - } - - /* register script */ - perl_current_script = weechat_script_add (perl_plugin, - &perl_scripts, - (perl_current_script_filename) ? - perl_current_script_filename : "", - name, version, shutdown_func, - description, charset); - if (perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl: registered script \"%s\", " - "version %s (%s)", - name, version, description); - } - else - { - XSRETURN_NO; - } - - XSRETURN_YES; -} - -/* - * weechat::set_charset: set script charset - */ - -static XS (XS_weechat_set_charset) -{ - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to set charset, " - "script not initialized"); - XSRETURN_EMPTY; - } - - if (items < 1) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"set_charset\" function"); - XSRETURN_EMPTY; - } - - weechat_script_set_charset (perl_plugin, - perl_current_script, - SvPV (ST (0), PL_na)); - - XSRETURN_YES; -} - -/* - * weechat::print: print message into a buffer (current or specified one) - */ - -static XS (XS_weechat_print) -{ - char *message, *channel_name, *server_name; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to print message, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 1) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"print\" function"); - XSRETURN_NO; - } - - message = SvPV (ST (0), PL_na); - - channel_name = NULL; - server_name = NULL; - - if (items > 1) - { - channel_name = SvPV (ST (1), PL_na); - if (items > 2) - server_name = SvPV (ST (2), PL_na); - } - - weechat_script_print (perl_plugin, perl_current_script, - server_name, channel_name, - "%s", message); - - XSRETURN_YES; -} - -/* - * weechat::print_server: print message into a server buffer - */ - -static XS (XS_weechat_print_server) -{ - char *message; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to print message, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 1) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"print_server\" function"); - XSRETURN_NO; - } - - message = SvPV (ST (0), PL_na); - - weechat_script_print_server (perl_plugin, perl_current_script, - "%s", message); - - XSRETURN_YES; -} - -/* - * weechat::print_infobar: print message to infobar - */ - -static XS (XS_weechat_print_infobar) -{ - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to print infobar message, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 2) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"print_infobar\" function"); - XSRETURN_NO; - } - - weechat_script_print_infobar (perl_plugin, perl_current_script, - SvIV (ST (0)), - "%s", SvPV (ST (1), PL_na)); - - XSRETURN_YES; -} - -/* - * weechat::remove_infobar: remove message(s) from infobar - */ - -static XS (XS_weechat_remove_infobar) -{ - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to remove infobar message(s), " - "script not initialized"); - XSRETURN_NO; - } - - perl_plugin->infobar_remove (perl_plugin, - (items >= 1) ? SvIV (ST (0)) : 0); - - XSRETURN_YES; -} - -/* - * weechat::log: log message in server/channel (current or specified ones) - */ - -static XS (XS_weechat_log) -{ - char *message, *channel_name, *server_name; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to print message, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 1) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"log\" function"); - XSRETURN_NO; - } - - message = SvPV (ST (0), PL_na); - - channel_name = NULL; - server_name = NULL; - - if (items > 1) - { - channel_name = SvPV (ST (1), PL_na); - if (items > 2) - server_name = SvPV (ST (2), PL_na); - } - - weechat_script_log (perl_plugin, perl_current_script, - server_name, channel_name, - "%s", message); - - XSRETURN_YES; -} - -/* - * weechat::command: send command to server - */ - -static XS (XS_weechat_command) -{ - char *channel_name, *server_name; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to run command, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 1) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"command\" function"); - XSRETURN_NO; - } - - channel_name = NULL; - server_name = NULL; - - if (items > 1) - { - channel_name = SvPV (ST (1), PL_na); - if (items > 2) - server_name = SvPV (ST (2), PL_na); - } - - weechat_script_exec_command (perl_plugin, perl_current_script, - server_name, channel_name, - SvPV (ST (0), PL_na)); - - XSRETURN_YES; -} - -/* - * weechat::add_message_handler: add a handler for messages (privmsg, ...) - */ - -static XS (XS_weechat_add_message_handler) -{ - char *irc_command, *function; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to add message handler, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 2) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"add_message_handler\" function"); - XSRETURN_NO; - } - - irc_command = SvPV (ST (0), PL_na); - function = SvPV (ST (1), PL_na); - - if (perl_plugin->msg_handler_add (perl_plugin, irc_command, - weechat_perl_cmd_msg_handler, function, - (void *)perl_current_script)) - XSRETURN_YES; - - XSRETURN_NO; -} - -/* - * weechat::add_command_handler: add a command handler (define/redefine commands) - */ - -static XS (XS_weechat_add_command_handler) -{ - char *command, *function, *description, *arguments, *arguments_description; - char *completion_template; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to add command handler, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 2) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"add_command_handler\" function"); - XSRETURN_NO; - } - - command = SvPV (ST (0), PL_na); - function = SvPV (ST (1), PL_na); - description = (items >= 3) ? SvPV (ST (2), PL_na) : NULL; - arguments = (items >= 4) ? SvPV (ST (3), PL_na) : NULL; - arguments_description = (items >= 5) ? SvPV (ST (4), PL_na) : NULL; - completion_template = (items >= 6) ? SvPV (ST (5), PL_na) : NULL; - - if (perl_plugin->cmd_handler_add (perl_plugin, - command, - description, - arguments, - arguments_description, - completion_template, - weechat_perl_cmd_msg_handler, - function, - (void *)perl_current_script)) - XSRETURN_YES; - - XSRETURN_NO; -} - -/* - * weechat::add_timer_handler: add a timer handler - */ - -static XS (XS_weechat_add_timer_handler) -{ - int interval; - char *function; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to add timer handler, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 2) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"add_timer_handler\" function"); - XSRETURN_NO; - } - - interval = SvIV (ST (0)); - function = SvPV (ST (1), PL_na); - - if (perl_plugin->timer_handler_add (perl_plugin, interval, - weechat_perl_timer_handler, function, - (void *)perl_current_script)) - XSRETURN_YES; - - XSRETURN_NO; -} - -/* - * weechat::add_keyboard_handler: add a keyboard handler - */ - -static XS (XS_weechat_add_keyboard_handler) -{ - char *function; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to add keyboard handler, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 1) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"add_keyboard_handler\" function"); - XSRETURN_NO; - } - - function = SvPV (ST (0), PL_na); - - if (perl_plugin->keyboard_handler_add (perl_plugin, - weechat_perl_keyboard_handler, - function, - (void *)perl_current_script)) - XSRETURN_YES; - - XSRETURN_NO; -} - -/* - * weechat::add_event_handler: add an event handler - */ - -static XS (XS_weechat_add_event_handler) -{ - char *event, *function; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to add event handler, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 2) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"add_event_handler\" function"); - XSRETURN_NO; - } - - event = SvPV (ST (0), PL_na); - function = SvPV (ST (1), PL_na); - - if (perl_plugin->event_handler_add (perl_plugin, event, - weechat_perl_event_handler, function, - (void *)perl_current_script)) - XSRETURN_YES; - - XSRETURN_NO; -} - -/* - * weechat::remove_handler: remove a message/command handler - */ - -static XS (XS_weechat_remove_handler) -{ - char *command, *function; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to remove handler, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 2) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"remove_handler\" function"); - XSRETURN_NO; - } - - command = SvPV (ST (0), PL_na); - function = SvPV (ST (1), PL_na); - - weechat_script_remove_handler (perl_plugin, perl_current_script, - command, function); - - XSRETURN_YES; -} - -/* - * weechat::remove_timer_handler: remove a timer handler - */ - -static XS (XS_weechat_remove_timer_handler) -{ - char *function; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to remove timer handler, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 1) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"remove_timer_handler\" function"); - XSRETURN_NO; - } - - function = SvPV (ST (0), PL_na); - - weechat_script_remove_timer_handler (perl_plugin, perl_current_script, - function); - - XSRETURN_YES; -} - -/* - * weechat::remove_keyboard_handler: remove a keyboard handler - */ - -static XS (XS_weechat_remove_keyboard_handler) -{ - char *function; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to remove keyboard handler, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 1) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"remove_keyboard_handler\" function"); - XSRETURN_NO; - } - - function = SvPV (ST (0), PL_na); - - weechat_script_remove_keyboard_handler (perl_plugin, perl_current_script, - function); - - XSRETURN_YES; -} - -/* - * weechat::remove_event_handler: remove an event handler - */ - -static XS (XS_weechat_remove_event_handler) -{ - char *function; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to remove event handler, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 1) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"remove_event_handler\" function"); - XSRETURN_NO; - } - - function = SvPV (ST (0), PL_na); - - weechat_script_remove_event_handler (perl_plugin, perl_current_script, - function); - - XSRETURN_YES; -} - -/* - * weechat::add_modifier: add a modifier - */ - -static XS (XS_weechat_add_modifier) -{ - char *type, *command, *function; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to add modifier, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 3) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"add_modifier\" function"); - XSRETURN_NO; - } - - type = SvPV (ST (0), PL_na); - command = SvPV (ST (1), PL_na); - function = SvPV (ST (2), PL_na); - - if (perl_plugin->modifier_add (perl_plugin, type, command, - weechat_perl_modifier, function, - (void *)perl_current_script)) - XSRETURN_YES; - - XSRETURN_NO; -} - -/* - * weechat::remove_modifier: remove a modifier - */ - -static XS (XS_weechat_remove_modifier) -{ - char *type, *command, *function; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to remove modifier, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 2) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"remove_modifier\" function"); - XSRETURN_NO; - } - - type = SvPV (ST (0), PL_na); - command = SvPV (ST (1), PL_na); - function = SvPV (ST (2), PL_na); - - weechat_script_remove_modifier (perl_plugin, perl_current_script, - type, command, function); - - XSRETURN_YES; -} - -/* - * weechat::get_info: get various infos - */ - -static XS (XS_weechat_get_info) -{ - char *arg, *info, *server_name; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to get info, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 1) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"get_info\" function"); - XSRETURN_NO; - } - - server_name = (items == 2) ? SvPV (ST (1), PL_na) : NULL; - - arg = SvPV (ST (0), PL_na); - if (arg) - { - info = perl_plugin->get_info (perl_plugin, arg, server_name); - - if (info) - { - XST_mPV (0, info); - free (info); - XSRETURN (1); - } - } - - XST_mPV (0, ""); - XSRETURN (1); -} - -/* - * weechat::get_dcc_info: get infos about DCC - */ - -static XS (XS_weechat_get_dcc_info) -{ - t_plugin_dcc_info *dcc_info, *ptr_dcc; - int count; - char timebuffer1[64]; - char timebuffer2[64]; - struct in_addr in; - HV *dcc_hash_member; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - (void) items; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to get DCC info, " - "script not initialized"); - XSRETURN_EMPTY; - } - - dcc_info = perl_plugin->get_dcc_info (perl_plugin); - count = 0; - if (!dcc_info) - XSRETURN_EMPTY; - - 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_hash_member = (HV *) sv_2mortal ((SV *) newHV()); - - hv_store (dcc_hash_member, "server", 6, newSVpv (ptr_dcc->server, 0), 0); - hv_store (dcc_hash_member, "channel", 7, newSVpv (ptr_dcc->channel, 0), 0); - hv_store (dcc_hash_member, "type", 4, newSViv (ptr_dcc->type), 0); - hv_store (dcc_hash_member, "status", 6, newSViv (ptr_dcc->status), 0); - hv_store (dcc_hash_member, "start_time", 10, newSVpv (timebuffer1, 0), 0); - hv_store (dcc_hash_member, "start_transfer", 14, newSVpv (timebuffer2, 0), 0); - hv_store (dcc_hash_member, "address", 7, newSVpv (inet_ntoa(in), 0), 0); - hv_store (dcc_hash_member, "port", 4, newSViv (ptr_dcc->port), 0); - hv_store (dcc_hash_member, "nick", 4, newSVpv (ptr_dcc->nick, 0), 0); - hv_store (dcc_hash_member, "remote_file", 11, newSVpv (ptr_dcc->filename, 0), 0); - hv_store (dcc_hash_member, "local_file", 10, newSVpv (ptr_dcc->local_filename, 0), 0); - hv_store (dcc_hash_member, "filename_suffix", 15, newSViv (ptr_dcc->filename_suffix), 0); - hv_store (dcc_hash_member, "size", 4, newSVnv (ptr_dcc->size), 0); - hv_store (dcc_hash_member, "pos", 3, newSVnv (ptr_dcc->pos), 0); - hv_store (dcc_hash_member, "start_resume", 12, newSVnv (ptr_dcc->start_resume), 0); - hv_store (dcc_hash_member, "cps", 3, newSViv (ptr_dcc->bytes_per_sec), 0); - - XPUSHs(newRV_inc((SV *) dcc_hash_member)); - count++; - } - perl_plugin->free_dcc_info (perl_plugin, dcc_info); - - XSRETURN (count); -} - -/* - * weechat::get_config: get value of a WeeChat config option - */ - -static XS (XS_weechat_get_config) -{ - char *option, *return_value; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to get config option, " - "script not initialized"); - XSRETURN_EMPTY; - } - - if (items < 1) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"get_config\" function"); - XSRETURN_EMPTY; - } - - option = SvPV (ST (0), PL_na); - - if (option) - { - return_value = perl_plugin->get_config (perl_plugin, option); - - if (return_value) - { - XST_mPV (0, return_value); - free (return_value); - XSRETURN (1); - } - } - - XST_mPV (0, ""); - XSRETURN (1); -} - -/* - * weechat::set_config: set value of a WeeChat config option - */ - -static XS (XS_weechat_set_config) -{ - char *option, *value; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to set config option, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 2) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"set_config\" function"); - XSRETURN_NO; - } - - option = SvPV (ST (0), PL_na); - value = SvPV (ST (1), PL_na); - - if (option && value) - { - if (perl_plugin->set_config (perl_plugin, option, value)) - XSRETURN_YES; - } - - XSRETURN_NO; -} - -/* - * weechat::get_plugin_config: get value of a plugin config option - */ - -static XS (XS_weechat_get_plugin_config) -{ - char *option, *return_value; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to get plugin config option, " - "script not initialized"); - XSRETURN_EMPTY; - } - - if (items < 1) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"get_plugin_config\" function"); - XSRETURN_EMPTY; - } - - option = SvPV (ST (0), PL_na); - - if (option) - { - return_value = weechat_script_get_plugin_config (perl_plugin, - perl_current_script, - option); - - if (return_value) - { - XST_mPV (0, return_value); - free (return_value); - XSRETURN (1); - } - } - - XST_mPV (0, ""); - XSRETURN (1); -} - -/* - * weechat::set_plugin_config: set value of a WeeChat config option - */ - -static XS (XS_weechat_set_plugin_config) -{ - char *option, *value; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to set plugin config option, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 2) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"set_plugin_config\" function"); - XSRETURN_NO; - } - - option = SvPV (ST (0), PL_na); - value = SvPV (ST (1), PL_na); - - if (option && value) - { - if (weechat_script_set_plugin_config (perl_plugin, - perl_current_script, - option, value)) - XSRETURN_YES; - } - - XSRETURN_NO; -} - -/* - * weechat::get_server_info: get infos about servers - */ - -static XS (XS_weechat_get_server_info) -{ - t_plugin_server_info *server_info, *ptr_server; - char timebuffer[64]; - HV *server_hash, *server_hash_member; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - (void) items; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to get server info, " - "script not initialized"); - XSRETURN_EMPTY; - } - - server_info = perl_plugin->get_server_info (perl_plugin); - if (!server_info) - { - XSRETURN_EMPTY; - } - - server_hash = (HV *) sv_2mortal((SV *) newHV()); - if (!server_hash) - { - perl_plugin->free_server_info (perl_plugin, server_info); - XSRETURN_EMPTY; - } - - 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 = (HV *) sv_2mortal((SV *) newHV()); - - hv_store (server_hash_member, "autoconnect", 11, newSViv (ptr_server->autoconnect), 0); - hv_store (server_hash_member, "autoreconnect", 13, newSViv (ptr_server->autoreconnect), 0); - hv_store (server_hash_member, "autoreconnect_delay", 19, newSViv (ptr_server->autoreconnect_delay), 0); - hv_store (server_hash_member, "temp_server", 11, newSViv (ptr_server->temp_server), 0); - hv_store (server_hash_member, "address", 7, newSVpv (ptr_server->address, 0), 0); - hv_store (server_hash_member, "port", 4, newSViv (ptr_server->port), 0); - hv_store (server_hash_member, "ipv6", 4, newSViv (ptr_server->ipv6), 0); - hv_store (server_hash_member, "ssl", 3, newSViv (ptr_server->ssl), 0); - hv_store (server_hash_member, "password", 8, newSVpv (ptr_server->password, 0), 0); - hv_store (server_hash_member, "nick1", 5, newSVpv (ptr_server->nick1, 0), 0); - hv_store (server_hash_member, "nick2", 5, newSVpv (ptr_server->nick2, 0), 0); - hv_store (server_hash_member, "nick3", 5, newSVpv (ptr_server->nick3, 0), 0); - hv_store (server_hash_member, "username", 8, newSVpv (ptr_server->username, 0), 0); - hv_store (server_hash_member, "realname", 8, newSVpv (ptr_server->realname, 0), 0); - hv_store (server_hash_member, "command", 7, newSVpv (ptr_server->command, 0), 0); - hv_store (server_hash_member, "command_delay", 13, newSViv (ptr_server->command_delay), 0); - hv_store (server_hash_member, "autojoin", 8, newSVpv (ptr_server->autojoin, 0), 0); - hv_store (server_hash_member, "autorejoin", 10, newSViv (ptr_server->autorejoin), 0); - hv_store (server_hash_member, "notify_levels", 13, newSVpv (ptr_server->notify_levels, 0), 0); - hv_store (server_hash_member, "is_connected", 12, newSViv (ptr_server->is_connected), 0); - hv_store (server_hash_member, "ssl_connected", 13, newSViv (ptr_server->ssl_connected), 0); - hv_store (server_hash_member, "nick", 4, newSVpv (ptr_server->nick, 0), 0); - hv_store (server_hash_member, "nick_modes", 10, newSVpv (ptr_server->nick_modes, 0), 0); - hv_store (server_hash_member, "away_time", 9, newSVpv (timebuffer, 0), 0); - hv_store (server_hash_member, "lag", 3, newSViv (ptr_server->lag), 0); - - hv_store (server_hash, ptr_server->name, strlen(ptr_server->name), newRV_inc((SV *) server_hash_member), 0); - } - perl_plugin->free_server_info (perl_plugin, server_info); - - ST (0) = newRV_inc((SV *) server_hash); - if (SvREFCNT(ST(0))) sv_2mortal(ST(0)); - - XSRETURN (1); -} - -/* - * weechat::get_channel_info: get infos about channels - */ - -static XS (XS_weechat_get_channel_info) -{ - t_plugin_channel_info *channel_info, *ptr_channel; - char *server; - HV *channel_hash, *channel_hash_member; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to get channel info, " - "script not initialized"); - XSRETURN_EMPTY; - } - - if (items != 1) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"get_channel_info\" function"); - XSRETURN_EMPTY; - } - - server = SvPV (ST (0), PL_na); - if (!server) - XSRETURN_EMPTY; - - channel_info = perl_plugin->get_channel_info (perl_plugin, server); - if (!channel_info) - { - XSRETURN_EMPTY; - } - - channel_hash = (HV *) sv_2mortal((SV *) newHV()); - if (!channel_hash) - { - perl_plugin->free_channel_info (perl_plugin, channel_info); - XSRETURN_EMPTY; - } - - for (ptr_channel = channel_info; ptr_channel; ptr_channel = ptr_channel->next_channel) - { - channel_hash_member = (HV *) sv_2mortal((SV *) newHV()); - - hv_store (channel_hash_member, "type", 4, newSViv (ptr_channel->type), 0); - hv_store (channel_hash_member, "topic", 5, newSVpv (ptr_channel->topic, 0), 0); - hv_store (channel_hash_member, "modes", 5, newSVpv (ptr_channel->modes, 0), 0); - hv_store (channel_hash_member, "limit", 5, newSViv (ptr_channel->limit), 0); - hv_store (channel_hash_member, "key", 3, newSVpv (ptr_channel->key, 0), 0); - hv_store (channel_hash_member, "nicks_count", 11, newSViv (ptr_channel->nicks_count), 0); - - hv_store (channel_hash, ptr_channel->name, strlen(ptr_channel->name), newRV_inc((SV *) channel_hash_member), 0); - } - perl_plugin->free_channel_info (perl_plugin, channel_info); - - ST (0) = newRV_inc((SV *) channel_hash); - if (SvREFCNT(ST(0))) sv_2mortal(ST(0)); - - XSRETURN (1); -} - -/* - * weechat::get_nick_info: get infos about nicks - */ - -static XS (XS_weechat_get_nick_info) -{ - t_plugin_nick_info *nick_info, *ptr_nick; - char *server, *channel; - HV *nick_hash; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to get nick info, " - "script not initialized"); - XSRETURN_EMPTY; - } - - if (items != 2) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"get_nick_info\" function"); - XSRETURN_EMPTY; - } - - server = SvPV (ST (0), PL_na); - channel = SvPV (ST (1), PL_na); - if (!server || !channel) - XSRETURN_EMPTY; - - nick_info = perl_plugin->get_nick_info (perl_plugin, server, channel); - if (!nick_info) - { - XSRETURN_EMPTY; - } - - nick_hash = (HV *) sv_2mortal((SV *) newHV()); - if (!nick_hash) - { - perl_plugin->free_nick_info (perl_plugin, nick_info); - XSRETURN_EMPTY; - } - - for (ptr_nick = nick_info; ptr_nick; ptr_nick = ptr_nick->next_nick) - { - HV *nick_hash_member = (HV *) sv_2mortal((SV *) newHV()); - - hv_store (nick_hash_member, "flags", 5, newSViv (ptr_nick->flags), 0); - hv_store (nick_hash_member, "host", 4, newSVpv ( - ptr_nick->host ? ptr_nick->host : "", 0), 0); - - hv_store (nick_hash, ptr_nick->nick, strlen(ptr_nick->nick), newRV_inc((SV *) nick_hash_member), 0); - } - perl_plugin->free_nick_info (perl_plugin, nick_info); - - ST (0) = newRV_inc((SV *) nick_hash); - if (SvREFCNT(ST(0))) sv_2mortal(ST(0)); - - XSRETURN (1); -} - -/* - * weechat::color_input: add color in input buffer - */ - -static XS (XS_weechat_input_color) -{ - int color, start, length; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to colorize input, " - "script not initialized"); - XSRETURN_NO; - } - - if (items < 3) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"color_input\" function"); - XSRETURN_NO; - } - - color = SvIV (ST (0)); - start = SvIV (ST (1)); - length = SvIV (ST (2)); - - perl_plugin->input_color (perl_plugin, color, start, length); - - XSRETURN_YES; -} - -/* - * weechat::get_irc_color: - * get the numeric value which identify an irc color by its name - */ - -static XS (XS_weechat_get_irc_color) -{ - char *color; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to get irc color, " - "script not initialized"); - XST_mIV (0, -1); - XSRETURN (1); - } - - if (items != 1) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"get_irc_info\" function"); - XST_mIV (0, -1); - XSRETURN (1); - } - - color = SvPV (ST (0), PL_na); - if (color) - { - XST_mIV (0, perl_plugin->get_irc_color (perl_plugin, color)); - XSRETURN (1); - } - - XST_mIV (0, -1); - XSRETURN (-1); -} - -/* - * weechat::get_window_info: get infos about windows - */ - -static XS (XS_weechat_get_window_info) -{ - t_plugin_window_info *window_info, *ptr_win; - int count; - HV *window_hash_member; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - (void) items; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to get window info, " - "script not initialized"); - XSRETURN_EMPTY; - } - - window_info = perl_plugin->get_window_info (perl_plugin); - count = 0; - if (!window_info) - XSRETURN_EMPTY; - - for (ptr_win = window_info; ptr_win; ptr_win = ptr_win->next_window) - { - window_hash_member = (HV *) sv_2mortal((SV *) newHV()); - - hv_store (window_hash_member, "num_buffer", 10, newSViv (ptr_win->num_buffer), 0); - hv_store (window_hash_member, "win_x", 5, newSViv (ptr_win->win_x), 0); - hv_store (window_hash_member, "win_y", 5, newSViv (ptr_win->win_y), 0); - hv_store (window_hash_member, "win_width", 9, newSViv (ptr_win->win_width), 0); - hv_store (window_hash_member, "win_height", 10, newSViv (ptr_win->win_height), 0); - hv_store (window_hash_member, "win_width_pct", 13, newSViv (ptr_win->win_width_pct), 0); - hv_store (window_hash_member, "win_height_pct", 14, newSViv (ptr_win->win_height_pct), 0); - - XPUSHs(newRV_inc((SV *) window_hash_member)); - count++; - } - perl_plugin->free_window_info (perl_plugin, window_info); - - XSRETURN (count); -} - -/* - * weechat::get_buffer_info: get infos about buffers - */ - -static XS (XS_weechat_get_buffer_info) -{ - t_plugin_buffer_info *buffer_info, *ptr_buffer; - HV *buffer_hash, *buffer_hash_member; - char conv[8]; - dXSARGS; - - /* make C compiler happy */ - (void) cv; - (void) items; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to get buffer info, " - "script not initialized"); - XSRETURN_EMPTY; - } - - buffer_info = perl_plugin->get_buffer_info (perl_plugin); - if (!buffer_info) - { - XSRETURN_EMPTY; - } - - buffer_hash = (HV *) sv_2mortal((SV *) newHV()); - if (!buffer_hash) - { - perl_plugin->free_buffer_info (perl_plugin, buffer_info); - XSRETURN_EMPTY; - } - - for (ptr_buffer = buffer_info; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - buffer_hash_member = (HV *) sv_2mortal((SV *) newHV()); - - hv_store (buffer_hash_member, "type", 4, newSViv (ptr_buffer->type), 0); - hv_store (buffer_hash_member, "num_displayed", 13, newSViv (ptr_buffer->num_displayed), 0); - hv_store (buffer_hash_member, "server", 6, - newSVpv (ptr_buffer->server_name == NULL ? "" : ptr_buffer->server_name, 0), 0); - hv_store (buffer_hash_member, "channel", 7, - newSVpv (ptr_buffer->channel_name == NULL ? "" : ptr_buffer->channel_name, 0), 0); - hv_store (buffer_hash_member, "notify_level", 12, newSViv (ptr_buffer->notify_level), 0); - hv_store (buffer_hash_member, "log_filename", 12, - newSVpv (ptr_buffer->log_filename == NULL ? "" : ptr_buffer->log_filename, 0), 0); - snprintf(conv, sizeof(conv), "%d", ptr_buffer->number); - hv_store (buffer_hash, conv, strlen(conv), newRV_inc((SV *) buffer_hash_member), 0); - } - perl_plugin->free_buffer_info (perl_plugin, buffer_info); - - ST (0) = newRV_inc((SV *) buffer_hash); - if (SvREFCNT(ST(0))) sv_2mortal(ST(0)); - - XSRETURN (1); -} - -/* - * weechat::get_buffer_data: get buffer content - */ - -static XS (XS_weechat_get_buffer_data) -{ - t_plugin_buffer_line *buffer_data, *ptr_data; - HV *data_list_member; - char *server, *channel; - char timebuffer[64]; - int count; - - dXSARGS; - - /* make C compiler happy */ - (void) cv; - (void) items; - - if (!perl_current_script) - { - perl_plugin->print_server (perl_plugin, - "Perl error: unable to get buffer data, " - "script not initialized"); - XSRETURN_EMPTY; - } - - if (items != 2) - { - perl_plugin->print_server (perl_plugin, - "Perl error: wrong parameters for " - "\"get_buffer_data\" function"); - XSRETURN_EMPTY; - } - - channel = NULL; - server = NULL; - - if (items >= 1) - server = SvPV (ST (0), PL_na); - if (items >= 2) - channel = SvPV (ST (1), PL_na); - - SP -= items; - - buffer_data = perl_plugin->get_buffer_data (perl_plugin, server, channel); - count = 0; - if (!buffer_data) - XSRETURN_EMPTY; - - for (ptr_data = buffer_data; ptr_data; ptr_data = ptr_data->next_line) - { - data_list_member = (HV *) sv_2mortal((SV *) newHV()); - - strftime(timebuffer, sizeof(timebuffer), "%F %T", - localtime(&ptr_data->date)); - - hv_store (data_list_member, "date", 4, newSVpv (timebuffer, 0), 0); - hv_store (data_list_member, "nick", 4, - newSVpv (ptr_data->nick == NULL ? "" : ptr_data->nick, 0), 0); - hv_store (data_list_member, "data", 4, - newSVpv (ptr_data->data == NULL ? "" : ptr_data->data, 0), 0); - - XPUSHs(newRV_inc((SV *) data_list_member)); - count++; - } - perl_plugin->free_buffer_data (perl_plugin, buffer_data); - - XSRETURN (count); -} - -/* - * weechat_perl_xs_init: initialize subroutines - */ - -void -weechat_perl_xs_init (pTHX) -{ - HV *stash; - - newXS ("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__); - - /* interface functions */ - newXS ("weechat::register", XS_weechat_register, "weechat"); - newXS ("weechat::set_charset", XS_weechat_set_charset, "weechat"); - newXS ("weechat::print", XS_weechat_print, "weechat"); - newXS ("weechat::print_server", XS_weechat_print_server, "weechat"); - newXS ("weechat::print_infobar", XS_weechat_print_infobar, "weechat"); - newXS ("weechat::remove_infobar", XS_weechat_remove_infobar, "weechat"); - newXS ("weechat::log", XS_weechat_log, "weechat"); - newXS ("weechat::command", XS_weechat_command, "weechat"); - newXS ("weechat::add_message_handler", XS_weechat_add_message_handler, "weechat"); - newXS ("weechat::add_command_handler", XS_weechat_add_command_handler, "weechat"); - newXS ("weechat::add_timer_handler", XS_weechat_add_timer_handler, "weechat"); - newXS ("weechat::add_keyboard_handler", XS_weechat_add_keyboard_handler, "weechat"); - newXS ("weechat::add_event_handler", XS_weechat_add_event_handler, "weechat"); - newXS ("weechat::remove_handler", XS_weechat_remove_handler, "weechat"); - newXS ("weechat::remove_timer_handler", XS_weechat_remove_timer_handler, "weechat"); - newXS ("weechat::remove_keyboard_handler", XS_weechat_remove_keyboard_handler, "weechat"); - newXS ("weechat::remove_event_handler", XS_weechat_remove_event_handler, "weechat"); - newXS ("weechat::add_modifier", XS_weechat_add_modifier, "weechat"); - newXS ("weechat::remove_modifier", XS_weechat_remove_modifier, "weechat"); - newXS ("weechat::get_info", XS_weechat_get_info, "weechat"); - newXS ("weechat::get_dcc_info", XS_weechat_get_dcc_info, "weechat"); - newXS ("weechat::get_config", XS_weechat_get_config, "weechat"); - newXS ("weechat::set_config", XS_weechat_set_config, "weechat"); - newXS ("weechat::get_plugin_config", XS_weechat_get_plugin_config, "weechat"); - newXS ("weechat::set_plugin_config", XS_weechat_set_plugin_config, "weechat"); - newXS ("weechat::get_server_info", XS_weechat_get_server_info, "weechat"); - newXS ("weechat::get_channel_info", XS_weechat_get_channel_info, "weechat"); - newXS ("weechat::get_nick_info", XS_weechat_get_nick_info, "weechat"); - newXS ("weechat::input_color", XS_weechat_input_color, "weechat"); - newXS ("weechat::get_irc_color", XS_weechat_get_irc_color, "weechat"); - newXS ("weechat::get_window_info", XS_weechat_get_window_info, "weechat"); - newXS ("weechat::get_buffer_info", XS_weechat_get_buffer_info, "weechat"); - newXS ("weechat::get_buffer_data", XS_weechat_get_buffer_data, "weechat"); - - /* interface constants */ - stash = gv_stashpv ("weechat", TRUE); - newCONSTSUB (stash, "weechat::PLUGIN_RC_KO", newSViv (PLUGIN_RC_KO)); - newCONSTSUB (stash, "weechat::PLUGIN_RC_OK", newSViv (PLUGIN_RC_OK)); - newCONSTSUB (stash, "weechat::PLUGIN_RC_OK_IGNORE_WEECHAT", newSViv (PLUGIN_RC_OK_IGNORE_WEECHAT)); - newCONSTSUB (stash, "weechat::PLUGIN_RC_OK_IGNORE_PLUGINS", newSViv (PLUGIN_RC_OK_IGNORE_PLUGINS)); - newCONSTSUB (stash, "weechat::PLUGIN_RC_OK_IGNORE_ALL", newSViv (PLUGIN_RC_OK_IGNORE_ALL)); - newCONSTSUB (stash, "weechat::PLUGIN_RC_OK_WITH_HIGHLIGHT", newSViv (PLUGIN_RC_OK_WITH_HIGHLIGHT)); -} - -/* - * weechat_perl_load: load a Perl script - */ - -int -weechat_perl_load (t_weechat_plugin *plugin, char *filename) -{ - STRLEN len; - t_plugin_script tempscript; - int *eval; - struct stat buf; - -#ifndef MULTIPLICITY - char pkgname[64]; -#else - PerlInterpreter *perl_current_interpreter; - char *perl_args[] = { "", "-e", "0" }; -#endif - - plugin->print_server (plugin, "Loading Perl script \"%s\"", filename); - - if (stat (filename, &buf) != 0) - { - plugin->print_server (plugin, "Perl error: script \"%s\" not found", - filename); - return 0; - } - - perl_current_script = NULL; - -#ifndef MULTIPLICITY - snprintf(pkgname, sizeof(pkgname), "%s%d", PKG_NAME_PREFIX, perl_num); - perl_num++; - tempscript.interpreter = "WeechatPerlScriptLoader"; - eval = weechat_perl_exec (plugin, &tempscript, - SCRIPT_EXEC_INT, - "weechat_perl_load_eval_file", filename, pkgname, ""); -#else - perl_current_interpreter = perl_alloc(); - - if (perl_current_interpreter == NULL) - { - plugin->print_server (plugin, - "Perl error: unable to create new sub-interpreter"); - return 0; - } - - perl_current_script_filename = filename; - - PERL_SET_CONTEXT (perl_current_interpreter); - perl_construct (perl_current_interpreter); - tempscript.interpreter = (PerlInterpreter *) perl_current_interpreter; - perl_parse (perl_current_interpreter, weechat_perl_xs_init, 3, perl_args, NULL); - - eval_pv (perl_weechat_code, TRUE); - eval = weechat_perl_exec (plugin, &tempscript, - SCRIPT_EXEC_INT, - "weechat_perl_load_eval_file", filename, "", ""); -#endif - if (eval == NULL) - { - plugin->print_server (plugin, - "Perl error: memory error while parsing file \"%s\"", - filename); - return 0; - } - - if ( *eval != 0) - { - if (*eval == 2) - { - plugin->print_server (plugin, - "Perl error: unable to parse file \"%s\"", - filename); - plugin->print_server (plugin, - "Perl error: %s", -#ifndef MULTIPLICITY - SvPV(perl_get_sv("WeechatPerlScriptLoader::weechat_perl_load_eval_file_error", FALSE), len) -#else - SvPV(perl_get_sv("weechat_perl_load_eval_file_error", FALSE), len) -#endif - ); - } - else if (*eval == 1) - { - plugin->print_server (plugin, - "Perl error: unable to run file \"%s\"", - filename); - } - else { - plugin->print_server (plugin, - "Perl error: unknown error while loading file \"%s\"", - filename); - } -#ifdef MULTIPLICITY - perl_destruct (perl_current_interpreter); - perl_free (perl_current_interpreter); -#endif - if ((perl_current_script != NULL) && (perl_current_script != &tempscript)) - weechat_script_remove (plugin, &perl_scripts, perl_current_script); - - free (eval); - return 0; - } - - free (eval); - - if (perl_current_script == NULL) - { - plugin->print_server (plugin, - "Perl error: function \"register\" not found " - "(or failed) in file \"%s\"", - filename); -#ifdef MULTIPLICITY - perl_destruct (perl_current_interpreter); - perl_free (perl_current_interpreter); -#endif - return 0; - } - -#ifndef MULTIPLICITY - perl_current_script->interpreter = strdup(pkgname); -#else - perl_current_script->interpreter = (PerlInterpreter *) perl_current_interpreter; -#endif - - return 1; -} - -/* - * weechat_perl_unload: unload a Perl script - */ - -void -weechat_perl_unload (t_weechat_plugin *plugin, t_plugin_script *script) -{ - int *r; - - plugin->print_server (plugin, - "Unloading Perl script \"%s\"", - script->name); - -#ifndef MULTIPLICITY - eval_pv(script->interpreter, TRUE); -#else - PERL_SET_CONTEXT (script->interpreter); -#endif - - if (script->shutdown_func[0]) - { - r = (int *) weechat_perl_exec (plugin, script, SCRIPT_EXEC_INT, - script->shutdown_func, NULL, NULL, NULL); - if (r) - free (r); - } - -#ifndef MULTIPLICITY - if (script->interpreter) - free (script->interpreter); -#else - perl_destruct (script->interpreter); - perl_free (script->interpreter); -#endif - - weechat_script_remove (plugin, &perl_scripts, script); -} - -/* - * weechat_perl_unload_name: unload a Perl script by name - */ - -void -weechat_perl_unload_name (t_weechat_plugin *plugin, char *name) -{ - t_plugin_script *ptr_script; - - ptr_script = weechat_script_search (plugin, &perl_scripts, name); - if (ptr_script) - { - weechat_perl_unload (plugin, ptr_script); - plugin->print_server (plugin, - "Perl script \"%s\" unloaded", - name); - } - else - { - plugin->print_server (plugin, - "Perl error: script \"%s\" not loaded", - name); - } -} - -/* - * weechat_perl_unload_all: unload all Perl scripts - */ - -void -weechat_perl_unload_all (t_weechat_plugin *plugin) -{ - plugin->print_server (plugin, - "Unloading all Perl scripts"); - while (perl_scripts) - weechat_perl_unload (plugin, perl_scripts); - - plugin->print_server (plugin, - "Perl scripts unloaded"); -} - -/* - * weechat_perl_cmd: /perl command handler - */ - -int -weechat_perl_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; - - if (cmd_argc < 3) - return PLUGIN_RC_KO; - - /* make C compiler happy */ - (void) handler_args; - (void) handler_pointer; - - 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 Perl scripts */ - plugin->print_server (plugin, ""); - plugin->print_server (plugin, "Registered Perl scripts:"); - if (perl_scripts) - { - for (ptr_script = perl_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 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) - plugin->print_server (plugin, " (none)"); - break; - - case 1: - if (plugin->strcasecmp (plugin, argv[0], "autoload") == 0) - weechat_script_auto_load (plugin, "perl", weechat_perl_load); - else if (plugin->strcasecmp (plugin, argv[0], "reload") == 0) - { - weechat_perl_unload_all (plugin); - weechat_script_auto_load (plugin, "perl", weechat_perl_load); - } - else if (plugin->strcasecmp (plugin, argv[0], "unload") == 0) - weechat_perl_unload_all (plugin); - break; - case 2: - if (plugin->strcasecmp (plugin, argv[0], "load") == 0) - { - /* load Perl script */ - path_script = weechat_script_search_full_name (plugin, "perl", argv[1]); - weechat_perl_load (plugin, (path_script) ? path_script : argv[1]); - if (path_script) - free (path_script); - } - else if (plugin->strcasecmp (plugin, argv[0], "unload") == 0) - { - /* unload Perl script */ - weechat_perl_unload_name (plugin, argv[1]); - } - else - { - plugin->print_server (plugin, - "Perl error: unknown option for " - "\"perl\" command"); - } - break; - default: - plugin->print_server (plugin, - "Perl error: wrong argument count for \"perl\" command"); - } - - if (argv) - plugin->free_exploded_string (plugin, argv); - - return PLUGIN_RC_OK; -} - -/* - * weechat_plugin_init: initialize Perl plugin - */ - -int -weechat_plugin_init (t_weechat_plugin *plugin) -{ - perl_plugin = plugin; - -#ifdef MULTIPLICITY - plugin->print_server (plugin, "Loading Perl module \"weechat\""); -#else - char *perl_args[] = { "", "-e", "0" }; - - plugin->print_server (plugin, "Loading Perl module \"weechat\" (without multiplicity)"); - - perl_main = perl_alloc (); - - if (!perl_main) - { - plugin->print_server (plugin, - "Perl error: unable to initialize Perl"); - return PLUGIN_RC_KO; - } - - perl_construct (perl_main); - perl_parse (perl_main, weechat_perl_xs_init, 3, perl_args, NULL); - eval_pv (perl_weechat_code, TRUE); -#endif - - plugin->cmd_handler_add (plugin, "perl", - "list/load/unload Perl scripts", - "[load filename] | [autoload] | [reload] | [unload [script]]", - "filename: Perl script (file) to load\n" - "script: script name to unload\n\n" - "Without argument, /perl command lists all loaded Perl scripts.", - "load|autoload|reload|unload %f", - weechat_perl_cmd, NULL, NULL); - - plugin->mkdir_home (plugin, "perl"); - plugin->mkdir_home (plugin, "perl/autoload"); - - weechat_script_auto_load (plugin, "perl", weechat_perl_load); - - /* init ok */ - return PLUGIN_RC_OK; -} - -/* - * weechat_plugin_end: shutdown Perl interface - */ - -void -weechat_plugin_end (t_weechat_plugin *plugin) -{ - /* unload all scripts */ - weechat_perl_unload_all (plugin); - -#ifndef MULTIPLICITY - /* free perl intepreter */ - if (perl_main) - { - perl_destruct (perl_main); - perl_free (perl_main); - perl_main = NULL; - } -#endif - - perl_plugin->print_server (perl_plugin, - "Perl plugin ended"); -} diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c new file mode 100644 index 000000000..4ccbe7dbf --- /dev/null +++ b/src/plugins/scripts/perl/weechat-perl-api.c @@ -0,0 +1,1865 @@ +/* + * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org> + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/* weechat-perl-api.c: Perl API functions */ + +#undef _ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <EXTERN.h> +#include <perl.h> +#include <XSUB.h> + +#include "../../weechat-plugin.h" +#include "../script.h" +#include "weechat-perl.h" + + +extern void boot_DynaLoader (pTHX_ CV* cv); + + +/* + * weechat::register: startup function for all WeeChat Perl scripts + */ + +static XS (XS_weechat_register) +{ + char *name, *version, *shutdown_func, *description, *charset; + dXSARGS; + + /* make C compiler happy */ + (void) items; + (void) cv; + + perl_current_script = NULL; + + if ((items < 4) || (items > 5)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "register"); + XSRETURN_NO; + } + + name = SvPV (ST (0), PL_na); + version = SvPV (ST (1), PL_na); + shutdown_func = SvPV (ST (2), PL_na); + description = SvPV (ST (3), PL_na); + charset = (items == 5) ? SvPV (ST (4), PL_na) : NULL; + + if (weechat_script_search (weechat_perl_plugin, &perl_scripts, name)) + { + /* error: another script 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"), "perl", name); + XSRETURN_NO; + } + + /* register script */ + perl_current_script = weechat_script_add (weechat_perl_plugin, + &perl_scripts, + (perl_current_script_filename) ? + perl_current_script_filename : "", + name, version, shutdown_func, + description, charset); + if (perl_current_script) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: registered script \"%s\", " + "version %s (%s)"), + weechat_prefix ("info"), "perl", + name, version, description); + } + else + { + XSRETURN_NO; + } + + XSRETURN_YES; +} + +/* + * weechat::charser_set: set script charset + */ + +static XS (XS_weechat_charset_set) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "charset_set"); + XSRETURN_NO; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "charset_set"); + XSRETURN_NO; + } + + weechat_script_charset_set (perl_current_script, + SvPV (ST (0), PL_na)); + + XSRETURN_YES; +} + +/* + * weechat::iconv_to_internal: convert string to internal WeeChat charset + */ + +static XS (XS_weechat_iconv_to_internal) +{ + char *charset, *string, *result; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "iconv_to_internal"); + XSRETURN_EMPTY; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "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); + } + + result = weechat_iconv_to_internal (charset, string); + if (result) + { + XST_mPV (0, result); + free (result); + XSRETURN (1); + } + + XST_mPV (0, ""); + XSRETURN (1); +} + +/* + * weechat::iconv_from_internal: convert string from WeeChat inernal to other + */ + +static XS (XS_weechat_iconv_from_internal) +{ + char *charset, *string, *result; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "iconv_from_internal"); + XSRETURN_EMPTY; + } + + if (items < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "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); + } + + XST_mPV (0, ""); + XSRETURN (1); +} + +/* + * weechat::mkdir_home: create a directory in WeeChat home + */ + +static XS (XS_weechat_mkdir_home) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "mkdir_home"); + XSRETURN_NO; + } + + if (items < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "mkdir_home"); + XSRETURN_NO; + } + + weechat_mkdir_home (SvPV (ST (0), PL_na), /* directory */ + SvIV (ST (1))); /* mode */ + XSRETURN_YES; +} + +/* + * weechat::mkdir: create a directory + */ + +static XS (XS_weechat_mkdir) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "mkdir"); + XSRETURN_NO; + } + + if (items < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "mkdir"); + XSRETURN_NO; + } + + weechat_mkdir (SvPV (ST (0), PL_na), /* directory */ + SvIV (ST (1))); /* mode */ + XSRETURN_YES; +} + +/* + * weechat::prefix: get a prefix, used for display + */ + +static XS (XS_weechat_prefix) +{ + char *result; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "prefix"); + XSRETURN_EMPTY; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "prefix"); + XSRETURN_EMPTY; + } + + result = weechat_prefix (SvPV (ST (0), PL_na)); + if (result) + { + XST_mPV (0, result); + XSRETURN (1); + } + + XST_mPV (0, ""); + XSRETURN (1); +} + +/* + * weechat::color: get a color code, used for display + */ + +static XS (XS_weechat_color) +{ + char *result; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "color"); + XSRETURN_EMPTY; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "color"); + XSRETURN_EMPTY; + } + + result = weechat_color (SvPV (ST (0), PL_na)); + if (result) + { + XST_mPV (0, result); + XSRETURN (1); + } + + XST_mPV (0, ""); + XSRETURN (1); +} + +/* + * weechat::print: print message into a buffer (current or specified one) + */ + +static XS (XS_weechat_print) +{ + char *buffer, *message; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "print"); + XSRETURN_NO; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "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); + } + + weechat_script_printf (weechat_perl_plugin, perl_current_script, + weechat_script_string_to_pointer (buffer), + "%s", message); + + XSRETURN_YES; +} + +/* + * weechat::infobar_print: print message to infobar + */ + +static XS (XS_weechat_infobar_print) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "infobar_print"); + XSRETURN_NO; + } + + if (items < 3) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "infobar_print"); + XSRETURN_NO; + } + + weechat_script_infobar_printf (weechat_perl_plugin, perl_current_script, + SvIV (ST (0)), + SvPV (ST (1), PL_na), + "%s", SvPV (ST (1), PL_na)); + + XSRETURN_YES; +} + +/* + * weechat::infobar_remove: remove message(s) from infobar + */ + +static XS (XS_weechat_infobar_remove) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "infobar_remove"); + XSRETURN_NO; + } + + weechat_infobar_remove ((items >= 1) ? SvIV (ST (0)) : 0); + + XSRETURN_YES; +} + +/* + * weechat::log_print: log message in server/channel (current or specified ones) + */ + +static XS (XS_weechat_log_print) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "log_print"); + XSRETURN_NO; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "log_print"); + XSRETURN_NO; + } + + weechat_script_log_printf (weechat_perl_plugin, perl_current_script, + "%s", SvPV (ST (0), PL_na)); + + XSRETURN_YES; +} + +/* + * weechat_perl_api_hook_command_cb: callback for command hooked + */ + +int +weechat_perl_api_hook_command_cb (void *data, struct t_gui_buffer *buffer, + int argc, char **argv, char **argv_eol) +{ + struct t_script_hook *script_hook; + char *perl_argv[3]; + int *r, ret; + + /* make C compiler happy */ + (void) argv; + + script_hook = (struct t_script_hook *)data; + + perl_argv[0] = weechat_script_pointer_to_string (buffer); + if (argc > 1) + { + perl_argv[1] = argv_eol[1]; + perl_argv[2] = NULL; + } + else + { + perl_argv[1] = NULL; + } + r = (int *) weechat_perl_exec (script_hook->script, + WEECHAT_SCRIPT_EXEC_INT, + script_hook->function, + perl_argv); + if (!r) + ret = WEECHAT_RC_ERROR; + else + { + ret = *r; + free (r); + } + if (perl_argv[0]) + free (perl_argv[0]); + return ret; +} + +/* + * weechat::hook_command: hook a command + */ + +static XS (XS_weechat_hook_command) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "hook_command"); + XSRETURN_NO; + } + + if (items < 6) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "hook_command"); + XSRETURN_NO; + } + + if (weechat_script_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))) + XSRETURN_YES; + + XSRETURN_NO; +} + +/* + * weechat_perl_api_hook_timer_cb: callback for timer hooked + */ + +int +weechat_perl_api_hook_timer_cb (void *data) +{ + struct t_script_hook *script_hook; + char *perl_argv[1] = { NULL }; + int *r, ret; + + script_hook = (struct t_script_hook *)data; + + r = (int *) weechat_perl_exec (script_hook->script, + WEECHAT_SCRIPT_EXEC_INT, + script_hook->function, + perl_argv); + if (!r) + ret = WEECHAT_RC_ERROR; + else + { + ret = *r; + free (r); + } + return ret; +} + +/* + * weechat::hook_timer: hook a timer + */ + +static XS (XS_weechat_hook_timer) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "hook_timer"); + XSRETURN_NO; + } + + if (items < 4) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "hook_timer"); + XSRETURN_NO; + } + + if (weechat_script_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))) + XSRETURN_YES; + + XSRETURN_NO; +} + +/* + * weechat_perl_api_hook_fd_cb: callback for fd hooked + */ + +int +weechat_perl_api_hook_fd_cb (void *data) +{ + struct t_script_hook *script_hook; + char *perl_argv[1] = { NULL }; + int *r; + int ret; + + script_hook = (struct t_script_hook *)data; + + r = (int *) weechat_perl_exec (script_hook->script, + WEECHAT_SCRIPT_EXEC_INT, + script_hook->function, + perl_argv); + if (!r) + ret = WEECHAT_RC_ERROR; + else + { + ret = *r; + free (r); + } + return ret; +} + +/* + * weechat::hook_fd: hook a fd + */ + +static XS (XS_weechat_hook_fd) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "hook_fd"); + XSRETURN_NO; + } + + if (items < 5) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "hook_fd"); + XSRETURN_NO; + } + + if (weechat_script_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))) + XSRETURN_YES; + + XSRETURN_NO; +} + +/* + * weechat_perl_api_hook_print_cb: callback for print hooked + */ + +int +weechat_perl_api_hook_print_cb (void *data, struct t_gui_buffer *buffer, + time_t date, char *prefix, char *message) +{ + struct t_script_hook *script_hook; + char *perl_argv[5]; + static char timebuffer[64]; + int *r, ret; + + script_hook = (struct t_script_hook *)data; + + snprintf (timebuffer, sizeof (timebuffer) - 1, "%ld", date); + + perl_argv[0] = weechat_script_pointer_to_string (buffer); + perl_argv[1] = timebuffer; + perl_argv[2] = prefix; + perl_argv[3] = message; + perl_argv[4] = NULL; + + r = (int *) weechat_perl_exec (script_hook->script, + WEECHAT_SCRIPT_EXEC_INT, + script_hook->function, + perl_argv); + if (!r) + ret = WEECHAT_RC_ERROR; + else + { + ret = *r; + free (r); + } + if (perl_argv[0]) + free (perl_argv[0]); + return ret; +} + +/* + * weechat::hook_print: hook a print + */ + +static XS (XS_weechat_hook_print) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "hook_print"); + XSRETURN_NO; + } + + if (items < 4) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "hook_print"); + XSRETURN_NO; + } + + if (weechat_script_hook_print (weechat_perl_plugin, + perl_current_script, + weechat_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))) + XSRETURN_YES; + + XSRETURN_NO; +} + +/* + * weechat_perl_api_hook_signal_cb: callback for signal hooked + */ + +int +weechat_perl_api_hook_signal_cb (void *data, char *signal, char *type_data, + void *signal_data) +{ + struct t_script_hook *script_hook; + char *perl_argv[3]; + static char value_str[64]; + int *r, ret, free_needed; + + script_hook = (struct t_script_hook *)data; + + perl_argv[0] = signal; + free_needed = 0; + if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) + { + perl_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)); + perl_argv[1] = value_str; + } + else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0) + { + perl_argv[1] = weechat_script_pointer_to_string (signal_data); + free_needed = 1; + } + else + perl_argv[1] = NULL; + perl_argv[2] = NULL; + + r = (int *) weechat_perl_exec (script_hook->script, + WEECHAT_SCRIPT_EXEC_INT, + script_hook->function, + perl_argv); + if (!r) + ret = WEECHAT_RC_ERROR; + else + { + ret = *r; + free (r); + } + if (free_needed && perl_argv[1]) + free (perl_argv[1]); + return ret; +} + +/* + * weechat::hook_signal: hook a signal + */ + +static XS (XS_weechat_hook_signal) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "hook_signal"); + XSRETURN_NO; + } + + if (items < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "hook_signal"); + XSRETURN_NO; + } + + if (weechat_script_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))) + XSRETURN_YES; + + XSRETURN_NO; +} + +/* + * weechat_perl_api_hook_config_cb: callback for config option hooked + */ + +int +weechat_perl_api_hook_config_cb (void *data, char *type, char *option, + char *value) +{ + struct t_script_hook *script_hook; + char *perl_argv[4]; + int *r, ret; + + script_hook = (struct t_script_hook *)data; + + perl_argv[0] = type; + perl_argv[1] = option; + perl_argv[2] = value; + perl_argv[3] = NULL; + + r = (int *) weechat_perl_exec (script_hook->script, + WEECHAT_SCRIPT_EXEC_INT, + script_hook->function, + perl_argv); + if (!r) + ret = WEECHAT_RC_ERROR; + else + { + ret = *r; + free (r); + } + return ret; +} + +/* + * weechat::hook_config: hook a config option + */ + +static XS (XS_weechat_hook_config) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "hook_config"); + XSRETURN_NO; + } + + if (items < 3) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "hook_config"); + XSRETURN_NO; + } + + if (weechat_script_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))) + XSRETURN_YES; + + XSRETURN_NO; +} + +/* + * weechat_perl_api_hook_completion_cb: callback for completion hooked + */ + +int +weechat_perl_api_hook_completion_cb (void *data, char *completion, + struct t_gui_buffer *buffer, + struct t_weelist *list) +{ + struct t_script_hook *script_hook; + char *perl_argv[4]; + int *r, ret; + + script_hook = (struct t_script_hook *)data; + + perl_argv[0] = completion; + perl_argv[1] = weechat_script_pointer_to_string (buffer); + perl_argv[2] = weechat_script_pointer_to_string (list); + perl_argv[3] = NULL; + + r = (int *) weechat_perl_exec (script_hook->script, + WEECHAT_SCRIPT_EXEC_INT, + script_hook->function, + perl_argv); + if (!r) + ret = WEECHAT_RC_ERROR; + else + { + ret = *r; + free (r); + } + if (perl_argv[1]) + free (perl_argv[1]); + if (perl_argv[2]) + free (perl_argv[2]); + return ret; +} + +/* + * weechat::hook_completion: hook a completion + */ + +static XS (XS_weechat_hook_completion) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "hook_completion"); + XSRETURN_NO; + } + + if (items < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "hook_completion"); + XSRETURN_NO; + } + + if (weechat_script_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))) + XSRETURN_YES; + + XSRETURN_NO; +} + +/* + * weechat::unhook: unhook something + */ + +static XS (XS_weechat_unhook) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "unhook"); + XSRETURN_NO; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "unhook"); + XSRETURN_NO; + } + + weechat_script_unhook (weechat_perl_plugin, perl_current_script, + weechat_script_string_to_pointer (SvPV (ST (0), PL_na))); + XSRETURN_YES; +} + +/* + * weechat::command: execute a command on a buffer + */ + +static XS (XS_weechat_command) +{ + char *buffer, *command; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "command"); + XSRETURN_NO; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "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); + } + + weechat_script_command (weechat_perl_plugin, perl_current_script, + weechat_script_string_to_pointer (buffer), + command); + + XSRETURN_YES; +} + +/* + * weechat::info_get: get info about WeeChat + */ + +static XS (XS_weechat_info_get) +{ + char *value; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "info_get"); + XSRETURN_EMPTY; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "info_get"); + XSRETURN_EMPTY; + } + + value = weechat_info_get (SvPV (ST (0), PL_na)); + if (value) + { + XST_mPV (0, value); + XSRETURN (1); + } + + XST_mPV (0, ""); + XSRETURN (1); +} + +/* + * weechat::get_dcc_info: get infos about DCC + */ + +/* +static XS (XS_weechat_get_dcc_info) +{ + t_plugin_dcc_info *dcc_info, *ptr_dcc; + int count; + char timebuffer1[64]; + char timebuffer2[64]; + struct in_addr in; + HV *dcc_hash_member; + dXSARGS; + + // make C compiler happy + (void) cv; + (void) items; + + if (!perl_current_script) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: unable to get DCC info, " + "script not initialized"); + XSRETURN_EMPTY; + } + + dcc_info = weechat_perl_plugin->get_dcc_info (weechat_perl_plugin); + count = 0; + if (!dcc_info) + XSRETURN_EMPTY; + + 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_hash_member = (HV *) sv_2mortal ((SV *) newHV()); + + hv_store (dcc_hash_member, "server", 6, newSVpv (ptr_dcc->server, 0), 0); + hv_store (dcc_hash_member, "channel", 7, newSVpv (ptr_dcc->channel, 0), 0); + hv_store (dcc_hash_member, "type", 4, newSViv (ptr_dcc->type), 0); + hv_store (dcc_hash_member, "status", 6, newSViv (ptr_dcc->status), 0); + hv_store (dcc_hash_member, "start_time", 10, newSVpv (timebuffer1, 0), 0); + hv_store (dcc_hash_member, "start_transfer", 14, newSVpv (timebuffer2, 0), 0); + hv_store (dcc_hash_member, "address", 7, newSVpv (inet_ntoa(in), 0), 0); + hv_store (dcc_hash_member, "port", 4, newSViv (ptr_dcc->port), 0); + hv_store (dcc_hash_member, "nick", 4, newSVpv (ptr_dcc->nick, 0), 0); + hv_store (dcc_hash_member, "remote_file", 11, newSVpv (ptr_dcc->filename, 0), 0); + hv_store (dcc_hash_member, "local_file", 10, newSVpv (ptr_dcc->local_filename, 0), 0); + hv_store (dcc_hash_member, "filename_suffix", 15, newSViv (ptr_dcc->filename_suffix), 0); + hv_store (dcc_hash_member, "size", 4, newSVnv (ptr_dcc->size), 0); + hv_store (dcc_hash_member, "pos", 3, newSVnv (ptr_dcc->pos), 0); + hv_store (dcc_hash_member, "start_resume", 12, newSVnv (ptr_dcc->start_resume), 0); + hv_store (dcc_hash_member, "cps", 3, newSViv (ptr_dcc->bytes_per_sec), 0); + + XPUSHs(newRV_inc((SV *) dcc_hash_member)); + count++; + } + weechat_perl_plugin->free_dcc_info (weechat_perl_plugin, dcc_info); + + XSRETURN (count); +} +*/ + +/* + * weechat::config_get_weechat: get value of a WeeChat config option + */ + + /* +static XS (XS_weechat_config_get_weechat) +{ + char *option; + struct t_config_option *value; + dXSARGS; + + // make C compiler happy + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "config_get_weechat"); + XSRETURN_EMPTY; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "config_get_weechat"); + XSRETURN_EMPTY; + } + + option = SvPV (ST (0), PL_na); + + if (option) + { + value = weechat_config_get_weechat (option); + + if (return_value) + { + XST_mPV (0, return_value); + free (return_value); + XSRETURN (1); + } + } + + XST_mPV (0, ""); + XSRETURN (1); +} +*/ + +/* + * weechat::set_config: set value of a WeeChat config option + */ + +/* +static XS (XS_weechat_set_config) +{ + char *option, *value; + dXSARGS; + + // make C compiler happy + (void) cv; + + if (!perl_current_script) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: unable to set config option, " + "script not initialized"); + XSRETURN_NO; + } + + if (items < 2) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: wrong parameters for " + "\"set_config\" function"); + XSRETURN_NO; + } + + option = SvPV (ST (0), PL_na); + value = SvPV (ST (1), PL_na); + + if (option && value) + { + if (weechat_perl_plugin->set_config (weechat_perl_plugin, option, value)) + XSRETURN_YES; + } + + XSRETURN_NO; +} +*/ + +/* + * weechat::get_plugin_config: get value of a plugin config option + */ + +/* +static XS (XS_weechat_get_plugin_config) +{ + char *option, *return_value; + dXSARGS; + + // make C compiler happy + (void) cv; + + if (!perl_current_script) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: unable to get plugin config option, " + "script not initialized"); + XSRETURN_EMPTY; + } + + if (items < 1) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: wrong parameters for " + "\"get_plugin_config\" function"); + XSRETURN_EMPTY; + } + + option = SvPV (ST (0), PL_na); + + if (option) + { + return_value = weechat_script_get_plugin_config (weechat_perl_plugin, + perl_current_script, + option); + + if (return_value) + { + XST_mPV (0, return_value); + free (return_value); + XSRETURN (1); + } + } + + XST_mPV (0, ""); + XSRETURN (1); +} +*/ + +/* + * weechat::set_plugin_config: set value of a WeeChat config option + */ + +/* +static XS (XS_weechat_set_plugin_config) +{ + char *option, *value; + dXSARGS; + + // make C compiler happy + (void) cv; + + if (!perl_current_script) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: unable to set plugin config option, " + "script not initialized"); + XSRETURN_NO; + } + + if (items < 2) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: wrong parameters for " + "\"set_plugin_config\" function"); + XSRETURN_NO; + } + + option = SvPV (ST (0), PL_na); + value = SvPV (ST (1), PL_na); + + if (option && value) + { + if (weechat_script_set_plugin_config (weechat_perl_plugin, + perl_current_script, + option, value)) + XSRETURN_YES; + } + + XSRETURN_NO; +} +*/ + +/* + * weechat::get_server_info: get infos about servers + */ + +/* +static XS (XS_weechat_get_server_info) +{ + t_plugin_server_info *server_info, *ptr_server; + char timebuffer[64]; + HV *server_hash, *server_hash_member; + dXSARGS; + + // make C compiler happy + (void) cv; + (void) items; + + if (!perl_current_script) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: unable to get server info, " + "script not initialized"); + XSRETURN_EMPTY; + } + + server_info = weechat_perl_plugin->get_server_info (weechat_perl_plugin); + if (!server_info) + { + XSRETURN_EMPTY; + } + + server_hash = (HV *) sv_2mortal((SV *) newHV()); + if (!server_hash) + { + weechat_perl_plugin->free_server_info (weechat_perl_plugin, server_info); + XSRETURN_EMPTY; + } + + 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 = (HV *) sv_2mortal((SV *) newHV()); + + hv_store (server_hash_member, "autoconnect", 11, newSViv (ptr_server->autoconnect), 0); + hv_store (server_hash_member, "autoreconnect", 13, newSViv (ptr_server->autoreconnect), 0); + hv_store (server_hash_member, "autoreconnect_delay", 19, newSViv (ptr_server->autoreconnect_delay), 0); + hv_store (server_hash_member, "temp_server", 11, newSViv (ptr_server->temp_server), 0); + hv_store (server_hash_member, "address", 7, newSVpv (ptr_server->address, 0), 0); + hv_store (server_hash_member, "port", 4, newSViv (ptr_server->port), 0); + hv_store (server_hash_member, "ipv6", 4, newSViv (ptr_server->ipv6), 0); + hv_store (server_hash_member, "ssl", 3, newSViv (ptr_server->ssl), 0); + hv_store (server_hash_member, "password", 8, newSVpv (ptr_server->password, 0), 0); + hv_store (server_hash_member, "nick1", 5, newSVpv (ptr_server->nick1, 0), 0); + hv_store (server_hash_member, "nick2", 5, newSVpv (ptr_server->nick2, 0), 0); + hv_store (server_hash_member, "nick3", 5, newSVpv (ptr_server->nick3, 0), 0); + hv_store (server_hash_member, "username", 8, newSVpv (ptr_server->username, 0), 0); + hv_store (server_hash_member, "realname", 8, newSVpv (ptr_server->realname, 0), 0); + hv_store (server_hash_member, "command", 7, newSVpv (ptr_server->command, 0), 0); + hv_store (server_hash_member, "command_delay", 13, newSViv (ptr_server->command_delay), 0); + hv_store (server_hash_member, "autojoin", 8, newSVpv (ptr_server->autojoin, 0), 0); + hv_store (server_hash_member, "autorejoin", 10, newSViv (ptr_server->autorejoin), 0); + hv_store (server_hash_member, "notify_levels", 13, newSVpv (ptr_server->notify_levels, 0), 0); + hv_store (server_hash_member, "is_connected", 12, newSViv (ptr_server->is_connected), 0); + hv_store (server_hash_member, "ssl_connected", 13, newSViv (ptr_server->ssl_connected), 0); + hv_store (server_hash_member, "nick", 4, newSVpv (ptr_server->nick, 0), 0); + hv_store (server_hash_member, "nick_modes", 10, newSVpv (ptr_server->nick_modes, 0), 0); + hv_store (server_hash_member, "away_time", 9, newSVpv (timebuffer, 0), 0); + hv_store (server_hash_member, "lag", 3, newSViv (ptr_server->lag), 0); + + hv_store (server_hash, ptr_server->name, strlen(ptr_server->name), newRV_inc((SV *) server_hash_member), 0); + } + weechat_perl_plugin->free_server_info (weechat_perl_plugin, server_info); + + ST (0) = newRV_inc((SV *) server_hash); + if (SvREFCNT(ST(0))) sv_2mortal(ST(0)); + + XSRETURN (1); +} +*/ + +/* + * weechat::get_channel_info: get infos about channels + */ + +/* +static XS (XS_weechat_get_channel_info) +{ + t_plugin_channel_info *channel_info, *ptr_channel; + char *server; + HV *channel_hash, *channel_hash_member; + dXSARGS; + + // make C compiler happy + (void) cv; + + if (!perl_current_script) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: unable to get channel info, " + "script not initialized"); + XSRETURN_EMPTY; + } + + if (items != 1) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: wrong parameters for " + "\"get_channel_info\" function"); + XSRETURN_EMPTY; + } + + server = SvPV (ST (0), PL_na); + if (!server) + XSRETURN_EMPTY; + + channel_info = weechat_perl_plugin->get_channel_info (weechat_perl_plugin, server); + if (!channel_info) + { + XSRETURN_EMPTY; + } + + channel_hash = (HV *) sv_2mortal((SV *) newHV()); + if (!channel_hash) + { + weechat_perl_plugin->free_channel_info (weechat_perl_plugin, channel_info); + XSRETURN_EMPTY; + } + + for (ptr_channel = channel_info; ptr_channel; ptr_channel = ptr_channel->next_channel) + { + channel_hash_member = (HV *) sv_2mortal((SV *) newHV()); + + hv_store (channel_hash_member, "type", 4, newSViv (ptr_channel->type), 0); + hv_store (channel_hash_member, "topic", 5, newSVpv (ptr_channel->topic, 0), 0); + hv_store (channel_hash_member, "modes", 5, newSVpv (ptr_channel->modes, 0), 0); + hv_store (channel_hash_member, "limit", 5, newSViv (ptr_channel->limit), 0); + hv_store (channel_hash_member, "key", 3, newSVpv (ptr_channel->key, 0), 0); + hv_store (channel_hash_member, "nicks_count", 11, newSViv (ptr_channel->nicks_count), 0); + + hv_store (channel_hash, ptr_channel->name, strlen(ptr_channel->name), newRV_inc((SV *) channel_hash_member), 0); + } + weechat_perl_plugin->free_channel_info (weechat_perl_plugin, channel_info); + + ST (0) = newRV_inc((SV *) channel_hash); + if (SvREFCNT(ST(0))) sv_2mortal(ST(0)); + + XSRETURN (1); +} +*/ + +/* + * weechat::get_nick_info: get infos about nicks + */ + +/* +static XS (XS_weechat_get_nick_info) +{ + t_plugin_nick_info *nick_info, *ptr_nick; + char *server, *channel; + HV *nick_hash; + dXSARGS; + + // make C compiler happy + (void) cv; + + if (!perl_current_script) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: unable to get nick info, " + "script not initialized"); + XSRETURN_EMPTY; + } + + if (items != 2) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: wrong parameters for " + "\"get_nick_info\" function"); + XSRETURN_EMPTY; + } + + server = SvPV (ST (0), PL_na); + channel = SvPV (ST (1), PL_na); + if (!server || !channel) + XSRETURN_EMPTY; + + nick_info = weechat_perl_plugin->get_nick_info (weechat_perl_plugin, server, channel); + if (!nick_info) + { + XSRETURN_EMPTY; + } + + nick_hash = (HV *) sv_2mortal((SV *) newHV()); + if (!nick_hash) + { + weechat_perl_plugin->free_nick_info (weechat_perl_plugin, nick_info); + XSRETURN_EMPTY; + } + + for (ptr_nick = nick_info; ptr_nick; ptr_nick = ptr_nick->next_nick) + { + HV *nick_hash_member = (HV *) sv_2mortal((SV *) newHV()); + + hv_store (nick_hash_member, "flags", 5, newSViv (ptr_nick->flags), 0); + hv_store (nick_hash_member, "host", 4, newSVpv ( + ptr_nick->host ? ptr_nick->host : "", 0), 0); + + hv_store (nick_hash, ptr_nick->nick, strlen(ptr_nick->nick), newRV_inc((SV *) nick_hash_member), 0); + } + weechat_perl_plugin->free_nick_info (weechat_perl_plugin, nick_info); + + ST (0) = newRV_inc((SV *) nick_hash); + if (SvREFCNT(ST(0))) sv_2mortal(ST(0)); + + XSRETURN (1); +} +*/ + +/* + * weechat::color_input: add color in input buffer + */ + +/* +static XS (XS_weechat_input_color) +{ + int color, start, length; + dXSARGS; + + // make C compiler happy + (void) cv; + + if (!perl_current_script) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: unable to colorize input, " + "script not initialized"); + XSRETURN_NO; + } + + if (items < 3) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: wrong parameters for " + "\"color_input\" function"); + XSRETURN_NO; + } + + color = SvIV (ST (0)); + start = SvIV (ST (1)); + length = SvIV (ST (2)); + + weechat_perl_plugin->input_color (weechat_perl_plugin, color, start, length); + + XSRETURN_YES; +} +*/ + +/* + * weechat::get_irc_color: + * get the numeric value which identify an irc color by its name + */ + +/* +static XS (XS_weechat_get_irc_color) +{ + char *color; + dXSARGS; + + // make C compiler happy + (void) cv; + + if (!perl_current_script) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: unable to get irc color, " + "script not initialized"); + XST_mIV (0, -1); + XSRETURN (1); + } + + if (items != 1) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: wrong parameters for " + "\"get_irc_info\" function"); + XST_mIV (0, -1); + XSRETURN (1); + } + + color = SvPV (ST (0), PL_na); + if (color) + { + XST_mIV (0, weechat_perl_plugin->get_irc_color (weechat_perl_plugin, color)); + XSRETURN (1); + } + + XST_mIV (0, -1); + XSRETURN (-1); +} +*/ + +/* + * weechat::get_window_info: get infos about windows + */ + +/* +static XS (XS_weechat_get_window_info) +{ + t_plugin_window_info *window_info, *ptr_win; + int count; + HV *window_hash_member; + dXSARGS; + + // make C compiler happy + (void) cv; + (void) items; + + if (!perl_current_script) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: unable to get window info, " + "script not initialized"); + XSRETURN_EMPTY; + } + + window_info = weechat_perl_plugin->get_window_info (weechat_perl_plugin); + count = 0; + if (!window_info) + XSRETURN_EMPTY; + + for (ptr_win = window_info; ptr_win; ptr_win = ptr_win->next_window) + { + window_hash_member = (HV *) sv_2mortal((SV *) newHV()); + + hv_store (window_hash_member, "num_buffer", 10, newSViv (ptr_win->num_buffer), 0); + hv_store (window_hash_member, "win_x", 5, newSViv (ptr_win->win_x), 0); + hv_store (window_hash_member, "win_y", 5, newSViv (ptr_win->win_y), 0); + hv_store (window_hash_member, "win_width", 9, newSViv (ptr_win->win_width), 0); + hv_store (window_hash_member, "win_height", 10, newSViv (ptr_win->win_height), 0); + hv_store (window_hash_member, "win_width_pct", 13, newSViv (ptr_win->win_width_pct), 0); + hv_store (window_hash_member, "win_height_pct", 14, newSViv (ptr_win->win_height_pct), 0); + + XPUSHs(newRV_inc((SV *) window_hash_member)); + count++; + } + weechat_perl_plugin->free_window_info (weechat_perl_plugin, window_info); + + XSRETURN (count); +} +*/ + +/* + * weechat::get_buffer_info: get infos about buffers + */ + +/* +static XS (XS_weechat_get_buffer_info) +{ + t_plugin_buffer_info *buffer_info, *ptr_buffer; + HV *buffer_hash, *buffer_hash_member; + char conv[8]; + dXSARGS; + + // make C compiler happy + (void) cv; + (void) items; + + if (!perl_current_script) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: unable to get buffer info, " + "script not initialized"); + XSRETURN_EMPTY; + } + + buffer_info = weechat_perl_plugin->get_buffer_info (weechat_perl_plugin); + if (!buffer_info) + { + XSRETURN_EMPTY; + } + + buffer_hash = (HV *) sv_2mortal((SV *) newHV()); + if (!buffer_hash) + { + weechat_perl_plugin->free_buffer_info (weechat_perl_plugin, buffer_info); + XSRETURN_EMPTY; + } + + for (ptr_buffer = buffer_info; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + buffer_hash_member = (HV *) sv_2mortal((SV *) newHV()); + + hv_store (buffer_hash_member, "type", 4, newSViv (ptr_buffer->type), 0); + hv_store (buffer_hash_member, "num_displayed", 13, newSViv (ptr_buffer->num_displayed), 0); + hv_store (buffer_hash_member, "server", 6, + newSVpv ((ptr_buffer->server_name == NULL) ? "" : ptr_buffer->server_name, 0), 0); + hv_store (buffer_hash_member, "channel", 7, + newSVpv ((ptr_buffer->channel_name == NULL) ? "" : ptr_buffer->channel_name, 0), 0); + hv_store (buffer_hash_member, "notify_level", 12, newSViv (ptr_buffer->notify_level), 0); + hv_store (buffer_hash_member, "log_filename", 12, + newSVpv ((ptr_buffer->log_filename == NULL) ? "" : ptr_buffer->log_filename, 0), 0); + snprintf(conv, sizeof(conv), "%d", ptr_buffer->number); + hv_store (buffer_hash, conv, strlen(conv), newRV_inc((SV *) buffer_hash_member), 0); + } + weechat_perl_plugin->free_buffer_info (weechat_perl_plugin, buffer_info); + + ST (0) = newRV_inc((SV *) buffer_hash); + if (SvREFCNT(ST(0))) sv_2mortal(ST(0)); + + XSRETURN (1); +} +*/ + +/* + * weechat::get_buffer_data: get buffer content + */ + +/* +static XS (XS_weechat_get_buffer_data) +{ + t_plugin_buffer_line *buffer_data, *ptr_data; + HV *data_list_member; + char *server, *channel; + char timebuffer[64]; + int count; + + dXSARGS; + + // make C compiler happy + (void) cv; + (void) items; + + if (!perl_current_script) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: unable to get buffer data, " + "script not initialized"); + XSRETURN_EMPTY; + } + + if (items != 2) + { + weechat_perl_plugin->print_server (weechat_perl_plugin, + "Perl error: wrong parameters for " + "\"get_buffer_data\" function"); + XSRETURN_EMPTY; + } + + channel = NULL; + server = NULL; + + if (items >= 1) + server = SvPV (ST (0), PL_na); + if (items >= 2) + channel = SvPV (ST (1), PL_na); + + SP -= items; + + buffer_data = weechat_perl_plugin->get_buffer_data (weechat_perl_plugin, server, channel); + count = 0; + if (!buffer_data) + XSRETURN_EMPTY; + + for (ptr_data = buffer_data; ptr_data; ptr_data = ptr_data->next_line) + { + data_list_member = (HV *) sv_2mortal((SV *) newHV()); + + strftime(timebuffer, sizeof(timebuffer), "%F %T", + localtime(&ptr_data->date)); + + hv_store (data_list_member, "date", 4, newSVpv (timebuffer, 0), 0); + hv_store (data_list_member, "nick", 4, + newSVpv ((ptr_data->nick == NULL) ? "" : ptr_data->nick, 0), 0); + hv_store (data_list_member, "data", 4, + newSVpv ((ptr_data->data == NULL) ? "" : ptr_data->data, 0), 0); + + XPUSHs(newRV_inc((SV *) data_list_member)); + count++; + } + weechat_perl_plugin->free_buffer_data (weechat_perl_plugin, buffer_data); + + XSRETURN (count); +} +*/ + +/* + * weechat_perl_xs_init: initialize subroutines + */ + +void +weechat_perl_xs_init (pTHX) +{ + HV *stash; + + newXS ("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__); + + /* interface functions */ + newXS ("weechat::register", XS_weechat_register, "weechat"); + newXS ("weechat::charset_set", XS_weechat_charset_set, "weechat"); + newXS ("weechat::iconv_to_internal", XS_weechat_iconv_to_internal, "weechat"); + newXS ("weechat::iconv_from_internal", XS_weechat_iconv_from_internal, "weechat"); + newXS ("weechat::mkdir_home", XS_weechat_mkdir_home, "weechat"); + newXS ("weechat::mkdir", XS_weechat_mkdir, "weechat"); + newXS ("weechat::prefix", XS_weechat_prefix, "weechat"); + newXS ("weechat::color", XS_weechat_color, "weechat"); + newXS ("weechat::print", XS_weechat_print, "weechat"); + newXS ("weechat::infobar_print", XS_weechat_infobar_print, "weechat"); + newXS ("weechat::infobar_remove", XS_weechat_infobar_remove, "weechat"); + newXS ("weechat::log_print", XS_weechat_log_print, "weechat"); + newXS ("weechat::hook_command", XS_weechat_hook_command, "weechat"); + newXS ("weechat::hook_timer", XS_weechat_hook_timer, "weechat"); + newXS ("weechat::hook_fd", XS_weechat_hook_fd, "weechat"); + newXS ("weechat::hook_print", XS_weechat_hook_print, "weechat"); + newXS ("weechat::hook_signal", XS_weechat_hook_signal, "weechat"); + newXS ("weechat::hook_config", XS_weechat_hook_config, "weechat"); + newXS ("weechat::hook_completion", XS_weechat_hook_completion, "weechat"); + newXS ("weechat::unhook", XS_weechat_unhook, "weechat"); + newXS ("weechat::command", XS_weechat_command, "weechat"); + newXS ("weechat::info_get", XS_weechat_info_get, "weechat"); + //newXS ("weechat::get_dcc_info", XS_weechat_get_dcc_info, "weechat"); + //newXS ("weechat::get_config", XS_weechat_get_config, "weechat"); + //newXS ("weechat::set_config", XS_weechat_set_config, "weechat"); + //newXS ("weechat::get_plugin_config", XS_weechat_get_plugin_config, "weechat"); + //newXS ("weechat::set_plugin_config", XS_weechat_set_plugin_config, "weechat"); + //newXS ("weechat::get_server_info", XS_weechat_get_server_info, "weechat"); + //newXS ("weechat::get_channel_info", XS_weechat_get_channel_info, "weechat"); + //newXS ("weechat::get_nick_info", XS_weechat_get_nick_info, "weechat"); + //newXS ("weechat::input_color", XS_weechat_input_color, "weechat"); + //newXS ("weechat::get_irc_color", XS_weechat_get_irc_color, "weechat"); + //newXS ("weechat::get_window_info", XS_weechat_get_window_info, "weechat"); + //newXS ("weechat::get_buffer_info", XS_weechat_get_buffer_info, "weechat"); + //newXS ("weechat::get_buffer_data", XS_weechat_get_buffer_data, "weechat"); + + /* 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_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)); + newCONSTSUB (stash, "weechat::WEECHAT_RC_OK_WITH_HIGHLIGHT", newSViv (WEECHAT_RC_OK_WITH_HIGHLIGHT)); +} diff --git a/src/plugins/scripts/perl/weechat-perl-api.h b/src/plugins/scripts/perl/weechat-perl-api.h new file mode 100644 index 000000000..90a9b3777 --- /dev/null +++ b/src/plugins/scripts/perl/weechat-perl-api.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org> + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef __WEECHAT_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 new file mode 100644 index 000000000..f52137d75 --- /dev/null +++ b/src/plugins/scripts/perl/weechat-perl.c @@ -0,0 +1,734 @@ +/* + * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org> + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/* weechat-perl.c: Perl plugin for WeeChat */ + +#undef _ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <EXTERN.h> +#include <perl.h> +#include <XSUB.h> + +#include "../../weechat-plugin.h" +#include "../script.h" +#include "weechat-perl.h" +#include "weechat-perl-api.h" + + +WEECHAT_PLUGIN_NAME("perl"); +WEECHAT_PLUGIN_DESCRIPTION("Perl plugin for WeeChat"); +WEECHAT_PLUGIN_AUTHOR("FlashCode <flashcode@flashtux.org>"); +WEECHAT_PLUGIN_VERSION("0.1"); +WEECHAT_PLUGIN_LICENSE("GPL"); + +struct t_weechat_plugin *weechat_perl_plugin = NULL; + +struct t_plugin_script *perl_scripts = NULL; +struct t_plugin_script *perl_current_script = NULL; +char *perl_current_script_filename = NULL; + +#ifdef NO_PERL_MULTIPLICITY +#undef MULTIPLICITY +#endif + +#ifndef MULTIPLICITY +#define PKG_NAME_PREFIX "WeechatPerlPackage" +static PerlInterpreter *perl_main = NULL; +int perl_num = 0; +#endif + +char *perl_weechat_code = +{ +#ifndef MULTIPLICITY + "package WeechatPerlScriptLoader;" +#endif + "$weechat_perl_load_eval_file_error = \"\";" + "sub weechat_perl_load_file" + "{" + " my $filename = shift;" + " local $/ = undef;" + " open FILE, $filename or return \"__WEECHAT_PERL_ERROR__\";" + " $_ = <FILE>;" + " close FILE;" + " return $_;" + "}" + "sub weechat_perl_load_eval_file" + "{" +#ifndef MULTIPLICITY + " my ($filename, $package) = @_;" +#else + " my $filename = shift;" +#endif + " my $content = weechat_perl_load_file ($filename);" + " if ($content eq \"__WEECHAT_PERL_ERROR__\")" + " {" + " return 1;" + " }" +#ifndef MULTIPLICITY + " my $eval = qq{package $package; $content;};" +#else + " my $eval = $content;" +#endif + " {" + " eval $eval;" + " }" + " if ($@)" + " {" + " $weechat_perl_load_eval_file_error = $@;" + " return 2;" + " }" + " return 0;" + "}" + "$SIG{__WARN__} = sub { weechat::print \"Perl error: $_[0]\", \"\"; };" + "$SIG{__DIE__} = sub { weechat::print \"Perl error: $_[0]\", \"\"; };" +}; + + +/* + * weechat_perl_exec: execute a Perl script + */ + +void * +weechat_perl_exec (struct t_plugin_script *script, + int ret_type, char *function, char **argv) +{ + char *func; + unsigned int count; + void *ret_value; + int *ret_i, mem_err; + SV *ret_s; + + /* this code is placed here to conform ISO C90 */ + dSP; + +#ifndef MULTIPLICITY + int size = strlen (script->interpreter) + strlen(function) + 3; + func = (char *)malloc (size * sizeof(char)); + if (!func) + return NULL; + snprintf (func, size, "%s::%s", (char *) script->interpreter, function); +#else + func = function; + PERL_SET_CONTEXT (script->interpreter); +#endif + + ENTER; + SAVETMPS; + PUSHMARK(sp); + + /* are we loading the script file ? */ + if (strcmp (function, "weechat_perl_load_eval_file") != 0) + perl_current_script = script; + + count = perl_call_argv (func, G_EVAL | G_SCALAR, argv); + ret_value = NULL; + mem_err = 1; + + SPAGAIN; + + if (SvTRUE (ERRSV)) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: error: %s"), + weechat_prefix ("error"), "perl", SvPV_nolen (ERRSV)); + (void) POPs; /* poping the 'undef' */ + mem_err = 0; + } + else + { + if (count != 1) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: function \"%s\" must " + "return one valid value (%d)"), + weechat_prefix ("error"), "perl", function, count); + mem_err = 0; + } + else + { + if (ret_type == WEECHAT_SCRIPT_EXEC_STRING) + { + ret_s = newSVsv(POPs); + ret_value = strdup (SvPV_nolen (ret_s)); + SvREFCNT_dec (ret_s); + } + else if (ret_type == WEECHAT_SCRIPT_EXEC_INT) + { + ret_i = (int *)malloc (sizeof(int)); + if (ret_i) + *ret_i = POPi; + ret_value = ret_i; + } + else + { + weechat_printf (NULL, + weechat_gettext ("%s%s: function \"%s\" is " + "internally misused"), + weechat_prefix ("error"), "perl", function); + mem_err = 0; + } + } + } + + PUTBACK; + FREETMPS; + LEAVE; + +#ifndef MULTIPLICITY + free (func); +#endif + + if (!ret_value && (mem_err == 1)) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: not enough memory in function " + "\"%s\""), + weechat_prefix ("error"), "perl", function); + return NULL; + } + + return ret_value; +} + +/* + * weechat_perl_load: load a Perl script + */ + +int +weechat_perl_load (char *filename) +{ + STRLEN len; + struct t_plugin_script tempscript; + int *eval; + struct stat buf; + char *perl_argv[2]; + +#ifndef MULTIPLICITY + char pkgname[64]; +#else + PerlInterpreter *perl_current_interpreter; + char *perl_args[] = { "", "-e", "0" }; +#endif + + weechat_printf (NULL, + weechat_gettext ("%s%s: loading Perl script \"%s\""), + weechat_prefix ("info"), "perl", filename); + + if (stat (filename, &buf) != 0) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: script \"%s\" not found"), + weechat_prefix ("error"), "perl", filename); + return 0; + } + + perl_current_script = NULL; + +#ifndef MULTIPLICITY + snprintf(pkgname, sizeof(pkgname), "%s%d", PKG_NAME_PREFIX, perl_num); + perl_num++; + tempscript.interpreter = "WeechatPerlScriptLoader"; + perl_argv[0] = filename; + perl_argv[1] = pkgname; + perl_argv[2] = NULL; + eval = weechat_perl_exec (plugin, &tempscript, + WEECHAT_SCRIPT_EXEC_INT, + "weechat_perl_load_eval_file", perl_argv); +#else + perl_current_interpreter = perl_alloc(); + + if (!perl_current_interpreter) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: unable to create new " + "sub-interpreter"), + weechat_prefix ("error"), "perl"); + return 0; + } + + perl_current_script_filename = filename; + + PERL_SET_CONTEXT (perl_current_interpreter); + perl_construct (perl_current_interpreter); + tempscript.interpreter = (PerlInterpreter *) perl_current_interpreter; + perl_parse (perl_current_interpreter, weechat_perl_xs_init, 3, perl_args, + NULL); + + eval_pv (perl_weechat_code, TRUE); + perl_argv[0] = filename; + perl_argv[1] = NULL; + eval = weechat_perl_exec (&tempscript, + WEECHAT_SCRIPT_EXEC_INT, + "weechat_perl_load_eval_file", + perl_argv); +#endif + if (!eval) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: not enough memory to parse " + "file \"%s\""), + weechat_prefix ("error"), "perl", filename); + return 0; + } + + if ( *eval != 0) + { + if (*eval == 2) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: unable to parse file " + "\"%s\""), + weechat_prefix ("error"), "perl", filename); + weechat_printf (NULL, + weechat_gettext ("%s%s: error: %s"), + weechat_prefix ("error"), "perl", +#ifndef MULTIPLICITY + SvPV(perl_get_sv("WeechatPerlScriptLoader::" + "weechat_perl_load_eval_file_error", + FALSE), len) +#else + SvPV(perl_get_sv("weechat_perl_load_eval_file_error", + FALSE), len) +#endif + ); + } + else if (*eval == 1) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: unable to run file \"%s\""), + weechat_prefix ("error"), "perl", filename); + } + else + { + weechat_printf (NULL, + weechat_gettext ("%s%s: unknown error while " + "loading file \"%s\""), + weechat_prefix ("error"), "perl", filename); + } +#ifdef MULTIPLICITY + perl_destruct (perl_current_interpreter); + perl_free (perl_current_interpreter); +#endif + if (perl_current_script && (perl_current_script != &tempscript)) + weechat_script_remove (weechat_perl_plugin, + &perl_scripts, perl_current_script); + + free (eval); + return 0; + } + + free (eval); + + if (!perl_current_script) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: function \"register\" not " + "found (or failed) in file \"%s\""), + weechat_prefix ("error"), "perl", filename); +#ifdef MULTIPLICITY + perl_destruct (perl_current_interpreter); + perl_free (perl_current_interpreter); +#endif + return 0; + } + +#ifndef MULTIPLICITY + perl_current_script->interpreter = strdup (pkgname); +#else + perl_current_script->interpreter = (PerlInterpreter *)perl_current_interpreter; +#endif + + return 1; +} + +/* + * weechat_perl_load_cb: callback for weechat_script_auto_load() function + */ + +int +weechat_perl_load_cb (void *data, char *filename) +{ + /* make C compiler happy */ + (void) data; + + return weechat_perl_load (filename); +} + +/* + * weechat_perl_unload: unload a Perl script + */ + +void +weechat_perl_unload (struct t_plugin_script *script) +{ + int *r; + char *perl_argv[1] = { NULL }; + + weechat_printf (NULL, + weechat_gettext ("%s%s: unloading script \"%s\""), + weechat_prefix ("info"), "perl", script->name); + +#ifndef MULTIPLICITY + eval_pv (script->interpreter, TRUE); +#else + PERL_SET_CONTEXT (script->interpreter); +#endif + + if (script->shutdown_func[0]) + { + r = (int *) weechat_perl_exec (script, + WEECHAT_SCRIPT_EXEC_INT, + script->shutdown_func, + perl_argv); + if (r) + free (r); + } + +#ifndef MULTIPLICITY + if (script->interpreter) + free (script->interpreter); +#else + perl_destruct (script->interpreter); + perl_free (script->interpreter); +#endif + + weechat_script_remove (weechat_perl_plugin, &perl_scripts, script); +} + +/* + * weechat_perl_unload_name: unload a Perl script by name + */ + +void +weechat_perl_unload_name (char *name) +{ + struct t_plugin_script *ptr_script; + + ptr_script = weechat_script_search (weechat_perl_plugin, + &perl_scripts, name); + if (ptr_script) + { + weechat_perl_unload (ptr_script); + weechat_printf (NULL, + weechat_gettext ("%s%s: script \"%s\" unloaded"), + weechat_prefix ("info"), "perl", name); + } + else + { + weechat_printf (NULL, + weechat_gettext ("%s%s: script \"%s\" not loaded"), + weechat_prefix ("error"), "perl", name); + } +} + +/* + * weechat_perl_unload_all: unload all Perl scripts + */ + +void +weechat_perl_unload_all () +{ + while (perl_scripts) + { + weechat_perl_unload (perl_scripts); + } +} + +/* + * weechat_perl_command_cb: callback for "/perl" command + */ + +int +weechat_perl_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 Perl scripts */ + weechat_printf (NULL, ""); + weechat_printf (NULL, weechat_gettext ("Registered Perl scripts:")); + if (perl_scripts) + { + for (ptr_script = perl_scripts; + ptr_script; ptr_script = ptr_script->next_script) + { + weechat_printf (NULL, + " %s v%s%s%s", + ptr_script->name, + ptr_script->version, + (ptr_script->description[0]) ? " - " : "", + ptr_script->description); + } + } + else + weechat_printf (NULL, " (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) + plugin->print_server (plugin, " (none)"); + */ + } + else if (argc == 2) + { + if (weechat_strcasecmp (argv[1], "autoload") == 0) + { + weechat_script_auto_load (weechat_perl_plugin, + "perl", &weechat_perl_load_cb); + } + else if (weechat_strcasecmp (argv[1], "reload") == 0) + { + weechat_perl_unload_all (); + weechat_script_auto_load (weechat_perl_plugin, + "perl", &weechat_perl_load_cb); + } + else if (weechat_strcasecmp (argv[1], "unload") == 0) + { + weechat_perl_unload_all (); + } + } + else + { + if (weechat_strcasecmp (argv[1], "load") == 0) + { + /* load Perl script */ + path_script = weechat_script_search_full_name (weechat_perl_plugin, + "perl", argv_eol[2]); + weechat_perl_load ((path_script) ? path_script : argv_eol[2]); + if (path_script) + free (path_script); + } + else if (weechat_strcasecmp (argv[1], "unload") == 0) + { + /* unload Perl script */ + weechat_perl_unload_name (argv_eol[2]); + } + else + { + weechat_printf (NULL, + weechat_gettext ("%s%s: unknown option for " + "command \"%s\""), + weechat_prefix ("error"), "perl", "perl"); + } + } + + return WEECHAT_RC_OK; +} + +/* + * weechat_plugin_init: initialize Perl plugin + */ + +int +weechat_plugin_init (struct t_weechat_plugin *plugin) +{ + weechat_perl_plugin = plugin; + +#ifndef MULTIPLICITY + char *perl_args[] = { "", "-e", "0" }; + + perl_main = perl_alloc (); + + if (!perl_main) + { + weechat_printf (NULL, + weechat_gettext ("%s%s: unable to initialize Perl"), + weechat_prefix ("error"), "perl"); + return WEECHAT_RC_ERROR; + } + + perl_construct (perl_main); + perl_parse (perl_main, weechat_perl_xs_init, 3, perl_args, NULL); + eval_pv (perl_weechat_code, TRUE); +#endif + + weechat_hook_command ("perl", + weechat_gettext ("list/load/unload Perl scripts"), + weechat_gettext ("[load filename] | [autoload] | " + "[reload] | [unload [script]]"), + weechat_gettext ("filename: Perl script (file) to " + "load\n" + "script: script name to unload\n\n" + "Without argument, /perl command " + "lists all loaded Perl scripts."), + "load|autoload|reload|unload %f", + &weechat_perl_command_cb, NULL); + + weechat_mkdir_home ("perl", 0644); + weechat_mkdir_home ("perl/autoload", 0644); + + weechat_script_auto_load (weechat_perl_plugin, + "perl", &weechat_perl_load_cb); + + /* init ok */ + return WEECHAT_RC_OK; +} + +/* + * weechat_plugin_end: end Perl plugin + */ + +void +weechat_plugin_end (struct t_weechat_plugin *plugin) +{ + /* make C compiler happy */ + (void) plugin; + + /* unload all scripts */ + weechat_perl_unload_all (weechat_perl_plugin); + +#ifndef MULTIPLICITY + /* free perl intepreter */ + if (perl_main) + { + perl_destruct (perl_main); + perl_free (perl_main); + perl_main = NULL; + } +#endif +} diff --git a/src/plugins/scripts/perl/weechat-perl.h b/src/plugins/scripts/perl/weechat-perl.h new file mode 100644 index 000000000..3aab01578 --- /dev/null +++ b/src/plugins/scripts/perl/weechat-perl.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org> + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef __WEECHAT_PERL_H +#define __WEECHAT_PERL_H 1 + +#include "../../weechat-plugin.h" +#include "../script.h" + +#define weechat_plugin weechat_perl_plugin + +extern struct t_weechat_plugin *weechat_perl_plugin; + +extern struct t_plugin_script *perl_scripts; +extern struct t_plugin_script *perl_current_script; +extern char *perl_current_script_filename; + +extern void * weechat_perl_exec (struct t_plugin_script *script, + int ret_type, char *function, char **argv); + +#endif /* weechat-perl.h */ diff --git a/src/plugins/scripts/script.c b/src/plugins/scripts/script.c index f9340c917..42f3365eb 100644 --- a/src/plugins/scripts/script.c +++ b/src/plugins/scripts/script.c @@ -33,50 +33,84 @@ /* + * weechat_script_pointer_to_string: convert pointer to string for usage + * in a script (any language) + * WARNING: result has to be free() after use + */ + +char * +weechat_script_pointer_to_string (void *pointer) +{ + char pointer_str[128]; + + if (!pointer) + return strdup (""); + + snprintf (pointer_str, sizeof (pointer_str) - 1, + "0x%x", (unsigned int)pointer); + + return strdup (pointer_str); +} + +/* + * weechat_script_string_to_pointer: convert stirng to pointer for usage + * outside script + */ + +void * +weechat_script_string_to_pointer (char *pointer_str) +{ + unsigned int value; + + if (!pointer_str || (pointer_str[0] != '0') || (pointer_str[0] != 'x')) + return NULL; + + sscanf (pointer_str + 2, "%x", &value); + + return (void *)value; +} + +/* * weechat_script_auto_load: auto-load all scripts in a directory */ void -weechat_script_auto_load (struct t_weechat_plugin *plugin, char *language, +weechat_script_auto_load (struct t_weechat_plugin *weechat_plugin, + char *language, int (*callback)(void *data, char *filename)) { char *dir_home, *dir_name; int dir_length; /* build directory, adding WeeChat home */ - dir_home = plugin->get_info (plugin, "weechat_dir", NULL); + dir_home = weechat_info_get ("weechat_dir"); if (!dir_home) return; dir_length = strlen (dir_home) + strlen (language) + 16; - dir_name = - (char *)malloc (dir_length * sizeof (char)); + dir_name = (char *)malloc (dir_length * sizeof (char)); if (!dir_name) - { - free (dir_home); return; - } - snprintf (dir_name, dir_length, "%s/%s/autoload", dir_home, language); - plugin->exec_on_files (dir_name, plugin, callback); + snprintf (dir_name, dir_length, "%s/%s/autoload", dir_home, language); + weechat_exec_on_files (dir_name, NULL, callback); free (dir_name); - free (dir_home); } /* * weechat_script_search: search a script in list */ -t_plugin_script * -weechat_script_search (struct t_weechat_plugin *plugin, - t_plugin_script **list, char *name) +struct t_plugin_script * +weechat_script_search (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script **list, char *name) { - t_plugin_script *ptr_script; + struct t_plugin_script *ptr_script; for (ptr_script = *list; ptr_script; ptr_script = ptr_script->next_script) { - if (plugin->strcasecmp (plugin, ptr_script->name, name) == 0) + if (weechat_strcasecmp (ptr_script->name, name) == 0) return ptr_script; } @@ -89,7 +123,7 @@ weechat_script_search (struct t_weechat_plugin *plugin, */ char * -weechat_script_search_full_name (struct t_weechat_plugin *plugin, +weechat_script_search_full_name (struct t_weechat_plugin *weechat_plugin, char *language, char *filename) { char *final_name, *dir_home, *dir_system; @@ -110,110 +144,90 @@ weechat_script_search_full_name (struct t_weechat_plugin *plugin, } return NULL; } - - /* try WeeChat user's autoload dir */ - dir_home = plugin->get_info (plugin, "weechat_dir", NULL); + + dir_home = weechat_info_get ("weechat_dir"); if (dir_home) { + /* try WeeChat user's autoload dir */ length = strlen (dir_home) + strlen (language) + 8 + strlen (filename) + 16; final_name = (char *)malloc (length); if (final_name) { - snprintf (final_name, length, "%s/%s/autoload/%s", dir_home, language, filename); + snprintf (final_name, length, + "%s/%s/autoload/%s", dir_home, language, filename); if ((stat (final_name, &st) == 0) && (st.st_size > 0)) - { - free (dir_home); return final_name; - } free (final_name); } - free (dir_home); - } - - /* try WeeChat language user's dir */ - dir_home = plugin->get_info (plugin, "weechat_dir", NULL); - if (dir_home) - { + + /* try WeeChat language user's dir */ length = strlen (dir_home) + strlen (language) + strlen (filename) + 16; final_name = (char *)malloc (length); if (final_name) { - snprintf (final_name, length, "%s/%s/%s", dir_home, language, filename); + snprintf (final_name, length, + "%s/%s/%s", dir_home, language, filename); if ((stat (final_name, &st) == 0) && (st.st_size > 0)) - { - free (dir_home); return final_name; - } free (final_name); } - free (dir_home); - } - - /* try WeeChat user's dir */ - dir_home = plugin->get_info (plugin, "weechat_dir", NULL); - if (dir_home) - { + + /* try WeeChat user's dir */ length = strlen (dir_home) + strlen (filename) + 16; final_name = (char *)malloc (length); if (final_name) { - snprintf (final_name, length, "%s/%s", dir_home, filename); + snprintf (final_name, length, + "%s/%s", dir_home, filename); if ((stat (final_name, &st) == 0) && (st.st_size > 0)) - { - free (dir_home); return final_name; - } free (final_name); } - free (dir_home); } - + /* try WeeChat system dir */ - dir_system = plugin->get_info (plugin, "weechat_sharedir", NULL); + dir_system = weechat_info_get ("weechat_sharedir"); if (dir_system) { length = strlen (dir_system) + strlen (dir_system) + strlen (filename) + 16; final_name = (char *)malloc (length); if (final_name) { - snprintf (final_name,length, "%s/%s/%s", dir_system, language, filename); + snprintf (final_name,length, + "%s/%s/%s", dir_system, language, filename); if ((stat (final_name, &st) == 0) && (st.st_size > 0)) - { - free (dir_system); return final_name; - } free (final_name); } - free (dir_system); } - - return strdup(filename); + + return strdup (filename); } /* * weechat_script_add: add a script to list of scripts */ -t_plugin_script * -weechat_script_add (struct t_weechat_plugin *plugin, - t_plugin_script **script_list, +struct t_plugin_script * +weechat_script_add (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script **script_list, char *filename, char *name, char *version, char *shutdown_func, char *description, char *charset) { - t_plugin_script *new_script; + struct t_plugin_script *new_script; if (strchr (name, ' ')) { - plugin->print_server (plugin, - "Error: unable to load script " - "\"%s\" (bad name, spaces are forbidden)", - name); + weechat_printf (NULL, + _("%s: error loading script \"%s\" (bad name, spaces " + "are forbidden)"), + weechat_plugin->name, name); return NULL; } - new_script = (t_plugin_script *)malloc (sizeof (t_plugin_script)); + new_script = (struct t_plugin_script *)malloc (sizeof (struct t_plugin_script)); if (new_script) { new_script->filename = strdup (filename); @@ -224,59 +238,64 @@ weechat_script_add (struct t_weechat_plugin *plugin, new_script->description = strdup (description); new_script->charset = (charset) ? strdup (charset) : NULL; + new_script->hooks = NULL; + /* add new script to list */ if ((*script_list)) (*script_list)->prev_script = new_script; new_script->prev_script = NULL; new_script->next_script = (*script_list); (*script_list) = new_script; + return new_script; } - - plugin->print_server (plugin, - "Error: unable to load script " - "\"%s\" (not enough memory)", - name); + + weechat_printf (NULL, + _("%s: error loading script \"%s\" (not enough memory)"), + weechat_plugin->name, name); + return NULL; } /* + * weechat_script_remove_script_hook: remove a script_hook from script + */ + +void +weechat_script_remove_script_hook (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + struct t_script_hook *script_hook) +{ + /* remove script_hook from list */ + if (script_hook->prev_hook) + script_hook->prev_hook->next_hook = script_hook->next_hook; + if (script_hook->next_hook) + script_hook->next_hook->prev_hook = script_hook->prev_hook; + if (script->hooks == script_hook) + script->hooks = script_hook->next_hook; + + /* unhook and free data */ + if (script_hook->hook) + weechat_unhook (script_hook->hook); + if (script_hook->function) + free (script_hook->function); +} + +/* * weechat_script_remove: remove a script from list of scripts */ void -weechat_script_remove (struct t_weechat_plugin *plugin, - t_plugin_script **script_list, t_plugin_script *script) +weechat_script_remove (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script **script_list, + struct t_plugin_script *script) { - t_plugin_handler *ptr_handler, *next_handler; - t_plugin_modifier *ptr_modifier, *next_modifier; - - /* remove all handlers pointing to script */ - ptr_handler = plugin->handlers; - while (ptr_handler) + /* remove all hooks created by this script */ + while (script->hooks) { - if ((t_plugin_script *)ptr_handler->handler_pointer == script) - { - next_handler = ptr_handler->next_handler; - plugin->handler_remove (plugin, ptr_handler); - ptr_handler = next_handler; - } - else - ptr_handler = ptr_handler->next_handler; - } - - /* remove all modifiers pointing to script */ - ptr_modifier = plugin->modifiers; - while (ptr_modifier) - { - if ((t_plugin_script *)ptr_modifier->modifier_pointer == script) - { - next_modifier = ptr_modifier->next_modifier; - plugin->modifier_remove (plugin, ptr_modifier); - ptr_modifier = next_modifier; - } - else - ptr_modifier = ptr_modifier->next_modifier; + weechat_script_remove_script_hook (weechat_plugin, + script, + script->hooks); } /* free data */ @@ -306,296 +325,469 @@ weechat_script_remove (struct t_weechat_plugin *plugin, } /* - * weechat_script_print: print a message on a server or channel buffer + * weechat_script_charset_set: set charset for script */ void -weechat_script_print (struct t_weechat_plugin *plugin, - t_plugin_script *script, - char *server, char *channel, - char *message, ...) +weechat_script_charset_set (struct t_plugin_script *script, + char *charset) { - va_list argptr; - static char buf[8192]; - char *buf2; - - va_start (argptr, message); - vsnprintf (buf, sizeof (buf) - 1, message, argptr); - va_end (argptr); + if (script->charset) + free (script->charset); - buf2 = (script->charset && script->charset[0]) ? - plugin->iconv_to_internal (plugin, script->charset, buf) : NULL; - plugin->print (plugin, server, channel, "%s", (buf2) ? buf2 : buf); - if (buf2) - free (buf2); + script->charset = (charset) ? strdup (charset) : NULL; } /* - * weechat_script_print_server: print a message on server buffer + * weechat_script_printf: print a message */ void -weechat_script_print_server (struct t_weechat_plugin *plugin, - t_plugin_script *script, - char *message, ...) +weechat_script_printf (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + struct t_gui_buffer *buffer, char *format, ...) { va_list argptr; static char buf[8192]; char *buf2; - va_start (argptr, message); - vsnprintf (buf, sizeof (buf) - 1, message, argptr); + va_start (argptr, format); + vsnprintf (buf, sizeof (buf) - 1, format, argptr); va_end (argptr); buf2 = (script->charset && script->charset[0]) ? - plugin->iconv_to_internal (plugin, script->charset, buf) : NULL; - plugin->print_server (plugin, "%s", (buf2) ? buf2 : buf); + weechat_iconv_to_internal (script->charset, buf) : NULL; + weechat_printf (buffer, "%s", (buf2) ? buf2 : buf); if (buf2) free (buf2); } /* - * weechat_script_print_infobar: print a message in infobar + * weechat_script_infobar_printf: print a message in infobar */ void -weechat_script_print_infobar (struct t_weechat_plugin *plugin, - t_plugin_script *script, - int delay, char *message, ...) +weechat_script_infobar_printf (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + int delay, char *color_name, char *format, ...) { va_list argptr; static char buf[1024]; char *buf2; - va_start (argptr, message); - vsnprintf (buf, sizeof (buf) - 1, message, argptr); + va_start (argptr, format); + vsnprintf (buf, sizeof (buf) - 1, format, argptr); va_end (argptr); buf2 = (script->charset && script->charset[0]) ? - plugin->iconv_to_internal (plugin, script->charset, buf) : NULL; - plugin->print_infobar (plugin, delay, "%s", (buf2) ? buf2 : buf); + weechat_iconv_to_internal (script->charset, buf) : NULL; + weechat_infobar_printf (delay, color_name, "%s", (buf2) ? buf2 : buf); if (buf2) free (buf2); } /* - * weechat_script_log: add a message in buffer log file + * weechat_script_log_printf: add a message in WeeChat log file */ void -weechat_script_log (struct t_weechat_plugin *plugin, - t_plugin_script *script, - char *server, char *channel, char *message, ...) +weechat_script_log_printf (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + char *format, ...) { va_list argptr; static char buf[1024]; char *buf2; - va_start (argptr, message); - vsnprintf (buf, sizeof (buf) - 1, message, argptr); + va_start (argptr, format); + vsnprintf (buf, sizeof (buf) - 1, format, argptr); va_end (argptr); buf2 = (script->charset && script->charset[0]) ? - plugin->iconv_to_internal (plugin, script->charset, buf) : NULL; - plugin->log (plugin, server, channel, "%s", (buf2) ? buf2 : buf); + weechat_iconv_to_internal (script->charset, buf) : NULL; + weechat_log_printf ("%s", (buf2) ? buf2 : buf); if (buf2) free (buf2); } /* - * weechat_script_exec_command: execute a command (simulate user entry) + * weechat_script_hook_command: hook a command + * return 1 if ok, 0 if error */ -void -weechat_script_exec_command (struct t_weechat_plugin *plugin, - t_plugin_script *script, - char *server, char *channel, char *command) +int +weechat_script_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) { - char *command2; + struct t_script_hook *new_script_hook; + struct t_hook *new_hook; + + new_script_hook = (struct t_script_hook *)malloc (sizeof (struct t_script_hook)); + if (!new_script_hook) + return 0; + + new_script_hook->hook = NULL; + new_script_hook->function = NULL; + new_script_hook->script = NULL; - command2 = (script->charset && script->charset[0]) ? - plugin->iconv_to_internal (plugin, script->charset, command) : NULL; - plugin->exec_command (plugin, server, channel, - (command2) ? command2 : command); - if (command2) - free (command2); + new_hook = weechat_hook_command (command, description, args, + args_description, completion, + callback, new_script_hook); + if (!new_hook) + { + free (new_script_hook); + return 0; + } + + new_script_hook->hook = new_hook; + new_script_hook->function = strdup (function); + new_script_hook->script = script; + + /* add script_hook to list of hooks for current script */ + if (script->hooks) + script->hooks->prev_hook = new_script_hook; + new_script_hook->prev_hook = NULL; + new_script_hook->next_hook = script->hooks; + script->hooks = new_script_hook; + + return 1; } /* - * weechat_script_remove_handler: remove a handler for a script - * for a msg handler, arg1=irc command, arg2=function - * for a cmd handler, arg1=command, arg2=function + * weechat_script_hook_timer: hook a timer + * return 1 if ok, 0 if error */ -void -weechat_script_remove_handler (struct t_weechat_plugin *plugin, - t_plugin_script *script, - char *arg1, char *arg2) +int +weechat_script_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) { - t_plugin_handler *ptr_handler, *next_handler; - char *ptr_arg1; + struct t_script_hook *new_script_hook; + struct t_hook *new_hook; + + new_script_hook = (struct t_script_hook *)malloc (sizeof (struct t_script_hook)); + if (!new_script_hook) + return 0; + + new_script_hook->hook = NULL; + new_script_hook->function = NULL; + new_script_hook->script = NULL; - /* search and remove handlers */ - ptr_handler = plugin->handlers; - while (ptr_handler) + new_hook = weechat_hook_timer (interval, align_second, max_calls, + callback, new_script_hook); + if (!new_hook) { - ptr_arg1 = NULL; - if (ptr_handler->type == PLUGIN_HANDLER_MESSAGE) - ptr_arg1 = ptr_handler->irc_command; - else if (ptr_handler->type == PLUGIN_HANDLER_COMMAND) - ptr_arg1 = ptr_handler->command; - - if ((ptr_arg1) - && ((t_plugin_script *)ptr_handler->handler_pointer == script) - && (plugin->strcasecmp (plugin, ptr_arg1, arg1) == 0) - && (plugin->strcasecmp (plugin, ptr_handler->handler_args, arg2) == 0)) - { - next_handler = ptr_handler->next_handler; - plugin->handler_remove (plugin, ptr_handler); - ptr_handler = next_handler; - } - else - ptr_handler = ptr_handler->next_handler; + free (new_script_hook); + return 0; } + + new_script_hook->hook = new_hook; + new_script_hook->function = strdup (function); + new_script_hook->script = script; + + /* add script_hook to list of hooks for current script */ + if (script->hooks) + script->hooks->prev_hook = new_script_hook; + new_script_hook->prev_hook = NULL; + new_script_hook->next_hook = script->hooks; + script->hooks = new_script_hook; + + return 1; } /* - * weechat_script_remove_timer_handler: remove a timer handler for a script + * weechat_script_hook_fd: hook a fd + * return 1 if ok, 0 if error */ -void -weechat_script_remove_timer_handler (struct t_weechat_plugin *plugin, - t_plugin_script *script, - char *function) +int +weechat_script_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) { - t_plugin_handler *ptr_handler, *next_handler; + struct t_script_hook *new_script_hook; + struct t_hook *new_hook; + + new_script_hook = (struct t_script_hook *)malloc (sizeof (struct t_script_hook)); + if (!new_script_hook) + return 0; + + new_script_hook->hook = NULL; + new_script_hook->function = NULL; + new_script_hook->script = NULL; - /* search and remove timer handlers */ - ptr_handler = plugin->handlers; - while (ptr_handler) + new_hook = weechat_hook_fd (fd, flag_read, flag_write, flag_exception, + callback, new_script_hook); + if (!new_hook) { - if ((ptr_handler->type == PLUGIN_HANDLER_TIMER) - && ((t_plugin_script *)ptr_handler->handler_pointer == script) - && (plugin->strcasecmp (plugin, ptr_handler->handler_args, function) == 0)) - { - next_handler = ptr_handler->next_handler; - plugin->handler_remove (plugin, ptr_handler); - ptr_handler = next_handler; - } - else - ptr_handler = ptr_handler->next_handler; + free (new_script_hook); + return 0; } + + new_script_hook->hook = new_hook; + new_script_hook->function = strdup (function); + new_script_hook->script = script; + + /* add script_hook to list of hooks for current script */ + if (script->hooks) + script->hooks->prev_hook = new_script_hook; + new_script_hook->prev_hook = NULL; + new_script_hook->next_hook = script->hooks; + script->hooks = new_script_hook; + + return 1; } /* - * weechat_script_remove_keyboard_handler: remove a keyboard handler for a script + * weechat_script_hook_print: hook a print + * return 1 if ok, 0 if error */ -void -weechat_script_remove_keyboard_handler (struct t_weechat_plugin *plugin, - t_plugin_script *script, - char *function) +int +weechat_script_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) { - t_plugin_handler *ptr_handler, *next_handler; + struct t_script_hook *new_script_hook; + struct t_hook *new_hook; + + new_script_hook = (struct t_script_hook *)malloc (sizeof (struct t_script_hook)); + if (!new_script_hook) + return 0; + + new_script_hook->hook = NULL; + new_script_hook->function = NULL; + new_script_hook->script = NULL; - /* search and remove keyboard handlers */ - ptr_handler = plugin->handlers; - while (ptr_handler) + new_hook = weechat_hook_print (buffer, message, strip_colors, + callback, new_script_hook); + if (!new_hook) { - if ((ptr_handler->type == PLUGIN_HANDLER_KEYBOARD) - && ((t_plugin_script *)ptr_handler->handler_pointer == script) - && (plugin->strcasecmp (plugin, ptr_handler->handler_args, function) == 0)) - { - next_handler = ptr_handler->next_handler; - plugin->handler_remove (plugin, ptr_handler); - ptr_handler = next_handler; - } - else - ptr_handler = ptr_handler->next_handler; + free (new_script_hook); + return 0; } + + new_script_hook->hook = new_hook; + new_script_hook->function = strdup (function); + new_script_hook->script = script; + + /* add script_hook to list of hooks for current script */ + if (script->hooks) + script->hooks->prev_hook = new_script_hook; + new_script_hook->prev_hook = NULL; + new_script_hook->next_hook = script->hooks; + script->hooks = new_script_hook; + + return 1; } /* - * weechat_script_remove_event_handler: remove an event handler for a script + * weechat_script_hook_signal: hook a signal + * return 1 if ok, 0 if error */ -void -weechat_script_remove_event_handler (struct t_weechat_plugin *plugin, - t_plugin_script *script, - char *function) +int +weechat_script_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) { - t_plugin_handler *ptr_handler, *next_handler; + struct t_script_hook *new_script_hook; + struct t_hook *new_hook; + + new_script_hook = (struct t_script_hook *)malloc (sizeof (struct t_script_hook)); + if (!new_script_hook) + return 0; + + new_script_hook->hook = NULL; + new_script_hook->function = NULL; + new_script_hook->script = NULL; - /* search and remove timer handlers */ - ptr_handler = plugin->handlers; - while (ptr_handler) + new_hook = weechat_hook_signal (signal, callback, new_script_hook); + if (!new_hook) { - if ((ptr_handler->type == PLUGIN_HANDLER_EVENT) - && ((t_plugin_script *)ptr_handler->handler_pointer == script) - && (plugin->strcasecmp (plugin, ptr_handler->handler_args, function) == 0)) - { - next_handler = ptr_handler->next_handler; - plugin->handler_remove (plugin, ptr_handler); - ptr_handler = next_handler; - } - else - ptr_handler = ptr_handler->next_handler; + free (new_script_hook); + return 0; } + + new_script_hook->hook = new_hook; + new_script_hook->function = strdup (function); + new_script_hook->script = script; + + /* add script_hook to list of hooks for current script */ + if (script->hooks) + script->hooks->prev_hook = new_script_hook; + new_script_hook->prev_hook = NULL; + new_script_hook->next_hook = script->hooks; + script->hooks = new_script_hook; + + return 1; } /* - * weechat_script_remove_modifier: remove a modifier - * arg1=type, arg2=command, arg3=function + * weechat_script_hook_config: hook a config option + * return 1 if ok, 0 if error */ -void -weechat_script_remove_modifier (struct t_weechat_plugin *plugin, - t_plugin_script *script, - char *arg1, char *arg2, char *arg3) +int +weechat_script_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) { - t_plugin_modifier *ptr_modifier, *next_modifier; - t_plugin_modifier_type type; - char *ptr_arg2; - - if (strcasecmp (arg1, PLUGIN_MODIFIER_IRC_IN_STR) == 0) - type = PLUGIN_MODIFIER_IRC_IN; - else if (strcasecmp (arg1, PLUGIN_MODIFIER_IRC_USER_STR) == 0) - type = PLUGIN_MODIFIER_IRC_USER; - else if (strcasecmp (arg1, PLUGIN_MODIFIER_IRC_OUT_STR) == 0) - type = PLUGIN_MODIFIER_IRC_OUT; - else - return; + struct t_script_hook *new_script_hook; + struct t_hook *new_hook; + + new_script_hook = (struct t_script_hook *)malloc (sizeof (struct t_script_hook)); + if (!new_script_hook) + return 0; + + new_script_hook->hook = NULL; + new_script_hook->function = NULL; + new_script_hook->script = NULL; - /* search and remove modifiers */ - ptr_modifier = plugin->modifiers; - while (ptr_modifier) + new_hook = weechat_hook_config (type, option, callback, new_script_hook); + if (!new_hook) { - ptr_arg2 = NULL; - if (ptr_modifier->type == type) - ptr_arg2 = ptr_modifier->command; - - if ((ptr_arg2) - && ((t_plugin_script *)ptr_modifier->modifier_pointer == script) - && (plugin->strcasecmp (plugin, ptr_arg2, arg2) == 0) - && (plugin->strcasecmp (plugin, ptr_modifier->modifier_args, arg3) == 0)) - { - next_modifier = ptr_modifier->next_modifier; - plugin->modifier_remove (plugin, ptr_modifier); - ptr_modifier = next_modifier; - } - else - ptr_modifier = ptr_modifier->next_modifier; + free (new_script_hook); + return 0; } + + new_script_hook->hook = new_hook; + new_script_hook->function = strdup (function); + new_script_hook->script = script; + + /* add script_hook to list of hooks for current script */ + if (script->hooks) + script->hooks->prev_hook = new_script_hook; + new_script_hook->prev_hook = NULL; + new_script_hook->next_hook = script->hooks; + script->hooks = new_script_hook; + + return 1; } /* - * weechat_script_get_plugin_config: get a value of a script option + * weechat_script_hook_completion: hook a completion + * return 1 if ok, 0 if error + */ + +int +weechat_script_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) +{ + struct t_script_hook *new_script_hook; + struct t_hook *new_hook; + + new_script_hook = (struct t_script_hook *)malloc (sizeof (struct t_script_hook)); + if (!new_script_hook) + return 0; + + new_script_hook->hook = NULL; + new_script_hook->function = NULL; + new_script_hook->script = NULL; + + new_hook = weechat_hook_completion (completion, callback, new_script_hook); + if (!new_hook) + { + free (new_script_hook); + return 0; + } + + new_script_hook->hook = new_hook; + new_script_hook->function = strdup (function); + new_script_hook->script = script; + + /* add script_hook to list of hooks for current script */ + if (script->hooks) + script->hooks->prev_hook = new_script_hook; + new_script_hook->prev_hook = NULL; + new_script_hook->next_hook = script->hooks; + script->hooks = new_script_hook; + + return 1; +} + +/* + * weechat_script_unhook: unhook something + */ + +void +weechat_script_unhook (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + struct t_hook *hook) +{ + struct t_script_hook *ptr_script_hook; + + for (ptr_script_hook = script->hooks; ptr_script_hook; + ptr_script_hook = ptr_script_hook->next_hook) + { + if (ptr_script_hook->hook == hook) + break; + } + + if (ptr_script_hook) + weechat_script_remove_script_hook (weechat_plugin, + script, + ptr_script_hook); +} + +/* + * weechat_script_command: execute a command (simulate user entry) + */ + +void +weechat_script_command (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + struct t_gui_buffer *buffer, char *command) +{ + char *command2; + + command2 = (script->charset && script->charset[0]) ? + weechat_iconv_to_internal (script->charset, command) : NULL; + weechat_command (buffer, (command2) ? command2 : command); + if (command2) + free (command2); +} + +/* + * weechat_script_config_get_plugin: get a value of a script option * format in file is: plugin.script.option=value */ char * -weechat_script_get_plugin_config (struct t_weechat_plugin *plugin, - t_plugin_script *script, +weechat_script_config_get_plugin (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, char *option) { char *option_fullname, *return_value; @@ -609,20 +801,20 @@ weechat_script_get_plugin_config (struct t_weechat_plugin *plugin, strcat (option_fullname, "."); strcat (option_fullname, option); - return_value = plugin->get_plugin_config (plugin, option_fullname); + return_value = weechat_config_get_plugin (option_fullname); free (option_fullname); return return_value; } /* - * weechat_script_set_plugin_config: set value of a script config option + * weechat_script_config_set_plugin: set value of a script config option * format in file is: plugin.script.option=value */ int -weechat_script_set_plugin_config (struct t_weechat_plugin *plugin, - t_plugin_script *script, +weechat_script_config_set_plugin (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, char *option, char *value) { char *option_fullname; @@ -637,26 +829,8 @@ weechat_script_set_plugin_config (struct t_weechat_plugin *plugin, strcat (option_fullname, "."); strcat (option_fullname, option); - return_code = plugin->set_plugin_config (plugin, option_fullname, value); + return_code = weechat_config_set_plugin (option_fullname, value); free (option_fullname); return return_code; } - -/* - * weechat_script_set_charset: set charset for script - */ - -void -weechat_script_set_charset (struct t_weechat_plugin *plugin, - t_plugin_script *script, - char *charset) -{ - /* make C compiler happy */ - (void) plugin; - - if (script->charset) - free (script->charset); - - script->charset = (charset) ? strdup (charset) : NULL; -} diff --git a/src/plugins/scripts/script.h b/src/plugins/scripts/script.h index 3ca18ae7f..3fad8624e 100644 --- a/src/plugins/scripts/script.h +++ b/src/plugins/scripts/script.h @@ -23,8 +23,29 @@ #define __WEECHAT_SCRIPT_H 1 /* constants which defines return types for weechat_<lang>_exec functions */ -#define SCRIPT_EXEC_INT 1 -#define SCRIPT_EXEC_STRING 2 +#define WEECHAT_SCRIPT_EXEC_INT 1 +#define WEECHAT_SCRIPT_EXEC_STRING 2 + +#define WEECHAT_SCRIPT_MSG_NOT_INITIALIZED(__language, __function) \ + weechat_printf (NULL, \ + weechat_gettext("%s%s: unable to call function " \ + "\"%s\", script is not " \ + "initialized"), \ + weechat_prefix ("error"), __language, __function) +#define WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS(__language, __function) \ + weechat_printf (NULL, \ + weechat_gettext("%s%s: wrong arguments for " \ + "function \"%s\""), \ + weechat_prefix ("error"), __language, __function) + +struct t_script_hook +{ + struct t_hook *hook; /* pointer to hook */ + char *function; /* script function called */ + void *script; /* pointer to script */ + struct t_script_hook *prev_hook; /* link to next script hook */ + struct t_script_hook *next_hook; /* link to previous hook */ +}; struct t_plugin_script { @@ -37,69 +58,112 @@ struct t_plugin_script char *shutdown_func; /* function when script is unloaded*/ char *charset; /* script charset */ + struct t_script_hook *hooks; /* hooks for script */ + struct t_plugin_script *prev_script; /* link to previous script */ struct t_plugin_script *next_script; /* link to next script */ }; -extern void weechat_script_auto_load (struct t_weechat_plugin *plugin, char *language, +extern char *weechat_script_pointer_to_string (void *pointer); +extern void *weechat_script_string_to_pointer (char *pointer_str); +extern void weechat_script_auto_load (struct t_weechat_plugin *weechat_plugin, + char *language, int (*callback)(void *data, char *filename)); -extern struct t_plugin_script *weechat_script_search (struct t_weechat_plugin *plugin, +extern struct t_plugin_script *weechat_script_search (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script **list, char *name); -extern char *weechat_script_search_full_name (struct t_weechat_plugin *plugin, +extern char *weechat_script_search_full_name (struct t_weechat_plugin *weechat_plugin, char *language, char *filename); -extern struct t_plugin_script *weechat_script_add (struct t_weechat_plugin *plugin, +extern struct t_plugin_script *weechat_script_add (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script **script_list, char *filename, char *name, char *version, char *shutdown_func, char *description, char *charset); -extern void weechat_script_remove (struct t_weechat_plugin *plugin, +extern void weechat_script_remove (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script **script_list, struct t_plugin_script *script); -extern void weechat_script_print (struct t_weechat_plugin *plugin, - struct t_plugin_script *script, - char *server, char *channel, - char *message, ...); -extern void weechat_script_print_server (struct t_weechat_plugin *plugin, - struct t_plugin_script *script, - char *message, ...); -extern void weechat_script_print_infobar (struct t_weechat_plugin *plugin, - struct t_plugin_script *script, - int delay, char *message, ...); -extern void weechat_script_log (struct t_weechat_plugin *plugin, - struct t_plugin_script *script, - char *server, char *channel, - char *message, ...); -extern void weechat_script_exec_command (struct t_weechat_plugin *plugin, - struct t_plugin_script *script, - char *server, char *channel, - char *command); -extern void weechat_script_remove_handler (struct t_weechat_plugin *plugin, +extern void weechat_script_charset_set (struct t_plugin_script *script, + char *charset); +extern void weechat_script_printf (struct t_weechat_plugin *plugin, + struct t_plugin_script *script, + struct t_gui_buffer *buffer, + char *format, ...); +extern void weechat_script_infobar_printf (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + int delay, char *color_name, + char *format, ...); +extern void weechat_script_log_printf (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + char *format, ...); +extern int weechat_script_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 weechat_script_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 weechat_script_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 weechat_script_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 weechat_script_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 weechat_script_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 weechat_script_hook_completion (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, - char *arg1, char *arg2); -extern void weechat_script_remove_timer_handler (struct t_weechat_plugin *plugin, - struct t_plugin_script *script, - char *function); -extern void weechat_script_remove_keyboard_handler (struct t_weechat_plugin *plugin, - struct t_plugin_script *script, - char *function); -extern void weechat_script_remove_event_handler (struct t_weechat_plugin *plugin, - struct t_plugin_script *script, - char *function); -extern void weechat_script_remove_modifier (struct t_weechat_plugin *plugin, - struct t_plugin_script *script, - char *arg1, char *arg2, - char *arg3); -extern char *weechat_script_get_plugin_config (struct t_weechat_plugin *plugin, + char *completion, + int (*callback)(void *data, + char *completion, + struct t_gui_buffer *buffer, + struct t_weelist *list), + char *function); +extern void weechat_script_unhook (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + struct t_hook *hook); +extern void weechat_script_command (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + struct t_gui_buffer *buffer, + char *command); +extern char *weechat_script_config_get_plugin (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, char *option); -extern int weechat_script_set_plugin_config (struct t_weechat_plugin *plugin, +extern int weechat_script_config_set_plugin (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, char *option, char *value); -extern void weechat_script_set_charset (struct t_weechat_plugin *plugin, - struct t_plugin_script *script, - char *charset); #endif /* script.h */ diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 5fe6c9c52..d9c778ebb 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -44,13 +44,13 @@ struct t_weelist; /* return codes specific to message handlers: messages can be discarded for WeeChat, for plugins, or both */ -#define WEECHAT_RC_IGNORE_WEECHAT 1 /* ignore WeeChat for this message */ -#define WEECHAT_RC_IGNORE_PLUGINS 2 /* ignore other plugins for msg */ -#define WEECHAT_RC_IGNORE_ALL (PLUGIN_RC_OK_IGNORE_WEECHAT \ - | PLUGIN_RC_OK_IGNORE_PLUGINS) - /* ignore WeeChat and other plugins */ -#define WEECHAT_RC_WITH_HIGHLIGHT 4 /* ok and ask for highlight */ - /* (for message handler only) */ +#define WEECHAT_RC_OK_IGNORE_WEECHAT 1 /* ignore WeeChat for this message */ +#define WEECHAT_RC_OK_IGNORE_PLUGINS 2 /* ignore other plugins for msg */ +#define WEECHAT_RC_OK_IGNORE_ALL (WEECHAT_RC_OK_IGNORE_WEECHAT \ + | WEECHAT_RC_OK_IGNORE_PLUGINS) + /* ignore WeeChat and other plugins */ +#define WEECHAT_RC_OK_WITH_HIGHLIGHT 4 /* ok and ask for highlight */ + /* (for message handler only) */ /* list management (order of elements) */ #define WEECHAT_LIST_POS_SORT "sort" @@ -63,6 +63,11 @@ struct t_weelist; #define WEECHAT_HOTLIST_PRIVATE "2" #define WEECHAT_HOTLIST_HIGHLIGHT "3" +/* type of data for signal hooked */ +#define WEECHAT_HOOK_SIGNAL_STRING "string" +#define WEECHAT_HOOK_SIGNAL_INT "int" +#define WEECHAT_HOOK_SIGNAL_POINTER "pointer" + struct t_weechat_plugin { /* plugin variables */ @@ -197,10 +202,10 @@ struct t_weechat_plugin char *(*color) (char *color_name); void (*printf_date) (struct t_gui_buffer *buffer, time_t date, char *message, ...); - void (*log_printf) (char *message, ...); void (*infobar_printf) (struct t_weechat_plugin *plugin, int delay, char *color_name, char *format, ...); void (*infobar_remove) (int how_many); + void (*log_printf) (char *message, ...); /* hooks */ struct t_hook *(*hook_command) (struct t_weechat_plugin *plugin, @@ -233,9 +238,11 @@ struct t_weechat_plugin struct t_hook *(*hook_signal) (struct t_weechat_plugin *plugin, char *signal, int (*callback)(void *data, char *signal, + char *type_data, void *signal_data), void *callback_data); - void (*hook_signal_send) (char *signal, void *signal_data); + void (*hook_signal_send) (char *signal, char *type_data, + void *signal_data); struct t_hook *(*hook_config) (struct t_weechat_plugin *plugin, char *type, char *option, int (*callback)(void *data, char *type, @@ -315,11 +322,16 @@ struct t_weechat_plugin #define weechat_iconv_from_internal(__charset, __string) \ weechat_plugin->iconv_from_internal(__charset, __string) #ifndef __WEECHAT_H +#ifndef _ #define _(string) weechat_plugin->gettext(string) #define N_(string) (string) #define NG_(single,plural,number) \ weechat_plugin->ngettext(single, plural, number) #endif +#endif +#define weechat_gettext(string) weechat_plugin->gettext(string) +#define weechat_ngettext(single,plural,number) \ + weechat_plugin->ngettext(single, plural, number) #define weechat_strcasecmp(__string1, __string2) \ weechat_plugin->strcasecmp(__string1, __string2) #define weechat_strncasecmp(__string1, __string2, __max) \ @@ -472,14 +484,14 @@ struct t_weechat_plugin weechat_plugin->printf_date(__buffer, 0, __message, ##__argz) #define weechat_printf_date(__buffer, __date, __message, __argz...) \ weechat_plugin->printf_date(__buffer, __date, __message, ##__argz) -#define weechat_log_printf(__message, __argz...) \ - weechat_plugin->log_printf(__message, ##__argz) #define weechat_infobar_printf(__delay, __color_name, __message, \ __argz...) \ weechat_plugin->infobar_printf(weechat_plugin, __delay, \ __color_name, __message, ##__argz) #define weechat_infobar_remove(__how_many) \ weechat_plugin->infobar_remove(__how_many) +#define weechat_log_printf(__message, __argz...) \ + weechat_plugin->log_printf(__message, ##__argz) /* hooks */ #define weechat_hook_command(__command, __description, __args, \ @@ -505,8 +517,9 @@ struct t_weechat_plugin #define weechat_hook_signal(__signal, __callback, __data) \ weechat_plugin->hook_signal(weechat_plugin, __signal, __callback, \ __data) -#define weechat_hook_signal_send(__signal, __pointer) \ - weechat_plugin->hook_signal_send(__signal, __pointer) +#define weechat_hook_signal_send(__signal, __type_data, __signal_data) \ + weechat_plugin->hook_signal_send(__signal, __type_data, \ + __signal_data) #define weechat_hook_config(__type, __option, __callback, __data) \ weechat_plugin->hook_config(weechat_plugin, __type, __option, \ __callback, __data) |