1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-30 14:56:39 +02:00

Add of "modifier" hook, migration of charset plugin to new API, SIGHUP signal catched (reload all config files), better config files reloading

This commit is contained in:
Sebastien Helleu
2008-01-24 16:50:20 +01:00
parent 25c5bc6421
commit ed26a0389c
48 changed files with 2335 additions and 1113 deletions
+27 -39
View File
@@ -309,7 +309,8 @@ alias_new (char *name, char *command)
return ptr_alias;
}
if ((new_alias = ((struct t_alias *)malloc (sizeof (struct t_alias)))))
new_alias = (struct t_alias *)malloc (sizeof (struct t_alias));
if (new_alias)
{
new_hook = weechat_hook_command (name, "[alias]", NULL, NULL, NULL,
alias_cb, new_alias);
@@ -331,11 +332,9 @@ alias_new (char *name, char *command)
else
alias_list = new_alias;
last_alias = new_alias;
return new_alias;
}
return NULL;
return new_alias;
}
/*
@@ -372,7 +371,7 @@ alias_get_final_command (struct t_alias *alias)
}
/*
* alias_free: free an alias and reomve it from list
* alias_free: free an alias and remove it from list
*/
void
@@ -390,7 +389,6 @@ alias_free (struct t_alias *alias)
}
else
new_alias_list = alias->next_alias;
if (alias->next_alias)
(alias->next_alias)->prev_alias = alias->prev_alias;
@@ -402,6 +400,7 @@ alias_free (struct t_alias *alias)
if (alias->command)
free (alias->command);
free (alias);
alias_list = new_alias_list;
}
@@ -416,6 +415,20 @@ alias_free_all ()
alias_free (alias_list);
}
/*
* alias_config_reaload: reload alias configuration file
*/
int
alias_config_reload (struct t_config_file *config_file)
{
/* make C compiler happy */
(void) config_file;
alias_free_all ();
return weechat_config_reload (alias_config_file);
}
/*
* alias_config_read_line: read an alias in configuration file
*/
@@ -510,7 +523,8 @@ alias_config_init ()
{
struct t_config_section *ptr_section;
alias_config_file = weechat_config_new (ALIAS_CONFIG_FILENAME);
alias_config_file = weechat_config_new (ALIAS_CONFIG_FILENAME,
&alias_config_reload);
if (!alias_config_file)
return 0;
@@ -537,34 +551,6 @@ alias_config_read ()
return weechat_config_read (alias_config_file);
}
/*
* alias_config_reaload_signal_cb: reload alias configuration file
*/
int
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 ();
if (weechat_config_reload (alias_config_file) == 0)
{
weechat_printf (NULL,
_("%s%s: configuration file reloaded"),
weechat_prefix ("info"), "alias");
return WEECHAT_RC_OK;
}
weechat_printf (NULL,
_("%s%s: failed to reload configuration file"),
weechat_prefix ("error"), "alias");
return WEECHAT_RC_ERROR;
}
/*
* alias_config_write: write alias configuration file
*/
@@ -651,7 +637,8 @@ alias_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
else
weechat_printf (NULL, _("No alias defined"));
}
return 0;
return WEECHAT_RC_OK;
}
/*
@@ -755,8 +742,6 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
"%(alias)",
&unalias_command_cb, NULL);
weechat_hook_signal ("config_reload", &alias_config_reload_signal_cb, NULL);
weechat_hook_completion ("alias", &alias_completion_cb, NULL);
return WEECHAT_RC_OK;
@@ -767,8 +752,11 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
*/
int
weechat_plugin_end ()
weechat_plugin_end (struct t_weechat_plugin *plugin)
{
/* make C compiler happy */
(void) plugin;
alias_config_write ();
alias_free_all ();
weechat_config_free (alias_config_file);
+1 -1
View File
@@ -20,6 +20,6 @@ libdir = ${weechat_libdir}/plugins
lib_LTLIBRARIES = charset.la
charset_la_SOURCES = charset.c
charset_la_SOURCES = charset.c charset.h
charset_la_LDFLAGS = -module
charset_la_LIBADD = $(CHARSET_LFLAGS)
File diff suppressed because it is too large Load Diff
+33
View File
@@ -0,0 +1,33 @@
/*
* 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_CHARSET_H
#define __WEECHAT_CHARSET_H 1
#define CHARSET_CONFIG_FILENAME "charset.rc"
struct t_charset
{
char *name; /* charset name (identifier) */
char *charset; /* charset value for name */
struct t_charset *prev_charset; /* link to previous charset */
struct t_charset *next_charset; /* link to next charset */
};
#endif /* charset.h */
+4 -1
View File
@@ -387,7 +387,10 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
*/
int
weechat_plugin_end ()
weechat_plugin_end (struct t_weechat_plugin *plugin)
{
/* make C compiler happy */
(void) plugin;
return WEECHAT_RC_OK;
}
+4 -1
View File
@@ -368,8 +368,11 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
*/
int
weechat_plugin_end ()
weechat_plugin_end (struct t_weechat_plugin *plugin)
{
/* make C compiler happy */
(void) plugin;
fifo_remove ();
return WEECHAT_RC_OK;
+60 -69
View File
@@ -207,6 +207,64 @@ irc_config_change_notify_levels ()
{
}
/*
* irc_config_reload: reload IRC configuration file
*/
int
irc_config_reload (struct t_config_file *config_file)
{
struct t_irc_server *ptr_server, *next_server;
int rc;
/* make C compiler happy */
(void) config_file;
irc_config_server = NULL;
irc_config_reload_flag = 1;
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
ptr_server->reloaded_from_config = 0;
}
rc = weechat_config_reload (irc_config_file);
if (rc == 0)
{
if (irc_config_server)
irc_server_init_with_config_options (irc_config_server,
irc_config_section_server,
irc_config_reload_flag);
ptr_server = irc_servers;
while (ptr_server)
{
next_server = ptr_server->next_server;
if (!ptr_server->reloaded_from_config)
{
if (ptr_server->is_connected)
{
weechat_printf (NULL,
_("%s%s: warning: server \"%s\" not found "
"in configuration file, not deleted in "
"memory because it's currently used"),
weechat_prefix ("error"), "irc",
ptr_server->name);
}
else
irc_server_free (ptr_server);
}
ptr_server = next_server;
}
}
return rc;
}
/*
* irc_config_read_server_line: read a server line in configuration file
*/
@@ -410,7 +468,8 @@ irc_config_init ()
{
struct t_config_section *ptr_section;
irc_config_file = weechat_config_new (IRC_CONFIG_FILENAME);
irc_config_file = weechat_config_new (IRC_CONFIG_FILENAME,
&irc_config_reload);
if (!irc_config_file)
return 0;
@@ -726,74 +785,6 @@ irc_config_read ()
return rc;
}
/*
* irc_config_reload_cb: read IRC configuration file
*/
int
irc_config_reload_cb (void *data, char *event, void *pointer)
{
struct t_irc_server *ptr_server, *next_server;
int rc;
/* make C compiler happy */
(void) data;
(void) event;
(void) pointer;
irc_config_server = NULL;
irc_config_reload_flag = 1;
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
ptr_server->reloaded_from_config = 0;
}
rc = weechat_config_reload (irc_config_file);
if (rc == 0)
{
if (irc_config_server)
irc_server_init_with_config_options (irc_config_server,
irc_config_section_server,
irc_config_reload_flag);
ptr_server = irc_servers;
while (ptr_server)
{
next_server = ptr_server->next_server;
if (!ptr_server->reloaded_from_config)
{
if (ptr_server->is_connected)
{
weechat_printf (NULL,
_("%s%s: warning: server \"%s\" not found "
"in configuration file. It has not been "
"deleted because it's used now."),
weechat_prefix ("info"), "irc",
ptr_server->name);
}
else
irc_server_free (ptr_server);
}
ptr_server = next_server;
}
weechat_printf (NULL,
_("%s%s: configuration file reloaded"),
weechat_prefix ("info"), "irc");
return WEECHAT_RC_OK;
}
weechat_printf (NULL,
_("%s%s: failed to reload configuration file"),
weechat_prefix ("error"), "irc");
return WEECHAT_RC_ERROR;
}
/*
* irc_config_write: write IRC configuration file
* return: 0 if ok
-1
View File
@@ -69,7 +69,6 @@ struct t_config_option *irc_config_log_hide_nickserv_pwd;
int irc_config_init ();
int irc_config_read ();
int irc_config_reload_cb ();
int irc_config_write ();
#endif /* irc-config.h */
+1 -1
View File
@@ -499,7 +499,7 @@ irc_protocol_recv_command (struct t_irc_server *server, char *entire_line,
if (!command)
return -2;
/* look for IRC command */
cmd_found = -1;
for (i = 0; irc_protocol_messages[i].name; i++)
+2 -2
View File
@@ -37,8 +37,8 @@ struct t_irc_protocol_msg
t_irc_recv_func2 *recv_function2; /* function called when msg is received */
};
extern int irc_protocol_is_highlight (char *, char *);
extern int irc_protocol_recv_command (struct t_irc_server *, char *, char *, char *, char *);
extern int irc_protocol_is_highlight (char *message, char *nick);
extern int irc_protocol_recv_command (struct t_irc_server *server, char *entire_line, char *host, char *command, char *arguments);
extern int irc_protocol_cmd_error (struct t_irc_server *server, int argc, char **argv, char **argv_eol, int ignore, int highlight);
extern int irc_protocol_cmd_invite (struct t_irc_server *server, int argc, char **argv, char **argv_eol, int ignore, int highlight);
extern int irc_protocol_cmd_join (struct t_irc_server *server, int argc, char **argv, char **argv_eol, int ignore, int highlight);
+95 -17
View File
@@ -986,24 +986,33 @@ irc_server_sendf (struct t_irc_server *server, char *format, ...)
/*
* irc_server_parse_message: parse IRC message and return pointer to
* host, command and arguments (if any)
* host, command, channel, target nick and arguments
* (if any)
*/
void
irc_server_parse_message (char *message, char **host, char **command, char **args)
irc_server_parse_message (char *message, char **nick, char **host,
char **command, char **channel, char **arguments)
{
char *pos, *pos2;
char *pos, *pos2, *pos3, *pos4;
*nick = NULL;
*host = NULL;
*command = NULL;
*args = NULL;
*channel = NULL;
*arguments = NULL;
if (message[0] == ':')
{
pos2 = strchr (message, '!');
pos = strchr (message, ' ');
if (pos2)
*nick = weechat_strndup (message + 1, pos2 - (message + 1));
else if (pos)
*nick = weechat_strndup (message + 1, pos - (message + 1));
if (pos)
{
*host = strndup (message + 1, pos - (message + 1));
*host = weechat_strndup (message + 1, pos - (message + 1));
pos++;
}
else
@@ -1019,11 +1028,47 @@ irc_server_parse_message (char *message, char **host, char **command, char **arg
pos2 = strchr (pos, ' ');
if (pos2)
{
*command = strndup (pos, pos2 - pos);
*command = weechat_strndup (pos, pos2 - pos);
pos2++;
while (pos2[0] == ' ')
pos2++;
*args = strdup (pos2);
*arguments = strdup (pos2);
if (pos2[0] != ':')
{
if (irc_channel_is_channel (pos2))
{
pos3 = strchr (pos2, ' ');
if (pos3)
*channel = weechat_strndup (pos2, pos3 - pos2);
else
*channel = strdup (pos2);
}
else
{
pos3 = strchr (pos2, ' ');
if (!*nick)
{
if (pos3)
*nick = weechat_strndup (pos2, pos3 - pos2);
else
*nick = strdup (pos2);
}
if (pos3)
{
pos3++;
while (pos3[0] == ' ')
pos3++;
if (irc_channel_is_channel (pos3))
{
pos4 = strchr (pos3, ' ');
if (pos4)
*channel = weechat_strndup (pos3, pos4 - pos3);
else
*channel = strdup (pos3);
}
}
}
}
}
}
}
@@ -1171,7 +1216,9 @@ irc_server_msgq_flush ()
{
struct t_irc_message *next;
char *ptr_data, *new_msg, *ptr_msg, *pos;
char *host, *command, *args;
char *nick, *host, *command, *channel, *arguments, *msg_decoded;
char *modifier_data, *ptr_chan_nick;
int length;
while (irc_recv_msgq)
{
@@ -1220,17 +1267,48 @@ irc_server_msgq_flush ()
pos = strchr (ptr_msg, '\n');
if (pos)
pos[0] = '\0';
//if (new_msg)
// gui_chat_printf_raw_data (irc_recv_msgq->server,
// 0, 1, ptr_msg);
irc_server_parse_message (ptr_msg, &host,
&command, &args);
irc_server_parse_message (ptr_msg, &nick, &host,
&command, &channel,
&arguments);
/* convert charset for message */
msg_decoded = NULL;
ptr_chan_nick = (channel) ? channel : nick;
length = strlen (weechat_plugin->name) + 1 +
strlen (irc_recv_msgq->server->name) + 1 +
((ptr_chan_nick) ? strlen (ptr_chan_nick) : 0) + 1;
modifier_data = (char *)malloc (length);
if (modifier_data)
{
if (ptr_chan_nick)
{
snprintf (modifier_data, length, "%s.%s.%s",
weechat_plugin->name,
irc_recv_msgq->server->name,
ptr_chan_nick);
}
else
{
snprintf (modifier_data, length, "%s.%s.%s",
weechat_plugin->name,
irc_recv_msgq->server->name,
ptr_chan_nick);
}
msg_decoded = weechat_hook_modifier_exec ("charset_decode",
modifier_data,
ptr_msg);
free (modifier_data);
}
switch (irc_protocol_recv_command (irc_recv_msgq->server,
ptr_msg,
host, command, args))
(msg_decoded) ?
msg_decoded : ptr_msg,
host, command,
arguments))
{
case -1:
weechat_printf (irc_recv_msgq->server->buffer,
@@ -1251,9 +1329,9 @@ irc_server_msgq_flush ()
_("%s%s: unknown command: "
"cmd=\"%s\", "
"host=\"%s\", "
"args=\"%s\""),
"arguments=\"%s\""),
weechat_prefix ("error"),
"irc", command, host, args);
"irc", command, host, arguments);
break;
}
@@ -1261,8 +1339,8 @@ irc_server_msgq_flush ()
free (host);
if (command)
free (command);
if (args)
free (args);
if (arguments)
free (arguments);
if (pos)
{
+3 -2
View File
@@ -161,8 +161,9 @@ extern int irc_server_send (struct t_irc_server *server, char *buffer,
int size_buf);
extern void irc_server_outqueue_send (struct t_irc_server *server);
extern void irc_server_sendf (struct t_irc_server *server, char *format, ...);
extern void irc_server_parse_message (char *message, char **host,
char **command, char **args);
extern void irc_server_parse_message (char *message, char **nick,
char **host, char **command,
char **channel, char **arguments);
extern int irc_server_recv_cb (void *arg_server);
extern void irc_server_timer_cb (void *empty);
extern void irc_server_timer_check_away (void *empty);
+5 -3
View File
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* irc-core.c: main IRC functions */
/* irc.c: IRC plugin for WeeChat */
#ifdef HAVE_CONFIG_H
@@ -185,7 +185,6 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
/* hook signals */
weechat_hook_signal ("dump_data", &irc_dump_data_cb, NULL);
weechat_hook_signal ("config_reload", &irc_config_reload_cb, NULL);
weechat_hook_signal ("quit", &irc_quit_cb, NULL);
weechat_hook_signal ("debug", &irc_debug_cb, NULL);
@@ -213,8 +212,11 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
*/
int
weechat_plugin_end ()
weechat_plugin_end (struct t_weechat_plugin *plugin)
{
/* make C compiler happy */
(void) plugin;
irc_config_write ();
irc_server_disconnect_all ();
+4 -1
View File
@@ -659,8 +659,11 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
*/
int
weechat_plugin_end ()
weechat_plugin_end (struct t_weechat_plugin *plugin)
{
/* make C compiler happy */
(void) plugin;
logger_stop_all ();
return WEECHAT_RC_OK;
+22 -18
View File
@@ -281,6 +281,26 @@ plugin_config_free_all ()
plugin_config_free (plugin_options);
}
/*
* plugin_config_reload: reload plugins configuration file
* return: 0 = successful
* -1 = config file file not found
* -2 = error in config file
*/
int
plugin_config_reload (struct t_config_file *config_file)
{
/* make C compiler happy */
(void) config_file;
/* remove all plugin options */
plugin_config_free_all ();
/* reload plugins config file */
return config_file_reload (plugin_config);
}
/*
* plugin_config_read_option: read an option in config file
* Return: 0 = successful
@@ -335,7 +355,8 @@ plugin_config_write_options (struct t_config_file *config_file,
void
plugin_config_init ()
{
plugin_config = config_file_new (NULL, PLUGIN_CONFIG_FILENAME);
plugin_config = config_file_new (NULL, PLUGIN_CONFIG_FILENAME,
&plugin_config_reload);
if (plugin_config)
{
config_file_new_section (plugin_config, "plugins",
@@ -358,23 +379,6 @@ plugin_config_read ()
return config_file_read (plugin_config);
}
/*
* plugin_config_reload: read plugins configuration file
* return: 0 = successful
* -1 = config file file not found
* -2 = error in config file
*/
int
plugin_config_reload ()
{
/* remove all plugin options */
plugin_config_free_all ();
/* reload plugins config file */
return config_file_reload (plugin_config);
}
/*
* plugin_config_write: write plugins configuration file
* return: 0 if ok
+4 -1
View File
@@ -233,6 +233,7 @@ plugin_load (char *filename)
new_plugin->iconv_from_internal = &string_iconv_from_internal;
new_plugin->gettext = &plugin_api_gettext;
new_plugin->ngettext = &plugin_api_ngettext;
new_plugin->strndup = &string_strndup;
new_plugin->strcasecmp = &string_strcasecmp;
new_plugin->strncasecmp = &string_strncasecmp;
new_plugin->strcmp_ignore_chars = &string_strcmp_ignore_chars;
@@ -315,6 +316,8 @@ plugin_load (char *filename)
new_plugin->hook_signal_send = &hook_signal_send;
new_plugin->hook_config = &hook_config;
new_plugin->hook_completion = &hook_completion;
new_plugin->hook_modifier = &hook_modifier;
new_plugin->hook_modifier_exec = &hook_modifier_exec;
new_plugin->unhook = &unhook;
new_plugin->unhook_all = &unhook_all_plugin;
@@ -517,7 +520,7 @@ plugin_remove (struct t_weechat_plugin *plugin)
/* remove all hooks */
unhook_all_plugin (plugin);
/* remove pointer to this plugin on buffers */
for (ptr_buffer = gui_buffers; ptr_buffer;
ptr_buffer = ptr_buffer->next_buffer)
+111 -1
View File
@@ -1671,7 +1671,7 @@ weechat_lua_api_hook_config (lua_State *L)
}
/*
* weechat_lua_api_hook_completion_cb: callback for completion option hooked
* weechat_lua_api_hook_completion_cb: callback for completion hooked
*/
int
@@ -1752,6 +1752,114 @@ weechat_lua_api_hook_completion (lua_State *L)
LUA_RETURN_STRING_FREE(result);
}
/*
* weechat_lua_api_hook_modifier_cb: callback for modifier hooked
*/
char *
weechat_lua_api_hook_modifier_cb (void *data, char *modifier,
char *modifier_data, char *string)
{
struct t_script_callback *script_callback;
char *lua_argv[4];
script_callback = (struct t_script_callback *)data;
lua_argv[0] = modifier;
lua_argv[1] = modifier_data;
lua_argv[2] = string;
lua_argv[3] = NULL;
return (char *)weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_STRING,
script_callback->function,
lua_argv);
}
/*
* weechat_lua_api_hook_modifier: hook a modifier
*/
static int
weechat_lua_api_hook_modifier (lua_State *L)
{
const char *modifier, *function;
char *result;
int n;
/* make C compiler happy */
(void) L;
if (!lua_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_modifier");
LUA_RETURN_EMPTY;
}
modifier = NULL;
function = NULL;
n = lua_gettop (lua_current_interpreter);
if (n < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_modifier");
LUA_RETURN_EMPTY;
}
modifier = lua_tostring (lua_current_interpreter, -2);
function = lua_tostring (lua_current_interpreter, -1);
result = script_ptr2str (script_api_hook_modifier (weechat_lua_plugin,
lua_current_script,
(char *)modifier,
&weechat_lua_api_hook_modifier_cb,
(char *)function));
LUA_RETURN_STRING_FREE(result);
}
/*
* weechat_lua_api_hook_modifier_exec: execute a modifier hook
*/
static int
weechat_lua_api_hook_modifier_exec (lua_State *L)
{
const char *modifier, *modifier_data, *string;
char *result;
int n;
/* make C compiler happy */
(void) L;
if (!lua_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_modifier_exec");
LUA_RETURN_EMPTY;
}
modifier = NULL;
modifier_data = NULL;
string = NULL;
n = lua_gettop (lua_current_interpreter);
if (n < 3)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_modifier_exec");
LUA_RETURN_ERROR;
}
modifier = lua_tostring (lua_current_interpreter, -3);
modifier_data = lua_tostring (lua_current_interpreter, -2);
string = lua_tostring (lua_current_interpreter, -1);
result = weechat_hook_modifier_exec ((char *)modifier,
(char *)modifier_data,
(char *)string);
LUA_RETURN_STRING_FREE(result);
}
/*
* weechat_lua_api_unhook: unhook something
*/
@@ -3539,6 +3647,8 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
{ "hook_signal_send", &weechat_lua_api_hook_signal_send },
{ "hook_config", &weechat_lua_api_hook_config },
{ "hook_completion", &weechat_lua_api_hook_completion },
{ "hook_modifier", &weechat_lua_api_hook_modifier },
{ "hook_modifier_exec", &weechat_lua_api_hook_modifier_exec },
{ "unhook", &weechat_lua_api_unhook },
{ "unhook_all", &weechat_lua_api_unhook_all },
{ "buffer_new", &weechat_lua_api_buffer_new },
+96 -8
View File
@@ -1422,6 +1422,92 @@ static XS (XS_weechat_hook_completion)
PERL_RETURN_STRING_FREE(result);
}
/*
* weechat_perl_api_hook_modifier_cb: callback for modifier hooked
*/
char *
weechat_perl_api_hook_modifier_cb (void *data, char *modifier,
char *modifier_data, char *string)
{
struct t_script_callback *script_callback;
char *perl_argv[4];
script_callback = (struct t_script_callback *)data;
perl_argv[0] = modifier;
perl_argv[1] = modifier_data;
perl_argv[2] = string;
perl_argv[3] = NULL;
return (char *)weechat_perl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_STRING,
script_callback->function,
perl_argv);
}
/*
* weechat::hook_modifier: hook a modifier
*/
static XS (XS_weechat_hook_modifier)
{
char *result;
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_modifier");
PERL_RETURN_EMPTY;
}
if (items < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_modifier");
PERL_RETURN_EMPTY;
}
result = script_ptr2str (script_api_hook_modifier (weechat_perl_plugin,
perl_current_script,
SvPV (ST (0), PL_na), /* modifier */
&weechat_perl_api_hook_modifier_cb,
SvPV (ST (1), PL_na))); /* perl function */
PERL_RETURN_STRING_FREE(result);
}
/*
* weechat::hook_modifier_exec: execute a modifier hook
*/
static XS (XS_weechat_hook_modifier_exec)
{
char *result;
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_modifier_exec");
PERL_RETURN_EMPTY;
}
if (items < 3)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_modifier_exec");
PERL_RETURN_EMPTY;
}
result = weechat_hook_modifier_exec (SvPV (ST (0), PL_na), /* modifier */
SvPV (ST (1), PL_na), /* modifier_data */
SvPV (ST (2), PL_na)); /* string */
PERL_RETURN_STRING_FREE(result);
}
/*
* weechat::unhook: unhook something
*/
@@ -1487,7 +1573,7 @@ weechat_perl_api_input_data_cb (void *data, struct t_gui_buffer *buffer,
{
struct t_script_callback *script_callback;
char *perl_argv[3];
int *r, ret;
int *rc, ret;
script_callback = (struct t_script_callback *)data;
@@ -1495,16 +1581,16 @@ weechat_perl_api_input_data_cb (void *data, struct t_gui_buffer *buffer,
perl_argv[1] = input_data;
perl_argv[2] = NULL;
r = (int *) weechat_perl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
perl_argv);
if (!r)
rc = (int *) weechat_perl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
perl_argv);
if (!rc)
ret = WEECHAT_RC_ERROR;
else
{
ret = *r;
free (r);
ret = *rc;
free (rc);
}
if (perl_argv[0])
free (perl_argv[0]);
@@ -2723,6 +2809,8 @@ weechat_perl_api_init (pTHX)
newXS ("weechat::hook_signal_send", XS_weechat_hook_signal_send, "weechat");
newXS ("weechat::hook_config", XS_weechat_hook_config, "weechat");
newXS ("weechat::hook_completion", XS_weechat_hook_completion, "weechat");
newXS ("weechat::hook_modifier", XS_weechat_hook_modifier, "weechat");
newXS ("weechat::hook_modifier_exec", XS_weechat_hook_modifier_exec, "weechat");
newXS ("weechat::unhook", XS_weechat_unhook, "weechat");
newXS ("weechat::unhook_all", XS_weechat_unhook_all, "weechat");
newXS ("weechat::buffer_new", XS_weechat_buffer_new, "weechat");
+5 -4
View File
@@ -110,19 +110,20 @@ weechat_perl_exec (struct t_plugin_script *script,
char *func;
unsigned int count;
void *ret_value;
int *ret_i, mem_err;
int *ret_i, mem_err, length;
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));
int length = strlen (script->interpreter) + strlen (function) + 3;
func = (char *)malloc (length * sizeof(char));
if (!func)
return NULL;
snprintf (func, size, "%s::%s", (char *) script->interpreter, function);
snprintf (func, length, "%s::%s", (char *) script->interpreter, function);
#else
(void) length;
func = function;
PERL_SET_CONTEXT (script->interpreter);
#endif
@@ -1551,6 +1551,99 @@ weechat_python_api_hook_completion (PyObject *self, PyObject *args)
PYTHON_RETURN_STRING_FREE(result);
}
/*
* weechat_python_api_hook_modifier_cb: callback for modifier hooked
*/
char *
weechat_python_api_hook_modifier_cb (void *data, char *modifier,
char *modifier_data, char *string)
{
struct t_script_callback *script_callback;
char *python_argv[4];
script_callback = (struct t_script_callback *)data;
python_argv[0] = modifier;
python_argv[1] = modifier_data;
python_argv[2] = string;
python_argv[3] = NULL;
return (char *)weechat_python_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_STRING,
script_callback->function,
python_argv);
}
/*
* weechat_python_api_hook_modifier: hook a modifier
*/
static PyObject *
weechat_python_api_hook_modifier (PyObject *self, PyObject *args)
{
char *modifier, *function, *result;
PyObject *object;
/* make C compiler happy */
(void) self;
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_modifier");
PYTHON_RETURN_EMPTY;
}
modifier = NULL;
function = NULL;
if (!PyArg_ParseTuple (args, "ss", &modifier, &function))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_modifier");
PYTHON_RETURN_EMPTY;
}
result = script_ptr2str(script_api_hook_modifier (weechat_python_plugin,
python_current_script,
modifier,
&weechat_python_api_hook_modifier_cb,
function));
PYTHON_RETURN_STRING_FREE(result);
}
/*
* weechat_python_api_hook_modifier_exec: execute a modifier hook
*/
static PyObject *
weechat_python_api_hook_modifier_exec (PyObject *self, PyObject *args)
{
char *modifier, *modifier_data, *string, *result;
PyObject *object;
/* make C compiler happy */
(void) self;
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_modifier_exec");
PYTHON_RETURN_EMPTY;
}
modifier = NULL;
modifier_data = NULL;
string = NULL;
if (!PyArg_ParseTuple (args, "sss", &modifier, &modifier_data, &string))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_modifier_exec");
PYTHON_RETURN_EMPTY;
}
result = weechat_hook_modifier_exec (modifier, modifier_data, string);
PYTHON_RETURN_STRING_FREE(result);
}
/*
* weechat_python_api_unhook: unhook something
*/
@@ -3160,6 +3253,8 @@ PyMethodDef weechat_python_funcs[] =
{ "hook_signal_send", &weechat_python_api_hook_signal_send, METH_VARARGS, "" },
{ "hook_config", &weechat_python_api_hook_config, METH_VARARGS, "" },
{ "hook_completion", &weechat_python_api_hook_completion, METH_VARARGS, "" },
{ "hook_modifier", &weechat_python_api_hook_modifier, METH_VARARGS, "" },
{ "hook_modifier_exec", &weechat_python_api_hook_modifier_exec, METH_VARARGS, "" },
{ "unhook", &weechat_python_api_unhook, METH_VARARGS, "" },
{ "unhook_all", &weechat_python_api_unhook_all, METH_VARARGS, "" },
{ "buffer_new", &weechat_python_api_buffer_new, METH_VARARGS, "" },
+110
View File
@@ -1777,6 +1777,114 @@ weechat_ruby_api_hook_completion (VALUE class, VALUE completion,
RUBY_RETURN_STRING_FREE(result);
}
/*
* weechat_ruby_api_hook_modifier_cb: callback for modifier hooked
*/
char *
weechat_ruby_api_hook_modifier_cb (void *data, char *modifier,
char *modifier_data, char *string)
{
struct t_script_callback *script_callback;
char *ruby_argv[4];
script_callback = (struct t_script_callback *)data;
ruby_argv[0] = modifier;
ruby_argv[1] = modifier_data;
ruby_argv[2] = string;
ruby_argv[3] = NULL;
return (char *)weechat_ruby_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_STRING,
script_callback->function,
ruby_argv);
}
/*
* weechat_ruby_api_hook_modifier: hook a modifier
*/
static VALUE
weechat_ruby_api_hook_modifier (VALUE class, VALUE modifier, VALUE function)
{
char *c_modifier, *c_function, *result;
VALUE return_value;
/* make C compiler happy */
(void) class;
if (!ruby_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_modifier");
RUBY_RETURN_EMPTY;
}
c_modifier = NULL;
c_function = NULL;
if (NIL_P (modifier) || NIL_P (function))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_modifier");
RUBY_RETURN_EMPTY;
}
Check_Type (modifier, T_STRING);
Check_Type (function, T_STRING);
c_modifier = STR2CSTR (modifier);
c_function = STR2CSTR (function);
result = script_ptr2str (script_api_hook_modifier (weechat_ruby_plugin,
ruby_current_script,
c_modifier,
&weechat_ruby_api_hook_modifier_cb,
c_function));
RUBY_RETURN_STRING_FREE(result);
}
/*
* weechat_ruby_api_hook_modifier_exec: execute a modifier hook
*/
static VALUE
weechat_ruby_api_hook_modifier_exec (VALUE class, VALUE modifier,
VALUE modifier_data, VALUE string)
{
char *c_modifier, *c_modifier_data, *c_string, *result;
VALUE return_value;
/* make C compiler happy */
(void) class;
if (!ruby_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_modifier_exec");
RUBY_RETURN_EMPTY;
}
c_modifier = NULL;
c_modifier_data = NULL;
c_string = NULL;
if (NIL_P (modifier) || NIL_P (modifier_data) || NIL_P (string))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_modifier_exec");
RUBY_RETURN_EMPTY;
}
Check_Type (modifier, T_STRING);
Check_Type (modifier_data, T_STRING);
Check_Type (string, T_STRING);
c_modifier = STR2CSTR (modifier);
c_modifier_data = STR2CSTR (modifier_data);
c_string = STR2CSTR (string);
result = weechat_hook_modifier_exec (c_modifier, c_modifier_data, c_string);
RUBY_RETURN_STRING_FREE(result);
}
/*
* weechat_ruby_api_unhook: unhook something
*/
@@ -3300,6 +3408,8 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "hook_signal_send", &weechat_ruby_api_hook_signal_send, 3);
rb_define_module_function (ruby_mWeechat, "hook_config", &weechat_ruby_api_hook_config, 3);
rb_define_module_function (ruby_mWeechat, "hook_completion", &weechat_ruby_api_hook_completion, 2);
rb_define_module_function (ruby_mWeechat, "hook_modifier", &weechat_ruby_api_hook_modifier, 2);
rb_define_module_function (ruby_mWeechat, "hook_modifier_exec", &weechat_ruby_api_hook_modifier_exec, 3);
rb_define_module_function (ruby_mWeechat, "unhook", &weechat_ruby_api_unhook, 1);
rb_define_module_function (ruby_mWeechat, "unhook_all", &weechat_ruby_api_unhook_all, 0);
rb_define_module_function (ruby_mWeechat, "buffer_new", &weechat_ruby_api_buffer_new, 3);
+36
View File
@@ -385,6 +385,42 @@ script_api_hook_completion (struct t_weechat_plugin *weechat_plugin,
return new_hook;
}
/*
* script_api_hook_modifier: hook a modifier
* return new hook, NULL if error
*/
struct t_hook *
script_api_hook_modifier (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
char *modifier,
char *(*callback)(void *data, char *modifier,
char *modifier_data, char *string),
char *function)
{
struct t_script_callback *new_script_callback;
struct t_hook *new_hook;
new_script_callback = script_callback_alloc ();
if (!new_script_callback)
return NULL;
new_hook = weechat_hook_modifier (modifier, callback, new_script_callback);
if (!new_hook)
{
free (new_script_callback);
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
new_script_callback->hook = new_hook;
script_callback_add (script, new_script_callback);
return new_hook;
}
/*
* script_api_unhook: unhook something
* return 1 if ok, 0 if error
+8
View File
@@ -87,6 +87,14 @@ extern struct t_hook *script_api_hook_completion (struct t_weechat_plugin *weech
struct t_gui_buffer *buffer,
struct t_weelist *list),
char *function);
extern struct t_hook *script_api_hook_modifier (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
char *modifier,
char *(*callback)(void *data,
char *modifier,
char *modifier_data,
char *string),
char *function);
extern int script_api_unhook (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_hook *hook);
+25 -3
View File
@@ -94,6 +94,7 @@ struct t_weechat_plugin
char *(*iconv_from_internal) (char *charset, char *string);
char *(*gettext) (char *string);
char *(*ngettext) (char *single, char *plural, int count);
char *(*strndup) (char *string, int length);
int (*strcasecmp) (char *string1, char *string2);
int (*strncasecmp) (char *string1, char *string2, int max);
int (*strcmp_ignore_chars) (char *string1, char *string2,
@@ -155,7 +156,8 @@ struct t_weechat_plugin
/* config files */
struct t_config_file *(*config_new) (struct t_weechat_plugin *plugin,
char *filename);
char *filename,
int (*callback_reload)(struct t_config_file *config_file));
struct t_config_section *(*config_new_section) (struct t_config_file *config_file,
char *name,
void (*callback_read)
@@ -257,6 +259,16 @@ struct t_weechat_plugin
struct t_gui_buffer *buffer,
struct t_weelist *list),
void *callback_data);
struct t_hook *(*hook_modifier) (struct t_weechat_plugin *plugin,
char *modifier,
char *(*callback)(void *data,
char *modifier,
char *modifier_data,
char *string),
void *callback_data);
char *(*hook_modifier_exec) (struct t_weechat_plugin *plugin,
char *modifier, char *modifier_data,
char *string);
void (*unhook) (struct t_hook *hook);
void (*unhook_all) (struct t_weechat_plugin *plugin);
@@ -336,6 +348,8 @@ struct t_weechat_plugin
#define weechat_gettext(string) weechat_plugin->gettext(string)
#define weechat_ngettext(single,plural,number) \
weechat_plugin->ngettext(single, plural, number)
#define weechat_strndup(__string, __length) \
weechat_plugin->strndup(__string, __length)
#define weechat_strcasecmp(__string1, __string2) \
weechat_plugin->strcasecmp(__string1, __string2)
#define weechat_strncasecmp(__string1, __string2, __max) \
@@ -435,8 +449,9 @@ struct t_weechat_plugin
weechat_plugin->list_free(__list)
/* config files */
#define weechat_config_new(__filename) \
weechat_plugin->config_new(weechat_plugin, __filename)
#define weechat_config_new(__filename, __callback_reload) \
weechat_plugin->config_new(weechat_plugin, __filename, \
__callback_reload)
#define weechat_config_new_section(__config, __name, __cb_read, \
__cb_write_std, __cb_write_def) \
weechat_plugin->config_new_section(__config, __name, __cb_read, \
@@ -535,6 +550,13 @@ struct t_weechat_plugin
#define weechat_hook_completion(__completion, __callback, __data) \
weechat_plugin->hook_completion(weechat_plugin, __completion, \
__callback, __data)
#define weechat_hook_modifier(__modifier, __callback, __data) \
weechat_plugin->hook_modifier(weechat_plugin, __modifier, \
__callback, __data)
#define weechat_hook_modifier_exec(__modifier, __modifier_data, \
__string) \
weechat_plugin->hook_modifier_exec(weechat_plugin, __modifier, \
__modifier_data, __string)
#define weechat_unhook(__hook) \
weechat_plugin->unhook( __hook)
#define weechat_unhook_all() \