Browse Source

Removed dependency on locale cppcms_boost!!!! :-)))))))))))

master
Artyom Beilis 8 years ago
parent
commit
4d4ef0c2aa
7 changed files with 50 additions and 382 deletions
  1. +6
    -2
      CMakeLists.txt
  2. BIN
      cppcms_boost.tar.bz2
  3. +0
    -173
      cppcms_boost/src/gzip.cpp
  4. +0
    -191
      cppcms_boost/src/zlib.cpp
  5. +38
    -0
      private/crc32.h
  6. +3
    -8
      src/session_posix_file_storage.cpp
  7. +3
    -8
      src/session_win32_file_storage.cpp

+ 6
- 2
CMakeLists.txt View File

@@ -437,10 +437,14 @@ endif()

if(WINDOWS_NATIVE)
set(CPPCMS_SOURCES ${CPPCMS_SOURCES} src/session_win32_file_storage.cpp)
if(NOT DISABLE_GZIP)
set(CPPCMS_SOURCES ${CPPCMS_SOURCES} src/session_win32_file_storage.cpp)
endif()
set(CPPCMS_SOURCES ${CPPCMS_SOURCES} src/winservice.cpp)
else()
set(CPPCMS_SOURCES ${CPPCMS_SOURCES} src/session_posix_file_storage.cpp)
if(NOT DISABLE_GZIP)
set(CPPCMS_SOURCES ${CPPCMS_SOURCES} src/session_posix_file_storage.cpp)
endif()
set(CPPCMS_SOURCES ${CPPCMS_SOURCES} src/daemonize.cpp)
endif()



BIN
cppcms_boost.tar.bz2 View File


+ 0
- 173
cppcms_boost/src/gzip.cpp View File

@@ -1,173 +0,0 @@
// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
// (C) Copyright 2003-2007 Jonathan Turkanis
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)

// See http://www.boost.org/libs/iostreams for documentation.

// To configure Boost to work with libbz2, see the
// installation instructions here:
// http://boost.org/libs/iostreams/doc/index.html?path=7

// Define BOOST_IOSTREAMS_SOURCE so that <boost/iostreams/detail/config.hpp>
// knows that we are building the library (possibly exporting code), rather
// than using it (possibly importing code).
#define CPPCMS_BOOST_IOSTREAMS_SOURCE

#include <cppcms_boost/iostreams/detail/config/dyn_link.hpp>
#include <cppcms_boost/iostreams/filter/gzip.hpp>

