]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Use io_stream_get_disconnect_reason() instead of duplicating its code all over the...
authorTimo Sirainen <tss@iki.fi>
Mon, 24 Aug 2015 09:14:40 +0000 (12:14 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 24 Aug 2015 09:14:40 +0000 (12:14 +0300)
src/imap/imap-client.c
src/lib/connection.c
src/lmtp/client.c
src/login-common/client-common-auth.c
src/pop3/pop3-client.c

index e8d6ba0a4c07460a293c0b4ee7fca967903a92f8..57f38abac805a09ee00f230686cd2fa2fdfe13ab 100644 (file)
@@ -6,6 +6,7 @@
 #include "str.h"
 #include "hostpid.h"
 #include "net.h"
+#include "iostream.h"
 #include "istream.h"
 #include "ostream.h"
 #include "time-util.h"
@@ -248,19 +249,6 @@ static const char *client_stats(struct client *client)
        return str_c(str);
 }
 
-static const char *client_get_disconnect_reason(struct client *client)
-{
-       errno = client->input->stream_errno != 0 ?
-               client->input->stream_errno :
-               client->output->stream_errno;
-       if (errno == 0 || errno == EPIPE)
-               return "Connection closed";
-       return t_strdup_printf("Connection closed: %s",
-                              client->input->stream_errno != 0 ?
-                              i_stream_get_error(client->input) :
-                              o_stream_get_error(client->output));
-}
-
 void client_destroy(struct client *client, const char *reason)
 {
        client->v.destroy(client, reason);
@@ -275,8 +263,10 @@ static void client_default_destroy(struct client *client, const char *reason)
 
        if (!client->disconnected) {
                client->disconnected = TRUE;
-               if (reason == NULL)
-                       reason = client_get_disconnect_reason(client);
+               if (reason == NULL) {
+                       reason = io_stream_get_disconnect_reason(client->input,
+                                                                client->output);
+               }
                i_info("%s %s", reason, client_stats(client));
        }
 
index 17d1c081916b0ac5e342fce3a59012a79775953c..103c173d022f9c5e9e6363af1363545d952e4820 100644 (file)
@@ -4,6 +4,7 @@
 #include "ioloop.h"
 #include "istream.h"
 #include "ostream.h"
+#include "iostream.h"
 #include "net.h"
 #include "strescape.h"
 #include "llist.h"
@@ -358,23 +359,7 @@ int connection_input_read(struct connection *conn)
 
 const char *connection_disconnect_reason(struct connection *conn)
 {
-       const char *errstr;
-
-       if (conn->input != NULL && conn->input->stream_errno != 0) {
-               errno = conn->input->stream_errno;
-               errstr = i_stream_get_error(conn->input);
-       } else if (conn->output != NULL && conn->output->stream_errno != 0) {
-               errno = conn->output->stream_errno;
-               errstr = o_stream_get_error(conn->output);
-       } else {
-               errno = 0;
-               errstr = "";
-       }
-
-       if (errno == 0 || errno == EPIPE)
-               return "Connection closed";
-       else
-               return t_strdup_printf("Connection closed: %s", errstr);
+       return io_stream_get_disconnect_reason(conn->input, conn->output);
 }
 
 void connection_switch_ioloop(struct connection *conn)
index 51a05f73b94ab52a04353cc2b2e53b3ddf8d670b..0246df2b0b508aafdfb7d252180a0f1ae8ec3e71 100644 (file)
@@ -5,6 +5,7 @@
 #include "base64.h"
 #include "str.h"
 #include "llist.h"
+#include "iostream.h"
 #include "istream.h"
 #include "ostream.h"
 #include "hostpid.h"
@@ -323,16 +324,9 @@ static const char *client_get_disconnect_reason(struct client *client)
                                               err);
                }
        }
-       errno = client->input->stream_errno != 0 ?
-               client->input->stream_errno :
-               client->output->stream_errno;
-       if (errno == 0 || errno == EPIPE)
-               return "Connection closed";
-       return t_strdup_printf("Connection closed: %s",
-                              client->input->stream_errno != 0 ?
-                              i_stream_get_error(client->input) :
-                              o_stream_get_error(client->output));
+       return io_stream_get_disconnect_reason(client->input, client->output);
 }
+
 void client_disconnect(struct client *client, const char *prefix,
                       const char *reason)
 {
index 8f4151f0e677667fd8bef5e3a2a07a0ebdf58038..8d95910b48fa55e0307e7be62ec8d75aad10cf63 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "hostpid.h"
 #include "login-common.h"
+#include "iostream.h"
 #include "istream.h"
 #include "ostream.h"
 #include "str.h"
@@ -216,13 +217,6 @@ void client_proxy_failed(struct client *client, bool send_line)
        client_auth_failed(client);
 }
 
-static const char *get_disconnect_reason(struct istream *input)
-{
-       errno = input->stream_errno;
-       return errno == 0 || errno == EPIPE ? "Connection closed" :
-               t_strdup_printf("Connection closed: %m");
-}
-
 static void proxy_input(struct client *client)
 {
        struct istream *input;
@@ -262,7 +256,7 @@ static void proxy_input(struct client *client)
                        "(state=%u, duration=%us)%s",
                        login_proxy_get_host(client->login_proxy),
                        login_proxy_get_port(client->login_proxy),
-                       get_disconnect_reason(input),
+                       io_stream_get_disconnect_reason(input, NULL),
                        client->proxy_state, duration,
                        line == NULL ? "" : t_strdup_printf(
                                " - BUG: line not read: %s", line)));
index 36d863b6bb21a113148fdb4758d527584f6bed95..31a0384ee4b88b0283428b513796b0a7beeb611d 100644 (file)
@@ -4,6 +4,7 @@
 #include "array.h"
 #include "ioloop.h"
 #include "net.h"
+#include "iostream.h"
 #include "istream.h"
 #include "ostream.h"
 #include "crc32.h"
@@ -556,18 +557,6 @@ static const char *client_stats(struct client *client)
        return str_c(str);
 }
 
-static const char *client_get_disconnect_reason(struct client *client)
-{
-       errno = client->input->stream_errno != 0 ?
-               client->input->stream_errno :
-               client->output->stream_errno;
-       if (errno == 0 || errno == EPIPE)
-               return "Connection closed";
-       return t_strdup_printf("Connection closed: %s",
-                              client->input->stream_errno != 0 ?
-                              i_stream_get_error(client->input) :
-                              o_stream_get_error(client->output));
-}
 void client_destroy(struct client *client, const char *reason)
 {
        client->v.destroy(client, reason);
@@ -579,8 +568,10 @@ static void client_default_destroy(struct client *client, const char *reason)
                (void)client_update_mails(client);
 
        if (!client->disconnected) {
-               if (reason == NULL)
-                       reason = client_get_disconnect_reason(client);
+               if (reason == NULL) {
+                       reason = io_stream_get_disconnect_reason(client->input,
+                                                                client->output);
+               }
                i_info("%s %s", reason, client_stats(client));
        }