ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

174 lines
4.5 KiB

  1. // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
  2. // (C) Copyright 2003-2007 Jonathan Turkanis
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
  5. // See http://www.boost.org/libs/iostreams for documentation.
  6. // To configure Boost to work with libbz2, see the
  7. // installation instructions here:
  8. // http://boost.org/libs/iostreams/doc/index.html?path=7
  9. // Define BOOST_IOSTREAMS_SOURCE so that <boost/iostreams/detail/config.hpp>
  10. // knows that we are building the library (possibly exporting code), rather
  11. // than using it (possibly importing code).
  12. #define CPPCMS_BOOST_IOSTREAMS_SOURCE
  13. #include <cppcms_boost/iostreams/detail/config/dyn_link.hpp>
  14. #include <cppcms_boost/iostreams/filter/gzip.hpp>
  15. namespace cppcms_boost { namespace iostreams {
  16. //------------------Implementation of gzip_header-----------------------------//
  17. namespace detail {
  18. void gzip_header::process(char c)
  19. {
  20. uint8_t value = static_cast<uint8_t>(c);
  21. switch (state_) {
  22. case s_id1:
  23. if (value != gzip::magic::id1)
  24. throw gzip_error(gzip::bad_header);
  25. state_ = s_id2;
  26. break;
  27. case s_id2:
  28. if (value != gzip::magic::id2)
  29. throw gzip_error(gzip::bad_header);
  30. state_ = s_cm;
  31. break;
  32. case s_cm:
  33. if (value != gzip::method::deflate)
  34. throw gzip_error(gzip::bad_method);
  35. state_ = s_flg;
  36. break;
  37. case s_flg:
  38. flags_ = value;
  39. state_ = s_mtime;
  40. break;
  41. case s_mtime:
  42. mtime_ += value << (offset_ * 8);
  43. if (offset_ == 3) {
  44. state_ = s_xfl;
  45. offset_ = 0;
  46. } else {
  47. ++offset_;
  48. }
  49. break;
  50. case s_xfl:
  51. state_ = s_os;
  52. break;
  53. case s_os:
  54. os_ = value;
  55. if (flags_ & gzip::flags::extra) {
  56. state_ = s_extra;
  57. } else if (flags_ & gzip::flags::name) {
  58. state_ = s_name;
  59. } else if (flags_ & gzip::flags::comment) {
  60. state_ = s_comment;
  61. } else if (flags_ & gzip::flags::header_crc) {
  62. state_ = s_hcrc;
  63. } else {
  64. state_ = s_done;
  65. }
  66. break;
  67. case s_xlen:
  68. xlen_ += value << (offset_ * 8);
  69. if (offset_ == 1) {
  70. state_ = s_extra;
  71. offset_ = 0;
  72. } else {
  73. ++offset_;
  74. }
  75. break;
  76. case s_extra:
  77. if (--xlen_ == 0) {
  78. if (flags_ & gzip::flags::name) {
  79. state_ = s_name;
  80. } else if (flags_ & gzip::flags::comment) {
  81. state_ = s_comment;
  82. } else if (flags_ & gzip::flags::header_crc) {
  83. state_ = s_hcrc;
  84. } else {
  85. state_ = s_done;
  86. }
  87. }
  88. break;
  89. case s_name:
  90. if (c != 0) {
  91. file_name_ += c;
  92. } else if (flags_ & gzip::flags::comment) {
  93. state_ = s_comment;
  94. } else if (flags_ & gzip::flags::header_crc) {
  95. state_ = s_hcrc;
  96. } else {
  97. state_ = s_done;
  98. }
  99. break;
  100. case s_comment:
  101. if (c != 0) {
  102. comment_ += c;
  103. } else if (flags_ & gzip::flags::header_crc) {
  104. state_ = s_hcrc;
  105. } else {
  106. state_ = s_done;
  107. }
  108. break;
  109. case s_hcrc:
  110. if (offset_ == 1) {
  111. state_ = s_done;
  112. offset_ = 0;
  113. } else {
  114. ++offset_;
  115. }
  116. break;
  117. default:
  118. assert(0);
  119. }
  120. }
  121. void gzip_header::reset()
  122. {
  123. file_name_.clear();
  124. comment_.clear();
  125. os_ = flags_ = offset_ = xlen_ = 0;
  126. mtime_ = 0;
  127. state_ = s_id1;
  128. }
  129. //------------------Implementation of gzip_footer-----------------------------//
  130. void gzip_footer::process(char c)
  131. {
  132. uint8_t value = static_cast<uint8_t>(c);
  133. if (state_ == s_crc) {
  134. crc_ += value << (offset_ * 8);
  135. if (offset_ == 3) {
  136. state_ = s_isize;
  137. offset_ = 0;
  138. } else {
  139. ++offset_;
  140. }
  141. } else if (state_ == s_isize) {
  142. isize_ += value << (offset_ * 8);
  143. if (offset_ == 3) {
  144. state_ = s_done;
  145. offset_ = 0;
  146. } else {
  147. ++offset_;
  148. }
  149. } else {
  150. assert(0);
  151. }
  152. }
  153. void gzip_footer::reset()
  154. {
  155. crc_ = isize_ = offset_ = 0;
  156. state_ = s_crc;
  157. }
  158. } // End namespace boost::iostreams::detail.
  159. } } // End namespaces iostreams, boost.