inflate.h 5.5 KB

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