about summary refs log tree commit diff stats
path: root/src/command.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-10-27 18:12:04 +0100
committerJames Booth <boothj5@gmail.com>2012-10-27 18:12:04 +0100
commit28d388319abd2fc6aafe17ce1d4bc80c2bac5ae5 (patch)
tree52d82445fb3a783469e09b744ccc83e30dd1c9fe /src/command.c
parent852112cda81a861e7895de00233ea20b86c80a82 (diff)
downloadprofani-tty-28d388319abd2fc6aafe17ce1d4bc80c2bac5ae5.tar.gz
Added /disconnect command
Diffstat (limited to 'src/command.c')
-rw-r--r--src/command.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/command.c b/src/command.c
index d5245e0d..938142e4 100644
--- a/src/command.c
+++ b/src/command.c
@@ -65,6 +65,7 @@ static gboolean _cmd_about(const char * const inp, struct cmd_help_t help);
 static gboolean _cmd_prefs(const char * const inp, struct cmd_help_t help);
 static gboolean _cmd_who(const char * const inp, struct cmd_help_t help);
 static gboolean _cmd_connect(const char * const inp, struct cmd_help_t help);
+static gboolean _cmd_disconnect(const char * const inp, struct cmd_help_t help);
 static gboolean _cmd_msg(const char * const inp, struct cmd_help_t help);
 static gboolean _cmd_tiny(const char * const inp, struct cmd_help_t help);
 static gboolean _cmd_close(const char * const inp, struct cmd_help_t help);
@@ -124,6 +125,15 @@ static struct cmd_t main_commands[] =
           "Example: /connect myuser@gmail.com",
           NULL  } } },
 
+    { "/disconnect",
+        _cmd_disconnect,
+        { "/disconnect", "Logout of current jabber session.",
+        { "/disconnect",
+          "------------------",
+          "Disconnect from the current jabber session.",
+          "See the /connect command for connecting again.",
+          NULL  } } },
+
     { "/prefs",
         _cmd_prefs,
         { "/prefs", "Show current preferences.",
@@ -565,6 +575,27 @@ _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();
+    }
+
+    contact_list_clear();
+    jabber_restart();
+    cons_show("%s logged out successfully.", jid);
+    free(jid);
+
+    return TRUE;
+}
+
+static gboolean
 _cmd_quit(const char * const inp, struct cmd_help_t help)
 {
     log_info("Profanity is shutting down...");