[evolution-data-server] Remove CamelIMAPXConnManager.



commit 5484498f0bf316d999a103523c662aa922ba95f9
Author: Matthew Barnes <mbarnes redhat com>
Date:   Thu Jul 11 14:22:49 2013 -0400

    Remove CamelIMAPXConnManager.
    
    It turns out CamelIMAPXConnManager's server selection logic has been
    broken for some time and we've been operating on a single connection
    regardless of the "concurrent-connections" setting.
    
    And you know what?  A single connection works fine.  The only thing
    CamelIMAPXConnManager actually does nowadays is occasionally deadlock
    because it tries to connect to a server while holding a locked mutex,
    which is a major no-no.
    
    CamelIMAPXConnManager is not documented, it's not only NOT doing its
    job but is actively causing problems, and I can't seem to wrap my head
    around the implications of multiple connections in a CamelService.  So
    I decided to just junk it.
    
    New functions:
    
      camel_imapx_store_ref_server()
    
    Removed functions:
    
      camel_imapx_store_get_server()
      camel_imapx_store_op_done()

 camel/Makefile.am                       |    2 -
 camel/camel-imapx-conn-manager.c        |  743 -------------------------------
 camel/camel-imapx-conn-manager.h        |   87 ----
 camel/camel-imapx-folder.c              |  195 ++-------
 camel/camel-imapx-server.c              |   58 +--
 camel/camel-imapx-server.h              |    5 -
 camel/camel-imapx-store.c               |  238 +++++-----
 camel/camel-imapx-store.h               |   11 +-
 camel/camel.h                           |    1 -
 docs/reference/camel/camel-docs.sgml    |    1 -
 docs/reference/camel/camel-sections.txt |   26 +-
 docs/reference/camel/camel.types        |    1 -
 12 files changed, 167 insertions(+), 1201 deletions(-)
---
diff --git a/camel/Makefile.am b/camel/Makefile.am
index 68a2a17..7483e58 100644
--- a/camel/Makefile.am
+++ b/camel/Makefile.am
@@ -176,7 +176,6 @@ libcamel_1_2_la_SOURCES =                   \
        camel-vee-summary.c                     \
        camel-vtrash-folder.c                   \
        camel-imapx-command.c                   \
-       camel-imapx-conn-manager.c              \
        camel-imapx-folder.c                    \
        camel-imapx-job.c                       \
        camel-imapx-search.c                    \
@@ -311,7 +310,6 @@ libcamelinclude_HEADERS =                   \
        camel-vee-summary.h                     \
        camel-vtrash-folder.h                   \
        camel-imapx-command.h                   \
-       camel-imapx-conn-manager.h              \
        camel-imapx-folder.h                    \
        camel-imapx-job.h                       \
        camel-imapx-search.h                    \
