about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/command/commands.c19
-rw-r--r--src/event/client_events.c20
-rw-r--r--src/event/client_events.h2
-rw-r--r--src/event/server_events.c1
4 files changed, 27 insertions, 15 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index c58a1588..225deda5 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -984,24 +984,13 @@ cmd_sub(ProfWin *window, const char *const command, gchar **args)
 gboolean
 cmd_disconnect(ProfWin *window, const char *const command, gchar **args)
 {
-    if (jabber_get_connection_status() == JABBER_CONNECTED) {
-        char *jid = strdup(jabber_get_fulljid());
-        cons_show("%s logged out successfully.", jid);
-        jabber_disconnect();
-        roster_clear();
-        muc_invites_clear();
-        chat_sessions_clear();
-        tlscerts_clear_current();
-        ui_disconnected();
-        ui_close_all_wins();
-#ifdef HAVE_LIBGPGME
-        p_gpg_on_disconnect();
-#endif
-        free(jid);
-    } else {
+    if (jabber_get_connection_status() != JABBER_CONNECTED) {
         cons_show("You are not currently connected.");
+        return TRUE;
     }
 
+    cl_ev_disconnect();
+
     return TRUE;
 }
 
diff --git a/src/event/client_events.c b/src/event/client_events.c
index 88776fd5..b2efd491 100644
--- a/src/event/client_events.c
+++ b/src/event/client_events.c
@@ -41,6 +41,8 @@
 #include "ui/ui.h"
 #include "window_list.h"
 #include "xmpp/xmpp.h"
+#include "roster_list.h"
+#include "chat_session.h"
 #ifdef HAVE_LIBOTR
 #include "otr/otr.h"
 #endif
@@ -66,6 +68,24 @@ cl_ev_connect_account(ProfAccount *account)
 }
 
 void
+cl_ev_disconnect(void)
+{
+    const char *jid = jabber_get_fulljid();
+    cons_show("%s logged out successfully.", jid);
+
+    jabber_disconnect();
+    roster_clear();
+    muc_invites_clear();
+    chat_sessions_clear();
+    tlscerts_clear_current();
+    ui_disconnected();
+    ui_close_all_wins();
+#ifdef HAVE_LIBGPGME
+    p_gpg_on_disconnect();
+#endif
+}
+
+void
 cl_ev_presence_send(const resource_presence_t presence_type, const char *const msg, const int idle_secs)
 {
     char *signed_status = NULL;
diff --git a/src/event/client_events.h b/src/event/client_events.h
index 11d1fb38..708ad080 100644
--- a/src/event/client_events.h
+++ b/src/event/client_events.h
@@ -38,6 +38,8 @@
 jabber_conn_status_t cl_ev_connect_jid(const char *const jid, const char *const passwd, const char *const altdomain, const int port, const char *const tls_policy);
 jabber_conn_status_t cl_ev_connect_account(ProfAccount *account);
 
+void cl_ev_disconnect(void);
+
 void cl_ev_presence_send(const resource_presence_t presence_type, const char *const msg, const int idle_secs);
 
 void cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg);
diff --git a/src/event/server_events.c b/src/event/server_events.c
index 53904ca9..db8329b1 100644
--- a/src/event/server_events.c
+++ b/src/event/server_events.c
@@ -149,6 +149,7 @@ void
 sv_ev_lost_connection(void)
 {
     cons_show_error("Lost connection.");
+
     roster_clear();
     muc_invites_clear();
     chat_sessions_clear();