diff --git a/Makefile.am b/Makefile.am index 832ff045..7e3e7fdf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -15,6 +15,7 @@ core_sources = \ src/xmpp/bookmark.c src/xmpp/bookmark.h \ src/xmpp/blocking.c src/xmpp/blocking.h \ src/xmpp/form.c src/xmpp/form.h \ + src/event/common.c src/event/common.h \ src/event/server_events.c src/event/server_events.h \ src/event/client_events.c src/event/client_events.h \ src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/core.c \ @@ -95,6 +96,7 @@ unittest_sources = \ src/plugins/settings.c src/plugins/settings.h \ src/plugins/disco.c src/plugins/disco.h \ src/ui/window_list.c src/ui/window_list.h \ + src/event/common.c src/event/common.h \ src/event/server_events.c src/event/server_events.h \ src/event/client_events.c src/event/client_events.h \ src/ui/tray.h src/ui/tray.c \ diff --git a/src/event/client_events.c b/src/event/client_events.c index c2149985..a2784d1a 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -39,12 +39,11 @@ #include "log.h" #include "config/preferences.h" +#include "event/common.h" #include "plugins/plugins.h" #include "ui/window_list.h" -#include "ui/ui.h" -#include "xmpp/xmpp.h" -#include "xmpp/roster_list.h" #include "xmpp/chat_session.h" +#include "xmpp/xmpp.h" #ifdef HAVE_LIBOTR #include "otr/otr.h" @@ -87,20 +86,7 @@ cl_ev_disconnect(void) cons_show("%s logged out successfully.", jidp->barejid); jid_destroy(jidp); - ui_disconnected(); - ui_close_all_wins(); - session_disconnect(); - roster_destroy(); - muc_invites_clear(); - muc_confserver_clear(); - chat_sessions_clear(); - tlscerts_clear_current(); -#ifdef HAVE_LIBGPGME - p_gpg_on_disconnect(); -#endif -#ifdef HAVE_OMEMO - omemo_on_disconnect(); -#endif + ev_disconnect_cleanup(); } void diff --git a/src/event/common.c b/src/event/common.c new file mode 100644 index 00000000..aa8db832 --- /dev/null +++ b/src/event/common.c @@ -0,0 +1,68 @@ +/* + * common.c + * + * Copyright (C) 2019 Michael Vetter + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + * In addition, as a special exception, the copyright holders give permission to + * link the code of portions of this program with the OpenSSL library under + * certain conditions as described in each individual source file, and + * distribute linked combinations including the two. + * + * You must obey the GNU General Public License in all respects for all of the + * code used other than OpenSSL. If you modify file(s) with this exception, you + * may extend this exception to your version of the file(s), but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. If you delete this exception statement from all + * source files in the program, then also delete it here. + * + */ + +#include "config/tlscerts.h" +#include "ui/ui.h" +#include "xmpp/chat_session.h" +#include "xmpp/roster_list.h" +#include "xmpp/muc.h" +#include "xmpp/xmpp.h" + +#ifdef HAVE_LIBGPGME +#include "pgp/gpg.h" +#endif + +#ifdef HAVE_OMEMO +#include "omemo/omemo.h" +#endif + +void +ev_disconnect_cleanup(void) +{ + ui_disconnected(); + ui_close_all_wins(); + session_disconnect(); + roster_destroy(); + muc_invites_clear(); + muc_confserver_clear(); + chat_sessions_clear(); + tlscerts_clear_current(); +#ifdef HAVE_LIBGPGME + p_gpg_on_disconnect(); +#endif +#ifdef HAVE_OMEMO + omemo_on_disconnect(); +#endif +} + diff --git a/src/event/common.h b/src/event/common.h new file mode 100644 index 00000000..8af86933 --- /dev/null +++ b/src/event/common.h @@ -0,0 +1,40 @@ +/* + * common.h + * + * Copyright (C) 2019 Michael Vetter + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + * In addition, as a special exception, the copyright holders give permission to + * link the code of portions of this program with the OpenSSL library under + * certain conditions as described in each individual source file, and + * distribute linked combinations including the two. + * + * You must obey the GNU General Public License in all respects for all of the + * code used other than OpenSSL. If you modify file(s) with this exception, you + * may extend this exception to your version of the file(s), but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. If you delete this exception statement from all + * source files in the program, then also delete it here. + * + */ + +#ifndef EVENT_COMMON_H +#define EVENT_COMMON_H + +void ev_disconnect_cleanup(void); + +#endif diff --git a/src/event/server_events.c b/src/event/server_events.c index cf1c35b8..b76f7cfa 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -45,6 +45,7 @@ #include "config/account.h" #include "config/scripts.h" #include "event/client_events.h" +#include "event/common.h" #include "plugins/plugins.h" #include "ui/window_list.h" #include "xmpp/muc.h" @@ -211,19 +212,7 @@ sv_ev_lost_connection(void) } #endif - muc_invites_clear(); - muc_confserver_clear(); - chat_sessions_clear(); - ui_disconnected(); - ui_close_all_wins(); - roster_destroy(); - tlscerts_clear_current(); -#ifdef HAVE_LIBGPGME - p_gpg_on_disconnect(); -#endif -#ifdef HAVE_OMEMO - omemo_on_disconnect(); -#endif + ev_disconnect_cleanup(); } void