1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-02 07:46:38 +02:00

Added Perl message handlers

This commit is contained in:
Sebastien Helleu
2003-11-17 21:07:17 +00:00
parent fe4ca01615
commit edcc01bcf0
18 changed files with 124 additions and 20 deletions
+3 -1
View File
@@ -1,7 +1,7 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
WeeChat known bugs, 2003-11-16
WeeChat known bugs, 2003-11-17
- ./configure does not check that Curses headers are installed
- ./configure does not check that Gtk 2.0 libraries are installed
@@ -16,3 +16,5 @@ WeeChat known bugs, 2003-11-16
- when quitting WeeChat term title is not restored (if look_set_title is ON)
- command name for /server can not contain spaces
- wrong alias is not created and not saved when quitting WeeChat
- when many WeeChat are launched, log file is not properly written (cleared by
each WeeChat at startup)
+5
View File
@@ -51,6 +51,7 @@ AC_FUNC_SELECT_ARGTYPES
AC_TYPE_SIGNAL
AC_CHECK_FUNCS([gethostbyname gethostname gettimeofday inet_ntoa memset mkdir select setlocale socket strcasecmp strchr strdup strncasecmp strpbrk strrchr strstr uname])
AH_VERBATIM([PLUGINS], [#undef PLUGINS])
AH_VERBATIM([PLUGIN_PERL], [#undef PLUGIN_PERL])
AH_VERBATIM([DEBUG], [#undef DEBUG])
@@ -101,6 +102,10 @@ if test "x$enable_perl" = "xyes" ; then
AC_DEFINE(PLUGIN_PERL)
fi
if test "x$enable_plugins" = "xyes" ; then
AC_DEFINE(PLUGINS)
fi
AC_SUBST(PLUGINS_LIBS)
if test "x$enable_debug" = "xyes" ; then
+11 -4
View File
@@ -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;
}
+5 -2
View File
@@ -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);
+1 -1
View File
@@ -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 *);
+4 -2
View File
@@ -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 =
{
+1
View File
@@ -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 ();
+31
View File
@@ -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
}
/*
@@ -173,6 +177,33 @@ plugins_msg_handlers_free_all ()
plugins_msg_handler_free (plugins_msg_handlers);
}
/*
* 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
*/
+1
View File
@@ -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 */
+3 -1
View File
@@ -1,7 +1,7 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
WeeChat known bugs, 2003-11-16
WeeChat known bugs, 2003-11-17
- ./configure does not check that Curses headers are installed
- ./configure does not check that Gtk 2.0 libraries are installed
@@ -16,3 +16,5 @@ WeeChat known bugs, 2003-11-16
- when quitting WeeChat term title is not restored (if look_set_title is ON)
- command name for /server can not contain spaces
- wrong alias is not created and not saved when quitting WeeChat
- when many WeeChat are launched, log file is not properly written (cleared by
each WeeChat at startup)
+5
View File
@@ -51,6 +51,7 @@ AC_FUNC_SELECT_ARGTYPES
AC_TYPE_SIGNAL
AC_CHECK_FUNCS([gethostbyname gethostname gettimeofday inet_ntoa memset mkdir select setlocale socket strcasecmp strchr strdup strncasecmp strpbrk strrchr strstr uname])
AH_VERBATIM([PLUGINS], [#undef PLUGINS])
AH_VERBATIM([PLUGIN_PERL], [#undef PLUGIN_PERL])
AH_VERBATIM([DEBUG], [#undef DEBUG])
@@ -101,6 +102,10 @@ if test "x$enable_perl" = "xyes" ; then
AC_DEFINE(PLUGIN_PERL)
fi
if test "x$enable_plugins" = "xyes" ; then
AC_DEFINE(PLUGINS)
fi
AC_SUBST(PLUGINS_LIBS)
if test "x$enable_debug" = "xyes" ; then
+11 -4
View File
@@ -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;
}
+5 -2
View File
@@ -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);
+1 -1
View File
@@ -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 *);
+4 -2
View File
@@ -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 =
{
+1
View File
@@ -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 ();
+31
View File
@@ -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
}
/*
@@ -173,6 +177,33 @@ plugins_msg_handlers_free_all ()
plugins_msg_handler_free (plugins_msg_handlers);
}
/*
* 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
*/
+1
View File
@@ -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 */