diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2003-11-17 21:07:17 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2003-11-17 21:07:17 +0000 |
commit | edcc01bcf0a0c17992314cfa7af355f1952113e5 (patch) | |
tree | 9b9ff69235b575a58bb5e1ed907bba0d93e37d0d /src | |
parent | fe4ca016156b01a1c66410dcecce5a970aa55bd3 (diff) | |
download | weechat-edcc01bcf0a0c17992314cfa7af355f1952113e5.zip |
Added Perl message handlers
Diffstat (limited to 'src')
-rw-r--r-- | src/irc/irc-recv.c | 15 | ||||
-rw-r--r-- | src/irc/irc-server.c | 7 | ||||
-rw-r--r-- | src/irc/irc.h | 2 | ||||
-rw-r--r-- | src/plugins/perl/wee-perl.c | 6 | ||||
-rw-r--r-- | src/plugins/perl/wee-perl.h | 1 | ||||
-rw-r--r-- | src/plugins/plugins.c | 31 | ||||
-rw-r--r-- | src/plugins/plugins.h | 1 |
7 files changed, 54 insertions, 9 deletions
diff --git a/src/irc/irc-recv.c b/src/irc/irc-recv.c index 8e816a26f..a338d4a8f 100644 --- a/src/irc/irc-recv.c +++ b/src/irc/irc-recv.c @@ -40,6 +40,7 @@ #include "../common/command.h" #include "../common/weeconfig.h" #include "../gui/gui.h" +#include "../plugins/plugins.h" /* @@ -51,29 +52,35 @@ */ int -irc_recv_command (t_irc_server *server, +irc_recv_command (t_irc_server *server, char *entire_line, char *host, char *command, char *arguments) { - int i, cmd_found; + int i, cmd_found, return_code; if (command == NULL) return -2; - /* looks for irc command */ + /* look for IRC command */ cmd_found = -1; for (i = 0; irc_commands[i].command_name; i++) + { if (strcasecmp (irc_commands[i].command_name, command) == 0) { cmd_found = i; break; } + } /* command not found */ if (cmd_found < 0) return -3; if (irc_commands[i].recv_function != NULL) - return (int) (irc_commands[i].recv_function) (server, host, arguments); + { + return_code = (int) (irc_commands[i].recv_function) (server, host, arguments); + plugins_event_msg (irc_commands[i].command_name, entire_line); + return return_code; + } return 0; } diff --git a/src/irc/irc-server.c b/src/irc/irc-server.c index 25928eeb5..070b1312f 100644 --- a/src/irc/irc-server.c +++ b/src/irc/irc-server.c @@ -366,7 +366,7 @@ server_msgq_flush () t_irc_message *next; /*char **argv; int argc;*/ - char *ptr_data, *pos, *pos2; + char *entire_line, *ptr_data, *pos, *pos2; char *host, *command, *args; /* TODO: optimize this function, parse only a few messages (for low CPU time!) */ @@ -377,6 +377,7 @@ server_msgq_flush () #endif ptr_data = recv_msgq->data; + entire_line = strdup (ptr_data); while (ptr_data[0] == ' ') ptr_data++; @@ -417,7 +418,8 @@ server_msgq_flush () } } - switch (irc_recv_command (recv_msgq->server, host, command, args)) + switch (irc_recv_command (recv_msgq->server, entire_line, host, + command, args)) { case -1: gui_printf (recv_msgq->server->window, @@ -435,6 +437,7 @@ server_msgq_flush () } } + free (entire_line); free (recv_msgq->data); next = recv_msgq->next_message; free (recv_msgq); diff --git a/src/irc/irc.h b/src/irc/irc.h index f7cfd4074..5e27b7a47 100644 --- a/src/irc/irc.h +++ b/src/irc/irc.h @@ -185,7 +185,7 @@ extern void irc_display_mode (t_gui_window *, char *, char, char *, char *, /* IRC protocol (irc-commands.c) */ -extern int irc_recv_command (t_irc_server *, char *, char *, char *); +extern int irc_recv_command (t_irc_server *, char *, char *, char *, char *); extern void irc_login (t_irc_server *); /* IRC commands issued by user */ extern int irc_cmd_send_admin (t_irc_server *, char *); diff --git a/src/plugins/perl/wee-perl.c b/src/plugins/perl/wee-perl.c index f0d105843..2433e8fab 100644 --- a/src/plugins/perl/wee-perl.c +++ b/src/plugins/perl/wee-perl.c @@ -101,7 +101,9 @@ static XS (XS_IRC_print) for (i = 0; i < items; i++) { message = SvPV (ST (i), integer); - gui_printf (NULL, "%s\n", message); + gui_printf (gui_current_window, "%s%s", + message, + (message[strlen (message) - 1] == '\n') ? "" : "\n"); } XSRETURN_EMPTY; @@ -144,7 +146,7 @@ void wee_perl_init () { char *perl_args[] = { "", "-e", "0" }; - /* This Perl code is extracted/modified from X-Chat IRC client */ + /* Following Perl code is extracted/modified from X-Chat IRC client */ /* X-Chat is (c) 1998-2002 Peter Zelezny */ char *weechat_perl_func = { diff --git a/src/plugins/perl/wee-perl.h b/src/plugins/perl/wee-perl.h index 5898285ca..c018bf44a 100644 --- a/src/plugins/perl/wee-perl.h +++ b/src/plugins/perl/wee-perl.h @@ -37,6 +37,7 @@ struct t_perl_script extern void wee_perl_init (); extern t_perl_script *wee_perl_search (char *); +extern int wee_perl_exec (char *, char *); extern int wee_perl_load (char *); extern void wee_perl_unload (t_perl_script *); extern void wee_perl_unload_all (); diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index f7cde6d6d..8ef0627e4 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -62,6 +62,7 @@ plugins_init () void plugins_load (int plugin_type, char *filename) { + #ifdef PLUGINS switch (plugin_type) { case PLUGIN_PERL: @@ -76,6 +77,7 @@ plugins_load (int plugin_type, char *filename) /* TODO: load Ruby script */ break; } + #endif } /* @@ -85,6 +87,7 @@ plugins_load (int plugin_type, char *filename) void plugins_unload (int plugin_type, char *scriptname) { + #ifdef PLUGINS switch (plugin_type) { case PLUGIN_PERL: @@ -99,6 +102,7 @@ plugins_unload (int plugin_type, char *scriptname) /* TODO: load Ruby script */ break; } + #endif } /* @@ -174,6 +178,33 @@ plugins_msg_handlers_free_all () } /* + * plugins_event_msg: IRC message received => call all handlers for this message + */ + +void +plugins_event_msg (char *command, char *arguments) +{ + #ifdef PLUGINS + t_plugin_handler *ptr_plugin_handler; + + for (ptr_plugin_handler = plugins_msg_handlers; ptr_plugin_handler; + ptr_plugin_handler = ptr_plugin_handler->next_handler) + { + if (strcasecmp (ptr_plugin_handler->name, command) == 0) + { + #ifdef PLUGIN_PERL + if (ptr_plugin_handler->plugin_type == PLUGIN_PERL) + wee_perl_exec (ptr_plugin_handler->function_name, arguments); + #endif + } + } + #else + /* make gcc happy */ + (void) command; + #endif +} + +/* * plugins_end: shutdown plugin interface */ diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h index 68ea44c27..aa1553f1e 100644 --- a/src/plugins/plugins.h +++ b/src/plugins/plugins.h @@ -44,6 +44,7 @@ extern void plugins_init (); extern void plugins_load (int, char *); extern void plugins_unload (int, char *); extern void plugins_msg_handler_add (int, char *, char *); +extern void plugins_event_msg (char *, char *); extern void plugins_end (); #endif /* plugins.h */ |