[evolution-data-server] POP3: Use GError instead of errno.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] POP3: Use GError instead of errno.
- Date: Tue, 5 Jul 2011 02:11:26 +0000 (UTC)
commit 8681f51e067140bdccaf5371488fcda4c232e3f8
Author: Matthew Barnes <mbarnes redhat com>
Date: Mon Jul 4 22:08:04 2011 -0400
POP3: Use GError instead of errno.
camel/providers/pop3/camel-pop3-engine.c | 34 +++++++---
camel/providers/pop3/camel-pop3-engine.h | 32 ++++++---
camel/providers/pop3/camel-pop3-folder.c | 103 ++++++++++--------------------
camel/providers/pop3/camel-pop3-folder.h | 1 -
camel/providers/pop3/camel-pop3-store.c | 33 +++------
camel/providers/pop3/camel-pop3-stream.c | 50 +++++----------
camel/providers/pop3/camel-pop3-stream.h | 21 ++++--
7 files changed, 119 insertions(+), 155 deletions(-)
---
diff --git a/camel/providers/pop3/camel-pop3-engine.c b/camel/providers/pop3/camel-pop3-engine.c
index 99d5d08..b9d7a06 100644
--- a/camel/providers/pop3/camel-pop3-engine.c
+++ b/camel/providers/pop3/camel-pop3-engine.c
@@ -24,7 +24,6 @@
#include <config.h>
#endif
-#include <errno.h>
#include <stdio.h>
#include <string.h>
@@ -100,7 +99,7 @@ read_greeting (CamelPOP3Engine *pe)
guint len;
/* first, read the greeting */
- if (camel_pop3_stream_line (pe->stream, &line, &len) == -1
+ if (camel_pop3_stream_line (pe->stream, &line, &len, NULL, NULL) == -1
|| strncmp ((gchar *) line, "+OK", 3) != 0)
return -1;
@@ -187,7 +186,7 @@ cmd_capa (CamelPOP3Engine *pe, CamelPOP3Stream *stream, gpointer data)
dd(printf("cmd_capa\n"));
do {
- ret = camel_pop3_stream_line (stream, &line, &len);
+ ret = camel_pop3_stream_line (stream, &line, &len, NULL, NULL);
if (ret >= 0) {
if (strncmp((gchar *) line, "SASL ", 5) == 0) {
tok = line+5;
@@ -222,14 +221,14 @@ get_capabilities (CamelPOP3Engine *pe)
if (!(pe->flags & CAMEL_POP3_ENGINE_DISABLE_EXTENSIONS)) {
pc = camel_pop3_engine_command_new(pe, CAMEL_POP3_COMMAND_MULTI, cmd_capa, NULL, NULL, NULL, "CAPA\r\n");
- while (camel_pop3_engine_iterate (pe, pc) > 0)
+ while (camel_pop3_engine_iterate (pe, pc, NULL, NULL) > 0)
;
camel_pop3_engine_command_free (pe, pc);
if (pe->state == CAMEL_POP3_ENGINE_TRANSACTION && !(pe->capa & CAMEL_POP3_CAP_UIDL)) {
/* check for UIDL support manually */
pc = camel_pop3_engine_command_new (pe, CAMEL_POP3_COMMAND_SIMPLE, NULL, NULL, NULL, NULL, "UIDL 1\r\n");
- while (camel_pop3_engine_iterate (pe, pc) > 0)
+ while (camel_pop3_engine_iterate (pe, pc, NULL, NULL) > 0)
;
if (pc->state == CAMEL_POP3_COMMAND_OK)
@@ -242,7 +241,10 @@ get_capabilities (CamelPOP3Engine *pe)
/* returns true if the command was sent, false if it was just queued */
static gboolean
-engine_command_queue (CamelPOP3Engine *pe, CamelPOP3Command *pc, GCancellable *cancellable, GError **error)
+engine_command_queue (CamelPOP3Engine *pe,
+ CamelPOP3Command *pc,
+ GCancellable *cancellable,
+ GError **error)
{
if (((pe->capa & CAMEL_POP3_CAP_PIPE) == 0 || (pe->sentlen + strlen (pc->data)) > CAMEL_POP3_SEND_LIMIT)
&& pe->current != NULL) {
@@ -268,9 +270,12 @@ engine_command_queue (CamelPOP3Engine *pe, CamelPOP3Command *pc, GCancellable *c
return TRUE;
}
-/* returns -1 on error (sets errno), 0 when no work to do, or >0 if work remaining */
+/* returns -1 on error, 0 when no work to do, or >0 if work remaining */
gint
-camel_pop3_engine_iterate (CamelPOP3Engine *pe, CamelPOP3Command *pcwait)
+camel_pop3_engine_iterate (CamelPOP3Engine *pe,
+ CamelPOP3Command *pcwait,
+ GCancellable *cancellable,
+ GError **error)
{
guchar *p;
guint len;
@@ -285,7 +290,7 @@ camel_pop3_engine_iterate (CamelPOP3Engine *pe, CamelPOP3Command *pcwait)
/* LOCK */
- if (camel_pop3_stream_line (pe->stream, &pe->line, &pe->linelen) == -1)
+ if (camel_pop3_stream_line (pe->stream, &pe->line, &pe->linelen, cancellable, error) == -1)
goto ioerror;
p = pe->line;
@@ -300,7 +305,7 @@ camel_pop3_engine_iterate (CamelPOP3Engine *pe, CamelPOP3Command *pcwait)
pc->func (pe, pe->stream, pc->func_data);
/* Make sure we get all data before going back to command mode */
- while (camel_pop3_stream_getd (pe->stream, &p, &len) > 0)
+ while (camel_pop3_stream_getd (pe->stream, &p, &len, NULL, NULL) > 0)
;
camel_pop3_stream_set_mode (pe->stream, CAMEL_POP3_STREAM_LINE);
} else {
@@ -377,7 +382,14 @@ ioerror:
}
CamelPOP3Command *
-camel_pop3_engine_command_new (CamelPOP3Engine *pe, guint32 flags, CamelPOP3CommandFunc func, gpointer data, GCancellable *cancellable, GError **error, const gchar *fmt, ...)
+camel_pop3_engine_command_new (CamelPOP3Engine *pe,
+ guint32 flags,
+ CamelPOP3CommandFunc func,
+ gpointer data,
+ GCancellable *cancellable,
+ GError **error,
+ const gchar *fmt,
+ ...)
{
CamelPOP3Command *pc;
va_list ap;
diff --git a/camel/providers/pop3/camel-pop3-engine.h b/camel/providers/pop3/camel-pop3-engine.h
index e7ff7c5..b611361 100644
--- a/camel/providers/pop3/camel-pop3-engine.h
+++ b/camel/providers/pop3/camel-pop3-engine.h
@@ -136,17 +136,27 @@ struct _CamelPOP3EngineClass {
CamelObjectClass parent_class;
};
-GType camel_pop3_engine_get_type (void);
-
-CamelPOP3Engine *camel_pop3_engine_new (CamelStream *source, guint32 flags);
-
-void camel_pop3_engine_reget_capabilities (CamelPOP3Engine *engine);
-
-void camel_pop3_engine_command_free (CamelPOP3Engine *pe, CamelPOP3Command *pc);
-
-gint camel_pop3_engine_iterate (CamelPOP3Engine *pe, CamelPOP3Command *pc);
-
-CamelPOP3Command *camel_pop3_engine_command_new (CamelPOP3Engine *pe, guint32 flags, CamelPOP3CommandFunc func, gpointer data, GCancellable *cancellable, GError **error, const gchar *fmt, ...);
+GType camel_pop3_engine_get_type (void);
+CamelPOP3Engine *
+ camel_pop3_engine_new (CamelStream *source,
+ guint32 flags);
+void camel_pop3_engine_reget_capabilities
+ (CamelPOP3Engine *engine);
+void camel_pop3_engine_command_free (CamelPOP3Engine *pe,
+ CamelPOP3Command *pc);
+gint camel_pop3_engine_iterate (CamelPOP3Engine *pe,
+ CamelPOP3Command *pc,
+ GCancellable *cancellable,
+ GError **error);
+CamelPOP3Command *
+ camel_pop3_engine_command_new (CamelPOP3Engine *pe,
+ guint32 flags,
+ CamelPOP3CommandFunc func,
+ gpointer data,
+ GCancellable *cancellable,
+ GError **error,
+ const gchar *fmt,
+ ...);
G_END_DECLS
diff --git a/camel/providers/pop3/camel-pop3-folder.c b/camel/providers/pop3/camel-pop3-folder.c
index 9e892e5..b15cf49 100644
--- a/camel/providers/pop3/camel-pop3-folder.c
+++ b/camel/providers/pop3/camel-pop3-folder.c
@@ -27,7 +27,6 @@
#include <config.h>
#endif
-#include <errno.h>
#include <stdlib.h>
#include <string.h>
@@ -54,7 +53,7 @@ cmd_uidl (CamelPOP3Engine *pe,
CamelPOP3Folder *folder = data;
do {
- ret = camel_pop3_stream_line (stream, &line, &len);
+ ret = camel_pop3_stream_line (stream, &line, &len, NULL, NULL);
if (ret>=0) {
if (strlen ((gchar *) line) > 1024)
line[1024] = 0;
@@ -135,7 +134,7 @@ cmd_list (CamelPOP3Engine *pe, CamelPOP3Stream *stream, gpointer data)
pop3_store = CAMEL_POP3_STORE (parent_store);
do {
- ret = camel_pop3_stream_line (stream, &line, &len);
+ ret = camel_pop3_stream_line (stream, &line, &len, NULL, NULL);
if (ret>=0) {
if (sscanf((gchar *) line, "%u %u", &id, &size) == 2) {
fi = g_malloc0 (sizeof (*fi));
@@ -159,16 +158,17 @@ cmd_tocache (CamelPOP3Engine *pe,
CamelPOP3FolderInfo *fi = data;
gchar buffer[2048];
gint w = 0, n;
+ GError *error = NULL;
/* What if it fails? */
/* We write an '*' to the start of the stream to say its not complete yet */
/* This should probably be part of the cache code */
- if ((n = camel_stream_write (fi->stream, "*", 1, NULL, NULL)) == -1)
+ if ((n = camel_stream_write (fi->stream, "*", 1, NULL, &error)) == -1)
goto done;
- while ((n = camel_stream_read ((CamelStream *) stream, buffer, sizeof (buffer), NULL, NULL)) > 0) {
- n = camel_stream_write (fi->stream, buffer, n, NULL, NULL);
+ while ((n = camel_stream_read ((CamelStream *) stream, buffer, sizeof (buffer), NULL, &error)) > 0) {
+ n = camel_stream_write (fi->stream, buffer, n, NULL, &error);
if (n == -1)
break;
@@ -180,16 +180,15 @@ cmd_tocache (CamelPOP3Engine *pe,
}
/* it all worked, output a '#' to say we're a-ok */
- if (n != -1) {
+ if (error == NULL) {
camel_stream_reset (fi->stream, NULL);
- n = camel_stream_write(fi->stream, "#", 1, NULL, NULL);
+ camel_stream_write (fi->stream, "#", 1, NULL, &error);
}
+
done:
- if (n == -1) {
- fi->err = errno;
- g_warning("POP3 retrieval failed: %s", g_strerror(errno));
- } else {
- fi->err = 0;
+ if (error != NULL) {
+ g_warning ("POP3 retrieval failed: %s", error->message);
+ g_error_free (error);
}
g_object_unref (fi->stream);
@@ -213,7 +212,7 @@ pop3_folder_dispose (GObject *object)
for (i = 0; i < pop3_folder->uids->len; i++, fi++) {
if (fi[0]->cmd && pop3_store) {
- while (camel_pop3_engine_iterate (pop3_store->engine, fi[0]->cmd) > 0)
+ while (camel_pop3_engine_iterate (pop3_store->engine, fi[0]->cmd, NULL, NULL) > 0)
;
camel_pop3_engine_command_free (pop3_store->engine, fi[0]->cmd);
}
@@ -352,29 +351,17 @@ pop3_folder_get_message_sync (CamelFolder *folder,
& then retrieve from cache, otherwise, start a new one, and similar */
if (fi->cmd != NULL) {
- while ((i = camel_pop3_engine_iterate (pop3_store->engine, fi->cmd)) > 0)
+ while ((i = camel_pop3_engine_iterate (pop3_store->engine, fi->cmd, cancellable, error)) > 0)
;
- if (i == -1)
- fi->err = errno;
-
/* getting error code? */
/*g_assert (fi->cmd->state == CAMEL_POP3_COMMAND_DATA);*/
camel_pop3_engine_command_free (pop3_store->engine, fi->cmd);
fi->cmd = NULL;
- if (fi->err != 0) {
- if (fi->err == EINTR)
- g_set_error (
- error, G_IO_ERROR,
- G_IO_ERROR_CANCELLED,
- _("Cancelled"));
- else
- g_set_error (
- error, CAMEL_ERROR,
- CAMEL_ERROR_GENERIC,
- _("Cannot get message %s: %s"),
- uid, g_strerror (fi->err));
+ if (i == -1) {
+ g_prefix_error (
+ error, _("Cannot get message %s: "), uid);
goto fail;
}
}
@@ -392,7 +379,6 @@ pop3_folder_get_message_sync (CamelFolder *folder,
/* ref it, the cache storage routine unref's when done */
fi->stream = g_object_ref (stream);
- fi->err = EIO;
pcr = camel_pop3_engine_command_new(pop3_store->engine, CAMEL_POP3_COMMAND_MULTI, cmd_tocache, fi, NULL, NULL, "RETR %u\r\n", fi->id);
/* Also initiate retrieval of some of the following messages, assume we'll be receiving them */
@@ -407,7 +393,6 @@ pop3_folder_get_message_sync (CamelFolder *folder,
if (pfi->uid && pfi->cmd == NULL) {
pfi->stream = camel_data_cache_add(pop3_store->cache, "cache", pfi->uid, NULL);
if (pfi->stream) {
- pfi->err = EIO;
pfi->cmd = camel_pop3_engine_command_new (pop3_store->engine, CAMEL_POP3_COMMAND_MULTI,
cmd_tocache, pfi, NULL, NULL, "RETR %u\r\n", pfi->id);
}
@@ -416,30 +401,18 @@ pop3_folder_get_message_sync (CamelFolder *folder,
}
/* now wait for the first one to finish */
- while ((i = camel_pop3_engine_iterate (pop3_store->engine, pcr)) > 0)
+ while ((i = camel_pop3_engine_iterate (pop3_store->engine, pcr, cancellable, error)) > 0)
;
- if (i == -1)
- fi->err = errno;
-
/* getting error code? */
/*g_assert (pcr->state == CAMEL_POP3_COMMAND_DATA);*/
camel_pop3_engine_command_free (pop3_store->engine, pcr);
camel_stream_reset (stream, NULL);
/* Check to see we have safely written flag set */
- if (fi->err != 0) {
- if (fi->err == EINTR)
- g_set_error (
- error, G_IO_ERROR,
- G_IO_ERROR_CANCELLED,
- _("Cancelled"));
- else
- g_set_error (
- error, CAMEL_ERROR,
- CAMEL_ERROR_GENERIC,
- _("Cannot get message %s: %s"),
- uid, g_strerror (fi->err));
+ if (i == -1) {
+ g_prefix_error (
+ error, _("Cannot get message %s: "), uid);
goto done;
}
@@ -499,24 +472,14 @@ pop3_folder_refresh_info_sync (CamelFolder *folder,
pcl = camel_pop3_engine_command_new(pop3_store->engine, CAMEL_POP3_COMMAND_MULTI, cmd_list, folder, cancellable, &local_error, "LIST\r\n");
if (!local_error && (pop3_store->engine->capa & CAMEL_POP3_CAP_UIDL) != 0)
pcu = camel_pop3_engine_command_new(pop3_store->engine, CAMEL_POP3_COMMAND_MULTI, cmd_uidl, folder, cancellable, &local_error, "UIDL\r\n");
- while ((i = camel_pop3_engine_iterate (pop3_store->engine, NULL)) > 0)
+ while ((i = camel_pop3_engine_iterate (pop3_store->engine, NULL, cancellable, error)) > 0)
;
if (local_error) {
g_propagate_error (error, local_error);
success = FALSE;
} else if (i == -1) {
- if (errno == EINTR)
- g_set_error (
- error, G_IO_ERROR,
- G_IO_ERROR_CANCELLED,
- _("Cancelled"));
- else
- g_set_error (
- error, G_IO_ERROR,
- g_io_error_from_errno (errno),
- _("Cannot get POP summary: %s"),
- g_strerror (errno));
+ g_prefix_error (error, _("Cannot get POP summary: "));
success = FALSE;
}
@@ -593,7 +556,7 @@ pop3_folder_synchronize_sync (CamelFolder *folder,
fi = pop3_folder->uids->pdata[i];
/* busy already? wait for that to finish first */
if (fi->cmd) {
- while (camel_pop3_engine_iterate (pop3_store->engine, fi->cmd) > 0)
+ while (camel_pop3_engine_iterate (pop3_store->engine, fi->cmd, NULL, NULL) > 0)
;
camel_pop3_engine_command_free (pop3_store->engine, fi->cmd);
fi->cmd = NULL;
@@ -618,7 +581,7 @@ pop3_folder_synchronize_sync (CamelFolder *folder,
fi = pop3_folder->uids->pdata[i];
/* wait for delete commands to finish */
if (fi->cmd) {
- while (camel_pop3_engine_iterate (pop3_store->engine, fi->cmd) > 0)
+ while (camel_pop3_engine_iterate (pop3_store->engine, fi->cmd, NULL, NULL) > 0)
;
camel_pop3_engine_command_free (pop3_store->engine, fi->cmd);
fi->cmd = NULL;
@@ -706,11 +669,15 @@ pop3_get_message_time_from_cache (CamelFolder *folder, const gchar *uid, time_t
&& camel_stream_read (stream, buffer, 1, NULL, NULL) == 1
&& buffer[0] == '#') {
CamelMimeMessage *message;
+ GError *error = NULL;
message = camel_mime_message_new ();
- if (!camel_data_wrapper_construct_from_stream_sync (
- (CamelDataWrapper *) message, stream, NULL, NULL)) {
- g_warning (_("Cannot get message %s: %s"), uid, g_strerror (errno));
+ camel_data_wrapper_construct_from_stream_sync (
+ (CamelDataWrapper *) message, stream, NULL, &error);
+ if (error != NULL) {
+ g_warning (_("Cannot get message %s: %s"), uid, error->message);
+ g_error_free (error);
+
g_object_unref (message);
message = NULL;
}
@@ -755,7 +722,7 @@ camel_pop3_delete_old (CamelFolder *folder,
fi = pop3_folder->uids->pdata[i];
if (fi->cmd) {
- while (camel_pop3_engine_iterate (pop3_store->engine, fi->cmd) > 0) {
+ while (camel_pop3_engine_iterate (pop3_store->engine, fi->cmd, NULL, NULL) > 0) {
; /* do nothing - iterating until end */
}
@@ -788,7 +755,7 @@ camel_pop3_delete_old (CamelFolder *folder,
if (day_lag > days_to_delete) {
if (fi->cmd) {
- while (camel_pop3_engine_iterate (pop3_store->engine, fi->cmd) > 0) {
+ while (camel_pop3_engine_iterate (pop3_store->engine, fi->cmd, NULL, NULL) > 0) {
; /* do nothing - iterating until end */
}
@@ -815,7 +782,7 @@ camel_pop3_delete_old (CamelFolder *folder,
fi = pop3_folder->uids->pdata[i];
/* wait for delete commands to finish */
if (fi->cmd) {
- while (camel_pop3_engine_iterate (pop3_store->engine, fi->cmd) > 0)
+ while (camel_pop3_engine_iterate (pop3_store->engine, fi->cmd, NULL, NULL) > 0)
;
camel_pop3_engine_command_free (pop3_store->engine, fi->cmd);
fi->cmd = NULL;
diff --git a/camel/providers/pop3/camel-pop3-folder.h b/camel/providers/pop3/camel-pop3-folder.h
index 42e4be0..1a6f2c5 100644
--- a/camel/providers/pop3/camel-pop3-folder.h
+++ b/camel/providers/pop3/camel-pop3-folder.h
@@ -59,7 +59,6 @@ struct _CamelPOP3FolderInfo {
guint32 flags;
guint32 index; /* index of request */
gchar *uid;
- gint err;
struct _CamelPOP3Command *cmd;
struct _CamelStream *stream;
};
diff --git a/camel/providers/pop3/camel-pop3-store.c b/camel/providers/pop3/camel-pop3-store.c
index bf3b064..88e93a0 100644
--- a/camel/providers/pop3/camel-pop3-store.c
+++ b/camel/providers/pop3/camel-pop3-store.c
@@ -27,7 +27,6 @@
#include <config.h>
#endif
-#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -205,7 +204,7 @@ connect_to_server (CamelService *service,
}
pc = camel_pop3_engine_command_new (store->engine, 0, NULL, NULL, cancellable, error, "STLS\r\n");
- while (camel_pop3_engine_iterate (store->engine, NULL) > 0)
+ while (camel_pop3_engine_iterate (store->engine, NULL, NULL, NULL) > 0)
;
ret = pc->state == CAMEL_POP3_COMMAND_OK;
@@ -254,7 +253,7 @@ connect_to_server (CamelService *service,
if (clean_quit) {
/* try to disconnect cleanly */
pc = camel_pop3_engine_command_new (store->engine, 0, NULL, NULL, NULL, NULL, "QUIT\r\n");
- while (camel_pop3_engine_iterate (store->engine, NULL) > 0)
+ while (camel_pop3_engine_iterate (store->engine, NULL, NULL, NULL) > 0)
;
camel_pop3_engine_command_free (store->engine, pc);
}
@@ -335,7 +334,7 @@ try_sasl (CamelPOP3Store *store,
goto ioerror;
while (1) {
- if (camel_pop3_stream_line (stream, &line, &len) == -1)
+ if (camel_pop3_stream_line (stream, &line, &len, cancellable, error) == -1)
goto ioerror;
if (strncmp((gchar *) line, "+OK", 3) == 0)
break;
@@ -360,7 +359,7 @@ try_sasl (CamelPOP3Store *store,
|| camel_sasl_get_authenticated (sasl)
|| (resp = (guchar *) camel_sasl_challenge_base64_sync (sasl, (const gchar *) line+2, cancellable, NULL)) == NULL) {
camel_stream_printf((CamelStream *)stream, "*\r\n");
- camel_pop3_stream_line (stream, &line, &len);
+ camel_pop3_stream_line (stream, &line, &len, NULL, NULL);
g_set_error (
error, CAMEL_SERVICE_ERROR,
CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
@@ -494,24 +493,14 @@ pop3_try_authenticate (CamelService *service,
return 0;
}
- while ((status = camel_pop3_engine_iterate (store->engine, pcp)) > 0)
+ while ((status = camel_pop3_engine_iterate (store->engine, pcp, cancellable, error)) > 0)
;
if (status == -1) {
- if (errno == EINTR) {
- g_set_error (
- error, G_IO_ERROR,
- G_IO_ERROR_CANCELLED,
- _("Cancelled"));
- } else {
- g_set_error (
- error, G_IO_ERROR,
- g_io_error_from_errno (errno),
- _("Unable to connect to POP server %s.\n"
- "Error sending password: %s"),
- url->host, errno ?
- g_strerror (errno) : _("Unknown error"));
- }
+ g_prefix_error (
+ error,
+ _("Unable to connect to POP server %s.\n"
+ "Error sending password: "), url->host);
} else if (pcu && pcu->state != CAMEL_POP3_COMMAND_OK) {
gchar *tmp;
@@ -663,7 +652,7 @@ pop3_store_disconnect_sync (CamelService *service,
CamelPOP3Command *pc;
pc = camel_pop3_engine_command_new(store->engine, 0, NULL, NULL, cancellable, error, "QUIT\r\n");
- while (camel_pop3_engine_iterate (store->engine, NULL) > 0)
+ while (camel_pop3_engine_iterate (store->engine, NULL, NULL, NULL) > 0)
;
camel_pop3_engine_command_free (store->engine, pc);
}
@@ -813,7 +802,7 @@ camel_pop3_store_expunge (CamelPOP3Store *store,
pc = camel_pop3_engine_command_new (
store->engine, 0, NULL, NULL, NULL, error, "QUIT\r\n");
- while (camel_pop3_engine_iterate (store->engine, NULL) > 0)
+ while (camel_pop3_engine_iterate (store->engine, NULL, NULL, NULL) > 0)
;
camel_pop3_engine_command_free (store->engine, pc);
diff --git a/camel/providers/pop3/camel-pop3-stream.c b/camel/providers/pop3/camel-pop3-stream.c
index 979beb6..a68b26c 100644
--- a/camel/providers/pop3/camel-pop3-stream.c
+++ b/camel/providers/pop3/camel-pop3-stream.c
@@ -27,7 +27,6 @@
#include <config.h>
#endif
-#include <errno.h>
#include <stdio.h>
#include <string.h>
@@ -281,7 +280,11 @@ camel_pop3_stream_new (CamelStream *source)
/* Get one line from the pop3 stream */
gint
-camel_pop3_stream_line (CamelPOP3Stream *is, guchar **data, guint *len)
+camel_pop3_stream_line (CamelPOP3Stream *is,
+ guchar **data,
+ guint *len,
+ GCancellable *cancellable,
+ GError **error)
{
register guchar c, *p, *o, *oe;
gint newlen, oldlen;
@@ -303,7 +306,7 @@ camel_pop3_stream_line (CamelPOP3Stream *is, guchar **data, guint *len)
/* need at least 3 chars in buffer */
while (e-p < 3) {
is->ptr = p;
- if (stream_fill (is, NULL, NULL) == -1)
+ if (stream_fill (is, cancellable, error) == -1)
return -1;
p = is->ptr;
e = is->end;
@@ -364,41 +367,20 @@ camel_pop3_stream_line (CamelPOP3Stream *is, guchar **data, guint *len)
return -1;
}
-/* returns -1 on error, 0 if last lot of data, >0 if more remaining */
-gint camel_pop3_stream_gets (CamelPOP3Stream *is, guchar **start, guint *len)
-{
- gint max;
- guchar *end;
-
- *len = 0;
-
- max = is->end - is->ptr;
- if (max == 0) {
- max = stream_fill (is, NULL, NULL);
- if (max <= 0)
- return max;
- }
-
- *start = is->ptr;
- end = memchr (is->ptr, '\n', max);
- if (end)
- max = (end - is->ptr) + 1;
- *start = is->ptr;
- *len = max;
- is->ptr += max;
-
- dd (printf ("POP3_STREAM_GETS (%s,%d): '%.*s'\n", end==NULL?"more":"last", *len, (gint)*len, *start));
-
- return end == NULL?1:0;
-}
-
-void camel_pop3_stream_set_mode (CamelPOP3Stream *is, camel_pop3_stream_mode_t mode)
+void
+camel_pop3_stream_set_mode (CamelPOP3Stream *is,
+ camel_pop3_stream_mode_t mode)
{
is->mode = mode;
}
/* returns -1 on erorr, 0 if last data, >0 if more data left */
-gint camel_pop3_stream_getd (CamelPOP3Stream *is, guchar **start, guint *len)
+gint
+camel_pop3_stream_getd (CamelPOP3Stream *is,
+ guchar **start,
+ guint *len,
+ GCancellable *cancellable,
+ GError **error)
{
guchar *p, *e, *s;
gint state;
@@ -419,7 +401,7 @@ gint camel_pop3_stream_getd (CamelPOP3Stream *is, guchar **start, guint *len)
while (e - p < 3) {
is->ptr = p;
- if (stream_fill (is, NULL, NULL) == -1)
+ if (stream_fill (is, cancellable, error) == -1)
return -1;
p = is->ptr;
e = is->end;
diff --git a/camel/providers/pop3/camel-pop3-stream.h b/camel/providers/pop3/camel-pop3-stream.h
index 8aaa085..74bf7a0 100644
--- a/camel/providers/pop3/camel-pop3-stream.h
+++ b/camel/providers/pop3/camel-pop3-stream.h
@@ -73,14 +73,19 @@ struct _CamelPOP3StreamClass {
};
GType camel_pop3_stream_get_type (void);
-
-CamelStream *camel_pop3_stream_new (CamelStream *source);
-
-void camel_pop3_stream_set_mode (CamelPOP3Stream *is, camel_pop3_stream_mode_t mode);
-
-gint camel_pop3_stream_line (CamelPOP3Stream *is, guchar **data, guint *len);
-gint camel_pop3_stream_gets (CamelPOP3Stream *is, guchar **start, guint *len);
-gint camel_pop3_stream_getd (CamelPOP3Stream *is, guchar **start, guint *len);
+CamelStream * camel_pop3_stream_new (CamelStream *source);
+void camel_pop3_stream_set_mode (CamelPOP3Stream *is,
+ camel_pop3_stream_mode_t mode);
+gint camel_pop3_stream_line (CamelPOP3Stream *is,
+ guchar **data,
+ guint *len,
+ GCancellable *cancellable,
+ GError **error);
+gint camel_pop3_stream_getd (CamelPOP3Stream *is,
+ guchar **start,
+ guint *len,
+ GCancellable *cancellable,
+ GError **error);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]