[evolution-data-server/wip/camel-more-gobject] Port CamelMedium to CamelNameValueArray



commit 95e656b300e04dfc08cebec477fe17b839600676
Author: Corentin Noël <corentin elementary io>
Date:   Mon Oct 31 19:36:19 2016 +0100

    Port CamelMedium to CamelNameValueArray

 src/camel/camel-medium.c         |   42 +++++++------------------------------
 src/camel/camel-medium.h         |   28 ++++++++++---------------
 src/camel/camel-mime-message.c   |    4 +-
 src/camel/camel-mime-part.c      |   25 ++++++----------------
 src/camel/camel-search-private.c |   22 +++++++++++--------
 src/camel/camel-service.c        |   10 +++++---
 6 files changed, 47 insertions(+), 84 deletions(-)
---
diff --git a/src/camel/camel-medium.c b/src/camel/camel-medium.c
index dc0d5d0..7a705b3 100644
--- a/src/camel/camel-medium.c
+++ b/src/camel/camel-medium.c
@@ -178,7 +178,7 @@ camel_medium_init (CamelMedium *medium)
 void
 camel_medium_add_header (CamelMedium *medium,
                          const gchar *name,
-                         gconstpointer value)
+                         const gchar *value)
 {
        CamelMediumClass *class;
 
@@ -205,7 +205,7 @@ camel_medium_add_header (CamelMedium *medium,
 void
 camel_medium_set_header (CamelMedium *medium,
                          const gchar *name,
-                         gconstpointer value)
+                         const gchar *value)
 {
        CamelMediumClass *class;
 
@@ -258,9 +258,9 @@ camel_medium_remove_header (CamelMedium *medium,
  * instance of the header.  For multi-occuring headers, use
  * :get_headers().
  *
- * Returns: (transfer none) (nullable): the value of the named header, or %NULL
+ * Returns: (nullable): the value of the named header, or %NULL
  **/
-gconstpointer
+const gchar *
 camel_medium_get_header (CamelMedium *medium,
                          const gchar *name)
 {
@@ -279,15 +279,12 @@ camel_medium_get_header (CamelMedium *medium,
  * camel_medium_get_headers:
  * @medium: a #CamelMedium object
  *
- * Gets an array of all header name/value pairs (as
- * CamelMediumHeader structures). The values will be decoded
- * to UTF-8 for any headers that are recognized by Camel. The
- * caller should not modify the returned data.
+ * Gets an array of all header name/value pairs. The values will be
+ * decoded to UTF-8 for any headers that are recognized by Camel.
  *
- * Returns: (element-type CamelMediumHeader) (transfer full): the array of
- * headers, which must be freed with camel_medium_free_headers().
+ * Returns: (transfer full): the array of headers, which must be freed with camel_name_value_array_free().
  **/
-GArray *
+CamelNameValueArray *
 camel_medium_get_headers (CamelMedium *medium)
 {
        CamelMediumClass *class;
@@ -301,29 +298,6 @@ camel_medium_get_headers (CamelMedium *medium)
 }
 
 /**
- * camel_medium_free_headers:
- * @medium: a #CamelMedium object
- * @headers: (element-type CamelMediumHeader): an array of headers returned
- * from camel_medium_get_headers()
- *
- * Frees @headers.
- **/
-void
-camel_medium_free_headers (CamelMedium *medium,
-                           GArray *headers)
-{
-       CamelMediumClass *class;
-
-       g_return_if_fail (CAMEL_IS_MEDIUM (medium));
-       g_return_if_fail (headers != NULL);
-
-       class = CAMEL_MEDIUM_GET_CLASS (medium);
-       g_return_if_fail (class->free_headers != NULL);
-
-       class->free_headers (medium, headers);
-}
-
-/**
  * camel_medium_get_content:
  * @medium: a #CamelMedium object
  *
diff --git a/src/camel/camel-medium.h b/src/camel/camel-medium.h
index 3d83723..c3eef65 100644
--- a/src/camel/camel-medium.h
+++ b/src/camel/camel-medium.h
@@ -27,6 +27,7 @@
 #define CAMEL_MEDIUM_H
 
 #include <camel/camel-data-wrapper.h>
+#include <camel/camel-name-value-array.h>
 
 /* Standard GObject macros */
 #define CAMEL_TYPE_MEDIUM \
@@ -53,11 +54,6 @@ typedef struct _CamelMedium CamelMedium;
 typedef struct _CamelMediumClass CamelMediumClass;
 typedef struct _CamelMediumPrivate CamelMediumPrivate;
 
-typedef struct {
-       const gchar *name;
-       const gchar *value;
-} CamelMediumHeader;
-
 struct _CamelMedium {
        CamelDataWrapper parent;
        CamelMediumPrivate *priv;
@@ -68,17 +64,16 @@ struct _CamelMediumClass {
 
        void            (*add_header)           (CamelMedium *medium,
                                                 const gchar *name,
-                                                gconstpointer value);
+                                                const gchar *value);
        void            (*set_header)           (CamelMedium *medium,
                                                 const gchar *name,
-                                                gconstpointer value);
+                                                const gchar *value);
        void            (*remove_header)        (CamelMedium *medium,
                                                 const gchar *name);
-       gconstpointer   (*get_header)           (CamelMedium *medium,
+       const gchar *   (*get_header)           (CamelMedium *medium,
                                                 const gchar *name);
-       GArray *        (*get_headers)          (CamelMedium *medium);
-       void            (*free_headers)         (CamelMedium *medium,
-                                                GArray *headers);
+       CamelNameValueArray *
+                       (*get_headers)          (CamelMedium *medium);
        CamelDataWrapper *
                        (*get_content)          (CamelMedium *medium);
        void            (*set_content)          (CamelMedium *medium,
@@ -88,17 +83,16 @@ struct _CamelMediumClass {
 GType          camel_medium_get_type           (void);
 void           camel_medium_add_header         (CamelMedium *medium,
                                                 const gchar *name,
-                                                gconstpointer value);
+                                                const gchar *value);
 void           camel_medium_set_header         (CamelMedium *medium,
                                                 const gchar *name,
-                                                gconstpointer value);
+                                                const gchar *value);
 void           camel_medium_remove_header      (CamelMedium *medium,
                                                 const gchar *name);
-gconstpointer  camel_medium_get_header         (CamelMedium *medium,
+const gchar *  camel_medium_get_header         (CamelMedium *medium,
                                                 const gchar *name);
-GArray *       camel_medium_get_headers        (CamelMedium *medium);
-void           camel_medium_free_headers       (CamelMedium *medium,
-                                                GArray *headers);
+CamelNameValueArray *
+               camel_medium_get_headers        (CamelMedium *medium);
 CamelDataWrapper *
                camel_medium_get_content        (CamelMedium *medium);
 void           camel_medium_set_content        (CamelMedium *medium,
diff --git a/src/camel/camel-mime-message.c b/src/camel/camel-mime-message.c
index c7ea3a0..2dc1a7e 100644
--- a/src/camel/camel-mime-message.c
+++ b/src/camel/camel-mime-message.c
@@ -271,7 +271,7 @@ mime_message_write_to_output_stream_sync (CamelDataWrapper *data_wrapper,
 static void
 mime_message_add_header (CamelMedium *medium,
                          const gchar *name,
-                         gconstpointer value)
+                         const gchar *value)
 {
        CamelMediumClass *medium_class;
 
@@ -287,7 +287,7 @@ mime_message_add_header (CamelMedium *medium,
 static void
 mime_message_set_header (CamelMedium *medium,
                          const gchar *name,
-                         gconstpointer value)
+                         const gchar *value)
 {
        process_header (medium, name, value);
 
diff --git a/src/camel/camel-mime-part.c b/src/camel/camel-mime-part.c
index 82e63e5..8c5350c 100644
--- a/src/camel/camel-mime-part.c
+++ b/src/camel/camel-mime-part.c
@@ -462,7 +462,7 @@ mime_part_finalize (GObject *object)
 static void
 mime_part_add_header (CamelMedium *medium,
                       const gchar *name,
-                      gconstpointer value)
+                      const gchar *value)
 {
        CamelMimePart *part = CAMEL_MIME_PART (medium);
 
@@ -480,7 +480,7 @@ mime_part_add_header (CamelMedium *medium,
 static void
 mime_part_set_header (CamelMedium *medium,
                       const gchar *name,
-                      gconstpointer value)
+                      const gchar *value)
 {
        CamelMimePart *part = CAMEL_MIME_PART (medium);
 
@@ -498,7 +498,7 @@ mime_part_remove_header (CamelMedium *medium,
        camel_header_raw_remove (&part->headers, name);
 }
 
-static gconstpointer
+static const gchar *
 mime_part_get_header (CamelMedium *medium,
                       const gchar *name)
 {
@@ -514,32 +514,22 @@ mime_part_get_header (CamelMedium *medium,
        return value;
 }
 
-static GArray *
+static CamelNameValueArray *
 mime_part_get_headers (CamelMedium *medium)
 {
        CamelMimePart *part = (CamelMimePart *) medium;
-       GArray *headers;
-       CamelMediumHeader header;
+       CamelNameValueArray *headers;
        CamelHeaderRaw *h;
 
-       headers = g_array_new (FALSE, FALSE, sizeof (CamelMediumHeader));
+       headers = camel_name_value_array_new ();
        for (h = part->headers; h; h = h->next) {
-               header.name = h->name;
-               header.value = h->value;
-               g_array_append_val (headers, header);
+               camel_name_value_array_append (headers, h->name, h->value);
        }
 
        return headers;
 }
 
 static void
-mime_part_free_headers (CamelMedium *medium,
-                        GArray *headers)
-{
-       g_array_free (headers, TRUE);
-}
-
-static void
 mime_part_set_content (CamelMedium *medium,
                        CamelDataWrapper *content)
 {
@@ -1046,7 +1036,6 @@ camel_mime_part_class_init (CamelMimePartClass *class)
        medium_class->remove_header = mime_part_remove_header;
        medium_class->get_header = mime_part_get_header;
        medium_class->get_headers = mime_part_get_headers;
-       medium_class->free_headers = mime_part_free_headers;
        medium_class->set_content = mime_part_set_content;
 
        data_wrapper_class = CAMEL_DATA_WRAPPER_CLASS (class);
diff --git a/src/camel/camel-search-private.c b/src/camel/camel-search-private.c
index ced34e9..335b388 100644
--- a/src/camel/camel-search-private.c
+++ b/src/camel/camel-search-private.c
@@ -831,9 +831,9 @@ camel_search_get_all_headers_decoded (CamelMimeMessage *message)
 {
        CamelMedium *medium;
        GString *str;
-       GArray *headers;
+       CamelNameValueArray *headers;
        const gchar *default_charset;
-       guint ii;
+       guint ii, length;
 
        g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), NULL);
 
@@ -845,19 +845,23 @@ camel_search_get_all_headers_decoded (CamelMimeMessage *message)
        default_charset = camel_search_get_default_charset_from_message (message);
        str = g_string_new ("");
 
-       for (ii = 0; ii < headers->len; ii++) {
-               CamelMediumHeader *header;
+       length = camel_name_value_array_get_length (headers);
+       for (ii = 0; ii < length; ii++) {
                gchar *content;
+               const gchar *header_name = NULL;
+               const gchar *header_value = NULL;
 
-               header = &g_array_index (headers, CamelMediumHeader, ii);
-               if (!header->value)
+               if (!camel_name_value_array_get (headers, ii, &header_name, &header_value))
                        continue;
 
-               content = camel_search_get_header_decoded (header->name, header->value, default_charset);
+               if (!header_name || !header_value)
+                       continue;
+
+               content = camel_search_get_header_decoded (header_name, header_value, default_charset);
                if (!content)
                        continue;
 
-               g_string_append (str, header->name);
+               g_string_append (str, header_name);
                if (isspace (content[0]))
                        g_string_append (str, ":");
                else
@@ -868,7 +872,7 @@ camel_search_get_all_headers_decoded (CamelMimeMessage *message)
                g_free (content);
        }
 
-       camel_medium_free_headers (medium, headers);
+       camel_name_value_array_free (headers);
 
        return g_string_free (str, FALSE);
 }
diff --git a/src/camel/camel-service.c b/src/camel/camel-service.c
index bbc4e99..0f1b093 100644
--- a/src/camel/camel-service.c
+++ b/src/camel/camel-service.c
@@ -2389,8 +2389,9 @@ camel_service_query_auth_types_finish (CamelService *service,
 void
 camel_service_auth_type_free (CamelServiceAuthType *service_auth_type)
 {
-       // This is needed for the introspection.
-       // In the reality, each CamelSasl subclass has a static reference of it.
+       /* This is needed for the introspection.
+        * In the reality, each CamelSasl subclass has a static reference of it.
+        */
 }
 
 /**
@@ -2405,7 +2406,8 @@ camel_service_auth_type_free (CamelServiceAuthType *service_auth_type)
 CamelServiceAuthType *
 camel_service_auth_type_copy           (const CamelServiceAuthType* service_auth_type)
 {
-       // This is needed for the introspection.
-       // In the reality, each CamelSasl subclass has a static reference of it.
+       /* This is needed for the introspection.
+        * In the reality, each CamelSasl subclass has a static reference of it.
+        */
        return service_auth_type;
 }


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