diff --git a/camel/camel-imapx-folder.c b/camel/camel-imapx-folder.c
index 46c46e3..27c6031 100644
--- a/camel/camel-imapx-folder.c
+++ b/camel/camel-imapx-folder.c
@@ -303,30 +303,21 @@ imapx_search_by_uids (CamelFolder *folder,
                       GCancellable *cancellable,
                       GError **error)
 {
+       CamelIMAPXStore *imapx_store;
        CamelIMAPXFolder *imapx_folder;
        CamelIMAPXSearch *imapx_search;
-       CamelIMAPXServer *imapx_server = NULL;
+       CamelIMAPXServer *imapx_server;
        CamelStore *store;
        GPtrArray *matches;
-       const gchar *folder_name;
-       gboolean online;
 
        if (uids->len == 0)
                return g_ptr_array_new ();
 
        imapx_folder = CAMEL_IMAPX_FOLDER (folder);
-       folder_name = camel_folder_get_full_name (folder);
        store = camel_folder_get_parent_store (folder);
 
-       online = camel_offline_store_get_online (CAMEL_OFFLINE_STORE (store));
-
-       if (online) {
-               /* do not panic when the server cannot be reached for whatever reason,
-                  show offline data at least */
-               imapx_server = camel_imapx_store_get_server (
-                       CAMEL_IMAPX_STORE (store),
-                       folder_name, cancellable, NULL);
-       }
+       imapx_store = CAMEL_IMAPX_STORE (store);
+       imapx_server = camel_imapx_store_ref_server (imapx_store, NULL);
 
        g_mutex_lock (&imapx_folder->search_lock);
 
@@ -353,27 +344,18 @@ imapx_count_by_expression (CamelFolder *folder,
                            GCancellable *cancellable,
                            GError **error)
 {
+       CamelIMAPXStore *imapx_store;
        CamelIMAPXFolder *imapx_folder;
        CamelIMAPXSearch *imapx_search;
-       CamelIMAPXServer *imapx_server = NULL;
+       CamelIMAPXServer *imapx_server;
        CamelStore *store;
-       const gchar *folder_name;
-       gboolean online;
        guint32 matches;
 
        imapx_folder = CAMEL_IMAPX_FOLDER (folder);
-       folder_name = camel_folder_get_full_name (folder);
        store = camel_folder_get_parent_store (folder);
 
-       online = camel_offline_store_get_online (CAMEL_OFFLINE_STORE (store));
-
-       if (online) {
-               /* do not panic when the server cannot be reached for whatever reason,
-                  show offline data at least */
-               imapx_server = camel_imapx_store_get_server (
-                       CAMEL_IMAPX_STORE (store),
-                       folder_name, cancellable, NULL);
-       }
+       imapx_store = CAMEL_IMAPX_STORE (store);
+       imapx_server = camel_imapx_store_ref_server (imapx_store, NULL);
 
        g_mutex_lock (&imapx_folder->search_lock);
 
@@ -400,27 +382,18 @@ imapx_search_by_expression (CamelFolder *folder,
                             GCancellable *cancellable,
                             GError **error)
 {
+       CamelIMAPXStore *imapx_store;
        CamelIMAPXFolder *imapx_folder;
        CamelIMAPXSearch *imapx_search;
-       CamelIMAPXServer *imapx_server = NULL;
+       CamelIMAPXServer *imapx_server;
        CamelStore *store;
        GPtrArray *matches;
-       const gchar *folder_name;
-       gboolean online;
 
        imapx_folder = CAMEL_IMAPX_FOLDER (folder);
-       folder_name = camel_folder_get_full_name (folder);
        store = camel_folder_get_parent_store (folder);
 
-       online = camel_offline_store_get_online (CAMEL_OFFLINE_STORE (store));
-
-       if (online) {
-               /* do not panic when the server cannot be reached for whatever reason,
-                  show offline data at least */
-               imapx_server = camel_imapx_store_get_server (
-                       CAMEL_IMAPX_STORE (store),
-                       folder_name, cancellable, NULL);
-       }
+       imapx_store = CAMEL_IMAPX_STORE (store);
+       imapx_server = camel_imapx_store_ref_server (imapx_store, NULL);
 
        g_mutex_lock (&imapx_folder->search_lock);
 
@@ -468,21 +441,13 @@ imapx_append_message_sync (CamelFolder *folder,
        gboolean success = FALSE;
 
        store = camel_folder_get_parent_store (folder);
-       imapx_store = CAMEL_IMAPX_STORE (store);
 
-       if (!camel_offline_store_get_online (CAMEL_OFFLINE_STORE (imapx_store))) {
-               g_set_error (
-                       error, CAMEL_SERVICE_ERROR,
-                       CAMEL_SERVICE_ERROR_UNAVAILABLE,
-                       _("You must be working online to complete this operation"));
-               return FALSE;
-       }
+       imapx_store = CAMEL_IMAPX_STORE (store);
+       imapx_server = camel_imapx_store_ref_server (imapx_store, error);
 
        if (appended_uid != NULL)
                *appended_uid = NULL;
 
-       imapx_server = camel_imapx_store_get_server (
-               imapx_store, NULL, cancellable, error);
        if (imapx_server != NULL) {
                success = camel_imapx_server_append_message (
                        imapx_server, folder, message, info,
@@ -502,28 +467,16 @@ imapx_expunge_sync (CamelFolder *folder,
        CamelStore *store;
        CamelIMAPXStore *imapx_store;
        CamelIMAPXServer *imapx_server;
-       const gchar *folder_name;
        gboolean success = FALSE;
 
-       folder_name = camel_folder_get_full_name (folder);
        store = camel_folder_get_parent_store (folder);
-       imapx_store = CAMEL_IMAPX_STORE (store);
 
-       if (!camel_offline_store_get_online (CAMEL_OFFLINE_STORE (imapx_store))) {
-               g_set_error (
-                       error, CAMEL_SERVICE_ERROR,
-                       CAMEL_SERVICE_ERROR_UNAVAILABLE,
-                       _("You must be working online to complete this operation"));
-               return FALSE;
-       }
+       imapx_store = CAMEL_IMAPX_STORE (store);
+       imapx_server = camel_imapx_store_ref_server (imapx_store, error);
 
-       imapx_server = camel_imapx_store_get_server (
-               imapx_store, folder_name, cancellable, error);
        if (imapx_server != NULL) {
                success = camel_imapx_server_expunge (
                        imapx_server, folder, cancellable, error);
-               camel_imapx_store_op_done (
-                       imapx_store, imapx_server, folder_name);
        }
 
        g_clear_object (&imapx_server);
@@ -538,36 +491,19 @@ imapx_fetch_messages_sync (CamelFolder *folder,
                            GCancellable *cancellable,
                            GError **error)
 {
-       CamelService *service;
        CamelStore *store;
        CamelIMAPXStore *imapx_store;
        CamelIMAPXServer *imapx_server;
-       const gchar *folder_name;
        gboolean success = FALSE;
 
-       folder_name = camel_folder_get_full_name (folder);
        store = camel_folder_get_parent_store (folder);
-       imapx_store = CAMEL_IMAPX_STORE (store);
-       service = CAMEL_SERVICE (store);
 
-       if (!camel_offline_store_get_online (CAMEL_OFFLINE_STORE (imapx_store))) {
-               g_set_error (
-                       error, CAMEL_SERVICE_ERROR,
-                       CAMEL_SERVICE_ERROR_UNAVAILABLE,
-                       _("You must be working online to complete this operation"));
-               return FALSE;
-       }
-
-       if (!camel_service_connect_sync (service, cancellable, error))
-               return FALSE;
+       imapx_store = CAMEL_IMAPX_STORE (store);
+       imapx_server = camel_imapx_store_ref_server (imapx_store, error);
 
-       imapx_server = camel_imapx_store_get_server (
-               imapx_store, folder_name, cancellable, error);
        if (imapx_server != NULL) {
                success = camel_imapx_server_fetch_messages (
                        imapx_server, folder, type, limit, cancellable, error);
-               camel_imapx_store_op_done (
-                       imapx_store, imapx_server, folder_name);
        }
 
        g_clear_object (&imapx_server);
@@ -584,16 +520,12 @@ imapx_get_message_sync (CamelFolder *folder,
        CamelMimeMessage *msg = NULL;
        CamelStream *stream = NULL;
        CamelStore *store;
-       CamelIMAPXStore *imapx_store;
        CamelIMAPXFolder *imapx_folder;
-       const gchar *folder_name;
        const gchar *path = NULL;
        gboolean offline_message = FALSE;
 
-       folder_name = camel_folder_get_full_name (folder);
        imapx_folder = CAMEL_IMAPX_FOLDER (folder);
        store = camel_folder_get_parent_store (folder);
-       imapx_store = CAMEL_IMAPX_STORE (store);
 
        if (!strchr (uid, '-'))
                path = "cur";
@@ -614,21 +546,12 @@ imapx_get_message_sync (CamelFolder *folder,
                        return NULL;
                }
 
-               if (!camel_offline_store_get_online (CAMEL_OFFLINE_STORE (imapx_store))) {
-                       g_set_error (
-                               error, CAMEL_SERVICE_ERROR,
-                               CAMEL_SERVICE_ERROR_UNAVAILABLE,
-                               _("You must be working online to complete this operation"));
-                       return NULL;
-               }
+               imapx_server = camel_imapx_store_ref_server (
+                       CAMEL_IMAPX_STORE (store), error);
 
-               imapx_server = camel_imapx_store_get_server (
-                       imapx_store, folder_name, cancellable, error);
                if (imapx_server != NULL) {
                        stream = camel_imapx_server_get_message (
                                imapx_server, folder, uid, cancellable, error);
-                       camel_imapx_store_op_done (
-                               imapx_store, imapx_server, folder_name);
                }
 
                g_clear_object (&imapx_server);
@@ -680,18 +603,18 @@ imapx_get_quota_info_sync (CamelFolder *folder,
                            GError **error)
 {
        CamelStore *store;
+       CamelIMAPXStore *imapx_store;
        CamelIMAPXServer *imapx_server;
        CamelFolderQuotaInfo *quota_info = NULL;
        const gchar *folder_name;
        gchar **quota_root_names;
        gboolean success = FALSE;
 
-       folder_name = camel_folder_get_full_name (folder);
        store = camel_folder_get_parent_store (folder);
+       folder_name = camel_folder_get_full_name (folder);
 
-       imapx_server = camel_imapx_store_get_server (
-               CAMEL_IMAPX_STORE (store),
-               folder_name, cancellable, error);
+       imapx_store = CAMEL_IMAPX_STORE (store);
+       imapx_server = camel_imapx_store_ref_server (imapx_store, error);
 
        if (imapx_server != NULL) {
                success = camel_imapx_server_update_quota_info (
@@ -739,36 +662,19 @@ imapx_refresh_info_sync (CamelFolder *folder,
                          GCancellable *cancellable,
                          GError **error)
 {
-       CamelService *service;
        CamelStore *store;
        CamelIMAPXStore *imapx_store;
        CamelIMAPXServer *imapx_server;
-       const gchar *folder_name;
        gboolean success = FALSE;
 
-       folder_name = camel_folder_get_full_name (folder);
        store = camel_folder_get_parent_store (folder);
-       imapx_store = CAMEL_IMAPX_STORE (store);
-       service = CAMEL_SERVICE (store);
-
-       if (!camel_offline_store_get_online (CAMEL_OFFLINE_STORE (imapx_store))) {
-               g_set_error (
-                       error, CAMEL_SERVICE_ERROR,
-                       CAMEL_SERVICE_ERROR_UNAVAILABLE,
-                       _("You must be working online to complete this operation"));
-               return FALSE;
-       }
 
-       if (!camel_service_connect_sync (service, cancellable, error))
-               return FALSE;
+       imapx_store = CAMEL_IMAPX_STORE (store);
+       imapx_server = camel_imapx_store_ref_server (imapx_store, error);
 
-       imapx_server = camel_imapx_store_get_server (
-               imapx_store, folder_name, cancellable, error);
        if (imapx_server != NULL) {
                success = camel_imapx_server_refresh_info (
                        imapx_server, folder, cancellable, error);
-               camel_imapx_store_op_done (
-                       imapx_store, imapx_server, folder_name);
        }
 
        g_clear_object (&imapx_server);
@@ -933,23 +839,13 @@ imapx_synchronize_sync (CamelFolder *folder,
        CamelStore *store;
        CamelIMAPXStore *imapx_store;
        CamelIMAPXServer *imapx_server;
-       const gchar *folder_name;
        gboolean success = FALSE;
 
-       folder_name = camel_folder_get_full_name (folder);
        store = camel_folder_get_parent_store (folder);
-       imapx_store = CAMEL_IMAPX_STORE (store);
 
-       if (!camel_offline_store_get_online (CAMEL_OFFLINE_STORE (imapx_store))) {
-               g_set_error (
-                       error, CAMEL_SERVICE_ERROR,
-                       CAMEL_SERVICE_ERROR_UNAVAILABLE,
-                       _("You must be working online to complete this operation"));
-               return FALSE;
-       }
+       imapx_store = CAMEL_IMAPX_STORE (store);
+       imapx_server = camel_imapx_store_ref_server (imapx_store, error);
 
-       imapx_server = camel_imapx_store_get_server (
-               imapx_store, folder_name, cancellable, error);
        if (imapx_server != NULL) {
                gboolean need_to_expunge;
 
@@ -976,9 +872,6 @@ imapx_synchronize_sync (CamelFolder *folder,
                if (success && expunge)
                        success = camel_imapx_server_expunge (
                                imapx_server, folder, cancellable, error);
-
-               camel_imapx_store_op_done (
-                       imapx_store, imapx_server, folder_name);
        }
 
        g_clear_object (&imapx_server);
@@ -995,28 +888,16 @@ imapx_synchronize_message_sync (CamelFolder *folder,
        CamelStore *store;
        CamelIMAPXStore *imapx_store;
        CamelIMAPXServer *imapx_server;
-       const gchar *folder_name;
        gboolean success = FALSE;
 
-       folder_name = camel_folder_get_full_name (folder);
        store = camel_folder_get_parent_store (folder);
-       imapx_store = CAMEL_IMAPX_STORE (store);
 
-       if (!camel_offline_store_get_online (CAMEL_OFFLINE_STORE (imapx_store))) {
-               g_set_error (
-                       error, CAMEL_SERVICE_ERROR,
-                       CAMEL_SERVICE_ERROR_UNAVAILABLE,
-                       _("You must be working online to complete this operation"));
-               return FALSE;
-       }
+       imapx_store = CAMEL_IMAPX_STORE (store);
+       imapx_server = camel_imapx_store_ref_server (imapx_store, error);
 
-       imapx_server = camel_imapx_store_get_server (
-               imapx_store, folder_name, cancellable, error);
        if (imapx_server != NULL) {
                success = camel_imapx_server_sync_message (
                        imapx_server, folder, uid, cancellable, error);
-               camel_imapx_store_op_done (
-                       imapx_store, imapx_server, folder_name);
        }
 
        g_clear_object (&imapx_server);
@@ -1036,29 +917,17 @@ imapx_transfer_messages_to_sync (CamelFolder *source,
        CamelStore *store;
        CamelIMAPXStore *imapx_store;
        CamelIMAPXServer *imapx_server;
-       const gchar *folder_name;
        gboolean success = FALSE;
 
-       folder_name = camel_folder_get_full_name (source);
        store = camel_folder_get_parent_store (source);
-       imapx_store = CAMEL_IMAPX_STORE (store);
 
-       if (!camel_offline_store_get_online (CAMEL_OFFLINE_STORE (imapx_store))) {
-               g_set_error (
-                       error, CAMEL_SERVICE_ERROR,
-                       CAMEL_SERVICE_ERROR_UNAVAILABLE,
-                       _("You must be working online to complete this operation"));
-               return FALSE;
-       }
+       imapx_store = CAMEL_IMAPX_STORE (store);
+       imapx_server = camel_imapx_store_ref_server (imapx_store, error);
 
-       imapx_server = camel_imapx_store_get_server (
-               imapx_store, folder_name, cancellable, error);
        if (imapx_server != NULL) {
                success = camel_imapx_server_copy_message (
                        imapx_server, source, dest, uids,
                        delete_originals, cancellable, error);
-               camel_imapx_store_op_done (
-                       imapx_store, imapx_server, folder_name);
 
                /* Update destination folder only if it's not frozen,
                 * to avoid updating for each "move" action on a single
diff --git a/camel/camel-imapx-server.c b/camel/camel-imapx-server.c
index 91a75ee..127f9ae 100644
--- a/camel/camel-imapx-server.c
+++ b/camel/camel-imapx-server.c
@@ -351,14 +351,6 @@ enum {
        PROP_STORE
 };
 
-enum {
-       SELECT_CHANGED,
-       SHUTDOWN,
-       LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL];
-
 static void    imapx_uidset_init               (struct _uidset_state *ss,
                                                 gint total,
                                                 gint limit);
@@ -2297,6 +2289,7 @@ imapx_untagged_bye (CamelIMAPXServer *is,
                     GCancellable *cancellable,
                     GError **error)
 {
+       CamelIMAPXStore *store;
        guchar *token = NULL;
 
        g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), FALSE);
@@ -2314,6 +2307,12 @@ imapx_untagged_bye (CamelIMAPXServer *is,
 
        is->state = IMAPX_SHUTDOWN;
 
+       /* Disconnect the CamelIMAPXStore. */
+       store = camel_imapx_server_ref_store (is);
+       camel_service_disconnect_sync (
+               CAMEL_SERVICE (store), FALSE, NULL, NULL);
+       g_object_unref (store);
+
        return FALSE;
 }
 
@@ -3453,7 +3452,6 @@ imapx_command_select_done (CamelIMAPXServer *is,
                            GCancellable *cancellable,
                            GError **error)
 {
-       const gchar *selected_folder = NULL;
        gboolean success = TRUE;
        GError *local_error = NULL;
 
@@ -3564,7 +3562,6 @@ imapx_command_select_done (CamelIMAPXServer *is,
                        ;
                }
                ifolder->uidvalidity_on_server = is->uidvalidity;
-               selected_folder = camel_folder_get_full_name (folder);
 
                if (is->uidvalidity && is->uidvalidity != ((CamelIMAPXSummary *) folder->summary)->validity)
                        invalidate_local_cache (ifolder, is->uidvalidity);
@@ -3583,8 +3580,6 @@ imapx_command_select_done (CamelIMAPXServer *is,
 
        camel_imapx_command_unref (ic);
 
-       g_signal_emit (is, signals[SELECT_CHANGED], 0, selected_folder);
-
        return success;
 }
 
@@ -6861,6 +6856,7 @@ imapx_parser_thread (gpointer d)
 {
        CamelIMAPXServer *is = d;
        CamelIMAPXStream *stream;
+       CamelIMAPXStore *store;
        GCancellable *cancellable;
        gboolean have_stream;
        GError *local_error = NULL;
@@ -6952,8 +6948,6 @@ imapx_parser_thread (gpointer d)
 
        cancel_all_jobs (is, local_error);
 
-       g_clear_error (&local_error);
-
        QUEUE_LOCK (is);
        if (is->cancellable != NULL) {
                g_object_unref (is->cancellable);
@@ -6963,7 +6957,14 @@ imapx_parser_thread (gpointer d)
        QUEUE_UNLOCK (is);
 
        is->parser_quit = FALSE;
-       g_signal_emit (is, signals[SHUTDOWN], 0);
+
+       /* Disconnect the CamelService. */
+       store = camel_imapx_server_ref_store (is);
+       camel_service_disconnect_sync (
+               CAMEL_SERVICE (store), FALSE, NULL, NULL);
+       g_object_unref (store);
+
+       g_clear_error (&local_error);
 
        g_object_unref (is);
 
@@ -7117,9 +7118,6 @@ camel_imapx_server_class_init (CamelIMAPXServerClass *class)
        object_class->dispose = imapx_server_dispose;
        object_class->constructed = imapx_server_constructed;
 
-       class->select_changed = NULL;
-       class->shutdown = NULL;
-
        g_object_class_install_property (
                object_class,
                PROP_STREAM,
@@ -7143,30 +7141,6 @@ camel_imapx_server_class_init (CamelIMAPXServerClass *class)
                        G_PARAM_CONSTRUCT_ONLY |
                        G_PARAM_STATIC_STRINGS));
 
-       /**
-        * CamelIMAPXServer::select_changed
-        * @server: the #CamelIMAPXServer which emitted the signal
-        **/
-       signals[SELECT_CHANGED] = g_signal_new (
-               "select_changed",
-               G_OBJECT_CLASS_TYPE (class),
-               G_SIGNAL_RUN_FIRST,
-               G_STRUCT_OFFSET (CamelIMAPXServerClass, select_changed),
-               NULL, NULL, NULL,
-               G_TYPE_NONE, 1, G_TYPE_STRING);
-
-       /**
-        * CamelIMAPXServer::shutdown
-        * @server: the #CamelIMAPXServer which emitted the signal
-        **/
-       signals[SHUTDOWN] = g_signal_new (
-               "shutdown",
-               G_OBJECT_CLASS_TYPE (class),
-               G_SIGNAL_RUN_FIRST,
-               G_STRUCT_OFFSET (CamelIMAPXServerClass, shutdown),
-               NULL, NULL, NULL,
-               G_TYPE_NONE, 0);
-
        class->tagprefix = 'A';
 }
 
diff --git a/camel/camel-imapx-server.h b/camel/camel-imapx-server.h
index f931265..ae18490 100644
--- a/camel/camel-imapx-server.h
+++ b/camel/camel-imapx-server.h
@@ -164,11 +164,6 @@ struct _CamelIMAPXServer {
 struct _CamelIMAPXServerClass {
        CamelObjectClass parent_class;
 
-       /* Signals */
-       void    (*select_changed)       (CamelIMAPXServer *is,
-                                        const gchar *selected_folder);
-       void    (*shutdown)             (CamelIMAPXServer *is);
-
        gchar tagprefix;
 };
 
diff --git a/camel/camel-imapx-store.c b/camel/camel-imapx-store.c
index 6a21ed3..f41cbb5 100644
--- a/camel/camel-imapx-store.c
+++ b/camel/camel-imapx-store.c
@@ -57,6 +57,10 @@
        ((obj), CAMEL_TYPE_IMAPX_STORE, CamelIMAPXStorePrivate))
 
 struct _CamelIMAPXStorePrivate {
+       CamelIMAPXServer *connected_server;
+       CamelIMAPXServer *connecting_server;
+       GMutex server_lock;
+
        GHashTable *quota_info;
        GMutex quota_info_lock;
 
@@ -250,13 +254,6 @@ imapx_store_dispose (GObject *object)
 {
        CamelIMAPXStore *imapx_store = CAMEL_IMAPX_STORE (object);
 
-       /* Force disconnect so we dont have it run later,
-        * after we've cleaned up some stuff. */
-       if (imapx_store->con_man != NULL) {
-               camel_service_disconnect_sync (
-                       CAMEL_SERVICE (imapx_store), TRUE, NULL, NULL);
-       }
-
        if (imapx_store->priv->settings_notify_handler_id > 0) {
                g_signal_handler_disconnect (
                        imapx_store->priv->settings,
@@ -264,10 +261,10 @@ imapx_store_dispose (GObject *object)
                imapx_store->priv->settings_notify_handler_id = 0;
        }
 
-       g_clear_object (&imapx_store->con_man);
-       g_clear_object (&imapx_store->authenticating_server);
        g_clear_object (&imapx_store->summary);
 
+       g_clear_object (&imapx_store->priv->connected_server);
+       g_clear_object (&imapx_store->priv->connecting_server);
        g_clear_object (&imapx_store->priv->settings);
 
        /* Chain up to parent's dispose() method. */
@@ -281,6 +278,8 @@ imapx_store_finalize (GObject *object)
 
        g_mutex_clear (&imapx_store->get_finfo_lock);
 
+       g_mutex_clear (&imapx_store->priv->server_lock);
+
        g_hash_table_destroy (imapx_store->priv->quota_info);
        g_mutex_clear (&imapx_store->priv->quota_info_lock);
 
@@ -335,45 +334,48 @@ imapx_get_name (CamelService *service,
        return name;
 }
 
-CamelIMAPXServer *
-camel_imapx_store_get_server (CamelIMAPXStore *imapx_store,
-                              const gchar *folder_name,
-                              GCancellable *cancellable,
-                              GError **error)
-{
-       return camel_imapx_conn_manager_get_connection (
-               imapx_store->con_man, folder_name, cancellable, error);
-}
-
-void
-camel_imapx_store_op_done (CamelIMAPXStore *imapx_store,
-                           CamelIMAPXServer *server,
-                           const gchar *folder_name)
-{
-       g_return_if_fail (server != NULL);
-
-       camel_imapx_conn_manager_update_con_info (
-               imapx_store->con_man, server, folder_name);
-}
-
 static gboolean
 imapx_connect_sync (CamelService *service,
                     GCancellable *cancellable,
                     GError **error)
 {
        CamelIMAPXStore *imapx_store;
-       CamelIMAPXServer *server;
+       CamelIMAPXServer *imapx_server;
+       gboolean success;
 
        imapx_store = CAMEL_IMAPX_STORE (service);
+       imapx_server = camel_imapx_server_new (imapx_store);
 
-       server = camel_imapx_store_get_server (
-               imapx_store, NULL, cancellable, error);
-       if (server != NULL) {
-               g_object_unref (server);
-               return TRUE;
+       g_mutex_lock (&imapx_store->priv->server_lock);
+
+       /* We need to share the CamelIMAPXServer instance with the
+        * authenticate_sync() method, but we don't want other parts
+        * getting at it just yet.  So stash it in a special private
+        * variable while connecting to the IMAP server. */
+       g_warn_if_fail (imapx_store->priv->connecting_server == NULL);
+       imapx_store->priv->connecting_server = g_object_ref (imapx_server);
+
+       g_mutex_unlock (&imapx_store->priv->server_lock);
+
+       success = camel_imapx_server_connect (
+               imapx_server, cancellable, error);
+
+       g_mutex_lock (&imapx_store->priv->server_lock);
+
+       g_warn_if_fail (imapx_store->priv->connecting_server == imapx_server);
+       g_clear_object (&imapx_store->priv->connecting_server);
+
+       if (success) {
+               g_clear_object (&imapx_store->priv->connected_server);
+               imapx_store->priv->connected_server = imapx_server;
+               g_object_ref (imapx_server);
        }
 
-       return FALSE;
+       g_mutex_unlock (&imapx_store->priv->server_lock);
+
+       g_clear_object (&imapx_server);
+
+       return success;
 }
 
 static gboolean
@@ -383,16 +385,15 @@ imapx_disconnect_sync (CamelService *service,
                        GError **error)
 {
        CamelIMAPXStore *imapx_store;
-       CamelServiceClass *service_class;
 
        imapx_store = CAMEL_IMAPX_STORE (service);
 
-       service_class = CAMEL_SERVICE_CLASS (camel_imapx_store_parent_class);
-       if (!service_class->disconnect_sync (service, clean, cancellable, error))
-               return FALSE;
+       g_mutex_lock (&imapx_store->priv->server_lock);
 
-       if (imapx_store->con_man != NULL)
-               camel_imapx_conn_manager_close_connections (imapx_store->con_man);
+       g_warn_if_fail (imapx_store->priv->connecting_server == NULL);
+       g_clear_object (&imapx_store->priv->connected_server);
+
+       g_mutex_unlock (&imapx_store->priv->server_lock);
 
        return TRUE;
 }
@@ -404,24 +405,22 @@ imapx_authenticate_sync (CamelService *service,
                          GError **error)
 {
        CamelIMAPXStore *imapx_store;
-       CamelIMAPXServer *server;
+       CamelIMAPXServer *imapx_server;
+       CamelAuthenticationResult result;
 
        imapx_store = CAMEL_IMAPX_STORE (service);
 
-       /* CamelIMAPXConnManager sets this before calling
-        * camel_imapx_server_connect()(), and then clears it
-        * immediately after, all while holding the recursive
-        * connection lock (CAMEL_SERVICE_REC_CONNECT_LOCK).
-        * Otherwise we'd have no way of knowing which server
-        * is trying to authenticate. */
-       server = imapx_store->authenticating_server;
+       /* This should have been set for us by connect_sync(). */
+       g_mutex_lock (&imapx_store->priv->server_lock);
+       imapx_server = g_object_ref (imapx_store->priv->connecting_server);
+       g_mutex_unlock (&imapx_store->priv->server_lock);
 
-       g_return_val_if_fail (
-               CAMEL_IS_IMAPX_SERVER (server),
-               CAMEL_AUTHENTICATION_REJECTED);
+       result = camel_imapx_server_authenticate (
+               imapx_server, mechanism, cancellable, error);
 
-       return camel_imapx_server_authenticate (
-               server, mechanism, cancellable, error);
+       g_clear_object (&imapx_server);
+
+       return result;
 }
 
 CamelServiceAuthType camel_imapx_password_authtype = {
@@ -780,12 +779,7 @@ imapx_subscribe_folder (CamelStore *store,
        gboolean success = FALSE;
 
        imapx_store = CAMEL_IMAPX_STORE (store);
-
-       if (!camel_offline_store_get_online (CAMEL_OFFLINE_STORE (store)))
-               return TRUE;
-
-       imapx_server = camel_imapx_store_get_server (
-               imapx_store, NULL, cancellable, error);
+       imapx_server = camel_imapx_store_ref_server (imapx_store, error);
 
        if (folder_name != NULL && *folder_name == '/')
                folder_name++;
@@ -817,12 +811,7 @@ imapx_unsubscribe_folder (CamelStore *store,
        gboolean success = FALSE;
 
        imapx_store = CAMEL_IMAPX_STORE (store);
-
-       if (!camel_offline_store_get_online (CAMEL_OFFLINE_STORE (store)))
-               return TRUE;
-
-       imapx_server = camel_imapx_store_get_server (
-               imapx_store, NULL, cancellable, error);
+       imapx_server = camel_imapx_store_ref_server (imapx_store, error);
 
        if (folder_name != NULL && *folder_name == '/')
                folder_name++;
@@ -1210,8 +1199,8 @@ fetch_folders_for_namespaces (CamelIMAPXStore *imapx_store,
        GHashTable *folders = NULL;
        GList *namespaces = NULL, *l;
 
-       server = camel_imapx_store_get_server (
-               imapx_store, NULL, cancellable, error);
+       server = camel_imapx_store_ref_server (imapx_store, error);
+
        if (server == NULL)
                return NULL;
 
@@ -1762,17 +1751,8 @@ imapx_store_create_folder_sync (CamelStore *store,
        gboolean success;
 
        imapx_store = CAMEL_IMAPX_STORE (store);
+       imapx_server = camel_imapx_store_ref_server (imapx_store, error);
 
-       if (!camel_offline_store_get_online (CAMEL_OFFLINE_STORE (store))) {
-               g_set_error (
-                       error, CAMEL_SERVICE_ERROR,
-                       CAMEL_SERVICE_ERROR_UNAVAILABLE,
-                       _("You must be working online to complete this operation"));
-               return NULL;
-       }
-
-       imapx_server = camel_imapx_store_get_server (
-               imapx_store, NULL, cancellable, error);
        if (imapx_server == NULL)
                return NULL;
 
@@ -1862,21 +1842,7 @@ imapx_store_delete_folder_sync (CamelStore *store,
        gboolean success = FALSE;
 
        imapx_store = CAMEL_IMAPX_STORE (store);
-
-       if (!camel_offline_store_get_online (CAMEL_OFFLINE_STORE (store))) {
-               g_set_error (
-                       error, CAMEL_SERVICE_ERROR,
-                       CAMEL_SERVICE_ERROR_UNAVAILABLE,
-                       _("You must be working online to complete this operation"));
-               return FALSE;
-       }
-
-       /* Use INBOX connection as the implementation would try to select
-        * inbox to ensure we are not selected on the folder being deleted. */
-       imapx_server = camel_imapx_store_get_server (
-               imapx_store, "INBOX", cancellable, error);
-       if (imapx_server == NULL)
-               return FALSE;
+       imapx_server = camel_imapx_store_ref_server (imapx_store, error);
 
        if (imapx_server != NULL) {
                success = camel_imapx_server_delete_folder (
@@ -1919,18 +1885,9 @@ imapx_store_rename_folder_sync (CamelStore *store,
 
        g_object_unref (settings);
 
-       if (!camel_offline_store_get_online (CAMEL_OFFLINE_STORE (store))) {
-               g_set_error (
-                       error, CAMEL_SERVICE_ERROR,
-                       CAMEL_SERVICE_ERROR_UNAVAILABLE,
-                       _("You must be working online to complete this operation"));
-               return FALSE;
-       }
+       imapx_store = CAMEL_IMAPX_STORE (store);
+       imapx_server = camel_imapx_store_ref_server (imapx_store, error);
 
-       /* Use INBOX connection as the implementation would try to select
-        * inbox to ensure we are not selected on the folder being renamed. */
-       imapx_server = camel_imapx_store_get_server (
-               imapx_store, "INBOX", cancellable, error);
        if (imapx_server != NULL) {
                gchar *oldpath;
                gchar *newpath;
@@ -1986,26 +1943,20 @@ imapx_store_noop_sync (CamelStore *store,
                        GError **error)
 {
        CamelIMAPXStore *imapx_store;
-       GList *list, *link;
+       CamelIMAPXServer *imapx_server;
        gboolean success = TRUE;
 
-       imapx_store = CAMEL_IMAPX_STORE (store);
-
-       if (!camel_offline_store_get_online (CAMEL_OFFLINE_STORE (store)))
-               return TRUE;
-
-       list = camel_imapx_conn_manager_get_connections (imapx_store->con_man);
+       /* If we're not connected then this truly is a no-op. */
 
-       for (link = list; link != NULL; link = g_list_next (link)) {
-               CamelIMAPXServer *server = CAMEL_IMAPX_SERVER (link->data);
+       imapx_store = CAMEL_IMAPX_STORE (store);
+       imapx_server = camel_imapx_store_ref_server (imapx_store, NULL);
 
-               /* we just return last noops value, technically not correct though */
-               success = camel_imapx_server_noop (server, NULL, cancellable, error);
-               if (!success)
-                       break;
+       if (imapx_server != NULL) {
+               success = camel_imapx_server_noop (
+                       imapx_server, NULL, cancellable, error);
        }
 
-       g_list_free_full (list, (GDestroyNotify) g_object_unref);
+       g_clear_object (&imapx_server);
 
        return success;
 }
@@ -2240,7 +2191,8 @@ camel_imapx_store_init (CamelIMAPXStore *store)
        g_mutex_init (&store->get_finfo_lock);
        store->last_refresh_time = time (NULL) - (FINFO_REFRESH_INTERVAL + 10);
        store->dir_sep = '/';
-       store->con_man = camel_imapx_conn_manager_new (CAMEL_STORE (store));
+
+       g_mutex_init (&store->priv->server_lock);
 
        store->priv->quota_info = g_hash_table_new_full (
                (GHashFunc) g_str_hash,
@@ -2258,6 +2210,50 @@ camel_imapx_store_init (CamelIMAPXStore *store)
                G_CALLBACK (imapx_store_update_store_flags), NULL);
 }
 
+/**
+ * camel_imapx_store_ref_server:
+ * @store: a #CamelIMAPXStore
+ * @error: return location for a #GError, or %NULL
+ *
+ * Returns the #CamelIMAPXServer for @store, if available.
+ *
+ * As a convenience, if the @store is not currently connected to an IMAP
+ * server, the function sets @error to %CAMEL_SERVER_ERROR_UNAVAILABLE and
+ * returns %NULL.  If an operation can possibly be executed while offline,
+ * pass %NULL for @error.
+ *
+ * The returned #CamelIMAPXServer is referenced for thread-safety and must
+ * be unreferenced with g_object_unref() when finished with it.
+ *
+ * Returns: a #CamelIMAPXServer, or %NULL
+ *
+ * Since: 3.10
+ **/
+CamelIMAPXServer *
+camel_imapx_store_ref_server (CamelIMAPXStore *store,
+                              GError **error)
+{
+       CamelIMAPXServer *server = NULL;
+
+       g_return_val_if_fail (CAMEL_IS_IMAPX_STORE (store), NULL);
+
+       g_mutex_lock (&store->priv->server_lock);
+
+       if (store->priv->connected_server != NULL) {
+               server = g_object_ref (store->priv->connected_server);
+       } else {
+               g_set_error (
+                       error, CAMEL_SERVICE_ERROR,
+                       CAMEL_SERVICE_ERROR_UNAVAILABLE,
+                       _("You must be working online "
+                       "to complete this operation"));
+       }
+
+       g_mutex_unlock (&store->priv->server_lock);
+
+       return server;
+}
+
 CamelFolderQuotaInfo *
 camel_imapx_store_dup_quota_info (CamelIMAPXStore *store,
                                   const gchar *quota_root_name)
diff --git a/camel/camel-imapx-store.h b/camel/camel-imapx-store.h
index 3eac2e0..ea882f9 100644
--- a/camel/camel-imapx-store.h
+++ b/camel/camel-imapx-store.h
@@ -32,7 +32,6 @@
 
 #include "camel-imapx-server.h"
 #include "camel-imapx-store-summary.h"
-#include "camel-imapx-conn-manager.h"
 
 /* Standard GObject macros */
 #define CAMEL_TYPE_IMAPX_STORE \
@@ -63,9 +62,6 @@ struct _CamelIMAPXStore {
        CamelOfflineStore parent;
        CamelIMAPXStorePrivate *priv;
 
-       CamelIMAPXConnManager *con_man;
-       CamelIMAPXServer *authenticating_server;
-
        CamelIMAPXStoreSummary *summary; /* in-memory list of folders */
        gchar dir_sep;
 
@@ -91,13 +87,8 @@ struct _CamelIMAPXStoreClass {
 
 GType          camel_imapx_store_get_type      (void);
 CamelIMAPXServer *
-               camel_imapx_store_get_server    (CamelIMAPXStore *store,
-                                                const gchar *folder_name,
-                                                GCancellable *cancellable,
+               camel_imapx_store_ref_server    (CamelIMAPXStore *store,
                                                 GError **error);
-void           camel_imapx_store_op_done       (CamelIMAPXStore *istore,
-                                                CamelIMAPXServer *server,
-                                                const gchar *folder_name);
 CamelFolderQuotaInfo *
                camel_imapx_store_dup_quota_info
                                                (CamelIMAPXStore *store,
diff --git a/camel/camel.h b/camel/camel.h
index 63eeaf9..c38229d 100644
--- a/camel/camel.h
+++ b/camel/camel.h
@@ -144,7 +144,6 @@
 #include <camel/camel-vtrash-folder.h>
 #include <camel/camel-imapx-command.h>
 #include <camel/camel-imapx-job.h>
-#include <camel/camel-imapx-conn-manager.h>
 #include <camel/camel-imapx-folder.h>
 #include <camel/camel-imapx-search.h>
 #include <camel/camel-imapx-server.h>
diff --git a/docs/reference/camel/camel-docs.sgml b/docs/reference/camel/camel-docs.sgml
index 28efb22..a11b143 100644
--- a/docs/reference/camel/camel-docs.sgml
+++ b/docs/reference/camel/camel-docs.sgml
@@ -202,7 +202,6 @@
     <chapter id="IMAP">
       <title>Extensible IMAP</title>
       <xi:include href="xml/camel-imapx-command.xml"/>
-      <xi:include href="xml/camel-imapx-conn-manager.xml"/>
       <xi:include href="xml/camel-imapx-folder.xml"/>
       <xi:include href="xml/camel-imapx-job.xml"/>
       <xi:include href="xml/camel-imapx-search.xml"/>
diff --git a/docs/reference/camel/camel-sections.txt b/docs/reference/camel/camel-sections.txt
index b287a97..2b9fcbf 100644
--- a/docs/reference/camel/camel-sections.txt
+++ b/docs/reference/camel/camel-sections.txt
@@ -770,29 +770,6 @@ camel_imapx_command_queue_delete_link
 </SECTION>
 
 <SECTION>
-<FILE>camel-imapx-conn-manager</FILE>
-<TITLE>CamelIMAPXConnManager</TITLE>
-CamelIMAPXConnManager
-camel_imapx_conn_manager_new
-camel_imapx_conn_manager_ref_store
-camel_imapx_conn_manager_get_connection
-camel_imapx_conn_manager_close_connections
-camel_imapx_conn_manager_get_connections
-camel_imapx_conn_manager_update_con_info
-<SUBSECTION Standard>
-CAMEL_IMAPX_CONN_MANAGER
-CAMEL_IS_IMAPX_CONN_MANAGER
-CAMEL_TYPE_IMAPX_CONN_MANAGER
-CAMEL_IMAPX_CONN_MANAGER_CLASS
-CAMEL_IS_IMAPX_CONN_MANAGER_CLASS
-CAMEL_IMAPX_CONN_MANAGER_GET_CLASS
-CamelIMAPXConnManagerClass
-camel_imapx_conn_manager_get_type
-<SUBSECTION Private>
-CamelIMAPXConnManagerPrivate
-</SECTION>
-
-<SECTION>
 <FILE>camel-imapx-folder</FILE>
 <TITLE>CamelIMAPXFolder</TITLE>
 CamelIMAPXFolder
@@ -970,8 +947,7 @@ CamelIMAPXSettingsPrivate
 <FILE>camel-imapx-store</FILE>
 <TITLE>CamelIMAPXStore</TITLE>
 CamelIMAPXStore
-camel_imapx_store_get_server
-camel_imapx_store_op_done
+camel_imapx_store_ref_server
 camel_imapx_store_dup_quota_info
 camel_imapx_store_set_quota_info
 <SUBSECTION Standard>
diff --git a/docs/reference/camel/camel.types b/docs/reference/camel/camel.types
index 3865ec1..1c71e7a 100644
--- a/docs/reference/camel/camel.types
+++ b/docs/reference/camel/camel.types
@@ -16,7 +16,6 @@ camel_folder_search_get_type
 camel_folder_summary_get_type
 camel_gpg_context_get_type
 camel_html_parser_get_type
-camel_imapx_conn_manager_get_type
 camel_imapx_folder_get_type
 camel_imapx_search_get_type
 camel_imapx_server_get_type


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]