namespace cppcms_boost { namespace iostreams {

//------------------Implementation of gzip_header-----------------------------//

namespace detail {

void gzip_header::process(char c)
{
uint8_t value = static_cast<uint8_t>(c);
switch (state_) {
case s_id1:
if (value != gzip::magic::id1)
throw gzip_error(gzip::bad_header);
state_ = s_id2;
break;
case s_id2:
if (value != gzip::magic::id2)
throw gzip_error(gzip::bad_header);
state_ = s_cm;
break;
case s_cm:
if (value != gzip::method::deflate)
throw gzip_error(gzip::bad_method);
state_ = s_flg;
break;
case s_flg:
flags_ = value;
state_ = s_mtime;
break;
case s_mtime:
mtime_ += value << (offset_ * 8);
if (offset_ == 3) {
state_ = s_xfl;
offset_ = 0;
} else {
++offset_;
}
break;
case s_xfl:
state_ = s_os;
break;
case s_os:
os_ = value;
if (flags_ & gzip::flags::extra) {
state_ = s_extra;
} else if (flags_ & gzip::flags::name) {
state_ = s_name;
} else if (flags_ & gzip::flags::comment) {
state_ = s_comment;
} else if (flags_ & gzip::flags::header_crc) {
state_ = s_hcrc;
} else {
state_ = s_done;
}
break;
case s_xlen:
xlen_ += value << (offset_ * 8);
if (offset_ == 1) {
state_ = s_extra;
offset_ = 0;
} else {
++offset_;
}
break;
case s_extra:
if (--xlen_ == 0) {
if (flags_ & gzip::flags::name) {
state_ = s_name;
} else if (flags_ & gzip::flags::comment) {
state_ = s_comment;
} else if (flags_ & gzip::flags::header_crc) {
state_ = s_hcrc;
} else {
state_ = s_done;
}
}
break;
case s_name:
if (c != 0) {
file_name_ += c;
} else if (flags_ & gzip::flags::comment) {
state_ = s_comment;
} else if (flags_ & gzip::flags::header_crc) {
state_ = s_hcrc;
} else {
state_ = s_done;
}
break;
case s_comment:
if (c != 0) {
comment_ += c;
} else if (flags_ & gzip::flags::header_crc) {
state_ = s_hcrc;
} else {
state_ = s_done;
}
break;
case s_hcrc:
if (offset_ == 1) {
state_ = s_done;
offset_ = 0;
} else {
++offset_;
}
break;
default:
assert(0);
}
}

void gzip_header::reset()
{
file_name_.clear();
comment_.clear();
os_ = flags_ = offset_ = xlen_ = 0;
mtime_ = 0;
state_ = s_id1;
}

//------------------Implementation of gzip_footer-----------------------------//

void gzip_footer::process(char c)
{
uint8_t value = static_cast<uint8_t>(c);
if (state_ == s_crc) {
crc_ += value << (offset_ * 8);
if (offset_ == 3) {
state_ = s_isize;
offset_ = 0;
} else {
++offset_;
}
} else if (state_ == s_isize) {
isize_ += value << (offset_ * 8);
if (offset_ == 3) {
state_ = s_done;
offset_ = 0;
} else {
++offset_;
}
} else {
assert(0);
}
}

void gzip_footer::reset()
{
crc_ = isize_ = offset_ = 0;
state_ = s_crc;
}

} // End namespace boost::iostreams::detail.

} } // End namespaces iostreams, boost.

+ 0
- 191
cppcms_boost/src/zlib.cpp View File

@@ -1,191 +0,0 @@
// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
// (C) Copyright 2003-2007 Jonathan Turkanis
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)

// See http://www.boost.org/libs/iostreams for documentation.

// To configure Boost to work with zlib, see the
// installation instructions here:
// http://boost.org/libs/iostreams/doc/index.html?path=7

// Define BOOST_IOSTREAMS_SOURCE so that <boost/iostreams/detail/config.hpp>
// knows that we are building the library (possibly exporting code), rather
// than using it (possibly importing code).
#define CPPCMS_BOOST_IOSTREAMS_SOURCE

#include <cppcms_boost/iostreams/detail/config/dyn_link.hpp>
#include <cppcms_boost/iostreams/filter/zlib.hpp>
#include "zlib.h" // Jean-loup Gailly's and Mark Adler's "zlib.h" header.
// To configure Boost to work with zlib, see the
// installation instructions here:
// http://boost.org/libs/iostreams/doc/index.html?path=7

