[gmime] Converted GMimeParam and GMimeParamList into GObjects



commit 048e237671419bbe8bee326a3d39a1149e6c8614
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date:   Thu Mar 16 12:21:02 2017 -0400

    Converted GMimeParam and GMimeParamList into GObjects

 PORTING                           |    6 +-
 TODO                              |    2 -
 docs/reference/changes-3.0.sgml   |    4 +-
 docs/reference/gmime-sections.txt |   21 +++-
 docs/reference/gmime.hierarchy    |    5 +
 examples/imap-example.c           |    8 +-
 gmime/gmime-content-type.c        |    8 +-
 gmime/gmime-content-type.h        |    2 +-
 gmime/gmime-disposition.c         |    8 +-
 gmime/gmime-disposition.h         |    2 +-
 gmime/gmime-header.c              |   34 +++--
 gmime/gmime-param.c               |  264 ++++++++++++++++++++++++-------------
 gmime/gmime-param.h               |   40 ++++++-
 gmime/gmime.c                     |    2 +
 tests/test-headers.c              |    4 +-
 tests/test-mime.c                 |    4 +-
 16 files changed, 283 insertions(+), 131 deletions(-)
---
diff --git a/PORTING b/PORTING
index bf665c2..dcea2ea 100644
--- a/PORTING
+++ b/PORTING
@@ -58,13 +58,17 @@ Porting from GMime 2.6 to GMime 3.0
 - g_mime_content_type_new_from_string() has been replaced by
   g_mime_content_type_parse() and now takes a GMimeParserOptions argument.
 
-- g_mime_content_type_to_string() has been replaced by g_mime_content_type_get_mime_type().
+- g_mime_content_type_to_string() has been renamed to g_mime_content_type_get_mime_type().
+
+- g_mime_content_type_get_params() has been renamed to g_mime_content_type_get_parameters().
 
 - g_mime_content_disposition_new_from_string() has been replaced by
   g_mime_content_disposition_parse() and now takes a GMimeParserOptions argument.
 
 - g_mime_content_disposition_to_string() has been replaced by g_mime_content_disposition_encode().
 
+- g_mime_content_disposition_get_params() has been renamed to g_mime_content_disposition_get_parameters().
+
 - internet_address_list_parse_string() has been replaced by
   internet_address_list_parse() and now takes a GMimeParserOptions argument.
 
diff --git a/TODO b/TODO
index 7a3ef3b..fd56e0d 100644
--- a/TODO
+++ b/TODO
@@ -6,8 +6,6 @@ tasks are presented in.
 GMime 3.0 Planning:
 ===================
 
-- Convert GMimeParam[List] into GObjects
-
 - Rewrite GMimeReferences into a GObject and split into its own file
 
 - Add g_mime_utils_header_decode_[text,phrase]() variants that also return charset/lang values?
diff --git a/docs/reference/changes-3.0.sgml b/docs/reference/changes-3.0.sgml
index e422f81..ce47eef 100644
--- a/docs/reference/changes-3.0.sgml
+++ b/docs/reference/changes-3.0.sgml
@@ -42,9 +42,11 @@
       <listitem><para><function>g_mime_object_new()</function> and 
<function>g_mime_object_new_with_type()</function> both now take a GMimeParserOptions 
argument.</para></listitem>
       <listitem><para><function>g_mime_param_new_from_string()</function> has been replaced by 
<function>g_mime_param_list_parse()</function> and now takes a GMimeParserOptions argument.</para></listitem>
       <listitem><para><function>g_mime_content_type_new_from_string()</function> has been replaced by 
<function>g_mime_content_type_parse()</function> and now takes a GMimeParserOptions 
argument.</para></listitem>
-      <listitem><para><function>g_mime_content_type_to_string()</function> has been replaced by 
<function>g_mime_content_type_get_mime_type()</function> and a new function has been introduced called 
<function>g_mime_content_type_encode()</function> that includes the encoded parameter list.</para></listitem>
+      <listitem><para><function>g_mime_content_type_to_string()</function> has been renamed to 
<function>g_mime_content_type_get_mime_type()</function> and a new function has been introduced called 
<function>g_mime_content_type_encode()</function> that includes the encoded parameter list.</para></listitem>
+      <listitem><para><function>g_mime_content_type_get_params()</function> has been renamed to 
<function>g_mime_content_type_get_parameters()</function>.</para></listitem>
       <listitem><para><function>g_mime_content_disposition_new_from_string()<function> has been replaced by 
<function>g_mime_content_disposition_parse()</function> and now takes a GMimeParserOptions 
argument.</para></listitem>
       <listitem><para><function>g_mime_content_disposition_to_string()</function> has been replaced by 
<function>g_mime_content_disposition_encode()</function>.</para></listitem>
+      <listitem><para><function>g_mime_content_disposition_get_params()</function> has been renamed to 
<function>g_mime_content_disposition_get_parameters()</function>.</para></listitem>
       <listitem><para><function>internet_address_list_parse_string()</function> has been replaced by 
