[gmime: 10/21] Replace GMimeFilterMd5 with GMimeFilterChecksum



commit 8953b21dcf3474d8596cadaff2443a56d3c6b9f7
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date:   Wed Mar 22 17:22:43 2017 -0400

    Replace GMimeFilterMd5 with GMimeFilterChecksum

 PORTING                                            |    2 +
 docs/reference/changes-3.0.sgml                    |    3 +-
 docs/reference/gmime-sections.txt                  |   24 +++---
 gmime/Makefile.am                                  |    4 +-
 ...{gmime-filter-md5.c => gmime-filter-checksum.c} |   96 ++++++++++++--------
 gmime/gmime-filter-checksum.h                      |   66 ++++++++++++++
 gmime/gmime-filter-md5.h                           |   66 --------------
 gmime/gmime-part.c                                 |   12 ++--
 gmime/gmime.c                                      |    2 +-
 gmime/gmime.h                                      |    2 +-
 10 files changed, 148 insertions(+), 129 deletions(-)
---
diff --git a/PORTING b/PORTING
index af6d1d4..963d18d 100644
--- a/PORTING
+++ b/PORTING
@@ -146,6 +146,8 @@ Porting from GMime 2.6 to GMime 3.0
 
 - g_mime_parser_construct_[part,message]() now take a GMimeParserOptions argument.
 
+- Renamed GMimeFilterMd5 to GMimeFilterChecksum.
+
 
 Porting from GMime 2.4 to GMime 2.6
 -----------------------------------
diff --git a/docs/reference/changes-3.0.sgml b/docs/reference/changes-3.0.sgml
index 63a679c..08e9c7d 100644
--- a/docs/reference/changes-3.0.sgml
+++ b/docs/reference/changes-3.0.sgml
@@ -57,8 +57,9 @@
       <listitem><para><function>g_mime_part_set_content_object()</function> has been renamed to 
<function>g_mime_part_set_content()</function>.</para></listitem>
       <listitem><para><function>g_mime_parser_get_scan_from()</function> and 
<function>g_mime_parser_set_scan_from()</function> have been replaced by 
<function>g_mime_parser_get_format()</function> and <function>g_mime_parser_get_format()</function> which 
take a GMimeFormat argument.</para></listitem>
       <listitem><para><function>g_mime_parser_get_from()</function> has been renamed to 
<function>g_mime_parser_get_mbox_marker()</function>.</para></listitem>
-      <likstitem><para><function>g_mime_parser_get_from_offset()</function> has been renamed to 
<function>g_mime_parser_get_mbox_marker_offset()</function>.</para></listitem>
+      <listitem><para><function>g_mime_parser_get_from_offset()</function> has been renamed to 
<function>g_mime_parser_get_mbox_marker_offset()</function>.</para></listitem>
       <listitem><para><function>g_mime_parser_construct_message()</function> and 
<function>g_mime_parser_construct_part()</function> now take a GMimeParserOptions argument.</para></listitem>
+      <listitem><para>Renamed GMimeFilterMd5 to GMimeFilterChecksum.</para></listitem>
     </itemizedlist>
   </refsect1>
 </refentry>
diff --git a/docs/reference/gmime-sections.txt b/docs/reference/gmime-sections.txt
index e222d5d..d6aca74 100644
--- a/docs/reference/gmime-sections.txt
+++ b/docs/reference/gmime-sections.txt
@@ -473,22 +473,22 @@ GMIME_FILTER_HTML_GET_CLASS
 </SECTION>
 
 <SECTION>
-<FILE>gmime-filter-md5</FILE>
-GMimeFilterMd5
-g_mime_filter_md5_new
-g_mime_filter_md5_get_digest
+<FILE>gmime-filter-checksum</FILE>
+GMimeFilterChecksum
+g_mime_filter_checksum_new
+g_mime_filter_checksum_get_digest
 
 <SUBSECTION Private>
-g_mime_filter_md5_get_type
+g_mime_filter_checksum_get_type
 
 <SUBSECTION Standard>
