aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorPeter Williams <peterw@src.gnome.org>2000-08-31 01:09:42 +0800
committerPeter Williams <peterw@src.gnome.org>2000-08-31 01:09:42 +0800
commit2bdcfe5c47e9add476eab5d848b30d9d1715c153 (patch)
tree03ea965b34ee45f22bc00a737e9d9af1dd1992f7 /camel
parente8df3eea83688f5656c076952dfcffb297c08ad1 (diff)
downloadgsoc2013-evolution-2bdcfe5c47e9add476eab5d848b30d9d1715c153.tar
gsoc2013-evolution-2bdcfe5c47e9add476eab5d848b30d9d1715c153.tar.gz
gsoc2013-evolution-2bdcfe5c47e9add476eab5d848b30d9d1715c153.tar.bz2
gsoc2013-evolution-2bdcfe5c47e9add476eab5d848b30d9d1715c153.tar.lz
gsoc2013-evolution-2bdcfe5c47e9add476eab5d848b30d9d1715c153.tar.xz
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
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog23
-rw-r--r--camel/camel-remote-store.c51
-rw-r--r--camel/camel-remote-store.h2
-rw-r--r--camel/camel-service.c22
-rw-r--r--camel/camel-session.c19
-rw-r--r--camel/camel-session.h9
-rw-r--r--camel/providers/imap/camel-imap-store.c37
7 files changed, 104 insertions, 59 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 *