Changeset 0acfd1e


Ignore:
Timestamp:
05/14/13 11:48:23 (8 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, 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:
d57ae6f
Parents:
460855d
Message:
  • Added a wandio_create_uncompressed function to the libwandio API. It's there for people who are running into problems with the compression autodetection incorrectly thinking their uncompressed files are actually compressed. Hopefully, this should be very very rare, but it can't hurt to have it right?
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lib/format_helper.c

    r4c484de r0acfd1e  
    247247io_t *trace_open_file(libtrace_t *trace)
    248248{
     249        int ad = (trace->format->type != TRACE_FORMAT_ERF);
    249250        io_t *io=wandio_create(trace->uridata);
     251
    250252        if (!io) {
    251253                if (errno != 0) {
  • libwandio/wandio.c

    r460855d r0acfd1e  
    125125#endif
    126126
    127 DLLEXPORT io_t *wandio_create(const char *filename)
     127static io_t *create_io_reader(const char *filename, int autodetect)
    128128{
    129129        parse_env();
     
    141141                return NULL;
    142142        len = wandio_peek(io, buffer, sizeof(buffer));
    143         /* Auto detect gzip compressed data */
    144         if (len>=3 && buffer[0] == '\037' && buffer[1] == '\213' &&
    145                         buffer[2] == 0x08) {
     143        /* Auto detect gzip compressed data -- if autodetect is false,
     144         * instead we just assume uncompressed.
     145         */
     146
     147        if (autodetect) {
     148                if (len>=3 && buffer[0] == '\037' && buffer[1] == '\213' &&
     149                                buffer[2] == 0x08) {
    146150#if HAVE_LIBZ
    147                 DEBUG_PIPELINE("zlib");
    148                 io = zlib_open(io);
     151                        DEBUG_PIPELINE("zlib");
     152                        io = zlib_open(io);
    149153#else
    150                 fprintf(stderr, "File %s is gzip compressed but libtrace has not been built with zlib support!\n", filename);
    151                 return NULL;
    152 #endif
    153         }
    154         /* Auto detect compress(1) compressed data (gzip can read this) */
    155         if (len>=2 && buffer[0] == '\037' && buffer[1] == '\235') {
     154                        fprintf(stderr, "File %s is gzip compressed but libtrace has not been built with zlib support!\n", filename);
     155                        return NULL;
     156#endif
     157                }
     158                /* Auto detect compress(1) compressed data (gzip can read this) */
     159                if (len>=2 && buffer[0] == '\037' && buffer[1] == '\235') {
    156160#if HAVE_LIBZ
    157                 DEBUG_PIPELINE("zlib");
    158                 io = zlib_open(io);
     161                        DEBUG_PIPELINE("zlib");
     162                        io = zlib_open(io);
    159163#else
    160                 fprintf(stderr, "File %s is compress(1) compressed but libtrace has not been built with zlib support!\n", filename);
    161                 return NULL;
    162 #endif
    163         }
    164 
    165         /* Auto detect bzip compressed data */
    166         if (len>=3 && buffer[0] == 'B' && buffer[1] == 'Z' && buffer[2] == 'h') {
     164                        fprintf(stderr, "File %s is compress(1) compressed but libtrace has not been built with zlib support!\n", filename);
     165                        return NULL;
     166#endif
     167                }
     168
     169                /* Auto detect bzip compressed data */
     170                if (len>=3 && buffer[0] == 'B' && buffer[1] == 'Z' && buffer[2] == 'h') {
    167171#if HAVE_LIBBZ2
    168                 DEBUG_PIPELINE("bzip");
    169                 io = bz_open(io);
     172                        DEBUG_PIPELINE("bzip");
     173                        io = bz_open(io);
    170174#else
    171                 fprintf(stderr, "File %s is bzip compressed but libtrace has not been built with bzip2 support!\n", filename);
    172                 return NULL;
    173 #endif
    174         }
    175        
     175                        fprintf(stderr, "File %s is bzip compressed but libtrace has not been built with bzip2 support!\n", filename);
     176                        return NULL;
     177#endif
     178                }
     179        }       
    176180        /* Now open a threaded, peekable reader using the appropriate module
    177181         * to read the data */
     
    185189        return peek_open(io);
    186190}
     191
     192DLLEXPORT io_t *wandio_create(const char *filename) {
     193        return create_io_reader(filename, 1);
     194}
     195
     196DLLEXPORT io_t *wandio_create_uncompressed(const char *filename) {
     197        return create_io_reader(filename, 0);
     198}
     199
    187200
    188201DLLEXPORT off_t wandio_tell(io_t *io)
  • libwandio/wandio.h

    rbd37451 r0acfd1e  
    233233 * @return A pointer to a new libtrace IO reader, or NULL if an error occurs
    234234 *
    235  * This function will attempt to detect the compression format used for the
    236  * given file (if any), provided that libtrace was built with the appropriate
    237  * libraries.
     235 * The compression format will be determined automatically by peeking at the
     236 * first few bytes of the file and comparing them against known compression
     237 * file header formats. If no formats match, the file will be assumed to be
     238 * uncompressed.
    238239 */
    239240io_t *wandio_create(const char *filename);
     241
     242/** Creates a new libtrace IO reader and opens the provided file for reading.
     243 *
     244 * @param filename      The name of the file to open
     245 * @return A pointer to a new libtrace IO reader, or NULL if an error occurs
     246 *
     247 * Unlike wandio_create, this function will always assume the file is
     248 * uncompressed and therefore not run the compression autodetection algorithm.
     249 *
     250 * Use this function if you are only working with uncompressed files and are
     251 * running into problems with the start of your files resembling compression
     252 * format headers. Otherwise, you should really be using wandio_create.
     253 */
     254io_t *wandio_create_uncompressed(const char *filename);
    240255
    241256/** Returns the current offset of the read pointer for a libtrace IO reader.
Note: See TracChangeset for help on using the changeset viewer.