aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--camel/ChangeLog8
-rw-r--r--camel/camel-data-wrapper.c412
-rw-r--r--camel/camel-data-wrapper.h38
-rw-r--r--camel/camel-medium.c260
-rw-r--r--camel/camel-medium.h45
-rw-r--r--camel/camel-simple-data-wrapper.c164
-rw-r--r--camel/camel-simple-data-wrapper.h9
7 files changed, 488 insertions, 448 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index f8f5f0a594..1f92b1f4d7 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,11 @@
+2000-04-18 Dan Winship <danw@helixcode.com>
+
+ * camel-data-wrapper.[ch]:
+ * camel-simple-data-wrapper.[ch]:
+ * camel-medium.[ch]: Clean, polish, document. Most of the gtk-doc
+ comments added to camel-data-wrapper.c note serious problems that
+ need to be fixed.
+
2000-04-17 Dan Winship <danw@helixcode.com>
* camel-mime-message.[ch]: Remove the "session" field from
diff --git a/camel/camel-data-wrapper.c b/camel/camel-data-wrapper.c
index 1cf79a70e4..6b3f26e023 100644
--- a/camel/camel-data-wrapper.c
+++ b/camel/camel-data-wrapper.c
@@ -1,18 +1,18 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camelDataWrapper.c : Abstract class for a data_wrapper */
+/* camel-data-wrapper.c : Abstract class for a data_wrapper */
/** THIS IS MOSTLY AN ABSTRACT CLASS THAT SHOULD HAVE BEEN AN
INTERFACE. **/
-/*
+/*
*
- * Author :
+ * Author :
* Bertrand Guiheneuf <bertrand@helixcode.com>
*
* Copyright 1999, 2000 Helix Code, Inc. (http://www.helixcode.com)
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
@@ -28,65 +28,63 @@
*/
#include <config.h>
#include "camel-data-wrapper.h"
-#include "camel-log.h"
-static GtkObjectClass *parent_class=NULL;
+static GtkObjectClass *parent_class = NULL;
/* Returns the class for a CamelDataWrapper */
-#define CDW_CLASS(so) CAMEL_DATA_WRAPPER_CLASS (GTK_OBJECT(so)->klass)
-
-
-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);
+#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 void finalize (GtkObject *object);
static void
camel_data_wrapper_class_init (CamelDataWrapperClass *camel_data_wrapper_class)
{
- GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (camel_data_wrapper_class);
+ GtkObjectClass *gtk_object_class =
+ GTK_OBJECT_CLASS (camel_data_wrapper_class);
parent_class = gtk_type_class (gtk_object_get_type ());
-
+
/* virtual method definition */
- 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;
+ 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->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;
/* virtual method overload */
- gtk_object_class->finalize = my_finalize;
+ gtk_object_class->finalize = finalize;
}
-
-
-
-
static void
-camel_data_wrapper_init (gpointer object, gpointer klass)
+camel_data_wrapper_init (gpointer object, gpointer klass)
{
CamelDataWrapper *camel_data_wrapper = CAMEL_DATA_WRAPPER (object);
- CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_init:: Entering\n");
camel_data_wrapper->mime_type = gmime_content_field_new (NULL, NULL);
- CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_init:: Leaving\n");
}
@@ -95,9 +93,9 @@ GtkType
camel_data_wrapper_get_type (void)
{
static GtkType camel_data_wrapper_type = 0;
-
- if (!camel_data_wrapper_type) {
- GtkTypeInfo camel_data_wrapper_info =
+
+ if (!camel_data_wrapper_type) {
+ GtkTypeInfo camel_data_wrapper_info =
{
"CamelDataWrapper",
sizeof (CamelDataWrapper),
@@ -108,21 +106,19 @@ camel_data_wrapper_get_type (void)
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
-
+
camel_data_wrapper_type = gtk_type_unique (gtk_object_get_type (), &camel_data_wrapper_info);
}
-
+
return camel_data_wrapper_type;
}
-static void
-my_finalize (GtkObject *object)
+static void
+finalize (GtkObject *object)
{
CamelDataWrapper *camel_data_wrapper = CAMEL_DATA_WRAPPER (object);
- CAMEL_LOG_FULL_DEBUG ("Entering CamelDataWrapper::finalize\n");
- CAMEL_LOG_FULL_DEBUG ("CamelDataWrapper::finalize, finalizing object %p\n", object);
if (camel_data_wrapper->mime_type)
gmime_content_field_unref (camel_data_wrapper->mime_type);
@@ -133,65 +129,74 @@ my_finalize (GtkObject *object)
gtk_object_unref (GTK_OBJECT (camel_data_wrapper->output_stream));
parent_class->finalize (object);
- CAMEL_LOG_FULL_DEBUG ("Leaving CamelDataWrapper::finalize\n");
}
-
-
-
-
-static void
-my_set_input_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
+static void
+set_input_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
- g_assert (data_wrapper);
-
if (data_wrapper->input_stream)
gtk_object_unref (GTK_OBJECT (data_wrapper->input_stream));
data_wrapper->input_stream = stream;
if (!data_wrapper->output_stream && stream)
- my_set_output_stream (data_wrapper, stream);
-
+ set_output_stream (data_wrapper, stream);
+
if (stream)
gtk_object_ref (GTK_OBJECT (stream));
}
-
-void
-camel_data_wrapper_set_input_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
+/**
+ * camel_data_wrapper_set_input_stream:
+ * @data_wrapper: a data wrapper
+ * @stream: a stream that can be read from, or %NULL
+ *
+ * This sets the data wrapper's input stream from @stream, most likely
+ * causing @data_wrapper to initialize itself from that stream.
+ * @data_wrapper may or may not notice future changes to @stream, and
+ * if @stream is closed before @data_wrapper is destroyed, it could
+ * be arbitrarily bad. This function may fail, but there is no way
+ * for the caller to know this.
+ *
+ * If @data_wrapper has no output stream, its output stream will also
+ * be set to @stream.
+ **/
+void
+camel_data_wrapper_set_input_stream (CamelDataWrapper *data_wrapper,
+ CamelStream *stream)
{
- g_assert (data_wrapper);
- CDW_CLASS(data_wrapper)->set_input_stream (data_wrapper, stream);
-}
-
-
+ g_return_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper));
+ g_return_if_fail (stream == NULL || CAMEL_IS_STREAM (stream));
+ CDW_CLASS (data_wrapper)->set_input_stream (data_wrapper, stream);
+}
-static CamelStream *
-my_get_input_stream (CamelDataWrapper *data_wrapper)
+static CamelStream *
+get_input_stream (CamelDataWrapper *data_wrapper)
{
- g_assert (data_wrapper);
- return (data_wrapper->input_stream);
+ return data_wrapper->input_stream;
}
-CamelStream *
+/**
+ * camel_data_wrapper_get_input_stream:
+ * @data_wrapper: a data wrapper
+ *
+ * Return value: @data_wrapper's input stream
+ **/
+CamelStream *
camel_data_wrapper_get_input_stream (CamelDataWrapper *data_wrapper)
{
- g_assert (data_wrapper);
- return CDW_CLASS(data_wrapper)->get_input_stream (data_wrapper);
-}
-
+ g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper), NULL);
+ return CDW_CLASS (data_wrapper)->get_input_stream (data_wrapper);
+}
-static void
-my_set_output_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
+static void
+set_output_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
- g_assert (data_wrapper);
-
if (data_wrapper->output_stream)
gtk_object_unref (GTK_OBJECT (data_wrapper->output_stream));
@@ -200,67 +205,61 @@ my_set_output_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
gtk_object_ref (GTK_OBJECT (stream));
}
-void
-camel_data_wrapper_set_output_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
+/**
+ * camel_data_wrapper_set_output_stream:
+ * @data_wrapper: a data wrapper
+ * @stream: a stream that can be read from
+ *
+ * This sets the data wrapper's output stream to @stream. Unlike
+ * camel_data_wrapper_set_input_stream(), this function has no side
+ * effects.
+ *
+ * The output stream should theoretically be a stream that, if read
+ * from, produces the data wrapper's contents. However, while certain
+ * pieces of code assume this, nothing enforces it.
+ **/
+void
+camel_data_wrapper_set_output_stream (CamelDataWrapper *data_wrapper,
+ CamelStream *stream)
{
- g_assert (data_wrapper);
- CDW_CLASS(data_wrapper)->set_output_stream (data_wrapper, stream);
-}
-
+ g_return_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper));
+ g_return_if_fail (CAMEL_IS_STREAM (stream));
+ CDW_CLASS (data_wrapper)->set_output_stream (data_wrapper, stream);
+}
-static CamelStream *
-my_get_output_stream (CamelDataWrapper *data_wrapper)
+static CamelStream *
+get_output_stream (CamelDataWrapper *data_wrapper)
{
- g_assert (data_wrapper);
- return (data_wrapper->output_stream);
+ return data_wrapper->output_stream;
}
-CamelStream *
+/**
+ * camel_data_wrapper_get_output_stream:
+ * @data_wrapper: a data wrapper
+ *
+ * Return value: @data_wrapper's output stream
+ **/
+CamelStream *
camel_data_wrapper_get_output_stream (CamelDataWrapper *data_wrapper)
{
- g_assert (data_wrapper);
- return CDW_CLASS(data_wrapper)->get_output_stream (data_wrapper);
-}
-
-
+ g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper), NULL);
+ return CDW_CLASS (data_wrapper)->get_output_stream (data_wrapper);
+}
-/**
- * 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
- *
- * This method must be overriden by subclasses
- * Data must be written in the bytes stream
- * in a architecture independant fashion.
- * If data is a standard data (for example an jpg image)
- * it must be serialized in the strea exactly as it
- * would be saved on disk. A simple dump of the stream in
- * a file should be sufficient for the data to be
- * re-read by a foreign application.
- *
- **/
static void
-my_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
+write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
gchar tmp_buf[4096];
gint nb_read;
gint nb_written;
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);
-
- if (!output_stream)
+ if (!output_stream)
return;
camel_stream_reset (output_stream);
@@ -268,120 +267,159 @@ my_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
while (!camel_stream_eos (output_stream)) {
nb_read = camel_stream_read (output_stream, tmp_buf, 4096);
nb_written = 0;
- while (nb_written < nb_read)
+ while (nb_written < nb_read)
nb_written += camel_stream_write (stream, tmp_buf + nb_written, nb_read - nb_written);
}
-
- CAMEL_LOG_FULL_DEBUG ("CamelDataWrapper::write_to_stream, nmumber of bytes written : %d\n", nb_written);
-
}
/**
- * camel_data_wrapper_write_to_stream: write data in a stream
- * @data_wrapper: the data wrapper object
- * @stream: byte stream where data will be written
+ * camel_data_wrapper_write_to_stream:
+ * @data_wrapper: a data wrapper
+ * @stream: stream for data to be written to
*
- * Write data content in a stream. Data is stored in a machine
- * independant format.
- *
+ * Writes the data content to @stream in a machine-independent format
+ * appropriate for the data. It should be possible to construct an
+ * equivalent data wrapper object later by passing this stream to
+ * camel_data_construct_from_stream().
+ *
+ * Of course, this operation might fail, and of course, there's no
+ * way for you to find out about it.
**/
-void
-camel_data_wrapper_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
+void
+camel_data_wrapper_write_to_stream (CamelDataWrapper *data_wrapper,
+ CamelStream *stream)
{
- CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_write_to_stream:: Entering\n");
- CDW_CLASS(data_wrapper)->write_to_stream (data_wrapper, stream);
- CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_write_to_stream:: Leaving\n");
-}
-
-
-
+ g_return_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper));
+ g_return_if_fail (CAMEL_IS_STREAM (stream));
+ CDW_CLASS (data_wrapper)->write_to_stream (data_wrapper, stream);
+}
static void
-my_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
+construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
/* nothing */
}
-void
-camel_data_wrapper_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
+/**
+ * camel_data_wrapper_construct_from_stream:
+ * @data_wrapper: a data wrapper
+ * @stream: a stream that can be read from
+ *
+ * This constructs a data wrapper object from a stream. It is not clear
+ * how this differs from camel_data_wrapper_set_input_stream(), nor is
+ * it clear how it affects the data wrapper's input and output streams.
+ *
+ * This could fail, but you can't know if it did.
+ **/
+void
+camel_data_wrapper_construct_from_stream (CamelDataWrapper *data_wrapper,
+ CamelStream *stream)
{
- CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_construct_from_stream:: Entering\n");
- CDW_CLASS(data_wrapper)->construct_from_stream (data_wrapper, stream);
- CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_construct_from_stream:: Leaving\n");
-}
+ g_return_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper));
+ g_return_if_fail (CAMEL_IS_STREAM (stream));
+ CDW_CLASS (data_wrapper)->construct_from_stream (data_wrapper, stream);
+}
static void
-my_set_mime_type (CamelDataWrapper *data_wrapper, const gchar *mime_type)
+set_mime_type (CamelDataWrapper *data_wrapper, const gchar *mime_type)
{
- CAMEL_LOG_FULL_DEBUG ( "CamelDataWrapper::set_mime_type Entering\n");
- g_assert (mime_type);
- gmime_content_field_construct_from_string (data_wrapper->mime_type, mime_type);
- CAMEL_LOG_FULL_DEBUG ( "CamelDataWrapper::set_mime_type Leaving\n");
+ gmime_content_field_construct_from_string (data_wrapper->mime_type,
+ mime_type);
}
-void
-camel_data_wrapper_set_mime_type (CamelDataWrapper *data_wrapper, const gchar *mime_type)
+/**
+ * camel_data_wrapper_set_mime_type:
+ * @data_wrapper: a data wrapper
+ * @mime_type: the text representation of a MIME type
+ *
+ * This sets the data wrapper's MIME type.
+ * It might fail, but you won't know. It will allow you to set
+ * Content-Type parameters on the data wrapper, which are meaningless.
+ * You should not be allowed to change the MIME type of a data wrapper
+ * that contains data, or at least, if you do, it should invalidate the
+ * data.
+ **/
+void
+camel_data_wrapper_set_mime_type (CamelDataWrapper *data_wrapper,
+ const gchar *mime_type)
{
- CDW_CLASS(data_wrapper)->set_mime_type (data_wrapper, mime_type);
+ g_return_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper));
+ g_return_if_fail (mime_type != NULL);
+
+ CDW_CLASS (data_wrapper)->set_mime_type (data_wrapper, mime_type);
}
static gchar *
-my_get_mime_type (CamelDataWrapper *data_wrapper)
+get_mime_type (CamelDataWrapper *data_wrapper)
{
- gchar *mime_type;
-
- mime_type = gmime_content_field_get_mime_type (data_wrapper->mime_type);
- return mime_type;
+ return gmime_content_field_get_mime_type (data_wrapper->mime_type);
}
+/**
+ * camel_data_wrapper_get_mime_type:
+ * @data_wrapper: a data wrapper
+ *
+ * Return value: the text form of the data wrapper's MIME type
+ **/
gchar *
camel_data_wrapper_get_mime_type (CamelDataWrapper *data_wrapper)
{
- CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_get_mime_type:: Entering before returning\n");
- return CDW_CLASS(data_wrapper)->get_mime_type (data_wrapper);
+ g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper));
+
+ return CDW_CLASS (data_wrapper)->get_mime_type (data_wrapper);
}
static GMimeContentField *
-my_get_mime_type_field (CamelDataWrapper *data_wrapper)
+get_mime_type_field (CamelDataWrapper *data_wrapper)
{
return data_wrapper->mime_type;
}
+/**
+ * camel_data_wrapper_get_mime_type_field:
+ * @data_wrapper: a data wrapper
+ *
+ * Return value: the parsed form of the data wrapper's MIME type
+ **/
GMimeContentField *
camel_data_wrapper_get_mime_type_field (CamelDataWrapper *data_wrapper)
{
- return CDW_CLASS(data_wrapper)->get_mime_type_field (data_wrapper);
+ g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper));
+
+ return CDW_CLASS (data_wrapper)->get_mime_type_field (data_wrapper);
}
+/**
+ * camel_data_wrapper_set_mime_type_field:
+ * @data_wrapper: a data wrapper
+ * @mime_type: the parsed representation of a MIME type
+ *
+ * This sets the data wrapper's MIME type. It suffers from the same
+ * flaws as camel_data_wrapper_set_mime_type.
+ **/
static void
-my_set_mime_type_field (CamelDataWrapper *data_wrapper, GMimeContentField *mime_type)
+set_mime_type_field (CamelDataWrapper *data_wrapper,
+ GMimeContentField *mime_type)
{
- if (data_wrapper->mime_type) gmime_content_field_unref (data_wrapper->mime_type);
+ g_return_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper));
+ g_return_if_fail (mime_type != NULL);
+
+ if (data_wrapper->mime_type)
+ gmime_content_field_unref (data_wrapper->mime_type);
data_wrapper->mime_type = mime_type;
}
void
-camel_data_wrapper_set_mime_type_field (CamelDataWrapper *data_wrapper, GMimeContentField *mime_type)
-{
- CDW_CLASS(data_wrapper)->set_mime_type_field (data_wrapper, mime_type);
-}
-
-static CamelStream *
-my_get_stream (CamelDataWrapper *data_wrapper)
-{
- /* This needs to be implemented in subclasses. */
- return NULL;
-}
-
-CamelStream *
-camel_data_wrapper_get_stream (CamelDataWrapper *data_wrapper)
+camel_data_wrapper_set_mime_type_field (CamelDataWrapper *data_wrapper,
+ GMimeContentField *mime_type)
{
- return CDW_CLASS(data_wrapper)->get_stream (data_wrapper);
+ CDW_CLASS (data_wrapper)->set_mime_type_field (data_wrapper,
+ mime_type);
}
diff --git a/camel/camel-data-wrapper.h b/camel/camel-data-wrapper.h
index 1fec594f62..0805bc47ce 100644
--- a/camel/camel-data-wrapper.h
+++ b/camel/camel-data-wrapper.h
@@ -1,15 +1,15 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* camelDataWrapper.h : Abstract class for a data wrapper */
-/*
+/*
*
- * Author :
+ * Author :
* Bertrand Guiheneuf <bertrand@helixcode.com>
*
* Copyright 1999, 2000 Helix Code, Inc. (http://www.helixcode.com)
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
@@ -60,28 +60,27 @@ struct _CamelDataWrapper
typedef struct {
GtkObjectClass parent_class;
-
- /* Virtual methods */
- void (*set_input_stream) (CamelDataWrapper *data_wrapper,
+
+ /* Virtual methods */
+ void (*set_input_stream) (CamelDataWrapper *data_wrapper,
CamelStream *stream);
CamelStream * (*get_input_stream) (CamelDataWrapper *data_wrapper);
- void (*set_output_stream) (CamelDataWrapper *data_wrapper,
+ void (*set_output_stream) (CamelDataWrapper *data_wrapper,
CamelStream *stream);
CamelStream * (*get_output_stream) (CamelDataWrapper *data_wrapper);
- void (*set_mime_type) (CamelDataWrapper *data_wrapper,
+ void (*set_mime_type) (CamelDataWrapper *data_wrapper,
const gchar * mime_type);
gchar * (*get_mime_type) (CamelDataWrapper *data_wrapper);
GMimeContentField * (*get_mime_type_field) (CamelDataWrapper *data_wrapper);
- void (*set_mime_type_field) (CamelDataWrapper *data_wrapper,
+ void (*set_mime_type_field) (CamelDataWrapper *data_wrapper,
GMimeContentField *mime_type_field);
/* deprecated method */
- CamelStream * (*get_stream) (CamelDataWrapper *data_wrapper);
- void (*write_to_stream) (CamelDataWrapper *data_wrapper,
+ void (*write_to_stream) (CamelDataWrapper *data_wrapper,
CamelStream *stream);
- void (*construct_from_stream) (CamelDataWrapper *data_wrapper,
+ void (*construct_from_stream) (CamelDataWrapper *data_wrapper,
CamelStream *stream);
} CamelDataWrapperClass;
@@ -94,27 +93,26 @@ GtkType camel_data_wrapper_get_type (void);
/* public methods */
-void camel_data_wrapper_write_to_stream (CamelDataWrapper *data_wrapper,
+void camel_data_wrapper_write_to_stream (CamelDataWrapper *data_wrapper,
CamelStream *stream);
-void camel_data_wrapper_set_mime_type (CamelDataWrapper *data_wrapper,
+void camel_data_wrapper_set_mime_type (CamelDataWrapper *data_wrapper,
const gchar *mime_type);
gchar * camel_data_wrapper_get_mime_type (CamelDataWrapper *data_wrapper);
GMimeContentField * camel_data_wrapper_get_mime_type_field (CamelDataWrapper *data_wrapper);
-void camel_data_wrapper_set_mime_type_field (CamelDataWrapper *data_wrapper,
+void camel_data_wrapper_set_mime_type_field (CamelDataWrapper *data_wrapper,
GMimeContentField *mime_type);
-void camel_data_wrapper_set_input_stream (CamelDataWrapper *data_wrapper,
+void camel_data_wrapper_set_input_stream (CamelDataWrapper *data_wrapper,
CamelStream *stream);
CamelStream * camel_data_wrapper_get_input_stream (CamelDataWrapper *data_wrapper);
-void camel_data_wrapper_set_output_stream (CamelDataWrapper *data_wrapper,
+void camel_data_wrapper_set_output_stream (CamelDataWrapper *data_wrapper,
CamelStream *stream);
CamelStream * camel_data_wrapper_get_output_stream (CamelDataWrapper *data_wrapper);
/* deprecated methods. Left until the new parser scheme is ok */
-CamelStream * camel_data_wrapper_get_stream (CamelDataWrapper *data_wrapper);
-void camel_data_wrapper_construct_from_stream (CamelDataWrapper *data_wrapper,
+void camel_data_wrapper_construct_from_stream (CamelDataWrapper *data_wrapper,
CamelStream *stream);
#ifdef __cplusplus
diff --git a/camel/camel-medium.c b/camel/camel-medium.c
index d87c601b51..25f6b097bd 100644
--- a/camel/camel-medium.c
+++ b/camel/camel-medium.c
@@ -1,16 +1,15 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* camelMedium.c : Abstract class for a medium */
-
-/*
+/*
*
- * Author :
+ * Author :
* Bertrand Guiheneuf <bertrand@helixcode.com>
*
* Copyright 1999, 2000 Helix Code, Inc. (http://www.helixcode.com)
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
@@ -29,70 +28,64 @@
#include <stdio.h>
#include "gmime-content-field.h"
#include "string-utils.h"
-#include "camel-log.h"
#include "gmime-utils.h"
#include "camel-simple-data-wrapper.h"
-
-
-
-static CamelDataWrapperClass *parent_class=NULL;
+static CamelDataWrapperClass *parent_class = NULL;
/* Returns the class for a CamelMedium */
-#define CM_CLASS(so) CAMEL_MEDIUM_CLASS (GTK_OBJECT(so)->klass)
+#define CM_CLASS(so) CAMEL_MEDIUM_CLASS (GTK_OBJECT (so)->klass)
-static void _add_header (CamelMedium *medium, gchar *header_name, gchar *header_value);
-static void _remove_header (CamelMedium *medium, const gchar *header_name);
-static const gchar *_get_header (CamelMedium *medium, const gchar *header_name);
+static void add_header (CamelMedium *medium, gchar *header_name,
+ gchar *header_value);
+static void remove_header (CamelMedium *medium, const gchar *header_name);
+static const gchar *get_header (CamelMedium *medium, const gchar *header_name);
-static CamelDataWrapper *_get_content_object(CamelMedium *medium);
-static void _set_content_object(CamelMedium *medium, CamelDataWrapper *content);
+static CamelDataWrapper *get_content_object (CamelMedium *medium);
+static void set_content_object (CamelMedium *medium,
+ CamelDataWrapper *content);
-static void _finalize (GtkObject *object);
+static void finalize (GtkObject *object);
static void
camel_medium_class_init (CamelMediumClass *camel_medium_class)
{
- CamelDataWrapperClass *camel_data_wrapper_class = CAMEL_DATA_WRAPPER_CLASS (camel_medium_class);
- GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (camel_data_wrapper_class);
+ CamelDataWrapperClass *camel_data_wrapper_class =
+ CAMEL_DATA_WRAPPER_CLASS (camel_medium_class);
+ GtkObjectClass *gtk_object_class =
+ GTK_OBJECT_CLASS (camel_data_wrapper_class);
parent_class = gtk_type_class (camel_data_wrapper_get_type ());
-
+
/* virtual method definition */
- camel_medium_class->add_header = _add_header;
- camel_medium_class->remove_header = _remove_header;
- camel_medium_class->get_header = _get_header;
-
- camel_medium_class->set_content_object = _set_content_object;
- camel_medium_class->get_content_object = _get_content_object;
-
- /* virtual method overload */
- /* camel_data_wrapper_class->write_to_stream = _write_to_stream; */
- /* camel_data_wrapper_class->construct_from_stream = _construct_from_stream; */
-
- gtk_object_class->finalize = _finalize;
+ camel_medium_class->add_header = add_header;
+ camel_medium_class->remove_header = remove_header;
+ camel_medium_class->get_header = get_header;
+
+ camel_medium_class->set_content_object = set_content_object;
+ camel_medium_class->get_content_object = get_content_object;
+
+ gtk_object_class->finalize = finalize;
}
static void
-camel_medium_init (gpointer object, gpointer klass)
+camel_medium_init (gpointer object, gpointer klass)
{
CamelMedium *camel_medium = CAMEL_MEDIUM (object);
-
- camel_medium->headers = g_hash_table_new (g_str_hash, g_str_equal);
- camel_medium->content = NULL;
-}
-
+ camel_medium->headers = g_hash_table_new (g_str_hash, g_str_equal);
+ camel_medium->content = NULL;
+}
GtkType
camel_medium_get_type (void)
{
static GtkType camel_medium_type = 0;
-
- if (!camel_medium_type) {
- GtkTypeInfo camel_medium_info =
+
+ if (!camel_medium_type) {
+ GtkTypeInfo camel_medium_info =
{
"CamelMedium",
sizeof (CamelMedium),
@@ -103,31 +96,28 @@ camel_medium_get_type (void)
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
-
+
camel_medium_type = gtk_type_unique (camel_data_wrapper_get_type (), &camel_medium_info);
}
-
+
return camel_medium_type;
}
static void
-_free_header (gpointer key, gpointer value, gpointer data)
+free_header (gpointer key, gpointer value, gpointer data)
{
g_free (key);
g_free (value);
}
-static void
-_finalize (GtkObject *object)
+static void
+finalize (GtkObject *object)
{
CamelMedium *medium = CAMEL_MEDIUM (object);
-
- CAMEL_LOG_FULL_DEBUG ("Entering CamelMedium::finalize\n");
-
if (medium->headers) {
- g_hash_table_foreach (medium->headers, _free_header, NULL);
+ g_hash_table_foreach (medium->headers, free_header, NULL);
g_hash_table_destroy (medium->headers);
}
@@ -135,134 +125,164 @@ _finalize (GtkObject *object)
gtk_object_unref (GTK_OBJECT (medium->content));
GTK_OBJECT_CLASS (parent_class)->finalize (object);
- CAMEL_LOG_FULL_DEBUG ("Leaving CamelMedium::finalize\n");
}
-/* **** */
-
static void
-_add_header (CamelMedium *medium, gchar *header_name, gchar *header_value)
+add_header (CamelMedium *medium, gchar *header_name, gchar *header_value)
{
- gboolean header_exists;
- gchar *old_header_name;
- gchar *old_header_value;
-
-
- header_exists = g_hash_table_lookup_extended (medium->headers, header_name,
- (gpointer *) &old_header_name,
- (gpointer *) &old_header_value);
- /* ghashtables actually dont duplicate key pointers on existing fields,
- just remove the old one first always (avoiding this assumption) */
- if (header_exists) {
+ gpointer old_name;
+ gpointer old_value;
+
+ /* FIXME: This only allows each header to occur once. */
+ if (g_hash_table_lookup_extended (medium->headers, header_name,
+ &old_name, &old_value)) {
g_hash_table_remove (medium->headers, old_header_name);
-#if 1
- g_free (old_header_name);
- g_free (old_header_value);
-#endif
+ g_free (old_name);
+ g_free (old_value);
}
g_hash_table_insert (medium->headers, g_strdup (header_name),
g_strdup (header_value));
}
-
+/**
+ * camel_medium_add_header:
+ * @medium: a CamelMedium
+ * @header_name: name of the header
+ * @header_value: value of the header
+ *
+ * Adds a header to a medium.
+ *
+ * FIXME: Where does it add it? We need to be able to prepend and
+ * append headers, and also be able to insert them relative to other
+ * headers.
+ **/
void
-camel_medium_add_header (CamelMedium *medium, gchar *header_name, gchar *header_value)
+camel_medium_add_header (CamelMedium *medium, gchar *header_name,
+ gchar *header_value)
{
- CM_CLASS(medium)->add_header(medium, header_name, header_value);
-}
-
+ g_return_if_fail (CAMEL_IS_MEDIUM (medium));
+ g_return_if_fail (header_name != NULL);
+ g_return_if_fail (header_value != NULL);
-/* **** */
+ CM_CLASS (medium)->add_header (medium, header_name, header_value);
+}
static void
-_remove_header (CamelMedium *medium, const gchar *header_name)
+remove_header (CamelMedium *medium, const gchar *header_name)
{
-
- gboolean header_exists;
- gchar *old_header_name;
- gchar *old_header_value;
-
- header_exists = g_hash_table_lookup_extended (medium->headers, header_name,
- (gpointer *) &old_header_name,
- (gpointer *) &old_header_value);
- if (header_exists) {
- g_hash_table_remove (medium->headers, header_name);
+ gpointer old_name;
+ gpointer old_value;
- g_free (old_header_name);
- g_free (old_header_value);
+ /* FIXME: This only allows each header to occur once. */
+ if (g_hash_table_lookup_extended (medium->headers, header_name,
+ &old_name, &old_value)) {
+ g_hash_table_remove (medium->headers, header_name);
+ g_free (old_name);
+ g_free (old_value);
}
}
+/**
+ * camel_medium_remove_header:
+ * @medium: a medium
+ * @header_name: the name of the header
+ *
+ * Removes the named header from the medium.
+ *
+ * FIXME: If there are multiple occurrences of the header, which
+ * gets/get removed?
+ **/
void
camel_medium_remove_header (CamelMedium *medium, const gchar *header_name)
{
- CM_CLASS(medium)->remove_header(medium, header_name);
-}
-
+ g_return_if_fail (CAMEL_IS_MEDIUM (medium));
+ g_return_if_fail (header_name != NULL);
-/* **** */
+ CM_CLASS (medium)->remove_header (medium, header_name);
+}
static const gchar *
-_get_header (CamelMedium *medium, const gchar *header_name)
+get_header (CamelMedium *medium, const gchar *header_name)
{
-
gchar *header_value;
-
- header_value = (gchar *)g_hash_table_lookup (medium->headers, header_name);
+
+ header_value = (gchar *)g_hash_table_lookup (medium->headers,
+ header_name);
return header_value;
}
+/**
+ * camel_medium_get_header:
+ * @medium: a medium
+ * @header_name: the name of the header
+ *
+ * Returns the value of the named header in the medium, or %NULL if
+ * it is unset. The caller should not modify or free the data.
+ *
+ * FIXME: What if the header occurs more than once?
+ *
+ * Return value: the value of the named header, or %NULL
+ **/
const gchar *
camel_medium_get_header (CamelMedium *medium, const gchar *header_name)
{
- return CM_CLASS(medium)->get_header (medium, header_name);
-}
+ g_return_val_if_fail (CAMEL_IS_MEDIUM (medium), NULL);
+ g_return_val_if_fail (header_name != NULL, NULL);
-
-/* **** */
+ return CM_CLASS (medium)->get_header (medium, header_name);
+}
static CamelDataWrapper *
-_get_content_object (CamelMedium *medium)
+get_content_object (CamelMedium *medium)
{
return medium->content;
-
}
-
+/**
+ * camel_medium_get_content_object:
+ * @medium: a medium
+ *
+ * Returns a data wrapper that represents the content of the medium,
+ * without its headers.
+ *
+ * Return value: the medium's content object.
+ **/
CamelDataWrapper *
camel_medium_get_content_object (CamelMedium *medium)
{
- return CM_CLASS(medium)->get_content_object (medium);
-}
-
+ g_return_val_if_fail (CAMEL_IS_MEDIUM (medium), NULL);
-/* **** */
+ return CM_CLASS (medium)->get_content_object (medium);
+}
static void
-_set_content_object (CamelMedium *medium, CamelDataWrapper *content)
+set_content_object (CamelMedium *medium, CamelDataWrapper *content)
{
-
- CAMEL_LOG_FULL_DEBUG ("Entering CamelMedium::set_content_object\n");
- if (medium->content) {
- CAMEL_LOG_FULL_DEBUG ("CamelMedium::set_content_object unreferencing old content object\n");
+ if (medium->content)
gtk_object_unref (GTK_OBJECT (medium->content));
- }
gtk_object_ref (GTK_OBJECT (content));
medium->content = content;
-
}
-void
-camel_medium_set_content_object (CamelMedium *medium, CamelDataWrapper *content)
+/**
+ * camel_medium_set_content_object:
+ * @medium: a medium
+ * @content: a data wrapper representing the medium's content
+ *
+ * Sets the content of @medium to be @content.
+ **/
+void
+camel_medium_set_content_object (CamelMedium *medium,
+ CamelDataWrapper *content)
{
- CM_CLASS(medium)->set_content_object (medium, content);
-}
-
+ g_return_if_fail (CAMEL_IS_MEDIUM (medium));
+ g_return_if_fail (CAMEL_IS_DATA_WRAPPER (content));
-/* **** */
+ CM_CLASS (medium)->set_content_object (medium, content);
+}
diff --git a/camel/camel-medium.h b/camel/camel-medium.h
index ce3bb9983b..0e34f1c2a7 100644
--- a/camel/camel-medium.h
+++ b/camel/camel-medium.h
@@ -1,15 +1,15 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* camel-medium.h : class for a medium object */
-/*
+/*
*
- * Author :
+ * Author :
* Bertrand Guiheneuf <bertrand@helixcode.com>
*
* Copyright 1999, 2000 Helix Code, Inc. (http://www.helixcode.com)
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
@@ -47,25 +47,32 @@ extern "C" {
struct _CamelMedium
{
CamelDataWrapper parent_object;
-
+
GHashTable *headers;
-
- CamelDataWrapper *content; /* part real content */
-
+
+ /* The content of the medium, as opposed to our parent
+ * CamelDataWrapper, which wraps both the headers and the
+ * content.
+ */
+ CamelDataWrapper *content;
+
};
typedef struct {
CamelDataWrapperClass parent_class;
-
- /* Virtual methods */
- void (*add_header) (CamelMedium *medium, gchar *header_name, gchar *header_value);
+
+ /* Virtual methods */
+ void (*add_header) (CamelMedium *medium, gchar *header_name,
+ gchar *header_value);
void (*remove_header) (CamelMedium *medium, const gchar *header_name);
- const gchar * (*get_header) (CamelMedium *medium, const gchar *header_name);
+ const gchar * (*get_header) (CamelMedium *medium,
+ const gchar *header_name);
CamelDataWrapper * (*get_content_object) (CamelMedium *medium);
- void (*set_content_object) (CamelMedium *medium, CamelDataWrapper *content);
+ void (*set_content_object) (CamelMedium *medium,
+ CamelDataWrapper *content);
} CamelMediumClass;
@@ -76,13 +83,17 @@ GtkType camel_medium_get_type (void);
/* public methods */
-void camel_medium_add_header (CamelMedium *medium, gchar *header_name, gchar *header_value);
-void camel_medium_remove_header (CamelMedium *medium, const gchar *header_name);
-const gchar *camel_medium_get_header (CamelMedium *medium, const gchar *header_name);
+void camel_medium_add_header (CamelMedium *medium, gchar *header_name,
+ gchar *header_value);
+void camel_medium_remove_header (CamelMedium *medium,
+ const gchar *header_name);
+const gchar *camel_medium_get_header (CamelMedium *medium,
+ const gchar *header_name);
CamelDataWrapper *camel_medium_get_content_object (CamelMedium *medium);
-void camel_medium_set_content_object (CamelMedium *medium, CamelDataWrapper *content);
+void camel_medium_set_content_object (CamelMedium *medium,
+ CamelDataWrapper *content);
#ifdef __cplusplus
diff --git a/camel/camel-simple-data-wrapper.c b/camel/camel-simple-data-wrapper.c
index b0f4553360..7f128116dc 100644
--- a/camel/camel-simple-data-wrapper.c
+++ b/camel/camel-simple-data-wrapper.c
@@ -2,15 +2,15 @@
/* camel-simple-data-wrapper.c : simple implementation of a data wrapper */
/* store the data in a glib byte array */
-/*
+/*
*
- * Author :
+ * Author :
* Bertrand Guiheneuf <bertrand@helixcode.com>
*
* Copyright 1999, 2000 Helix Code, Inc. (http://www.helixcode.com)
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
@@ -28,37 +28,38 @@
#include "camel-simple-data-wrapper.h"
#include "camel-simple-data-wrapper-stream.h"
-#include "camel-log.h"
-static CamelDataWrapperClass *parent_class=NULL;
+static CamelDataWrapperClass *parent_class = NULL;
/* Returns the class for a CamelDataWrapper */
-#define CSDW_CLASS(so) CAMEL_SIMPLE_DATA_WRAPPER_CLASS (GTK_OBJECT(so)->klass)
+#define CSDW_CLASS(so) CAMEL_SIMPLE_DATA_WRAPPER_CLASS (GTK_OBJECT (so)->klass)
-static void my_construct_from_stream (CamelDataWrapper *data_wrapper,
+static void construct_from_stream (CamelDataWrapper *data_wrapper,
CamelStream *stream);
-static void my_write_to_stream (CamelDataWrapper *data_wrapper,
+static void write_to_stream (CamelDataWrapper *data_wrapper,
CamelStream *stream);
-static void my_finalize (GtkObject *object);
-static CamelStream * my_get_output_stream (CamelDataWrapper *data_wrapper);
+static void finalize (GtkObject *object);
+static CamelStream * get_output_stream (CamelDataWrapper *data_wrapper);
static void
camel_simple_data_wrapper_class_init (CamelSimpleDataWrapperClass *camel_simple_data_wrapper_class)
{
- CamelDataWrapperClass *camel_data_wrapper_class = CAMEL_DATA_WRAPPER_CLASS (camel_simple_data_wrapper_class);
- GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (camel_data_wrapper_class);
+ CamelDataWrapperClass *camel_data_wrapper_class =
+ CAMEL_DATA_WRAPPER_CLASS (camel_simple_data_wrapper_class);
+ GtkObjectClass *gtk_object_class =
+ GTK_OBJECT_CLASS (camel_data_wrapper_class);
parent_class = gtk_type_class (camel_data_wrapper_get_type ());
- /* virtual method definition */
+
/* virtual method overload */
- 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->get_output_stream = my_get_output_stream;
+ camel_data_wrapper_class->write_to_stream = write_to_stream;
+ camel_data_wrapper_class->construct_from_stream = construct_from_stream;
+ camel_data_wrapper_class->get_output_stream = get_output_stream;
- gtk_object_class->finalize = my_finalize;
+ gtk_object_class->finalize = finalize;
}
@@ -74,9 +75,9 @@ GtkType
camel_simple_data_wrapper_get_type (void)
{
static GtkType camel_simple_data_wrapper_type = 0;
-
- if (!camel_simple_data_wrapper_type) {
- GtkTypeInfo camel_simple_data_wrapper_info =
+
+ if (!camel_simple_data_wrapper_type) {
+ GtkTypeInfo camel_simple_data_wrapper_info =
{
"CamelSimpleDataWrapper",
sizeof (CamelSimpleDataWrapper),
@@ -87,160 +88,125 @@ camel_simple_data_wrapper_get_type (void)
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
-
- camel_simple_data_wrapper_type = gtk_type_unique (camel_data_wrapper_get_type (),
- &camel_simple_data_wrapper_info);
+
+ camel_simple_data_wrapper_type =
+ gtk_type_unique (camel_data_wrapper_get_type (),
+ &camel_simple_data_wrapper_info);
}
-
+
return camel_simple_data_wrapper_type;
}
-static void
-my_finalize (GtkObject *object)
+static void
+finalize (GtkObject *object)
{
- CamelSimpleDataWrapper *simple_data_wrapper = CAMEL_SIMPLE_DATA_WRAPPER (object);
+ CamelSimpleDataWrapper *simple_data_wrapper =
+ CAMEL_SIMPLE_DATA_WRAPPER (object);
- CAMEL_LOG_FULL_DEBUG ("Entering CamelMimePart::finalize\n");
- if (simple_data_wrapper->byte_array) g_byte_array_free (simple_data_wrapper->byte_array, TRUE);
+ if (simple_data_wrapper->byte_array)
+ g_byte_array_free (simple_data_wrapper->byte_array, TRUE);
GTK_OBJECT_CLASS (parent_class)->finalize (object);
- CAMEL_LOG_FULL_DEBUG ("Leaving CamelMimePart::finalize\n");
}
/**
- * camel_simple_data_wrapper_new: create a new CamelSimpleDataWrapper object
- *
- *
- *
- * Return value:
+ * camel_simple_data_wrapper_new:
+ *
+ * Return value: a new CamelSimpleDataWrapper object
**/
CamelSimpleDataWrapper *
camel_simple_data_wrapper_new (void)
{
- CamelSimpleDataWrapper *simple_data_wrapper;
- CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Entering new()\n");
-
- simple_data_wrapper = (CamelSimpleDataWrapper *)gtk_type_new (CAMEL_SIMPLE_DATA_WRAPPER_TYPE);
- CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Leaving new()\n");
- return simple_data_wrapper;
+ return (CamelSimpleDataWrapper *)
+ gtk_type_new (CAMEL_SIMPLE_DATA_WRAPPER_TYPE);
}
-
static void
-my_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
+write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
- CamelSimpleDataWrapper *simple_data_wrapper = CAMEL_SIMPLE_DATA_WRAPPER (data_wrapper);
+ CamelSimpleDataWrapper *simple_data_wrapper =
+ CAMEL_SIMPLE_DATA_WRAPPER (data_wrapper);
GByteArray *array;
- CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Entering my_write_to_stream\n");
- g_assert (data_wrapper);
- g_assert (stream);
-
array = simple_data_wrapper->byte_array;
if ( array && array->len)
camel_stream_write (stream, (gchar *)array->data, array->len);
else
parent_class->write_to_stream (data_wrapper, stream);
- CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Leaving my_write_to_stream\n");
}
-#define my_CMSDW_TMP_BUF_SIZE 100
+#define CMSDW_TMP_BUF_SIZE 100
static void
-my_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
+construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
- CamelSimpleDataWrapper *simple_data_wrapper = CAMEL_SIMPLE_DATA_WRAPPER (data_wrapper);
+ CamelSimpleDataWrapper *simple_data_wrapper =
+ CAMEL_SIMPLE_DATA_WRAPPER (data_wrapper);
gint nb_bytes_read;
static gchar *tmp_buf;
GByteArray *array;
- CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Entering my_construct_from_stream\n");
+ if (!tmp_buf)
+ tmp_buf = g_new (gchar, CMSDW_TMP_BUF_SIZE);
- g_assert (data_wrapper);
- g_assert (stream);
-
- if (!tmp_buf) {
- CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper::construct_from_stream allocating new temp buffer "
- "with %d bytes\n", my_CMSDW_TMP_BUF_SIZE);
- tmp_buf = g_new (gchar, my_CMSDW_TMP_BUF_SIZE);
- }
-
array = simple_data_wrapper->byte_array;
- if (array) {
- CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper::construct_from_stream freeing old byte array\n");
+ if (array)
g_byte_array_free (array, FALSE);
- }
-
+
array = g_byte_array_new ();
- CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper::construct_from_stream new byte array address:%p\n", array);
simple_data_wrapper->byte_array = array;
- nb_bytes_read = camel_stream_read (stream, tmp_buf, my_CMSDW_TMP_BUF_SIZE);
- while (nb_bytes_read>0) {
- CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper::construct_from_stream read %d bytes from stream\n", nb_bytes_read);
- if (nb_bytes_read>0) g_byte_array_append (array, tmp_buf, nb_bytes_read);
- nb_bytes_read = camel_stream_read (stream, tmp_buf, my_CMSDW_TMP_BUF_SIZE);
+ nb_bytes_read = camel_stream_read (stream, tmp_buf, CMSDW_TMP_BUF_SIZE);
+ while (nb_bytes_read > 0) {
+ if (nb_bytes_read > 0)
+ g_byte_array_append (array, tmp_buf, nb_bytes_read);
+ nb_bytes_read = camel_stream_read (stream, tmp_buf,
+ CMSDW_TMP_BUF_SIZE);
};
-
- CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Leaving my_construct_from_stream\n");
}
/**
- * camel_simple_data_wrapper_set_text: set some text as data wrapper content
+ * camel_simple_data_wrapper_set_text: set some text as data wrapper content
* @simple_data_wrapper: SimpleDataWrapper object
* @text: the text to use
- *
+ *
* Utility routine used to set up the content of a SimpleDataWrapper object
- * to be a character string.
+ * to be a character string.
**/
void
camel_simple_data_wrapper_set_text (CamelSimpleDataWrapper *simple_data_wrapper, const gchar *text)
{
GByteArray *array;
- CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Entering set_text\n");
array = simple_data_wrapper->byte_array;
- if (array) {
- CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper::set_text freeing old byte array\n");
+ if (array)
g_byte_array_free (array, FALSE);
- }
-
+
array = g_byte_array_new ();
simple_data_wrapper->byte_array = array;
-
- g_byte_array_append (array, text, strlen (text));
- CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Entering set_text\n");
+ g_byte_array_append (array, text, strlen (text));
}
-
-
-
static CamelStream *
-my_get_output_stream (CamelDataWrapper *data_wrapper)
+get_output_stream (CamelDataWrapper *data_wrapper)
{
CamelSimpleDataWrapper *simple_data_wrapper;
CamelStream *output_stream = NULL;
-
- CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper::get_output_stream leaving\n");
-
- g_assert (data_wrapper);
simple_data_wrapper = CAMEL_SIMPLE_DATA_WRAPPER (data_wrapper);
-
- if (simple_data_wrapper->byte_array && !(simple_data_wrapper->has_byte_array_stream)) {
+
+ if (simple_data_wrapper->byte_array &&
+ !(simple_data_wrapper->has_byte_array_stream)) {
output_stream = camel_simple_data_wrapper_stream_new (simple_data_wrapper);
camel_data_wrapper_set_output_stream (data_wrapper, output_stream);
}
- CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper::get_output_stream leaving\n");
-
return parent_class->get_output_stream (data_wrapper);
-
}
diff --git a/camel/camel-simple-data-wrapper.h b/camel/camel-simple-data-wrapper.h
index 844f691562..a16d1373a1 100644
--- a/camel/camel-simple-data-wrapper.h
+++ b/camel/camel-simple-data-wrapper.h
@@ -2,15 +2,15 @@
/* camel-simple-data-wrapper.c : simple implementation of a data wrapper */
/* store the data in a glib byte array */
-/*
+/*
*
- * Author :
+ * Author :
* Bertrand Guiheneuf <bertrand@helixcode.com>
*
* Copyright 1999, 2000 Helix Code, Inc. (http://www.helixcode.com)
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
@@ -57,7 +57,6 @@ struct _CamelSimpleDataWrapper
typedef struct {
CamelDataWrapperClass parent_class;
-
} CamelSimpleDataWrapperClass;