Always signal a disconnect after connection_do_close()
authorFrank Zschockelt <lm@freakysoft.de>
Sat, 11 May 2019 22:14:44 +0200
changeset 735 7ae46452fb10
parent 734 866607b4c186
child 736 97f3ff94976f
Always signal a disconnect after connection_do_close()
loudmouth/lm-connection.c
loudmouth/lm-feature-ping.c
--- a/loudmouth/lm-connection.c	Sat May 04 18:24:41 2019 +0200
+++ b/loudmouth/lm-connection.c	Sat May 11 22:14:44 2019 +0200
@@ -896,6 +896,15 @@
                               gboolean      result,
                               LmConnection *connection)
 {
+    /* FIXME: Set up according to XMPP 1.0 specification */
+    /*        StartTLS and the like */
+    if (result == TRUE && !connection_send (connection,
+                          "<?xml version='1.0' encoding='UTF-8'?>", -1,
+                          NULL)) {
+        lm_verbose ("Failed to send xml version and encoding\n");
+        result = FALSE;
+    }
+
     if (result == FALSE) {
         connection_do_close (connection);
 
@@ -909,21 +918,9 @@
             _lm_utils_free_callback (cb);
         }
 
-        return;
+    } else {
+        connection_send_stream_header (connection);
     }
-
-    /* FIXME: Set up according to XMPP 1.0 specification */
-    /*        StartTLS and the like */
-    if (!connection_send (connection,
-                          "<?xml version='1.0' encoding='UTF-8'?>", -1,
-                          NULL)) {
-        lm_verbose ("Failed to send xml version and encoding\n");
-        connection_do_close (connection);
-
-        return;
-    }
-
-    connection_send_stream_header (connection);
 }
 
 static gboolean
@@ -969,6 +966,7 @@
     if (!lm_connection_send (connection, m, NULL)) {
         lm_verbose ("Failed to send stream information\n");
         connection_do_close (connection);
+        connection_signal_disconnect (connection, LM_DISCONNECT_REASON_ERROR);
     }
 
     lm_message_unref (m);
@@ -1040,11 +1038,12 @@
     lm_message_unref (m);
     if (result < 0) {
         connection_do_close (connection);
+        connection_signal_disconnect (connection, LM_DISCONNECT_REASON_ERROR);
+    } else {
+        /* We may finally tell the client they're authorized */
+        connection_call_auth_cb (connection, TRUE);
     }
 
-    /* We may finally tell the client they're authorized */
-    connection_call_auth_cb (connection, TRUE);
-
     return LM_HANDLER_RESULT_REMOVE_MESSAGE;
 }
 
@@ -1125,6 +1124,8 @@
             g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
                    "%s: can't send resource binding request\n", G_STRFUNC);
             connection_do_close (connection);
+            connection_signal_disconnect (connection,
+                                          LM_DISCONNECT_REASON_ERROR);
         }
     }
 
--- a/loudmouth/lm-feature-ping.c	Sat May 04 18:24:41 2019 +0200
+++ b/loudmouth/lm-feature-ping.c	Sat May 11 22:14:44 2019 +0200
@@ -193,13 +193,6 @@
     if (priv->keep_alive_counter > 3) {
         g_signal_emit (fp, signals[TIMED_OUT], 0);
        return FALSE;
-        /* FIXME */
-#if 0 /* Should be moved to signal callback in LmConnection */
-        connection_do_close (connection);
-        connection_signal_disconnect (connection,
-                                      LM_DISCONNECT_REASON_PING_TIME_OUT);
-#endif
-
     }
 
     server = _lm_connection_get_server (priv->connection);