Blame zlib-src/inflate.h

Packit Service 4a2782
/* inflate.h -- internal inflate state definition
Packit Service 4a2782
 * Copyright (C) 1995-2016 Mark Adler
Packit Service 4a2782
 * For conditions of distribution and use, see copyright notice in zlib.h
Packit Service 4a2782
 */
Packit Service 4a2782
Packit Service 4a2782
/* WARNING: this file should *not* be used by applications. It is
Packit Service 4a2782
   part of the implementation of the compression library and is
Packit Service 4a2782
   subject to change. Applications should only use zlib.h.
Packit Service 4a2782
 */
Packit Service 4a2782
Packit Service 4a2782
/* define NO_GZIP when compiling if you want to disable gzip header and
Packit Service 4a2782
   trailer decoding by inflate().  NO_GZIP would be used to avoid linking in
Packit Service 4a2782
   the crc code when it is not needed.  For shared libraries, gzip decoding
Packit Service 4a2782
   should be left enabled. */
Packit Service 4a2782
#ifndef NO_GZIP
Packit Service 4a2782
#  define GUNZIP
Packit Service 4a2782
#endif
Packit Service 4a2782
Packit Service 4a2782
/* Possible inflate modes between inflate() calls */
Packit Service 4a2782
typedef enum {
Packit Service 4a2782
    HEAD = 16180,   /* i: waiting for magic header */
Packit Service 4a2782
    FLAGS,      /* i: waiting for method and flags (gzip) */
Packit Service 4a2782
    TIME,       /* i: waiting for modification time (gzip) */
Packit Service 4a2782
    OS,         /* i: waiting for extra flags and operating system (gzip) */
Packit Service 4a2782
    EXLEN,      /* i: waiting for extra length (gzip) */
Packit Service 4a2782
    EXTRA,      /* i: waiting for extra bytes (gzip) */
Packit Service 4a2782
    NAME,       /* i: waiting for end of file name (gzip) */
Packit Service 4a2782
    COMMENT,    /* i: waiting for end of comment (gzip) */
Packit Service 4a2782
    HCRC,       /* i: waiting for header crc (gzip) */
Packit Service 4a2782
    DICTID,     /* i: waiting for dictionary check value */
Packit Service 4a2782
    DICT,       /* waiting for inflateSetDictionary() call */
Packit Service 4a2782
        TYPE,       /* i: waiting for type bits, including last-flag bit */
Packit Service 4a2782
        TYPEDO,     /* i: same, but skip check to exit inflate on new block */
Packit Service 4a2782
        STORED,     /* i: waiting for stored size (length and complement) */
Packit Service 4a2782
        COPY_,      /* i/o: same as COPY below, but only first time in */
Packit Service 4a2782
        COPY,       /* i/o: waiting for input or output to copy stored block */
Packit Service 4a2782
        TABLE,      /* i: waiting for dynamic block table lengths */
Packit Service 4a2782
        LENLENS,    /* i: waiting for code length code lengths */
Packit Service 4a2782
        CODELENS,   /* i: waiting for length/lit and distance code lengths */
Packit Service 4a2782
            LEN_,       /* i: same as LEN below, but only first time in */
Packit Service 4a2782
            LEN,        /* i: waiting for length/lit/eob code */
Packit Service 4a2782
            LENEXT,     /* i: waiting for length extra bits */
Packit Service 4a2782
            DIST,       /* i: waiting for distance code */
Packit Service 4a2782
            DISTEXT,    /* i: waiting for distance extra bits */
Packit Service 4a2782
            MATCH,      /* o: waiting for output space to copy string */
Packit Service 4a2782
            LIT,        /* o: waiting for output space to write literal */
Packit Service 4a2782
    CHECK,      /* i: waiting for 32-bit check value */
Packit Service 4a2782
    LENGTH,     /* i: waiting for 32-bit length (gzip) */
Packit Service 4a2782
    DONE,       /* finished check, done -- remain here until reset */
Packit Service 4a2782
    BAD,        /* got a data error -- remain here until reset */
Packit Service 4a2782
    MEM,        /* got an inflate() memory error -- remain here until reset */
Packit Service 4a2782
    SYNC        /* looking for synchronization bytes to restart inflate() */
Packit Service 4a2782
} inflate_mode;
Packit Service 4a2782
Packit Service 4a2782
/*
Packit Service 4a2782
    State transitions between above modes -
Packit Service 4a2782
Packit Service 4a2782
    (most modes can go to BAD or MEM on error -- not shown for clarity)
Packit Service 4a2782
Packit Service 4a2782
    Process header:
Packit Service 4a2782
        HEAD -> (gzip) or (zlib) or (raw)
Packit Service 4a2782
        (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT ->
Packit Service 4a2782
                  HCRC -> TYPE
Packit Service 4a2782
        (zlib) -> DICTID or TYPE
Packit Service 4a2782
        DICTID -> DICT -> TYPE
Packit Service 4a2782
        (raw) -> TYPEDO
Packit Service 4a2782
    Read deflate blocks:
Packit Service 4a2782
            TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK
Packit Service 4a2782
            STORED -> COPY_ -> COPY -> TYPE
Packit Service 4a2782
            TABLE -> LENLENS -> CODELENS -> LEN_
Packit Service 4a2782
            LEN_ -> LEN
Packit Service 4a2782
    Read deflate codes in fixed or dynamic block:
Packit Service 4a2782
                LEN -> LENEXT or LIT or TYPE
Packit Service 4a2782
                LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
Packit Service 4a2782
                LIT -> LEN
Packit Service 4a2782
    Process trailer:
Packit Service 4a2782
        CHECK -> LENGTH -> DONE
Packit Service 4a2782
 */
