api: use buffer pointer in argument "modifier_data" sent to weechat_print modifier callback (closes #42)
This commit is contained in:
parent
7f1aeae5fb
commit
3505324096
@ -42,6 +42,7 @@ Bug fixes::
|
||||
* core: fix WEECHAT_SHAREDIR with CMake build (issue #1461)
|
||||
* core: fix memory leak in calculation of expression on FreeBSD (issue #1469)
|
||||
* core: fix resize of a bar when its size is 0 (automatic) (issue #1470)
|
||||
* api: replace plugin and buffer name by buffer pointer in argument "modifier_data" sent to weechat_print modifier callback (issue #42)
|
||||
* exec: fix use of same task id for different tasks (issue #1491)
|
||||
* fifo: fix errors when writing in the FIFO pipe (issue #713)
|
||||
* irc: reuse a buffer with wrong type "channel" when a private message is received (issue #869)
|
||||
|
@ -20,6 +20,42 @@ https://weechat.org/files/changelog/ChangeLog-devel.html[ChangeLog]
|
||||
[[v2.9]]
|
||||
== Version 2.9 (under dev)
|
||||
|
||||
[[v2.9_modifier_weechat_print]]
|
||||
=== New modifier_data for modifier "weechat_print"
|
||||
|
||||
The modifier "weechat_print" has been fixed and the content of "modifier_data"
|
||||
sent to the callback has changed (see issue #42).
|
||||
|
||||
This is an incompatible change, therefore all plugins and scripts using this
|
||||
modifier and the "modifier_data" argument must be updated.
|
||||
|
||||
The old format contained plugin name + ";" + buffer name + ";" + tags:
|
||||
|
||||
----
|
||||
irc;freenode.#weechat;tag1,tag2,tag3
|
||||
----
|
||||
|
||||
The new format contains buffer pointer + ";" + tags:
|
||||
|
||||
----
|
||||
0x123abc;tag1,tag2,tag3
|
||||
----
|
||||
|
||||
The following scripts are updated consequently to be compatible with all
|
||||
WeeChat versions:
|
||||
|
||||
* https://weechat.org/scripts/source/colorize_lines.pl.html/[colorize_lines.pl] 3.9
|
||||
* https://weechat.org/scripts/source/colorize_nicks.py/[colorize_nicks.py] 27
|
||||
* https://weechat.org/scripts/source/colorizer.rb/[colorizer.rb] 0.2
|
||||
* https://weechat.org/scripts/source/curiousignore.pl/[curiousignore.pl] 0.4
|
||||
* https://weechat.org/scripts/source/format_lines.pl/[format_lines.pl] 1.6
|
||||
* https://weechat.org/scripts/source/identica.py/[identica.py] 0.4.3
|
||||
* https://weechat.org/scripts/source/mass_hl_blocker.pl/[mass_hl_blocker.pl] 0.2
|
||||
* https://weechat.org/scripts/source/noirccolors.py/[noirccolors.py] 0.4
|
||||
* https://weechat.org/scripts/source/parse_relayed_msg.pl/[parse_relayed_msg.pl] 1.9.3
|
||||
* https://weechat.org/scripts/source/unhighlight.py/[unhighlight.py] 0.1.3
|
||||
* https://weechat.org/scripts/source/weemoticons.py/[weemoticons.py] 0.3
|
||||
|
||||
[[v2.9_api_completion_functions]]
|
||||
=== Move of API completion functions
|
||||
|
||||
|
@ -11518,7 +11518,7 @@ List of modifiers used by WeeChat and plugins:
|
||||
New content of command line sent to buffer.
|
||||
|
||||
| [[hook_modifier_weechat_print]] weechat_print |
|
||||
plugin + ";" + buffer_name + ";" + tags |
|
||||
buffer pointer ("0x123...") + ";" + tags ^(3)^ |
|
||||
Message printed. |
|
||||
New message printed. +
|
||||
For more information on the hooks called when a line is printed, see
|
||||
@ -11527,7 +11527,8 @@ List of modifiers used by WeeChat and plugins:
|
||||
|
||||
[NOTE]
|
||||
^(1)^ _xxx_ is IRC command name. +
|
||||
^(2)^ _yyy_ is bar name.
|
||||
^(2)^ _yyy_ is bar name. +
|
||||
^(3)^ With WeeChat ≤ 2.8, the format was: plugin + ";" + buffer_name + ";" + tags.
|
||||
|
||||
C example:
|
||||
|
||||
|
@ -11756,7 +11756,7 @@ Liste des modificateurs utilisés par WeeChat et les extensions :
|
||||
Nouveau contenu de la ligne de commande envoyée au tampon.
|
||||
|
||||
| [[hook_modifier_weechat_print]] weechat_print |
|
||||
extension + ";" + nom_tampon + ";" + étiquettes |
|
||||
pointeur vers le tampon ("0x123..") + ";" + étiquettes ^(3)^ |
|
||||
Message affiché. |
|
||||
Nouveau message affiché. +
|
||||
Pour plus d'informations sur les "hooks" appelés lorsqu'une ligne est affichée,
|
||||
@ -11765,7 +11765,8 @@ Liste des modificateurs utilisés par WeeChat et les extensions :
|
||||
|
||||
[NOTE]
|
||||
^(1)^ _xxx_ est un nom de commande IRC. +
|
||||
^(2)^ _yyy_ est le nom de la barre.
|
||||
^(2)^ _yyy_ est le nom de la barre. +
|
||||
^(3)^ Avec WeeChat ≤ 2.8, le format était : extension + ";" + nom_tampon + ";" + étiquettes.
|
||||
|
||||
Exemple en C :
|
||||
|
||||
|
@ -11977,7 +11977,7 @@ List of modifiers used by WeeChat and plugins:
|
||||
|
||||
// TRANSLATION MISSING
|
||||
| [[hook_modifier_weechat_print]] weechat_print |
|
||||
plugin + ";" + buffer_name + ";" + tags |
|
||||
buffer pointer ("0x123...") + ";" + tags ^(3)^ |
|
||||
Messaggio stampato. |
|
||||
Nuovo messaggio stampato. +
|
||||
For more information on the hooks called when a line is printed, see
|
||||
@ -11986,7 +11986,8 @@ List of modifiers used by WeeChat and plugins:
|
||||
|
||||
[NOTE]
|
||||
^(1)^ _xxx_ è il nome del comando IRC. +
|
||||
^(2)^ _yyy_ è il nome della barra.
|
||||
^(2)^ _yyy_ è il nome della barra. +
|
||||
^(3)^ With WeeChat ≤ 2.8, the format was: plugin + ";" + buffer_name + ";" + tags.
|
||||
|
||||
Esempio in C:
|
||||
|
||||
|
@ -11511,16 +11511,18 @@ WeeChat とプラグインが使う修飾子のリスト:
|
||||
バッファに送信するコマンドラインの新しい内容
|
||||
|
||||
| [[hook_modifier_weechat_print]] weechat_print |
|
||||
plugin + ";" + buffer_name + ";" + tags |
|
||||
buffer pointer ("0x123...") + ";" + tags ^(3)^ |
|
||||
表示されたメッセージ |
|
||||
表示される新しいメッセージ +
|
||||
行が表示される際に呼び出されるフックについての詳細は
|
||||
<<_hook_line,hook_line>> を参照してください
|
||||
|===
|
||||
|
||||
// TRANSLATION MISSING
|
||||
[NOTE]
|
||||
^(1)^ _xxx_ は IRC コマンド名。 +
|
||||
^(2)^ _yyy_ はバーの名前。
|
||||
^(2)^ _yyy_ はバーの名前。 +
|
||||
^(3)^ With WeeChat ≤ 2.8, the format was: plugin + ";" + buffer_name + ";" + tags.
|
||||
|
||||
C 言語での使用例:
|
||||
|
||||
|
@ -761,12 +761,7 @@ gui_chat_printf_date_tags_internal (struct t_gui_buffer *buffer,
|
||||
goto no_print;
|
||||
|
||||
/* call modifier for message printed ("weechat_print") */
|
||||
length_data = strlen (gui_buffer_get_plugin_name (new_line->data->buffer)) +
|
||||
1 +
|
||||
strlen (new_line->data->buffer->name) +
|
||||
1 +
|
||||
((tags) ? strlen (tags) : 0) +
|
||||
1;
|
||||
length_data = 64 + 1 + ((tags) ? strlen (tags) : 0) + 1;
|
||||
modifier_data = malloc (length_data);
|
||||
length_str = ((new_line->data->prefix && new_line->data->prefix[0]) ? strlen (new_line->data->prefix) : 1) +
|
||||
1 +
|
||||
@ -776,9 +771,8 @@ gui_chat_printf_date_tags_internal (struct t_gui_buffer *buffer,
|
||||
if (modifier_data && string)
|
||||
{
|
||||
snprintf (modifier_data, length_data,
|
||||
"%s;%s;%s",
|
||||
gui_buffer_get_plugin_name (new_line->data->buffer),
|
||||
new_line->data->buffer->name,
|
||||
"0x%lx;%s",
|
||||
(unsigned long)buffer,
|
||||
(tags) ? tags : "");
|
||||
if (display_time)
|
||||
{
|
||||
|
@ -594,10 +594,11 @@ trigger_callback_modifier_cb (const void *pointer, void *data,
|
||||
{
|
||||
struct t_gui_buffer *buffer;
|
||||
const char *ptr_string;
|
||||
char *string_modified, *pos, *pos2, *plugin_name, *buffer_name;
|
||||
char *buffer_full_name, *str_tags, **tags, *prefix, *string_no_color;
|
||||
int length, num_tags;
|
||||
char *string_modified, *pos, *buffer_pointer;
|
||||
char *str_tags, **tags, *prefix, *string_no_color;
|
||||
int length, num_tags, rc;
|
||||
void *ptr_irc_server, *ptr_irc_channel;
|
||||
unsigned long value;
|
||||
|
||||
TRIGGER_CALLBACK_CB_INIT(NULL);
|
||||
|
||||
@ -700,41 +701,32 @@ trigger_callback_modifier_cb (const void *pointer, void *data,
|
||||
|
||||
/*
|
||||
* extract buffer/tags from modifier data
|
||||
* (format: "plugin;buffer_name;tags")
|
||||
* (format: "buffer_pointer;tags")
|
||||
*/
|
||||
pos = strchr (modifier_data, ';');
|
||||
if (pos)
|
||||
{
|
||||
plugin_name = weechat_strndup (modifier_data, pos - modifier_data);
|
||||
if (plugin_name)
|
||||
buffer_pointer = weechat_strndup (modifier_data,
|
||||
pos - modifier_data);
|
||||
if (buffer_pointer)
|
||||
{
|
||||
weechat_hashtable_set (extra_vars, "tg_plugin", plugin_name);
|
||||
pos++;
|
||||
pos2 = strchr (pos, ';');
|
||||
if (pos2)
|
||||
rc = sscanf (buffer_pointer, "0x%lx", &value);
|
||||
if ((rc != EOF) && (rc != 0))
|
||||
{
|
||||
buffer_name = weechat_strndup (pos, pos2 - pos);
|
||||
if (buffer_name)
|
||||
{
|
||||
buffer = weechat_buffer_search (plugin_name,
|
||||
buffer_name);
|
||||
length = strlen (plugin_name) + 1 + strlen (buffer_name) + 1;
|
||||
buffer_full_name = malloc (length);
|
||||
if (buffer_full_name)
|
||||
{
|
||||
snprintf (buffer_full_name, length,
|
||||
"%s.%s", plugin_name, buffer_name);
|
||||
weechat_hashtable_set (extra_vars, "tg_buffer",
|
||||
buffer_full_name);
|
||||
free (buffer_full_name);
|
||||
}
|
||||
free (buffer_name);
|
||||
}
|
||||
pos2++;
|
||||
if (pos2[0])
|
||||
buffer = (struct t_gui_buffer *)value;
|
||||
weechat_hashtable_set (
|
||||
extra_vars,
|
||||
"tg_plugin",
|
||||
weechat_buffer_get_string (buffer, "plugin"));
|
||||
weechat_hashtable_set (
|
||||
extra_vars,
|
||||
"tg_buffer",
|
||||
weechat_buffer_get_string (buffer, "full_name"));
|
||||
pos++;
|
||||
if (pos[0])
|
||||
{
|
||||
tags = weechat_string_split (
|
||||
pos2,
|
||||
pos,
|
||||
",",
|
||||
NULL,
|
||||
WEECHAT_STRING_SPLIT_STRIP_LEFT
|
||||
@ -742,18 +734,18 @@ trigger_callback_modifier_cb (const void *pointer, void *data,
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
|
||||
0,
|
||||
&num_tags);
|
||||
length = 1 + strlen (pos2) + 1 + 1;
|
||||
length = 1 + strlen (pos) + 1 + 1;
|
||||
str_tags = malloc (length);
|
||||
if (str_tags)
|
||||
{
|
||||
snprintf (str_tags, length, ",%s,", pos2);
|
||||
snprintf (str_tags, length, ",%s,", pos);
|
||||
weechat_hashtable_set (extra_vars, "tg_tags",
|
||||
str_tags);
|
||||
free (str_tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
free (plugin_name);
|
||||
free (buffer_pointer);
|
||||
}
|
||||
}
|
||||
weechat_hashtable_set (pointers, "buffer", buffer);
|
||||
|
@ -174,32 +174,43 @@ test_modifier_cb (const void *pointer, void *data,
|
||||
const char *string)
|
||||
{
|
||||
char **items, *new_string;
|
||||
const char *ptr_plugin, *ptr_name, *ptr_tags, *ptr_msg;
|
||||
int num_items, length;
|
||||
const char *ptr_plugin, *ptr_tags, *ptr_msg;
|
||||
int num_items, length, rc;
|
||||
unsigned long value;
|
||||
struct t_gui_buffer *ptr_buffer;
|
||||
|
||||
/* make C++ compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) modifier;
|
||||
|
||||
/* split modifier_data, which is: "plugin;name;tags" */
|
||||
new_string = NULL;
|
||||
|
||||
/* split modifier_data, which is: "buffer_pointer;tags" */
|
||||
items = string_split (modifier_data, ";", NULL,
|
||||
WEECHAT_STRING_SPLIT_STRIP_LEFT
|
||||
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
|
||||
3, &num_items);
|
||||
if (num_items < 2)
|
||||
return NULL;
|
||||
2, &num_items);
|
||||
if (!items || (num_items < 1))
|
||||
goto error;
|
||||
|
||||
ptr_plugin = items[0];
|
||||
ptr_name = items[1];
|
||||
ptr_tags = (num_items > 2) ? items[2] : NULL;
|
||||
ptr_tags = (num_items >= 2) ? items[1] : NULL;
|
||||
|
||||
rc = sscanf (items[0], "0x%lx", &value);
|
||||
if ((rc == EOF) || (rc == 0))
|
||||
goto error;
|
||||
ptr_buffer = (struct t_gui_buffer *)value;
|
||||
|
||||
ptr_plugin = gui_buffer_get_plugin_name (ptr_buffer);
|
||||
if (!ptr_plugin)
|
||||
goto error;
|
||||
|
||||
/* do nothing on a buffer different from "core.test" */
|
||||
if ((strcmp (ptr_plugin, "core") != 0)
|
||||
|| (strcmp (ptr_name, TEST_BUFFER_NAME) != 0))
|
||||
|| (strcmp (ptr_buffer->name, TEST_BUFFER_NAME) != 0))
|
||||
{
|
||||
return NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (strncmp (string, "\t\t", 2) == 0)
|
||||
@ -210,14 +221,14 @@ test_modifier_cb (const void *pointer, void *data,
|
||||
{
|
||||
ptr_msg = strchr (string, '\t');
|
||||
if (!ptr_msg)
|
||||
return NULL;
|
||||
goto error;
|
||||
ptr_msg++;
|
||||
}
|
||||
|
||||
length = strlen (string) + 128;
|
||||
new_string = (char *)malloc (length);
|
||||
if (!new_string)
|
||||
return NULL;
|
||||
goto error;
|
||||
new_string[0] = '\0';
|
||||
|
||||
if (ptr_tags && strstr (ptr_tags, "add_prefix"))
|
||||
@ -253,6 +264,13 @@ test_modifier_cb (const void *pointer, void *data,
|
||||
}
|
||||
|
||||
return new_string;
|
||||
|
||||
error:
|
||||
if (items)
|
||||
string_free_split (items);
|
||||
if (new_string)
|
||||
free (new_string);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user