diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2022-08-07 16:48:12 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2022-08-07 16:48:12 +0200 |
commit | d068fe0de5323fecb52c2491b8a8854a2850e410 (patch) | |
tree | a8a3b90a4e4a859ad93b59357dc9b91fb92643e6 /src/plugins/irc | |
parent | d91cddc90925deb9269a467e68bb4f3f05741d97 (diff) | |
download | weechat-d068fe0de5323fecb52c2491b8a8854a2850e410.zip |
core: add option `-save` in command `/upgrade` (closes #1630)
Diffstat (limited to 'src/plugins/irc')
-rw-r--r-- | src/plugins/irc/irc-info.c | 4 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 216 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.h | 3 | ||||
-rw-r--r-- | src/plugins/irc/irc-upgrade.c | 91 | ||||
-rw-r--r-- | src/plugins/irc/irc-upgrade.h | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc.c | 20 |
6 files changed, 227 insertions, 109 deletions
diff --git a/src/plugins/irc/irc-info.c b/src/plugins/irc/irc-info.c index 6918e9cbd..11dcf255f 100644 --- a/src/plugins/irc/irc-info.c +++ b/src/plugins/irc/irc-info.c @@ -534,7 +534,7 @@ irc_info_infolist_irc_server_cb (const void *pointer, void *data, if (obj_pointer) { /* build list with only one server */ - if (!irc_server_add_to_infolist (ptr_infolist, obj_pointer)) + if (!irc_server_add_to_infolist (ptr_infolist, obj_pointer, 0)) { weechat_infolist_free (ptr_infolist); return NULL; @@ -550,7 +550,7 @@ irc_info_infolist_irc_server_cb (const void *pointer, void *data, if (!arguments || !arguments[0] || weechat_string_match (ptr_server->name, arguments, 0)) { - if (!irc_server_add_to_infolist (ptr_infolist, ptr_server)) + if (!irc_server_add_to_infolist (ptr_infolist, ptr_server, 0)) { weechat_infolist_free (ptr_infolist); return NULL; diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index 6c1b8f408..a0f8acfe3 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -3907,6 +3907,13 @@ irc_server_close_connection (struct t_irc_server *server) { int i; + /* + * IMPORTANT: if changes are made in this function or sub-functions called, + * please also update the function irc_server_add_to_infolist: + * when the flag force_disconnected_state is set to 1 we simulate + * a disconnected state for server in infolist (used on /upgrade -save) + */ + if (server->hook_timer_connection) { weechat_unhook (server->hook_timer_connection); @@ -5402,6 +5409,13 @@ irc_server_disconnect (struct t_irc_server *server, int switch_address, { struct t_irc_channel *ptr_channel; + /* + * IMPORTANT: if changes are made in this function or sub-functions called, + * please also update the function irc_server_add_to_infolist: + * when the flag force_disconnected_state is set to 1 we simulate + * a disconnected state for server in infolist (used on /upgrade -save) + */ + if (server->is_connected) { /* @@ -5477,7 +5491,9 @@ irc_server_disconnect (struct t_irc_server *server, int switch_address, if (reconnect && IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTORECONNECT)) + { irc_server_reconnect_schedule (server); + } else { server->reconnect_delay = 0; @@ -6173,6 +6189,10 @@ irc_server_hdata_server_cb (const void *pointer, void *data, /* * Adds a server in an infolist. * + * If force_disconnected_state == 1, the infolist contains the server + * in a disconnected state (but the server is unchanged, still connected if it + * was). + * * Returns: * 1: OK * 0: error @@ -6180,9 +6200,13 @@ irc_server_hdata_server_cb (const void *pointer, void *data, int irc_server_add_to_infolist (struct t_infolist *infolist, - struct t_irc_server *server) + struct t_irc_server *server, + int force_disconnected_state) { struct t_infolist_item *ptr_item; + int reconnect_delay, reconnect_start; + struct timeval lag_check_time; + time_t lag_next_check; if (!infolist || !server) return 0; @@ -6327,40 +6351,138 @@ irc_server_add_to_infolist (struct t_infolist *infolist, return 0; if (!weechat_infolist_new_var_integer (ptr_item, "fake_server", server->fake_server)) return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "index_current_address", server->index_current_address)) - return 0; - if (!weechat_infolist_new_var_string (ptr_item, "current_address", server->current_address)) - return 0; - if (!weechat_infolist_new_var_string (ptr_item, "current_ip", server->current_ip)) - return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "current_port", server->current_port)) - return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "current_retry", server->current_retry)) - return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "sock", server->sock)) - return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "is_connected", server->is_connected)) - return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "ssl_connected", server->ssl_connected)) - return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "disconnected", server->disconnected)) - return 0; - if (!weechat_infolist_new_var_string (ptr_item, "unterminated_message", server->unterminated_message)) - return 0; - if (!weechat_infolist_new_var_string (ptr_item, "nick", server->nick)) - return 0; - if (!weechat_infolist_new_var_string (ptr_item, "nick_modes", server->nick_modes)) - return 0; - if (!weechat_infolist_new_var_string (ptr_item, "host", server->host)) - return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "checking_cap_ls", server->checking_cap_ls)) - return 0; - if (!weechat_hashtable_add_to_infolist (server->cap_ls, ptr_item, "cap_ls")) - return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "checking_cap_list", server->checking_cap_list)) - return 0; - if (!weechat_hashtable_add_to_infolist (server->cap_list, ptr_item, "cap_list")) - return 0; + if (server->is_connected && force_disconnected_state) + { + if (!weechat_infolist_new_var_integer (ptr_item, "index_current_address", 0)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "current_address", NULL)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "current_ip", NULL)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "current_port", 0)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "current_retry", 0)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "sock", -1)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "is_connected", 0)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "ssl_connected", 0)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "disconnected", 1)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "unterminated_message", NULL)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "monitor", 0)) + return 0; + if (!weechat_infolist_new_var_time (ptr_item, "monitor_time", 0)) + return 0; + reconnect_delay = IRC_SERVER_OPTION_INTEGER( + server, + IRC_SERVER_OPTION_AUTORECONNECT_DELAY); + reconnect_start = time (NULL) - reconnect_delay - 1; + if (!weechat_infolist_new_var_integer (ptr_item, "reconnect_delay", reconnect_delay)) + return 0; + if (!weechat_infolist_new_var_time (ptr_item, "reconnect_start", reconnect_start)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "nick", NULL)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "nick_modes", NULL)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "host", NULL)) + return 0; + /* + * note: these hashtables are NOT in the infolist when saving a + * disconnected state: + * - cap_ls + * - cap_list + */ + if (!weechat_infolist_new_var_integer (ptr_item, "checking_cap_ls", 0)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "checking_cap_list", 0)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "is_away", 0)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "away_message", NULL)) + return 0; + if (!weechat_infolist_new_var_time (ptr_item, "away_time", 0)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "lag", 0)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "lag_displayed", -1)) + return 0; + lag_check_time.tv_sec = 0; + lag_check_time.tv_usec = 0; + lag_next_check = time (NULL) + + weechat_config_integer (irc_config_network_lag_check); + if (!weechat_infolist_new_var_buffer (ptr_item, "lag_check_time", &lag_check_time, sizeof (lag_check_time))) + return 0; + if (!weechat_infolist_new_var_time (ptr_item, "lag_next_check", lag_next_check)) + return 0; + if (!weechat_infolist_new_var_time (ptr_item, "lag_last_refresh", 0)) + return 0; + } + else + { + if (!weechat_infolist_new_var_integer (ptr_item, "index_current_address", server->index_current_address)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "current_address", server->current_address)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "current_ip", server->current_ip)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "current_port", server->current_port)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "current_retry", server->current_retry)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "sock", server->sock)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "is_connected", server->is_connected)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "ssl_connected", server->ssl_connected)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "disconnected", server->disconnected)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "unterminated_message", server->unterminated_message)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "monitor", server->monitor)) + return 0; + if (!weechat_infolist_new_var_time (ptr_item, "monitor_time", server->monitor_time)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "reconnect_delay", server->reconnect_delay)) + return 0; + if (!weechat_infolist_new_var_time (ptr_item, "reconnect_start", server->reconnect_start)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "nick", server->nick)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "nick_modes", server->nick_modes)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "host", server->host)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "checking_cap_ls", server->checking_cap_ls)) + return 0; + if (!weechat_hashtable_add_to_infolist (server->cap_ls, ptr_item, "cap_ls")) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "checking_cap_list", server->checking_cap_list)) + return 0; + if (!weechat_hashtable_add_to_infolist (server->cap_list, ptr_item, "cap_list")) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "is_away", server->is_away)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "away_message", server->away_message)) + return 0; + if (!weechat_infolist_new_var_time (ptr_item, "away_time", server->away_time)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "lag", server->lag)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "lag_displayed", server->lag_displayed)) + return 0; + if (!weechat_infolist_new_var_buffer (ptr_item, "lag_check_time", &(server->lag_check_time), sizeof (server->lag_check_time))) + return 0; + if (!weechat_infolist_new_var_time (ptr_item, "lag_next_check", server->lag_next_check)) + return 0; + if (!weechat_infolist_new_var_time (ptr_item, "lag_last_refresh", server->lag_last_refresh)) + return 0; + } if (!weechat_infolist_new_var_string (ptr_item, "isupport", server->isupport)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "prefix_modes", server->prefix_modes)) @@ -6385,40 +6507,16 @@ irc_server_add_to_infolist (struct t_infolist *infolist, return 0; if (!weechat_infolist_new_var_string (ptr_item, "chanmodes", server->chanmodes)) return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "monitor", server->monitor)) - return 0; - if (!weechat_infolist_new_var_time (ptr_item, "monitor_time", server->monitor_time)) - return 0; if (!weechat_infolist_new_var_string (ptr_item, "clienttagdeny", server->clienttagdeny)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "typing_allowed", server->typing_allowed)) return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "reconnect_delay", server->reconnect_delay)) - return 0; - if (!weechat_infolist_new_var_time (ptr_item, "reconnect_start", server->reconnect_start)) - return 0; if (!weechat_infolist_new_var_time (ptr_item, "command_time", server->command_time)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "reconnect_join", server->reconnect_join)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "disable_autojoin", server->disable_autojoin)) return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "is_away", server->is_away)) - return 0; - if (!weechat_infolist_new_var_string (ptr_item, "away_message", server->away_message)) - return 0; - if (!weechat_infolist_new_var_time (ptr_item, "away_time", server->away_time)) - return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "lag", server->lag)) - return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "lag_displayed", server->lag_displayed)) - return 0; - if (!weechat_infolist_new_var_buffer (ptr_item, "lag_check_time", &(server->lag_check_time), sizeof (struct timeval))) - return 0; - if (!weechat_infolist_new_var_time (ptr_item, "lag_next_check", server->lag_next_check)) - return 0; - if (!weechat_infolist_new_var_time (ptr_item, "lag_last_refresh", server->lag_last_refresh)) - return 0; if (!weechat_infolist_new_var_time (ptr_item, "last_user_message", server->last_user_message)) return 0; if (!weechat_infolist_new_var_time (ptr_item, "last_away_check", server->last_away_check)) diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h index 041364943..f6cc28dc0 100644 --- a/src/plugins/irc/irc-server.h +++ b/src/plugins/irc/irc-server.h @@ -424,7 +424,8 @@ extern struct t_hdata *irc_server_hdata_server_cb (const void *pointer, void *data, const char *hdata_name); extern int irc_server_add_to_infolist (struct t_infolist *infolist, - struct t_irc_server *server); + struct t_irc_server *server, + int force_disconnected_state); extern void irc_server_print_log (); #endif /* WEECHAT_PLUGIN_IRC_SERVER_H */ diff --git a/src/plugins/irc/irc-upgrade.c b/src/plugins/irc/irc-upgrade.c index 1744f9fd1..f29356703 100644 --- a/src/plugins/irc/irc-upgrade.c +++ b/src/plugins/irc/irc-upgrade.c @@ -52,7 +52,8 @@ struct t_irc_modelist *irc_upgrade_current_modelist = NULL; */ int -irc_upgrade_save_all_data (struct t_upgrade_file *upgrade_file) +irc_upgrade_save_all_data (struct t_upgrade_file *upgrade_file, + int force_disconnected_state) { struct t_infolist *infolist; struct t_irc_server *ptr_server; @@ -73,7 +74,8 @@ irc_upgrade_save_all_data (struct t_upgrade_file *upgrade_file) infolist = weechat_infolist_new (); if (!infolist) return 0; - if (!irc_server_add_to_infolist (infolist, ptr_server)) + if (!irc_server_add_to_infolist (infolist, ptr_server, + force_disconnected_state)) { weechat_infolist_free (infolist); return 0; @@ -105,63 +107,66 @@ irc_upgrade_save_all_data (struct t_upgrade_file *upgrade_file) if (!rc) return 0; - for (ptr_nick = ptr_channel->nicks; ptr_nick; - ptr_nick = ptr_nick->next_nick) + if (!force_disconnected_state) { - /* save nick */ - infolist = weechat_infolist_new (); - if (!infolist) - return 0; - if (!irc_nick_add_to_infolist (infolist, ptr_nick)) - { - weechat_infolist_free (infolist); - return 0; - } - rc = weechat_upgrade_write_object (upgrade_file, - IRC_UPGRADE_TYPE_NICK, - infolist); - weechat_infolist_free (infolist); - if (!rc) - return 0; - } - - for (ptr_modelist = ptr_channel->modelists; ptr_modelist; - ptr_modelist = ptr_modelist->next_modelist) - { - /* save modelist */ - infolist = weechat_infolist_new (); - if (!infolist) - return 0; - if (!irc_modelist_add_to_infolist (infolist, ptr_modelist)) + for (ptr_nick = ptr_channel->nicks; ptr_nick; + ptr_nick = ptr_nick->next_nick) { + /* save nick */ + infolist = weechat_infolist_new (); + if (!infolist) + return 0; + if (!irc_nick_add_to_infolist (infolist, ptr_nick)) + { + weechat_infolist_free (infolist); + return 0; + } + rc = weechat_upgrade_write_object (upgrade_file, + IRC_UPGRADE_TYPE_NICK, + infolist); weechat_infolist_free (infolist); - return 0; + if (!rc) + return 0; } - rc = weechat_upgrade_write_object (upgrade_file, - IRC_UPGRADE_TYPE_MODELIST, - infolist); - weechat_infolist_free (infolist); - if (!rc) - return 0; - for (ptr_item = ptr_modelist->items; ptr_item; - ptr_item = ptr_item->next_item) + for (ptr_modelist = ptr_channel->modelists; ptr_modelist; + ptr_modelist = ptr_modelist->next_modelist) { - /* save modelist item */ + /* save modelist */ infolist = weechat_infolist_new (); if (!infolist) return 0; - if (!irc_modelist_item_add_to_infolist (infolist, ptr_item)) + if (!irc_modelist_add_to_infolist (infolist, ptr_modelist)) { weechat_infolist_free (infolist); return 0; } rc = weechat_upgrade_write_object (upgrade_file, - IRC_UPGRADE_TYPE_MODELIST_ITEM, + IRC_UPGRADE_TYPE_MODELIST, infolist); weechat_infolist_free (infolist); if (!rc) return 0; + + for (ptr_item = ptr_modelist->items; ptr_item; + ptr_item = ptr_item->next_item) + { + /* save modelist item */ + infolist = weechat_infolist_new (); + if (!infolist) + return 0; + if (!irc_modelist_item_add_to_infolist (infolist, ptr_item)) + { + weechat_infolist_free (infolist); + return 0; + } + rc = weechat_upgrade_write_object (upgrade_file, + IRC_UPGRADE_TYPE_MODELIST_ITEM, + infolist); + weechat_infolist_free (infolist); + if (!rc) + return 0; + } } } } @@ -263,7 +268,7 @@ irc_upgrade_save_all_data (struct t_upgrade_file *upgrade_file) */ int -irc_upgrade_save () +irc_upgrade_save (int force_disconnected_state) { int rc; struct t_upgrade_file *upgrade_file; @@ -273,7 +278,7 @@ irc_upgrade_save () if (!upgrade_file) return 0; - rc = irc_upgrade_save_all_data (upgrade_file); + rc = irc_upgrade_save_all_data (upgrade_file, force_disconnected_state); weechat_upgrade_close (upgrade_file); diff --git a/src/plugins/irc/irc-upgrade.h b/src/plugins/irc/irc-upgrade.h index cdcdf9bc1..fe4fd2d98 100644 --- a/src/plugins/irc/irc-upgrade.h +++ b/src/plugins/irc/irc-upgrade.h @@ -37,7 +37,7 @@ enum t_irc_upgrade_type IRC_UPGRADE_TYPE_MODELIST_ITEM, }; -extern int irc_upgrade_save (); +extern int irc_upgrade_save (int force_disconnected_state); extern int irc_upgrade_load (); #endif /* WEECHAT_PLUGIN_IRC_UPGRADE_H */ diff --git a/src/plugins/irc/irc.c b/src/plugins/irc/irc.c index e0c892dae..3d3fb7fd8 100644 --- a/src/plugins/irc/irc.c +++ b/src/plugins/irc/irc.c @@ -112,9 +112,21 @@ irc_signal_upgrade_cb (const void *pointer, void *data, (void) signal; (void) type_data; + /* only save session and continue? */ + if (signal_data && (strcmp (signal_data, "save") == 0)) + { + /* + * save session with a disconnected state in servers and a scheduled + * reconnection + */ + irc_upgrade_save (1); + return WEECHAT_RC_OK; + } + irc_signal_upgrade_received = 1; quit = (signal_data && (strcmp (signal_data, "quit") == 0)); + ssl_disconnected = 0; for (ptr_server = irc_servers; ptr_server; @@ -142,8 +154,10 @@ irc_signal_upgrade_cb (const void *pointer, void *data, * after restart */ ptr_server->index_current_address = 0; - ptr_server->reconnect_delay = IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_AUTORECONNECT_DELAY); - ptr_server->reconnect_start = time (NULL) - ptr_server->reconnect_delay - 1; + ptr_server->reconnect_delay = IRC_SERVER_OPTION_INTEGER( + ptr_server, IRC_SERVER_OPTION_AUTORECONNECT_DELAY); + ptr_server->reconnect_start = time (NULL) - + ptr_server->reconnect_delay - 1; } } if (ssl_disconnected > 0) @@ -293,7 +307,7 @@ weechat_plugin_end (struct t_weechat_plugin *plugin) if (irc_signal_upgrade_received) { irc_config_write (1); - irc_upgrade_save (); + irc_upgrade_save (0); } else { |