diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2009-05-03 17:19:42 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2009-05-03 17:19:42 +0200 |
commit | 28f376261837408a2c7fbf311aeafcc1c0f7818a (patch) | |
tree | ae5d56456eb8cdce3a9935960f4545748e02baee /src | |
parent | d6ed1485a4bca3044f8631963534e9e0a1ab7b8f (diff) | |
download | weechat-28f376261837408a2c7fbf311aeafcc1c0f7818a.zip |
Fix crash when deleting last server if there is one buffer for all servers
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/irc/irc-command.c | 34 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 49 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.h | 1 |
3 files changed, 51 insertions, 33 deletions
diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index a6453c8eb..f80e2fccf 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -3112,39 +3112,7 @@ irc_command_server (void *data, struct t_gui_buffer *buffer, int argc, if (weechat_strcasecmp (argv[1], "switch") == 0) { if (weechat_config_boolean (irc_config_look_one_server_buffer)) - { - if (irc_current_server) - { - ptr_server2 = irc_current_server->next_server; - if (!ptr_server2) - ptr_server2 = irc_servers; - while (ptr_server2 != irc_current_server) - { - if (ptr_server2->buffer) - { - irc_current_server = ptr_server2; - break; - } - ptr_server2 = ptr_server2->next_server; - if (!ptr_server2) - ptr_server2 = irc_servers; - } - } - else - { - for (ptr_server2 = irc_servers; ptr_server2; - ptr_server2 = ptr_server2->next_server) - { - if (ptr_server2->buffer) - { - irc_current_server = ptr_server2; - break; - } - } - } - if (irc_current_server) - irc_server_set_current_server (irc_current_server); - } + irc_server_switch_next (); return WEECHAT_RC_OK; } diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index ffcfc651c..dc18745dc 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -635,6 +635,48 @@ irc_server_outqueue_free_all (struct t_irc_server *server) } /* + * irc_server_switch_next: swicth to next server + */ + +void +irc_server_switch_next () +{ + struct t_irc_server *ptr_server; + + if (irc_current_server) + { + ptr_server = irc_current_server->next_server; + if (!ptr_server) + ptr_server = irc_servers; + while (ptr_server != irc_current_server) + { + if (ptr_server->buffer) + { + irc_current_server = ptr_server; + break; + } + ptr_server = ptr_server->next_server; + if (!ptr_server) + ptr_server = irc_servers; + } + } + else + { + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + if (ptr_server->buffer) + { + irc_current_server = ptr_server; + break; + } + } + } + if (irc_current_server) + irc_server_set_current_server (irc_current_server); +} + +/* * irc_server_free_data: free server data */ @@ -692,6 +734,13 @@ irc_server_free (struct t_irc_server *server) if (!server) return; + if (irc_current_server == server) + { + irc_server_switch_next (); + if (irc_current_server == server) + irc_current_server = NULL; + } + /* close all channels/privates */ irc_channel_free_all (server); diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h index 2ed059176..49344adc0 100644 --- a/src/plugins/irc/irc-server.h +++ b/src/plugins/irc/irc-server.h @@ -172,6 +172,7 @@ extern void irc_server_buffer_set_highlight_words (struct t_gui_buffer *buffer); extern void irc_server_set_nick (struct t_irc_server *server, const char *nick); extern struct t_irc_server *irc_server_alloc (const char *name); extern int irc_server_alloc_with_url (const char *irc_url); +extern void irc_server_switch_next (); extern void irc_server_free_all (); extern struct t_irc_server *irc_server_copy (struct t_irc_server *server, const char *new_name); |