11cb0ef41Sopenharmony_ci/* inflate.h -- internal inflate state definition 21cb0ef41Sopenharmony_ci * Copyright (C) 1995-2019 Mark Adler 31cb0ef41Sopenharmony_ci * For conditions of distribution and use, see copyright notice in zlib.h 41cb0ef41Sopenharmony_ci */ 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ci/* WARNING: this file should *not* be used by applications. It is 71cb0ef41Sopenharmony_ci part of the implementation of the compression library and is 81cb0ef41Sopenharmony_ci subject to change. Applications should only use zlib.h. 91cb0ef41Sopenharmony_ci */ 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci/* define NO_GZIP when compiling if you want to disable gzip header and 121cb0ef41Sopenharmony_ci trailer decoding by inflate(). NO_GZIP would be used to avoid linking in 131cb0ef41Sopenharmony_ci the crc code when it is not needed. For shared libraries, gzip decoding 141cb0ef41Sopenharmony_ci should be left enabled. */ 151cb0ef41Sopenharmony_ci#ifndef NO_GZIP 161cb0ef41Sopenharmony_ci# define GUNZIP 171cb0ef41Sopenharmony_ci#endif 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci/* Possible inflate modes between inflate() calls */ 201cb0ef41Sopenharmony_citypedef enum { 211cb0ef41Sopenharmony_ci HEAD = 16180, /* i: waiting for magic header */ 221cb0ef41Sopenharmony_ci FLAGS, /* i: waiting for method and flags (gzip) */ 231cb0ef41Sopenharmony_ci TIME, /* i: waiting for modification time (gzip) */ 241cb0ef41Sopenharmony_ci OS, /* i: waiting for extra flags and operating system (gzip) */ 251cb0ef41Sopenharmony_ci EXLEN, /* i: waiting for extra length (gzip) */ 261cb0ef41Sopenharmony_ci EXTRA, /* i: waiting for extra bytes (gzip) */ 271cb0ef41Sopenharmony_ci NAME, /* i: waiting for end of file name (gzip) */ 281cb0ef41Sopenharmony_ci COMMENT, /* i: waiting for end of comment (gzip) */ 291cb0ef41Sopenharmony_ci HCRC, /* i: waiting for header crc (gzip) */ 301cb0ef41Sopenharmony_ci DICTID, /* i: waiting for dictionary check value */ 311cb0ef41Sopenharmony_ci DICT, /* waiting for inflateSetDictionary() call */ 321cb0ef41Sopenharmony_ci TYPE, /* i: waiting for type bits, including last-flag bit */ 331cb0ef41Sopenharmony_ci TYPEDO, /* i: same, but skip check to exit inflate on new block */ 341cb0ef41Sopenharmony_ci STORED, /* i: waiting for stored size (length and complement) */ 351cb0ef41Sopenharmony_ci COPY_, /* i/o: same as COPY below, but only first time in */ 361cb0ef41Sopenharmony_ci COPY, /* i/o: waiting for input or output to copy stored block */ 371cb0ef41Sopenharmony_ci TABLE, /* i: waiting for dynamic block table lengths */ 381cb0ef41Sopenharmony_ci LENLENS, /* i: waiting for code length code lengths */ 391cb0ef41Sopenharmony_ci CODELENS, /* i: waiting for length/lit and distance code lengths */ 401cb0ef41Sopenharmony_ci LEN_, /* i: same as LEN below, but only first time in */ 411cb0ef41Sopenharmony_ci LEN, /* i: waiting for length/lit/eob code */ 421cb0ef41Sopenharmony_ci LENEXT, /* i: waiting for length extra bits */ 431cb0ef41Sopenharmony_ci DIST, /* i: waiting for distance code */ 441cb0ef41Sopenharmony_ci DISTEXT, /* i: waiting for distance extra bits */ 451cb0ef41Sopenharmony_ci MATCH, /* o: waiting for output space to copy string */ 461cb0ef41Sopenharmony_ci LIT, /* o: waiting for output space to write literal */ 471cb0ef41Sopenharmony_ci CHECK, /* i: waiting for 32-bit check value */ 481cb0ef41Sopenharmony_ci LENGTH, /* i: waiting for 32-bit length (gzip) */ 491cb0ef41Sopenharmony_ci DONE, /* finished check, done -- remain here until reset */ 501cb0ef41Sopenharmony_ci BAD, /* got a data error -- remain here until reset */ 511cb0ef41Sopenharmony_ci MEM, /* got an inflate() memory error -- remain here until reset */ 521cb0ef41Sopenharmony_ci SYNC /* looking for synchronization bytes to restart inflate() */ 531cb0ef41Sopenharmony_ci} inflate_mode; 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_ci/* 561cb0ef41Sopenharmony_ci State transitions between above modes - 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci (most modes can go to BAD or MEM on error -- not shown for clarity) 591cb0ef41Sopenharmony_ci 601cb0ef41Sopenharmony_ci Process header: 611cb0ef41Sopenharmony_ci HEAD -> (gzip) or (zlib) or (raw) 621cb0ef41Sopenharmony_ci (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT -> 631cb0ef41Sopenharmony_ci HCRC -> TYPE 641cb0ef41Sopenharmony_ci (zlib) -> DICTID or TYPE 651cb0ef41Sopenharmony_ci DICTID -> DICT -> TYPE 661cb0ef41Sopenharmony_ci (raw) -> TYPEDO 671cb0ef41Sopenharmony_ci Read deflate blocks: 681cb0ef41Sopenharmony_ci TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK 691cb0ef41Sopenharmony_ci STORED -> COPY_ -> COPY -> TYPE 701cb0ef41Sopenharmony_ci TABLE -> LENLENS -> CODELENS -> LEN_ 711cb0ef41Sopenharmony_ci LEN_ -> LEN 721cb0ef41Sopenharmony_ci Read deflate codes in fixed or dynamic block: 731cb0ef41Sopenharmony_ci LEN -> LENEXT or LIT or TYPE 741cb0ef41Sopenharmony_ci LENEXT -> DIST -> DISTEXT -> MATCH -> LEN 751cb0ef41Sopenharmony_ci LIT -> LEN 761cb0ef41Sopenharmony_ci Process trailer: 771cb0ef41Sopenharmony_ci CHECK -> LENGTH -> DONE 781cb0ef41Sopenharmony_ci */ 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_ci/* State maintained between inflate() calls -- approximately 7K bytes, not 811cb0ef41Sopenharmony_ci including the allocated sliding window, which is up to 32K bytes. */ 821cb0ef41Sopenharmony_cistruct inflate_state { 831cb0ef41Sopenharmony_ci z_streamp strm; /* pointer back to this zlib stream */ 841cb0ef41Sopenharmony_ci inflate_mode mode; /* current inflate mode */ 851cb0ef41Sopenharmony_ci int last; /* true if processing last block */ 861cb0ef41Sopenharmony_ci int wrap; /* bit 0 true for zlib, bit 1 true for gzip, 871cb0ef41Sopenharmony_ci bit 2 true to validate check value */ 881cb0ef41Sopenharmony_ci int havedict; /* true if dictionary provided */ 891cb0ef41Sopenharmony_ci int flags; /* gzip header method and flags, 0 if zlib, or 901cb0ef41Sopenharmony_ci -1 if raw or no header yet */ 911cb0ef41Sopenharmony_ci unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ 921cb0ef41Sopenharmony_ci unsigned long check; /* protected copy of check value */ 931cb0ef41Sopenharmony_ci unsigned long total; /* protected copy of output count */ 941cb0ef41Sopenharmony_ci gz_headerp head; /* where to save gzip header information */ 951cb0ef41Sopenharmony_ci /* sliding window */ 961cb0ef41Sopenharmony_ci unsigned wbits; /* log base 2 of requested window size */ 971cb0ef41Sopenharmony_ci unsigned wsize; /* window size or zero if not using window */ 981cb0ef41Sopenharmony_ci unsigned whave; /* valid bytes in the window */ 991cb0ef41Sopenharmony_ci unsigned wnext; /* window write index */ 1001cb0ef41Sopenharmony_ci unsigned char FAR *window; /* allocated sliding window, if needed */ 1011cb0ef41Sopenharmony_ci /* bit accumulator */ 1021cb0ef41Sopenharmony_ci unsigned long hold; /* input bit accumulator */ 1031cb0ef41Sopenharmony_ci unsigned bits; /* number of bits in "in" */ 1041cb0ef41Sopenharmony_ci /* for string and stored block copying */ 1051cb0ef41Sopenharmony_ci unsigned length; /* literal or length of data to copy */ 1061cb0ef41Sopenharmony_ci unsigned offset; /* distance back to copy string from */ 1071cb0ef41Sopenharmony_ci /* for table and code decoding */ 1081cb0ef41Sopenharmony_ci unsigned extra; /* extra bits needed */ 1091cb0ef41Sopenharmony_ci /* fixed and dynamic code tables */ 1101cb0ef41Sopenharmony_ci code const FAR *lencode; /* starting table for length/literal codes */ 1111cb0ef41Sopenharmony_ci code const FAR *distcode; /* starting table for distance codes */ 1121cb0ef41Sopenharmony_ci unsigned lenbits; /* index bits for lencode */ 1131cb0ef41Sopenharmony_ci unsigned distbits; /* index bits for distcode */ 1141cb0ef41Sopenharmony_ci /* dynamic table building */ 1151cb0ef41Sopenharmony_ci unsigned ncode; /* number of code length code lengths */ 1161cb0ef41Sopenharmony_ci unsigned nlen; /* number of length code lengths */ 1171cb0ef41Sopenharmony_ci unsigned ndist; /* number of distance code lengths */ 1181cb0ef41Sopenharmony_ci unsigned have; /* number of code lengths in lens[] */ 1191cb0ef41Sopenharmony_ci code FAR *next; /* next available space in codes[] */ 1201cb0ef41Sopenharmony_ci unsigned short lens[320]; /* temporary storage for code lengths */ 1211cb0ef41Sopenharmony_ci unsigned short work[288]; /* work area for code table building */ 1221cb0ef41Sopenharmony_ci code codes[ENOUGH]; /* space for code tables */ 1231cb0ef41Sopenharmony_ci int sane; /* if false, allow invalid distance too far */ 1241cb0ef41Sopenharmony_ci int back; /* bits back of last unprocessed length/lit */ 1251cb0ef41Sopenharmony_ci unsigned was; /* initial length of match */ 1261cb0ef41Sopenharmony_ci}; 127