inflate.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* inflate.h -- internal inflate state definition
  2. * Copyright (C) 1995-2004 Mark Adler
  3. * For conditions of distribution and use, see copyright notice in zlib.h
  4. */
  5. /* WARNING: this file should *not* be used by applications. It is
  6. part of the implementation of the compression library and is
  7. subject to change. Applications should only use zlib.h.
  8. */
  9. /* Possible inflate modes between inflate() calls */
  10. typedef enum {
  11. HEAD, /* i: waiting for magic header */
  12. FLAGS, /* i: waiting for method and flags (gzip) */
  13. TIME, /* i: waiting for modification time (gzip) */
  14. OS, /* i: waiting for extra flags and operating system (gzip) */
  15. EXLEN, /* i: waiting for extra length (gzip) */
  16. EXTRA, /* i: waiting for extra bytes (gzip) */
  17. NAME, /* i: waiting for end of file name (gzip) */
  18. COMMENT, /* i: waiting for end of comment (gzip) */
  19. HCRC, /* i: waiting for header crc (gzip) */
  20. DICTID, /* i: waiting for dictionary check value */
  21. DICT, /* waiting for inflateSetDictionary() call */
  22. TYPE, /* i: waiting for type bits, including last-flag bit */
  23. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  24. STORED, /* i: waiting for stored size (length and complement) */
  25. COPY, /* i/o: waiting for input or output to copy stored block */
  26. TABLE, /* i: waiting for dynamic block table lengths */
  27. LENLENS, /* i: waiting for code length code lengths */
  28. CODELENS, /* i: waiting for length/lit and distance code lengths */
  29. LEN, /* i: waiting for length/lit code */
  30. LENEXT, /* i: waiting for length extra bits */
  31. DIST, /* i: waiting for distance code */
  32. DISTEXT, /* i: waiting for distance extra bits */
  33. MATCH, /* o: waiting for output space to copy string */
  34. LIT, /* o: waiting for output space to write literal */
  35. CHECK, /* i: waiting for 32-bit check value */
  36. LENGTH, /* i: waiting for 32-bit length (gzip) */
  37. DONE, /* finished check, done -- remain here until reset */
  38. BAD, /* got a data error -- remain here until reset */
  39. MEM, /* got an inflate() memory error -- remain here until reset */
  40. SYNC /* looking for synchronization bytes to restart inflate() */
  41. } inflate_mode;
  42. /*
  43. State transitions between above modes -
  44. (most modes can go to the BAD or MEM mode -- not shown for clarity)
  45. Process header:
  46. HEAD -> (gzip) or (zlib)
  47. (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME
  48. NAME -> COMMENT -> HCRC -> TYPE
  49. (zlib) -> DICTID or TYPE
  50. DICTID -> DICT -> TYPE
  51. Read deflate blocks:
  52. TYPE -> STORED or TABLE or LEN or CHECK
  53. STORED -> COPY -> TYPE
  54. TABLE -> LENLENS -> CODELENS -> LEN
  55. Read deflate codes:
  56. LEN -> LENEXT or LIT or TYPE
  57. LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
  58. LIT -> LEN
  59. Process trailer:
  60. CHECK -> LENGTH -> DONE
  61. */
  62. /* state maintained between inflate() calls. Approximately 7K bytes. */
  63. struct inflate_state {
  64. inflate_mode mode; /* current inflate mode */
  65. int last; /* true if processing last block */
  66. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  67. int havedict; /* true if dictionary provided */
  68. int flags; /* gzip header method and flags (0 if zlib) */
  69. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  70. unsigned long check; /* protected copy of check value */
  71. unsigned long total; /* protected copy of output count */
  72. /* gz_headerp head; */ /* where to save gzip header information */
  73. /* sliding window */
  74. unsigned wbits; /* log base 2 of requested window size */
  75. unsigned wsize; /* window size or zero if not using window */
  76. unsigned whave; /* valid bytes in the window */
  77. unsigned write; /* window write index */
  78. unsigned char *window; /* allocated sliding window, if needed */
  79. /* bit accumulator */
  80. unsigned long hold; /* input bit accumulator */
  81. unsigned bits; /* number of bits in "in" */
  82. /* for string and stored block copying */
  83. unsigned length; /* literal or length of data to copy */
  84. unsigned offset; /* distance back to copy string from */
  85. /* for table and code decoding */
  86. unsigned extra; /* extra bits needed */
  87. /* fixed and dynamic code tables */
  88. code const *lencode; /* starting table for length/literal codes */
  89. code const *distcode; /* starting table for distance codes */
  90. unsigned lenbits; /* index bits for lencode */
  91. unsigned distbits; /* index bits for distcode */
  92. /* dynamic table building */
  93. unsigned ncode; /* number of code length code lengths */
  94. unsigned nlen; /* number of length code lengths */
  95. unsigned ndist; /* number of distance code lengths */
  96. unsigned have; /* number of code lengths in lens[] */
  97. code *next; /* next available space in codes[] */
  98. unsigned short lens[320]; /* temporary storage for code lengths */
  99. unsigned short work[288]; /* work area for code table building */
  100. code codes[ENOUGH]; /* space for code tables */
  101. };