-GMimeFilterMd5Class
-GMIME_TYPE_FILTER_MD5
-GMIME_FILTER_MD5
-GMIME_IS_FILTER_MD5
-GMIME_FILTER_MD5_CLASS
-GMIME_IS_FILTER_MD5_CLASS
-GMIME_FILTER_MD5_GET_CLASS
+GMimeFilterChecksumClass
+GMIME_TYPE_FILTER_CHECKSUM
+GMIME_FILTER_CHECKSUM
+GMIME_IS_FILTER_CHECKSUM
+GMIME_FILTER_CHECKSUM_CLASS
+GMIME_IS_FILTER_CHECKSUM_CLASS
+GMIME_FILTER_CHECKSUM_GET_CLASS
 </SECTION>
 
 <SECTION>
diff --git a/gmime/Makefile.am b/gmime/Makefile.am
index cf34f9d..12bfccc 100644
--- a/gmime/Makefile.am
+++ b/gmime/Makefile.am
@@ -35,13 +35,13 @@ libgmime_3_0_la_SOURCES =           \
        gmime-filter-basic.c            \
        gmime-filter-best.c             \
        gmime-filter-charset.c          \
+       gmime-filter-checksum.c         \
        gmime-filter-crlf.c             \
        gmime-filter-dos2unix.c         \
        gmime-filter-enriched.c         \
        gmime-filter-from.c             \
        gmime-filter-gzip.c             \
        gmime-filter-html.c             \
-       gmime-filter-md5.c              \
        gmime-filter-strip.c            \
        gmime-filter-unix2dos.c         \
        gmime-filter-windows.c          \
@@ -97,13 +97,13 @@ gmimeinclude_HEADERS =                      \
        gmime-filter-basic.h            \
        gmime-filter-best.h             \
        gmime-filter-charset.h          \
+       gmime-filter-checksum.h         \
        gmime-filter-crlf.h             \
        gmime-filter-dos2unix.h         \
        gmime-filter-enriched.h         \
        gmime-filter-from.h             \
        gmime-filter-gzip.h             \
        gmime-filter-html.h             \
-       gmime-filter-md5.h              \
        gmime-filter-strip.h            \
        gmime-filter-unix2dos.h         \
        gmime-filter-windows.h          \
diff --git a/gmime/gmime-filter-md5.c b/gmime/gmime-filter-checksum.c
similarity index 53%
rename from gmime/gmime-filter-md5.c
rename to gmime/gmime-filter-checksum.c
index 9df77d5..9c21356 100644
--- a/gmime/gmime-filter-md5.c
+++ b/gmime/gmime-filter-checksum.c
@@ -23,21 +23,21 @@
 #include <config.h>
 #endif
 
-#include "gmime-filter-md5.h"
+#include "gmime-filter-checksum.h"
 
 
 /**
- * SECTION: gmime-filter-md5
- * @title: GMimeFilterMd5
- * @short_description: Calculate an md5sum
+ * SECTION: gmime-filter-checksum
+ * @title: GMimeFilterChecksum
+ * @short_description: Calculate a checksum
  * @see_also: #GMimeFilter
  *
- * Calculate an md5sum for a stream.
+ * Calculate a checksum for a stream.
  **/
 
