[evolution-ews] Clean up and separate out the imported mspack code



commit 1fb5658be578f6ce981f3038c026c11b3efb9c76
Author: David Woodhouse <David Woodhouse intel com>
Date:   Wed May 15 17:23:29 2013 +0100

    Clean up and separate out the imported mspack code

 src/addressbook/Makefile.am                        |   32 +++++++-
 src/addressbook/e-book-backend-ews.c               |    6 +-
 src/addressbook/ews-oab-decompress.c               |   84 ++++++++++++++++++++
 .../ews-oal-decompress.h => ews-oab-decompress.h}  |   17 ++--
 .../{lzx => }/gal-lzx-decompress-test.c            |    6 +-
 src/addressbook/mspack/README.mspack               |   15 ++++
 src/addressbook/{lzx => mspack}/lzx.h              |    0
 src/addressbook/{lzx => mspack}/lzxd.c             |    0
 .../oab-decompress.c}                              |   73 ++----------------
 src/addressbook/{lzx => mspack}/readbits.h         |    0
 src/addressbook/{lzx => mspack}/readhuff.h         |    0
 11 files changed, 149 insertions(+), 84 deletions(-)
---
diff --git a/src/addressbook/Makefile.am b/src/addressbook/Makefile.am
index 6ba6d83..67005cf 100644
--- a/src/addressbook/Makefile.am
+++ b/src/addressbook/Makefile.am
@@ -1,9 +1,15 @@
 NULL =
 
-SUBDIRS = lzx .
-
 ebook_backend_LTLIBRARIES = libebookbackendews.la
 
+if HAVE_MSPACK
+USE_MSPACK_CFLAGS = $(MSPACK_CFLAGS)
+USE_MSPACK_LIBS = $(MSPACK_LIBS)
+MSPACK_SRCS = ews-oab-decompress.c
+else
+MSPACK_SRCS = mspack/lzx.h mspack/lzxd.c mspack/readbits.h mspack/readhuff.h mspack/oab-decompress.c
+endif
+
 libebookbackendews_la_CPPFLAGS = \
        $(AM_CPPFLAGS) \
        -DG_LOG_DOMAIN=\"libebookbackend\" \
@@ -12,6 +18,7 @@ libebookbackendews_la_CPPFLAGS = \
        -I$(top_srcdir)/src \
        -I$(top_builddir) \
        -I$(top_builddir)/src \
+       $(USE_MSPACK_CFLAGS) \
        $(LIBEBACKEND_CFLAGS) \
        $(LIBEDATASERVER_CFLAGS) \
        $(LIBEBOOK_CFLAGS) \
@@ -25,15 +32,17 @@ libebookbackendews_la_SOURCES = \
        ews-oab-props.h \
        ews-oab-decoder.c \
        ews-oab-decoder.h \
+       ews-oab-decompress.h \
        e-book-backend-ews.c \
        e-book-backend-ews.h \
        e-book-backend-ews-factory.c \
+       $(MSPACK_SRCS) \
        $(NULL)
 
 libebookbackendews_la_LIBADD = \
        $(top_builddir)/src/server/libeews-1.2.la \
        $(top_builddir)/src/utils/libewsutils.la \
-       $(top_builddir)/src/addressbook/lzx/liblzx.la \
+       $(USE_MSPACK_LIBS) \
        $(LIBEBACKEND_LIBS) \
        $(LIBEDATASERVER_LIBS) \
        $(LIBEDATABOOK_LIBS)  \
@@ -48,4 +57,21 @@ libebookbackendews_la_LIBADD = \
 libebookbackendews_la_LDFLAGS = \
        -module -avoid-version $(NO_UNDEFINED)
 
+noinst_PROGRAMS = gal-lzx-decompress-test
+
+gal_lzx_decompress_test_CPPFLAGS = \
+       $(AM_CPPFLAGS) \
+       $(GNOME_PLATFORM_CFLAGS) \
+       $(USE_MSPACK_CFLAGS) \
+       $(NULL)
+
+gal_lzx_decompress_test_SOURCES = \
+       gal-lzx-decompress-test.c \
+       $(MSPACK_SRCS)
+
+gal_lzx_decompress_test_LDADD = \
+       $(GNOME_PLATFORM_LIBS) \
+       $(USE_MSPACK_LIBS) \
+       $(NULL)
+
 -include $(top_srcdir)/git.mk
