[evolution-data-server] Remove the structured exception handling as it may cause
- From: Chenthill Palanisamy <pchen src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Remove the structured exception handling as it may cause
- Date: Thu, 22 Oct 2009 09:39:47 +0000 (UTC)
commit 1a4fe31b6706071fee4e106f0b208d08c2a26ac1
Author: Chenthill Palanisamy <pchenthill novell com>
Date: Thu Oct 22 15:03:26 2009 +0530
Remove the structured exception handling as it may cause
resource leaks and turn out hard to maintain although
it makes code a look lot cleaner.
camel/providers/imapx/Makefile.am | 6 +-
camel/providers/imapx/camel-imapx-server.c | 408 ++++++-------
camel/providers/imapx/camel-imapx-store.c | 22 +-
camel/providers/imapx/camel-imapx-stream.c | 95 ++--
camel/providers/imapx/camel-imapx-stream.h | 16 +-
camel/providers/imapx/camel-imapx-utils.c | 912 ++++++++++++++-------------
camel/providers/imapx/camel-imapx-utils.h | 24 +-
camel/providers/imapx/test-imapx.c | 3 +
8 files changed, 751 insertions(+), 735 deletions(-)
---
diff --git a/camel/providers/imapx/Makefile.am b/camel/providers/imapx/Makefile.am
index 8b1a37f..9b7d4bd 100644
--- a/camel/providers/imapx/Makefile.am
+++ b/camel/providers/imapx/Makefile.am
@@ -14,14 +14,14 @@ libcamelimapx_la_CPPFLAGS = \
libcamelimapx_la_SOURCES = \
camel-imapx-exception.c \
+ camel-imapx-stream.c \
+ camel-imapx-utils.c \
camel-imapx-provider.c \
camel-imapx-store-summary.c \
camel-imapx-summary.c \
camel-imapx-store.c \
camel-imapx-folder.c \
- camel-imapx-server.c \
- camel-imapx-utils.c \
- camel-imapx-stream.c
+ camel-imapx-server.c
noinst_HEADERS = \
camel-imapx-exception.h \
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index 0f07680..b02d0b4 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -232,7 +232,7 @@ enum {
-static void imapx_select(CamelIMAPXServer *is, CamelFolder *folder);
+static void imapx_select(CamelIMAPXServer *is, CamelFolder *folder, CamelException *ex);
@@ -732,7 +732,7 @@ imapx_command_start(CamelIMAPXServer *imap, CamelIMAPXCommand *ic)
/* must have QUEUE lock */
static void
-imapx_command_start_next(CamelIMAPXServer *imap)
+imapx_command_start_next(CamelIMAPXServer *imap, CamelException *ex)
{
CamelIMAPXCommand *ic, *nc;
int count = 0;
@@ -811,7 +811,7 @@ imapx_command_start_next(CamelIMAPXServer *imap)
/* If we need to select a folder for the first command, do it now, once
it is complete it will re-call us if it succeeded */
if (ic->job->folder) {
- imapx_select(imap, ic->job->folder);
+ imapx_select(imap, ic->job->folder, ex);
} else {
pri = ic->pri;
nc = ic->next;
@@ -860,7 +860,7 @@ imapx_command_queue(CamelIMAPXServer *imap, CamelIMAPXCommand *ic)
scan->prev = ic;
}
- imapx_command_start_next(imap);
+ imapx_command_start_next(imap, NULL);
QUEUE_UNLOCK(imap);
}
@@ -956,7 +956,7 @@ imapx_expunged(CamelIMAPXServer *imap)
/* handle any untagged responses */
static int
-imapx_untagged(CamelIMAPXServer *imap)
+imapx_untagged(CamelIMAPXServer *imap, CamelException *ex)
{
unsigned int id, len;
unsigned char *token, *p, c;
@@ -965,10 +965,10 @@ imapx_untagged(CamelIMAPXServer *imap)
e(printf("got untagged response\n"));
id = 0;
- tok = camel_imapx_stream_token(imap->stream, &token, &len);
+ tok = camel_imapx_stream_token(imap->stream, &token, &len, ex);
if (tok == IMAP_TOK_INT) {
id = strtoul(token, NULL, 10);
- tok = camel_imapx_stream_token(imap->stream, &token, &len);
+ tok = camel_imapx_stream_token(imap->stream, &token, &len, ex);
}
if (tok == '\n')
@@ -983,7 +983,7 @@ imapx_untagged(CamelIMAPXServer *imap)
case IMAP_CAPABILITY:
if (imap->cinfo)
imap_free_capability(imap->cinfo);
- imap->cinfo = imap_parse_capability(imap->stream);
+ imap->cinfo = imap_parse_capability(imap->stream, ex);
printf("got capability flags %08x\n", imap->cinfo->capa);
return 0;
case IMAP_EXPUNGE: {
@@ -1000,7 +1000,7 @@ imapx_untagged(CamelIMAPXServer *imap)
case IMAP_FLAGS: {
guint32 flags;
- imap_parse_flags(imap->stream, &flags, NULL);
+ imap_parse_flags(imap->stream, &flags, NULL, ex);
printf("flags: %08x\n", flags);
break;
@@ -1008,7 +1008,7 @@ imapx_untagged(CamelIMAPXServer *imap)
case IMAP_FETCH: {
struct _fetch_info *finfo;
- finfo = imap_parse_fetch(imap->stream);
+ finfo = imap_parse_fetch(imap->stream, ex);
//imap_dump_fetch(finfo);
@@ -1098,7 +1098,7 @@ imapx_untagged(CamelIMAPXServer *imap)
break;
}
case IMAP_LIST: case IMAP_LSUB: {
- struct _list_info *linfo = imap_parse_list(imap->stream);
+ struct _list_info *linfo = imap_parse_list(imap->stream, ex);
CamelIMAPXJob *job = imapx_find_job(imap, IMAPX_JOB_LIST, linfo->name);
// TODO: we want to make sure the names match?
@@ -1120,7 +1120,7 @@ imapx_untagged(CamelIMAPXServer *imap)
/* TODO: validate which ones of these can happen as unsolicited responses */
/* TODO: handle bye/preauth differently */
camel_imapx_stream_ungettoken(imap->stream, tok, token, len);
- sinfo = imap_parse_status(imap->stream);
+ sinfo = imap_parse_status(imap->stream, ex);
camel_object_trigger_event(imap, "status", sinfo);
switch(sinfo->condition) {
case IMAP_READ_WRITE:
@@ -1156,13 +1156,13 @@ imapx_untagged(CamelIMAPXServer *imap)
printf("unknown token: %s\n", token);
}
- return camel_imapx_stream_skip(imap->stream);
+ return camel_imapx_stream_skip(imap->stream, ex);
}
/* handle any continuation requests
either data continuations, or auth continuation */
static int
-imapx_continuation(CamelIMAPXServer *imap)
+imapx_continuation(CamelIMAPXServer *imap, CamelException *ex)
{
CamelIMAPXCommand *ic, *newliteral = NULL;
CamelIMAPXCommandPart *cp;
@@ -1176,7 +1176,7 @@ imapx_continuation(CamelIMAPXServer *imap)
ic = imap->literal;
if (ic == NULL) {
- camel_imapx_stream_skip(imap->stream);
+ camel_imapx_stream_skip(imap->stream, ex);
printf("got continuation response with no outstanding continuation requests?\n");
return 1;
}
@@ -1193,16 +1193,14 @@ imapx_continuation(CamelIMAPXServer *imap)
camel_stream_write_to_stream((CamelStream *)cp->ob, (CamelStream *)imap->stream);
break;
case CAMEL_IMAPX_COMMAND_AUTH: {
- CamelException *ex = camel_exception_new();
char *resp;
unsigned char *token;
int tok, len;
- tok = camel_imapx_stream_token(imap->stream, &token, &len);
+ tok = camel_imapx_stream_token(imap->stream, &token, &len, ex);
resp = camel_sasl_challenge_base64((CamelSasl *)cp->ob, token, ex);
if (camel_exception_is_set(ex))
- camel_exception_throw_ex(ex);
- camel_exception_free(ex);
+ return -1;
printf("got auth continuation, feeding token '%s' back to auth mech\n", resp);
@@ -1232,10 +1230,11 @@ imapx_continuation(CamelIMAPXServer *imap)
default:
/* should we just ignore? */
imap->literal = NULL;
- camel_exception_throw(1, "continuation response for non-continuation request");
+ camel_exception_set (ex, 1, "continuation response for non-continuation request");
+ return -1;
}
- camel_imapx_stream_skip(imap->stream);
+ camel_imapx_stream_skip(imap->stream, ex);
cp = cp->next;
if (cp->next) {
@@ -1255,7 +1254,7 @@ imapx_continuation(CamelIMAPXServer *imap)
QUEUE_LOCK(imap);
imap->literal = newliteral;
- imapx_command_start_next(imap);
+ imapx_command_start_next(imap, ex);
QUEUE_UNLOCK(imap);
return 1;
@@ -1263,7 +1262,7 @@ imapx_continuation(CamelIMAPXServer *imap)
/* handle a completion line */
static int
-imapx_completion(CamelIMAPXServer *imap, unsigned char *token, int len)
+imapx_completion(CamelIMAPXServer *imap, unsigned char *token, int len, CamelException *ex)
{
CamelIMAPXCommand * volatile ic;
unsigned int tag;
@@ -1298,7 +1297,7 @@ imapx_completion(CamelIMAPXServer *imap, unsigned char *token, int len)
// }
QUEUE_UNLOCK(imap);
- ic->status = imap_parse_status(imap->stream);
+ ic->status = imap_parse_status(imap->stream, ex);
if (ic->complete)
ic->complete(imap, ic);
@@ -1311,14 +1310,14 @@ imapx_completion(CamelIMAPXServer *imap, unsigned char *token, int len)
e_dlist_remove((EDListNode *)ic);
camel_imapx_command_free(ic);
}
- imapx_command_start_next(imap);
+ imapx_command_start_next(imap, ex);
QUEUE_UNLOCK(imap);
return 1;
}
static void
-imapx_step(CamelIMAPXServer *is)
+imapx_step(CamelIMAPXServer *is, CamelException *ex)
/* throws IO,PARSE exception */
{
unsigned int len;
@@ -1326,13 +1325,13 @@ imapx_step(CamelIMAPXServer *is)
int tok;
// poll ? wait for other stuff? loop?
- tok = camel_imapx_stream_token(is->stream, &token, &len);
+ tok = camel_imapx_stream_token(is->stream, &token, &len, ex);
if (tok == '*')
- imapx_untagged(is);
+ imapx_untagged(is, ex);
else if (tok == IMAP_TOK_TOKEN)
- imapx_completion(is, token, len);
+ imapx_completion(is, token, len, ex);
else if (tok == '+')
- imapx_continuation(is);
+ imapx_continuation(is, ex);
else
camel_exception_throw(1, "unexpected server response: %s", token);
}
@@ -1340,7 +1339,7 @@ imapx_step(CamelIMAPXServer *is)
/* Used to run 1 command synchronously,
use for capa, login, and selecting only. */
static void
-imapx_command_run(CamelIMAPXServer *is, CamelIMAPXCommand *ic)
+imapx_command_run(CamelIMAPXServer *is, CamelIMAPXCommand *ic, CamelException *ex)
/* throws IO,PARSE exception */
{
camel_imapx_command_close(ic);
@@ -1349,7 +1348,7 @@ imapx_command_run(CamelIMAPXServer *is, CamelIMAPXCommand *ic)
imapx_command_start(is, ic);
QUEUE_UNLOCK(is);
do {
- imapx_step(is);
+ imapx_step(is, ex);
} while (ic->status == NULL);
e_dlist_remove((EDListNode *)ic);
@@ -1413,7 +1412,7 @@ imapx_select_done(CamelIMAPXServer *is, CamelIMAPXCommand *ic)
}
static void
-imapx_select(CamelIMAPXServer *is, CamelFolder *folder)
+imapx_select(CamelIMAPXServer *is, CamelFolder *folder, CamelException *ex)
{
CamelIMAPXCommand *ic;
@@ -1440,7 +1439,7 @@ imapx_select(CamelIMAPXServer *is, CamelFolder *folder)
if (is->select_folder) {
while (!e_dlist_empty(&is->active)) {
QUEUE_UNLOCK(is);
- imapx_step(is);
+ imapx_step(is, ex);
QUEUE_LOCK(is);
}
g_free(is->select);
@@ -1465,123 +1464,125 @@ imapx_select(CamelIMAPXServer *is, CamelFolder *folder)
}
static void
-imapx_connect(CamelIMAPXServer *is, int ssl_mode, int try_starttls)
+imapx_connect(CamelIMAPXServer *is, int ssl_mode, int try_starttls, CamelException *ex)
/* throws IO exception */
{
- CamelStream * volatile tcp_stream = NULL;
+ CamelStream * tcp_stream = NULL;
int ret;
- {
#ifdef HAVE_SSL
- const char *mode;
+ const char *mode;
#endif
- unsigned char *buffer;
- int len;
- char *serv;
- const char *port = NULL;
- struct addrinfo *ai, hints = { 0 };
- CamelException ex = { 0 };
- CamelIMAPXCommand *ic;
+ guchar *buffer = NULL;
+ int len;
+ char *serv;
+ const char *port = NULL;
+ struct addrinfo *ai, hints = { 0 };
+ CamelIMAPXCommand *ic;
- if (is->url->port) {
- serv = g_alloca(16);
- sprintf(serv, "%d", is->url->port);
- } else {
- serv = "imap";
- port = "143";
- }
+ if (is->url->port) {
+ serv = g_alloca(16);
+ sprintf(serv, "%d", is->url->port);
+ } else {
+ serv = "imap";
+ port = "143";
+ }
#ifdef HAVE_SSL
- mode = camel_url_get_param(is->url, "use_ssl");
- if (mode && strcmp(mode, "never") != 0) {
- if (!strcmp(mode, "when-possible")) {
- tcp_stream = camel_tcp_stream_ssl_new_raw(is->session, is->url->host, STARTTLS_FLAGS);
- } else {
- if (is->url->port == 0) {
- serv = "imaps";
- port = "993";
- }
- tcp_stream = camel_tcp_stream_ssl_new(is->session, is->url->host, SSL_PORT_FLAGS);
- }
+ mode = camel_url_get_param(is->url, "use_ssl");
+ if (mode && strcmp(mode, "never") != 0) {
+ if (!strcmp(mode, "when-possible")) {
+ tcp_stream = camel_tcp_stream_ssl_new_raw(is->session, is->url->host, STARTTLS_FLAGS);
} else {
- tcp_stream = camel_tcp_stream_raw_new ();
+ if (is->url->port == 0) {
+ serv = "imaps";
+ port = "993";
+ }
+ tcp_stream = camel_tcp_stream_ssl_new(is->session, is->url->host, SSL_PORT_FLAGS);
}
-#else
+ } else {
tcp_stream = camel_tcp_stream_raw_new ();
+ }
+#else
+ tcp_stream = camel_tcp_stream_raw_new ();
#endif /* HAVE_SSL */
- hints.ai_socktype = SOCK_STREAM;
- ai = camel_getaddrinfo(is->url->host, serv, &hints, &ex);
- if (ex.id && ex.id != CAMEL_EXCEPTION_USER_CANCEL && port != NULL) {
- camel_exception_clear(&ex);
- ai = camel_getaddrinfo(is->url->host, port, &hints, &ex);
- }
+ hints.ai_socktype = SOCK_STREAM;
+ ai = camel_getaddrinfo(is->url->host, serv, &hints, ex);
+ if (ex->id && ex->id != CAMEL_EXCEPTION_USER_CANCEL && port != NULL) {
+ camel_exception_clear(ex);
+ ai = camel_getaddrinfo(is->url->host, port, &hints, ex);
+ }
- if (ex.id)
- camel_exception_throw_ex(&ex);
-
- ret = camel_tcp_stream_connect(CAMEL_TCP_STREAM(tcp_stream), ai);
- camel_freeaddrinfo(ai);
- if (ret == -1) {
- if (errno == EINTR)
- camel_exception_throw(CAMEL_EXCEPTION_USER_CANCEL, _("Connection cancelled"));
- else
- camel_exception_throw(CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("Could not connect to %s (port %s): %s"),
- is->url->host, serv, g_strerror(errno));
- }
+ if (ex->id) {
+ g_message ("Unable to connect %d %s \n", ex->id, ex->desc);
+ camel_object_unref(tcp_stream);
+ return;
+ }
- is->stream = (CamelIMAPXStream *)camel_imapx_stream_new(tcp_stream);
+ ret = camel_tcp_stream_connect(CAMEL_TCP_STREAM(tcp_stream), ai);
+ camel_freeaddrinfo(ai);
+ if (ret == -1) {
+ if (errno == EINTR)
+ camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL, _("Connection cancelled"));
+ else
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
+ _("Could not connect to %s (port %s): %s"),
+ is->url->host, serv, g_strerror(errno));
camel_object_unref(tcp_stream);
- tcp_stream = NULL;
+ return;
+ }
- camel_imapx_stream_gets(is->stream, &buffer, &len);
- printf("Got greeting '%.*s'\n", len, buffer);
+ is->stream = (CamelIMAPXStream *)camel_imapx_stream_new(tcp_stream);
+ camel_object_unref(tcp_stream);
+ tcp_stream = NULL;
- ic = camel_imapx_command_new("CAPABILITY", NULL, "CAPABILITY");
- imapx_command_run(is, ic);
- camel_imapx_command_free(ic);
- }
-
-
-/* CAMEL_CATCH(e) {
- if (tcp_stream)
- camel_object_unref(tcp_stream);
- camel_exception_throw_ex(e);
- } CAMEL_DONE; */
+ camel_imapx_stream_gets(is->stream, &buffer, &len);
+ printf("Got greeting '%.*s'\n", len, buffer);
+
+ ic = camel_imapx_command_new("CAPABILITY", NULL, "CAPABILITY");
+ imapx_command_run(is, ic, ex);
+ camel_imapx_command_free(ic);
}
static void
-imapx_reconnect(CamelIMAPXServer *is)
+imapx_reconnect(CamelIMAPXServer *is, CamelException *ex)
{
-retry:
- {
CamelSasl *sasl;
CamelIMAPXCommand *ic;
-
- imapx_connect(is, 0, 0);
-
+retry:
+ g_message ("Connecting \n");
+ imapx_connect(is, 0, 0, ex);
+ g_message ("Connected \n");
+
if (is->url->passwd == NULL) {
- CamelException ex = { 0 };
+ CamelException ex = { 0, NULL };
char *prompt = g_strdup_printf(_("%sPlease enter the IMAP password for %s %s"), "", is->url->user, is->url->host);
+ const gchar *auth_domain;
+ auth_domain = camel_url_get_param (is->url, "auth-domain");
is->url->passwd = camel_session_get_password(is->session, (CamelService *)is->store,
- camel_url_get_param(is->url, "auth-domain"),
- prompt, "password", 0, &ex);
+ auth_domain,
+ prompt, "password", 0, &ex);
+
g_free(prompt);
- if (ex.id)
- camel_exception_throw_ex(&ex);
+ if (ex.id) {
+ g_message ("Unable to connect %d ", ex.id);
+ return;
+ }
}
if (is->url->authmech
- && (sasl = camel_sasl_new("imap", is->url->authmech, NULL))) {
+ && (sasl = camel_sasl_new("imap", is->url->authmech, NULL))) {
ic = camel_imapx_command_new("AUTHENTICATE", NULL, "AUTHENTICATE %A", sasl);
camel_object_unref(sasl);
} else {
ic = camel_imapx_command_new("LOGIN", NULL, "LOGIN %s %s", is->url->user, is->url->passwd);
}
+ g_message ("Logged in now!! \n");
+
// TODO freeing data?
- imapx_command_run(is, ic);
+ imapx_command_run(is, ic, ex);
if (ic->status->result != IMAP_OK)
camel_exception_throw(CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE, "Login failed: %s", ic->status->text);
camel_imapx_command_free(ic);
@@ -1592,29 +1593,19 @@ retry:
is->cinfo = NULL;
}
ic = camel_imapx_command_new("CAPABILITY", NULL, "CAPABILITY");
- imapx_command_run(is, ic);
+ imapx_command_run(is, ic, ex);
camel_imapx_command_free(ic);
is->state = IMAPX_AUTHENTICATED;
- }
-
-/* if (camel_exception_is_set (e)) {
- if (*e->ex CAMEL_EXCEPTION_USER_CANCEL) {
- printf("Re Connection failed: %s\n", e->desc);
- sleep(5);
- // camelexception_done?
- goto retry;
- }
- } */
-
-/* CAMEL_CATCH(e) {
- /* Shrug, either way this re-loops back ...
- if (TRUE /*e->ex != CAMEL_EXCEPTION_USER_CANCEL) {
- printf("Re Connection failed: %s\n", e->desc);
- sleep(5);
- // camelexception_done?
- goto retry;
- }
- } CAMEL_DONE; */
+
+ if (camel_exception_is_set (ex))
+ /* Shrug, either way this re-loops back ... */
+ if (TRUE /*e->ex != CAMEL_EXCEPTION_USER_CANCEL*/) {
+ printf("Re Connection failed: %s\n", ex->desc);
+ sleep(5);
+ // camelexception_done?
+ camel_exception_clear (ex);
+ goto retry;
+ }
}
/* ********************************************************************** */
@@ -2176,6 +2167,7 @@ imapx_server_loop(void *d)
{
CamelIMAPXServer *is = d;
CamelIMAPXJob *job;
+ CamelException ex = {0, NULL};
/*
The main processing (reading) loop.
@@ -2197,95 +2189,91 @@ imapx_server_loop(void *d)
// FIXME: handle exceptions
while (1) {
- {
- printf ("Inside try catch loop \n");
- if (!is->stream)
- imapx_reconnect(is);
+ if (!is->stream)
+ imapx_reconnect(is, &ex);
- job = (CamelIMAPXJob *)e_msgport_get(is->port);
- if (job) {
- e_dlist_addtail(&is->jobs, (EDListNode *)job);
- job->start(is, job);
- }
+ job = (CamelIMAPXJob *)e_msgport_get(is->port);
+ if (job) {
+ e_dlist_addtail(&is->jobs, (EDListNode *)job);
+ job->start(is, job);
+ }
- if (!e_dlist_empty(&is->active)
- || camel_imapx_stream_buffered(is->stream))
- imapx_step(is);
- else
- e_msgport_wait(is->port);
+ if (!e_dlist_empty(&is->active)
+ || camel_imapx_stream_buffered(is->stream))
+ imapx_step(is, &ex);
+ else
+ e_msgport_wait(is->port);
#if 0
- /* TODO:
- This poll stuff wont work - we might block
- waiting for results inside loops etc.
+ /* TODO:
+ This poll stuff wont work - we might block
+ waiting for results inside loops etc.
- Requires a different approach:
+ Requires a different approach:
- New commands are queued in other threads as well
- as this thread, and get pipelined over the socket.
+ New commands are queued in other threads as well
+ as this thread, and get pipelined over the socket.
- Main area of locking required is command_queue
- and command_start_next, the 'literal' command,
- the jobs queue, the active queue, the queue
- queue. */
+ Main area of locking required is command_queue
+ and command_start_next, the 'literal' command,
+ the jobs queue, the active queue, the queue
+ queue. */
- /* if ssl stream ... */
+ /* if ssl stream ... */
#ifdef HAVE_SSL
- {
- PRPollDesc pollfds[2] = { };
- int res;
-
- printf("\nGoing to sleep waiting for work to do\n\n");
-
- pollfds[0].fd = camel_tcp_stream_ssl_sockfd((CamelTcpStreamSSL *)is->stream->source);
- pollfds[0].in_flags = PR_POLL_READ;
- pollfds[1].fd = e_msgport_prfd(is->port);
- pollfds[1].in_flags = PR_POLL_READ;
-
- res = PR_Poll(pollfds, 2, PR_TicksPerSecond() / 10);
- if (res == -1)
- sleep(1) /* ?? */ ;
- else if ((pollfds[0].out_flags & PR_POLL_READ)) {
- printf(" * woken * have data ready\n");
- do {
- /* This is quite shitty, it will often block on each
- part of the decode, causing significant
- processing delays. */
- imapx_step(is);
- } while (camel_imapx_stream_buffered(is->stream));
- } else if (pollfds[1].out_flags & PR_POLL_READ) {
- printf(" * woken * have new job\n");
- /* job is handled in main loop */
- }
+ {
+ PRPollDesc pollfds[2] = { };
+ int res;
+
+ printf("\nGoing to sleep waiting for work to do\n\n");
+
+ pollfds[0].fd = camel_tcp_stream_ssl_sockfd((CamelTcpStreamSSL *)is->stream->source);
+ pollfds[0].in_flags = PR_POLL_READ;
+ pollfds[1].fd = e_msgport_prfd(is->port);
+ pollfds[1].in_flags = PR_POLL_READ;
+
+ res = PR_Poll(pollfds, 2, PR_TicksPerSecond() / 10);
+ if (res == -1)
+ sleep(1) /* ?? */ ;
+ else if ((pollfds[0].out_flags & PR_POLL_READ)) {
+ printf(" * woken * have data ready\n");
+ do {
+ /* This is quite shitty, it will often block on each
+ part of the decode, causing significant
+ processing delays. */
+ imapx_step(is);
+ } while (camel_imapx_stream_buffered(is->stream));
+ } else if (pollfds[1].out_flags & PR_POLL_READ) {
+ printf(" * woken * have new job\n");
+ /* job is handled in main loop */
}
+ }
#else
- {
- struct pollfd[2] = { 0 };
- int res;
-
- pollfd[0].fd = ((CamelTcpStreamRaw *)is->stream->source)->sockfd;
- pollfd[0].events = POLLIN;
- pollfd[1].fd = e_msgport_fd(is->port);
- pollfd[1].events = POLLIN;
-
- res = poll(pollfd, 2, 1000*30);
- if (res == -1)
- sleep(1) /* ?? */ ;
- else if (res == 0)
- /* timed out */;
- else if (pollfds[0].revents & POLLIN) {
- do {
- imapx_step(is);
- } while (camel_imapx_stream_buffered(is->stream));
- }
+ {
+ struct pollfd[2] = { 0 };
+ int res;
+
+ pollfd[0].fd = ((CamelTcpStreamRaw *)is->stream->source)->sockfd;
+ pollfd[0].events = POLLIN;
+ pollfd[1].fd = e_msgport_fd(is->port);
+ pollfd[1].events = POLLIN;
+
+ res = poll(pollfd, 2, 1000*30);
+ if (res == -1)
+ sleep(1) /* ?? */ ;
+ else if (res == 0)
+ /* timed out */;
+ else if (pollfds[0].revents & POLLIN) {
+ do {
+ imapx_step(is);
+ } while (camel_imapx_stream_buffered(is->stream));
}
+ }
#endif
#endif
- }
-
-// CAMEL_CATCH(e) {
-// printf("######### Got main loop exception: %s\n", e->desc);
-// sleep(1);
-// } CAMEL_DONE;
+ if (camel_exception_is_set (&ex)) {
+ printf("######### Got main loop exception: %s\n", ex.desc);
+ sleep(1);
+ }
}
return NULL;
@@ -2360,7 +2348,7 @@ camel_imapx_server_new(CamelStore *store, CamelURL *url)
is->store = store;
is->url = camel_url_copy(url);
- camel_url_set_user(is->url, "camel");
+// camel_url_set_user(is->url, "camel");
camel_url_set_passwd(is->url, "camel");
return is;
diff --git a/camel/providers/imapx/camel-imapx-store.c b/camel/providers/imapx/camel-imapx-store.c
index 592a1c6..5e64757 100644
--- a/camel/providers/imapx/camel-imapx-store.c
+++ b/camel/providers/imapx/camel-imapx-store.c
@@ -93,19 +93,15 @@ static void imap_construct(CamelService *service, CamelSession *session, CamelPr
if (camel_exception_is_set(ex))
return;
- CAMEL_TRY {
- store->summary = camel_imapx_store_summary_new();
- store->storage_path = camel_session_get_storage_path(session, service, ex);
- if (store->storage_path) {
- summary = g_build_filename(store->storage_path, ".ev-store-summary", NULL);
- camel_store_summary_set_filename((CamelStoreSummary *)store->summary, summary);
- /* FIXME: need to remove params, passwords, etc */
- camel_store_summary_set_uri_base((CamelStoreSummary *)store->summary, service->url);
- camel_store_summary_load((CamelStoreSummary *)store->summary);
- }
- } CAMEL_CATCH(e) {
- camel_exception_xfer(ex, e);
- } CAMEL_DONE;
+ store->summary = camel_imapx_store_summary_new();
+ store->storage_path = camel_session_get_storage_path(session, service, ex);
+ if (store->storage_path) {
+ summary = g_build_filename(store->storage_path, ".ev-store-summary", NULL);
+ camel_store_summary_set_filename((CamelStoreSummary *)store->summary, summary);
+ /* FIXME: need to remove params, passwords, etc */
+ camel_store_summary_set_uri_base((CamelStoreSummary *)store->summary, service->url);
+ camel_store_summary_load((CamelStoreSummary *)store->summary);
+ }
}
diff --git a/camel/providers/imapx/camel-imapx-stream.c b/camel/providers/imapx/camel-imapx-stream.c
index b9a7c27..fa84879 100644
--- a/camel/providers/imapx/camel-imapx-stream.c
+++ b/camel/providers/imapx/camel-imapx-stream.c
@@ -253,12 +253,12 @@ skip_ws(CamelIMAPXStream *is, unsigned char *pp, unsigned char *pe)
/* FIXME: these should probably handle it themselves,
and get rid of the token interface? */
int
-camel_imapx_stream_atom(CamelIMAPXStream *is, unsigned char **data, unsigned int *lenp)
+camel_imapx_stream_atom(CamelIMAPXStream *is, unsigned char **data, unsigned int *lenp, CamelException *ex)
{
unsigned char *p, c;
/* this is only 'approximate' atom */
- switch(camel_imapx_stream_token(is, data, lenp)) {
+ switch(camel_imapx_stream_token(is, data, lenp, ex)) {
case IMAP_TOK_TOKEN:
p = *data;
while ((c = *p))
@@ -268,7 +268,7 @@ camel_imapx_stream_atom(CamelIMAPXStream *is, unsigned char **data, unsigned int
case IMAP_TOK_ERROR:
return IMAP_TOK_ERROR;
default:
- camel_exception_throw(1, "expecting atom");
+ camel_exception_set (ex, 1, "expecting atom");
printf("expecting atom!\n");
return IMAP_TOK_PROTOCOL;
}
@@ -276,12 +276,12 @@ camel_imapx_stream_atom(CamelIMAPXStream *is, unsigned char **data, unsigned int
/* gets an atom, a quoted_string, or a literal */
int
-camel_imapx_stream_astring(CamelIMAPXStream *is, unsigned char **data)
+camel_imapx_stream_astring(CamelIMAPXStream *is, unsigned char **data, CamelException *ex)
{
unsigned char *p, *start;
unsigned int len, inlen;
- switch(camel_imapx_stream_token(is, data, &len)) {
+ switch(camel_imapx_stream_token(is, data, &len, ex)) {
case IMAP_TOK_TOKEN:
case IMAP_TOK_INT:
case IMAP_TOK_STRING:
@@ -289,7 +289,7 @@ camel_imapx_stream_astring(CamelIMAPXStream *is, unsigned char **data)
case IMAP_TOK_LITERAL:
/* FIXME: just grow buffer */
if (len >= CAMEL_IMAPX_STREAM_TOKEN) {
- camel_exception_throw(1, "astring: literal too long");
+ camel_exception_set (ex, 1, "astring: literal too long");
printf("astring too long\n");
return IMAP_TOK_PROTOCOL;
}
@@ -308,7 +308,7 @@ camel_imapx_stream_astring(CamelIMAPXStream *is, unsigned char **data)
/* wont get unless no exception hanlder*/
return IMAP_TOK_ERROR;
default:
- camel_exception_throw(1, "expecting astring");
+ camel_exception_set (ex, 1, "expecting astring");
printf("expecting astring!\n");
return IMAP_TOK_PROTOCOL;
}
@@ -316,18 +316,18 @@ camel_imapx_stream_astring(CamelIMAPXStream *is, unsigned char **data)
/* check for NIL or (small) quoted_string or literal */
int
-camel_imapx_stream_nstring(CamelIMAPXStream *is, unsigned char **data)
+camel_imapx_stream_nstring(CamelIMAPXStream *is, unsigned char **data, CamelException *ex)
{
unsigned char *p, *start;
unsigned int len, inlen;
- switch(camel_imapx_stream_token(is, data, &len)) {
+ switch(camel_imapx_stream_token(is, data, &len, ex)) {
case IMAP_TOK_STRING:
return 0;
case IMAP_TOK_LITERAL:
/* FIXME: just grow buffer */
if (len >= CAMEL_IMAPX_STREAM_TOKEN) {
- camel_exception_throw(1, "nstring: literal too long");
+ camel_exception_set (ex, 1, "nstring: literal too long");
return IMAP_TOK_PROTOCOL;
}
p = is->tokenptr;
@@ -348,7 +348,7 @@ camel_imapx_stream_nstring(CamelIMAPXStream *is, unsigned char **data)
return 0;
}
default:
- camel_exception_throw(1, "expecting nstring");
+ camel_exception_set (ex, 1, "expecting nstring");
return IMAP_TOK_PROTOCOL;
case IMAP_TOK_ERROR:
/* we'll never get this unless there are no exception handlers anyway */
@@ -359,7 +359,7 @@ camel_imapx_stream_nstring(CamelIMAPXStream *is, unsigned char **data)
/* parse an nstring as a stream */
int
-camel_imapx_stream_nstring_stream(CamelIMAPXStream *is, CamelStream **stream)
+camel_imapx_stream_nstring_stream(CamelIMAPXStream *is, CamelStream **stream, CamelException *ex)
/* throws IO,PARSE exception */
{
unsigned char *token;
@@ -369,8 +369,7 @@ camel_imapx_stream_nstring_stream(CamelIMAPXStream *is, CamelStream **stream)
*stream = NULL;
- CAMEL_TRY {
- switch(camel_imapx_stream_token(is, &token, &len)) {
+ switch(camel_imapx_stream_token(is, &token, &len, ex)) {
case IMAP_TOK_STRING:
mem = camel_stream_mem_new_with_buffer(token, len);
*stream = mem;
@@ -379,8 +378,12 @@ camel_imapx_stream_nstring_stream(CamelIMAPXStream *is, CamelStream **stream)
/* if len is big, we could automatically use a file backing */
camel_imapx_stream_set_literal(is, len);
mem = camel_stream_mem_new();
- if (camel_stream_write_to_stream((CamelStream *)is, mem) == -1)
- camel_exception_throw(1, "nstring: io error: %s", strerror(errno));
+ if (camel_stream_write_to_stream((CamelStream *)is, mem) == -1) {
+ camel_exception_setv (ex, 1, "nstring: io error: %s", strerror(errno));
+ camel_object_unref((CamelObject *)mem);
+ ret = -1;
+ break;
+ }
camel_stream_reset(mem);
*stream = mem;
break;
@@ -391,26 +394,20 @@ camel_imapx_stream_nstring_stream(CamelIMAPXStream *is, CamelStream **stream)
}
default:
ret = -1;
- camel_exception_throw(1, "nstring: token not string");
- }
- } CAMEL_CATCH(ex) {
- if (mem)
- camel_object_unref((CamelObject *)mem);
- camel_exception_throw_ex(ex);
- } CAMEL_DONE;
+ camel_exception_set (ex, 1, "nstring: token not string");
+ }
- /* never reaches here anyway */
return ret;
}
guint32
-camel_imapx_stream_number(CamelIMAPXStream *is)
+camel_imapx_stream_number(CamelIMAPXStream *is, CamelException *ex)
{
unsigned char *token;
unsigned int len;
- if (camel_imapx_stream_token(is, &token, &len) != IMAP_TOK_INT) {
- camel_exception_throw(1, "expecting number");
+ if (camel_imapx_stream_token(is, &token, &len, ex) != IMAP_TOK_INT) {
+ camel_exception_set (ex, 1, "expecting number");
return 0;
}
@@ -418,16 +415,15 @@ camel_imapx_stream_number(CamelIMAPXStream *is)
}
int
-camel_imapx_stream_text(CamelIMAPXStream *is, unsigned char **text)
+camel_imapx_stream_text(CamelIMAPXStream *is, unsigned char **text, CamelException *ex)
{
GByteArray *build = g_byte_array_new();
unsigned char *token;
unsigned int len;
int tok;
- CAMEL_TRY {
- while (is->unget > 0) {
- switch (is->unget_tok) {
+ while (is->unget > 0) {
+ switch (is->unget_tok) {
case IMAP_TOK_TOKEN:
case IMAP_TOK_STRING:
case IMAP_TOK_INT:
@@ -435,22 +431,21 @@ camel_imapx_stream_text(CamelIMAPXStream *is, unsigned char **text)
g_byte_array_append(build, " ", 1);
default: /* invalid, but we'll ignore */
break;
- }
- is->unget--;
}
+ is->unget--;
+ }
- do {
- tok = camel_imapx_stream_gets(is, &token, &len);
- if (tok < 0)
- camel_exception_throw(1, "io error: %s", strerror(errno));
- if (len)
- g_byte_array_append(build, token, len);
- } while (tok > 0);
- } CAMEL_CATCH(ex) {
- *text = NULL;
- g_byte_array_free(build, TRUE);
- camel_exception_throw_ex(ex);
- } CAMEL_DONE;
+ do {
+ tok = camel_imapx_stream_gets(is, &token, &len);
+ if (tok < 0) {
+ camel_exception_setv (ex, 1, "io error: %s", strerror(errno));
+ *text = NULL;
+ g_byte_array_free(build, TRUE);
+ return -1;
+ }
+ if (len)
+ g_byte_array_append(build, token, len);
+ } while (tok > 0);
g_byte_array_append(build, "", 1);
*text = build->data;
@@ -462,7 +457,7 @@ camel_imapx_stream_text(CamelIMAPXStream *is, unsigned char **text)
/* Get one token from the imap stream */
camel_imapx_token_t
/* throws IO,PARSE exception */
-camel_imapx_stream_token(CamelIMAPXStream *is, unsigned char **data, unsigned int *len)
+camel_imapx_stream_token(CamelIMAPXStream *is, unsigned char **data, unsigned int *len, CamelException *ex)
{
register unsigned char c, *p, *o, *oe;
unsigned char *e;
@@ -618,7 +613,7 @@ camel_imapx_stream_token(CamelIMAPXStream *is, unsigned char **data, unsigned in
/* Had an i/o erorr */
io_error:
printf("Got io error\n");
- camel_exception_throw(1, "io error");
+ camel_exception_set (ex, 1, "io error");
return IMAP_TOK_ERROR;
/* Protocol error, skip until next lf? */
@@ -630,7 +625,7 @@ protocol_error:
else
is->ptr = p;
- camel_exception_throw(1, "protocol error");
+ camel_exception_set (ex, 1, "protocol error");
return IMAP_TOK_PROTOCOL;
}
@@ -705,14 +700,14 @@ int camel_imapx_stream_getl(CamelIMAPXStream *is, unsigned char **start, unsigne
/* skip the rest of the line of tokens */
int
-camel_imapx_stream_skip(CamelIMAPXStream *is)
+camel_imapx_stream_skip(CamelIMAPXStream *is, CamelException *ex)
{
int tok;
unsigned char *token;
unsigned int len;
do {
- tok = camel_imapx_stream_token(is, &token, &len);
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
if (tok == IMAP_TOK_LITERAL) {
camel_imapx_stream_set_literal(is, len);
while ((tok = camel_imapx_stream_getl(is, &token, &len)) > 0) {
diff --git a/camel/providers/imapx/camel-imapx-stream.h b/camel/providers/imapx/camel-imapx-stream.h
index b565b4c..b2c6d2b 100644
--- a/camel/providers/imapx/camel-imapx-stream.h
+++ b/camel/providers/imapx/camel-imapx-stream.h
@@ -66,7 +66,7 @@ CamelStream *camel_imapx_stream_new (CamelStream *source);
int camel_imapx_stream_buffered (CamelIMAPXStream *is);
-camel_imapx_token_t camel_imapx_stream_token (CamelIMAPXStream *is, unsigned char **start, unsigned int *len); /* throws IO,PARSE exception */
+camel_imapx_token_t camel_imapx_stream_token (CamelIMAPXStream *is, unsigned char **start, unsigned int *len, CamelException *ex); /* throws IO,PARSE exception */
void camel_imapx_stream_ungettoken (CamelIMAPXStream *is, camel_imapx_token_t tok, unsigned char *token, unsigned int len);
void camel_imapx_stream_set_literal (CamelIMAPXStream *is, unsigned int literal);
@@ -76,20 +76,20 @@ int camel_imapx_stream_getl (CamelIMAPXStream *is, unsigned char **start, un
/* all throw IO,PARSE exceptions */
/* gets an atom, upper-cases */
-int camel_imapx_stream_atom (CamelIMAPXStream *is, unsigned char **start, unsigned int *len);
+int camel_imapx_stream_atom (CamelIMAPXStream *is, unsigned char **start, unsigned int *len, CamelException *ex);
/* gets an atom or string */
-int camel_imapx_stream_astring (CamelIMAPXStream *is, unsigned char **start);
+int camel_imapx_stream_astring (CamelIMAPXStream *is, unsigned char **start, CamelException *ex);
/* gets a NIL or a string, start==NULL if NIL */
-int camel_imapx_stream_nstring (CamelIMAPXStream *is, unsigned char **start);
+int camel_imapx_stream_nstring (CamelIMAPXStream *is, unsigned char **start, CamelException *ex);
/* gets a NIL or string into a stream, stream==NULL if NIL */
-int camel_imapx_stream_nstring_stream(CamelIMAPXStream *is, CamelStream **stream);
+int camel_imapx_stream_nstring_stream(CamelIMAPXStream *is, CamelStream **stream, CamelException *ex);
/* gets 'text' */
-int camel_imapx_stream_text (CamelIMAPXStream *is, unsigned char **text);
+int camel_imapx_stream_text (CamelIMAPXStream *is, unsigned char **text, CamelException *ex);
/* gets a 'number' */
-guint32 camel_imapx_stream_number(CamelIMAPXStream *is);
+guint32 camel_imapx_stream_number(CamelIMAPXStream *is, CamelException *ex);
/* skips the rest of a line, including literals, etc */
-int camel_imapx_stream_skip(CamelIMAPXStream *is);
+int camel_imapx_stream_skip(CamelIMAPXStream *is, CamelException *ex);
#endif /* ! _CAMEL_IMAPX_STREAM_H */
diff --git a/camel/providers/imapx/camel-imapx-utils.c b/camel/providers/imapx/camel-imapx-utils.c
index f296008..f963d55 100644
--- a/camel/providers/imapx/camel-imapx-utils.c
+++ b/camel/providers/imapx/camel-imapx-utils.c
@@ -53,7 +53,7 @@ static struct {
shoudl this be part of imapx-driver? */
/* mabye this should be a stream op? */
void
-imap_parse_flags(CamelIMAPXStream *stream, guint32 *flagsp, CamelFlag **user_flagsp)
+imap_parse_flags(CamelIMAPXStream *stream, guint32 *flagsp, CamelFlag **user_flagsp, CamelException *ex)
/* throws IO,PARSE exception */
{
int tok, len, i;
@@ -62,10 +62,10 @@ imap_parse_flags(CamelIMAPXStream *stream, guint32 *flagsp, CamelFlag **user_fla
*flagsp = flags;
- tok = camel_imapx_stream_token(stream, &token, &len);
+ tok = camel_imapx_stream_token(stream, &token, &len, ex);
if (tok == '(') {
do {
- tok = camel_imapx_stream_token(stream, &token, &len);
+ tok = camel_imapx_stream_token(stream, &token, &len, ex);
if (tok == IMAP_TOK_TOKEN) {
p = token;
// FIXME: ascii_toupper
@@ -81,11 +81,13 @@ imap_parse_flags(CamelIMAPXStream *stream, guint32 *flagsp, CamelFlag **user_fla
found:
tok = tok; /* fixes stupid warning */
} else if (tok != ')') {
- camel_exception_throw(1, "expecting flag");
+ camel_exception_set (ex, 1, "expecting flag");
+ return;
}
} while (tok != ')');
} else {
- camel_exception_throw(1, "expecting flag list");
+ camel_exception_set (ex, 1, "expecting flag list");
+ return;
}
*flagsp = flags;
@@ -146,7 +148,7 @@ struct {
};
struct _capability_info *
-imap_parse_capability(CamelIMAPXStream *stream)
+imap_parse_capability(CamelIMAPXStream *stream, CamelException *ex)
{
int tok, len, i;
unsigned char *token, *p, c;
@@ -155,9 +157,8 @@ imap_parse_capability(CamelIMAPXStream *stream)
cinfo = g_malloc0(sizeof(*cinfo));
/* FIXME: handle auth types */
- CAMEL_TRY {
- while ( (tok = camel_imapx_stream_token(stream, &token, &len)) != '\n') {
- switch(tok) {
+ while (!camel_exception_is_set (ex) && (tok = camel_imapx_stream_token(stream, &token, &len, ex)) != '\n') {
+ switch(tok) {
case IMAP_TOK_TOKEN:
case IMAP_TOK_STRING:
p = token;
@@ -170,14 +171,15 @@ imap_parse_capability(CamelIMAPXStream *stream)
cinfo->capa |= capa_table[i].flag;
break;
default:
- camel_exception_throw(1, "capability: expecting name");
+ camel_exception_set (ex, 1, "capability: expecting name");
break;
- }
}
- } CAMEL_CATCH(ex) {
+ }
+
+ if (camel_exception_is_set (ex)) {
imap_free_capability(cinfo);
- camel_exception_throw_ex(ex);
- } CAMEL_DONE;
+ cinfo = NULL;
+ }
return cinfo;
}
@@ -330,7 +332,7 @@ imap_free_body(struct _CamelMessageContentInfo *cinfo)
}
void
-imap_parse_param_list(CamelIMAPXStream *is, struct _camel_header_param **plist)
+imap_parse_param_list(CamelIMAPXStream *is, struct _camel_header_param **plist, CamelException *ex)
{
int tok, len;
unsigned char *token, *param;
@@ -338,29 +340,29 @@ imap_parse_param_list(CamelIMAPXStream *is, struct _camel_header_param **plist)
p(printf("body_fld_param\n"));
/* body_fld_param ::= "(" 1#(string SPACE string) ")" / nil */
- tok = camel_imapx_stream_token(is, &token, &len);
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
if (tok == '(') {
while (1) {
- tok = camel_imapx_stream_token(is, &token, &len);
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
if (tok == ')')
break;
camel_imapx_stream_ungettoken(is, tok, token, len);
- camel_imapx_stream_astring(is, &token);
+ camel_imapx_stream_astring(is, &token, ex);
param = alloca(strlen(token)+1);
strcpy(param, token);
- camel_imapx_stream_astring(is, &token);
+ camel_imapx_stream_astring(is, &token, ex);
camel_header_set_param(plist, param, token);
}
} /* else check nil? no need */
}
struct _CamelContentDisposition *
-imap_parse_ext_optional(CamelIMAPXStream *is)
+imap_parse_ext_optional(CamelIMAPXStream *is, CamelException *ex)
{
int tok, len;
unsigned char *token;
- struct _CamelContentDisposition * volatile dinfo = NULL;
+ struct _CamelContentDisposition *dinfo = NULL;
/* this parses both extension types, from the body_fld_dsp onwards */
/* although the grammars are different, they can be parsed the same way */
@@ -377,41 +379,42 @@ imap_parse_ext_optional(CamelIMAPXStream *is)
;; MUST NOT be returned on non-extensible
;; "BODY" fetch */
- CAMEL_TRY {
- /* body_fld_dsp ::= "(" string SPACE body_fld_param ")" / nil */
+ /* body_fld_dsp ::= "(" string SPACE body_fld_param ")" / nil */
- tok = camel_imapx_stream_token(is, &token, &len);
- switch (tok) {
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ switch (tok) {
case '(':
dinfo = g_malloc0(sizeof(*dinfo));
dinfo->refcount = 1;
/* should be string */
- camel_imapx_stream_astring(is, &token);
-
+ camel_imapx_stream_astring(is, &token, ex);
+
dinfo->disposition = g_strdup(token);
- imap_parse_param_list(is, &dinfo->params);
+ imap_parse_param_list(is, &dinfo->params, ex);
case IMAP_TOK_TOKEN:
d(printf("body_fld_dsp: NIL\n"));
break;
default:
- camel_exception_throw(1, "body_fld_disp: expecting nil or list");
- }
-
- p(printf("body_fld_lang\n"));
+ camel_exception_set (ex, 1, "body_fld_disp: expecting nil or list");
+ return NULL;
+ }
- /* body_fld_lang ::= nstring / "(" 1#string ")" */
-
- /* we just drop the lang string/list, save it somewhere? */
-
- tok = camel_imapx_stream_token(is, &token, &len);
- switch (tok) {
+ p(printf("body_fld_lang\n"));
+
+ /* body_fld_lang ::= nstring / "(" 1#string ")" */
+
+ /* we just drop the lang string/list, save it somewhere? */
+
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ switch (tok) {
case '(':
while (1) {
- tok = camel_imapx_stream_token(is, &token, &len);
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
if (tok == ')') {
break;
} else if (tok != IMAP_TOK_STRING) {
- camel_exception_throw(1, "expecting string");
+ camel_exception_set (ex, 1, "expecting string");
+ break;
}
}
break;
@@ -430,18 +433,18 @@ imap_parse_ext_optional(CamelIMAPXStream *is)
}
break;
- }
- } CAMEL_CATCH(ex) {
+ }
+
+ if camel_exception_is_set (ex) {
if (dinfo)
camel_content_disposition_unref(dinfo);
- camel_exception_throw_ex(ex);
- } CAMEL_DONE;
+ }
return dinfo;
}
struct _CamelMessageContentInfo *
-imap_parse_body_fields(CamelIMAPXStream *is)
+imap_parse_body_fields(CamelIMAPXStream *is, CamelException *ex)
{
unsigned char *token, *type;
struct _CamelMessageContentInfo *cinfo;
@@ -454,40 +457,52 @@ imap_parse_body_fields(CamelIMAPXStream *is)
cinfo = g_malloc0(sizeof(*cinfo));
- CAMEL_TRY {
- /* this should be string not astring */
- camel_imapx_stream_astring(is, &token);
- type = alloca(strlen(token)+1);
- strcpy(type, token);
- camel_imapx_stream_astring(is, &token);
- cinfo->type = camel_content_type_new(type, token);
- imap_parse_param_list(is, &cinfo->type->params);
-
- /* body_fld_id ::= nstring */
- camel_imapx_stream_nstring(is, &token);
- cinfo->id = g_strdup(token);
-
- /* body_fld_desc ::= nstring */
- camel_imapx_stream_nstring(is, &token);
- cinfo->description = g_strdup(token);
+ /* this should be string not astring */
+ camel_imapx_stream_astring(is, &token, ex);
+ if (camel_exception_is_set (ex))
+ goto error;
+ type = alloca(strlen(token)+1);
+ strcpy(type, token);
+ camel_imapx_stream_astring(is, &token, ex);
+ if (camel_exception_is_set (ex))
+ goto error;
+ cinfo->type = camel_content_type_new(type, token);
+ imap_parse_param_list(is, &cinfo->type->params, ex);
+ if (camel_exception_is_set (ex))
+ goto error;
+
+ /* body_fld_id ::= nstring */
+ camel_imapx_stream_nstring(is, &token, ex);
+ if (camel_exception_is_set (ex))
+ goto error;
+ cinfo->id = g_strdup(token);
+
+ /* body_fld_desc ::= nstring */
+ camel_imapx_stream_nstring(is, &token, ex);
+ if (camel_exception_is_set (ex))
+ goto error;
+ cinfo->description = g_strdup(token);
+
+ /* body_fld_enc ::= (<"> ("7BIT" / "8BIT" / "BINARY" / "BASE64"/
+ "QUOTED-PRINTABLE") <">) / string */
+ camel_imapx_stream_astring(is, &token, ex);
+ if (camel_exception_is_set (ex))
+ goto error;
+ cinfo->encoding = g_strdup(token);
- /* body_fld_enc ::= (<"> ("7BIT" / "8BIT" / "BINARY" / "BASE64"/
- "QUOTED-PRINTABLE") <">) / string */
- camel_imapx_stream_astring(is, &token);
- cinfo->encoding = g_strdup(token);
-
- /* body_fld_octets ::= number */
- cinfo->size = camel_imapx_stream_number(is);
- } CAMEL_CATCH(ex) {
- imap_free_body(cinfo);
- camel_exception_throw_ex(ex);
- } CAMEL_DONE;
+ /* body_fld_octets ::= number */
+ cinfo->size = camel_imapx_stream_number(is, ex);
+ if (camel_exception_is_set (ex))
+ goto error;
return cinfo;
+error:
+ imap_free_body(cinfo);
+ return cinfo;
}
struct _camel_header_address *
-imap_parse_address_list(CamelIMAPXStream *is)
+imap_parse_address_list(CamelIMAPXStream *is, CamelException *ex)
/* throws PARSE,IO exception */
{
int tok, len;
@@ -496,75 +511,75 @@ imap_parse_address_list(CamelIMAPXStream *is)
/* "(" 1*address ")" / nil */
- CAMEL_TRY {
- tok = camel_imapx_stream_token(is, &token, &len);
- if (tok == '(') {
- while (1) {
- struct _camel_header_address *addr, *group = NULL;
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ if (tok == '(') {
+ while (1) {
+ struct _camel_header_address *addr, *group = NULL;
- /* address ::= "(" addr_name SPACE addr_adl SPACE addr_mailbox
- SPACE addr_host ")" */
- tok = camel_imapx_stream_token(is, &token, &len);
- if (tok == ')')
- break;
- if (tok != '(')
- camel_exception_throw(1, "missing '(' for address");
-
- addr = camel_header_address_new();
- addr->type = CAMEL_HEADER_ADDRESS_NAME;
- tok = camel_imapx_stream_nstring(is, &token);
- addr->name = g_strdup(token);
- /* we ignore the route, nobody uses it in the real world */
- tok = camel_imapx_stream_nstring(is, &token);
-
- /* [RFC-822] group syntax is indicated by a special
- form of address structure in which the host name
- field is NIL. If the mailbox name field is also
- NIL, this is an end of group marker (semi-colon in
- RFC 822 syntax). If the mailbox name field is
- non-NIL, this is a start of group marker, and the
- mailbox name field holds the group name phrase. */
-
- tok = camel_imapx_stream_nstring(is, &mbox);
- mbox = g_strdup(mbox);
- tok = camel_imapx_stream_nstring(is, &host);
- if (host == NULL) {
- if (mbox == NULL) {
- group = NULL;
- } else {
- d(printf("adding group '%s'\n", mbox));
- g_free(addr->name);
- addr->name = mbox;
- addr->type = CAMEL_HEADER_ADDRESS_GROUP;
- camel_header_address_list_append(&list, addr);
- group = addr;
- }
+ /* address ::= "(" addr_name SPACE addr_adl SPACE addr_mailbox
+ SPACE addr_host ")" */
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ if (tok == ')')
+ break;
+ if (tok != '(') {
+ camel_header_address_list_clear(&list);
+ camel_exception_set (ex, 1, "missing '(' for address");
+ return NULL;
+ }
+
+ addr = camel_header_address_new();
+ addr->type = CAMEL_HEADER_ADDRESS_NAME;
+ tok = camel_imapx_stream_nstring(is, &token, ex);
+ addr->name = g_strdup(token);
+ /* we ignore the route, nobody uses it in the real world */
+ tok = camel_imapx_stream_nstring(is, &token, ex);
+
+ /* [RFC-822] group syntax is indicated by a special
+ form of address structure in which the host name
+ field is NIL. If the mailbox name field is also
+ NIL, this is an end of group marker (semi-colon in
+ RFC 822 syntax). If the mailbox name field is
+ non-NIL, this is a start of group marker, and the
+ mailbox name field holds the group name phrase. */
+
+ tok = camel_imapx_stream_nstring(is, &mbox, ex);
+ mbox = g_strdup(mbox);
+ tok = camel_imapx_stream_nstring(is, &host, ex);
+ if (host == NULL) {
+ if (mbox == NULL) {
+ group = NULL;
} else {
- addr->v.addr = g_strdup_printf("%s%s%s", mbox?(char *)mbox:"", host?"@":"", host?(char *)host:"");
- g_free(mbox);
- d(printf("adding address '%s'\n", addr->v.addr));
- if (group != NULL)
- camel_header_address_add_member(group, addr);
- else
- camel_header_address_list_append(&list, addr);
+ d(printf("adding group '%s'\n", mbox));
+ g_free(addr->name);
+ addr->name = mbox;
+ addr->type = CAMEL_HEADER_ADDRESS_GROUP;
+ camel_header_address_list_append(&list, addr);
+ group = addr;
}
- do {
- tok = camel_imapx_stream_token(is, &token, &len);
- } while (tok != ')');
+ } else {
+ addr->v.addr = g_strdup_printf("%s%s%s", mbox?(char *)mbox:"", host?"@":"", host?(char *)host:"");
+ g_free(mbox);
+ d(printf("adding address '%s'\n", addr->v.addr));
+ if (group != NULL)
+ camel_header_address_add_member(group, addr);
+ else
+ camel_header_address_list_append(&list, addr);
}
- } else {
- d(printf("empty, nil '%s'\n", token));
+ do {
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ } while (tok != ')');
}
- } CAMEL_CATCH(ex) {
- camel_header_address_list_clear(&list);
- camel_exception_throw_ex(ex);
- } CAMEL_DONE;
+ } else {
+ d(printf("empty, nil '%s'\n", token));
+ }
+
+ /* CHEN TODO handle exception at required places */
return list;
}
struct _CamelMessageInfo *
-imap_parse_envelope(CamelIMAPXStream *is)
+imap_parse_envelope(CamelIMAPXStream *is, CamelException *ex)
{
int tok, len;
unsigned char *token;
@@ -581,97 +596,100 @@ imap_parse_envelope(CamelIMAPXStream *is)
minfo = (CamelMessageInfoBase *)camel_message_info_new(NULL);
- CAMEL_TRY {
- tok = camel_imapx_stream_token(is, &token, &len);
- if (tok != '(')
- camel_exception_throw(1, "envelope: expecting '('");
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ if (tok != '(') {
+ camel_message_info_free(minfo);
+ camel_exception_set (ex, 1, "envelope: expecting '('");
+ return NULL;
+ }
- /* env_date ::= nstring */
- camel_imapx_stream_nstring(is, &token);
- minfo->date_sent = camel_header_decode_date(token, NULL);
+ /* env_date ::= nstring */
+ camel_imapx_stream_nstring(is, &token, ex);
+ minfo->date_sent = camel_header_decode_date(token, NULL);
- /* env_subject ::= nstring */
- tok = camel_imapx_stream_nstring(is, &token);
- minfo->subject = camel_pstring_strdup(token);
+ /* env_subject ::= nstring */
+ tok = camel_imapx_stream_nstring(is, &token, ex);
+ minfo->subject = camel_pstring_strdup(token);
- /* we merge from/sender into from, append should probably merge more smartly? */
+ /* we merge from/sender into from, append should probably merge more smartly? */
- /* env_from ::= "(" 1*address ")" / nil */
- addr_from = imap_parse_address_list(is);
+ /* env_from ::= "(" 1*address ")" / nil */
+ addr_from = imap_parse_address_list(is, ex);
- /* env_sender ::= "(" 1*address ")" / nil */
- addr = imap_parse_address_list(is);
- if (addr_from) {
- camel_header_address_list_clear(&addr);
+ /* env_sender ::= "(" 1*address ")" / nil */
+ addr = imap_parse_address_list(is, ex);
+ if (addr_from) {
+ camel_header_address_list_clear(&addr);
#if 0
- if (addr)
- camel_header_address_list_append_list(&addr_from, &addr);
+ if (addr)
+ camel_header_address_list_append_list(&addr_from, &addr);
#endif
- } else {
- if (addr)
- addr_from = addr;
- }
+ } else {
+ if (addr)
+ addr_from = addr;
+ }
- if (addr_from) {
- addrstr = camel_header_address_list_format(addr_from);
- minfo->from = camel_pstring_strdup(addrstr);
- g_free(addrstr);
- camel_header_address_list_clear(&addr_from);
- }
+ if (addr_from) {
+ addrstr = camel_header_address_list_format(addr_from);
+ minfo->from = camel_pstring_strdup(addrstr);
+ g_free(addrstr);
+ camel_header_address_list_clear(&addr_from);
+ }
- /* we dont keep reply_to */
+ /* we dont keep reply_to */
- /* env_reply_to ::= "(" 1*address ")" / nil */
- addr = imap_parse_address_list(is);
- camel_header_address_list_clear(&addr);
+ /* env_reply_to ::= "(" 1*address ")" / nil */
+ addr = imap_parse_address_list(is, ex);
+ camel_header_address_list_clear(&addr);
- /* env_to ::= "(" 1*address ")" / nil */
- addr = imap_parse_address_list(is);
- if (addr) {
- addrstr = camel_header_address_list_format(addr);
- minfo->to = camel_pstring_strdup(addrstr);
- g_free(addrstr);
- camel_header_address_list_clear(&addr);
- }
+ /* env_to ::= "(" 1*address ")" / nil */
+ addr = imap_parse_address_list(is, ex);
+ if (addr) {
+ addrstr = camel_header_address_list_format(addr);
+ minfo->to = camel_pstring_strdup(addrstr);
+ g_free(addrstr);
+ camel_header_address_list_clear(&addr);
+ }
- /* env_cc ::= "(" 1*address ")" / nil */
- addr = imap_parse_address_list(is);
- if (addr) {
- addrstr = camel_header_address_list_format(addr);
- minfo->cc = camel_pstring_strdup(addrstr);
- g_free(addrstr);
- camel_header_address_list_clear(&addr);
- }
+ /* env_cc ::= "(" 1*address ")" / nil */
+ addr = imap_parse_address_list(is, ex);
+ if (addr) {
+ addrstr = camel_header_address_list_format(addr);
+ minfo->cc = camel_pstring_strdup(addrstr);
+ g_free(addrstr);
+ camel_header_address_list_clear(&addr);
+ }
- /* we dont keep bcc either */
+ /* we dont keep bcc either */
- /* env_bcc ::= "(" 1*address ")" / nil */
- addr = imap_parse_address_list(is);
- camel_header_address_list_clear(&addr);
+ /* env_bcc ::= "(" 1*address ")" / nil */
+ addr = imap_parse_address_list(is, ex);
+ camel_header_address_list_clear(&addr);
- /* FIXME: need to put in-reply-to into references hash list */
+ /* FIXME: need to put in-reply-to into references hash list */
- /* env_in_reply_to ::= nstring */
- tok = camel_imapx_stream_nstring(is, &token);
+ /* env_in_reply_to ::= nstring */
+ tok = camel_imapx_stream_nstring(is, &token, ex);
- /* FIXME: need to put message-id into message-id hash */
+ /* FIXME: need to put message-id into message-id hash */
- /* env_message_id ::= nstring */
- tok = camel_imapx_stream_nstring(is, &token);
+ /* env_message_id ::= nstring */
+ tok = camel_imapx_stream_nstring(is, &token, ex);
- tok = camel_imapx_stream_token(is, &token, &len);
- if (tok != ')')
- camel_exception_throw(1, "expecting ')'");
- } CAMEL_CATCH(ex) {
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ if (tok != ')') {
camel_message_info_free(minfo);
- camel_exception_throw_ex(ex);
- } CAMEL_DONE;
+ camel_exception_throw(1, "expecting ')'");
+ return NULL;
+ }
+
+ /* CHEN TODO handle exceptions better */
return (CamelMessageInfo *)minfo;
}
struct _CamelMessageContentInfo *
-imap_parse_body(CamelIMAPXStream *is)
+imap_parse_body(CamelIMAPXStream *is, CamelException *ex)
{
int tok, len;
unsigned char *token;
@@ -684,136 +702,140 @@ imap_parse_body(CamelIMAPXStream *is)
p(printf("body\n"));
- CAMEL_TRY {
- tok = camel_imapx_stream_token(is, &token, &len);
- if (tok != '(')
- camel_exception_throw(1, "body: expecting '('");
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ if (tok != '(') {
+ camel_exception_set (ex, 1, "body: expecting '('");
+ return NULL;
+ }
- /* 1*body (optional for multiparts) */
- tok = camel_imapx_stream_token(is, &token, &len);
- camel_imapx_stream_ungettoken(is, tok, token, len);
- if (tok == '(') {
- /* body_type_mpart ::= 1*body SPACE media_subtype
- [SPACE body_ext_mpart] */
+ /* 1*body (optional for multiparts) */
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ camel_imapx_stream_ungettoken(is, tok, token, len);
+ if (tok == '(') {
+ /* body_type_mpart ::= 1*body SPACE media_subtype
+ [SPACE body_ext_mpart] */
- cinfo = g_malloc0(sizeof(*cinfo));
- last = (struct _CamelMessageContentInfo *)&cinfo->childs;
- do {
- subinfo = imap_parse_body(is);
- last->next = subinfo;
- last = subinfo;
- subinfo->parent = cinfo;
- tok = camel_imapx_stream_token(is, &token, &len);
- camel_imapx_stream_ungettoken(is, tok, token, len);
- } while (tok == '(');
+ cinfo = g_malloc0(sizeof(*cinfo));
+ last = (struct _CamelMessageContentInfo *)&cinfo->childs;
+ do {
+ subinfo = imap_parse_body(is, ex);
+ last->next = subinfo;
+ last = subinfo;
+ subinfo->parent = cinfo;
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ camel_imapx_stream_ungettoken(is, tok, token, len);
+ } while (tok == '(');
- d(printf("media_subtype\n"));
+ d(printf("media_subtype\n"));
- camel_imapx_stream_astring(is, &token);
- cinfo->type = camel_content_type_new("multipart", token);
+ camel_imapx_stream_astring(is, &token, ex);
+ cinfo->type = camel_content_type_new("multipart", token);
- /* body_ext_mpart ::= body_fld_param
- [SPACE body_fld_dsp SPACE body_fld_lang
- [SPACE 1#body_extension]]
- ;; MUST NOT be returned on non-extensible
- ;; "BODY" fetch */
+ /* body_ext_mpart ::= body_fld_param
+ [SPACE body_fld_dsp SPACE body_fld_lang
+ [SPACE 1#body_extension]]
+ ;; MUST NOT be returned on non-extensible
+ ;; "BODY" fetch */
- d(printf("body_ext_mpart\n"));
+ d(printf("body_ext_mpart\n"));
- tok = camel_imapx_stream_token(is, &token, &len);
- camel_imapx_stream_ungettoken(is, tok, token, len);
- if (tok == '(') {
- imap_parse_param_list(is, &cinfo->type->params);
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ camel_imapx_stream_ungettoken(is, tok, token, len);
+ if (tok == '(') {
+ imap_parse_param_list(is, &cinfo->type->params, ex);
- /* body_fld_dsp ::= "(" string SPACE body_fld_param ")" / nil */
+ /* body_fld_dsp ::= "(" string SPACE body_fld_param ")" / nil */
- tok = camel_imapx_stream_token(is, &token, &len);
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ camel_imapx_stream_ungettoken(is, tok, token, len);
+ if (tok == '(' || tok == IMAP_TOK_TOKEN) {
+ dinfo = imap_parse_ext_optional(is, ex);
+ /* other extension fields?, soaked up below */
+ } else {
camel_imapx_stream_ungettoken(is, tok, token, len);
- if (tok == '(' || tok == IMAP_TOK_TOKEN) {
- dinfo = imap_parse_ext_optional(is);
- /* other extension fields?, soaked up below */
- } else {
- camel_imapx_stream_ungettoken(is, tok, token, len);
- }
}
- } else {
- /* body_type_1part ::= (body_type_basic / body_type_msg / body_type_text)
- [SPACE body_ext_1part]
-
- body_type_basic ::= media_basic SPACE body_fields
- body_type_text ::= media_text SPACE body_fields SPACE body_fld_lines
- body_type_msg ::= media_message SPACE body_fields SPACE envelope
- SPACE body SPACE body_fld_lines */
+ }
+ } else {
+ /* body_type_1part ::= (body_type_basic / body_type_msg / body_type_text)
+ [SPACE body_ext_1part]
- d(printf("Single part body\n"));
+ body_type_basic ::= media_basic SPACE body_fields
+ body_type_text ::= media_text SPACE body_fields SPACE body_fld_lines
+ body_type_msg ::= media_message SPACE body_fields SPACE envelope
+ SPACE body SPACE body_fld_lines */
- cinfo = imap_parse_body_fields(is);
+ d(printf("Single part body\n"));
- d(printf("envelope?\n"));
+ cinfo = imap_parse_body_fields(is, ex);
- /* do we have an envelope following */
- tok = camel_imapx_stream_token(is, &token, &len);
- camel_imapx_stream_ungettoken(is, tok, token, len);
- if (tok == '(') {
- /* what do we do with the envelope?? */
- minfo = imap_parse_envelope(is);
- /* what do we do with the message content info?? */
- //((CamelMessageInfoBase *)minfo)->content = imap_parse_body(is);
- camel_message_info_free(minfo);
- minfo = NULL;
- d(printf("Scanned envelope - what do i do with it?\n"));
- }
+ d(printf("envelope?\n"));
+
+ /* do we have an envelope following */
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ camel_imapx_stream_ungettoken(is, tok, token, len);
+ if (tok == '(') {
+ /* what do we do with the envelope?? */
+ minfo = imap_parse_envelope(is, ex);
+ /* what do we do with the message content info?? */
+ //((CamelMessageInfoBase *)minfo)->content = imap_parse_body(is);
+ camel_message_info_free(minfo);
+ minfo = NULL;
+ d(printf("Scanned envelope - what do i do with it?\n"));
+ }
- d(printf("fld_lines?\n"));
+ d(printf("fld_lines?\n"));
- /* do we have fld_lines following? */
- tok = camel_imapx_stream_token(is, &token, &len);
- if (tok == IMAP_TOK_INT) {
- d(printf("field lines: %s\n", token));
- tok = camel_imapx_stream_token(is, &token, &len);
- }
- camel_imapx_stream_ungettoken(is, tok, token, len);
+ /* do we have fld_lines following? */
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ if (tok == IMAP_TOK_INT) {
+ d(printf("field lines: %s\n", token));
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ }
+ camel_imapx_stream_ungettoken(is, tok, token, len);
- /* body_ext_1part ::= body_fld_md5 [SPACE body_fld_dsp
- [SPACE body_fld_lang
- [SPACE 1#body_extension]]]
- ;; MUST NOT be returned on non-extensible
- ;; "BODY" fetch */
+ /* body_ext_1part ::= body_fld_md5 [SPACE body_fld_dsp
+ [SPACE body_fld_lang
+ [SPACE 1#body_extension]]]
+ ;; MUST NOT be returned on non-extensible
+ ;; "BODY" fetch */
- d(printf("extension data?\n"));
+ d(printf("extension data?\n"));
- if (tok != ')') {
- camel_imapx_stream_nstring(is, &token);
+ if (tok != ')') {
+ camel_imapx_stream_nstring(is, &token, ex);
- d(printf("md5: %s\n", token?(char *)token:"NIL"));
+ d(printf("md5: %s\n", token?(char *)token:"NIL"));
- /* body_fld_dsp ::= "(" string SPACE body_fld_param ")" / nil */
+ /* body_fld_dsp ::= "(" string SPACE body_fld_param ")" / nil */
- tok = camel_imapx_stream_token(is, &token, &len);
- camel_imapx_stream_ungettoken(is, tok, token, len);
- if (tok == '(' || tok == IMAP_TOK_TOKEN) {
- dinfo = imap_parse_ext_optional(is);
- /* then other extension fields, soaked up below */
- }
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ camel_imapx_stream_ungettoken(is, tok, token, len);
+ if (tok == '(' || tok == IMAP_TOK_TOKEN) {
+ dinfo = imap_parse_ext_optional(is, ex);
+ /* then other extension fields, soaked up below */
}
}
+ }
- /* soak up any other extension fields that may be present */
- /* there should only be simple tokens, no lists */
- do {
- tok = camel_imapx_stream_token(is, &token, &len);
- if (tok != ')')
- d(printf("Dropping extension data '%s'\n", token));
- } while (tok != ')');
- } CAMEL_CATCH(ex) {
+ /* soak up any other extension fields that may be present */
+ /* there should only be simple tokens, no lists */
+ do {
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ if (tok != ')')
+ d(printf("Dropping extension data '%s'\n", token));
+ } while (tok != ')');
+
+
+ /* CHEN TODO handle exceptions better */
+ if (camel_exception_is_set (ex)) {
if (cinfo)
imap_free_body(cinfo);
if (dinfo)
camel_content_disposition_unref(dinfo);
if (minfo)
camel_message_info_free(minfo);
- camel_exception_throw_ex(ex);
- } CAMEL_DONE;
+ return NULL;
+ }
/* FIXME: do something with the disposition, currently we have no way to pass it out? */
if (dinfo)
@@ -822,12 +844,12 @@ imap_parse_body(CamelIMAPXStream *is)
return cinfo;
}
-char *
-imap_parse_section(CamelIMAPXStream *is)
+gchar *
+imap_parse_section(CamelIMAPXStream *is, CamelException *ex)
{
- int tok, len;
- unsigned char *token;
- char * volatile section = NULL;
+ gint tok, len;
+ guchar *token;
+ gchar * section = NULL;
/* currently we only return the part within the [section] specifier
any header fields are parsed, but dropped */
@@ -840,42 +862,47 @@ imap_parse_section(CamelIMAPXStream *is)
SPACE header_list / "TEXT"
*/
- CAMEL_TRY {
- tok = camel_imapx_stream_token(is, &token, &len);
- if (tok != '[')
- camel_exception_throw(1, "section: expecting '['");
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ if (tok != '[') {
+ camel_exception_set (ex, 1, "section: expecting '['");
+ return NULL;
+ }
- tok = camel_imapx_stream_token(is, &token, &len);
- if (tok == IMAP_TOK_INT || tok == IMAP_TOK_TOKEN)
- section = g_strdup(token);
- else if (tok == ']') {
- section = g_strdup("");
- camel_imapx_stream_ungettoken(is, tok, token, len);
- } else
- camel_exception_throw(1, "section: expecting token");
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ if (tok == IMAP_TOK_INT || tok == IMAP_TOK_TOKEN)
+ section = g_strdup(token);
+ else if (tok == ']') {
+ section = g_strdup("");
+ camel_imapx_stream_ungettoken(is, tok, token, len);
+ } else {
+ camel_exception_set (ex, 1, "section: expecting token");
+ return NULL;
+ }
- /* header_list ::= "(" 1#header_fld_name ")"
- header_fld_name ::= astring */
+ /* header_list ::= "(" 1#header_fld_name ")"
+ header_fld_name ::= astring */
- /* we dont need the header specifiers */
- tok = camel_imapx_stream_token(is, &token, &len);
- if (tok == '(') {
- do {
- tok = camel_imapx_stream_token(is, &token, &len);
- if (tok == IMAP_TOK_STRING || tok == IMAP_TOK_TOKEN || tok == IMAP_TOK_INT) {
- /* ?do something? */
- } else if (tok != ')')
- camel_exception_throw(1, "section: header fields: expecting string");
- } while (tok != ')');
- tok = camel_imapx_stream_token(is, &token, &len);
- }
+ /* we dont need the header specifiers */
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ if (tok == '(') {
+ do {
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ if (tok == IMAP_TOK_STRING || tok == IMAP_TOK_TOKEN || tok == IMAP_TOK_INT) {
+ /* ?do something? */
+ } else if (tok != ')'){
+ camel_exception_set (ex, 1, "section: header fields: expecting string");
+ g_free (section);
+ return NULL;
+ }
+ } while (tok != ')');
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ }
- if (tok != ']')
- camel_exception_throw(1, "section: expecting ']'");
- } CAMEL_CATCH(ex) {
+ if (tok != ']') {
+ camel_exception_set (ex, 1, "section: expecting ']'");
g_free(section);
- camel_exception_throw_ex(ex);
- } CAMEL_DONE;
+ return NULL;
+ }
return section;
}
@@ -961,7 +988,7 @@ imap_dump_fetch(struct _fetch_info *finfo)
}
struct _fetch_info *
-imap_parse_fetch(CamelIMAPXStream *is)
+imap_parse_fetch(CamelIMAPXStream *is, CamelException *ex)
{
int tok, len;
unsigned char *token, *p, c;
@@ -969,87 +996,94 @@ imap_parse_fetch(CamelIMAPXStream *is)
finfo = g_malloc0(sizeof(*finfo));
- CAMEL_TRY {
- tok = camel_imapx_stream_token(is, &token, &len);
- if (tok != '(')
- camel_exception_throw(1, "fetch: expecting '('");
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ if (tok != '(') {
+ camel_exception_set (ex, 1, "fetch: expecting '('");
+ g_free (finfo);
+ return NULL;
+ }
- while ( (tok = camel_imapx_stream_token(is, &token, &len)) == IMAP_TOK_TOKEN ) {
+ while ( (tok = camel_imapx_stream_token(is, &token, &len, ex)) == IMAP_TOK_TOKEN ) {
- p = token;
- while ((c=*p))
- *p++ = toupper(c);
+ p = token;
+ while ((c=*p))
+ *p++ = toupper(c);
- switch(imap_tokenise(token, len)) {
+ switch(imap_tokenise(token, len)) {
case IMAP_ENVELOPE:
- finfo->minfo = imap_parse_envelope(is);
+ finfo->minfo = imap_parse_envelope(is, ex);
finfo->got |= FETCH_MINFO;
break;
case IMAP_FLAGS:
- imap_parse_flags(is, &finfo->flags, &finfo->user_flags);
+ imap_parse_flags(is, &finfo->flags, &finfo->user_flags, ex);
finfo->got |= FETCH_FLAGS;
break;
case IMAP_INTERNALDATE:
- camel_imapx_stream_nstring(is, &token);
+ camel_imapx_stream_nstring(is, &token, ex);
/* TODO: convert to camel format? */
finfo->date = g_strdup(token);
finfo->got |= FETCH_DATE;
break;
case IMAP_RFC822_HEADER:
- camel_imapx_stream_nstring_stream(is, &finfo->header);
+ camel_imapx_stream_nstring_stream(is, &finfo->header, ex);
finfo->got |= FETCH_HEADER;
break;
case IMAP_RFC822_TEXT:
- camel_imapx_stream_nstring_stream(is, &finfo->text);
+ camel_imapx_stream_nstring_stream(is, &finfo->text, ex);
finfo->got |= FETCH_TEXT;
break;
case IMAP_RFC822_SIZE:
- finfo->size = camel_imapx_stream_number(is);
+ finfo->size = camel_imapx_stream_number(is, ex);
finfo->got |= FETCH_SIZE;
break;
case IMAP_BODYSTRUCTURE:
- finfo->cinfo = imap_parse_body(is);
+ finfo->cinfo = imap_parse_body(is, ex);
finfo->got |= FETCH_CINFO;
break;
case IMAP_BODY:
- tok = camel_imapx_stream_token(is, &token, &len);
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
camel_imapx_stream_ungettoken(is, tok, token, len);
if (tok == '(') {
- finfo->cinfo = imap_parse_body(is);
+ finfo->cinfo = imap_parse_body(is, ex);
finfo->got |= FETCH_CINFO;
} else if (tok == '[') {
- finfo->section = imap_parse_section(is);
+ finfo->section = imap_parse_section(is, ex);
finfo->got |= FETCH_SECTION;
- tok = camel_imapx_stream_token(is, &token, &len);
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
if (token[0] == '<') {
finfo->offset = strtoul(token+1, NULL, 10);
} else {
camel_imapx_stream_ungettoken(is, tok, token, len);
}
- camel_imapx_stream_nstring_stream(is, &finfo->body);
+ camel_imapx_stream_nstring_stream(is, &finfo->body, ex);
finfo->got |= FETCH_BODY;
} else {
- camel_exception_throw(1, "unknown body response");
+ camel_exception_set (ex, 1, "unknown body response");
+ imap_free_fetch(finfo);
+ return NULL;
}
break;
case IMAP_UID:
- tok = camel_imapx_stream_token(is, &token, &len);
- if (tok != IMAP_TOK_INT)
- camel_exception_throw(1, "uid not integer");
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ if (tok != IMAP_TOK_INT) {
+ camel_exception_set (ex, 1, "uid not integer");
+ }
+
finfo->uid = g_strdup(token);
finfo->got |= FETCH_UID;
break;
default:
- camel_exception_throw(1, "unknown body response");
- }
+ imap_free_fetch(finfo);
+ camel_exception_set (ex, 1, "unknown body response");
+ return NULL;
}
+ }
- if (tok != ')')
- camel_exception_throw(1, "missing closing ')' on fetch response");
- } CAMEL_CATCH(ex) {
- imap_free_fetch(finfo);
- camel_exception_throw_ex(ex);
- } CAMEL_DONE;
+ if (tok != ')') {
+ camel_exception_set (ex, 1, "missing closing ')' on fetch response");
+ imap_free_fetch (finfo);
+ return NULL;
+ }
return finfo;
}
@@ -1057,7 +1091,7 @@ imap_parse_fetch(CamelIMAPXStream *is)
/* rfc 2060 section 7.1 Status Responses */
/* shoudl this start after [ or before the [? token_unget anyone? */
struct _status_info *
-imap_parse_status(CamelIMAPXStream *is)
+imap_parse_status(CamelIMAPXStream *is, CamelException *ex)
{
int tok, len;
unsigned char *token;
@@ -1065,21 +1099,20 @@ imap_parse_status(CamelIMAPXStream *is)
sinfo = g_malloc0(sizeof(*sinfo));
- CAMEL_TRY {
- camel_imapx_stream_atom(is, &token, &len);
+ camel_imapx_stream_atom(is, &token, &len, ex);
- /*
- resp_cond_auth ::= ("OK" / "PREAUTH") SPACE resp_text
- ;; Authentication condition
+ /*
+ resp_cond_auth ::= ("OK" / "PREAUTH") SPACE resp_text
+ ;; Authentication condition
- resp_cond_bye ::= "BYE" SPACE resp_text
+ resp_cond_bye ::= "BYE" SPACE resp_text
- resp_cond_state ::= ("OK" / "NO" / "BAD") SPACE resp_text
- ;; Status condition
- */
+ resp_cond_state ::= ("OK" / "NO" / "BAD") SPACE resp_text
+ ;; Status condition
+ */
- sinfo->result = imap_tokenise(token, len);
- switch (sinfo->result) {
+ sinfo->result = imap_tokenise(token, len);
+ switch (sinfo->result) {
case IMAP_OK:
case IMAP_NO:
case IMAP_BAD:
@@ -1087,16 +1120,18 @@ imap_parse_status(CamelIMAPXStream *is)
case IMAP_BYE:
break;
default:
- camel_exception_throw(1, "expecting OK/NO/BAD");
- }
+ camel_exception_set (ex, 1, "expecting OK/NO/BAD");
+ g_free (sinfo);
+ return NULL;
+ }
- tok = camel_imapx_stream_token(is, &token, &len);
- if (tok == '[') {
- camel_imapx_stream_atom(is, &token, &len);
- sinfo->condition = imap_tokenise(token, len);
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ if (tok == '[') {
+ camel_imapx_stream_atom(is, &token, &len, ex);
+ sinfo->condition = imap_tokenise(token, len);
- /* parse any details */
- switch (sinfo->condition) {
+ /* parse any details */
+ switch (sinfo->condition) {
case IMAP_READ_ONLY:
case IMAP_READ_WRITE:
case IMAP_ALERT:
@@ -1104,47 +1139,46 @@ imap_parse_status(CamelIMAPXStream *is)
case IMAP_TRYCREATE:
break;
case IMAP_APPENDUID:
- sinfo->u.appenduid.uidvalidity = camel_imapx_stream_number(is);
- sinfo->u.appenduid.uid = camel_imapx_stream_number(is);
+ sinfo->u.appenduid.uidvalidity = camel_imapx_stream_number(is, ex);
+ sinfo->u.appenduid.uid = camel_imapx_stream_number(is, ex);
break;
case IMAP_NEWNAME:
/* the rfc doesn't specify the bnf for this */
- camel_imapx_stream_astring(is, &token);
+ camel_imapx_stream_astring(is, &token, ex);
sinfo->u.newname.oldname = g_strdup(token);
- camel_imapx_stream_astring(is, &token);
+ camel_imapx_stream_astring(is, &token, ex);
sinfo->u.newname.newname = g_strdup(token);
break;
case IMAP_PERMANENTFLAGS:
/* we only care about \* for permanent flags, not user flags */
- imap_parse_flags(is, &sinfo->u.permanentflags, NULL);
+ imap_parse_flags(is, &sinfo->u.permanentflags, NULL, ex);
break;
case IMAP_UIDVALIDITY:
- sinfo->u.uidvalidity = camel_imapx_stream_number(is);
+ sinfo->u.uidvalidity = camel_imapx_stream_number(is, ex);
break;
case IMAP_UNSEEN:
- sinfo->u.unseen = camel_imapx_stream_number(is);
+ sinfo->u.unseen = camel_imapx_stream_number(is, ex);
break;
default:
sinfo->condition = IMAP_UNKNOWN;
printf("Got unknown response code: %s: ignored\n", token);
- }
-
- /* ignore anything we dont know about */
- do {
- tok = camel_imapx_stream_token(is, &token, &len);
- if (tok == '\n')
- camel_exception_throw(1, "server response truncated");
- } while (tok != ']');
- } else {
- camel_imapx_stream_ungettoken(is, tok, token, len);
}
- /* and take the human readable response */
- camel_imapx_stream_text(is, (unsigned char **)&sinfo->text);
- } CAMEL_CATCH(ex) {
- imap_free_status(sinfo);
- camel_exception_throw_ex(ex);
- } CAMEL_DONE;
+ /* ignore anything we dont know about */
+ do {
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ if (tok == '\n') {
+ camel_exception_set (ex, 1, "server response truncated");
+ imap_free_status(sinfo);
+ return NULL;
+ }
+ } while (tok != ']');
+ } else {
+ camel_imapx_stream_ungettoken(is, tok, token, len);
+ }
+
+ /* and take the human readable response */
+ camel_imapx_stream_text(is, (unsigned char **)&sinfo->text, ex);
return sinfo;
}
@@ -1196,45 +1230,45 @@ static struct {
};
struct _list_info *
-imap_parse_list(CamelIMAPXStream *is)
+imap_parse_list(CamelIMAPXStream *is, CamelException *ex)
/* throws io, parse */
{
- int tok, len, i;
- unsigned char *token, *p, c;
+ gint tok, len, i;
+ guchar *token, *p, c;
struct _list_info * volatile linfo;
linfo = g_malloc0(sizeof(*linfo));
- CAMEL_TRY {
- /* mailbox_list ::= "(" #("\Marked" / "\Noinferiors" /
- "\Noselect" / "\Unmarked" / flag_extension) ")"
- SPACE (<"> QUOTED_CHAR <"> / nil) SPACE mailbox */
-
- tok = camel_imapx_stream_token(is, &token, &len);
- if (tok != '(')
- camel_exception_throw(1, "list: expecting '('");
+ /* mailbox_list ::= "(" #("\Marked" / "\Noinferiors" /
+ "\Noselect" / "\Unmarked" / flag_extension) ")"
+ SPACE (<"> QUOTED_CHAR <"> / nil) SPACE mailbox */
+
+ tok = camel_imapx_stream_token(is, &token, &len, ex);
+ if (tok != '(') {
+ camel_exception_set (ex, 1, "list: expecting '('");
+ g_free (linfo);
+ return NULL;
+ }
- while ( (tok = camel_imapx_stream_token(is, &token, &len)) != ')' ) {
- if (tok == IMAP_TOK_STRING || tok == IMAP_TOK_TOKEN) {
- p = token;
- while ((c=*p))
- *p++ = toupper(c);
- for (i=0;i<(int)(sizeof(list_flag_table)/sizeof(list_flag_table[0]));i++)
- if (!strcmp(token, list_flag_table[i].name))
- linfo->flags |= list_flag_table[i].flag;
- } else {
- camel_exception_throw(1, "list: expecting flag or ')'");
- }
+ while ( (tok = camel_imapx_stream_token(is, &token, &len, ex)) != ')' ) {
+ if (tok == IMAP_TOK_STRING || tok == IMAP_TOK_TOKEN) {
+ p = token;
+ while ((c=*p))
+ *p++ = toupper(c);
+ for (i=0;i<(int)(sizeof(list_flag_table)/sizeof(list_flag_table[0]));i++)
+ if (!strcmp(token, list_flag_table[i].name))
+ linfo->flags |= list_flag_table[i].flag;
+ } else {
+ imap_free_list(linfo);
+ camel_exception_set (ex, 1, "list: expecting flag or ')'");
+ return NULL;
}
+ }
- camel_imapx_stream_nstring(is, &token);
- linfo->separator = token?*token:0;
- camel_imapx_stream_astring(is, &token);
- linfo->name = g_strdup(token);
- } CAMEL_CATCH(ex) {
- imap_free_list(linfo);
- camel_exception_throw_ex(ex);
- } CAMEL_DONE;
+ camel_imapx_stream_nstring(is, &token, ex);
+ linfo->separator = token?*token:0;
+ camel_imapx_stream_astring(is, &token, ex);
+ linfo->name = g_strdup(token);
return linfo;
}
diff --git a/camel/providers/imapx/camel-imapx-utils.h b/camel/providers/imapx/camel-imapx-utils.h
index a0299cc..ad4e9f3 100644
--- a/camel/providers/imapx/camel-imapx-utils.h
+++ b/camel/providers/imapx/camel-imapx-utils.h
@@ -55,7 +55,7 @@ enum {
/* ********************************************************************** */
-void imap_parse_flags(struct _CamelIMAPXStream *stream, guint32 *flagsp, struct _CamelFlag **user_flagsp);
+void imap_parse_flags(struct _CamelIMAPXStream *stream, guint32 *flagsp, struct _CamelFlag **user_flagsp, CamelException *ex);
void imap_write_flags(CamelStream *stream, guint32 flags, struct _CamelFlag *user_flags);
/* ********************************************************************** */
@@ -74,16 +74,16 @@ struct _capability_info {
/* auth stuff here */
};
-struct _capability_info *imap_parse_capability(struct _CamelIMAPXStream *stream);
+struct _capability_info *imap_parse_capability(struct _CamelIMAPXStream *stream, CamelException *ex);
void imap_free_capability(struct _capability_info *);
-void imap_parse_param_list(struct _CamelIMAPXStream *is, struct _camel_header_param **plist) /* IO,PARSE */;
-struct _CamelContentDisposition *imap_parse_ext_optional(struct _CamelIMAPXStream *is) /* IO,PARSE */;
-struct _CamelMessageContentInfo *imap_parse_body_fields(struct _CamelIMAPXStream *is) /* IO,PARSE */;
-struct _camel_header_address *imap_parse_address_list(struct _CamelIMAPXStream *is) /* IO,PARSE */;
-struct _CamelMessageInfo *imap_parse_envelope(struct _CamelIMAPXStream *is) /* IO, PARSE */;
-struct _CamelMessageContentInfo *imap_parse_body(struct _CamelIMAPXStream *is) /* IO,PARSE */;
-char *imap_parse_section(struct _CamelIMAPXStream *is) /* IO,PARSE */;
+void imap_parse_param_list(struct _CamelIMAPXStream *is, struct _camel_header_param **plist, CamelException *ex) /* IO,PARSE */;
+struct _CamelContentDisposition *imap_parse_ext_optional(struct _CamelIMAPXStream *is, CamelException *ex) /* IO,PARSE */;
+struct _CamelMessageContentInfo *imap_parse_body_fields(struct _CamelIMAPXStream *is, CamelException *ex) /* IO,PARSE */;
+struct _camel_header_address *imap_parse_address_list(struct _CamelIMAPXStream *is, CamelException *ex) /* IO,PARSE */;
+struct _CamelMessageInfo *imap_parse_envelope(struct _CamelIMAPXStream *is, CamelException *ex) /* IO, PARSE */;
+struct _CamelMessageContentInfo *imap_parse_body(struct _CamelIMAPXStream *is, CamelException *ex) /* IO,PARSE */;
+char *imap_parse_section(struct _CamelIMAPXStream *is, CamelException *ex) /* IO,PARSE */;
void imap_free_body(struct _CamelMessageContentInfo *cinfo);
/* ********************************************************************** */
@@ -117,7 +117,7 @@ struct _fetch_info {
#define FETCH_SECTION (1<<9)
#define FETCH_UID (1<<10)
-struct _fetch_info *imap_parse_fetch(struct _CamelIMAPXStream *is);
+struct _fetch_info *imap_parse_fetch(struct _CamelIMAPXStream *is, CamelException *ex);
void imap_free_fetch(struct _fetch_info *finfo);
void imap_dump_fetch(struct _fetch_info *finfo);
@@ -144,7 +144,7 @@ struct _status_info {
char *text;
};
-struct _status_info *imap_parse_status(struct _CamelIMAPXStream *is);
+struct _status_info *imap_parse_status(struct _CamelIMAPXStream *is, CamelException *ex);
struct _status_info *imap_copy_status(struct _status_info *sinfo);
void imap_free_status(struct _status_info *sinfo);
@@ -158,7 +158,7 @@ struct _list_info {
char *name;
};
-struct _list_info *imap_parse_list(struct _CamelIMAPXStream *is);
+struct _list_info *imap_parse_list(struct _CamelIMAPXStream *is, CamelException *ex);
char *imapx_list_get_path(struct _list_info *li);
void imap_free_list(struct _list_info *linfo);
diff --git a/camel/providers/imapx/test-imapx.c b/camel/providers/imapx/test-imapx.c
index 6153b1e..fa39d85 100644
--- a/camel/providers/imapx/test-imapx.c
+++ b/camel/providers/imapx/test-imapx.c
@@ -30,5 +30,8 @@ main (int argc, char *argv [])
service = camel_session_get_service (session, uri, CAMEL_PROVIDER_STORE, ex);
camel_service_connect (service, ex);
+ while (1)
+ {
+ }
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]