diff options
author | Peter Williams <peterw@src.gnome.org> | 2000-08-31 01:09:42 +0800 |
---|---|---|
committer | Peter Williams <peterw@src.gnome.org> | 2000-08-31 01:09:42 +0800 |
commit | 2bdcfe5c47e9add476eab5d848b30d9d1715c153 (patch) | |
tree | 03ea965b34ee45f22bc00a737e9d9af1dd1992f7 | |
parent | e8df3eea83688f5656c076952dfcffb297c08ad1 (diff) | |
download | gsoc2013-evolution-2bdcfe5c47e9add476eab5d848b30d9d1715c153.tar.gz gsoc2013-evolution-2bdcfe5c47e9add476eab5d848b30d9d1715c153.tar.zst gsoc2013-evolution-2bdcfe5c47e9add476eab5d848b30d9d1715c153.zip |
Make CamelServices connect only when told to (old behavior). Make CamelRemoteStore do its stuff in service::connect, not ::post_connect.
svn path=/trunk/; revision=5116
-rw-r--r-- | camel/ChangeLog | 23 | ||||
-rw-r--r-- | camel/camel-remote-store.c | 51 | ||||
-rw-r--r-- | camel/camel-remote-store.h | 2 | ||||
-rw-r--r-- | camel/camel-service.c | 22 | ||||
-rw-r--r-- | camel/camel-session.c | 19 | ||||
-rw-r--r-- | camel/camel-session.h | 9 | ||||
-rw-r--r-- | camel/providers/imap/camel-imap-store.c | 37 | ||||
-rw-r--r-- | mail/ChangeLog | 9 | ||||
-rw-r--r-- | mail/component-factory.c | 84 | ||||
-rw-r--r-- | mail/mail-config-gui.c | 11 |
10 files changed, 130 insertions, 137 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 4c74dff873..f272ee4293 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,26 @@ +2000-08-30 Peter Williams <peterw@helixcode.com> + + * camel-remote-store.c (remote_connect): Unify with remote_post_connect. + (remote_disconnect): Unify with remote_pre_disconnect. + (camel_remote_store_class_init): Don't use the post_connect and + pre_disconnect classfuncs anymore ; they weren't especially useful. + + * providers/imap/camel-imap-store.c (imap_connect): Use this again + instead of implementing post_connect. + (imap_disconnect): Analogous to above. + + * camel-session.c (camel_session_get_service_connected): New function. + Like camel_session_get_service() but also connects to the service + if needed. camel_session_get_{store,transport} (defined in the header) + used this now, preventing annoying when-to-connect problems. + + * camel-service.c (camel_service_new): Revert to the old behavior + of not connecting until told to do so. Otherwise doing auth + testing correctly is really hard. + (camel_service_connect): Fix behavior here (set the connected + flag). + (camel_service_disconnect): Unset the connected flag. + 2000-08-30 Jeffrey Stedfast <fejj@helixcode.com> * providers/imap/camel-imap-store.c: General cleanup / moving diff --git a/camel/camel-remote-store.c b/camel/camel-remote-store.c index 4534c85544..5105045104 100644 --- a/camel/camel-remote-store.c +++ b/camel/camel-remote-store.c @@ -64,8 +64,6 @@ static char *remote_get_name (CamelService *service, gboolean brief); static char *remote_get_folder_name (CamelStore *store, const char *folder_name, CamelException *ex); -static void remote_post_connect (CamelRemoteStore *store, CamelException *ex); -static void remote_pre_disconnect (CamelRemoteStore *store, CamelException *ex); static gint remote_send_string (CamelRemoteStore *store, CamelException *ex, char *fmt, va_list ap); static gint remote_send_stream (CamelRemoteStore *store, CamelStream *stream, @@ -94,8 +92,6 @@ camel_remote_store_class_init (CamelRemoteStoreClass *camel_remote_store_class) camel_store_class->get_folder_name = remote_get_folder_name; - camel_remote_store_class->post_connect = remote_post_connect; - camel_remote_store_class->pre_disconnect = remote_pre_disconnect; camel_remote_store_class->send_string = remote_send_string; camel_remote_store_class->send_stream = remote_send_stream; camel_remote_store_class->recv_line = remote_recv_line; @@ -205,6 +201,13 @@ refresh_folder_info (gpointer key, gpointer value, gpointer data) } static gboolean +timeout_cb (gpointer data) +{ + CRSC (data)->keepalive (CAMEL_REMOTE_STORE (data)); + return TRUE; +} + +static gboolean remote_connect (CamelService *service, CamelException *ex) { CamelRemoteStore *store = CAMEL_REMOTE_STORE (service); @@ -246,7 +249,8 @@ remote_connect (CamelService *service, CamelException *ex) } /* parent class connect initialization */ - CAMEL_SERVICE_CLASS (store_class)->connect (service, ex); + if (CAMEL_SERVICE_CLASS (store_class)->connect (service, ex) == FALSE) + return FALSE; store->ostream = camel_stream_fs_new_with_fd (fd); store->istream = camel_stream_buffer_new (store->ostream, CAMEL_STREAM_BUFFER_READ); @@ -254,30 +258,15 @@ remote_connect (CamelService *service, CamelException *ex) /* Okay, good enough for us */ CAMEL_SERVICE (store)->connected = TRUE; - /* implementation of postconnect */ - CRSC (store)->post_connect (store, ex); - if (camel_exception_is_set (ex)) { CamelException dex; camel_exception_init (&dex); camel_service_disconnect (CAMEL_SERVICE (store), &dex); + camel_exception_clear (&dex); return FALSE; } - - return TRUE; -} -static gboolean -timeout_cb (gpointer data) -{ - CRSC (data)->keepalive (CAMEL_REMOTE_STORE (data)); - return TRUE; -} - -static void -remote_post_connect (CamelRemoteStore *store, CamelException *ex) -{ /* Add a timeout so that we can hopefully prevent getting disconnected */ /* (Only if the implementation supports it) */ if (CRSC (store)->keepalive) { @@ -290,25 +279,20 @@ remote_post_connect (CamelRemoteStore *store, CamelException *ex) /* Let's make sure that any of our folders are brought up to speed */ g_hash_table_foreach (CAMEL_STORE (store)->folders, refresh_folder_info, ex); + + return TRUE; } -static void -remote_pre_disconnect (CamelRemoteStore *store, CamelException *ex) +static gboolean +remote_disconnect (CamelService *service, CamelException *ex) { + CamelRemoteStore *store = CAMEL_REMOTE_STORE (service); + if (store->timeout_id) { camel_session_remove_timeout (camel_service_get_session (CAMEL_SERVICE (store)), store->timeout_id); store->timeout_id = 0; } -} - -static gboolean -remote_disconnect (CamelService *service, CamelException *ex) -{ - CamelRemoteStore *store = CAMEL_REMOTE_STORE (service); - - CRSC (service)->pre_disconnect (store, ex); - /* if the exception is set, screw it and dconn anyway */ if (!CAMEL_SERVICE_CLASS (store_class)->disconnect (service, ex)) return FALSE; @@ -361,6 +345,7 @@ remote_send_string (CamelRemoteStore *store, CamelException *ex, char *fmt, va_l camel_exception_init (&dex); camel_service_disconnect (CAMEL_SERVICE (store), &dex); + camel_exception_clear (&dex); return -1; } g_free (cmdbuf); @@ -419,6 +404,7 @@ remote_send_stream (CamelRemoteStore *store, CamelStream *stream, CamelException camel_exception_init (&dex); camel_service_disconnect (CAMEL_SERVICE (store), &dex); + camel_exception_clear (&dex); return -1; } @@ -478,6 +464,7 @@ remote_recv_line (CamelRemoteStore *store, char **dest, CamelException *ex) camel_exception_init (&dex); camel_service_disconnect (CAMEL_SERVICE (store), &dex); + camel_exception_clear (&dex); return -1; } diff --git a/camel/camel-remote-store.h b/camel/camel-remote-store.h index 55862513e8..627b012f3b 100644 --- a/camel/camel-remote-store.h +++ b/camel/camel-remote-store.h @@ -49,8 +49,6 @@ typedef struct { typedef struct { CamelStoreClass parent_class; - void (*post_connect) (CamelRemoteStore *store, CamelException *ex); - void (*pre_disconnect)(CamelRemoteStore *store, CamelException *ex); gint (*send_string) (CamelRemoteStore *store, CamelException *ex, char *fmt, va_list ap); gint (*send_stream) (CamelRemoteStore *store, CamelStream *stream, diff --git a/camel/camel-service.c b/camel/camel-service.c index 9df7837bf7..63af88f4cb 100644 --- a/camel/camel-service.c +++ b/camel/camel-service.c @@ -176,6 +176,7 @@ camel_service_new (CamelType type, CamelSession *session, CamelProvider *provide service->connected = FALSE; +#if 0 if (!url->empty) { if (CSERV_CLASS (service)->connect (service, ex) == FALSE) { camel_object_unref (CAMEL_OBJECT (service)); @@ -184,6 +185,7 @@ camel_service_new (CamelType type, CamelSession *session, CamelProvider *provide service->connected = TRUE; } +#endif return service; } @@ -224,7 +226,12 @@ camel_service_connect (CamelService *service, CamelException *ex) return TRUE; } - return CSERV_CLASS (service)->connect (service, ex); + if (CSERV_CLASS (service)->connect (service, ex)) { + service->connected = TRUE; + return TRUE; + } + + return FALSE; } static gboolean @@ -253,13 +260,17 @@ service_disconnect (CamelService *service, CamelException *ex) gboolean camel_service_disconnect (CamelService *service, CamelException *ex) { + gboolean res; + if (!service->connected) { camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_NOT_CONNECTED, "Trying to disconnect from a service that isn't connected"); return FALSE; } - return CSERV_CLASS (service)->disconnect (service, ex); + res = CSERV_CLASS (service)->disconnect (service, ex); + service->connected = FALSE; + return res; } /** @@ -387,13 +398,12 @@ query_auth_types_func (CamelService *service, CamelException *ex) GList * camel_service_query_auth_types (CamelService *service, CamelException *ex) { - if (service->connected) - return CSERV_CLASS (service)->query_auth_types_connected (service, ex); - else + if (service->url->empty) return CSERV_CLASS (service)->query_auth_types_generic (service, ex); + else + return CSERV_CLASS (service)->query_auth_types_connected (service, ex); } - static void free_auth_types (CamelService *service, GList *authtypes) { diff --git a/camel/camel-session.c b/camel/camel-session.c index 3454517216..9992a48aaf 100644 --- a/camel/camel-session.c +++ b/camel/camel-session.c @@ -253,6 +253,25 @@ camel_session_get_service (CamelSession *session, const char *url_string, return service; } +CamelService * +camel_session_get_service_connected (CamelSession *session, const char *url_string, + CamelProviderType type, CamelException *ex) +{ + CamelService *svc; + + svc = camel_session_get_service (session, url_string, type, ex); + if (svc == NULL) + return NULL; + + if (svc->connected == FALSE) { + if (camel_service_connect (svc, ex) == FALSE) { + camel_object_unref (CAMEL_OBJECT (svc)); + return NULL; + } + } + + return svc; +} /** * camel_session_query_authenticator: query the session authenticator diff --git a/camel/camel-session.h b/camel/camel-session.h index 704ae6a613..7cb2306e4c 100644 --- a/camel/camel-session.h +++ b/camel/camel-session.h @@ -95,10 +95,15 @@ CamelService * camel_session_get_service (CamelSession *session, const char *url_string, CamelProviderType type, CamelException *ex); +CamelService * camel_session_get_service_connected (CamelSession *session, + const char *url_string, + CamelProviderType type, + CamelException *ex); + #define camel_session_get_store(session, url_string, ex) \ - ((CamelStore *) camel_session_get_service (session, url_string, CAMEL_PROVIDER_STORE, ex)) + ((CamelStore *) camel_session_get_service_connected (session, url_string, CAMEL_PROVIDER_STORE, ex)) #define camel_session_get_transport(session, url_string, ex) \ - ((CamelTransport *) camel_session_get_service (session, url_string, CAMEL_PROVIDER_TRANSPORT, ex)) + ((CamelTransport *) camel_session_get_service_connected (session, url_string, CAMEL_PROVIDER_TRANSPORT, ex)) char * camel_session_query_authenticator (CamelSession *session, diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c index 31b0019688..c3b859c47e 100644 --- a/camel/providers/imap/camel-imap-store.c +++ b/camel/providers/imap/camel-imap-store.c @@ -52,8 +52,8 @@ static CamelRemoteStoreClass *remote_store_class = NULL; static gboolean imap_create (CamelFolder *folder, CamelException *ex); -static void imap_post_connect (CamelRemoteStore *remote_store, CamelException *ex); -static void imap_pre_disconnect (CamelRemoteStore *remote_store, CamelException *ex); +static gboolean imap_connect (CamelService *service, CamelException *ex); +static gboolean imap_disconnect (CamelService *service, CamelException *ex); static GList *query_auth_types_generic (CamelService *service, CamelException *ex); static GList *query_auth_types_connected (CamelService *service, CamelException *ex); static CamelFolder *get_folder (CamelStore *store, const char *folder_name, gboolean create, @@ -79,11 +79,11 @@ camel_imap_store_class_init (CamelImapStoreClass *camel_imap_store_class) /* virtual method overload */ camel_service_class->query_auth_types_generic = query_auth_types_generic; camel_service_class->query_auth_types_connected = query_auth_types_connected; + camel_service_class->connect = imap_connect; + camel_service_class->disconnect = imap_disconnect; camel_store_class->get_folder = get_folder; - camel_remote_store_class->post_connect = imap_post_connect; - camel_remote_store_class->pre_disconnect = imap_pre_disconnect; camel_remote_store_class->keepalive = imap_keepalive; } @@ -170,23 +170,25 @@ query_auth_types_generic (CamelService *service, CamelException *ex) return g_list_prepend (prev, &password_authtype); } -static void -imap_post_connect (CamelRemoteStore *remote_store, CamelException *ex) +static gboolean +imap_connect (CamelService *service, CamelException *ex) { - CamelService *service = CAMEL_SERVICE (remote_store); - CamelImapStore *store = CAMEL_IMAP_STORE (remote_store); + CamelImapStore *store = CAMEL_IMAP_STORE (service); CamelSession *session = camel_service_get_session (CAMEL_SERVICE (store)); gchar *buf, *result, *errbuf = NULL; gboolean authenticated = FALSE; gint status; + if (CAMEL_SERVICE_CLASS (remote_store_class)->connect (service, ex) == FALSE) + return FALSE; + store->command = 0; g_free (store->dir_sep); store->dir_sep = g_strdup ("/"); /* default dir sep */ /* Read the greeting, if any. */ - if (camel_remote_store_recv_line (remote_store, &buf, ex) < 0) { - return; + if (camel_remote_store_recv_line (CAMEL_REMOTE_STORE (service), &buf, ex) < 0) { + return FALSE; } g_free (buf); @@ -215,8 +217,9 @@ imap_post_connect (CamelRemoteStore *remote_store, CamelException *ex) errbuf = NULL; if (!service->url->passwd) { - camel_service_disconnect (service, ex); - return; + camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL, + "You didn\'t enter a password."); + return FALSE; } } @@ -278,13 +281,13 @@ imap_post_connect (CamelRemoteStore *remote_store, CamelException *ex) g_free (result); - CAMEL_REMOTE_STORE_CLASS (remote_store_class)->post_connect (remote_store, ex); + return TRUE; } -static void -imap_pre_disconnect (CamelRemoteStore *remote_store, CamelException *ex) +static gboolean +imap_disconnect (CamelService *service, CamelException *ex) { - CamelImapStore *store = CAMEL_IMAP_STORE (remote_store); + CamelImapStore *store = CAMEL_IMAP_STORE (service); char *result; int status; @@ -300,7 +303,7 @@ imap_pre_disconnect (CamelRemoteStore *remote_store, CamelException *ex) store->current_folder = NULL; - CAMEL_REMOTE_STORE_CLASS (remote_store_class)->pre_disconnect (remote_store, ex); + return CAMEL_SERVICE_CLASS (remote_store_class)->disconnect (service, ex); } const gchar * diff --git a/mail/ChangeLog b/mail/ChangeLog index 5b165ed3c2..7e7a873d8e 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,12 @@ +2000-08-30 Peter Williams <peterw@helixcode.com> + + * mail-config-gui.c (do_test_service): Explicitly connect to + the service again. + + * component-factory.c (mail_load_storages): Now that + camel_service_get_provider exists, use it to make this function + much simpler. + 2000-08-29 Peter Williams <peterw@helixcode.com> * folder-browser.c (folder_browser_new): Ref the Evolution_Shell. diff --git a/mail/component-factory.c b/mail/component-factory.c index 47153ad530..08dd3f73fc 100644 --- a/mail/component-factory.c +++ b/mail/component-factory.c @@ -202,95 +202,36 @@ void mail_load_storages (Evolution_Shell corba_shell, GSList *sources) { CamelException ex; - GList *providers; - GSList *iter; MailConfigService *svc; - GPtrArray *protos; - int i; + GSList *iter; camel_exception_init (&ex); - protos = g_ptr_array_new(); - - /* First, open all the storages so that camel - * loads only the providers that we're going - * to need. - * - * We don't open the storage per se but we - * slurp its protocol so that we don't try - * to connect to it just yet. - * - * We remember the protocol associated with - * each URI for the second pass. + + /* Load each service (don't connect!). Check its provider and + * see if this belongs in the shell's folder list. If so, add + * it. */ - + for (iter = sources; iter; iter = iter->next) { CamelService *temp; - gchar *p; - gchar *proto; + CamelProvider *prov = NULL; svc = (MailConfigService *) iter->data; if (svc->url == NULL || svc->url[0] == '\0') continue; - p = strchr (svc->url, ':'); - if (!p || *p == '\0') { - g_warning ("Bad url (no protocol): %s", svc->url); - continue; - } - - p++; /* we're on the char after the colon */ - - proto = g_strndup (svc->url, p - svc->url); - g_ptr_array_add (protos, proto); - - temp = camel_session_get_service (session, proto, + temp = camel_session_get_service (session, svc->url, CAMEL_PROVIDER_STORE, &ex); if (temp == NULL) { /* FIXME: real error dialog */ g_warning ("couldn't get service %s: %s\n", svc->url, camel_exception_get_description (&ex)); - } else - camel_object_unref (CAMEL_OBJECT (temp)); - } - - /* Okay. All the providers we need are loaded. - * Now get the list of them. - */ - - providers = camel_session_list_providers (session, FALSE); - - /* Now zip through the sources a second time. This time - * we check to see if its provider is a storage or not. - * If so, add it to the shell. - */ - - for (iter = sources, i = 0; iter; iter = iter->next, i++) { - CamelProvider *prov = NULL; - GList *prov_iter; - gchar *proto; - - svc = (MailConfigService *) iter->data; - - proto = g_ptr_array_index (protos, i); - - /* find its provider */ - for (prov_iter = providers; prov_iter; prov_iter = prov_iter->next) { - CamelProvider *thisone = (CamelProvider *) prov_iter->data; - - if (!g_strncasecmp (proto, thisone->protocol, strlen (thisone->protocol))) { - prov = thisone; - break; - } - } - - g_free (proto); - - if (prov == NULL) { - g_warning ("No provider for loaded URL \"%s\"?", svc->url); continue; } + prov = camel_service_get_provider (temp); + /* FIXME: this case is ambiguous for things like the mbox provider, * which can really be a spool (/var/spool/mail/user) or a storage * (~/mail/, eg). That issue can't be resolved on the provider @@ -306,10 +247,9 @@ mail_load_storages (Evolution_Shell corba_shell, GSList *sources) camel_exception_get_description (&ex)); } } - } - g_ptr_array_free (protos, TRUE); - camel_exception_clear (&ex); + camel_object_unref (CAMEL_OBJECT (temp)); + } } void diff --git a/mail/mail-config-gui.c b/mail/mail-config-gui.c index e64e7a15be..8a007dc1c1 100644 --- a/mail/mail-config-gui.c +++ b/mail/mail-config-gui.c @@ -2266,15 +2266,14 @@ static void do_test_service (gpointer in_data, gpointer op_data, CamelException service = camel_session_get_service (session, input->url, input->type, ex); - + if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) { data->success = FALSE; - /*} else if (camel_service_connect (service, ex)) { - *camel_service_disconnect (service, ex); - *data->success = TRUE; - */ + } else if (camel_service_connect (service, ex)) { + camel_service_disconnect (service, ex); + data->success = TRUE; } else { - data->success = TRUE; + data->success = FALSE; } camel_object_unref (CAMEL_OBJECT (service)); |