<function>internet_address_list_parse()</function> and now takes a GMimeParserOptions 
argument.</para></listitem>
       <listitem><para>GMimeHeaderIter has been dropped in favour of a more direct way of iterating over a 
GMimeHeaderList using int indexes.</para></listitem>
       <listitem><para><function>g_mime_stream_write_to_stream()</function>, 
<function>g_mime_stream_writev()</function>, and <function>g_mime_stream_printf()</function> now return a 
gint64.</para></listitem>
diff --git a/docs/reference/gmime-sections.txt b/docs/reference/gmime-sections.txt
index 9daef90..73dfe95 100644
--- a/docs/reference/gmime-sections.txt
+++ b/docs/reference/gmime-sections.txt
@@ -581,7 +581,6 @@ g_mime_param_get_encoding_method
 g_mime_param_set_encoding_method
 g_mime_param_list_new
 g_mime_param_list_parse
-g_mime_param_list_free
 g_mime_param_list_clear
 g_mime_param_list_length
 g_mime_param_list_set_parameter
@@ -590,6 +589,26 @@ g_mime_param_list_get_parameter_at
 g_mime_param_list_remove
 g_mime_param_list_remove_at
 g_mime_param_list_encode
+
+<SUBSECTION Private>
+g_mime_param_get_type
+g_mime_param_list_get_type
+
+<SUBSECTION Standard>
+GMIME_PARAM
+GMIME_IS_PARAM
+GMIME_TYPE_PARAM
+GMIME_PARAM_CLASS
+GMIME_IS_PARAM_CLASS
+GMIME_PARAM_GET_CLASS
+GMimeParamClass
+GMIME_PARAM_LIST
+GMIME_IS_PARAM_LIST
+GMIME_TYPE_PARAM_LIST
+GMIME_PARAM_LIST_CLASS
+GMIME_IS_PARAM_LIST_CLASS
+GMIME_PARAM_LIST_GET_CLASS
+GMimeParamListClass
 </SECTION>
 
 <SECTION>
diff --git a/docs/reference/gmime.hierarchy b/docs/reference/gmime.hierarchy
index c3e2821..e37ccc4 100644
--- a/docs/reference/gmime.hierarchy
+++ b/docs/reference/gmime.hierarchy
@@ -9,8 +9,12 @@ GObject
       GMimeMultipartEncrypted
       GMimeMultipartSigned
     GMimeMessagePart
+  GMimeParam
+  GMimeParamList
   GMimeContentType
   GMimeContentDisposition
+  GMimeHeader
+  GMimeHeaderList
   InternetAddress
     InternetAddressGroup
     InternetAddressMailbox
@@ -44,6 +48,7 @@ GObject
     GMimeStreamFile
     GMimeStreamFilter
     GMimeStreamFs
+    GMimeStreamGIO
     GMimeStreamMem
     GMimeStreamMmap
     GMimeStreamNull
diff --git a/examples/imap-example.c b/examples/imap-example.c
index d64bb1c..8b28866 100644
--- a/examples/imap-example.c
+++ b/examples/imap-example.c
@@ -95,7 +95,7 @@ write_part_bodystructure (GMimeObject *part, FILE *fp)
                fputs ("\"\"", fp);
        
        /* Content-Type params */
