1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-16 21:35:24 +00:00

Create seperate function for disconnect cleanup

Duplicate code in client_events.c and server_events.c. Let's have
events/common.c and a function containing that code.
This commit is contained in:
Michael Vetter 2019-05-19 22:22:58 +02:00
parent 813949667c
commit 883dbe1911
5 changed files with 115 additions and 30 deletions

View File

@ -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 \

View File

@ -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

68
src/event/common.c Normal file
View File

@ -0,0 +1,68 @@
/*
* common.c
*
* Copyright (C) 2019 Michael Vetter <jubalh@iodoru.org>
*
* 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 <https://www.gnu.org/licenses/>.
*
* 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
}

40
src/event/common.h Normal file
View File

@ -0,0 +1,40 @@
/*
* common.h
*
* Copyright (C) 2019 Michael Vetter <jubalh@iodoru.org>
*
* 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 <https://www.gnu.org/licenses/>.
*
* 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

View File

@ -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