Show more information about connections.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 10 Mar 2007 22:02:46 +0000 (23:02 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 10 Mar 2007 22:02:46 +0000 (23:02 +0100)
NEWS
src/admin.c
src/client.c
src/network.c
src/network.h

diff --git a/NEWS b/NEWS
index ec648862dc72cebe5512492831793da71cc3197d..1c5b0bc2f667421756c81301e5967a6e5dc0c7fd 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -28,6 +28,8 @@ Ctrlproxy 3.0.2 UNRELEASED
 
        * Do some more config checking (#102)
 
+       * Show disconnect reason in admin network (#100)
+
   PORTABILITY
 
     * Looks for check using pkg-config now.
index c32971532d2171245ffca50ce346eae6be72ea24..4c07d1bc9927561c2cfecee0668ada00d9e2c6ab 100644 (file)
@@ -284,14 +284,18 @@ static void list_networks(admin_handle h, char **args, void *userdata)
 
                switch (n->connection.state) {
                case NETWORK_CONNECTION_STATE_NOT_CONNECTED:
-                       admin_out(h, ("%s: Not connected"), n->name);
+                       if (n->connection.data.tcp.last_disconnect_reason)
+                               admin_out(h, "%s: Not connected: %s", n->name, 
+                                                 n->connection.data.tcp.last_disconnect_reason);
+                       else
+                               admin_out(h, "%s: Not connected", n->name);
                        break;
                case NETWORK_CONNECTION_STATE_RECONNECT_PENDING:
-                       admin_out(h, ("%s: Reconnecting"), n->name);
+                       admin_out(h, "%s: Reconnecting", n->name);
                        break;
                case NETWORK_CONNECTION_STATE_LOGIN_SENT:
                case NETWORK_CONNECTION_STATE_MOTD_RECVD:
-                       admin_out(h, ("%s: connected"), n->name);
+                       admin_out(h, "%s: connected", n->name);
                        break;
                }
        }
index 4c767517681c602ad13baa8d06ce8df787e0ed45..e98d6cd55f38b182f102f8e53551eeb24f9cefd4 100644 (file)
@@ -120,7 +120,14 @@ static gboolean process_from_client(struct client *c, struct line *l)
                        network_send_line(c->network, c, l);
                }
        } else if(c->network->connection.state == NETWORK_CONNECTION_STATE_NOT_CONNECTED) {
-               client_send_args(c, "NOTICE", c->nick?c->nick:c->network->state->me.nick, "Currently not connected to server...", NULL);
+               char *msg;
+               if (c->network->connection.data.tcp.last_disconnect_reason == NULL)
+                       msg = g_strdup("Currently not connected to server...");
+               else
+                       msg = g_strdup_printf("Currently not connected to server... (%s)",
+                                       c->network->connection.data.tcp.last_disconnect_reason);
+
+               client_send_args(c, "NOTICE", c->nick?c->nick:c->network->state->me.nick, msg, NULL);
        }
 
        return TRUE;
index f5b7b21000f128cda698e22b3f9be8e25d2de883..556c1cf8a2343a88e6f8d853195f48966c1abb4a 100644 (file)
@@ -192,6 +192,20 @@ static gboolean process_from_server(struct network *n, struct line *l)
        return TRUE;
 }
 
+static void network_report_disconnect(struct network *n, const char *fmt, ...)
+{
+       va_list ap;
+       char *tmp;
+       va_start(ap, fmt);
+       tmp = g_strdup_vprintf(fmt, ap);
+       va_end(ap);
+
+       g_free(n->connection.data.tcp.last_disconnect_reason);
+       n->connection.data.tcp.last_disconnect_reason = tmp;
+
+       log_network(LOG_WARNING, n, "%s", tmp);
+}
+
 static gboolean handle_server_receive (GIOChannel *c, GIOCondition cond, void *_server)
 {
        struct network *server = (struct network *)_server;
@@ -202,13 +216,13 @@ static gboolean handle_server_receive (GIOChannel *c, GIOCondition cond, void *_
        g_assert(server);
 
        if ((cond & G_IO_HUP)) {
-               log_network(LOG_WARNING, server, "Hangup from server, scheduling reconnect");
+               network_report_disconnect(server, "Hangup from server, scheduling reconnect");
                reconnect(server, FALSE);
                return FALSE;
        }
 
        if ((cond & G_IO_ERR)) {
-               log_network(LOG_WARNING, server, "Error from server, scheduling reconnect");
+               network_report_disconnect(server, "Error from server, scheduling reconnect");
                reconnect(server, FALSE);
                return FALSE;
        }
@@ -245,7 +259,7 @@ static gboolean handle_server_receive (GIOChannel *c, GIOCondition cond, void *_
                }
 
                if (status != G_IO_STATUS_AGAIN) {
-                       log_network(LOG_WARNING, server, 
+                       network_report_disconnect(server, 
                                "Error \"%s\" reading from server, reconnecting in %ds...",
                                err?err->message:"UNKNOWN", server->config->reconnect_interval);
                        reconnect(server, FALSE);
index f1c09817f343bad278a4c7b49f8d6427965a31b5..44ee0c3c9f49507786a0904d77493046316832ad 100644 (file)
@@ -66,6 +66,7 @@ struct network_connection {
                        struct sockaddr *remote_name;
                        struct sockaddr *local_name;
                        socklen_t namelen;
+                       const char *last_disconnect_reason;
                } tcp;
                
                struct {