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);
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;
timeout_remove(&client->to_destroy);
- imap_urlauth_worker_client_disconnect(client);
+ imap_urlauth_worker_client_deinit(&client->worker_client);
o_stream_destroy(&client->output);
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;
/* settings: */
const struct imap_urlauth_settings *set;
- enum imap_urlauth_worker_state worker_state;
+ struct imap_urlauth_worker_client *worker_client;
bool disconnected:1;
};
/* 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;
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;
}
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;
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;
#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