dovecot-2.1: Moved imapc-client into its own lib-imap-client lib...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Sep 26 15:28:38 EEST 2011
details: http://hg.dovecot.org/dovecot-2.1/rev/743ebecc1224
changeset: 13554:743ebecc1224
user: Timo Sirainen <tss at iki.fi>
date: Mon Sep 26 15:34:58 2011 +0300
description:
Moved imapc-client into its own lib-imap-client library.
diffstat:
configure.in | 3 +-
src/Makefile.am | 1 +
src/lib-imap-client/Makefile.am | 22 +
src/lib-imap-client/imapc-client-private.h | 40 +
src/lib-imap-client/imapc-client.c | 444 +++++
src/lib-imap-client/imapc-client.h | 155 +
src/lib-imap-client/imapc-connection.c | 1758 ++++++++++++++++++++
src/lib-imap-client/imapc-connection.h | 56 +
src/lib-imap-client/imapc-msgmap.c | 88 +
src/lib-imap-client/imapc-msgmap.h | 17 +
src/lib-storage/index/imapc/Makefile.am | 10 +-
src/lib-storage/index/imapc/imapc-client-private.h | 35 -
src/lib-storage/index/imapc/imapc-client.c | 402 ----
src/lib-storage/index/imapc/imapc-client.h | 151 -
src/lib-storage/index/imapc/imapc-connection.c | 1704 -------------------
src/lib-storage/index/imapc/imapc-connection.h | 54 -
src/lib-storage/index/imapc/imapc-msgmap.c | 88 -
src/lib-storage/index/imapc/imapc-msgmap.h | 17 -
18 files changed, 2584 insertions(+), 2461 deletions(-)
diffs (truncated from 5162 to 300 lines):
diff -r af13ef62d083 -r 743ebecc1224 configure.in
--- a/configure.in Sun Sep 25 22:32:04 2011 +0000
+++ b/configure.in Mon Sep 26 15:34:58 2011 +0300
@@ -2435,7 +2435,7 @@
sdbox_libs='$(top_builddir)/src/lib-storage/index/dbox-single/libstorage_dbox_single.la'
mdbox_libs='$(top_builddir)/src/lib-storage/index/dbox-multi/libstorage_dbox_multi.la'
cydir_libs='$(top_builddir)/src/lib-storage/index/cydir/libstorage_cydir.la'
-imapc_libs='$(top_builddir)/src/lib-storage/index/imapc/libstorage_imapc.la $(top_builddir)/src/lib-ssl-iostream/libssl_iostream.la'
+imapc_libs='$(top_builddir)/src/lib-storage/index/imapc/libstorage_imapc.la $(top_builddir)/src/lib-imap-client/libimap_client.la $(top_builddir)/src/lib-ssl-iostream/libssl_iostream.la'
raw_libs='$(top_builddir)/src/lib-storage/index/raw/libstorage_raw.la'
shared_libs='$(top_builddir)/src/lib-storage/index/shared/libstorage_shared.la'
@@ -2719,6 +2719,7 @@
src/lib-dns/Makefile
src/lib-fs/Makefile
src/lib-imap/Makefile
+src/lib-imap-client/Makefile
src/lib-index/Makefile
src/lib-lda/Makefile
src/lib-mail/Makefile
diff -r af13ef62d083 -r 743ebecc1224 src/Makefile.am
--- a/src/Makefile.am Sun Sep 25 22:32:04 2011 +0000
+++ b/src/Makefile.am Mon Sep 26 15:34:58 2011 +0300
@@ -14,6 +14,7 @@
lib-test \
$(LIBDOVECOT_SUBDIRS) \
lib-ssl-iostream \
+ lib-imap-client \
lib-dovecot \
lib-index \
lib-storage \
diff -r af13ef62d083 -r 743ebecc1224 src/lib-imap-client/Makefile.am
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-imap-client/Makefile.am Mon Sep 26 15:34:58 2011 +0300
@@ -0,0 +1,22 @@
+noinst_LTLIBRARIES = libimap_client.la
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/src/lib \
+ -I$(top_srcdir)/src/lib-dns \
+ -I$(top_srcdir)/src/lib-ssl-iostream \
+ -I$(top_srcdir)/src/lib-mail \
+ -I$(top_srcdir)/src/lib-imap
+
+libimap_client_la_SOURCES = \
+ imapc-client.c \
+ imapc-connection.c \
+ imapc-msgmap.c
+
+headers = \
+ imapc-client.h \
+ imapc-client-private.h \
+ imapc-connection.h \
+ imapc-msgmap.h
+
+pkginc_libdir=$(pkgincludedir)
+pkginc_lib_HEADERS = $(headers)
diff -r af13ef62d083 -r 743ebecc1224 src/lib-imap-client/imapc-client-private.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-imap-client/imapc-client-private.h Mon Sep 26 15:34:58 2011 +0300
@@ -0,0 +1,40 @@
+#ifndef IMAPC_CLIENT_PRIVATE_H
+#define IMAPC_CLIENT_PRIVATE_H
+
+#include "imapc-client.h"
+
+struct imapc_client_connection {
+ struct imapc_connection *conn;
+ struct imapc_client_mailbox *box;
+};
+
+struct imapc_client {
+ pool_t pool;
+ int refcount;
+
+ struct imapc_client_settings set;
+ struct ssl_iostream_context *ssl_ctx;
+
+ imapc_untagged_callback_t *untagged_callback;
+ void *untagged_context;
+
+ ARRAY_DEFINE(conns, struct imapc_client_connection *);
+
+ struct ioloop *ioloop;
+
+ unsigned int stop_now:1;
+};
+
+struct imapc_client_mailbox {
+ struct imapc_client *client;
+ struct imapc_connection *conn;
+ struct imapc_msgmap *msgmap;
+
+ void *untagged_box_context;
+ unsigned int pending_box_command_count;
+};
+
+void imapc_client_ref(struct imapc_client *client);
+void imapc_client_unref(struct imapc_client **client);
+
+#endif
diff -r af13ef62d083 -r 743ebecc1224 src/lib-imap-client/imapc-client.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-imap-client/imapc-client.c Mon Sep 26 15:34:58 2011 +0300
@@ -0,0 +1,444 @@
+/* Copyright (c) 2011 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "array.h"
+#include "str.h"
+#include "ioloop.h"
+#include "safe-mkstemp.h"
+#include "iostream-ssl.h"
+#include "imapc-msgmap.h"
+#include "imapc-connection.h"
+#include "imapc-client-private.h"
+
+#include <unistd.h>
+
+struct imapc_client_command_context {
+ struct imapc_client_mailbox *box;
+
+ imapc_command_callback_t *callback;
+ void *context;
+};
+
+const struct imapc_capability_name imapc_capability_names[] = {
+ { "SASL-IR", IMAPC_CAPABILITY_SASL_IR },
+ { "LITERAL+", IMAPC_CAPABILITY_LITERALPLUS },
+ { "QRESYNC", IMAPC_CAPABILITY_QRESYNC },
+ { "IDLE", IMAPC_CAPABILITY_IDLE },
+ { "UIDPLUS", IMAPC_CAPABILITY_UIDPLUS },
+ { "AUTH=PLAIN", IMAPC_CAPABILITY_AUTH_PLAIN },
+ { "STARTTLS", IMAPC_CAPABILITY_STARTTLS },
+
+ { "IMAP4REV1", IMAPC_CAPABILITY_IMAP4REV1 },
+ { NULL, 0 }
+};
+
+static void
+default_untagged_callback(const struct imapc_untagged_reply *reply ATTR_UNUSED,
+ void *context ATTR_UNUSED)
+{
+}
+
+struct imapc_client *
+imapc_client_init(const struct imapc_client_settings *set)
+{
+ struct imapc_client *client;
+ struct ssl_iostream_settings ssl_set;
+ const char *source;
+ pool_t pool;
+
+ pool = pool_alloconly_create("imapc client", 1024);
+ client = p_new(pool, struct imapc_client, 1);
+ client->pool = pool;
+ client->refcount = 1;
+
+ client->set.debug = set->debug;
+ client->set.host = p_strdup(pool, set->host);
+ client->set.port = set->port;
+ client->set.master_user = p_strdup(pool, set->master_user);
+ client->set.username = p_strdup(pool, set->username);
+ client->set.password = p_strdup(pool, set->password);
+ client->set.dns_client_socket_path =
+ p_strdup(pool, set->dns_client_socket_path);
+ client->set.temp_path_prefix =
+ p_strdup(pool, set->temp_path_prefix);
+ client->set.rawlog_dir = p_strdup(pool, set->rawlog_dir);
+
+ if (set->ssl_mode != IMAPC_CLIENT_SSL_MODE_NONE) {
+ client->set.ssl_mode = set->ssl_mode;
+ client->set.ssl_ca_dir = p_strdup(pool, set->ssl_ca_dir);
+
+ memset(&ssl_set, 0, sizeof(ssl_set));
+ ssl_set.ca_dir = set->ssl_ca_dir;
+ ssl_set.verify_remote_cert = TRUE;
+
+ source = t_strdup_printf("%s:%u", set->host, set->port);
+ if (ssl_iostream_context_init_client(source, &ssl_set,
+ &client->ssl_ctx) < 0) {
+ i_error("imapc(%s): Couldn't initialize SSL context",
+ source);
+ }
+ }
+ client->untagged_callback = default_untagged_callback;
+
+ p_array_init(&client->conns, pool, 8);
+ return client;
+}
+
+void imapc_client_ref(struct imapc_client *client)
+{
+ i_assert(client->refcount > 0);
+
+ client->refcount++;
+}
+
+void imapc_client_unref(struct imapc_client **_client)
+{
+ struct imapc_client *client = *_client;
+
+ i_assert(client->refcount > 0);
+ if (--client->refcount > 0)
+ return;
+
+ if (client->ssl_ctx != NULL)
+ ssl_iostream_context_deinit(&client->ssl_ctx);
+ pool_unref(&client->pool);
+}
+
+void imapc_client_deinit(struct imapc_client **_client)
+{
+ struct imapc_client *client = *_client;
+ struct imapc_client_connection **connp;
+
+ array_foreach_modifiable(&client->conns, connp) {
+ imapc_connection_deinit(&(*connp)->conn);
+ i_free(*connp);
+ }
+ array_clear(&client->conns);
+ imapc_client_unref(_client);
+}
+
+void imapc_client_register_untagged(struct imapc_client *client,
+ imapc_untagged_callback_t *callback,
+ void *context)
+{
+ client->untagged_callback = callback;
+ client->untagged_context = context;
+}
+
+void imapc_client_run_pre(struct imapc_client *client)
+{
+ struct imapc_client_connection *const *connp;
+ struct ioloop *prev_ioloop = current_ioloop;
+ bool handle_pending = client->stop_now;
+
+ i_assert(client->ioloop == NULL);
+
+ client->stop_now = FALSE;
+
+ client->ioloop = io_loop_create();
+ io_loop_set_running(client->ioloop);
+
+ array_foreach(&client->conns, connp) {
+ imapc_connection_ioloop_changed((*connp)->conn);
+ imapc_connection_connect((*connp)->conn, NULL, NULL);
+ if (handle_pending)
+ imapc_connection_input_pending((*connp)->conn);
+ }
+
+ if (io_loop_is_running(client->ioloop))
+ io_loop_run(client->ioloop);
+ current_ioloop = prev_ioloop;
+}
+
+void imapc_client_run_post(struct imapc_client *client)
+{
+ struct imapc_client_connection *const *connp;
+ struct ioloop *ioloop = client->ioloop;
+
+ client->ioloop = NULL;
+ array_foreach(&client->conns, connp)
+ imapc_connection_ioloop_changed((*connp)->conn);
+
+ current_ioloop = ioloop;
+ io_loop_destroy(&ioloop);
+}
+
+void imapc_client_stop(struct imapc_client *client)
+{
+ if (client->ioloop != NULL)
+ io_loop_stop(client->ioloop);
+}
+
+bool imapc_client_is_running(struct imapc_client *client)
+{
+ return client->ioloop != NULL;
+}
+
+void imapc_client_stop_now(struct imapc_client *client)
+{
+ client->stop_now = TRUE;
+ imapc_client_stop(client);
+}
+
+static struct imapc_client_connection *
+imapc_client_add_connection(struct imapc_client *client)
+{
+ struct imapc_client_connection *conn;
+
+ conn = i_new(struct imapc_client_connection, 1);
+ conn->conn = imapc_connection_init(client);
+ array_append(&client->conns, &conn, 1);
+ return conn;
+}
+
+static struct imapc_connection *
+imapc_client_find_connection(struct imapc_client *client)
More information about the dovecot-cvs
mailing list