mirror of
https://github.com/weechat/weechat.git
synced 2026-07-05 01:03:14 +02:00
Added Perl handlers
This commit is contained in:
@@ -27,13 +27,22 @@
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "../common/weechat.h"
|
||||
#include "plugins.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
#ifdef PLUGIN_PERL
|
||||
#include "perl/wee-perl.h"
|
||||
#endif
|
||||
|
||||
|
||||
t_plugin_handler *plugins_msg_handlers = NULL;
|
||||
t_plugin_handler *last_plugin_msg_handler = NULL;
|
||||
t_plugin_handler *plugins_cmd_handlers = NULL;
|
||||
t_plugin_handler *last_plugin_cmd_handler = NULL;
|
||||
|
||||
|
||||
/*
|
||||
* plugins_init: initialize all plugins
|
||||
*/
|
||||
@@ -92,6 +101,78 @@ plugins_unload (int plugin_type, char *scriptname)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* plugins_msg_handler_add: add a message handler
|
||||
*/
|
||||
|
||||
void
|
||||
plugins_msg_handler_add (int plugin_type, char *message, char *function)
|
||||
{
|
||||
t_plugin_handler *new_plugin_handler;
|
||||
|
||||
new_plugin_handler = (t_plugin_handler *)malloc (sizeof (t_plugin_handler));
|
||||
if (new_plugin_handler)
|
||||
{
|
||||
new_plugin_handler->plugin_type = plugin_type;
|
||||
new_plugin_handler->name = strdup (message);
|
||||
new_plugin_handler->function_name = strdup (function);
|
||||
|
||||
/* add new handler to list */
|
||||
new_plugin_handler->prev_handler = last_plugin_msg_handler;
|
||||
new_plugin_handler->next_handler = NULL;
|
||||
if (plugins_msg_handlers)
|
||||
last_plugin_msg_handler->next_handler = new_plugin_handler;
|
||||
else
|
||||
plugins_msg_handlers = new_plugin_handler;
|
||||
last_plugin_msg_handler = new_plugin_handler;
|
||||
}
|
||||
else
|
||||
gui_printf (NULL,
|
||||
_("%s unable to add handler for \"%s\" message (not enough memory)\n"),
|
||||
WEECHAT_ERROR, message);
|
||||
}
|
||||
|
||||
/*
|
||||
* plugins_msg_handler_free: free message handler
|
||||
*/
|
||||
|
||||
void
|
||||
plugins_msg_handler_free (t_plugin_handler *ptr_plugin_handler)
|
||||
{
|
||||
t_plugin_handler *new_plugins_msg_handlers;
|
||||
|
||||
/* remove handler from list */
|
||||
if (last_plugin_msg_handler == ptr_plugin_handler)
|
||||
last_plugin_msg_handler = ptr_plugin_handler->prev_handler;
|
||||
if (ptr_plugin_handler->prev_handler)
|
||||
{
|
||||
(ptr_plugin_handler->prev_handler)->next_handler = ptr_plugin_handler->next_handler;
|
||||
new_plugins_msg_handlers = plugins_msg_handlers;
|
||||
}
|
||||
else
|
||||
new_plugins_msg_handlers = ptr_plugin_handler->next_handler;
|
||||
|
||||
if (ptr_plugin_handler->next_handler)
|
||||
(ptr_plugin_handler->next_handler)->prev_handler = ptr_plugin_handler->prev_handler;
|
||||
|
||||
/* free data */
|
||||
free (ptr_plugin_handler->name);
|
||||
free (ptr_plugin_handler->function_name);
|
||||
free (ptr_plugin_handler);
|
||||
plugins_msg_handlers = new_plugins_msg_handlers;
|
||||
}
|
||||
|
||||
/*
|
||||
* plugins_remove_all_msg_handlers: remove all message handlers
|
||||
*/
|
||||
|
||||
void
|
||||
plugins_msg_handlers_free_all ()
|
||||
{
|
||||
while (plugins_msg_handlers)
|
||||
plugins_msg_handler_free (plugins_msg_handlers);
|
||||
}
|
||||
|
||||
/*
|
||||
* plugins_end: shutdown plugin interface
|
||||
*/
|
||||
@@ -99,6 +180,8 @@ plugins_unload (int plugin_type, char *scriptname)
|
||||
void
|
||||
plugins_end ()
|
||||
{
|
||||
plugins_msg_handlers_free_all ();
|
||||
|
||||
#ifdef PLUGIN_PERL
|
||||
wee_perl_end();
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user