-static void g_mime_filter_md5_class_init (GMimeFilterMd5Class *klass);
-static void g_mime_filter_md5_init (GMimeFilterMd5 *filter, GMimeFilterMd5Class *klass);
-static void g_mime_filter_md5_finalize (GObject *object);
+static void g_mime_filter_checksum_class_init (GMimeFilterChecksumClass *klass);
+static void g_mime_filter_checksum_init (GMimeFilterChecksum *filter, GMimeFilterChecksumClass *klass);
+static void g_mime_filter_checksum_finalize (GObject *object);
 
 static GMimeFilter *filter_copy (GMimeFilter *filter);
 static void filter_filter (GMimeFilter *filter, char *in, size_t len, size_t prespace,
@@ -51,24 +51,24 @@ static GMimeFilterClass *parent_class = NULL;
 
 
 GType
-g_mime_filter_md5_get_type (void)
+g_mime_filter_checksum_get_type (void)
 {
        static GType type = 0;
        
        if (!type) {
                static const GTypeInfo info = {
-                       sizeof (GMimeFilterMd5Class),
+                       sizeof (GMimeFilterChecksumClass),
                        NULL, /* base_class_init */
                        NULL, /* base_class_finalize */
-                       (GClassInitFunc) g_mime_filter_md5_class_init,
+                       (GClassInitFunc) g_mime_filter_checksum_class_init,
                        NULL, /* class_finalize */
                        NULL, /* class_data */
-                       sizeof (GMimeFilterMd5),
+                       sizeof (GMimeFilterChecksum),
                        0,    /* n_preallocs */
-                       (GInstanceInitFunc) g_mime_filter_md5_init,
+                       (GInstanceInitFunc) g_mime_filter_checksum_init,
                };
                
-               type = g_type_register_static (GMIME_TYPE_FILTER, "GMimeFilterMd5", &info, 0);
+               type = g_type_register_static (GMIME_TYPE_FILTER, "GMimeFilterChecksum", &info, 0);
        }
        
        return type;
@@ -76,14 +76,14 @@ g_mime_filter_md5_get_type (void)
 
 
 static void
-g_mime_filter_md5_class_init (GMimeFilterMd5Class *klass)
+g_mime_filter_checksum_class_init (GMimeFilterChecksumClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
        GMimeFilterClass *filter_class = GMIME_FILTER_CLASS (klass);
        
        parent_class = g_type_class_ref (GMIME_TYPE_FILTER);
        
-       object_class->finalize = g_mime_filter_md5_finalize;
+       object_class->finalize = g_mime_filter_checksum_finalize;
        
        filter_class->copy = filter_copy;
        filter_class->filter = filter_filter;
@@ -92,17 +92,18 @@ g_mime_filter_md5_class_init (GMimeFilterMd5Class *klass)
 }
 
 static void
-g_mime_filter_md5_init (GMimeFilterMd5 *filter, GMimeFilterMd5Class *klass)
+g_mime_filter_checksum_init (GMimeFilterChecksum *filter, GMimeFilterChecksumClass *klass)
 {
-       filter->md5 = g_checksum_new (G_CHECKSUM_MD5);
+       filter->checksum = NULL;
 }
 
 static void
-g_mime_filter_md5_finalize (GObject *object)
+g_mime_filter_checksum_finalize (GObject *object)
 {
-       GMimeFilterMd5 *filter = (GMimeFilterMd5 *) object;
+       GMimeFilterChecksum *filter = (GMimeFilterChecksum *) object;
        
-       g_checksum_free (filter->md5);
+       if (filter->checksum)
+               g_checksum_free (filter->checksum);
        
        G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -111,7 +112,13 @@ g_mime_filter_md5_finalize (GObject *object)
 static GMimeFilter *
 filter_copy (GMimeFilter *filter)
 {
-       return g_mime_filter_md5_new ();
+       GChecksum *checksum = ((GMimeFilterChecksum *) filter)->checksum;
+       GMimeFilterChecksum *copy;
+       
+       copy = g_object_newv (GMIME_TYPE_FILTER_CHECKSUM, 0, NULL);
+       copy->checksum = checksum ? g_checksum_copy (checksum) : NULL;
+       
+       return (GMimeFilter *) copy;
 }
 
 
@@ -119,9 +126,9 @@ static void
 filter_filter (GMimeFilter *filter, char *in, size_t len, size_t prespace,
               char **out, size_t *outlen, size_t *outprespace)
 {
-       GChecksum *md5 = ((GMimeFilterMd5 *) filter)->md5;
+       GChecksum *checksum = ((GMimeFilterChecksum *) filter)->checksum;
        
-       g_checksum_update (md5, (unsigned char *) in, len);
+       g_checksum_update (checksum, (unsigned char *) in, len);
        
        *out = in;
        *outlen = len;
@@ -138,39 +145,48 @@ filter_complete (GMimeFilter *filter, char *in, size_t len, size_t prespace,
 static void
 filter_reset (GMimeFilter *filter)
 {
-       GChecksum *md5 = ((GMimeFilterMd5 *) filter)->md5;
+       GChecksum *checksum = ((GMimeFilterChecksum *) filter)->checksum;
        
-       g_checksum_reset (md5);
+       g_checksum_reset (checksum);
 }
 
 
 /**
- * g_mime_filter_md5_new:
+ * g_mime_filter_checksum_new:
+ * @type: the type of checksum
  *
- * Creates a new Md5 filter.
+ * Creates a new checksum filter.
  *
- * Returns: a new Md5 filter.
+ * Returns: a new #GMimeFilterChecksum filter.
  **/
 GMimeFilter *
-g_mime_filter_md5_new (void)
+g_mime_filter_checksum_new (GChecksumType type)
 {
-       return g_object_newv (GMIME_TYPE_FILTER_MD5, 0, NULL);
+       GMimeFilterChecksum *checksum;
+       
+       checksum = g_object_newv (GMIME_TYPE_FILTER_CHECKSUM, 0, NULL);
+       checksum->checksum = g_checksum_new (type);
+       
+       return (GMimeFilter *) checksum;
 }
 
 
 /**
- * g_mime_filter_md5_get_digest:
- * @md5: md5 filter object
- * @digest: output buffer of at least 16 bytes
+ * g_mime_filter_checksum_get_digest:
+ * @checksum: checksum filter object
+ * @digest: the digest buffer
+ * @len: the length of the digest buffer
+ *
+ * Outputs the checksum digest into @digest.
  *
- * Outputs the md5 digest into @digest.
+ * Returns: the number of bytes used of the @digest buffer.
  **/
-void
-g_mime_filter_md5_get_digest (GMimeFilterMd5 *md5, unsigned char digest[16])
+size_t
+g_mime_filter_checksum_get_digest (GMimeFilterChecksum *checksum, unsigned char *digest, size_t len)
 {
-       gsize len = 16;
+       g_return_val_if_fail (GMIME_IS_FILTER_CHECKSUM (checksum), 0);
        
-       g_return_if_fail (GMIME_IS_FILTER_MD5 (md5));
+       g_checksum_get_digest (checksum->checksum, digest, &len);
        
-       g_checksum_get_digest (md5->md5, digest, &len);
+       return len;
 }
diff --git a/gmime/gmime-filter-checksum.h b/gmime/gmime-filter-checksum.h
new file mode 100644
index 0000000..7b11d42
--- /dev/null
+++ b/gmime/gmime-filter-checksum.h
@@ -0,0 +1,66 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*  GMime
+ *  Copyright (C) 2000-2017 Jeffrey Stedfast
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1
+ *  of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA.
+ */
+
+
+#ifndef __GMIME_FILTER_MD5_H__
+#define __GMIME_FILTER_MD5_H__
+
+#include <gmime/gmime-filter.h>
+
+G_BEGIN_DECLS
+
+#define GMIME_TYPE_FILTER_CHECKSUM            (g_mime_filter_checksum_get_type ())
+#define GMIME_FILTER_CHECKSUM(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GMIME_TYPE_FILTER_CHECKSUM, GMimeFilterChecksum))
+#define GMIME_FILTER_CHECKSUM_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GMIME_TYPE_FILTER_CHECKSUM, 
GMimeFilterChecksumClass))
+#define GMIME_IS_FILTER_CHECKSUM(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GMIME_TYPE_FILTER_CHECKSUM))
+#define GMIME_IS_FILTER_CHECKSUM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GMIME_TYPE_FILTER_CHECKSUM))
+#define GMIME_FILTER_CHECKSUM_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GMIME_TYPE_FILTER_CHECKSUM, 
GMimeFilterChecksumClass))
+
+typedef struct _GMimeFilterChecksum GMimeFilterChecksum;
+typedef struct _GMimeFilterChecksumClass GMimeFilterChecksumClass;
+
+/**
+ * GMimeFilterChecksum:
+ * @parent_object: parent #GMimeFilter
+ * @checksum: The checksum context
+ *
+ * A filter for calculating the checksum of a stream.
+ **/
+struct _GMimeFilterChecksum {
+       GMimeFilter parent_object;
+       
+       GChecksum *checksum;
+};
+
+struct _GMimeFilterChecksumClass {
+       GMimeFilterClass parent_class;
+       
+};
+
+
+GType g_mime_filter_checksum_get_type (void);
+
+GMimeFilter *g_mime_filter_checksum_new (GChecksumType type);
+
+size_t g_mime_filter_checksum_get_digest (GMimeFilterChecksum *checksum, unsigned char *digest, size_t len);
+
+G_END_DECLS
+
+#endif /* __GMIME_FILTER_CHECKSUM_H__ */
diff --git a/gmime/gmime-part.c b/gmime/gmime-part.c
index e0419ef..dcb220f 100644
--- a/gmime/gmime-part.c
+++ b/gmime/gmime-part.c
@@ -37,7 +37,7 @@
 #include "gmime-stream-filter.h"
 #include "gmime-filter-basic.h"
 #include "gmime-filter-best.h"
-#include "gmime-filter-md5.h"
+#include "gmime-filter-checksum.h"
 #include "gmime-filter-unix2dos.h"
 #include "gmime-table-private.h"
 
@@ -634,14 +634,14 @@ g_mime_part_set_content_md5 (GMimePart *mime_part, const char *content_md5)
                        g_object_unref (filter);
                }
                
