about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am2
-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
-rw-r--r--tests/unittests/config/stub_accounts.c14
-rw-r--r--tests/unittests/log/stub_log.c4
-rw-r--r--tests/unittests/otr/stub_otr.c10
-rw-r--r--tests/unittests/ui/stub_ui.c4
-rw-r--r--tests/unittests/xmpp/stub_xmpp.c18
10 files changed, 140 insertions, 55 deletions
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 <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
diff --git a/tests/unittests/config/stub_accounts.c b/tests/unittests/config/stub_accounts.c
index b164497e..ddda2401 100644
--- a/tests/unittests/config/stub_accounts.c
+++ b/tests/unittests/config/stub_accounts.c
@@ -36,25 +36,25 @@ int  accounts_remove(const char *jid)
 
 gchar** accounts_get_list(void)
 {
-    return (gchar **)mock();
+    return mock_ptr_type(gchar **);
 }
 
 ProfAccount* accounts_get_account(const char * const name)
 {
     check_expected(name);
-    return (ProfAccount*)mock();
+    return mock_ptr_type(ProfAccount*);
 }
 
 gboolean accounts_enable(const char * const name)
 {
     check_expected(name);
-    return (gboolean)mock();
+    return mock_type(gboolean);
 }
 
 gboolean accounts_disable(const char * const name)
 {
     check_expected(name);
-    return (gboolean)mock();
+    return mock_type(gboolean);
 }
 
 gboolean accounts_rename(const char * const account_name,
@@ -62,13 +62,13 @@ gboolean accounts_rename(const char * const account_name,
 {
     check_expected(account_name);
     check_expected(new_name);
-    return (gboolean)mock();
+    return mock_type(gboolean);
 }
 
 gboolean accounts_account_exists(const char * const account_name)
 {
     check_expected(account_name);
-    return (gboolean)mock();
+    return mock_type(gboolean);
 }
 
 void accounts_set_jid(const char * const account_name, const char * const value)
@@ -148,7 +148,7 @@ char * accounts_get_last_status(const char * const account_name)
 resource_presence_t accounts_get_last_presence(const char * const account_name)
 {
     check_expected(account_name);
-    return (resource_presence_t)mock();
+    return mock_type(resource_presence_t);
 }
 
 void accounts_set_priority_online(const char * const account_name, const gint value)
diff --git a/tests/unittests/log/stub_log.c b/tests/unittests/log/stub_log.c
index dfbec2bd..2eb9faa5 100644
--- a/tests/unittests/log/stub_log.c
+++ b/tests/unittests/log/stub_log.c
@@ -29,7 +29,7 @@
 void log_init(log_level_t filter) {}
 log_level_t log_get_filter(void)
 {
-    return (log_level_t)mock();
+    return mock_type(log_level_t);
 }
 void log_reinit(void) {}
 void log_close(void) {}
@@ -46,7 +46,7 @@ char * get_log_file_location(void)
 
 log_level_t log_level_from_string(char *log_level)
 {
-    return (log_level_t)mock();
+    return mock_type(log_level_t);
 }
 
 void log_stderr_init(log_level_t level) {}
diff --git a/tests/unittests/otr/stub_otr.c b/tests/unittests/otr/stub_otr.c
index 5070a66c..25c199a8 100644
--- a/tests/unittests/otr/stub_otr.c
+++ b/tests/unittests/otr/stub_otr.c
@@ -31,12 +31,12 @@ void otr_shutdown(void) {}
 
 char* otr_libotr_version(void)
 {
-    return (char*)mock();
+    return mock_ptr_type(char*);
 }
 
 char* otr_start_query(void)
 {
-    return (char*)mock();
+    return mock_ptr_type(char*);
 }
 
 void otr_poll(void) {}
@@ -57,7 +57,7 @@ void otr_keygen(ProfAccount *account)
 
 gboolean otr_key_loaded(void)
 {
-    return (gboolean)mock();
+    return mock_type(gboolean);
 }
 
 char* otr_tag_message(const char * const msg)
@@ -86,13 +86,13 @@ void otr_end_session(const char * const recipient) {}
 
 char * otr_get_my_fingerprint(void)
 {
-    return (char *)mock();
+    return mock_ptr_type(char *);
 }
 
 char * otr_get_their_fingerprint(const char * const recipient)
 {
     check_expected(recipient);
-    return (char *)mock();
+    return mock_ptr_type(char *);
 }
 
 char * otr_encrypt_message(const char * const to, const char * const message)
diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c
index bb13705a..a69e88a4 100644
--- a/tests/unittests/ui/stub_ui.c
+++ b/tests/unittests/ui/stub_ui.c
@@ -483,7 +483,7 @@ void occupantswin_occupants_all(void) {}
 // window interface
 ProfWin* win_create_console(void)
 {
-    return (ProfWin*)mock();
+    return mock_ptr_type(ProfWin*);
 }
 ProfWin* win_create_xmlconsole(void)
 {
@@ -491,7 +491,7 @@ ProfWin* win_create_xmlconsole(void)
 }
 ProfWin* win_create_chat(const char * const barejid)
 {
-    return (ProfWin*)mock();
+    return mock_ptr_type(ProfWin*);
 }
 ProfWin* win_create_muc(const char * const roomjid)
 {
diff --git a/tests/unittests/xmpp/stub_xmpp.c b/tests/unittests/xmpp/stub_xmpp.c
index 53a729e6..df862b9b 100644
--- a/tests/unittests/xmpp/stub_xmpp.c
+++ b/tests/unittests/xmpp/stub_xmpp.c
@@ -17,13 +17,13 @@ jabber_conn_status_t session_connect_with_details(const char * const jid,
     check_expected(passwd);
     check_expected(altdomain);
     check_expected(port);
-    return (jabber_conn_status_t)mock();
+    return mock_type(jabber_conn_status_t);
 }
 
 jabber_conn_status_t session_connect_with_account(const ProfAccount * const account)
 {
     check_expected(account);
-    return (jabber_conn_status_t)mock();
+    return mock_type(jabber_conn_status_t);
 }
 
 void session_disconnect(void) {}
@@ -31,7 +31,7 @@ void session_shutdown(void) {}
 void session_process_events(void) {}
 const char * connection_get_fulljid(void)
 {
-    return (char *)mock();
+    return mock_ptr_type(char *);
 }
 
 const char * connection_get_domain(void)
@@ -60,17 +60,17 @@ void connection_free_uuid(char * uuid) {}
 
 jabber_conn_status_t connection_get_status(void)
 {
-    return (jabber_conn_status_t)mock();
+    return mock_type(jabber_conn_status_t);
 }
 
 char* connection_get_presence_msg(void)
 {
-    return (char*)mock();
+    return mock_ptr_type(char*);
 }
 
 char* session_get_account_name(void)
 {
-    return (char*)mock();
+    return mock_ptr_type(char*);
 }
 
 GList * session_get_available_resources(void)
@@ -233,7 +233,7 @@ gboolean bookmark_add(const char *jid, const char *nick, const char *password, c
     check_expected(nick);
     check_expected(password);
     check_expected(autojoin_str);
-    return (gboolean)mock();
+    return mock_type(gboolean);
 }
 
 gboolean bookmark_update(const char *jid, const char *nick, const char *password, const char *autojoin_str)
@@ -244,7 +244,7 @@ gboolean bookmark_update(const char *jid, const char *nick, const char *password
 gboolean bookmark_remove(const char *jid)
 {
     check_expected(jid);
-    return (gboolean)mock();
+    return mock_type(gboolean);
 }
 
 gboolean bookmark_join(const char *jid)
@@ -254,7 +254,7 @@ gboolean bookmark_join(const char *jid)
 
 GList * bookmark_get_list(void)
 {
-    return (GList *)mock();
+    return mock_ptr_type(GList *);
 }
 
 char * bookmark_find(const char * const search_str, gboolean previous)