about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2019-05-19 22:22:58 +0200
committerMichael Vetter <jubalh@iodoru.org>2019-05-19 22:57:51 +0200
commit883dbe1911766e31e4483eabe713edb89e1eec4f (patch)
tree20464808b63787cceac5005f4324a9b6fef464aa /src
parent813949667c5120cab826b16d78b3f8689fd0b5f9 (diff)
downloadprofani-tty-883dbe1911766e31e4483eabe713edb89e1eec4f.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/event/client_events.c20
-rw-r--r--src/event/common.c68
-rw-r--r--src/event/common.h40
-rw-r--r--src/event/server_events.c15
4 files changed, 113 insertions, 30 deletions
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 <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
+}
+
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 <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
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