aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorbertrand <bertrand@helixcode.com>2000-02-29 22:12:59 +0800
committerBertrand Guiheneuf <bertrand@src.gnome.org>2000-02-29 22:12:59 +0800
commit39cbe68b8aba4a2839f10a4473f18954e591a5bf (patch)
treed36bc2ee1e78852871085c6381c582500d129e1e /camel
parent57bf3cc473c15d3f630aa8fde4ea52e083c5bdc6 (diff)
downloadgsoc2013-evolution-39cbe68b8aba4a2839f10a4473f18954e591a5bf.tar
gsoc2013-evolution-39cbe68b8aba4a2839f10a4473f18954e591a5bf.tar.gz
gsoc2013-evolution-39cbe68b8aba4a2839f10a4473f18954e591a5bf.tar.bz2
gsoc2013-evolution-39cbe68b8aba4a2839f10a4473f18954e591a5bf.tar.lz
gsoc2013-evolution-39cbe68b8aba4a2839f10a4473f18954e591a5bf.tar.xz
gsoc2013-evolution-39cbe68b8aba4a2839f10a4473f18954e591a5bf.tar.zst
gsoc2013-evolution-39cbe68b8aba4a2839f10a4473f18954e591a5bf.zip
new utility function.
2000-02-29 bertrand <bertrand@helixcode.com> * camel-stream-b64.c (camel_stream_b64_write_to_stream): new utility function. * camel-data-wrapper.c (_write_to_stream): default implementation. svn path=/trunk/; revision=1989
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog6
-rw-r--r--camel/camel-data-wrapper.c98
-rw-r--r--camel/camel-mime-part.c9
-rw-r--r--camel/camel-stream-b64.c20
-rw-r--r--camel/camel-stream-b64.h5
5 files changed, 91 insertions, 47 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index e8657d6d3b..d41d94a239 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,5 +1,11 @@
2000-02-29 bertrand <bertrand@helixcode.com>
+ * camel-stream-b64.c (camel_stream_b64_write_to_stream): new
+ utility function.
+
+ * camel-data-wrapper.c (_write_to_stream): default
+ implementation.
+
* gmime-utils.c (_store_header_pair_from_string):
revert strange changes.
diff --git a/camel/camel-data-wrapper.c b/camel/camel-data-wrapper.c
index fdc9aac45b..8fc258ac24 100644
--- a/camel/camel-data-wrapper.c
+++ b/camel/camel-data-wrapper.c
@@ -36,19 +36,19 @@ static GtkObjectClass *parent_class=NULL;
#define CDW_CLASS(so) CAMEL_DATA_WRAPPER_CLASS (GTK_OBJECT(so)->klass)
-static void _set_input_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
-static CamelStream *_get_input_stream (CamelDataWrapper *data_wrapper);
-static void _set_output_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
-static CamelStream *_get_output_stream (CamelDataWrapper *data_wrapper);
-
-static void _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
-static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
-static void _set_mime_type (CamelDataWrapper *data_wrapper, const gchar *mime_type);
-static gchar *_get_mime_type (CamelDataWrapper *data_wrapper);
-static GMimeContentField *_get_mime_type_field (CamelDataWrapper *data_wrapper);
-static void _set_mime_type_field (CamelDataWrapper *data_wrapper, GMimeContentField *mime_type);
-static CamelStream *_get_stream (CamelDataWrapper *data_wrapper);
-static void _finalize (GtkObject *object);
+static void my_set_input_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
+static CamelStream *my_get_input_stream (CamelDataWrapper *data_wrapper);
+static void my_set_output_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
+static CamelStream *my_get_output_stream (CamelDataWrapper *data_wrapper);
+
+static void my_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
+static void my_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
+static void my_set_mime_type (CamelDataWrapper *data_wrapper, const gchar *mime_type);
+static gchar *my_get_mime_type (CamelDataWrapper *data_wrapper);
+static GMimeContentField *my_get_mime_type_field (CamelDataWrapper *data_wrapper);
+static void my_set_mime_type_field (CamelDataWrapper *data_wrapper, GMimeContentField *mime_type);
+static CamelStream *my_get_stream (CamelDataWrapper *data_wrapper);
+static void my_finalize (GtkObject *object);
static void
camel_data_wrapper_class_init (CamelDataWrapperClass *camel_data_wrapper_class)
@@ -58,21 +58,21 @@ camel_data_wrapper_class_init (CamelDataWrapperClass *camel_data_wrapper_class)
parent_class = gtk_type_class (gtk_object_get_type ());
/* virtual method definition */
- camel_data_wrapper_class->write_to_stream = _write_to_stream;
- camel_data_wrapper_class->construct_from_stream = _construct_from_stream;
- camel_data_wrapper_class->set_mime_type = _set_mime_type;
- camel_data_wrapper_class->get_mime_type = _get_mime_type;
- camel_data_wrapper_class->get_mime_type_field = _get_mime_type_field;
- camel_data_wrapper_class->set_mime_type_field = _set_mime_type_field;
- camel_data_wrapper_class->get_stream = _get_stream;
-
- camel_data_wrapper_class->set_input_stream = _set_input_stream;
- camel_data_wrapper_class->get_input_stream = _get_input_stream;
- camel_data_wrapper_class->set_output_stream = _set_output_stream;
- camel_data_wrapper_class->get_output_stream = _get_output_stream;
+ camel_data_wrapper_class->write_to_stream = my_write_to_stream;
+ camel_data_wrapper_class->construct_from_stream = my_construct_from_stream;
+ camel_data_wrapper_class->set_mime_type = my_set_mime_type;
+ camel_data_wrapper_class->get_mime_type = my_get_mime_type;
+ camel_data_wrapper_class->get_mime_type_field = my_get_mime_type_field;
+ camel_data_wrapper_class->set_mime_type_field = my_set_mime_type_field;
+ camel_data_wrapper_class->get_stream = my_get_stream;
+
+ camel_data_wrapper_class->set_input_stream = my_set_input_stream;
+ camel_data_wrapper_class->get_input_stream = my_get_input_stream;
+ camel_data_wrapper_class->set_output_stream = my_set_output_stream;
+ camel_data_wrapper_class->get_output_stream = my_get_output_stream;
/* virtual method overload */
- gtk_object_class->finalize = _finalize;
+ gtk_object_class->finalize = my_finalize;
}
@@ -117,7 +117,7 @@ camel_data_wrapper_get_type (void)
static void
-_finalize (GtkObject *object)
+my_finalize (GtkObject *object)
{
CamelDataWrapper *camel_data_wrapper = CAMEL_DATA_WRAPPER (object);
@@ -142,7 +142,7 @@ _finalize (GtkObject *object)
static void
-_set_input_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
+my_set_input_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
g_assert (data_wrapper);
data_wrapper->input_stream = stream;
@@ -163,7 +163,7 @@ camel_data_wrapper_set_input_stream (CamelDataWrapper *data_wrapper, CamelStream
static CamelStream *
-_get_input_stream (CamelDataWrapper *data_wrapper)
+my_get_input_stream (CamelDataWrapper *data_wrapper)
{
g_assert (data_wrapper);
return (data_wrapper->input_stream);
@@ -180,7 +180,7 @@ camel_data_wrapper_get_input_stream (CamelDataWrapper *data_wrapper)
static void
-_set_output_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
+my_set_output_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
g_assert (data_wrapper);
data_wrapper->output_stream = stream;
@@ -199,7 +199,7 @@ camel_data_wrapper_set_output_stream (CamelDataWrapper *data_wrapper, CamelStrea
static CamelStream *
-_get_output_stream (CamelDataWrapper *data_wrapper)
+my_get_output_stream (CamelDataWrapper *data_wrapper)
{
g_assert (data_wrapper);
return (data_wrapper->output_stream);
@@ -217,7 +217,7 @@ camel_data_wrapper_get_output_stream (CamelDataWrapper *data_wrapper)
/**
- * _write_to_stream: write data content in a byte stream
+ * my_write_to_stream: write data content in a byte stream
* @data_wrapper: the data wrapper object
* @stream byte stream where data will be written
*
@@ -232,9 +232,27 @@ camel_data_wrapper_get_output_stream (CamelDataWrapper *data_wrapper)
*
**/
static void
-_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
+my_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
- /* nothing */
+ gchar tmp_buf[4096];
+ gint nb_read;
+ CamelStream *output_stream;
+
+ /*
+ * default implementation that uses the input
+ * stream and stream it in a blocking way.
+ */
+ g_assert (data_wrapper);
+ g_assert (stream);
+
+ output_stream = camel_data_wrapper_get_output_stream (data_wrapper);
+
+ while (!camel_stream_eos (output_stream)) {
+ nb_read = camel_stream_read (output_stream, tmp_buf, 4096);
+ if (nb_read)
+ camel_stream_write (stream, tmp_buf, nb_read);
+ }
+
}
@@ -261,7 +279,7 @@ camel_data_wrapper_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream
static void
-_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
+my_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
/* nothing */
}
@@ -277,7 +295,7 @@ camel_data_wrapper_construct_from_stream (CamelDataWrapper *data_wrapper, CamelS
static void
-_set_mime_type (CamelDataWrapper *data_wrapper, const gchar *mime_type)
+my_set_mime_type (CamelDataWrapper *data_wrapper, const gchar *mime_type)
{
CAMEL_LOG_FULL_DEBUG ( "CamelDataWrapper::set_mime_type Entering\n");
g_assert (mime_type);
@@ -292,7 +310,7 @@ camel_data_wrapper_set_mime_type (CamelDataWrapper *data_wrapper, const gchar *m
}
static gchar *
-_get_mime_type (CamelDataWrapper *data_wrapper)
+my_get_mime_type (CamelDataWrapper *data_wrapper)
{
gchar *mime_type;
@@ -309,7 +327,7 @@ camel_data_wrapper_get_mime_type (CamelDataWrapper *data_wrapper)
static GMimeContentField *
-_get_mime_type_field (CamelDataWrapper *data_wrapper)
+my_get_mime_type_field (CamelDataWrapper *data_wrapper)
{
return data_wrapper->mime_type;
}
@@ -322,7 +340,7 @@ camel_data_wrapper_get_mime_type_field (CamelDataWrapper *data_wrapper)
static void
-_set_mime_type_field (CamelDataWrapper *data_wrapper, GMimeContentField *mime_type)
+my_set_mime_type_field (CamelDataWrapper *data_wrapper, GMimeContentField *mime_type)
{
if (data_wrapper->mime_type) gmime_content_field_free (data_wrapper->mime_type);
data_wrapper->mime_type = mime_type;
@@ -335,7 +353,7 @@ camel_data_wrapper_set_mime_type_field (CamelDataWrapper *data_wrapper, GMimeCon
}
static CamelStream *
-_get_stream (CamelDataWrapper *data_wrapper)
+my_get_stream (CamelDataWrapper *data_wrapper)
{
/* This needs to be implemented in subclasses. */
return NULL;
diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c
index f9fb82cdc3..b6e5b55c36 100644
--- a/camel/camel-mime-part.c
+++ b/camel/camel-mime-part.c
@@ -675,13 +675,8 @@ _write_content_to_stream (CamelMimePart *mime_part, CamelStream *stream)
camel_data_wrapper_write_to_stream (content, stream);
break;
case CAMEL_MIME_PART_ENCODING_BASE64:
- wrapper_stream = camel_data_wrapper_get_stream (content);
- if (wrapper_stream == NULL) {
- /* FIXME in this case, we should probably copy stuff
- in-memory and make sure things work anyway. */
- g_warning ("Class `%s' does not implement `get_stream'",
- gtk_type_name (GTK_OBJECT (content)->klass->type));
- }
+ wrapper_stream = camel_data_wrapper_get_output_stream (content);
+
gmime_encode_base64_to_stream (wrapper_stream, stream);
break;
default:
diff --git a/camel/camel-stream-b64.c b/camel/camel-stream-b64.c
index 53c708fd14..29c89ba92b 100644
--- a/camel/camel-stream-b64.c
+++ b/camel/camel-stream-b64.c
@@ -551,4 +551,24 @@ my_reset (CamelStream *stream)
+void
+camel_stream_b64_write_to_stream (CamelStream *stream,
+ CamelStream *output_stream)
+{
+ gchar tmp_buf[4096];
+ gint nb_read;
+ /*
+ * default implementation that uses the input
+ * stream and stream it in a blocking way.
+ */
+ g_assert (output_stream);
+ g_assert (stream);
+
+ while (!camel_stream_eos (output_stream)) {
+ nb_read = camel_stream_read (stream, tmp_buf, 4096);
+ if (nb_read)
+ camel_stream_write (output_stream, tmp_buf, nb_read);
+ }
+
+}
diff --git a/camel/camel-stream-b64.h b/camel/camel-stream-b64.h
index 23ad7d39b2..2d2932951d 100644
--- a/camel/camel-stream-b64.h
+++ b/camel/camel-stream-b64.h
@@ -116,6 +116,11 @@ CamelStream * camel_stream_b64_new_with_input_stream (CamelStream *
void camel_stream_b64_set_mode (CamelStreamB64 *stream_b64,
CamelStreamB64Mode mode);
+/* utility function that writes the whole de/en-coded
+ stream to an output stream */
+void camel_stream_b64_write_to_stream (CamelStream *stream,
+ CamelStream *output_stream);
+
#ifdef __cplusplus
}