Packit Service 4a2782
Packit Service 4a2782
/* State maintained between inflate() calls -- approximately 7K bytes, not
Packit Service 4a2782
   including the allocated sliding window, which is up to 32K bytes. */
Packit Service 4a2782
struct inflate_state {
Packit Service 4a2782
    z_streamp strm;             /* pointer back to this zlib stream */
Packit Service 4a2782
    inflate_mode mode;          /* current inflate mode */
Packit Service 4a2782
    int last;                   /* true if processing last block */
Packit Service 4a2782
    int wrap;                   /* bit 0 true for zlib, bit 1 true for gzip,
Packit Service 4a2782
                                   bit 2 true to validate check value */
Packit Service 4a2782
    int havedict;               /* true if dictionary provided */
Packit Service 4a2782
    int flags;                  /* gzip header method and flags (0 if zlib) */
Packit Service 4a2782
    unsigned dmax;              /* zlib header max distance (INFLATE_STRICT) */
Packit Service 4a2782
    unsigned long check;        /* protected copy of check value */
Packit Service 4a2782
    unsigned long total;        /* protected copy of output count */
Packit Service 4a2782
    gz_headerp head;            /* where to save gzip header information */
Packit Service 4a2782
        /* sliding window */
Packit Service 4a2782
    unsigned wbits;             /* log base 2 of requested window size */
Packit Service 4a2782
    unsigned wsize;             /* window size or zero if not using window */
Packit Service 4a2782
    unsigned whave;             /* valid bytes in the window */
Packit Service 4a2782
    unsigned wnext;             /* window write index */
Packit Service 4a2782
    unsigned char FAR *window;  /* allocated sliding window, if needed */
Packit Service 4a2782
        /* bit accumulator */
Packit Service 4a2782
    unsigned long hold;         /* input bit accumulator */
Packit Service 4a2782
    unsigned bits;              /* number of bits in "in" */
Packit Service 4a2782
        /* for string and stored block copying */
Packit Service 4a2782
    unsigned length;            /* literal or length of data to copy */
Packit Service 4a2782
    unsigned offset;            /* distance back to copy string from */
Packit Service 4a2782
        /* for table and code decoding */
Packit Service 4a2782
    unsigned extra;             /* extra bits needed */
Packit Service 4a2782
        /* fixed and dynamic code tables */
Packit Service 4a2782
    code const FAR *lencode;    /* starting table for length/literal codes */
Packit Service 4a2782
    code const FAR *distcode;   /* starting table for distance codes */
Packit Service 4a2782
    unsigned lenbits;           /* index bits for lencode */
Packit Service 4a2782
    unsigned distbits;          /* index bits for distcode */
Packit Service 4a2782
        /* dynamic table building */
Packit Service 4a2782
    unsigned ncode;             /* number of code length code lengths */
Packit Service 4a2782
    unsigned nlen;              /* number of length code lengths */
Packit Service 4a2782
    unsigned ndist;             /* number of distance code lengths */
Packit Service 4a2782
    unsigned have;              /* number of code lengths in lens[] */
Packit Service 4a2782
    code FAR *next;             /* next available space in codes[] */
Packit Service 4a2782
    unsigned short lens[320];   /* temporary storage for code lengths */
Packit Service 4a2782
    unsigned short work[288];   /* work area for code table building */
Packit Service 4a2782
    code codes[ENOUGH];         /* space for code tables */
Packit Service 4a2782
    int sane;                   /* if false, allow invalid distance too far */
Packit Service 4a2782
    int back;                   /* bits back of last unprocessed length/lit */
Packit Service 4a2782
    unsigned was;               /* initial length of match */
Packit Service 4a2782
};