Add new functions in plugin API: hook_hsignal and hook_hsignal_send
parent
6e126937bc
commit
0cf04dca7c
|
@ -1,7 +1,7 @@
|
|||
WeeChat ChangeLog
|
||||
=================
|
||||
Sébastien Helleu <flashcode@flashtux.org>
|
||||
v0.3.4-dev, 2010-10-15
|
||||
v0.3.4-dev, 2010-10-23
|
||||
|
||||
|
||||
Version 0.3.4 (under dev!)
|
||||
|
@ -22,7 +22,7 @@ Version 0.3.4 (under dev!)
|
|||
(bug #30759)
|
||||
* api: add priority for hooks (task #10550)
|
||||
* api: add new functions: hashtable_get_string, hook_info_hashtable,
|
||||
info_get_hashtable
|
||||
info_get_hashtable, hook_hsignal, hook_hsignal_send
|
||||
* irc: add new options irc.color.nick_prefix and irc.color.nick_suffix
|
||||
* irc: add new option irc.look.item_away_message
|
||||
* irc: add tag "nick_xxx" in user messages
|
||||
|
|
|
@ -5788,8 +5788,8 @@ C example:
|
|||
weechat_hook_modifier ("2000|input_text_display", &modifier_cb, NULL);
|
||||
----------------------------------------
|
||||
|
||||
Following hook types allow priority: command, command_run, signal, config,
|
||||
completion, modifier, info, infolist.
|
||||
Following hook types allow priority: command, command_run, signal, hsignal,
|
||||
config, completion, modifier, info, infolist.
|
||||
|
||||
weechat_hook_command
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -6760,6 +6760,128 @@ weechat.hook_signal_send(signal, type_data, signal_data)
|
|||
weechat.hook_signal_send("my_signal", weechat.WEECHAT_HOOK_SIGNAL_STRING, my_string)
|
||||
----------------------------------------
|
||||
|
||||
weechat_hook_hsignal
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
_New in version 0.3.4._
|
||||
|
||||
Hook a hsignal (signal with hashtable).
|
||||
|
||||
Prototype:
|
||||
|
||||
[source,C]
|
||||
----------------------------------------
|
||||
struct t_hook *weechat_hook_hsignal (const char *signal,
|
||||
int (*callback)(void *data,
|
||||
const char *signal,
|
||||
struct t_hashtable *hashtable),
|
||||
void *callback_data);
|
||||
----------------------------------------
|
||||
|
||||
Arguments:
|
||||
|
||||
* 'signal': signal to catch, can begin or end with "*"
|
||||
(priority allowed, see note about <<hook_priority,priority>>):
|
||||
|
||||
[width="100%",cols="^1,^3,5",options="header"]
|
||||
|========================================
|
||||
| Plugin | Signal | Arguments
|
||||
|
||||
| irc | irc_redirection_xxx_yyy ^(1)^ |
|
||||
redirection output
|
||||
|========================================
|
||||
|
||||
[NOTE]
|
||||
^(1)^ 'xxx' is signal argument used in redirection, 'yyy' is redirection
|
||||
pattern.
|
||||
|
||||
* 'callback': function called when signal is received, arguments:
|
||||
** 'void *data': pointer
|
||||
** 'const char *signal': signal received
|
||||
** 'struct t_hashtable *hashtable': hashtable
|
||||
* 'callback_data': pointer given to callback when it is called by WeeChat
|
||||
|
||||
Return value:
|
||||
|
||||
* pointer to new hook, NULL if error occured
|
||||
|
||||
C example:
|
||||
|
||||
[source,C]
|
||||
----------------------------------------
|
||||
int
|
||||
my_hsignal_cb (void *data, const char *signal, struct t_hashtable *hashtable)
|
||||
{
|
||||
/* ... */
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
struct t_hook *my_hsignal_hook = weechat_hook_hsignal ("test",
|
||||
&my_hsignal_cb, NULL);
|
||||
----------------------------------------
|
||||
|
||||
Script (Python):
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
hook = weechat.hook_hsignal(signal, callback, callback_data)
|
||||
|
||||
# example
|
||||
def my_hsignal_cb(data, signal, hashtable):
|
||||
# ...
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
hook = weechat.hook_hsignal("test", "my_hsignal_cb", "")
|
||||
----------------------------------------
|
||||
|
||||
weechat_hook_hsignal_send
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
_New in version 0.3.4._
|
||||
|
||||
Send a hsignal (signal with hashtable).
|
||||
|
||||
Prototype:
|
||||
|
||||
[source,C]
|
||||
----------------------------------------
|
||||
void weechat_hook_hsignal_send (const char *signal, struct t_hashtable *hashtable);
|
||||
----------------------------------------
|
||||
|
||||
Arguments:
|
||||
|
||||
* 'signal': signal to send
|
||||
* 'hashtable': hashtable
|
||||
|
||||
C example:
|
||||
|
||||
[source,C]
|
||||
----------------------------------------
|
||||
struct t_hashtable *hashtable = weechat_hashtable_new (8,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
NULL,
|
||||
NULL);
|
||||
if (hashtable)
|
||||
{
|
||||
weechat_hashtable_set (hashtable, "key", "value");
|
||||
weechat_hook_hsignal_send ("my_hsignal", hashtable);
|
||||
weechat_hashtable_free (hashtable);
|
||||
}
|
||||
----------------------------------------
|
||||
|
||||
Script (Python):
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
weechat.hook_hsignal_send(signal, hashtable)
|
||||
|
||||
# example
|
||||
weechat.hook_hsignal_send("my_hsignal", { "key": "value" })
|
||||
----------------------------------------
|
||||
|
||||
weechat_hook_config
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
|
|
@ -5855,7 +5855,7 @@ weechat_hook_modifier ("2000|input_text_display", &modifier_cb, NULL);
|
|||
----------------------------------------
|
||||
|
||||
Les types de "hooks" suivants autorisent une priorité : command, command_run,
|
||||
signal, config, completion, modifier, info, infolist.
|
||||
signal, hsignal, config, completion, modifier, info, infolist.
|
||||
|
||||
weechat_hook_command
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -6844,6 +6844,129 @@ weechat.hook_signal_send(signal, type_data, signal_data)
|
|||
weechat.hook_signal_send("mon_signal", weechat.WEECHAT_HOOK_SIGNAL_STRING, ma_chaine)
|
||||
----------------------------------------
|
||||
|
||||
weechat_hook_hsignal
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
_Nouveau dans la version 0.3.4._
|
||||
|
||||
S'accroche à un hsignal (signal avec une hashtable).
|
||||
|
||||
Prototype :
|
||||
|
||||
[source,C]
|
||||
----------------------------------------
|
||||
struct t_hook *weechat_hook_hsignal (const char *signal,
|
||||
int (*callback)(void *data,
|
||||
const char *signal,
|
||||
struct t_hashtable *hashtable),
|
||||
void *callback_data);
|
||||
----------------------------------------
|
||||
|
||||
Paramètres :
|
||||
|
||||
* 'signal': signal à intercepter, peut commencer ou se terminer par "*"
|
||||
(priorité autorisée, voir la note sur la <<hook_priority,priorité>>) :
|
||||
|
||||
[width="100%",cols="^1,^3,5",options="header"]
|
||||
|========================================
|
||||
| Extension | Signal | Paramètres
|
||||
|
||||
| irc | irc_redirection_xxx_yyy ^(1)^ |
|
||||
sortie de la redirection
|
||||
|========================================
|
||||
|
||||
[NOTE]
|
||||
^(1)^ 'xxx' est l'argument "signal" utilisé dans la redirection, 'yyy' est le
|
||||
modèle de redirection ("pattern").
|
||||
|
||||
* 'callback' : fonction appelée quand le signal est reçu, paramètres :
|
||||
** 'void *data' : pointeur
|
||||
** 'const char *signal' : signal reçu
|
||||
** 'struct t_hashtable *hashtable' : hashtable
|
||||
* 'callback_data' : pointeur donné au "callback" lorsqu'il est appelé par
|
||||
WeeChat
|
||||
|
||||
Return value:
|
||||
|
||||
* pointeur vers le nouveau "hook", NULL en cas d'erreur
|
||||
|
||||
Exemple en C :
|
||||
|
||||
[source,C]
|
||||
----------------------------------------
|
||||
int
|
||||
my_hsignal_cb (void *data, const char *signal, struct t_hashtable *hashtable)
|
||||
{
|
||||
/* ... */
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
struct t_hook *my_hsignal_hook = weechat_hook_hsignal ("test",
|
||||
&my_hsignal_cb, NULL);
|
||||
----------------------------------------
|
||||
|
||||
Script (Python) :
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
hook = weechat.hook_hsignal(signal, callback, callback_data)
|
||||
|
||||
# exemple
|
||||
def my_hsignal_cb(data, signal, hashtable):
|
||||
# ...
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
hook = weechat.hook_hsignal("test", "my_hsignal_cb", "")
|
||||
----------------------------------------
|
||||
|
||||
weechat_hook_hsignal_send
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
_Nouveau dans la version 0.3.4._
|
||||
|
||||
Envoie un hsignal (signal avec hashtable).
|
||||
|
||||
Prototype :
|
||||
|
||||
[source,C]
|
||||
----------------------------------------
|
||||
void weechat_hook_hsignal_send (const char *signal, struct t_hashtable *hashtable);
|
||||
----------------------------------------
|
||||
|
||||
Paramètres :
|
||||
|
||||
* 'signal' : signal à envoyer
|
||||
* 'hashtable' : hashtable
|
||||
|
||||
Exemple en C :
|
||||
|
||||
[source,C]
|
||||
----------------------------------------
|
||||
struct t_hashtable *hashtable = weechat_hashtable_new (8,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
NULL,
|
||||
NULL);
|
||||
if (hashtable)
|
||||
{
|
||||
weechat_hashtable_set (hashtable, "clé", "valeur");
|
||||
weechat_hook_hsignal_send ("my_hsignal", hashtable);
|
||||
weechat_hashtable_free (hashtable);
|
||||
}
|
||||
----------------------------------------
|
||||
|
||||
Script (Python) :
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
weechat.hook_hsignal_send(signal, hashtable)
|
||||
|
||||
# example
|
||||
weechat.hook_hsignal_send("my_hsignal", { "clé": "valeur" })
|
||||
----------------------------------------
|
||||
|
||||
weechat_hook_config
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
|
|
@ -5841,7 +5841,7 @@ weechat_hook_modifier ("2000|input_text_display", &modifier_cb, NULL);
|
|||
----------------------------------------
|
||||
|
||||
I tipi di hook che seguono consentono la priorità: command, command_run,
|
||||
signal, config.
|
||||
signal, hsignal, config.
|
||||
|
||||
weechat_hook_command
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -6826,6 +6826,130 @@ weechat.hook_signal_send(signal, type_data, signal_data)
|
|||
weechat.hook_signal_send("my_signal", weechat.WEECHAT_HOOK_SIGNAL_STRING, my_string)
|
||||
----------------------------------------
|
||||
|
||||
// TRANSLATION MISSING
|
||||
weechat_hook_hsignal
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
_Novità nella versione 0.3.4._
|
||||
|
||||
Hook a hsignal (signal with hashtable).
|
||||
|
||||
Prototype:
|
||||
|
||||
[source,C]
|
||||
----------------------------------------
|
||||
struct t_hook *weechat_hook_hsignal (const char *signal,
|
||||
int (*callback)(void *data,
|
||||
const char *signal,
|
||||
struct t_hashtable *hashtable),
|
||||
void *callback_data);
|
||||
----------------------------------------
|
||||
|
||||
Arguments:
|
||||
|
||||
* 'signal': signal to catch, can begin or end with "*"
|
||||
(priority allowed, see note about <<hook_priority,priority>>):
|
||||
|
||||
[width="100%",cols="^1,^3,5",options="header"]
|
||||
|========================================
|
||||
| Plugin | Signal | Arguments
|
||||
|
||||
| irc | irc_redirection_xxx_yyy ^(1)^ |
|
||||
redirection output
|
||||
|========================================
|
||||
|
||||
[NOTE]
|
||||
^(1)^ 'xxx' is signal argument used in redirection, 'yyy' is redirection
|
||||
pattern.
|
||||
|
||||
* 'callback': function called when signal is received, arguments:
|
||||
** 'void *data': pointer
|
||||
** 'const char *signal': signal received
|
||||
** 'struct t_hashtable *hashtable': hashtable
|
||||
* 'callback_data': pointer given to callback when it is called by WeeChat
|
||||
|
||||
Return value:
|
||||
|
||||
* pointer to new hook, NULL if error occured
|
||||
|
||||
C example:
|
||||
|
||||
[source,C]
|
||||
----------------------------------------
|
||||
int
|
||||
my_hsignal_cb (void *data, const char *signal, struct t_hashtable *hashtable)
|
||||
{
|
||||
/* ... */
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
struct t_hook *my_hsignal_hook = weechat_hook_hsignal ("test",
|
||||
&my_hsignal_cb, NULL);
|
||||
----------------------------------------
|
||||
|
||||
Script (Python):
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
hook = weechat.hook_hsignal(signal, callback, callback_data)
|
||||
|
||||
# example
|
||||
def my_hsignal_cb(data, signal, hashtable):
|
||||
# ...
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
hook = weechat.hook_hsignal("test", "my_hsignal_cb", "")
|
||||
----------------------------------------
|
||||
|
||||
// TRANSLATION MISSING
|
||||
weechat_hook_hsignal_send
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
_Novità nella versione 0.3.4._
|
||||
|
||||
Send a hsignal (signal with hashtable).
|
||||
|
||||
Prototype:
|
||||
|
||||
[source,C]
|
||||
----------------------------------------
|
||||
void weechat_hook_hsignal_send (const char *signal, struct t_hashtable *hashtable);
|
||||
----------------------------------------
|
||||
|
||||
Arguments:
|
||||
|
||||
* 'signal': signal to send
|
||||
* 'hashtable': hashtable
|
||||
|
||||
C example:
|
||||
|
||||
[source,C]
|
||||
----------------------------------------
|
||||
struct t_hashtable *hashtable = weechat_hashtable_new (8,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
NULL,
|
||||
NULL);
|
||||
if (hashtable)
|
||||
{
|
||||
weechat_hashtable_set (hashtable, "key", "value");
|
||||
weechat_hook_hsignal_send ("my_hsignal", hashtable);
|
||||
weechat_hashtable_free (hashtable);
|
||||
}
|
||||
----------------------------------------
|
||||
|
||||
Script (Python):
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
weechat.hook_hsignal_send(signal, hashtable)
|
||||
|
||||
# example
|
||||
weechat.hook_hsignal_send("my_hsignal", { "key": "value" })
|
||||
----------------------------------------
|
||||
|
||||
weechat_hook_config
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
|
|
@ -53,8 +53,8 @@
|
|||
|
||||
char *hook_type_string[HOOK_NUM_TYPES] =
|
||||
{ "command", "command_run", "timer", "fd", "process", "connect", "print",
|
||||
"signal", "config", "completion", "modifier", "info", "info_hashtable",
|
||||
"infolist" };
|
||||
"signal", "hsignal", "config", "completion", "modifier",
|
||||
"info", "info_hashtable", "infolist" };
|
||||
struct t_hook *weechat_hooks[HOOK_NUM_TYPES]; /* list of hooks */
|
||||
struct t_hook *last_weechat_hook[HOOK_NUM_TYPES]; /* last hook */
|
||||
int hook_exec_recursion = 0; /* 1 when a hook is executed */
|
||||
|
@ -1875,6 +1875,77 @@ hook_signal_send (const char *signal, const char *type_data, void *signal_data)
|
|||
hook_exec_end ();
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_hsignal: hook a hsignal (signal with hashtable)
|
||||
*/
|
||||
|
||||
struct t_hook *
|
||||
hook_hsignal (struct t_weechat_plugin *plugin, const char *signal,
|
||||
t_hook_callback_hsignal *callback, void *callback_data)
|
||||
{
|
||||
struct t_hook *new_hook;
|
||||
struct t_hook_hsignal *new_hook_hsignal;
|
||||
int priority;
|
||||
const char *ptr_signal;
|
||||
|
||||
if (!signal || !signal[0] || !callback)
|
||||
return NULL;
|
||||
|
||||
new_hook = malloc (sizeof (*new_hook));
|
||||
if (!new_hook)
|
||||
return NULL;
|
||||
new_hook_hsignal = malloc (sizeof (*new_hook_hsignal));
|
||||
if (!new_hook_hsignal)
|
||||
{
|
||||
free (new_hook);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hook_get_priority_and_name (signal, &priority, &ptr_signal);
|
||||
hook_init_data (new_hook, plugin, HOOK_TYPE_HSIGNAL, priority,
|
||||
callback_data);
|
||||
|
||||
new_hook->hook_data = new_hook_hsignal;
|
||||
new_hook_hsignal->callback = callback;
|
||||
new_hook_hsignal->signal = strdup ((ptr_signal) ? ptr_signal : signal);
|
||||
|
||||
hook_add_to_list (new_hook);
|
||||
|
||||
return new_hook;
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_hsignal_send: send a hsignal (signal with hashtable)
|
||||
*/
|
||||
|
||||
void
|
||||
hook_hsignal_send (const char *signal, struct t_hashtable *hashtable)
|
||||
{
|
||||
struct t_hook *ptr_hook, *next_hook;
|
||||
|
||||
hook_exec_start ();
|
||||
|
||||
ptr_hook = weechat_hooks[HOOK_TYPE_HSIGNAL];
|
||||
while (ptr_hook)
|
||||
{
|
||||
next_hook = ptr_hook->next_hook;
|
||||
|
||||
if (!ptr_hook->deleted
|
||||
&& !ptr_hook->running
|
||||
&& (string_match (signal, HOOK_HSIGNAL(ptr_hook, signal), 0)))
|
||||
{
|
||||
ptr_hook->running = 1;
|
||||
(void) (HOOK_HSIGNAL(ptr_hook, callback))
|
||||
(ptr_hook->callback_data, signal, hashtable);
|
||||
ptr_hook->running = 0;
|
||||
}
|
||||
|
||||
ptr_hook = next_hook;
|
||||
}
|
||||
|
||||
hook_exec_end ();
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_config: hook a config option
|
||||
*/
|
||||
|
@ -2553,6 +2624,10 @@ unhook (struct t_hook *hook)
|
|||
if (HOOK_SIGNAL(hook, signal))
|
||||
free (HOOK_SIGNAL(hook, signal));
|
||||
break;
|
||||
case HOOK_TYPE_HSIGNAL:
|
||||
if (HOOK_HSIGNAL(hook, signal))
|
||||
free (HOOK_HSIGNAL(hook, signal));
|
||||
break;
|
||||
case HOOK_TYPE_CONFIG:
|
||||
if (HOOK_CONFIG(hook, option))
|
||||
free (HOOK_CONFIG(hook, option));
|
||||
|
@ -2865,6 +2940,15 @@ hook_add_to_infolist_type (struct t_infolist *infolist,
|
|||
return 0;
|
||||
}
|
||||
break;
|
||||
case HOOK_TYPE_HSIGNAL:
|
||||
if (!ptr_hook->deleted)
|
||||
{
|
||||
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_HSIGNAL(ptr_hook, callback)))
|
||||
return 0;
|
||||
if (!infolist_new_var_string (ptr_item, "signal", HOOK_HSIGNAL(ptr_hook, signal)))
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case HOOK_TYPE_CONFIG:
|
||||
if (!ptr_hook->deleted)
|
||||
{
|
||||
|
@ -3181,6 +3265,14 @@ hook_print_log ()
|
|||
log_printf (" signal. . . . . . . . : '%s'", HOOK_SIGNAL(ptr_hook, signal));
|
||||
}
|
||||
break;
|
||||
case HOOK_TYPE_HSIGNAL:
|
||||
if (!ptr_hook->deleted)
|
||||
{
|
||||
log_printf (" signal data:");
|
||||
log_printf (" callback. . . . . . . : 0x%lx", HOOK_HSIGNAL(ptr_hook, callback));
|
||||
log_printf (" signal. . . . . . . . : '%s'", HOOK_HSIGNAL(ptr_hook, signal));
|
||||
}
|
||||
break;
|
||||
case HOOK_TYPE_CONFIG:
|
||||
if (!ptr_hook->deleted)
|
||||
{
|
||||
|
|
|
@ -43,6 +43,7 @@ enum t_hook_type
|
|||
HOOK_TYPE_CONNECT, /* connect to peer with fork */
|
||||
HOOK_TYPE_PRINT, /* printed message */
|
||||
HOOK_TYPE_SIGNAL, /* signal */
|
||||
HOOK_TYPE_HSIGNAL, /* signal (using hashtable) */
|
||||
HOOK_TYPE_CONFIG, /* config option */
|
||||
HOOK_TYPE_COMPLETION, /* custom completions */
|
||||
HOOK_TYPE_MODIFIER, /* string modifier */
|
||||
|
@ -76,6 +77,7 @@ enum t_hook_type
|
|||
#define HOOK_CONNECT(hook, var) (((struct t_hook_connect *)hook->hook_data)->var)
|
||||
#define HOOK_PRINT(hook, var) (((struct t_hook_print *)hook->hook_data)->var)
|
||||
#define HOOK_SIGNAL(hook, var) (((struct t_hook_signal *)hook->hook_data)->var)
|
||||
#define HOOK_HSIGNAL(hook, var) (((struct t_hook_hsignal *)hook->hook_data)->var)
|
||||
#define HOOK_CONFIG(hook, var) (((struct t_hook_config *)hook->hook_data)->var)
|
||||
#define HOOK_COMPLETION(hook, var) (((struct t_hook_completion *)hook->hook_data)->var)
|
||||
#define HOOK_MODIFIER(hook, var) (((struct t_hook_modifier *)hook->hook_data)->var)
|
||||
|
@ -252,6 +254,18 @@ struct t_hook_signal
|
|||
/* with "*", "*" == any signal) */
|
||||
};
|
||||
|
||||
/* hook hsignal */
|
||||
|
||||
typedef int (t_hook_callback_hsignal)(void *data, const char *signal,
|
||||
struct t_hashtable *hashtable);
|
||||
|
||||
struct t_hook_hsignal
|
||||
{
|
||||
t_hook_callback_hsignal *callback; /* signal callback */
|
||||
char *signal; /* signal selected (may begin or end */
|
||||
/* with "*", "*" == any signal) */
|
||||
};
|
||||
|
||||
/* hook config */
|
||||
|
||||
typedef int (t_hook_callback_config)(void *data, const char *option,
|
||||
|
@ -409,6 +423,12 @@ extern struct t_hook *hook_signal (struct t_weechat_plugin *plugin,
|
|||
void *callback_data);
|
||||
extern void hook_signal_send (const char *signal, const char *type_data,
|
||||
void *signal_data);
|
||||
extern struct t_hook *hook_hsignal (struct t_weechat_plugin *plugin,
|
||||
const char *signal,
|
||||
t_hook_callback_hsignal *callback,
|
||||
void *callback_data);
|
||||
extern void hook_hsignal_send (const char *signal,
|
||||
struct t_hashtable *hashtable);
|
||||
extern struct t_hook *hook_config (struct t_weechat_plugin *plugin,
|
||||
const char *option,
|
||||
t_hook_callback_config *callback,
|
||||
|
|
|
@ -588,6 +588,8 @@ plugin_load (const char *filename)
|
|||
new_plugin->hook_print = &hook_print;
|
||||
new_plugin->hook_signal = &hook_signal;
|
||||
new_plugin->hook_signal_send = &hook_signal_send;
|
||||
new_plugin->hook_hsignal = &hook_hsignal;
|
||||
new_plugin->hook_hsignal_send = &hook_hsignal_send;
|
||||
new_plugin->hook_config = &hook_config;
|
||||
new_plugin->hook_completion = &hook_completion;
|
||||
new_plugin->hook_completion_list_add = &hook_completion_list_add;
|
||||
|
|
|
@ -4121,6 +4121,135 @@ weechat_lua_api_hook_signal_send (lua_State *L)
|
|||
LUA_RETURN_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_hook_hsignal_cb: callback for hsignal hooked
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_lua_api_hook_hsignal_cb (void *data, const char *signal,
|
||||
struct t_hashtable *hashtable)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
void *lua_argv[3];
|
||||
char empty_arg[1] = { '\0' };
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
if (script_callback && script_callback->function && script_callback->function[0])
|
||||
{
|
||||
lua_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
|
||||
lua_argv[1] = (signal) ? (char *)signal : empty_arg;
|
||||
lua_argv[2] = hashtable;
|
||||
|
||||
rc = (int *) weechat_lua_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
"ssh", lua_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_hook_hsignal: hook a hsignal
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_api_hook_hsignal (lua_State *L)
|
||||
{
|
||||
const char *signal, *function, *data;
|
||||
char *result;
|
||||
int n;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script || !lua_current_script->name)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, "hook_hsignal");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
signal = NULL;
|
||||
function = NULL;
|
||||
data = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n < 3)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "hook_hsignal");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
signal = lua_tostring (lua_current_interpreter, -3);
|
||||
function = lua_tostring (lua_current_interpreter, -2);
|
||||
data = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
result = script_ptr2str (script_api_hook_hsignal (weechat_lua_plugin,
|
||||
lua_current_script,
|
||||
signal,
|
||||
&weechat_lua_api_hook_hsignal_cb,
|
||||
function,
|
||||
data));
|
||||
|
||||
LUA_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_hook_hsignal_send: send a hsignal
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_api_hook_hsignal_send (lua_State *L)
|
||||
{
|
||||
const char *signal;
|
||||
struct t_hashtable *hashtable;
|
||||
int n;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script || !lua_current_script->name)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
|
||||
LUA_RETURN_ERROR;
|
||||
}
|
||||
|
||||
signal = NULL;
|
||||
hashtable = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
|
||||
LUA_RETURN_ERROR;
|
||||
}
|
||||
|
||||
signal = lua_tostring (lua_current_interpreter, -2);
|
||||
hashtable = weechat_lua_tohashtable (lua_current_interpreter, -1,
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
|
||||
|
||||
weechat_hook_hsignal_send (signal, hashtable);
|
||||
|
||||
if (hashtable)
|
||||
weechat_hashtable_free (hashtable);
|
||||
|
||||
LUA_RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_hook_config_cb: callback for config option hooked
|
||||
*/
|
||||
|
@ -7683,6 +7812,8 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
|
|||
{ "hook_print", &weechat_lua_api_hook_print },
|
||||
{ "hook_signal", &weechat_lua_api_hook_signal },
|
||||
{ "hook_signal_send", &weechat_lua_api_hook_signal_send },
|
||||
{ "hook_hsignal", &weechat_lua_api_hook_hsignal },
|
||||
{ "hook_hsignal_send", &weechat_lua_api_hook_hsignal_send },
|
||||
{ "hook_config", &weechat_lua_api_hook_config },
|
||||
{ "hook_completion", &weechat_lua_api_hook_completion },
|
||||
{ "hook_completion_list_add", &weechat_lua_api_hook_completion_list_add },
|
||||
|
|
|
@ -3486,6 +3486,121 @@ XS (XS_weechat_api_hook_signal_send)
|
|||
PERL_RETURN_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_api_hook_hsignal_cb: callback for hsignal hooked
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_perl_api_hook_hsignal_cb (void *data, const char *signal,
|
||||
struct t_hashtable *hashtable)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
void *perl_argv[3];
|
||||
char empty_arg[1] = { '\0' };
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
if (script_callback && script_callback->function && script_callback->function[0])
|
||||
{
|
||||
perl_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
|
||||
perl_argv[1] = (signal) ? (char *)signal : empty_arg;
|
||||
perl_argv[2] = hashtable;
|
||||
|
||||
rc = (int *) weechat_perl_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
"ssh", perl_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::hook_hsignal: hook a hsignal
|
||||
*/
|
||||
|
||||
XS (XS_weechat_api_hook_hsignal)
|
||||
{
|
||||
char *result, *signal, *function, *data;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script || !perl_current_script->name)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "hook_hsignal");
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (items < 3)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "hook_hsignal");
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
signal = SvPV (ST (0), PL_na);
|
||||
function = SvPV (ST (1), PL_na);
|
||||
data = SvPV (ST (2), PL_na);
|
||||
|
||||
result = script_ptr2str (script_api_hook_hsignal (weechat_perl_plugin,
|
||||
perl_current_script,
|
||||
signal,
|
||||
&weechat_perl_api_hook_hsignal_cb,
|
||||
function,
|
||||
data));
|
||||
|
||||
PERL_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::hook_hsignal_send: send a hsignal
|
||||
*/
|
||||
|
||||
XS (XS_weechat_api_hook_hsignal_send)
|
||||
{
|
||||
char *signal;
|
||||
struct t_hashtable *hashtable;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script || !perl_current_script->name)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
|
||||
PERL_RETURN_ERROR;
|
||||
}
|
||||
|
||||
if (items < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
|
||||
PERL_RETURN_ERROR;
|
||||
}
|
||||
|
||||
signal = SvPV (ST (0), PL_na);
|
||||
hashtable = weechat_perl_hash_to_hashtable (ST (1),
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
|
||||
|
||||
weechat_hook_hsignal_send (signal, hashtable);
|
||||
|
||||
if (hashtable)
|
||||
weechat_hashtable_free (hashtable);
|
||||
|
||||
PERL_RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_api_hook_config_cb: callback for config option hooked
|
||||
*/
|
||||
|
@ -6176,6 +6291,8 @@ weechat_perl_api_init (pTHX)
|
|||
newXS ("weechat::hook_print", XS_weechat_api_hook_print, "weechat");
|
||||
newXS ("weechat::hook_signal", XS_weechat_api_hook_signal, "weechat");
|
||||
newXS ("weechat::hook_signal_send", XS_weechat_api_hook_signal_send, "weechat");
|
||||
newXS ("weechat::hook_hsignal", XS_weechat_api_hook_hsignal, "weechat");
|
||||
newXS ("weechat::hook_hsignal_send", XS_weechat_api_hook_hsignal_send, "weechat");
|
||||
newXS ("weechat::hook_config", XS_weechat_api_hook_config, "weechat");
|
||||
newXS ("weechat::hook_completion", XS_weechat_api_hook_completion, "weechat");
|
||||
newXS ("weechat::hook_completion_list_add", XS_weechat_api_hook_completion_list_add, "weechat");
|
||||
|
|
|
@ -3680,6 +3680,128 @@ weechat_python_api_hook_signal_send (PyObject *self, PyObject *args)
|
|||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_hook_hsignal_cb: callback for hsignal hooked
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_python_api_hook_hsignal_cb (void *data, const char *signal,
|
||||
struct t_hashtable *hashtable)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
void *python_argv[3];
|
||||
char empty_arg[1] = { '\0' };
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
if (script_callback && script_callback->function && script_callback->function[0])
|
||||
{
|
||||
python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
|
||||
python_argv[1] = (signal) ? (char *)signal : empty_arg;
|
||||
python_argv[2] = weechat_python_hashtable_to_dict (hashtable);
|
||||
|
||||
rc = (int *) weechat_python_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
"ssO", python_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
if (python_argv[2])
|
||||
{
|
||||
Py_XDECREF((PyObject *)python_argv[2]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_hook_hsignal: hook a hsignal
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_api_hook_hsignal (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *signal, *function, *data, *result;
|
||||
PyObject *object;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script || !python_current_script->name)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_hsignal");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
signal = NULL;
|
||||
function = NULL;
|
||||
data = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "sss", &signal, &function, &data))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_hsignal");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
result = script_ptr2str (script_api_hook_hsignal (weechat_python_plugin,
|
||||
python_current_script,
|
||||
signal,
|
||||
&weechat_python_api_hook_hsignal_cb,
|
||||
function,
|
||||
data));
|
||||
|
||||
PYTHON_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_hook_hsignal_send: send a hsignal
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_api_hook_hsignal_send (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *signal;
|
||||
struct t_hashtable *hashtable;
|
||||
PyObject *dict;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script || !python_current_script->name)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
signal = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "sO", &signal, &dict))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
hashtable = weechat_python_dict_to_hashtable (dict,
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
|
||||
|
||||
weechat_hook_hsignal_send (signal, hashtable);
|
||||
|
||||
if (hashtable)
|
||||
weechat_hashtable_free (hashtable);
|
||||
|
||||
PYTHON_RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_hook_config_cb: callback for config option hooked
|
||||
*/
|
||||
|
@ -6496,6 +6618,8 @@ PyMethodDef weechat_python_funcs[] =
|
|||
{ "hook_print", &weechat_python_api_hook_print, METH_VARARGS, "" },
|
||||
{ "hook_signal", &weechat_python_api_hook_signal, METH_VARARGS, "" },
|
||||
{ "hook_signal_send", &weechat_python_api_hook_signal_send, METH_VARARGS, "" },
|
||||
{ "hook_hsignal", &weechat_python_api_hook_hsignal, METH_VARARGS, "" },
|
||||
{ "hook_hsignal_send", &weechat_python_api_hook_hsignal_send, METH_VARARGS, "" },
|
||||
{ "hook_config", &weechat_python_api_hook_config, METH_VARARGS, "" },
|
||||
{ "hook_completion", &weechat_python_api_hook_completion, METH_VARARGS, "" },
|
||||
{ "hook_completion_list_add", &weechat_python_api_hook_completion_list_add, METH_VARARGS, "" },
|
||||
|
|
|
@ -4248,6 +4248,136 @@ weechat_ruby_api_hook_signal_send (VALUE class, VALUE signal, VALUE type_data,
|
|||
RUBY_RETURN_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_hook_hsignal_cb: callback for hsignal hooked
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_ruby_api_hook_hsignal_cb (void *data, const char *signal,
|
||||
struct t_hashtable *hashtable)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
void *ruby_argv[3];
|
||||
char empty_arg[1] = { '\0' };
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
if (script_callback && script_callback->function && script_callback->function[0])
|
||||
{
|
||||
ruby_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
|
||||
ruby_argv[1] = (signal) ? (char *)signal : empty_arg;
|
||||
ruby_argv[2] = (void *)weechat_ruby_hashtable_to_hash (hashtable);
|
||||
|
||||
rc = (int *) weechat_ruby_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
"ssh", ruby_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_hook_hsignal: hook a hsignal
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_hook_hsignal (VALUE class, VALUE signal, VALUE function,
|
||||
VALUE data)
|
||||
{
|
||||
char *c_signal, *c_function, *c_data, *result;
|
||||
VALUE return_value;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script || !ruby_current_script->name)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "hook_hsignal");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
c_signal = NULL;
|
||||
c_function = NULL;
|
||||
c_data = NULL;
|
||||
|
||||
if (NIL_P (signal) || NIL_P (function) || NIL_P (data))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "hook_hsignal");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
Check_Type (signal, T_STRING);
|
||||
Check_Type (function, T_STRING);
|
||||
Check_Type (data, T_STRING);
|
||||
|
||||
c_signal = StringValuePtr (signal);
|
||||
c_function = StringValuePtr (function);
|
||||
c_data = StringValuePtr (data);
|
||||
|
||||
result = script_ptr2str (script_api_hook_hsignal (weechat_ruby_plugin,
|
||||
ruby_current_script,
|
||||
c_signal,
|
||||
&weechat_ruby_api_hook_hsignal_cb,
|
||||
c_function,
|
||||
c_data));
|
||||
|
||||
RUBY_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_hook_hsignal_send: send a hsignal
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_hook_hsignal_send (VALUE class, VALUE signal, VALUE hashtable)
|
||||
{
|
||||
char *c_signal;
|
||||
struct t_hashtable *c_hashtable;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script || !ruby_current_script->name)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
|
||||
RUBY_RETURN_ERROR;
|
||||
}
|
||||
|
||||
c_signal = NULL;
|
||||
|
||||
if (NIL_P (signal) || NIL_P (hashtable))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
|
||||
RUBY_RETURN_ERROR;
|
||||
}
|
||||
|
||||
Check_Type (signal, T_STRING);
|
||||
Check_Type (hashtable, T_HASH);
|
||||
|
||||
c_signal = StringValuePtr (signal);
|
||||
c_hashtable = weechat_ruby_hash_to_hashtable (hashtable,
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
|
||||
|
||||
weechat_hook_hsignal_send (c_signal, c_hashtable);
|
||||
|
||||
if (c_hashtable)
|
||||
weechat_hashtable_free (c_hashtable);
|
||||
|
||||
RUBY_RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_hook_config_cb: callback for config option hooked
|
||||
*/
|
||||
|
@ -7482,6 +7612,8 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
|
|||
rb_define_module_function (ruby_mWeechat, "hook_print", &weechat_ruby_api_hook_print, 6);
|
||||
rb_define_module_function (ruby_mWeechat, "hook_signal", &weechat_ruby_api_hook_signal, 3);
|
||||
rb_define_module_function (ruby_mWeechat, "hook_signal_send", &weechat_ruby_api_hook_signal_send, 3);
|
||||
rb_define_module_function (ruby_mWeechat, "hook_hsignal", &weechat_ruby_api_hook_hsignal, 3);
|
||||
rb_define_module_function (ruby_mWeechat, "hook_hsignal_send", &weechat_ruby_api_hook_hsignal_send, 2);
|
||||
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, 4);
|
||||
rb_define_module_function (ruby_mWeechat, "hook_completion_list_add", &weechat_ruby_api_hook_completion_list_add, 4);
|
||||
|
|
|
@ -1045,6 +1045,43 @@ script_api_hook_signal (struct t_weechat_plugin *weechat_plugin,
|
|||
return new_hook;
|
||||
}
|
||||
|
||||
/*
|
||||
* script_api_hook_hsignal: hook a hsignal
|
||||
* return new hook, NULL if error
|
||||
*/
|
||||
|
||||
struct t_hook *
|
||||
script_api_hook_hsignal (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
const char *signal,
|
||||
int (*callback)(void *data, const char *signal,
|
||||
struct t_hashtable *hashtable),
|
||||
const char *function,
|
||||
const char *data)
|
||||
{
|
||||
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_hsignal (signal, callback, new_script_callback);
|
||||
if (!new_hook)
|
||||
{
|
||||
script_callback_free_data (new_script_callback);
|
||||
free (new_script_callback);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
script_callback_init (new_script_callback, script, function, data);
|
||||
new_script_callback->hook = new_hook;
|
||||
|
||||
script_callback_add (script, new_script_callback);
|
||||
|
||||
return new_hook;
|
||||
}
|
||||
|
||||
/*
|
||||
* script_api_hook_config: hook a config option
|
||||
* return new hook, NULL if error
|
||||
|
|
|
@ -206,6 +206,14 @@ extern struct t_hook *script_api_hook_signal (struct t_weechat_plugin *weechat_p
|
|||
void *signal_data),
|
||||
const char *function,
|
||||
const char *data);
|
||||
extern struct t_hook *script_api_hook_hsignal (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
const char *signal,
|
||||
int (*callback)(void *data,
|
||||
const char *signal,
|
||||
struct t_hashtable *hashtable),
|
||||
const char *function,
|
||||
const char *data);
|
||||
extern struct t_hook *script_api_hook_config (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
const char *option,
|
||||
|
|
|
@ -3949,6 +3949,127 @@ weechat_tcl_api_hook_signal_send (ClientData clientData, Tcl_Interp *interp,
|
|||
TCL_RETURN_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_tcl_api_hook_hsignal_cb: callback for hsignal hooked
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_tcl_api_hook_hsignal_cb (void *data, const char *signal,
|
||||
struct t_hashtable *hashtable)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
void *tcl_argv[3];
|
||||
char empty_arg[1] = { '\0' };
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
if (script_callback && script_callback->function && script_callback->function[0])
|
||||
{
|
||||
tcl_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
|
||||
tcl_argv[1] = (signal) ? (char *)signal : empty_arg;
|
||||
tcl_argv[2] = hashtable;
|
||||
|
||||
rc = (int *) weechat_tcl_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
"ssh", tcl_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_tcl_api_hook_hsignal: hook a hsignal
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_tcl_api_hook_hsignal (ClientData clientData, Tcl_Interp *interp,
|
||||
int objc, Tcl_Obj *CONST objv[])
|
||||
{
|
||||
Tcl_Obj *objp;
|
||||
char *result, *signal, *function, *data;
|
||||
int i;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) clientData;
|
||||
|
||||
if (!tcl_current_script || !tcl_current_script->name)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "hook_hsignal");
|
||||
TCL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (objc < 4)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "hook_hsignal");
|
||||
TCL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
signal = Tcl_GetStringFromObj (objv[1], &i);
|
||||
function = Tcl_GetStringFromObj (objv[2], &i);
|
||||
data = Tcl_GetStringFromObj (objv[3], &i);
|
||||
|
||||
result = script_ptr2str (script_api_hook_hsignal (weechat_tcl_plugin,
|
||||
tcl_current_script,
|
||||
signal,
|
||||
&weechat_tcl_api_hook_hsignal_cb,
|
||||
function,
|
||||
data));
|
||||
|
||||
TCL_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_tcl_api_hook_hsignal_send: send a hsignal
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_tcl_api_hook_hsignal_send (ClientData clientData, Tcl_Interp *interp,
|
||||
int objc, Tcl_Obj *CONST objv[])
|
||||
{
|
||||
Tcl_Obj *objp;
|
||||
char *signal;
|
||||
struct t_hashtable *hashtable;
|
||||
int i;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) clientData;
|
||||
|
||||
if (!tcl_current_script || !tcl_current_script->name)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
|
||||
TCL_RETURN_ERROR;
|
||||
}
|
||||
|
||||
if (objc < 3)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
|
||||
TCL_RETURN_ERROR;
|
||||
}
|
||||
|
||||
signal = Tcl_GetStringFromObj (objv[1], &i);
|
||||
hashtable = weechat_tcl_dict_to_hashtable (interp, objv[2],
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
|
||||
|
||||
weechat_hook_hsignal_send (signal, hashtable);
|
||||
|
||||
if (hashtable)
|
||||
weechat_hashtable_free (hashtable);
|
||||
|
||||
TCL_RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_tcl_api_hook_config_cb: callback for config option hooked
|
||||
*/
|
||||
|
@ -7044,6 +7165,10 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
|
|||
weechat_tcl_api_hook_signal, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::hook_signal_send",
|
||||
weechat_tcl_api_hook_signal_send, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::hook_hsignal",
|
||||
weechat_tcl_api_hook_hsignal, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::hook_hsignal_send",
|
||||
weechat_tcl_api_hook_hsignal_send, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::hook_config",
|
||||
weechat_tcl_api_hook_config, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::hook_completion",
|
||||
|
|
|
@ -45,7 +45,7 @@ struct timeval;
|
|||
*/
|
||||
|
||||
/* API version (used to check that plugin has same API and can be loaded) */
|
||||
#define WEECHAT_PLUGIN_API_VERSION "20101017-01"
|
||||
#define WEECHAT_PLUGIN_API_VERSION "20101023-01"
|
||||
|
||||
/* macros for defining plugin infos */
|
||||
#define WEECHAT_PLUGIN_NAME(__name) \
|
||||
|
@ -487,6 +487,14 @@ struct t_weechat_plugin
|
|||
void *callback_data);
|
||||
void (*hook_signal_send) (const char *signal, const char *type_data,
|
||||
void *signal_data);
|
||||
struct t_hook *(*hook_hsignal) (struct t_weechat_plugin *plugin,
|
||||
const char *signal,
|
||||
int (*callback)(void *data,
|
||||
const char *signal,
|
||||
struct t_hashtable *hashtable),
|
||||
void *callback_data);
|
||||
void (*hook_hsignal_send) (const char *signal,
|
||||
struct t_hashtable *hashtable);
|
||||
struct t_hook *(*hook_config) (struct t_weechat_plugin *plugin,
|
||||
const char *option,
|
||||
int (*callback)(void *data,
|
||||
|
@ -1112,6 +1120,11 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
|
|||
#define weechat_hook_signal_send(__signal, __type_data, __signal_data) \
|
||||
weechat_plugin->hook_signal_send(__signal, __type_data, \
|
||||
__signal_data)
|
||||
#define weechat_hook_hsignal(__signal, __callback, __data) \
|
||||
weechat_plugin->hook_hsignal(weechat_plugin, __signal, __callback, \
|
||||
__data)
|
||||
#define weechat_hook_hsignal_send(__signal, __hashtable) \
|
||||
weechat_plugin->hook_hsignal_send(__signal, __hashtable)
|
||||
#define weechat_hook_config(__option, __callback, __data) \
|
||||
weechat_plugin->hook_config(weechat_plugin, __option, __callback, \
|
||||
__data)
|
||||
|
|
Loading…
Reference in New Issue