namespace cppcms_boost { namespace iostreams {

namespace zlib {

// Compression levels

const int no_compression = Z_NO_COMPRESSION;
const int best_speed = Z_BEST_SPEED;
const int best_compression = Z_BEST_COMPRESSION;
const int default_compression = Z_DEFAULT_COMPRESSION;

// Compression methods

const int deflated = Z_DEFLATED;

// Compression strategies

const int default_strategy = Z_DEFAULT_STRATEGY;
const int filtered = Z_FILTERED;
const int huffman_only = Z_HUFFMAN_ONLY;

// Status codes

const int okay = Z_OK;
const int stream_end = Z_STREAM_END;
const int stream_error = Z_STREAM_ERROR;
const int version_error = Z_VERSION_ERROR;
const int data_error = Z_DATA_ERROR;
const int mem_error = Z_MEM_ERROR;
const int buf_error = Z_BUF_ERROR;

// Flush codes

const int finish = Z_FINISH;
const int no_flush = Z_NO_FLUSH;
const int sync_flush = Z_SYNC_FLUSH;

// Code for current OS

//const int os_code = OS_CODE;

} // End namespace zlib.

//------------------Implementation of zlib_error------------------------------//
zlib_error::zlib_error(int error)
: CPPCMS_BOOST_IOSTREAMS_FAILURE("zlib error"), error_(error)
{ }

void zlib_error::check(int error)
{
switch (error) {
case Z_OK:
case Z_STREAM_END:
//case Z_BUF_ERROR:
return;
case Z_MEM_ERROR:
throw std::bad_alloc();
default:
throw zlib_error(error);
;
}
}

//------------------Implementation of zlib_base-------------------------------//

namespace detail {

zlib_base::zlib_base()
: stream_(new z_stream), calculate_crc_(false), crc_(0)
{ }

zlib_base::~zlib_base() { delete static_cast<z_stream*>(stream_); }

void zlib_base::before( const char*& src_begin, const char* src_end,
char*& dest_begin, char* dest_end )
{
z_stream* s = static_cast<z_stream*>(stream_);
s->next_in = reinterpret_cast<zlib::byte*>(const_cast<char*>(src_begin));
s->avail_in = static_cast<zlib::uint>(src_end - src_begin);
s->next_out = reinterpret_cast<zlib::byte*>(dest_begin);
s->avail_out= static_cast<zlib::uint>(dest_end - dest_begin);
}

void zlib_base::after(const char*& src_begin, char*& dest_begin, bool compress)
{
z_stream* s = static_cast<z_stream*>(stream_);
char* next_in = reinterpret_cast<char*>(s->next_in);
char* next_out = reinterpret_cast<char*>(s->next_out);
if (calculate_crc_) {
const zlib::byte* buf = compress ?
reinterpret_cast<const zlib::byte*>(src_begin) :
reinterpret_cast<const zlib::byte*>(
const_cast<const char*>(dest_begin)
);
zlib::uint length = compress ?
static_cast<zlib::uint>(next_in - src_begin) :
static_cast<zlib::uint>(next_out - dest_begin);
if (length > 0)
crc_ = crc32(crc_, buf, length);
}
total_in_ = s->total_in;
total_out_ = s->total_out;
src_begin = const_cast<const char*>(next_in);
dest_begin = next_out;
}

int zlib_base::xdeflate(int flush)
{
return ::deflate(static_cast<z_stream*>(stream_), flush);
}

int zlib_base::xinflate(int flush)
{
return ::inflate(static_cast<z_stream*>(stream_), flush);
}

void zlib_base::reset(bool compress, bool realloc)
{
z_stream* s = static_cast<z_stream*>(stream_);
// Undiagnosed bug:
// deflateReset(), etc., return Z_DATA_ERROR
//zlib_error::check(
realloc ?
(compress ? deflateReset(s) : inflateReset(s)) :
(compress ? deflateEnd(s) : inflateEnd(s))
;
//);
}

void zlib_base::do_init
( const zlib_params& p, bool compress,
#if !CPPCMS_BOOST_WORKAROUND(CPPCMS_BOOST_MSVC, < 1300)
zlib::xalloc_func /* alloc */, zlib::xfree_func /* free*/,
#endif
void* derived )
{
calculate_crc_ = p.calculate_crc;
z_stream* s = static_cast<z_stream*>(stream_);

// Current interface for customizing memory management
// is non-conforming and has been disabled:
//#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
// s->zalloc = alloc;
// s->zfree = free;
//#else
s->zalloc = 0;
s->zfree = 0;
//#endif
s->opaque = derived;
int window_bits = p.noheader? -p.window_bits : p.window_bits;
zlib_error::check(
compress ?
deflateInit2( s,
p.level,
p.method,
window_bits,
p.mem_level,
p.strategy ) :
inflateInit2(s, window_bits)
);
}

} // End namespace detail.

//----------------------------------------------------------------------------//

} } // End namespaces iostreams, boost.

