diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2009-04-14 19:16:47 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2009-04-14 19:16:47 +0200 |
commit | 433f5e86fa6900247b7a5667adc42059a3e76545 (patch) | |
tree | 59b9c0a2f935342659451f0f38cbba832ac52a1a | |
parent | 0b6203ac6fdb7d3a5d51c544195231cc25ce1313 (diff) | |
download | weechat-433f5e86fa6900247b7a5667adc42059a3e76545.zip |
Fix bug with upgrade and irc raw buffer, save irc raw messages during upgrade
-rw-r--r-- | src/plugins/irc/irc-raw.c | 157 | ||||
-rw-r--r-- | src/plugins/irc/irc-raw.h | 8 | ||||
-rw-r--r-- | src/plugins/irc/irc-upgrade.c | 32 | ||||
-rw-r--r-- | src/plugins/irc/irc-upgrade.h | 1 |
4 files changed, 145 insertions, 53 deletions
diff --git a/src/plugins/irc/irc-raw.c b/src/plugins/irc/irc-raw.c index 8f6ce7029..0aa0cbf82 100644 --- a/src/plugins/irc/irc-raw.c +++ b/src/plugins/irc/irc-raw.c @@ -154,21 +154,69 @@ irc_raw_message_free_all () } /* - * irc_raw_message_add: add new message to list + * irc_raw_message_remove_old: remove old raw messages if limit has been reached */ void +irc_raw_message_remove_old () +{ + int max_messages; + + max_messages = weechat_config_integer (irc_config_look_raw_messages); + while (irc_raw_messages && (irc_raw_messages_count >= max_messages)) + { + irc_raw_message_free (irc_raw_messages); + } +} + +/* + * irc_raw_message_add_to_list: add new message to list + */ + +struct t_irc_raw_message * +irc_raw_message_add_to_list (time_t date, const char *prefix, + const char *message) +{ + struct t_irc_raw_message *new_raw_message; + + irc_raw_message_remove_old (); + + new_raw_message = malloc (sizeof (*new_raw_message)); + if (new_raw_message) + { + new_raw_message->date = date; + new_raw_message->prefix = strdup (prefix); + new_raw_message->message = strdup (message); + + /* add message to list */ + new_raw_message->prev_message = last_irc_raw_message; + new_raw_message->next_message = NULL; + if (irc_raw_messages) + last_irc_raw_message->next_message = new_raw_message; + else + irc_raw_messages = new_raw_message; + last_irc_raw_message = new_raw_message; + + irc_raw_messages_count++; + } + + return new_raw_message; +} + +/* + * irc_raw_message_add: add new message to list + */ + +struct t_irc_raw_message * irc_raw_message_add (struct t_irc_server *server, int send, int modified, const char *message) { char *buf, *buf2, prefix[256]; const unsigned char *ptr_buf; const char *hexa = "0123456789ABCDEF"; - int pos_buf, pos_buf2, char_size, i, max_messages; + int pos_buf, pos_buf2, char_size, i; struct t_irc_raw_message *new_raw_message; - max_messages = weechat_config_integer (irc_config_look_raw_messages); - buf = weechat_iconv_to_internal (NULL, message); buf2 = malloc ((strlen (buf) * 3) + 1); if (buf2) @@ -196,59 +244,27 @@ irc_raw_message_add (struct t_irc_server *server, int send, int modified, } buf2[pos_buf2] = '\0'; } + snprintf (prefix, sizeof (prefix), "%s%s%s%s%s", + (server) ? weechat_color ("chat_server") : "", + (server) ? server->name : "", + (server) ? " " : "", + (send) ? + weechat_color ("chat_prefix_quit") : + weechat_color ("chat_prefix_join"), + (send) ? + ((modified) ? IRC_RAW_PREFIX_SEND_MOD : IRC_RAW_PREFIX_SEND) : + ((modified) ? IRC_RAW_PREFIX_RECV_MOD : IRC_RAW_PREFIX_RECV)); - new_raw_message = malloc (sizeof (*new_raw_message)); - if (new_raw_message) - { - new_raw_message->date = time (NULL); - snprintf (prefix, sizeof (prefix), "%s%s%s%s%s", - (server) ? weechat_color ("chat_server") : "", - (server) ? server->name : "", - (server) ? " " : "", - (send) ? - weechat_color ("chat_prefix_quit") : - weechat_color ("chat_prefix_join"), - (send) ? - ((modified) ? IRC_RAW_PREFIX_SEND_MOD : IRC_RAW_PREFIX_SEND) : - ((modified) ? IRC_RAW_PREFIX_RECV_MOD : IRC_RAW_PREFIX_RECV)); - new_raw_message->prefix = strdup (prefix); - new_raw_message->message = strdup ((buf2) ? buf2 : ((buf) ? buf : message)); - new_raw_message->prev_message = NULL; - new_raw_message->next_message = NULL; - - while (irc_raw_messages_count >= max_messages) - { - irc_raw_message_free (irc_raw_messages); - } - - if (max_messages > 0) - { - new_raw_message->prev_message = last_irc_raw_message; - new_raw_message->next_message = NULL; - if (irc_raw_messages) - last_irc_raw_message->next_message = new_raw_message; - else - irc_raw_messages = new_raw_message; - last_irc_raw_message = new_raw_message; - - irc_raw_messages_count++; - - if (irc_raw_buffer) - irc_raw_message_print (new_raw_message); - } - else - { - /* don't store message, just print it if raw buffer is opened */ - if (irc_raw_buffer) - irc_raw_message_print (new_raw_message); - irc_raw_message_free (new_raw_message); - } - } + 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; } /* @@ -259,11 +275,48 @@ void irc_raw_print (struct t_irc_server *server, int send, int modified, const char *message) { + struct t_irc_raw_message *new_raw_message; + if (!message) return; if (!irc_raw_buffer && (weechat_irc_plugin->debug >= 1)) irc_raw_open (0); - irc_raw_message_add (server, send, modified, message); + new_raw_message = irc_raw_message_add (server, send, modified, message); + if (new_raw_message) + { + if (irc_raw_buffer) + irc_raw_message_print (new_raw_message); + if (weechat_config_integer (irc_config_look_raw_messages) == 0) + irc_raw_message_free (new_raw_message); + } +} + +/* + * irc_raw_add_to_infolist: add a raw messagt in an infolist + * return 1 if ok, 0 if error + */ + +int +irc_raw_add_to_infolist (struct t_infolist *infolist, + struct t_irc_raw_message *raw_message) +{ + struct t_infolist_item *ptr_item; + + if (!infolist || !raw_message) + return 0; + + ptr_item = weechat_infolist_new_item (infolist); + if (!ptr_item) + return 0; + + 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)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "message", raw_message->message)) + return 0; + + return 1; } diff --git a/src/plugins/irc/irc-raw.h b/src/plugins/irc/irc-raw.h index d0b6038d1..b8b4ff539 100644 --- a/src/plugins/irc/irc-raw.h +++ b/src/plugins/irc/irc-raw.h @@ -38,10 +38,16 @@ struct t_irc_raw_message struct t_irc_server; 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_open (int switch_to_buffer); -extern void irc_raw_max_messages (int number); +extern struct t_irc_raw_message *irc_raw_message_add_to_list (time_t date, + const char *prefix, + const char *message); extern void irc_raw_print (struct t_irc_server *server, int send, int modified, const char *message); +extern int irc_raw_add_to_infolist (struct t_infolist *infolist, + struct t_irc_raw_message *raw_message); #endif /* irc-raw.h */ diff --git a/src/plugins/irc/irc-upgrade.c b/src/plugins/irc/irc-upgrade.c index 096f2839c..759aeafac 100644 --- a/src/plugins/irc/irc-upgrade.c +++ b/src/plugins/irc/irc-upgrade.c @@ -31,6 +31,7 @@ #include "irc-server.h" #include "irc-channel.h" #include "irc-nick.h" +#include "irc-raw.h" struct t_irc_server *irc_upgrade_current_server = NULL; @@ -48,6 +49,7 @@ irc_upgrade_save_all_data (struct t_upgrade_file *upgrade_file) struct t_irc_server *ptr_server; struct t_irc_channel *ptr_channel; struct t_irc_nick *ptr_nick; + struct t_irc_raw_message *ptr_raw_message; int rc; for (ptr_server = irc_servers; ptr_server; @@ -110,6 +112,26 @@ irc_upgrade_save_all_data (struct t_upgrade_file *upgrade_file) } } + /* save raw messages */ + for (ptr_raw_message = irc_raw_messages; ptr_raw_message; + ptr_raw_message = ptr_raw_message->next_message) + { + infolist = weechat_infolist_new (); + if (!infolist) + return 0; + if (!irc_raw_add_to_infolist (infolist, ptr_raw_message)) + { + weechat_infolist_free (infolist); + return 0; + } + rc = weechat_upgrade_write_object (upgrade_file, + IRC_UPGRADE_TYPE_RAW_MESSAGE, + infolist); + weechat_infolist_free (infolist); + if (!rc) + return 0; + } + return 1; } @@ -156,6 +178,11 @@ irc_upgrade_set_buffer_callbacks () ptr_buffer = weechat_infolist_pointer (infolist, "pointer"); weechat_buffer_set_pointer (ptr_buffer, "close_callback", &irc_buffer_close_cb); weechat_buffer_set_pointer (ptr_buffer, "input_callback", &irc_input_data_cb); + if (strcmp (weechat_infolist_string (infolist, "name"), + IRC_RAW_BUFFER_NAME) == 0) + { + irc_raw_buffer = ptr_buffer; + } } } } @@ -338,6 +365,11 @@ irc_upgrade_read_cb (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")); + break; } } diff --git a/src/plugins/irc/irc-upgrade.h b/src/plugins/irc/irc-upgrade.h index 304a6ee93..fbfe5ae21 100644 --- a/src/plugins/irc/irc-upgrade.h +++ b/src/plugins/irc/irc-upgrade.h @@ -29,6 +29,7 @@ enum t_irc_upgrade_type IRC_UPGRADE_TYPE_SERVER = 0, IRC_UPGRADE_TYPE_CHANNEL, IRC_UPGRADE_TYPE_NICK, + IRC_UPGRADE_TYPE_RAW_MESSAGE, }; extern int irc_upgrade_save (); |