[gmime] Renamed g_mime_header_list_[get, set]() to g_mime_header_list_[get, set]_value()



commit e2e8d7e634b7d57f01b406fa7cfe587f54f8e0e3
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date:   Sat Mar 11 21:43:21 2017 -0500

    Renamed g_mime_header_list_[get,set]() to g_mime_header_list_[get,set]_value()

 PORTING                |    3 ++
 gmime/gmime-header.c   |   28 ++++++++--------
 gmime/gmime-header.h   |   10 +++---
 gmime/gmime-internal.h |    4 +-
 gmime/gmime-message.c  |    6 ++--
 gmime/gmime-object.c   |   10 +++---
 gmime/gmime-part.c     |   15 +++++---
 tests/test-headers.c   |   82 ++++++++++++++++++++++++++++++++++++++++++++++--
 8 files changed, 120 insertions(+), 38 deletions(-)
---
diff --git a/PORTING b/PORTING
index 4669de7..4b6a6ab 100644
--- a/PORTING
+++ b/PORTING
@@ -126,6 +126,9 @@ Porting from GMime 2.6 to GMime 3.0
   argument nor does it return int. Instead, this function now returns a newly
   allocated GMimeMultipartSigned.
 
+- g_mime_header_list_[get,set]() have been renamed to
+  g_mime_header_list_[get,set]_value().
+
 
 Porting from GMime 2.4 to GMime 2.6
 -----------------------------------
diff --git a/gmime/gmime-header.c b/gmime/gmime-header.c
index f114024..9044fd6 100644
--- a/gmime/gmime-header.c
+++ b/gmime/gmime-header.c
@@ -388,9 +388,9 @@ g_mime_header_list_get_count (GMimeHeaderList *headers)
  * Returns: %TRUE if the specified header exists or %FALSE otherwise.
  **/
 gboolean