+ 38
- 0
private/crc32.h View File

@@ -0,0 +1,38 @@
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
//
// See accompanying file COPYING.TXT file for licensing details.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef CPPCMS_IMPL_CRC32_H
#define CPPCMS_IMPL_CRC32_H
#include <cppcms/cstdint.h>
#include <zlib.h>

namespace cppcms {
namespace impl {

class crc32_calc {
public:
crc32_calc()
{
value_ = crc32(0,0,0);
}
void process_bytes(void const *ptr,size_t n)
{
if(n==0)
return;
value_ = crc32(value_,reinterpret_cast<Bytef const *>(ptr),n);
}
uint32_t checksum() const
{
return value_;
}
private:
uint32_t value_;
};

} // impl
} // cppcms
#endif

+ 3
- 8
src/session_posix_file_storage.cpp View File

@@ -13,12 +13,7 @@
#include <cppcms/cppcms_error.h>
#include <cppcms/config.h>

#ifdef CPPCMS_USE_EXTERNAL_BOOST
# include <boost/crc.hpp>
#else // Internal Boost
# include <cppcms_boost/crc.hpp>
namespace boost = cppcms_boost;
#endif
#include "crc32.h"

#include <sys/types.h>
#include <sys/stat.h>
@@ -258,7 +253,7 @@ bool session_file_storage::read_from_file(int fd,time_t &timeout,std::string &da
if(!read_all(fd,&crc,sizeof(crc)) || !read_all(fd,&size,sizeof(size)))
return false;
std::vector<char> buffer(size,0);
boost::crc_32_type crc_calc;
impl::crc32_calc crc_calc;
if(size > 0) {
if(!read_all(fd,&buffer.front(),size))
return false;
@@ -282,7 +277,7 @@ void session_file_storage::save_to_file(int fd,time_t timeout,std::string const
uint32_t crc;
uint32_t size;
} tmp = { timeout, 0, static_cast<uint32_t>(in.size()) };
boost::crc_32_type crc_calc;
impl::crc32_calc crc_calc;
crc_calc.process_bytes(in.data(),in.size());
tmp.crc=crc_calc.checksum();
if(!write_all(fd,&tmp,sizeof(tmp)) || !write_all(fd,in.data(),in.size()))


+ 3
- 8
src/session_win32_file_storage.cpp View File

@@ -15,12 +15,7 @@
#include <booster/nowide/cstdio.h>


#ifdef CPPCMS_USE_EXTERNAL_BOOST
# include <boost/crc.hpp>
#else // Internal Boost
# include <cppcms_boost/crc.hpp>
namespace boost = cppcms_boost;
#endif
#include "crc32.h"

#include <memory>
#include <time.h>
@@ -168,7 +163,7 @@ bool session_file_storage::read_from_file(HANDLE h,time_t &timeout,std::string &
if(!read_all(h,&crc,sizeof(crc)) || !read_all(h,&size,sizeof(size)))
return false;
std::vector<char> buffer(size,0);
boost::crc_32_type crc_calc;
impl::crc32_calc crc_calc;
if(size > 0) {
if(!read_all(h,&buffer.front(),size))
return false;
@@ -192,7 +187,7 @@ void session_file_storage::save_to_file(HANDLE h,time_t timeout,std::string cons
uint32_t crc;
uint32_t size;
} tmp = { timeout, 0, in.size() };
boost::crc_32_type crc_calc;
impl::crc32_calc crc_calc;
crc_calc.process_bytes(in.data(),in.size());
tmp.crc=crc_calc.checksum();
if(!write_all(h,&tmp,sizeof(tmp)) || !write_all(h,in.data(),in.size()))


Loading…
Cancel
Save