about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-05-10 23:18:11 +0100
committerJames Booth <boothj5@gmail.com>2016-05-10 23:18:11 +0100
commit3d20c85ada04c4dbd1552671d87ef1729d78a1c8 (patch)
tree33cd70ba98cf83f54dc4f0f329ab876ac83c7243
parent22c4d91c5068d1fd194ee0383dc6f4b5cf86cdeb (diff)
downloadprofani-tty-3d20c85ada04c4dbd1552671d87ef1729d78a1c8.tar.gz
Remove JABBER_STARTED, JABBER_UNDEFINED connection states
-rw-r--r--src/command/commands.c2
-rw-r--r--src/xmpp/connection.c13
-rw-r--r--src/xmpp/connection.h1
-rw-r--r--src/xmpp/session.c19
-rw-r--r--src/xmpp/xmpp.h2
-rw-r--r--tests/unittests/test_cmd_bookmark.c10
-rw-r--r--tests/unittests/test_cmd_bookmark.h1
-rw-r--r--tests/unittests/test_cmd_connect.c5
-rw-r--r--tests/unittests/test_cmd_join.c5
-rw-r--r--tests/unittests/test_cmd_otr.c20
-rw-r--r--tests/unittests/test_cmd_otr.h2
-rw-r--r--tests/unittests/test_cmd_pgp.c10
-rw-r--r--tests/unittests/test_cmd_pgp.h1
-rw-r--r--tests/unittests/test_cmd_rooms.c10
-rw-r--r--tests/unittests/test_cmd_rooms.h1
-rw-r--r--tests/unittests/test_cmd_roster.c5
-rw-r--r--tests/unittests/unittests.c15
17 files changed, 18 insertions, 104 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index 3cbca95e..f64c16e6 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -354,7 +354,7 @@ gboolean
 cmd_connect(ProfWin *window, const char *const command, gchar **args)
 {
     jabber_conn_status_t conn_status = connection_get_status();
-    if ((conn_status != JABBER_DISCONNECTED) && (conn_status != JABBER_STARTED)) {
+    if (conn_status != JABBER_DISCONNECTED) {
         cons_show("You are either connected already, or a login is in process.");
         return TRUE;
     }
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index c93cb35a..d73d73c5 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -81,7 +81,7 @@ void
 connection_init(void)
 {
     xmpp_initialize();
-    conn.conn_status = JABBER_STARTED;
+    conn.conn_status = JABBER_DISCONNECTED;
     conn.presence_message = NULL;
     conn.xmpp_conn = NULL;
     conn.xmpp_ctx = NULL;
@@ -174,6 +174,17 @@ connection_connect(const char *const fulljid, const char *const passwd, const ch
     return conn.conn_status;
 }
 
+void
+connection_disconnect(void)
+{
+    conn.conn_status = JABBER_DISCONNECTING;
+    xmpp_disconnect(conn.xmpp_conn);
+
+    while (conn.conn_status == JABBER_DISCONNECTING) {
+        session_process_events(10);
+    }
+}
+
 #ifdef HAVE_LIBMESODE
 TLSCertificate*
 connection_get_tls_peer_cert(void)
diff --git a/src/xmpp/connection.h b/src/xmpp/connection.h
index f4d0e387..b7148769 100644
--- a/src/xmpp/connection.h
+++ b/src/xmpp/connection.h
@@ -41,6 +41,7 @@ void connection_init(void);
 
 jabber_conn_status_t connection_connect(const char *const fulljid, const char *const passwd, const char *const altdomain, int port,
     const char *const tls_policy);
+void connection_disconnect(void);
 
 void connection_set_status(jabber_conn_status_t status);
 void connection_set_presence_msg(const char *const message);
diff --git a/src/xmpp/session.c b/src/xmpp/session.c
index b435a579..7be762a5 100644
--- a/src/xmpp/session.c
+++ b/src/xmpp/session.c
@@ -180,13 +180,7 @@ session_autoping_fail(void)
         const char *fulljid = connection_get_fulljid();
         plugins_on_disconnect(account_name, fulljid);
         accounts_set_last_activity(session_get_account_name());
-        connection_set_status(JABBER_DISCONNECTING);
-        xmpp_disconnect(connection_get_conn());
-
-        while (connection_get_status() == JABBER_DISCONNECTING) {
-            session_process_events(10);
-        }
-
+        connection_disconnect();
         connection_free_conn();
         connection_free_ctx();
     }
@@ -204,17 +198,12 @@ session_disconnect(void)
 {
     // if connected, send end stream and wait for response
     if (connection_get_status() == JABBER_CONNECTED) {
+        log_info("Closing connection");
         char *account_name = session_get_account_name();
         const char *fulljid = connection_get_fulljid();
         plugins_on_disconnect(account_name, fulljid);
-        log_info("Closing connection");
         accounts_set_last_activity(session_get_account_name());
-        connection_set_status(JABBER_DISCONNECTING);
-        xmpp_disconnect(connection_get_conn());
-
-        while (connection_get_status() == JABBER_DISCONNECTING) {
-            session_process_events(10);
-        }
+        connection_disconnect();
         _session_free_saved_account();
         _session_free_saved_details();
         connection_disco_items_free();
@@ -228,7 +217,7 @@ session_disconnect(void)
     connection_free_presence_msg();
     connection_free_domain();
 
-    connection_set_status(JABBER_STARTED);
+    connection_set_status(JABBER_DISCONNECTED);
 }
 
 void
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 167a4bbf..65d2cbad 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -57,8 +57,6 @@
 #define XMPP_FEATURE_BLOCKING "urn:xmpp:blocking"
 
 typedef enum {
-    JABBER_UNDEFINED,
-    JABBER_STARTED,
     JABBER_CONNECTING,
     JABBER_CONNECTED,
     JABBER_DISCONNECTING,
diff --git a/tests/unittests/test_cmd_bookmark.c b/tests/unittests/test_cmd_bookmark.c
index 49ea7b10..8b8b4871 100644
--- a/tests/unittests/test_cmd_bookmark.c
+++ b/tests/unittests/test_cmd_bookmark.c
@@ -46,16 +46,6 @@ void cmd_bookmark_shows_message_when_connecting(void **state)
     test_with_connection_status(JABBER_CONNECTING);
 }
 
-void cmd_bookmark_shows_message_when_started(void **state)
-{
-    test_with_connection_status(JABBER_STARTED);
-}
-
-void cmd_bookmark_shows_message_when_undefined(void **state)
-{
-    test_with_connection_status(JABBER_UNDEFINED);
-}
-
 void cmd_bookmark_shows_usage_when_no_args(void **state)
 {
     gchar *args[] = { NULL };
diff --git a/tests/unittests/test_cmd_bookmark.h b/tests/unittests/test_cmd_bookmark.h
index 9505e105..abbdbe98 100644
--- a/tests/unittests/test_cmd_bookmark.h
+++ b/tests/unittests/test_cmd_bookmark.h
@@ -1,7 +1,6 @@
 void cmd_bookmark_shows_message_when_disconnected(void **state);
 void cmd_bookmark_shows_message_when_disconnecting(void **state);
 void cmd_bookmark_shows_message_when_connecting(void **state);
-void cmd_bookmark_shows_message_when_started(void **state);
 void cmd_bookmark_shows_message_when_undefined(void **state);
 void cmd_bookmark_shows_usage_when_no_args(void **state);
 void cmd_bookmark_list_shows_bookmarks(void **state);
diff --git a/tests/unittests/test_cmd_connect.c b/tests/unittests/test_cmd_connect.c
index 5e3ffa41..e4f01271 100644
--- a/tests/unittests/test_cmd_connect.c
+++ b/tests/unittests/test_cmd_connect.c
@@ -41,11 +41,6 @@ void cmd_connect_shows_message_when_connected(void **state)
     test_with_connection_status(JABBER_CONNECTED);
 }
 
-void cmd_connect_shows_message_when_undefined(void **state)
-{
-    test_with_connection_status(JABBER_UNDEFINED);
-}
-
 void cmd_connect_when_no_account(void **state)
 {
     gchar *args[] = { "user@server.org", NULL };
diff --git a/tests/unittests/test_cmd_join.c b/tests/unittests/test_cmd_join.c
index 690da6a6..8b71c5e5 100644
--- a/tests/unittests/test_cmd_join.c
+++ b/tests/unittests/test_cmd_join.c
@@ -43,11 +43,6 @@ void cmd_join_shows_message_when_disconnected(void **state)
     test_with_connection_status(JABBER_DISCONNECTED);
 }
 
-void cmd_join_shows_message_when_undefined(void **state)
-{
-    test_with_connection_status(JABBER_UNDEFINED);
-}
-
 void cmd_join_shows_error_message_when_invalid_room_jid(void **state)
 {
     gchar *args[] = { "//@@/", NULL };
diff --git a/tests/unittests/test_cmd_otr.c b/tests/unittests/test_cmd_otr.c
index 26f05dcb..44703943 100644
--- a/tests/unittests/test_cmd_otr.c
+++ b/tests/unittests/test_cmd_otr.c
@@ -164,16 +164,6 @@ void cmd_otr_gen_shows_message_when_disconnected(void **state)
     test_with_command_and_connection_status("gen", cmd_otr_gen, JABBER_DISCONNECTED);
 }
 
-void cmd_otr_gen_shows_message_when_undefined(void **state)
-{
-    test_with_command_and_connection_status("gen", cmd_otr_gen, JABBER_UNDEFINED);
-}
-
-void cmd_otr_gen_shows_message_when_started(void **state)
-{
-    test_with_command_and_connection_status("gen", cmd_otr_gen, JABBER_STARTED);
-}
-
 void cmd_otr_gen_shows_message_when_connecting(void **state)
 {
     test_with_command_and_connection_status("gen", cmd_otr_gen, JABBER_CONNECTING);
@@ -209,16 +199,6 @@ void cmd_otr_myfp_shows_message_when_disconnected(void **state)
     test_with_command_and_connection_status("myfp", cmd_otr_myfp, JABBER_DISCONNECTED);
 }
 
-void cmd_otr_myfp_shows_message_when_undefined(void **state)
-{
-    test_with_command_and_connection_status("myfp", cmd_otr_myfp, JABBER_UNDEFINED);
-}
-
-void cmd_otr_myfp_shows_message_when_started(void **state)
-{
-    test_with_command_and_connection_status("myfp", cmd_otr_myfp, JABBER_STARTED);
-}
-
 void cmd_otr_myfp_shows_message_when_connecting(void **state)
 {
     test_with_command_and_connection_status("myfp", cmd_otr_myfp, JABBER_CONNECTING);
diff --git a/tests/unittests/test_cmd_otr.h b/tests/unittests/test_cmd_otr.h
index 4f00b6b1..5343cc57 100644
--- a/tests/unittests/test_cmd_otr.h
+++ b/tests/unittests/test_cmd_otr.h
@@ -13,12 +13,10 @@ void cmd_otr_gen_shows_message_when_not_connected(void **state);
 void cmd_otr_gen_generates_key_for_connected_account(void **state);
 void cmd_otr_gen_shows_message_when_disconnected(void **state);
 void cmd_otr_gen_shows_message_when_undefined(void **state);
-void cmd_otr_gen_shows_message_when_started(void **state);
 void cmd_otr_gen_shows_message_when_connecting(void **state);
 void cmd_otr_gen_shows_message_when_disconnecting(void **state);
 void cmd_otr_myfp_shows_message_when_disconnected(void **state);
 void cmd_otr_myfp_shows_message_when_undefined(void **state);
-void cmd_otr_myfp_shows_message_when_started(void **state);
 void cmd_otr_myfp_shows_message_when_connecting(void **state);
 void cmd_otr_myfp_shows_message_when_disconnecting(void **state);
 void cmd_otr_myfp_shows_message_when_no_key(void **state);
diff --git a/tests/unittests/test_cmd_pgp.c b/tests/unittests/test_cmd_pgp.c
index ee057018..ec010cce 100644
--- a/tests/unittests/test_cmd_pgp.c
+++ b/tests/unittests/test_cmd_pgp.c
@@ -55,16 +55,6 @@ void cmd_pgp_start_shows_message_when_connecting(void **state)
     cmd_pgp_start_shows_message_when_connection(JABBER_CONNECTING);
 }
 
-void cmd_pgp_start_shows_message_when_undefined(void **state)
-{
-    cmd_pgp_start_shows_message_when_connection(JABBER_UNDEFINED);
-}
-
-void cmd_pgp_start_shows_message_when_started(void **state)
-{
-    cmd_pgp_start_shows_message_when_connection(JABBER_STARTED);
-}
-
 void cmd_pgp_start_shows_message_when_no_arg_in_wintype(win_type_t wintype)
 {
     gchar *args[] = { "start", NULL };
diff --git a/tests/unittests/test_cmd_pgp.h b/tests/unittests/test_cmd_pgp.h
index fcb24500..0d681a4a 100644
--- a/tests/unittests/test_cmd_pgp.h
+++ b/tests/unittests/test_cmd_pgp.h
@@ -6,7 +6,6 @@ void cmd_pgp_start_shows_message_when_disconnected(void **state);
 void cmd_pgp_start_shows_message_when_disconnecting(void **state);
 void cmd_pgp_start_shows_message_when_connecting(void **state);
 void cmd_pgp_start_shows_message_when_undefined(void **state);
-void cmd_pgp_start_shows_message_when_started(void **state);
 void cmd_pgp_start_shows_message_when_no_arg_in_console(void **state);
 void cmd_pgp_start_shows_message_when_no_arg_in_muc(void **state);
 void cmd_pgp_start_shows_message_when_no_arg_in_mucconf(void **state);
diff --git a/tests/unittests/test_cmd_rooms.c b/tests/unittests/test_cmd_rooms.c
index f4364215..85a528b5 100644
--- a/tests/unittests/test_cmd_rooms.c
+++ b/tests/unittests/test_cmd_rooms.c
@@ -41,16 +41,6 @@ void cmd_rooms_shows_message_when_connecting(void **state)
     test_with_connection_status(JABBER_CONNECTING);
 }
 
-void cmd_rooms_shows_message_when_started(void **state)
-{
-    test_with_connection_status(JABBER_STARTED);
-}
-
-void cmd_rooms_shows_message_when_undefined(void **state)
-{
-    test_with_connection_status(JABBER_UNDEFINED);
-}
-
 void cmd_rooms_uses_account_default_when_no_arg(void **state)
 {
     gchar *args[] = { NULL };
diff --git a/tests/unittests/test_cmd_rooms.h b/tests/unittests/test_cmd_rooms.h
index a9a7af83..1b13cf07 100644
--- a/tests/unittests/test_cmd_rooms.h
+++ b/tests/unittests/test_cmd_rooms.h
@@ -1,7 +1,6 @@
 void cmd_rooms_shows_message_when_disconnected(void **state);
 void cmd_rooms_shows_message_when_disconnecting(void **state);
 void cmd_rooms_shows_message_when_connecting(void **state);
-void cmd_rooms_shows_message_when_started(void **state);
 void cmd_rooms_shows_message_when_undefined(void **state);
 void cmd_rooms_uses_account_default_when_no_arg(void **state);
 void cmd_rooms_arg_used_when_passed(void **state);
diff --git a/tests/unittests/test_cmd_roster.c b/tests/unittests/test_cmd_roster.c
index bd624642..8b194de4 100644
--- a/tests/unittests/test_cmd_roster.c
+++ b/tests/unittests/test_cmd_roster.c
@@ -42,11 +42,6 @@ void cmd_roster_shows_message_when_disconnected(void **state)
     test_with_connection_status(JABBER_DISCONNECTED);
 }
 
-void cmd_roster_shows_message_when_undefined(void **state)
-{
-    test_with_connection_status(JABBER_UNDEFINED);
-}
-
 void cmd_roster_shows_roster_when_no_args(void **state)
 {
     gchar *args[] = { NULL };
diff --git a/tests/unittests/unittests.c b/tests/unittests/unittests.c
index 7baa9615..2c3d6ce5 100644
--- a/tests/unittests/unittests.c
+++ b/tests/unittests/unittests.c
@@ -238,9 +238,6 @@ int main(int argc, char* argv[]) {
         unit_test_setup_teardown(cmd_connect_shows_message_when_connected,
             load_preferences,
             close_preferences),
-        unit_test_setup_teardown(cmd_connect_shows_message_when_undefined,
-            load_preferences,
-            close_preferences),
         unit_test_setup_teardown(cmd_connect_when_no_account,
             load_preferences,
             close_preferences),
@@ -308,8 +305,6 @@ int main(int argc, char* argv[]) {
         unit_test(cmd_rooms_shows_message_when_disconnected),
         unit_test(cmd_rooms_shows_message_when_disconnecting),
         unit_test(cmd_rooms_shows_message_when_connecting),
-        unit_test(cmd_rooms_shows_message_when_started),
-        unit_test(cmd_rooms_shows_message_when_undefined),
         unit_test(cmd_rooms_uses_account_default_when_no_arg),
         unit_test(cmd_rooms_arg_used_when_passed),
 
@@ -484,8 +479,6 @@ int main(int argc, char* argv[]) {
         unit_test(cmd_bookmark_shows_message_when_disconnected),
         unit_test(cmd_bookmark_shows_message_when_disconnecting),
         unit_test(cmd_bookmark_shows_message_when_connecting),
-        unit_test(cmd_bookmark_shows_message_when_started),
-        unit_test(cmd_bookmark_shows_message_when_undefined),
         unit_test(cmd_bookmark_shows_usage_when_no_args),
         unit_test(cmd_bookmark_list_shows_bookmarks),
         unit_test(cmd_bookmark_add_shows_message_when_invalid_jid),
@@ -518,13 +511,9 @@ int main(int argc, char* argv[]) {
         unit_test(cmd_otr_gen_shows_message_when_not_connected),
         unit_test(cmd_otr_gen_generates_key_for_connected_account),
         unit_test(cmd_otr_gen_shows_message_when_disconnected),
-        unit_test(cmd_otr_gen_shows_message_when_undefined),
-        unit_test(cmd_otr_gen_shows_message_when_started),
         unit_test(cmd_otr_gen_shows_message_when_connecting),
         unit_test(cmd_otr_gen_shows_message_when_disconnecting),
         unit_test(cmd_otr_myfp_shows_message_when_disconnected),
-        unit_test(cmd_otr_myfp_shows_message_when_undefined),
-        unit_test(cmd_otr_myfp_shows_message_when_started),
         unit_test(cmd_otr_myfp_shows_message_when_connecting),
         unit_test(cmd_otr_myfp_shows_message_when_disconnecting),
         unit_test(cmd_otr_myfp_shows_message_when_no_key),
@@ -551,8 +540,6 @@ int main(int argc, char* argv[]) {
         unit_test(cmd_pgp_start_shows_message_when_disconnected),
         unit_test(cmd_pgp_start_shows_message_when_disconnecting),
         unit_test(cmd_pgp_start_shows_message_when_connecting),
-        unit_test(cmd_pgp_start_shows_message_when_undefined),
-        unit_test(cmd_pgp_start_shows_message_when_started),
         unit_test(cmd_pgp_start_shows_message_when_no_arg_in_console),
         unit_test(cmd_pgp_start_shows_message_when_no_arg_in_muc),
         unit_test(cmd_pgp_start_shows_message_when_no_arg_in_mucconf),
@@ -565,7 +552,6 @@ int main(int argc, char* argv[]) {
         unit_test(cmd_join_shows_message_when_disconnecting),
         unit_test(cmd_join_shows_message_when_connecting),
         unit_test(cmd_join_shows_message_when_disconnected),
-        unit_test(cmd_join_shows_message_when_undefined),
         unit_test(cmd_join_shows_error_message_when_invalid_room_jid),
         unit_test(cmd_join_uses_account_mucservice_when_no_service_specified),
         unit_test(cmd_join_uses_supplied_nick),
@@ -575,7 +561,6 @@ int main(int argc, char* argv[]) {
         unit_test(cmd_roster_shows_message_when_disconnecting),
         unit_test(cmd_roster_shows_message_when_connecting),
         unit_test(cmd_roster_shows_message_when_disconnected),
-        unit_test(cmd_roster_shows_message_when_undefined),
         unit_test(cmd_roster_shows_roster_when_no_args),
         unit_test(cmd_roster_add_shows_message_when_no_jid),
         unit_test(cmd_roster_add_sends_roster_add_request),