-               filter = g_mime_filter_md5_new ();
+               filter = g_mime_filter_checksum_new (G_CHECKSUM_MD5);
                g_mime_stream_filter_add ((GMimeStreamFilter *) filtered, filter);
                
                g_mime_data_wrapper_write_to_stream (mime_part->content, filtered);
                g_object_unref (filtered);
                
                memset (digest, 0, 16);
-               g_mime_filter_md5_get_digest ((GMimeFilterMd5 *) filter, digest);
+               g_mime_filter_checksum_get_digest ((GMimeFilterChecksum *) filter, digest, 16);
                g_object_unref (filter);
                
                len = g_mime_encoding_base64_encode_close (digest, 16, b64digest, &state, &save);
@@ -680,7 +680,7 @@ g_mime_part_verify_content_md5 (GMimePart *mime_part)
        size_t len;
        
        g_return_val_if_fail (GMIME_IS_PART (mime_part), FALSE);
-       g_return_val_if_fail (mime_part->content != NULL, FALSE);
+       g_return_val_if_fail (GMIME_IS_DATA_WRAPPER (mime_part->content), FALSE);
        
        if (!mime_part->content_md5)
                return FALSE;
@@ -696,14 +696,14 @@ g_mime_part_verify_content_md5 (GMimePart *mime_part)
                g_object_unref (filter);
        }
        