-g_mime_header_list_contains (const GMimeHeaderList *headers, const char *name)
+g_mime_header_list_contains (GMimeHeaderList *headers, const char *name)
 {
-       const GMimeHeader *header;
+       GMimeHeader *header;
        
        g_return_val_if_fail (headers != NULL, FALSE);
        g_return_val_if_fail (name != NULL, FALSE);
@@ -403,9 +403,9 @@ g_mime_header_list_contains (const GMimeHeaderList *headers, const char *name)
 
 
 gboolean
-_g_mime_header_list_has_raw_value (const GMimeHeaderList *headers, const char *name)
+_g_mime_header_list_has_raw_value (GMimeHeaderList *headers, const char *name)
 {
-       const GMimeHeader *header;
+       GMimeHeader *header;
        
        if (!(header = g_hash_table_lookup (headers->hash, name)))
                return FALSE;
@@ -503,7 +503,7 @@ g_mime_header_list_append (GMimeHeaderList *headers, const char *name, const cha
 
 
 /**
- * g_mime_header_list_get:
+ * g_mime_header_list_get_value:
  * @headers: a #GMimeHeaderList
  * @name: header name
  *
@@ -515,9 +515,9 @@ g_mime_header_list_append (GMimeHeaderList *headers, const char *name, const cha
  * g_mime_utils_header_decode_text() before displaying to the user.
  **/
 const char *
-g_mime_header_list_get (const GMimeHeaderList *headers, const char *name)
+g_mime_header_list_get_value (GMimeHeaderList *headers, const char *name)
 {
-       const GMimeHeader *header;
+       GMimeHeader *header;
        
        g_return_val_if_fail (headers != NULL, NULL);
        g_return_val_if_fail (name != NULL, NULL);
@@ -530,7 +530,7 @@ g_mime_header_list_get (const GMimeHeaderList *headers, const char *name)
 
 
 void
-_g_mime_header_list_set (GMimeHeaderList *headers, const char *name, const char *value, const char 
*raw_value, gint64 offset)
+_g_mime_header_list_set_value (GMimeHeaderList *headers, const char *name, const char *value, const char 
*raw_value, gint64 offset)
 {
        GMimeHeader *header, *hdr;
        guint i;
@@ -565,7 +565,7 @@ _g_mime_header_list_set (GMimeHeaderList *headers, const char *name, const char
 
 
 /**
- * g_mime_header_list_set:
+ * g_mime_header_list_set_value:
  * @headers: a #GMimeHeaderList
  * @name: header name
  * @value: header value
@@ -583,12 +583,12 @@ _g_mime_header_list_set (GMimeHeaderList *headers, const char *name, const char
  * g_mime_utils_header_encode_text().
  **/
 void
-g_mime_header_list_set (GMimeHeaderList *headers, const char *name, const char *value)
+g_mime_header_list_set_value (GMimeHeaderList *headers, const char *name, const char *value)
 {
        g_return_if_fail (headers != NULL);
        g_return_if_fail (name != NULL);
        
-       _g_mime_header_list_set (headers, name, value, NULL, -1);
+       _g_mime_header_list_set_value (headers, name, value, NULL, -1);
 }
 
 
@@ -627,7 +627,7 @@ g_mime_header_list_get_header (GMimeHeaderList *headers, int index)
 gboolean
 g_mime_header_list_remove (GMimeHeaderList *headers, const char *name)
 {
-       GMimeHeader *header, *node;
+       GMimeHeader *header;
        guint i;
        
        g_return_val_if_fail (headers != NULL, FALSE);
@@ -718,7 +718,7 @@ g_mime_header_list_remove_at (GMimeHeaderList *headers, int index)
  * Returns: the number of bytes written or %-1 on fail.
  **/
 ssize_t
-g_mime_header_list_write_to_stream (const GMimeHeaderList *headers, GMimeStream *stream)
+g_mime_header_list_write_to_stream (GMimeHeaderList *headers, GMimeStream *stream)
 {
        ssize_t nwritten, total = 0;
        GMimeHeader *header;
@@ -750,7 +750,7 @@ g_mime_header_list_write_to_stream (const GMimeHeaderList *headers, GMimeStream
  * Returns: a string containing the header block.
  **/
 char *
-g_mime_header_list_to_string (const GMimeHeaderList *headers)
+g_mime_header_list_to_string (GMimeHeaderList *headers)
 {
        GMimeStream *stream;
        GByteArray *array;
diff --git a/gmime/gmime-header.h b/gmime/gmime-header.h
index 0777bda..bc3d5b9 100644
--- a/gmime/gmime-header.h
+++ b/gmime/gmime-header.h
@@ -74,18 +74,18 @@ void g_mime_header_list_destroy (GMimeHeaderList *headers);
 
 void g_mime_header_list_clear (GMimeHeaderList *headers);
 int g_mime_header_list_get_count (GMimeHeaderList *headers);
-gboolean g_mime_header_list_contains (const GMimeHeaderList *headers, const char *name);
+gboolean g_mime_header_list_contains (GMimeHeaderList *headers, const char *name);
 void g_mime_header_list_prepend (GMimeHeaderList *headers, const char *name, const char *value);
 void g_mime_header_list_append (GMimeHeaderList *headers, const char *name, const char *value);
-void g_mime_header_list_set (GMimeHeaderList *headers, const char *name, const char *value);
-const char *g_mime_header_list_get (const GMimeHeaderList *headers, const char *name);
+void g_mime_header_list_set_value (GMimeHeaderList *headers, const char *name, const char *value);
+const char *g_mime_header_list_get_value (GMimeHeaderList *headers, const char *name);
 GMimeHeader *g_mime_header_list_get_header (GMimeHeaderList *headers, int index);
 gboolean g_mime_header_list_remove (GMimeHeaderList *headers, const char *name);
 void g_mime_header_list_remove_at (GMimeHeaderList *headers, int index);
 
 void g_mime_header_list_register_writer (GMimeHeaderList *headers, const char *name, GMimeHeaderWriter 
writer);
-ssize_t g_mime_header_list_write_to_stream (const GMimeHeaderList *headers, GMimeStream *stream);
-char *g_mime_header_list_to_string (const GMimeHeaderList *headers);
+ssize_t g_mime_header_list_write_to_stream (GMimeHeaderList *headers, GMimeStream *stream);
+char *g_mime_header_list_to_string (GMimeHeaderList *headers);
 
 G_END_DECLS
 
diff --git a/gmime/gmime-internal.h b/gmime/gmime-internal.h
index 029e963..9400551 100644
--- a/gmime/gmime-internal.h
+++ b/gmime/gmime-internal.h
@@ -41,10 +41,10 @@ G_GNUC_INTERNAL void _g_mime_header_set_offset (GMimeHeader *header, gint64 offs
 /* GMimeHeaderList */
 G_GNUC_INTERNAL GMimeParserOptions *_g_mime_header_list_get_options (GMimeHeaderList *headers);
 G_GNUC_INTERNAL void _g_mime_header_list_set_options (GMimeHeaderList *headers, GMimeParserOptions *options);
-G_GNUC_INTERNAL gboolean _g_mime_header_list_has_raw_value (const GMimeHeaderList *headers, const char 
*name);
+G_GNUC_INTERNAL gboolean _g_mime_header_list_has_raw_value (GMimeHeaderList *headers, const char *name);
 G_GNUC_INTERNAL void _g_mime_header_list_prepend (GMimeHeaderList *headers, const char *name, const char 
*value, const char *raw_value, gint64 offset);
 G_GNUC_INTERNAL void _g_mime_header_list_append (GMimeHeaderList *headers, const char *name, const char 
*value, const char *raw_value, gint64 offset);
-G_GNUC_INTERNAL void _g_mime_header_list_set (GMimeHeaderList *headers, const char *name, const char *value, 
const char *raw_value, gint64 offset);
+G_GNUC_INTERNAL void _g_mime_header_list_set_value (GMimeHeaderList *headers, const char *name, const char 
*value, const char *raw_value, gint64 offset);
 G_GNUC_INTERNAL GMimeEvent *_g_mime_header_list_get_changed_event (GMimeHeaderList *headers);
 
 /* GMimeObject */
diff --git a/gmime/gmime-message.c b/gmime/gmime-message.c
index 70eac15..0337643 100644
--- a/gmime/gmime-message.c
+++ b/gmime/gmime-message.c
@@ -805,7 +805,7 @@ message_set_header (GMimeObject *object, const char *header, const char *value,
        if (!process_header (object, SET, header, value))
                GMIME_OBJECT_CLASS (parent_class)->set_header (object, header, value, raw_value, offset);
        else
-               _g_mime_header_list_set (object->headers, header, value, raw_value, offset);
+               _g_mime_header_list_set_value (object->headers, header, value, raw_value, offset);
 }
 
 static const char *
@@ -1045,7 +1045,7 @@ g_mime_message_new (gboolean pretty_headers)
                /* Populate with the "standard" rfc822 headers so we can have a standard order */
                headers = ((GMimeObject *) message)->headers;
                for (i = 0; i < G_N_ELEMENTS (rfc822_headers); i++) 
-                       g_mime_header_list_set (headers, rfc822_headers[i], NULL);
+                       g_mime_header_list_set_value (headers, rfc822_headers[i], NULL);
        }
        
        return message;
@@ -1161,7 +1161,7 @@ sync_internet_address_list (InternetAddressList *list, GMimeMessage *message, co
        char *string;
        
        string = internet_address_list_to_string (list, TRUE);
-       g_mime_header_list_set (object->headers, name, string);
+       g_mime_header_list_set_value (object->headers, name, string);
        g_free (string);
 }
 
diff --git a/gmime/gmime-object.c b/gmime/gmime-object.c
index 7965d3e..faf7773 100644
--- a/gmime/gmime-object.c
+++ b/gmime/gmime-object.c
@@ -213,7 +213,7 @@ content_type_changed (GMimeContentType *content_type, gpointer args, GMimeObject
        g_string_free (string, FALSE);
        
        type = p + strlen ("Content-Type: ");
-       g_mime_header_list_set (object->headers, "Content-Type", type);
+       g_mime_header_list_set_value (object->headers, "Content-Type", type);
        g_free (p);
 }
 
@@ -246,7 +246,7 @@ content_disposition_changed (GMimeContentDisposition *disposition, gpointer args
        
        if (object->disposition) {
                str = g_mime_content_disposition_to_string (object->disposition, FALSE);
-               g_mime_header_list_set (object->headers, "Content-Disposition", str);
+               g_mime_header_list_set_value (object->headers, "Content-Disposition", str);
                g_free (str);
        } else {
                g_mime_header_list_remove (object->headers, "Content-Disposition");
@@ -775,7 +775,7 @@ process_header (GMimeObject *object, const char *header, const char *value, cons
                return FALSE;
        }
        
-       _g_mime_header_list_set (object->headers, header, value, raw_value, offset);
+       _g_mime_header_list_set_value (object->headers, header, value, raw_value, offset);
        
        return TRUE;
 }
@@ -857,7 +857,7 @@ static void
 object_set_header (GMimeObject *object, const char *header, const char *value, const char *raw_value, gint64 
offset)
 {
        if (!process_header (object, header, value, raw_value, offset))
-               _g_mime_header_list_set (object->headers, header, value, raw_value, offset);
+               _g_mime_header_list_set_value (object->headers, header, value, raw_value, offset);
 }
 
 
@@ -893,7 +893,7 @@ g_mime_object_set_header (GMimeObject *object, const char *header, const char *v
 static const char *
 object_get_header (GMimeObject *object, const char *header)
 {
-       return g_mime_header_list_get (object->headers, header);
+       return g_mime_header_list_get_value (object->headers, header);
 }
 
 
diff --git a/gmime/gmime-part.c b/gmime/gmime-part.c
index f688823..8f3ff42 100644
--- a/gmime/gmime-part.c
+++ b/gmime/gmime-part.c
@@ -240,7 +240,7 @@ mime_part_set_header (GMimeObject *object, const char *header, const char *value
        if (!process_header (object, header, value))
                GMIME_OBJECT_CLASS (parent_class)->set_header (object, header, value, raw_value, offset);
        else
-               _g_mime_header_list_set (object->headers, header, value, raw_value, offset);
+               _g_mime_header_list_set_value (object->headers, header, value, raw_value, offset);
 }
 
 static gboolean
@@ -500,7 +500,7 @@ g_mime_part_set_content_description (GMimePart *mime_part, const char *descripti
        
        g_free (mime_part->content_description);
        mime_part->content_description = g_strdup (description);
-       g_mime_header_list_set (GMIME_OBJECT (mime_part)->headers, "Content-Description", description);
+       g_mime_header_list_set_value (GMIME_OBJECT (mime_part)->headers, "Content-Description", description);
 }
 
 
@@ -613,7 +613,7 @@ g_mime_part_set_content_md5 (GMimePart *mime_part, const char *content_md5)
        }
        
        mime_part->content_md5 = g_strdup (content_md5);
-       g_mime_header_list_set (GMIME_OBJECT (mime_part)->headers, "Content-Md5", content_md5);
+       g_mime_header_list_set_value (GMIME_OBJECT (mime_part)->headers, "Content-Md5", content_md5);
 }
 
 
@@ -711,7 +711,7 @@ g_mime_part_set_content_location (GMimePart *mime_part, const char *content_loca
        
        g_free (mime_part->content_location);
        mime_part->content_location = g_strdup (content_location);
-       g_mime_header_list_set (GMIME_OBJECT (mime_part)->headers, "Content-Location", content_location);
+       g_mime_header_list_set_value (GMIME_OBJECT (mime_part)->headers, "Content-Location", 
content_location);
 }
 
 
@@ -743,11 +743,14 @@ g_mime_part_get_content_location (GMimePart *mime_part)
 void
 g_mime_part_set_content_encoding (GMimePart *mime_part, GMimeContentEncoding encoding)
 {
+       const char *value;
+       
        g_return_if_fail (GMIME_IS_PART (mime_part));
        
+       value = g_mime_content_encoding_to_string (encoding);
        mime_part->encoding = encoding;
-       g_mime_header_list_set (GMIME_OBJECT (mime_part)->headers, "Content-Transfer-Encoding",
-                               g_mime_content_encoding_to_string (encoding));
+       
+       g_mime_header_list_set_value (GMIME_OBJECT (mime_part)->headers, "Content-Transfer-Encoding", value);
 }
 
 
diff --git a/tests/test-headers.c b/tests/test-headers.c
index 8c405a7..a4b47a6 100644
--- a/tests/test-headers.c
+++ b/tests/test-headers.c
@@ -58,8 +58,9 @@ header_list_new (void)
        guint i;
        
        list = g_mime_header_list_new (g_mime_parser_options_get_default ());
-       for (i = 0; i < G_N_ELEMENTS (initial); i++)
+       for (i = 1; i < G_N_ELEMENTS (initial); i++)
                g_mime_header_list_append (list, initial[i].name, initial[i].value);
+       g_mime_header_list_prepend (list, initial[0].name, initial[0].value);
        
        return list;
 }
@@ -109,6 +110,59 @@ test_indexing (void)
 }
 
 static void
+test_remove (void)
+{
+       const char *name, *value;
+       GMimeHeaderList *list;
+       GMimeHeader *header;
+       guint i;
+       
+       list = header_list_new ();
+       
+       testsuite_check ("remove first header");
+       try {
+               /* remove the first header */
+               if (!g_mime_header_list_remove (list, initial[0].name))
+                       throw (exception_new ("failed to remove header"));
+               
+               /* make sure the first header is now the same as the second original header */
+               header = g_mime_header_list_get_header (list, 0);
+               name = g_mime_header_get_name (header);
+               value = g_mime_header_get_value (header);
+               
+               if (strcmp (initial[1].name, name) != 0 ||
+                   strcmp (initial[1].value, value) != 0)
+                       throw (exception_new ("expected second Received header"));
+               
+               /* make sure that the internal hash table was properly updated */
+               if (!(value = g_mime_header_list_get_value (list, "Received")))
+                       throw (exception_new ("lookup of Received header failed"));
+               
+               if (strcmp (initial[1].value, value) != 0)
+                       throw (exception_new ("expected second Received header value"));
+               
+               testsuite_check_passed ();
+       } catch (ex) {
+               testsuite_check_failed ("remove first header: %s", ex->message);
+       } finally;
+       
+       testsuite_check ("remove last header");
+       try {
+               /* remove the last header */
+               g_mime_header_list_remove (list, "Message-Id");
+               
+               if ((value = g_mime_header_list_get_value (list, "Message-Id")) != NULL)
+                       throw (exception_new ("lookup of Message-Id should have failed"));
+               
+               testsuite_check_passed ();
+       } catch (ex) {
+               testsuite_check_failed ("remove last header: %s", ex->message);
+       } finally;
+       
+       g_mime_header_list_destroy (list);
+}
+
+static void
 test_remove_at (void)
 {
        const char *name, *value;
@@ -134,7 +188,7 @@ test_remove_at (void)
                        throw (exception_new ("expected second Received header"));
                
                /* make sure that the internal hash table was properly updated */
-               if (!(value = g_mime_header_list_get (list, "Received")))
+               if (!(value = g_mime_header_list_get_value (list, "Received")))
                        throw (exception_new ("lookup of Received header failed"));
                
                if (strcmp (initial[1].value, value) != 0)
@@ -151,7 +205,7 @@ test_remove_at (void)
                count = g_mime_header_list_get_count (list);
                g_mime_header_list_remove_at (list, count - 1);
                
-               if ((value = g_mime_header_list_get (list, "Message-Id")) != NULL)
+               if ((value = g_mime_header_list_get_value (list, "Message-Id")) != NULL)
                        throw (exception_new ("lookup of Message-Id should have failed"));
                
                testsuite_check_passed ();
@@ -168,14 +222,18 @@ test_header_sync (void)
        GMimeContentDisposition *disposition;
        InternetAddressList *list;
        InternetAddress *addr, *ia;
+       GMimeHeaderList *headers;
        GMimeContentType *type;
        GMimeMessage *message;
        GMimeObject *object;
+       GMimeHeader *header;
        const char *value;
        GMimePart *part;
        
        part = g_mime_part_new_with_type ("application", "octet-stream");
        object = (GMimeObject *) part;
+
+       headers = g_mime_object_get_header_list (object);
        
        testsuite_check ("content-type synchronization");
        try {
@@ -216,6 +274,13 @@ test_header_sync (void)
                if (strcmp ("text/plain", value) != 0)
                        throw (exception_new ("content-type header had unexpected value after setting 
params"));
                
+               /* let's try this in reverse... set the header value and make sure GMimeContentType gets 
updated */
+               //header = g_mime_header_list_get_header (headers, 0);
+               //g_mime_header_set_value (header, "text/html; charset=utf-8");
+               //type = g_mime_object_get_content_type (object);
+               //if (!g_mime_content_type_is_type (type, "text", "html"))
+               //      throw (exception_new ("GMimeContentType object was not updated"));
+               
                testsuite_check_passed ();
        } catch (ex) {
                testsuite_check_failed ("content-type header not synchronized: %s", ex->message);
@@ -255,6 +320,13 @@ test_header_sync (void)
                if (strcmp ("inline", value) != 0)
                        throw (exception_new ("content-disposition header had unexpected value after setting 
params"));
                
+               /* let's try this in reverse... set the header value and make sure GMimeContentDisposition 
gets updated */
+               //header = g_mime_header_list_get_header (headers, 1);
+               //g_mime_header_set_value (header, "attachment; filename=xyz");
+               //disposition = g_mime_object_get_content_disposition (object);
+               //if (!g_mime_content_disposition_is_attachment (disposition))
+               //      throw (exception_new ("GMimeContentDisposition object was not updated"));
+               
                testsuite_check_passed ();
        } catch (ex) {
                testsuite_check_failed ("content-disposition header not synchronized: %s", ex->message);
@@ -348,6 +420,10 @@ int main (int argc, char **argv)
        testsuite_start ("indexing");
        test_indexing ();
        testsuite_end ();
+
+       testsuite_start ("removing");
+       test_remove ();
+       testsuite_end ();
        
        testsuite_start ("removing at an index");
        test_remove_at ();


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