]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap-urlauth: imap-urlauth-worker-client - Make the worker a separate struct.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Wed, 3 Aug 2022 01:32:36 +0000 (03:32 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 24 Mar 2023 07:14:54 +0000 (07:14 +0000)
src/imap-urlauth/imap-urlauth-client.c
src/imap-urlauth/imap-urlauth-client.h
src/imap-urlauth/imap-urlauth-worker-client.c
src/imap-urlauth/imap-urlauth-worker-client.h

index 5b55904276e0689daf7a6fa5193727c1e5d2c141..83b9a6e92e3b0fcf74c94d6019048862d0a0f952 100644 (file)
@@ -54,7 +54,6 @@ int client_create(const char *service, const char *username,
        client = i_new(struct client, 1);
        client->fd_in = fd_in;
        client->fd_out = fd_out;
-       client->fd_ctrl = -1;
        client->set = set;
 
        client->event = event_create(NULL);
@@ -63,7 +62,8 @@ int client_create(const char *service, const char *username,
        event_set_append_log_prefix(client->event, t_strdup_printf(
                "user %s: ", username));
 
-       if (imap_urlauth_worker_client_connect(client) < 0) {
+       client->worker_client = imap_urlauth_worker_client_init(client);
+       if (imap_urlauth_worker_client_connect(client->worker_client) < 0) {
                event_unref(&client->event);
                i_free(client);
                return -1;
@@ -138,7 +138,7 @@ void client_destroy(struct client *client, const char *reason)
 
        timeout_remove(&client->to_destroy);
 
-       imap_urlauth_worker_client_disconnect(client);
+       imap_urlauth_worker_client_deinit(&client->worker_client);
 
        o_stream_destroy(&client->output);
 
index d6015d5f323054af067231b3dbe0d14abbd9adf4..6a49b746840ed632ac1c9062e72874da32e8a431 100644 (file)
@@ -4,19 +4,11 @@
 struct client;
 struct mail_storage;
 
-enum imap_urlauth_worker_state {
-       IMAP_URLAUTH_WORKER_STATE_INACTIVE = 0,
-       IMAP_URLAUTH_WORKER_STATE_CONNECTED,
-       IMAP_URLAUTH_WORKER_STATE_ACTIVE,
-};
-
 struct client {
        struct client *prev, *next;
 
-       int fd_in, fd_out, fd_ctrl;
-       struct io *ctrl_io;
-       struct ostream *output, *ctrl_output;
-       struct istream *ctrl_input;
+       int fd_in, fd_out;
+       struct ostream *output;
        struct timeout *to_destroy;
        struct event *event;
 
@@ -26,7 +18,7 @@ struct client {
        /* settings: */
        const struct imap_urlauth_settings *set;
 
-       enum imap_urlauth_worker_state worker_state;
+       struct imap_urlauth_worker_client *worker_client;
 
        bool disconnected:1;
 };
index 0a945353925763e46e14a95d1555e47364b14161..4d0a4cf42166c6f9014a6499889331cb3264c39c 100644 (file)
 /* max. length of input lines (URLs) */
 #define MAX_INBUF_SIZE 2048
 
-static void client_worker_input(struct client *wclient);
+enum imap_urlauth_worker_state {
+       IMAP_URLAUTH_WORKER_STATE_INACTIVE = 0,
+       IMAP_URLAUTH_WORKER_STATE_CONNECTED,
+       IMAP_URLAUTH_WORKER_STATE_ACTIVE,
+};
 
-int imap_urlauth_worker_client_connect(struct client *wclient)
+struct imap_urlauth_worker_client {
+       struct client *client;
+       int fd_ctrl;
+       struct io *ctrl_io;
+       struct ostream *ctrl_output;
+       struct istream *ctrl_input;
+       struct event *event;
+
+       enum imap_urlauth_worker_state worker_state;
+
+       bool disconnected:1;
+};
+
+static void client_worker_input(struct imap_urlauth_worker_client *wclient);
+
+struct imap_urlauth_worker_client *
+imap_urlauth_worker_client_init(struct client *client)
+{
+       struct imap_urlauth_worker_client *wclient;
+
+       wclient = i_new(struct imap_urlauth_worker_client, 1);
+       wclient->client = client;
+       wclient->fd_ctrl = -1;
+
+       wclient->event = client->event;
+       
+       return wclient;
+}
+
+void imap_urlauth_worker_client_deinit(
+       struct imap_urlauth_worker_client **_wclient)
+{
+       struct imap_urlauth_worker_client *wclient = *_wclient;
+
+       if (wclient == NULL)
+               return;
+       *_wclient = NULL;
+
+       imap_urlauth_worker_client_disconnect(wclient);
+       i_free(wclient);
+}
+
+int imap_urlauth_worker_client_connect(
+       struct imap_urlauth_worker_client *wclient)
 {
-       struct client *client = wclient;
+       struct client *client = wclient->client;
        static const char handshake[] = "VERSION\timap-urlauth-worker\t2\t0\n";
        const char *socket_path;
        ssize_t ret;
@@ -85,7 +132,8 @@ int imap_urlauth_worker_client_connect(struct client *wclient)
        return 0;
 }
 
-void imap_urlauth_worker_client_disconnect(struct client *wclient)
+void imap_urlauth_worker_client_disconnect(
+       struct imap_urlauth_worker_client *wclient)
 {
        wclient->worker_state = IMAP_URLAUTH_WORKER_STATE_INACTIVE;
 
@@ -99,15 +147,18 @@ void imap_urlauth_worker_client_disconnect(struct client *wclient)
 }
 
 static void
-imap_urlauth_worker_client_error(struct client *wclient, const char *error)
+imap_urlauth_worker_client_error(struct imap_urlauth_worker_client *wclient,
+                                const char *error)
 {
-       client_disconnect(wclient, error);
+       client_disconnect(wclient->client, error);
+       imap_urlauth_worker_client_disconnect(wclient);
 }
 
 static int
-client_worker_input_line(struct client *wclient, const char *response)
+client_worker_input_line(struct imap_urlauth_worker_client *wclient,
+                        const char *response)
 {
-       struct client *client = wclient;
+       struct client *client = wclient->client;
        const char *const *apps;
        unsigned int count, i;
        bool restart;
@@ -197,7 +248,7 @@ client_worker_input_line(struct client *wclient, const char *response)
        return 0;
 }
 
-static void client_worker_input(struct client *wclient)
+static void client_worker_input(struct imap_urlauth_worker_client *wclient)
 {
        struct istream *input = wclient->ctrl_input;
        const char *line;
index 70304ab013f8a2b11eaa0da2f9734b5fbbc8b0a8..f799928d2b653e2a63474fe8141563cc3bf6656b 100644 (file)
@@ -3,7 +3,14 @@
 
 #include "imap-urlauth-worker-common.h"
 
-int imap_urlauth_worker_client_connect(struct client *wclient);
-void imap_urlauth_worker_client_disconnect(struct client *wclient);
+struct imap_urlauth_worker_client *
+imap_urlauth_worker_client_init(struct client *client);
+void imap_urlauth_worker_client_deinit(
+       struct imap_urlauth_worker_client **_wclient);
+
+int imap_urlauth_worker_client_connect(
+       struct imap_urlauth_worker_client *wclient);
+void imap_urlauth_worker_client_disconnect(
+       struct imap_urlauth_worker_client *wclient);
 
 #endif