-       filter = g_mime_filter_md5_new ();
+       filter = g_mime_filter_checksum_new (G_CHECKSUM_MD5);
        g_mime_stream_filter_add ((GMimeStreamFilter *) filtered, filter);
        
        g_mime_data_wrapper_write_to_stream (mime_part->content, filtered);
        g_object_unref (filtered);
        
        memset (digest, 0, 16);
-       g_mime_filter_md5_get_digest ((GMimeFilterMd5 *) filter, digest);
+       g_mime_filter_checksum_get_digest ((GMimeFilterChecksum *) filter, digest, 16);
        g_object_unref (filter);
        
        len = g_mime_encoding_base64_encode_close (digest, 16, b64digest, &state, &save);
diff --git a/gmime/gmime.c b/gmime/gmime.c
index 54e6aae..2c56af9 100644
--- a/gmime/gmime.c
+++ b/gmime/gmime.c
@@ -142,13 +142,13 @@ g_mime_init (void)
        g_mime_filter_basic_get_type ();
        g_mime_filter_best_get_type ();
        g_mime_filter_charset_get_type ();
+       g_mime_filter_checksum_get_type ();
        g_mime_filter_crlf_get_type ();
        g_mime_filter_dos2unix_get_type ();
        g_mime_filter_enriched_get_type ();
        g_mime_filter_from_get_type ();
        g_mime_filter_gzip_get_type ();
        g_mime_filter_html_get_type ();
-       g_mime_filter_md5_get_type ();
        g_mime_filter_strip_get_type ();
        g_mime_filter_unix2dos_get_type ();
        g_mime_filter_windows_get_type ();
diff --git a/gmime/gmime.h b/gmime/gmime.h
index d1a4764..c86f4b6 100644
--- a/gmime/gmime.h
+++ b/gmime/gmime.h
@@ -64,13 +64,13 @@
 #include <gmime/gmime-filter-basic.h>
 #include <gmime/gmime-filter-best.h>
 #include <gmime/gmime-filter-charset.h>
+#include <gmime/gmime-filter-checksum.h>
 #include <gmime/gmime-filter-crlf.h>
 #include <gmime/gmime-filter-dos2unix.h>
 #include <gmime/gmime-filter-enriched.h>
 #include <gmime/gmime-filter-from.h>
 #include <gmime/gmime-filter-gzip.h>
 #include <gmime/gmime-filter-html.h>
-#include <gmime/gmime-filter-md5.h>
 #include <gmime/gmime-filter-strip.h>
 #include <gmime/gmime-filter-unix2dos.h>
 #include <gmime/gmime-filter-windows.h>


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