From fa86654782270089197d30bbe94f657bb9a0b529 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Tue, 3 Aug 2004 16:31:47 +0000 Subject: Pass a reconnect func. 2004-08-03 Jeffrey Stedfast * providers/imap4/camel-imap4-store.c (imap4_construct): Pass a reconnect func. * providers/imap4/camel-imap4-engine.c (camel_imap4_engine_iterate): Reconnect if needed. (camel_imap4_engine_new): Now takes a reconnect func. svn path=/trunk/; revision=26813 --- camel/providers/imap4/camel-imap4-engine.c | 22 +++++++++++++++++++++- camel/providers/imap4/camel-imap4-engine.h | 7 ++++++- camel/providers/imap4/camel-imap4-store.c | 3 ++- 3 files changed, 29 insertions(+), 3 deletions(-) (limited to 'camel/providers') diff --git a/camel/providers/imap4/camel-imap4-engine.c b/camel/providers/imap4/camel-imap4-engine.c index b1a2bbc2e9..88c03310ae 100644 --- a/camel/providers/imap4/camel-imap4-engine.c +++ b/camel/providers/imap4/camel-imap4-engine.c @@ -167,7 +167,7 @@ camel_imap4_engine_finalize (CamelObject *object) * Returns a new imap4 engine **/ CamelIMAP4Engine * -camel_imap4_engine_new (CamelService *service) +camel_imap4_engine_new (CamelService *service, CamelIMAP4ReconnectFunc reconnect) { CamelIMAP4Engine *engine; @@ -177,6 +177,7 @@ camel_imap4_engine_new (CamelService *service) engine->session = service->session; engine->url = service->url; engine->service = service; + engine->reconnect = reconnect; return engine; } @@ -1232,6 +1233,25 @@ camel_imap4_engine_iterate (CamelIMAP4Engine *engine) if (e_dlist_empty (&engine->queue)) return 0; + /* This sucks... it would be nicer if we didn't have to check the stream's disconnected status */ + if ((engine->state == CAMEL_IMAP4_ENGINE_DISCONNECTED || engine->istream->disconnected) && !engine->reconnecting) { + CamelException rex; + gboolean connected; + + camel_exception_init (&rex); + engine->reconnecting = TRUE; + connected = engine->reconnect (engine, &rex); + engine->reconnecting = FALSE; + + if (!connected) { + /* pop the first command and act as tho it failed (which, technically, it did...) */ + ic = (CamelIMAP4Command *) e_dlist_remhead (&engine->queue); + ic->status = CAMEL_IMAP4_COMMAND_ERROR; + camel_exception_xfer (&ic->ex, &rex); + return -1; + } + } + /* check to see if we need to pre-queue a SELECT, if so do it */ engine_prequeue_folder_select (engine); diff --git a/camel/providers/imap4/camel-imap4-engine.h b/camel/providers/imap4/camel-imap4-engine.h index 8d97011be4..738a17f7b6 100644 --- a/camel/providers/imap4/camel-imap4-engine.h +++ b/camel/providers/imap4/camel-imap4-engine.h @@ -143,9 +143,14 @@ enum { CAMEL_IMAP4_ENGINE_MAXLEN_TOKEN }; +typedef gboolean (* CamelIMAP4ReconnectFunc) (CamelIMAP4Engine *engine, CamelException *ex); + struct _CamelIMAP4Engine { CamelObject parent_object; + CamelIMAP4ReconnectFunc reconnect; + gboolean reconnecting; + CamelSession *session; CamelService *service; CamelURL *url; @@ -182,7 +187,7 @@ struct _CamelIMAP4EngineClass { CamelType camel_imap4_engine_get_type (void); -CamelIMAP4Engine *camel_imap4_engine_new (CamelService *service); +CamelIMAP4Engine *camel_imap4_engine_new (CamelService *service, CamelIMAP4ReconnectFunc reconnect); /* returns 0 on success or -1 on error */ int camel_imap4_engine_take_stream (CamelIMAP4Engine *engine, CamelStream *stream, CamelException *ex); diff --git a/camel/providers/imap4/camel-imap4-store.c b/camel/providers/imap4/camel-imap4-store.c index 0d47c3252e..ee96800ed5 100644 --- a/camel/providers/imap4/camel-imap4-store.c +++ b/camel/providers/imap4/camel-imap4-store.c @@ -53,6 +53,7 @@ static void imap4_construct (CamelService *service, CamelSession *session, CamelException *ex); static char *imap4_get_name (CamelService *service, gboolean brief); static gboolean imap4_connect (CamelService *service, CamelException *ex); +static gboolean imap4_reconnect (CamelIMAP4Engine *engine, CamelException *ex); static gboolean imap4_disconnect (CamelService *service, gboolean clean, CamelException *ex); static GList *imap4_query_auth_types (CamelService *service, CamelException *ex); @@ -166,7 +167,7 @@ imap4_construct (CamelService *service, CamelSession *session, CamelProvider *pr return; store->storage_path = camel_session_get_storage_path (session, service, ex); - store->engine = camel_imap4_engine_new (service); + store->engine = camel_imap4_engine_new (service, imap4_reconnect); } static char * -- cgit