Changeset 4b0cd2f


Ignore:
Timestamp:
06/30/14 13:20:00 (6 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
d19ff50
Parents:
3a3b661
Message:

Integrate lzma into libwandio properly

Update configure to detect lzma properly.
Add missing get_compression_type API function to wandio code.
Add code to detect if input file is LZMA.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • configure.in

    rabf01b6 r4b0cd2f  
    580580)
    581581
     582AC_ARG_WITH([lzma],
     583        AC_HELP_STRING([--with-lzma], [build with support for lzma compressed files]))
     584
     585AS_IF([test "x$with_lzma" != "xno"],
     586        [
     587        AC_CHECK_LIB(lzma, lzma_code, have_lzma=yes, have_lzma=no)
     588        ], [have_lzma=no])
     589
     590AS_IF([test "x$have_lzma" = "xyes"], [
     591        if test "$ac_cv_lib_lzma_code" != "none required"; then
     592                LIBWANDIO_LIBS="$LIBWANDIO_LIBS -llzma"
     593        fi
     594        AC_DEFINE(HAVE_LIBLZMA, 1, "Compiled with lzma support")
     595        with_lzma=yes],
     596
     597       
     598        [AS_IF([test "x$with_lzma" = "xyes"],
     599                [AC_MSG_ERROR([lzma requested but not found])])
     600        AC_DEFINE(HAVE_LIBLZMA, 0, "Compiled with lzma support")
     601        with_lzma=no]
     602)
    582603
    583604# Define automake conditionals for use in our Makefile.am files
     
    594615AM_CONDITIONAL([HAVE_ZLIB], [test "x$with_zlib" != "xno"])
    595616AM_CONDITIONAL([HAVE_LZO], [ test "x$with_lzo" != "xno"])
     617AM_CONDITIONAL([HAVE_LZMA], [ test "x$with_lzma" != "xno"])
    596618
    597619# Check for miscellaneous programs
     
    648670reportopt "Compiled with compressed trace (bz2) support" $with_bzip2
    649671reportopt "Compiled with compressed trace (lzo write only) support" $with_lzo
     672reportopt "Compiled with compressed trace (lzma) support" $with_lzma
    650673if test x"$libtrace_dag" = xtrue; then
    651674        if test "$libtrace_dag_version" = 24; then
  • libwandio/Makefile.am

    rbd119b3 r4b0cd2f  
    2424endif
    2525
     26if HAVE_LZMA
     27LIBTRACEIO_LZMA=ior-lzma.c iow-lzma.c
     28else
     29LIBTRACEIO_LZMA=
     30endif
     31
    2632libwandio_la_SOURCES=wandio.c ior-peek.c ior-stdio.c ior-thread.c \
    2733                iow-stdio.c iow-thread.c wandio.h wandio_internal.h \
    28                 $(LIBTRACEIO_ZLIB) $(LIBTRACEIO_BZLIB) $(LIBTRACEIO_LZO)
     34                $(LIBTRACEIO_ZLIB) $(LIBTRACEIO_BZLIB) $(LIBTRACEIO_LZO) \
     35                $(LIBTRACEIO_LZMA)
    2936
    3037AM_CPPFLAGS = @ADD_INCLS@
     
    3239libwandio_la_LDFLAGS=-version-info 1:0:0 @ADD_LDFLAGS@
    3340
     41bin_PROGRAMS = wandiocat
     42wandiocat_SOURCES = wcat.c
     43wandiocat_CFLAGS = -I"$(top_srcdir)/libwandio"
     44wandiocat_CXXFLAGS = -I"$(top_srcdir)/libwandio"
     45wandiocat_LDFLAGS = -L"$(top_srcdir)/libwandio" -lwandio
  • libwandio/wandio.c

    r10f924c r4b0cd2f  
    4646 */
    4747
    48 struct compression_type compression_type[]  = {
    49         { "GZ",         "gz",   WANDIO_COMPRESS_ZLIB    },
    50         { "BZ2",        "bz2",  WANDIO_COMPRESS_BZ2     },
    51         { "LZO",        "lzo",  WANDIO_COMPRESS_LZO     },
     48struct wandio_compression_type compression_type[]  = {
     49        { "gzip",       "gz",   WANDIO_COMPRESS_ZLIB    },
     50        { "bzip2",      "bz2",  WANDIO_COMPRESS_BZ2     },
     51        { "lzo",        "lzo",  WANDIO_COMPRESS_LZO     },
     52        { "lzma",       "xz",  WANDIO_COMPRESS_LZMA     },
    5253        { "NONE",       "",     WANDIO_COMPRESS_NONE    }
    5354};
     
    141142        DEBUG_PIPELINE("peek");
    142143        io_t *io = peek_open(stdio_open(filename));
    143         char buffer[1024];
     144        unsigned char buffer[1024];
    144145        int len;
    145146        if (!io)
     
    151152
    152153        if (autodetect) {
    153                 if (len>=3 && buffer[0] == '\037' && buffer[1] == '\213' &&
     154                if (len>=3 && buffer[0] == 0x1f && buffer[1] == 0x8b &&
    154155                                buffer[2] == 0x08) {
    155156#if HAVE_LIBZ
     
    162163                }
    163164                /* Auto detect compress(1) compressed data (gzip can read this) */
    164                 if (len>=2 && buffer[0] == '\037' && buffer[1] == '\235') {
     165                if (len>=2 && buffer[0] == 0x1f && buffer[1] == 0x9d) {
    165166#if HAVE_LIBZ
    166167                        DEBUG_PIPELINE("zlib");
     
    182183#endif
    183184                }
     185
     186                if (len >=5 && buffer[0] == 0xfd && buffer[1] == '7' &&
     187                                buffer[2] == 'z' && buffer[3] == 'X' &&
     188                                buffer[4] == 'Z') {
     189#if HAVE_LIBLZMA
     190                        DEBUG_PIPELINE("lzma");
     191                        io = lzma_open(io);
     192#else
     193                        fprintf(stderr, "File %s is lzma compressed but libtrace has not been built with lzma support!\n", filename);
     194                        return NULL;
     195#endif
     196                }
    184197        }       
    185198        /* Now open a threaded, peekable reader using the appropriate module
     
    193206        DEBUG_PIPELINE("peek");
    194207        return peek_open(io);
     208}
     209
     210DLLEXPORT struct wandio_compression_type *wandio_lookup_compression_type(
     211        const char *name) {
     212
     213        struct wandio_compression_type *wct = compression_type;
     214
     215        while (strcmp(wct->name, "NONE") != 0) {
     216                if (strcmp(wct->name, name) == 0)
     217                        return wct;
     218                wct++;
     219        }
     220
     221        return NULL;
    195222}
    196223
     
    291318        }
    292319#endif
     320#if HAVE_LIBLZMA
     321        else if (compression_level != 0 &&
     322            compress_type == WANDIO_COMPRESS_LZMA) {
     323                iow = lzma_wopen(iow,compression_level);
     324        }
     325#endif
    293326        /* Open a threaded writer */
    294327        if (use_threads)
  • libwandio/wandio.h

    rc7021d9 r4b0cd2f  
    6666
    6767/** Structure defining a supported compression method */
    68 struct compression_type {
     68struct wandio_compression_type {
    6969        /** Name of the compression method */
    7070        const char *name;
     
    7777
    7878/** The list of supported compression methods */
    79 extern struct compression_type compression_type[];
     79extern struct wandio_compression_type compression_type[];
    8080
    8181/** Structure defining a libtrace IO reader module */
     
    178178        /** LZO compression */
    179179        WANDIO_COMPRESS_LZO     = 3,
     180        /** LZMA compression */
     181        WANDIO_COMPRESS_LZMA    = 4,
    180182        /** All supported methods - used as a bitmask */
    181183        WANDIO_COMPRESS_MASK    = 7
     
    193195io_t *zlib_open(io_t *parent);
    194196io_t *thread_open(io_t *parent);
     197io_t *lzma_open(io_t *parent);
    195198io_t *peek_open(io_t *parent);
    196199io_t *stdio_open(const char *filename);
     
    199202iow_t *bz_wopen(iow_t *child, int compress_level);
    200203iow_t *lzo_wopen(iow_t *child, int compress_level);
     204iow_t *lzma_wopen(iow_t *child, int compress_level);
    201205iow_t *thread_wopen(iow_t *child);
    202206iow_t *stdio_wopen(const char *filename, int fileflags);
     
    211215 *
    212216 * @{ */
     217
     218/** Given a string describing the compression method, finds the internal
     219  * data structure representing that method. This is mostly useful for
     220  * nicely mapping a method name to the internal libwandio compression
     221  * method enum when configuring an output file.
     222  *
     223  * @param name          The compression method name as a string, e.g. "gzip",
     224  *                      "bzip2", "lzo" or "lzma".
     225  * @return A pointer to the compression_type structure representing the
     226  * compression method or NULL if no match can be found.
     227  *
     228  */
     229struct wandio_compression_type *wandio_lookup_compression_type(const char *name);
    213230
    214231/** Creates a new libtrace IO reader and opens the provided file for reading.
Note: See TracChangeset for help on using the changeset viewer.