-       params = g_mime_content_type_get_params (content_type);
+       params = g_mime_content_type_get_parameters (content_type);
        if ((n = g_mime_param_list_length (params)) > 0) {
                fputc ('(', fp);
                for (i = 0; i < n; i++) {
@@ -210,7 +210,7 @@ write_part_bodystructure (GMimeObject *part, FILE *fp)
                if (disposition) {
                        fprintf (fp, "\"%s\" ", g_mime_content_disposition_get_disposition (disposition));
                        
-                       params = g_mime_content_disposition_get_params (disposition);
+                       params = g_mime_content_disposition_get_parameters (disposition);
                        if ((n = g_mime_param_list_length (params)) > 0) {
                                fputc ('(', fp);
                                for (i = 0; i < n; i++) {
@@ -717,11 +717,11 @@ bodystruct_free (struct _bodystruct *node)
                g_free (node->content.type);
                g_free (node->content.subtype);
                if (node->content.params)
-                       g_mime_param_list_free (node->content.params);
+                       g_object_unref (node->content.params);
                
                g_free (node->disposition.type);
                if (node->disposition.params)
-                       g_mime_param_list_free (node->disposition.params);
+                       g_object_unref (node->disposition.params);
                
                g_free (node->encoding);
                
diff --git a/gmime/gmime-content-type.c b/gmime/gmime-content-type.c
index 89016b6..4d822cb 100644
--- a/gmime/gmime-content-type.c
+++ b/gmime/gmime-content-type.c
@@ -114,8 +114,8 @@ g_mime_content_type_finalize (GObject *object)
 {
        GMimeContentType *content_type = (GMimeContentType *) object;
        
-       g_mime_param_list_free (content_type->params);
        g_mime_event_free (content_type->changed);
+       g_object_unref (content_type->params);
        g_free (content_type->subtype);
        g_free (content_type->type);
        
@@ -208,7 +208,7 @@ g_mime_content_type_parse (GMimeParserOptions *options, const char *str)
        
        if (*inptr++ == ';' && *inptr && (params = g_mime_param_list_parse (options, inptr))) {
                g_mime_event_add (params->changed, (GMimeEventCallback) param_list_changed, content_type);
-               g_mime_param_list_free (content_type->params);
+               g_object_unref (content_type->params);
                content_type->params = params;
        }
        
@@ -394,7 +394,7 @@ g_mime_content_type_get_media_subtype (GMimeContentType *content_type)
 
 
 /**
- * g_mime_content_type_get_params:
+ * g_mime_content_type_get_parameters:
  * @content_type: a #GMimeContentType
  *
  * Gets the Content-Type's parameter list.
@@ -402,7 +402,7 @@ g_mime_content_type_get_media_subtype (GMimeContentType *content_type)
  * Returns: the Content-Type's parameter list.
  **/
 GMimeParamList *
-g_mime_content_type_get_params (GMimeContentType *content_type)
+g_mime_content_type_get_parameters (GMimeContentType *content_type)
 {
        g_return_val_if_fail (GMIME_IS_CONTENT_TYPE (content_type), NULL);
        
diff --git a/gmime/gmime-content-type.h b/gmime/gmime-content-type.h
index 67a91ef..983a54b 100644
--- a/gmime/gmime-content-type.h
+++ b/gmime/gmime-content-type.h
@@ -80,7 +80,7 @@ const char *g_mime_content_type_get_media_type (GMimeContentType *content_type);
 void g_mime_content_type_set_media_subtype (GMimeContentType *content_type, const char *subtype);
 const char *g_mime_content_type_get_media_subtype (GMimeContentType *content_type);
 
-GMimeParamList *g_mime_content_type_get_params (GMimeContentType *content_type);
+GMimeParamList *g_mime_content_type_get_parameters (GMimeContentType *content_type);
 
 void g_mime_content_type_set_parameter (GMimeContentType *content_type, const char *name, const char *value);
 const char *g_mime_content_type_get_parameter (GMimeContentType *content_type, const char *name);
diff --git a/gmime/gmime-disposition.c b/gmime/gmime-disposition.c
index 85e1fd5..6ab38d9 100644
--- a/gmime/gmime-disposition.c
+++ b/gmime/gmime-disposition.c
@@ -102,8 +102,8 @@ g_mime_content_disposition_finalize (GObject *object)
 {
        GMimeContentDisposition *disposition = (GMimeContentDisposition *) object;
        
-       g_mime_param_list_free (disposition->params);
        g_mime_event_free (disposition->changed);
+       g_object_unref (disposition->params);
        g_free (disposition->disposition);
        
        G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -170,7 +170,7 @@ g_mime_content_disposition_parse (GMimeParserOptions *options, const char *str)
        /* parse the parameters, if any */
        if (*inptr++ == ';' && *inptr && (params = g_mime_param_list_parse (options, inptr))) {
                g_mime_event_add (params->changed, (GMimeEventCallback) param_list_changed, disposition);
-               g_mime_param_list_free (disposition->params);
+               g_object_unref (disposition->params);
                disposition->params = params;
        }
        
@@ -223,7 +223,7 @@ g_mime_content_disposition_get_disposition (GMimeContentDisposition *disposition
 
 
 /**
- * g_mime_content_disposition_get_params:
+ * g_mime_content_disposition_get_parameters:
  * @disposition: a #GMimeContentDisposition object
  *
  * Gets the Content-Disposition parameter list.
@@ -231,7 +231,7 @@ g_mime_content_disposition_get_disposition (GMimeContentDisposition *disposition
  * Returns: the Content-Disposition's parameter list.
  **/
 GMimeParamList *
-g_mime_content_disposition_get_params (GMimeContentDisposition *disposition)
+g_mime_content_disposition_get_parameters (GMimeContentDisposition *disposition)
 {
        g_return_val_if_fail (GMIME_IS_CONTENT_DISPOSITION (disposition), NULL);
        
diff --git a/gmime/gmime-disposition.h b/gmime/gmime-disposition.h
index 3e55c33..6007c76 100644
--- a/gmime/gmime-disposition.h
+++ b/gmime/gmime-disposition.h
@@ -87,7 +87,7 @@ GMimeContentDisposition *g_mime_content_disposition_parse (GMimeParserOptions *o
 void g_mime_content_disposition_set_disposition (GMimeContentDisposition *disposition, const char *value);
 const char *g_mime_content_disposition_get_disposition (GMimeContentDisposition *disposition);
 
-GMimeParamList *g_mime_content_disposition_get_params (GMimeContentDisposition *disposition);
+GMimeParamList *g_mime_content_disposition_get_parameters (GMimeContentDisposition *disposition);
 
 void g_mime_content_disposition_set_parameter (GMimeContentDisposition *disposition,
                                               const char *name, const char *value);
diff --git a/gmime/gmime-header.c b/gmime/gmime-header.c
index 5c72238..59f96b1 100644
--- a/gmime/gmime-header.c
+++ b/gmime/gmime-header.c
@@ -48,7 +48,7 @@
 
 
 static void g_mime_header_class_init (GMimeHeaderClass *klass);
-static void g_mime_header_init (GMimeHeader *cert, GMimeHeaderClass *klass);
+static void g_mime_header_init (GMimeHeader *header, GMimeHeaderClass *klass);
 static void g_mime_header_finalize (GObject *object);
 
 static GObjectClass *parent_class = NULL;
@@ -318,6 +318,18 @@ g_mime_header_write_to_stream (GMimeHeaderList *headers, GMimeHeader *header, GM
 }
 
 
+static void
+header_changed (GMimeHeader *header, gpointer user_args, GMimeHeaderList *list)
+{
+       GMimeHeaderListChangedEventArgs args;
+       
+       args.action = GMIME_HEADER_LIST_CHANGED_ACTION_CHANGED;
+       args.header = header;
+       
+       g_mime_event_emit (list->changed, &args);
+}
+
+
 static void g_mime_header_list_class_init (GMimeHeaderListClass *klass);
 static void g_mime_header_list_init (GMimeHeaderList *list, GMimeHeaderListClass *klass);
 static void g_mime_header_list_finalize (GObject *object);
@@ -377,10 +389,14 @@ static void
 g_mime_header_list_finalize (GObject *object)
 {
        GMimeHeaderList *headers = (GMimeHeaderList *) object;
+       GMimeHeader *header;
        guint i;
        
-       for (i = 0; i < headers->array->len; i++)
-               g_object_unref (headers->array->pdata[i]);
+       for (i = 0; i < headers->array->len; i++) {
+               header = (GMimeHeader *) headers->array->pdata[i];
+               g_mime_event_remove (header->changed, (GMimeEventCallback) header_changed, headers);
+               g_object_unref (header);
+       }
        
        g_ptr_array_free (headers->array, TRUE);
        
@@ -393,18 +409,6 @@ g_mime_header_list_finalize (GObject *object)
 }
 
 
-static void
-header_changed (GMimeHeader *header, gpointer user_args, GMimeHeaderList *list)
-{
-       GMimeHeaderListChangedEventArgs args;
-       
-       args.action = GMIME_HEADER_LIST_CHANGED_ACTION_CHANGED;
-       args.header = header;
-       
-       g_mime_event_emit (list->changed, &args);
-}
-
-
 /**
  * g_mime_header_list_new:
  * @options: a #GMimeParserOptions
diff --git a/gmime/gmime-param.c b/gmime/gmime-param.c
index 55d08c8..f56e99a 100644
--- a/gmime/gmime-param.c
+++ b/gmime/gmime-param.c
@@ -65,41 +65,62 @@ static unsigned char tohex[16] = {
 };
 
 
-/**
- * g_mime_param_new:
- *
- * Creates a new #GMimeParam.
- *
- * Returns: a new #GMimeParam.
- **/
-static GMimeParam *
-g_mime_param_new (void)
+static void g_mime_param_class_init (GMimeParamClass *klass);
+static void g_mime_param_init (GMimeParam *cert, GMimeParamClass *klass);
+static void g_mime_param_finalize (GObject *object);
+
+static GObjectClass *parent_class = NULL;
+
+
+GType
+g_mime_param_get_type (void)
 {
-       GMimeParam *param;
+       static GType type = 0;
+       
+       if (!type) {
+               static const GTypeInfo info = {
+                       sizeof (GMimeParamClass),
+                       NULL, /* base_class_init */
+                       NULL, /* base_class_finalize */
+                       (GClassInitFunc) g_mime_param_class_init,
+                       NULL, /* class_finalize */
+                       NULL, /* class_data */
+                       sizeof (GMimeParam),
+                       0,    /* n_preallocs */
+                       (GInstanceInitFunc) g_mime_param_init,
+               };
+               
+               type = g_type_register_static (G_TYPE_OBJECT, "GMimeParam", &info, 0);
+       }
        
-       param = g_slice_new (GMimeParam);
-       param->changed = g_mime_event_new (param);
+       return type;
+}
+
+static void
+g_mime_param_class_init (GMimeParamClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       
+       parent_class = g_type_class_ref (G_TYPE_OBJECT);
+       
+       object_class->finalize = g_mime_param_finalize;
+}
+
+static void
+g_mime_param_init (GMimeParam *param, GMimeParamClass *klass)
+{
        param->method = GMIME_PARAM_ENCODING_METHOD_DEFAULT;
+       param->changed = g_mime_event_new (param);
        param->charset = NULL;
        param->value = NULL;
        param->name = NULL;
        param->lang = NULL;
-       
-       return param;
 }
 
-
-/**
- * g_mime_param_free:
- * @param: a #GMimeParam
- *
- * Releases all memory used by this mime param back to the Operating
- * System.
- **/
 static void
-g_mime_param_free (GMimeParam *param)
+g_mime_param_finalize (GObject *object)
 {
-       g_return_if_fail (param != NULL);
+       GMimeParam *param = (GMimeParam *) object;
        
        g_mime_event_free (param->changed);
        g_free (param->charset);
@@ -107,7 +128,21 @@ g_mime_param_free (GMimeParam *param)
        g_free (param->name);
        g_free (param->lang);
        
-       g_slice_free (GMimeParam, param);
+       G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+
+/**
+ * g_mime_param_new:
+ *
+ * Creates a new #GMimeParam.
+ *
+ * Returns: a new #GMimeParam.
+ **/
+static GMimeParam *
+g_mime_param_new (void)
+{
+       return g_object_newv (GMIME_TYPE_PARAM, 0, NULL);
 }
 
 
@@ -122,7 +157,7 @@ g_mime_param_free (GMimeParam *param)
 const char *
 g_mime_param_get_name (GMimeParam *param)
 {
-       g_return_val_if_fail (param != NULL, NULL);
+       g_return_val_if_fail (GMIME_IS_PARAM (param), NULL);
        
        return param->name;
 }
@@ -139,7 +174,7 @@ g_mime_param_get_name (GMimeParam *param)
 const char *
 g_mime_param_get_value (GMimeParam *param)
 {
-       g_return_val_if_fail (param != NULL, NULL);
+       g_return_val_if_fail (GMIME_IS_PARAM (param), NULL);
        
        return param->value;
 }
@@ -155,7 +190,7 @@ g_mime_param_get_value (GMimeParam *param)
 void
 g_mime_param_set_value (GMimeParam *param, const char *value)
 {
-       g_return_if_fail (param != NULL);
+       g_return_if_fail (GMIME_IS_PARAM (param));
        g_return_if_fail (value != NULL);
        
        g_free (param->value);
@@ -176,7 +211,7 @@ g_mime_param_set_value (GMimeParam *param, const char *value)
 const char *
 g_mime_param_get_charset (GMimeParam *param)
 {
-       g_return_val_if_fail (param != NULL, NULL);
+       g_return_val_if_fail (GMIME_IS_PARAM (param), NULL);
        
        return param->charset;
 }
@@ -192,7 +227,7 @@ g_mime_param_get_charset (GMimeParam *param)
 void
 g_mime_param_set_charset (GMimeParam *param, const char *charset)
 {
-       g_return_if_fail (param != NULL);
+       g_return_if_fail (GMIME_IS_PARAM (param));
        
        g_free (param->charset);
        param->charset = charset ? g_strdup (charset) : NULL;
@@ -212,7 +247,7 @@ g_mime_param_set_charset (GMimeParam *param, const char *charset)
 const char *
 g_mime_param_get_lang (GMimeParam *param)
 {
-       g_return_val_if_fail (param != NULL, NULL);
+       g_return_val_if_fail (GMIME_IS_PARAM (param), NULL);
        
        return param->lang;
 }
@@ -228,7 +263,7 @@ g_mime_param_get_lang (GMimeParam *param)
 void
 g_mime_param_set_lang (GMimeParam *param, const char *lang)
 {
-       g_return_if_fail (param != NULL);
+       g_return_if_fail (GMIME_IS_PARAM (param));
        
        g_free (param->lang);
        param->lang = lang ? g_strdup (lang) : NULL;
@@ -248,7 +283,7 @@ g_mime_param_set_lang (GMimeParam *param, const char *lang)
 GMimeParamEncodingMethod
 g_mime_param_get_encoding_method (GMimeParam *param)
 {
-       g_return_val_if_fail (param != NULL, GMIME_PARAM_ENCODING_METHOD_DEFAULT);
+       g_return_val_if_fail (GMIME_IS_PARAM (param), GMIME_PARAM_ENCODING_METHOD_DEFAULT);
        
        return param->method;
 }
@@ -264,7 +299,7 @@ g_mime_param_get_encoding_method (GMimeParam *param)
 void
 g_mime_param_set_encoding_method (GMimeParam *param, GMimeParamEncodingMethod method)
 {
-       g_return_if_fail (param != NULL);
+       g_return_if_fail (GMIME_IS_PARAM (param));
        
        param->method = method;
        
@@ -279,46 +314,87 @@ param_changed (GMimeParam *param, gpointer args, GMimeParamList *list)
 }
 
 
-/**
- * g_mime_param_list_new:
- *
- * Creates a new Content-Type or Content-Disposition parameter list.
- *
- * Returns: a new #GMimeParamList.
- **/
-GMimeParamList *
-g_mime_param_list_new (void)
+static void g_mime_param_list_class_init (GMimeParamListClass *klass);
+static void g_mime_param_list_init (GMimeParamList *list, GMimeParamListClass *klass);
+static void g_mime_param_list_finalize (GObject *object);
+
+
+static GObjectClass *list_parent_class = NULL;
+
+
+GType
+g_mime_param_list_get_type (void)
+{
+       static GType type = 0;
+       
+       if (!type) {
+               static const GTypeInfo info = {
+                       sizeof (GMimeParamListClass),
+                       NULL, /* base_class_init */
+                       NULL, /* base_class_finalize */
+                       (GClassInitFunc) g_mime_param_list_class_init,
+                       NULL, /* class_finalize */
+                       NULL, /* class_data */
+                       sizeof (GMimeParamList),
+                       0,    /* n_preallocs */
+                       (GInstanceInitFunc) g_mime_param_list_init,
+               };
+               
+               type = g_type_register_static (G_TYPE_OBJECT, "GMimeParamList", &info, 0);
+       }
+       
+       return type;
+}
+
+
+static void
+g_mime_param_list_class_init (GMimeParamListClass *klass)
 {
-       GMimeParamList *list;
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
        
-       list = g_slice_new (GMimeParamList);
-       list->changed = g_mime_event_new (list);
-       list->params = g_ptr_array_new ();
+       list_parent_class = g_type_class_ref (G_TYPE_OBJECT);
        
-       return list;
+       object_class->finalize = g_mime_param_list_finalize;
 }
 
+static void
+g_mime_param_list_init (GMimeParamList *list, GMimeParamListClass *klass)
+{
+       list->changed = g_mime_event_new (list);
+       list->array = g_ptr_array_new ();
+}
 
-/**
- * g_mime_param_list_free:
- * @list: a #GMimeParamList
- *
- * Frees the #GMimeParamList.
- **/
-void
-g_mime_param_list_free (GMimeParamList *list)
+static void
+g_mime_param_list_finalize (GObject *object)
 {
+       GMimeParamList *list = (GMimeParamList *) object;
+       GMimeParam *param;
        guint i;
        
-       g_return_if_fail (list != NULL);
-       
-       for (i = 0; i < list->params->len; i++)
-               g_mime_param_free (list->params->pdata[i]);
+       for (i = 0; i < list->array->len; i++) {
+               param = (GMimeParam *) list->array->pdata[i];
+               g_mime_event_remove (param->changed, (GMimeEventCallback) param_changed, list);
+               g_object_unref (param);
+       }
        
-       g_ptr_array_free (list->params, TRUE);
+       g_ptr_array_free (list->array, TRUE);
        g_mime_event_free (list->changed);
        
-       g_slice_free (GMimeParamList, list);
+       G_OBJECT_CLASS (list_parent_class)->finalize (object);
+}
+
+
+/**
+ * g_mime_param_list_new:
+ *
+ * Creates a new Content-Type or Content-Disposition parameter list.
+ *
+ * Returns: a new #GMimeParamList.
+ **/
+GMimeParamList *
+g_mime_param_list_new (void)
+{
+       return g_object_newv (GMIME_TYPE_PARAM_LIST, 0, NULL);
 }
 
 
@@ -333,9 +409,9 @@ g_mime_param_list_free (GMimeParamList *list)
 int
 g_mime_param_list_length (GMimeParamList *list)
 {
-       g_return_val_if_fail (list != NULL, -1);
+       g_return_val_if_fail (GMIME_IS_PARAM_LIST (list), -1);
        
-       return list->params->len;
+       return list->array->len;
 }
 
 
@@ -348,14 +424,18 @@ g_mime_param_list_length (GMimeParamList *list)
 void
 g_mime_param_list_clear (GMimeParamList *list)
 {
+       GMimeParam *param;
        guint i;
        
-       g_return_if_fail (list != NULL);
+       g_return_if_fail (GMIME_IS_PARAM_LIST (list));
        
-       for (i = 0; i < list->params->len; i++)
-               g_mime_param_free (list->params->pdata[i]);
+       for (i = 0; i < list->array->len; i++) {
+               param = (GMimeParam *) list->array->pdata[i];
+               g_mime_event_remove (param->changed, (GMimeEventCallback) param_changed, list);
+               g_object_unref (param);
+       }
        
-       g_ptr_array_set_size (list->params, 0);
+       g_ptr_array_set_size (list->array, 0);
        
        g_mime_event_emit (list->changed, NULL);
 }
@@ -374,7 +454,7 @@ static void
 g_mime_param_list_add (GMimeParamList *list, GMimeParam *param)
 {
        g_mime_event_add (param->changed, (GMimeEventCallback) param_changed, list);
-       g_ptr_array_add (list->params, param);
+       g_ptr_array_add (list->array, param);
 }
 
 
@@ -392,12 +472,12 @@ g_mime_param_list_set_parameter (GMimeParamList *list, const char *name, const c
        GMimeParam *param;
        guint i;
        
-       g_return_if_fail (list != NULL);
+       g_return_if_fail (GMIME_IS_PARAM_LIST (list));
        g_return_if_fail (name != NULL);
        g_return_if_fail (value != NULL);
        
-       for (i = 0; i < list->params->len; i++) {
-               param = list->params->pdata[i];
+       for (i = 0; i < list->array->len; i++) {
+               param = list->array->pdata[i];
                
                if (!g_ascii_strcasecmp (param->name, name)) {
                        g_mime_param_set_value (param, value);
@@ -430,11 +510,11 @@ g_mime_param_list_get_parameter (GMimeParamList *list, const char *name)
        GMimeParam *param;
        guint i;
        
-       g_return_val_if_fail (list != NULL, NULL);
+       g_return_val_if_fail (GMIME_IS_PARAM_LIST (list), NULL);
        g_return_val_if_fail (name != NULL, NULL);
        
-       for (i = 0; i < list->params->len; i++) {
-               param = list->params->pdata[i];
+       for (i = 0; i < list->array->len; i++) {
+               param = list->array->pdata[i];
                
                if (!g_ascii_strcasecmp (param->name, name))
                        return param;
@@ -456,13 +536,13 @@ g_mime_param_list_get_parameter (GMimeParamList *list, const char *name)
 GMimeParam *
 g_mime_param_list_get_parameter_at (GMimeParamList *list, int index)
 {
-       g_return_val_if_fail (list != NULL, NULL);
+       g_return_val_if_fail (GMIME_IS_PARAM_LIST (list), NULL);
        g_return_val_if_fail (index >= 0, NULL);
        
-       if ((guint) index >= list->params->len)
+       if ((guint) index >= list->array->len)
                return NULL;
        
-       return list->params->pdata[index];
+       return list->array->pdata[index];
 }
 
 
@@ -481,15 +561,16 @@ g_mime_param_list_remove (GMimeParamList *list, const char *name)
        GMimeParam *param;
        guint i;
        
-       g_return_val_if_fail (list != NULL, FALSE);
+       g_return_val_if_fail (GMIME_IS_PARAM_LIST (list), FALSE);
        g_return_val_if_fail (name != NULL, FALSE);
        
-       for (i = 0; i < list->params->len; i++) {
-               param = list->params->pdata[i];
+       for (i = 0; i < list->array->len; i++) {
+               param = list->array->pdata[i];
                
                if (!g_ascii_strcasecmp (param->name, name)) {
-                       g_ptr_array_remove_index (list->params, i);
-                       g_mime_param_free (param);
+                       g_mime_event_remove (param->changed, (GMimeEventCallback) param_changed, list);
+                       g_ptr_array_remove_index (list->array, i);
+                       g_object_unref (param);
                        return TRUE;
                }
        }
@@ -512,15 +593,16 @@ g_mime_param_list_remove_at (GMimeParamList *list, int index)
 {
        GMimeParam *param;
        
-       g_return_val_if_fail (list != NULL, FALSE);
+       g_return_val_if_fail (GMIME_IS_PARAM_LIST (list), FALSE);
        g_return_val_if_fail (index >= 0, FALSE);
        
-       if ((guint) index >= list->params->len)
+       if ((guint) index >= list->array->len)
                return FALSE;
        
-       param = list->params->pdata[index];
-       g_ptr_array_remove_index (list->params, index);
-       g_mime_param_free (param);
+       param = list->array->pdata[index];
+       g_mime_event_remove (param->changed, (GMimeEventCallback) param_changed, list);
+       g_ptr_array_remove_index (list->array, index);
+       g_object_unref (param);
        
        return TRUE;
 }
@@ -641,10 +723,10 @@ g_mime_param_list_encode (GMimeParamList *list, gboolean fold, GString *str)
        guint count, i;
        int used;
        
-       g_return_if_fail (list != NULL);
+       g_return_if_fail (GMIME_IS_PARAM_LIST (list));
        g_return_if_fail (str != NULL);
        
-       count = list->params->len;
+       count = list->array->len;
        used = str->len;
        
        for (i = 0; i < count; i++) {
@@ -656,7 +738,7 @@ g_mime_param_list_encode (GMimeParamList *list, gboolean fold, GString *str)
                GMimeParam *param;
                int quote = 0;
                
-               param = (GMimeParam *) list->params->pdata[i];
+               param = (GMimeParam *) list->array->pdata[i];
                
                if (!param->value)
                        continue;
diff --git a/gmime/gmime-param.h b/gmime/gmime-param.h
index 73a5cb5..b589e62 100644
--- a/gmime/gmime-param.h
+++ b/gmime/gmime-param.h
@@ -23,12 +23,30 @@
 #define __GMIME_PARAM_H__
 
 #include <glib.h>
+#include <glib-object.h>
 #include <gmime/gmime-parser-options.h>
 
 G_BEGIN_DECLS
 
+#define GMIME_TYPE_PARAM                  (g_mime_param_get_type ())
+#define GMIME_PARAM(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMIME_TYPE_PARAM, GMimeParam))
+#define GMIME_PARAM_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GMIME_TYPE_PARAM, 
GMimeParamClass))
+#define GMIME_IS_PARAM(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GMIME_TYPE_PARAM))
+#define GMIME_IS_PARAM_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GMIME_TYPE_PARAM))
+#define GMIME_PARAM_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GMIME_TYPE_PARAM, 
GMimeParamClass))
+
+#define GMIME_TYPE_PARAM_LIST             (g_mime_param_list_get_type ())
+#define GMIME_PARAM_LIST(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMIME_TYPE_PARAM_LIST, 
GMimeParamList))
+#define GMIME_PARAM_LIST_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GMIME_TYPE_PARAM_LIST, 
GMimeParamListClass))
+#define GMIME_IS_PARAM_LIST(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GMIME_TYPE_PARAM_LIST))
+#define GMIME_IS_PARAM_LIST_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GMIME_TYPE_PARAM_LIST))
+#define GMIME_PARAM_LIST_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GMIME_TYPE_PARAM_LIST, 
GMimeParamListClass))
+
 typedef struct _GMimeParam GMimeParam;
+typedef struct _GMimeParamClass GMimeParamClass;
+
 typedef struct _GMimeParamList GMimeParamList;
+typedef struct _GMimeParamListClass GMimeParamListClass;
 
 
 /**
@@ -61,6 +79,8 @@ typedef enum {
  * A parameter name/value pair as used in the Content-Type and Content-Disposition headers.
  **/
 struct _GMimeParam {
+       GObject parent_object;
+       
        GMimeParamEncodingMethod method;
        char *charset, *lang;
        char *name, *value;
@@ -69,6 +89,14 @@ struct _GMimeParam {
        gpointer changed;
 };
 
+struct _GMimeParamClass {
+       GObjectClass parent_class;
+       
+};
+
+
+GType g_mime_param_get_type (void);
+
 const char *g_mime_param_get_name (GMimeParam *param);
 
 const char *g_mime_param_get_value (GMimeParam *param);
@@ -91,13 +119,21 @@ void g_mime_param_set_encoding_method (GMimeParam *param, GMimeParamEncodingMeth
  **/
 struct _GMimeParamList {
        /* < private > */
-       GPtrArray *params;
+       GObject parent_object;
+       GPtrArray *array;
        gpointer changed;
 };
 
+struct _GMimeParamListClass {
+       GObjectClass parent_class;
+       
+};
+
+
+GType g_mime_param_list_get_type (void);
+
 GMimeParamList *g_mime_param_list_new (void);
 GMimeParamList *g_mime_param_list_parse (GMimeParserOptions *options, const char *str);
-void g_mime_param_list_free (GMimeParamList *list);
 
 int g_mime_param_list_length (GMimeParamList *list);
 
diff --git a/gmime/gmime.c b/gmime/gmime.c
index 6f17d4e..2f1da33 100644
--- a/gmime/gmime.c
+++ b/gmime/gmime.c
@@ -176,7 +176,9 @@ g_mime_init (void)
        internet_address_group_get_type ();
        internet_address_mailbox_get_type ();
        
+       g_mime_param_get_type ();
        g_mime_header_get_type ();
+       g_mime_param_list_get_type ();
        g_mime_header_list_get_type ();
        g_mime_content_type_get_type ();
        g_mime_content_disposition_get_type ();
diff --git a/tests/test-headers.c b/tests/test-headers.c
index affd2cd..3c03748 100644
--- a/tests/test-headers.c
+++ b/tests/test-headers.c
@@ -275,7 +275,7 @@ test_header_sync (void)
                        throw (exception_new ("content-type header had unexpected value after setting a 
param"));
                
                /* now change the content-type's parameters by clearing the params */
-               params = g_mime_content_type_get_params (type);
+               params = g_mime_content_type_get_parameters (type);
                g_mime_param_list_clear (params);
                if (!(value = g_mime_object_get_header (object, "Content-Type")))
                        throw (exception_new ("content-type header was unexpectedly null after clearing 
params"));
@@ -322,7 +322,7 @@ test_header_sync (void)
                        throw (exception_new ("content-disposition header had unexpected value after setting 
a param"));
                
                /* now change the content-disposition's parameters by clearing the params */
-               params = g_mime_content_disposition_get_params (disposition);
+               params = g_mime_content_disposition_get_parameters (disposition);
                g_mime_param_list_clear (params);
                if (!(value = g_mime_object_get_header (object, "Content-Disposition")))
                        throw (exception_new ("content-disposition header was unexpectedly null after setting 
params"));
diff --git a/tests/test-mime.c b/tests/test-mime.c
index 08f4c13..79e31ba 100644
--- a/tests/test-mime.c
+++ b/tests/test-mime.c
@@ -566,7 +566,7 @@ test_rfc2184 (GMimeParserOptions *options)
                n = str->len;
                
                g_mime_param_list_encode (params, TRUE, str);
-               g_mime_param_list_free (params);
+               g_object_unref (params);
                params = NULL;
                
                testsuite_check ("rfc2184[%u]", i);
@@ -606,7 +606,7 @@ test_rfc2184 (GMimeParserOptions *options)
                } finally;
                
                if (params != NULL)
-                       g_mime_param_list_free (params);
+                       g_object_unref (params);
                
                g_string_free (str, TRUE);
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]