diff --git a/src/addressbook/e-book-backend-ews.c b/src/addressbook/e-book-backend-ews.c
index dacbcfd..b23e6e6 100644
--- a/src/addressbook/e-book-backend-ews.c
+++ b/src/addressbook/e-book-backend-ews.c
@@ -40,8 +40,6 @@
 
 #include <libedata-book/libedata-book.h>
 
-#include "lzx/ews-oal-decompress.h"
-
 #include "server/e-ews-item-change.h"
 #include "server/e-ews-message.h"
 #include "server/e-ews-connection.h"
@@ -52,6 +50,8 @@
 
 #include "e-book-backend-ews.h"
 #include "ews-oab-decoder.h"
+#include "ews-oab-decompress.h"
+
 
 #define d(x) x
 
@@ -2115,7 +2115,7 @@ ews_download_full_gal (EBookBackendEws *cbews,
 
        cache_file = g_strdup_printf ("%s-%d.oab", priv->folder_name, full->seq);
        uncompress_file = g_build_filename (cache_dir, cache_file, NULL);
-       if (!oal_decompress_v4_full_detail_file (comp_cache_file, uncompress_file, error)) {
+       if (!ews_oab_decompress_full (comp_cache_file, uncompress_file, error)) {
                g_free (uncompress_file);
                uncompress_file = NULL;
                goto exit;
diff --git a/src/addressbook/ews-oab-decompress.c b/src/addressbook/ews-oab-decompress.c
new file mode 100644
index 0000000..757ec0e
--- /dev/null
+++ b/src/addressbook/ews-oab-decompress.c
@@ -0,0 +1,84 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/* e-book-backend-ews.h - Ews contact backend.
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+#include "ews-oab-decompress.h"
+#include <mspack.h>
+
+/* This contains the minimal implementation of these functions, for use with
+   a sufficiently up-to-date version of libmspack. For the full implementation
+   for use without libmspack, see the lzx/ directory. */
+
+gboolean
+ews_oab_decompress_full (const gchar *filename, const gchar *output_filename,
+                        GError **error)
+{
+       struct msoab_decompressor *msoab;
+       int ret;
+
+       msoab = mspack_create_oab_decompressor (NULL);
+       if (!msoab) {
+               g_set_error_literal (error, g_quark_from_string ("lzx"), 1,
+                                    "Unable to create msoab decompressor");
+               return FALSE;
+       }
+       ret = msoab->decompress (msoab, filename, output_filename);
+       mspack_destroy_oab_decompressor (msoab);
+       if (ret != MSPACK_ERR_OK) {
+               g_set_error (error, g_quark_from_string ("lzx"), 1,
+                            "Failed to decompress LZX file: %d", ret);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+
+gboolean
+ews_oab_decompress_patch (const gchar *filename, const gchar *orig_filename,
+                         const gchar *output_filename, GError **error)
+{
+       struct msoab_decompressor *msoab;
+       int ret;
+
+       msoab = mspack_create_oab_decompressor (NULL);
+       if (!msoab) {
+               g_set_error_literal (error, g_quark_from_string ("lzx"), 1,
+                                    "Unable to create msoab decompressor");
+               return FALSE;
+       }
+       ret = msoab->decompress_incremental (msoab, filename,
+                                            orig_filename, output_filename);
+       mspack_destroy_oab_decompressor (msoab);
+       if (ret != MSPACK_ERR_OK) {
+               g_set_error (error, g_quark_from_string ("lzx"), 1,
+                            "Failed to apply LZX patch file: %d", ret);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
diff --git a/src/addressbook/lzx/ews-oal-decompress.h b/src/addressbook/ews-oab-decompress.h
similarity index 72%
rename from src/addressbook/lzx/ews-oal-decompress.h
rename to src/addressbook/ews-oab-decompress.h
index c9b6af4..830499a 100644
--- a/src/addressbook/lzx/ews-oal-decompress.h
+++ b/src/addressbook/ews-oab-decompress.h
@@ -20,16 +20,17 @@
  *
  */
 
-#ifndef __EWS_OAL_DECOMPRESS_H__
-#define __EWS_OAL_DECOMPRESS_H__
+#ifndef __EWS_OAB_DECOMPRESS_H__
+#define __EWS_OAB_DECOMPRESS_H__
 
 #include <glib.h>
 
-gboolean
-oal_decompress_v4_full_detail_file (const gchar *filename, const gchar *output_filename, GError **error);
-gboolean
-oal_apply_binpatch (const gchar *filename, const gchar *orig_filename,
-                   const gchar *output_filename,
-                   GError **error);
+gboolean ews_oab_decompress_full (const gchar *filename,
+                                 const gchar *output_filename,
+                                 GError **error);
+gboolean ews_oab_decompress_patch (const gchar *filename,
+                                  const gchar *orig_filename,
+                                  const gchar *output_filename,
+                                  GError **error);
 
 #endif
diff --git a/src/addressbook/lzx/gal-lzx-decompress-test.c b/src/addressbook/gal-lzx-decompress-test.c
similarity index 77%
rename from src/addressbook/lzx/gal-lzx-decompress-test.c
rename to src/addressbook/gal-lzx-decompress-test.c
index 9185ca8..35925af 100644
--- a/src/addressbook/lzx/gal-lzx-decompress-test.c
+++ b/src/addressbook/gal-lzx-decompress-test.c
@@ -1,5 +1,5 @@
 
-#include "ews-oal-decompress.h"
+#include "ews-oab-decompress.h"
 #include <glib.h>
 
 gint
@@ -15,14 +15,14 @@ main (gint argc, gchar *argv[])
        if (argc == 4) {
                g_print("Applying binary patch %s to %s to create %s\n",
                        argv[1], argv[2], argv[3]);
-               if (oal_apply_binpatch(argv[1], argv[2], argv[3], &error))
+               if (ews_oab_decompress_patch (argv[1], argv[2], argv[3], &error))
                        g_print("Successfully applied\n");
                else
                        g_print("apply failed: %s\n", error->message);
        } else
 
 
-       if (oal_decompress_v4_full_detail_file (argv[1], argv[2], &error))
+       if (ews_oab_decompress_full (argv[1], argv[2], &error))
                g_print ("Successfully decompressed \n");
        else
                g_print ("decompression failed: %s\n", error->message);
diff --git a/src/addressbook/mspack/README.mspack b/src/addressbook/mspack/README.mspack
new file mode 100644
index 0000000..3dc6e1e
--- /dev/null
+++ b/src/addressbook/mspack/README.mspack
@@ -0,0 +1,15 @@
+
+This contains a local copy of parts of libmspack.
+
+Parts (lzxd.c and various header files) were originally lifted from
+libmspack and modified to support the LZX DELTA format.
+
+The "file format" support in oab-decompress.c was developed as part of
+Evolution-EWS, and a mostly rewritten version was later submitted for
+inclusion in libmspack upstream.
+
+If you have a sufficiently recent version of libmspack, none of the
+code in this directory will be used. Instead ews-oab-decompressor.c
+in the parent directory will invoke the decompressor in libmspack.
+
+
diff --git a/src/addressbook/lzx/lzx.h b/src/addressbook/mspack/lzx.h
similarity index 100%
rename from src/addressbook/lzx/lzx.h
rename to src/addressbook/mspack/lzx.h
diff --git a/src/addressbook/lzx/lzxd.c b/src/addressbook/mspack/lzxd.c
similarity index 100%
rename from src/addressbook/lzx/lzxd.c
rename to src/addressbook/mspack/lzxd.c
diff --git a/src/addressbook/lzx/ews-oal-decompress.c b/src/addressbook/mspack/oab-decompress.c
similarity index 86%
rename from src/addressbook/lzx/ews-oal-decompress.c
rename to src/addressbook/mspack/oab-decompress.c
index cb45b91..d118e44 100644
--- a/src/addressbook/lzx/ews-oal-decompress.c
+++ b/src/addressbook/mspack/oab-decompress.c
@@ -31,67 +31,8 @@
 #include <unistd.h>
 #include <glib.h>
 #include <glib/gstdio.h>
-#ifdef USE_MSPACK
-#include <mspack.h>
-#else
 #include "lzx.h"
-#endif
-#include "ews-oal-decompress.h"
-
-#ifdef USE_MSPACK
-
-gboolean
-oal_decompress_v4_full_detail_file (const gchar *filename,
-                                    const gchar *output_filename,
-                                    GError **error)
-{
-       struct msoab_decompressor *msoab;
-       int ret;
-
-       msoab = mspack_create_oab_decompressor (NULL);
-       if (!msoab) {
-               g_set_error_literal (error, g_quark_from_string ("lzx"), 1,
-                                    "Unable to create msoab decompressor");
-               return FALSE;
-       }
-       ret = msoab->decompress (msoab, filename, output_filename);
-       mspack_destroy_oab_decompressor (msoab);
-       if (ret != MSPACK_ERR_OK) {
-               g_set_error (error, g_quark_from_string ("lzx"), 1,
-                            "Failed to decompress LZX file: %d", ret);
-               return FALSE;
-       }
-
-       return TRUE;
-}
-
-
-gboolean
-oal_apply_binpatch (const gchar *filename, const gchar *orig_filename,
-                   const gchar *output_filename, GError **error)
-{
-       struct msoab_decompressor *msoab;
-       int ret;
-
-       msoab = mspack_create_oab_decompressor (NULL);
-       if (!msoab) {
-               g_set_error_literal (error, g_quark_from_string ("lzx"), 1,
-                                    "Unable to create msoab decompressor");
-               return FALSE;
-       }
-       ret = msoab->decompress_incremental (msoab, filename,
-                                            orig_filename, output_filename);
-       mspack_destroy_oab_decompressor (msoab);
-       if (ret != MSPACK_ERR_OK) {
-               g_set_error (error, g_quark_from_string ("lzx"), 1,
-                            "Failed to apply LZX patch file: %d", ret);
-               return FALSE;
-       }
-
-       return TRUE;
-}
-
-#else /* USE_MSPACK */
+#include "../ews-oab-decompress.h"
 
 /* endian-neutral reading of little-endian data */
 #define __egi32(a,n) ( ((((unsigned char *) a)[n+3]) << 24) | \
@@ -208,9 +149,8 @@ exit:
 }
 
 gboolean
-oal_decompress_v4_full_detail_file (const gchar *filename,
-                                    const gchar *output_filename,
-                                    GError **error)
+ews_oab_decompress_full (const gchar *filename, const gchar *output_filename,
+                        GError **error)
 {
        LzxHeader *lzx_h = NULL;
        guint total_decomp_size = 0;
@@ -425,9 +365,8 @@ exit:
 }
 
 gboolean
-oal_apply_binpatch (const gchar *filename, const gchar *orig_filename,
-                   const gchar *output_filename,
-                   GError **error)
+ews_oab_decompress_patch (const gchar *filename, const gchar *orig_filename,
+                         const gchar *output_filename, GError **error)
 {
        LzxPatchHeader *lzx_h = NULL;
        guint total_decomp_size = 0;
@@ -539,4 +478,4 @@ exit:
 
        return ret;
 }
-#endif /* USE_MSPACK */
+
diff --git a/src/addressbook/lzx/readbits.h b/src/addressbook/mspack/readbits.h
similarity index 100%
rename from src/addressbook/lzx/readbits.h
rename to src/addressbook/mspack/readbits.h
diff --git a/src/addressbook/lzx/readhuff.h b/src/addressbook/mspack/readhuff.h
similarity index 100%
rename from src/addressbook/lzx/readhuff.h
rename to src/addressbook/mspack/readhuff.h


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