gmime r1415 - in trunk: . docs/reference gmime tests tools
- From: fejj svn gnome org
- To: svn-commits-list gnome org
- Subject: gmime r1415 - in trunk: . docs/reference gmime tests tools
- Date: Sun, 31 Aug 2008 18:01:51 +0000 (UTC)
Author: fejj
Date: Sun Aug 31 18:01:51 2008
New Revision: 1415
URL: http://svn.gnome.org/viewvc/gmime?rev=1415&view=rev
Log:
2008-08-31 Jeffrey Stedfast <fejj novell com>
* gmime/gmime-message-partial.c (g_mime_message_partial_new): Need
to unref the content_type after setting it on the object.
* gmime/gmime-message-part.c (g_mime_message_part_new): Need to
unref the content_type after setting it on the object.
* gmime/gmime-multipart.c (g_mime_multipart_new): Need to unref
the content_type after setting it on the object.
(g_mime_multipart_new_with_subtype): Same.
* gmime/gmime-multipart-signed.c (g_mime_multipart_signed_sign):
Need to unref the content_type after setting it on the
object. Also need to set mps->protocol /before/ we use it.
* gmime/gmime-multipart-encrypted.c (g_mime_multipart_encrypted_new):
Need to unref the content_type after setting it on the object.
(g_mime_multipart_encrypted_encrypt): Same.
* gmime/gmime-part.c (g_mime_part_new): Need to unref the
content_type after setting it on the object.
(g_mime_part_new_with_type): Same.
(g_mime_part_set_content_header): Removed.
(g_mime_part_get_content_header): Removed.
(g_mime_part_set_filename): Don't need to pre-set a
ContentDisposition ob the object if it is NULL,
g_mime_object_set_content_disposition_parameter() will do that for
us.
* gmime/gmime-parser.c (parser_construct_leaf_part): Instead of
going around the GMimeObject's back to set the content_type, call
g_mime_object_set_content_type().
(parser_construct_multipart): Same.
* gmime/gmime-object.c: Updated for GMimeContentType and
ContentDisposition GObjectification.
(g_mime_object_new): New function.
* gmime/gmime-disposition.c: Subclass GObject.
* gmime/gmime-content-type.c: Subclass GObject.
* gmime/internet-address.c: Got rid of unneeded vfuncs for the
changed event (which we don't want to be made public).
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
Modified:
trunk/ChangeLog
trunk/docs/reference/gmime-sections.txt
trunk/gmime/gmime-content-type.c
trunk/gmime/gmime-content-type.h
trunk/gmime/gmime-disposition.c
trunk/gmime/gmime-disposition.h
trunk/gmime/gmime-message-part.c
trunk/gmime/gmime-message-partial.c
trunk/gmime/gmime-multipart-encrypted.c
trunk/gmime/gmime-multipart-signed.c
trunk/gmime/gmime-multipart.c
trunk/gmime/gmime-object.c
trunk/gmime/gmime-object.h
trunk/gmime/gmime-parser.c
trunk/gmime/gmime-part.c
trunk/gmime/gmime-part.h
trunk/gmime/internet-address.c
trunk/gmime/internet-address.h
trunk/tests/test-mbox.c
trunk/tools/gmime-port-2-2-to-2-4.sh
Modified: trunk/docs/reference/gmime-sections.txt
==============================================================================
--- trunk/docs/reference/gmime-sections.txt (original)
+++ trunk/docs/reference/gmime-sections.txt Sun Aug 31 18:01:51 2008
@@ -611,7 +611,6 @@
GMimeContentType
g_mime_content_type_new
g_mime_content_type_new_from_string
-g_mime_content_type_destroy
g_mime_content_type_to_string
g_mime_content_type_is_type
g_mime_content_type_get_media_type
@@ -622,6 +621,18 @@
g_mime_content_type_set_params
g_mime_content_type_get_parameter
g_mime_content_type_set_parameter
+
+<SUBSECTION Private>
+g_mime_content_type_get_type
+
+<SUBSECTION Standard>
+GMIME_CONTENT_TYPE
+GMIME_IS_CONTENT_TYPE
+GMIME_TYPE_CONTENT_TYPE
+GMIME_CONTENT_TYPE_CLASS
+GMIME_IS_CONTENT_TYPE_CLASS
+GMIME_CONTENT_TYPE_GET_CLASS
+GMimeContentTypeClass
</SECTION>
<SECTION>
@@ -631,7 +642,6 @@
GMimeContentDisposition
g_mime_content_disposition_new
g_mime_content_disposition_new_from_string
-g_mime_content_disposition_destroy
g_mime_content_disposition_set_disposition
g_mime_content_disposition_get_disposition
g_mime_content_disposition_get_params
@@ -639,6 +649,18 @@
g_mime_content_disposition_set_parameter
g_mime_content_disposition_get_parameter
g_mime_content_disposition_to_string
+
+<SUBSECTION Private>
+g_mime_content_disposition_get_type
+
+<SUBSECTION Standard>
+GMIME_CONTENT_DISPOSITION
+GMIME_IS_CONTENT_DISPOSITION
+GMIME_TYPE_CONTENT_DISPOSITION
+GMIME_CONTENT_DISPOSITION_CLASS
+GMIME_IS_CONTENT_DISPOSITION_CLASS
+GMIME_CONTENT_DISPOSITION_GET_CLASS
+GMimeContentDispositionClass
</SECTION>
<SECTION>
@@ -646,6 +668,7 @@
GMimeObject
GMimePartFunc
g_mime_object_register_type
+g_mime_object_new
g_mime_object_new_type
g_mime_object_set_content_type
g_mime_object_get_content_type
@@ -687,8 +710,6 @@
GMimePart
g_mime_part_new
g_mime_part_new_with_type
-g_mime_part_set_content_header
-g_mime_part_get_content_header
g_mime_part_set_content_description
g_mime_part_get_content_description
g_mime_part_set_content_id
Modified: trunk/gmime/gmime-content-type.c
==============================================================================
--- trunk/gmime/gmime-content-type.c (original)
+++ trunk/gmime/gmime-content-type.c Sun Aug 31 18:01:51 2008
@@ -53,8 +53,88 @@
**/
-struct _GMimeObject;
-void _g_mime_object_content_type_changed (struct _GMimeObject *object);
+enum {
+ CHANGED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+static void g_mime_content_type_class_init (GMimeContentTypeClass *klass);
+static void g_mime_content_type_init (GMimeContentType *content_type, GMimeContentTypeClass *klass);
+static void g_mime_content_type_finalize (GObject *object);
+
+
+static GObjectClass *parent_class = NULL;
+
+
+GType
+g_mime_content_type_get_type (void)
+{
+ static GType type = 0;
+
+ if (!type) {
+ static const GTypeInfo info = {
+ sizeof (GMimeContentTypeClass),
+ NULL, /* base_class_init */
+ NULL, /* base_class_finalize */
+ (GClassInitFunc) g_mime_content_type_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (GMimeContentType),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) g_mime_content_type_init,
+ };
+
+ type = g_type_register_static (G_TYPE_OBJECT, "GMimeContentType", &info, 0);
+ }
+
+ return type;
+}
+
+
+static void
+g_mime_content_type_class_init (GMimeContentTypeClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ parent_class = g_type_class_ref (G_TYPE_OBJECT);
+
+ object_class->finalize = g_mime_content_type_finalize;
+
+ /* signals */
+ signals[CHANGED] =
+ g_signal_new ("changed",
+ GMIME_TYPE_CONTENT_TYPE,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+}
+
+static void
+g_mime_content_type_init (GMimeContentType *content_type, GMimeContentTypeClass *klass)
+{
+ content_type->param_hash = g_hash_table_new (g_mime_strcase_hash, g_mime_strcase_equal);
+ content_type->params = NULL;
+ content_type->subtype = NULL;
+ content_type->type = NULL;
+}
+
+static void
+g_mime_content_type_finalize (GObject *object)
+{
+ GMimeContentType *content_type = (GMimeContentType *) object;
+
+ g_hash_table_destroy (content_type->param_hash);
+ g_mime_param_destroy (content_type->params);
+ g_free (content_type->subtype);
+ g_free (content_type->type);
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
/**
@@ -64,14 +144,14 @@
*
* Creates a Content-Type object with type @type and subtype @subtype.
*
- * Returns: a new MIME Content-Type object.
+ * Returns: a new #GMimeContentType object.
**/
GMimeContentType *
g_mime_content_type_new (const char *type, const char *subtype)
{
GMimeContentType *mime_type;
- mime_type = g_new0 (GMimeContentType, 1);
+ mime_type = g_object_new (GMIME_TYPE_CONTENT_TYPE, NULL);
if (type && *type && subtype && *subtype) {
mime_type->type = g_strdup (type);
@@ -108,7 +188,7 @@
*
* Constructs a new Content-Type object based on the input string.
*
- * Returns: a new MIME Content-Type based on the input string.
+ * Returns: a new #GMimeContentType object based on the input string.
**/
GMimeContentType *
g_mime_content_type_new_from_string (const char *str)
@@ -157,16 +237,12 @@
inptr++;
if (*inptr++ == ';' && *inptr) {
- GMimeParam *p;
+ GMimeParam *param;
- mime_type->params = g_mime_param_new_from_string (inptr);
- if ((p = mime_type->params) != NULL) {
- mime_type->param_hash = g_hash_table_new (g_mime_strcase_hash, g_mime_strcase_equal);
-
- while (p != NULL) {
- g_hash_table_insert (mime_type->param_hash, p->name, p);
- p = p->next;
- }
+ param = mime_type->params = g_mime_param_new_from_string (inptr);
+ while (param != NULL) {
+ g_hash_table_insert (mime_type->param_hash, param->name, param);
+ param = param->next;
}
}
@@ -175,31 +251,8 @@
/**
- * g_mime_content_type_destroy: Destroy a MIME Content-Type object
- * @mime_type: MIME Content-Type object to destroy
- *
- * Destroys the given MIME Content-Type object.
- **/
-void
-g_mime_content_type_destroy (GMimeContentType *mime_type)
-{
- g_return_if_fail (mime_type != NULL);
-
- g_free (mime_type->type);
- g_free (mime_type->subtype);
-
- if (mime_type->param_hash)
- g_hash_table_destroy (mime_type->param_hash);
-
- g_mime_param_destroy (mime_type->params);
-
- g_free (mime_type);
-}
-
-
-/**
* g_mime_content_type_to_string:
- * @mime_type: MIME Content-Type
+ * @mime_type: a #GMimeContentType object
*
* Allocates a string buffer containing the type and subtype defined
* by the @mime_type.
@@ -208,11 +261,11 @@
* content-type in the format: type/subtype.
**/
char *
-g_mime_content_type_to_string (const GMimeContentType *mime_type)
+g_mime_content_type_to_string (GMimeContentType *mime_type)
{
char *string;
- g_return_val_if_fail (mime_type != NULL, NULL);
+ g_return_val_if_fail (GMIME_IS_CONTENT_TYPE (mime_type), NULL);
/* type and subtype should never be NULL, but check anyway */
string = g_strdup_printf ("%s/%s", mime_type->type ? mime_type->type : "text",
@@ -224,7 +277,7 @@
/**
* g_mime_content_type_is_type:
- * @mime_type: MIME Content-Type
+ * @mime_type: a #GMimeContentType object
* @type: MIME type to compare against
* @subtype: MIME subtype to compare against
*
@@ -235,9 +288,9 @@
* use "*" in place of @type and/or @subtype as a wilcard.
**/
gboolean
-g_mime_content_type_is_type (const GMimeContentType *mime_type, const char *type, const char *subtype)
+g_mime_content_type_is_type (GMimeContentType *mime_type, const char *type, const char *subtype)
{
- g_return_val_if_fail (mime_type != NULL, FALSE);
+ g_return_val_if_fail (GMIME_IS_CONTENT_TYPE (mime_type), FALSE);
g_return_val_if_fail (mime_type->type != NULL, FALSE);
g_return_val_if_fail (mime_type->subtype != NULL, FALSE);
g_return_val_if_fail (type != NULL, FALSE);
@@ -259,7 +312,7 @@
/**
* g_mime_content_type_set_media_type:
- * @mime_type: MIME Content-Type
+ * @mime_type: a #GMimeContentType object
* @type: media type
*
* Sets the Content-Type's media type.
@@ -269,30 +322,29 @@
{
char *buf;
- g_return_if_fail (mime_type != NULL);
+ g_return_if_fail (GMIME_IS_CONTENT_TYPE (mime_type));
g_return_if_fail (type != NULL);
buf = g_strdup (type);
g_free (mime_type->type);
mime_type->type = buf;
- if (mime_type->parent_object)
- _g_mime_object_content_type_changed (mime_type->parent_object);
+ g_signal_emit (mime_type, signals[CHANGED], 0);
}
/**
* g_mime_content_type_get_media_type:
- * @mime_type: MIME Content-Type
+ * @mime_type: a #GMimeContentType object
*
* Gets the Content-Type's media type.
*
* Returns: the Content-Type's media type.
**/
const char *
-g_mime_content_type_get_media_type (const GMimeContentType *mime_type)
+g_mime_content_type_get_media_type (GMimeContentType *mime_type)
{
- g_return_val_if_fail (mime_type != NULL, NULL);
+ g_return_val_if_fail (GMIME_IS_CONTENT_TYPE (mime_type), NULL);
return mime_type->type;
}
@@ -300,7 +352,7 @@
/**
* g_mime_content_type_set_media_subtype:
- * @mime_type: MIME Content-Type
+ * @mime_type: a #GMimeContentType object
* @subtype: media subtype
*
* Sets the Content-Type's media subtype.
@@ -310,30 +362,29 @@
{
char *buf;
- g_return_if_fail (mime_type != NULL);
+ g_return_if_fail (GMIME_IS_CONTENT_TYPE (mime_type));
g_return_if_fail (subtype != NULL);
buf = g_strdup (subtype);
g_free (mime_type->subtype);
mime_type->subtype = buf;
- if (mime_type->parent_object)
- _g_mime_object_content_type_changed (mime_type->parent_object);
+ g_signal_emit (mime_type, signals[CHANGED], 0);
}
/**
* g_mime_content_type_get_media_subtype:
- * @mime_type: MIME Content-Type
+ * @mime_type: a #GMimeContentType object
*
* Gets the Content-Type's media sub-type.
*
* Returns: the Content-Type's media sub-type.
**/
const char *
-g_mime_content_type_get_media_subtype (const GMimeContentType *mime_type)
+g_mime_content_type_get_media_subtype (GMimeContentType *mime_type)
{
- g_return_val_if_fail (mime_type != NULL, NULL);
+ g_return_val_if_fail (GMIME_IS_CONTENT_TYPE (mime_type), NULL);
return mime_type->subtype;
}
@@ -341,7 +392,7 @@
/**
* g_mime_content_type_set_params:
- * @mime_type: MIME Content-Type
+ * @mime_type: a #GMimeContentType object
* @params: a list of #GMimeParam objects
*
* Sets the Content-Type's parameter list.
@@ -349,41 +400,34 @@
void
g_mime_content_type_set_params (GMimeContentType *mime_type, GMimeParam *params)
{
- g_return_if_fail (mime_type != NULL);
-
- /* destroy the current list/hash */
- if (mime_type->param_hash)
- g_hash_table_destroy (mime_type->param_hash);
+ g_return_if_fail (GMIME_IS_CONTENT_TYPE (mime_type));
+ /* clear the current list/hash */
+ g_hash_table_remove_all (mime_type->param_hash);
g_mime_param_destroy (mime_type->params);
mime_type->params = params;
- if (params != NULL) {
- mime_type->param_hash = g_hash_table_new (g_mime_strcase_hash, g_mime_strcase_equal);
- while (params != NULL) {
- g_hash_table_insert (mime_type->param_hash, params->name, params);
- params = params->next;
- }
- } else {
- mime_type->param_hash = NULL;
+ while (params != NULL) {
+ g_hash_table_insert (mime_type->param_hash, params->name, params);
+ params = params->next;
}
- if (mime_type->parent_object)
- _g_mime_object_content_type_changed (mime_type->parent_object);
+ g_signal_emit (mime_type, signals[CHANGED], 0);
}
+
/**
* g_mime_content_type_get_params:
- * @mime_type: MIME Content-Type
+ * @mime_type: a #GMimeContentType object
*
* Gets the Content-Type's parameter list.
*
* Returns: the Content-Type's parameter list.
**/
const GMimeParam *
-g_mime_content_type_get_params (const GMimeContentType *mime_type)
+g_mime_content_type_get_params (GMimeContentType *mime_type)
{
- g_return_val_if_fail (mime_type != NULL, NULL);
+ g_return_val_if_fail (GMIME_IS_CONTENT_TYPE (mime_type), NULL);
return mime_type->params;
}
@@ -402,35 +446,26 @@
{
GMimeParam *param = NULL;
- g_return_if_fail (mime_type != NULL);
+ g_return_if_fail (GMIME_IS_CONTENT_TYPE (mime_type));
g_return_if_fail (attribute != NULL);
g_return_if_fail (value != NULL);
- if (mime_type->params) {
- if ((param = g_hash_table_lookup (mime_type->param_hash, attribute))) {
- g_free (param->value);
- param->value = g_strdup (value);
- goto changed;
- }
- } else if (!mime_type->param_hash) {
- /* hash table not initialized */
- mime_type->param_hash = g_hash_table_new (g_mime_strcase_hash, g_mime_strcase_equal);
+ if ((param = g_hash_table_lookup (mime_type->param_hash, attribute))) {
+ g_free (param->value);
+ param->value = g_strdup (value);
+ } else {
+ param = g_mime_param_new (attribute, value);
+ mime_type->params = g_mime_param_append_param (mime_type->params, param);
+ g_hash_table_insert (mime_type->param_hash, param->name, param);
}
- param = g_mime_param_new (attribute, value);
- mime_type->params = g_mime_param_append_param (mime_type->params, param);
- g_hash_table_insert (mime_type->param_hash, param->name, param);
-
- changed:
-
- if (mime_type->parent_object)
- _g_mime_object_content_type_changed (mime_type->parent_object);
+ g_signal_emit (mime_type, signals[CHANGED], 0);
}
/**
* g_mime_content_type_get_parameter:
- * @mime_type: MIME Content-Type
+ * @mime_type: a #GMimeContentType object
* @attribute: parameter name (aka attribute)
*
* Gets the parameter value specified by @attribute if it's available.
@@ -439,16 +474,13 @@
* @attribute or %NULL on fail.
**/
const char *
-g_mime_content_type_get_parameter (const GMimeContentType *mime_type, const char *attribute)
+g_mime_content_type_get_parameter (GMimeContentType *mime_type, const char *attribute)
{
GMimeParam *param;
- g_return_val_if_fail (mime_type != NULL, NULL);
+ g_return_val_if_fail (GMIME_IS_CONTENT_TYPE (mime_type), NULL);
g_return_val_if_fail (attribute != NULL, NULL);
- if (!mime_type->param_hash)
- return NULL;
-
if (!(param = g_hash_table_lookup (mime_type->param_hash, attribute)))
return NULL;
Modified: trunk/gmime/gmime-content-type.h
==============================================================================
--- trunk/gmime/gmime-content-type.h (original)
+++ trunk/gmime/gmime-content-type.h Sun Aug 31 18:01:51 2008
@@ -23,13 +23,25 @@
#define __GMIME_CONTENT_TYPE_H__
#include <glib.h>
+#include <glib-object.h>
+
#include <gmime/gmime-param.h>
G_BEGIN_DECLS
+#define GMIME_TYPE_CONTENT_TYPE (g_mime_content_type_get_type ())
+#define GMIME_CONTENT_TYPE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), g_mime_content_type_get_type (), GMimeContentType))
+#define GMIME_CONTENT_TYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), g_mime_content_type_get_type (), GMimeContentTypeClass))
+#define GMIME_IS_CONTENT_TYPE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), g_mime_content_type_get_type ()))
+#define GMIME_IS_CONTENT_TYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), g_mime_content_type_get_type ()))
+#define GMIME_CONTENT_TYPE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), g_mime_content_type_get_type (), GMimeContentTypeClass))
+
+typedef struct _GMimeContentType GMimeContentType;
+typedef struct _GMimeContentTypeClass GMimeContentTypeClass;
+
/**
* GMimeContentType:
- * @parent_object: parent object pointer
+ * @parent_object: parent #GObject
* @param_hash: parameter hash keyed by param name
* @params: a #GMimeParam list
* @type: media type
@@ -38,38 +50,40 @@
* A data structure representing a Content-Type.
**/
struct _GMimeContentType {
- /* <private> */
- gpointer parent_object;
- GHashTable *param_hash;
+ GObject parent_object;
- /* <public:read-only> */
+ GHashTable *param_hash;
GMimeParam *params;
char *type;
char *subtype;
};
-typedef struct _GMimeContentType GMimeContentType;
+struct _GMimeContentTypeClass {
+ GObjectClass parent_class;
+
+};
+
+GType g_mime_content_type_get_type (void);
+
GMimeContentType *g_mime_content_type_new (const char *type, const char *subtype);
GMimeContentType *g_mime_content_type_new_from_string (const char *str);
-void g_mime_content_type_destroy (GMimeContentType *mime_type);
-
-char *g_mime_content_type_to_string (const GMimeContentType *mime_type);
+char *g_mime_content_type_to_string (GMimeContentType *mime_type);
-gboolean g_mime_content_type_is_type (const GMimeContentType *mime_type, const char *type, const char *subtype);
+gboolean g_mime_content_type_is_type (GMimeContentType *mime_type, const char *type, const char *subtype);
void g_mime_content_type_set_media_type (GMimeContentType *mime_type, const char *type);
-const char *g_mime_content_type_get_media_type (const GMimeContentType *mime_type);
+const char *g_mime_content_type_get_media_type (GMimeContentType *mime_type);
void g_mime_content_type_set_media_subtype (GMimeContentType *mime_type, const char *subtype);
-const char *g_mime_content_type_get_media_subtype (const GMimeContentType *mime_type);
+const char *g_mime_content_type_get_media_subtype (GMimeContentType *mime_type);
void g_mime_content_type_set_params (GMimeContentType *mime_type, GMimeParam *params);
-const GMimeParam *g_mime_content_type_get_params (const GMimeContentType *mime_type);
+const GMimeParam *g_mime_content_type_get_params (GMimeContentType *mime_type);
void g_mime_content_type_set_parameter (GMimeContentType *mime_type, const char *attribute, const char *value);
-const char *g_mime_content_type_get_parameter (const GMimeContentType *mime_type, const char *attribute);
+const char *g_mime_content_type_get_parameter (GMimeContentType *mime_type, const char *attribute);
G_END_DECLS
Modified: trunk/gmime/gmime-disposition.c
==============================================================================
--- trunk/gmime/gmime-disposition.c (original)
+++ trunk/gmime/gmime-disposition.c Sun Aug 31 18:01:51 2008
@@ -41,8 +41,86 @@
**/
-struct _GMimeObject;
-void _g_mime_object_content_disposition_changed (struct _GMimeObject *object);
+enum {
+ CHANGED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+static void g_mime_content_disposition_class_init (GMimeContentDispositionClass *klass);
+static void g_mime_content_disposition_init (GMimeContentDisposition *disposition, GMimeContentDispositionClass *klass);
+static void g_mime_content_disposition_finalize (GObject *object);
+
+
+static GObjectClass *parent_class = NULL;
+
+
+GType
+g_mime_content_disposition_get_type (void)
+{
+ static GType type = 0;
+
+ if (!type) {
+ static const GTypeInfo info = {
+ sizeof (GMimeContentDispositionClass),
+ NULL, /* base_class_init */
+ NULL, /* base_class_finalize */
+ (GClassInitFunc) g_mime_content_disposition_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (GMimeContentDisposition),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) g_mime_content_disposition_init,
+ };
+
+ type = g_type_register_static (G_TYPE_OBJECT, "GMimeContentDisposition", &info, 0);
+ }
+
+ return type;
+}
+
+
+static void
+g_mime_content_disposition_class_init (GMimeContentDispositionClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ parent_class = g_type_class_ref (G_TYPE_OBJECT);
+
+ object_class->finalize = g_mime_content_disposition_finalize;
+
+ /* signals */
+ signals[CHANGED] =
+ g_signal_new ("changed",
+ GMIME_TYPE_CONTENT_DISPOSITION,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+}
+
+static void
+g_mime_content_disposition_init (GMimeContentDisposition *disposition, GMimeContentDispositionClass *klass)
+{
+ disposition->param_hash = g_hash_table_new (g_mime_strcase_hash, g_mime_strcase_equal);
+ disposition->disposition = NULL;
+ disposition->params = NULL;
+}
+
+static void
+g_mime_content_disposition_finalize (GObject *object)
+{
+ GMimeContentDisposition *disposition = (GMimeContentDisposition *) object;
+
+ g_hash_table_destroy (disposition->param_hash);
+ g_mime_param_destroy (disposition->params);
+ g_free (disposition->disposition);
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
/**
@@ -57,11 +135,8 @@
{
GMimeContentDisposition *disposition;
- disposition = g_new (GMimeContentDisposition, 1);
+ disposition = g_object_new (GMIME_TYPE_CONTENT_DISPOSITION, NULL);
disposition->disposition = g_strdup (GMIME_DISPOSITION_ATTACHMENT);
- disposition->parent_object = NULL;
- disposition->param_hash = NULL;
- disposition->params = NULL;
return disposition;
}
@@ -86,8 +161,7 @@
if (str == NULL)
return g_mime_content_disposition_new ();
- disposition = g_new (GMimeContentDisposition, 1);
- disposition->parent_object = NULL;
+ disposition = g_object_new (GMIME_TYPE_CONTENT_DISPOSITION, NULL);
/* get content disposition part */
@@ -101,14 +175,11 @@
/* parse the parameters, if any */
if (*inptr++ == ';' && *inptr) {
param = disposition->params = g_mime_param_new_from_string (inptr);
- disposition->param_hash = g_hash_table_new (g_mime_strcase_hash, g_mime_strcase_equal);
+
while (param) {
g_hash_table_insert (disposition->param_hash, param->name, param);
param = param->next;
}
- } else {
- disposition->param_hash = NULL;
- disposition->params = NULL;
}
return disposition;
@@ -116,26 +187,6 @@
/**
- * g_mime_content_disposition_destroy:
- * @disposition: a #GMimeContentDisposition object
- *
- * Destroy the #GMimeContentDisposition object.
- **/
-void
-g_mime_content_disposition_destroy (GMimeContentDisposition *disposition)
-{
- if (disposition) {
- g_free (disposition->disposition);
- if (disposition->params)
- g_mime_param_destroy (disposition->params);
- if (disposition->param_hash)
- g_hash_table_destroy (disposition->param_hash);
- g_free (disposition);
- }
-}
-
-
-/**
* g_mime_content_disposition_set_disposition:
* @disposition: a #GMimeContentDisposition object
* @value: disposition value
@@ -148,14 +199,16 @@
void
g_mime_content_disposition_set_disposition (GMimeContentDisposition *disposition, const char *value)
{
- g_return_if_fail (disposition != NULL);
+ char *buf;
+
+ g_return_if_fail (GMIME_IS_CONTENT_DISPOSITION (disposition));
g_return_if_fail (value != NULL);
+ buf = g_strdup (value);
g_free (disposition->disposition);
- disposition->disposition = g_strdup (value);
+ disposition->disposition = buf;
- if (disposition->parent_object)
- _g_mime_object_content_disposition_changed (disposition->parent_object);
+ g_signal_emit (disposition, signals[CHANGED], 0);
}
@@ -169,9 +222,9 @@
* #GMIME_DISPOSITION_ATTACHMENT or #GMIME_DISPOSITION_INLINE.
**/
const char *
-g_mime_content_disposition_get_disposition (const GMimeContentDisposition *disposition)
+g_mime_content_disposition_get_disposition (GMimeContentDisposition *disposition)
{
- g_return_val_if_fail (disposition != NULL, NULL);
+ g_return_val_if_fail (GMIME_IS_CONTENT_DISPOSITION (disposition), NULL);
return disposition->disposition;
}
@@ -187,27 +240,19 @@
void
g_mime_content_disposition_set_params (GMimeContentDisposition *disposition, GMimeParam *params)
{
- g_return_if_fail (disposition != NULL);
+ g_return_if_fail (GMIME_IS_CONTENT_DISPOSITION (disposition));
/* destroy the current list/hash */
- if (disposition->param_hash)
- g_hash_table_destroy (disposition->param_hash);
-
+ g_hash_table_remove_all (disposition->param_hash);
g_mime_param_destroy (disposition->params);
disposition->params = params;
- if (params != NULL) {
- disposition->param_hash = g_hash_table_new (g_mime_strcase_hash, g_mime_strcase_equal);
- while (params != NULL) {
- g_hash_table_insert (disposition->param_hash, params->name, params);
- params = params->next;
- }
- } else {
- disposition->param_hash = NULL;
+ while (params != NULL) {
+ g_hash_table_insert (disposition->param_hash, params->name, params);
+ params = params->next;
}
- if (disposition->parent_object)
- _g_mime_object_content_disposition_changed (disposition->parent_object);
+ g_signal_emit (disposition, signals[CHANGED], 0);
}
@@ -220,9 +265,9 @@
* Returns: the list of #GMimeParam's set on @disposition.
**/
const GMimeParam *
-g_mime_content_disposition_get_params (const GMimeContentDisposition *disposition)
+g_mime_content_disposition_get_params (GMimeContentDisposition *disposition)
{
- g_return_val_if_fail (disposition != NULL, NULL);
+ g_return_val_if_fail (GMIME_IS_CONTENT_DISPOSITION (disposition), NULL);
return disposition->params;
}
@@ -241,29 +286,20 @@
{
GMimeParam *param = NULL;
- g_return_if_fail (disposition != NULL);
+ g_return_if_fail (GMIME_IS_CONTENT_DISPOSITION (disposition));
g_return_if_fail (attribute != NULL);
g_return_if_fail (value != NULL);
- if (disposition->params) {
- if ((param = g_hash_table_lookup (disposition->param_hash, attribute))) {
- g_free (param->value);
- param->value = g_strdup (value);
- goto changed;
- }
- } else if (!disposition->param_hash) {
- /* hash table may not be initialized */
- disposition->param_hash = g_hash_table_new (g_mime_strcase_hash, g_mime_strcase_equal);
+ if ((param = g_hash_table_lookup (disposition->param_hash, attribute))) {
+ g_free (param->value);
+ param->value = g_strdup (value);
+ } else {
+ param = g_mime_param_new (attribute, value);
+ disposition->params = g_mime_param_append_param (disposition->params, param);
+ g_hash_table_insert (disposition->param_hash, param->name, param);
}
- param = g_mime_param_new (attribute, value);
- disposition->params = g_mime_param_append_param (disposition->params, param);
- g_hash_table_insert (disposition->param_hash, param->name, param);
-
- changed:
-
- if (disposition->parent_object)
- _g_mime_object_content_disposition_changed (disposition->parent_object);
+ g_signal_emit (disposition, signals[CHANGED], 0);
}
@@ -277,16 +313,13 @@
* Returns: the value of the parameter of name @attribute.
**/
const char *
-g_mime_content_disposition_get_parameter (const GMimeContentDisposition *disposition, const char *attribute)
+g_mime_content_disposition_get_parameter (GMimeContentDisposition *disposition, const char *attribute)
{
GMimeParam *param;
- g_return_val_if_fail (disposition != NULL, NULL);
+ g_return_val_if_fail (GMIME_IS_CONTENT_DISPOSITION (disposition), NULL);
g_return_val_if_fail (attribute != NULL, NULL);
- if (!disposition->param_hash)
- return NULL;
-
if (!(param = g_hash_table_lookup (disposition->param_hash, attribute)))
return NULL;
@@ -305,12 +338,12 @@
* Returns: a string containing the disposition header
**/
char *
-g_mime_content_disposition_to_string (const GMimeContentDisposition *disposition, gboolean fold)
+g_mime_content_disposition_to_string (GMimeContentDisposition *disposition, gboolean fold)
{
GString *string;
char *header, *buf;
- g_return_val_if_fail (disposition != NULL, NULL);
+ g_return_val_if_fail (GMIME_IS_CONTENT_DISPOSITION (disposition), NULL);
/* we need to have this so wrapping is correct */
string = g_string_new ("Content-Disposition: ");
Modified: trunk/gmime/gmime-disposition.h
==============================================================================
--- trunk/gmime/gmime-disposition.h (original)
+++ trunk/gmime/gmime-disposition.h Sun Aug 31 18:01:51 2008
@@ -23,10 +23,21 @@
#define __GMIME_DISPOSITION_H__
#include <glib.h>
+#include <glib-object.h>
+
#include <gmime/gmime-param.h>
G_BEGIN_DECLS
+#define GMIME_TYPE_CONTENT_DISPOSITION (g_mime_content_disposition_get_type ())
+#define GMIME_CONTENT_DISPOSITION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), g_mime_content_disposition_get_type (), GMimeContentDisposition))
+#define GMIME_CONTENT_DISPOSITION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), g_mime_content_disposition_get_type (), GMimeContentDispositionClass))
+#define GMIME_IS_CONTENT_DISPOSITION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), g_mime_content_disposition_get_type ()))
+#define GMIME_IS_CONTENT_DISPOSITION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), g_mime_content_disposition_get_type ()))
+#define GMIME_CONTENT_DISPOSITION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), g_mime_content_disposition_get_type (), GMimeContentDispositionClass))
+
+typedef struct _GMimeContentDisposition GMimeContentDisposition;
+typedef struct _GMimeContentDispositionClass GMimeContentDispositionClass;
/**
* GMIME_DISPOSITION_ATTACHMENT:
@@ -46,7 +57,7 @@
/**
* GMimeContentDisposition:
- * @parent_object: parent object pointer
+ * @parent_object: parent #GObject
* @param_hash: parameter hash table keyed by param name
* @params: a #GMimeParam list
* @disposition: disposition
@@ -54,34 +65,36 @@
* A data structure representing a Content-Disposition.
**/
struct _GMimeContentDisposition {
- /* <private> */
- gpointer parent_object;
- GHashTable *param_hash;
+ GObject parent_object;
- /* <public:read-only> */
+ GHashTable *param_hash;
GMimeParam *params;
char *disposition;
};
-typedef struct _GMimeContentDisposition GMimeContentDisposition;
+struct _GMimeContentDispositionClass {
+ GObjectClass parent_class;
+
+};
+
+GType g_mime_content_disposition_get_type (void);
+
GMimeContentDisposition *g_mime_content_disposition_new (void);
GMimeContentDisposition *g_mime_content_disposition_new_from_string (const char *str);
-void g_mime_content_disposition_destroy (GMimeContentDisposition *disposition);
-
void g_mime_content_disposition_set_disposition (GMimeContentDisposition *disposition, const char *value);
-const char *g_mime_content_disposition_get_disposition (const GMimeContentDisposition *disposition);
+const char *g_mime_content_disposition_get_disposition (GMimeContentDisposition *disposition);
void g_mime_content_disposition_set_params (GMimeContentDisposition *disposition, GMimeParam *params);
-const GMimeParam *g_mime_content_disposition_get_params (const GMimeContentDisposition *disposition);
+const GMimeParam *g_mime_content_disposition_get_params (GMimeContentDisposition *disposition);
void g_mime_content_disposition_set_parameter (GMimeContentDisposition *disposition,
const char *attribute, const char *value);
-const char *g_mime_content_disposition_get_parameter (const GMimeContentDisposition *disposition,
+const char *g_mime_content_disposition_get_parameter (GMimeContentDisposition *disposition,
const char *attribute);
-char *g_mime_content_disposition_to_string (const GMimeContentDisposition *disposition, gboolean fold);
+char *g_mime_content_disposition_to_string (GMimeContentDisposition *disposition, gboolean fold);
G_END_DECLS
Modified: trunk/gmime/gmime-message-part.c
==============================================================================
--- trunk/gmime/gmime-message-part.c (original)
+++ trunk/gmime/gmime-message-part.c Sun Aug 31 18:01:51 2008
@@ -231,13 +231,14 @@
GMimeMessagePart *
g_mime_message_part_new (const char *subtype)
{
+ GMimeContentType *content_type;
GMimeMessagePart *part;
- GMimeContentType *type;
part = g_object_new (GMIME_TYPE_MESSAGE_PART, NULL);
- type = g_mime_content_type_new ("message", subtype ? subtype : "rfc822");
- g_mime_object_set_content_type (GMIME_OBJECT (part), type);
+ content_type = g_mime_content_type_new ("message", subtype ? subtype : "rfc822");
+ g_mime_object_set_content_type (GMIME_OBJECT (part), content_type);
+ g_object_unref (content_type);
return part;
}
Modified: trunk/gmime/gmime-message-partial.c
==============================================================================
--- trunk/gmime/gmime-message-partial.c (original)
+++ trunk/gmime/gmime-message-partial.c Sun Aug 31 18:01:51 2008
@@ -203,28 +203,29 @@
GMimeMessagePartial *
g_mime_message_partial_new (const char *id, int number, int total)
{
+ GMimeContentType *content_type;
GMimeMessagePartial *partial;
- GMimeContentType *type;
char *num;
partial = g_object_new (GMIME_TYPE_MESSAGE_PARTIAL, NULL);
- type = g_mime_content_type_new ("message", "partial");
+ content_type = g_mime_content_type_new ("message", "partial");
partial->id = g_strdup (id);
- g_mime_content_type_set_parameter (type, "id", id);
+ g_mime_content_type_set_parameter (content_type, "id", id);
partial->number = number;
num = g_strdup_printf ("%d", number);
- g_mime_content_type_set_parameter (type, "number", num);
+ g_mime_content_type_set_parameter (content_type, "number", num);
g_free (num);
partial->total = total;
num = g_strdup_printf ("%d", total);
- g_mime_content_type_set_parameter (type, "total", num);
+ g_mime_content_type_set_parameter (content_type, "total", num);
g_free (num);
- g_mime_object_set_content_type (GMIME_OBJECT (partial), type);
+ g_mime_object_set_content_type (GMIME_OBJECT (partial), content_type);
+ g_object_unref (content_type);
return partial;
}
Modified: trunk/gmime/gmime-multipart-encrypted.c
==============================================================================
--- trunk/gmime/gmime-multipart-encrypted.c (original)
+++ trunk/gmime/gmime-multipart-encrypted.c Sun Aug 31 18:01:51 2008
@@ -207,12 +207,13 @@
g_mime_multipart_encrypted_new (void)
{
GMimeMultipartEncrypted *multipart;
- GMimeContentType *type;
+ GMimeContentType *content_type;
multipart = g_object_new (GMIME_TYPE_MULTIPART_ENCRYPTED, NULL);
- type = g_mime_content_type_new ("multipart", "encrypted");
- g_mime_object_set_content_type (GMIME_OBJECT (multipart), type);
+ content_type = g_mime_content_type_new ("multipart", "encrypted");
+ g_mime_object_set_content_type (GMIME_OBJECT (multipart), content_type);
+ g_object_unref (content_type);
return multipart;
}
@@ -281,7 +282,10 @@
g_mime_stream_reset (ciphertext);
/* construct the version part */
- version_part = g_mime_part_new ();
+ content_type = g_mime_content_type_new_from_string (ctx->encrypt_protocol);
+ version_part = g_mime_part_new_with_type (content_type->type, content_type->subtype);
+ g_object_unref (content_type);
+
content_type = g_mime_content_type_new_from_string (ctx->encrypt_protocol);
g_mime_object_set_content_type (GMIME_OBJECT (version_part), content_type);
g_mime_part_set_content_encoding (version_part, GMIME_CONTENT_ENCODING_7BIT);
@@ -340,9 +344,9 @@
GError **err)
{
GMimeObject *decrypted, *version, *encrypted;
- const GMimeContentType *mime_type;
GMimeStream *stream, *ciphertext;
GMimeStream *filtered_stream;
+ GMimeContentType *mime_type;
GMimeSignatureValidity *sv;
GMimeDataWrapper *wrapper;
GMimeFilter *crlf_filter;
Modified: trunk/gmime/gmime-multipart-signed.c
==============================================================================
--- trunk/gmime/gmime-multipart-signed.c (original)
+++ trunk/gmime/gmime-multipart-signed.c Sun Aug 31 18:01:51 2008
@@ -205,12 +205,13 @@
g_mime_multipart_signed_new (void)
{
GMimeMultipartSigned *multipart;
- GMimeContentType *type;
+ GMimeContentType *content_type;
multipart = g_object_new (GMIME_TYPE_MULTIPART_SIGNED, NULL);
- type = g_mime_content_type_new ("multipart", "signed");
- g_mime_object_set_content_type (GMIME_OBJECT (multipart), type);
+ content_type = g_mime_content_type_new ("multipart", "signed");
+ g_mime_object_set_content_type (GMIME_OBJECT (multipart), content_type);
+ g_object_unref (content_type);
return multipart;
}
@@ -285,7 +286,7 @@
GMimeStream *stream, *filtered, *sigstream;
GMimeContentType *content_type;
GMimeDataWrapper *wrapper;
- GMimeObject *signature;
+ GMimePart *signature;
GMimeFilter *filter;
GMimeParser *parser;
int rv;
@@ -338,6 +339,13 @@
g_mime_stream_reset (sigstream);
g_mime_stream_reset (stream);
+ /* set the multipart/signed protocol and micalg */
+ mps->protocol = g_strdup (ctx->sign_protocol);
+ mps->micalg = g_strdup (g_mime_cipher_context_hash_name (ctx, (GMimeCipherHash) rv));
+ g_mime_object_set_content_type_parameter (GMIME_OBJECT (mps), "protocol", mps->protocol);
+ g_mime_object_set_content_type_parameter (GMIME_OBJECT (mps), "micalg", mps->micalg);
+ g_mime_multipart_set_boundary (GMIME_MULTIPART (mps), NULL);
+
/* construct the content part */
parser = g_mime_parser_new_with_stream (stream);
content = g_mime_parser_construct_part (parser);
@@ -345,40 +353,31 @@
g_object_unref (parser);
/* construct the signature part */
- signature = (GMimeObject *) g_mime_part_new ();
+ content_type = g_mime_content_type_new_from_string (mps->protocol);
+ signature = g_mime_part_new_with_type (content_type->type, content_type->subtype);
+ g_object_unref (content_type);
+
wrapper = g_mime_data_wrapper_new ();
g_mime_data_wrapper_set_stream (wrapper, sigstream);
- g_mime_part_set_content_object (GMIME_PART (signature), wrapper);
+ g_mime_part_set_content_object (signature, wrapper);
g_object_unref (sigstream);
g_object_unref (wrapper);
- mps->protocol = g_strdup (ctx->sign_protocol);
- mps->micalg = g_strdup (g_mime_cipher_context_hash_name (ctx, (GMimeCipherHash) rv));
-
- /* set the content-type of the signature part */
- content_type = g_mime_content_type_new_from_string (mps->protocol);
- g_mime_object_set_content_type (signature, content_type);
-
/* FIXME: temporary hack, this info should probably be set in
* the CipherContext class - maybe ::sign can take/output a
* GMimePart instead. */
if (!g_ascii_strcasecmp (mps->protocol, "application/pkcs7-signature")) {
- g_mime_part_set_content_encoding (GMIME_PART (signature), GMIME_CONTENT_ENCODING_BASE64);
- g_mime_part_set_filename (GMIME_PART (signature), "smime.p7m");
+ g_mime_part_set_content_encoding (signature, GMIME_CONTENT_ENCODING_BASE64);
+ g_mime_part_set_filename (signature, "smime.p7m");
}
/* save the content and signature parts */
/* FIXME: make sure there aren't any other parts?? */
g_mime_multipart_add_part (GMIME_MULTIPART (mps), content);
- g_mime_multipart_add_part (GMIME_MULTIPART (mps), signature);
+ g_mime_multipart_add_part (GMIME_MULTIPART (mps), (GMimeObject *) signature);
g_object_unref (signature);
g_object_unref (content);
- /* set the content-type params for this multipart/signed part */
- g_mime_object_set_content_type_parameter (GMIME_OBJECT (mps), "micalg", mps->micalg);
- g_mime_object_set_content_type_parameter (GMIME_OBJECT (mps), "protocol", mps->protocol);
- g_mime_multipart_set_boundary (GMIME_MULTIPART (mps), NULL);
-
return 0;
}
Modified: trunk/gmime/gmime-multipart.c
==============================================================================
--- trunk/gmime/gmime-multipart.c (original)
+++ trunk/gmime/gmime-multipart.c Sun Aug 31 18:01:51 2008
@@ -312,13 +312,14 @@
GMimeMultipart *
g_mime_multipart_new (void)
{
+ GMimeContentType *content_type;
GMimeMultipart *multipart;
- GMimeContentType *type;
multipart = g_object_new (GMIME_TYPE_MULTIPART, NULL);
- type = g_mime_content_type_new ("multipart", "mixed");
- g_mime_object_set_content_type (GMIME_OBJECT (multipart), type);
+ content_type = g_mime_content_type_new ("multipart", "mixed");
+ g_mime_object_set_content_type (GMIME_OBJECT (multipart), content_type);
+ g_object_unref (content_type);
return multipart;
}
@@ -337,13 +338,14 @@
GMimeMultipart *
g_mime_multipart_new_with_subtype (const char *subtype)
{
+ GMimeContentType *content_type;
GMimeMultipart *multipart;
- GMimeContentType *type;
multipart = g_object_new (GMIME_TYPE_MULTIPART, NULL);
- type = g_mime_content_type_new ("multipart", subtype ? subtype : "mixed");
- g_mime_object_set_content_type (GMIME_OBJECT (multipart), type);
+ content_type = g_mime_content_type_new ("multipart", subtype ? subtype : "mixed");
+ g_mime_object_set_content_type (GMIME_OBJECT (multipart), content_type);
+ g_object_unref (content_type);
return multipart;
}
Modified: trunk/gmime/gmime-object.c
==============================================================================
--- trunk/gmime/gmime-object.c (original)
+++ trunk/gmime/gmime-object.c Sun Aug 31 18:01:51 2008
@@ -35,7 +35,7 @@
/**
* SECTION: gmime-object
* @title: GMimeObject
- * @short_description: Abstract Mime objects
+ * @short_description: Abstract MIME objects
* @see_also:
*
* #GMimeObject is an abstract class from which all Message and Mime
@@ -54,9 +54,6 @@
GType object_type;
};
-extern void _g_mime_object_content_type_changed (GMimeObject *object);
-extern void _g_mime_object_content_disposition_changed (GMimeObject *object);
-
static void g_mime_object_class_init (GMimeObjectClass *klass);
static void g_mime_object_init (GMimeObject *object, GMimeObjectClass *klass);
static void g_mime_object_finalize (GObject *object);
@@ -73,6 +70,9 @@
static ssize_t write_content_type (GMimeStream *stream, const char *name, const char *value);
static ssize_t write_disposition (GMimeStream *stream, const char *name, const char *value);
+static void content_type_changed (GMimeContentType *content_type, GMimeObject *object);
+static void content_disposition_changed (GMimeContentDisposition *disposition, GMimeObject *object);
+
static void type_registry_init (void);
@@ -144,11 +144,19 @@
{
GMimeObject *mime = (GMimeObject *) object;
- if (mime->content_type)
- g_mime_content_type_destroy (mime->content_type);
+ if (mime->content_type) {
+ g_signal_handlers_disconnect_matched (mime->content_type,
+ G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
+ 0, 0, NULL, content_type_changed, object);
+ g_object_unref (mime->content_type);
+ }
- if (mime->disposition)
- g_mime_content_disposition_destroy (mime->disposition);
+ if (mime->disposition) {
+ g_signal_handlers_disconnect_matched (mime->disposition,
+ G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
+ 0, 0, NULL, content_disposition_changed, object);
+ g_object_unref (mime->disposition);
+ }
if (mime->headers)
g_mime_header_list_destroy (mime->headers);
@@ -177,7 +185,7 @@
g_free (val);
g_mime_param_write_to_string (content_type->params, TRUE, out);
- g_mime_content_type_destroy (content_type);
+ g_object_unref (content_type);
nwritten = g_mime_stream_write (stream, out->str, out->len);
g_string_free (out, TRUE);
@@ -185,16 +193,13 @@
return nwritten;
}
-void
-_g_mime_object_content_type_changed (GMimeObject *object)
+static void
+content_type_changed (GMimeContentType *content_type, GMimeObject *object)
{
- GMimeContentType *content_type;
GMimeParam *params;
GString *string;
char *type, *p;
- content_type = object->content_type;
-
string = g_string_new ("Content-Type: ");
type = g_mime_content_type_to_string (content_type);
@@ -226,7 +231,7 @@
g_string_append (out, disposition->disposition);
g_mime_param_write_to_string (disposition->params, TRUE, out);
- g_mime_content_disposition_destroy (disposition);
+ g_object_unref (disposition);
nwritten = g_mime_stream_write (stream, out->str, out->len);
g_string_free (out, TRUE);
@@ -234,8 +239,8 @@
return nwritten;
}
-void
-_g_mime_object_content_disposition_changed (GMimeObject *object)
+static void
+content_disposition_changed (GMimeContentDisposition *disposition, GMimeObject *object)
{
char *str;
@@ -287,6 +292,82 @@
g_hash_table_insert (bucket->subtype_hash, sub->subtype, sub);
}
+static void
+set_content_type_internal (GMimeObject *object, GMimeContentType *content_type, gboolean resync)
+{
+ if (content_type == object->content_type)
+ return;
+
+ if (object->content_type) {
+ g_signal_handlers_disconnect_matched (object->content_type,
+ G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
+ 0, 0, NULL, content_type_changed, object);
+ g_object_unref (object->content_type);
+ }
+
+ g_signal_connect (content_type, "changed", G_CALLBACK (content_type_changed), object);
+ object->content_type = content_type;
+ g_object_ref (content_type);
+
+ if (resync)
+ content_type_changed (content_type, object);
+}
+
+/**
+ * g_mime_object_new:
+ * @content_type: a #GMimeContentType object
+ *
+ * Performs a lookup of registered #GMimeObject subclasses, registered
+ * using g_mime_object_register_type(), to find an appropriate class
+ * capable of handling MIME parts of the specified Content-Type. If no
+ * class has been registered to handle that type, it looks for a
+ * registered class that can handle @content_type's media type. If
+ * that also fails, then it will use the generic part class,
+ * #GMimePart.
+ *
+ * Returns: an appropriate #GMimeObject registered to handle MIME
+ * parts appropriate for @content_type.
+ **/
+GMimeObject *
+g_mime_object_new (GMimeContentType *content_type)
+{
+ struct _type_bucket *bucket;
+ struct _subtype_bucket *sub;
+ GMimeObject *object;
+ GType obj_type;
+
+ g_return_val_if_fail (GMIME_IS_CONTENT_TYPE (content_type), NULL);
+
+ type_registry_init ();
+
+ if ((bucket = g_hash_table_lookup (type_hash, content_type->type))) {
+ if (!(sub = g_hash_table_lookup (bucket->subtype_hash, content_type->subtype)))
+ sub = g_hash_table_lookup (bucket->subtype_hash, "*");
+
+ obj_type = sub ? sub->object_type : 0;
+ } else {
+ bucket = g_hash_table_lookup (type_hash, "*");
+ obj_type = bucket ? bucket->object_type : 0;
+ }
+
+ if (!obj_type) {
+ /* use the default mime object */
+ if ((bucket = g_hash_table_lookup (type_hash, "*"))) {
+ sub = g_hash_table_lookup (bucket->subtype_hash, "*");
+ obj_type = sub ? sub->object_type : 0;
+ }
+
+ if (!obj_type)
+ return NULL;
+ }
+
+ object = g_object_new (obj_type, NULL);
+
+ g_mime_object_set_content_type (object, content_type);
+
+ return object;
+}
+
/**
* g_mime_object_new_type:
@@ -295,7 +376,7 @@
*
* Performs a lookup of registered #GMimeObject subclasses, registered
* using g_mime_object_register_type(), to find an appropriate class
- * capable of handling Mime parts of type @type/@subtype. If no class
+ * capable of handling MIME parts of type @type/@subtype. If no class
* has been registered to handle that type, it looks for a registered
* class that can handle @type. If that also fails, then it will use
* the generic part class, #GMimePart.
@@ -341,31 +422,26 @@
return object;
}
+
static void
set_content_type (GMimeObject *object, GMimeContentType *content_type)
{
- if (object->content_type)
- g_mime_content_type_destroy (object->content_type);
-
- if ((object->content_type = content_type))
- content_type->parent_object = object;
-
- _g_mime_object_content_type_changed (object);
+ set_content_type_internal (object, content_type, TRUE);
}
/**
* g_mime_object_set_content_type:
* @object: a #GMimeObject
- * @mime_type: Mime type
+ * @mime_type: a #GMimeContentType object
*
- * Sets the content-type for the specified Mime object.
+ * Sets the content-type for the specified MIME object.
**/
void
g_mime_object_set_content_type (GMimeObject *object, GMimeContentType *mime_type)
{
+ g_return_if_fail (GMIME_IS_CONTENT_TYPE (mime_type));
g_return_if_fail (GMIME_IS_OBJECT (object));
- g_return_if_fail (mime_type != NULL);
GMIME_OBJECT_GET_CLASS (object)->set_content_type (object, mime_type);
}
@@ -375,10 +451,10 @@
* g_mime_object_get_content_type:
* @object: a #GMimeObject
*
- * Gets the #GMimeContentType object for the given Mime object or
+ * Gets the #GMimeContentType object for the given MIME object or
* %NULL on fail.
*
- * Returns: the content-type object for the specified Mime object.
+ * Returns: the content-type object for the specified MIME object.
**/
GMimeContentType *
g_mime_object_get_content_type (GMimeObject *object)
@@ -412,7 +488,7 @@
* @object: a #GMimeObject
* @name: param name
*
- * Gets the value of the content-type param @name set on the Mime part
+ * Gets the value of the content-type param @name set on the MIME part
* @object.
*
* Returns: the value of the requested content-type param or %NULL on
@@ -432,9 +508,9 @@
* g_mime_object_get_content_disposition:
* @object: a #GMimeObject
*
- * Gets the #GMimeContentDisposition for the specified Mime object.
+ * Gets the #GMimeContentDisposition for the specified MIME object.
*
- * Returns: the #GMimeContentDisposition set on the Mime object.
+ * Returns: the #GMimeContentDisposition set on the MIME object.
**/
GMimeContentDisposition *
g_mime_object_get_content_disposition (GMimeObject *object)
@@ -445,6 +521,27 @@
}
+static void
+set_content_disposition_internal (GMimeObject *object, GMimeContentDisposition *disposition, gboolean resync)
+{
+ if (disposition == object->disposition)
+ return;
+
+ if (object->disposition) {
+ g_signal_handlers_disconnect_matched (object->disposition,
+ G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
+ 0, 0, NULL, content_disposition_changed, object);
+ g_object_unref (object->disposition);
+ }
+
+ g_signal_connect (disposition, "changed", G_CALLBACK (content_disposition_changed), object);
+ object->disposition = disposition;
+ g_object_ref (disposition);
+
+ if (resync)
+ content_disposition_changed (disposition, object);
+}
+
/**
* g_mime_object_set_content_disposition:
* @object: a #GMimeObject
@@ -455,15 +552,10 @@
void
g_mime_object_set_content_disposition (GMimeObject *object, GMimeContentDisposition *disposition)
{
+ g_return_if_fail (GMIME_IS_CONTENT_DISPOSITION (disposition));
g_return_if_fail (GMIME_IS_OBJECT (object));
- if (object->disposition)
- g_mime_content_disposition_destroy (object->disposition);
-
- if ((object->disposition = disposition))
- disposition->parent_object = object;
-
- _g_mime_object_content_disposition_changed (object);
+ set_content_disposition_internal (object, disposition, TRUE);
}
@@ -474,21 +566,26 @@
*
* Sets the disposition to @disposition which may be one of
* #GMIME_DISPOSITION_ATTACHMENT or #GMIME_DISPOSITION_INLINE or, by
- * your choice, any other string which would indicate how the Mime
+ * your choice, any other string which would indicate how the MIME
* part should be displayed by the MUA.
**/
void
g_mime_object_set_disposition (GMimeObject *object, const char *disposition)
{
+ GMimeContentDisposition *disp;
+
g_return_if_fail (GMIME_IS_OBJECT (object));
+ g_return_if_fail (disposition != NULL);
if (object->disposition) {
g_mime_content_disposition_set_disposition (object->disposition, disposition);
- } else if (disposition) {
- if ((object->disposition = g_mime_content_disposition_new_from_string (disposition)))
- object->disposition->parent_object = object;
- _g_mime_object_content_disposition_changed (object);
+ return;
}
+
+ disp = g_mime_content_disposition_new ();
+ g_mime_content_disposition_set_disposition (disp, disposition);
+ g_mime_object_set_content_disposition (object, disp);
+ g_object_ref (disp);
}
@@ -496,7 +593,7 @@
* g_mime_object_get_disposition:
* @object: a #GMimeObject
*
- * Gets the Mime object's disposition if set or %NULL otherwise.
+ * Gets the MIME object's disposition if set or %NULL otherwise.
*
* Returns: the disposition string which is probably one of
* #GMIME_DISPOSITION_ATTACHMENT or #GMIME_DISPOSITION_INLINE.
@@ -524,12 +621,14 @@
void
g_mime_object_set_content_disposition_parameter (GMimeObject *object, const char *attribute, const char *value)
{
+ GMimeContentDisposition *disposition;
+
g_return_if_fail (GMIME_IS_OBJECT (object));
g_return_if_fail (attribute != NULL);
if (!object->disposition) {
- object->disposition = g_mime_content_disposition_new ();
- object->disposition->parent_object = object;
+ disposition = g_mime_content_disposition_new ();
+ set_content_disposition_internal (object, disposition, FALSE);
}
g_mime_content_disposition_set_parameter (object->disposition, attribute, value);
@@ -565,7 +664,7 @@
* @object: a #GMimeObject
* @content_id: content-id (addr-spec portion)
*
- * Sets the Content-Id of the Mime object.
+ * Sets the Content-Id of the MIME object.
**/
void
g_mime_object_set_content_id (GMimeObject *object, const char *content_id)
@@ -587,7 +686,7 @@
* g_mime_object_get_content_id:
* @object: a #GMimeObject
*
- * Gets the Content-Id of the Mime object or NULL if one is not set.
+ * Gets the Content-Id of the MIME object or NULL if one is not set.
*
* Returns: a const pointer to the Content-Id header.
**/
@@ -628,13 +727,13 @@
switch (i) {
case HEADER_CONTENT_DISPOSITION:
disposition = g_mime_content_disposition_new_from_string (value);
- if (object->disposition)
- g_mime_content_disposition_destroy (object->disposition);
- object->disposition = disposition;
+ set_content_disposition_internal (object, disposition, FALSE);
+ g_object_unref (disposition);
break;
case HEADER_CONTENT_TYPE:
content_type = g_mime_content_type_new_from_string (value);
- g_mime_object_set_content_type (object, content_type);
+ set_content_type_internal (object, content_type, FALSE);
+ g_object_unref (content_type);
break;
case HEADER_CONTENT_ID:
g_free (object->content_id);
@@ -663,7 +762,7 @@
* @header: header name
* @value: header value
*
- * Prepends a header to the Mime object.
+ * Prepends a header to the MIME object.
**/
void
g_mime_object_prepend_header (GMimeObject *object, const char *header, const char *value)
@@ -689,7 +788,7 @@
* @header: header name
* @value: header value
*
- * Appends a header to the Mime object.
+ * Appends a header to the MIME object.
**/
void
g_mime_object_append_header (GMimeObject *object, const char *header, const char *value)
@@ -716,7 +815,7 @@
* @header: header name
* @value: header value
*
- * Sets an arbitrary header on the Mime object.
+ * Sets an arbitrary header on the MIME object.
**/
void
g_mime_object_set_header (GMimeObject *object, const char *header, const char *value)
@@ -770,7 +869,10 @@
switch (i) {
case HEADER_CONTENT_DISPOSITION:
if (object->disposition) {
- g_mime_content_disposition_destroy (object->disposition);
+ g_signal_handlers_disconnect_matched (object->disposition,
+ G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
+ 0, 0, NULL, content_disposition_changed, object);
+ g_object_unref (object->disposition);
object->disposition = NULL;
}
break;
@@ -820,10 +922,10 @@
* g_mime_object_get_headers:
* @object: a #GMimeObject
*
- * Allocates a string buffer containing all of the Mime object's raw
+ * Allocates a string buffer containing all of the MIME object's raw
* headers.
*
- * Returns: an allocated string containing all of the raw Mime headers.
+ * Returns: an allocated string containing all of the raw MIME headers.
**/
char *
g_mime_object_get_headers (GMimeObject *object)
@@ -846,7 +948,7 @@
* @object: a #GMimeObject
* @stream: stream
*
- * Write the contents of the Mime object to @stream.
+ * Write the contents of the MIME object to @stream.
*
* Returns: the number of bytes written or %-1 on fail.
**/
Modified: trunk/gmime/gmime-object.h
==============================================================================
--- trunk/gmime/gmime-object.h (original)
+++ trunk/gmime/gmime-object.h Sun Aug 31 18:01:51 2008
@@ -93,6 +93,8 @@
GType g_mime_object_get_type (void);
void g_mime_object_register_type (const char *type, const char *subtype, GType object_type);
+
+GMimeObject *g_mime_object_new (GMimeContentType *content_type);
GMimeObject *g_mime_object_new_type (const char *type, const char *subtype);
void g_mime_object_set_content_type (GMimeObject *object, GMimeContentType *mime_type);
Modified: trunk/gmime/gmime-parser.c
==============================================================================
--- trunk/gmime/gmime-parser.c (original)
+++ trunk/gmime/gmime-parser.c Sun Aug 31 18:01:51 2008
@@ -1376,9 +1376,8 @@
header_raw_clear (&priv->headers);
- if (object->content_type)
- g_mime_content_type_destroy (object->content_type);
- object->content_type = content_type;
+ g_mime_object_set_content_type (object, content_type);
+ g_object_unref (content_type);
g_mime_header_list_set_raw (object->headers, priv->rawbuf);
raw_header_reset (priv);
@@ -1528,9 +1527,8 @@
header_raw_clear (&priv->headers);
- if (object->content_type)
- g_mime_content_type_destroy (object->content_type);
- object->content_type = content_type;
+ g_mime_object_set_content_type (object, content_type);
+ g_object_unref (content_type);
g_mime_header_list_set_raw (object->headers, priv->rawbuf);
raw_header_reset (priv);
Modified: trunk/gmime/gmime-part.c
==============================================================================
--- trunk/gmime/gmime-part.c (original)
+++ trunk/gmime/gmime-part.c Sun Aug 31 18:01:51 2008
@@ -411,13 +411,14 @@
GMimePart *
g_mime_part_new (void)
{
+ GMimeContentType *content_type;
GMimePart *mime_part;
- GMimeContentType *type;
mime_part = g_object_new (GMIME_TYPE_PART, NULL);
- type = g_mime_content_type_new ("text", "plain");
- g_mime_object_set_content_type (GMIME_OBJECT (mime_part), type);
+ content_type = g_mime_content_type_new ("text", "plain");
+ g_mime_object_set_content_type (GMIME_OBJECT (mime_part), content_type);
+ g_object_unref (content_type);
return mime_part;
}
@@ -435,57 +436,20 @@
GMimePart *
g_mime_part_new_with_type (const char *type, const char *subtype)
{
- GMimePart *mime_part;
GMimeContentType *content_type;
+ GMimePart *mime_part;
mime_part = g_object_new (GMIME_TYPE_PART, NULL);
content_type = g_mime_content_type_new (type, subtype);
g_mime_object_set_content_type (GMIME_OBJECT (mime_part), content_type);
+ g_object_unref (content_type);
return mime_part;
}
/**
- * g_mime_part_set_content_header:
- * @mime_part: mime part
- * @header: header name
- * @value: header value
- *
- * Set an arbitrary MIME content header.
- **/
-void
-g_mime_part_set_content_header (GMimePart *mime_part, const char *header, const char *value)
-{
- g_return_if_fail (GMIME_IS_PART (mime_part));
- g_return_if_fail (header != NULL);
-
- g_mime_object_set_header (GMIME_OBJECT (mime_part), header, value);
-}
-
-
-/**
- * g_mime_part_get_content_header:
- * @mime_part: mime part
- * @header: header name
- *
- * Gets the value of the requested header if it exists, or %NULL
- * otherwise.
- *
- * Returns: the value of the content header @header.
- **/
-const char *
-g_mime_part_get_content_header (GMimePart *mime_part, const char *header)
-{
- g_return_val_if_fail (GMIME_IS_PART (mime_part), NULL);
- g_return_val_if_fail (header != NULL, NULL);
-
- return g_mime_object_get_header (GMIME_OBJECT (mime_part), header);
-}
-
-
-/**
* g_mime_part_set_content_description:
* @mime_part: Mime part
* @description: content description
@@ -568,8 +532,8 @@
g_mime_part_set_content_md5 (GMimePart *mime_part, const char *content_md5)
{
unsigned char digest[16], b64digest[32];
- const GMimeContentType *content_type;
GMimeStreamFilter *filtered_stream;
+ GMimeContentType *content_type;
GMimeFilter *md5_filter;
GMimeStream *stream;
guint32 save = 0;
@@ -632,8 +596,8 @@
g_mime_part_verify_content_md5 (GMimePart *mime_part)
{
unsigned char digest[16], b64digest[32];
- const GMimeContentType *content_type;
GMimeStreamFilter *filtered_stream;
+ GMimeContentType *content_type;
GMimeFilter *md5_filter;
GMimeStream *stream;
guint32 save = 0;
@@ -784,9 +748,6 @@
g_return_if_fail (GMIME_IS_PART (mime_part));
- if (!object->disposition)
- g_mime_object_set_disposition (object, GMIME_DISPOSITION_ATTACHMENT);
-
g_mime_object_set_content_disposition_parameter (object, "filename", filename);
g_mime_object_set_content_type_parameter (object, "name", filename);
}
Modified: trunk/gmime/gmime-part.h
==============================================================================
--- trunk/gmime/gmime-part.h (original)
+++ trunk/gmime/gmime-part.h Sun Aug 31 18:01:51 2008
@@ -76,9 +76,6 @@
GMimePart *g_mime_part_new_with_type (const char *type, const char *subtype);
/* accessor functions */
-void g_mime_part_set_content_header (GMimePart *mime_part, const char *header, const char *value);
-const char *g_mime_part_get_content_header (GMimePart *mime_part, const char *header);
-
void g_mime_part_set_content_description (GMimePart *mime_part, const char *description);
const char *g_mime_part_get_content_description (const GMimePart *mime_part);
Modified: trunk/gmime/internet-address.c
==============================================================================
--- trunk/gmime/internet-address.c (original)
+++ trunk/gmime/internet-address.c Sun Aug 31 18:01:51 2008
@@ -120,7 +120,7 @@
g_signal_new ("changed",
INTERNET_ADDRESS_TYPE,
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (InternetAddressClass, changed),
+ 0,
NULL,
NULL,
g_cclosure_marshal_VOID__VOID,
@@ -569,9 +569,9 @@
/* signals */
list_signals[CHANGED] =
g_signal_new ("changed",
- internet_address_list_get_type (),
+ INTERNET_ADDRESS_LIST_TYPE,
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (InternetAddressListClass, changed),
+ 0,
NULL,
NULL,
g_cclosure_marshal_VOID__VOID,
Modified: trunk/gmime/internet-address.h
==============================================================================
--- trunk/gmime/internet-address.h (original)
+++ trunk/gmime/internet-address.h Sun Aug 31 18:01:51 2008
@@ -82,9 +82,6 @@
struct _InternetAddressClass {
GObjectClass parent_class;
- /* internal signals */
- void (* changed) (InternetAddress *ia);
-
/* public virtual methods */
void (* to_string) (InternetAddress *ia, guint32 flags, size_t *linelen, GString *out);
};
@@ -170,8 +167,6 @@
struct _InternetAddressListClass {
GObjectClass parent_class;
- /* internal signals */
- void (* changed) (InternetAddressList *list);
};
Modified: trunk/tests/test-mbox.c
==============================================================================
--- trunk/tests/test-mbox.c (original)
+++ trunk/tests/test-mbox.c Sun Aug 31 18:01:51 2008
@@ -419,6 +419,7 @@
g_object_unref (istream);
g_object_unref (ostream);
+ g_object_unref (parser);
#ifdef ENABLE_MBOX_MATCH
g_object_unref (mstream);
Modified: trunk/tools/gmime-port-2-2-to-2-4.sh
==============================================================================
--- trunk/tools/gmime-port-2-2-to-2-4.sh (original)
+++ trunk/tools/gmime-port-2-2-to-2-4.sh Sun Aug 31 18:01:51 2008
@@ -52,6 +52,8 @@
-e "s/g_mime_part_set_content_disposition_object/g_mime_object_set_content_disposition/g" \
-e "s/g_mime_part_get_content_disposition/g_mime_object_get_disposition/g" \
-e "s/g_mime_part_set_content_disposition/g_mime_object_set_disposition/g" \
+ -e "s/g_mime_part_get_content_header/g_mime_object_get_header/g" \
+ -e "s/g_mime_part_set_content_header/g_mime_object_set_header/g" \
-e "s/g_mime_part_get_content_type/g_mime_object_get_content_type/g" \
-e "s/g_mime_part_set_content_type/g_mime_object_set_content_type/g" \
-e "s/g_mime_part_get_encoding/g_mime_part_get_content_encoding/g" \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]