about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-10-27 18:26:57 +0100
committerJames Booth <boothj5@gmail.com>2012-10-27 18:26:57 +0100
commit847850742c55876676e22e6b7918361dfe086145 (patch)
tree3be011012faa8f8bc57f92a713d398d0d3982a6b /src
parentd658915740d8681db8ce61bf65aa4647f8007993 (diff)
downloadprofani-tty-847850742c55876676e22e6b7918361dfe086145.tar.gz
Refactored disconnect
Diffstat (limited to 'src')
-rw-r--r--src/command.c22
-rw-r--r--src/jabber.c15
-rw-r--r--src/jabber.h2
-rw-r--r--src/profanity.c10
4 files changed, 16 insertions, 33 deletions
diff --git a/src/command.c b/src/command.c
index 938142e4..361f53b4 100644
--- a/src/command.c
+++ b/src/command.c
@@ -577,21 +577,17 @@ _cmd_connect(const char * const inp, struct cmd_help_t help)
 static gboolean
 _cmd_disconnect(const char * const inp, struct cmd_help_t help)
 {
-    char *jid = strdup(jabber_get_jid());
-    gboolean wait_response = jabber_disconnect();
-
-    if (wait_response) {
-        while (jabber_get_connection_status() == JABBER_DISCONNECTING) {
-            jabber_process_events();
-        }
-        jabber_free_resources();
+    if (jabber_get_connection_status() == JABBER_CONNECTED) {
+        char *jid = strdup(jabber_get_jid());
+        jabber_disconnect();
+        contact_list_clear();
+        jabber_restart();
+        cons_show("%s logged out successfully.", jid);
+        free(jid);
+    } else {
+        cons_show("You are not currently connected.");
     }
 
-    contact_list_clear();
-    jabber_restart();
-    cons_show("%s logged out successfully.", jid);
-    free(jid);
-
     return TRUE;
 }
 
diff --git a/src/jabber.c b/src/jabber.c
index 2a199676..e6436f91 100644
--- a/src/jabber.c
+++ b/src/jabber.c
@@ -105,7 +105,7 @@ jabber_connect(const char * const user,
     return jabber_conn.conn_status;
 }
 
-gboolean
+void
 jabber_disconnect(void)
 {
     // if connected, send end stream and wait for response
@@ -113,16 +113,11 @@ jabber_disconnect(void)
         log_info("Closing connection");
         xmpp_disconnect(jabber_conn.conn);
         jabber_conn.conn_status = JABBER_DISCONNECTING;
-        return TRUE;
-
-    // if disconnected dont wait just shutdown
-    } else if (jabber_conn.conn_status == JABBER_DISCONNECTED) {
-        log_info("No connection open");
-        return FALSE;
 
-    // any other states, just shutdown
-    } else {
-        return FALSE;
+        while (jabber_get_connection_status() == JABBER_DISCONNECTING) {
+            jabber_process_events();
+        }
+        jabber_free_resources();
     }
 }
 
diff --git a/src/jabber.h b/src/jabber.h
index a03566a7..d12d00b3 100644
--- a/src/jabber.h
+++ b/src/jabber.h
@@ -43,7 +43,7 @@ typedef enum {
 void jabber_init(const int disable_tls);
 jabber_conn_status_t jabber_connect(const char * const user,
     const char * const passwd);
-gboolean jabber_disconnect(void);
+void jabber_disconnect(void);
 void jabber_roster_request(void);
 void jabber_process_events(void);
 void jabber_send(const char * const msg, const char * const recipient);
diff --git a/src/profanity.c b/src/profanity.c
index 22144376..261410ff 100644
--- a/src/profanity.c
+++ b/src/profanity.c
@@ -292,15 +292,7 @@ _init(const int disable_tls, char *log_level)
 static void
 _shutdown(void)
 {
-    gboolean wait_response = jabber_disconnect();
-
-    if (wait_response) {
-        while (jabber_get_connection_status() == JABBER_DISCONNECTING) {
-            jabber_process_events();
-        }
-        jabber_free_resources();
-    }
-
+    jabber_disconnect();
     contact_list_clear();
     gui_close();
     chat_log_close();