diff options
Diffstat (limited to 'src/plugins/irc')
-rw-r--r-- | src/plugins/irc/irc-command.c | 31 | ||||
-rw-r--r-- | src/plugins/irc/irc-completion.c | 59 | ||||
-rw-r--r-- | src/plugins/irc/irc-input.c | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-raw.c | 526 | ||||
-rw-r--r-- | src/plugins/irc/irc-raw.h | 14 | ||||
-rw-r--r-- | src/plugins/irc/irc-upgrade.c | 18 | ||||
-rw-r--r-- | src/plugins/irc/irc.c | 4 |
7 files changed, 508 insertions, 146 deletions
diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index ae950cf31..027cf9873 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -5143,7 +5143,7 @@ irc_command_display_server (struct t_irc_server *server, int with_detail) IRC_COMMAND_CALLBACK(server) { - int i, detailed_list, one_server_found, length, count; + int i, detailed_list, one_server_found, length, count, refresh; struct t_irc_server *ptr_server2, *server_found, *new_server; char *server_name, *message; @@ -5520,7 +5520,12 @@ IRC_COMMAND_CALLBACK(server) if (weechat_strcasecmp (argv[1], "raw") == 0) { + refresh = irc_raw_buffer && (argc > 2); + if (argc > 2) + irc_raw_set_filter (argv_eol[2]); irc_raw_open (1); + if (refresh) + irc_raw_refresh (1); return WEECHAT_RC_OK; } @@ -6974,7 +6979,8 @@ irc_command_init () " || reorder <name> [<name>...]" " || open <name>|-all [<name>...]" " || del|keep <name>" - " || deloutq|jump|raw"), + " || deloutq|jump" + " || raw [<filter>]"), N_(" list: list servers (without argument, this list is displayed)\n" "listfull: list servers with detailed info for each server\n" " add: add a new server\n" @@ -6997,6 +7003,22 @@ irc_command_init () "WeeChat is currently sending)\n" " jump: jump to server buffer\n" " raw: open buffer with raw IRC data\n" + " filter: set a new filter to see only matching messages (this " + "filter can be used as input in raw IRC data buffer as well); " + "allowed formats are:\n" + " * show all messages (no filter)\n" + " xxx show only messages containing \"xxx\"\n" + " s:xxx show only messages for server \"xxx\"\n" + " f:xxx show only messages with a flag: recv (message " + "received), sent (message sent), modified (message modified by " + "a modifier), redirected (message redirected)\n" + " m:xxx show only IRC command \"xxx\"\n" + " c:xxx show only options matching the evaluated " + "condition \"xxx\", using following variables: output of function " + "irc_message_parse (like nick, command, channel, text, etc., see " + "function info_get_hashtable in plugin API reference for the list " + "of all variables), date (format: \"yyyy-mm-dd hh:mm:ss\"), server, " + "recv, sent, modified, redirected\n" "\n" "Examples:\n" " /server listfull\n" @@ -7004,6 +7026,9 @@ irc_command_init () " /server add freenode chat.freenode.net/6697 -ssl -autoconnect\n" " /server add chatspike irc.chatspike.net/6667," "irc.duckspike.net/6667\n" + " /server raw\n" + " /server raw s:freenode\n" + " /server raw c:${recv} && ${command}==PRIVMSG && ${nick}==foo\n" " /server copy freenode freenode-test\n" " /server rename freenode-test freenode2\n" " /server reorder freenode2 freenode\n" @@ -7020,7 +7045,7 @@ irc_command_init () " || del %(irc_servers)" " || deloutq" " || jump" - " || raw", + " || raw %(irc_raw_filters)", &irc_command_server, NULL, NULL); weechat_hook_command ( "servlist", diff --git a/src/plugins/irc/irc-completion.c b/src/plugins/irc/irc-completion.c index e617bbf53..e72152cdb 100644 --- a/src/plugins/irc/irc-completion.c +++ b/src/plugins/irc/irc-completion.c @@ -812,6 +812,62 @@ irc_completion_notify_nicks_cb (const void *pointer, void *data, } /* + * Adds filters for raw buffer to completion list. + */ + +int +irc_completion_raw_filters_cb (const void *pointer, void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + char str_filter[1024]; + + IRC_BUFFER_GET_SERVER(buffer); + + /* make C compiler happy */ + (void) pointer; + (void) data; + (void) completion_item; + + /* all messages */ + weechat_hook_completion_list_add (completion, "*", + 0, WEECHAT_LIST_POS_SORT); + + /* condition */ + weechat_hook_completion_list_add (completion, + "c:${recv} && ${command}==PRIVMSG", + 0, WEECHAT_LIST_POS_SORT); + + /* message flag */ + weechat_hook_completion_list_add (completion, "f:modified", + 0, WEECHAT_LIST_POS_SORT); + weechat_hook_completion_list_add (completion, "f:recv", + 0, WEECHAT_LIST_POS_SORT); + weechat_hook_completion_list_add (completion, "f:redirected", + 0, WEECHAT_LIST_POS_SORT); + weechat_hook_completion_list_add (completion, "f:sent", + 0, WEECHAT_LIST_POS_SORT); + + /* IRC command */ + weechat_hook_completion_list_add (completion, "m:notice", + 0, WEECHAT_LIST_POS_SORT); + weechat_hook_completion_list_add (completion, "m:privmsg", + 0, WEECHAT_LIST_POS_SORT); + + /* server */ + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + snprintf (str_filter, sizeof (str_filter), "s:%s", ptr_server->name); + weechat_hook_completion_list_add (completion, str_filter, + 0, WEECHAT_LIST_POS_SORT); + } + + return WEECHAT_RC_OK; +} + +/* * Hooks completions. */ @@ -874,4 +930,7 @@ irc_completion_init () weechat_hook_completion ("irc_notify_nicks", N_("nicks in notify list"), &irc_completion_notify_nicks_cb, NULL, NULL); + weechat_hook_completion ("irc_raw_filters", + N_("filters for irc raw buffer"), + &irc_completion_raw_filters_cb, NULL, NULL); } diff --git a/src/plugins/irc/irc-input.c b/src/plugins/irc/irc-input.c index 53dedba4a..96da22bf5 100644 --- a/src/plugins/irc/irc-input.c +++ b/src/plugins/irc/irc-input.c @@ -204,6 +204,8 @@ irc_input_data (struct t_gui_buffer *buffer, const char *input_data, int flags, { if (weechat_strcasecmp (input_data, "q") == 0) weechat_buffer_close (buffer); + else + irc_raw_filter_options (input_data); } else { diff --git a/src/plugins/irc/irc-raw.c b/src/plugins/irc/irc-raw.c index 8422e4cfb..8ff7343cc 100644 --- a/src/plugins/irc/irc-raw.c +++ b/src/plugins/irc/irc-raw.c @@ -29,6 +29,7 @@ #include "irc-raw.h" #include "irc-buffer.h" #include "irc-config.h" +#include "irc-message.h" #include "irc-input.h" #include "irc-server.h" @@ -39,6 +40,142 @@ int irc_raw_messages_count = 0; struct t_irc_raw_message *irc_raw_messages = NULL; struct t_irc_raw_message *last_irc_raw_message = NULL; +char *irc_raw_filter = NULL; +struct t_hashtable *irc_raw_filter_hashtable_options = NULL; + + +/* + * Checks if a string matches a mask. + * + * If mask has no "*" inside, it just checks if "mask" is inside the "string". + * If mask has at least one "*" inside, the function weechat_string_match is + * used. + * + * Returns: + * 1: string matches mask + * 0: string does not match mask + */ + +int +irc_raw_message_string_match (const char *string, const char *mask) +{ + if (strchr (mask, '*')) + return weechat_string_match (string, mask, 0); + else + return (weechat_strcasestr (string, mask)) ? 1 : 0; +} + +/* + * Checks if a messages is matching current filter(s). + * + * Returns: + * 1: message is matching filter(s) + * 0: message does not match filter(s) + */ + +int +irc_raw_message_match_filter (struct t_irc_raw_message *raw_message, + const char *filter) +{ + int match; + char *command, *result, str_date[128]; + struct t_hashtable *hashtable; + struct tm *date_tmp; + + if (!filter || !filter[0]) + return 1; + + if (strncmp (filter, "c:", 2) == 0) + { + /* filter by evaluated condition */ + hashtable = irc_message_parse_to_hashtable (raw_message->server, + raw_message->message); + if (hashtable) + { + date_tmp = localtime (&(raw_message->date)); + if (strftime (str_date, sizeof (str_date), + "%Y-%m-%d %H:%M:%S", date_tmp) == 0) + { + str_date[0] = '\0'; + } + weechat_hashtable_set (hashtable, "date", str_date); + weechat_hashtable_set (hashtable, + "server", raw_message->server->name); + weechat_hashtable_set ( + hashtable, + "recv", + (raw_message->flags & IRC_RAW_FLAG_RECV) ? "1" : "0"); + weechat_hashtable_set ( + hashtable, + "sent", + (raw_message->flags & IRC_RAW_FLAG_SEND) ? "1" : "0"); + weechat_hashtable_set ( + hashtable, + "modified", + (raw_message->flags & IRC_RAW_FLAG_MODIFIED) ? "1" : "0"); + weechat_hashtable_set ( + hashtable, + "redirected", + (raw_message->flags & IRC_RAW_FLAG_REDIRECT) ? "1" : "0"); + } + result = weechat_string_eval_expression ( + filter + 2, + NULL, + hashtable, + irc_raw_filter_hashtable_options); + match = (result && (strcmp (result, "1") == 0)) ? 1 : 0; + if (hashtable) + weechat_hashtable_free (hashtable); + if (result) + free (result); + return match; + } + else if (strncmp (filter, "s:", 2) == 0) + { + /* filter by server name */ + return (weechat_strcasecmp (raw_message->server->name, + filter + 2) == 0) ? 1 : 0; + } + else if (strncmp (filter, "f:", 2) == 0) + { + /* filter by message flag */ + if (weechat_strcasecmp (filter + 2, "recv") == 0) + { + return (raw_message->flags & IRC_RAW_FLAG_RECV) ? 1 : 0; + } + else if (weechat_strcasecmp (filter + 2, "sent") == 0) + { + return (raw_message->flags & IRC_RAW_FLAG_SEND) ? 1 : 0; + } + else if (weechat_strcasecmp (filter + 2, "modified") == 0) + { + return (raw_message->flags & IRC_RAW_FLAG_MODIFIED) ? 1 : 0; + } + else if (weechat_strcasecmp (filter + 2, "redirected") == 0) + { + return (raw_message->flags & IRC_RAW_FLAG_REDIRECT) ? 1 : 0; + } + return 0; + } + else if (strncmp (filter, "m:", 2) == 0) + { + /* filter by IRC command */ + irc_message_parse (raw_message->server, raw_message->message, + NULL, NULL, NULL, NULL, NULL, &command, NULL, + NULL, NULL, NULL, NULL, NULL, NULL); + match = (command && (weechat_strcasecmp (command, filter + 2) == 0)) ? + 1 : 0; + if (command) + free (command); + return match; + } + else + { + /* filter by text in message */ + return (irc_raw_message_string_match (raw_message->message, + filter)) ? 1 : 0; + } +} /* * Prints an irc raw message. @@ -47,26 +184,184 @@ struct t_irc_raw_message *last_irc_raw_message = NULL; void irc_raw_message_print (struct t_irc_raw_message *raw_message) { - if (irc_raw_buffer && raw_message) + char *buf, *buf2, prefix[512], prefix_arrow[16]; + const unsigned char *ptr_buf; + const char *hexa = "0123456789ABCDEF"; + int pos_buf, pos_buf2, char_size, i; + + if (!irc_raw_buffer || !raw_message) + return; + + if (!irc_raw_message_match_filter (raw_message, irc_raw_filter)) + return; + + buf = NULL; + buf2 = NULL; + + if (raw_message->flags & IRC_RAW_FLAG_BINARY) + { + buf = weechat_string_hex_dump ( + raw_message->message, + strlen (raw_message->message), + 16, + " > ", + NULL); + snprintf (prefix, sizeof (prefix), " "); + } + else { - weechat_printf_date_tags (irc_raw_buffer, - raw_message->date, NULL, - "%s\t%s", - raw_message->prefix, - raw_message->message); + buf = weechat_iconv_to_internal (NULL, raw_message->message); + buf2 = malloc ((strlen (buf) * 4) + 1); + if (buf2) + { + ptr_buf = (buf) ? + (unsigned char *)buf : (unsigned char *)(raw_message->message); + pos_buf = 0; + pos_buf2 = 0; + while (ptr_buf[pos_buf]) + { + if ((ptr_buf[pos_buf] < 32) + || !weechat_utf8_is_valid ((const char *)(ptr_buf + pos_buf), + 1, NULL)) + { + buf2[pos_buf2++] = '\\'; + buf2[pos_buf2++] = 'x'; + buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] / 16]; + buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] % 16]; + pos_buf++; + } + else + { + char_size = weechat_utf8_char_size ((const char *)(ptr_buf + pos_buf)); + for (i = 0; i < char_size; i++) + { + buf2[pos_buf2++] = ptr_buf[pos_buf++]; + } + } + } + buf2[pos_buf2] = '\0'; + } + + /* build prefix with arrow */ + prefix_arrow[0] = '\0'; + switch (raw_message->flags & (IRC_RAW_FLAG_RECV + | IRC_RAW_FLAG_SEND + | IRC_RAW_FLAG_MODIFIED + | IRC_RAW_FLAG_REDIRECT)) + { + case IRC_RAW_FLAG_RECV: + strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV); + break; + case IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_MODIFIED: + strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV_MODIFIED); + break; + case IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_REDIRECT: + strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV_REDIRECT); + break; + case IRC_RAW_FLAG_SEND: + strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND); + break; + case IRC_RAW_FLAG_SEND | IRC_RAW_FLAG_MODIFIED: + strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND_MODIFIED); + break; + default: + if (raw_message->flags & IRC_RAW_FLAG_RECV) + strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV); + else + strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND); + break; + } + + snprintf (prefix, sizeof (prefix), "%s%s%s%s%s", + (raw_message->flags & IRC_RAW_FLAG_SEND) ? + weechat_color ("chat_prefix_quit") : + weechat_color ("chat_prefix_join"), + prefix_arrow, + (raw_message->server) ? weechat_color ("chat_server") : "", + (raw_message->server) ? " " : "", + (raw_message->server) ? (raw_message->server)->name : ""); } + + weechat_printf_date_tags ( + irc_raw_buffer, + raw_message->date, NULL, + "%s\t%s", + prefix, + (buf2) ? buf2 : ((buf) ? buf : raw_message->message)); + + if (buf) + free (buf); + if (buf2) + free (buf2); } /* - * Opens IRC raw buffer. + * Sets the local variable "filter" in the irc raw buffer. */ void -irc_raw_open (int switch_to_buffer) +irc_raw_set_localvar_filter () +{ + if (!irc_raw_buffer) + return; + + weechat_buffer_set (irc_raw_buffer, "localvar_set_filter", + (irc_raw_filter) ? irc_raw_filter : "*"); +} + +/* + * Sets title of irc raw buffer. + */ + +void +irc_raw_set_title () +{ + char str_title[1024]; + + if (!irc_raw_buffer) + return; + + snprintf (str_title, sizeof (str_title), + _("IRC raw messages | Filter: %s"), + (irc_raw_filter) ? irc_raw_filter : "*"); + + weechat_buffer_set (irc_raw_buffer, "title", str_title); +} + +/* + * Updates list of messages in raw buffer. + */ + +void +irc_raw_refresh (int clear) { struct t_irc_raw_message *ptr_raw_message; if (!irc_raw_buffer) + return; + + if (clear) + weechat_buffer_clear (irc_raw_buffer); + + /* print messages in list */ + for (ptr_raw_message = irc_raw_messages; ptr_raw_message; + ptr_raw_message = ptr_raw_message->next_message) + { + irc_raw_message_print (ptr_raw_message); + } + + irc_raw_set_title (); +} + + +/* + * Opens IRC raw buffer. + */ + +void +irc_raw_open (int switch_to_buffer) +{ + if (!irc_raw_buffer) { irc_raw_buffer = weechat_buffer_search (IRC_PLUGIN_NAME, IRC_RAW_BUFFER_NAME); @@ -81,9 +376,6 @@ irc_raw_open (int switch_to_buffer) if (!irc_raw_buffer) return; - weechat_buffer_set (irc_raw_buffer, - "title", _("IRC raw messages")); - if (!weechat_buffer_get_integer (irc_raw_buffer, "short_name_is_set")) { weechat_buffer_set (irc_raw_buffer, "short_name", @@ -97,12 +389,9 @@ irc_raw_open (int switch_to_buffer) /* disable all highlights on this buffer */ weechat_buffer_set (irc_raw_buffer, "highlight_words", "-"); - /* print messages in list */ - for (ptr_raw_message = irc_raw_messages; ptr_raw_message; - ptr_raw_message = ptr_raw_message->next_message) - { - irc_raw_message_print (ptr_raw_message); - } + irc_raw_set_localvar_filter (); + + irc_raw_refresh (0); } } @@ -111,6 +400,32 @@ irc_raw_open (int switch_to_buffer) } /* + * Sets the raw messages filter. + */ + +void +irc_raw_set_filter (const char *filter) +{ + if (irc_raw_filter) + free (irc_raw_filter); + irc_raw_filter = (filter && (strcmp (filter, "*") != 0)) ? + strdup (filter) : NULL; +} + +/* + * Filters raw messages. + */ + +void +irc_raw_filter_options (const char *filter) +{ + irc_raw_set_filter (filter); + irc_raw_set_localvar_filter (); + irc_raw_refresh (1); +} + + +/* * Frees a raw message and removes it from list. */ @@ -137,8 +452,6 @@ irc_raw_message_free (struct t_irc_raw_message *raw_message) (raw_message->next_message)->prev_message = raw_message->prev_message; /* free data */ - if (raw_message->prefix) - free (raw_message->prefix); if (raw_message->message) free (raw_message->message); @@ -185,12 +498,12 @@ irc_raw_message_remove_old () */ struct t_irc_raw_message * -irc_raw_message_add_to_list (time_t date, const char *prefix, - const char *message) +irc_raw_message_add_to_list (time_t date, struct t_irc_server *server, + int flags, const char *message) { struct t_irc_raw_message *new_raw_message; - if (!prefix || !message) + if (!message) return NULL; irc_raw_message_remove_old (); @@ -199,7 +512,8 @@ irc_raw_message_add_to_list (time_t date, const char *prefix, if (new_raw_message) { new_raw_message->date = date; - new_raw_message->prefix = strdup (prefix); + new_raw_message->server = server; + new_raw_message->flags = flags; new_raw_message->message = strdup (message); /* add message to list */ @@ -218,114 +532,6 @@ irc_raw_message_add_to_list (time_t date, const char *prefix, } /* - * Adds a new raw message to list. - * - * Returns pointer to new raw message, NULL if error. - */ - -struct t_irc_raw_message * -irc_raw_message_add (struct t_irc_server *server, int flags, - const char *message) -{ - char *buf, *buf2, prefix[256], prefix_arrow[16]; - const unsigned char *ptr_buf; - const char *hexa = "0123456789ABCDEF"; - int pos_buf, pos_buf2, char_size, i; - struct t_irc_raw_message *new_raw_message; - - buf = NULL; - buf2 = NULL; - - if (flags & IRC_RAW_FLAG_BINARY) - { - buf = weechat_string_hex_dump (message, strlen (message), 16, - " > ", NULL); - snprintf (prefix, sizeof (prefix), " "); - } - else - { - buf = weechat_iconv_to_internal (NULL, message); - buf2 = malloc ((strlen (buf) * 4) + 1); - if (buf2) - { - ptr_buf = (buf) ? (unsigned char *)buf : (unsigned char *)message; - pos_buf = 0; - pos_buf2 = 0; - while (ptr_buf[pos_buf]) - { - if ((ptr_buf[pos_buf] < 32) - || !weechat_utf8_is_valid ((const char *)(ptr_buf + pos_buf), - 1, NULL)) - { - buf2[pos_buf2++] = '\\'; - buf2[pos_buf2++] = 'x'; - buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] / 16]; - buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] % 16]; - pos_buf++; - } - else - { - char_size = weechat_utf8_char_size ((const char *)(ptr_buf + pos_buf)); - for (i = 0; i < char_size; i++) - { - buf2[pos_buf2++] = ptr_buf[pos_buf++]; - } - } - } - buf2[pos_buf2] = '\0'; - } - - /* build prefix with arrow */ - prefix_arrow[0] = '\0'; - switch (flags & (IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_SEND - | IRC_RAW_FLAG_MODIFIED | IRC_RAW_FLAG_REDIRECT)) - { - case IRC_RAW_FLAG_RECV: - strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV); - break; - case IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_MODIFIED: - strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV_MODIFIED); - break; - case IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_REDIRECT: - strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV_REDIRECT); - break; - case IRC_RAW_FLAG_SEND: - strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND); - break; - case IRC_RAW_FLAG_SEND | IRC_RAW_FLAG_MODIFIED: - strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND_MODIFIED); - break; - default: - if (flags & IRC_RAW_FLAG_RECV) - strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV); - else - strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND); - break; - } - - snprintf (prefix, sizeof (prefix), "%s%s%s%s%s", - (flags & IRC_RAW_FLAG_SEND) ? - weechat_color ("chat_prefix_quit") : - weechat_color ("chat_prefix_join"), - prefix_arrow, - (server) ? weechat_color ("chat_server") : "", - (server) ? " " : "", - (server) ? server->name : ""); - } - - new_raw_message = irc_raw_message_add_to_list (time (NULL), - prefix, - (buf2) ? buf2 : ((buf) ? buf : message)); - - if (buf) - free (buf); - if (buf2) - free (buf2); - - return new_raw_message; -} - -/* * Prints a message on IRC raw buffer. */ @@ -334,6 +540,7 @@ irc_raw_print (struct t_irc_server *server, int flags, const char *message) { struct t_irc_raw_message *new_raw_message; + time_t now; if (!message) return; @@ -342,7 +549,10 @@ irc_raw_print (struct t_irc_server *server, int flags, if (!irc_raw_buffer && (weechat_irc_plugin->debug >= 1)) irc_raw_open (0); - new_raw_message = irc_raw_message_add (server, flags, message); + now = time (NULL); + + new_raw_message = irc_raw_message_add_to_list (now, server, flags, + message); if (new_raw_message) { if (irc_raw_buffer) @@ -353,9 +563,11 @@ irc_raw_print (struct t_irc_server *server, int flags, if (weechat_irc_plugin->debug >= 2) { - new_raw_message = irc_raw_message_add (server, - flags | IRC_RAW_FLAG_BINARY, - message); + new_raw_message = irc_raw_message_add_to_list ( + now, + server, + flags | IRC_RAW_FLAG_BINARY, + message); if (new_raw_message) { if (irc_raw_buffer) @@ -389,10 +601,52 @@ irc_raw_add_to_infolist (struct t_infolist *infolist, if (!weechat_infolist_new_var_time (ptr_item, "date", raw_message->date)) return 0; - if (!weechat_infolist_new_var_string (ptr_item, "prefix", raw_message->prefix)) + if (!weechat_infolist_new_var_string (ptr_item, "server", raw_message->server->name)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "flags", raw_message->flags)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "message", raw_message->message)) return 0; return 1; } + +/* + * Initializes irc raw. + */ + +void +irc_raw_init () +{ + irc_raw_filter_hashtable_options = weechat_hashtable_new ( + 8, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, NULL); + if (irc_raw_filter_hashtable_options) + { + weechat_hashtable_set (irc_raw_filter_hashtable_options, + "type", "condition"); + } +} + +/* + * Ends irc raw. + */ + +void +irc_raw_end () +{ + irc_raw_message_free_all (); + + if (irc_raw_filter) + { + free (irc_raw_filter); + irc_raw_filter = NULL; + } + if (irc_raw_filter_hashtable_options) + { + weechat_hashtable_free (irc_raw_filter_hashtable_options); + irc_raw_filter_hashtable_options = NULL; + } +} diff --git a/src/plugins/irc/irc-raw.h b/src/plugins/irc/irc-raw.h index db431ce6a..7a35c256b 100644 --- a/src/plugins/irc/irc-raw.h +++ b/src/plugins/irc/irc-raw.h @@ -36,10 +36,13 @@ #define IRC_RAW_FLAG_REDIRECT (1 << 3) #define IRC_RAW_FLAG_BINARY (1 << 4) +struct t_irc_server; + struct t_irc_raw_message { time_t date; /* date/time of message */ - char *prefix; /* prefix */ + struct t_irc_server *server; /* server */ + int flags; /* flags */ char *message; /* message */ struct t_irc_raw_message *prev_message; /* pointer to previous message */ struct t_irc_raw_message *next_message; /* pointer to next message */ @@ -51,14 +54,19 @@ extern struct t_gui_buffer *irc_raw_buffer; extern int irc_raw_messages_count; extern struct t_irc_raw_message *irc_raw_messages, *last_irc_raw_message; +extern void irc_raw_refresh (int clear); extern void irc_raw_open (int switch_to_buffer); +extern void irc_raw_set_filter (const char *filter); +extern void irc_raw_filter_options (const char *filter); extern struct t_irc_raw_message *irc_raw_message_add_to_list (time_t date, - const char *prefix, + struct t_irc_server *server, + int flags, const char *message); extern void irc_raw_print (struct t_irc_server *server, int flags, const char *message); -extern void irc_raw_message_free_all (); extern int irc_raw_add_to_infolist (struct t_infolist *infolist, struct t_irc_raw_message *raw_message); +extern void irc_raw_init (); +extern void irc_raw_end (); #endif /* WEECHAT_PLUGIN_IRC_RAW_H */ diff --git a/src/plugins/irc/irc-upgrade.c b/src/plugins/irc/irc-upgrade.c index 6f4f13612..f6a42ba7e 100644 --- a/src/plugins/irc/irc-upgrade.c +++ b/src/plugins/irc/irc-upgrade.c @@ -345,6 +345,7 @@ irc_upgrade_read_cb (const void *pointer, void *data, char *buf, option_name[64], **nicks, *nick_join, *pos, *error; char **items; const char *buffer_name, *str, *nick; + struct t_irc_server *ptr_server; struct t_irc_nick *ptr_nick; struct t_irc_redirect *ptr_redirect; struct t_irc_notify *ptr_notify; @@ -859,9 +860,20 @@ irc_upgrade_read_cb (const void *pointer, void *data, } break; case IRC_UPGRADE_TYPE_RAW_MESSAGE: - irc_raw_message_add_to_list (weechat_infolist_time (infolist, "date"), - weechat_infolist_string (infolist, "prefix"), - weechat_infolist_string (infolist, "message")); + /* "server" and "flags" are new in WeeChat 2.7 */ + str = weechat_infolist_string (infolist, "server"); + if (str && str[0]) + { + ptr_server = irc_server_search (str); + if (ptr_server) + { + irc_raw_message_add_to_list ( + weechat_infolist_time (infolist, "date"), + ptr_server, + weechat_infolist_integer (infolist, "flags"), + weechat_infolist_string (infolist, "message")); + } + } break; } } diff --git a/src/plugins/irc/irc.c b/src/plugins/irc/irc.c index f42eddc2a..e9bd207cc 100644 --- a/src/plugins/irc/irc.c +++ b/src/plugins/irc/irc.c @@ -173,6 +173,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) irc_config_read (); + irc_raw_init (); + irc_command_init (); irc_info_init (); @@ -287,7 +289,7 @@ weechat_plugin_end (struct t_weechat_plugin *plugin) irc_ignore_free_all (); - irc_raw_message_free_all (); + irc_raw_end (); irc_server_free_all (); |