aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@novell.com>2004-07-27 05:24:20 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2004-07-27 05:24:20 +0800
commit8cfdad88c98a0e7a7f09e7ae07cff451a9c6cce4 (patch)
tree340b2752994e8c4ded399c2247d1a106b74e0189
parentbde01cf042eeb5ea55874828a334ad1cbb492108 (diff)
downloadgsoc2013-evolution-8cfdad88c98a0e7a7f09e7ae07cff451a9c6cce4.tar.gz
gsoc2013-evolution-8cfdad88c98a0e7a7f09e7ae07cff451a9c6cce4.tar.zst
gsoc2013-evolution-8cfdad88c98a0e7a7f09e7ae07cff451a9c6cce4.zip
Don't instantiate an engine here. Instead, take an engine as an argument
2004-07-26 Jeffrey Stedfast <fejj@novell.com> * providers/imap4/camel-imap4-store.c (connect_to_server): Don't instantiate an engine here. Instead, take an engine as an argument (it has a service pointer) and connect using that. Also, if connect fails, don't unref the engine. (connect_to_server_wrapper): Now also takes an engine argument rather than a service argument. (imap4_try_authenticate): Now also takes an engine argument. (imap4_connect): Pass the engine to connect/auth functions rather than the store. (imap4_query_auth_types): Updated. (imap4_disconnect): Don't unref the engine here. (camel_imap4_store_init): Create the engine here. (imap4_get_folder_info): Can't check engine == NULL to know to connect (that was a broken check anyway). * providers/imap4/camel-imap4-engine.c (camel_imap4_engine_new): Now simply takes a service argument rather than a session and url. (camel_imap4_engine_next_token): Set the state to DISCONNECTED. (camel_imap4_engine_eat_line): Same. (camel_imap4_engine_line): Same. (camel_imap4_engine_literal): Same. svn path=/trunk/; revision=26740
-rw-r--r--camel/ChangeLog24
-rw-r--r--camel/providers/imap4/camel-imap4-engine.c36
-rw-r--r--camel/providers/imap4/camel-imap4-engine.h21
-rw-r--r--camel/providers/imap4/camel-imap4-store.c81
4 files changed, 77 insertions, 85 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 3f01cd49c7..d8862c2f2d 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,27 @@
+2004-07-26 Jeffrey Stedfast <fejj@novell.com>
+
+ * providers/imap4/camel-imap4-store.c (connect_to_server): Don't
+ instantiate an engine here. Instead, take an engine as an argument
+ (it has a service pointer) and connect using that. Also, if
+ connect fails, don't unref the engine.
+ (connect_to_server_wrapper): Now also takes an engine argument
+ rather than a service argument.
+ (imap4_try_authenticate): Now also takes an engine argument.
+ (imap4_connect): Pass the engine to connect/auth functions rather
+ than the store.
+ (imap4_query_auth_types): Updated.
+ (imap4_disconnect): Don't unref the engine here.
+ (camel_imap4_store_init): Create the engine here.
+ (imap4_get_folder_info): Can't check engine == NULL to know to
+ connect (that was a broken check anyway).
+
+ * providers/imap4/camel-imap4-engine.c (camel_imap4_engine_new):
+ Now simply takes a service argument rather than a session and url.
+ (camel_imap4_engine_next_token): Set the state to DISCONNECTED.
+ (camel_imap4_engine_eat_line): Same.
+ (camel_imap4_engine_line): Same.
+ (camel_imap4_engine_literal): Same.
+
2004-07-22 Not Zed <NotZed@Ximian.com>
** See bug #61761.
diff --git a/camel/providers/imap4/camel-imap4-engine.c b/camel/providers/imap4/camel-imap4-engine.c
index bd5ebfff07..40501ae399 100644
--- a/camel/providers/imap4/camel-imap4-engine.c
+++ b/camel/providers/imap4/camel-imap4-engine.c
@@ -82,6 +82,7 @@ camel_imap4_engine_init (CamelIMAP4Engine *engine, CamelIMAP4EngineClass *klass)
engine->level = CAMEL_IMAP4_LEVEL_UNKNOWN;
engine->session = NULL;
+ engine->service = NULL;
engine->url = NULL;
engine->istream = NULL;
@@ -134,9 +135,6 @@ camel_imap4_engine_finalize (CamelObject *object)
CamelIMAP4Engine *engine = (CamelIMAP4Engine *) object;
EDListNode *node;
- if (engine->session)
- camel_object_unref (engine->session);
-
if (engine->istream)
camel_object_unref (engine->istream);
@@ -164,22 +162,21 @@ camel_imap4_engine_finalize (CamelObject *object)
/**
* camel_imap4_engine_new:
- * @session: session
- * @url: service url
+ * @service: service
*
* Returns a new imap4 engine
**/
CamelIMAP4Engine *
-camel_imap4_engine_new (CamelSession *session, CamelURL *url)
+camel_imap4_engine_new (CamelService *service)
{
CamelIMAP4Engine *engine;
- g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL);
+ g_return_val_if_fail (CAMEL_IS_SERVICE (service), NULL);
engine = (CamelIMAP4Engine *) camel_object_new (CAMEL_TYPE_IMAP4_ENGINE);
- camel_object_ref (session);
- engine->session = session;
- engine->url = url;
+ engine->session = service->session;
+ engine->url = service->url;
+ engine->service = service;
return engine;
}
@@ -989,15 +986,7 @@ camel_imap4_engine_handle_untagged_1 (CamelIMAP4Engine *engine, camel_imap4_toke
engine->state = CAMEL_IMAP4_ENGINE_DISCONNECTED;
- /* FIXME: emit a "disconnected" signal for our Store?
- * The Store could then initiate a reconnect if
- * desirable. */
-
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- _("IMAP4 server %s unexpectedly disconnected: %s"),
- engine->url->host, _("Got BYE response"));
-
- return -1;
+ /* we don't return -1 here because there may be more untagged responses after the BYE */
} else if (!strcmp ("CAPABILITY", token->v.atom)) {
/* capability tokens follow */
if (engine_parse_capability (engine, '\n', ex) == -1)
@@ -1377,6 +1366,9 @@ camel_imap4_engine_next_token (CamelIMAP4Engine *engine, camel_imap4_token_t *to
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
_("IMAP4 server %s unexpectedly disconnected: %s"),
engine->url->host, errno ? g_strerror (errno) : _("Unknown"));
+
+ engine->state = CAMEL_IMAP4_ENGINE_DISCONNECTED;
+
return -1;
}
@@ -1405,6 +1397,8 @@ camel_imap4_engine_eat_line (CamelIMAP4Engine *engine, CamelException *ex)
_("IMAP4 server %s unexpectedly disconnected: %s"),
engine->url->host, errno ? g_strerror (errno) : _("Unknown"));
+ engine->state = CAMEL_IMAP4_ENGINE_DISCONNECTED;
+
return -1;
}
}
@@ -1438,6 +1432,8 @@ camel_imap4_engine_line (CamelIMAP4Engine *engine, unsigned char **line, size_t
if (linebuf != NULL)
g_byte_array_free (linebuf, TRUE);
+ engine->state = CAMEL_IMAP4_ENGINE_DISCONNECTED;
+
return -1;
}
@@ -1478,6 +1474,8 @@ camel_imap4_engine_literal (CamelIMAP4Engine *engine, unsigned char **literal, s
if (literalbuf != NULL)
g_byte_array_free (literalbuf, TRUE);
+ engine->state = CAMEL_IMAP4_ENGINE_DISCONNECTED;
+
return -1;
}
diff --git a/camel/providers/imap4/camel-imap4-engine.h b/camel/providers/imap4/camel-imap4-engine.h
index 25ae7ed113..1dda36ac43 100644
--- a/camel/providers/imap4/camel-imap4-engine.h
+++ b/camel/providers/imap4/camel-imap4-engine.h
@@ -68,14 +68,14 @@ typedef enum {
enum {
CAMEL_IMAP4_CAPABILITY_IMAP44 = (1 << 0),
CAMEL_IMAP4_CAPABILITY_IMAP44REV1 = (1 << 1),
- CAMEL_IMAP4_CAPABILITY_STATUS = (1 << 2),
- CAMEL_IMAP4_CAPABILITY_NAMESPACE = (1 << 3),
- CAMEL_IMAP4_CAPABILITY_UIDPLUS = (1 << 4),
- CAMEL_IMAP4_CAPABILITY_LITERALPLUS = (1 << 5),
- CAMEL_IMAP4_CAPABILITY_LOGINDISABLED = (1 << 6),
- CAMEL_IMAP4_CAPABILITY_STARTTLS = (1 << 7),
- CAMEL_IMAP4_CAPABILITY_useful_lsub = (1 << 8),
- CAMEL_IMAP4_CAPABILITY_utf8_search = (1 << 9),
+ CAMEL_IMAP4_CAPABILITY_STATUS = (1 << 2),
+ CAMEL_IMAP4_CAPABILITY_NAMESPACE = (1 << 3),
+ CAMEL_IMAP4_CAPABILITY_UIDPLUS = (1 << 4),
+ CAMEL_IMAP4_CAPABILITY_LITERALPLUS = (1 << 5),
+ CAMEL_IMAP4_CAPABILITY_LOGINDISABLED = (1 << 6),
+ CAMEL_IMAP4_CAPABILITY_STARTTLS = (1 << 7),
+ CAMEL_IMAP4_CAPABILITY_useful_lsub = (1 << 8),
+ CAMEL_IMAP4_CAPABILITY_utf8_search = (1 << 9),
};
typedef enum {
@@ -147,11 +147,12 @@ struct _CamelIMAP4Engine {
CamelObject parent_object;
CamelSession *session;
+ CamelService *service;
CamelURL *url;
camel_imap4_engine_t state;
camel_imap4_level_t level;
- guint32 capa;
+ guint32 capa:31;
guint32 maxlen:31;
guint32 maxlentype:1;
@@ -181,7 +182,7 @@ struct _CamelIMAP4EngineClass {
CamelType camel_imap4_engine_get_type (void);
-CamelIMAP4Engine *camel_imap4_engine_new (CamelSession *session, CamelURL *url);
+CamelIMAP4Engine *camel_imap4_engine_new (CamelService *service);
/* 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 26a9186a03..08f7459614 100644
--- a/camel/providers/imap4/camel-imap4-store.c
+++ b/camel/providers/imap4/camel-imap4-store.c
@@ -159,13 +159,14 @@ camel_imap4_store_finalize (CamelObject *object)
static void
imap4_construct (CamelService *service, CamelSession *session, CamelProvider *provider, CamelURL *url, CamelException *ex)
{
- CamelIMAP4Store *imap_store = (CamelIMAP4Store *) service;
+ CamelIMAP4Store *store = (CamelIMAP4Store *) service;
CAMEL_SERVICE_CLASS (parent_class)->construct (service, session, provider, url, ex);
if (camel_exception_is_set (ex))
return;
- imap_store->storage_path = camel_session_get_storage_path (session, service, ex);
+ store->storage_path = camel_session_get_storage_path (session, service, ex);
+ store->engine = camel_imap4_engine_new (service);
}
static char *
@@ -188,18 +189,12 @@ enum {
#define STARTTLS_FLAGS (CAMEL_TCP_STREAM_SSL_ENABLE_TLS)
static gboolean
-connect_to_server (CamelService *service, struct hostent *host, int ssl_mode, int try_starttls, CamelException *ex)
+connect_to_server (CamelIMAP4Engine *engine, struct hostent *host, int ssl_mode, int try_starttls, CamelException *ex)
{
- CamelIMAP4Store *store = (CamelIMAP4Store *) service;
- CamelIMAP4Engine *engine;
+ CamelService *service = engine->service;
CamelStream *tcp_stream;
int port, ret;
- if (store->engine) {
- camel_object_unref (store->engine);
- store->engine = NULL;
- }
-
port = service->url->port ? service->url->port : 143;
if (ssl_mode) {
@@ -225,7 +220,6 @@ connect_to_server (CamelService *service, struct hostent *host, int ssl_mode, in
tcp_stream = camel_tcp_stream_raw_new ();
}
- fprintf (stderr, "connecting to %s:%d\n", service->url->host, port);
if ((ret = camel_tcp_stream_connect ((CamelTcpStream *) tcp_stream, host, port)) == -1) {
if (errno == EINTR)
camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL,
@@ -241,20 +235,11 @@ connect_to_server (CamelService *service, struct hostent *host, int ssl_mode, in
return FALSE;
}
- engine = camel_imap4_engine_new (service->session, service->url);
- if (camel_imap4_engine_take_stream (engine, tcp_stream, ex) == -1) {
- camel_object_unref (engine);
-
+ if (camel_imap4_engine_take_stream (engine, tcp_stream, ex) == -1)
return FALSE;
- }
- if (camel_imap4_engine_capability (engine, ex) == -1) {
- camel_object_unref (engine);
-
+ if (camel_imap4_engine_capability (engine, ex) == -1)
return FALSE;
- }
-
- store->engine = engine;
#ifdef HAVE_SSL
if (ssl_mode == USE_SSL_WHEN_POSSIBLE) {
@@ -271,7 +256,7 @@ connect_to_server (CamelService *service, struct hostent *host, int ssl_mode, in
_("Failed to connect to IMAP server %s in secure mode: "
"Server does not support STARTTLS"),
service->url->host);
- goto exception;
+ return FALSE;
}
}
}
@@ -301,20 +286,13 @@ connect_to_server (CamelService *service, struct hostent *host, int ssl_mode, in
camel_imap4_command_unref (ic);
- goto exception;
+ return FALSE;
}
camel_imap4_command_unref (ic);
}
return TRUE;
-
- exception:
-
- camel_object_unref (store->engine);
- store->engine = NULL;
-
- return FALSE;
#endif /* HAVE_SSL */
}
@@ -330,8 +308,9 @@ static struct {
};
static gboolean
-connect_to_server_wrapper (CamelService *service, CamelException *ex)
+connect_to_server_wrapper (CamelIMAP4Engine *engine, CamelException *ex)
{
+ CamelService *service = engine->service;
const char *use_ssl;
struct hostent *h;
int ssl_mode;
@@ -351,19 +330,19 @@ connect_to_server_wrapper (CamelService *service, CamelException *ex)
if (ssl_mode == USE_SSL_ALWAYS) {
/* First try the ssl port */
- if (!(ret = connect_to_server (service, h, ssl_mode, FALSE, ex))) {
+ if (!(ret = connect_to_server (engine, h, ssl_mode, FALSE, ex))) {
if (camel_exception_get_id (ex) == CAMEL_EXCEPTION_SERVICE_UNAVAILABLE) {
/* The ssl port seems to be unavailable, lets try STARTTLS */
camel_exception_clear (ex);
- ret = connect_to_server (service, h, ssl_mode, TRUE, ex);
+ ret = connect_to_server (engine, h, ssl_mode, TRUE, ex);
}
}
} else if (ssl_mode == USE_SSL_WHEN_POSSIBLE) {
/* If the server supports STARTTLS, use it */
- ret = connect_to_server (service, h, ssl_mode, TRUE, ex);
+ ret = connect_to_server (engine, h, ssl_mode, TRUE, ex);
} else {
/* User doesn't care about SSL */
- ret = connect_to_server (service, h, USE_SSL_NEVER, FALSE, ex);
+ ret = connect_to_server (engine, h, USE_SSL_NEVER, FALSE, ex);
}
camel_free_host (h);
@@ -410,9 +389,9 @@ sasl_auth (CamelIMAP4Engine *engine, CamelIMAP4Command *ic, const unsigned char
}
static int
-imap4_try_authenticate (CamelService *service, gboolean reprompt, const char *errmsg, CamelException *ex)
+imap4_try_authenticate (CamelIMAP4Engine *engine, gboolean reprompt, const char *errmsg, CamelException *ex)
{
- CamelIMAP4Store *store = (CamelIMAP4Store *) service;
+ CamelService *service = engine->service;
CamelSession *session = service->session;
CamelSasl *sasl = NULL;
CamelIMAP4Command *ic;
@@ -441,18 +420,18 @@ imap4_try_authenticate (CamelService *service, gboolean reprompt, const char *er
if (service->url->authmech) {
CamelServiceAuthType *mech;
- mech = g_hash_table_lookup (store->engine->authtypes, service->url->authmech);
+ mech = g_hash_table_lookup (engine->authtypes, service->url->authmech);
sasl = camel_sasl_new ("imap4", mech->authproto, service);
- ic = camel_imap4_engine_queue (store->engine, NULL, "AUTHENTICATE %s\r\n", service->url->authmech);
+ ic = camel_imap4_engine_queue (engine, NULL, "AUTHENTICATE %s\r\n", service->url->authmech);
ic->plus = sasl_auth;
ic->user_data = sasl;
} else {
- ic = camel_imap4_engine_queue (store->engine, NULL, "LOGIN %S %S\r\n",
+ ic = camel_imap4_engine_queue (engine, NULL, "LOGIN %S %S\r\n",
service->url->user, service->url->passwd);
}
- while ((id = camel_imap4_engine_iterate (store->engine)) < ic->id && id != -1)
+ while ((id = camel_imap4_engine_iterate (engine)) < ic->id && id != -1)
;
if (sasl != NULL)
@@ -490,7 +469,7 @@ imap4_connect (CamelService *service, CamelException *ex)
CAMEL_SERVICE_LOCK (store, connect_lock);
- if (!connect_to_server_wrapper (service, ex)) {
+ if (!connect_to_server_wrapper (store->engine, ex)) {
CAMEL_SERVICE_UNLOCK (store, connect_lock);
return FALSE;
}
@@ -502,16 +481,13 @@ imap4_connect (CamelService *service, CamelException *ex)
_("Cannot authenticate to IMAP server %s using %s"),
service->url->host, service->url->authmech);
- camel_object_unref (store->engine);
- store->engine = NULL;
-
CAMEL_SERVICE_UNLOCK (store, connect_lock);
return FALSE;
}
camel_exception_init (&lex);
- while (imap4_try_authenticate (service, reprompt, errmsg, &lex)) {
+ while (imap4_try_authenticate (store->engine, reprompt, errmsg, &lex)) {
g_free (errmsg);
errmsg = g_strdup (lex.desc);
camel_exception_clear (&lex);
@@ -521,8 +497,6 @@ imap4_connect (CamelService *service, CamelException *ex)
if (camel_exception_is_set (&lex)) {
camel_exception_xfer (ex, &lex);
- camel_object_unref (store->engine);
- store->engine = NULL;
CAMEL_SERVICE_UNLOCK (store, connect_lock);
@@ -530,9 +504,6 @@ imap4_connect (CamelService *service, CamelException *ex)
}
if (camel_imap4_engine_namespace (store->engine, ex) == -1) {
- camel_object_unref (store->engine);
- store->engine = NULL;
-
CAMEL_SERVICE_UNLOCK (store, connect_lock);
return FALSE;
@@ -558,8 +529,6 @@ imap4_disconnect (CamelService *service, gboolean clean, CamelException *ex)
camel_imap4_command_unref (ic);
}
- camel_object_unref (store->engine);
-
return 0;
}
@@ -574,7 +543,7 @@ imap4_query_auth_types (CamelService *service, CamelException *ex)
gboolean connected;
CAMEL_SERVICE_LOCK (store, connect_lock);
- connected = connect_to_server_wrapper (service, ex);
+ connected = connect_to_server_wrapper (store->engine, ex);
CAMEL_SERVICE_UNLOCK (store, connect_lock);
if (!connected)
return NULL;
@@ -1180,7 +1149,7 @@ imap4_get_folder_info (CamelStore *store, const char *top, guint32 flags, CamelE
CAMEL_SERVICE_LOCK (store, connect_lock);
- if (engine == NULL) {
+ if (engine->state == CAMEL_IMAP4_ENGINE_DISCONNECTED) {
if (!camel_service_connect ((CamelService *) store, ex))
return NULL;