diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2017-06-02 07:46:17 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2017-06-02 07:46:17 +0200 |
commit | 593eee869f47872dd8c512ab9ac74f3167ad50af (patch) | |
tree | 8def62153567113172a5d397accb6c58b6fb3e51 | |
parent | eff373e73bdf204ff597b7ebcd074ee58e606d09 (diff) | |
download | weechat-593eee869f47872dd8c512ab9ac74f3167ad50af.zip |
trigger: add "irc_server" and "irc_channel" pointers in data for IRC signal/modifier hooks
-rw-r--r-- | ChangeLog.adoc | 1 | ||||
-rw-r--r-- | doc/de/weechat_user.de.adoc | 32 | ||||
-rw-r--r-- | doc/en/weechat_user.en.adoc | 30 | ||||
-rw-r--r-- | doc/fr/weechat_user.fr.adoc | 30 | ||||
-rw-r--r-- | doc/it/weechat_user.it.adoc | 34 | ||||
-rw-r--r-- | doc/ja/weechat_user.ja.adoc | 32 | ||||
-rw-r--r-- | doc/pl/weechat_user.pl.adoc | 32 | ||||
-rw-r--r-- | src/plugins/trigger/trigger-callback.c | 104 |
8 files changed, 195 insertions, 100 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 47a3ec059..711896377 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -28,6 +28,7 @@ Improvements:: * core: allow index for hdata arrays in evaluation of expressions * buflist: add support of char "~" in option buflist.look.sort for case insensitive comparison * buflist: add variable `${current_buffer}` (boolean "0" / "1") in bar item evaluation + * trigger: add "irc_server" and "irc_channel" pointers in data for IRC signal/modifier hooks Bug fixes:: diff --git a/doc/de/weechat_user.de.adoc b/doc/de/weechat_user.de.adoc index a46040653..6201fcde2 100644 --- a/doc/de/weechat_user.de.adoc +++ b/doc/de/weechat_user.de.adoc @@ -3582,20 +3582,24 @@ und die Daten in einer Hashtable gesichert: [width="100%",cols="3m,2,14",options="header"] |=== -| Variable | Typ | Beschreibung -| server | string | Name des Server (Beispiel: "freenode"). -| tags | string | Tags in Nachricht (findet selten Verwendung). -| message_without_tags | string | Nachricht ohne Tags. -| nick | string | Nick. -| host | string | Hostname. -| command | string | IRC Befehl (Beispiel: "PRIVMSG", "NOTICE", ...). -| channel | string | IRC Channel. -| arguments | string | Argumente des Befehls (Beinhaltet Wert von _channel_). -| text | string | Text (zum Beipiel eine Nachricht eines Users). -| pos_command | string | Index von _command_ innerhalb einer Nachricht ("-1" falls _command_ nicht gefunden wird). -| pos_arguments | string | Index von_arguments_ innerhalb einer Nachricht ("-1" falls _arguments_ nicht gefunden wird). -| pos_channel | string | Index von _channel_ innerhalb einer Nachricht ("-1" falls _channel_ nicht gefunden wird). -| pos_text | string | Index von _text_ innerhalb einer Nachricht ("-1" falls _text_ nicht gefunden wird). +| Variable | Typ | Beschreibung +// TRANSLATION MISSING +| irc_server | pointer | Pointer to IRC server (variables in hdata of type "irc_server" can be used, like `${irc_server.name}`). +// TRANSLATION MISSING +| irc_channel | pointer | Pointer to IRC channel (variables in hdata of type "irc_channel" can be used, like `${irc_channel.name}`). +| server | string | Name des Server (Beispiel: "freenode"). +| tags | string | Tags in Nachricht (findet selten Verwendung). +| message_without_tags | string | Nachricht ohne Tags. +| nick | string | Nick. +| host | string | Hostname. +| command | string | IRC Befehl (Beispiel: "PRIVMSG", "NOTICE", ...). +| channel | string | IRC Channel. +| arguments | string | Argumente des Befehls (Beinhaltet Wert von _channel_). +| text | string | Text (zum Beipiel eine Nachricht eines Users). +| pos_command | string | Index von _command_ innerhalb einer Nachricht ("-1" falls _command_ nicht gefunden wird). +| pos_arguments | string | Index von_arguments_ innerhalb einer Nachricht ("-1" falls _arguments_ nicht gefunden wird). +| pos_channel | string | Index von _channel_ innerhalb einer Nachricht ("-1" falls _channel_ nicht gefunden wird). +| pos_text | string | Index von _text_ innerhalb einer Nachricht ("-1" falls _text_ nicht gefunden wird). |=== Sofern es sich bei den Daten um einen Pointer handelt, kann die Variable `tg_signal_data` diff --git a/doc/en/weechat_user.en.adoc b/doc/en/weechat_user.en.adoc index 7a65021b7..26e26ff0f 100644 --- a/doc/en/weechat_user.en.adoc +++ b/doc/en/weechat_user.en.adoc @@ -3488,20 +3488,22 @@ is added in hashtable: [width="100%",cols="3m,2,14",options="header"] |=== -| Variable | Type | Description -| server | string | Name of server (example: "freenode"). -| tags | string | Tags in message (rarely used). -| message_without_tags | string | Message without tags. -| nick | string | Nick. -| host | string | Hostname. -| command | string | IRC command (example: "PRIVMSG", "NOTICE", ...). -| channel | string | IRC channel. -| arguments | string | Arguments of command (includes value of _channel_). -| text | string | Text (for example user message). -| pos_command | string | The index of _command_ in message ("-1" if _command_ was not found). -| pos_arguments | string | The index of _arguments_ in message ("-1" if _arguments_ was not found). -| pos_channel | string | The index of _channel_ in message ("-1" if _channel_ was not found). -| pos_text | string | The index of _text_ in message ("-1" if _text_ was not found). +| Variable | Type | Description +| irc_server | pointer | Pointer to IRC server (variables in hdata of type "irc_server" can be used, like `${irc_server.name}`). +| irc_channel | pointer | Pointer to IRC channel (variables in hdata of type "irc_channel" can be used, like `${irc_channel.name}`). +| server | string | Name of server (example: "freenode"). +| tags | string | Tags in message (rarely used). +| message_without_tags | string | Message without tags. +| nick | string | Nick. +| host | string | Hostname. +| command | string | IRC command (example: "PRIVMSG", "NOTICE", ...). +| channel | string | IRC channel. +| arguments | string | Arguments of command (includes value of _channel_). +| text | string | Text (for example user message). +| pos_command | string | The index of _command_ in message ("-1" if _command_ was not found). +| pos_arguments | string | The index of _arguments_ in message ("-1" if _arguments_ was not found). +| pos_channel | string | The index of _channel_ in message ("-1" if _channel_ was not found). +| pos_text | string | The index of _text_ in message ("-1" if _text_ was not found). |=== When the data is a pointer, the variable `tg_signal_data` can be used like this diff --git a/doc/fr/weechat_user.fr.adoc b/doc/fr/weechat_user.fr.adoc index 83811030b..ac60c70d7 100644 --- a/doc/fr/weechat_user.fr.adoc +++ b/doc/fr/weechat_user.fr.adoc @@ -3606,20 +3606,22 @@ suivantes sont ajoutées dans la table de hachage : [width="100%",cols="3m,2,14",options="header"] |=== -| Variable | Type | Description -| server | chaîne | Nom du serveur (exemple : "freenode"). -| tags | chaîne | Étiquettes dans le message (rarement utilisées). -| message_without_tags | chaîne | Message sans les étiquettes. -| nick | chaîne | Pseudo. -| host | chaîne | Nom d'hôte. -| command | chaîne | Commande IRC (exemple : "PRIVMSG", "NOTICE", ...). -| channel | chaîne | Canal IRC. -| arguments | chaîne | Paramètres de la commande (inclut la valeur de _channel_). -| text | chaîne | Texte (par exemple message utilisateur). -| pos_command | chaîne | L'index de _command_ dans le message ("-1" si _command_ n'a pas été trouvé). -| pos_arguments | chaîne | L'index de _arguments_ dans le message ("-1" si _arguments_ n'a pas été trouvé). -| pos_channel | chaîne | L'index de _channel_ dans le message ("-1" si _channel_ n'a pas été trouvé). -| pos_text | chaîne | L'index de _text_ dans le message ("-1" si _text_ n'a pas été trouvé). +| Variable | Type | Description +| irc_server | pointeur | Pointeur vers le serveur IRC (les variables dans le hdata de type "irc_server" peuvent être utilisées, comme `${irc_server.name}`). +| irc_channel | pointeur | Pointeur vers le canal IRC (les variables dans le hdata de type "irc_channel" peuvent être utilisées, comme `${irc_channel.name}`). +| server | chaîne | Nom du serveur (exemple : "freenode"). +| tags | chaîne | Étiquettes dans le message (rarement utilisées). +| message_without_tags | chaîne | Message sans les étiquettes. +| nick | chaîne | Pseudo. +| host | chaîne | Nom d'hôte. +| command | chaîne | Commande IRC (exemple : "PRIVMSG", "NOTICE", ...). +| channel | chaîne | Canal IRC. +| arguments | chaîne | Paramètres de la commande (inclut la valeur de _channel_). +| text | chaîne | Texte (par exemple message utilisateur). +| pos_command | chaîne | L'index de _command_ dans le message ("-1" si _command_ n'a pas été trouvé). +| pos_arguments | chaîne | L'index de _arguments_ dans le message ("-1" si _arguments_ n'a pas été trouvé). +| pos_channel | chaîne | L'index de _channel_ dans le message ("-1" si _channel_ n'a pas été trouvé). +| pos_text | chaîne | L'index de _text_ dans le message ("-1" si _text_ n'a pas été trouvé). |=== Lorsque la donnée est un pointeur, la variable `tg_signal_data` peut être diff --git a/doc/it/weechat_user.it.adoc b/doc/it/weechat_user.it.adoc index 1858dd705..710df2de7 100644 --- a/doc/it/weechat_user.it.adoc +++ b/doc/it/weechat_user.it.adoc @@ -3692,24 +3692,22 @@ is added in hashtable: [width="100%",cols="3m,2,14",options="header"] |=== -| Variable | Type | Description -| server | string | Name of server (example: "freenode"). -| tags | string | Tags in message (rarely used). -| message_without_tags | string | Message without tags. -| nick | string | Nick. -| host | string | Hostname. -| command | string | IRC command (example: "PRIVMSG", "NOTICE", ...). -| channel | string | IRC channel. -| arguments | string | Arguments of command (includes value of _channel_). -| text | string | Text (for example user message). -// TRANSLATION MISSING -| pos_command | string | The index of _command_ in message ("-1" if _command_ was not found). -// TRANSLATION MISSING -| pos_arguments | string | The index of _arguments_ in message ("-1" if _arguments_ was not found). -// TRANSLATION MISSING -| pos_channel | string | The index of _channel_ in message ("-1" if _channel_ was not found). -// TRANSLATION MISSING -| pos_text | string | The index of _text_ in message ("-1" if _text_ was not found). +| Variable | Type | Description +| irc_server | pointer | Pointer to IRC server (variables in hdata of type "irc_server" can be used, like `${irc_server.name}`). +| irc_channel | pointer | Pointer to IRC channel (variables in hdata of type "irc_channel" can be used, like `${irc_channel.name}`). +| server | string | Name of server (example: "freenode"). +| tags | string | Tags in message (rarely used). +| message_without_tags | string | Message without tags. +| nick | string | Nick. +| host | string | Hostname. +| command | string | IRC command (example: "PRIVMSG", "NOTICE", ...). +| channel | string | IRC channel. +| arguments | string | Arguments of command (includes value of _channel_). +| text | string | Text (for example user message). +| pos_command | string | The index of _command_ in message ("-1" if _command_ was not found). +| pos_arguments | string | The index of _arguments_ in message ("-1" if _arguments_ was not found). +| pos_channel | string | The index of _channel_ in message ("-1" if _channel_ was not found). +| pos_text | string | The index of _text_ in message ("-1" if _text_ was not found). |=== When the data is a pointer, the variable `tg_signal_data` can be used like this diff --git a/doc/ja/weechat_user.ja.adoc b/doc/ja/weechat_user.ja.adoc index aa3c2ccfd..7bb6acb69 100644 --- a/doc/ja/weechat_user.ja.adoc +++ b/doc/ja/weechat_user.ja.adoc @@ -3482,20 +3482,24 @@ _var_ [width="100%",cols="3m,2,14",options="header"] |=== -| 変数 | 型 | 説明 -| server | string | サーバの名前 (例: "freenode") -| tags | string | メッセージ内のタグ (使われることはまれです) -| message_without_tags | string | タグを含まないメッセージ -| nick | string | ニックネーム -| host | string | ホスト名 -| command | string | IRC コマンド (例: "PRIVMSG"、"NOTICE"、...) -| channel | string | IRC チャンネル -| arguments | string | コマンドの引数 (_channel_ の値を含みます) -| text | string | テキスト (例えばユーザメッセージ) -| pos_command | string | メッセージ内における _command_ のインデックス (_command_ が見つからない場合 "-1") -| pos_arguments | string | メッセージ内における _arguments_ のインデックス (_arguments_ が見つからない場合 "-1") -| pos_channel | string | メッセージ内における _channel_ のインデックス (_channel_ が見つからない場合 "-1") -| pos_text | string | メッセージ内における _text_ のインデックス (_text_ が見つからない場合 "-1") +| 変数 | 型 | 説明 +// TRANSLATION MISSING +| irc_server | pointer | Pointer to IRC server (variables in hdata of type "irc_server" can be used, like `${irc_server.name}`). +// TRANSLATION MISSING +| irc_channel | pointer | Pointer to IRC channel (variables in hdata of type "irc_channel" can be used, like `${irc_channel.name}`). +| server | string | サーバの名前 (例: "freenode") +| tags | string | メッセージ内のタグ (使われることはまれです) +| message_without_tags | string | タグを含まないメッセージ +| nick | string | ニックネーム +| host | string | ホスト名 +| command | string | IRC コマンド (例: "PRIVMSG"、"NOTICE"、...) +| channel | string | IRC チャンネル +| arguments | string | コマンドの引数 (_channel_ の値を含みます) +| text | string | テキスト (例えばユーザメッセージ) +| pos_command | string | メッセージ内における _command_ のインデックス (_command_ が見つからない場合 "-1") +| pos_arguments | string | メッセージ内における _arguments_ のインデックス (_arguments_ が見つからない場合 "-1") +| pos_channel | string | メッセージ内における _channel_ のインデックス (_channel_ が見つからない場合 "-1") +| pos_text | string | メッセージ内における _text_ のインデックス (_text_ が見つからない場合 "-1") |=== データがポインタの場合、hdata の属性を読むために変数 `tg_signal_data` diff --git a/doc/pl/weechat_user.pl.adoc b/doc/pl/weechat_user.pl.adoc index ac5cdd127..0842b225a 100644 --- a/doc/pl/weechat_user.pl.adoc +++ b/doc/pl/weechat_user.pl.adoc @@ -3526,20 +3526,24 @@ są dodawane do tablicy hashy: [width="100%",cols="3m,2,14",options="header"] |=== -| Zmienna | Typ | Opis -| server | ciąg | Nazwa serwera (przykład: "freenode"). -| tags | ciąg | Tagi w wiadomości (rzadko używane). -| message_without_tags | ciąg | Wiadomość bez tagów. -| nick | ciąg | Nick. -| host | ciąg | Nazwa hosta. -| command | ciąg | Komendy IRC (na przykład: "PRIVMSG", "NOTICE", ...). -| channel | ciąg | Kanał IRC. -| arguments | ciąg | Argumenty komendy (razem z wartością _channel_). -| text | ciąg | Tekst (na przykład wiadomość użytkownika). -| pos_command | ciąg | Indeks _command_ w wiadomości ("-1" jeśli _command_ nie zostanie znalezione). -| pos_arguments | ciąg | Indeks _arguments_ w wiadomości ("-1" jeśli _arguments_ nie zostaną znalezione). -| pos_channel | ciąg | Indeks _channel_ w wiadomości ("-1" jeśli _channel_ nie został znaleziony). -| pos_text | ciąg | Indeks _text_ w wiadomości ("-1" jeśli _text_ nie został znaleziony). +| Zmienna | Typ | Opis +// TRANSLATION MISSING +| irc_server | pointer | Pointer to IRC server (variables in hdata of type "irc_server" can be used, like `${irc_server.name}`). +// TRANSLATION MISSING +| irc_channel | pointer | Pointer to IRC channel (variables in hdata of type "irc_channel" can be used, like `${irc_channel.name}`). +| server | ciąg | Nazwa serwera (przykład: "freenode"). +| tags | ciąg | Tagi w wiadomości (rzadko używane). +| message_without_tags | ciąg | Wiadomość bez tagów. +| nick | ciąg | Nick. +| host | ciąg | Nazwa hosta. +| command | ciąg | Komendy IRC (na przykład: "PRIVMSG", "NOTICE", ...). +| channel | ciąg | Kanał IRC. +| arguments | ciąg | Argumenty komendy (razem z wartością _channel_). +| text | ciąg | Tekst (na przykład wiadomość użytkownika). +| pos_command | ciąg | Indeks _command_ w wiadomości ("-1" jeśli _command_ nie zostanie znalezione). +| pos_arguments | ciąg | Indeks _arguments_ w wiadomości ("-1" jeśli _arguments_ nie zostaną znalezione). +| pos_channel | ciąg | Indeks _channel_ w wiadomości ("-1" jeśli _channel_ nie został znaleziony). +| pos_text | ciąg | Indeks _text_ w wiadomości ("-1" jeśli _text_ nie został znaleziony). |=== Kiedy dane są wskaźnikiem, zmienna `tg_signal_data` może zostać użyta do diff --git a/src/plugins/trigger/trigger-callback.c b/src/plugins/trigger/trigger-callback.c index c48a8d3fe..106888832 100644 --- a/src/plugins/trigger/trigger-callback.c +++ b/src/plugins/trigger/trigger-callback.c @@ -47,7 +47,7 @@ struct t_hashtable *trigger_callback_hashtable_options_regex = NULL; struct t_hashtable * trigger_callback_irc_message_parse (const char *irc_message, - const char *irc_server) + const char *irc_server_name) { struct t_hashtable *hashtable_in, *hashtable_out; @@ -60,7 +60,7 @@ trigger_callback_irc_message_parse (const char *irc_message, if (hashtable_in) { weechat_hashtable_set (hashtable_in, "message", irc_message); - weechat_hashtable_set (hashtable_in, "server", irc_server); + weechat_hashtable_set (hashtable_in, "server", irc_server_name); hashtable_out = weechat_info_get_hashtable ("irc_message_parse", hashtable_in); weechat_hashtable_free (hashtable_in); @@ -68,6 +68,63 @@ trigger_callback_irc_message_parse (const char *irc_message, return hashtable_out; } + +/* + * Gets the pointer to IRC server with its name. + * + * Returns pointer to IRC server, or NULL if not found. + */ + +void +trigger_callback_get_irc_server_channel (const char *irc_server_name, + const char *irc_channel_name, + void **irc_server, void **irc_channel) +{ + struct t_hdata *hdata_irc_server, *hdata_irc_channel; + const char *ptr_name; + + *irc_server = NULL; + *irc_channel = NULL; + + if (!irc_server_name) + return; + + hdata_irc_server = weechat_hdata_get ("irc_server"); + if (!hdata_irc_server) + return; + + /* search the server by name in list of servers */ + *irc_server = weechat_hdata_get_list (hdata_irc_server, "irc_servers"); + while (*irc_server) + { + ptr_name = weechat_hdata_string (hdata_irc_server, *irc_server, "name"); + if (strcmp (ptr_name, irc_server_name) == 0) + break; + *irc_server = weechat_hdata_move (hdata_irc_server, *irc_server, 1); + } + if (!*irc_server) + return; + + if (!irc_channel_name) + return; + + hdata_irc_channel = weechat_hdata_get ("irc_channel"); + if (!hdata_irc_channel) + return; + + /* search the channel by name in list of channels on the server */ + *irc_channel = weechat_hdata_pointer (hdata_irc_server, + *irc_server, "channels"); + while (*irc_channel) + { + ptr_name = weechat_hdata_string (hdata_irc_channel, + *irc_channel, "name"); + if (strcmp (ptr_name, irc_channel_name) == 0) + break; + *irc_channel = weechat_hdata_move (hdata_irc_channel, *irc_channel, 1); + } +} + /* * Sets variables in "extra_vars" hashtable using tags from message. * @@ -370,13 +427,16 @@ trigger_callback_signal_cb (const void *pointer, void *data, void *signal_data) { const char *ptr_signal_data; - char str_data[128], *irc_server; + char str_data[128], *irc_server_name; const char *pos, *ptr_irc_message; + void *ptr_irc_server, *ptr_irc_channel; TRIGGER_CALLBACK_CB_INIT(WEECHAT_RC_OK); + TRIGGER_CALLBACK_CB_NEW_POINTERS; + /* split IRC message (if signal_data is an IRC message) */ - irc_server = NULL; + irc_server_name = NULL; ptr_irc_message = NULL; if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) { @@ -390,7 +450,7 @@ trigger_callback_signal_cb (const void *pointer, void *data, pos = strchr (signal, ','); if (pos) { - irc_server = weechat_strndup (signal, pos - signal); + irc_server_name = weechat_strndup (signal, pos - signal); ptr_irc_message = (const char *)signal_data; } } @@ -399,22 +459,31 @@ trigger_callback_signal_cb (const void *pointer, void *data, pos = strstr (signal, ",irc_outtags_"); if (pos) { - irc_server = weechat_strndup (signal, pos - signal); + irc_server_name = weechat_strndup (signal, pos - signal); pos = strchr ((const char *)signal_data, ';'); if (pos) ptr_irc_message = pos + 1; } } } - if (irc_server && ptr_irc_message) + if (irc_server_name && ptr_irc_message) { extra_vars = trigger_callback_irc_message_parse (ptr_irc_message, - irc_server); + irc_server_name); if (extra_vars) - weechat_hashtable_set (extra_vars, "server", irc_server); + { + weechat_hashtable_set (extra_vars, "server", irc_server_name); + trigger_callback_get_irc_server_channel ( + irc_server_name, + weechat_hashtable_get (extra_vars, "channel"), + &ptr_irc_server, + &ptr_irc_channel); + weechat_hashtable_set (pointers, "irc_server", ptr_irc_server); + weechat_hashtable_set (pointers, "irc_channel", ptr_irc_channel); + } } - if (irc_server) - free (irc_server); + if (irc_server_name) + free (irc_server_name); /* create hashtable (if not already created) */ if (!extra_vars) @@ -520,9 +589,12 @@ trigger_callback_modifier_cb (const void *pointer, void *data, char *string_modified, *pos, *pos2, *plugin_name, *buffer_name; char *buffer_full_name, *str_tags, **tags, *prefix, *string_no_color; int length, num_tags; + void *ptr_irc_server, *ptr_irc_channel; TRIGGER_CALLBACK_CB_INIT(NULL); + TRIGGER_CALLBACK_CB_NEW_POINTERS; + buffer = NULL; tags = NULL; num_tags = 0; @@ -537,10 +609,18 @@ trigger_callback_modifier_cb (const void *pointer, void *data, extra_vars = trigger_callback_irc_message_parse (string, modifier_data); if (extra_vars) + { weechat_hashtable_set (extra_vars, "server", modifier_data); + trigger_callback_get_irc_server_channel ( + modifier_data, + weechat_hashtable_get (extra_vars, "channel"), + &ptr_irc_server, + &ptr_irc_channel); + weechat_hashtable_set (pointers, "irc_server", ptr_irc_server); + weechat_hashtable_set (pointers, "irc_channel", ptr_irc_channel); + } } - TRIGGER_CALLBACK_CB_NEW_POINTERS; if (!extra_vars) { TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS; |